Skip to content

Commit

Permalink
fix: only error on invalid tsconfig if explicitly passed in (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed May 23, 2024
1 parent 3f42ae3 commit b6bf39b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
17 changes: 16 additions & 1 deletion src/utils/tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,22 @@ export const loadTsconfig = (
config: parseTsconfig(resolvedConfigPath),
};
} else {
tsconfig = getTsconfig();
try {
tsconfig = getTsconfig();
} catch {
// Not warning here for now because it gets warned twice
// Once by ESM loader and then by CJS loader
// const disableWarning = (
// getFlag('--no-warnings', Boolean)
// || Boolean(process.env.NODE_NO_WARNINGS)
// );
// if (!disableWarning) {
// if (error instanceof Error) {
// console.warn(`(tsx:${process.pid}) [-----] TsconfigWarning:`, error.message);
// }
// }
}

if (!tsconfig) {
return;
}
Expand Down
7 changes: 2 additions & 5 deletions tests/specs/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export default testSuite(({ describe }, node: NodeApis) => {
});

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

const { exitCode, stderr } = await execaNode('register.mjs', [], {
reject: false,
await execaNode('register.mjs', [], {
cwd: fixture.path,
nodePath: node.path,
nodeOptions: [],
});
expect(exitCode).toBe(1);
expect(stderr).toMatch('File \'doesnt-exist\' not found.');
});

test('disable lookup', async () => {
Expand Down
26 changes: 26 additions & 0 deletions tests/specs/tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
onFinish(async () => await fixture.rm());

describe('detected tsconfig', ({ test }) => {
test('invalid tsconfig should be ignored', async () => {
await using fixture = await createFixture({
'package.json': createPackageJson({ type: packageType }),
'tsconfig.json': createTsconfig({
extends: 'doesnt-exist',
}),
'index.ts': '',
});

const pTsconfig = await tsx(['index.ts'], fixture.path);
expect(pTsconfig.failed).toBe(false);
});

test('tsconfig', async ({ onTestFail }) => {
const pTsconfig = await tsx(['index.tsx'], fixture.path);
onTestFail((error) => {
Expand All @@ -126,6 +139,19 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
});

describe('custom tsconfig', ({ test }) => {
test('invalid tsconfig should error', async () => {
await using fixture = await createFixture({
'package.json': createPackageJson({ type: packageType }),
'tsconfig.json': createTsconfig({
extends: 'doesnt-exist',
}),
'index.ts': '',
});

const pTsconfig = await tsx(['--tsconfig', 'tsconfig.json', 'index.ts'], fixture.path);
expect(pTsconfig.failed).toBe(true);
});

test('custom tsconfig', async ({ onTestFail }) => {
const pTsconfigAllowJs = await tsx(['--tsconfig', 'tsconfig-allowJs.json', 'jsx.jsx'], fixture.path);
onTestFail((error) => {
Expand Down

0 comments on commit b6bf39b

Please sign in to comment.