From ae9f4d79247a0d56dfa5347c49e1578d3344ef88 Mon Sep 17 00:00:00 2001 From: brandonocasey Date: Thu, 13 Sep 2018 11:12:39 -0400 Subject: [PATCH] use npm ci --- generators/app/index.js | 22 +++++++++++++++++++++- scripts/run-integration-tests.js | 6 ++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/generators/app/index.js b/generators/app/index.js index 4dad3d32..dec6d758 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -10,6 +10,7 @@ const constants = require('./constants'); const naming = require('./naming'); const packageJSON = require('./package-json'); const validators = require('./validators'); +const spawnSync = require('child_process').spawnSync; module.exports = class extends Generator { @@ -327,7 +328,26 @@ module.exports = class extends Generator { * we don't want to run that (or depend on it in any way). */ install() { - this.npmInstall(); + const result = spawnSync('npm', ['--version']); + + // no access to npm uh oh, lets let yeoman throw an error + if (result.status !== 0) { + return this.npmInstall(); + } + + // get the major version for npm + const major = parseFloat(result.stdout.toString().trim().split('.')[0]); + + if (!major || major <= 5) { + return this.npmInstall(); + } + + // if we are on npm greater than 6 + // save time by updating package-lock-only + // and then running npm ci + spawnSync('npm', ['i', '--package-lock-only'], {stdio: 'inherit', cwd: this.destinationRoot()}); + spawnSync('npm', ['ci'], {stdio: 'inherit', cwd: this.destinationRoot()}); + } /** diff --git a/scripts/run-integration-tests.js b/scripts/run-integration-tests.js index 82f73501..4d072395 100644 --- a/scripts/run-integration-tests.js +++ b/scripts/run-integration-tests.js @@ -12,8 +12,9 @@ let tempDir; helpers.run(libs.GENERATOR_PATH) .inTmpDir(function(dir) { tempDir = dir; + console.log(`Generating Project in ${tempDir}`); }) - .withOptions(libs.options()) + .withOptions(Object.assign(libs.options(), {skipInstall: false})) .withPrompts({ name: 'integration-test', author: 'John Doe', @@ -46,9 +47,6 @@ helpers.run(libs.GENERATOR_PATH) const commands = [ ['git', 'init'], - // mimics yeoman install command - ['npm', 'install', '--cache-min', '86400'], - ['npm', 'ci'], ['git', 'add', '--all'], ['git', 'commit', '-a', '-m', 'feat: initial release!'], ['npm', 'version', 'prerelease'],