diff --git a/scripts/run-ci-e2e-tests.js b/scripts/run-ci-e2e-tests.js index 7bbd538ec4045e..2b68e2917d44cf 100644 --- a/scripts/run-ci-e2e-tests.js +++ b/scripts/run-ci-e2e-tests.js @@ -85,7 +85,7 @@ try { ); describe('Set up Verdaccio'); - VERDACCIO_PID = setupVerdaccio(ROOT, VERDACCIO_CONFIG_PATH); + VERDACCIO_PID = setupVerdaccio(); describe('Build and publish packages'); if (exec('node ./scripts/build/build.js', {cwd: ROOT}).code) { diff --git a/scripts/template/initialize.js b/scripts/template/initialize.js index dd38532d26f1b2..a4e17f8a41cbe1 100644 --- a/scripts/template/initialize.js +++ b/scripts/template/initialize.js @@ -19,7 +19,6 @@ const {execSync} = require('child_process'); const path = require('path'); const REPO_ROOT = path.resolve(__dirname, '../..'); -const VERDACCIO_CONFIG_PATH = `${REPO_ROOT}/.circleci/verdaccio.yml`; const NPM_REGISTRY_SERVER = 'http://localhost:4873'; const config = { @@ -60,7 +59,7 @@ async function main() { return; } - const VERDACCIO_PID = setupVerdaccio(REPO_ROOT, VERDACCIO_CONFIG_PATH); + const VERDACCIO_PID = setupVerdaccio(); try { process.stdout.write('Bootstrapped Verdaccio \u2705\n'); diff --git a/scripts/template/setup-verdaccio.js b/scripts/template/setup-verdaccio.js index 1e843f9cc39f98..1d6347f8b0afba 100644 --- a/scripts/template/setup-verdaccio.js +++ b/scripts/template/setup-verdaccio.js @@ -12,24 +12,38 @@ 'use strict'; const {execSync, spawn} = require('child_process'); +const fs = require('fs'); +const path = require('path'); -function setupVerdaccio( - reactNativeRootPath /*: string */, - verdaccioConfigPath /*: string */, - verdaccioStoragePath /*: ?string */, -) /*: number */ { - execSync('echo "//localhost:4873/:_authToken=secretToken" > .npmrc', { - cwd: reactNativeRootPath, - }); +const REPO_ROOT = path.join(__dirname, '../..'); +const NPM_CONFIG_PATH = path.join(REPO_ROOT, '.npmrc'); + +// TODO(huntie): Relocate (used by both local and CI scripts) +const VERDACCIO_CONFIG_PATH = `${REPO_ROOT}/.circleci/verdaccio.yml`; +const VERDACCIO_STORAGE_PATH = `${REPO_ROOT}/.circleci/storage`; +const VERDACCIO_SERVER_URL = 'http://localhost:4873'; + +/** + * Configure and run a local Verdaccio server. This is an npm proxy that can be + * used with `npm publish` and `npm install`, configured in + * `.circleci/verdaccio.yml`. + */ +function setupVerdaccio() /*: number */ { + const {host} = new URL(VERDACCIO_SERVER_URL); + + // NOTE: Reading from/writing to an .npmrc in a workspaces project root is + // invalid from npm 9.x. Keyed config, such as `--registry`, should be + // specified in env vars or command invocations instead. + // See https://github.com/npm/cli/issues/6099 + fs.writeFileSync(NPM_CONFIG_PATH, `//${host}/:_authToken=secretToken\n`); const verdaccioProcess = spawn( 'npx', - ['verdaccio@5.16.3', '--config', verdaccioConfigPath], - {env: {...process.env, VERDACCIO_STORAGE_PATH: verdaccioStoragePath}}, + ['verdaccio@5.16.3', '--config', VERDACCIO_CONFIG_PATH], + {env: {...process.env, VERDACCIO_STORAGE_PATH}}, ); - execSync('npx wait-on@6.0.1 http://localhost:4873'); - execSync('npm set registry http://localhost:4873'); + execSync(`npx wait-on@6.0.1 ${VERDACCIO_SERVER_URL}`); return verdaccioProcess.pid; }