aboutsummaryrefslogtreecommitdiff
path: root/pkgs/development/node-packages/node-env.nix
diff options
context:
space:
mode:
authoradisbladis <adisbladis@gmail.com>2019-07-05 11:01:52 +0100
committerRobin Gloster <mail@glob.in>2019-08-02 02:34:33 +0200
commitfae732edb11876800db7b9f1eebbc7c553a9c99b (patch)
tree7fb3647b7f3267671d4b054bc1595908e95654b3 /pkgs/development/node-packages/node-env.nix
parent443b0f63323b09e936bd0fe967899ec4bfec7958 (diff)
nodePackages: Regenerate node packages for nodejs 10 & 12
Diffstat (limited to 'pkgs/development/node-packages/node-env.nix')
-rw-r--r--pkgs/development/node-packages/node-env.nix152
1 files changed, 77 insertions, 75 deletions
diff --git a/pkgs/development/node-packages/node-env.nix b/pkgs/development/node-packages/node-env.nix
index 670556bf271a..720e0cc08503 100644
--- a/pkgs/development/node-packages/node-env.nix
+++ b/pkgs/development/node-packages/node-env.nix
@@ -11,7 +11,7 @@ let
cat > $out/bin/tar <<EOF
#! ${stdenv.shell} -e
- $(type -p tar) "\$@" --warning=no-unknown-keyword --delay-directory-restore
+ $(type -p tar) "\$@" --warning=no-unknown-keyword
EOF
chmod +x $out/bin/tar
@@ -72,7 +72,7 @@ let
packageDir="$(find . -maxdepth 1 -type d | tail -1)"
# Restore write permissions to make building work
- find "$packageDir" -type d -exec chmod u+x {} \;
+ find "$packageDir" -type d -print0 | xargs -0 chmod u+x
chmod -R u+w "$packageDir"
# Move the extracted tarball into the output folder
@@ -219,16 +219,7 @@ let
packageObj["_integrity"] = "sha1-000000000000000000000000000="; // When no _integrity string has been provided (e.g. by Git dependencies), add a dummy one. It does not seem to harm and it bypasses downloads.
}
- if(dependency.resolved) {
- packageObj["_resolved"] = dependency.resolved; // Adopt the resolved property if one has been provided
- } else {
- packageObj["_resolved"] = dependency.version; // Set the resolved version to the version identifier. This prevents NPM from cloning Git repositories.
- }
-
- if(dependency.from !== undefined) { // Adopt from property if one has been provided
- packageObj["_from"] = dependency.from;
- }
-
+ packageObj["_resolved"] = dependency.version; // Set the resolved version to the version identifier. This prevents NPM from cloning Git repositories.
fs.writeFileSync(packageJSONPath, JSON.stringify(packageObj, null, 2));
}
@@ -317,61 +308,6 @@ let
'';
};
- prepareAndInvokeNPM = {packageName, bypassCache, reconstructLock, npmFlags, production}:
- let
- forceOfflineFlag = if bypassCache then "--offline" else "--registry http://www.example.com";
- in
- ''
- # Pinpoint the versions of all dependencies to the ones that are actually being used
- echo "pinpointing versions of dependencies..."
- source $pinpointDependenciesScriptPath
-
- # Patch the shebangs of the bundled modules to prevent them from
- # calling executables outside the Nix store as much as possible
- patchShebangs .
-
- # Deploy the Node.js package by running npm install. Since the
- # dependencies have been provided already by ourselves, it should not
- # attempt to install them again, which is good, because we want to make
- # it Nix's responsibility. If it needs to install any dependencies
- # anyway (e.g. because the dependency parameters are
- # incomplete/incorrect), it fails.
- #
- # The other responsibilities of NPM are kept -- version checks, build
- # steps, postprocessing etc.
-
- export HOME=$TMPDIR
- cd "${packageName}"
- runHook preRebuild
-
- ${stdenv.lib.optionalString bypassCache ''
- ${stdenv.lib.optionalString reconstructLock ''
- if [ -f package-lock.json ]
- then
- echo "WARNING: Reconstruct lock option enabled, but a lock file already exists!"
- echo "This will most likely result in version mismatches! We will remove the lock file and regenerate it!"
- rm package-lock.json
- else
- echo "No package-lock.json file found, reconstructing..."
- fi
-
- node ${reconstructPackageLock}
- ''}
-
- node ${addIntegrityFieldsScript}
- ''}
-
- npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${stdenv.lib.optionalString production "--production"} rebuild
-
- if [ "$dontNpmInstall" != "1" ]
- then
- # NPM tries to download packages even when they already exist if npm-shrinkwrap is used.
- rm -f npm-shrinkwrap.json
-
- npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${stdenv.lib.optionalString production "--production"} install
- fi
- '';
-
# Builds and composes an NPM package including all its dependencies
buildNodePackage =
{ name
@@ -383,7 +319,6 @@ let
, npmFlags ? ""
, dontNpmInstall ? false
, bypassCache ? false
- , reconstructLock ? false
, preRebuild ? ""
, dontStrip ? true
, unpackPhase ? "true"
@@ -391,10 +326,11 @@ let
, ... }@args:
let
+ forceOfflineFlag = if bypassCache then "--offline" else "--registry http://www.example.com";
extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" "dontStrip" "dontNpmInstall" "preRebuild" "unpackPhase" "buildPhase" ];
in
stdenv.mkDerivation ({
- name = "node_${name}-${version}";
+ name = "node-${name}-${version}";
buildInputs = [ tarWrapper python nodejs ]
++ stdenv.lib.optional (stdenv.isLinux) utillinux
++ stdenv.lib.optional (stdenv.isDarwin) libtool
@@ -416,7 +352,47 @@ let
# Compose the package and all its dependencies
source $compositionScriptPath
- ${prepareAndInvokeNPM { inherit packageName bypassCache reconstructLock npmFlags production; }}
+ # Pinpoint the versions of all dependencies to the ones that are actually being used
+ echo "pinpointing versions of dependencies..."
+ source $pinpointDependenciesScriptPath
+
+ # Patch the shebangs of the bundled modules to prevent them from
+ # calling executables outside the Nix store as much as possible
+ patchShebangs .
+
+ # Deploy the Node.js package by running npm install. Since the
+ # dependencies have been provided already by ourselves, it should not
+ # attempt to install them again, which is good, because we want to make
+ # it Nix's responsibility. If it needs to install any dependencies
+ # anyway (e.g. because the dependency parameters are
+ # incomplete/incorrect), it fails.
+ #
+ # The other responsibilities of NPM are kept -- version checks, build
+ # steps, postprocessing etc.
+
+ export HOME=$TMPDIR
+ cd "${packageName}"
+ runHook preRebuild
+
+ ${stdenv.lib.optionalString bypassCache ''
+ if [ ! -f package-lock.json ]
+ then
+ echo "No package-lock.json file found, reconstructing..."
+ node ${reconstructPackageLock}
+ fi
+
+ node ${addIntegrityFieldsScript}
+ ''}
+
+ npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${stdenv.lib.optionalString production "--production"} rebuild
+
+ if [ "$dontNpmInstall" != "1" ]
+ then
+ # NPM tries to download packages even when they already exist if npm-shrinkwrap is used.
+ rm -f npm-shrinkwrap.json
+
+ npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${stdenv.lib.optionalString production "--production"} install
+ fi
# Create symlink to the deployed executable folder, if applicable
if [ -d "$out/lib/node_modules/.bin" ]
@@ -455,13 +431,14 @@ let
, npmFlags ? ""
, dontNpmInstall ? false
, bypassCache ? false
- , reconstructLock ? false
, dontStrip ? true
, unpackPhase ? "true"
, buildPhase ? "true"
, ... }@args:
let
+ forceOfflineFlag = if bypassCache then "--offline" else "--registry http://www.example.com";
+
extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" ];
nodeDependencies = stdenv.mkDerivation ({
@@ -496,13 +473,39 @@ let
fi
''}
- # Go to the parent folder to make sure that all packages are pinpointed
+ # Pinpoint the versions of all dependencies to the ones that are actually being used
+ echo "pinpointing versions of dependencies..."
cd ..
${stdenv.lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
- ${prepareAndInvokeNPM { inherit packageName bypassCache reconstructLock npmFlags production; }}
+ source $pinpointDependenciesScriptPath
+ cd ${packageName}
+
+ # Patch the shebangs of the bundled modules to prevent them from
+ # calling executables outside the Nix store as much as possible
+ patchShebangs .
+
+ export HOME=$PWD
+
+ ${stdenv.lib.optionalString bypassCache ''
+ if [ ! -f package-lock.json ]
+ then
+ echo "No package-lock.json file found, reconstructing..."
+ node ${reconstructPackageLock}
+ fi
+
+ node ${addIntegrityFieldsScript}
+ ''}
+
+ npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${stdenv.lib.optionalString production "--production"} rebuild
+
+ ${stdenv.lib.optionalString (!dontNpmInstall) ''
+ # NPM tries to download packages even when they already exist if npm-shrinkwrap is used.
+ rm -f npm-shrinkwrap.json
+
+ npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${stdenv.lib.optionalString production "--production"} install
+ ''}
- # Expose the executables that were installed
cd ..
${stdenv.lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
@@ -529,7 +532,6 @@ let
inherit nodeDependencies;
shellHook = stdenv.lib.optionalString (dependencies != []) ''
export NODE_PATH=$nodeDependencies/lib/node_modules
- export PATH="$nodeDependencies/bin:$PATH"
'';
};
in