diff --git a/.gitignore b/.gitignore index f23bfa05951d..cd1be1573a5f 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ test-results /bench .verdaccio-cache .next +/.npmrc # Yarn stuff /**/.yarn/* diff --git a/scripts/run-registry.ts b/scripts/run-registry.ts index 8393dc4f7416..e8d75a83e97c 100755 --- a/scripts/run-registry.ts +++ b/scripts/run-registry.ts @@ -12,6 +12,7 @@ import { PACKS_DIRECTORY } from './utils/constants'; import { maxConcurrentTasks } from './utils/concurrency'; import { getWorkspaces } from './utils/workspace'; +import { execa, execaSync } from 'execa'; program .option('-O, --open', 'keep process open') @@ -21,6 +22,8 @@ program.parse(process.argv); const logger = console; +const root = path.resolve(__dirname, '..'); + const startVerdaccio = async () => { let resolved = false; return Promise.race([ @@ -108,19 +111,6 @@ const publish = async (packages: { name: string; location: string }[], url: stri ); }; -const addUser = (url: string) => - new Promise((res, rej) => { - logger.log(`👤 add temp user to verdaccio`); - - exec(`npx npm-cli-adduser -r "${url}" -a -u user -p password -e user@example.com`, (e) => { - if (e) { - rej(e); - } else { - res(); - } - }); - }); - const run = async () => { const verdaccioUrl = `http://localhost:6001`; @@ -146,12 +136,15 @@ const run = async () => { logger.log(`🌿 verdaccio running on ${verdaccioUrl}`); - // in some environments you need to add a dummy user. always try to add & catch on failure - try { - await addUser(verdaccioUrl); - } catch (e) { - // - } + logger.log(`👤 add temp user to verdaccio`); + await execa( + 'npx', + // creates a .npmrc file in the root directory of the project + ['npm-auth-to-token', '-u', 'foo', '-p', 's3cret', '-e', 'test@test.com', '-r', verdaccioUrl], + { + cwd: root, + } + ); logger.log(`📦 found ${packages.length} storybook packages at version ${chalk.blue(version)}`); @@ -159,6 +152,8 @@ const run = async () => { await publish(packages, verdaccioUrl); } + await execa('npx', ['rimraf', '.npmrc'], { cwd: root }); + if (!program.open) { verdaccioServer.close(); } @@ -166,5 +161,6 @@ const run = async () => { run().catch((e) => { logger.error(e); + execaSync('npx', ['rimraf', '.npmrc'], { cwd: root }); process.exit(1); });