Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rich-heads-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nodesecure/mama": patch
---

Normalize node_modules/.bin/ prefix without leading ./
2 changes: 1 addition & 1 deletion workspaces/mama/src/utils/integrity-hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
])
);
}
36 changes: 36 additions & 0 deletions workspaces/mama/test/packageJSONIntegrityHash.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading