Skip to content

Commit 6dea5b0

Browse files
Merge pull request #28361 from storybookjs/valentin/fix-verdaccio-caching-issues
Build: Fix caching issue with Verdaccio
2 parents ea5690e + 230331f commit 6dea5b0

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ test-results
1414
/bench
1515
.verdaccio-cache
1616
.next
17+
/.npmrc
1718

1819
# Yarn stuff
1920
/**/.yarn/*

scripts/run-registry.ts

+15-19
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { PACKS_DIRECTORY } from './utils/constants';
1212

1313
import { maxConcurrentTasks } from './utils/concurrency';
1414
import { getWorkspaces } from './utils/workspace';
15+
import { execa, execaSync } from 'execa';
1516

1617
program
1718
.option('-O, --open', 'keep process open')
@@ -21,6 +22,8 @@ program.parse(process.argv);
2122

2223
const logger = console;
2324

25+
const root = path.resolve(__dirname, '..');
26+
2427
const startVerdaccio = async () => {
2528
let resolved = false;
2629
return Promise.race([
@@ -108,19 +111,6 @@ const publish = async (packages: { name: string; location: string }[], url: stri
108111
);
109112
};
110113

111-
const addUser = (url: string) =>
112-
new Promise<void>((res, rej) => {
113-
logger.log(`👤 add temp user to verdaccio`);
114-
115-
exec(`npx npm-cli-adduser -r "${url}" -a -u user -p password -e [email protected]`, (e) => {
116-
if (e) {
117-
rej(e);
118-
} else {
119-
res();
120-
}
121-
});
122-
});
123-
124114
const run = async () => {
125115
const verdaccioUrl = `http://localhost:6001`;
126116

@@ -146,25 +136,31 @@ const run = async () => {
146136

147137
logger.log(`🌿 verdaccio running on ${verdaccioUrl}`);
148138

149-
// in some environments you need to add a dummy user. always try to add & catch on failure
150-
try {
151-
await addUser(verdaccioUrl);
152-
} catch (e) {
153-
//
154-
}
139+
logger.log(`👤 add temp user to verdaccio`);
140+
await execa(
141+
'npx',
142+
// creates a .npmrc file in the root directory of the project
143+
['npm-auth-to-token', '-u', 'foo', '-p', 's3cret', '-e', '[email protected]', '-r', verdaccioUrl],
144+
{
145+
cwd: root,
146+
}
147+
);
155148

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

158151
if (program.publish) {
159152
await publish(packages, verdaccioUrl);
160153
}
161154

155+
await execa('npx', ['rimraf', '.npmrc'], { cwd: root });
156+
162157
if (!program.open) {
163158
verdaccioServer.close();
164159
}
165160
};
166161

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

0 commit comments

Comments
 (0)