|
1 | 1 | import * as path from 'node:path';
|
2 |
| -import {execPromise} from '../../common/util/helpers'; |
| 2 | +import {execFileSync} from 'child_process'; |
3 | 3 | import {getFileName, removeFileIfExists} from '../../common/util/fs';
|
4 | 4 | import {STRINGS} from '../config';
|
5 | 5 |
|
@@ -28,47 +28,63 @@ export const executeCommands = async (manifest: string, cwd: boolean) => {
|
28 | 28 | const sanitizedExecutedManifest = escapeShellArg(executedManifest);
|
29 | 29 |
|
30 | 30 | const ifEnvCommand = [
|
31 |
| - isGlobal ? 'if-env' : 'npm run if-env', |
| 31 | + isGlobal ? 'if-env' : 'npm', |
| 32 | + ...(isGlobal ? [] : ['run', 'if-env']), |
32 | 33 | '--',
|
33 |
| - ...(prefixFlag === '' ? [] : prefixFlag), |
| 34 | + ...(prefixFlag === '' ? [] : [prefixFlag]), |
34 | 35 | '-m',
|
35 | 36 | sanitizedManifest,
|
36 | 37 | ];
|
37 | 38 |
|
38 | 39 | const ifRunCommand = [
|
39 |
| - isGlobal ? 'if-run' : 'npm run if-run', |
| 40 | + isGlobal ? 'if-run' : 'npm', |
| 41 | + ...(isGlobal ? [] : ['run', 'if-run']), |
40 | 42 | '--',
|
41 |
| - ...(prefixFlag === '' ? [] : prefixFlag), |
| 43 | + ...(prefixFlag === '' ? [] : [prefixFlag]), |
42 | 44 | '-m',
|
43 | 45 | sanitizedManifest,
|
44 | 46 | '-o',
|
45 | 47 | sanitizedExecutedManifest,
|
46 | 48 | ];
|
47 | 49 |
|
48 |
| - const ttyCommand = ['node', '-p', "'Boolean(process.stdout.isTTY)'"]; |
| 50 | + const ttyCommand = ['node', '-p', 'Boolean(process.stdout.isTTY)']; |
49 | 51 | const ifDiffCommand = [
|
50 |
| - isGlobal ? 'if-diff' : 'npm run if-diff', |
| 52 | + isGlobal ? 'if-diff' : 'npm', |
| 53 | + ...(isGlobal ? [] : ['run', 'if-diff']), |
51 | 54 | '--',
|
52 |
| - ...(prefixFlag === '' ? [] : prefixFlag), |
| 55 | + ...(prefixFlag === '' ? [] : [prefixFlag]), |
53 | 56 | '-s',
|
54 | 57 | `${sanitizedExecutedManifest}.yaml`,
|
55 | 58 | '-t',
|
56 | 59 | sanitizedManifest,
|
57 | 60 | ];
|
58 | 61 |
|
59 |
| - const fullCommand = [ |
60 |
| - ...ifEnvCommand, |
61 |
| - '&&', |
62 |
| - ...ifRunCommand, |
63 |
| - '&&', |
64 |
| - ...ttyCommand, |
65 |
| - '|', |
66 |
| - ...ifDiffCommand, |
67 |
| - ].join(' '); |
68 |
| - |
69 |
| - // Execute the full command |
70 |
| - await execPromise(fullCommand, { |
| 62 | + execFileSync(ifEnvCommand[0], ifEnvCommand.slice(1), { |
71 | 63 | cwd: process.env.CURRENT_DIR || process.cwd(),
|
| 64 | + shell: true, |
| 65 | + }); |
| 66 | + |
| 67 | + execFileSync(ifRunCommand[0], ifRunCommand.slice(1), { |
| 68 | + cwd: process.env.CURRENT_DIR || process.cwd(), |
| 69 | + }); |
| 70 | + |
| 71 | + execFileSync(ttyCommand[0], ttyCommand.slice(1), { |
| 72 | + cwd: process.env.CURRENT_DIR || process.cwd(), |
| 73 | + }); |
| 74 | + |
| 75 | + const ttyResult = execFileSync(ttyCommand[0], ttyCommand.slice(1), { |
| 76 | + cwd: process.env.CURRENT_DIR || process.cwd(), |
| 77 | + }); |
| 78 | + |
| 79 | + const tty = ttyResult && ttyResult.toString().trim(); |
| 80 | + const fullCommand = `${tty === 'true' ? 'tty |' : ''} ${ifDiffCommand.join( |
| 81 | + ' ' |
| 82 | + )}`; |
| 83 | + |
| 84 | + execFileSync(fullCommand, { |
| 85 | + cwd: process.env.CURRENT_DIR || process.cwd(), |
| 86 | + stdio: 'inherit', |
| 87 | + shell: true, |
72 | 88 | });
|
73 | 89 |
|
74 | 90 | if (!cwd) {
|
|
0 commit comments