From fe69b5b110e097a36875a814e14e9acdc843d1ee Mon Sep 17 00:00:00 2001 From: Hans Larsen Date: Tue, 28 Feb 2017 16:13:40 -0800 Subject: [PATCH] ci: add option to ignore imports/requires from dependencies It needs to be in the file itself where the require/import is made. --- packages/@angular/cli/lib/cli/index.js | 1 - .../@ngtools/webpack/src/extract_i18n_plugin.ts | 1 + packages/@ngtools/webpack/src/index.ts | 1 + packages/@ngtools/webpack/src/plugin.ts | 1 + packages/@ngtools/webpack/src/reflector_host.ts | 1 + scripts/publish/validate_dependencies.js | 15 +++++++++++++++ 6 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/@angular/cli/lib/cli/index.js b/packages/@angular/cli/lib/cli/index.js index 3e0f3c056b..41bedb0337 100644 --- a/packages/@angular/cli/lib/cli/index.js +++ b/packages/@angular/cli/lib/cli/index.js @@ -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. diff --git a/packages/@ngtools/webpack/src/extract_i18n_plugin.ts b/packages/@ngtools/webpack/src/extract_i18n_plugin.ts index a8e2f55aee..c3ce93e669 100644 --- a/packages/@ngtools/webpack/src/extract_i18n_plugin.ts +++ b/packages/@ngtools/webpack/src/extract_i18n_plugin.ts @@ -1,3 +1,4 @@ +// @ignoreDep @angular/compiler-cli import * as ts from 'typescript'; import * as path from 'path'; import * as fs from 'fs'; diff --git a/packages/@ngtools/webpack/src/index.ts b/packages/@ngtools/webpack/src/index.ts index 98dfb2e498..1d38f20424 100644 --- a/packages/@ngtools/webpack/src/index.ts +++ b/packages/@ngtools/webpack/src/index.ts @@ -1,3 +1,4 @@ +// @ignoreDep @angular/compiler-cli import * as path from 'path'; let version; diff --git a/packages/@ngtools/webpack/src/plugin.ts b/packages/@ngtools/webpack/src/plugin.ts index e42b33bcd7..60da107cb4 100644 --- a/packages/@ngtools/webpack/src/plugin.ts +++ b/packages/@ngtools/webpack/src/plugin.ts @@ -1,3 +1,4 @@ +// @ignoreDep @angular/compiler-cli import * as fs from 'fs'; import * as path from 'path'; import * as ts from 'typescript'; diff --git a/packages/@ngtools/webpack/src/reflector_host.ts b/packages/@ngtools/webpack/src/reflector_host.ts index 7b0492ff02..7381010b11 100644 --- a/packages/@ngtools/webpack/src/reflector_host.ts +++ b/packages/@ngtools/webpack/src/reflector_host.ts @@ -1,3 +1,4 @@ +// @ignoreDep @angular/compiler-cli import {CodeGenerator} from '@angular/compiler-cli'; diff --git a/scripts/publish/validate_dependencies.js b/scripts/publish/validate_dependencies.js index ae69faca13..04e340cfcc 100644 --- a/scripts/publish/validate_dependencies.js +++ b/scripts/publish/validate_dependencies.js @@ -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)