Skip to content

Commit b3a14d0

Browse files
clydindgp1130
authored andcommitted
fix(@angular-devkit/build-angular): allow third-party sourcemaps to be ignored in esbuild builder
The `sourcemap.vendor` build option for the esbuild-based browser application builder will now properly be considered when processing sourcemaps for third-party code (code originating from a `node_modules` directory).
1 parent 53dd929 commit b3a14d0

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

packages/angular_devkit/build_angular/src/builders/browser-esbuild/compiler-plugin.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,12 @@ function convertTypeScriptDiagnostic(
116116
// This is a non-watch version of the compiler code from `@ngtools/webpack` augmented for esbuild
117117
// eslint-disable-next-line max-lines-per-function
118118
export function createCompilerPlugin(
119-
pluginOptions: { sourcemap: boolean; tsconfig: string; advancedOptimizations?: boolean },
119+
pluginOptions: {
120+
sourcemap: boolean;
121+
tsconfig: string;
122+
advancedOptimizations?: boolean;
123+
thirdPartySourcemaps?: boolean;
124+
},
120125
styleOptions: BundleStylesheetOptions,
121126
): Plugin {
122127
return {
@@ -318,10 +323,14 @@ export function createCompilerPlugin(
318323
};
319324
}
320325

326+
const useInputSourcemap =
327+
pluginOptions.sourcemap &&
328+
(!!pluginOptions.thirdPartySourcemaps || !/[\\/]node_modules[\\/]/.test(args.path));
329+
321330
const data = typescriptResult.content ?? '';
322331
const babelResult = await transformAsync(data, {
323332
filename: args.path,
324-
inputSourceMap: (pluginOptions.sourcemap ? undefined : false) as undefined,
333+
inputSourceMap: (useInputSourcemap ? undefined : false) as undefined,
325334
sourceMaps: pluginOptions.sourcemap ? 'inline' : false,
326335
compact: false,
327336
configFile: false,
@@ -355,10 +364,14 @@ export function createCompilerPlugin(
355364
)
356365
).createEs2015LinkerPlugin;
357366

367+
const useInputSourcemap =
368+
pluginOptions.sourcemap &&
369+
(!!pluginOptions.thirdPartySourcemaps || !/[\\/]node_modules[\\/]/.test(args.path));
370+
358371
const data = await fs.readFile(args.path, 'utf-8');
359372
const result = await transformAsync(data, {
360373
filename: args.path,
361-
inputSourceMap: (pluginOptions.sourcemap ? undefined : false) as undefined,
374+
inputSourceMap: (useInputSourcemap ? undefined : false) as undefined,
362375
sourceMaps: pluginOptions.sourcemap ? 'inline' : false,
363376
compact: false,
364377
configFile: false,

packages/angular_devkit/build_angular/src/builders/browser-esbuild/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ async function bundleCode(
323323
// JS/TS options
324324
{
325325
sourcemap: !!sourcemapOptions.scripts,
326+
thirdPartySourcemaps: sourcemapOptions.vendor,
326327
tsconfig,
327328
advancedOptimizations: options.buildOptimizer,
328329
},

0 commit comments

Comments
 (0)