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/giant-papers-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nodesecure/mama": patch
---

Remove ./node_modules/.bin/ from scripts and integrity hash
19 changes: 18 additions & 1 deletion workspaces/mama/src/utils/integrity-hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,28 @@ export function packageJSONIntegrityHash(
version,
dependencies,
license,
scripts
/**
* Note: NPM registry automatically add `./node_modules/.bin/` to scripts
* This artifact do not concern raw scripts in the tarball package.json.
*/
scripts: isFromRemoteRegistry ?
removeNodeModulesBin(scripts) :
scripts
};

return {
object,
integrity: hash(object)
};
}

function removeNodeModulesBin(
scripts: Record<string, string>
) {
return Object.fromEntries(
Object.entries(scripts).map(([key, value]) => [
key,
value.replaceAll("./node_modules/.bin/", "")
])
);
}
14 changes: 14 additions & 0 deletions workspaces/mama/test/packageJSONIntegrityHash.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,18 @@ describe("packageJSONIntegrityHash", () => {
kMinimalPackageJSONIntegrity
);
});

test("Given a script with an instance of './node_modules/.bin/'", () => {
const { object } = packageJSONIntegrityHash({
...kMinimalPackageJSON,
scripts: {
test: "./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape ./test/integration/*.js"
}
}, { isFromRemoteRegistry: true });

assert.strictEqual(
object.scripts.test,
"istanbul cover ./node_modules/tape/bin/tape ./test/integration/*.js"
);
});
});