Skip to content

Commit

Permalink
Revert normalizeNonRelativeId changes in `config/resolveModuleIds.t…
Browse files Browse the repository at this point in the history
…s` (#9073)
  • Loading branch information
benjamn committed Nov 16, 2021
1 parent bcceee8 commit 402a028
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Apollo Client 3.5.3 (not yet released)

- Avoid rewriting non-relative imported module specifiers in `config/rewriteModuleIds.ts` script, thereby allowing bundlers to resolve those imports as they see fit. <br/>
[@benjamn](https://github.com/benjamn) in [#9073](https://github.com/apollographql/apollo-client/pull/9073)

## Apollo Client 3.5.2 (2021-11-10)

- Fix useMutation execute function returning non-identical execution functions when passing similar options. <br/>
Expand Down
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 402a028

Please sign in to comment.