refactor(circleci/template): publish all packages to Verdaccio before template initialization (#35459)

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

Changelog:
[Internal] [Changed] - now bootstrapping Verdaccio before template app initialization, this is required because react-native migh depend on some package which version is not yet published to npm

Reviewed By: cipolleschi

Differential Revision: D41521496

fbshipit-source-id: 6183ab02c697d9d08e9dca5b323bd7a11a749c3a
This commit is contained in:
Ruslan Lesiutin
2022-11-24 13:56:09 -08:00
committed by Facebook GitHub Bot
parent 50c6ee40ea
commit 6a45f2ce79
5 changed files with 107 additions and 128 deletions
+2 -4
View File
@@ -764,8 +764,7 @@ jobs:
command: |
REPO_ROOT=$(pwd)
node ./scripts/set-rn-template-version.js "file:$REPO_ROOT/build/$(cat build/react-native-package-version)"
node cli.js init $PROJECT_NAME --directory "/tmp/$PROJECT_NAME" --template $REPO_ROOT --verbose --skip-install
node ./scripts/template/install-dependencies.js --reactNativeRootPath $REPO_ROOT --templatePath "/tmp/$PROJECT_NAME"
node ./scripts/template/initialize.js --reactNativeRootPath $REPO_ROOT --templateName $PROJECT_NAME --templateConfigPath $REPO_ROOT --directory "/tmp/$PROJECT_NAME"
- run:
name: Build the template application for << parameters.flavor >> with Architecture set to << parameters.architecture >>, and using the << parameters.jsengine>> JS engine.
command: |
@@ -849,8 +848,7 @@ jobs:
PACKAGE=$(cat build/react-native-package-version)
PATH_TO_PACKAGE="$REPO_ROOT/build/$PACKAGE"
node ./scripts/set-rn-template-version.js "file:$PATH_TO_PACKAGE"
node cli.js init $PROJECT_NAME --directory "/tmp/$PROJECT_NAME" --template $REPO_ROOT --verbose --skip-install
node ./scripts/template/install-dependencies.js --reactNativeRootPath $REPO_ROOT --templatePath "/tmp/$PROJECT_NAME"
node ./scripts/template/initialize.js --reactNativeRootPath $REPO_ROOT --templateName $PROJECT_NAME --templateConfigPath $REPO_ROOT --directory "/tmp/$PROJECT_NAME"
- run:
name: Install iOS dependencies - Configuration << parameters.flavor >>; New Architecture << parameters.architecture >>; JS Engine << parameters.jsengine>>; Flipper << parameters.flipper >>
command: |
-30
View File
@@ -1,30 +0,0 @@
## Why?
The main purpose of `install-dependencies.js` is to bootstrap [Verdaccio](https://verdaccio.org/docs/what-is-verdaccio). It will host all the local packages, which are not yet present on npm registry. In the near future this should help us in keep template tests green, because once we move to [monorepo structure](https://github.com/react-native-community/discussions-and-proposals/pull/480), template app may use some versions of dependencies that are not yet present on npm registry.
## I have migrated some module to package, which is not yet published to npm, how to use it?
First of all, you need to modify [Verdaccio config](https://github.com/facebook/react-native/tree/main/scripts/template/verdaccio.yml):
```diff
packages:
+ '<my-migrated-package-name>':
+ access: $all
+ publish: $all
'@*/*':
access: $all
publish: $authenticated
proxy: npmjs
'**':
access: $all
publish: $all
proxy: npmjs
```
After that, you should modify [install-dependencies script](https://github.com/facebook/react-native/tree/main/scripts/template/install-dependencies.js) to include your package for publishing
```diff
const PACKAGES_TO_PUBLISH_PATHS = [
...
+ "packages/<your-package-folder-name>"
];
```
+105
View File
@@ -0,0 +1,105 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
'use strict';
const yargs = require('yargs');
const {execSync, spawnSync} = require('child_process');
const fs = require('fs');
const path = require('path');
const setupVerdaccio = require('../setup-verdaccio');
const {argv} = yargs
.option('r', {
alias: 'reactNativeRootPath',
describe: 'Path to root folder of react-native',
required: true,
})
.option('n', {
alias: 'templateName',
describe: 'Template App name',
required: true,
})
.option('tcp', {
alias: 'templateConfigPath',
describe: 'Path to folder containing template config',
required: true,
})
.option('d', {
alias: 'directory',
describe: 'Path to template application folder',
required: true,
})
.strict();
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 packageManifest = readPackageJSON(packageAbsolutePath);
if (packageManifest.private) {
return;
}
const packageRelativePath = packageEntity.location;
const packageAbsolutePath = `${reactNativeRootPath}/${packageRelativePath}`;
execSync('npm publish --registry http://localhost:4873 --access public', {
cwd: `${reactNativeRootPath}/${packageEntity.location}`,
stdio: [process.stdin, process.stdout, process.stderr],
});
process.stdout.write(`Published ${packageName} to proxy \u2705\n`);
});
process.stdout.write('Published all packages \u2705\n');
execSync(
`node cli.js init ${templateName} --directory ${directory} --template ${templateConfigPath} --verbose --skip-install`,
{
cwd: reactNativeRootPath,
stdio: [process.stdin, process.stdout, process.stderr],
},
);
process.stdout.write('Completed initialization of template app \u2705\n');
process.stdout.write('Installing dependencies in template app folder...\n');
spawnSync('yarn', ['install'], {
cwd: directory,
stdio: [process.stdin, process.stdout, process.stderr],
});
process.stdout.write('Installed dependencies via Yarn \u2705\n');
process.stdout.write(`Killing verdaccio. PID — ${VERDACCIO_PID}...\n`);
execSync(`kill -9 ${VERDACCIO_PID}`);
process.stdout.write('Killed Verdaccio process \u2705\n');
process.exit();
}
install();
-67
View File
@@ -1,67 +0,0 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
'use strict';
const yargs = require('yargs');
const {execSync, spawnSync} = require('child_process');
const setupVerdaccio = require('../setup-verdaccio');
const {argv} = yargs
.option('r', {
alias: 'reactNativeRootPath',
describe: 'Path to root folder of react-native',
required: true,
})
.option('c', {
alias: 'templatePath',
describe: 'Path to template application folder',
required: true,
})
.strict();
const {reactNativeRootPath, templatePath} = argv;
const VERDACCIO_CONFIG_PATH = `${reactNativeRootPath}/scripts/template/verdaccio.yml`;
const VERDACCIO_STORAGE_PATH = `${templatePath}/node_modules`;
const PACKAGES_TO_PUBLISH_PATHS = [];
function install() {
const VERDACCIO_PID = setupVerdaccio(
reactNativeRootPath,
VERDACCIO_CONFIG_PATH,
VERDACCIO_STORAGE_PATH,
);
process.stdout.write('Bootstrapped Verdaccio \u2705\n');
// Publish all necessary packages...
for (const packagePath of PACKAGES_TO_PUBLISH_PATHS) {
execSync('npm publish --registry http://localhost:4873 --access public', {
cwd: `${reactNativeRootPath}/${packagePath}`,
stdio: [process.stdin, process.stdout, process.stderr],
});
process.stdout.write(`Published /${packagePath} to proxy \u2705\n`);
}
spawnSync('yarn', ['install'], {
cwd: templatePath,
stdio: [process.stdin, process.stdout, process.stderr],
});
process.stdout.write('Installed dependencies via Yarn \u2705\n');
process.stdout.write(`Killing verdaccio. PID — ${VERDACCIO_PID}...\n`);
execSync(`kill -9 ${VERDACCIO_PID}`);
process.stdout.write('Killed Verdaccio process \u2705\n');
process.exit();
}
install();
-27
View File
@@ -1,27 +0,0 @@
storage: ./storage
auth:
htpasswd:
file: ./htpasswd
uplinks:
npmjs:
url: https://registry.npmjs.org/
max_fails: 40
maxage: 30m
timeout: 60s
fail_timeout: 10m
cache: false
agent_options:
keepAlive: true
maxSockets: 40
maxFreeSockets: 10
packages:
'@*/*':
access: $all
publish: $authenticated
proxy: npmjs
'**':
access: $all
publish: $all
proxy: npmjs
logs:
- {type: file, path: verdaccio.log, format: json, level: warn}