Skip to content

Commit 07572df

Browse files
committed
chore(repo): remove populate-storage scripts, consolidate into nx-release
Remove the now-redundant populate-storage.js and run-populate-storage.mjs scripts. The release logic is inlined directly in global-setup.ts, and the populate-local-registry-storage task is simplified to an orchestration point that delegates to nx-release via dependsOn. When running e2e tests outside of Nx (e.g. Jest directly), global-setup now auto-starts verdaccio if it's not already running.
1 parent 0d2d7cb commit 07572df

File tree

5 files changed

+83
-119
lines changed

5 files changed

+83
-119
lines changed

e2e/utils/global-setup.ts

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { Config } from '@jest/types';
22
import { existsSync, removeSync } from 'fs-extra';
33
import * as isCI from 'is-ci';
4-
import { exec, execSync } from 'node:child_process';
4+
import { ChildProcess, exec, execSync, spawn } from 'node:child_process';
55
import { join } from 'node:path';
66
import { registerTsConfigPaths } from '../../packages/nx/src/plugins/js/utils/register';
7-
import { runLocalRelease } from '../../scripts/local-registry/populate-storage';
87

98
export default async function (globalConfig: Config.ConfigGlobals) {
109
try {
@@ -25,14 +24,23 @@ export default async function (globalConfig: Config.ConfigGlobals) {
2524
const registry = `http://${listenAddress}:${port}`;
2625
const authToken = 'secretVerdaccioToken';
2726

28-
while (true) {
29-
await new Promise((resolve) => setTimeout(resolve, 250));
30-
try {
31-
await assertLocalRegistryIsRunning(registry);
32-
break;
33-
} catch {
34-
console.log(`Waiting for Local registry to start on ${registry}...`);
35-
}
27+
// When running outside of Nx (e.g. Jest directly), start verdaccio ourselves
28+
let verdaccioProcess: ChildProcess | undefined;
29+
if (requiresLocalRelease && !(await isLocalRegistryRunning(registry))) {
30+
console.log(
31+
`Local registry not detected at ${registry}, starting verdaccio...`
32+
);
33+
verdaccioProcess = spawn(
34+
'npx',
35+
[
36+
'verdaccio',
37+
'--config',
38+
'.verdaccio/config.yml',
39+
'--listen',
40+
`${listenAddress}:${port}`,
41+
],
42+
{ stdio: 'ignore', detached: true }
43+
);
3644
}
3745

3846
process.env.npm_config_registry = registry;
@@ -54,6 +62,11 @@ export default async function (globalConfig: Config.ConfigGlobals) {
5462
global.e2eTeardown = () => {
5563
// Clean up environment variable instead of npm config command
5664
delete process.env[`npm_config_//${listenAddress}:${port}/:_authToken`];
65+
// Kill verdaccio if we started it
66+
if (verdaccioProcess) {
67+
verdaccioProcess.kill();
68+
verdaccioProcess = undefined;
69+
}
5770
};
5871

5972
/**
@@ -77,8 +90,26 @@ export default async function (globalConfig: Config.ConfigGlobals) {
7790
if (requiresLocalRelease) {
7891
console.log('Publishing packages to local registry');
7992
const publishVersion = process.env.PUBLISHED_VERSION ?? 'major';
80-
// Always show full release logs on CI, they should only happen once via e2e-ci
81-
await runLocalRelease(publishVersion, isCI || isVerbose);
93+
const verbose = isCI || isVerbose;
94+
const releaseCommand = `pnpm nx-release --local ${publishVersion}`;
95+
console.log(`> ${releaseCommand}`);
96+
await new Promise<void>((resolve, reject) => {
97+
const child = exec(releaseCommand, {
98+
maxBuffer: 1024 * 1000000,
99+
windowsHide: false,
100+
});
101+
if (verbose) {
102+
child.stdout?.pipe(process.stdout);
103+
child.stderr?.pipe(process.stderr);
104+
}
105+
child.on('exit', (code) => {
106+
if (code === 0) {
107+
resolve();
108+
} else {
109+
reject(new Error(`Local release failed with exit code ${code}`));
110+
}
111+
});
112+
});
82113
}
83114
}
84115
} catch (err) {
@@ -112,9 +143,11 @@ function getPublishedVersion(): Promise<string | undefined> {
112143
});
113144
}
114145

115-
async function assertLocalRegistryIsRunning(url) {
116-
const response = await fetch(url);
117-
if (!response.ok) {
118-
throw new Error(`HTTP error! status: ${response.status}`);
146+
async function isLocalRegistryRunning(url: string): Promise<boolean> {
147+
try {
148+
const response = await fetch(url);
149+
return response.ok;
150+
} catch {
151+
return false;
119152
}
120153
}

project.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,10 @@
2222
"input": "production",
2323
"projects": ["tag:maven:dev.nx.maven"]
2424
},
25-
"{workspaceRoot}/scripts/local-registry",
2625
"native"
2726
],
28-
"dependsOn": [
29-
"local-registry",
30-
{
31-
"target": "build",
32-
"projects": ["tag:npm:public"]
33-
}
34-
],
35-
"command": "node ./scripts/local-registry/run-populate-storage.mjs",
27+
"dependsOn": ["local-registry", "nx-release"],
28+
"command": "echo 'Registry storage populated via nx-release dependency'",
3629
"outputs": ["{workspaceRoot}/dist/local-registry/storage"]
3730
},
3831
"nx-release": {

scripts/local-registry/populate-storage.js

Lines changed: 0 additions & 79 deletions
This file was deleted.

scripts/local-registry/run-populate-storage.mjs

Lines changed: 0 additions & 11 deletions
This file was deleted.

scripts/nx-release.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ const VALID_AUTHORS_FOR_LATEST = [
218218

219219
hackFixForDevkitPeerDependencies();
220220

221+
if (options.local) {
222+
await waitForLocalRegistry();
223+
}
224+
221225
// Run with dynamic output-style so that we have more minimal logs by default but still always see errors
222226
let publishCommand = `pnpm nx release publish --registry=${getRegistry()} --tag=${distTag} --output-style=dynamic --parallel=8`;
223227
if (options.dryRun) {
@@ -400,10 +404,6 @@ function parseArgs() {
400404
'Registry is still set to localhost! Run "pnpm local-registry disable" or pass --force'
401405
);
402406
}
403-
} else {
404-
if (!args.force && !registryIsLocalhost) {
405-
throw new Error('--local was passed and registry is not localhost');
406-
}
407407
}
408408

409409
return true;
@@ -476,6 +476,34 @@ function determineDistTag(
476476
return distTag;
477477
}
478478

479+
function waitForLocalRegistry(): Promise<void> {
480+
const registryUrl = getRegistry().toString();
481+
console.log(`Waiting for local registry at ${registryUrl}...`);
482+
return new Promise<void>((resolve, reject) => {
483+
const timeout = setTimeout(() => {
484+
clearInterval(interval);
485+
reject(
486+
new Error(
487+
`Local registry at ${registryUrl} did not become available within 60 seconds`
488+
)
489+
);
490+
}, 60_000);
491+
const interval = setInterval(async () => {
492+
try {
493+
const response = await fetch(registryUrl);
494+
if (response.ok) {
495+
clearInterval(interval);
496+
clearTimeout(timeout);
497+
console.log('Local registry is ready.');
498+
resolve();
499+
}
500+
} catch {
501+
// Registry not up yet
502+
}
503+
}, 50);
504+
});
505+
}
506+
479507
//TODO(@Coly010): Remove this after fixing up the release peer dep handling
480508
function hackFixForDevkitPeerDependencies() {
481509
const { readFileSync, writeFileSync } = require('fs');

0 commit comments

Comments
 (0)