react-native-community / cli

The React Native Community CLI - command line tools to help you build RN apps
MIT License
2.41k stars 905 forks source link

fix: Remove hardcoded npm registry url #2520

Open jasonjiicloud opened 1 month ago

jasonjiicloud commented 1 month ago

Summary:

fixes: #2519 Official npm registry url is hardcoded, the "cli" can't run successfully in a closed environment.

Following error is displayed when running npx @react-native-community/cli@latest init AwesomeProject --verbose.

error fetch failed.
TypeError: fetch failed
    at node:internal/deps/undici/undici:13178:13
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async getTemplateVersion (/Users/jilingyun/.npm/_npx/2788f5fbd47acb89/node_modules/@react-native-community/cli/build/tools/npm.js:121:16)
    at async createTemplateUri (/Users/jilingyun/.npm/_npx/2788f5fbd47acb89/node_modules/@react-native-community/cli/build/commands/init/version.js:53:29)
    at async createProject (/Users/jilingyun/.npm/_npx/2788f5fbd47acb89/node_modules/@react-native-community/cli/build/commands/init/init.js:341:23)
    at async Object.initialize [as func] (/Users/jilingyun/.npm/_npx/2788f5fbd47acb89/node_modules/@react-native-community/cli/build/commands/init/init.js:422:7)
    at async Command.handleAction (/Users/jilingyun/.npm/_npx/2788f5fbd47acb89/node_modules/@react-native-community/cli/build/index.js:116:9)

My solution is using getNpmRegistryUrl() to get real npm registry url in user's local environment, then it can avoid using official npm registry directly.

Test Plan:

Build and run node /path/to/react-native-cli/packages/cli/build/bin.js init AwesomeProject

Checklist

szymonrybczak commented 1 month ago

cc @blakef