MCPcopy Index your code
hub / github.com/stenciljs/core / runPluginTransforms

Function runPluginTransforms

src/compiler/plugin/plugin.ts:74–210  ·  view source on GitHub ↗
(
  config: d.ValidatedConfig,
  compilerCtx: d.CompilerCtx,
  buildCtx: d.BuildCtx,
  id: string,
  cmp?: d.ComponentCompilerMeta,
)

Source from the content-addressed store, hash-verified

72};
73
74export const runPluginTransforms = async (
75 config: d.ValidatedConfig,
76 compilerCtx: d.CompilerCtx,
77 buildCtx: d.BuildCtx,
78 id: string,
79 cmp?: d.ComponentCompilerMeta,
80): Promise<PluginTransformResults | null> => {
81 const pluginCtx: PluginCtx = {
82 config: config,
83 sys: config.sys,
84 fs: compilerCtx.fs,
85 cache: compilerCtx.cache,
86 diagnostics: [],
87 };
88
89 const resolvedId = await runPluginResolveId(pluginCtx, id);
90 const sourceText = await runPluginLoad(pluginCtx, resolvedId);
91 if (!isString(sourceText)) {
92 const diagnostic = buildError(buildCtx.diagnostics);
93 diagnostic.header = `Unable to find "${basename(id)}"`;
94 diagnostic.messageText = `The file "${relative(config.rootDir, id)}" was unable to load.`;
95 return null;
96 }
97
98 const transformResults = {
99 code: sourceText,
100 id: id,
101 dependencies: [] as string[],
102 } satisfies PluginTransformResults;
103
104 const isRawCssFile = transformResults.id.toLowerCase().endsWith('.css');
105 const shouldParseCssDocs = cmp != null && config.outputTargets.some(isOutputTargetDocs);
106
107 if (isRawCssFile) {
108 // concat all css @imports into one file
109 // when the entry file is a .css file (not .scss)
110 // do this BEFORE transformations on css files
111 if (shouldParseCssDocs && cmp != null) {
112 cmp.styleDocs = cmp.styleDocs || [];
113 const cssParseResults = await parseCssImports(
114 config,
115 compilerCtx,
116 buildCtx,
117 id,
118 id,
119 transformResults.code,
120 cmp.styleDocs,
121 );
122 transformResults.code = cssParseResults.styleText;
123 transformResults.dependencies = cssParseResults.imports;
124 } else {
125 const cssParseResults = await parseCssImports(config, compilerCtx, buildCtx, id, id, transformResults.code);
126 transformResults.code = cssParseResults.styleText;
127 transformResults.dependencies = cssParseResults.imports;
128 }
129 }
130
131 for (const plugin of pluginCtx.config?.plugins ?? []) {

Callers 1

buildGlobalStylesFunction · 0.90

Calls 11

parseCssImportsFunction · 0.90
runPluginResolveIdFunction · 0.85
runPluginLoadFunction · 0.85
buildErrorFunction · 0.85
relativeFunction · 0.85
isFunctionFunction · 0.85
getDependencySubsetFunction · 0.85
catchErrorFunction · 0.85
transformMethod · 0.80
pushMethod · 0.80
isStringFunction · 0.50

Tested by

no test coverage detected