Skip to content

Commit

Permalink
Revert normalizeNonRelativeId changes in config/resolveModuleIds.ts.
Browse files Browse the repository at this point in the history
This reverts commit 60e18e9 from PR #8396.
  • Loading branch information
benjamn committed Nov 16, 2021
1 parent bcceee8 commit df7be26
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions config/resolveModuleIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,39 +83,16 @@ class Transformer {
}

normalizeSourceString(file: string, source?: Node | null) {
if (source && n.StringLiteral.check(source)) {
if (source && n.StringLiteral.check(source) && this.isRelative(source.value)) {
try {
source.value = this.isRelative(source.value)
? this.normalizeId(source.value, file)
: this.normalizeNonRelativeId(source.value, file);
source.value = this.normalizeId(source.value, file);
} catch (error) {
console.error(`Failed to resolve ${source.value} in ${file} with error ${error}`);
process.exit(1);
}
}
}

normalizeNonRelativeId(id: string, file: string) {
const normal = this.normalizeId(id, file);
const normalParts = normal.split("/");
const sourceParts = id.split("/");
const nodeModulesIndex = normalParts.lastIndexOf("node_modules");
if (
nodeModulesIndex >= 0 &&
normalParts[nodeModulesIndex + 1] === sourceParts[0]
) {
const bareModuleIdentifier =
normalParts.slice(nodeModulesIndex + 1).join("/");
if (normal === this.normalizeId(bareModuleIdentifier, file)) {
return bareModuleIdentifier;
}
console.error(`Leaving ${id} import in ${file} unchanged because ${
bareModuleIdentifier
} does not resolve to the same module`);
}
return id;
}

normalizeId(id: string, file: string) {
const basedir = path.dirname(file);
const absPath = resolve.sync(id, {
Expand Down

0 comments on commit df7be26

Please sign in to comment.