fix(@angular-devkit/build-angular): ensure esbuild builder sourcemap … · angular/angular-cli@53dd929 (original) (raw)

5 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -221,7 +221,7 @@ jobs:
221 221 name: Execute CLI E2E Tests Subset with esbuild builder
222 222 command: |
223 223 mkdir /mnt/ramdisk/e2e-esbuild
224 - node ./tests/legacy-cli/run_e2e --nb-shards=${CIRCLE_NODE_TOTAL} --shard=${CIRCLE_NODE_INDEX} <<# parameters.snapshots >>--ng-snapshots<</ parameters.snapshots >> --esbuild --tmpdir=/mnt/ramdisk/e2e-esbuild --glob="{tests/basic/**,tests/build/prod-build.ts,tests/build/styles/scss.ts,tests/build/styles/include-paths.ts,tests/commands/add/add-pwa.ts}" --ignore="tests/basic/{environment,rebuild,serve,scripts-array}.ts"
224 + node ./tests/legacy-cli/run_e2e --nb-shards=${CIRCLE_NODE_TOTAL} --shard=${CIRCLE_NODE_INDEX} <<# parameters.snapshots >>--ng-snapshots<</ parameters.snapshots >> --esbuild --tmpdir=/mnt/ramdisk/e2e-esbuild --glob="{tests/basic/**,tests/build/prod-build.ts,tests/build/relative-sourcemap.ts,tests/build/styles/scss.ts,tests/build/styles/include-paths.ts,tests/commands/add/add-pwa.ts}" --ignore="tests/basic/{environment,rebuild,serve,scripts-array}.ts"
225 225 - fail_fast
226 226
227 227 test-browsers:
Original file line number Diff line number Diff line change
@@ -16,10 +16,6 @@ import {
16 16 build,
17 17 formatMessages,
18 18 } from 'esbuild';
19 -import { resolve } from 'path';
20 -
21 -/** Default outdir setting for esbuild. */
22 -export const DEFAULT_OUTDIR = resolve('/virtual-output');
23 19
24 20 /**
25 21 * Determines if an unknown value is an esbuild BuildFailure error object thrown by esbuild.
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ import { augmentAppWithServiceWorker } from '../../utils/service-worker';
21 21 import { getIndexInputFile, getIndexOutputFile } from '../../utils/webpack-browser-config';
22 22 import { resolveGlobalStyles } from '../../webpack/configs';
23 23 import { createCompilerPlugin } from './compiler-plugin';
24 -import { DEFAULT_OUTDIR, bundle, logMessages } from './esbuild';
24 +import { bundle, logMessages } from './esbuild';
25 25 import { logExperimentalWarnings } from './experimental-warnings';
26 26 import { normalizeOptions } from './options';
27 27 import { Schema as BrowserBuilderOptions, SourceMapClass } from './schema';
@@ -120,7 +120,7 @@ export async function buildEsbuildBrowser(
120 120 const relativeFilePath = path.relative(workspaceRoot, outputFile.path);
121 121 const entryPoint = result.metafile?.outputs[relativeFilePath]?.entryPoint;
122 122
123 -outputFile.path = path.relative(DEFAULT_OUTDIR, outputFile.path);
123 +outputFile.path = relativeFilePath;
124 124
125 125 if (entryPoint) {
126 126 // An entryPoint value indicates an initial file
@@ -159,6 +159,7 @@ export async function buildEsbuildBrowser(
159 159 virtualEntryData,
160 160 { virtualName: `angular:style/global;${name}`, resolvePath: workspaceRoot },
161 161 {
162 + workspaceRoot,
162 163 optimization: !!optimizationOptions.styles.minify,
163 164 sourcemap: !!sourcemapOptions.styles && (sourcemapOptions.hidden ? 'external' : true),
164 165 outputNames: noInjectNames.includes(name) ? { media: outputNames.media } : outputNames,
@@ -309,7 +310,7 @@ async function bundleCode(
309 310 metafile: true,
310 311 minify: optimizationOptions.scripts,
311 312 pure: ['forwardRef'],
312 -outdir: DEFAULT_OUTDIR,
313 +outdir: workspaceRoot,
313 314 sourcemap: sourcemapOptions.scripts && (sourcemapOptions.hidden ? 'external' : true),
314 315 splitting: true,
315 316 tsconfig,
Original file line number Diff line number Diff line change
@@ -8,11 +8,11 @@
8 8
9 9 import type { BuildOptions, OutputFile } from 'esbuild';
10 10 import * as path from 'path';
11 -import { DEFAULT_OUTDIR, bundle } from './esbuild';
11 +import { bundle } from './esbuild';
12 12 import { createSassPlugin } from './sass-plugin';
13 13
14 14 export interface BundleStylesheetOptions {
15 -workspaceRoot?: string;
15 +workspaceRoot: string;
16 16 optimization: boolean;
17 17 preserveSymlinks?: boolean;
18 18 sourcemap: boolean | 'external' 'inline';
@@ -34,7 +34,7 @@ async function bundleStylesheet(
34 34 logLevel: 'silent',
35 35 minify: options.optimization,
36 36 sourcemap: options.sourcemap,
37 -outdir: DEFAULT_OUTDIR,
37 +outdir: options.workspaceRoot,
38 38 write: false,
39 39 platform: 'browser',
40 40 preserveSymlinks: options.preserveSymlinks,
@@ -52,7 +52,7 @@ async function bundleStylesheet(
52 52 const resourceFiles: OutputFile[] = [];
53 53 if (result.outputFiles) {
54 54 for (const outputFile of result.outputFiles) {
55 -outputFile.path = path.relative(DEFAULT_OUTDIR, outputFile.path);
55 +outputFile.path = path.relative(options.workspaceRoot, outputFile.path);
56 56 const filename = path.basename(outputFile.path);
57 57 if (filename.endsWith('.css')) {
58 58 outputPath = outputFile.path;
Original file line number Diff line number Diff line change
@@ -1,19 +1,45 @@
1 1 import * as fs from 'fs';
2 2
3 3 import { isAbsolute } from 'path';
4 +import { getGlobalVariable } from '../../utils/env';
4 5 import { ng } from '../../utils/process';
6 +import { updateJsonFile } from '../../utils/project';
5 7
6 8 export default async function () {
7 9 // General secondary application project
8 10 await ng('generate', 'application', 'secondary-project', '--skip-install');
11 +// Setup esbuild builder if requested on the commandline
12 +const useEsbuildBuilder = !!getGlobalVariable('argv')['esbuild'];
13 +if (useEsbuildBuilder) {
14 +await updateJsonFile('angular.json', (json) => {
15 +json['projects']['secondary-project']['architect']['build']['builder'] =
16 +'@angular-devkit/build-angular:browser-esbuild';
17 +});
18 +}
19 +
9 20 await ng('build', 'secondary-project', '--configuration=development');
10 21
11 22 await ng('build', '--output-hashing=none', '--source-map', '--configuration=development');
12 23 const content = fs.readFileSync('./dist/secondary-project/main.js.map', 'utf8');
13 -const { sources } = JSON.parse(content);
24 +const { sources } = JSON.parse(content) as { sources: string[] };
25 +let mainFileFound = false;
14 26 for (const source of sources) {
15 27 if (isAbsolute(source)) {
16 28 throw new Error(`Expected ${source} to be relative.`);
17 29 }
30 +
31 +if (source.endsWith('main.ts')) {
32 +mainFileFound = true;
33 +if (
34 +source !== 'projects/secondary-project/src/main.ts' &&
35 +source !== './projects/secondary-project/src/main.ts'
36 +) {
37 +throw new Error(`Expected main file ${source} to be relative to the workspace root.`);
38 +}
39 +}
40 +}
41 +
42 +if (!mainFileFound) {
43 +throw new Error('Could not find the main file in the application sourcemap sources array.');
18 44 }
19 45 }