Skip to content

Commit a32f62b

Browse files
committed
Write tests to demonstrate how baseUrl + pathMapping to node_modules behaves
1 parent 62e6e6a commit a32f62b

5 files changed

+72
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [tests/cases/compiler/pathMappingBasedModuleResolution_withExtension_MapedToNodeModules.ts] ////
2+
3+
//// [foobar.js]
4+
module.exports = { a: 10 };
5+
6+
//// [a.ts]
7+
import foobar from "foo/bar/foobar.js";
8+
9+
10+
//// [/bin/node_modules/foo/bar/foobar.js]
11+
module.exports = { a: 10 };
12+
//// [/bin/a.js]
13+
"use strict";
14+
exports.__esModule = true;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
=== /a.ts ===
2+
import foobar from "foo/bar/foobar.js";
3+
>foobar : Symbol(foobar, Decl(a.ts, 0, 6))
4+
5+
=== /node_modules/foo/bar/foobar.js ===
6+
module.exports = { a: 10 };
7+
>module.exports : Symbol("/node_modules/foo/bar/foobar", Decl(foobar.js, 0, 0))
8+
>module : Symbol(export=, Decl(foobar.js, 0, 0))
9+
>exports : Symbol(export=, Decl(foobar.js, 0, 0))
10+
>a : Symbol(a, Decl(foobar.js, 0, 18))
11+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
"======== Resolving module 'foo/bar/foobar.js' from '/a.ts'. ========",
3+
"Module resolution kind is not specified, using 'NodeJs'.",
4+
"'baseUrl' option is set to '/', using this value to resolve non-relative module name 'foo/bar/foobar.js'.",
5+
"'paths' option is specified, looking for a pattern to match module name 'foo/bar/foobar.js'.",
6+
"Module name 'foo/bar/foobar.js', matched pattern '*'.",
7+
"Trying substitution 'node_modules/*', candidate module location: 'node_modules/foo/bar/foobar.js'.",
8+
"File '/node_modules/foo/bar/foobar.js' exist - use it as a name resolution result.",
9+
"======== Module name 'foo/bar/foobar.js' was successfully resolved to '/node_modules/foo/bar/foobar.js'. ========"
10+
]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== /a.ts ===
2+
import foobar from "foo/bar/foobar.js";
3+
>foobar : { a: number; }
4+
5+
=== /node_modules/foo/bar/foobar.js ===
6+
module.exports = { a: 10 };
7+
>module.exports = { a: 10 } : { a: number; }
8+
>module.exports : { a: number; }
9+
>module : { "/node_modules/foo/bar/foobar": { a: number; }; }
10+
>exports : { a: number; }
11+
>{ a: 10 } : { a: number; }
12+
>a : number
13+
>10 : 10
14+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// @noImplicitReferences: true
2+
// @traceResolution: true
3+
// @allowJs: true
4+
// @esModuleInterop: true
5+
// @fullEmitPaths: true
6+
7+
// @Filename: /node_modules/foo/bar/foobar.js
8+
module.exports = { a: 10 };
9+
10+
// @Filename: /a.ts
11+
import foobar from "foo/bar/foobar.js";
12+
13+
// @Filename: /tsconfig.json
14+
{
15+
"compilerOptions": {
16+
"baseUrl": ".",
17+
"paths": {
18+
"*": ["node_modules/*", "src/types"]
19+
},
20+
"allowJs": true,
21+
"outDir": "bin"
22+
}
23+
}

0 commit comments

Comments
 (0)