Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not throw an error when killing the verdaccio process #7695

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/publish-npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,15 @@ async function main() {
// Build and publish all packages to a local Verdaccio repo for staging.
console.log(
chalk.magenta.bold('~~~ Staging packages locally in Verdaccio ~~~'));
const verdaccio = await runVerdaccio();
const killVerdaccio = await runVerdaccio();
try {
for (const pkg of packages) {
await publish(pkg, VERDACCIO_REGISTRY);
}
} finally {
// Make sure to kill the verdaccio server before exiting even if publish
// throws an error. Otherwise, it blocks the port for the next run.
verdaccio.kill();
killVerdaccio();
}

if (args.dry) {
Expand Down
24 changes: 16 additions & 8 deletions scripts/release-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import * as readline from 'readline';
import * as shell from 'shelljs';
import rimraf from 'rimraf';
import * as path from 'path';
import {ChildProcess, fork} from 'child_process';
import {fork} from 'child_process';

export interface Phase {
// The list of packages that will be updated with this change.
Expand Down Expand Up @@ -615,7 +615,7 @@ export function memoize<I, O>(f: (arg: I) => Promise<O>): (arg: I) => Promise<O>
}
}

export async function runVerdaccio(): Promise<ChildProcess> {
export async function runVerdaccio(): Promise<() => void> {
// Remove the verdaccio package store.
// TODO(mattsoulanille): Move the verdaccio storage and config file here
// once the nightly verdaccio tests are handled by this script.
Expand All @@ -625,7 +625,8 @@ export async function runVerdaccio(): Promise<ChildProcess> {
// messaging works and verdaccio can tell node that it has started.
// https://verdaccio.org/docs/verdaccio-programmatically/#using-fork-from-child_process-module
const verdaccioBin = require.resolve('verdaccio/bin/verdaccio');
const serverProcess = fork(verdaccioBin, ['--config=e2e/scripts/verdaccio.yaml']);
const config = path.join(__dirname, '../e2e/scripts/verdaccio.yaml');
const serverProcess = fork(verdaccioBin, [`--config=${config}`]);
Comment on lines +628 to +629
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More reliable config directory resolution.

const ready = new Promise<void>((resolve, reject) => {
const timeLimitMilliseconds = 30_000;
console.log(`Waiting ${timeLimitMilliseconds / 1000} seconds for ` +
Expand All @@ -647,15 +648,22 @@ export async function runVerdaccio(): Promise<ChildProcess> {
serverProcess.on('error', (err: unknown) => {
throw new Error(`Verdaccio error: ${err}`);
});
serverProcess.on('disconnect', (err: unknown) => {
throw new Error(`Verdaccio disconnected: ${err}`);
});

const onUnexpectedDisconnect = (err: unknown) => {
throw new Error(`Verdaccio process unexpectedly disconnected: ${err}`);
};
serverProcess.on('disconnect', onUnexpectedDisconnect);

const killVerdaccio = () => {
serverProcess.off('disconnect', onUnexpectedDisconnect);
serverProcess.kill();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: };


// Kill verdaccio when node exits.
process.on('exit', () => {serverProcess.kill();});
process.on('exit', killVerdaccio);

await ready;
return serverProcess;
return killVerdaccio;
}

/**
Expand Down