Skip to content
Closed
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
21 changes: 21 additions & 0 deletions pkgs/build-support/node/build-npm-package/hooks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,27 @@
substitutions = {
hostNode = "${nodejs}/bin/node";
jq = "${jq}/bin/jq";
prunePart = /* bash */ ''
if [ -z "''${dontNpmPrune-}" ]; then
if ! npm prune \
--omit=dev \
--no-save \
''${npmWorkspace+--workspace=$npmWorkspace} \
$npmPruneFlags \
"''${npmPruneFlagsArray[@]}" \
$npmFlags \
"''${npmFlagsArray[@]}"; then
echo
echo
echo "ERROR: npm prune step failed"
echo
echo 'If npm tried to download additional dependencies above, try setting `dontNpmPrune = true`.'
echo

exit 1
fi
fi
'';
};
} ./npm-install-hook.sh;
}
34 changes: 17 additions & 17 deletions pkgs/build-support/node/build-npm-package/hooks/npm-install-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,22 @@ npmInstallHook() {
local dest="$packageOut/$(dirname "$file")"
mkdir -p "$dest"
cp "${npmWorkspace-.}/$file" "$dest"
done < <(@jq@ --raw-output '.[0].files | map(.path | select(. | startswith("node_modules/") | not)) | join("\n")' <<< "$(npm_config_cache="$HOME/.npm" npm pack --json --dry-run --loglevel=warn --no-foreground-scripts ${npmWorkspace+--workspace=$npmWorkspace} $npmPackFlags "${npmPackFlagsArray[@]}" $npmFlags "${npmFlagsArray[@]}")")
done < <(@jq@ --raw-output \
'.[0].files
| map(.path | select(. | startswith("node_modules/") | not))
| join("\n")
' <<< "$(npm_config_cache="$HOME/.npm" npm pack \
--json \
--dry-run \
--loglevel=warn \
--no-foreground-scripts \
${npmWorkspace+--workspace=$npmWorkspace} \
$npmPackFlags \
"${npmPackFlagsArray[@]}" \
$npmFlags \
"${npmFlagsArray[@]}" \
)" \
)

# Based on code from Python's buildPythonPackage wrap.sh script, for
# supporting both the case when makeWrapperArgs is an array and a
Expand Down Expand Up @@ -43,22 +58,7 @@ npmInstallHook() {
local -r nodeModulesPath="$packageOut/node_modules"

if [ ! -d "$nodeModulesPath" ]; then
if [ -z "${dontNpmPrune-}" ]; then
if ! npm prune --omit=dev --no-save ${npmWorkspace+--workspace=$npmWorkspace} $npmPruneFlags "${npmPruneFlagsArray[@]}" $npmFlags "${npmFlagsArray[@]}"; then
echo
echo
echo "ERROR: npm prune step failed"
echo
echo 'If npm tried to download additional dependencies above, try setting `dontNpmPrune = true`.'
echo

exit 1
fi
fi

find node_modules -maxdepth 1 -type d -empty -delete

cp -r node_modules "$nodeModulesPath"
@prunePart@
fi

runHook postInstall
Expand Down
45 changes: 45 additions & 0 deletions pkgs/build-support/node/fetch-yarn-deps/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
cacert,
callPackage,
nix,
installShellFiles,
jq,
nodejs,
}:

let
Expand Down Expand Up @@ -175,4 +178,46 @@ in
description = "Run yarn build in buildPhase";
};
} ./yarn-build-hook.sh;

yarnInstallHook = makeSetupHook {
name = "yarn-install-hook";
propagatedBuildInputs = [
installShellFiles
makeWrapper
];
substitutions = {
hostNode = "${nodejs}/bin/node";
jq = "${jq}/bin/jq";
prunePart = ''
if [ -z "''${yarnKeepDevDeps-}" ]; then
# Yarn has a 'prune' command, but it's only a stub that instructs
# you to use `yarn install`. The goal of this prunePart is to
# remove the development dependencies from the resulted
# node_modules directory. Running yarn install here (again - after
# we ran it inyarnConfigHook), with the --production=true flag,
# should do the same thing.
if ! yarn install \
--frozen-lockfile \
--force \
--production=true \
--ignore-engines \
--ignore-platform \
--ignore-scripts \
--no-progress \
--non-interactive \
--offline
then
echo
echo
echo "ERROR: yarn install --production=true step failed"
echo
echo 'If yarn tried to download additional dependencies above, try setting `yarnKeepDevDeps = true`.'
echo

exit 1
fi
fi
'';
};
} ../build-npm-package/hooks/npm-install-hook.sh;
}
6 changes: 2 additions & 4 deletions pkgs/by-name/po/postlight-parser/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
, yarnConfigHook
, yarnBuildHook
, nodejs
, npmHooks
, yarnInstallHook
}:

stdenv.mkDerivation (finalAttrs: {
Expand All @@ -27,8 +27,8 @@ stdenv.mkDerivation (finalAttrs: {
nativeBuildInputs = [
yarnConfigHook
yarnBuildHook
yarnInstallHook
nodejs
npmHooks.npmInstallHook
];
# Upstream doesn't include a script in package.json that only builds without
# testing, and tests fail because they need to access online websites. Hence
Expand All @@ -39,8 +39,6 @@ stdenv.mkDerivation (finalAttrs: {
postBuild = ''
yarn --offline run rollup -c
'';
# Tries to download stuff from the internet in this phase.
dontNpmPrune = true;

meta = {
changelog = "https://github.com/postlight/parser/blob/${finalAttrs.src.rev}/CHANGELOG.md";
Expand Down
1 change: 1 addition & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,7 @@ with pkgs;
prefetch-yarn-deps
yarnConfigHook
yarnBuildHook
yarnInstallHook
fetchYarnDeps;

find-cursor = callPackage ../tools/X11/find-cursor { };
Expand Down