Skip to content

Commit

Permalink
Merge pull request #166 from llllvvuu/fix/build_arg_first
Browse files Browse the repository at this point in the history
fix: error TS6369: Option '--build' must be the first command line argument.
  • Loading branch information
gilamran authored Mar 27, 2024
2 parents 108d6ed + f683e93 commit de62974
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/lib/args-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ export function extractArgs(inputArgs: string[]) {
} else {
compiler = require.resolve(compiler, { paths: [process.cwd()] });
}
if (signalEmittedFiles || requestedToListEmittedFiles) {
if (args[0] === '--build' || args[0] === '-b') {
// TS6369: Option '--build' must be the first command line argument.
args.splice(1, 0, '--listEmittedFiles');
} else {
args.unshift('--listEmittedFiles');
}
}

return {
onFirstSuccessCommand,
Expand Down
1 change: 0 additions & 1 deletion src/lib/tsc-watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ function spawnTsc({ maxNodeMem, requestedToListEmittedFiles, signalEmittedFiles
const nodeArgs = [
...((maxNodeMem) ? [`--max_old_space_size=${maxNodeMem}`] : []),
tscBin,
...((signalEmittedFiles || requestedToListEmittedFiles) ? ['--listEmittedFiles'] : []),
...args
];

Expand Down
15 changes: 15 additions & 0 deletions src/test/args-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ describe('Args Manager', () => {
expect(args.indexOf('--watch')).toBe(3);
});

it('Should not insert args before --build (TS6369)', () => {
const { args } = extractArgs([
'node',
'tsc-watch.js',
'--signalEmittedFiles',
'--build',
'1.tsconfig.conf',
'2.tsconfig.conf',
]);
expect(args.indexOf('--build')).toBe(0);
expect(args.indexOf('--listEmittedFiles')).toBe(1);
})

it('Should not re-add watch', () => {
expect(
extractArgs(['node', 'tsc-watch.js', '-w', '1.ts']).args.indexOf('-w'),
Expand Down Expand Up @@ -118,11 +131,13 @@ describe('Args Manager', () => {
it('Should return the signalEmittedFiles', () => {
expect(extractArgs(['node', 'tsc-watch.js', '1.ts']).signalEmittedFiles).toBe(false);
expect(extractArgs(['node', 'tsc-watch.js', '--signalEmittedFiles', '1.ts']).signalEmittedFiles).toBe(true);
expect(extractArgs(['node', 'tsc-watch.js', '--signalEmittedFiles', '1.ts']).args.includes('--listEmittedFiles')).toBe(true);
});

it('Should return requestedToListEmittedFiles when tsc native listEmittedFiles is set', () => {
expect(extractArgs(['node', 'tsc-watch.js', '1.ts']).requestedToListEmittedFiles).toBe(false);
expect(extractArgs(['node', 'tsc-watch.js', '--listEmittedFiles', '1.ts']).requestedToListEmittedFiles).toBe(true);
expect(extractArgs(['node', 'tsc-watch.js', '--listEmittedFiles', '1.ts']).args.includes('--listEmittedFiles')).toBe(true);
});

it('Should return the compiler', () => {
Expand Down

0 comments on commit de62974

Please sign in to comment.