fix(npm): Run npm install with —ignore-scripts

This commit is contained in:
Rhys Arkins 2017-07-24 06:54:13 +02:00
parent cd762c7bc6
commit 2bd452281f
2 changed files with 17 additions and 7 deletions

View file

@ -68,7 +68,6 @@ async function ensureBranch(config) {
const commitMessage = handlebars.compile(config.commitMessage)(config); const commitMessage = handlebars.compile(config.commitMessage)(config);
const api = config.api; const api = config.api;
const versions = config.versions;
const cacheFolder = config.yarnCacheFolder; const cacheFolder = config.yarnCacheFolder;
const packageFiles = {}; const packageFiles = {};
const commitFiles = []; const commitFiles = [];
@ -144,7 +143,7 @@ async function ensureBranch(config) {
packageFiles[packageFile], packageFiles[packageFile],
api, api,
config.versions.npm, config.versions.npm,
versions.npm logger
); );
if (packageLockFile) { if (packageLockFile) {
// Add new package-lock.json file too // Add new package-lock.json file too

View file

@ -1,9 +1,10 @@
const logger = require('../../logger');
const fs = require('fs'); const fs = require('fs');
const cp = require('child_process'); const cp = require('child_process');
const tmp = require('tmp'); const tmp = require('tmp');
const path = require('path'); const path = require('path');
let logger = require('../../logger');
module.exports = { module.exports = {
generateLockFile, generateLockFile,
getLockFile, getLockFile,
@ -20,12 +21,14 @@ async function generateLockFile(newPackageJson, npmrcContent) {
fs.writeFileSync(path.join(tmpDir.name, '.npmrc'), npmrcContent); fs.writeFileSync(path.join(tmpDir.name, '.npmrc'), npmrcContent);
} }
logger.debug('Spawning npm install'); logger.debug('Spawning npm install');
const result = cp.spawnSync('npm', ['install'], { const result = cp.spawnSync('npm', ['install', '--ignore-scripts'], {
cwd: tmpDir.name, cwd: tmpDir.name,
shell: true, shell: true,
}); });
logger.debug(String(result.stdout)); logger.debug(
logger.debug(String(result.stderr)); { stdout: String(result.stdout), stderr: String(result.stderr) },
'npm install complete'
);
packageLock = fs.readFileSync(path.join(tmpDir.name, 'package-lock.json')); packageLock = fs.readFileSync(path.join(tmpDir.name, 'package-lock.json'));
} catch (error) /* istanbul ignore next */ { } catch (error) /* istanbul ignore next */ {
try { try {
@ -43,7 +46,14 @@ async function generateLockFile(newPackageJson, npmrcContent) {
return packageLock; return packageLock;
} }
async function getLockFile(packageFile, packageContent, api, npmVersion) { async function getLockFile(
packageFile,
packageContent,
api,
npmVersion,
parentLogger
) {
logger = parentLogger || logger;
// Detect if a package-lock.json file is in use // Detect if a package-lock.json file is in use
const packageLockFileName = path.join( const packageLockFileName = path.join(
path.dirname(packageFile), path.dirname(packageFile),
@ -78,6 +88,7 @@ async function getLockFile(packageFile, packageContent, api, npmVersion) {
} }
async function maintainLockFile(inputConfig) { async function maintainLockFile(inputConfig) {
logger = inputConfig.logger || logger;
logger.trace({ config: inputConfig }, `maintainLockFile`); logger.trace({ config: inputConfig }, `maintainLockFile`);
const packageContent = await inputConfig.api.getFileContent( const packageContent = await inputConfig.api.getFileContent(
inputConfig.packageFile inputConfig.packageFile