Skip to content

Commit

Permalink
feat(@turbo/codemod): add support for custom NPM registries (#9803)
Browse files Browse the repository at this point in the history
Fixes #4152

### Description

<!--
  ✍️ Write a short summary of your work.
  If necessary, include relevant screenshots.
-->

NPM (and alternative tools like PNPM) pass the registry as an
environment variable `npm_config_registry`.

This allows the `codemod` package to use it when present (which is often
the case).

### Testing Instructions

<!--
  Give a quick description of steps to test your changes.
-->

- Go to `turbo-codemod`
- Run `turbo run build`
- Invoke the binary `dist/cli.js migrate --to=latest --force` (maybe
play with other `to` values also)

Co-authored-by: Mohamed Meligy <[email protected]>
Co-authored-by: Anthony Shew <[email protected]>
  • Loading branch information
3 people authored Feb 6, 2025
1 parent 3b9881a commit 818a3a8
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from "axios";
import type { MigrateCommandOptions } from "../types";

const REGISTRY = "https://registry.npmjs.org";
const DEFAULT_REGISTRY = "https://registry.npmjs.org";

interface PackageDetailsResponse {
"dist-tags": {
Expand All @@ -12,9 +12,12 @@ interface PackageDetailsResponse {
}

async function getPackageDetails({ packageName }: { packageName: string }) {
const registry =
process.env.npm_config_registry?.replace(/\/$/, "") || DEFAULT_REGISTRY;

try {
const result = await axios.get<PackageDetailsResponse>(
`${REGISTRY}/${packageName}`
`${registry}/${packageName}`
);
return result.data;
} catch (err) {
Expand Down

0 comments on commit 818a3a8

Please sign in to comment.