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

feat(build): add --poll option to build/serve/test commands #4268

Closed
wants to merge 2 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/documentation/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,5 @@ or `ng serve --prod` will also make use of uglifying and tree-shaking functional
`--output-hashing` define the output filename cache-busting hashing mode

`--stats-json` generates a `stats.json` file which can be analyzed using tools such as: `webpack-bundle-analyzer` or https://webpack.github.io/analyse

`--poll` enable and define the file watching poll time period (milliseconds)
2 changes: 2 additions & 0 deletions docs/documentation/serve.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@
`--extract-css` (`-ec`) extract css from global styles onto css files instead of js ones

`--output-hashing` define the output filename cache-busting hashing mode

`--poll` enable and define the file watching poll time period (milliseconds)
2 changes: 2 additions & 0 deletions docs/documentation/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ You can run tests with coverage via `--code-coverage`. The coverage report will
`--reporters` list of reporters to use

`--build` flag to build prior to running tests

`--poll` enable and define the file watching poll time period (milliseconds)
10 changes: 10 additions & 0 deletions packages/@angular/cli/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { CliConfig } from '../models/config';
import { BuildOptions } from '../models/build-options';
import { Version } from '../upgrade/version';

const Command = require('../ember-cli/lib/models/command');

const config = CliConfig.fromProject() || CliConfig.fromGlobal();
const pollDefault = config.config.defaults && config.config.defaults.poll;

// defaults for BuildOptions
export const baseBuildCommandOptions: any = [
{
Expand Down Expand Up @@ -32,6 +36,12 @@ export const baseBuildCommandOptions: any = [
aliases: ['oh']
},
{ name: 'stats-json', type: Boolean, default: false },
{
name: 'poll',
type: Number,
default: pollDefault,
description: 'enable and define the file watching poll time period (milliseconds)'
}
];

export interface BuildTaskOptions extends BuildOptions {
Expand Down
12 changes: 11 additions & 1 deletion packages/@angular/cli/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ const EmberTestCommand = require('../ember-cli/lib/commands/test');
import TestTask from '../tasks/test';
import {CliConfig} from '../models/config';

const config = CliConfig.fromProject() || CliConfig.fromGlobal();
const pollDefault = config.config.defaults && config.config.defaults.poll;

export interface TestOptions {
watch?: boolean;
codeCoverage?: boolean;
Expand All @@ -15,6 +18,7 @@ export interface TestOptions {
sourcemap?: boolean;
progress?: boolean;
config: string;
poll?: number;
}


Expand All @@ -31,7 +35,13 @@ const TestCommand = EmberTestCommand.extend({
{ name: 'port', type: Number },
{ name: 'reporters', type: String },
{ name: 'build', type: Boolean, default: true },
{ name: 'sourcemap', type: Boolean, default: true, aliases: ['sm'] }
{ name: 'sourcemap', type: Boolean, default: true, aliases: ['sm'] },
{
name: 'poll',
type: Number,
default: pollDefault,
description: 'enable and define the file watching poll time period (milliseconds)'
}
],

run: function(commandOptions: TestOptions) {
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 @@ -14,4 +14,5 @@ export interface BuildOptions {
locale?: string;
extractCss?: boolean;
outputHashing?: string;
poll?: number;
}
3 changes: 1 addition & 2 deletions packages/@angular/cli/plugins/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const path = require('path');
const fs = require('fs');

const getTestConfig = require('../models/webpack-configs/test').getTestConfig;
const CliConfig = require('../models/config').CliConfig;

function isDirectory(path) {
try {
Expand Down Expand Up @@ -81,7 +80,7 @@ const init = (config) => {
chunkModules: false
},
watchOptions: {
poll: CliConfig.fromProject().config.defaults.poll
poll: config.angularCli.poll
}
};

Expand Down
2 changes: 1 addition & 1 deletion packages/@angular/cli/tasks/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default Task.extend({
};

if (runTaskOptions.watch) {
webpackCompiler.watch({}, callback);
webpackCompiler.watch({ poll: runTaskOptions.poll }, callback);
} else {
webpackCompiler.run(callback);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@angular/cli/tasks/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default Task.extend({
proxy: proxyConfig,
compress: serveTaskOptions.target === 'production',
watchOptions: {
poll: projectConfig.defaults && projectConfig.defaults.poll
poll: serveTaskOptions.poll
},
https: serveTaskOptions.ssl,
overlay: serveTaskOptions.target === 'development'
Expand Down
3 changes: 2 additions & 1 deletion packages/@angular/cli/tasks/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export default Task.extend({
karmaOptions.angularCli = {
codeCoverage: options.codeCoverage,
sourcemap: options.sourcemap,
progress: options.progress
progress: options.progress,
poll: options.poll
};

// Assign additional karmaConfig options to the local ngapp config
Expand Down
27 changes: 27 additions & 0 deletions tests/e2e/tests/build/poll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { appendToFile } from '../../utils/fs';
import {
killAllProcesses,
waitForAnyProcessOutputToMatch,
silentExecAndWaitForOutputToMatch
} from '../../utils/process';
import {expectToFail, wait} from '../../utils/utils';

const webpackGoodRegEx = /webpack: Compiled successfully./;

export default function() {
return silentExecAndWaitForOutputToMatch('ng', ['serve', '--poll=10000'], webpackGoodRegEx)
// Wait before editing a file.
// Editing too soon seems to trigger a rebuild and throw polling out of whack.
// .then(() => wait(1000))
// .then(() => appendToFile('src/main.ts', 'console.log(1);'))
.then(() => waitForAnyProcessOutputToMatch(webpackGoodRegEx, 12000))
.then(() => appendToFile('src/main.ts', 'console.log(1);'))
// No rebuilds should occur for a while
.then(() => expectToFail(() => waitForAnyProcessOutputToMatch(webpackGoodRegEx, 6000)))
// But a rebuild should happen roughly within the 10 second window.
.then(() => waitForAnyProcessOutputToMatch(webpackGoodRegEx, 12000))
.then(() => killAllProcesses(), (err: any) => {
killAllProcesses();
throw err;
});
}