From 4c1e25c8ce752bc3130b0ac83c849e568d070cd4 Mon Sep 17 00:00:00 2001
From: Peter Jaszkowiak
Date: Fri, 19 May 2017 14:27:52 -0600
Subject: [PATCH] Link instead of copying files
Only mkdirp the necessary directories
---
src/meta/js.js | 33 +++++++++------------------------
1 file changed, 9 insertions(+), 24 deletions(-)
diff --git a/src/meta/js.js b/src/meta/js.js
index bfae9260c2..d0399c70c1 100644
--- a/src/meta/js.js
+++ b/src/meta/js.js
@@ -88,31 +88,16 @@ module.exports = function (Meta) {
},
};
- function copyFile(source, target, cb) {
- var called = false;
-
- var rd = fs.createReadStream(source);
- rd.on('error', done);
-
- var wr = fs.createWriteStream(target);
- wr.on('error', done);
- wr.on('close', function () {
- done();
- });
- rd.pipe(wr);
-
- function done(err) {
- if (!called) {
- cb(err);
- called = true;
+ function minifyModules(modules, fork, callback) {
+ var moduleDirs = modules.reduce(function (prev, mod) {
+ var dir = path.resolve(path.dirname(mod.destPath));
+ if (prev.indexOf(dir) === -1) {
+ prev.push(dir);
}
- }
- }
+ return prev;
+ }, []);
- function minifyModules(modules, fork, callback) {
- async.eachLimit(modules, 1000, function (mod, next) {
- mkdirp(path.dirname(mod.destPath), next);
- }, function (err) {
+ async.eachLimit(moduleDirs, 1000, mkdirp, function (err) {
if (err) {
return callback(err);
}
@@ -133,7 +118,7 @@ module.exports = function (Meta) {
},
function (cb) {
async.eachLimit(filtered.skip, 500, function (mod, next) {
- copyFile(mod.srcPath, mod.destPath, next);
+ file.link(mod.srcPath, mod.destPath, next);
}, cb);
},
], callback);