( port: number, httpsPort: number, withAuthentication = false, )
| 7 | import { existsSync } from 'node:fs'; |
| 8 | |
| 9 | export async function createNpmRegistry( |
| 10 | port: number, |
| 11 | httpsPort: number, |
| 12 | withAuthentication = false, |
| 13 | ): Promise<ChildProcess> { |
| 14 | // Setup local package registry |
| 15 | const registryPath = join(getGlobalVariable('tmp-root'), 'registry'); |
| 16 | if (!existsSync(registryPath)) { |
| 17 | await mkdir(registryPath); |
| 18 | } |
| 19 | |
| 20 | const configFileName = withAuthentication ? 'verdaccio_auth.yaml' : 'verdaccio.yaml'; |
| 21 | let configContent = await readFile(join(__dirname, '../', configFileName)); |
| 22 | configContent = configContent |
| 23 | .replace(/\$\{HTTP_PORT\}/g, String(port)) |
| 24 | .replace(/\$\{HTTPS_PORT\}/g, String(httpsPort)); |
| 25 | const configPath = join(registryPath, configFileName); |
| 26 | |
| 27 | await writeFile(configPath, configContent); |
| 28 | |
| 29 | const verdaccioServer = fork(require.resolve('verdaccio/bin/verdaccio'), ['-c', configPath]); |
| 30 | for await (const events of on(verdaccioServer, 'message', { |
| 31 | signal: AbortSignal.timeout(30_000), |
| 32 | })) { |
| 33 | if ( |
| 34 | events.some( |
| 35 | (event: unknown) => |
| 36 | event && |
| 37 | typeof event === 'object' && |
| 38 | 'verdaccio_started' in event && |
| 39 | event.verdaccio_started, |
| 40 | ) |
| 41 | ) { |
| 42 | break; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | return verdaccioServer; |
| 47 | } |
| 48 | |
| 49 | // Token was generated using `echo -n 'testing:s3cret' | openssl base64`. |
| 50 | const VALID_TOKEN = `dGVzdGluZzpzM2NyZXQ=`; |
no test coverage detected