Skip to content

Commit b6bf39b

Browse files
fix: only error on invalid tsconfig if explicitly passed in (#30)
1 parent 3f42ae3 commit b6bf39b

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

src/utils/tsconfig.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,22 @@ export const loadTsconfig = (
2828
config: parseTsconfig(resolvedConfigPath),
2929
};
3030
} else {
31-
tsconfig = getTsconfig();
31+
try {
32+
tsconfig = getTsconfig();
33+
} catch {
34+
// Not warning here for now because it gets warned twice
35+
// Once by ESM loader and then by CJS loader
36+
// const disableWarning = (
37+
// getFlag('--no-warnings', Boolean)
38+
// || Boolean(process.env.NODE_NO_WARNINGS)
39+
// );
40+
// if (!disableWarning) {
41+
// if (error instanceof Error) {
42+
// console.warn(`(tsx:${process.pid}) [-----] TsconfigWarning:`, error.message);
43+
// }
44+
// }
45+
}
46+
3247
if (!tsconfig) {
3348
return;
3449
}

tests/specs/api.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export default testSuite(({ describe }, node: NodeApis) => {
287287
});
288288

289289
describe('tsconfig', ({ test }) => {
290-
test('should error on unresolvable tsconfig', async () => {
290+
test('should ignore detected unresolvable tsconfig', async () => {
291291
await using fixture = await createFixture({
292292
'tsconfig.json': createTsconfig({
293293
extends: 'doesnt-exist',
@@ -298,14 +298,11 @@ export default testSuite(({ describe }, node: NodeApis) => {
298298
`,
299299
});
300300

301-
const { exitCode, stderr } = await execaNode('register.mjs', [], {
302-
reject: false,
301+
await execaNode('register.mjs', [], {
303302
cwd: fixture.path,
304303
nodePath: node.path,
305304
nodeOptions: [],
306305
});
307-
expect(exitCode).toBe(1);
308-
expect(stderr).toMatch('File \'doesnt-exist\' not found.');
309306
});
310307

311308
test('disable lookup', async () => {

tests/specs/tsconfig.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,19 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
113113
onFinish(async () => await fixture.rm());
114114

115115
describe('detected tsconfig', ({ test }) => {
116+
test('invalid tsconfig should be ignored', async () => {
117+
await using fixture = await createFixture({
118+
'package.json': createPackageJson({ type: packageType }),
119+
'tsconfig.json': createTsconfig({
120+
extends: 'doesnt-exist',
121+
}),
122+
'index.ts': '',
123+
});
124+
125+
const pTsconfig = await tsx(['index.ts'], fixture.path);
126+
expect(pTsconfig.failed).toBe(false);
127+
});
128+
116129
test('tsconfig', async ({ onTestFail }) => {
117130
const pTsconfig = await tsx(['index.tsx'], fixture.path);
118131
onTestFail((error) => {
@@ -126,6 +139,19 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
126139
});
127140

128141
describe('custom tsconfig', ({ test }) => {
142+
test('invalid tsconfig should error', async () => {
143+
await using fixture = await createFixture({
144+
'package.json': createPackageJson({ type: packageType }),
145+
'tsconfig.json': createTsconfig({
146+
extends: 'doesnt-exist',
147+
}),
148+
'index.ts': '',
149+
});
150+
151+
const pTsconfig = await tsx(['--tsconfig', 'tsconfig.json', 'index.ts'], fixture.path);
152+
expect(pTsconfig.failed).toBe(true);
153+
});
154+
129155
test('custom tsconfig', async ({ onTestFail }) => {
130156
const pTsconfigAllowJs = await tsx(['--tsconfig', 'tsconfig-allowJs.json', 'jsx.jsx'], fixture.path);
131157
onTestFail((error) => {

0 commit comments

Comments
 (0)