MCPcopy Index your code
hub / github.com/react/react / publishToNPM

Function publishToNPM

scripts/devtools/publish-release.js:60–120  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

58}
59
60async function publishToNPM() {
61 const {otp} = await inquirer.prompt([
62 {
63 type: 'input',
64 name: 'otp',
65 message: 'Please provide an NPM two-factor auth token:',
66 },
67 ]);
68
69 console.log('');
70
71 if (!otp) {
72 console.error(chalk.red(`Invalid OTP provided: "${chalk.bold(otp)}"`));
73 process.exit(0);
74 }
75
76 for (let index = 0; index < NPM_PACKAGES.length; index++) {
77 const npmPackage = NPM_PACKAGES[index];
78 const packagePath = join(ROOT_PATH, 'packages', npmPackage);
79 const {version} = readJsonSync(join(packagePath, 'package.json'));
80
81 // Check if this package version has already been published.
82 // If so we might be resuming from a previous run.
83 // We could infer this by comparing the build-info.json,
84 // But for now the easiest way is just to ask if this is expected.
85 const versionListJSON = await execRead(
86 `npm view ${npmPackage} versions --json`
87 );
88 const versionList = JSON.parse(versionListJSON);
89 const versionIsAlreadyPublished = versionList.includes(version);
90
91 if (versionIsAlreadyPublished) {
92 console.log('');
93 console.log(
94 `${npmPackage} version ${chalk.bold(
95 version
96 )} has already been published.`
97 );
98
99 await confirm(`Is this expected (will skip ${npmPackage}@${version})?`);
100 continue;
101 }
102
103 if (DRY_RUN) {
104 console.log(`Publishing package ${chalk.bold(npmPackage)}`);
105 console.log(chalk.dim(` npm publish --otp=${otp}`));
106 } else {
107 const publishPromise = exec(`npm publish --otp=${otp}`, {
108 cwd: packagePath,
109 });
110
111 await logger(
112 publishPromise,
113 `Publishing package ${chalk.bold(npmPackage)}`,
114 {
115 estimate: 2500,
116 }
117 );

Callers 2

runFunction · 0.85
mainFunction · 0.85

Calls 6

execFunction · 0.85
loggerFunction · 0.85
exitMethod · 0.80
execReadFunction · 0.70
confirmFunction · 0.70
errorMethod · 0.65

Tested by

no test coverage detected