mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-27 23:58:38 -06:00
Deprioritize declaration emit paths from baseUrl containing node_modules (#57145)
This commit is contained in:
parent
966242c6a1
commit
25a4f9e535
@ -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
|
||||
|
||||
63
tests/baselines/reference/declarationEmitMonorepoBaseUrl.js
Normal file
63
tests/baselines/reference/declarationEmitMonorepoBaseUrl.js
Normal file
@ -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
tests/cases/compiler/declarationEmitMonorepoBaseUrl.ts
Normal file
57
tests/cases/compiler/declarationEmitMonorepoBaseUrl.ts
Normal file
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user