( config: d.ValidatedConfig, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx, id: string, cmp?: d.ComponentCompilerMeta, )
| 72 | }; |
| 73 | |
| 74 | export 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 ?? []) { |
no test coverage detected