@angular-devkit/build-angular 14.0.0-next.9 → 14.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/builders.json +5 -0
  2. package/package.json +29 -29
  3. package/src/babel/presets/application.d.ts +3 -2
  4. package/src/babel/presets/application.js +2 -3
  5. package/src/babel/webpack-loader.d.ts +1 -0
  6. package/src/babel/webpack-loader.js +29 -15
  7. package/src/builders/app-shell/index.js +1 -1
  8. package/src/builders/browser/index.js +1 -1
  9. package/src/builders/browser-esbuild/compiler-plugin.d.ts +14 -0
  10. package/src/builders/browser-esbuild/compiler-plugin.js +338 -0
  11. package/src/builders/browser-esbuild/esbuild.d.ts +36 -0
  12. package/src/builders/browser-esbuild/esbuild.js +62 -0
  13. package/src/builders/browser-esbuild/experimental-warnings.d.ts +10 -0
  14. package/src/builders/browser-esbuild/experimental-warnings.js +65 -0
  15. package/src/builders/browser-esbuild/index.d.ts +19 -0
  16. package/src/builders/browser-esbuild/index.js +262 -0
  17. package/src/builders/browser-esbuild/options.d.ts +34 -0
  18. package/src/builders/browser-esbuild/options.js +87 -0
  19. package/src/builders/browser-esbuild/stylesheets.d.ts +52 -0
  20. package/src/builders/browser-esbuild/stylesheets.js +119 -0
  21. package/src/builders/protractor/index.js +50 -52
  22. package/src/utils/service-worker.d.ts +1 -1
  23. package/src/utils/service-worker.js +2 -2
  24. package/src/webpack/configs/common.js +1 -0
  25. package/src/webpack/configs/styles.d.ts +6 -0
  26. package/src/webpack/configs/styles.js +2 -1
  27. package/src/webpack/plugins/css-optimizer-plugin.js +7 -0
  28. package/src/webpack/plugins/javascript-optimizer-plugin.js +6 -0
  29. package/src/webpack/plugins/karma/karma.js +7 -27
  30. package/src/webpack/plugins/typescript.js +5 -0
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { BuilderContext } from '@angular-devkit/architect';
9
+ import { BuildFailure, BuildOptions, BuildResult, Message, OutputFile } from 'esbuild';
10
+ /** Default outdir setting for esbuild. */
11
+ export declare const DEFAULT_OUTDIR: string;
12
+ /**
13
+ * Determines if an unknown value is an esbuild BuildFailure error object thrown by esbuild.
14
+ * @param value A potential esbuild BuildFailure error object.
15
+ * @returns `true` if the object is determined to be a BuildFailure object; otherwise, `false`.
16
+ */
17
+ export declare function isEsBuildFailure(value: unknown): value is BuildFailure;
18
+ /**
19
+ * Executes the esbuild build function and normalizes the build result in the event of a
20
+ * build failure that results in no output being generated.
21
+ * All builds use the `write` option with a value of `false` to allow for the output files
22
+ * build result array to be populated.
23
+ *
24
+ * @param options The esbuild options object to use when building.
25
+ * @returns If output files are generated, the full esbuild BuildResult; if not, the
26
+ * warnings and errors for the attempted build.
27
+ */
28
+ export declare function bundle(options: BuildOptions): Promise<(BuildResult & {
29
+ outputFiles: OutputFile[];
30
+ }) | (BuildFailure & {
31
+ outputFiles?: never;
32
+ })>;
33
+ export declare function logMessages(context: BuilderContext, { errors, warnings }: {
34
+ errors: Message[];
35
+ warnings: Message[];
36
+ }): Promise<void>;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.logMessages = exports.bundle = exports.isEsBuildFailure = exports.DEFAULT_OUTDIR = void 0;
11
+ const esbuild_1 = require("esbuild");
12
+ const path_1 = require("path");
13
+ /** Default outdir setting for esbuild. */
14
+ exports.DEFAULT_OUTDIR = (0, path_1.resolve)('/virtual-output');
15
+ /**
16
+ * Determines if an unknown value is an esbuild BuildFailure error object thrown by esbuild.
17
+ * @param value A potential esbuild BuildFailure error object.
18
+ * @returns `true` if the object is determined to be a BuildFailure object; otherwise, `false`.
19
+ */
20
+ function isEsBuildFailure(value) {
21
+ return !!value && typeof value === 'object' && 'errors' in value && 'warnings' in value;
22
+ }
23
+ exports.isEsBuildFailure = isEsBuildFailure;
24
+ /**
25
+ * Executes the esbuild build function and normalizes the build result in the event of a
26
+ * build failure that results in no output being generated.
27
+ * All builds use the `write` option with a value of `false` to allow for the output files
28
+ * build result array to be populated.
29
+ *
30
+ * @param options The esbuild options object to use when building.
31
+ * @returns If output files are generated, the full esbuild BuildResult; if not, the
32
+ * warnings and errors for the attempted build.
33
+ */
34
+ async function bundle(options) {
35
+ try {
36
+ return await (0, esbuild_1.build)({
37
+ ...options,
38
+ write: false,
39
+ });
40
+ }
41
+ catch (failure) {
42
+ // Build failures will throw an exception which contains errors/warnings
43
+ if (isEsBuildFailure(failure)) {
44
+ return failure;
45
+ }
46
+ else {
47
+ throw failure;
48
+ }
49
+ }
50
+ }
51
+ exports.bundle = bundle;
52
+ async function logMessages(context, { errors, warnings }) {
53
+ if (warnings.length) {
54
+ const warningMessages = await (0, esbuild_1.formatMessages)(warnings, { kind: 'warning', color: true });
55
+ context.logger.warn(warningMessages.join('\n'));
56
+ }
57
+ if (errors.length) {
58
+ const errorMessages = await (0, esbuild_1.formatMessages)(errors, { kind: 'error', color: true });
59
+ context.logger.error(errorMessages.join('\n'));
60
+ }
61
+ }
62
+ exports.logMessages = logMessages;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { BuilderContext } from '@angular-devkit/architect';
9
+ import { Schema as BrowserBuilderOptions } from '../browser/schema';
10
+ export declare function logExperimentalWarnings(options: BrowserBuilderOptions, context: BuilderContext): void;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.logExperimentalWarnings = void 0;
11
+ const UNSUPPORTED_OPTIONS = [
12
+ 'allowedCommonJsDependencies',
13
+ 'budgets',
14
+ 'extractLicenses',
15
+ 'fileReplacements',
16
+ 'progress',
17
+ 'scripts',
18
+ 'statsJson',
19
+ // * i18n support
20
+ 'localize',
21
+ // The following two have no effect when localize is not enabled
22
+ // 'i18nDuplicateTranslation',
23
+ // 'i18nMissingTranslation',
24
+ // * Serviceworker support
25
+ 'ngswConfigPath',
26
+ 'serviceWorker',
27
+ // * Stylesheet preprocessor support
28
+ 'inlineStyleLanguage',
29
+ // The following option has no effect until preprocessors are supported
30
+ // 'stylePreprocessorOptions',
31
+ // * Watch mode
32
+ 'watch',
33
+ 'poll',
34
+ // * Deprecated
35
+ 'deployUrl',
36
+ // * Always enabled with esbuild
37
+ // 'commonChunk',
38
+ // * Currently unsupported by esbuild
39
+ 'namedChunks',
40
+ 'vendorChunk',
41
+ 'webWorkerTsConfig',
42
+ ];
43
+ function logExperimentalWarnings(options, context) {
44
+ // Warn about experimental status of this builder
45
+ context.logger.warn(`The esbuild browser application builder ('browser-esbuild') is currently experimental.`);
46
+ // Validate supported options
47
+ // Currently only a subset of the Webpack-based browser builder options are supported.
48
+ for (const unsupportedOption of UNSUPPORTED_OPTIONS) {
49
+ const value = options[unsupportedOption];
50
+ if (value === undefined || value === false) {
51
+ continue;
52
+ }
53
+ if (Array.isArray(value) && value.length === 0) {
54
+ continue;
55
+ }
56
+ if (typeof value === 'object' && Object.keys(value).length === 0) {
57
+ continue;
58
+ }
59
+ if (unsupportedOption === 'inlineStyleLanguage' && value === 'css') {
60
+ continue;
61
+ }
62
+ context.logger.warn(`The '${unsupportedOption}' option is currently unsupported by this experimental builder and will be ignored.`);
63
+ }
64
+ }
65
+ exports.logExperimentalWarnings = logExperimentalWarnings;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { BuilderContext, BuilderOutput } from '@angular-devkit/architect';
9
+ import { Schema as BrowserBuilderOptions } from '../browser/schema';
10
+ /**
11
+ * Main execution function for the esbuild-based application builder.
12
+ * The options are compatible with the Webpack-based builder.
13
+ * @param options The browser builder options to use when setting up the application build
14
+ * @param context The Architect builder context object
15
+ * @returns A promise with the builder result output
16
+ */
17
+ export declare function execute(options: BrowserBuilderOptions, context: BuilderContext): Promise<BuilderOutput>;
18
+ declare const _default: import("@angular-devkit/architect/src/internal").Builder<BrowserBuilderOptions & import("../../../../core/src").JsonObject>;
19
+ export default _default;
@@ -0,0 +1,262 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.execute = void 0;
34
+ const architect_1 = require("@angular-devkit/architect");
35
+ const assert = __importStar(require("assert"));
36
+ const fs_1 = require("fs");
37
+ const path = __importStar(require("path"));
38
+ const utils_1 = require("../../utils");
39
+ const copy_assets_1 = require("../../utils/copy-assets");
40
+ const index_html_generator_1 = require("../../utils/index-file/index-html-generator");
41
+ const package_chunk_sort_1 = require("../../utils/package-chunk-sort");
42
+ const webpack_browser_config_1 = require("../../utils/webpack-browser-config");
43
+ const configs_1 = require("../../webpack/configs");
44
+ const compiler_plugin_1 = require("./compiler-plugin");
45
+ const esbuild_1 = require("./esbuild");
46
+ const experimental_warnings_1 = require("./experimental-warnings");
47
+ const options_1 = require("./options");
48
+ const stylesheets_1 = require("./stylesheets");
49
+ /**
50
+ * Main execution function for the esbuild-based application builder.
51
+ * The options are compatible with the Webpack-based builder.
52
+ * @param options The browser builder options to use when setting up the application build
53
+ * @param context The Architect builder context object
54
+ * @returns A promise with the builder result output
55
+ */
56
+ // eslint-disable-next-line max-lines-per-function
57
+ async function execute(options, context) {
58
+ var _a, _b, _c, _d, _e, _f;
59
+ const startTime = Date.now();
60
+ // Only AOT is currently supported
61
+ if (options.aot !== true) {
62
+ context.logger.error('JIT mode is currently not supported by this experimental builder. AOT mode must be used.');
63
+ return { success: false };
64
+ }
65
+ // Inform user of experimental status of builder and options
66
+ (0, experimental_warnings_1.logExperimentalWarnings)(options, context);
67
+ // Determine project name from builder context target
68
+ const projectName = (_a = context.target) === null || _a === void 0 ? void 0 : _a.project;
69
+ if (!projectName) {
70
+ context.logger.error(`The 'browser-esbuild' builder requires a target to be specified.`);
71
+ return { success: false };
72
+ }
73
+ const { workspaceRoot, mainEntryPoint, polyfillsEntryPoint, optimizationOptions, outputPath, sourcemapOptions, tsconfig, assets, outputNames, } = await (0, options_1.normalizeOptions)(context, projectName, options);
74
+ // Clean output path if enabled
75
+ if (options.deleteOutputPath) {
76
+ (0, utils_1.deleteOutputDir)(workspaceRoot, options.outputPath);
77
+ }
78
+ // Setup bundler entry points
79
+ const entryPoints = {
80
+ main: mainEntryPoint,
81
+ };
82
+ if (polyfillsEntryPoint) {
83
+ entryPoints['polyfills'] = polyfillsEntryPoint;
84
+ }
85
+ // Create reverse lookup used during index HTML generation
86
+ const entryPointNameLookup = new Map(Object.entries(entryPoints).map(([name, filePath]) => [path.relative(workspaceRoot, filePath), name]));
87
+ // Execute esbuild
88
+ const result = await bundleCode(workspaceRoot, entryPoints, outputNames, options, optimizationOptions, sourcemapOptions, tsconfig);
89
+ // Log all warnings and errors generated during bundling
90
+ await (0, esbuild_1.logMessages)(context, result);
91
+ // Return if the bundling failed to generate output files or there are errors
92
+ if (!result.outputFiles || result.errors.length) {
93
+ return { success: false };
94
+ }
95
+ // Structure the bundling output files
96
+ const initialFiles = [];
97
+ const outputFiles = [];
98
+ for (const outputFile of result.outputFiles) {
99
+ // Entries in the metafile are relative to the `absWorkingDir` option which is set to the workspaceRoot
100
+ const relativeFilePath = path.relative(workspaceRoot, outputFile.path);
101
+ const entryPoint = (_c = (_b = result.metafile) === null || _b === void 0 ? void 0 : _b.outputs[relativeFilePath]) === null || _c === void 0 ? void 0 : _c.entryPoint;
102
+ outputFile.path = path.relative(esbuild_1.DEFAULT_OUTDIR, outputFile.path);
103
+ if (entryPoint) {
104
+ // An entryPoint value indicates an initial file
105
+ initialFiles.push({
106
+ file: outputFile.path,
107
+ name: (_d = entryPointNameLookup.get(entryPoint)) !== null && _d !== void 0 ? _d : '',
108
+ extension: path.extname(outputFile.path),
109
+ });
110
+ }
111
+ outputFiles.push(outputFile);
112
+ }
113
+ // Create output directory if needed
114
+ try {
115
+ await fs_1.promises.mkdir(outputPath, { recursive: true });
116
+ }
117
+ catch (e) {
118
+ const reason = 'message' in e ? e.message : 'Unknown error';
119
+ context.logger.error('Unable to create output directory: ' + reason);
120
+ return { success: false };
121
+ }
122
+ // Process global stylesheets
123
+ if (options.styles) {
124
+ // resolveGlobalStyles is temporarily reused from the Webpack builder code
125
+ const { entryPoints: stylesheetEntrypoints, noInjectNames } = (0, configs_1.resolveGlobalStyles)(options.styles, workspaceRoot, !!options.preserveSymlinks);
126
+ for (const [name, files] of Object.entries(stylesheetEntrypoints)) {
127
+ const virtualEntryData = files
128
+ .map((file) => `@import '${file.replace(/\\/g, '/')}';`)
129
+ .join('\n');
130
+ const sheetResult = await (0, stylesheets_1.bundleStylesheetText)(virtualEntryData, { virtualName: `angular:style/global;${name}`, resolvePath: workspaceRoot }, {
131
+ optimization: !!optimizationOptions.styles.minify,
132
+ sourcemap: !!sourcemapOptions.styles,
133
+ outputNames: noInjectNames.includes(name) ? { media: outputNames.media } : outputNames,
134
+ });
135
+ await (0, esbuild_1.logMessages)(context, sheetResult);
136
+ if (!sheetResult.path) {
137
+ // Failed to process the stylesheet
138
+ assert.ok(sheetResult.errors.length, `Global stylesheet processing for '${name}' failed with no errors.`);
139
+ return { success: false };
140
+ }
141
+ // The virtual stylesheets will be named `stdin` by esbuild. This must be replaced
142
+ // with the actual name of the global style and the leading directory separator must
143
+ // also be removed to make the path relative.
144
+ const sheetPath = sheetResult.path.replace('stdin', name);
145
+ outputFiles.push(createOutputFileFromText(sheetPath, sheetResult.contents));
146
+ if (sheetResult.map) {
147
+ outputFiles.push(createOutputFileFromText(sheetPath + '.map', sheetResult.map));
148
+ }
149
+ if (!noInjectNames.includes(name)) {
150
+ initialFiles.push({
151
+ file: sheetPath,
152
+ name,
153
+ extension: '.css',
154
+ });
155
+ }
156
+ outputFiles.push(...sheetResult.resourceFiles);
157
+ }
158
+ }
159
+ // Generate index HTML file
160
+ if (options.index) {
161
+ const entrypoints = (0, package_chunk_sort_1.generateEntryPoints)({
162
+ scripts: (_e = options.scripts) !== null && _e !== void 0 ? _e : [],
163
+ styles: (_f = options.styles) !== null && _f !== void 0 ? _f : [],
164
+ });
165
+ // Create an index HTML generator that reads from the in-memory output files
166
+ const indexHtmlGenerator = new index_html_generator_1.IndexHtmlGenerator({
167
+ indexPath: path.join(context.workspaceRoot, (0, webpack_browser_config_1.getIndexInputFile)(options.index)),
168
+ entrypoints,
169
+ sri: options.subresourceIntegrity,
170
+ optimization: optimizationOptions,
171
+ crossOrigin: options.crossOrigin,
172
+ });
173
+ /** Virtual output path to support reading in-memory files. */
174
+ const virtualOutputPath = '/';
175
+ indexHtmlGenerator.readAsset = async function (filePath) {
176
+ // Remove leading directory separator
177
+ const relativefilePath = path.relative(virtualOutputPath, filePath);
178
+ const file = outputFiles.find((file) => file.path === relativefilePath);
179
+ if (file) {
180
+ return file.text;
181
+ }
182
+ throw new Error(`Output file does not exist: ${path}`);
183
+ };
184
+ const { content, warnings, errors } = await indexHtmlGenerator.process({
185
+ baseHref: options.baseHref,
186
+ lang: undefined,
187
+ outputPath: virtualOutputPath,
188
+ files: initialFiles,
189
+ });
190
+ for (const error of errors) {
191
+ context.logger.error(error);
192
+ }
193
+ for (const warning of warnings) {
194
+ context.logger.warn(warning);
195
+ }
196
+ outputFiles.push(createOutputFileFromText((0, webpack_browser_config_1.getIndexOutputFile)(options.index), content));
197
+ }
198
+ // Copy assets
199
+ if (assets) {
200
+ await (0, copy_assets_1.copyAssets)(assets, [outputPath], workspaceRoot);
201
+ }
202
+ // Write output files
203
+ await Promise.all(outputFiles.map((file) => fs_1.promises.writeFile(path.join(outputPath, file.path), file.contents)));
204
+ context.logger.info(`Complete. [${(Date.now() - startTime) / 1000} seconds]`);
205
+ return { success: true };
206
+ }
207
+ exports.execute = execute;
208
+ function createOutputFileFromText(path, text) {
209
+ return {
210
+ path,
211
+ text,
212
+ get contents() {
213
+ return Buffer.from(this.text, 'utf-8');
214
+ },
215
+ };
216
+ }
217
+ async function bundleCode(workspaceRoot, entryPoints, outputNames, options, optimizationOptions, sourcemapOptions, tsconfig) {
218
+ return (0, esbuild_1.bundle)({
219
+ absWorkingDir: workspaceRoot,
220
+ bundle: true,
221
+ format: 'esm',
222
+ entryPoints,
223
+ entryNames: outputNames.bundles,
224
+ assetNames: outputNames.media,
225
+ target: 'es2020',
226
+ mainFields: ['es2020', 'browser', 'module', 'main'],
227
+ conditions: ['es2020', 'module'],
228
+ resolveExtensions: ['.ts', '.tsx', '.mjs', '.js'],
229
+ logLevel: options.verbose ? 'debug' : 'silent',
230
+ metafile: true,
231
+ minify: optimizationOptions.scripts,
232
+ pure: ['forwardRef'],
233
+ outdir: esbuild_1.DEFAULT_OUTDIR,
234
+ sourcemap: sourcemapOptions.scripts && (sourcemapOptions.hidden ? 'external' : true),
235
+ splitting: true,
236
+ tsconfig,
237
+ write: false,
238
+ platform: 'browser',
239
+ preserveSymlinks: options.preserveSymlinks,
240
+ plugins: [
241
+ (0, compiler_plugin_1.createCompilerPlugin)(
242
+ // JS/TS options
243
+ {
244
+ sourcemap: !!sourcemapOptions.scripts,
245
+ tsconfig,
246
+ advancedOptimizations: options.buildOptimizer,
247
+ },
248
+ // Component stylesheet options
249
+ {
250
+ workspaceRoot,
251
+ optimization: !!optimizationOptions.styles.minify,
252
+ sourcemap: !!sourcemapOptions.styles,
253
+ outputNames,
254
+ }),
255
+ ],
256
+ define: {
257
+ 'ngDevMode': optimizationOptions.scripts ? 'false' : 'true',
258
+ 'ngJitMode': 'false',
259
+ },
260
+ });
261
+ }
262
+ exports.default = (0, architect_1.createBuilder)(execute);
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { BuilderContext } from '@angular-devkit/architect';
9
+ import { Schema as BrowserBuilderOptions } from '../browser/schema';
10
+ /**
11
+ * Normalize the user provided options by creating full paths for all path based options
12
+ * and converting multi-form options into a single form that can be directly used
13
+ * by the build process.
14
+ *
15
+ * @param context The context for current builder execution.
16
+ * @param projectName The name of the project for the current execution.
17
+ * @param options An object containing the options to use for the build.
18
+ * @returns An object containing normalized options required to perform the build.
19
+ */
20
+ export declare function normalizeOptions(context: BuilderContext, projectName: string, options: BrowserBuilderOptions): Promise<{
21
+ workspaceRoot: string;
22
+ mainEntryPoint: string;
23
+ polyfillsEntryPoint: string | undefined;
24
+ optimizationOptions: import("../../utils").NormalizedOptimizationOptions;
25
+ outputPath: string;
26
+ sourcemapOptions: import("../browser/schema").SourceMapClass;
27
+ tsconfig: string;
28
+ projectRoot: string;
29
+ assets: import("../browser/schema").AssetPatternClass[] | undefined;
30
+ outputNames: {
31
+ bundles: string;
32
+ media: string;
33
+ };
34
+ }>;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.normalizeOptions = void 0;
34
+ const path = __importStar(require("path"));
35
+ const utils_1 = require("../../utils");
36
+ const schema_1 = require("../browser/schema");
37
+ /**
38
+ * Normalize the user provided options by creating full paths for all path based options
39
+ * and converting multi-form options into a single form that can be directly used
40
+ * by the build process.
41
+ *
42
+ * @param context The context for current builder execution.
43
+ * @param projectName The name of the project for the current execution.
44
+ * @param options An object containing the options to use for the build.
45
+ * @returns An object containing normalized options required to perform the build.
46
+ */
47
+ async function normalizeOptions(context, projectName, options) {
48
+ var _a, _b, _c, _d;
49
+ const workspaceRoot = context.workspaceRoot;
50
+ const projectMetadata = await context.getProjectMetadata(projectName);
51
+ const projectRoot = path.join(workspaceRoot, (_a = projectMetadata.root) !== null && _a !== void 0 ? _a : '');
52
+ const projectSourceRoot = path.join(workspaceRoot, (_b = projectMetadata.sourceRoot) !== null && _b !== void 0 ? _b : 'src');
53
+ // Normalize options
54
+ const mainEntryPoint = path.join(workspaceRoot, options.main);
55
+ const polyfillsEntryPoint = options.polyfills && path.join(workspaceRoot, options.polyfills);
56
+ const tsconfig = path.join(workspaceRoot, options.tsConfig);
57
+ const outputPath = path.join(workspaceRoot, options.outputPath);
58
+ const optimizationOptions = (0, utils_1.normalizeOptimization)(options.optimization);
59
+ const sourcemapOptions = (0, utils_1.normalizeSourceMaps)((_c = options.sourceMap) !== null && _c !== void 0 ? _c : false);
60
+ const assets = ((_d = options.assets) === null || _d === void 0 ? void 0 : _d.length)
61
+ ? (0, utils_1.normalizeAssetPatterns)(options.assets, workspaceRoot, projectRoot, projectSourceRoot)
62
+ : undefined;
63
+ const outputNames = {
64
+ bundles: options.outputHashing === schema_1.OutputHashing.All || options.outputHashing === schema_1.OutputHashing.Bundles
65
+ ? '[name].[hash]'
66
+ : '[name]',
67
+ media: options.outputHashing === schema_1.OutputHashing.All || options.outputHashing === schema_1.OutputHashing.Media
68
+ ? '[name].[hash]'
69
+ : '[name]',
70
+ };
71
+ if (options.resourcesOutputPath) {
72
+ outputNames.media = path.join(options.resourcesOutputPath, outputNames.media);
73
+ }
74
+ return {
75
+ workspaceRoot,
76
+ mainEntryPoint,
77
+ polyfillsEntryPoint,
78
+ optimizationOptions,
79
+ outputPath,
80
+ sourcemapOptions,
81
+ tsconfig,
82
+ projectRoot,
83
+ assets,
84
+ outputNames,
85
+ };
86
+ }
87
+ exports.normalizeOptions = normalizeOptions;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import type { OutputFile } from 'esbuild';
9
+ export interface BundleStylesheetOptions {
10
+ workspaceRoot?: string;
11
+ optimization: boolean;
12
+ preserveSymlinks?: boolean;
13
+ sourcemap: boolean | 'external';
14
+ outputNames?: {
15
+ bundles?: string;
16
+ media?: string;
17
+ };
18
+ }
19
+ /**
20
+ * Bundle a stylesheet that exists as a file on the filesystem.
21
+ *
22
+ * @param filename The path to the file to bundle.
23
+ * @param options The stylesheet bundling options to use.
24
+ * @returns The bundle result object.
25
+ */
26
+ export declare function bundleStylesheetFile(filename: string, options: BundleStylesheetOptions): Promise<{
27
+ errors: import("esbuild").Message[];
28
+ warnings: import("esbuild").Message[];
29
+ contents: string;
30
+ map: string | undefined;
31
+ path: string | undefined;
32
+ resourceFiles: OutputFile[];
33
+ }>;
34
+ /**
35
+ * Bundle stylesheet text data from a string.
36
+ *
37
+ * @param data The string content of a stylesheet to bundle.
38
+ * @param dataOptions The options to use to resolve references and name output of the stylesheet data.
39
+ * @param bundleOptions The stylesheet bundling options to use.
40
+ * @returns The bundle result object.
41
+ */
42
+ export declare function bundleStylesheetText(data: string, dataOptions: {
43
+ resolvePath: string;
44
+ virtualName?: string;
45
+ }, bundleOptions: BundleStylesheetOptions): Promise<{
46
+ errors: import("esbuild").Message[];
47
+ warnings: import("esbuild").Message[];
48
+ contents: string;
49
+ map: string | undefined;
50
+ path: string | undefined;
51
+ resourceFiles: OutputFile[];
52
+ }>;