| 3121 | // #endregion |
| 3122 | |
| 3123 | async function getSource( |
| 3124 | source: string, |
| 3125 | filename: string, |
| 3126 | additionalData: PreprocessorAdditionalData | undefined, |
| 3127 | enableSourcemap: boolean, |
| 3128 | sep: string = '', |
| 3129 | ): Promise<{ content: string; map?: ExistingRawSourceMap }> { |
| 3130 | if (!additionalData) return { content: source } |
| 3131 | |
| 3132 | if (typeof additionalData === 'function') { |
| 3133 | const newContent = await additionalData(source, filename) |
| 3134 | if (typeof newContent === 'string') { |
| 3135 | return { content: newContent } |
| 3136 | } |
| 3137 | return newContent |
| 3138 | } |
| 3139 | |
| 3140 | if (!enableSourcemap) { |
| 3141 | return { content: additionalData + sep + source } |
| 3142 | } |
| 3143 | |
| 3144 | const ms = new MagicString(source) |
| 3145 | ms.appendLeft(0, sep) |
| 3146 | ms.appendLeft(0, additionalData) |
| 3147 | |
| 3148 | const map = ms.generateMap({ hires: 'boundary' }) |
| 3149 | map.file = filename |
| 3150 | map.sources = [filename] |
| 3151 | |
| 3152 | return { |
| 3153 | content: ms.toString(), |
| 3154 | map, |
| 3155 | } |
| 3156 | } |
| 3157 | |
| 3158 | const createPreprocessorWorkerController = (maxWorkers: number | undefined) => { |
| 3159 | const scss = scssProcessor(maxWorkers) |