Skip to content

Commit

Permalink
build: update E2E setup to use NPM 10 to publish packages
Browse files Browse the repository at this point in the history
This commit updates the e2e setup to use the latest version of NPM to publish packages.
  • Loading branch information
alan-agius4 committed Jun 12, 2024
1 parent 34f2a12 commit 8d256b0
Show file tree
Hide file tree
Showing 5 changed files with 420 additions and 1,081 deletions.
1 change: 1 addition & 0 deletions .github/dependency-review-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ vulnerability_check: false
allow_licenses:
- '0BSD'
- 'Apache-2.0'
- 'Artistic-2.0'
- 'BlueOak-1.0.0'
- 'BSD-2-Clause'
- 'BSD-3-Clause'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
"mini-css-extract-plugin": "2.9.0",
"mrmime": "2.0.0",
"ng-packagr": "18.0.0",
"npm": "^8.11.0",
"npm": "^10.8.1",
"npm-package-arg": "11.0.2",
"open": "10.1.0",
"ora": "5.4.1",
Expand Down
29 changes: 14 additions & 15 deletions tests/legacy-cli/e2e/setup/010-local-publish.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { writeFile } from 'node:fs/promises';
import { join } from 'node:path/posix';
import { getGlobalVariable } from '../utils/env';
import { PkgInfo } from '../utils/packages';
import { globalNpm, extractNpmEnv } from '../utils/process';
Expand All @@ -6,25 +8,22 @@ import { isPrereleaseCli } from '../utils/project';
export default async function () {
const testRegistry: string = getGlobalVariable('package-registry');
const packageTars: PkgInfo[] = Object.values(getGlobalVariable('package-tars'));
const npmrc = join(getGlobalVariable('tmp-root'), '.npmrc-publish');
await writeFile(
npmrc,
`
--registry=${testRegistry}
${testRegistry.replace(/^https?:/, '')}/:_authToken=fake-secret
`,
);

// Publish packages specified with --package
await Promise.all(
packageTars.map(({ path: p }) =>
globalNpm(
[
'publish',
`--registry=${testRegistry}`,
'--tag',
isPrereleaseCli() ? 'next' : 'latest',
p,
],
{
...extractNpmEnv(),
// Also set an auth token value for the local test registry which is required by npm 7+
// even though it is never actually used.
'NPM_CONFIG__AUTH': 'e2e-testing',
},
),
globalNpm(['publish', '--tag', isPrereleaseCli() ? 'next' : 'latest', p], {
...extractNpmEnv(),
'NPM_CONFIG_USERCONFIG': npmrc,
}),
),
);
}
36 changes: 24 additions & 12 deletions tests/legacy-cli/e2e/utils/registry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { spawn } from 'child_process';
import { join } from 'path';
import { ChildProcess, fork } from 'node:child_process';
import { on } from 'node:events';
import { join } from 'node:path';
import { getGlobalVariable } from './env';
import { writeFile, readFile } from './fs';
import { mktempd } from './utils';
Expand All @@ -8,7 +9,7 @@ export async function createNpmRegistry(
port: number,
httpsPort: number,
withAuthentication = false,
) {
): Promise<ChildProcess> {
// Setup local package registry
const registryPath = await mktempd('angular-cli-e2e-registry-');

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

return spawn(
process.execPath,
[require.resolve('verdaccio/bin/verdaccio'), '-c', './verdaccio.yaml'],
{
cwd: registryPath,
stdio: 'inherit',
},
);
const verdaccioServer = fork(require.resolve('verdaccio/bin/verdaccio'), ['-c', configPath]);
for await (const events of on(verdaccioServer, 'message', {
signal: AbortSignal.timeout(30_000),
})) {
if (
events.some(
(event: unknown) =>
event &&
typeof event === 'object' &&
'verdaccio_started' in event &&
event.verdaccio_started,
)
) {
break;
}
}

return verdaccioServer;
}

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

0 comments on commit 8d256b0

Please sign in to comment.