Skip to content

Commit 1b2558f

Browse files
fix: ignore ts extension for require in typescript code (#55)
1 parent 86811f7 commit 1b2558f

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

configs/node.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,18 @@ async function getCommonJSConfig() {
155155
checkTypeImports: true,
156156
pattern: {
157157
js: "never",
158+
ts: "never",
158159
},
160+
// Allow to have `ts` extension in `require` for compatibility with Node.js built-in typescript support
161+
pathGroupOverrides: [
162+
{
163+
pattern: "*.ts",
164+
patternOptions: {
165+
matchBase: true,
166+
},
167+
action: "ignore",
168+
},
169+
],
159170
},
160171
],
161172
},

validation/commonjs-package/file.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ const otherMod = require("./other-module.cjs");
55
// eslint-disable-next-line import/extensions
66
const modAgain = require("./my-module.js");
77

8+
require("../typescript-node-support/my-other-code.ts");
9+
require("../typescript-node-support/my-other-code");
10+
// eslint-disable-next-line import/extensions
11+
require("./my-module-1.js");
12+
813
const foo = 1;
914
const bar = 2;
1015

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"use strict";
2+
3+
module.exports.a = 1;
4+
module.exports.b = 2;

validation/dirty-package/file.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import otherMod from "././other-module.cjs";
33

44
const commonJSModule = require("./module-js-common.js");
55

6+
require("../typescript-node-support/my-other-code.ts");
7+
require("../typescript-node-support/my-other-code");
8+
69
const foo = 1;
710
const bar = 2;
811

validation/my-ts-code.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import sum from "./module.js";
22
import { a, b } from "./named-exports.js";
3-
// Should be error by default
43
import otherSum from "./my-module.ts";
54
// eslint-disable-next-line import/extensions
65
import otherSumAgain from "./my-module";

0 commit comments

Comments
 (0)