Skip to content

Commit

Permalink
node2nix: 1.3.0 -> 1.4.0 + regenerate packages
Browse files Browse the repository at this point in the history
  • Loading branch information
svanderburg committed Nov 3, 2017
1 parent 24eaf4c commit 5b12708
Show file tree
Hide file tree
Showing 5 changed files with 22,182 additions and 29,039 deletions.
2 changes: 1 addition & 1 deletion pkgs/development/node-packages/composition-v4.nix
@@ -1,4 +1,4 @@
# This file has been generated by node2nix 1.3.0. Do not edit!
# This file has been generated by node2nix 1.4.0. Do not edit!

{pkgs ? import <nixpkgs> {
inherit system;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/node-packages/composition-v6.nix
@@ -1,4 +1,4 @@
# This file has been generated by node2nix 1.3.0. Do not edit!
# This file has been generated by node2nix 1.4.0. Do not edit!

{pkgs ? import <nixpkgs> {
inherit system;
Expand Down
52 changes: 27 additions & 25 deletions pkgs/development/node-packages/node-env.nix
Expand Up @@ -110,16 +110,16 @@ let
text = ''
var fs = require('fs');
var path = require('path');
function resolveDependencyVersion(location, name) {
if(location == process.env['NIX_STORE']) {
return null;
} else {
var dependencyPackageJSON = path.join(location, "node_modules", name, "package.json");
if(fs.existsSync(dependencyPackageJSON)) {
var dependencyPackageObj = JSON.parse(fs.readFileSync(dependencyPackageJSON));
if(dependencyPackageObj.name == name) {
return dependencyPackageObj.version;
}
Expand All @@ -128,12 +128,12 @@ let
}
}
}
function replaceDependencies(dependencies) {
if(typeof dependencies == "object" && dependencies !== null) {
for(var dependency in dependencies) {
var resolvedVersion = resolveDependencyVersion(process.cwd(), dependency);
if(resolvedVersion === null) {
process.stderr.write("WARNING: cannot pinpoint dependency: "+dependency+", context: "+process.cwd()+"\n");
} else {
Expand All @@ -142,25 +142,25 @@ let
}
}
}
/* Read the package.json configuration */
var packageObj = JSON.parse(fs.readFileSync('./package.json'));
/* Pinpoint all dependencies */
replaceDependencies(packageObj.dependencies);
if(process.argv[2] == "development") {
replaceDependencies(packageObj.devDependencies);
}
replaceDependencies(packageObj.optionalDependencies);
/* Write the fixed package.json file */
fs.writeFileSync("package.json", JSON.stringify(packageObj, null, 2));
'';
};
in
''
node ${pinpointDependenciesFromPackageJSON} ${if production then "production" else "development"}
${stdenv.lib.optionalString (dependencies != [])
''
if [ -d node_modules ]
Expand All @@ -171,11 +171,11 @@ let
fi
''}
'';

# Recursively traverses all dependencies of a package and pinpoints all
# dependencies in the package.json file to the versions that are actually
# being used.

pinpointDependenciesOfPackage = { packageName, dependencies ? [], production ? true, ... }@args:
''
if [ -d "${packageName}" ]
Expand Down Expand Up @@ -210,7 +210,7 @@ let

compositionScript = composePackage args;
pinpointDependenciesScript = pinpointDependenciesOfPackage args;

passAsFile = [ "compositionScript" "pinpointDependenciesScript" ];

installPhase = args.installPhase or ''
Expand All @@ -220,7 +220,7 @@ let
# Compose the package and all its dependencies
source $compositionScriptPath
# Pinpoint the versions of all dependencies to the ones that are actually being used
echo "pinpointing versions of dependencies..."
source $pinpointDependenciesScriptPath
Expand Down Expand Up @@ -287,31 +287,31 @@ let

includeScript = includeDependencies { inherit dependencies; };
pinpointDependenciesScript = pinpointDependenciesOfPackage args;

passAsFile = [ "includeScript" "pinpointDependenciesScript" ];

buildCommand = ''
mkdir -p $out/lib
cd $out/lib
mkdir -p $out/${packageName}
cd $out/${packageName}
source $includeScriptPath
# Create fake package.json to make the npm commands work properly
cp ${src}/package.json .
chmod 644 package.json
# Pinpoint the versions of all dependencies to the ones that are actually being used
echo "pinpointing versions of dependencies..."
cd ..
source $pinpointDependenciesScriptPath
# Create fake package.json to make the npm commands work properly
cat > package.json <<EOF
{
"name": "${packageName}",
"version": "${version}"
}
EOF
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
npm --registry http://www.example.com --nodedir=${nodeSources} ${npmFlags} ${stdenv.lib.optionalString production "--production"} rebuild
${stdenv.lib.optionalString (!dontNpmInstall) ''
Expand All @@ -321,6 +321,8 @@ let
npm --registry http://www.example.com --nodedir=${nodeSources} ${npmFlags} ${stdenv.lib.optionalString production "--production"} install
''}
cd ..
mv ${packageName} lib
ln -s $out/lib/node_modules/.bin $out/bin
'';
};
Expand Down

0 comments on commit 5b12708

Please sign in to comment.