|
| 1 | +import { startLocalRegistry } from '@nx/js/plugins/jest/local-registry'; |
1 | 2 | import { join } from 'path';
|
2 |
| -import { ChildProcess, exec, fork } from 'child_process'; |
| 3 | +import { exec } from 'child_process'; |
3 | 4 | import { tmpdir } from 'tmp';
|
4 | 5 | import { existsSync } from 'fs-extra';
|
5 | 6 | import { Config } from '@jest/types';
|
6 | 7 |
|
7 | 8 | export default async function (globalConfig: Config.ConfigGlobals) {
|
8 |
| - const isVerbose = |
9 |
| - process.env.NX_VERBOSE_LOGGING === 'true' || globalConfig.verbose; |
| 9 | + const isVerbose: boolean = |
| 10 | + process.env.NX_VERBOSE_LOGGING === 'true' || !!globalConfig.verbose; |
10 | 11 | const storageLocation = join(
|
11 | 12 | tmpdir,
|
12 | 13 | 'local-registry/storage',
|
13 | 14 | process.env.NX_TASK_TARGET_PROJECT ?? ''
|
14 | 15 | );
|
15 |
| - global.nxLocalRegistryProcess = await new Promise<ChildProcess>( |
16 |
| - (resolve, reject) => { |
17 |
| - const childProcess = fork( |
18 |
| - require.resolve(`nx`), |
19 |
| - `local-registry @nx/nx-source --config scripts/local-registry/config.yml --location none --storage ${storageLocation} --clear ${ |
20 |
| - process.env.NX_E2E_SKIP_BUILD_CLEANUP !== 'true' |
21 |
| - }`.split(' '), |
22 |
| - { stdio: 'pipe' } |
23 |
| - ); |
24 |
| - |
25 |
| - const listener = (data) => { |
26 |
| - if (data.toString().includes('http://localhost:')) { |
27 |
| - const port = parseInt( |
28 |
| - data.toString().match(/localhost:(?<port>\d+)/)?.groups?.port |
29 |
| - ); |
30 |
| - console.log('Local registry started on port ' + port); |
31 |
| - |
32 |
| - const registry = `http://localhost:${port}`; |
33 |
| - process.env.npm_config_registry = registry; |
34 |
| - process.env.YARN_REGISTRY = registry; |
35 |
| - console.log('Set npm and yarn config registry to ' + registry); |
36 |
| - |
37 |
| - resolve(childProcess); |
38 |
| - childProcess.stdout?.off('data', listener); |
39 |
| - } |
40 |
| - }; |
41 |
| - childProcess?.stdout?.on('data', listener); |
42 |
| - childProcess?.stderr?.on('data', (data) => { |
43 |
| - process.stderr.write(data); |
44 |
| - }); |
45 |
| - childProcess.on('error', (err) => { |
46 |
| - console.log('local registry error', err); |
47 |
| - reject(err); |
48 |
| - }); |
49 |
| - childProcess.on('exit', (code) => { |
50 |
| - console.log('local registry exit', code); |
51 |
| - reject(code); |
52 |
| - }); |
53 |
| - } |
54 |
| - ); |
| 16 | + global.e2eTeardown = await startLocalRegistry({ |
| 17 | + localRegistryTarget: '@nx/nx-source:local-registry', |
| 18 | + verbose: isVerbose, |
| 19 | + storage: storageLocation, |
| 20 | + }); |
55 | 21 |
|
56 | 22 | if (
|
57 | 23 | process.env.NX_E2E_SKIP_BUILD_CLEANUP !== 'true' ||
|
58 | 24 | !existsSync('./build')
|
59 | 25 | ) {
|
60 | 26 | console.log('Publishing packages to local registry');
|
61 | 27 | await new Promise<void>((res, rej) => {
|
62 |
| - const publishProcess = exec('pnpm nx-release --local major'); |
| 28 | + const publishProcess = exec('pnpm nx-release --local major', { |
| 29 | + env: process.env, |
| 30 | + }); |
63 | 31 | let logs = Buffer.from('');
|
64 | 32 | if (isVerbose) {
|
65 | 33 | publishProcess?.stdout?.pipe(process.stdout);
|
|
0 commit comments