Currently using my package as a git:
dependency doesn’t work because we use TypeScript and generated JS files aren’t in the Git repo.
https://docs.npmjs.com/cli/v11/using-npm/scripts says
prepare
NOTE: If a package being installed through git contains a prepare script, its dependencies and devDependencies will be installed, and the prepare script will be run, before the package is packaged and installed.
and
prepack
Runs BEFORE a tarball is packed (on “npm pack”, “npm publish”, and when installing a git dependency).
By comparison, https://yarnpkg.com/advanced/lifecycle-scripts:
prepack and postpack
Those script are called right at the beginning and the end of each call to yarn pack. They are respectively meant to turn your package from development into production, and cleanup any lingering artifact. For instance, a typical prepack script would call Babel or TypeScript on the source directory to turn .ts files into .js files.
So I thought using prepack
should work for both. But I don’t see it being run in Yarn Classic, at least. So looking at https://classic.yarnpkg.com/en/docs/package-json#scripts-
Certain script names are special. If defined, the preinstall script is called by yarn before your package is installed. For compatibility reasons, scripts called install, postinstall, prepublish, and prepare will all be called after your package has finished installing.
So no prepack
, and it doesn’t mention devDependencies
being installed. On the other hand Yarn v2+ doesn’t support prepublishOnly
or prepare
.
Finally, pnpm just has https://pnpm.io/scripts which doesn’t mention any of these scripts, only about pnpm:devPreinstall
which doesn’t seem to be applicable.
Is defining (the same) prepare
and prepack
which transpile TypeScript enough for all package managers? Are there other important considerations to make my package consumable in this way?
Related question: Ignoring type errors in a prepack script.