mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-16 02:24:10 +08:00
refactor(@angular/build): remove esbuild sourcemap workarounds
These are no longer requires since 0.25.1
This commit is contained in:
parent
97ed10b964
commit
596b9ae60c
@ -9,7 +9,6 @@
|
|||||||
import { NodePath, PluginObj, types } from '@babel/core';
|
import { NodePath, PluginObj, types } from '@babel/core';
|
||||||
import { Visitor, programVisitor } from 'istanbul-lib-instrument';
|
import { Visitor, programVisitor } from 'istanbul-lib-instrument';
|
||||||
import assert from 'node:assert';
|
import assert from 'node:assert';
|
||||||
import { fileURLToPath } from 'node:url';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A babel plugin factory function for adding istanbul instrumentation.
|
* A babel plugin factory function for adding istanbul instrumentation.
|
||||||
@ -23,19 +22,9 @@ export default function (): PluginObj {
|
|||||||
visitor: {
|
visitor: {
|
||||||
Program: {
|
Program: {
|
||||||
enter(path, state) {
|
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, {
|
const visitor = programVisitor(types, state.filename, {
|
||||||
// Babel returns a Converter object from the `convert-source-map` package
|
// Babel returns a Converter object from the `convert-source-map` package
|
||||||
inputSourceMap,
|
inputSourceMap: (state.file.inputMap as undefined | { toObject(): object })?.toObject(),
|
||||||
});
|
});
|
||||||
visitors.set(path, visitor);
|
visitors.set(path, visitor);
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@ import type {
|
|||||||
import assert from 'node:assert';
|
import assert from 'node:assert';
|
||||||
import { createHash } from 'node:crypto';
|
import { createHash } from 'node:crypto';
|
||||||
import * as path from 'node:path';
|
import * as path from 'node:path';
|
||||||
import { pathToFileURL } from 'node:url';
|
|
||||||
import { maxWorkers, useTypeChecking } from '../../../utils/environment-options';
|
import { maxWorkers, useTypeChecking } from '../../../utils/environment-options';
|
||||||
import { AngularHostOptions } from '../../angular/angular-host';
|
import { AngularHostOptions } from '../../angular/angular-host';
|
||||||
import { AngularCompilation, DiagnosticModes, NoopCompilation } from '../../angular/compilation';
|
import { AngularCompilation, DiagnosticModes, NoopCompilation } from '../../angular/compilation';
|
||||||
@ -707,10 +706,6 @@ function createCompilerOptionsTransformer(
|
|||||||
return {
|
return {
|
||||||
...compilerOptions,
|
...compilerOptions,
|
||||||
noEmitOnError: false,
|
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,
|
inlineSources: !!pluginOptions.sourcemap,
|
||||||
inlineSourceMap: !!pluginOptions.sourcemap,
|
inlineSourceMap: !!pluginOptions.sourcemap,
|
||||||
sourceMap: undefined,
|
sourceMap: undefined,
|
||||||
|
@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
import type { Location, OnLoadResult, PluginBuild } from 'esbuild';
|
import type { Location, OnLoadResult, PluginBuild } from 'esbuild';
|
||||||
import { readFile } from 'node:fs/promises';
|
import { readFile } from 'node:fs/promises';
|
||||||
import { isAbsolute } from 'node:path';
|
|
||||||
import { pathToFileURL } from 'node:url';
|
|
||||||
import { StylesheetLanguage, StylesheetPluginOptions } from './stylesheet-plugin-factory';
|
import { StylesheetLanguage, StylesheetPluginOptions } from './stylesheet-plugin-factory';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -115,7 +113,7 @@ async function compileString(
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { imports, map, css } = await less.render(data, {
|
const { imports, css } = await less.render(data, {
|
||||||
filename,
|
filename,
|
||||||
paths: options.includePaths,
|
paths: options.includePaths,
|
||||||
plugins: [resolverPlugin],
|
plugins: [resolverPlugin],
|
||||||
@ -123,16 +121,14 @@ async function compileString(
|
|||||||
javascriptEnabled: unsafeInlineJavaScript,
|
javascriptEnabled: unsafeInlineJavaScript,
|
||||||
sourceMap: options.sourcemap
|
sourceMap: options.sourcemap
|
||||||
? {
|
? {
|
||||||
sourceMapFileInline: false,
|
sourceMapFileInline: true,
|
||||||
outputSourceFiles: true,
|
outputSourceFiles: true,
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
} as Less.Options);
|
} as Less.Options);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// There can be cases where `less` will return an undefined `map` even
|
contents: css,
|
||||||
// though the types do not specify this as a possibility.
|
|
||||||
contents: map ? `${css}\n${sourceMapToUrlComment(map)}` : css,
|
|
||||||
loader: 'css',
|
loader: 'css',
|
||||||
watchFiles: [filename, ...imports],
|
watchFiles: [filename, ...imports],
|
||||||
};
|
};
|
||||||
@ -194,18 +190,3 @@ function convertExceptionLocation(exception: LessException): Partial<Location> {
|
|||||||
lineText: exception.extract && exception.extract[Math.trunc(exception.extract.length / 2)],
|
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} */`;
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user