arethetypeswrong / arethetypeswrong.github.io

Tool for analyzing TypeScript types of npm packages

Home Page:https://arethetypeswrong.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`npm pack` does not work with pre/post scripts

moltar opened this issue · comments

The code relies on execSync returning the filename that was packed. But if there are any pre/post scripts, then this output will also be sucked into the final string.

execSync("npm pack", { cwd: fileOrDirectory, encoding: "utf8", stdio: "pipe" }).trim()

The fix could be using the --pack-destination flag to set a predictable path for the packed tarball, rather than relying on output.

I also wonder if it’s worth it to make the pack destination an OS tmp directory

That's what I ended up doing. The only caveat is that the packed file lands into the temp dir, but the file name is hard coded to match the package name and version. So I used shell glob expansion to pick up the single file in the dir. But that feels a bit fragile. As it'll probably not work on Windows.

In other words pack destination must be a dir, not a file.

Well, I already know the name and version, so I guess I could also just let it pack in the directory and not rely on STDOUT.