Skip to content

Commit 1c24256

Browse files
committed
resolver: move exports root resolution to CLI only
As requested — keep core src/ logic unchanged, handle modern exports only in CLI package loading path.
1 parent d5afdb4 commit 1c24256

File tree

3 files changed

+1
-38
lines changed

3 files changed

+1
-38
lines changed

cli/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ export async function main(argv, options) {
600600
if (!entryPath) entryPath = "index";
601601
const plainName = entryPath;
602602
if ((sourceText = await readFile(path.join(currentDir, packageName, plainName + extension), baseDir)) != null) {
603-
sourcePath = `${libraryPrefix}${packageName}/${plainName}${extension}`;
603+
sourcePath = plainName !== "index" ? `${libraryPrefix}${packageName}${extension}` : `${libraryPrefix}${packageName}/${plainName}${extension}`;
604604
packageBases.set(sourcePath.replace(extension_re, ""), path.join(currentDir, packageName));
605605
break;
606606
}

src/ast.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ import {
3434
CharCode
3535
} from "./util";
3636

37-
import { fs, path } from "../util/node.js";
38-
3937
import {
4038
ExpressionRef
4139
} from "./module";

src/parser.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ import {
9191
mangleInternalPath
9292
} from "./ast";
9393

94-
import { fs, path, process } from "../util/node.js";
95-
9694
/** Represents a dependee. */
9795
class Dependee {
9896
constructor(
@@ -2797,13 +2795,6 @@ export class Parser extends DiagnosticEmitter {
27972795
} else {
27982796
ret = Node.createImportStatement(members, path, tn.range(startPos, tn.pos));
27992797
}
2800-
// Resolve package.json for non-relative imports
2801-
if (!path.value.startsWith(".")) {
2802-
const resolvedPath = this.resolvePackagePath(path.value);
2803-
if (resolvedPath) {
2804-
ret.internalPath = resolvedPath;
2805-
}
2806-
}
28072798
let internalPath = ret.internalPath;
28082799
if (!this.seenlog.has(internalPath)) {
28092800
this.dependees.set(internalPath, new Dependee(assert(this.currentSource), path));
@@ -2867,32 +2858,6 @@ export class Parser extends DiagnosticEmitter {
28672858
return null;
28682859
}
28692860

2870-
/** Resolves a package name to its internal path via package.json. */
2871-
private resolvePackagePath(packageName: string): string | null {
2872-
try {
2873-
const nodeModulesPath = path.join(this.baseDir, 'node_modules');
2874-
const packageJsonPath = path.join(nodeModulesPath, packageName, 'package.json');
2875-
if (fs.existsSync(packageJsonPath)) {
2876-
const content = fs.readFileSync(packageJsonPath, 'utf8');
2877-
const pkg = JSON.parse(content);
2878-
let entry = pkg.ascMain || pkg.assembly || pkg.main || pkg.module;
2879-
if (!entry && pkg.exports && pkg.exports["."] && pkg.exports["."].default) {
2880-
entry = pkg.exports["."].default;
2881-
}
2882-
if (entry) {
2883-
if (entry.startsWith("./")) entry = entry.substring(2);
2884-
// Remove .ts extension if present
2885-
const entryPath = entry.replace(/\.ts$/, '');
2886-
const result = mangleInternalPath(LIBRARY_PREFIX + packageName + '/' + entryPath);
2887-
return result;
2888-
}
2889-
}
2890-
} catch (e) {
2891-
// Ignore errors
2892-
}
2893-
return null;
2894-
}
2895-
28962861
parseExportImport(
28972862
tn: Tokenizer,
28982863
startPos: i32

0 commit comments

Comments
 (0)