Skip to content

Commit acd9105

Browse files
fix(mama): normalize node_modules/.bin/ prefix (#716)
1 parent 6b6fa55 commit acd9105

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

.changeset/rich-heads-float.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nodesecure/mama": patch
3+
---
4+
5+
Normalize node_modules/.bin/ prefix without leading ./

workspaces/mama/src/utils/integrity-hash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function removeNodeModulesBin(
7171
return Object.fromEntries(
7272
Object.entries(scripts).map(([key, value]) => [
7373
key,
74-
value.replaceAll("./node_modules/.bin/", "")
74+
value.replace(/(?:\.\/)?node_modules\/\.bin\//g, "")
7575
])
7676
);
7777
}

workspaces/mama/test/packageJSONIntegrityHash.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,42 @@ describe("packageJSONIntegrityHash", () => {
6565
}
6666
});
6767

68+
test("Given a script with an instance of 'node_modules/.bin/'", () => {
69+
for (const arg of [undefined, { isFromRemoteRegistry: true }]) {
70+
const { object } = packageJSONIntegrityHash({
71+
...kMinimalPackageJSON,
72+
scripts: {
73+
test: "node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape ./test/integration/*.js"
74+
}
75+
}, arg);
76+
77+
assert.strictEqual(
78+
object.scripts.test,
79+
"istanbul cover ./node_modules/tape/bin/tape ./test/integration/*.js"
80+
);
81+
}
82+
});
83+
84+
test("tarball script 'node_modules/.bin/x' and registry script 'x' should produce the same integrity", () => {
85+
const tarball = packageJSONIntegrityHash({
86+
...kMinimalPackageJSON,
87+
scripts: {
88+
test: "node_modules/.bin/mocha --reporter spec",
89+
pegjs: "node_modules/.bin/pegjs lib/parser/pbxproj.pegjs"
90+
}
91+
});
92+
93+
const registry = packageJSONIntegrityHash({
94+
...kMinimalPackageJSON,
95+
scripts: {
96+
test: "mocha --reporter spec",
97+
pegjs: "pegjs lib/parser/pbxproj.pegjs"
98+
}
99+
});
100+
101+
assert.strictEqual(tarball.integrity, registry.integrity);
102+
});
103+
68104
test("should include optional dependencies in the hash when there is some", () => {
69105
const packageJSONWithOptionalDeps = {
70106
...kMinimalPackageJSON,

0 commit comments

Comments
 (0)