Update dependencies

master
Sven Slootweg 6 years ago
parent d7a09deda0
commit 5c740f77fc

@ -1,13 +1,14 @@
# This file has been generated by node2nix 1.2.0. Do not edit! # This file has been generated by node2nix 1.6.0. Do not edit!
{pkgs ? import <nixpkgs> { {pkgs ? import <nixpkgs> {
inherit system; inherit system;
}, system ? builtins.currentSystem, nodejs ? pkgs."nodejs-6_x"}: }, system ? builtins.currentSystem, nodejs ? pkgs."nodejs-10_x"}:
let let
nodeEnv = import ./node-env.nix { nodeEnv = import ./node-env.nix {
inherit (pkgs) stdenv python2 utillinux runCommand writeTextFile; inherit (pkgs) stdenv python2 utillinux runCommand writeTextFile;
inherit nodejs; inherit nodejs;
libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null;
}; };
in in
import ./node-packages.nix { import ./node-packages.nix {

@ -1,6 +1,6 @@
# This file originates from node2nix # This file originates from node2nix
{stdenv, nodejs, python2, utillinux, runCommand, writeTextFile}: {stdenv, nodejs, python2, utillinux, libtool, runCommand, writeTextFile}:
let let
python = if nodejs ? python then nodejs.python else python2; python = if nodejs ? python then nodejs.python else python2;
@ -27,7 +27,7 @@ let
buildInputs = [ nodejs ]; buildInputs = [ nodejs ];
buildPhase = '' buildPhase = ''
export HOME=$TMPDIR export HOME=$TMPDIR
tgzFile=$(npm pack) tgzFile=$(npm pack | tail -n 1) # Hooks to the pack command will add output (https://docs.npmjs.com/misc/scripts)
''; '';
installPhase = '' installPhase = ''
mkdir -p $out/tarballs mkdir -p $out/tarballs
@ -110,16 +110,16 @@ let
text = '' text = ''
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
function resolveDependencyVersion(location, name) { function resolveDependencyVersion(location, name) {
if(location == process.env['NIX_STORE']) { if(location == process.env['NIX_STORE']) {
return null; return null;
} else { } else {
var dependencyPackageJSON = path.join(location, "node_modules", name, "package.json"); var dependencyPackageJSON = path.join(location, "node_modules", name, "package.json");
if(fs.existsSync(dependencyPackageJSON)) { if(fs.existsSync(dependencyPackageJSON)) {
var dependencyPackageObj = JSON.parse(fs.readFileSync(dependencyPackageJSON)); var dependencyPackageObj = JSON.parse(fs.readFileSync(dependencyPackageJSON));
if(dependencyPackageObj.name == name) { if(dependencyPackageObj.name == name) {
return dependencyPackageObj.version; return dependencyPackageObj.version;
} }
@ -128,12 +128,12 @@ let
} }
} }
} }
function replaceDependencies(dependencies) { function replaceDependencies(dependencies) {
if(typeof dependencies == "object" && dependencies !== null) { if(typeof dependencies == "object" && dependencies !== null) {
for(var dependency in dependencies) { for(var dependency in dependencies) {
var resolvedVersion = resolveDependencyVersion(process.cwd(), dependency); var resolvedVersion = resolveDependencyVersion(process.cwd(), dependency);
if(resolvedVersion === null) { if(resolvedVersion === null) {
process.stderr.write("WARNING: cannot pinpoint dependency: "+dependency+", context: "+process.cwd()+"\n"); process.stderr.write("WARNING: cannot pinpoint dependency: "+dependency+", context: "+process.cwd()+"\n");
} else { } else {
@ -142,17 +142,17 @@ let
} }
} }
} }
/* Read the package.json configuration */ /* Read the package.json configuration */
var packageObj = JSON.parse(fs.readFileSync('./package.json')); var packageObj = JSON.parse(fs.readFileSync('./package.json'));
/* Pinpoint all dependencies */ /* Pinpoint all dependencies */
replaceDependencies(packageObj.dependencies); replaceDependencies(packageObj.dependencies);
if(process.argv[2] == "development") { if(process.argv[2] == "development") {
replaceDependencies(packageObj.devDependencies); replaceDependencies(packageObj.devDependencies);
} }
replaceDependencies(packageObj.optionalDependencies); replaceDependencies(packageObj.optionalDependencies);
/* Write the fixed package.json file */ /* Write the fixed package.json file */
fs.writeFileSync("package.json", JSON.stringify(packageObj, null, 2)); fs.writeFileSync("package.json", JSON.stringify(packageObj, null, 2));
''; '';
@ -160,7 +160,7 @@ let
in in
'' ''
node ${pinpointDependenciesFromPackageJSON} ${if production then "production" else "development"} node ${pinpointDependenciesFromPackageJSON} ${if production then "production" else "development"}
${stdenv.lib.optionalString (dependencies != []) ${stdenv.lib.optionalString (dependencies != [])
'' ''
if [ -d node_modules ] if [ -d node_modules ]
@ -171,11 +171,11 @@ let
fi fi
''} ''}
''; '';
# Recursively traverses all dependencies of a package and pinpoints all # Recursively traverses all dependencies of a package and pinpoints all
# dependencies in the package.json file to the versions that are actually # dependencies in the package.json file to the versions that are actually
# being used. # being used.
pinpointDependenciesOfPackage = { packageName, dependencies ? [], production ? true, ... }@args: pinpointDependenciesOfPackage = { packageName, dependencies ? [], production ? true, ... }@args:
'' ''
if [ -d "${packageName}" ] if [ -d "${packageName}" ]
@ -194,33 +194,164 @@ let
mv node-* $out mv node-* $out
''; '';
# Builds and composes an NPM package including all its dependencies # Script that adds _integrity fields to all package.json files to prevent NPM from consulting the cache (that is empty)
buildNodePackage = { name, packageName, version, dependencies ? [], production ? true, npmFlags ? "", dontNpmInstall ? false, preRebuild ? "", ... }@args: addIntegrityFieldsScript = writeTextFile {
name = "addintegrityfields.js";
text = ''
var fs = require('fs');
var path = require('path');
stdenv.lib.makeOverridable stdenv.mkDerivation (builtins.removeAttrs args [ "dependencies" ] // { function augmentDependencies(baseDir, dependencies) {
name = "node-${name}-${version}"; for(var dependencyName in dependencies) {
buildInputs = [ tarWrapper python nodejs ] ++ stdenv.lib.optional (stdenv.isLinux) utillinux ++ args.buildInputs or []; var dependency = dependencies[dependencyName];
dontStrip = args.dontStrip or true; # Striping may fail a build for some package deployments
// Open package.json and augment metadata fields
var packageJSONDir = path.join(baseDir, "node_modules", dependencyName);
var packageJSONPath = path.join(packageJSONDir, "package.json");
if(fs.existsSync(packageJSONPath)) { // Only augment packages that exist. Sometimes we may have production installs in which development dependencies can be ignored
console.log("Adding metadata fields to: "+packageJSONPath);
var packageObj = JSON.parse(fs.readFileSync(packageJSONPath));
inherit dontNpmInstall preRebuild; if(dependency.integrity) {
packageObj["_integrity"] = dependency.integrity;
} else {
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.
}
unpackPhase = args.unpackPhase or "true"; 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));
}
buildPhase = args.buildPhase or "true"; // Augment transitive dependencies
if(dependency.dependencies !== undefined) {
augmentDependencies(packageJSONDir, dependency.dependencies);
}
}
}
if(fs.existsSync("./package-lock.json")) {
var packageLock = JSON.parse(fs.readFileSync("./package-lock.json"));
if(packageLock.lockfileVersion !== 1) {
process.stderr.write("Sorry, I only understand lock file version 1!\n");
process.exit(1);
}
if(packageLock.dependencies !== undefined) {
augmentDependencies(".", packageLock.dependencies);
}
}
'';
};
# Reconstructs a package-lock file from the node_modules/ folder structure and package.json files with dummy sha1 hashes
reconstructPackageLock = writeTextFile {
name = "addintegrityfields.js";
text = ''
var fs = require('fs');
var path = require('path');
var packageObj = JSON.parse(fs.readFileSync("package.json"));
var lockObj = {
name: packageObj.name,
version: packageObj.version,
lockfileVersion: 1,
requires: true,
dependencies: {}
};
function augmentPackageJSON(filePath, dependencies) {
var packageJSON = path.join(filePath, "package.json");
if(fs.existsSync(packageJSON)) {
var packageObj = JSON.parse(fs.readFileSync(packageJSON));
dependencies[packageObj.name] = {
version: packageObj.version,
integrity: "sha1-000000000000000000000000000=",
dependencies: {}
};
processDependencies(path.join(filePath, "node_modules"), dependencies[packageObj.name].dependencies);
}
}
function processDependencies(dir, dependencies) {
if(fs.existsSync(dir)) {
var files = fs.readdirSync(dir);
files.forEach(function(entry) {
var filePath = path.join(dir, entry);
var stats = fs.statSync(filePath);
if(stats.isDirectory()) {
if(entry.substr(0, 1) == "@") {
// When we encounter a namespace folder, augment all packages belonging to the scope
var pkgFiles = fs.readdirSync(filePath);
pkgFiles.forEach(function(entry) {
if(stats.isDirectory()) {
var pkgFilePath = path.join(filePath, entry);
augmentPackageJSON(pkgFilePath, dependencies);
}
});
} else {
augmentPackageJSON(filePath, dependencies);
}
}
});
}
}
processDependencies("node_modules", lockObj.dependencies);
fs.writeFileSync("package-lock.json", JSON.stringify(lockObj, null, 2));
'';
};
# Builds and composes an NPM package including all its dependencies
buildNodePackage =
{ name
, packageName
, version
, dependencies ? []
, buildInputs ? []
, production ? true
, npmFlags ? ""
, dontNpmInstall ? false
, bypassCache ? false
, preRebuild ? ""
, 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" "dontStrip" "dontNpmInstall" "preRebuild" "unpackPhase" "buildPhase" ];
in
stdenv.mkDerivation ({
name = "node-${name}-${version}";
buildInputs = [ tarWrapper python nodejs ]
++ stdenv.lib.optional (stdenv.isLinux) utillinux
++ stdenv.lib.optional (stdenv.isDarwin) libtool
++ buildInputs;
inherit dontStrip; # Stripping may fail a build for some package deployments
inherit dontNpmInstall preRebuild unpackPhase buildPhase;
compositionScript = composePackage args; compositionScript = composePackage args;
pinpointDependenciesScript = pinpointDependenciesOfPackage args; pinpointDependenciesScript = pinpointDependenciesOfPackage args;
passAsFile = [ "compositionScript" "pinpointDependenciesScript" ]; passAsFile = [ "compositionScript" "pinpointDependenciesScript" ];
installPhase = args.installPhase or '' installPhase = ''
# Create and enter a root node_modules/ folder # Create and enter a root node_modules/ folder
mkdir -p $out/lib/node_modules mkdir -p $out/lib/node_modules
cd $out/lib/node_modules cd $out/lib/node_modules
# Compose the package and all its dependencies # Compose the package and all its dependencies
source $compositionScriptPath source $compositionScriptPath
# Pinpoint the versions of all dependencies to the ones that are actually being used # Pinpoint the versions of all dependencies to the ones that are actually being used
echo "pinpointing versions of dependencies..." echo "pinpointing versions of dependencies..."
source $pinpointDependenciesScriptPath source $pinpointDependenciesScriptPath
@ -242,14 +373,25 @@ let
export HOME=$TMPDIR export HOME=$TMPDIR
cd "${packageName}" cd "${packageName}"
runHook preRebuild runHook preRebuild
npm --registry http://www.example.com --nodedir=${nodeSources} ${npmFlags} ${stdenv.lib.optionalString production "--production"} rebuild
${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" ] if [ "$dontNpmInstall" != "1" ]
then then
# NPM tries to download packages even when they already exist if npm-shrinkwrap is used. # NPM tries to download packages even when they already exist if npm-shrinkwrap is used.
rm -f npm-shrinkwrap.json rm -f npm-shrinkwrap.json
npm --registry http://www.example.com --nodedir=${nodeSources} ${npmFlags} ${stdenv.lib.optionalString production "--production"} install npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${stdenv.lib.optionalString production "--production"} install
fi fi
# Create symlink to the deployed executable folder, if applicable # Create symlink to the deployed executable folder, if applicable
@ -275,60 +417,107 @@ let
# Run post install hook, if provided # Run post install hook, if provided
runHook postInstall runHook postInstall
''; '';
}); } // extraArgs);
# Builds a development shell # Builds a development shell
buildNodeShell = { name, packageName, version, src, dependencies ? [], production ? true, npmFlags ? "", dontNpmInstall ? false, ... }@args: buildNodeShell =
{ name
, packageName
, version
, src
, dependencies ? []
, buildInputs ? []
, production ? true
, npmFlags ? ""
, dontNpmInstall ? false
, bypassCache ? false
, dontStrip ? true
, unpackPhase ? "true"
, buildPhase ? "true"
, ... }@args:
let let
nodeDependencies = stdenv.mkDerivation { forceOfflineFlag = if bypassCache then "--offline" else "--registry http://www.example.com";
extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" ];
nodeDependencies = stdenv.mkDerivation ({
name = "node-dependencies-${name}-${version}"; name = "node-dependencies-${name}-${version}";
buildInputs = [ tarWrapper python nodejs ] ++ stdenv.lib.optional (stdenv.isLinux) utillinux ++ args.buildInputs or []; buildInputs = [ tarWrapper python nodejs ]
++ stdenv.lib.optional (stdenv.isLinux) utillinux
++ stdenv.lib.optional (stdenv.isDarwin) libtool
++ buildInputs;
inherit dontStrip; # Stripping may fail a build for some package deployments
inherit dontNpmInstall unpackPhase buildPhase;
includeScript = includeDependencies { inherit dependencies; }; includeScript = includeDependencies { inherit dependencies; };
pinpointDependenciesScript = pinpointDependenciesOfPackage args; pinpointDependenciesScript = pinpointDependenciesOfPackage args;
passAsFile = [ "includeScript" "pinpointDependenciesScript" ]; passAsFile = [ "includeScript" "pinpointDependenciesScript" ];
buildCommand = '' installPhase = ''
mkdir -p $out/lib mkdir -p $out/${packageName}
cd $out/lib cd $out/${packageName}
source $includeScriptPath source $includeScriptPath
# Create fake package.json to make the npm commands work properly
cp ${src}/package.json .
chmod 644 package.json
${stdenv.lib.optionalString bypassCache ''
if [ -f ${src}/package-lock.json ]
then
cp ${src}/package-lock.json .
fi
''}
# Pinpoint the versions of all dependencies to the ones that are actually being used # Pinpoint the versions of all dependencies to the ones that are actually being used
echo "pinpointing versions of dependencies..." echo "pinpointing versions of dependencies..."
source $pinpointDependenciesScriptPath cd ..
${stdenv.lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
# Create fake package.json to make the npm commands work properly source $pinpointDependenciesScriptPath
cat > package.json <<EOF cd ${packageName}
{
"name": "${packageName}",
"version": "${version}"
}
EOF
# Patch the shebangs of the bundled modules to prevent them from # Patch the shebangs of the bundled modules to prevent them from
# calling executables outside the Nix store as much as possible # calling executables outside the Nix store as much as possible
patchShebangs . patchShebangs .
export HOME=$PWD export HOME=$PWD
npm --registry http://www.example.com --nodedir=${nodeSources} ${npmFlags} ${stdenv.lib.optionalString production "--production"} rebuild
${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) '' ${stdenv.lib.optionalString (!dontNpmInstall) ''
# NPM tries to download packages even when they already exist if npm-shrinkwrap is used. # NPM tries to download packages even when they already exist if npm-shrinkwrap is used.
rm -f npm-shrinkwrap.json rm -f npm-shrinkwrap.json
npm --registry http://www.example.com --nodedir=${nodeSources} ${npmFlags} ${stdenv.lib.optionalString production "--production"} install npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${stdenv.lib.optionalString production "--production"} install
''} ''}
cd ..
${stdenv.lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
mv ${packageName} lib
ln -s $out/lib/node_modules/.bin $out/bin ln -s $out/lib/node_modules/.bin $out/bin
''; '';
}; } // extraArgs);
in in
stdenv.lib.makeOverridable stdenv.mkDerivation { stdenv.mkDerivation {
name = "node-shell-${name}-${version}"; name = "node-shell-${name}-${version}";
buildInputs = [ python nodejs ] ++ stdenv.lib.optional (stdenv.isLinux) utillinux ++ args.buildInputs or []; buildInputs = [ python nodejs ] ++ stdenv.lib.optional (stdenv.isLinux) utillinux ++ buildInputs;
buildCommand = '' buildCommand = ''
mkdir -p $out/bin mkdir -p $out/bin
cat > $out/bin/shell <<EOF cat > $out/bin/shell <<EOF
@ -346,4 +535,8 @@ let
''; '';
}; };
in in
{ inherit buildNodeSourceDist buildNodePackage buildNodeShell; } {
buildNodeSourceDist = stdenv.lib.makeOverridable buildNodeSourceDist;
buildNodePackage = stdenv.lib.makeOverridable buildNodePackage;
buildNodeShell = stdenv.lib.makeOverridable buildNodeShell;
}

File diff suppressed because it is too large Load Diff

@ -1 +1 @@
nix-shell -p nodePackages.node2nix --run "node2nix -6 --pkg-name nodejs-6_x" nix-shell -p nodePackages.node2nix --run "node2nix --nodejs-10 --pkg-name nodejs-10_x"

Loading…
Cancel
Save