Skip to content

Commit

Permalink
Merge pull request #24 from laurisvan/master
Browse files Browse the repository at this point in the history
Fix: Full dependencies not installed for externals
  • Loading branch information
asprouse authored Jul 16, 2016
2 parents a11b688 + 373051b commit da649ad
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions lib/copyModules.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
'use strict';
const path = require('path');
const fs = require('fs-extra');
const childProcess = require('child_process');
const Promise = require('bluebird');

const copy = Promise.promisify(fs.copy);
const exec = Promise.promisify(childProcess.execFile);

module.exports = function copyModules(projectPath, moduleNames, dest) {
return Promise.all(moduleNames.map(moduleName => {
const modulePath = path.join(projectPath, 'node_modules', moduleName);
return copy(modulePath, path.join(dest, moduleName));
}));
// No dependencies, just return, so that npm install would not fail.
if (moduleNames.length === 0) {
return Promise.resolve();
}

const pkg = require(path.join(projectPath, 'package.json'));
const modulesAndVersions = moduleNames.map(moduleName => {
const moduleVersion = pkg.dependencies[moduleName];

// If no module version was found, throw an error
if (!moduleVersion) {
throw new Error(`Error: Could not find module ${moduleName} in package.json!`);
}

return `${moduleName}@${moduleVersion}`;
});
const opts = { cwd: path.join(dest), env: process.env };
const args = ['install', '--production'].concat(modulesAndVersions);

// Run 'npm install' on each module to get a full set of dependencies,
// not just the directly copied ones.
return exec('npm', args, opts);
};

0 comments on commit da649ad

Please sign in to comment.