Skip to content

Commit

Permalink
refactor(scripts): use forEachPackage instead of `yarn workspaces inf…
Browse files Browse the repository at this point in the history
…o` (#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
  • Loading branch information
hoxyq authored and facebook-github-bot committed Dec 14, 2022
1 parent be895c8 commit 7f29357
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 36 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 13 additions & 7 deletions scripts/run-ci-e2e-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}`);
Expand Down
48 changes: 19 additions & 29 deletions scripts/template/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}`;

const packageManifest = readPackageJSON(packageAbsolutePath);
if (packageManifest.private) {
return;
}

execSync('npm publish --registry http://localhost:4873 --access public', {
cwd: `${reactNativeRootPath}/${packageEntity.location}`,
stdio: [process.stdin, process.stdout, process.stderr],
});
process.stdout.write('Starting to publish every package...\n');
forEachPackage(
(packageAbsolutePath, packageRelativePathFromRoot, packageManifest) => {
if (packageManifest.private) {
return;
}

execSync('npm publish --registry http://localhost:4873 --access public', {
cwd: packageAbsolutePath,
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`,
Expand Down

0 comments on commit 7f29357

Please sign in to comment.