@angular-devkit/build-angular 15.1.0-next.2 → 15.1.0-next.3
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 +10 -10
- package/src/babel/presets/application.js +1 -1
- package/src/builders/browser-esbuild/compiler-plugin.d.ts +3 -1
- package/src/builders/browser-esbuild/compiler-plugin.js +11 -12
- package/src/builders/browser-esbuild/experimental-warnings.js +3 -7
- package/src/builders/browser-esbuild/index.js +6 -1
- package/src/builders/browser-esbuild/javascript-transformer-worker.js +1 -1
- package/src/builders/browser-esbuild/javascript-transformer.js +2 -2
- package/src/builders/browser-esbuild/options.d.ts +1 -0
- package/src/builders/browser-esbuild/options.js +2 -1
- package/src/builders/browser-esbuild/sass-plugin.d.ts +5 -3
- package/src/builders/browser-esbuild/sass-plugin.js +87 -74
- package/src/builders/browser-esbuild/stylesheets.d.ts +13 -25
- package/src/builders/browser-esbuild/stylesheets.js +57 -40
- package/src/builders/browser-esbuild/worker-angular-compilation.d.ts +0 -0
- package/src/builders/browser-esbuild/worker-angular-compilation.js +59 -0
- package/src/builders/karma/index.js +3 -1
- package/src/utils/i18n-inlining.js +1 -1
- package/src/utils/process-bundle.js +1 -1
- package/src/webpack/configs/styles.js +1 -0
- package/src/webpack/plugins/styles-webpack-plugin.js +26 -24
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-devkit/build-angular",
|
|
3
|
-
"version": "15.1.0-next.
|
|
3
|
+
"version": "15.1.0-next.3",
|
|
4
4
|
"description": "Angular Webpack Build Facade",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"typings": "src/index.d.ts",
|
|
7
7
|
"builders": "builders.json",
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@ampproject/remapping": "2.2.0",
|
|
10
|
-
"@angular-devkit/architect": "0.1501.0-next.
|
|
11
|
-
"@angular-devkit/build-webpack": "0.1501.0-next.
|
|
12
|
-
"@angular-devkit/core": "15.1.0-next.
|
|
10
|
+
"@angular-devkit/architect": "0.1501.0-next.3",
|
|
11
|
+
"@angular-devkit/build-webpack": "0.1501.0-next.3",
|
|
12
|
+
"@angular-devkit/core": "15.1.0-next.3",
|
|
13
13
|
"@babel/core": "7.20.5",
|
|
14
14
|
"@babel/generator": "7.20.5",
|
|
15
15
|
"@babel/helper-annotate-as-pure": "7.18.6",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@babel/runtime": "7.20.6",
|
|
21
21
|
"@babel/template": "7.18.10",
|
|
22
22
|
"@discoveryjs/json-ext": "0.5.7",
|
|
23
|
-
"@ngtools/webpack": "15.1.0-next.
|
|
23
|
+
"@ngtools/webpack": "15.1.0-next.3",
|
|
24
24
|
"ansi-colors": "4.1.3",
|
|
25
25
|
"autoprefixer": "10.4.13",
|
|
26
26
|
"babel-loader": "9.1.0",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"chokidar": "3.5.3",
|
|
31
31
|
"copy-webpack-plugin": "11.0.0",
|
|
32
32
|
"critters": "0.0.16",
|
|
33
|
-
"css-loader": "6.7.
|
|
34
|
-
"esbuild-wasm": "0.16.
|
|
33
|
+
"css-loader": "6.7.3",
|
|
34
|
+
"esbuild-wasm": "0.16.6",
|
|
35
35
|
"glob": "8.0.3",
|
|
36
36
|
"https-proxy-agent": "5.0.1",
|
|
37
37
|
"inquirer": "8.2.4",
|
|
@@ -47,11 +47,11 @@
|
|
|
47
47
|
"ora": "5.4.1",
|
|
48
48
|
"parse5-html-rewriting-stream": "6.0.1",
|
|
49
49
|
"piscina": "3.2.0",
|
|
50
|
-
"postcss": "8.4.
|
|
50
|
+
"postcss": "8.4.20",
|
|
51
51
|
"postcss-loader": "7.0.2",
|
|
52
52
|
"resolve-url-loader": "5.0.0",
|
|
53
53
|
"rxjs": "6.6.7",
|
|
54
|
-
"sass": "1.56.
|
|
54
|
+
"sass": "1.56.2",
|
|
55
55
|
"sass-loader": "13.2.0",
|
|
56
56
|
"semver": "7.3.8",
|
|
57
57
|
"source-map-loader": "4.0.1",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"webpack-subresource-integrity": "5.1.0"
|
|
68
68
|
},
|
|
69
69
|
"optionalDependencies": {
|
|
70
|
-
"esbuild": "0.16.
|
|
70
|
+
"esbuild": "0.16.6"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
73
|
"@angular/compiler-cli": "^15.0.0-next",
|
|
@@ -139,7 +139,7 @@ function default_1(api, options) {
|
|
|
139
139
|
// downlevel class properties by ensuring the class properties Babel plugin
|
|
140
140
|
// is always included- regardless of the preset-env targets.
|
|
141
141
|
if (options.supportedBrowsers.some((b) => safariClassFieldScopeBugBrowsers.has(b))) {
|
|
142
|
-
includePlugins.push('@babel/plugin-proposal-class-properties');
|
|
142
|
+
includePlugins.push('@babel/plugin-proposal-class-properties', '@babel/plugin-proposal-private-methods');
|
|
143
143
|
}
|
|
144
144
|
presets.push([
|
|
145
145
|
require('@babel/preset-env').default,
|
|
@@ -22,4 +22,6 @@ export interface CompilerPluginOptions {
|
|
|
22
22
|
fileReplacements?: Record<string, string>;
|
|
23
23
|
sourceFileCache?: SourceFileCache;
|
|
24
24
|
}
|
|
25
|
-
export declare function createCompilerPlugin(pluginOptions: CompilerPluginOptions, styleOptions: BundleStylesheetOptions
|
|
25
|
+
export declare function createCompilerPlugin(pluginOptions: CompilerPluginOptions, styleOptions: BundleStylesheetOptions & {
|
|
26
|
+
inlineStyleLanguage: string;
|
|
27
|
+
}): Plugin;
|
|
@@ -44,6 +44,10 @@ const angular_compilation_1 = require("./angular-compilation");
|
|
|
44
44
|
const javascript_transformer_1 = require("./javascript-transformer");
|
|
45
45
|
const profiling_1 = require("./profiling");
|
|
46
46
|
const stylesheets_1 = require("./stylesheets");
|
|
47
|
+
/**
|
|
48
|
+
* A counter for component styles used to generate unique build-time identifiers for each stylesheet.
|
|
49
|
+
*/
|
|
50
|
+
let componentStyleCounter = 0;
|
|
47
51
|
/**
|
|
48
52
|
* Converts TypeScript Diagnostic related information into an esbuild compatible note object.
|
|
49
53
|
* Related information is a subset of a full TypeScript Diagnostic and also used for diagnostic
|
|
@@ -149,6 +153,10 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
|
|
|
149
153
|
// Skip keys that have been manually provided
|
|
150
154
|
continue;
|
|
151
155
|
}
|
|
156
|
+
if (key === 'ngDevMode') {
|
|
157
|
+
// ngDevMode is already set based on the builder's script optimization option
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
152
160
|
// esbuild requires values to be a string (actual strings need to be quoted).
|
|
153
161
|
// In this case, all provided values are booleans.
|
|
154
162
|
build.initialOptions.define[key] = value.toString();
|
|
@@ -213,18 +221,9 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
|
|
|
213
221
|
var _a, _b;
|
|
214
222
|
// Stylesheet file only exists for external stylesheets
|
|
215
223
|
const filename = stylesheetFile !== null && stylesheetFile !== void 0 ? stylesheetFile : containingFile;
|
|
216
|
-
|
|
217
|
-
//
|
|
218
|
-
|
|
219
|
-
if (filename.endsWith('.scss') || filename.endsWith('.sass')) {
|
|
220
|
-
stylesheetResult = await (0, stylesheets_1.bundleStylesheetFile)(filename, styleOptions);
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
stylesheetResult = await (0, stylesheets_1.bundleStylesheetText)(data, {
|
|
224
|
-
resolvePath: path.dirname(filename),
|
|
225
|
-
virtualName: filename,
|
|
226
|
-
}, styleOptions);
|
|
227
|
-
}
|
|
224
|
+
const stylesheetResult = await (0, stylesheets_1.bundleComponentStylesheet)(
|
|
225
|
+
// TODO: Evaluate usage of a fast hash instead
|
|
226
|
+
`${++componentStyleCounter}`, styleOptions.inlineStyleLanguage, data, filename, !stylesheetFile, styleOptions);
|
|
228
227
|
const { contents, resourceFiles, errors, warnings } = stylesheetResult;
|
|
229
228
|
((_a = result.errors) !== null && _a !== void 0 ? _a : (result.errors = [])).push(...errors);
|
|
230
229
|
((_b = result.warnings) !== null && _b !== void 0 ? _b : (result.warnings = [])).push(...warnings);
|
|
@@ -20,10 +20,6 @@ const UNSUPPORTED_OPTIONS = [
|
|
|
20
20
|
// The following two have no effect when localize is not enabled
|
|
21
21
|
// 'i18nDuplicateTranslation',
|
|
22
22
|
// 'i18nMissingTranslation',
|
|
23
|
-
// * Stylesheet preprocessor support
|
|
24
|
-
'inlineStyleLanguage',
|
|
25
|
-
// The following option has no effect until preprocessors are supported
|
|
26
|
-
// 'stylePreprocessorOptions',
|
|
27
23
|
// * Deprecated
|
|
28
24
|
'deployUrl',
|
|
29
25
|
// * Always enabled with esbuild
|
|
@@ -49,10 +45,10 @@ function logExperimentalWarnings(options, context) {
|
|
|
49
45
|
if (typeof value === 'object' && Object.keys(value).length === 0) {
|
|
50
46
|
continue;
|
|
51
47
|
}
|
|
52
|
-
if (unsupportedOption === 'inlineStyleLanguage' && value === 'css') {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
48
|
context.logger.warn(`The '${unsupportedOption}' option is currently unsupported by this experimental builder and will be ignored.`);
|
|
56
49
|
}
|
|
50
|
+
if (options.inlineStyleLanguage === 'less') {
|
|
51
|
+
context.logger.warn('The less stylesheet preprocessor is not currently supported.');
|
|
52
|
+
}
|
|
57
53
|
}
|
|
58
54
|
exports.logExperimentalWarnings = logExperimentalWarnings;
|
|
@@ -180,7 +180,7 @@ function createOutputFileFromText(path, text) {
|
|
|
180
180
|
};
|
|
181
181
|
}
|
|
182
182
|
function createCodeBundleOptions(options, target, sourceFileCache) {
|
|
183
|
-
const { workspaceRoot, entryPoints, optimizationOptions, sourcemapOptions, tsconfig, outputNames, fileReplacements, externalDependencies, preserveSymlinks, stylePreprocessorOptions, advancedOptimizations, } = options;
|
|
183
|
+
const { workspaceRoot, entryPoints, optimizationOptions, sourcemapOptions, tsconfig, outputNames, fileReplacements, externalDependencies, preserveSymlinks, stylePreprocessorOptions, advancedOptimizations, inlineStyleLanguage, } = options;
|
|
184
184
|
return {
|
|
185
185
|
absWorkingDir: workspaceRoot,
|
|
186
186
|
bundle: true,
|
|
@@ -229,10 +229,15 @@ function createCodeBundleOptions(options, target, sourceFileCache) {
|
|
|
229
229
|
includePaths: stylePreprocessorOptions === null || stylePreprocessorOptions === void 0 ? void 0 : stylePreprocessorOptions.includePaths,
|
|
230
230
|
externalDependencies,
|
|
231
231
|
target,
|
|
232
|
+
inlineStyleLanguage,
|
|
232
233
|
}),
|
|
233
234
|
],
|
|
234
235
|
define: {
|
|
236
|
+
// Only set to false when script optimizations are enabled. It should not be set to true because
|
|
237
|
+
// Angular turns `ngDevMode` into an object for development debugging purposes when not defined
|
|
238
|
+
// which a constant true value would break.
|
|
235
239
|
...(optimizationOptions.scripts ? { 'ngDevMode': 'false' } : undefined),
|
|
240
|
+
// Only AOT mode is supported currently
|
|
236
241
|
'ngJitMode': 'false',
|
|
237
242
|
},
|
|
238
243
|
};
|
|
@@ -25,7 +25,7 @@ exports.default = transformJavaScript;
|
|
|
25
25
|
let linkerPluginCreator;
|
|
26
26
|
async function transformWithBabel({ filename, data, ...options }) {
|
|
27
27
|
var _a, _b;
|
|
28
|
-
const forceAsyncTransformation = (_a = options.forceAsyncTransformation) !== null && _a !== void 0 ? _a : (!/[\\/][_f]?esm2015[\\/]/.test(filename) && /async
|
|
28
|
+
const forceAsyncTransformation = (_a = options.forceAsyncTransformation) !== null && _a !== void 0 ? _a : (!/[\\/][_f]?esm2015[\\/]/.test(filename) && /async(?:\s+function)?\s*\*/.test(data));
|
|
29
29
|
const shouldLink = !options.skipLinker && (await (0, webpack_loader_1.requiresLinking)(filename, data));
|
|
30
30
|
const useInputSourcemap = options.sourcemap &&
|
|
31
31
|
(!!options.thirdPartySourcemaps || !/[\\/]node_modules[\\/]/.test(filename));
|
|
@@ -75,8 +75,8 @@ class JavaScriptTransformer {
|
|
|
75
75
|
let forceAsyncTransformation;
|
|
76
76
|
if (skipLinker && !__classPrivateFieldGet(this, _JavaScriptTransformer_commonOptions, "f").advancedOptimizations) {
|
|
77
77
|
// If the linker is being skipped and no optimizations are needed, only async transformation is left.
|
|
78
|
-
// This checks for async generator functions. All other async transformation is handled by esbuild.
|
|
79
|
-
forceAsyncTransformation = data.includes('async') && /async
|
|
78
|
+
// This checks for async generator functions and class methods. All other async transformation is handled by esbuild.
|
|
79
|
+
forceAsyncTransformation = data.includes('async') && /async(?:\s+function)?\s*\*/.test(data);
|
|
80
80
|
if (!forceAsyncTransformation) {
|
|
81
81
|
return Buffer.from(data, 'utf-8');
|
|
82
82
|
}
|
|
@@ -24,6 +24,7 @@ export declare function normalizeOptions(context: BuilderContext, projectName: s
|
|
|
24
24
|
cacheOptions: import("../../utils/normalize-cache").NormalizedCachedOptions;
|
|
25
25
|
crossOrigin: import("./schema").CrossOrigin | undefined;
|
|
26
26
|
externalDependencies: string[] | undefined;
|
|
27
|
+
inlineStyleLanguage: string;
|
|
27
28
|
poll: number | undefined;
|
|
28
29
|
preserveSymlinks: boolean;
|
|
29
30
|
stylePreprocessorOptions: import("./schema").StylePreprocessorOptions | undefined;
|
|
@@ -122,7 +122,7 @@ async function normalizeOptions(context, projectName, options) {
|
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
// Initial options to keep
|
|
125
|
-
const { baseHref, buildOptimizer, crossOrigin, externalDependencies, poll, preserveSymlinks, stylePreprocessorOptions, subresourceIntegrity, verbose, watch, } = options;
|
|
125
|
+
const { baseHref, buildOptimizer, crossOrigin, externalDependencies, inlineStyleLanguage = 'css', poll, preserveSymlinks, stylePreprocessorOptions, subresourceIntegrity, verbose, watch, } = options;
|
|
126
126
|
// Return all the normalized options
|
|
127
127
|
return {
|
|
128
128
|
advancedOptimizations: buildOptimizer,
|
|
@@ -130,6 +130,7 @@ async function normalizeOptions(context, projectName, options) {
|
|
|
130
130
|
cacheOptions,
|
|
131
131
|
crossOrigin,
|
|
132
132
|
externalDependencies,
|
|
133
|
+
inlineStyleLanguage,
|
|
133
134
|
poll,
|
|
134
135
|
// If not explicitly set, default to the Node.js process argument
|
|
135
136
|
preserveSymlinks: preserveSymlinks !== null && preserveSymlinks !== void 0 ? preserveSymlinks : process.execArgv.includes('--preserve-symlinks'),
|
|
@@ -6,8 +6,10 @@
|
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
8
|
import type { Plugin } from 'esbuild';
|
|
9
|
-
export
|
|
10
|
-
export declare function createSassPlugin(options: {
|
|
9
|
+
export interface SassPluginOptions {
|
|
11
10
|
sourcemap: boolean;
|
|
12
11
|
loadPaths?: string[];
|
|
13
|
-
|
|
12
|
+
inlineComponentData?: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
export declare function shutdownSassWorkerPool(): void;
|
|
15
|
+
export declare function createSassPlugin(options: SassPluginOptions): Plugin;
|
|
@@ -6,8 +6,12 @@
|
|
|
6
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
7
7
|
* found in the LICENSE file at https://angular.io/license
|
|
8
8
|
*/
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
9
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
13
|
exports.createSassPlugin = exports.shutdownSassWorkerPool = void 0;
|
|
14
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
11
15
|
const promises_1 = require("node:fs/promises");
|
|
12
16
|
const node_path_1 = require("node:path");
|
|
13
17
|
const node_url_1 = require("node:url");
|
|
@@ -46,86 +50,95 @@ function createSassPlugin(options) {
|
|
|
46
50
|
}
|
|
47
51
|
return result;
|
|
48
52
|
};
|
|
53
|
+
build.onLoad({ filter: /^angular:styles\/component;s[ac]ss;/, namespace: 'angular:styles/component' }, async (args) => {
|
|
54
|
+
var _a;
|
|
55
|
+
const data = (_a = options.inlineComponentData) === null || _a === void 0 ? void 0 : _a[args.path];
|
|
56
|
+
(0, node_assert_1.default)(data, `component style name should always be found [${args.path}]`);
|
|
57
|
+
const [, language, , filePath] = args.path.split(';', 4);
|
|
58
|
+
const syntax = language === 'sass' ? 'indented' : 'scss';
|
|
59
|
+
return compileString(data, filePath, syntax, options, resolveUrl);
|
|
60
|
+
});
|
|
49
61
|
build.onLoad({ filter: /\.s[ac]ss$/ }, async (args) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
const data = await (0, promises_1.readFile)(args.path, 'utf-8');
|
|
55
|
-
const { css, sourceMap, loadedUrls } = await sassWorkerPool.compileStringAsync(data, {
|
|
56
|
-
url: (0, node_url_1.pathToFileURL)(args.path),
|
|
57
|
-
style: 'expanded',
|
|
58
|
-
loadPaths: options.loadPaths,
|
|
59
|
-
sourceMap: options.sourcemap,
|
|
60
|
-
sourceMapIncludeSources: options.sourcemap,
|
|
61
|
-
quietDeps: true,
|
|
62
|
-
importers: [
|
|
63
|
-
{
|
|
64
|
-
findFileUrl: async (url, { previousResolvedModules }) => {
|
|
65
|
-
const result = await resolveUrl(url, previousResolvedModules);
|
|
66
|
-
// Check for package deep imports
|
|
67
|
-
if (!result.path) {
|
|
68
|
-
const parts = url.split('/');
|
|
69
|
-
const hasScope = parts.length >= 2 && parts[0].startsWith('@');
|
|
70
|
-
const [nameOrScope, nameOrFirstPath, ...pathPart] = parts;
|
|
71
|
-
const packageName = hasScope
|
|
72
|
-
? `${nameOrScope}/${nameOrFirstPath}`
|
|
73
|
-
: nameOrScope;
|
|
74
|
-
const packageResult = await resolveUrl(packageName + '/package.json', previousResolvedModules);
|
|
75
|
-
if (packageResult.path) {
|
|
76
|
-
return (0, node_url_1.pathToFileURL)((0, node_path_1.join)((0, node_path_1.dirname)(packageResult.path), !hasScope ? nameOrFirstPath : '', ...pathPart));
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return result.path ? (0, node_url_1.pathToFileURL)(result.path) : null;
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
logger: {
|
|
84
|
-
warn: (text, { deprecation, span }) => {
|
|
85
|
-
warnings.push({
|
|
86
|
-
text: deprecation ? 'Deprecation' : text,
|
|
87
|
-
location: span && {
|
|
88
|
-
file: span.url && (0, node_url_1.fileURLToPath)(span.url),
|
|
89
|
-
lineText: span.context,
|
|
90
|
-
// Sass line numbers are 0-based while esbuild's are 1-based
|
|
91
|
-
line: span.start.line + 1,
|
|
92
|
-
column: span.start.column,
|
|
93
|
-
},
|
|
94
|
-
notes: deprecation ? [{ text }] : undefined,
|
|
95
|
-
});
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
return {
|
|
100
|
-
loader: 'css',
|
|
101
|
-
contents: sourceMap
|
|
102
|
-
? `${css}\n${sourceMapToUrlComment(sourceMap, (0, node_path_1.dirname)(args.path))}`
|
|
103
|
-
: css,
|
|
104
|
-
watchFiles: loadedUrls.map((url) => (0, node_url_1.fileURLToPath)(url)),
|
|
105
|
-
warnings,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
catch (error) {
|
|
109
|
-
if (isSassException(error)) {
|
|
110
|
-
const file = error.span.url ? (0, node_url_1.fileURLToPath)(error.span.url) : undefined;
|
|
111
|
-
return {
|
|
112
|
-
loader: 'css',
|
|
113
|
-
errors: [
|
|
114
|
-
{
|
|
115
|
-
text: error.message,
|
|
116
|
-
},
|
|
117
|
-
],
|
|
118
|
-
warnings,
|
|
119
|
-
watchFiles: file ? [file] : undefined,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
throw error;
|
|
123
|
-
}
|
|
62
|
+
const data = await (0, promises_1.readFile)(args.path, 'utf-8');
|
|
63
|
+
const syntax = (0, node_path_1.extname)(args.path).toLowerCase() === '.sass' ? 'indented' : 'scss';
|
|
64
|
+
return compileString(data, args.path, syntax, options, resolveUrl);
|
|
124
65
|
});
|
|
125
66
|
},
|
|
126
67
|
};
|
|
127
68
|
}
|
|
128
69
|
exports.createSassPlugin = createSassPlugin;
|
|
70
|
+
async function compileString(data, filePath, syntax, options, resolveUrl) {
|
|
71
|
+
// Lazily load Sass when a Sass file is found
|
|
72
|
+
sassWorkerPool !== null && sassWorkerPool !== void 0 ? sassWorkerPool : (sassWorkerPool = new sass_service_1.SassWorkerImplementation(true));
|
|
73
|
+
const warnings = [];
|
|
74
|
+
try {
|
|
75
|
+
const { css, sourceMap, loadedUrls } = await sassWorkerPool.compileStringAsync(data, {
|
|
76
|
+
url: (0, node_url_1.pathToFileURL)(filePath),
|
|
77
|
+
style: 'expanded',
|
|
78
|
+
syntax,
|
|
79
|
+
loadPaths: options.loadPaths,
|
|
80
|
+
sourceMap: options.sourcemap,
|
|
81
|
+
sourceMapIncludeSources: options.sourcemap,
|
|
82
|
+
quietDeps: true,
|
|
83
|
+
importers: [
|
|
84
|
+
{
|
|
85
|
+
findFileUrl: async (url, { previousResolvedModules }) => {
|
|
86
|
+
const result = await resolveUrl(url, previousResolvedModules);
|
|
87
|
+
// Check for package deep imports
|
|
88
|
+
if (!result.path) {
|
|
89
|
+
const parts = url.split('/');
|
|
90
|
+
const hasScope = parts.length >= 2 && parts[0].startsWith('@');
|
|
91
|
+
const [nameOrScope, nameOrFirstPath, ...pathPart] = parts;
|
|
92
|
+
const packageName = hasScope ? `${nameOrScope}/${nameOrFirstPath}` : nameOrScope;
|
|
93
|
+
const packageResult = await resolveUrl(packageName + '/package.json', previousResolvedModules);
|
|
94
|
+
if (packageResult.path) {
|
|
95
|
+
return (0, node_url_1.pathToFileURL)((0, node_path_1.join)((0, node_path_1.dirname)(packageResult.path), !hasScope ? nameOrFirstPath : '', ...pathPart));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return result.path ? (0, node_url_1.pathToFileURL)(result.path) : null;
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
logger: {
|
|
103
|
+
warn: (text, { deprecation, span }) => {
|
|
104
|
+
warnings.push({
|
|
105
|
+
text: deprecation ? 'Deprecation' : text,
|
|
106
|
+
location: span && {
|
|
107
|
+
file: span.url && (0, node_url_1.fileURLToPath)(span.url),
|
|
108
|
+
lineText: span.context,
|
|
109
|
+
// Sass line numbers are 0-based while esbuild's are 1-based
|
|
110
|
+
line: span.start.line + 1,
|
|
111
|
+
column: span.start.column,
|
|
112
|
+
},
|
|
113
|
+
notes: deprecation ? [{ text }] : undefined,
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
return {
|
|
119
|
+
loader: 'css',
|
|
120
|
+
contents: sourceMap ? `${css}\n${sourceMapToUrlComment(sourceMap, (0, node_path_1.dirname)(filePath))}` : css,
|
|
121
|
+
watchFiles: loadedUrls.map((url) => (0, node_url_1.fileURLToPath)(url)),
|
|
122
|
+
warnings,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
if (isSassException(error)) {
|
|
127
|
+
const file = error.span.url ? (0, node_url_1.fileURLToPath)(error.span.url) : undefined;
|
|
128
|
+
return {
|
|
129
|
+
loader: 'css',
|
|
130
|
+
errors: [
|
|
131
|
+
{
|
|
132
|
+
text: error.message,
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
warnings,
|
|
136
|
+
watchFiles: file ? [file] : undefined,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
129
142
|
function sourceMapToUrlComment(sourceMap, root) {
|
|
130
143
|
// Remove `file` protocol from all sourcemap sources and adjust to be relative to the input file.
|
|
131
144
|
// This allows esbuild to correctly process the paths.
|
|
@@ -19,36 +19,24 @@ export interface BundleStylesheetOptions {
|
|
|
19
19
|
externalDependencies?: string[];
|
|
20
20
|
target: string[];
|
|
21
21
|
}
|
|
22
|
-
export declare function createStylesheetBundleOptions(options: BundleStylesheetOptions): BuildOptions & {
|
|
22
|
+
export declare function createStylesheetBundleOptions(options: BundleStylesheetOptions, inlineComponentData?: Record<string, string>): BuildOptions & {
|
|
23
23
|
plugins: NonNullable<BuildOptions['plugins']>;
|
|
24
24
|
};
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* Bundles a component stylesheet. The stylesheet can be either an inline stylesheet that
|
|
27
|
+
* is contained within the Component's metadata definition or an external file referenced
|
|
28
|
+
* from the Component's metadata definition.
|
|
27
29
|
*
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
30
|
-
* @
|
|
30
|
+
* @param identifier A unique string identifier for the component stylesheet.
|
|
31
|
+
* @param language The language of the stylesheet such as `css` or `scss`.
|
|
32
|
+
* @param data The string content of the stylesheet.
|
|
33
|
+
* @param filename The filename representing the source of the stylesheet content.
|
|
34
|
+
* @param inline If true, the stylesheet source is within the component metadata;
|
|
35
|
+
* if false, the source is a stylesheet file.
|
|
36
|
+
* @param options An object containing the stylesheet bundling options.
|
|
37
|
+
* @returns An object containing the output of the bundling operation.
|
|
31
38
|
*/
|
|
32
|
-
export declare function
|
|
33
|
-
errors: import("esbuild").Message[];
|
|
34
|
-
warnings: import("esbuild").Message[];
|
|
35
|
-
contents: string;
|
|
36
|
-
map: string | undefined;
|
|
37
|
-
path: string | undefined;
|
|
38
|
-
resourceFiles: OutputFile[];
|
|
39
|
-
}>;
|
|
40
|
-
/**
|
|
41
|
-
* Bundle stylesheet text data from a string.
|
|
42
|
-
*
|
|
43
|
-
* @param data The string content of a stylesheet to bundle.
|
|
44
|
-
* @param dataOptions The options to use to resolve references and name output of the stylesheet data.
|
|
45
|
-
* @param bundleOptions The stylesheet bundling options to use.
|
|
46
|
-
* @returns The bundle result object.
|
|
47
|
-
*/
|
|
48
|
-
export declare function bundleStylesheetText(data: string, dataOptions: {
|
|
49
|
-
resolvePath: string;
|
|
50
|
-
virtualName?: string;
|
|
51
|
-
}, bundleOptions: BundleStylesheetOptions): Promise<{
|
|
39
|
+
export declare function bundleComponentStylesheet(identifier: string, language: string, data: string, filename: string, inline: boolean, options: BundleStylesheetOptions): Promise<{
|
|
52
40
|
errors: import("esbuild").Message[];
|
|
53
41
|
warnings: import("esbuild").Message[];
|
|
54
42
|
contents: string;
|
|
@@ -30,12 +30,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
30
30
|
return result;
|
|
31
31
|
};
|
|
32
32
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
-
exports.
|
|
34
|
-
const path = __importStar(require("path"));
|
|
33
|
+
exports.bundleComponentStylesheet = exports.createStylesheetBundleOptions = void 0;
|
|
34
|
+
const path = __importStar(require("node:path"));
|
|
35
35
|
const css_resource_plugin_1 = require("./css-resource-plugin");
|
|
36
36
|
const esbuild_1 = require("./esbuild");
|
|
37
37
|
const sass_plugin_1 = require("./sass-plugin");
|
|
38
|
-
function createStylesheetBundleOptions(options) {
|
|
38
|
+
function createStylesheetBundleOptions(options, inlineComponentData) {
|
|
39
39
|
var _a, _b;
|
|
40
40
|
return {
|
|
41
41
|
absWorkingDir: options.workspaceRoot,
|
|
@@ -54,18 +54,65 @@ function createStylesheetBundleOptions(options) {
|
|
|
54
54
|
conditions: ['style', 'sass'],
|
|
55
55
|
mainFields: ['style', 'sass'],
|
|
56
56
|
plugins: [
|
|
57
|
-
(0, sass_plugin_1.createSassPlugin)({
|
|
57
|
+
(0, sass_plugin_1.createSassPlugin)({
|
|
58
|
+
sourcemap: !!options.sourcemap,
|
|
59
|
+
loadPaths: options.includePaths,
|
|
60
|
+
inlineComponentData,
|
|
61
|
+
}),
|
|
58
62
|
(0, css_resource_plugin_1.createCssResourcePlugin)(),
|
|
59
63
|
],
|
|
60
64
|
};
|
|
61
65
|
}
|
|
62
66
|
exports.createStylesheetBundleOptions = createStylesheetBundleOptions;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Bundles a component stylesheet. The stylesheet can be either an inline stylesheet that
|
|
69
|
+
* is contained within the Component's metadata definition or an external file referenced
|
|
70
|
+
* from the Component's metadata definition.
|
|
71
|
+
*
|
|
72
|
+
* @param identifier A unique string identifier for the component stylesheet.
|
|
73
|
+
* @param language The language of the stylesheet such as `css` or `scss`.
|
|
74
|
+
* @param data The string content of the stylesheet.
|
|
75
|
+
* @param filename The filename representing the source of the stylesheet content.
|
|
76
|
+
* @param inline If true, the stylesheet source is within the component metadata;
|
|
77
|
+
* if false, the source is a stylesheet file.
|
|
78
|
+
* @param options An object containing the stylesheet bundling options.
|
|
79
|
+
* @returns An object containing the output of the bundling operation.
|
|
80
|
+
*/
|
|
81
|
+
async function bundleComponentStylesheet(identifier, language, data, filename, inline, options) {
|
|
82
|
+
const namespace = 'angular:styles/component';
|
|
83
|
+
const entry = [namespace, language, identifier, filename].join(';');
|
|
84
|
+
const buildOptions = createStylesheetBundleOptions(options, { [entry]: data });
|
|
85
|
+
buildOptions.entryPoints = [entry];
|
|
86
|
+
buildOptions.plugins.push({
|
|
87
|
+
name: 'angular-component-styles',
|
|
88
|
+
setup(build) {
|
|
89
|
+
build.onResolve({ filter: /^angular:styles\/component;/ }, (args) => {
|
|
90
|
+
if (args.kind !== 'entry-point') {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
if (inline) {
|
|
94
|
+
return {
|
|
95
|
+
path: args.path,
|
|
96
|
+
namespace,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
return {
|
|
101
|
+
path: filename,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
build.onLoad({ filter: /^angular:styles\/component;css;/, namespace }, async () => {
|
|
106
|
+
return {
|
|
107
|
+
contents: data,
|
|
108
|
+
loader: 'css',
|
|
109
|
+
resolveDir: path.dirname(filename),
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
},
|
|
68
113
|
});
|
|
114
|
+
// Execute esbuild
|
|
115
|
+
const result = await (0, esbuild_1.bundle)(options.workspaceRoot, buildOptions);
|
|
69
116
|
// Extract the result of the bundling from the output files
|
|
70
117
|
let contents = '';
|
|
71
118
|
let map;
|
|
@@ -96,34 +143,4 @@ async function bundleStylesheet(entry, options) {
|
|
|
96
143
|
resourceFiles,
|
|
97
144
|
};
|
|
98
145
|
}
|
|
99
|
-
|
|
100
|
-
* Bundle a stylesheet that exists as a file on the filesystem.
|
|
101
|
-
*
|
|
102
|
-
* @param filename The path to the file to bundle.
|
|
103
|
-
* @param options The stylesheet bundling options to use.
|
|
104
|
-
* @returns The bundle result object.
|
|
105
|
-
*/
|
|
106
|
-
async function bundleStylesheetFile(filename, options) {
|
|
107
|
-
return bundleStylesheet({ entryPoints: [filename] }, options);
|
|
108
|
-
}
|
|
109
|
-
exports.bundleStylesheetFile = bundleStylesheetFile;
|
|
110
|
-
/**
|
|
111
|
-
* Bundle stylesheet text data from a string.
|
|
112
|
-
*
|
|
113
|
-
* @param data The string content of a stylesheet to bundle.
|
|
114
|
-
* @param dataOptions The options to use to resolve references and name output of the stylesheet data.
|
|
115
|
-
* @param bundleOptions The stylesheet bundling options to use.
|
|
116
|
-
* @returns The bundle result object.
|
|
117
|
-
*/
|
|
118
|
-
async function bundleStylesheetText(data, dataOptions, bundleOptions) {
|
|
119
|
-
const result = bundleStylesheet({
|
|
120
|
-
stdin: {
|
|
121
|
-
contents: data,
|
|
122
|
-
sourcefile: dataOptions.virtualName,
|
|
123
|
-
resolveDir: dataOptions.resolvePath,
|
|
124
|
-
loader: 'css',
|
|
125
|
-
},
|
|
126
|
-
}, bundleOptions);
|
|
127
|
-
return result;
|
|
128
|
-
}
|
|
129
|
-
exports.bundleStylesheetText = bundleStylesheetText;
|
|
146
|
+
exports.bundleComponentStylesheet = bundleComponentStylesheet;
|
|
File without changes
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
// import type ng from '@angular/compiler-cli';
|
|
10
|
+
// import { Worker } from 'node:worker_threads';
|
|
11
|
+
// import { AngularHostOptions } from './angular-host';
|
|
12
|
+
// interface Message {
|
|
13
|
+
// id: number;
|
|
14
|
+
// }
|
|
15
|
+
// interface InitializeRequest extends Message {
|
|
16
|
+
// tsconfig: string;
|
|
17
|
+
// tsCallbackId: number;
|
|
18
|
+
// tcoCallbackId?: number;
|
|
19
|
+
// }
|
|
20
|
+
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
// type ResponseCallback = (...args: any[]) => void;
|
|
22
|
+
// let callbackIds = 0;
|
|
23
|
+
// export class WorkerAngularCompilation {
|
|
24
|
+
// #worker: Worker;
|
|
25
|
+
// #callbacks = new Map<number, ResponseCallback>();
|
|
26
|
+
// constructor() {
|
|
27
|
+
// this.#worker = new Worker(require.resolve('./compilation-worker'));
|
|
28
|
+
// }
|
|
29
|
+
// async initialize(
|
|
30
|
+
// tsconfig: string,
|
|
31
|
+
// hostOptions: AngularHostOptions,
|
|
32
|
+
// transformCompilerOptions?: (compilerOptions: ng.CompilerOptions) => ng.CompilerOptions,
|
|
33
|
+
// ): Promise<{ compilerOptions: ng.CompilerOptions }> {
|
|
34
|
+
// const request: InitializeRequest = {
|
|
35
|
+
// id: ++callbackIds,
|
|
36
|
+
// tsconfig,
|
|
37
|
+
// tsCallbackId: ++callbackIds,
|
|
38
|
+
// };
|
|
39
|
+
// this.#callbacks.set(request.tsCallbackId, () => {
|
|
40
|
+
// hostOptions.transformStylesheet();
|
|
41
|
+
// });
|
|
42
|
+
// if (transformCompilerOptions) {
|
|
43
|
+
// request.tcoCallbackId = ++callbackIds;
|
|
44
|
+
// this.#callbacks.set(request.tcoCallbackId, (id: number, compilerOptions) => {
|
|
45
|
+
// try {
|
|
46
|
+
// transformCompilerOptions(compilerOptions);
|
|
47
|
+
// } catch (e) {
|
|
48
|
+
// }
|
|
49
|
+
// });
|
|
50
|
+
// }
|
|
51
|
+
// const result = new Promise<{ compilerOptions: ng.CompilerOptions }>((resolve, reject) => {
|
|
52
|
+
// this.#callbacks.set(request.id, () => {
|
|
53
|
+
// resolve({});
|
|
54
|
+
// });
|
|
55
|
+
// });
|
|
56
|
+
// this.#worker.postMessage(request);
|
|
57
|
+
// return result;
|
|
58
|
+
// }
|
|
59
|
+
// }
|
|
@@ -149,7 +149,9 @@ function execute(options, context, transforms = {}) {
|
|
|
149
149
|
});
|
|
150
150
|
const karmaStart = karmaServer.start();
|
|
151
151
|
// Cleanup, signal Karma to exit.
|
|
152
|
-
return () =>
|
|
152
|
+
return () => {
|
|
153
|
+
void karmaStart.then(() => karmaServer.stop());
|
|
154
|
+
};
|
|
153
155
|
})), (0, operators_1.defaultIfEmpty)({ success: false }));
|
|
154
156
|
}
|
|
155
157
|
exports.execute = execute;
|
|
@@ -52,7 +52,7 @@ function emittedFilesToInlineOptions(emittedFiles, scriptsEntryPointName, emitte
|
|
|
52
52
|
code: fs.readFileSync(originalPath, 'utf8'),
|
|
53
53
|
outputPath,
|
|
54
54
|
missingTranslation,
|
|
55
|
-
setLocale: emittedFile.name === 'main'
|
|
55
|
+
setLocale: emittedFile.name === 'main',
|
|
56
56
|
};
|
|
57
57
|
originalFiles.push(originalPath);
|
|
58
58
|
try {
|
|
@@ -211,7 +211,7 @@ async function inlineLocalesDirect(ast, options) {
|
|
|
211
211
|
}
|
|
212
212
|
let outputSource = content;
|
|
213
213
|
if (options.setLocale) {
|
|
214
|
-
const setLocaleText = `
|
|
214
|
+
const setLocaleText = `globalThis.$localize=Object.assign(globalThis.$localize || {},{locale:"${locale}"});\n`;
|
|
215
215
|
// If locale data is provided, load it and prepend to file
|
|
216
216
|
let localeDataSource;
|
|
217
217
|
const localeDataPath = i18n.locales[locale] && i18n.locales[locale].dataPath;
|
|
@@ -24,8 +24,6 @@ class StylesWebpackPlugin {
|
|
|
24
24
|
}
|
|
25
25
|
apply(compiler) {
|
|
26
26
|
const { entryPoints, preserveSymlinks, root } = this.options;
|
|
27
|
-
const webpackOptions = compiler.options;
|
|
28
|
-
const entry = typeof webpackOptions.entry === 'function' ? webpackOptions.entry() : webpackOptions.entry;
|
|
29
27
|
const resolver = compiler.resolverFactory.get('global-styles', {
|
|
30
28
|
conditionNames: ['sass', 'less', 'style'],
|
|
31
29
|
mainFields: ['sass', 'less', 'style', 'main', '...'],
|
|
@@ -36,33 +34,37 @@ class StylesWebpackPlugin {
|
|
|
36
34
|
symlinks: !preserveSymlinks,
|
|
37
35
|
fileSystem: compiler.inputFileSystem,
|
|
38
36
|
});
|
|
39
|
-
webpackOptions
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
for (const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
37
|
+
const webpackOptions = compiler.options;
|
|
38
|
+
compiler.hooks.environment.tap(PLUGIN_NAME, () => {
|
|
39
|
+
const entry = typeof webpackOptions.entry === 'function' ? webpackOptions.entry() : webpackOptions.entry;
|
|
40
|
+
webpackOptions.entry = async () => {
|
|
41
|
+
var _a, _b;
|
|
42
|
+
var _c;
|
|
43
|
+
const entrypoints = await entry;
|
|
44
|
+
for (const [bundleName, paths] of Object.entries(entryPoints)) {
|
|
45
|
+
(_a = entrypoints[bundleName]) !== null && _a !== void 0 ? _a : (entrypoints[bundleName] = {});
|
|
46
|
+
const entryImport = ((_b = (_c = entrypoints[bundleName]).import) !== null && _b !== void 0 ? _b : (_c.import = []));
|
|
47
|
+
for (const path of paths) {
|
|
48
|
+
try {
|
|
49
|
+
const resolvedPath = resolver.resolveSync({}, root, path);
|
|
50
|
+
if (resolvedPath) {
|
|
51
|
+
entryImport.push(`${resolvedPath}?ngGlobalStyle`);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
(0, assert_1.default)(this.compilation, 'Compilation cannot be undefined.');
|
|
55
|
+
(0, webpack_diagnostics_1.addError)(this.compilation, `Cannot resolve '${path}'.`);
|
|
56
|
+
}
|
|
51
57
|
}
|
|
52
|
-
|
|
58
|
+
catch (error) {
|
|
53
59
|
(0, assert_1.default)(this.compilation, 'Compilation cannot be undefined.');
|
|
54
|
-
(0,
|
|
60
|
+
(0, error_1.assertIsError)(error);
|
|
61
|
+
(0, webpack_diagnostics_1.addError)(this.compilation, error.message);
|
|
55
62
|
}
|
|
56
63
|
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
(0, assert_1.default)(this.compilation, 'Compilation cannot be undefined.');
|
|
59
|
-
(0, error_1.assertIsError)(error);
|
|
60
|
-
(0, webpack_diagnostics_1.addError)(this.compilation, error.message);
|
|
61
|
-
}
|
|
62
64
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
};
|
|
65
|
+
return entrypoints;
|
|
66
|
+
};
|
|
67
|
+
});
|
|
66
68
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
67
69
|
this.compilation = compilation;
|
|
68
70
|
});
|