@angular-devkit/build-angular 15.0.0-next.3 → 15.0.0-next.5

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 (53) hide show
  1. package/package.json +19 -18
  2. package/src/builders/app-shell/index.js +39 -40
  3. package/src/builders/app-shell/render-worker.d.ts +36 -0
  4. package/src/builders/app-shell/render-worker.js +82 -0
  5. package/src/builders/browser/index.d.ts +2 -0
  6. package/src/builders/browser/index.js +38 -19
  7. package/src/builders/browser/schema.json +2 -2
  8. package/src/builders/browser-esbuild/compiler-plugin.d.ts +10 -2
  9. package/src/builders/browser-esbuild/compiler-plugin.js +211 -115
  10. package/src/builders/browser-esbuild/esbuild.d.ts +4 -3
  11. package/src/builders/browser-esbuild/esbuild.js +12 -6
  12. package/src/builders/browser-esbuild/experimental-warnings.js +0 -3
  13. package/src/builders/browser-esbuild/index.d.ts +3 -3
  14. package/src/builders/browser-esbuild/index.js +145 -87
  15. package/src/builders/browser-esbuild/options.d.ts +26 -4
  16. package/src/builders/browser-esbuild/options.js +56 -5
  17. package/src/builders/browser-esbuild/profiling.d.ts +11 -0
  18. package/src/builders/browser-esbuild/profiling.js +64 -0
  19. package/src/builders/browser-esbuild/sass-plugin.js +11 -5
  20. package/src/builders/browser-esbuild/schema.json +2 -2
  21. package/src/builders/browser-esbuild/watcher.d.ts +23 -0
  22. package/src/builders/browser-esbuild/watcher.js +93 -0
  23. package/src/builders/dev-server/index.d.ts +2 -0
  24. package/src/builders/dev-server/index.js +10 -7
  25. package/src/builders/karma/find-tests-plugin.js +1 -0
  26. package/src/builders/karma/index.d.ts +1 -1
  27. package/src/builders/karma/index.js +50 -9
  28. package/src/builders/karma/schema.d.ts +1 -1
  29. package/src/builders/karma/schema.json +1 -1
  30. package/src/builders/server/schema.json +1 -1
  31. package/src/utils/environment-options.d.ts +1 -0
  32. package/src/utils/environment-options.js +3 -1
  33. package/src/utils/process-bundle.js +1 -1
  34. package/src/utils/service-worker.d.ts +3 -0
  35. package/src/utils/service-worker.js +29 -2
  36. package/src/webpack/configs/common.js +31 -7
  37. package/src/webpack/configs/index.d.ts +0 -1
  38. package/src/webpack/configs/index.js +0 -1
  39. package/src/webpack/configs/styles.d.ts +1 -7
  40. package/src/webpack/configs/styles.js +70 -60
  41. package/src/webpack/plugins/occurrences-plugin.d.ts +18 -0
  42. package/src/webpack/plugins/occurrences-plugin.js +79 -0
  43. package/src/webpack/plugins/scripts-webpack-plugin.js +24 -5
  44. package/src/webpack/plugins/styles-webpack-plugin.d.ts +19 -0
  45. package/src/webpack/plugins/styles-webpack-plugin.js +71 -0
  46. package/src/webpack/utils/helpers.d.ts +5 -1
  47. package/src/webpack/utils/helpers.js +24 -14
  48. package/src/webpack/utils/stats.d.ts +13 -8
  49. package/src/webpack/utils/stats.js +57 -6
  50. package/src/webpack/configs/analytics.d.ts +0 -11
  51. package/src/webpack/configs/analytics.js +0 -27
  52. package/src/webpack/plugins/analytics.d.ts +0 -66
  53. package/src/webpack/plugins/analytics.js +0 -236
@@ -33,21 +33,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
33
  return (mod && mod.__esModule) ? mod : { "default": mod };
34
34
  };
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.createCompilerPlugin = void 0;
36
+ exports.createCompilerPlugin = exports.SourceFileCache = void 0;
37
37
  const core_1 = require("@babel/core");
38
38
  const assert = __importStar(require("assert"));
39
39
  const fs_1 = require("fs");
40
+ const os_1 = require("os");
40
41
  const path = __importStar(require("path"));
41
42
  const typescript_1 = __importDefault(require("typescript"));
42
43
  const application_1 = __importDefault(require("../../babel/presets/application"));
43
44
  const webpack_loader_1 = require("../../babel/webpack-loader");
44
45
  const load_esm_1 = require("../../utils/load-esm");
46
+ const profiling_1 = require("./profiling");
45
47
  const stylesheets_1 = require("./stylesheets");
46
48
  /**
47
49
  * Converts TypeScript Diagnostic related information into an esbuild compatible note object.
48
50
  * Related information is a subset of a full TypeScript Diagnostic and also used for diagnostic
49
51
  * notes associated with the main Diagnostic.
50
- * @param diagnostic The TypeScript diagnostic relative information to convert.
52
+ * @param info The TypeScript diagnostic relative information to convert.
51
53
  * @param host A TypeScript FormatDiagnosticsHost instance to use during conversion.
52
54
  * @returns An esbuild diagnostic message as a PartialMessage object
53
55
  */
@@ -106,6 +108,28 @@ function convertTypeScriptDiagnostic(diagnostic, host) {
106
108
  }
107
109
  return message;
108
110
  }
111
+ const USING_WINDOWS = (0, os_1.platform)() === 'win32';
112
+ const WINDOWS_SEP_REGEXP = new RegExp(`\\${path.win32.sep}`, 'g');
113
+ class SourceFileCache extends Map {
114
+ constructor() {
115
+ super(...arguments);
116
+ this.modifiedFiles = new Set();
117
+ this.babelFileCache = new Map();
118
+ }
119
+ invalidate(files) {
120
+ this.modifiedFiles.clear();
121
+ for (let file of files) {
122
+ this.babelFileCache.delete(file);
123
+ // Normalize separators to allow matching TypeScript Host paths
124
+ if (USING_WINDOWS) {
125
+ file = file.replace(WINDOWS_SEP_REGEXP, path.posix.sep);
126
+ }
127
+ this.delete(file);
128
+ this.modifiedFiles.add(file);
129
+ }
130
+ }
131
+ }
132
+ exports.SourceFileCache = SourceFileCache;
109
133
  // This is a non-watch version of the compiler code from `@ngtools/webpack` augmented for esbuild
110
134
  // eslint-disable-next-line max-lines-per-function
111
135
  function createCompilerPlugin(pluginOptions, styleOptions) {
@@ -115,14 +139,15 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
115
139
  async setup(build) {
116
140
  var _a, _b;
117
141
  var _c;
142
+ let setupWarnings;
118
143
  // This uses a wrapped dynamic import to load `@angular/compiler-cli` which is ESM.
119
144
  // Once TypeScript provides support for retaining dynamic imports this workaround can be dropped.
120
- const compilerCli = await (0, load_esm_1.loadEsmModule)('@angular/compiler-cli');
145
+ const { GLOBAL_DEFS_FOR_TERSER_WITH_AOT, NgtscProgram, OptimizeFor, readConfiguration } = await (0, load_esm_1.loadEsmModule)('@angular/compiler-cli');
121
146
  // Temporary deep import for transformer support
122
147
  const { mergeTransformers, replaceBootstrap, } = require('@ngtools/webpack/src/ivy/transformation');
123
148
  // Setup defines based on the values provided by the Angular compiler-cli
124
149
  (_a = (_c = build.initialOptions).define) !== null && _a !== void 0 ? _a : (_c.define = {});
125
- for (const [key, value] of Object.entries(compilerCli.GLOBAL_DEFS_FOR_TERSER_WITH_AOT)) {
150
+ for (const [key, value] of Object.entries(GLOBAL_DEFS_FOR_TERSER_WITH_AOT)) {
126
151
  if (key in build.initialOptions.define) {
127
152
  // Skip keys that have been manually provided
128
153
  continue;
@@ -133,7 +158,7 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
133
158
  }
134
159
  // The tsconfig is loaded in setup instead of in start to allow the esbuild target build option to be modified.
135
160
  // esbuild build options can only be modified in setup prior to starting the build.
136
- const { options: compilerOptions, rootNames, errors: configurationDiagnostics, } = compilerCli.readConfiguration(pluginOptions.tsconfig, {
161
+ const { options: compilerOptions, rootNames, errors: configurationDiagnostics, } = (0, profiling_1.profileSync)('NG_READ_CONFIG', () => readConfiguration(pluginOptions.tsconfig, {
137
162
  noEmitOnError: false,
138
163
  suppressOutputPathCheck: true,
139
164
  outDir: undefined,
@@ -147,22 +172,41 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
147
172
  allowEmptyCodegenFiles: false,
148
173
  annotationsAs: 'decorators',
149
174
  enableResourceInlining: false,
150
- });
175
+ }));
151
176
  if (compilerOptions.target === undefined || compilerOptions.target < typescript_1.default.ScriptTarget.ES2022) {
152
177
  // If 'useDefineForClassFields' is already defined in the users project leave the value as is.
153
178
  // Otherwise fallback to false due to https://github.com/microsoft/TypeScript/issues/45995
154
179
  // which breaks the deprecated `@Effects` NGRX decorator and potentially other existing code as well.
155
180
  compilerOptions.target = typescript_1.default.ScriptTarget.ES2022;
156
181
  (_b = compilerOptions.useDefineForClassFields) !== null && _b !== void 0 ? _b : (compilerOptions.useDefineForClassFields = false);
157
- // TODO: show warning about this override when we have access to the logger.
182
+ (setupWarnings !== null && setupWarnings !== void 0 ? setupWarnings : (setupWarnings = [])).push({
183
+ text: 'TypeScript compiler options "target" and "useDefineForClassFields" are set to "ES2022" and ' +
184
+ '"false" respectively by the Angular CLI.',
185
+ location: { file: pluginOptions.tsconfig },
186
+ notes: [
187
+ {
188
+ text: `To control ECMA version and features use the Browerslist configuration. ' +
189
+ 'For more information, see https://github.com/browserslist/browserslist#queries'`,
190
+ },
191
+ ],
192
+ });
158
193
  }
159
194
  // The file emitter created during `onStart` that will be used during the build in `onLoad` callbacks for TS files
160
195
  let fileEmitter;
161
196
  // The stylesheet resources from component stylesheets that will be added to the build results output files
162
197
  let stylesheetResourceFiles;
198
+ let previousBuilder;
199
+ let previousAngularProgram;
200
+ const babelDataCache = new Map();
201
+ const diagnosticCache = new WeakMap();
163
202
  build.onStart(async () => {
164
- var _a, _b;
165
- const result = {};
203
+ const result = {
204
+ warnings: setupWarnings,
205
+ };
206
+ // Reset the setup warnings so that they are only shown during the first build.
207
+ setupWarnings = undefined;
208
+ // Reset debug performance tracking
209
+ (0, profiling_1.resetCumulativeDurations)();
166
210
  // Reset stylesheet resource output files
167
211
  stylesheetResourceFiles = [];
168
212
  // Create TypeScript compiler host
@@ -201,53 +245,81 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
201
245
  stylesheetResourceFiles.push(...resourceFiles);
202
246
  return { content: contents };
203
247
  };
248
+ // Temporary deep import for host augmentation support
249
+ const { augmentHostWithCaching, augmentHostWithReplacements, augmentProgramWithVersioning, } = require('@ngtools/webpack/src/ivy/host');
204
250
  // Augment TypeScript Host for file replacements option
205
251
  if (pluginOptions.fileReplacements) {
206
- // Temporary deep import for file replacements support
207
- const { augmentHostWithReplacements } = require('@ngtools/webpack/src/ivy/host');
208
252
  augmentHostWithReplacements(host, pluginOptions.fileReplacements);
209
253
  }
254
+ // Augment TypeScript Host with source file caching if provided
255
+ if (pluginOptions.sourceFileCache) {
256
+ augmentHostWithCaching(host, pluginOptions.sourceFileCache);
257
+ // Allow the AOT compiler to request the set of changed templates and styles
258
+ host.getModifiedResourceFiles = function () {
259
+ var _a;
260
+ return (_a = pluginOptions.sourceFileCache) === null || _a === void 0 ? void 0 : _a.modifiedFiles;
261
+ };
262
+ }
210
263
  // Create the Angular specific program that contains the Angular compiler
211
- const angularProgram = new compilerCli.NgtscProgram(rootNames, compilerOptions, host);
264
+ const angularProgram = (0, profiling_1.profileSync)('NG_CREATE_PROGRAM', () => new NgtscProgram(rootNames, compilerOptions, host, previousAngularProgram));
265
+ previousAngularProgram = angularProgram;
212
266
  const angularCompiler = angularProgram.compiler;
213
- const { ignoreForDiagnostics } = angularCompiler;
214
267
  const typeScriptProgram = angularProgram.getTsProgram();
215
- const builder = typescript_1.default.createAbstractBuilder(typeScriptProgram, host);
216
- await angularCompiler.analyzeAsync();
268
+ augmentProgramWithVersioning(typeScriptProgram);
269
+ const builder = typescript_1.default.createEmitAndSemanticDiagnosticsBuilderProgram(typeScriptProgram, host, previousBuilder, configurationDiagnostics);
270
+ previousBuilder = builder;
271
+ await (0, profiling_1.profileAsync)('NG_ANALYZE_PROGRAM', () => angularCompiler.analyzeAsync());
217
272
  function* collectDiagnostics() {
218
273
  // Collect program level diagnostics
219
- yield* configurationDiagnostics;
274
+ yield* builder.getConfigFileParsingDiagnostics();
220
275
  yield* angularCompiler.getOptionDiagnostics();
221
276
  yield* builder.getOptionsDiagnostics();
222
277
  yield* builder.getGlobalDiagnostics();
223
278
  // Collect source file specific diagnostics
224
- const OptimizeFor = compilerCli.OptimizeFor;
279
+ const affectedFiles = findAffectedFiles(builder, angularCompiler);
280
+ const optimizeFor = affectedFiles.size > 1 ? OptimizeFor.WholeProgram : OptimizeFor.SingleFile;
225
281
  for (const sourceFile of builder.getSourceFiles()) {
226
- if (ignoreForDiagnostics.has(sourceFile)) {
282
+ if (angularCompiler.ignoreForDiagnostics.has(sourceFile)) {
227
283
  continue;
228
284
  }
229
- yield* builder.getSyntacticDiagnostics(sourceFile);
230
- yield* builder.getSemanticDiagnostics(sourceFile);
231
- const angularDiagnostics = angularCompiler.getDiagnosticsForFile(sourceFile, OptimizeFor.WholeProgram);
232
- yield* angularDiagnostics;
285
+ // TypeScript will use cached diagnostics for files that have not been
286
+ // changed or affected for this build when using incremental building.
287
+ yield* (0, profiling_1.profileSync)('NG_DIAGNOSTICS_SYNTACTIC', () => builder.getSyntacticDiagnostics(sourceFile), true);
288
+ yield* (0, profiling_1.profileSync)('NG_DIAGNOSTICS_SEMANTIC', () => builder.getSemanticDiagnostics(sourceFile), true);
289
+ // Only request Angular template diagnostics for affected files to avoid
290
+ // overhead of template diagnostics for unchanged files.
291
+ if (affectedFiles.has(sourceFile)) {
292
+ const angularDiagnostics = (0, profiling_1.profileSync)('NG_DIAGNOSTICS_TEMPLATE', () => angularCompiler.getDiagnosticsForFile(sourceFile, optimizeFor), true);
293
+ diagnosticCache.set(sourceFile, angularDiagnostics);
294
+ yield* angularDiagnostics;
295
+ }
296
+ else {
297
+ const angularDiagnostics = diagnosticCache.get(sourceFile);
298
+ if (angularDiagnostics) {
299
+ yield* angularDiagnostics;
300
+ }
301
+ }
233
302
  }
234
303
  }
235
- for (const diagnostic of collectDiagnostics()) {
236
- const message = convertTypeScriptDiagnostic(diagnostic, host);
237
- if (diagnostic.category === typescript_1.default.DiagnosticCategory.Error) {
238
- ((_a = result.errors) !== null && _a !== void 0 ? _a : (result.errors = [])).push(message);
239
- }
240
- else {
241
- ((_b = result.warnings) !== null && _b !== void 0 ? _b : (result.warnings = [])).push(message);
304
+ (0, profiling_1.profileSync)('NG_DIAGNOSTICS_TOTAL', () => {
305
+ var _a, _b;
306
+ for (const diagnostic of collectDiagnostics()) {
307
+ const message = convertTypeScriptDiagnostic(diagnostic, host);
308
+ if (diagnostic.category === typescript_1.default.DiagnosticCategory.Error) {
309
+ ((_a = result.errors) !== null && _a !== void 0 ? _a : (result.errors = [])).push(message);
310
+ }
311
+ else {
312
+ ((_b = result.warnings) !== null && _b !== void 0 ? _b : (result.warnings = [])).push(message);
313
+ }
242
314
  }
243
- }
315
+ });
244
316
  fileEmitter = createFileEmitter(builder, mergeTransformers(angularCompiler.prepareEmit().transformers, {
245
317
  before: [replaceBootstrap(() => builder.getProgram().getTypeChecker())],
246
- }), () => []);
318
+ }), (sourceFile) => angularCompiler.incrementalCompilation.recordSuccessfulEmit(sourceFile));
247
319
  return result;
248
320
  });
249
- build.onLoad({ filter: compilerOptions.allowJs ? /\.[cm]?[jt]sx?$/ : /\.[cm]?tsx?$/ }, async (args) => {
250
- var _a, _b, _c, _d;
321
+ build.onLoad({ filter: compilerOptions.allowJs ? /\.[cm]?[jt]sx?$/ : /\.[cm]?tsx?$/ }, (args) => (0, profiling_1.profileAsync)('NG_EMIT_TS*', async () => {
322
+ var _a, _b, _c;
251
323
  assert.ok(fileEmitter, 'Invalid plugin execution order');
252
324
  const typescriptResult = await fileEmitter((_b = (_a = pluginOptions.fileReplacements) === null || _a === void 0 ? void 0 : _a[args.path]) !== null && _b !== void 0 ? _b : args.path);
253
325
  if (!typescriptResult) {
@@ -260,8 +332,7 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
260
332
  return {
261
333
  errors: [
262
334
  {
263
- text: 'File is missing from the TypeScript compilation.',
264
- location: { file: args.path },
335
+ text: `File '${args.path}' is missing from the TypeScript compilation.`,
265
336
  notes: [
266
337
  {
267
338
  text: `Ensure the file is part of the TypeScript program via the 'files' or 'include' property.`,
@@ -272,99 +343,43 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
272
343
  };
273
344
  }
274
345
  const data = (_c = typescriptResult.content) !== null && _c !== void 0 ? _c : '';
275
- const forceAsyncTransformation = /async\s+function\s*\*/.test(data);
276
- const useInputSourcemap = pluginOptions.sourcemap &&
277
- (!!pluginOptions.thirdPartySourcemaps || !/[\\/]node_modules[\\/]/.test(args.path));
278
- // If no additional transformations are needed, return the TypeScript output directly
279
- if (!forceAsyncTransformation && !pluginOptions.advancedOptimizations) {
280
- return {
281
- // Strip sourcemaps if they should not be used
282
- contents: useInputSourcemap
283
- ? data
284
- : data.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, ''),
285
- loader: 'js',
286
- };
346
+ // The pre-transformed data is used as a cache key. Since the cache is memory only,
347
+ // the options cannot change and do not need to be represented in the key. If the
348
+ // cache is later stored to disk, then the options that affect transform output
349
+ // would need to be added to the key as well.
350
+ let contents = babelDataCache.get(data);
351
+ if (contents === undefined) {
352
+ contents = await transformWithBabel(args.path, data, pluginOptions);
353
+ babelDataCache.set(data, contents);
287
354
  }
288
- const babelResult = await (0, core_1.transformAsync)(data, {
289
- filename: args.path,
290
- inputSourceMap: (useInputSourcemap ? undefined : false),
291
- sourceMaps: pluginOptions.sourcemap ? 'inline' : false,
292
- compact: false,
293
- configFile: false,
294
- babelrc: false,
295
- browserslistConfigFile: false,
296
- plugins: [],
297
- presets: [
298
- [
299
- application_1.default,
300
- {
301
- forceAsyncTransformation,
302
- optimize: pluginOptions.advancedOptimizations && {},
303
- },
304
- ],
305
- ],
306
- });
307
355
  return {
308
- contents: (_d = babelResult === null || babelResult === void 0 ? void 0 : babelResult.code) !== null && _d !== void 0 ? _d : '',
356
+ contents,
309
357
  loader: 'js',
310
358
  };
311
- });
312
- build.onLoad({ filter: /\.[cm]?js$/ }, async (args) => {
313
- var _a;
314
- const data = await fs_1.promises.readFile(args.path, 'utf-8');
315
- const forceAsyncTransformation = !/[\\/][_f]?esm2015[\\/]/.test(args.path) && /async\s+function\s*\*/.test(data);
316
- const shouldLink = await (0, webpack_loader_1.requiresLinking)(args.path, data);
317
- const useInputSourcemap = pluginOptions.sourcemap &&
318
- (!!pluginOptions.thirdPartySourcemaps || !/[\\/]node_modules[\\/]/.test(args.path));
319
- // If no additional transformations are needed, return the TypeScript output directly
320
- if (!forceAsyncTransformation && !pluginOptions.advancedOptimizations && !shouldLink) {
321
- return {
322
- // Strip sourcemaps if they should not be used
323
- contents: useInputSourcemap
324
- ? data
325
- : data.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, ''),
326
- loader: 'js',
327
- };
359
+ }, true));
360
+ build.onLoad({ filter: /\.[cm]?js$/ }, (args) => (0, profiling_1.profileAsync)('NG_EMIT_JS*', async () => {
361
+ var _a, _b;
362
+ // The filename is currently used as a cache key. Since the cache is memory only,
363
+ // the options cannot change and do not need to be represented in the key. If the
364
+ // cache is later stored to disk, then the options that affect transform output
365
+ // would need to be added to the key as well as a check for any change of content.
366
+ let contents = (_a = pluginOptions.sourceFileCache) === null || _a === void 0 ? void 0 : _a.babelFileCache.get(args.path);
367
+ if (contents === undefined) {
368
+ const data = await fs_1.promises.readFile(args.path, 'utf-8');
369
+ contents = await transformWithBabel(args.path, data, pluginOptions);
370
+ (_b = pluginOptions.sourceFileCache) === null || _b === void 0 ? void 0 : _b.babelFileCache.set(args.path, contents);
328
371
  }
329
- const angularPackage = /[\\/]node_modules[\\/]@angular[\\/]/.test(args.path);
330
- const linkerPluginCreator = (await (0, load_esm_1.loadEsmModule)('@angular/compiler-cli/linker/babel')).createEs2015LinkerPlugin;
331
- const result = await (0, core_1.transformAsync)(data, {
332
- filename: args.path,
333
- inputSourceMap: (useInputSourcemap ? undefined : false),
334
- sourceMaps: pluginOptions.sourcemap ? 'inline' : false,
335
- compact: false,
336
- configFile: false,
337
- babelrc: false,
338
- browserslistConfigFile: false,
339
- plugins: [],
340
- presets: [
341
- [
342
- application_1.default,
343
- {
344
- angularLinker: {
345
- shouldLink,
346
- jitMode: false,
347
- linkerPluginCreator,
348
- },
349
- forceAsyncTransformation,
350
- optimize: pluginOptions.advancedOptimizations && {
351
- looseEnums: angularPackage,
352
- pureTopLevel: angularPackage,
353
- },
354
- },
355
- ],
356
- ],
357
- });
358
372
  return {
359
- contents: (_a = result === null || result === void 0 ? void 0 : result.code) !== null && _a !== void 0 ? _a : data,
373
+ contents,
360
374
  loader: 'js',
361
375
  };
362
- });
376
+ }, true));
363
377
  build.onEnd((result) => {
364
378
  var _a;
365
379
  if (stylesheetResourceFiles.length) {
366
380
  (_a = result.outputFiles) === null || _a === void 0 ? void 0 : _a.push(...stylesheetResourceFiles);
367
381
  }
382
+ (0, profiling_1.logCumulativeDurations)();
368
383
  });
369
384
  },
370
385
  };
@@ -386,3 +401,84 @@ function createFileEmitter(program, transformers = {}, onAfterEmit) {
386
401
  return { content, dependencies: [] };
387
402
  };
388
403
  }
404
+ async function transformWithBabel(filename, data, pluginOptions) {
405
+ var _a;
406
+ const forceAsyncTransformation = !/[\\/][_f]?esm2015[\\/]/.test(filename) && /async\s+function\s*\*/.test(data);
407
+ const shouldLink = await (0, webpack_loader_1.requiresLinking)(filename, data);
408
+ const useInputSourcemap = pluginOptions.sourcemap &&
409
+ (!!pluginOptions.thirdPartySourcemaps || !/[\\/]node_modules[\\/]/.test(filename));
410
+ // If no additional transformations are needed, return the data directly
411
+ if (!forceAsyncTransformation && !pluginOptions.advancedOptimizations && !shouldLink) {
412
+ // Strip sourcemaps if they should not be used
413
+ return useInputSourcemap ? data : data.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, '');
414
+ }
415
+ const angularPackage = /[\\/]node_modules[\\/]@angular[\\/]/.test(filename);
416
+ const linkerPluginCreator = shouldLink
417
+ ? (await (0, load_esm_1.loadEsmModule)('@angular/compiler-cli/linker/babel')).createEs2015LinkerPlugin
418
+ : undefined;
419
+ const result = await (0, core_1.transformAsync)(data, {
420
+ filename,
421
+ inputSourceMap: (useInputSourcemap ? undefined : false),
422
+ sourceMaps: pluginOptions.sourcemap ? 'inline' : false,
423
+ compact: false,
424
+ configFile: false,
425
+ babelrc: false,
426
+ browserslistConfigFile: false,
427
+ plugins: [],
428
+ presets: [
429
+ [
430
+ application_1.default,
431
+ {
432
+ angularLinker: {
433
+ shouldLink,
434
+ jitMode: false,
435
+ linkerPluginCreator,
436
+ },
437
+ forceAsyncTransformation,
438
+ optimize: pluginOptions.advancedOptimizations && {
439
+ looseEnums: angularPackage,
440
+ pureTopLevel: angularPackage,
441
+ },
442
+ },
443
+ ],
444
+ ],
445
+ });
446
+ return (_a = result === null || result === void 0 ? void 0 : result.code) !== null && _a !== void 0 ? _a : data;
447
+ }
448
+ function findAffectedFiles(builder, { ignoreForDiagnostics, ignoreForEmit, incrementalCompilation }) {
449
+ const affectedFiles = new Set();
450
+ // eslint-disable-next-line no-constant-condition
451
+ while (true) {
452
+ const result = builder.getSemanticDiagnosticsOfNextAffectedFile(undefined, (sourceFile) => {
453
+ // If the affected file is a TTC shim, add the shim's original source file.
454
+ // This ensures that changes that affect TTC are typechecked even when the changes
455
+ // are otherwise unrelated from a TS perspective and do not result in Ivy codegen changes.
456
+ // For example, changing @Input property types of a directive used in another component's
457
+ // template.
458
+ // A TTC shim is a file that has been ignored for diagnostics and has a filename ending in `.ngtypecheck.ts`.
459
+ if (ignoreForDiagnostics.has(sourceFile) && sourceFile.fileName.endsWith('.ngtypecheck.ts')) {
460
+ // This file name conversion relies on internal compiler logic and should be converted
461
+ // to an official method when available. 15 is length of `.ngtypecheck.ts`
462
+ const originalFilename = sourceFile.fileName.slice(0, -15) + '.ts';
463
+ const originalSourceFile = builder.getSourceFile(originalFilename);
464
+ if (originalSourceFile) {
465
+ affectedFiles.add(originalSourceFile);
466
+ }
467
+ return true;
468
+ }
469
+ return false;
470
+ });
471
+ if (!result) {
472
+ break;
473
+ }
474
+ affectedFiles.add(result.affected);
475
+ }
476
+ // A file is also affected if the Angular compiler requires it to be emitted
477
+ for (const sourceFile of builder.getSourceFiles()) {
478
+ if (ignoreForEmit.has(sourceFile) || incrementalCompilation.safeToSkipEmit(sourceFile)) {
479
+ continue;
480
+ }
481
+ affectedFiles.add(sourceFile);
482
+ }
483
+ return affectedFiles;
484
+ }
@@ -6,7 +6,7 @@
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
8
  import { BuilderContext } from '@angular-devkit/architect';
9
- import { BuildFailure, BuildOptions, BuildResult, Message, OutputFile } from 'esbuild';
9
+ import { BuildFailure, BuildInvalidate, BuildOptions, BuildResult, Message, OutputFile } from 'esbuild';
10
10
  /**
11
11
  * Determines if an unknown value is an esbuild BuildFailure error object thrown by esbuild.
12
12
  * @param value A potential esbuild BuildFailure error object.
@@ -19,11 +19,12 @@ export declare function isEsBuildFailure(value: unknown): value is BuildFailure;
19
19
  * All builds use the `write` option with a value of `false` to allow for the output files
20
20
  * build result array to be populated.
21
21
  *
22
- * @param options The esbuild options object to use when building.
22
+ * @param optionsOrInvalidate The esbuild options object to use when building or the invalidate object
23
+ * returned from an incremental build to perform an additional incremental build.
23
24
  * @returns If output files are generated, the full esbuild BuildResult; if not, the
24
25
  * warnings and errors for the attempted build.
25
26
  */
26
- export declare function bundle(options: BuildOptions): Promise<(BuildResult & {
27
+ export declare function bundle(optionsOrInvalidate: BuildOptions | BuildInvalidate): Promise<(BuildResult & {
27
28
  outputFiles: OutputFile[];
28
29
  }) | (BuildFailure & {
29
30
  outputFiles?: never;
@@ -24,16 +24,22 @@ exports.isEsBuildFailure = isEsBuildFailure;
24
24
  * All builds use the `write` option with a value of `false` to allow for the output files
25
25
  * build result array to be populated.
26
26
  *
27
- * @param options The esbuild options object to use when building.
27
+ * @param optionsOrInvalidate The esbuild options object to use when building or the invalidate object
28
+ * returned from an incremental build to perform an additional incremental build.
28
29
  * @returns If output files are generated, the full esbuild BuildResult; if not, the
29
30
  * warnings and errors for the attempted build.
30
31
  */
31
- async function bundle(options) {
32
+ async function bundle(optionsOrInvalidate) {
32
33
  try {
33
- return await (0, esbuild_1.build)({
34
- ...options,
35
- write: false,
36
- });
34
+ if (typeof optionsOrInvalidate === 'function') {
35
+ return (await optionsOrInvalidate());
36
+ }
37
+ else {
38
+ return await (0, esbuild_1.build)({
39
+ ...optionsOrInvalidate,
40
+ write: false,
41
+ });
42
+ }
37
43
  }
38
44
  catch (failure) {
39
45
  // Build failures will throw an exception which contains errors/warnings
@@ -24,9 +24,6 @@ const UNSUPPORTED_OPTIONS = [
24
24
  'inlineStyleLanguage',
25
25
  // The following option has no effect until preprocessors are supported
26
26
  // 'stylePreprocessorOptions',
27
- // * Watch mode
28
- 'watch',
29
- 'poll',
30
27
  // * Deprecated
31
28
  'deployUrl',
32
29
  // * Always enabled with esbuild
@@ -10,10 +10,10 @@ import { Schema as BrowserBuilderOptions } from './schema';
10
10
  /**
11
11
  * Main execution function for the esbuild-based application builder.
12
12
  * The options are compatible with the Webpack-based builder.
13
- * @param options The browser builder options to use when setting up the application build
13
+ * @param initialOptions The browser builder options to use when setting up the application build
14
14
  * @param context The Architect builder context object
15
- * @returns A promise with the builder result output
15
+ * @returns An async iterable with the builder result output
16
16
  */
17
- export declare function buildEsbuildBrowser(options: BrowserBuilderOptions, context: BuilderContext): Promise<BuilderOutput>;
17
+ export declare function buildEsbuildBrowser(initialOptions: BrowserBuilderOptions, context: BuilderContext): AsyncIterable<BuilderOutput>;
18
18
  declare const _default: import("@angular-devkit/architect/src/internal").Builder<BrowserBuilderOptions & import("../../../../core/src").JsonObject>;
19
19
  export default _default;