@angular-devkit/build-angular 17.1.0 → 17.2.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +27 -27
- package/src/builders/dev-server/options.js +3 -2
- package/src/builders/dev-server/schema.json +1 -1
- package/src/builders/dev-server/vite-server.js +14 -213
- package/src/builders/extract-i18n/options.js +3 -2
- package/src/builders/extract-i18n/schema.json +1 -1
- package/src/builders/jest/index.js +44 -5
- package/src/builders/jest/jest.config.mjs +11 -0
- package/src/builders/prerender/routes-extractor-worker.js +1 -1
- package/src/tools/esbuild/angular/compilation/angular-compilation.d.ts +9 -2
- package/src/tools/esbuild/angular/compilation/angular-compilation.js +11 -3
- package/src/tools/esbuild/angular/compilation/aot-compilation.d.ts +2 -2
- package/src/tools/esbuild/angular/compilation/aot-compilation.js +19 -8
- package/src/tools/esbuild/angular/compilation/index.d.ts +1 -1
- package/src/tools/esbuild/angular/compilation/index.js +2 -1
- package/src/tools/esbuild/angular/compilation/jit-compilation.d.ts +2 -2
- package/src/tools/esbuild/angular/compilation/jit-compilation.js +12 -6
- package/src/tools/esbuild/angular/compilation/parallel-compilation.d.ts +2 -2
- package/src/tools/esbuild/angular/compilation/parallel-compilation.js +2 -2
- package/src/tools/esbuild/angular/compilation/parallel-worker.d.ts +2 -1
- package/src/tools/esbuild/angular/compilation/parallel-worker.js +2 -2
- package/src/tools/esbuild/angular/compiler-plugin.js +7 -7
- package/src/tools/esbuild/angular/component-stylesheets.js +10 -8
- package/src/tools/esbuild/application-code-bundle.js +12 -3
- package/src/tools/esbuild/bundler-context.js +12 -8
- package/src/tools/esbuild/external-packages-plugin.d.ts +16 -0
- package/src/tools/esbuild/external-packages-plugin.js +66 -0
- package/src/tools/esbuild/stylesheets/css-resource-plugin.js +3 -2
- package/src/tools/vite/angular-memory-plugin.d.ts +24 -0
- package/src/tools/vite/angular-memory-plugin.js +252 -0
- package/src/utils/environment-options.d.ts +1 -0
- package/src/utils/environment-options.js +3 -1
- package/src/utils/index-file/inline-critical-css.js +28 -20
- package/src/utils/server-rendering/render-page.js +5 -0
|
@@ -86,22 +86,33 @@ class AotCompilation extends angular_compilation_1.AngularCompilation {
|
|
|
86
86
|
this.#state = new AngularCompilationState(angularProgram, host, typeScriptProgram, affectedFiles, affectedFiles.size === 1 ? OptimizeFor.SingleFile : OptimizeFor.WholeProgram, (0, web_worker_transformer_1.createWorkerTransformer)(hostOptions.processWebWorker.bind(hostOptions)), this.#state?.diagnosticCache);
|
|
87
87
|
return { affectedFiles, compilerOptions, referencedFiles };
|
|
88
88
|
}
|
|
89
|
-
*collectDiagnostics() {
|
|
89
|
+
*collectDiagnostics(modes) {
|
|
90
90
|
(0, node_assert_1.default)(this.#state, 'Angular compilation must be initialized prior to collecting diagnostics.');
|
|
91
91
|
const { affectedFiles, angularCompiler, diagnosticCache, templateDiagnosticsOptimization, typeScriptProgram, } = this.#state;
|
|
92
|
+
const syntactic = modes & angular_compilation_1.DiagnosticModes.Syntactic;
|
|
93
|
+
const semantic = modes & angular_compilation_1.DiagnosticModes.Semantic;
|
|
92
94
|
// Collect program level diagnostics
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
if (modes & angular_compilation_1.DiagnosticModes.Option) {
|
|
96
|
+
yield* typeScriptProgram.getConfigFileParsingDiagnostics();
|
|
97
|
+
yield* angularCompiler.getOptionDiagnostics();
|
|
98
|
+
yield* typeScriptProgram.getOptionsDiagnostics();
|
|
99
|
+
}
|
|
100
|
+
if (syntactic) {
|
|
101
|
+
yield* typeScriptProgram.getGlobalDiagnostics();
|
|
102
|
+
}
|
|
97
103
|
// Collect source file specific diagnostics
|
|
98
104
|
for (const sourceFile of typeScriptProgram.getSourceFiles()) {
|
|
99
105
|
if (angularCompiler.ignoreForDiagnostics.has(sourceFile)) {
|
|
100
106
|
continue;
|
|
101
107
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
108
|
+
if (syntactic) {
|
|
109
|
+
// TypeScript will use cached diagnostics for files that have not been
|
|
110
|
+
// changed or affected for this build when using incremental building.
|
|
111
|
+
yield* (0, profiling_1.profileSync)('NG_DIAGNOSTICS_SYNTACTIC', () => typeScriptProgram.getSyntacticDiagnostics(sourceFile), true);
|
|
112
|
+
}
|
|
113
|
+
if (!semantic) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
105
116
|
yield* (0, profiling_1.profileSync)('NG_DIAGNOSTICS_SEMANTIC', () => typeScriptProgram.getSemanticDiagnostics(sourceFile), true);
|
|
106
117
|
// Declaration files cannot have template diagnostics
|
|
107
118
|
if (sourceFile.isDeclarationFile) {
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
|
-
export { AngularCompilation } from './angular-compilation';
|
|
8
|
+
export { AngularCompilation, DiagnosticModes } from './angular-compilation';
|
|
9
9
|
export { createAngularCompilation } from './factory';
|
|
10
10
|
export { NoopCompilation } from './noop-compilation';
|
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
* found in the LICENSE file at https://angular.io/license
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.NoopCompilation = exports.createAngularCompilation = exports.AngularCompilation = void 0;
|
|
10
|
+
exports.NoopCompilation = exports.createAngularCompilation = exports.DiagnosticModes = exports.AngularCompilation = void 0;
|
|
11
11
|
var angular_compilation_1 = require("./angular-compilation");
|
|
12
12
|
Object.defineProperty(exports, "AngularCompilation", { enumerable: true, get: function () { return angular_compilation_1.AngularCompilation; } });
|
|
13
|
+
Object.defineProperty(exports, "DiagnosticModes", { enumerable: true, get: function () { return angular_compilation_1.DiagnosticModes; } });
|
|
13
14
|
var factory_1 = require("./factory");
|
|
14
15
|
Object.defineProperty(exports, "createAngularCompilation", { enumerable: true, get: function () { return factory_1.createAngularCompilation; } });
|
|
15
16
|
var noop_compilation_1 = require("./noop-compilation");
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import type ng from '@angular/compiler-cli';
|
|
9
9
|
import ts from 'typescript';
|
|
10
10
|
import { AngularHostOptions } from '../angular-host';
|
|
11
|
-
import { AngularCompilation, EmitFileResult } from './angular-compilation';
|
|
11
|
+
import { AngularCompilation, DiagnosticModes, EmitFileResult } from './angular-compilation';
|
|
12
12
|
export declare class JitCompilation extends AngularCompilation {
|
|
13
13
|
#private;
|
|
14
14
|
initialize(tsconfig: string, hostOptions: AngularHostOptions, compilerOptionsTransformer?: (compilerOptions: ng.CompilerOptions) => ng.CompilerOptions): Promise<{
|
|
@@ -16,6 +16,6 @@ export declare class JitCompilation extends AngularCompilation {
|
|
|
16
16
|
compilerOptions: ng.CompilerOptions;
|
|
17
17
|
referencedFiles: readonly string[];
|
|
18
18
|
}>;
|
|
19
|
-
collectDiagnostics(): Iterable<ts.Diagnostic>;
|
|
19
|
+
collectDiagnostics(modes: DiagnosticModes): Iterable<ts.Diagnostic>;
|
|
20
20
|
emitAffectedFiles(): Iterable<EmitFileResult>;
|
|
21
21
|
}
|
|
@@ -51,15 +51,21 @@ class JitCompilation extends angular_compilation_1.AngularCompilation {
|
|
|
51
51
|
.map((sourceFile) => sourceFile.fileName);
|
|
52
52
|
return { affectedFiles, compilerOptions, referencedFiles };
|
|
53
53
|
}
|
|
54
|
-
*collectDiagnostics() {
|
|
54
|
+
*collectDiagnostics(modes) {
|
|
55
55
|
(0, node_assert_1.default)(this.#state, 'Compilation must be initialized prior to collecting diagnostics.');
|
|
56
56
|
const { typeScriptProgram } = this.#state;
|
|
57
57
|
// Collect program level diagnostics
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
if (modes & angular_compilation_1.DiagnosticModes.Option) {
|
|
59
|
+
yield* typeScriptProgram.getConfigFileParsingDiagnostics();
|
|
60
|
+
yield* typeScriptProgram.getOptionsDiagnostics();
|
|
61
|
+
}
|
|
62
|
+
if (modes & angular_compilation_1.DiagnosticModes.Syntactic) {
|
|
63
|
+
yield* typeScriptProgram.getGlobalDiagnostics();
|
|
64
|
+
yield* (0, profiling_1.profileSync)('NG_DIAGNOSTICS_SYNTACTIC', () => typeScriptProgram.getSyntacticDiagnostics());
|
|
65
|
+
}
|
|
66
|
+
if (modes & angular_compilation_1.DiagnosticModes.Semantic) {
|
|
67
|
+
yield* (0, profiling_1.profileSync)('NG_DIAGNOSTICS_SEMANTIC', () => typeScriptProgram.getSemanticDiagnostics());
|
|
68
|
+
}
|
|
63
69
|
}
|
|
64
70
|
emitAffectedFiles() {
|
|
65
71
|
(0, node_assert_1.default)(this.#state, 'Compilation must be initialized prior to emitting files.');
|
|
@@ -9,7 +9,7 @@ import type { CompilerOptions } from '@angular/compiler-cli';
|
|
|
9
9
|
import type { PartialMessage } from 'esbuild';
|
|
10
10
|
import type { SourceFile } from 'typescript';
|
|
11
11
|
import type { AngularHostOptions } from '../angular-host';
|
|
12
|
-
import { AngularCompilation, EmitFileResult } from './angular-compilation';
|
|
12
|
+
import { AngularCompilation, DiagnosticModes, EmitFileResult } from './angular-compilation';
|
|
13
13
|
/**
|
|
14
14
|
* An Angular compilation which uses a Node.js Worker thread to load and execute
|
|
15
15
|
* the TypeScript and Angular compilers. This allows for longer synchronous actions
|
|
@@ -32,7 +32,7 @@ export declare class ParallelCompilation extends AngularCompilation {
|
|
|
32
32
|
* with the serializable esbuild compatible diagnostics.
|
|
33
33
|
*/
|
|
34
34
|
protected collectDiagnostics(): never;
|
|
35
|
-
diagnoseFiles(): Promise<{
|
|
35
|
+
diagnoseFiles(modes?: DiagnosticModes): Promise<{
|
|
36
36
|
errors?: PartialMessage[];
|
|
37
37
|
warnings?: PartialMessage[];
|
|
38
38
|
}>;
|
|
@@ -106,8 +106,8 @@ class ParallelCompilation extends angular_compilation_1.AngularCompilation {
|
|
|
106
106
|
collectDiagnostics() {
|
|
107
107
|
throw new Error('Not implemented in ParallelCompilation.');
|
|
108
108
|
}
|
|
109
|
-
diagnoseFiles() {
|
|
110
|
-
return this.#worker.run(
|
|
109
|
+
diagnoseFiles(modes = angular_compilation_1.DiagnosticModes.All) {
|
|
110
|
+
return this.#worker.run(modes, { name: 'diagnose' });
|
|
111
111
|
}
|
|
112
112
|
emitAffectedFiles() {
|
|
113
113
|
return this.#worker.run(undefined, { name: 'emit' });
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
/// <reference types="@types/node/ts4.8/worker_threads" />
|
|
11
11
|
import type { PartialMessage } from 'esbuild';
|
|
12
12
|
import { type MessagePort } from 'node:worker_threads';
|
|
13
|
+
import type { DiagnosticModes } from './angular-compilation';
|
|
13
14
|
export interface InitRequest {
|
|
14
15
|
jit: boolean;
|
|
15
16
|
tsconfig: string;
|
|
@@ -26,7 +27,7 @@ export declare function initialize(request: InitRequest): Promise<{
|
|
|
26
27
|
allowJs: boolean | undefined;
|
|
27
28
|
};
|
|
28
29
|
}>;
|
|
29
|
-
export declare function diagnose(): Promise<{
|
|
30
|
+
export declare function diagnose(modes: DiagnosticModes): Promise<{
|
|
30
31
|
errors?: PartialMessage[];
|
|
31
32
|
warnings?: PartialMessage[];
|
|
32
33
|
}>;
|
|
@@ -72,9 +72,9 @@ async function initialize(request) {
|
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
74
|
exports.initialize = initialize;
|
|
75
|
-
async function diagnose() {
|
|
75
|
+
async function diagnose(modes) {
|
|
76
76
|
(0, node_assert_1.default)(compilation);
|
|
77
|
-
const diagnostics = await compilation.diagnoseFiles();
|
|
77
|
+
const diagnostics = await compilation.diagnoseFiles(modes);
|
|
78
78
|
return diagnostics;
|
|
79
79
|
}
|
|
80
80
|
exports.diagnose = diagnose;
|
|
@@ -195,13 +195,6 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
|
|
|
195
195
|
hasCompilationErrors = await sharedTSCompilationState.waitUntilReady;
|
|
196
196
|
return result;
|
|
197
197
|
}
|
|
198
|
-
const diagnostics = await compilation.diagnoseFiles();
|
|
199
|
-
if (diagnostics.errors?.length) {
|
|
200
|
-
(result.errors ??= []).push(...diagnostics.errors);
|
|
201
|
-
}
|
|
202
|
-
if (diagnostics.warnings?.length) {
|
|
203
|
-
(result.warnings ??= []).push(...diagnostics.warnings);
|
|
204
|
-
}
|
|
205
198
|
// Update TypeScript file output cache for all affected files
|
|
206
199
|
try {
|
|
207
200
|
await (0, profiling_1.profileAsync)('NG_EMIT_TS', async () => {
|
|
@@ -222,6 +215,13 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
|
|
|
222
215
|
],
|
|
223
216
|
});
|
|
224
217
|
}
|
|
218
|
+
const diagnostics = await compilation.diagnoseFiles(environment_options_1.useTypeChecking ? compilation_1.DiagnosticModes.All : compilation_1.DiagnosticModes.All & ~compilation_1.DiagnosticModes.Semantic);
|
|
219
|
+
if (diagnostics.errors?.length) {
|
|
220
|
+
(result.errors ??= []).push(...diagnostics.errors);
|
|
221
|
+
}
|
|
222
|
+
if (diagnostics.warnings?.length) {
|
|
223
|
+
(result.warnings ??= []).push(...diagnostics.warnings);
|
|
224
|
+
}
|
|
225
225
|
// Add errors from failed additional results.
|
|
226
226
|
// This must be done after emit to capture latest web worker results.
|
|
227
227
|
for (const { errors } of additionalResults.values()) {
|
|
@@ -110,18 +110,20 @@ class ComponentStylesheetBundler {
|
|
|
110
110
|
if (!result.errors) {
|
|
111
111
|
for (const outputFile of result.outputFiles) {
|
|
112
112
|
const filename = node_path_1.default.basename(outputFile.path);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
113
|
+
if (outputFile.type === bundler_context_1.BuildOutputFileType.Media || filename.endsWith('.css.map')) {
|
|
114
|
+
// The output files could also contain resources (images/fonts/etc.) that were referenced and the map files.
|
|
115
|
+
// Clone the output file to avoid amending the original path which would causes problems during rebuild.
|
|
116
|
+
const clonedOutputFile = outputFile.clone();
|
|
117
|
+
// Needed for Bazel as otherwise the files will not be written in the correct place,
|
|
118
|
+
// this is because esbuild will resolve the output file from the outdir which is currently set to `workspaceRoot` twice,
|
|
119
|
+
// once in the stylesheet and the other in the application code bundler.
|
|
120
|
+
// Ex: `../../../../../app.component.css.map`.
|
|
121
|
+
clonedOutputFile.path = node_path_1.default.join(this.options.workspaceRoot, outputFile.path);
|
|
122
|
+
outputFiles.push(clonedOutputFile);
|
|
118
123
|
}
|
|
119
124
|
else if (filename.endsWith('.css')) {
|
|
120
125
|
contents = outputFile.text;
|
|
121
126
|
}
|
|
122
|
-
else if (filename.endsWith('.css.map')) {
|
|
123
|
-
outputFiles.push(outputFile);
|
|
124
|
-
}
|
|
125
127
|
else {
|
|
126
128
|
throw new Error(`Unexpected non CSS/Media file "${filename}" outputted during component stylesheet processing.`);
|
|
127
129
|
}
|
|
@@ -18,6 +18,7 @@ const node_path_1 = require("node:path");
|
|
|
18
18
|
const environment_options_1 = require("../../utils/environment-options");
|
|
19
19
|
const compiler_plugin_1 = require("./angular/compiler-plugin");
|
|
20
20
|
const compiler_plugin_options_1 = require("./compiler-plugin-options");
|
|
21
|
+
const external_packages_plugin_1 = require("./external-packages-plugin");
|
|
21
22
|
const i18n_locale_plugin_1 = require("./i18n-locale-plugin");
|
|
22
23
|
const rxjs_esm_resolution_plugin_1 = require("./rxjs-esm-resolution-plugin");
|
|
23
24
|
const sourcemap_ignorelist_plugin_1 = require("./sourcemap-ignorelist-plugin");
|
|
@@ -47,12 +48,20 @@ function createBrowserCodeBundleOptions(options, target, sourceFileCache) {
|
|
|
47
48
|
styleOptions),
|
|
48
49
|
],
|
|
49
50
|
};
|
|
50
|
-
if (options.externalPackages) {
|
|
51
|
-
buildOptions.packages = 'external';
|
|
52
|
-
}
|
|
53
51
|
if (options.plugins) {
|
|
54
52
|
buildOptions.plugins?.push(...options.plugins);
|
|
55
53
|
}
|
|
54
|
+
if (options.externalPackages) {
|
|
55
|
+
// Package files affected by a customized loader should not be implicitly marked as external
|
|
56
|
+
if (options.loaderExtensions || options.plugins) {
|
|
57
|
+
// Plugin must be added after custom plugins to ensure any added loader options are considered
|
|
58
|
+
buildOptions.plugins?.push((0, external_packages_plugin_1.createExternalPackagesPlugin)());
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// Safe to use the packages external option directly
|
|
62
|
+
buildOptions.packages = 'external';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
56
65
|
return buildOptions;
|
|
57
66
|
}
|
|
58
67
|
exports.createBrowserCodeBundleOptions = createBrowserCodeBundleOptions;
|
|
@@ -177,10 +177,12 @@ class BundlerContext {
|
|
|
177
177
|
if (this.incremental) {
|
|
178
178
|
// When incremental always add any files from the load result cache
|
|
179
179
|
if (this.#loadCache) {
|
|
180
|
-
this.#loadCache.watchFiles
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
180
|
+
for (const file of this.#loadCache.watchFiles) {
|
|
181
|
+
if (!isInternalAngularFile(file)) {
|
|
182
|
+
// watch files are fully resolved paths
|
|
183
|
+
this.watchFiles.add(file);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
184
186
|
}
|
|
185
187
|
}
|
|
186
188
|
}
|
|
@@ -189,10 +191,12 @@ class BundlerContext {
|
|
|
189
191
|
// currently enabled with watch mode where watch files are needed.
|
|
190
192
|
if (this.incremental) {
|
|
191
193
|
// Add input files except virtual angular files which do not exist on disk
|
|
192
|
-
Object.keys(result.metafile.inputs)
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
194
|
+
for (const input of Object.keys(result.metafile.inputs)) {
|
|
195
|
+
if (!isInternalAngularFile(input)) {
|
|
196
|
+
// input file paths are always relative to the workspace root
|
|
197
|
+
this.watchFiles.add((0, node_path_1.join)(this.workspaceRoot, input));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
196
200
|
}
|
|
197
201
|
// Return if the build encountered any errors
|
|
198
202
|
if (result.errors.length) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
import type { Plugin } from 'esbuild';
|
|
9
|
+
/**
|
|
10
|
+
* Creates a plugin that marks any resolved path as external if it is within a node modules directory.
|
|
11
|
+
* This is used instead of the esbuild `packages` option to avoid marking files that should be loaded
|
|
12
|
+
* via customized loaders. This is necessary to prevent Vite development server pre-bundling errors.
|
|
13
|
+
*
|
|
14
|
+
* @returns An esbuild plugin.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createExternalPackagesPlugin(): Plugin;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.io/license
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.createExternalPackagesPlugin = void 0;
|
|
11
|
+
const node_path_1 = require("node:path");
|
|
12
|
+
const EXTERNAL_PACKAGE_RESOLUTION = Symbol('EXTERNAL_PACKAGE_RESOLUTION');
|
|
13
|
+
/**
|
|
14
|
+
* Creates a plugin that marks any resolved path as external if it is within a node modules directory.
|
|
15
|
+
* This is used instead of the esbuild `packages` option to avoid marking files that should be loaded
|
|
16
|
+
* via customized loaders. This is necessary to prevent Vite development server pre-bundling errors.
|
|
17
|
+
*
|
|
18
|
+
* @returns An esbuild plugin.
|
|
19
|
+
*/
|
|
20
|
+
function createExternalPackagesPlugin() {
|
|
21
|
+
return {
|
|
22
|
+
name: 'angular-external-packages',
|
|
23
|
+
setup(build) {
|
|
24
|
+
// Safe to use native packages external option if no loader options present
|
|
25
|
+
if (build.initialOptions.loader === undefined ||
|
|
26
|
+
Object.keys(build.initialOptions.loader).length === 0) {
|
|
27
|
+
build.initialOptions.packages = 'external';
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const loaderFileExtensions = new Set(Object.keys(build.initialOptions.loader));
|
|
31
|
+
// Only attempt resolve of non-relative and non-absolute paths
|
|
32
|
+
build.onResolve({ filter: /^[^./]/ }, async (args) => {
|
|
33
|
+
if (args.pluginData?.[EXTERNAL_PACKAGE_RESOLUTION]) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const { importer, kind, resolveDir, namespace, pluginData = {} } = args;
|
|
37
|
+
pluginData[EXTERNAL_PACKAGE_RESOLUTION] = true;
|
|
38
|
+
const result = await build.resolve(args.path, {
|
|
39
|
+
importer,
|
|
40
|
+
kind,
|
|
41
|
+
namespace,
|
|
42
|
+
pluginData,
|
|
43
|
+
resolveDir,
|
|
44
|
+
});
|
|
45
|
+
// Return result if unable to resolve or explicitly marked external (externalDependencies option)
|
|
46
|
+
if (!result.path || result.external) {
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
// Allow customized loaders to run against configured paths regardless of location
|
|
50
|
+
if (loaderFileExtensions.has((0, node_path_1.extname)(result.path))) {
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
// Mark paths from a node modules directory as external
|
|
54
|
+
if (/[\\/]node_modules[\\/]/.test(result.path)) {
|
|
55
|
+
return {
|
|
56
|
+
path: args.path,
|
|
57
|
+
external: true,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
// Otherwise return original result
|
|
61
|
+
return result;
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
exports.createExternalPackagesPlugin = createExternalPackagesPlugin;
|
|
@@ -11,6 +11,7 @@ exports.createCssResourcePlugin = void 0;
|
|
|
11
11
|
const promises_1 = require("node:fs/promises");
|
|
12
12
|
const node_path_1 = require("node:path");
|
|
13
13
|
const load_result_cache_1 = require("../load-result-cache");
|
|
14
|
+
const CSS_RESOURCE_NAMESPACE = 'angular:css-resource';
|
|
14
15
|
/**
|
|
15
16
|
* Symbol marker used to indicate CSS resource resolution is being attempted.
|
|
16
17
|
* This is used to prevent an infinite loop within the plugin's resolve hook.
|
|
@@ -89,10 +90,10 @@ function createCssResourcePlugin(cache) {
|
|
|
89
90
|
// Use a relative path to prevent fully resolved paths in the metafile (JSON stats file).
|
|
90
91
|
// This is only necessary for custom namespaces. esbuild will handle the file namespace.
|
|
91
92
|
path: (0, node_path_1.relative)(build.initialOptions.absWorkingDir ?? '', result.path),
|
|
92
|
-
namespace:
|
|
93
|
+
namespace: CSS_RESOURCE_NAMESPACE,
|
|
93
94
|
};
|
|
94
95
|
});
|
|
95
|
-
build.onLoad({ filter: /./, namespace:
|
|
96
|
+
build.onLoad({ filter: /./, namespace: CSS_RESOURCE_NAMESPACE }, (0, load_result_cache_1.createCachedLoad)(cache, async (args) => {
|
|
96
97
|
const resourcePath = (0, node_path_1.join)(build.initialOptions.absWorkingDir ?? '', args.path);
|
|
97
98
|
return {
|
|
98
99
|
contents: await (0, promises_1.readFile)(resourcePath),
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
import type { Connect, Plugin } from 'vite';
|
|
9
|
+
export interface AngularMemoryPluginOptions {
|
|
10
|
+
workspaceRoot: string;
|
|
11
|
+
virtualProjectRoot: string;
|
|
12
|
+
outputFiles: Map<string, {
|
|
13
|
+
contents: Uint8Array;
|
|
14
|
+
servable: boolean;
|
|
15
|
+
}>;
|
|
16
|
+
assets: Map<string, string>;
|
|
17
|
+
ssr: boolean;
|
|
18
|
+
external?: string[];
|
|
19
|
+
extensionMiddleware?: Connect.NextHandleFunction[];
|
|
20
|
+
extraHeaders?: Record<string, string>;
|
|
21
|
+
indexHtmlTransformer?: (content: string) => Promise<string>;
|
|
22
|
+
normalizePath: (path: string) => string;
|
|
23
|
+
}
|
|
24
|
+
export declare function createAngularMemoryPlugin(options: AngularMemoryPluginOptions): Plugin;
|