Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(@angular/cli): add option to ignore files #7448

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/documentation/angular-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
- *baseHref* (`string`): Base url for the application being built.
- *progress* (`boolean`): Log progress to the console while building. Default is `true`.
- *poll* (`number`): Enable and define the file watching poll time period (milliseconds).
- *ignored* (`string|array`): Avoid rebuilding files when files matching this [anymatch](https://github.com/es128/anymatch) pattern fails.
- *deleteOutputPath* (`boolean`): Delete output path before build. Default is `true`.
- *preserveSymlinks* (`boolean`): Do not use the real path when resolving modules. Default is `false`.
- *showCircularDependencies* (`boolean`): Show circular dependency warnings on builds. Default is `true`.
Expand Down
8 changes: 7 additions & 1 deletion packages/@angular/cli/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Command = require('../ember-cli/lib/models/command');
const config = CliConfig.fromProject() || CliConfig.fromGlobal();
const buildConfigDefaults = config.getPaths('defaults.build', [
'sourcemaps', 'baseHref', 'progress', 'poll', 'deleteOutputPath', 'preserveSymlinks',
'showCircularDependencies', 'commonChunk', 'namedChunks'
'showCircularDependencies', 'commonChunk', 'namedChunks', 'ignored'
]);

// defaults for BuildOptions
Expand Down Expand Up @@ -131,6 +131,12 @@ export const baseBuildCommandOptions: any = [
description: 'Enable and define the file watching poll time period (milliseconds).',
default: buildConfigDefaults['poll']
},
{
name: 'ignored',
type: String,
description: 'Avoid rebuilding files when files matching this anymatch pattern fails.',
default: buildConfigDefaults['ignored']
},
{
name: 'app',
type: String,
Expand Down
1 change: 1 addition & 0 deletions packages/@angular/cli/custom-typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface IWebpackDevServerConfigurationOptions {
filename?: string;
watchOptions?: {
aggregateTimeout?: number;
ignored?: string | string[];
poll?: number;
};
publicPath?: string;
Expand Down
14 changes: 14 additions & 0 deletions packages/@angular/cli/lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,20 @@
"description": "Enable and define the file watching poll time period (milliseconds).",
"type": "number"
},
"ignored": {
"description": "Avoid rebuilding files when files matching this anymatch pattern fails.",
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"deleteOutputPath": {
"description": "Delete output path before build.",
"type": "boolean",
Expand Down
1 change: 1 addition & 0 deletions packages/@angular/cli/models/build-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface BuildOptions {
extractCss?: boolean;
watch?: boolean;
outputHashing?: string;
ignored?: string | string[];
poll?: number;
app?: string;
deleteOutputPath?: boolean;
Expand Down
1 change: 1 addition & 0 deletions packages/@angular/cli/tasks/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export default Task.extend({
proxy: proxyConfig,
compress: serveTaskOptions.target === 'production',
watchOptions: {
ignored: serveTaskOptions.ignored,
poll: serveTaskOptions.poll
},
https: serveTaskOptions.ssl,
Expand Down
72 changes: 72 additions & 0 deletions tests/e2e/tests/build/ignored.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import {
killAllProcesses,
waitForAnyProcessOutputToMatch
} from '../../utils/process';
import { readFile, writeFile } from '../../utils/fs';
import { expectToFail } from '../../utils/utils';
import { ngServe, updateJsonFile, useCIDefaults } from '../../utils/project';

const webpackGoodRegEx = /webpack: Compiled successfully./;
const shouldCompile = () => waitForAnyProcessOutputToMatch(webpackGoodRegEx, 10000);
const shouldNotCompile = () => expectToFail(shouldCompile);

const touch = (fileName: string) => readFile(fileName)
.then(
(content: string) => writeFile(fileName, content.concat('console.log(1);')),
error => writeFile(fileName, 'console.log(1);')
);

const updateIgnoredConfig = (ignored: string | string[]) => updateJsonFile(
'.angular-cli.json',
({ defaults }) => {
const { build = {} } = defaults;
defaults.build = { ...build, ignored };
}
);

export default function() {
return Promise.resolve()
// Can specify an array of ignored options via the config
.then(() => updateIgnoredConfig([ '**/*~', '**/.*.sw[pon]' ])
.then(() => ngServe())
.then(() => touch('src/main.ts')).then(shouldCompile)
.then(() => touch('src/main.ts~')).then(shouldNotCompile)
.then(() => touch('src/.main.ts.swp')).then(shouldNotCompile)
.then(() => touch('src/.main.ts.swo')).then(shouldNotCompile)
.then(() => touch('src/.main.ts.swn')).then(shouldNotCompile)
.then(() => touch('src/main.ts')).then(shouldCompile)
.then(() => killAllProcesses())

// Can specify a single ignored option via the config
.then(() => updateIgnoredConfig('**/*~')
.then(() => ngServe())
.then(() => touch('src/main.ts')).then(shouldCompile)
.then(() => touch('src/main.ts~')).then(shouldNotCompile)
.then(() => touch('src/.main.ts.swp')).then(shouldCompile)
.then(() => touch('src/.main.ts.swo')).then(shouldCompile)
.then(() => touch('src/.main.ts.swn')).then(shouldCompile)
.then(() => touch('src/main.ts')).then(shouldCompile)
.then(() => killAllProcesses())

// Can specify a single ignored option via the command line
.then(() => useCIDefaults())
.then(() => ngServe('--ignored', '**/.*.sw[po]'))
.then(() => touch('src/main.ts')).then(shouldCompile)
.then(() => touch('src/main.ts~')).then(shouldCompile)
.then(() => touch('src/.main.ts.swp')).then(shouldNotCompile)
.then(() => touch('src/.main.ts.swo')).then(shouldNotCompile)
.then(() => touch('src/.main.ts.swn')).then(shouldCompile)
.then(() => touch('src/main.ts')).then(shouldCompile)
.then(() => killAllProcesses())

// Compiles on every file change by default
.then(() => useCIDefaults())
.then(() => ngServe())
.then(() => touch('src/main.ts')).then(shouldCompile)
.then(() => touch('src/main.ts~')).then(shouldCompile)
.then(() => touch('src/.main.ts.swp')).then(shouldCompile)
.then(() => touch('src/.main.ts.swo')).then(shouldCompile)
.then(() => touch('src/.main.ts.swn')).then(shouldCompile)
.then(() => touch('src/main.ts')).then(shouldCompile)
.then(() => killAllProcesses(), err => { killAllProcesses(); throw err; });
}