Skip to content

Commit

Permalink
fix: avoid unnecessary npm i --only-prod
Browse files Browse the repository at this point in the history
  • Loading branch information
3cp committed May 14, 2019
1 parent b5f1e31 commit 7a06004
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/skeleton-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs');
const path = require('path');
const {fileExists} = require('./file-exists');
const {fileExists, folderExists} = require('./file-exists');
const {info} = require('./log');
const run = require('./run');

Expand All @@ -19,7 +19,8 @@ module.exports = async function(dir, {
_require = defaultRequire
} = {}) {
const metaFile = path.join(dir, 'package.json');
if (fileExists(metaFile)) {
const nodeModules = path.join(dir, 'node_modules');
if (fileExists(metaFile) && !folderExists(nodeModules)) {
const meta = JSON.parse(fs.readFileSync(metaFile, 'utf8'));
if (meta.dependencies && Object.keys(meta.dependencies).length) {
await _npmInstall(dir);
Expand Down Expand Up @@ -84,6 +85,6 @@ module.exports = async function(dir, {

function npmInstall(dir) {
const cmd = 'npm i --only=prod';
info('Skeleton requires additional dependencies. run ' + cmd);
info('Skeleton requires additional dependencies. Running ' + cmd);
return run(cmd, dir);
}
26 changes: 26 additions & 0 deletions test/skeleton-config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,32 @@ test.serial('skeletonConfig runs npm install when required', async t => {
});
});

test.serial('skeletonConfig does not run npm install when node_modules exists', async t => {
mockfs({
'skeleton/package.json': '{"dependencies":{"foo":"1.0.0"}}',
'skeleton/node_modules': {}
});

let installed;
function npmInstall(dir) {
installed = dir;
}

const result = await config('skeleton', {_npmInstall: npmInstall});
t.falsy(installed);
t.deepEqual(result, {
questions: [{
name: 'name',
message: 'Please name this new project:',
default: 'my-app'
}],
prependTransforms: [],
appendTransforms: [],
before: undefined,
after: undefined
});
});

test.serial('skeletonConfig does not run npm install for devDependencies', async t => {
mockfs({
'skeleton/package.json': '{"devDpendencies":{"foo":"1.0.0"}}'
Expand Down

0 comments on commit 7a06004

Please sign in to comment.