MCPcopy
hub / github.com/vitejs/vite / stylProcessor

Function stylProcessor

packages/vite/src/node/plugins/css.ts:3048–3101  ·  view source on GitHub ↗
(
  maxWorkers: number | undefined,
)

Source from the content-addressed store, hash-verified

3046}
3047
3048const stylProcessor = (
3049 maxWorkers: number | undefined,
3050): StylePreprocessor<StylusStylePreprocessorInternalOptions> => {
3051 let worker: ReturnType<typeof makeStylWorker> | undefined
3052
3053 return {
3054 close() {
3055 worker?.stop()
3056 },
3057 async process(_environment, source, root, options, _resolvers) {
3058 const stylusPath = loadPreprocessorPath(PreprocessLang.stylus, root)
3059 worker ??= makeStylWorker(maxWorkers)
3060
3061 // Get source with preprocessor options.additionalData. Make sure a new line separator
3062 // is added to avoid any render error, as added stylus content may not have semi-colon separators
3063 const { content, map: additionalMap } = await getSource(
3064 source,
3065 options.filename,
3066 options.additionalData,
3067 options.enableSourcemap,
3068 '\n',
3069 )
3070 // Get preprocessor options.imports dependencies as stylus
3071 // does not return them with its builtin `.deps()` method
3072 const importsDeps = (options.imports ?? []).map((dep: string) =>
3073 path.resolve(dep),
3074 )
3075 const optionsWithoutAdditionalData = {
3076 ...options,
3077 additionalData: undefined,
3078 }
3079 try {
3080 const { code, map, deps } = await worker.run(
3081 pathToFileURL(stylusPath).href,
3082 content,
3083 root,
3084 optionsWithoutAdditionalData,
3085 )
3086 return {
3087 code,
3088 map: formatStylusSourceMap(map, root),
3089 additionalMap,
3090 // Concat imports deps with computed deps
3091 deps: [...deps, ...importsDeps],
3092 }
3093 } catch (e) {
3094 const wrapped = new Error(`[stylus] ${e.message}`)
3095 wrapped.name = e.name
3096 wrapped.stack = e.stack
3097 return { code: '', error: wrapped, deps: [] }
3098 }
3099 },
3100 }
3101}
3102
3103function formatStylusSourceMap(
3104 mapBefore: ExistingRawSourceMap | undefined,

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected