Skip to content

Commit 8d256b0

Browse files
committed
build: update E2E setup to use NPM 10 to publish packages
This commit updates the e2e setup to use the latest version of NPM to publish packages.
1 parent 34f2a12 commit 8d256b0

File tree

5 files changed

+420
-1081
lines changed

5 files changed

+420
-1081
lines changed

.github/dependency-review-config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ vulnerability_check: false
22
allow_licenses:
33
- '0BSD'
44
- 'Apache-2.0'
5+
- 'Artistic-2.0'
56
- 'BlueOak-1.0.0'
67
- 'BSD-2-Clause'
78
- 'BSD-3-Clause'

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
"mini-css-extract-plugin": "2.9.0",
165165
"mrmime": "2.0.0",
166166
"ng-packagr": "18.0.0",
167-
"npm": "^8.11.0",
167+
"npm": "^10.8.1",
168168
"npm-package-arg": "11.0.2",
169169
"open": "10.1.0",
170170
"ora": "5.4.1",
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { writeFile } from 'node:fs/promises';
2+
import { join } from 'node:path/posix';
13
import { getGlobalVariable } from '../utils/env';
24
import { PkgInfo } from '../utils/packages';
35
import { globalNpm, extractNpmEnv } from '../utils/process';
@@ -6,25 +8,22 @@ import { isPrereleaseCli } from '../utils/project';
68
export default async function () {
79
const testRegistry: string = getGlobalVariable('package-registry');
810
const packageTars: PkgInfo[] = Object.values(getGlobalVariable('package-tars'));
11+
const npmrc = join(getGlobalVariable('tmp-root'), '.npmrc-publish');
12+
await writeFile(
13+
npmrc,
14+
`
15+
--registry=${testRegistry}
16+
${testRegistry.replace(/^https?:/, '')}/:_authToken=fake-secret
17+
`,
18+
);
919

1020
// Publish packages specified with --package
1121
await Promise.all(
1222
packageTars.map(({ path: p }) =>
13-
globalNpm(
14-
[
15-
'publish',
16-
`--registry=${testRegistry}`,
17-
'--tag',
18-
isPrereleaseCli() ? 'next' : 'latest',
19-
p,
20-
],
21-
{
22-
...extractNpmEnv(),
23-
// Also set an auth token value for the local test registry which is required by npm 7+
24-
// even though it is never actually used.
25-
'NPM_CONFIG__AUTH': 'e2e-testing',
26-
},
27-
),
23+
globalNpm(['publish', '--tag', isPrereleaseCli() ? 'next' : 'latest', p], {
24+
...extractNpmEnv(),
25+
'NPM_CONFIG_USERCONFIG': npmrc,
26+
}),
2827
),
2928
);
3029
}

tests/legacy-cli/e2e/utils/registry.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { spawn } from 'child_process';
2-
import { join } from 'path';
1+
import { ChildProcess, fork } from 'node:child_process';
2+
import { on } from 'node:events';
3+
import { join } from 'node:path';
34
import { getGlobalVariable } from './env';
45
import { writeFile, readFile } from './fs';
56
import { mktempd } from './utils';
@@ -8,7 +9,7 @@ export async function createNpmRegistry(
89
port: number,
910
httpsPort: number,
1011
withAuthentication = false,
11-
) {
12+
): Promise<ChildProcess> {
1213
// Setup local package registry
1314
const registryPath = await mktempd('angular-cli-e2e-registry-');
1415

@@ -17,16 +18,27 @@ export async function createNpmRegistry(
1718
);
1819
configContent = configContent.replace(/\$\{HTTP_PORT\}/g, String(port));
1920
configContent = configContent.replace(/\$\{HTTPS_PORT\}/g, String(httpsPort));
20-
await writeFile(join(registryPath, 'verdaccio.yaml'), configContent);
21+
const configPath = join(registryPath, 'verdaccio.yaml');
22+
await writeFile(configPath, configContent);
2123

22-
return spawn(
23-
process.execPath,
24-
[require.resolve('verdaccio/bin/verdaccio'), '-c', './verdaccio.yaml'],
25-
{
26-
cwd: registryPath,
27-
stdio: 'inherit',
28-
},
29-
);
24+
const verdaccioServer = fork(require.resolve('verdaccio/bin/verdaccio'), ['-c', configPath]);
25+
for await (const events of on(verdaccioServer, 'message', {
26+
signal: AbortSignal.timeout(30_000),
27+
})) {
28+
if (
29+
events.some(
30+
(event: unknown) =>
31+
event &&
32+
typeof event === 'object' &&
33+
'verdaccio_started' in event &&
34+
event.verdaccio_started,
35+
)
36+
) {
37+
break;
38+
}
39+
}
40+
41+
return verdaccioServer;
3042
}
3143

3244
// Token was generated using `echo -n 'testing:s3cret' | openssl base64`.

0 commit comments

Comments
 (0)