Skip to content

Commit

Permalink
Fix caching issue with Verdaccio
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Jun 26, 2024
1 parent ea5690e commit 230331f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ test-results
/bench
.verdaccio-cache
.next
/.npmrc

# Yarn stuff
/**/.yarn/*
Expand Down
34 changes: 15 additions & 19 deletions scripts/run-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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([
Expand Down Expand Up @@ -108,19 +111,6 @@ const publish = async (packages: { name: string; location: string }[], url: stri
);
};

const addUser = (url: string) =>
new Promise<void>((res, rej) => {
logger.log(`👤 add temp user to verdaccio`);

exec(`npx npm-cli-adduser -r "${url}" -a -u user -p password -e [email protected]`, (e) => {
if (e) {
rej(e);
} else {
res();
}
});
});

const run = async () => {
const verdaccioUrl = `http://localhost:6001`;

Expand All @@ -146,25 +136,31 @@ 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', '[email protected]', '-r', verdaccioUrl],
{
cwd: root,
}
);

logger.log(`📦 found ${packages.length} storybook packages at version ${chalk.blue(version)}`);

if (program.publish) {
await publish(packages, verdaccioUrl);
}

await execa('npx', ['rimraf', '.npmrc'], { cwd: root });

if (!program.open) {
verdaccioServer.close();
}
};

run().catch((e) => {
logger.error(e);
execaSync('npx', ['rimraf', '.npmrc'], { cwd: root });
process.exit(1);
});

0 comments on commit 230331f

Please sign in to comment.