Include fewer files in packages

- Only include either one of `node_modules` or `.yarn/cache` directories
- When a `files:` field is present in the package.json file, only
  include files matching those patterns
This commit is contained in:
Nick Novitski
2022-07-13 20:52:41 -07:00
parent f8ac3bac04
commit d7620c8bd3
+21 -3
View File
@@ -137,15 +137,33 @@ let
installPhase = '' installPhase = ''
runHook preInstall runHook preInstall
mkdir -p $out/libexec $out/bin mkdir -p "$out/libexec/$sourceRoot" "$out/bin"
# Move the package contents to the output directory.
# - If the package.json has a `files` field, only files matching those patterns are copied
# - Otherwise all files are copied
yarn pack --out package.tgz
tar xzvf package.tgz --directory "$out/libexec/$name" --strip-components=1
cp .yarnrc* "$out/libexec/$name"
cp --recursive .yarn "$out/libexec/$name"
# If the project uses the node-modules linker, then
# include the node_modules folder in the package.
if [ -d node_modules ]; then
cp --recursive node_modules "$out/libexec/$name"
fi
# Move the entire project to the output directory.
mv $PWD "$out/libexec/$name"
cd "$out/libexec/$name" cd "$out/libexec/$name"
# Invoke a plugin internal command to setup binaries. # Invoke a plugin internal command to setup binaries.
yarn nixify install-bin $out/bin yarn nixify install-bin $out/bin
# A package with node_modules doesn't need the cache
if [ -d node_modules ]; then
yarn cache clean
fi
runHook postInstall runHook postInstall
''; '';