Skip to content
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 @@ -3,20 +3,20 @@
# This file should be checked into version control along with the pnpm-lock.yaml file.
.npmrc=-1406867100
modules/testing/builder/package.json=973445093
package.json=1699878288
packages/angular/build/package.json=-2062350529
package.json=188352334
packages/angular/build/package.json=1444505662
packages/angular/cli/package.json=-803141029
packages/angular/pwa/package.json=1108903917
packages/angular/ssr/package.json=1856194341
packages/angular_devkit/architect/package.json=-1496633956
packages/angular_devkit/architect_cli/package.json=1551210941
packages/angular_devkit/build_angular/package.json=420468135
packages/angular_devkit/build_angular/package.json=1633828551
packages/angular_devkit/build_webpack/package.json=373950017
packages/angular_devkit/core/package.json=339935828
packages/angular_devkit/schematics/package.json=673943597
packages/angular_devkit/schematics_cli/package.json=774399812
packages/ngtools/webpack/package.json=1282929706
packages/schematics/angular/package.json=251715148
pnpm-lock.yaml=-617616317
pnpm-lock.yaml=602674798
pnpm-workspace.yaml=-1056556036
yarn.lock=1382132490
yarn.lock=1767327014
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@
"copy-webpack-plugin": "12.0.2",
"css-loader": "7.1.2",
"debug": "^4.1.1",
"esbuild": "0.24.2",
"esbuild-wasm": "0.24.2",
"esbuild": "0.25.0",
"esbuild-wasm": "0.25.0",
"eslint": "8.57.0",
"eslint-config-prettier": "10.0.1",
"eslint-plugin-header": "3.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@vitejs/plugin-basic-ssl": "1.2.0",
"beasties": "0.2.0",
"browserslist": "^4.23.0",
"esbuild": "0.24.2",
"esbuild": "0.25.0",
"fast-glob": "3.3.3",
"https-proxy-agent": "7.0.6",
"istanbul-lib-instrument": "6.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,24 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
.content.not.toContain('sourceMappingURL=app.component.css.map');
harness.expectFile('dist/browser/app.component.css.map').toNotExist();
});

for (const ext of ['css', 'scss', 'less']) {
it(`should generate a correct sourcemap when input file is ${ext}`, async () => {
await harness.writeFile(`src/styles.${ext}`, `* { color: red }`);

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

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

expect(result?.success).toBeTrue();
harness
.expectFile('dist/browser/styles.css.map')
.content.toContain(`"sources": ["src/styles.${ext}"]`);
});
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { NodePath, PluginObj, types } from '@babel/core';
import { Visitor, programVisitor } from 'istanbul-lib-instrument';
import assert from 'node:assert';
import { fileURLToPath } from 'node:url';

/**
* A babel plugin factory function for adding istanbul instrumentation.
Expand All @@ -22,9 +23,19 @@ export default function (): PluginObj {
visitor: {
Program: {
enter(path, state) {
const inputSourceMap = // eslint-disable-next-line @typescript-eslint/no-explicit-any
(state.file.inputMap as undefined | { toObject(): Record<string, any> })?.toObject();

// istanbul does not support URL as sources.
if (inputSourceMap?.sources) {
inputSourceMap.sources = inputSourceMap.sources.map((s: string) =>
s.startsWith('file://') ? fileURLToPath(s) : s,
);
}

const visitor = programVisitor(types, state.filename, {
// Babel returns a Converter object from the `convert-source-map` package
inputSourceMap: (state.file.inputMap as undefined | { toObject(): object })?.toObject(),
inputSourceMap,
});
visitors.set(path, visitor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {
import assert from 'node:assert';
import { createHash } from 'node:crypto';
import * as path from 'node:path';
import { pathToFileURL } from 'node:url';
import { maxWorkers, useTypeChecking } from '../../../utils/environment-options';
import { AngularHostOptions } from '../../angular/angular-host';
import { AngularCompilation, DiagnosticModes, NoopCompilation } from '../../angular/compilation';
Expand Down Expand Up @@ -292,6 +293,7 @@ export function createCompilerPlugin(
pluginOptions,
preserveSymlinks,
build.initialOptions.conditions,
build.initialOptions.absWorkingDir,
),
);
shouldTsIgnoreJs = !initializationResult.compilerOptions.allowJs;
Expand Down Expand Up @@ -622,6 +624,7 @@ function createCompilerOptionsTransformer(
pluginOptions: CompilerPluginOptions,
preserveSymlinks: boolean | undefined,
customConditions: string[] | undefined,
absWorkingDir: string | undefined,
): Parameters<AngularCompilation['initialize']>[2] {
return (compilerOptions) => {
// target of 9 is ES2022 (using the number avoids an expensive import of typescript just for an enum)
Expand Down Expand Up @@ -704,6 +707,10 @@ function createCompilerOptionsTransformer(
return {
...compilerOptions,
noEmitOnError: false,
// Using the path as a URL is necessary here; otherwise, esbuild will not generate source maps correctly.
// https://github.com/evanw/esbuild/issues/4070
// https://github.com/evanw/esbuild/issues/4075
outDir: absWorkingDir ? pathToFileURL(absWorkingDir + '/').href : undefined,
inlineSources: !!pluginOptions.sourcemap,
inlineSourceMap: !!pluginOptions.sourcemap,
sourceMap: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import type { Location, OnLoadResult, PluginBuild } from 'esbuild';
import { readFile } from 'node:fs/promises';
import { isAbsolute } from 'node:path';
import { pathToFileURL } from 'node:url';
import { StylesheetLanguage, StylesheetPluginOptions } from './stylesheet-plugin-factory';

/**
Expand Down Expand Up @@ -113,24 +115,24 @@ async function compileString(
};

try {
const result = await less.render(data, {
const { imports, map, css } = await less.render(data, {
filename,
paths: options.includePaths,
plugins: [resolverPlugin],
rewriteUrls: 'all',
javascriptEnabled: unsafeInlineJavaScript,
sourceMap: options.sourcemap
? {
sourceMapFileInline: true,
sourceMapFileInline: false,
outputSourceFiles: true,
}
: undefined,
} as Less.Options);

return {
contents: result.css,
contents: options.sourcemap ? `${css}\n${sourceMapToUrlComment(map)}` : css,
loader: 'css',
watchFiles: [filename, ...result.imports],
watchFiles: [filename, ...imports],
};
} catch (error) {
if (isLessException(error)) {
Expand Down Expand Up @@ -190,3 +192,18 @@ function convertExceptionLocation(exception: LessException): Partial<Location> {
lineText: exception.extract && exception.extract[Math.trunc(exception.extract.length / 2)],
};
}

function sourceMapToUrlComment(sourceMap: string): string {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const map = JSON.parse(sourceMap) as Record<string, any>;
// Using file URLs instead of paths ensures that esbuild correctly resolves the source map.
// https://github.com/evanw/esbuild/issues/4070
// https://github.com/evanw/esbuild/issues/4075
map.sources = map.sources.map((source: string) =>
source && isAbsolute(source) ? pathToFileURL(source).href : source,
);

const urlSourceMap = Buffer.from(JSON.stringify(map), 'utf-8').toString('base64');

return `/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${urlSourceMap} */`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import type { OnLoadResult, PartialMessage, PartialNote, ResolveResult } from 'esbuild';
import { dirname, join, relative } from 'node:path';
import { dirname, join } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import type { CanonicalizeContext, CompileResult, Exception, Syntax } from 'sass';
import type { SassWorkerImplementation } from '../../sass/sass-service';
Expand Down Expand Up @@ -170,7 +170,7 @@ async function compileString(

return {
loader: 'css',
contents: sourceMap ? `${css}\n${sourceMapToUrlComment(sourceMap, dirname(filePath))}` : css,
contents: sourceMap ? `${css}\n${sourceMapToUrlComment(sourceMap)}` : css,
watchFiles: loadedUrls.map((url) => fileURLToPath(url)),
warnings,
};
Expand Down Expand Up @@ -199,14 +199,7 @@ async function compileString(
}
}

function sourceMapToUrlComment(
sourceMap: Exclude<CompileResult['sourceMap'], undefined>,
root: string,
): string {
// Remove `file` protocol from all sourcemap sources and adjust to be relative to the input file.
// This allows esbuild to correctly process the paths.
sourceMap.sources = sourceMap.sources.map((source) => relative(root, fileURLToPath(source)));

function sourceMapToUrlComment(sourceMap: Exclude<CompileResult['sourceMap'], undefined>): string {
const urlSourceMap = Buffer.from(JSON.stringify(sourceMap), 'utf-8').toString('base64');

return `/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${urlSourceMap} */`;
Expand Down
4 changes: 2 additions & 2 deletions packages/angular_devkit/build_angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"browserslist": "^4.21.5",
"copy-webpack-plugin": "12.0.2",
"css-loader": "7.1.2",
"esbuild-wasm": "0.24.2",
"esbuild-wasm": "0.25.0",
"fast-glob": "3.3.3",
"http-proxy-middleware": "3.0.3",
"istanbul-lib-instrument": "6.0.3",
Expand Down Expand Up @@ -63,7 +63,7 @@
"webpack-subresource-integrity": "5.1.0"
},
"optionalDependencies": {
"esbuild": "0.24.2"
"esbuild": "0.25.0"
},
"devDependencies": {
"undici": "7.3.0",
Expand Down
Loading
Loading