Skip to content

Commit 596b9ae

Browse files
committed
refactor(@angular/build): remove esbuild sourcemap workarounds
These are no longer requires since 0.25.1
1 parent 97ed10b commit 596b9ae

File tree

3 files changed

+4
-39
lines changed

3 files changed

+4
-39
lines changed

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

+1-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
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';
1312

1413
/**
1514
* A babel plugin factory function for adding istanbul instrumentation.
@@ -23,19 +22,9 @@ export default function (): PluginObj {
2322
visitor: {
2423
Program: {
2524
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-
3625
const visitor = programVisitor(types, state.filename, {
3726
// Babel returns a Converter object from the `convert-source-map` package
38-
inputSourceMap,
27+
inputSourceMap: (state.file.inputMap as undefined | { toObject(): object })?.toObject(),
3928
});
4029
visitors.set(path, visitor);
4130

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

-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ 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';
2322
import { maxWorkers, useTypeChecking } from '../../../utils/environment-options';
2423
import { AngularHostOptions } from '../../angular/angular-host';
2524
import { AngularCompilation, DiagnosticModes, NoopCompilation } from '../../angular/compilation';
@@ -707,10 +706,6 @@ function createCompilerOptionsTransformer(
707706
return {
708707
...compilerOptions,
709708
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,
714709
inlineSources: !!pluginOptions.sourcemap,
715710
inlineSourceMap: !!pluginOptions.sourcemap,
716711
sourceMap: undefined,

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

+3-22
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
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';
1311
import { StylesheetLanguage, StylesheetPluginOptions } from './stylesheet-plugin-factory';
1412

1513
/**
@@ -115,24 +113,22 @@ async function compileString(
115113
};
116114

117115
try {
118-
const { imports, map, css } = await less.render(data, {
116+
const { imports, css } = await less.render(data, {
119117
filename,
120118
paths: options.includePaths,
121119
plugins: [resolverPlugin],
122120
rewriteUrls: 'all',
123121
javascriptEnabled: unsafeInlineJavaScript,
124122
sourceMap: options.sourcemap
125123
? {
126-
sourceMapFileInline: false,
124+
sourceMapFileInline: true,
127125
outputSourceFiles: true,
128126
}
129127
: undefined,
130128
} as Less.Options);
131129

132130
return {
133-
// There can be cases where `less` will return an undefined `map` even
134-
// though the types do not specify this as a possibility.
135-
contents: map ? `${css}\n${sourceMapToUrlComment(map)}` : css,
131+
contents: css,
136132
loader: 'css',
137133
watchFiles: [filename, ...imports],
138134
};
@@ -194,18 +190,3 @@ function convertExceptionLocation(exception: LessException): Partial<Location> {
194190
lineText: exception.extract && exception.extract[Math.trunc(exception.extract.length / 2)],
195191
};
196192
}
197-
198-
function sourceMapToUrlComment(sourceMap: string): string {
199-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
200-
const map = JSON.parse(sourceMap) as Record<string, any>;
201-
// Using file URLs instead of paths ensures that esbuild correctly resolves the source map.
202-
// https://github.com/evanw/esbuild/issues/4070
203-
// https://github.com/evanw/esbuild/issues/4075
204-
map.sources = map.sources.map((source: string) =>
205-
source && isAbsolute(source) ? pathToFileURL(source).href : source,
206-
);
207-
208-
const urlSourceMap = Buffer.from(JSON.stringify(map), 'utf-8').toString('base64');
209-
210-
return `/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${urlSourceMap} */`;
211-
}

0 commit comments

Comments
 (0)