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

committed by
Alex Rickabaugh

parent
544a7ad0a5
commit
2d5ef15e08
@ -265,13 +265,14 @@ export class MetadataCollector {
|
||||
|
||||
const isExportedIdentifier = (identifier: ts.Identifier) => exportMap.has(identifier.text);
|
||||
const isExported =
|
||||
(node: ts.FunctionDeclaration | ts.ClassDeclaration | ts.InterfaceDeclaration | ts.TypeAliasDeclaration |
|
||||
ts.EnumDeclaration) => isExport(node) || isExportedIdentifier(node.name);
|
||||
(node: ts.FunctionDeclaration | ts.ClassDeclaration | ts.InterfaceDeclaration |
|
||||
ts.TypeAliasDeclaration | ts.EnumDeclaration) =>
|
||||
isExport(node) || isExportedIdentifier(node.name);
|
||||
const exportedIdentifierName = (identifier: ts.Identifier) =>
|
||||
exportMap.get(identifier.text) || identifier.text;
|
||||
const exportedName =
|
||||
(node: ts.FunctionDeclaration | ts.ClassDeclaration | ts.InterfaceDeclaration | ts.TypeAliasDeclaration |
|
||||
ts.EnumDeclaration) => exportedIdentifierName(node.name);
|
||||
(node: ts.FunctionDeclaration | ts.ClassDeclaration | ts.InterfaceDeclaration |
|
||||
ts.TypeAliasDeclaration | ts.EnumDeclaration) => exportedIdentifierName(node.name);
|
||||
|
||||
|
||||
// Predeclare classes and functions
|
||||
|
@ -71,7 +71,7 @@ describe('Collector', () => {
|
||||
const sourceFile = program.getSourceFile('/exported-type.ts');
|
||||
const metadata = collector.getMetadata(sourceFile);
|
||||
expect(metadata).toEqual(
|
||||
{__symbolic: 'module', version: 3, metadata: {SomeType: {__symbolic: 'interface'}}});
|
||||
{__symbolic: 'module', version: 3, metadata: {SomeType: {__symbolic: 'interface'}}});
|
||||
});
|
||||
|
||||
it('should return an interface reference for interfaces', () => {
|
||||
|
@ -30,7 +30,7 @@ if (+process.version[1] < 5) {
|
||||
try {
|
||||
semver = require('semver');
|
||||
} catch (e) {
|
||||
issues.push('Looks like you are missing some npm dependencies. Run: npm install');
|
||||
issues.push('Looks like you are missing some npm dependencies. Run: `yarn install`');
|
||||
}
|
||||
|
||||
if (issues.length) {
|
||||
@ -46,7 +46,7 @@ if (issues.length) {
|
||||
try {
|
||||
checkNodeModules = require('./npm/check-node-modules.js');
|
||||
} catch (e) {
|
||||
issues.push('Looks like you are missing some npm dependencies. Run: npm install');
|
||||
issues.push('Looks like you are missing some npm dependencies. Run: `yarn install`');
|
||||
throw e;
|
||||
} finally {
|
||||
// print warnings and move on, the next steps will likely fail, but hey, we warned them.
|
||||
@ -65,46 +65,36 @@ if (require.main === module) {
|
||||
}
|
||||
|
||||
function checkEnvironment(reqs) {
|
||||
exec('npm --version', function(npmErr, npmStdout) {
|
||||
exec('yarn --version', function(yarnErr, yarnStdout) {
|
||||
var foundNodeVersion = process.version;
|
||||
var foundNpmVersion = semver.clean(npmStdout);
|
||||
var foundYarnVersion = !yarnErr && semver.clean(yarnStdout);
|
||||
var issues = [];
|
||||
exec('yarn --version', function(yarnErr, yarnStdout) {
|
||||
var foundNodeVersion = process.version;
|
||||
var foundYarnVersion = !yarnErr && semver.clean(yarnStdout);
|
||||
var issues = [];
|
||||
|
||||
if (!semver.satisfies(foundNodeVersion, reqs.requiredNodeVersion)) {
|
||||
issues.push(
|
||||
'You are running unsupported node version. Found: ' + foundNodeVersion + ' Expected: ' +
|
||||
reqs.requiredNodeVersion + '. Use nvm to update your node version.');
|
||||
}
|
||||
|
||||
if (!semver.satisfies(foundNodeVersion, reqs.requiredNodeVersion)) {
|
||||
issues.push(
|
||||
'You are running unsupported node version. Found: ' + foundNodeVersion + ' Expected: ' +
|
||||
reqs.requiredNodeVersion + '. Use nvm to update your node version.');
|
||||
}
|
||||
if (yarnErr) {
|
||||
issues.push(
|
||||
'You don\'t have yarn globally installed. This is required because we use yarn to ' +
|
||||
'ensure that we all use the exact same npm dependencies. Installation instructions: ' +
|
||||
'https://yarnpkg.com/lang/en/docs/install/');
|
||||
} else if (!semver.satisfies(foundYarnVersion, reqs.requiredYarnVersion)) {
|
||||
issues.push(
|
||||
'You are running an unsupported yarn version. Found: ' + foundYarnVersion +
|
||||
' Expected: ' + reqs.requiredYarnVersion + '. This is required because we use yarn to ' +
|
||||
'ensure that we all use the exact same npm dependencies. Installation instructions: ' +
|
||||
'https://yarnpkg.com/lang/en/docs/install/');
|
||||
}
|
||||
|
||||
if (!semver.satisfies(foundNpmVersion, reqs.requiredNpmVersion)) {
|
||||
issues.push(
|
||||
'You are running unsupported npm version. Found: ' + foundNpmVersion + ' Expected: ' +
|
||||
reqs.requiredNpmVersion + '. Run: npm update -g npm');
|
||||
}
|
||||
if (!checkNodeModules()) {
|
||||
issues.push(
|
||||
'Your node_modules directory is stale or out of sync with yarn.lock. Run: yarn install');
|
||||
}
|
||||
|
||||
if (yarnErr) {
|
||||
issues.push(
|
||||
'You don\'t have yarn globally installed. This is required if you want to work on ' +
|
||||
'certain areas, such as `aio/` and `integration/`. Installation instructions: ' +
|
||||
'https://yarnpkg.com/lang/en/docs/install/');
|
||||
} else if (!semver.satisfies(foundYarnVersion, reqs.requiredYarnVersion)) {
|
||||
issues.push(
|
||||
'You are running unsupported yarn version. Found: ' + foundYarnVersion + ' Expected: ' +
|
||||
reqs.requiredYarnVersion + '. This is required if you want to work on ' +
|
||||
'certain areas, such as `aio/` and `integration/`. See: ' +
|
||||
'https://yarnpkg.com/lang/en/docs/install/');
|
||||
}
|
||||
|
||||
if (!checkNodeModules()) {
|
||||
issues.push(
|
||||
'Your node_modules directory is stale or out of sync with npm-shrinkwrap.json. Run: npm install');
|
||||
}
|
||||
|
||||
printWarning(issues);
|
||||
})
|
||||
printWarning(issues);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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