refactor(scripts): use forEachPackage instead of yarn workspaces info (#35633)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/35633

Changelog: [Internal]

These changes add usage of `forEachPackage` as a replacement for `yarn --json workspaces info`.

This is because at some point in release cycle there is a script which removed `workspaces` block from react-native's `package.json`, so `yarn --info workspaces info` produces an error

Reviewed By: cortinico

Differential Revision: D41996732

fbshipit-source-id: 2c62c1a5eb41d711c563f9f7b0de3d67fc11823d
This commit is contained in:
Ruslan Lesiutin
2022-12-14 03:04:06 -08:00
committed by Facebook GitHub Bot
parent be895c870c
commit 7f29357c7c
3 changed files with 31 additions and 34 deletions
+1
View File
@@ -1577,6 +1577,7 @@ jobs:
executor: reactnativeandroid
steps:
- checkout
- run_yarn
- run:
name: Set NPM auth token
command: echo "//registry.npmjs.org/:_authToken=${CIRCLE_NPM_TOKEN}" > ~/.npmrc
+13 -7
View File
@@ -23,6 +23,8 @@ const {cd, cp, echo, exec, exit, mv} = require('shelljs');
const spawn = require('child_process').spawn;
const argv = require('yargs').argv;
const path = require('path');
const forEachPackage = require('./monorepo/for-each-package');
const setupVerdaccio = require('./setup-verdaccio');
const SCRIPTS = __dirname;
@@ -79,14 +81,18 @@ try {
VERDACCIO_PID = setupVerdaccio(ROOT, VERDACCIO_CONFIG_PATH);
describe('Publish packages');
const packages = JSON.parse(
JSON.parse(exec('yarn --json workspaces info').stdout).data,
forEachPackage(
(packageAbsolutePath, packageRelativePathFromRoot, packageManifest) => {
if (packageManifest.private) {
return;
}
exec(
'npm publish --registry http://localhost:4873 --yes --access public',
{cwd: packageAbsolutePath},
);
},
);
Object.keys(packages).forEach(packageName => {
exec(
`cd ${packages[packageName].location} && npm publish --registry http://localhost:4873 --yes --access public`,
);
});
describe('Scaffold a basic React Native app from template');
exec(`rsync -a ${ROOT}/template ${REACT_NATIVE_TEMP_DIR}`);
+17 -27
View File
@@ -11,9 +11,8 @@
const yargs = require('yargs');
const {execSync, spawnSync} = require('child_process');
const fs = require('fs');
const path = require('path');
const forEachPackage = require('../monorepo/for-each-package');
const setupVerdaccio = require('../setup-verdaccio');
const {argv} = yargs
@@ -43,41 +42,32 @@ const {reactNativeRootPath, templateName, templateConfigPath, directory} = argv;
const VERDACCIO_CONFIG_PATH = `${reactNativeRootPath}/.circleci/verdaccio.yml`;
function readPackageJSON(pathToPackage) {
return JSON.parse(fs.readFileSync(path.join(pathToPackage, 'package.json')));
}
function install() {
const yarnWorkspacesStdout = execSync('yarn --json workspaces info', {
cwd: reactNativeRootPath,
encoding: 'utf8',
});
const packages = JSON.parse(JSON.parse(yarnWorkspacesStdout).data);
const VERDACCIO_PID = setupVerdaccio(
reactNativeRootPath,
VERDACCIO_CONFIG_PATH,
);
process.stdout.write('Bootstrapped Verdaccio \u2705\n');
process.stdout.write('Starting to publish all the packages...\n');
Object.entries(packages).forEach(([packageName, packageEntity]) => {
const packageRelativePath = packageEntity.location;
const packageAbsolutePath = `${reactNativeRootPath}/${packageRelativePath}`;
process.stdout.write('Starting to publish every package...\n');
forEachPackage(
(packageAbsolutePath, packageRelativePathFromRoot, packageManifest) => {
if (packageManifest.private) {
return;
}
const packageManifest = readPackageJSON(packageAbsolutePath);
if (packageManifest.private) {
return;
}
execSync('npm publish --registry http://localhost:4873 --access public', {
cwd: packageAbsolutePath,
stdio: [process.stdin, process.stdout, process.stderr],
});
execSync('npm publish --registry http://localhost:4873 --access public', {
cwd: `${reactNativeRootPath}/${packageEntity.location}`,
stdio: [process.stdin, process.stdout, process.stderr],
});
process.stdout.write(
`Published ${packageManifest.name} to proxy \u2705\n`,
);
},
);
process.stdout.write(`Published ${packageName} to proxy \u2705\n`);
});
process.stdout.write('Published all packages \u2705\n');
process.stdout.write('Published every package \u2705\n');
execSync(
`node cli.js init ${templateName} --directory ${directory} --template ${templateConfigPath} --verbose --skip-install`,