Skip to content

Commit 0451e23

Browse files
committedNov 11, 2023
Move tsx to separate module + reuse node resolver (fixes #344)
1 parent 08483e8 commit 0451e23

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed
 

Diff for: ‎src/binaries/resolvers/fallback.ts

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const argFilters: ArgResolvers = {
1919
execa: withPositional,
2020
'ts-node': withPositional,
2121
zx: withPositional,
22-
tsx: parsed => parsed._.filter(p => p !== 'watch'),
2322
default: withoutPositional,
2423
};
2524

Diff for: ‎src/binaries/resolvers/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export * as npx from './npx.js';
66
export * as nx from './nx.js';
77
export * as pnpm from './pnpm.js';
88
export * as rollup from './rollup.js';
9+
export * as tsx from './tsx.js';
910
export * as yarn from './yarn.js';

Diff for: ‎src/binaries/resolvers/tsx.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { toBinary } from '../../util/protocols.js';
2+
import { resolve as resolveNode } from './node.js';
3+
import type { Resolver } from '../types.js';
4+
5+
export const resolve: Resolver = (binary, args, options) => {
6+
args = args.map(a => (a === 'watch' ? '--watch' : a));
7+
return [toBinary(binary), ...resolveNode(binary, args, options)];
8+
};

Diff for: ‎test/util/getReferencesFromScripts.test.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,20 @@ test('getReferencesFromScripts (node)', () => {
4444
t('node dist/index.js', []);
4545
t('./script.js', [js]);
4646
t('node --watch ./script.js', [js]);
47+
t('node ./script.js build', [js]);
4748
});
4849

49-
test('getReferencesFromScripts (ts-node/tsx)', () => {
50+
test('getReferencesFromScripts (ts-node)', () => {
5051
t('ts-node --require pkg/register main.ts', ['bin:ts-node', ts, 'pkg']);
52+
t('babel-node --inspect=0.0.0.0 ./main.ts', ['bin:babel-node', ts]);
53+
});
54+
55+
test('getReferencesFromScripts (tsx)', () => {
5156
t('tsx ./main.ts', ['bin:tsx', ts]);
5257
t('tsx watch ./main.ts', ['bin:tsx', ts]);
5358
t('node --loader tsx ./main.ts', [ts, 'tsx']);
54-
t('npx tsx main', ['bin:tsx', ts]);
55-
t('babel-node --inspect=0.0.0.0 ./main.ts', ['bin:babel-node', ts]);
59+
t('tsx main', ['bin:tsx', ts]);
60+
t('tsx ./main.ts build', ['bin:tsx', ts]);
5661
});
5762

5863
test('getReferencesFromScripts (--require)', () => {
@@ -121,6 +126,9 @@ test('getReferencesFromScripts (npx)', () => {
121126
t("npx --package=foo -c 'curl --output /dev/null'", ['foo', 'bin:curl']);
122127
t('npx swagger-typescript-api -p http://localhost:3030/swagger.v1.json', ['bin:swagger-typescript-api']);
123128
t('npx swagger-typescript-api -- -p http://localhost:3030/swagger.v1.json', ['bin:swagger-typescript-api']);
129+
t('npx tsx main', ['bin:tsx', ts]);
130+
t('npx tsx ./main.ts build', ['bin:tsx', ts]);
131+
t('npx tsx ./main.ts -- build', ['bin:tsx', ts]);
124132
});
125133

126134
test('getReferencesFromScripts (pnpm)', () => {

0 commit comments

Comments
 (0)
Please sign in to comment.