diff --git a/.changeset/rich-heads-float.md b/.changeset/rich-heads-float.md new file mode 100644 index 00000000..4f5c5357 --- /dev/null +++ b/.changeset/rich-heads-float.md @@ -0,0 +1,5 @@ +--- +"@nodesecure/mama": patch +--- + +Normalize node_modules/.bin/ prefix without leading ./ diff --git a/workspaces/mama/src/utils/integrity-hash.ts b/workspaces/mama/src/utils/integrity-hash.ts index 30798164..9e854e4f 100644 --- a/workspaces/mama/src/utils/integrity-hash.ts +++ b/workspaces/mama/src/utils/integrity-hash.ts @@ -71,7 +71,7 @@ function removeNodeModulesBin( return Object.fromEntries( Object.entries(scripts).map(([key, value]) => [ key, - value.replaceAll("./node_modules/.bin/", "") + value.replace(/(?:\.\/)?node_modules\/\.bin\//g, "") ]) ); } diff --git a/workspaces/mama/test/packageJSONIntegrityHash.spec.ts b/workspaces/mama/test/packageJSONIntegrityHash.spec.ts index e41af1f4..f1c3785c 100644 --- a/workspaces/mama/test/packageJSONIntegrityHash.spec.ts +++ b/workspaces/mama/test/packageJSONIntegrityHash.spec.ts @@ -65,6 +65,42 @@ describe("packageJSONIntegrityHash", () => { } }); + test("Given a script with an instance of 'node_modules/.bin/'", () => { + for (const arg of [undefined, { isFromRemoteRegistry: true }]) { + const { object } = packageJSONIntegrityHash({ + ...kMinimalPackageJSON, + scripts: { + test: "node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape ./test/integration/*.js" + } + }, arg); + + assert.strictEqual( + object.scripts.test, + "istanbul cover ./node_modules/tape/bin/tape ./test/integration/*.js" + ); + } + }); + + test("tarball script 'node_modules/.bin/x' and registry script 'x' should produce the same integrity", () => { + const tarball = packageJSONIntegrityHash({ + ...kMinimalPackageJSON, + scripts: { + test: "node_modules/.bin/mocha --reporter spec", + pegjs: "node_modules/.bin/pegjs lib/parser/pbxproj.pegjs" + } + }); + + const registry = packageJSONIntegrityHash({ + ...kMinimalPackageJSON, + scripts: { + test: "mocha --reporter spec", + pegjs: "pegjs lib/parser/pbxproj.pegjs" + } + }); + + assert.strictEqual(tarball.integrity, registry.integrity); + }); + test("should include optional dependencies in the hash when there is some", () => { const packageJSONWithOptionalDeps = { ...kMinimalPackageJSON,