-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from laurisvan/master
Fix: Full dependencies not installed for externals
- Loading branch information
Showing
1 changed file
with
24 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |