Skip to content

Commit 2466d75

Browse files
committed
fix: remove accidental duplication of params in source
1 parent c02d930 commit 2466d75

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

packages/acceptance-tests/pkg-tests-specs/sources/commands/patchCommit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ describe(`Commands`, () => {
233233
const manifest = await xfs.readJsonPromise(ppath.join(path, Filename.manifest));
234234

235235
expect(manifest.dependencies).toEqual({
236-
[`unconventional-tarball`]: expect.stringMatching(/^patch:unconventional-tarball@npm%3A1\.0\.0#.*::__archiveUrl=https%3A%2F%2Fregistry\.example\.org/),
236+
[`unconventional-tarball`]: expect.stringMatching(/^patch:unconventional-tarball@npm%3A1\.0\.0#.*\.patch::__archiveUrl=/),
237237
});
238238

239239
// Ensure the patch URL format is correct (not malformed)

packages/plugin-patch/sources/patchUtils.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,24 @@ function makeSpec<T>({parentLocator, sourceItem, patchPaths, sourceVersion, patc
103103
? {hash: patchHash}
104104
: {} as {};
105105

106+
// Parse the source to separate base range from existing bindings
106107
const sourceString = sourceStringifier(sourceItem);
107-
const {params: sourceParams} = structUtils.parseRange(sourceString);
108+
const {protocol, source, selector, params: sourceParams} = structUtils.parseRange(sourceString);
109+
110+
// Reconstruct the source without existing bindings
111+
const baseSource = structUtils.makeRange({
112+
protocol,
113+
source,
114+
selector,
115+
params: null, // Remove existing bindings from source
116+
});
108117

109118
return structUtils.makeRange({
110119
protocol: `patch:`,
111-
source: sourceString,
120+
source: baseSource,
112121
selector: patchPaths.join(`&`),
113122
params: {
114-
...normalizeParams(sourceParams),
123+
...normalizeParams(sourceParams), // Preserve original bindings (like __archiveUrl)
115124
...sourceVersionSpread,
116125
...patchHashSpread,
117126
...parentLocatorSpread,
@@ -375,7 +384,11 @@ export function normalizeParams(params: ReturnType<typeof structUtils.parseRange
375384

376385
for (const [key, value] of Object.entries(params)) {
377386
if (value !== undefined) {
378-
result[key] = Array.isArray(value) ? value.join(`,`) : String(value);
387+
if (Array.isArray(value) && value.length > 0) {
388+
result[key] = value.join(`,`);
389+
} else {
390+
result[key] = String(value);
391+
}
379392
}
380393
}
381394

0 commit comments

Comments
 (0)