Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): allow third-party sourcemaps to b…
Browse files Browse the repository at this point in the history
…e 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).
  • Loading branch information
clydin authored and dgp1130 committed Jul 12, 2022
1 parent 53dd929 commit b3a14d0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ function convertTypeScriptDiagnostic(
// This is a non-watch version of the compiler code from `@ngtools/webpack` augmented for esbuild
// eslint-disable-next-line max-lines-per-function
export function createCompilerPlugin(
pluginOptions: { sourcemap: boolean; tsconfig: string; advancedOptimizations?: boolean },
pluginOptions: {
sourcemap: boolean;
tsconfig: string;
advancedOptimizations?: boolean;
thirdPartySourcemaps?: boolean;
},
styleOptions: BundleStylesheetOptions,
): Plugin {
return {
Expand Down Expand Up @@ -318,10 +323,14 @@ export function createCompilerPlugin(
};
}

const useInputSourcemap =
pluginOptions.sourcemap &&
(!!pluginOptions.thirdPartySourcemaps || !/[\\/]node_modules[\\/]/.test(args.path));

const data = typescriptResult.content ?? '';
const babelResult = await transformAsync(data, {
filename: args.path,
inputSourceMap: (pluginOptions.sourcemap ? undefined : false) as undefined,
inputSourceMap: (useInputSourcemap ? undefined : false) as undefined,
sourceMaps: pluginOptions.sourcemap ? 'inline' : false,
compact: false,
configFile: false,
Expand Down Expand Up @@ -355,10 +364,14 @@ export function createCompilerPlugin(
)
).createEs2015LinkerPlugin;

const useInputSourcemap =
pluginOptions.sourcemap &&
(!!pluginOptions.thirdPartySourcemaps || !/[\\/]node_modules[\\/]/.test(args.path));

const data = await fs.readFile(args.path, 'utf-8');
const result = await transformAsync(data, {
filename: args.path,
inputSourceMap: (pluginOptions.sourcemap ? undefined : false) as undefined,
inputSourceMap: (useInputSourcemap ? undefined : false) as undefined,
sourceMaps: pluginOptions.sourcemap ? 'inline' : false,
compact: false,
configFile: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ async function bundleCode(
// JS/TS options
{
sourcemap: !!sourcemapOptions.scripts,
thirdPartySourcemaps: sourcemapOptions.vendor,
tsconfig,
advancedOptimizations: options.buildOptimizer,
},
Expand Down

0 comments on commit b3a14d0

Please sign in to comment.