From 00644824daaaba70473c03f7b14d0103f6290c20 Mon Sep 17 00:00:00 2001 From: Gary Katsevman Date: Tue, 16 Feb 2016 13:29:44 -0500 Subject: [PATCH] Remove vendor directory on prepublish and pack This is necessary because if a user is bundling node-sass in their package, the vendor directory should stay so that the user isn't required to run 'npm rebuild' afterwards, assuming that it was originally installed on a like-architecture. However, at the same time, when publishing, we don't want to include the binaries since they may not work for a user plus there's the build step that tries to download the correct binary for the current architecture. Unfortunately, npm's prepublish hook runs on both prepublish *and* npm install (see npm/npm#10074), so, using in-publish as a workaround to get the prepublish script to only run prepublish and pack but not on install. Fixes #1183 Closes #1384 --- package.json | 7 +++++-- scripts/prepublish.js | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 scripts/prepublish.js diff --git a/package.json b/package.json index d04897879..9f3a0e31c 100644 --- a/package.json +++ b/package.json @@ -32,14 +32,16 @@ "postinstall": "node scripts/build.js", "pretest": "node_modules/.bin/jshint bin lib scripts test", "test": "node_modules/.bin/mocha test", - "build": "node scripts/build.js --force" + "build": "node scripts/build.js --force", + "prepublish": "not-in-install && node scripts/prepublish.js || in-install" }, "files": [ "bin", "binding.gyp", "lib", "scripts", - "src" + "src", + "vendor" ], "keywords": [ "css", @@ -58,6 +60,7 @@ "glob": "^7.0.3", "got": "^5.5.0", "meow": "^3.7.0", + "in-publish": "^2.0.0", "mkdirp": "^0.5.1", "nan": "^2.2.0", "node-gyp": "^3.3.1", diff --git a/scripts/prepublish.js b/scripts/prepublish.js new file mode 100644 index 000000000..87e9ff5fc --- /dev/null +++ b/scripts/prepublish.js @@ -0,0 +1,17 @@ +/*! + * node-sass: scripts/install.js + */ + +var path = require('path'), + rimraf = require('rimraf'); + +function prepublish() { + var vendorPath = path.resolve(__dirname, '..', 'vendor'); + rimraf.sync(vendorPath); +} + +/** + * Run + */ + +prepublish();