From 02170de9a54574e3ae1372dd40f1e95ff65f4e54 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Wed, 2 Nov 2022 21:38:36 -0700 Subject: [PATCH] preserve querystring in `emitDependency` --- src/node-file-trace.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/node-file-trace.ts b/src/node-file-trace.ts index 7dd8627b..769e8e40 100644 --- a/src/node-file-trace.ts +++ b/src/node-file-trace.ts @@ -355,6 +355,7 @@ export class Job { await this.emitFile(asset, 'asset', path); }), ...[...deps].map(async dep => { + const queryString = dep.split("?")[1] try { var resolved = await this.resolve(dep, path, this, !isESM); } @@ -363,15 +364,27 @@ export class Job { return; } if (Array.isArray(resolved)) { - for (const item of resolved) { + for (let item of resolved) { // ignore builtins if (item.startsWith('node:')) return; + // Dependencies which differ only by querystring are considered separate dependencies by + // webpack, and therefore need to be treated separately here, too. Resolution can strip + // the querystring off, in which case we need to put it back on to preserve the distinction. + if (queryString && !item.includes(queryString)) { + item += `?${queryString}` + } await this.emitDependency(item, path); } } else { // ignore builtins if (resolved.startsWith('node:')) return; + // Dependencies which differ only by querystring are considered separate dependencies by + // webpack, and therefore need to be treated separately here, too. Resolution can strip + // the querystring off, in which case we need to put it back on to preserve the distinction. + if (queryString && !resolved.includes(queryString)) { + resolved += `?${queryString}` + } await this.emitDependency(resolved, path); } }),