|
| 1 | +import { ChildProcess, fork } from 'node:child_process'; |
| 2 | +import { on } from 'node:events'; |
1 | 3 | import { join } from 'node:path'; |
2 | 4 | import { getGlobalVariable } from './env'; |
3 | 5 | import { writeFile, readFile } from './fs'; |
4 | 6 | import { mktempd } from './utils'; |
5 | | -import { runServer as runVerdaccioServer } from 'verdaccio'; |
6 | | -import { setup as setupVerdaccioLogger } from 'verdaccio/build/lib/logger'; |
7 | 7 |
|
8 | 8 | export async function createNpmRegistry( |
9 | 9 | port: number, |
10 | 10 | httpsPort: number, |
11 | 11 | withAuthentication = false, |
12 | | -): Promise<void> { |
| 12 | +): Promise<ChildProcess> { |
13 | 13 | // Setup local package registry |
14 | 14 | const registryPath = await mktempd('angular-cli-e2e-registry-'); |
15 | 15 |
|
16 | 16 | let configContent = await readFile( |
17 | | - join('tests/legacy-cli', withAuthentication ? 'verdaccio_auth.yaml' : 'verdaccio.yaml'), |
| 17 | + join(__dirname, '../', withAuthentication ? 'verdaccio_auth.yaml' : 'verdaccio.yaml'), |
18 | 18 | ); |
19 | 19 | configContent = configContent.replace(/\$\{HTTP_PORT\}/g, String(port)); |
20 | 20 | configContent = configContent.replace(/\$\{HTTPS_PORT\}/g, String(httpsPort)); |
21 | 21 | const configPath = join(registryPath, 'verdaccio.yaml'); |
22 | 22 | await writeFile(configPath, configContent); |
23 | 23 |
|
24 | | - const instancePort = withAuthentication ? httpsPort : port; |
25 | | - |
26 | | - // Verdaccio config `log` section is not respected by the programmatic API. |
27 | | - setupVerdaccioLogger({ |
28 | | - type: 'stdout', |
29 | | - level: 'warn', |
30 | | - format: 'pretty', |
31 | | - }); |
32 | | - |
33 | | - const server = await runVerdaccioServer(configPath); |
34 | | - |
35 | | - await new Promise<void>((resolve) => { |
36 | | - server.listen(instancePort, () => resolve()); |
37 | | - }); |
| 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 | + } |
38 | 40 |
|
39 | | - console.log(`Verdaccio running on: http://localhost:${instancePort}`); |
| 41 | + return verdaccioServer; |
40 | 42 | } |
41 | 43 |
|
42 | 44 | // Token was generated using `echo -n 'testing:s3cret' | openssl base64`. |
|
0 commit comments