@samitouri / QOS-React-1 / commits / 5572edc929

[compiler] Various fixes for publishing script

- Specify a registry for npm publish because otherwise it tries to use the yarn registry - `packages` option actually works This _should_ work now (note last line of output), will test it once we land this since i want to publish a new version of the eslint plugin with some important fixes. ``` npm notice npm notice 📦 eslint-plugin-react-compiler@0.0.0-experimental-53bb89e-20240515 npm notice === Tarball Contents === npm notice 827B README.md npm notice 2.1MB dist/index.js npm notice 1.0kB package.json npm notice === Tarball Details === npm notice name: eslint-plugin-react-compiler npm notice version: 0.0.0-experimental-53bb89e-20240515 npm notice filename: eslint-plugin-react-compiler-0.0.0-experimental-53bb89e-20240515.tgz npm notice package size: 300.9 kB npm notice unpacked size: 2.1 MB npm notice shasum: cb99823f3a483c74f470085cac177bd020f7a85a npm notice integrity: sha512-L3HV9qja1dnCl[...]IaRSZJ3P/v6yQ== npm notice total files: 3 npm notice npm notice Publishing to http://registry.npmjs.org/ with tag latest and default access (dry-run) ``` ghstack-source-id: 63067ef772c780a665fc04e642b0f533aaacbe44 Pull Request resolved: https://github.com/facebook/react/pull/29082

Lauren Tan committed May 15, 2024 at 16:13 UTC 5572edc929bca8d4248d579d7931ab79e3395d04
1 file changed +21 -14
compiler/scripts/publish.js
+21 -14
@@ -24,7 +24,7 @@ const spawnHelper = util.promisify(_spawn);
24 function execHelper(command, options, streamStdout = false) {
25 return new Promise((resolve, reject) => {
26 const proc = cp.exec(command, options, (error, stdout) =>
27 - error ? reject(error) : resolve(stdout.trim())
27 + error ? reject(error) : resolve(stdout.trim()),
28 );
29 if (streamStdout) {
30 proc.stdout.pipe(process.stdout);
@@ -38,7 +38,7 @@ function sleep(ms) {
38
39 async function getDateStringForCommit(commit) {
40 let dateString = await execHelper(
41 - `git show -s --no-show-signature --format=%cd --date=format:%Y%m%d ${commit}`
41 + `git show -s --no-show-signature --format=%cd --date=format:%Y%m%d ${commit}`,
42 );
43
44 // On CI environment, this string is wrapped with quotes '...'s
@@ -92,14 +92,18 @@ async function main() {
92 .parseSync();
93
94 const { packages, forReal, debug } = argv;
95 + let pkgNames = packages;
96 + if (Array.isArray(packages) === false) {
97 + pkgNames = [packages];
98 + }
99 const spinner = ora(
100 `Preparing to publish ${
101 forReal === true ? "(for real)" : "(dry run)"
98 - } [debug=${debug}]`
102 + } [debug=${debug}]`,
103 ).info();
104
105 spinner.info("Building packages");
102 - for (const pkgName of packages) {
106 + for (const pkgName of pkgNames) {
107 const command = `yarn workspace ${pkgName} run build`;
108 spinner.start(`Running: ${command}\n`);
109 try {
@@ -114,7 +118,7 @@ async function main() {
118
119 if (forReal === false) {
120 spinner.info("Dry run: Report tarball contents");
117 - for (const pkgName of packages) {
121 + for (const pkgName of pkgNames) {
122 console.log(`\n========== ${pkgName} ==========\n`);
123 spinner.start(`Running npm pack --dry-run\n`);
124 try {
@@ -129,7 +133,7 @@ async function main() {
133 spinner.stop(`Successfully packed ${pkgName} (dry run)`);
134 }
135 spinner.succeed(
132 - "Please confirm contents of packages before publishing. You can run this command again with --for-real to publish to npm"
136 + "Please confirm contents of packages before publishing. You can run this command again with --for-real to publish to npm",
137 );
138 }
139
@@ -138,11 +142,11 @@ async function main() {
142 "git show -s --no-show-signature --format=%h",
143 {
144 cwd: path.resolve(__dirname, ".."),
141 - }
145 + },
146 );
147 const dateString = await getDateStringForCommit(commit);
148
145 - for (const pkgName of packages) {
149 + for (const pkgName of pkgNames) {
150 const pkgDir = path.resolve(__dirname, `../packages/${pkgName}`);
151 const { hash } = await hashElement(pkgDir, {
152 encoding: "hex",
@@ -157,20 +161,20 @@ async function main() {
161 `yarn version --new-version ${newVersion} --no-git-tag-version`,
162 {
163 cwd: pkgDir,
160 - }
164 + },
165 );
166 await execHelper(
167 `git add package.json && git commit -m "Bump version to ${newVersion}"`,
168 {
169 cwd: pkgDir,
166 - }
170 + },
171 );
172 } catch (e) {
173 spinner.fail(e.toString());
174 throw e;
175 }
176 spinner.succeed(
173 - `Bumped ${pkgName} to ${newVersion} and added a git commit`
177 + `Bumped ${pkgName} to ${newVersion} and added a git commit`,
178 );
179 }
180
@@ -178,19 +182,22 @@ async function main() {
182 spinner.info(
183 `🚨🚨🚨 About to publish to npm in ${
184 TIME_TO_RECONSIDER / 1000
181 - } seconds. You still have time to kill this script!`
185 + } seconds. You still have time to kill this script!`,
186 );
187 await sleep(TIME_TO_RECONSIDER);
188 }
189
186 - for (const pkgName of packages) {
190 + for (const pkgName of pkgNames) {
191 const pkgDir = path.resolve(__dirname, `../packages/${pkgName}`);
192 console.log(`\n========== ${pkgName} ==========\n`);
193 spinner.start(`Publishing ${pkgName} to npm\n`);
194
195 const opts = debug === true ? ["publish", "--dry-run"] : ["publish"];
196 try {
193 - await execHelper(`npm ${opts.join(" ")}`, { cwd: pkgDir });
197 + await spawnHelper("npm", [...opts, "--registry=http://registry.npmjs.org"], {
198 + cwd: pkgDir,
199 + stdio: "inherit",
200 + });
201 console.log("\n");
202 } catch (e) {
203 spinner.fail(e.toString());