build: switch from npm to yarn
This commit is contained in:

committed by
Alex Rickabaugh

parent
544a7ad0a5
commit
2d5ef15e08
@ -10,16 +10,17 @@
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var childProcess = require('child_process');
|
||||
|
||||
var NPM_SHRINKWRAP_FILE = 'npm-shrinkwrap.json';
|
||||
var NPM_SHRINKWRAP_CACHED_FILE = 'node_modules/.npm-shrinkwrap.cached.json';
|
||||
var FS_OPTS = {encoding: 'utf-8'};
|
||||
var PROJECT_ROOT = path.join(__dirname, '../../');
|
||||
|
||||
|
||||
function checkNodeModules(logOutput, purgeIfStale) {
|
||||
var nodeModulesOK = _checkCache(NPM_SHRINKWRAP_FILE, NPM_SHRINKWRAP_CACHED_FILE);
|
||||
var yarnCheck = childProcess.spawnSync(
|
||||
'./node_modules/.bin/yarn check --integrity',
|
||||
{shell: true, cwd: path.resolve(__dirname, '../..')});
|
||||
|
||||
var nodeModulesOK = yarnCheck.status === 0;
|
||||
if (nodeModulesOK) {
|
||||
if (logOutput) console.log(':-) npm dependencies are looking good!');
|
||||
} else {
|
||||
@ -34,20 +35,6 @@ function checkNodeModules(logOutput, purgeIfStale) {
|
||||
}
|
||||
|
||||
|
||||
function _checkCache(markerFile, cacheMarkerFile) {
|
||||
var absoluteMarkerFilePath = path.join(PROJECT_ROOT, markerFile);
|
||||
var absoluteCacheMarkerFilePath = path.join(PROJECT_ROOT, cacheMarkerFile);
|
||||
|
||||
|
||||
if (!fs.existsSync(absoluteCacheMarkerFilePath)) return false;
|
||||
|
||||
var markerContent = fs.readFileSync(absoluteMarkerFilePath, FS_OPTS);
|
||||
var cacheMarkerContent = fs.readFileSync(absoluteCacheMarkerFilePath, FS_OPTS);
|
||||
|
||||
return markerContent == cacheMarkerContent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Custom implementation of recursive `rm` because we can't rely on the state of node_modules to
|
||||
* pull in existing module.
|
||||
|
@ -1,43 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* this script is just a temporary solution to deal with the issue of npm outputting the npm
|
||||
* shrinkwrap file in an unstable manner.
|
||||
*
|
||||
* See: https://github.com/npm/npm/issues/3581
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
|
||||
function cleanModule(moduleRecord) {
|
||||
// keep `resolve` properties for git dependencies, delete otherwise
|
||||
delete moduleRecord.from;
|
||||
if (!(moduleRecord.resolved && moduleRecord.resolved.match(/^git(\+[a-z]+)?:\/\//))) {
|
||||
delete moduleRecord.resolved;
|
||||
}
|
||||
|
||||
if (moduleRecord.dependencies) {
|
||||
Object.keys(moduleRecord.dependencies)
|
||||
.forEach((name) => cleanModule(moduleRecord.dependencies[name]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// console.log('Reading npm-shrinkwrap.json');
|
||||
const shrinkwrap = require('../../npm-shrinkwrap.json');
|
||||
|
||||
// console.log('Cleaning shrinkwrap object');
|
||||
cleanModule(shrinkwrap);
|
||||
|
||||
const cleanShrinkwrapPath = path.join(__dirname, '..', '..', 'npm-shrinkwrap.clean.json');
|
||||
console.log('writing npm-shrinkwrap.clean.json');
|
||||
fs.writeFileSync(cleanShrinkwrapPath, JSON.stringify(shrinkwrap, null, 2) + '\n');
|
@ -1,18 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var fs = require('fs');
|
||||
var fse = require('fs-extra');
|
||||
var path = require('path');
|
||||
|
||||
var NPM_SHRINKWRAP_FILE = 'npm-shrinkwrap.json';
|
||||
var NPM_SHRINKWRAP_CACHED_FILE = 'node_modules/.npm-shrinkwrap.cached.json';
|
||||
var PROJECT_ROOT = path.join(__dirname, '../../');
|
||||
|
||||
process.chdir(PROJECT_ROOT);
|
||||
|
||||
if (fs.existsSync(NPM_SHRINKWRAP_FILE)) {
|
||||
console.log('copying shrinkwrap fingerprint to', NPM_SHRINKWRAP_CACHED_FILE);
|
||||
fse.copySync(NPM_SHRINKWRAP_FILE, NPM_SHRINKWRAP_CACHED_FILE);
|
||||
} else {
|
||||
console.warn(`${NPM_SHRINKWRAP_FILE} not found. Copy operation will be skipped.`);
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
let childProcess = require('child_process');
|
||||
|
||||
childProcess.spawn('npm', ['shrinkwrap', '--dev'], {stdio: 'inherit'}).on('exit', (exitCode) => {
|
||||
if (exitCode !== 0) return;
|
||||
|
||||
childProcess.fork('./tools/npm/clean-shrinkwrap.js').on('exit', (exitCode) => {
|
||||
if (exitCode !== 0) return;
|
||||
|
||||
childProcess.fork('./tools/npm/copy-npm-shrinkwrap');
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user