Skip to content

Commit 7f29357

Browse files
hoxyqfacebook-github-bot
authored andcommitted
refactor(scripts): use forEachPackage instead of yarn workspaces info (#35633)
Summary: Pull Request resolved: #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
1 parent be895c8 commit 7f29357

File tree

3 files changed

+33
-36
lines changed

3 files changed

+33
-36
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,7 @@ jobs:
15771577
executor: reactnativeandroid
15781578
steps:
15791579
- checkout
1580+
- run_yarn
15801581
- run:
15811582
name: Set NPM auth token
15821583
command: echo "//registry.npmjs.org/:_authToken=${CIRCLE_NPM_TOKEN}" > ~/.npmrc

scripts/run-ci-e2e-tests.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const {cd, cp, echo, exec, exit, mv} = require('shelljs');
2323
const spawn = require('child_process').spawn;
2424
const argv = require('yargs').argv;
2525
const path = require('path');
26+
27+
const forEachPackage = require('./monorepo/for-each-package');
2628
const setupVerdaccio = require('./setup-verdaccio');
2729

2830
const SCRIPTS = __dirname;
@@ -79,14 +81,18 @@ try {
7981
VERDACCIO_PID = setupVerdaccio(ROOT, VERDACCIO_CONFIG_PATH);
8082

8183
describe('Publish packages');
82-
const packages = JSON.parse(
83-
JSON.parse(exec('yarn --json workspaces info').stdout).data,
84+
forEachPackage(
85+
(packageAbsolutePath, packageRelativePathFromRoot, packageManifest) => {
86+
if (packageManifest.private) {
87+
return;
88+
}
89+
90+
exec(
91+
'npm publish --registry http://localhost:4873 --yes --access public',
92+
{cwd: packageAbsolutePath},
93+
);
94+
},
8495
);
85-
Object.keys(packages).forEach(packageName => {
86-
exec(
87-
`cd ${packages[packageName].location} && npm publish --registry http://localhost:4873 --yes --access public`,
88-
);
89-
});
9096

9197
describe('Scaffold a basic React Native app from template');
9298
exec(`rsync -a ${ROOT}/template ${REACT_NATIVE_TEMP_DIR}`);

scripts/template/initialize.js

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111

1212
const yargs = require('yargs');
1313
const {execSync, spawnSync} = require('child_process');
14-
const fs = require('fs');
15-
const path = require('path');
1614

15+
const forEachPackage = require('../monorepo/for-each-package');
1716
const setupVerdaccio = require('../setup-verdaccio');
1817

1918
const {argv} = yargs
@@ -43,41 +42,32 @@ const {reactNativeRootPath, templateName, templateConfigPath, directory} = argv;
4342

4443
const VERDACCIO_CONFIG_PATH = `${reactNativeRootPath}/.circleci/verdaccio.yml`;
4544

46-
function readPackageJSON(pathToPackage) {
47-
return JSON.parse(fs.readFileSync(path.join(pathToPackage, 'package.json')));
48-
}
49-
5045
function install() {
51-
const yarnWorkspacesStdout = execSync('yarn --json workspaces info', {
52-
cwd: reactNativeRootPath,
53-
encoding: 'utf8',
54-
});
55-
const packages = JSON.parse(JSON.parse(yarnWorkspacesStdout).data);
56-
5746
const VERDACCIO_PID = setupVerdaccio(
5847
reactNativeRootPath,
5948
VERDACCIO_CONFIG_PATH,
6049
);
6150
process.stdout.write('Bootstrapped Verdaccio \u2705\n');
6251

63-
process.stdout.write('Starting to publish all the packages...\n');
64-
Object.entries(packages).forEach(([packageName, packageEntity]) => {
65-
const packageRelativePath = packageEntity.location;
66-
const packageAbsolutePath = `${reactNativeRootPath}/${packageRelativePath}`;
67-
68-
const packageManifest = readPackageJSON(packageAbsolutePath);
69-
if (packageManifest.private) {
70-
return;
71-
}
72-
73-
execSync('npm publish --registry http://localhost:4873 --access public', {
74-
cwd: `${reactNativeRootPath}/${packageEntity.location}`,
75-
stdio: [process.stdin, process.stdout, process.stderr],
76-
});
52+
process.stdout.write('Starting to publish every package...\n');
53+
forEachPackage(
54+
(packageAbsolutePath, packageRelativePathFromRoot, packageManifest) => {
55+
if (packageManifest.private) {
56+
return;
57+
}
58+
59+
execSync('npm publish --registry http://localhost:4873 --access public', {
60+
cwd: packageAbsolutePath,
61+
stdio: [process.stdin, process.stdout, process.stderr],
62+
});
63+
64+
process.stdout.write(
65+
`Published ${packageManifest.name} to proxy \u2705\n`,
66+
);
67+
},
68+
);
7769

78-
process.stdout.write(`Published ${packageName} to proxy \u2705\n`);
79-
});
80-
process.stdout.write('Published all packages \u2705\n');
70+
process.stdout.write('Published every package \u2705\n');
8171

8272
execSync(
8373
`node cli.js init ${templateName} --directory ${directory} --template ${templateConfigPath} --verbose --skip-install`,

0 commit comments

Comments
 (0)