Skip to content

Commit 733cddf

Browse files
committed
feat: add TsconfigPathsPlugin
1 parent 0947dc3 commit 733cddf

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

.cspell.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434
"zipp",
3535
"zippi",
3636
"zizizi",
37-
"codecov"
37+
"codecov",
38+
"xiaoxiaojx",
39+
"Natsu",
40+
"tsconfigs"
3841
],
3942
"ignorePaths": ["package.json", "yarn.lock", "coverage", "*.log"]
4043
}

test/tsconfig-paths.test.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
const fs = require("fs");
44
const path = require("path");
5+
56
const { ResolverFactory } = require("../");
7+
const CachedInputFileSystem = require("../lib/CachedInputFileSystem");
8+
9+
const fileSystem = new CachedInputFileSystem(fs, 4000);
610

711
const exampleDir = path.resolve(__dirname, "fixtures", "tsconfig", "example");
812
const referenceDir = path.resolve(
@@ -15,11 +19,12 @@ const referenceDir = path.resolve(
1519
describe("TsconfigPathsPlugin", () => {
1620
it("resolves exact mapped path 'foo' via tsconfig option (example)", (done) => {
1721
const resolver = ResolverFactory.createResolver({
18-
fileSystem: fs,
22+
fileSystem,
1923
extensions: [".ts", ".tsx"],
2024
mainFields: ["browser", "main"],
2125
mainFiles: ["index"],
2226
tsconfig: path.join(exampleDir, "tsconfig.json"),
27+
useSyncFileSystemCalls: true,
2328
});
2429

2530
resolver.resolve({}, exampleDir, "foo", {}, (err, result) => {
@@ -34,11 +39,12 @@ describe("TsconfigPathsPlugin", () => {
3439

3540
it("resolves wildcard mapped path 'bar/*' via tsconfig option (example)", (done) => {
3641
const resolver = ResolverFactory.createResolver({
37-
fileSystem: fs,
42+
fileSystem,
3843
extensions: [".ts", ".tsx"],
3944
mainFields: ["browser", "main"],
4045
mainFiles: ["index"],
4146
tsconfig: path.join(exampleDir, "tsconfig.json"),
47+
useSyncFileSystemCalls: true,
4248
});
4349

4450
resolver.resolve({}, exampleDir, "bar/file1", {}, (err, result) => {
@@ -53,11 +59,12 @@ describe("TsconfigPathsPlugin", () => {
5359

5460
it("falls through when no mapping exists (example)", (done) => {
5561
const resolver = ResolverFactory.createResolver({
56-
fileSystem: fs,
62+
fileSystem,
5763
extensions: [".ts", ".tsx"],
5864
mainFields: ["browser", "main"],
5965
mainFiles: ["index"],
6066
tsconfig: path.join(exampleDir, "tsconfig.json"),
67+
useSyncFileSystemCalls: true,
6168
});
6269

6370
resolver.resolve({}, exampleDir, "does-not-exist", {}, (err, result) => {
@@ -69,11 +76,12 @@ describe("TsconfigPathsPlugin", () => {
6976

7077
it("resolves using references from referenceExample project", (done) => {
7178
const resolver = ResolverFactory.createResolver({
72-
fileSystem: fs,
79+
fileSystem,
7380
extensions: [".ts", ".tsx"],
7481
mainFields: ["browser", "main"],
7582
mainFiles: ["index"],
7683
tsconfig: path.join(referenceDir, "tsconfig.json"),
84+
useSyncFileSystemCalls: true,
7785
});
7886

7987
// 'foo' is mapped in referenceExample to src/mapped/bar (within referenceExample)

0 commit comments

Comments
 (0)