aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2019-10-12 21:31:28 +0200
committerIgor Pashev <pashev.igor@gmail.com>2019-10-12 21:31:28 +0200
commit2d7643789f7fc2abcb3bc9c12e5e0ad91ed90fdb (patch)
tree97ec94aaa8e2a2a37389f879e7b9e57963ae0dd0
parent895f1f156d214a850d8a9b994e6a54589b2e20c7 (diff)
downloadnpm.nix-2d7643789f7fc2abcb3bc9c12e5e0ad91ed90fdb.tar.gz
Refactor stripping
Motivation: remove unsed scripts like prepublish
-rw-r--r--npmPackages/_scripts/strip.js48
-rw-r--r--npmPackages/buildNpmPackage.nix8
2 files changed, 38 insertions, 18 deletions
diff --git a/npmPackages/_scripts/strip.js b/npmPackages/_scripts/strip.js
index e76bf6d..526730d 100644
--- a/npmPackages/_scripts/strip.js
+++ b/npmPackages/_scripts/strip.js
@@ -5,14 +5,20 @@ const {
} = require('./package.js');
-var stripDependencies = false;
+var phase;
const args = process.argv.slice(2);
for (var i = 0; i < args.length; i++) {
switch (args[i]) {
- case '--strip-dependencies':
- stripDependencies = true;
+ case '--post-configure':
+ phase = 'postConfigure';
+ break;
+ case '--pre-install':
+ phase = 'preInstall';
+ break;
+ case '--post-install':
+ phase = 'postInstall';
break;
default:
;
@@ -20,18 +26,30 @@ for (var i = 0; i < args.length; i++) {
}
pipeThrough((pkg, done) => {
- delete pkg.devDependencies;
- delete pkg.engines;
- delete pkg.keywords;
- delete pkg.optionalDependencies;
- delete pkg.peerDependencies;
- delete pkg.scripts;
- delete pkg.tap;
- delete pkg.xo;
-
- if (stripDependencies) {
- delete pkg.dependencies;
+ switch (phase) {
+ case 'postInstall':
+ delete pkg.dependencies;
+ // fall throw
+
+ case 'preInstall':
+ delete pkg.engines;
+ delete pkg.keywords;
+ delete pkg.scripts;
+ delete pkg.tap;
+ delete pkg.xo;
+ // fall throw
+
+ case 'postConfigure':
+ delete pkg.devDependencies;
+ delete pkg.optionalDependencies;
+ delete pkg.peerDependencies;
+ if (pkg.scripts) {
+ delete pkg.scripts.prepublish;
+ }
+ break;
+ default:
+ throw (`Unknown phase: "${phase}"`);
}
done(pkg);
-});
+}); \ No newline at end of file
diff --git a/npmPackages/buildNpmPackage.nix b/npmPackages/buildNpmPackage.nix
index 9856291..5a0f4e5 100644
--- a/npmPackages/buildNpmPackage.nix
+++ b/npmPackages/buildNpmPackage.nix
@@ -58,11 +58,13 @@ stdenv.mkDerivation {
rm -f package-lock.json
npm --ignore-scripts install
+ node ${scripts}/strip.js --post-configure < package.json > package.json.stripped
+ mv package.json.stripped package.json
+
'';
installPhase = ''
- # remove things that are not needed any more or not needed with Nix:
- node ${scripts}/strip.js < package.json > package.json.stripped
+ node ${scripts}/strip.js --pre-install < package.json > package.json.stripped
mv package.json.stripped package.json
${lib.optionalString (files != []) ''
@@ -90,7 +92,7 @@ stdenv.mkDerivation {
# Finally, strip info about runtime dependencies,
# so that NPM will not complain about missed or extraneous dependencies:
- node ${scripts}/strip.js --strip-dependencies < package.json > package.json.stripped
+ node ${scripts}/strip.js --post-install < package.json > package.json.stripped
mv package.json.stripped package.json
'';
}