ci: add option to ignore imports/requires from dependencies

It needs to be in the file itself where the require/import is made.
This commit is contained in:
Hans Larsen 2017-02-28 16:13:40 -08:00 committed by Hans
parent b965a49a49
commit fe69b5b110
6 changed files with 19 additions and 1 deletions

View File

@ -3,7 +3,6 @@
// Prevent the dependency validation from tripping because we don't import these. We need
// it as a peer dependency of @angular/core.
// require('zone.js')
// require('@angular/tsc-wrapped')
// This file hooks up on require calls to transpile TypeScript.

View File

@ -1,3 +1,4 @@
// @ignoreDep @angular/compiler-cli
import * as ts from 'typescript';
import * as path from 'path';
import * as fs from 'fs';

View File

@ -1,3 +1,4 @@
// @ignoreDep @angular/compiler-cli
import * as path from 'path';
let version;

View File

@ -1,3 +1,4 @@
// @ignoreDep @angular/compiler-cli
import * as fs from 'fs';
import * as path from 'path';
import * as ts from 'typescript';

View File

@ -1,3 +1,4 @@
// @ignoreDep @angular/compiler-cli
import {CodeGenerator} from '@angular/compiler-cli';

View File

@ -11,6 +11,7 @@ const path = require('path');
const IMPORT_RE = /(^|\n)\s*import\b(?:.|\n)*?\'[^\']*\'/g;
const REQUIRE_RE = /\brequire\('[^)]+?'\)/g;
const IGNORE_RE = /\s+@ignoreDep\s+\S+/g;
const NODE_PACKAGES = [
'child_process',
'fs',
@ -72,6 +73,16 @@ function listRequiredModules(source) {
});
}
function listIgnoredModules(source) {
const ignored = source.match(IGNORE_RE);
return (ignored || [])
.map(match => {
const m = match.match(/@ignoreDep\s+(\S+)/);
return m && m[1];
})
.filter(x => !!x);
}
function reportMissingDependencies(missingDeps) {
if (missingDeps.length == 0) {
console.log(chalk.green(' no dependency missing from package.json.'));
@ -110,6 +121,10 @@ for (const packageName of Object.keys(packages)) {
.forEach(modulePath => importMap[modulePath] = true);
listRequiredModules(source)
.forEach(modulePath => importMap[modulePath] = true);
listIgnoredModules(source)
.forEach(modulePath => {
delete importMap[modulePath];
});
});
const dependencies = Object.keys(importMap)