From 466d86dc8d3398695055f9eced7402804848a381 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Fri, 9 Jun 2023 12:58:41 +0000 Subject: [PATCH] refactor(@angular-devkit/build-angular): update code base structure to facilitate future builders This commit updates the code base structure in preparation for future works. --- goldens/circular-deps/packages.json | 4 +- .../build_angular/plugins/karma.ts | 2 +- .../src/builders/browser-esbuild/index.ts | 263 ++---------------- .../src/builders/browser-esbuild/options.ts | 5 +- .../src/builders/browser/index.ts | 24 +- .../tests/options/named-chunks_spec.ts | 2 +- .../src/builders/dev-server/vite-server.ts | 2 +- .../src/builders/dev-server/webpack-server.ts | 18 +- .../src/builders/extract-i18n/index.ts | 4 +- .../build_angular/src/builders/karma/index.ts | 2 +- .../src/builders/server/index.ts | 18 +- .../src/testing/file-watching.ts | 2 +- .../src/{ => tools}/babel/babel-loader.d.ts | 0 .../plugins/adjust-static-class-members.ts | 0 .../adjust-static-class-members_spec.ts | 0 .../babel/plugins/adjust-typescript-enums.ts | 0 .../plugins/adjust-typescript-enums_spec.ts | 0 .../babel/plugins/elide-angular-metadata.ts | 0 .../plugins/elide-angular-metadata_spec.ts | 0 .../babel/plugins/pure-toplevel-functions.ts | 0 .../plugins/pure-toplevel-functions_spec.ts | 0 .../{ => tools}/babel/presets/application.ts | 0 .../src/{ => tools}/babel/webpack-loader.ts | 4 +- .../esbuild}/angular/angular-compilation.ts | 0 .../esbuild}/angular/angular-host.ts | 0 .../esbuild}/angular/aot-compilation.ts | 0 .../esbuild}/angular/compiler-plugin.ts | 0 .../esbuild}/angular/diagnostics.ts | 0 .../esbuild}/angular/jit-compilation.ts | 0 .../esbuild}/angular/jit-plugin-callbacks.ts | 0 .../angular/jit-resource-transformer.ts | 0 .../esbuild}/angular/uri.ts | 0 .../esbuild/bundler-context.ts} | 34 +-- .../esbuild}/commonjs-checker.ts | 0 .../tools/esbuild/external-packages-plugin.ts | 52 ++++ .../esbuild}/global-scripts.ts | 2 +- .../esbuild}/global-styles.ts | 2 +- .../esbuild}/javascript-transformer-worker.ts | 4 +- .../esbuild}/javascript-transformer.ts | 0 .../esbuild}/license-extractor.ts | 0 .../esbuild}/load-result-cache.ts | 0 .../esbuild}/profiling.ts | 0 .../esbuild}/sourcemap-ignorelist-plugin.ts | 0 .../esbuild}/stylesheets/bundle-options.ts | 2 +- .../esbuild}/stylesheets/css-language.ts | 0 .../stylesheets/css-resource-plugin.ts | 0 .../esbuild}/stylesheets/less-language.ts | 0 .../esbuild}/stylesheets/sass-language.ts | 4 +- .../stylesheets/stylesheet-plugin-factory.ts | 0 .../build_angular/src/tools/esbuild/utils.ts | 221 +++++++++++++++ .../esbuild}/virtual-module-plugin.ts | 0 .../esbuild}/watcher.ts | 0 .../src/{ => tools}/sass/rebasing-importer.ts | 0 .../{ => tools}/sass/sass-service-legacy.ts | 2 +- .../src/{ => tools}/sass/sass-service.ts | 2 +- .../src/{ => tools}/sass/worker-legacy.ts | 0 .../src/{ => tools}/sass/worker.ts | 0 .../src/{ => tools}/webpack/configs/common.ts | 6 +- .../{ => tools}/webpack/configs/dev-server.ts | 8 +- .../src/{ => tools}/webpack/configs/index.ts | 0 .../src/{ => tools}/webpack/configs/styles.ts | 6 +- .../any-component-style-budget-checker.ts | 6 +- .../webpack/plugins/builder-watch-plugin.ts | 0 .../plugins/common-js-usage-warn-plugin.ts | 2 +- .../webpack/plugins/css-optimizer-plugin.ts | 4 +- .../plugins/dedupe-module-resolve-plugin.ts | 2 +- .../webpack/plugins/devtools-ignore-plugin.ts | 0 .../webpack/plugins/esbuild-executor.ts | 0 .../webpack/plugins/hmr/hmr-accept.ts | 0 .../webpack/plugins/hmr/hmr-loader.ts | 0 .../plugins/index-html-webpack-plugin.ts | 8 +- .../src/{ => tools}/webpack/plugins/index.ts | 0 .../plugins/javascript-optimizer-plugin.ts | 6 +- .../plugins/javascript-optimizer-worker.ts | 0 .../webpack/plugins/json-stats-plugin.ts | 5 +- .../webpack/plugins/karma/karma-context.html | 0 .../webpack/plugins/karma/karma-debug.html | 0 .../webpack/plugins/karma/karma.ts | 4 +- .../webpack/plugins/named-chunks-plugin.ts | 0 .../webpack/plugins/occurrences-plugin.ts | 0 .../webpack/plugins/postcss-cli-resources.ts | 2 +- .../webpack/plugins/progress-plugin.ts | 2 +- .../webpack/plugins/remove-hash-plugin.ts | 0 .../webpack/plugins/scripts-webpack-plugin.ts | 4 +- .../webpack/plugins/service-worker-plugin.ts | 2 +- .../webpack/plugins/styles-webpack-plugin.ts | 4 +- .../suppress-entry-chunks-webpack-plugin.ts | 0 .../webpack/plugins/transfer-size-plugin.ts | 2 +- .../{ => tools}/webpack/plugins/typescript.ts | 2 +- .../plugins/watch-files-logs-plugin.ts | 0 .../{ => tools}/webpack/utils/async-chunks.ts | 0 .../src/{ => tools}/webpack/utils/helpers.ts | 6 +- .../src/{ => tools}/webpack/utils/stats.ts | 8 +- .../src/utils/bundle-calculator.ts | 2 +- .../src/utils/package-chunk-sort.ts | 2 +- .../src/utils/webpack-browser-config.ts | 5 +- 96 files changed, 409 insertions(+), 364 deletions(-) rename packages/angular_devkit/build_angular/src/{ => tools}/babel/babel-loader.d.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/babel/plugins/adjust-static-class-members.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/babel/plugins/adjust-static-class-members_spec.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/babel/plugins/adjust-typescript-enums.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/babel/plugins/adjust-typescript-enums_spec.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/babel/plugins/elide-angular-metadata.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/babel/plugins/elide-angular-metadata_spec.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/babel/plugins/pure-toplevel-functions.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/babel/plugins/pure-toplevel-functions_spec.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/babel/presets/application.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/babel/webpack-loader.ts (98%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/angular/angular-compilation.ts (100%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/angular/angular-host.ts (100%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/angular/aot-compilation.ts (100%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/angular/compiler-plugin.ts (100%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/angular/diagnostics.ts (100%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/angular/jit-compilation.ts (100%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/angular/jit-plugin-callbacks.ts (100%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/angular/jit-resource-transformer.ts (100%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/angular/uri.ts (100%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild/esbuild.ts => tools/esbuild/bundler-context.ts} (91%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/commonjs-checker.ts (100%) create mode 100644 packages/angular_devkit/build_angular/src/tools/esbuild/external-packages-plugin.ts rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/global-scripts.ts (98%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/global-styles.ts (96%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/javascript-transformer-worker.ts (95%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/javascript-transformer.ts (100%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/license-extractor.ts (100%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/load-result-cache.ts (100%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/profiling.ts (100%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/sourcemap-ignorelist-plugin.ts (100%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/stylesheets/bundle-options.ts (99%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/stylesheets/css-language.ts (100%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/stylesheets/css-resource-plugin.ts (100%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/stylesheets/less-language.ts (100%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/stylesheets/sass-language.ts (98%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/stylesheets/stylesheet-plugin-factory.ts (100%) create mode 100644 packages/angular_devkit/build_angular/src/tools/esbuild/utils.ts rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/virtual-module-plugin.ts (100%) rename packages/angular_devkit/build_angular/src/{builders/browser-esbuild => tools/esbuild}/watcher.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/sass/rebasing-importer.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/sass/sass-service-legacy.ts (99%) rename packages/angular_devkit/build_angular/src/{ => tools}/sass/sass-service.ts (99%) rename packages/angular_devkit/build_angular/src/{ => tools}/sass/worker-legacy.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/sass/worker.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/configs/common.ts (98%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/configs/dev-server.ts (97%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/configs/index.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/configs/styles.ts (98%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/any-component-style-budget-checker.ts (93%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/builder-watch-plugin.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/common-js-usage-warn-plugin.ts (98%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/css-optimizer-plugin.ts (97%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/dedupe-module-resolve-plugin.ts (98%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/devtools-ignore-plugin.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/esbuild-executor.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/hmr/hmr-accept.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/hmr/hmr-loader.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/index-html-webpack-plugin.ts (92%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/index.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/javascript-optimizer-plugin.ts (97%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/javascript-optimizer-worker.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/json-stats-plugin.ts (90%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/karma/karma-context.html (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/karma/karma-debug.html (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/karma/karma.ts (98%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/named-chunks-plugin.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/occurrences-plugin.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/postcss-cli-resources.ts (99%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/progress-plugin.ts (95%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/remove-hash-plugin.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/scripts-webpack-plugin.ts (98%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/service-worker-plugin.ts (96%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/styles-webpack-plugin.ts (95%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/suppress-entry-chunks-webpack-plugin.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/transfer-size-plugin.ts (96%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/typescript.ts (97%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/plugins/watch-files-logs-plugin.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/utils/async-chunks.ts (100%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/utils/helpers.ts (98%) rename packages/angular_devkit/build_angular/src/{ => tools}/webpack/utils/stats.ts (98%) diff --git a/goldens/circular-deps/packages.json b/goldens/circular-deps/packages.json index 7cfa45ae1df0..1f70498fbe86 100644 --- a/goldens/circular-deps/packages.json +++ b/goldens/circular-deps/packages.json @@ -1,7 +1,7 @@ [ [ - "packages/angular_devkit/build_angular/src/utils/bundle-calculator.ts", - "packages/angular_devkit/build_angular/src/webpack/utils/stats.ts" + "packages/angular_devkit/build_angular/src/tools/webpack/utils/stats.ts", + "packages/angular_devkit/build_angular/src/utils/bundle-calculator.ts" ], [ "packages/angular/cli/src/analytics/analytics-collector.ts", diff --git a/packages/angular_devkit/build_angular/plugins/karma.ts b/packages/angular_devkit/build_angular/plugins/karma.ts index 18409cffe9a9..2e3bfe1c869a 100644 --- a/packages/angular_devkit/build_angular/plugins/karma.ts +++ b/packages/angular_devkit/build_angular/plugins/karma.ts @@ -6,4 +6,4 @@ * found in the LICENSE file at https://angular.io/license */ -module.exports = require('../src/webpack/plugins/karma/karma'); +module.exports = require('../src/tools/webpack/plugins/karma/karma'); diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/index.ts b/packages/angular_devkit/build_angular/src/builders/browser-esbuild/index.ts index 884a3023744b..63e6e471f65b 100644 --- a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/index.ts +++ b/packages/angular_devkit/build_angular/src/builders/browser-esbuild/index.ts @@ -7,35 +7,39 @@ */ import { BuilderContext, BuilderOutput, createBuilder } from '@angular-devkit/architect'; -import type { BuildOptions, Metafile, OutputFile } from 'esbuild'; -import { constants as fsConstants } from 'node:fs'; +import type { BuildOptions, OutputFile } from 'esbuild'; import fs from 'node:fs/promises'; import path from 'node:path'; -import { promisify } from 'node:util'; -import { brotliCompress } from 'node:zlib'; +import { SourceFileCache, createCompilerPlugin } from '../../tools/esbuild/angular/compiler-plugin'; +import { BundlerContext } from '../../tools/esbuild/bundler-context'; +import { checkCommonJSModules } from '../../tools/esbuild/commonjs-checker'; +import { createExternalPackagesPlugin } from '../../tools/esbuild/external-packages-plugin'; +import { createGlobalScriptsBundleOptions } from '../../tools/esbuild/global-scripts'; +import { createGlobalStylesBundleOptions } from '../../tools/esbuild/global-styles'; +import { extractLicenses } from '../../tools/esbuild/license-extractor'; +import { createSourcemapIngorelistPlugin } from '../../tools/esbuild/sourcemap-ignorelist-plugin'; +import { shutdownSassWorkerPool } from '../../tools/esbuild/stylesheets/sass-language'; +import { + calculateEstimatedTransferSizes, + createOutputFileFromText, + getFeatureSupport, + logBuildStats, + logMessages, + withNoProgress, + withSpinner, + writeResultFiles, +} from '../../tools/esbuild/utils'; +import { createVirtualModulePlugin } from '../../tools/esbuild/virtual-module-plugin'; +import type { ChangedFiles } from '../../tools/esbuild/watcher'; import { copyAssets } from '../../utils/copy-assets'; import { assertIsError } from '../../utils/error'; import { transformSupportedBrowsersToTargets } from '../../utils/esbuild-targets'; import { IndexHtmlGenerator } from '../../utils/index-file/index-html-generator'; import { augmentAppWithServiceWorkerEsbuild } from '../../utils/service-worker'; -import { Spinner } from '../../utils/spinner'; import { getSupportedBrowsers } from '../../utils/supported-browsers'; -import { BundleStats, generateBuildStatsTable } from '../../webpack/utils/stats'; -import { SourceFileCache, createCompilerPlugin } from './angular/compiler-plugin'; import { logBuilderStatusWarnings } from './builder-status-warnings'; -import { checkCommonJSModules } from './commonjs-checker'; -import { BundlerContext, InitialFileRecord, logMessages } from './esbuild'; -import { createGlobalScriptsBundleOptions } from './global-scripts'; -import { createGlobalStylesBundleOptions } from './global-styles'; -import { extractLicenses } from './license-extractor'; import { BrowserEsbuildOptions, NormalizedBrowserOptions, normalizeOptions } from './options'; import { Schema as BrowserBuilderOptions } from './schema'; -import { createSourcemapIngorelistPlugin } from './sourcemap-ignorelist-plugin'; -import { shutdownSassWorkerPool } from './stylesheets/sass-language'; -import { createVirtualModulePlugin } from './virtual-module-plugin'; -import type { ChangedFiles } from './watcher'; - -const compressAsync = promisify(brotliCompress); interface RebuildState { rebuildContexts: BundlerContext[]; @@ -299,51 +303,6 @@ async function execute( return executionResult; } -async function writeResultFiles( - outputFiles: OutputFile[], - assetFiles: { source: string; destination: string }[] | undefined, - outputPath: string, -) { - const directoryExists = new Set(); - await Promise.all( - outputFiles.map(async (file) => { - // Ensure output subdirectories exist - const basePath = path.dirname(file.path); - if (basePath && !directoryExists.has(basePath)) { - await fs.mkdir(path.join(outputPath, basePath), { recursive: true }); - directoryExists.add(basePath); - } - // Write file contents - await fs.writeFile(path.join(outputPath, file.path), file.contents); - }), - ); - - if (assetFiles?.length) { - await Promise.all( - assetFiles.map(async ({ source, destination }) => { - // Ensure output subdirectories exist - const basePath = path.dirname(destination); - if (basePath && !directoryExists.has(basePath)) { - await fs.mkdir(path.join(outputPath, basePath), { recursive: true }); - directoryExists.add(basePath); - } - // Copy file contents - await fs.copyFile(source, path.join(outputPath, destination), fsConstants.COPYFILE_FICLONE); - }), - ); - } -} - -function createOutputFileFromText(path: string, text: string): OutputFile { - return { - path, - text, - get contents() { - return Buffer.from(this.text, 'utf-8'); - }, - }; -} - function createCodeBundleOptions( options: NormalizedBrowserOptions, target: string[], @@ -438,43 +397,8 @@ function createCodeBundleOptions( }; if (options.externalPackages) { - // Add a plugin that marks any resolved path as external if it is within a node modules directory. - // This is used instead of the esbuild `packages` option to avoid marking bare specifiers that use - // tsconfig path mapping to resolve to a workspace relative path. This is common for monorepos that - // contain libraries that are built along with the application. These libraries should not be considered - // external even though the imports appear to be packages. - const EXTERNAL_PACKAGE_RESOLUTION = Symbol('EXTERNAL_PACKAGE_RESOLUTION'); buildOptions.plugins ??= []; - buildOptions.plugins.push({ - name: 'angular-external-packages', - setup(build) { - build.onResolve({ filter: /./ }, async (args) => { - if (args.pluginData?.[EXTERNAL_PACKAGE_RESOLUTION]) { - return null; - } - - const { importer, kind, resolveDir, namespace, pluginData = {} } = args; - pluginData[EXTERNAL_PACKAGE_RESOLUTION] = true; - - const result = await build.resolve(args.path, { - importer, - kind, - namespace, - pluginData, - resolveDir, - }); - - if (result.path && /[\\/]node_modules[\\/]/.test(result.path)) { - return { - path: args.path, - external: true, - }; - } - - return result; - }); - }, - }); + buildOptions.plugins.push(createExternalPackagesPlugin()); } const polyfills = options.polyfills ? [...options.polyfills] : []; @@ -504,82 +428,6 @@ function createCodeBundleOptions( return buildOptions; } -/** - * Generates a syntax feature object map for Angular applications based on a list of targets. - * A full set of feature names can be found here: https://esbuild.github.io/api/#supported - * @param target An array of browser/engine targets in the format accepted by the esbuild `target` option. - * @returns An object that can be used with the esbuild build `supported` option. - */ -function getFeatureSupport(target: string[]): BuildOptions['supported'] { - const supported: Record = { - // Native async/await is not supported with Zone.js. Disabling support here will cause - // esbuild to downlevel async/await and for await...of to a Zone.js supported form. However, esbuild - // does not currently support downleveling async generators. Instead babel is used within the JS/TS - // loader to perform the downlevel transformation. - // NOTE: If esbuild adds support in the future, the babel support for async generators can be disabled. - 'async-await': false, - // V8 currently has a performance defect involving object spread operations that can cause signficant - // degradation in runtime performance. By not supporting the language feature here, a downlevel form - // will be used instead which provides a workaround for the performance issue. - // For more details: https://bugs.chromium.org/p/v8/issues/detail?id=11536 - 'object-rest-spread': false, - // esbuild currently has a defect involving self-referencing a class within a static code block or - // static field initializer. This is not an issue for projects that use the default browserslist as these - // elements are an ES2022 feature which is not support by all browsers in the default list. However, if a - // custom browserslist is used that only has newer browsers than the static code elements may be present. - // This issue is compounded by the default usage of the tsconfig `"useDefineForClassFields": false` option - // present in generated CLI projects which causes static code blocks to be used instead of static fields. - // esbuild currently unconditionally downlevels all static fields in top-level classes so to workaround the - // Angular issue only static code blocks are disabled here. - // For more details: https://github.com/evanw/esbuild/issues/2950 - 'class-static-blocks': false, - }; - - // Detect Safari browser versions that have a class field behavior bug - // See: https://github.com/angular/angular-cli/issues/24355#issuecomment-1333477033 - // See: https://github.com/WebKit/WebKit/commit/e8788a34b3d5f5b4edd7ff6450b80936bff396f2 - let safariClassFieldScopeBug = false; - for (const browser of target) { - let majorVersion; - if (browser.startsWith('ios')) { - majorVersion = Number(browser.slice(3, 5)); - } else if (browser.startsWith('safari')) { - majorVersion = Number(browser.slice(6, 8)); - } else { - continue; - } - // Technically, 14.0 is not broken but rather does not have support. However, the behavior - // is identical since it would be set to false by esbuild if present as a target. - if (majorVersion === 14 || majorVersion === 15) { - safariClassFieldScopeBug = true; - break; - } - } - // If class field support cannot be used set to false; otherwise leave undefined to allow - // esbuild to use `target` to determine support. - if (safariClassFieldScopeBug) { - supported['class-field'] = false; - supported['class-static-field'] = false; - } - - return supported; -} - -async function withSpinner(text: string, action: () => T | Promise): Promise { - const spinner = new Spinner(text); - spinner.start(); - - try { - return await action(); - } finally { - spinner.stop(); - } -} - -async function withNoProgress(test: string, action: () => T | Promise): Promise { - return action(); -} - /** * Main execution function for the esbuild-based application builder. * The options are compatible with the Webpack-based builder. @@ -695,7 +543,7 @@ export async function* buildEsbuildBrowserInternal( } // Setup a watcher - const { createWatcher } = await import('./watcher'); + const { createWatcher } = await import('../../tools/esbuild/watcher'); const watcher = createWatcher({ polling: typeof userOptions.poll === 'number', interval: userOptions.poll, @@ -772,66 +620,3 @@ export async function* buildEsbuildBrowserInternal( } export default createBuilder(buildEsbuildBrowser); - -function logBuildStats( - context: BuilderContext, - metafile: Metafile, - initial: Map, - estimatedTransferSizes?: Map, -) { - const stats: BundleStats[] = []; - for (const [file, output] of Object.entries(metafile.outputs)) { - // Only display JavaScript and CSS files - if (!file.endsWith('.js') && !file.endsWith('.css')) { - continue; - } - // Skip internal component resources - // eslint-disable-next-line @typescript-eslint/no-explicit-any - if ((output as any)['ng-component']) { - continue; - } - - stats.push({ - initial: initial.has(file), - stats: [ - file, - initial.get(file)?.name ?? '-', - output.bytes, - estimatedTransferSizes?.get(file) ?? '-', - ], - }); - } - - const tableText = generateBuildStatsTable(stats, true, true, !!estimatedTransferSizes, undefined); - - context.logger.info('\n' + tableText + '\n'); -} - -async function calculateEstimatedTransferSizes(outputFiles: OutputFile[]) { - const sizes = new Map(); - - const pendingCompression = []; - for (const outputFile of outputFiles) { - // Only calculate JavaScript and CSS files - if (!outputFile.path.endsWith('.js') && !outputFile.path.endsWith('.css')) { - continue; - } - - // Skip compressing small files which may end being larger once compressed and will most likely not be - // compressed in actual transit. - if (outputFile.contents.byteLength < 1024) { - sizes.set(outputFile.path, outputFile.contents.byteLength); - continue; - } - - pendingCompression.push( - compressAsync(outputFile.contents).then((result) => - sizes.set(outputFile.path, result.byteLength), - ), - ); - } - - await Promise.all(pendingCompression); - - return sizes; -} diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/options.ts b/packages/angular_devkit/build_angular/src/builders/browser-esbuild/options.ts index eca625eef575..5c87bf7396c5 100644 --- a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/options.ts +++ b/packages/angular_devkit/build_angular/src/builders/browser-esbuild/options.ts @@ -9,12 +9,15 @@ import { BuilderContext } from '@angular-devkit/architect'; import { createRequire } from 'node:module'; import path from 'node:path'; +import { + globalScriptsByBundleName, + normalizeGlobalStyles, +} from '../../tools/webpack/utils/helpers'; import { normalizeAssetPatterns, normalizeOptimization, normalizeSourceMaps } from '../../utils'; import { normalizeCacheOptions } from '../../utils/normalize-cache'; import { generateEntryPoints } from '../../utils/package-chunk-sort'; import { findTailwindConfigurationFile } from '../../utils/tailwind'; import { getIndexInputFile, getIndexOutputFile } from '../../utils/webpack-browser-config'; -import { globalScriptsByBundleName, normalizeGlobalStyles } from '../../webpack/utils/helpers'; import { Schema as BrowserBuilderOptions, OutputHashing } from './schema'; export type NormalizedBrowserOptions = Awaited>; diff --git a/packages/angular_devkit/build_angular/src/builders/browser/index.ts b/packages/angular_devkit/build_angular/src/builders/browser/index.ts index 2c245a5e6253..d915ed0d71ba 100644 --- a/packages/angular_devkit/build_angular/src/builders/browser/index.ts +++ b/packages/angular_devkit/build_angular/src/builders/browser/index.ts @@ -12,6 +12,18 @@ import * as fs from 'fs'; import * as path from 'path'; import { Observable, concatMap, from, map, switchMap } from 'rxjs'; import webpack, { StatsCompilation } from 'webpack'; +import { getCommonConfig, getStylesConfig } from '../../tools/webpack/configs'; +import { markAsyncChunksNonInitial } from '../../tools/webpack/utils/async-chunks'; +import { normalizeExtraEntryPoints } from '../../tools/webpack/utils/helpers'; +import { + BuildEventStats, + generateBuildEventStats, + statsErrorsToString, + statsHasErrors, + statsHasWarnings, + statsWarningsToString, + webpackStatsLogger, +} from '../../tools/webpack/utils/stats'; import { ExecutionTransformer } from '../../transforms'; import { deleteOutputDir, @@ -46,18 +58,6 @@ import { getIndexInputFile, getIndexOutputFile, } from '../../utils/webpack-browser-config'; -import { getCommonConfig, getStylesConfig } from '../../webpack/configs'; -import { markAsyncChunksNonInitial } from '../../webpack/utils/async-chunks'; -import { normalizeExtraEntryPoints } from '../../webpack/utils/helpers'; -import { - BuildEventStats, - generateBuildEventStats, - statsErrorsToString, - statsHasErrors, - statsHasWarnings, - statsWarningsToString, - webpackStatsLogger, -} from '../../webpack/utils/stats'; import { Schema as BrowserBuilderSchema } from './schema'; /** diff --git a/packages/angular_devkit/build_angular/src/builders/browser/tests/options/named-chunks_spec.ts b/packages/angular_devkit/build_angular/src/builders/browser/tests/options/named-chunks_spec.ts index 87d67ac17461..7ae1cfcdbaff 100644 --- a/packages/angular_devkit/build_angular/src/builders/browser/tests/options/named-chunks_spec.ts +++ b/packages/angular_devkit/build_angular/src/builders/browser/tests/options/named-chunks_spec.ts @@ -11,7 +11,7 @@ import { BASE_OPTIONS, BROWSER_BUILDER_INFO, describeBuilder } from '../setup'; const MAIN_OUTPUT = 'dist/main.js'; const NAMED_LAZY_OUTPUT = 'dist/src_lazy-module_ts.js'; -const UNNAMED_LAZY_OUTPUT = 'dist/459.js'; +const UNNAMED_LAZY_OUTPUT = 'dist/631.js'; describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => { describe('Option: "namedChunks"', () => { diff --git a/packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts b/packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts index 4de5f3bc1069..3e9ee01ea4d0 100644 --- a/packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts +++ b/packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts @@ -16,8 +16,8 @@ import { readFile } from 'node:fs/promises'; import type { AddressInfo } from 'node:net'; import path from 'node:path'; import { InlineConfig, ViteDevServer, createServer, normalizePath } from 'vite'; +import { JavaScriptTransformer } from '../../tools/esbuild/javascript-transformer'; import { buildEsbuildBrowserInternal } from '../browser-esbuild'; -import { JavaScriptTransformer } from '../browser-esbuild/javascript-transformer'; import { BrowserEsbuildOptions } from '../browser-esbuild/options'; import type { Schema as BrowserBuilderOptions } from '../browser-esbuild/schema'; import { loadProxyConfiguration } from './load-proxy-config'; diff --git a/packages/angular_devkit/build_angular/src/builders/dev-server/webpack-server.ts b/packages/angular_devkit/build_angular/src/builders/dev-server/webpack-server.ts index 781ac9350a49..c67f2626d40e 100644 --- a/packages/angular_devkit/build_angular/src/builders/dev-server/webpack-server.ts +++ b/packages/angular_devkit/build_angular/src/builders/dev-server/webpack-server.ts @@ -18,6 +18,14 @@ import { Observable, concatMap, from, switchMap } from 'rxjs'; import * as url from 'url'; import webpack from 'webpack'; import webpackDevServer from 'webpack-dev-server'; +import { getCommonConfig, getDevServerConfig, getStylesConfig } from '../../tools/webpack/configs'; +import { IndexHtmlWebpackPlugin } from '../../tools/webpack/plugins/index-html-webpack-plugin'; +import { ServiceWorkerPlugin } from '../../tools/webpack/plugins/service-worker-plugin'; +import { + BuildEventStats, + createWebpackLoggingCallback, + generateBuildEventStats, +} from '../../tools/webpack/utils/stats'; import { ExecutionTransformer } from '../../transforms'; import { normalizeOptimization } from '../../utils'; import { colors } from '../../utils/color'; @@ -33,14 +41,6 @@ import { getIndexOutputFile, } from '../../utils/webpack-browser-config'; import { addError, addWarning } from '../../utils/webpack-diagnostics'; -import { getCommonConfig, getDevServerConfig, getStylesConfig } from '../../webpack/configs'; -import { IndexHtmlWebpackPlugin } from '../../webpack/plugins/index-html-webpack-plugin'; -import { ServiceWorkerPlugin } from '../../webpack/plugins/service-worker-plugin'; -import { - BuildEventStats, - createWebpackLoggingCallback, - generateBuildEventStats, -} from '../../webpack/utils/stats'; import { Schema as BrowserBuilderSchema, OutputHashing } from '../browser/schema'; import { NormalizedDevServerOptions } from './options'; @@ -317,7 +317,7 @@ async function setupLocalize( enforce: 'post', use: [ { - loader: require.resolve('../../babel/webpack-loader'), + loader: require.resolve('../../tools/babel/webpack-loader'), options: { cacheDirectory: (cacheOptions.enabled && path.join(cacheOptions.path, 'babel-dev-server-i18n')) || diff --git a/packages/angular_devkit/build_angular/src/builders/extract-i18n/index.ts b/packages/angular_devkit/build_angular/src/builders/extract-i18n/index.ts index 4fe63607496e..96116bdf712a 100644 --- a/packages/angular_devkit/build_angular/src/builders/extract-i18n/index.ts +++ b/packages/angular_devkit/build_angular/src/builders/extract-i18n/index.ts @@ -15,14 +15,14 @@ import * as fs from 'fs'; import * as path from 'path'; import { lastValueFrom } from 'rxjs'; import webpack, { Configuration } from 'webpack'; +import { getCommonConfig } from '../../tools/webpack/configs'; +import { createWebpackLoggingCallback } from '../../tools/webpack/utils/stats'; import { ExecutionTransformer } from '../../transforms'; import { createI18nOptions } from '../../utils/i18n-options'; import { loadEsmModule } from '../../utils/load-esm'; import { purgeStaleBuildCache } from '../../utils/purge-cache'; import { assertCompatibleAngularVersion } from '../../utils/version'; import { generateBrowserWebpackConfigFromContext } from '../../utils/webpack-browser-config'; -import { getCommonConfig } from '../../webpack/configs'; -import { createWebpackLoggingCallback } from '../../webpack/utils/stats'; import { Schema as BrowserBuilderOptions, OutputHashing } from '../browser/schema'; import { Format, Schema } from './schema'; diff --git a/packages/angular_devkit/build_angular/src/builders/karma/index.ts b/packages/angular_devkit/build_angular/src/builders/karma/index.ts index 5dbc0c590858..7c96f9fe91e4 100644 --- a/packages/angular_devkit/build_angular/src/builders/karma/index.ts +++ b/packages/angular_devkit/build_angular/src/builders/karma/index.ts @@ -13,11 +13,11 @@ import { createRequire } from 'module'; import * as path from 'path'; import { Observable, defaultIfEmpty, from, switchMap } from 'rxjs'; import { Configuration } from 'webpack'; +import { getCommonConfig, getStylesConfig } from '../../tools/webpack/configs'; import { ExecutionTransformer } from '../../transforms'; import { purgeStaleBuildCache } from '../../utils/purge-cache'; import { assertCompatibleAngularVersion } from '../../utils/version'; import { generateBrowserWebpackConfigFromContext } from '../../utils/webpack-browser-config'; -import { getCommonConfig, getStylesConfig } from '../../webpack/configs'; import { Schema as BrowserBuilderOptions, OutputHashing } from '../browser/schema'; import { FindTestsPlugin } from './find-tests-plugin'; import { Schema as KarmaBuilderOptions } from './schema'; diff --git a/packages/angular_devkit/build_angular/src/builders/server/index.ts b/packages/angular_devkit/build_angular/src/builders/server/index.ts index 7dc4fce07e2b..e76825e86f67 100644 --- a/packages/angular_devkit/build_angular/src/builders/server/index.ts +++ b/packages/angular_devkit/build_angular/src/builders/server/index.ts @@ -12,6 +12,15 @@ import { readFile } from 'node:fs/promises'; import * as path from 'node:path'; import { Observable, concatMap, from } from 'rxjs'; import webpack, { Configuration } from 'webpack'; +import { getCommonConfig, getStylesConfig } from '../../tools/webpack/configs'; +import { isPlatformServerInstalled } from '../../tools/webpack/utils/helpers'; +import { + statsErrorsToString, + statsHasErrors, + statsHasWarnings, + statsWarningsToString, + webpackStatsLogger, +} from '../../tools/webpack/utils/stats'; import { ExecutionTransformer } from '../../transforms'; import { NormalizedBrowserBuilderSchema, @@ -31,15 +40,6 @@ import { BrowserWebpackConfigOptions, generateI18nBrowserWebpackConfigFromContext, } from '../../utils/webpack-browser-config'; -import { getCommonConfig, getStylesConfig } from '../../webpack/configs'; -import { isPlatformServerInstalled } from '../../webpack/utils/helpers'; -import { - statsErrorsToString, - statsHasErrors, - statsHasWarnings, - statsWarningsToString, - webpackStatsLogger, -} from '../../webpack/utils/stats'; import { Schema as ServerBuilderOptions } from './schema'; /** diff --git a/packages/angular_devkit/build_angular/src/testing/file-watching.ts b/packages/angular_devkit/build_angular/src/testing/file-watching.ts index a09c38dc8645..8263fb874ef6 100644 --- a/packages/angular_devkit/build_angular/src/testing/file-watching.ts +++ b/packages/angular_devkit/build_angular/src/testing/file-watching.ts @@ -9,7 +9,7 @@ import { BuilderWatcherCallback, BuilderWatcherFactory, -} from '../webpack/plugins/builder-watch-plugin'; +} from '../tools/webpack/plugins/builder-watch-plugin'; class WatcherDescriptor { constructor( diff --git a/packages/angular_devkit/build_angular/src/babel/babel-loader.d.ts b/packages/angular_devkit/build_angular/src/tools/babel/babel-loader.d.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/babel/babel-loader.d.ts rename to packages/angular_devkit/build_angular/src/tools/babel/babel-loader.d.ts diff --git a/packages/angular_devkit/build_angular/src/babel/plugins/adjust-static-class-members.ts b/packages/angular_devkit/build_angular/src/tools/babel/plugins/adjust-static-class-members.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/babel/plugins/adjust-static-class-members.ts rename to packages/angular_devkit/build_angular/src/tools/babel/plugins/adjust-static-class-members.ts diff --git a/packages/angular_devkit/build_angular/src/babel/plugins/adjust-static-class-members_spec.ts b/packages/angular_devkit/build_angular/src/tools/babel/plugins/adjust-static-class-members_spec.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/babel/plugins/adjust-static-class-members_spec.ts rename to packages/angular_devkit/build_angular/src/tools/babel/plugins/adjust-static-class-members_spec.ts diff --git a/packages/angular_devkit/build_angular/src/babel/plugins/adjust-typescript-enums.ts b/packages/angular_devkit/build_angular/src/tools/babel/plugins/adjust-typescript-enums.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/babel/plugins/adjust-typescript-enums.ts rename to packages/angular_devkit/build_angular/src/tools/babel/plugins/adjust-typescript-enums.ts diff --git a/packages/angular_devkit/build_angular/src/babel/plugins/adjust-typescript-enums_spec.ts b/packages/angular_devkit/build_angular/src/tools/babel/plugins/adjust-typescript-enums_spec.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/babel/plugins/adjust-typescript-enums_spec.ts rename to packages/angular_devkit/build_angular/src/tools/babel/plugins/adjust-typescript-enums_spec.ts diff --git a/packages/angular_devkit/build_angular/src/babel/plugins/elide-angular-metadata.ts b/packages/angular_devkit/build_angular/src/tools/babel/plugins/elide-angular-metadata.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/babel/plugins/elide-angular-metadata.ts rename to packages/angular_devkit/build_angular/src/tools/babel/plugins/elide-angular-metadata.ts diff --git a/packages/angular_devkit/build_angular/src/babel/plugins/elide-angular-metadata_spec.ts b/packages/angular_devkit/build_angular/src/tools/babel/plugins/elide-angular-metadata_spec.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/babel/plugins/elide-angular-metadata_spec.ts rename to packages/angular_devkit/build_angular/src/tools/babel/plugins/elide-angular-metadata_spec.ts diff --git a/packages/angular_devkit/build_angular/src/babel/plugins/pure-toplevel-functions.ts b/packages/angular_devkit/build_angular/src/tools/babel/plugins/pure-toplevel-functions.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/babel/plugins/pure-toplevel-functions.ts rename to packages/angular_devkit/build_angular/src/tools/babel/plugins/pure-toplevel-functions.ts diff --git a/packages/angular_devkit/build_angular/src/babel/plugins/pure-toplevel-functions_spec.ts b/packages/angular_devkit/build_angular/src/tools/babel/plugins/pure-toplevel-functions_spec.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/babel/plugins/pure-toplevel-functions_spec.ts rename to packages/angular_devkit/build_angular/src/tools/babel/plugins/pure-toplevel-functions_spec.ts diff --git a/packages/angular_devkit/build_angular/src/babel/presets/application.ts b/packages/angular_devkit/build_angular/src/tools/babel/presets/application.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/babel/presets/application.ts rename to packages/angular_devkit/build_angular/src/tools/babel/presets/application.ts diff --git a/packages/angular_devkit/build_angular/src/babel/webpack-loader.ts b/packages/angular_devkit/build_angular/src/tools/babel/webpack-loader.ts similarity index 98% rename from packages/angular_devkit/build_angular/src/babel/webpack-loader.ts rename to packages/angular_devkit/build_angular/src/tools/babel/webpack-loader.ts index 743f94b748d2..f8080253a4f3 100644 --- a/packages/angular_devkit/build_angular/src/babel/webpack-loader.ts +++ b/packages/angular_devkit/build_angular/src/tools/babel/webpack-loader.ts @@ -7,8 +7,8 @@ */ import { custom } from 'babel-loader'; -import { loadEsmModule } from '../utils/load-esm'; -import { VERSION } from '../utils/package-version'; +import { loadEsmModule } from '../../utils/load-esm'; +import { VERSION } from '../../utils/package-version'; import { ApplicationPresetOptions, I18nPluginCreators } from './presets/application'; interface AngularCustomOptions extends Omit { diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/angular/angular-compilation.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/angular/angular-compilation.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/angular/angular-compilation.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/angular/angular-compilation.ts diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/angular/angular-host.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/angular/angular-host.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/angular/angular-host.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/angular/angular-host.ts diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/angular/aot-compilation.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/angular/aot-compilation.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/angular/aot-compilation.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/angular/aot-compilation.ts diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/angular/compiler-plugin.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/angular/compiler-plugin.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/angular/compiler-plugin.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/angular/compiler-plugin.ts diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/angular/diagnostics.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/angular/diagnostics.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/angular/diagnostics.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/angular/diagnostics.ts diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/angular/jit-compilation.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/angular/jit-compilation.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/angular/jit-compilation.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/angular/jit-compilation.ts diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/angular/jit-plugin-callbacks.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/angular/jit-plugin-callbacks.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/angular/jit-plugin-callbacks.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/angular/jit-plugin-callbacks.ts diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/angular/jit-resource-transformer.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/angular/jit-resource-transformer.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/angular/jit-resource-transformer.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/angular/jit-resource-transformer.ts diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/angular/uri.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/angular/uri.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/angular/uri.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/angular/uri.ts diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/esbuild.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/bundler-context.ts similarity index 91% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/esbuild.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/bundler-context.ts index 43910efa3837..50d38243f290 100644 --- a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/esbuild.ts +++ b/packages/angular_devkit/build_angular/src/tools/esbuild/bundler-context.ts @@ -6,7 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -import { BuilderContext } from '@angular-devkit/architect'; import { BuildContext, BuildFailure, @@ -14,10 +13,8 @@ import { Message, Metafile, OutputFile, - PartialMessage, build, context, - formatMessages, } from 'esbuild'; import { basename, extname, relative } from 'node:path'; @@ -31,22 +28,22 @@ export type BundleContextResult = initialFiles: Map; }; +export interface InitialFileRecord { + entrypoint: boolean; + name?: string; + type: 'script' | 'style'; + external?: boolean; +} + /** * Determines if an unknown value is an esbuild BuildFailure error object thrown by esbuild. * @param value A potential esbuild BuildFailure error object. * @returns `true` if the object is determined to be a BuildFailure object; otherwise, `false`. */ -export function isEsBuildFailure(value: unknown): value is BuildFailure { +function isEsBuildFailure(value: unknown): value is BuildFailure { return !!value && typeof value === 'object' && 'errors' in value && 'warnings' in value; } -export interface InitialFileRecord { - entrypoint: boolean; - name?: string; - type: 'script' | 'style'; - external?: boolean; -} - export class BundlerContext { #esbuildContext?: BuildContext<{ metafile: true; write: false }>; #esbuildOptions: BuildOptions & { metafile: true; write: false }; @@ -224,18 +221,3 @@ export class BundlerContext { } } } - -export async function logMessages( - context: BuilderContext, - { errors, warnings }: { errors?: PartialMessage[]; warnings?: PartialMessage[] }, -): Promise { - if (warnings?.length) { - const warningMessages = await formatMessages(warnings, { kind: 'warning', color: true }); - context.logger.warn(warningMessages.join('\n')); - } - - if (errors?.length) { - const errorMessages = await formatMessages(errors, { kind: 'error', color: true }); - context.logger.error(errorMessages.join('\n')); - } -} diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/commonjs-checker.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/commonjs-checker.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/commonjs-checker.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/commonjs-checker.ts diff --git a/packages/angular_devkit/build_angular/src/tools/esbuild/external-packages-plugin.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/external-packages-plugin.ts new file mode 100644 index 000000000000..f17d5788ed51 --- /dev/null +++ b/packages/angular_devkit/build_angular/src/tools/esbuild/external-packages-plugin.ts @@ -0,0 +1,52 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import type { Plugin } from 'esbuild'; + +const EXTERNAL_PACKAGE_RESOLUTION = Symbol('EXTERNAL_PACKAGE_RESOLUTION'); + +/** + * Creates a plugin that marks any resolved path as external if it is within a node modules directory. + * This is used instead of the esbuild `packages` option to avoid marking bare specifiers that use + * tsconfig path mapping to resolve to a workspace relative path. This is common for monorepos that + * contain libraries that are built along with the application. These libraries should not be considered + * + * @returns An esbuild plugin. + */ +export function createExternalPackagesPlugin(): Plugin { + return { + name: 'angular-external-packages', + setup(build) { + build.onResolve({ filter: /./ }, async (args) => { + if (args.pluginData?.[EXTERNAL_PACKAGE_RESOLUTION]) { + return null; + } + + const { importer, kind, resolveDir, namespace, pluginData = {} } = args; + pluginData[EXTERNAL_PACKAGE_RESOLUTION] = true; + + const result = await build.resolve(args.path, { + importer, + kind, + namespace, + pluginData, + resolveDir, + }); + + if (result.path && /[\\/]node_modules[\\/]/.test(result.path)) { + return { + path: args.path, + external: true, + }; + } + + return result; + }); + }, + }; +} diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/global-scripts.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/global-scripts.ts similarity index 98% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/global-scripts.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/global-scripts.ts index 80997989e1d2..d3ca2c0c3d85 100644 --- a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/global-scripts.ts +++ b/packages/angular_devkit/build_angular/src/tools/esbuild/global-scripts.ts @@ -11,9 +11,9 @@ import MagicString, { Bundle } from 'magic-string'; import assert from 'node:assert'; import { readFile } from 'node:fs/promises'; import path from 'node:path'; +import type { NormalizedBrowserOptions } from '../../builders/browser-esbuild/options'; import { assertIsError } from '../../utils/error'; import { LoadResultCache, createCachedLoad } from './load-result-cache'; -import type { NormalizedBrowserOptions } from './options'; import { createSourcemapIngorelistPlugin } from './sourcemap-ignorelist-plugin'; import { createVirtualModulePlugin } from './virtual-module-plugin'; diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/global-styles.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/global-styles.ts similarity index 96% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/global-styles.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/global-styles.ts index 26cf52172293..0722cb361250 100644 --- a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/global-styles.ts +++ b/packages/angular_devkit/build_angular/src/tools/esbuild/global-styles.ts @@ -8,8 +8,8 @@ import type { BuildOptions } from 'esbuild'; import assert from 'node:assert'; +import { NormalizedBrowserOptions } from '../../builders/browser-esbuild/options'; import { LoadResultCache } from './load-result-cache'; -import { NormalizedBrowserOptions } from './options'; import { createStylesheetBundleOptions } from './stylesheets/bundle-options'; import { createVirtualModulePlugin } from './virtual-module-plugin'; diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/javascript-transformer-worker.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/javascript-transformer-worker.ts similarity index 95% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/javascript-transformer-worker.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/javascript-transformer-worker.ts index 1a4bc1106f60..3d7cdadd4f24 100644 --- a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/javascript-transformer-worker.ts +++ b/packages/angular_devkit/build_angular/src/tools/esbuild/javascript-transformer-worker.ts @@ -8,8 +8,8 @@ import { transformAsync } from '@babel/core'; import { readFile } from 'node:fs/promises'; -import angularApplicationPreset from '../../babel/presets/application'; -import { requiresLinking } from '../../babel/webpack-loader'; +import angularApplicationPreset from '../../tools/babel/presets/application'; +import { requiresLinking } from '../../tools/babel/webpack-loader'; import { loadEsmModule } from '../../utils/load-esm'; interface JavaScriptTransformRequest { diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/javascript-transformer.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/javascript-transformer.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/javascript-transformer.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/javascript-transformer.ts diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/license-extractor.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/license-extractor.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/license-extractor.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/license-extractor.ts diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/load-result-cache.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/load-result-cache.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/load-result-cache.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/load-result-cache.ts diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/profiling.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/profiling.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/profiling.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/profiling.ts diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/sourcemap-ignorelist-plugin.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/sourcemap-ignorelist-plugin.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/sourcemap-ignorelist-plugin.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/sourcemap-ignorelist-plugin.ts diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/stylesheets/bundle-options.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/stylesheets/bundle-options.ts similarity index 99% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/stylesheets/bundle-options.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/stylesheets/bundle-options.ts index 587d9e337a77..3b5aa3fa33eb 100644 --- a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/stylesheets/bundle-options.ts +++ b/packages/angular_devkit/build_angular/src/tools/esbuild/stylesheets/bundle-options.ts @@ -9,7 +9,7 @@ import type { BuildOptions, OutputFile } from 'esbuild'; import { createHash } from 'node:crypto'; import path from 'node:path'; -import { BundlerContext } from '../esbuild'; +import { BundlerContext } from '../bundler-context'; import { LoadResultCache } from '../load-result-cache'; import { CssStylesheetLanguage } from './css-language'; import { createCssResourcePlugin } from './css-resource-plugin'; diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/stylesheets/css-language.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/stylesheets/css-language.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/stylesheets/css-language.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/stylesheets/css-language.ts diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/stylesheets/css-resource-plugin.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/stylesheets/css-resource-plugin.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/stylesheets/css-resource-plugin.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/stylesheets/css-resource-plugin.ts diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/stylesheets/less-language.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/stylesheets/less-language.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/stylesheets/less-language.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/stylesheets/less-language.ts diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/stylesheets/sass-language.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/stylesheets/sass-language.ts similarity index 98% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/stylesheets/sass-language.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/stylesheets/sass-language.ts index 559fdd8fe114..eb4a0c9d532c 100644 --- a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/stylesheets/sass-language.ts +++ b/packages/angular_devkit/build_angular/src/tools/esbuild/stylesheets/sass-language.ts @@ -13,7 +13,7 @@ import type { CompileResult, Exception, Syntax } from 'sass'; import type { FileImporterWithRequestContextOptions, SassWorkerImplementation, -} from '../../../sass/sass-service'; +} from '../../sass/sass-service'; import { StylesheetLanguage, StylesheetPluginOptions } from './stylesheet-plugin-factory'; let sassWorkerPool: SassWorkerImplementation | undefined; @@ -70,7 +70,7 @@ async function compileString( ): Promise { // Lazily load Sass when a Sass file is found if (sassWorkerPool === undefined) { - const sassService = await import('../../../sass/sass-service'); + const sassService = await import('../../sass/sass-service'); sassWorkerPool = new sassService.SassWorkerImplementation(true); } diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/stylesheets/stylesheet-plugin-factory.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/stylesheets/stylesheet-plugin-factory.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.ts diff --git a/packages/angular_devkit/build_angular/src/tools/esbuild/utils.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/utils.ts new file mode 100644 index 000000000000..f9580a048c95 --- /dev/null +++ b/packages/angular_devkit/build_angular/src/tools/esbuild/utils.ts @@ -0,0 +1,221 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import { BuilderContext } from '@angular-devkit/architect'; +import { BuildOptions, Metafile, OutputFile, PartialMessage, formatMessages } from 'esbuild'; +import { constants as fsConstants } from 'node:fs'; +import fs from 'node:fs/promises'; +import path from 'node:path'; +import { promisify } from 'node:util'; +import { brotliCompress } from 'node:zlib'; +import { Spinner } from '../../utils/spinner'; +import { BundleStats, generateBuildStatsTable } from '../webpack/utils/stats'; +import { InitialFileRecord } from './bundler-context'; + +const compressAsync = promisify(brotliCompress); + +export function logBuildStats( + context: BuilderContext, + metafile: Metafile, + initial: Map, + estimatedTransferSizes?: Map, +): void { + const stats: BundleStats[] = []; + for (const [file, output] of Object.entries(metafile.outputs)) { + // Only display JavaScript and CSS files + if (!file.endsWith('.js') && !file.endsWith('.css')) { + continue; + } + // Skip internal component resources + // eslint-disable-next-line @typescript-eslint/no-explicit-any + if ((output as any)['ng-component']) { + continue; + } + + stats.push({ + initial: initial.has(file), + stats: [ + file, + initial.get(file)?.name ?? '-', + output.bytes, + estimatedTransferSizes?.get(file) ?? '-', + ], + }); + } + + const tableText = generateBuildStatsTable(stats, true, true, !!estimatedTransferSizes, undefined); + + context.logger.info('\n' + tableText + '\n'); +} + +export async function calculateEstimatedTransferSizes( + outputFiles: OutputFile[], +): Promise> { + const sizes = new Map(); + const pendingCompression = []; + + for (const outputFile of outputFiles) { + // Only calculate JavaScript and CSS files + if (!outputFile.path.endsWith('.js') && !outputFile.path.endsWith('.css')) { + continue; + } + + // Skip compressing small files which may end being larger once compressed and will most likely not be + // compressed in actual transit. + if (outputFile.contents.byteLength < 1024) { + sizes.set(outputFile.path, outputFile.contents.byteLength); + continue; + } + + pendingCompression.push( + compressAsync(outputFile.contents).then((result) => + sizes.set(outputFile.path, result.byteLength), + ), + ); + } + + await Promise.all(pendingCompression); + + return sizes; +} + +export async function withSpinner(text: string, action: () => T | Promise): Promise { + const spinner = new Spinner(text); + spinner.start(); + + try { + return await action(); + } finally { + spinner.stop(); + } +} + +export async function withNoProgress(test: string, action: () => T | Promise): Promise { + return action(); +} + +export async function logMessages( + context: BuilderContext, + { errors, warnings }: { errors?: PartialMessage[]; warnings?: PartialMessage[] }, +): Promise { + if (warnings?.length) { + const warningMessages = await formatMessages(warnings, { kind: 'warning', color: true }); + context.logger.warn(warningMessages.join('\n')); + } + + if (errors?.length) { + const errorMessages = await formatMessages(errors, { kind: 'error', color: true }); + context.logger.error(errorMessages.join('\n')); + } +} + +/** + * Generates a syntax feature object map for Angular applications based on a list of targets. + * A full set of feature names can be found here: https://esbuild.github.io/api/#supported + * @param target An array of browser/engine targets in the format accepted by the esbuild `target` option. + * @returns An object that can be used with the esbuild build `supported` option. + */ +export function getFeatureSupport(target: string[]): BuildOptions['supported'] { + const supported: Record = { + // Native async/await is not supported with Zone.js. Disabling support here will cause + // esbuild to downlevel async/await and for await...of to a Zone.js supported form. However, esbuild + // does not currently support downleveling async generators. Instead babel is used within the JS/TS + // loader to perform the downlevel transformation. + // NOTE: If esbuild adds support in the future, the babel support for async generators can be disabled. + 'async-await': false, + // V8 currently has a performance defect involving object spread operations that can cause signficant + // degradation in runtime performance. By not supporting the language feature here, a downlevel form + // will be used instead which provides a workaround for the performance issue. + // For more details: https://bugs.chromium.org/p/v8/issues/detail?id=11536 + 'object-rest-spread': false, + // esbuild currently has a defect involving self-referencing a class within a static code block or + // static field initializer. This is not an issue for projects that use the default browserslist as these + // elements are an ES2022 feature which is not support by all browsers in the default list. However, if a + // custom browserslist is used that only has newer browsers than the static code elements may be present. + // This issue is compounded by the default usage of the tsconfig `"useDefineForClassFields": false` option + // present in generated CLI projects which causes static code blocks to be used instead of static fields. + // esbuild currently unconditionally downlevels all static fields in top-level classes so to workaround the + // Angular issue only static code blocks are disabled here. + // For more details: https://github.com/evanw/esbuild/issues/2950 + 'class-static-blocks': false, + }; + + // Detect Safari browser versions that have a class field behavior bug + // See: https://github.com/angular/angular-cli/issues/24355#issuecomment-1333477033 + // See: https://github.com/WebKit/WebKit/commit/e8788a34b3d5f5b4edd7ff6450b80936bff396f2 + let safariClassFieldScopeBug = false; + for (const browser of target) { + let majorVersion; + if (browser.startsWith('ios')) { + majorVersion = Number(browser.slice(3, 5)); + } else if (browser.startsWith('safari')) { + majorVersion = Number(browser.slice(6, 8)); + } else { + continue; + } + // Technically, 14.0 is not broken but rather does not have support. However, the behavior + // is identical since it would be set to false by esbuild if present as a target. + if (majorVersion === 14 || majorVersion === 15) { + safariClassFieldScopeBug = true; + break; + } + } + // If class field support cannot be used set to false; otherwise leave undefined to allow + // esbuild to use `target` to determine support. + if (safariClassFieldScopeBug) { + supported['class-field'] = false; + supported['class-static-field'] = false; + } + + return supported; +} + +export async function writeResultFiles( + outputFiles: OutputFile[], + assetFiles: { source: string; destination: string }[] | undefined, + outputPath: string, +) { + const directoryExists = new Set(); + await Promise.all( + outputFiles.map(async (file) => { + // Ensure output subdirectories exist + const basePath = path.dirname(file.path); + if (basePath && !directoryExists.has(basePath)) { + await fs.mkdir(path.join(outputPath, basePath), { recursive: true }); + directoryExists.add(basePath); + } + // Write file contents + await fs.writeFile(path.join(outputPath, file.path), file.contents); + }), + ); + + if (assetFiles?.length) { + await Promise.all( + assetFiles.map(async ({ source, destination }) => { + // Ensure output subdirectories exist + const basePath = path.dirname(destination); + if (basePath && !directoryExists.has(basePath)) { + await fs.mkdir(path.join(outputPath, basePath), { recursive: true }); + directoryExists.add(basePath); + } + // Copy file contents + await fs.copyFile(source, path.join(outputPath, destination), fsConstants.COPYFILE_FICLONE); + }), + ); + } +} + +export function createOutputFileFromText(path: string, text: string): OutputFile { + return { + path, + text, + get contents() { + return Buffer.from(this.text, 'utf-8'); + }, + }; +} diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/virtual-module-plugin.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/virtual-module-plugin.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/virtual-module-plugin.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/virtual-module-plugin.ts diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/watcher.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/watcher.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/builders/browser-esbuild/watcher.ts rename to packages/angular_devkit/build_angular/src/tools/esbuild/watcher.ts diff --git a/packages/angular_devkit/build_angular/src/sass/rebasing-importer.ts b/packages/angular_devkit/build_angular/src/tools/sass/rebasing-importer.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/sass/rebasing-importer.ts rename to packages/angular_devkit/build_angular/src/tools/sass/rebasing-importer.ts diff --git a/packages/angular_devkit/build_angular/src/sass/sass-service-legacy.ts b/packages/angular_devkit/build_angular/src/tools/sass/sass-service-legacy.ts similarity index 99% rename from packages/angular_devkit/build_angular/src/sass/sass-service-legacy.ts rename to packages/angular_devkit/build_angular/src/tools/sass/sass-service-legacy.ts index e1f64abad2d7..02a7ce0f2fff 100644 --- a/packages/angular_devkit/build_angular/src/sass/sass-service-legacy.ts +++ b/packages/angular_devkit/build_angular/src/tools/sass/sass-service-legacy.ts @@ -17,7 +17,7 @@ import { LegacySyncImporter as SyncImporter, } from 'sass'; import { MessageChannel, Worker } from 'worker_threads'; -import { maxWorkers } from '../utils/environment-options'; +import { maxWorkers } from '../../utils/environment-options'; /** * The maximum number of Workers that will be created to execute render requests. diff --git a/packages/angular_devkit/build_angular/src/sass/sass-service.ts b/packages/angular_devkit/build_angular/src/tools/sass/sass-service.ts similarity index 99% rename from packages/angular_devkit/build_angular/src/sass/sass-service.ts rename to packages/angular_devkit/build_angular/src/tools/sass/sass-service.ts index abdf6e76aa68..a4e23211f783 100644 --- a/packages/angular_devkit/build_angular/src/sass/sass-service.ts +++ b/packages/angular_devkit/build_angular/src/tools/sass/sass-service.ts @@ -19,7 +19,7 @@ import { StringOptionsWithImporter, StringOptionsWithoutImporter, } from 'sass'; -import { maxWorkers } from '../utils/environment-options'; +import { maxWorkers } from '../../utils/environment-options'; /** * The maximum number of Workers that will be created to execute render requests. diff --git a/packages/angular_devkit/build_angular/src/sass/worker-legacy.ts b/packages/angular_devkit/build_angular/src/tools/sass/worker-legacy.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/sass/worker-legacy.ts rename to packages/angular_devkit/build_angular/src/tools/sass/worker-legacy.ts diff --git a/packages/angular_devkit/build_angular/src/sass/worker.ts b/packages/angular_devkit/build_angular/src/tools/sass/worker.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/sass/worker.ts rename to packages/angular_devkit/build_angular/src/tools/sass/worker.ts diff --git a/packages/angular_devkit/build_angular/src/webpack/configs/common.ts b/packages/angular_devkit/build_angular/src/tools/webpack/configs/common.ts similarity index 98% rename from packages/angular_devkit/build_angular/src/webpack/configs/common.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/configs/common.ts index 0e7d98764699..f19052f3aca1 100644 --- a/packages/angular_devkit/build_angular/src/webpack/configs/common.ts +++ b/packages/angular_devkit/build_angular/src/tools/webpack/configs/common.ts @@ -17,10 +17,10 @@ import { SourceMapDevToolPlugin, } from 'webpack'; import { SubresourceIntegrityPlugin } from 'webpack-subresource-integrity'; +import { WebpackConfigOptions } from '../../../utils/build-options'; +import { allowMangle } from '../../../utils/environment-options'; +import { loadEsmModule } from '../../../utils/load-esm'; import { AngularBabelLoaderOptions } from '../../babel/webpack-loader'; -import { WebpackConfigOptions } from '../../utils/build-options'; -import { allowMangle } from '../../utils/environment-options'; -import { loadEsmModule } from '../../utils/load-esm'; import { CommonJsUsageWarnPlugin, DedupeModuleResolvePlugin, diff --git a/packages/angular_devkit/build_angular/src/webpack/configs/dev-server.ts b/packages/angular_devkit/build_angular/src/tools/webpack/configs/dev-server.ts similarity index 97% rename from packages/angular_devkit/build_angular/src/webpack/configs/dev-server.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/configs/dev-server.ts index 830223378e98..0dffc7537891 100644 --- a/packages/angular_devkit/build_angular/src/webpack/configs/dev-server.ts +++ b/packages/angular_devkit/build_angular/src/tools/webpack/configs/dev-server.ts @@ -12,10 +12,10 @@ import { extname, posix, resolve } from 'path'; import { URL, pathToFileURL } from 'url'; import { Configuration, RuleSetRule } from 'webpack'; import type { Configuration as DevServerConfiguration } from 'webpack-dev-server'; -import { WebpackConfigOptions, WebpackDevServerOptions } from '../../utils/build-options'; -import { assertIsError } from '../../utils/error'; -import { loadEsmModule } from '../../utils/load-esm'; -import { getIndexOutputFile } from '../../utils/webpack-browser-config'; +import { WebpackConfigOptions, WebpackDevServerOptions } from '../../../utils/build-options'; +import { assertIsError } from '../../../utils/error'; +import { loadEsmModule } from '../../../utils/load-esm'; +import { getIndexOutputFile } from '../../../utils/webpack-browser-config'; import { HmrLoader } from '../plugins/hmr/hmr-loader'; export async function getDevServerConfig( diff --git a/packages/angular_devkit/build_angular/src/webpack/configs/index.ts b/packages/angular_devkit/build_angular/src/tools/webpack/configs/index.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/webpack/configs/index.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/configs/index.ts diff --git a/packages/angular_devkit/build_angular/src/webpack/configs/styles.ts b/packages/angular_devkit/build_angular/src/tools/webpack/configs/styles.ts similarity index 98% rename from packages/angular_devkit/build_angular/src/webpack/configs/styles.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/configs/styles.ts index 33e1b825d41e..13e1b48ee328 100644 --- a/packages/angular_devkit/build_angular/src/webpack/configs/styles.ts +++ b/packages/angular_devkit/build_angular/src/tools/webpack/configs/styles.ts @@ -11,14 +11,14 @@ import * as path from 'node:path'; import { pathToFileURL } from 'node:url'; import type { FileImporter } from 'sass'; import type { Configuration, LoaderContext, RuleSetUseItem } from 'webpack'; +import { WebpackConfigOptions } from '../../../utils/build-options'; +import { useLegacySass } from '../../../utils/environment-options'; +import { findTailwindConfigurationFile } from '../../../utils/tailwind'; import { FileImporterWithRequestContextOptions, SassWorkerImplementation, } from '../../sass/sass-service'; import { SassLegacyWorkerImplementation } from '../../sass/sass-service-legacy'; -import { WebpackConfigOptions } from '../../utils/build-options'; -import { useLegacySass } from '../../utils/environment-options'; -import { findTailwindConfigurationFile } from '../../utils/tailwind'; import { AnyComponentStyleBudgetChecker, PostcssCliResources, diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/any-component-style-budget-checker.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/any-component-style-budget-checker.ts similarity index 93% rename from packages/angular_devkit/build_angular/src/webpack/plugins/any-component-style-budget-checker.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/any-component-style-budget-checker.ts index eb18e0917777..4402aa7a929e 100644 --- a/packages/angular_devkit/build_angular/src/webpack/plugins/any-component-style-budget-checker.ts +++ b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/any-component-style-budget-checker.ts @@ -8,13 +8,13 @@ import * as path from 'path'; import { Compilation, Compiler } from 'webpack'; -import { Budget, Type } from '../../builders/browser/schema'; +import { Budget, Type } from '../../../builders/browser/schema'; import { ThresholdSeverity, calculateThresholds, checkThresholds, -} from '../../utils/bundle-calculator'; -import { addError, addWarning } from '../../utils/webpack-diagnostics'; +} from '../../../utils/bundle-calculator'; +import { addError, addWarning } from '../../../utils/webpack-diagnostics'; const PLUGIN_NAME = 'AnyComponentStyleBudgetChecker'; diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/builder-watch-plugin.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/builder-watch-plugin.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/webpack/plugins/builder-watch-plugin.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/builder-watch-plugin.ts diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/common-js-usage-warn-plugin.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/common-js-usage-warn-plugin.ts similarity index 98% rename from packages/angular_devkit/build_angular/src/webpack/plugins/common-js-usage-warn-plugin.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/common-js-usage-warn-plugin.ts index a6e12bf72c33..e34f356fb81a 100644 --- a/packages/angular_devkit/build_angular/src/webpack/plugins/common-js-usage-warn-plugin.ts +++ b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/common-js-usage-warn-plugin.ts @@ -8,7 +8,7 @@ import { isAbsolute } from 'path'; import { Compilation, Compiler, Dependency, Module, NormalModule } from 'webpack'; -import { addWarning } from '../../utils/webpack-diagnostics'; +import { addWarning } from '../../../utils/webpack-diagnostics'; // Webpack doesn't export these so the deep imports can potentially break. const AMDDefineDependency = require('webpack/lib/dependencies/AMDDefineDependency'); diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/css-optimizer-plugin.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/css-optimizer-plugin.ts similarity index 97% rename from packages/angular_devkit/build_angular/src/webpack/plugins/css-optimizer-plugin.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/css-optimizer-plugin.ts index 548ce7b63372..3627c5f9a9bb 100644 --- a/packages/angular_devkit/build_angular/src/webpack/plugins/css-optimizer-plugin.ts +++ b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/css-optimizer-plugin.ts @@ -8,8 +8,8 @@ import type { Message, TransformResult } from 'esbuild'; import type { Compilation, Compiler, sources } from 'webpack'; -import { transformSupportedBrowsersToTargets } from '../../utils/esbuild-targets'; -import { addWarning } from '../../utils/webpack-diagnostics'; +import { transformSupportedBrowsersToTargets } from '../../../utils/esbuild-targets'; +import { addWarning } from '../../../utils/webpack-diagnostics'; import { EsbuildExecutor } from './esbuild-executor'; /** diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/dedupe-module-resolve-plugin.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/dedupe-module-resolve-plugin.ts similarity index 98% rename from packages/angular_devkit/build_angular/src/webpack/plugins/dedupe-module-resolve-plugin.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/dedupe-module-resolve-plugin.ts index 5c44420db96c..386ab22e6aa5 100644 --- a/packages/angular_devkit/build_angular/src/webpack/plugins/dedupe-module-resolve-plugin.ts +++ b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/dedupe-module-resolve-plugin.ts @@ -7,7 +7,7 @@ */ import { Compiler } from 'webpack'; -import { addWarning } from '../../utils/webpack-diagnostics'; +import { addWarning } from '../../../utils/webpack-diagnostics'; interface ResourceData { relativePath: string; diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/devtools-ignore-plugin.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/devtools-ignore-plugin.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/webpack/plugins/devtools-ignore-plugin.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/devtools-ignore-plugin.ts diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/esbuild-executor.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/esbuild-executor.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/webpack/plugins/esbuild-executor.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/esbuild-executor.ts diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/hmr/hmr-accept.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/hmr/hmr-accept.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/webpack/plugins/hmr/hmr-accept.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/hmr/hmr-accept.ts diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/hmr/hmr-loader.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/hmr/hmr-loader.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/webpack/plugins/hmr/hmr-loader.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/hmr/hmr-loader.ts diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/index-html-webpack-plugin.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/index-html-webpack-plugin.ts similarity index 92% rename from packages/angular_devkit/build_angular/src/webpack/plugins/index-html-webpack-plugin.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/index-html-webpack-plugin.ts index d7cfc58704e9..14f3a81069e1 100644 --- a/packages/angular_devkit/build_angular/src/webpack/plugins/index-html-webpack-plugin.ts +++ b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/index-html-webpack-plugin.ts @@ -8,14 +8,14 @@ import { basename, dirname, extname } from 'path'; import { Compilation, Compiler, sources } from 'webpack'; -import { assertIsError } from '../../utils/error'; -import { FileInfo } from '../../utils/index-file/augment-index-html'; +import { assertIsError } from '../../../utils/error'; +import { FileInfo } from '../../../utils/index-file/augment-index-html'; import { IndexHtmlGenerator, IndexHtmlGeneratorOptions, IndexHtmlGeneratorProcessOptions, -} from '../../utils/index-file/index-html-generator'; -import { addError, addWarning } from '../../utils/webpack-diagnostics'; +} from '../../../utils/index-file/index-html-generator'; +import { addError, addWarning } from '../../../utils/webpack-diagnostics'; export interface IndexHtmlWebpackPluginOptions extends IndexHtmlGeneratorOptions, diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/index.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/index.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/webpack/plugins/index.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/index.ts diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/javascript-optimizer-plugin.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/javascript-optimizer-plugin.ts similarity index 97% rename from packages/angular_devkit/build_angular/src/webpack/plugins/javascript-optimizer-plugin.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/javascript-optimizer-plugin.ts index a7bb0402a73e..3c1436522328 100644 --- a/packages/angular_devkit/build_angular/src/webpack/plugins/javascript-optimizer-plugin.ts +++ b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/javascript-optimizer-plugin.ts @@ -8,9 +8,9 @@ import Piscina from 'piscina'; import type { Compiler, sources } from 'webpack'; -import { maxWorkers } from '../../utils/environment-options'; -import { transformSupportedBrowsersToTargets } from '../../utils/esbuild-targets'; -import { addError } from '../../utils/webpack-diagnostics'; +import { maxWorkers } from '../../../utils/environment-options'; +import { transformSupportedBrowsersToTargets } from '../../../utils/esbuild-targets'; +import { addError } from '../../../utils/webpack-diagnostics'; import { EsbuildExecutor } from './esbuild-executor'; import type { OptimizeRequestOptions } from './javascript-optimizer-worker'; diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/javascript-optimizer-worker.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/javascript-optimizer-worker.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/webpack/plugins/javascript-optimizer-worker.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/javascript-optimizer-worker.ts diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/json-stats-plugin.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/json-stats-plugin.ts similarity index 90% rename from packages/angular_devkit/build_angular/src/webpack/plugins/json-stats-plugin.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/json-stats-plugin.ts index 6de412de69a2..1834bcb57631 100644 --- a/packages/angular_devkit/build_angular/src/webpack/plugins/json-stats-plugin.ts +++ b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/json-stats-plugin.ts @@ -9,9 +9,8 @@ import { createWriteStream, promises as fsPromises } from 'fs'; import { dirname } from 'path'; import { Compiler } from 'webpack'; -import { assertIsError } from '../../utils/error'; - -import { addError } from '../../utils/webpack-diagnostics'; +import { assertIsError } from '../../../utils/error'; +import { addError } from '../../../utils/webpack-diagnostics'; export class JsonStatsPlugin { constructor(private readonly statsOutputPath: string) {} diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/karma/karma-context.html b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/karma/karma-context.html similarity index 100% rename from packages/angular_devkit/build_angular/src/webpack/plugins/karma/karma-context.html rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/karma/karma-context.html diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/karma/karma-debug.html b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/karma/karma-debug.html similarity index 100% rename from packages/angular_devkit/build_angular/src/webpack/plugins/karma/karma-debug.html rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/karma/karma-debug.html diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/karma/karma.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/karma/karma.ts similarity index 98% rename from packages/angular_devkit/build_angular/src/webpack/plugins/karma/karma.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/karma/karma.ts index a2e7fc4b8a56..833dfa4c39d6 100644 --- a/packages/angular_devkit/build_angular/src/webpack/plugins/karma/karma.ts +++ b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/karma/karma.ts @@ -16,8 +16,8 @@ import webpackDevMiddleware from 'webpack-dev-middleware'; import { statsErrorsToString } from '../../utils/stats'; import { createConsoleLogger } from '@angular-devkit/core/node'; import { logging } from '@angular-devkit/core'; -import { BuildOptions } from '../../../utils/build-options'; -import { normalizeSourceMaps } from '../../../utils/index'; +import { BuildOptions } from '../../../../utils/build-options'; +import { normalizeSourceMaps } from '../../../../utils/index'; const KARMA_APPLICATION_PATH = '_karma_webpack_'; diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/named-chunks-plugin.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/named-chunks-plugin.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/webpack/plugins/named-chunks-plugin.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/named-chunks-plugin.ts diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/occurrences-plugin.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/occurrences-plugin.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/webpack/plugins/occurrences-plugin.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/occurrences-plugin.ts diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/postcss-cli-resources.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/postcss-cli-resources.ts similarity index 99% rename from packages/angular_devkit/build_angular/src/webpack/plugins/postcss-cli-resources.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/postcss-cli-resources.ts index f130d6c10e75..cec8a7e75161 100644 --- a/packages/angular_devkit/build_angular/src/webpack/plugins/postcss-cli-resources.ts +++ b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/postcss-cli-resources.ts @@ -10,7 +10,7 @@ import { interpolateName } from 'loader-utils'; import * as path from 'path'; import { Declaration, Plugin } from 'postcss'; import * as url from 'url'; -import { assertIsError } from '../../utils/error'; +import { assertIsError } from '../../../utils/error'; function wrapUrl(url: string): string { let wrappedUrl; diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/progress-plugin.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/progress-plugin.ts similarity index 95% rename from packages/angular_devkit/build_angular/src/webpack/plugins/progress-plugin.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/progress-plugin.ts index 0c3c2f33d411..740142b7c084 100644 --- a/packages/angular_devkit/build_angular/src/webpack/plugins/progress-plugin.ts +++ b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/progress-plugin.ts @@ -7,7 +7,7 @@ */ import { ProgressPlugin as WebpackProgressPlugin } from 'webpack'; -import { Spinner } from '../../utils/spinner'; +import { Spinner } from '../../../utils/spinner'; export class ProgressPlugin extends WebpackProgressPlugin { constructor(platform: 'server' | 'browser') { diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/remove-hash-plugin.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/remove-hash-plugin.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/webpack/plugins/remove-hash-plugin.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/remove-hash-plugin.ts diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/scripts-webpack-plugin.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/scripts-webpack-plugin.ts similarity index 98% rename from packages/angular_devkit/build_angular/src/webpack/plugins/scripts-webpack-plugin.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/scripts-webpack-plugin.ts index 8b438d26021d..c3dc68838caa 100644 --- a/packages/angular_devkit/build_angular/src/webpack/plugins/scripts-webpack-plugin.ts +++ b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/scripts-webpack-plugin.ts @@ -9,8 +9,8 @@ import { interpolateName } from 'loader-utils'; import * as path from 'path'; import { Chunk, Compilation, Compiler, sources as webpackSources } from 'webpack'; -import { assertIsError } from '../../utils/error'; -import { addError } from '../../utils/webpack-diagnostics'; +import { assertIsError } from '../../../utils/error'; +import { addError } from '../../../utils/webpack-diagnostics'; const Entrypoint = require('webpack/lib/Entrypoint'); diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/service-worker-plugin.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/service-worker-plugin.ts similarity index 96% rename from packages/angular_devkit/build_angular/src/webpack/plugins/service-worker-plugin.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/service-worker-plugin.ts index a42a6fa89db9..600089e27192 100644 --- a/packages/angular_devkit/build_angular/src/webpack/plugins/service-worker-plugin.ts +++ b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/service-worker-plugin.ts @@ -7,7 +7,7 @@ */ import type { Compiler } from 'webpack'; -import { augmentAppWithServiceWorker } from '../../utils/service-worker'; +import { augmentAppWithServiceWorker } from '../../../utils/service-worker'; export interface ServiceWorkerPluginOptions { projectRoot: string; diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/styles-webpack-plugin.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/styles-webpack-plugin.ts similarity index 95% rename from packages/angular_devkit/build_angular/src/webpack/plugins/styles-webpack-plugin.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/styles-webpack-plugin.ts index c364c2459820..84b5e990c0b2 100644 --- a/packages/angular_devkit/build_angular/src/webpack/plugins/styles-webpack-plugin.ts +++ b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/styles-webpack-plugin.ts @@ -8,8 +8,8 @@ import assert from 'assert'; import type { Compilation, Compiler } from 'webpack'; -import { assertIsError } from '../../utils/error'; -import { addError } from '../../utils/webpack-diagnostics'; +import { assertIsError } from '../../../utils/error'; +import { addError } from '../../../utils/webpack-diagnostics'; export interface StylesWebpackPluginOptions { preserveSymlinks?: boolean; diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/suppress-entry-chunks-webpack-plugin.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/suppress-entry-chunks-webpack-plugin.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/webpack/plugins/suppress-entry-chunks-webpack-plugin.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/suppress-entry-chunks-webpack-plugin.ts diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/transfer-size-plugin.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/transfer-size-plugin.ts similarity index 96% rename from packages/angular_devkit/build_angular/src/webpack/plugins/transfer-size-plugin.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/transfer-size-plugin.ts index 461a08967eec..440efb68489b 100644 --- a/packages/angular_devkit/build_angular/src/webpack/plugins/transfer-size-plugin.ts +++ b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/transfer-size-plugin.ts @@ -9,7 +9,7 @@ import { promisify } from 'util'; import { Compiler } from 'webpack'; import { brotliCompress } from 'zlib'; -import { addWarning } from '../../utils/webpack-diagnostics'; +import { addWarning } from '../../../utils/webpack-diagnostics'; const brotliCompressAsync = promisify(brotliCompress); diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/typescript.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/typescript.ts similarity index 97% rename from packages/angular_devkit/build_angular/src/webpack/plugins/typescript.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/typescript.ts index 60e1ae51f93c..7ad8290df9cc 100644 --- a/packages/angular_devkit/build_angular/src/webpack/plugins/typescript.ts +++ b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/typescript.ts @@ -9,7 +9,7 @@ import type { CompilerOptions } from '@angular/compiler-cli'; import { AngularWebpackPlugin } from '@ngtools/webpack'; import { ScriptTarget } from 'typescript'; -import { WebpackConfigOptions } from '../../utils/build-options'; +import { WebpackConfigOptions } from '../../../utils/build-options'; export function createIvyPlugin( wco: WebpackConfigOptions, diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/watch-files-logs-plugin.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/watch-files-logs-plugin.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/webpack/plugins/watch-files-logs-plugin.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/plugins/watch-files-logs-plugin.ts diff --git a/packages/angular_devkit/build_angular/src/webpack/utils/async-chunks.ts b/packages/angular_devkit/build_angular/src/tools/webpack/utils/async-chunks.ts similarity index 100% rename from packages/angular_devkit/build_angular/src/webpack/utils/async-chunks.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/utils/async-chunks.ts diff --git a/packages/angular_devkit/build_angular/src/webpack/utils/helpers.ts b/packages/angular_devkit/build_angular/src/tools/webpack/utils/helpers.ts similarity index 98% rename from packages/angular_devkit/build_angular/src/webpack/utils/helpers.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/utils/helpers.ts index 0bae8d699975..7d4dd5924077 100644 --- a/packages/angular_devkit/build_angular/src/webpack/utils/helpers.ts +++ b/packages/angular_devkit/build_angular/src/tools/webpack/utils/helpers.ts @@ -16,9 +16,9 @@ import { OutputHashing, ScriptElement, StyleElement, -} from '../../builders/browser/schema'; -import { WebpackConfigOptions } from '../../utils/build-options'; -import { VERSION } from '../../utils/package-version'; +} from '../../../builders/browser/schema'; +import { WebpackConfigOptions } from '../../../utils/build-options'; +import { VERSION } from '../../../utils/package-version'; export interface HashFormat { chunk: string; diff --git a/packages/angular_devkit/build_angular/src/webpack/utils/stats.ts b/packages/angular_devkit/build_angular/src/tools/webpack/utils/stats.ts similarity index 98% rename from packages/angular_devkit/build_angular/src/webpack/utils/stats.ts rename to packages/angular_devkit/build_angular/src/tools/webpack/utils/stats.ts index fac12ac468a5..afb310e231a8 100644 --- a/packages/angular_devkit/build_angular/src/webpack/utils/stats.ts +++ b/packages/angular_devkit/build_angular/src/tools/webpack/utils/stats.ts @@ -12,10 +12,10 @@ import assert from 'assert'; import * as path from 'path'; import textTable from 'text-table'; import { Configuration, StatsCompilation } from 'webpack'; -import { Schema as BrowserBuilderOptions } from '../../builders/browser/schema'; -import { normalizeOptimization } from '../../utils'; -import { BudgetCalculatorResult } from '../../utils/bundle-calculator'; -import { colors as ansiColors, removeColor } from '../../utils/color'; +import { Schema as BrowserBuilderOptions } from '../../../builders/browser/schema'; +import { normalizeOptimization } from '../../../utils'; +import { BudgetCalculatorResult } from '../../../utils/bundle-calculator'; +import { colors as ansiColors, removeColor } from '../../../utils/color'; import { markAsyncChunksNonInitial } from './async-chunks'; import { WebpackStatsOptions, getStatsOptions, normalizeExtraEntryPoints } from './helpers'; diff --git a/packages/angular_devkit/build_angular/src/utils/bundle-calculator.ts b/packages/angular_devkit/build_angular/src/utils/bundle-calculator.ts index 56662afd01b3..833193a9172c 100644 --- a/packages/angular_devkit/build_angular/src/utils/bundle-calculator.ts +++ b/packages/angular_devkit/build_angular/src/utils/bundle-calculator.ts @@ -8,7 +8,7 @@ import { StatsAsset, StatsChunk, StatsCompilation } from 'webpack'; import { Budget, Type } from '../builders/browser/schema'; -import { formatSize } from '../webpack/utils/stats'; +import { formatSize } from '../tools/webpack/utils/stats'; interface Size { size: number; diff --git a/packages/angular_devkit/build_angular/src/utils/package-chunk-sort.ts b/packages/angular_devkit/build_angular/src/utils/package-chunk-sort.ts index 78ca469f2265..e8188a7cdff5 100644 --- a/packages/angular_devkit/build_angular/src/utils/package-chunk-sort.ts +++ b/packages/angular_devkit/build_angular/src/utils/package-chunk-sort.ts @@ -7,7 +7,7 @@ */ import { ScriptElement, StyleElement } from '../builders/browser/schema'; -import { normalizeExtraEntryPoints } from '../webpack/utils/helpers'; +import { normalizeExtraEntryPoints } from '../tools/webpack/utils/helpers'; export type EntryPointsType = [name: string, isModule: boolean]; diff --git a/packages/angular_devkit/build_angular/src/utils/webpack-browser-config.ts b/packages/angular_devkit/build_angular/src/utils/webpack-browser-config.ts index abdcfa35c863..a727f845005b 100644 --- a/packages/angular_devkit/build_angular/src/utils/webpack-browser-config.ts +++ b/packages/angular_devkit/build_angular/src/utils/webpack-browser-config.ts @@ -12,10 +12,13 @@ import * as path from 'path'; import { Configuration, javascript } from 'webpack'; import { merge as webpackMerge } from 'webpack-merge'; import { Schema as BrowserBuilderSchema } from '../builders/browser/schema'; +import { + BuilderWatchPlugin, + BuilderWatcherFactory, +} from '../tools/webpack/plugins/builder-watch-plugin'; import { NormalizedBrowserBuilderSchema, defaultProgress, normalizeBrowserSchema } from '../utils'; import { WebpackConfigOptions } from '../utils/build-options'; import { readTsconfig } from '../utils/read-tsconfig'; -import { BuilderWatchPlugin, BuilderWatcherFactory } from '../webpack/plugins/builder-watch-plugin'; import { I18nOptions, configureI18nBuild } from './i18n-options'; export type BrowserWebpackConfigOptions = WebpackConfigOptions;