Skip to content

Deprioritize declaration emit paths from baseUrl containing node_modules #57145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/compiler/moduleSpecifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,16 @@ function computeModuleSpecifiers(
redirectPathsSpecifiers = append(redirectPathsSpecifiers, local);
}
else if (pathIsBareSpecifier(local)) {
pathsSpecifiers = append(pathsSpecifiers, local);
if (pathContainsNodeModules(local)) {
// We could be in this branch due to inappropriate use of `baseUrl`, not intentional `paths`
// usage. It's impossible to reason about where to prioritize baseUrl-generated module
// specifiers, but if they contain `/node_modules/`, they're going to trigger a portability
// error, so *at least* don't prioritize those.
relativeSpecifiers = append(relativeSpecifiers, local);
}
else {
pathsSpecifiers = append(pathsSpecifiers, local);
}
}
else if (forAutoImport || !importedFileIsInNodeModules || modulePath.isInNodeModules) {
// Why this extra conditional, not just an `else`? If some path to the file contained
Expand Down
63 changes: 63 additions & 0 deletions tests/baselines/reference/declarationEmitMonorepoBaseUrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//// [tests/cases/compiler/declarationEmitMonorepoBaseUrl.ts] ////

//// [package.json]
{
"name": "@babel/parser",
"version": "7.23.6",
"main": "./lib/index.js",
"types": "./typings/babel-parser.d.ts"
}

//// [babel-parser.d.ts]
export declare function createPlugin(): PluginConfig;
export declare class PluginConfig {}

//// [package.json]
{
"name": "@vue/compiler-core",
"version": "3.0.0",
"main": "./src/index.ts",
"dependencies": {
"@babel/parser": "^7.0.0"
}
}

//// [package.json]
{
"name": "@vue/compiler-sfc",
"version": "3.0.0",
"main": "./src/index.ts",
"dependencies": {
"@babel/parser": "^7.0.0",
"@vue/compiler-core": "^3.0.0"
}
}

//// [index.ts]
import { PluginConfig } from "@babel/parser";

//// [index.ts]
import { createPlugin } from "@babel/parser";
export function resolveParserPlugins() {
return [createPlugin()];
}


//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveParserPlugins = void 0;
const parser_1 = require("@babel/parser");
function resolveParserPlugins() {
return [(0, parser_1.createPlugin)()];
}
exports.resolveParserPlugins = resolveParserPlugins;


//// [index.d.ts]
export {};
//// [index.d.ts]
export declare function resolveParserPlugins(): import("@babel/parser").PluginConfig[];
57 changes: 57 additions & 0 deletions tests/cases/compiler/declarationEmitMonorepoBaseUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// @noTypesAndSymbols: true

// @Filename: /tsconfig.json
{
"compilerOptions": {
"module": "nodenext",
"declaration": true,
"outDir": "temp",
"baseUrl": "."
}
}

// @Filename: /node_modules/.pnpm/@babel+parser@7.23.6/node_modules/@babel/parser/package.json
{
"name": "@babel/parser",
"version": "7.23.6",
"main": "./lib/index.js",
"types": "./typings/babel-parser.d.ts"
}

// @Filename: /node_modules/.pnpm/@babel+parser@7.23.6/node_modules/@babel/parser/typings/babel-parser.d.ts
export declare function createPlugin(): PluginConfig;
export declare class PluginConfig {}

// @Filename: /packages/compiler-core/package.json
{
"name": "@vue/compiler-core",
"version": "3.0.0",
"main": "./src/index.ts",
"dependencies": {
"@babel/parser": "^7.0.0"
}
}

// @Filename: /packages/compiler-core/src/index.ts
import { PluginConfig } from "@babel/parser";

// @Filename: /packages/compiler-sfc/package.json
{
"name": "@vue/compiler-sfc",
"version": "3.0.0",
"main": "./src/index.ts",
"dependencies": {
"@babel/parser": "^7.0.0",
"@vue/compiler-core": "^3.0.0"
}
}

// @Filename: /packages/compiler-sfc/src/index.ts
import { createPlugin } from "@babel/parser";
export function resolveParserPlugins() {
return [createPlugin()];
}

// @link: /node_modules/.pnpm/@babel+parser@7.23.6/node_modules/@babel/parser -> /node_modules/@babel/parser
// @link: /node_modules/.pnpm/@babel+parser@7.23.6/node_modules/@babel/parser -> /packages/compiler-core/node_modules/@babel/parser
// @link: /node_modules/.pnpm/@babel+parser@7.23.6/node_modules/@babel/parser -> /packages/compiler-sfc/node_modules/@babel/parser