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

Function process

packages/vite/src/node/plugins/css.ts:2632–2707  ·  view source on GitHub ↗
(environment, source, root, options, resolvers)

Source from the content-addressed store, hash-verified

2630 await worker?.stop()
2631 },
2632 async process(environment, source, root, options, resolvers) {
2633 let sassPackage = loadSassPackage(root, failedSassEmbedded ?? false)
2634 if (failedSassEmbedded === undefined) {
2635 failedSassEmbedded = false
2636 try {
2637 await import(sassPackage.path)
2638 } catch (e) {
2639 if (/sass-embedded-[a-z0-9]+-[a-z0-9]+/i.test(e.message)) {
2640 failedSassEmbedded = true
2641 sassPackage = loadSassPackage(root, failedSassEmbedded)
2642 }
2643 }
2644 }
2645
2646 worker ??= makeScssWorker(environment, resolvers, maxWorkers)
2647
2648 const { content: data, map: additionalMap } = await getSource(
2649 source,
2650 options.filename,
2651 options.additionalData,
2652 options.enableSourcemap,
2653 )
2654
2655 const optionsWithoutAdditionalData = {
2656 ...options,
2657 additionalData: undefined,
2658 }
2659 try {
2660 const result = await worker.run(
2661 pathToFileURL(sassPackage.path).href,
2662 data,
2663 optionsWithoutAdditionalData,
2664 )
2665 const deps = result.stats.includedFiles.map((f) => cleanScssBugUrl(f))
2666 const map: ExistingRawSourceMap | undefined = result.map
2667 ? JSON.parse(result.map.toString())
2668 : undefined
2669
2670 if (map) {
2671 // Note: the real `Sourcemap#sources` maybe `null`, but rollup typing is not handle it.
2672 map.sources = map.sources!.map((url) =>
2673 url!.startsWith('file://')
2674 ? normalizePath(fileURLToPath(url!))
2675 : url,
2676 )
2677 }
2678
2679 return {
2680 code: result.css.toString(),
2681 map,
2682 additionalMap,
2683 deps,
2684 }
2685 } catch (e) {
2686 if (!normalizedErrors.has(e)) {
2687 // normalize SASS error
2688 e.message = `[sass] ${e.message}`
2689 e.id = e.file

Callers

nothing calls this directly

Calls 13

normalizePathFunction · 0.90
loadSassPackageFunction · 0.85
makeScssWorkerFunction · 0.85
getSourceFunction · 0.85
cleanScssBugUrlFunction · 0.85
loadPreprocessorPathFunction · 0.85
makeLessWorkerFunction · 0.85
makeStylWorkerFunction · 0.85
formatStylusSourceMapFunction · 0.85
parseMethod · 0.80
hasMethod · 0.80
addMethod · 0.80

Tested by

no test coverage detected