Skip to content

Commit e10d74c

Browse files
andrewbranchtypescript-bot
authored andcommitted
Deprioritize declaration emit paths from baseUrl containing node_modules (#57145)
1 parent 80ebb9d commit e10d74c

File tree

3 files changed

+130
-1
lines changed

3 files changed

+130
-1
lines changed

src/compiler/moduleSpecifiers.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,16 @@ function computeModuleSpecifiers(
437437
redirectPathsSpecifiers = append(redirectPathsSpecifiers, local);
438438
}
439439
else if (pathIsBareSpecifier(local)) {
440-
pathsSpecifiers = append(pathsSpecifiers, local);
440+
if (pathContainsNodeModules(local)) {
441+
// We could be in this branch due to inappropriate use of `baseUrl`, not intentional `paths`
442+
// usage. It's impossible to reason about where to prioritize baseUrl-generated module
443+
// specifiers, but if they contain `/node_modules/`, they're going to trigger a portability
444+
// error, so *at least* don't prioritize those.
445+
relativeSpecifiers = append(relativeSpecifiers, local);
446+
}
447+
else {
448+
pathsSpecifiers = append(pathsSpecifiers, local);
449+
}
441450
}
442451
else if (forAutoImport || !importedFileIsInNodeModules || modulePath.isInNodeModules) {
443452
// Why this extra conditional, not just an `else`? If some path to the file contained
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//// [tests/cases/compiler/declarationEmitMonorepoBaseUrl.ts] ////
2+
3+
//// [package.json]
4+
{
5+
"name": "@babel/parser",
6+
"version": "7.23.6",
7+
"main": "./lib/index.js",
8+
"types": "./typings/babel-parser.d.ts"
9+
}
10+
11+
//// [babel-parser.d.ts]
12+
export declare function createPlugin(): PluginConfig;
13+
export declare class PluginConfig {}
14+
15+
//// [package.json]
16+
{
17+
"name": "@vue/compiler-core",
18+
"version": "3.0.0",
19+
"main": "./src/index.ts",
20+
"dependencies": {
21+
"@babel/parser": "^7.0.0"
22+
}
23+
}
24+
25+
//// [package.json]
26+
{
27+
"name": "@vue/compiler-sfc",
28+
"version": "3.0.0",
29+
"main": "./src/index.ts",
30+
"dependencies": {
31+
"@babel/parser": "^7.0.0",
32+
"@vue/compiler-core": "^3.0.0"
33+
}
34+
}
35+
36+
//// [index.ts]
37+
import { PluginConfig } from "@babel/parser";
38+
39+
//// [index.ts]
40+
import { createPlugin } from "@babel/parser";
41+
export function resolveParserPlugins() {
42+
return [createPlugin()];
43+
}
44+
45+
46+
//// [index.js]
47+
"use strict";
48+
Object.defineProperty(exports, "__esModule", { value: true });
49+
//// [index.js]
50+
"use strict";
51+
Object.defineProperty(exports, "__esModule", { value: true });
52+
exports.resolveParserPlugins = void 0;
53+
const parser_1 = require("@babel/parser");
54+
function resolveParserPlugins() {
55+
return [(0, parser_1.createPlugin)()];
56+
}
57+
exports.resolveParserPlugins = resolveParserPlugins;
58+
59+
60+
//// [index.d.ts]
61+
export {};
62+
//// [index.d.ts]
63+
export declare function resolveParserPlugins(): import("@babel/parser").PluginConfig[];
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// @noTypesAndSymbols: true
2+
3+
// @Filename: /tsconfig.json
4+
{
5+
"compilerOptions": {
6+
"module": "nodenext",
7+
"declaration": true,
8+
"outDir": "temp",
9+
"baseUrl": "."
10+
}
11+
}
12+
13+
// @Filename: /node_modules/.pnpm/@[email protected]/node_modules/@babel/parser/package.json
14+
{
15+
"name": "@babel/parser",
16+
"version": "7.23.6",
17+
"main": "./lib/index.js",
18+
"types": "./typings/babel-parser.d.ts"
19+
}
20+
21+
// @Filename: /node_modules/.pnpm/@[email protected]/node_modules/@babel/parser/typings/babel-parser.d.ts
22+
export declare function createPlugin(): PluginConfig;
23+
export declare class PluginConfig {}
24+
25+
// @Filename: /packages/compiler-core/package.json
26+
{
27+
"name": "@vue/compiler-core",
28+
"version": "3.0.0",
29+
"main": "./src/index.ts",
30+
"dependencies": {
31+
"@babel/parser": "^7.0.0"
32+
}
33+
}
34+
35+
// @Filename: /packages/compiler-core/src/index.ts
36+
import { PluginConfig } from "@babel/parser";
37+
38+
// @Filename: /packages/compiler-sfc/package.json
39+
{
40+
"name": "@vue/compiler-sfc",
41+
"version": "3.0.0",
42+
"main": "./src/index.ts",
43+
"dependencies": {
44+
"@babel/parser": "^7.0.0",
45+
"@vue/compiler-core": "^3.0.0"
46+
}
47+
}
48+
49+
// @Filename: /packages/compiler-sfc/src/index.ts
50+
import { createPlugin } from "@babel/parser";
51+
export function resolveParserPlugins() {
52+
return [createPlugin()];
53+
}
54+
55+
// @link: /node_modules/.pnpm/@[email protected]/node_modules/@babel/parser -> /node_modules/@babel/parser
56+
// @link: /node_modules/.pnpm/@[email protected]/node_modules/@babel/parser -> /packages/compiler-core/node_modules/@babel/parser
57+
// @link: /node_modules/.pnpm/@[email protected]/node_modules/@babel/parser -> /packages/compiler-sfc/node_modules/@babel/parser

0 commit comments

Comments
 (0)