@angular-devkit/build-angular 0.1101.0-next.2 → 0.1101.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/package.json +28 -28
  2. package/src/babel/babel-loader.d.ts +24 -0
  3. package/src/babel/presets/application.d.ts +2 -1
  4. package/src/babel/presets/application.js +30 -0
  5. package/src/babel/webpack-loader.d.ts +2 -0
  6. package/src/babel/webpack-loader.js +114 -0
  7. package/src/browser/index.js +3 -4
  8. package/src/browser/schema.d.ts +9 -6
  9. package/src/browser/schema.json +4 -4
  10. package/src/browser/tests/setup.d.ts +18 -0
  11. package/src/browser/tests/setup.js +20 -0
  12. package/src/dev-server/schema.d.ts +9 -8
  13. package/src/dev-server/schema.json +4 -4
  14. package/src/extract-i18n/index.js +24 -1
  15. package/src/extract-i18n/schema.d.ts +2 -0
  16. package/src/extract-i18n/schema.js +2 -0
  17. package/src/extract-i18n/schema.json +6 -2
  18. package/src/karma/schema.d.ts +4 -2
  19. package/src/karma/schema.json +1 -1
  20. package/src/server/index.js +1 -1
  21. package/src/server/schema.d.ts +6 -4
  22. package/src/server/schema.json +2 -2
  23. package/src/testing/builder-harness.d.ts +50 -0
  24. package/src/testing/builder-harness.js +307 -0
  25. package/src/testing/file-watching.d.ts +19 -0
  26. package/src/testing/file-watching.js +34 -0
  27. package/src/testing/index.d.ts +9 -0
  28. package/src/testing/index.js +5 -0
  29. package/src/testing/jasmine-helpers.d.ts +26 -0
  30. package/src/testing/jasmine-helpers.js +86 -0
  31. package/src/utils/build-options.d.ts +2 -2
  32. package/src/utils/load-translations.js +3 -0
  33. package/src/utils/webpack-browser-config.js +12 -2
  34. package/src/webpack/configs/browser.js +1 -1
  35. package/src/webpack/configs/common.js +14 -30
  36. package/src/webpack/configs/styles.js +3 -0
  37. package/src/webpack/es5-polyfills.js +7 -0
  38. package/src/webpack/plugins/builder-watch-plugin.d.ts +51 -0
  39. package/src/webpack/plugins/builder-watch-plugin.js +103 -0
  40. package/src/webpack/plugins/hmr/hmr-accept.js +4 -0
  41. package/src/webpack/plugins/karma.d.ts +0 -7
  42. package/src/webpack/plugins/karma.js +14 -23
@@ -68,7 +68,7 @@ export interface BuildOptions {
68
68
  fileReplacements: NormalizedFileReplacement[];
69
69
  experimentalRollupPass?: boolean;
70
70
  allowedCommonJsDependencies?: string[];
71
- differentialLoadingMode?: boolean;
71
+ differentialLoadingNeeded?: boolean;
72
72
  }
73
73
  export interface WebpackTestOptions extends BuildOptions {
74
74
  codeCoverage?: boolean;
@@ -84,5 +84,5 @@ export interface WebpackConfigOptions<T = BuildOptions> {
84
84
  buildOptions: T;
85
85
  tsConfig: ParsedConfiguration;
86
86
  tsConfigPath: string;
87
- supportES2015: boolean;
87
+ scriptTarget: import('typescript').ScriptTarget;
88
88
  }
@@ -51,6 +51,9 @@ async function importParsers() {
51
51
  const localizeDiag = await Promise.resolve().then(() => require('@angular/localize/src/tools/src/diagnostics'));
52
52
  const diagnostics = new localizeDiag.Diagnostics();
53
53
  const parsers = {
54
+ arb: new (await Promise.resolve().then(() => require(
55
+ // tslint:disable-next-line:trailing-comma
56
+ '@angular/localize/src/tools/src/translate/translation_files/translation_parsers/arb_translation_parser'))).ArbTranslationParser(),
54
57
  json: new (await Promise.resolve().then(() => require(
55
58
  // tslint:disable-next-line:trailing-comma
56
59
  '@angular/localize/src/tools/src/translate/translation_files/translation_parsers/simple_json_translation_parser'))).SimpleJsonTranslationParser(),
@@ -7,6 +7,7 @@ const path = require("path");
7
7
  const webpack_merge_1 = require("webpack-merge");
8
8
  const utils_1 = require("../utils");
9
9
  const read_tsconfig_1 = require("../utils/read-tsconfig");
10
+ const builder_watch_plugin_1 = require("../webpack/plugins/builder-watch-plugin");
10
11
  const helpers_1 = require("../webpack/utils/helpers");
11
12
  const environment_options_1 = require("./environment-options");
12
13
  const i18n_options_1 = require("./i18n-options");
@@ -40,7 +41,7 @@ async function generateWebpackConfig(workspaceRoot, projectRoot, sourceRoot, opt
40
41
  buildOptions,
41
42
  tsConfig,
42
43
  tsConfigPath,
43
- supportES2015,
44
+ scriptTarget,
44
45
  };
45
46
  wco.buildOptions.progress = utils_1.defaultProgress(wco.buildOptions.progress);
46
47
  const webpackConfig = webpack_merge_1.merge(webpackPartialGenerator(wco));
@@ -62,7 +63,7 @@ async function generateWebpackConfig(workspaceRoot, projectRoot, sourceRoot, opt
62
63
  }
63
64
  }
64
65
  if (environment_options_1.profilingEnabled) {
65
- const esVersionInFileName = helpers_1.getEsVersionForFileName(tsConfig.options.target, buildOptions.differentialLoadingMode);
66
+ const esVersionInFileName = helpers_1.getEsVersionForFileName(tsConfig.options.target, buildOptions.differentialLoadingNeeded);
66
67
  const SpeedMeasurePlugin = await Promise.resolve().then(() => require('speed-measure-webpack-plugin'));
67
68
  const smp = new SpeedMeasurePlugin({
68
69
  outputFormat: 'json',
@@ -135,6 +136,15 @@ async function generateBrowserWebpackConfigFromContext(options, context, webpack
135
136
  : undefined;
136
137
  const normalizedOptions = utils_1.normalizeBrowserSchema(host, workspaceRoot, projectRoot, sourceRoot, options);
137
138
  const config = await generateWebpackConfig(core_1.getSystemPath(workspaceRoot), core_1.getSystemPath(projectRoot), sourceRoot && core_1.getSystemPath(sourceRoot), normalizedOptions, webpackPartialGenerator, context.logger, extraBuildOptions);
139
+ // If builder watch support is present in the context, add watch plugin
140
+ // This is internal only and currently only used for testing
141
+ const watcherFactory = context.watcherFactory;
142
+ if (watcherFactory) {
143
+ if (!config.plugins) {
144
+ config.plugins = [];
145
+ }
146
+ config.plugins.push(new builder_watch_plugin_1.BuilderWatchPlugin(watcherFactory));
147
+ }
138
148
  return {
139
149
  config,
140
150
  projectRoot: core_1.getSystemPath(projectRoot),
@@ -28,7 +28,7 @@ function getBrowserConfig(wco) {
28
28
  }));
29
29
  }
30
30
  if (scriptsSourceMap || stylesSourceMap) {
31
- extraPlugins.push(helpers_1.getSourceMapDevTool(scriptsSourceMap, stylesSourceMap, buildOptions.differentialLoadingMode ? true : hiddenSourceMap, false));
31
+ extraPlugins.push(helpers_1.getSourceMapDevTool(scriptsSourceMap, stylesSourceMap, buildOptions.differentialLoadingNeeded && !buildOptions.watch ? true : hiddenSourceMap, false));
32
32
  }
33
33
  let crossOriginLoading = false;
34
34
  if (subresourceIntegrity && crossOrigin === 'none') {
@@ -35,7 +35,7 @@ function getCommonConfig(wco) {
35
35
  const entryPoints = {};
36
36
  // determine hashing format
37
37
  const hashFormat = helpers_1.getOutputHashFormat(buildOptions.outputHashing || 'none');
38
- const targetInFileName = helpers_1.getEsVersionForFileName(tsConfig.options.target, buildOptions.differentialLoadingMode);
38
+ const targetInFileName = helpers_1.getEsVersionForFileName(tsConfig.options.target, buildOptions.differentialLoadingNeeded);
39
39
  if (buildOptions.main) {
40
40
  const mainPath = path.resolve(root, buildOptions.main);
41
41
  entryPoints['main'] = [mainPath];
@@ -78,7 +78,7 @@ function getCommonConfig(wco) {
78
78
  });
79
79
  }
80
80
  }
81
- const differentialLoadingMode = buildOptions.differentialLoadingMode;
81
+ const differentialLoadingMode = buildOptions.differentialLoadingNeeded && !buildOptions.watch;
82
82
  if (platform !== 'server') {
83
83
  if (differentialLoadingMode || tsConfig.options.target === typescript_1.ScriptTarget.ES5) {
84
84
  const buildBrowserFeatures = new utils_1.BuildBrowserFeatures(projectRoot);
@@ -439,35 +439,19 @@ function getCommonConfig(wco) {
439
439
  sideEffects: true,
440
440
  },
441
441
  {
442
- test: /\.m?js$/,
443
- exclude: [/[\/\\](?:core-js|\@babel|tslib)[\/\\]/, /(ngfactory|ngstyle)\.js$/],
442
+ test: /\.[cm]?js$/,
443
+ exclude: [/[\/\\](?:core-js|\@babel|tslib|web-animations-js)[\/\\]/, /(ngfactory|ngstyle)\.js$/],
444
444
  use: [
445
- ...(wco.supportES2015
446
- ? []
447
- : [
448
- {
449
- loader: require.resolve('babel-loader'),
450
- options: {
451
- babelrc: false,
452
- configFile: false,
453
- compact: false,
454
- cacheCompression: false,
455
- cacheDirectory: cache_path_1.findCachePath('babel-webpack'),
456
- cacheIdentifier: JSON.stringify({
457
- buildAngular: require('../../../package.json').version,
458
- }),
459
- sourceType: 'unambiguous',
460
- presets: [
461
- [
462
- require.resolve('../../babel/presets/application'),
463
- {
464
- forceES5: true,
465
- },
466
- ],
467
- ],
468
- },
469
- },
470
- ]),
445
+ {
446
+ loader: require.resolve('../../babel/webpack-loader'),
447
+ options: {
448
+ cacheDirectory: cache_path_1.findCachePath('babel-webpack'),
449
+ cacheIdentifier: JSON.stringify({
450
+ buildAngular: require('../../../package.json').version,
451
+ }),
452
+ scriptTarget: wco.scriptTarget,
453
+ },
454
+ },
471
455
  ...buildOptimizerUseRule,
472
456
  ],
473
457
  },
@@ -40,6 +40,9 @@ function getStylesConfig(wco) {
40
40
  }
41
41
  catch (_a) { }
42
42
  }
43
+ if (!buildOptions.preserveSymlinks) {
44
+ resolvedPath = fs.realpathSync(resolvedPath);
45
+ }
43
46
  // Add style entry points.
44
47
  if (entryPoints[style.bundleName]) {
45
48
  entryPoints[style.bundleName].push(resolvedPath);
@@ -32,6 +32,10 @@ import 'core-js/modules/es.object.assign';
32
32
  import 'core-js/modules/es.object.is';
33
33
  import 'core-js/modules/es.object.set-prototype-of';
34
34
  import 'core-js/modules/es.object.to-string';
35
+ import 'core-js/modules/es.object.entries';
36
+ import 'core-js/modules/es.object.values';
37
+ import 'core-js/modules/es.object.get-own-property-descriptors';
38
+ import 'core-js/modules/es.object.from-entries';
35
39
 
36
40
  // ES2015 array capabilities
37
41
  import 'core-js/modules/es.array.concat';
@@ -56,6 +60,9 @@ import 'core-js/modules/es.array.fill';
56
60
  import 'core-js/modules/es.array.find';
57
61
  import 'core-js/modules/es.array.find-index';
58
62
  import 'core-js/modules/es.array.iterator';
63
+ import 'core-js/modules/es.array.includes';
64
+ import 'core-js/modules/es.array.flat';
65
+ import 'core-js/modules/es.array.flat-map';
59
66
 
60
67
  // ES2015 string capabilities
61
68
  import 'core-js/modules/es.string.from-code-point';
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google Inc. All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { Compiler } from 'webpack';
9
+ export declare type BuilderWatcherCallback = (events: Array<{
10
+ path: string;
11
+ type: 'created' | 'modified' | 'deleted';
12
+ time?: number;
13
+ }>) => void;
14
+ export interface BuilderWatcherFactory {
15
+ watch(files: Iterable<string>, directories: Iterable<string>, callback: BuilderWatcherCallback): {
16
+ close(): void;
17
+ };
18
+ }
19
+ export interface WebpackWatcher {
20
+ close(): void;
21
+ pause(): void;
22
+ getFileTimestamps(): Map<string, number>;
23
+ getContextTimestamps(): Map<string, number>;
24
+ getFileTimeInfoEntries(): Map<string, {
25
+ safeTime: number;
26
+ timestamp: number;
27
+ }>;
28
+ getContextTimeInfoEntries(): Map<string, {
29
+ safeTime: number;
30
+ timestamp: number;
31
+ }>;
32
+ }
33
+ declare type WatchCallback4 = (error: Error | undefined, fileChanges: Set<string>, directoryChanges: Set<string>, missingChanges: Set<string>, files: Map<string, number>, contexts: Map<string, number>, removals: Set<string>) => void;
34
+ declare type WatchCallback5 = (error: Error | undefined, files: Map<string, {
35
+ safeTime: number;
36
+ timestamp: number;
37
+ }>, contexts: Map<string, {
38
+ safeTime: number;
39
+ timestamp: number;
40
+ }>, changes: Set<string>, removals: Set<string>) => void;
41
+ export interface WebpackWatchFileSystem {
42
+ watch(files: Iterable<string>, directories: Iterable<string>, missing: Iterable<string>, startTime: number, options: {}, callback: WatchCallback4 | WatchCallback5, callbackUndelayed: (file: string, time: number) => void): WebpackWatcher;
43
+ }
44
+ export declare class BuilderWatchPlugin {
45
+ private readonly watcherFactory;
46
+ constructor(watcherFactory: BuilderWatcherFactory);
47
+ apply(compiler: Compiler & {
48
+ watchFileSystem: WebpackWatchFileSystem;
49
+ }): void;
50
+ }
51
+ export {};
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BuilderWatchPlugin = void 0;
4
+ const webpack_version_1 = require("../../utils/webpack-version");
5
+ class TimeInfoMap extends Map {
6
+ update(path, timestamp) {
7
+ this.set(path, Object.freeze({ safeTime: timestamp, timestamp }));
8
+ }
9
+ toTimestamps() {
10
+ const timestamps = new Map();
11
+ for (const [file, entry] of this) {
12
+ timestamps.set(file, entry.timestamp);
13
+ }
14
+ return timestamps;
15
+ }
16
+ }
17
+ class BuilderWatchFileSystem {
18
+ constructor(watcherFactory, inputFileSystem) {
19
+ this.watcherFactory = watcherFactory;
20
+ this.inputFileSystem = inputFileSystem;
21
+ }
22
+ watch(files, directories, missing, startTime, _options, callback, callbackUndelayed) {
23
+ const watchedFiles = new Set(files);
24
+ const watchedDirectories = new Set(directories);
25
+ const watchedMissing = new Set(missing);
26
+ const timeInfo = new TimeInfoMap();
27
+ for (const file of files) {
28
+ timeInfo.update(file, startTime);
29
+ }
30
+ for (const directory of directories) {
31
+ timeInfo.update(directory, startTime);
32
+ }
33
+ const watcher = this.watcherFactory.watch(files, directories, (events) => {
34
+ if (events.length === 0) {
35
+ return;
36
+ }
37
+ if (callbackUndelayed) {
38
+ process.nextTick(() => { var _a; return callbackUndelayed(events[0].path, (_a = events[0].time) !== null && _a !== void 0 ? _a : Date.now()); });
39
+ }
40
+ process.nextTick(() => {
41
+ var _a, _b, _c;
42
+ const removals = new Set();
43
+ const fileChanges = new Set();
44
+ const directoryChanges = new Set();
45
+ const missingChanges = new Set();
46
+ for (const event of events) {
47
+ (_b = (_a = this.inputFileSystem).purge) === null || _b === void 0 ? void 0 : _b.call(_a, event.path);
48
+ if (event.type === 'deleted') {
49
+ timeInfo.delete(event.path);
50
+ removals.add(event.path);
51
+ }
52
+ else {
53
+ timeInfo.update(event.path, (_c = event.time) !== null && _c !== void 0 ? _c : Date.now());
54
+ if (watchedFiles.has(event.path)) {
55
+ fileChanges.add(event.path);
56
+ }
57
+ else if (watchedDirectories.has(event.path)) {
58
+ directoryChanges.add(event.path);
59
+ }
60
+ else if (watchedMissing.has(event.path)) {
61
+ missingChanges.add(event.path);
62
+ }
63
+ }
64
+ }
65
+ if (webpack_version_1.isWebpackFiveOrHigher()) {
66
+ callback(undefined, new Map(timeInfo), new Map(timeInfo), new Set([...fileChanges, ...directoryChanges, ...missingChanges]), removals);
67
+ }
68
+ else {
69
+ callback(undefined, fileChanges, directoryChanges, missingChanges, timeInfo.toTimestamps(), timeInfo.toTimestamps(), removals);
70
+ }
71
+ });
72
+ });
73
+ return {
74
+ close() {
75
+ watcher.close();
76
+ },
77
+ pause() { },
78
+ getFileTimestamps() {
79
+ return timeInfo.toTimestamps();
80
+ },
81
+ getContextTimestamps() {
82
+ return timeInfo.toTimestamps();
83
+ },
84
+ getFileTimeInfoEntries() {
85
+ return new Map(timeInfo);
86
+ },
87
+ getContextTimeInfoEntries() {
88
+ return new Map(timeInfo);
89
+ },
90
+ };
91
+ }
92
+ }
93
+ class BuilderWatchPlugin {
94
+ constructor(watcherFactory) {
95
+ this.watcherFactory = watcherFactory;
96
+ }
97
+ apply(compiler) {
98
+ compiler.hooks.environment.tap('BuilderWatchPlugin', () => {
99
+ compiler.watchFileSystem = new BuilderWatchFileSystem(this.watcherFactory, compiler.inputFileSystem);
100
+ });
101
+ }
102
+ }
103
+ exports.BuilderWatchPlugin = BuilderWatchPlugin;
@@ -14,6 +14,10 @@ function default_1(mod) {
14
14
  if (!mod['hot']) {
15
15
  return;
16
16
  }
17
+ if (!core_1.isDevMode()) {
18
+ console.error(`[NG HMR] Cannot use HMR when Angular is running in production mode. To prevent production mode, do not call 'enableProdMode()'.`);
19
+ return;
20
+ }
17
21
  mod['hot'].accept();
18
22
  mod['hot'].dispose(() => {
19
23
  if (typeof ng === 'undefined') {
@@ -1,8 +1 @@
1
- /**
2
- * @license
3
- * Copyright Google Inc. All Rights Reserved.
4
- *
5
- * Use of this source code is governed by an MIT-style license that can be
6
- * found in the LICENSE file at https://angular.io/license
7
- */
8
1
  export {};
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- /**
3
- * @license
4
- * Copyright Google Inc. All Rights Reserved.
5
- *
6
- * Use of this source code is governed by an MIT-style license that can be
7
- * found in the LICENSE file at https://angular.io/license
8
- */
9
- // tslint:disable
10
- // TODO: cleanup this file, it's copied as is from Angular CLI.
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const path = require("path");
13
4
  const glob = require("glob");
@@ -25,6 +16,7 @@ const index_1 = require("../../utils/index");
25
16
  * require('source-map-support')
26
17
  * require('karma-source-map-support')
27
18
  */
19
+ const KARMA_APPLICATION_PATH = '_karma_webpack_';
28
20
  let blocked = [];
29
21
  let isBlocked = false;
30
22
  let webpackMiddleware;
@@ -105,7 +97,7 @@ const init = (config, emitter, customFileHandlers) => {
105
97
  // Hide webpack output because its noisy.
106
98
  logLevel: 'error',
107
99
  stats: false,
108
- publicPath: '/_karma_webpack_/',
100
+ publicPath: `/${KARMA_APPLICATION_PATH}/`,
109
101
  };
110
102
  const compilationErrorCb = (error, errors) => {
111
103
  // Notify potential listeners of the compile error
@@ -142,8 +134,8 @@ const init = (config, emitter, customFileHandlers) => {
142
134
  });
143
135
  }
144
136
  // Files need to be served from a custom path for Karma.
145
- webpackConfig.output.path = '/_karma_webpack_/';
146
- webpackConfig.output.publicPath = '/_karma_webpack_/';
137
+ webpackConfig.output.path = `/${KARMA_APPLICATION_PATH}/`;
138
+ webpackConfig.output.publicPath = `/${KARMA_APPLICATION_PATH}/`;
147
139
  let compiler;
148
140
  try {
149
141
  compiler = webpack(webpackConfig);
@@ -190,18 +182,18 @@ const init = (config, emitter, customFileHandlers) => {
190
182
  webpackMiddleware = new webpackDevMiddleware(compiler, webpackMiddlewareConfig);
191
183
  // Forward requests to webpack server.
192
184
  customFileHandlers.push({
193
- urlRegex: /^\/_karma_webpack_\/.*/,
185
+ urlRegex: new RegExp(`\\/${KARMA_APPLICATION_PATH}\\/.*`),
194
186
  handler: function handler(req, res) {
195
187
  webpackMiddleware(req, res, function () {
196
188
  // Ensure script and style bundles are served.
197
189
  // They are mentioned in the custom karma context page and we don't want them to 404.
198
190
  const alwaysServe = [
199
- '/_karma_webpack_/runtime.js',
200
- '/_karma_webpack_/polyfills.js',
201
- '/_karma_webpack_/polyfills-es5.js',
202
- '/_karma_webpack_/scripts.js',
203
- '/_karma_webpack_/styles.js',
204
- '/_karma_webpack_/vendor.js',
191
+ `/${KARMA_APPLICATION_PATH}/runtime.js`,
192
+ `/${KARMA_APPLICATION_PATH}/polyfills.js`,
193
+ `/${KARMA_APPLICATION_PATH}/polyfills-es5.js`,
194
+ `/${KARMA_APPLICATION_PATH}/scripts.js`,
195
+ `/${KARMA_APPLICATION_PATH}/styles.js`,
196
+ `/${KARMA_APPLICATION_PATH}/vendor.js`,
205
197
  ];
206
198
  if (alwaysServe.indexOf(req.url) != -1) {
207
199
  res.statusCode = 200;
@@ -280,11 +272,10 @@ const sourceMapReporter = function (baseReporterDecorator, config) {
280
272
  sourceMapReporter.$inject = ['baseReporterDecorator', 'config'];
281
273
  // When a request is not found in the karma server, try looking for it from the webpack server root.
282
274
  function fallbackMiddleware() {
283
- return function (req, res, next) {
275
+ return function (request, response, next) {
284
276
  if (webpackMiddleware) {
285
- const webpackUrl = '/_karma_webpack_' + req.url;
286
- const webpackReq = { ...req, url: webpackUrl };
287
- webpackMiddleware(webpackReq, res, next);
277
+ request.url = '/' + KARMA_APPLICATION_PATH + request.url;
278
+ webpackMiddleware(request, response, next);
288
279
  }
289
280
  else {
290
281
  next();