Skip to content

Commit

Permalink
Merge pull request #19001 from storybookjs/shilman/improve-generate-r…
Browse files Browse the repository at this point in the history
…epros

Build: Improve generate-repros-next
  • Loading branch information
shilman authored Aug 23, 2022
2 parents 78dc04f + 19a76d9 commit 6ec7732
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 27 deletions.
2 changes: 1 addition & 1 deletion scripts/build-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async function run() {
}

selection?.filter(Boolean).forEach(async (v) => {
const commmand = (await readJSON(resolve(v.location, 'package.json'))).scripts.prep;
const commmand = (await readJSON(resolve(v.location, 'package.json'))).scripts.prepare;
const cwd = resolve(__dirname, '..', 'code', v.location);
const sub = require('execa').command(
`${commmand}${watchMode ? ' --watch' : ''}${prodMode ? ' --optimized' : ''}`,
Expand Down
2 changes: 1 addition & 1 deletion scripts/check-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { resolve } = require('path');
const { readJSON } = require('fs-extra');

const getStorybookPackages = async () => {
const workspaceJSON = await readJSON(resolve(__dirname, '..', 'workspace.json'));
const workspaceJSON = await readJSON(resolve(__dirname, '..', 'code', 'workspace.json'));
return Object.entries(workspaceJSON.projects).map(([k, v]) => ({
location: v.root,
name: k,
Expand Down
31 changes: 20 additions & 11 deletions scripts/next-repro-generators/generate-repros.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,11 @@ const sbInit = async (cwd: string) => {
const LOCAL_REGISTRY_URL = 'http://localhost:6001';
const withLocalRegistry = async (packageManager: JsPackageManager, action: () => Promise<void>) => {
const prevUrl = packageManager.getRegistryURL();
let controller: AbortController;
try {
// @ts-ignore
await publish.run();
console.log(`⚙️ Starting local registry: ${LOCAL_REGISTRY_URL}`);
controller = await servePackages({});

console.log(`📦 Configuring local registry: ${LOCAL_REGISTRY_URL}`);
packageManager.setRegistryURL(LOCAL_REGISTRY_URL);
await action();
} finally {
if (controller) {
console.log(`🛑 Stopping local registry: ${LOCAL_REGISTRY_URL}`);
controller.abort();
}
console.log(`📦 Restoring registry: ${prevUrl}`);
packageManager.setRegistryURL(prevUrl);
}
Expand Down Expand Up @@ -115,7 +105,15 @@ const runGenerators = async (

const limit = pLimit(maxConcurrentTasks);

return Promise.all(
let controller: AbortController;
if (localRegistry) {
// @ts-ignore
await publish.run();
console.log(`⚙️ Starting local registry: ${LOCAL_REGISTRY_URL}`);
controller = await servePackages({ debug: true });
}

await Promise.all(
generators.map(({ dirName, name, script }) =>
limit(async () => {
const time = process.hrtime();
Expand Down Expand Up @@ -146,6 +144,17 @@ const runGenerators = async (
})
)
);

if (controller) {
console.log(`🛑 Stopping local registry: ${LOCAL_REGISTRY_URL}`);
controller.abort();
console.log(`✅ Stopped`);
}

// FIXME: Kill dangling processes. For some reason in CI,
// the abort signal gets executed but the child process kill
// does not succeed?!?
process.exit(0);
};

const generate = async ({
Expand Down
2 changes: 2 additions & 0 deletions scripts/next-repro-generators/utils/yarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ interface SetupYarnOptions {
}

export async function setupYarn({ cwd, pnp = false, version = 'classic' }: SetupYarnOptions) {
// force yarn
await runCommand(`touch yarn.lock`, { cwd });
await runCommand(`yarn set version ${version}`, { cwd });
if (version === 'berry' && !pnp) {
await runCommand('yarn config set nodeLinker node-modules', { cwd });
Expand Down
32 changes: 18 additions & 14 deletions scripts/run-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,18 @@ const publish = (packages: { name: string; location: string }[], url: string) =>
);
};

// 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 [email protected]`, (e) => {
// if (e) {
// rej(e);
// } else {
// res();
// }
// });
// });
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 [email protected]`, (e) => {
if (e) {
rej(e);
} else {
res();
}
});
});

const run = async () => {
const port = await freePort(program.port);
Expand Down Expand Up @@ -135,8 +135,12 @@ const run = async () => {

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

// first time running, you might need to enable this
// await addUser(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(`📦 found ${packages.length} storybook packages at version ${chalk.blue(version)}`);

Expand Down

0 comments on commit 6ec7732

Please sign in to comment.