MCPcopy Create free account
hub / github.com/rolldown/tsdown / processWithPostCSS

Function processWithPostCSS

packages/css/src/postcss.ts:67–140  ·  view source on GitHub ↗
(
  code: string,
  filename: string,
  postcssOption: PostCSSOptions | undefined,
  cwd: string,
  injectImport?: boolean,
  modulesOptions?: PostCSSModulesOptions,
  sourceMap?: boolean,
)

Source from the content-addressed store, hash-verified

65}
66
67export async function processWithPostCSS(
68 code: string,
69 filename: string,
70 postcssOption: PostCSSOptions | undefined,
71 cwd: string,
72 injectImport?: boolean,
73 modulesOptions?: PostCSSModulesOptions,
74 sourceMap?: boolean,
75): Promise<PostCSSProcessResult> {
76 const config = await resolvePostCSSConfig(postcssOption, cwd)
77
78 const plugins: any[] = []
79
80 let modules: Record<string, string> | undefined
81
82 if (modulesOptions?.isModule) {
83 const postcssModules: any = await importWithError('postcss-modules')
84 const {
85 localsConvention: _,
86 getJSON: userGetJSON,
87 ...rest
88 } = modulesOptions.config ?? {}
89 plugins.push(
90 (postcssModules.default ?? postcssModules)({
91 ...rest,
92 getJSON(
93 cssFileName: string,
94 json: Record<string, string>,
95 outputFileName: string,
96 ) {
97 modules = json
98 userGetJSON?.(cssFileName, json, outputFileName)
99 },
100 }),
101 )
102 }
103
104 if (injectImport) {
105 const postcssImport: any = await importWithError('postcss-import')
106 plugins.push((postcssImport.default ?? postcssImport)())
107 }
108
109 if (config) {
110 plugins.push(...config.plugins)
111 }
112
113 if (!plugins.length && !config?.options.parser) {
114 return { code, deps: [] }
115 }
116
117 const postcss = await importWithError<typeof import('postcss')>('postcss')
118 const result = await postcss.default(plugins).process(code, {
119 ...config?.options,
120 from: filename,
121 to: filename,
122 map: sourceMap
123 ? { inline: false, annotation: false, prev: false }
124 : undefined,

Callers

nothing calls this directly

Calls 2

importWithErrorFunction · 0.90
resolvePostCSSConfigFunction · 0.85

Tested by

no test coverage detected