Skip to content

Commit 286e1cf

Browse files
committed
fix(inspect-npm-pack): skip package scripts when inspecting npm pack
They don't do anything useful here and may parint to stdout and break npm pack output parsing.
1 parent 21b2dab commit 286e1cf

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

src/module/inspect-npm-pack.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,17 @@ interface FileInfo {
2424
mode: number;
2525
}
2626

27-
const PACK_CMD = ["npm", "pack", "--dry-run", "--json"];
27+
const PACK_CMD = [
28+
"npm",
29+
"pack",
30+
// Don't create any package, we just need to see what would be packed.
31+
"--dry-run",
32+
// Prevents things like Husky from outputting to stdout, we don't need them
33+
// here anyway.
34+
"--ignore-scripts",
35+
// JSON is easier to parse and more stable between npm versions.
36+
"--json",
37+
];
2838

2939
/**
3040
* @param textOrLines
@@ -49,10 +59,16 @@ function runNpmPack(): PackageInfo[] {
4959
// from there doesn't exhibit those issues.
5060
execSync(`${PACK_CMD.join(" ")} > ${tmpFile}`, {
5161
encoding: "utf-8",
52-
env: { ...process.env, LC_ALL: "C" },
62+
env: {
63+
...process.env,
64+
LC_ALL: "C",
65+
NODE_ENV: "production",
66+
},
5367
});
5468

55-
const stdout = readFileSync(tmpFile, "utf-8");
69+
const stdout = readFileSync(tmpFile, "utf-8")
70+
// TODO: Why doesn't --ignore-scripts turn Husky off? It works in CLI.
71+
.replace(/^([^[]*)\[\n/, "[");
5672

5773
try {
5874
return JSON.parse(stdout);

0 commit comments

Comments
 (0)