Skip to content

Commit a274739

Browse files
committed
build: update to esbuild 0.25.0
This commit updates esbuild to 0.25.0
1 parent 8a416e7 commit a274739

File tree

11 files changed

+578
-64
lines changed

11 files changed

+578
-64
lines changed

.aspect/rules/external_repository_action_cache/npm_translate_lock_MzA5NzUwNzMx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
# This file should be checked into version control along with the pnpm-lock.yaml file.
44
.npmrc=-1406867100
55
modules/testing/builder/package.json=973445093
6-
package.json=1699878288
7-
packages/angular/build/package.json=-2062350529
6+
package.json=188352334
7+
packages/angular/build/package.json=1444505662
88
packages/angular/cli/package.json=-803141029
99
packages/angular/pwa/package.json=1108903917
1010
packages/angular/ssr/package.json=1856194341
1111
packages/angular_devkit/architect/package.json=-1496633956
1212
packages/angular_devkit/architect_cli/package.json=1551210941
13-
packages/angular_devkit/build_angular/package.json=420468135
13+
packages/angular_devkit/build_angular/package.json=1633828551
1414
packages/angular_devkit/build_webpack/package.json=373950017
1515
packages/angular_devkit/core/package.json=339935828
1616
packages/angular_devkit/schematics/package.json=673943597
1717
packages/angular_devkit/schematics_cli/package.json=774399812
1818
packages/ngtools/webpack/package.json=1282929706
1919
packages/schematics/angular/package.json=251715148
20-
pnpm-lock.yaml=-617616317
20+
pnpm-lock.yaml=602674798
2121
pnpm-workspace.yaml=-1056556036
22-
yarn.lock=1382132490
22+
yarn.lock=1767327014

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@
123123
"copy-webpack-plugin": "12.0.2",
124124
"css-loader": "7.1.2",
125125
"debug": "^4.1.1",
126-
"esbuild": "0.24.2",
127-
"esbuild-wasm": "0.24.2",
126+
"esbuild": "0.25.0",
127+
"esbuild-wasm": "0.25.0",
128128
"eslint": "8.57.0",
129129
"eslint-config-prettier": "10.0.1",
130130
"eslint-plugin-header": "3.1.1",

packages/angular/build/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@vitejs/plugin-basic-ssl": "1.2.0",
2929
"beasties": "0.2.0",
3030
"browserslist": "^4.23.0",
31-
"esbuild": "0.24.2",
31+
"esbuild": "0.25.0",
3232
"fast-glob": "3.3.3",
3333
"https-proxy-agent": "7.0.6",
3434
"istanbul-lib-instrument": "6.0.3",

packages/angular/build/src/builders/application/tests/options/sourcemap_spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,5 +240,24 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
240240
.content.not.toContain('sourceMappingURL=app.component.css.map');
241241
harness.expectFile('dist/browser/app.component.css.map').toNotExist();
242242
});
243+
244+
for (const ext of ['css', 'scss', 'less']) {
245+
it(`should generate a correct sourcemap when input file is ${ext}`, async () => {
246+
await harness.writeFile(`src/styles.${ext}`, `* { color: red }`);
247+
248+
harness.useTarget('build', {
249+
...BASE_OPTIONS,
250+
sourceMap: true,
251+
styles: [`src/styles.${ext}`],
252+
});
253+
254+
const { result } = await harness.executeOnce();
255+
256+
expect(result?.success).toBeTrue();
257+
harness
258+
.expectFile('dist/browser/styles.css.map')
259+
.content.toContain(`"sources": ["src/styles.${ext}"]`);
260+
});
261+
}
243262
});
244263
});

packages/angular/build/src/tools/babel/plugins/add-code-coverage.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import { NodePath, PluginObj, types } from '@babel/core';
1010
import { Visitor, programVisitor } from 'istanbul-lib-instrument';
1111
import assert from 'node:assert';
12+
import { fileURLToPath } from 'node:url';
1213

1314
/**
1415
* A babel plugin factory function for adding istanbul instrumentation.
@@ -22,9 +23,19 @@ export default function (): PluginObj {
2223
visitor: {
2324
Program: {
2425
enter(path, state) {
26+
const inputSourceMap = // eslint-disable-next-line @typescript-eslint/no-explicit-any
27+
(state.file.inputMap as undefined | { toObject(): Record<string, any> })?.toObject();
28+
29+
// istanbul does not support URL as sources.
30+
if (inputSourceMap?.sources) {
31+
inputSourceMap.sources = inputSourceMap.sources.map((s: string) =>
32+
s.startsWith('file://') ? fileURLToPath(s) : s,
33+
);
34+
}
35+
2536
const visitor = programVisitor(types, state.filename, {
2637
// Babel returns a Converter object from the `convert-source-map` package
27-
inputSourceMap: (state.file.inputMap as undefined | { toObject(): object })?.toObject(),
38+
inputSourceMap,
2839
});
2940
visitors.set(path, visitor);
3041

packages/angular/build/src/tools/esbuild/angular/compiler-plugin.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919
import assert from 'node:assert';
2020
import { createHash } from 'node:crypto';
2121
import * as path from 'node:path';
22+
import { pathToFileURL } from 'node:url';
2223
import { maxWorkers, useTypeChecking } from '../../../utils/environment-options';
2324
import { AngularHostOptions } from '../../angular/angular-host';
2425
import { AngularCompilation, DiagnosticModes, NoopCompilation } from '../../angular/compilation';
@@ -292,6 +293,7 @@ export function createCompilerPlugin(
292293
pluginOptions,
293294
preserveSymlinks,
294295
build.initialOptions.conditions,
296+
build.initialOptions.absWorkingDir,
295297
),
296298
);
297299
shouldTsIgnoreJs = !initializationResult.compilerOptions.allowJs;
@@ -622,6 +624,7 @@ function createCompilerOptionsTransformer(
622624
pluginOptions: CompilerPluginOptions,
623625
preserveSymlinks: boolean | undefined,
624626
customConditions: string[] | undefined,
627+
absWorkingDir: string | undefined,
625628
): Parameters<AngularCompilation['initialize']>[2] {
626629
return (compilerOptions) => {
627630
// target of 9 is ES2022 (using the number avoids an expensive import of typescript just for an enum)
@@ -704,6 +707,10 @@ function createCompilerOptionsTransformer(
704707
return {
705708
...compilerOptions,
706709
noEmitOnError: false,
710+
// Using the path as a URL is necessary here; otherwise, esbuild will not generate source maps correctly.
711+
// https://github.com/evanw/esbuild/issues/4070
712+
// https://github.com/evanw/esbuild/issues/4075
713+
outDir: absWorkingDir ? pathToFileURL(absWorkingDir + '/').href : undefined,
707714
inlineSources: !!pluginOptions.sourcemap,
708715
inlineSourceMap: !!pluginOptions.sourcemap,
709716
sourceMap: undefined,

packages/angular/build/src/tools/esbuild/stylesheets/less-language.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

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

1315
/**
@@ -113,24 +115,24 @@ async function compileString(
113115
};
114116

115117
try {
116-
const result = await less.render(data, {
118+
const { imports, map, css } = await less.render(data, {
117119
filename,
118120
paths: options.includePaths,
119121
plugins: [resolverPlugin],
120122
rewriteUrls: 'all',
121123
javascriptEnabled: unsafeInlineJavaScript,
122124
sourceMap: options.sourcemap
123125
? {
124-
sourceMapFileInline: true,
126+
sourceMapFileInline: false,
125127
outputSourceFiles: true,
126128
}
127129
: undefined,
128130
} as Less.Options);
129131

130132
return {
131-
contents: result.css,
133+
contents: options.sourcemap ? `${css}\n${sourceMapToUrlComment(map)}` : css,
132134
loader: 'css',
133-
watchFiles: [filename, ...result.imports],
135+
watchFiles: [filename, ...imports],
134136
};
135137
} catch (error) {
136138
if (isLessException(error)) {
@@ -190,3 +192,18 @@ function convertExceptionLocation(exception: LessException): Partial<Location> {
190192
lineText: exception.extract && exception.extract[Math.trunc(exception.extract.length / 2)],
191193
};
192194
}
195+
196+
function sourceMapToUrlComment(sourceMap: string): string {
197+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
198+
const map = JSON.parse(sourceMap) as Record<string, any>;
199+
// Using file URLs instead of paths ensures that esbuild correctly resolves the source map.
200+
// https://github.com/evanw/esbuild/issues/4070
201+
// https://github.com/evanw/esbuild/issues/4075
202+
map.sources = map.sources.map((source: string) =>
203+
source && isAbsolute(source) ? pathToFileURL(source).href : source,
204+
);
205+
206+
const urlSourceMap = Buffer.from(JSON.stringify(map), 'utf-8').toString('base64');
207+
208+
return `/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${urlSourceMap} */`;
209+
}

packages/angular/build/src/tools/esbuild/stylesheets/sass-language.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

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

171171
return {
172172
loader: 'css',
173-
contents: sourceMap ? `${css}\n${sourceMapToUrlComment(sourceMap, dirname(filePath))}` : css,
173+
contents: sourceMap ? `${css}\n${sourceMapToUrlComment(sourceMap)}` : css,
174174
watchFiles: loadedUrls.map((url) => fileURLToPath(url)),
175175
warnings,
176176
};
@@ -199,14 +199,7 @@ async function compileString(
199199
}
200200
}
201201

202-
function sourceMapToUrlComment(
203-
sourceMap: Exclude<CompileResult['sourceMap'], undefined>,
204-
root: string,
205-
): string {
206-
// Remove `file` protocol from all sourcemap sources and adjust to be relative to the input file.
207-
// This allows esbuild to correctly process the paths.
208-
sourceMap.sources = sourceMap.sources.map((source) => relative(root, fileURLToPath(source)));
209-
202+
function sourceMapToUrlComment(sourceMap: Exclude<CompileResult['sourceMap'], undefined>): string {
210203
const urlSourceMap = Buffer.from(JSON.stringify(sourceMap), 'utf-8').toString('base64');
211204

212205
return `/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${urlSourceMap} */`;

packages/angular_devkit/build_angular/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"browserslist": "^4.21.5",
3030
"copy-webpack-plugin": "12.0.2",
3131
"css-loader": "7.1.2",
32-
"esbuild-wasm": "0.24.2",
32+
"esbuild-wasm": "0.25.0",
3333
"fast-glob": "3.3.3",
3434
"http-proxy-middleware": "3.0.3",
3535
"istanbul-lib-instrument": "6.0.3",
@@ -63,7 +63,7 @@
6363
"webpack-subresource-integrity": "5.1.0"
6464
},
6565
"optionalDependencies": {
66-
"esbuild": "0.24.2"
66+
"esbuild": "0.25.0"
6767
},
6868
"devDependencies": {
6969
"undici": "7.3.0",

0 commit comments

Comments
 (0)