chore(repo): teardown local registry in case of setup error (#23470)

This commit is contained in:
James Henry 2024-05-21 19:05:14 +04:00 committed by GitHub
parent 44429451c8
commit b641852d9c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 49 additions and 34 deletions

View File

@ -2,12 +2,13 @@ import { Config } from '@jest/types';
import { startLocalRegistry } from '@nx/js/plugins/jest/local-registry';
import { existsSync, removeSync } from 'fs-extra';
import * as isCI from 'is-ci';
import { exec, execSync } from 'node:child_process';
import { exec } from 'node:child_process';
import { join } from 'node:path';
import { registerTsConfigPaths } from '../../packages/nx/src/plugins/js/utils/register';
import { runLocalRelease } from '../../scripts/local-registry/populate-storage';
export default async function (globalConfig: Config.ConfigGlobals) {
try {
const isVerbose: boolean =
process.env.NX_VERBOSE_LOGGING === 'true' || !!globalConfig.verbose;
@ -48,6 +49,14 @@ export default async function (globalConfig: Config.ConfigGlobals) {
await runLocalRelease(publishVersion, isCI || isVerbose);
}
}
} catch (err) {
// Clean up registry if possible after setup related errors
if (typeof global.e2eTeardown === 'function') {
global.e2eTeardown();
console.log('Killed local registry process due to an error during setup');
}
throw err;
}
}
function getPublishedVersion(): Promise<string | undefined> {

View File

@ -7,10 +7,11 @@ const {
} = require('nx/src/executors/run-commands/run-commands.impl');
async function populateLocalRegistryStorage() {
let registryTeardown;
try {
const publishVersion = process.env.PUBLISHED_VERSION ?? 'major';
const isVerbose = process.env.NX_VERBOSE_LOGGING === 'true';
const registryTeardown = await startLocalRegistry({
registryTeardown = await startLocalRegistry({
localRegistryTarget: '@nx/nx-source:local-registry',
verbose: isVerbose,
clearStorage: true,
@ -22,6 +23,11 @@ async function populateLocalRegistryStorage() {
registryTeardown();
console.log('Killed local registry process');
} catch (err) {
// Clean up registry if possible after setup related errors
if (typeof registryTeardown === 'function') {
registryTeardown();
console.log('Killed local registry process due to an error during setup');
}
console.error('Error:', err);
process.exit(1);
}