mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-25 00:31:36 +08:00
build: add return types for component stylesheet bundler
This commit is contained in:
parent
170bb19074
commit
bc43f9567c
@ -21,6 +21,11 @@ import {
|
|||||||
createStylesheetBundleOptions,
|
createStylesheetBundleOptions,
|
||||||
} from '../stylesheets/bundle-options';
|
} from '../stylesheets/bundle-options';
|
||||||
|
|
||||||
|
export type ComponentStylesheetResult = BundleContextResult & {
|
||||||
|
contents: string;
|
||||||
|
referencedFiles: Set<string> | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bundles component stylesheets. A stylesheet can be either an inline stylesheet that
|
* Bundles component stylesheets. A stylesheet can be either an inline stylesheet that
|
||||||
* is contained within the Component's metadata definition or an external file referenced
|
* is contained within the Component's metadata definition or an external file referenced
|
||||||
@ -48,7 +53,11 @@ export class ComponentStylesheetBundler {
|
|||||||
* @param direct If true, the output will be used directly by the builder; false if used inside the compiler plugin.
|
* @param direct If true, the output will be used directly by the builder; false if used inside the compiler plugin.
|
||||||
* @returns A component bundle result object.
|
* @returns A component bundle result object.
|
||||||
*/
|
*/
|
||||||
async bundleFile(entry: string, externalId?: string | boolean, direct?: boolean) {
|
async bundleFile(
|
||||||
|
entry: string,
|
||||||
|
externalId?: string | boolean,
|
||||||
|
direct?: boolean,
|
||||||
|
): Promise<ComponentStylesheetResult> {
|
||||||
const bundlerContext = await this.#fileContexts.getOrCreate(entry, () => {
|
const bundlerContext = await this.#fileContexts.getOrCreate(entry, () => {
|
||||||
return new BundlerContext(this.options.workspaceRoot, this.incremental, (loadCache) => {
|
return new BundlerContext(this.options.workspaceRoot, this.incremental, (loadCache) => {
|
||||||
const buildOptions = createStylesheetBundleOptions(this.options, loadCache);
|
const buildOptions = createStylesheetBundleOptions(this.options, loadCache);
|
||||||
@ -82,7 +91,7 @@ export class ComponentStylesheetBundler {
|
|||||||
filename: string,
|
filename: string,
|
||||||
language = this.defaultInlineLanguage,
|
language = this.defaultInlineLanguage,
|
||||||
externalId?: string,
|
externalId?: string,
|
||||||
) {
|
): Promise<ComponentStylesheetResult> {
|
||||||
// Use a hash of the inline stylesheet content to ensure a consistent identifier. External stylesheets will resolve
|
// Use a hash of the inline stylesheet content to ensure a consistent identifier. External stylesheets will resolve
|
||||||
// to the actual stylesheet file path.
|
// to the actual stylesheet file path.
|
||||||
// TODO: Consider xxhash instead for hashing
|
// TODO: Consider xxhash instead for hashing
|
||||||
@ -191,13 +200,13 @@ export class ComponentStylesheetBundler {
|
|||||||
referencedFiles: Set<string> | undefined,
|
referencedFiles: Set<string> | undefined,
|
||||||
external: boolean,
|
external: boolean,
|
||||||
direct: boolean,
|
direct: boolean,
|
||||||
) {
|
): ComponentStylesheetResult {
|
||||||
let contents = '';
|
let contents = '';
|
||||||
const outputFiles: BuildOutputFile[] = [];
|
const outputFiles: BuildOutputFile[] = [];
|
||||||
|
|
||||||
const { errors, warnings } = result;
|
const { errors, warnings } = result;
|
||||||
if (errors) {
|
if (errors) {
|
||||||
return { errors, warnings, referencedFiles };
|
return { errors, warnings, referencedFiles, contents: '' };
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const outputFile of result.outputFiles) {
|
for (const outputFile of result.outputFiles) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user