MCPcopy Index your code
hub / github.com/angular/angular-cli / augmentHostWithResources

Function augmentHostWithResources

packages/ngtools/webpack/src/ivy/host.ts:17–74  ·  view source on GitHub ↗
(
  host: ts.CompilerHost,
  resourceLoader: WebpackResourceLoader,
  options: {
    directTemplateLoading?: boolean;
    inlineStyleFileExtension?: string;
  } = {},
)

Source from the content-addressed store, hash-verified

15import { normalizePath } from './paths';
16
17export function augmentHostWithResources(
18 host: ts.CompilerHost,
19 resourceLoader: WebpackResourceLoader,
20 options: {
21 directTemplateLoading?: boolean;
22 inlineStyleFileExtension?: string;
23 } = {},
24): void {
25 const resourceHost = host as CompilerHost;
26
27 resourceHost.readResource = function (fileName: string) {
28 const filePath = normalizePath(fileName);
29
30 if (
31 options.directTemplateLoading &&
32 (filePath.endsWith('.html') || filePath.endsWith('.svg'))
33 ) {
34 const content = this.readFile(filePath);
35 if (content === undefined) {
36 throw new Error('Unable to locate component resource: ' + fileName);
37 }
38
39 resourceLoader.setAffectedResources(filePath, [filePath]);
40
41 return Promise.resolve(content);
42 } else {
43 return resourceLoader.get(filePath);
44 }
45 };
46
47 resourceHost.resourceNameToFileName = function (resourceName: string, containingFile: string) {
48 return path.join(path.dirname(containingFile), resourceName);
49 };
50
51 resourceHost.getModifiedResourceFiles = function () {
52 return resourceLoader.getModifiedResourceFiles();
53 };
54
55 resourceHost.transformResource = async function (data, context) {
56 // Only inline style resources are supported currently
57 if (context.resourceFile || context.type !== 'style') {
58 return null;
59 }
60
61 if (options.inlineStyleFileExtension) {
62 const content = await resourceLoader.process(
63 data,
64 options.inlineStyleFileExtension,
65 context.type,
66 context.containingFile,
67 );
68
69 return { content };
70 }
71
72 return null;
73 };
74}

Callers 1

setupCompilationMethod · 0.90

Calls 7

normalizePathFunction · 0.90
setAffectedResourcesMethod · 0.80
resolveMethod · 0.80
readFileMethod · 0.65
getMethod · 0.65
processMethod · 0.45

Tested by

no test coverage detected