Skip to content

fix(@angular/build): do not reference sourcemaps in web workers and global stylesheet bundles when hidden setting is enabled #27838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,74 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
harness.expectFile('dist/browser/main.js.map').content.toContain('/common/index.ts');
});

it(`should not include 'sourceMappingURL' sourcemaps when hidden suboption is true`, async () => {
await harness.writeFile('src/styles.css', `div { flex: 1 }`);

harness.useTarget('build', {
...BASE_OPTIONS,
styles: ['src/styles.css'],
sourceMap: { scripts: true, styles: true, hidden: true },
});

const { result } = await harness.executeOnce();

expect(result?.success).toBeTrue();

harness.expectFile('dist/browser/main.js.map').toExist();
harness
.expectFile('dist/browser/main.js')
.content.not.toContain('sourceMappingURL=main.js.map');

harness.expectFile('dist/browser/styles.css.map').toExist();
harness
.expectFile('dist/browser/styles.css')
.content.not.toContain('sourceMappingURL=styles.css.map');
});

it(`should include 'sourceMappingURL' sourcemaps when hidden suboption is false`, async () => {
await harness.writeFile('src/styles.css', `div { flex: 1 }`);

harness.useTarget('build', {
...BASE_OPTIONS,
styles: ['src/styles.css'],
sourceMap: { scripts: true, styles: true, hidden: false },
});

const { result } = await harness.executeOnce();

expect(result?.success).toBeTrue();

harness.expectFile('dist/browser/main.js.map').toExist();
harness.expectFile('dist/browser/main.js').content.toContain('sourceMappingURL=main.js.map');

harness.expectFile('dist/browser/styles.css.map').toExist();
harness
.expectFile('dist/browser/styles.css')
.content.toContain('sourceMappingURL=styles.css.map');
});

it(`should include 'sourceMappingURL' sourcemaps when hidden suboption is not set`, async () => {
await harness.writeFile('src/styles.css', `div { flex: 1 }`);

harness.useTarget('build', {
...BASE_OPTIONS,
styles: ['src/styles.css'],
sourceMap: { scripts: true, styles: true },
});

const { result } = await harness.executeOnce();

expect(result?.success).toBeTrue();

harness.expectFile('dist/browser/main.js.map').toExist();
harness.expectFile('dist/browser/main.js').content.toContain('sourceMappingURL=main.js.map');

harness.expectFile('dist/browser/styles.css.map').toExist();
harness
.expectFile('dist/browser/styles.css')
.content.toContain('sourceMappingURL=styles.css.map');
});

it('should add "x_google_ignoreList" extension to script sourcemap files when true', async () => {
harness.useTarget('build', {
...BASE_OPTIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { setupJitPluginCallbacks } from './jit-plugin-callbacks';
import { SourceFileCache } from './source-file-cache';

export interface CompilerPluginOptions {
sourcemap: boolean;
sourcemap: boolean | 'external';
tsconfig: string;
jit?: boolean;
/** Skip TypeScript compilation setup. This is useful to re-use the TypeScript compilation from another plugin. */
Expand Down Expand Up @@ -71,7 +71,12 @@ export function createCompilerPlugin(
);
}
const javascriptTransformer = new JavaScriptTransformer(
pluginOptions,
{
sourcemap: !!pluginOptions.sourcemap,
thirdPartySourcemaps: pluginOptions.thirdPartySourcemaps,
advancedOptimizations: pluginOptions.advancedOptimizations,
jit: pluginOptions.jit,
},
maxWorkers,
cacheStore?.createCache('jstransformer'),
);
Expand Down Expand Up @@ -541,8 +546,8 @@ function createCompilerOptionsTransformer(
return {
...compilerOptions,
noEmitOnError: false,
inlineSources: pluginOptions.sourcemap,
inlineSourceMap: pluginOptions.sourcemap,
inlineSources: !!pluginOptions.sourcemap,
inlineSourceMap: !!pluginOptions.sourcemap,
mapRoot: undefined,
sourceRoot: undefined,
preserveSymlinks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function createCompilerPluginOptions(
return {
// JS/TS options
pluginOptions: {
sourcemap: !!sourcemapOptions.scripts,
sourcemap: !!sourcemapOptions.scripts && (sourcemapOptions.hidden ? 'external' : true),
thirdPartySourcemaps: sourcemapOptions.vendor,
tsconfig,
jit,
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/build/src/tools/esbuild/global-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function createGlobalStylesBundleOptions(
workspaceRoot,
optimization: !!optimizationOptions.styles.minify,
inlineFonts: !!optimizationOptions.fonts.inline,
sourcemap: !!sourcemapOptions.styles,
sourcemap: !!sourcemapOptions.styles && (sourcemapOptions.hidden ? 'external' : true),
preserveSymlinks,
target,
externalDependencies,
Expand Down