* @param {string} testId test ID * @param {Options} options options * @param {Context} context context * @returns {{ css: string, map: RawSourceMap }} CSS and source map (if exist)
(testId, options = {}, context = {})
| 184 | * @returns {{ css: string, map: RawSourceMap }} CSS and source map (if exist) |
| 185 | */ |
| 186 | async function getCodeFromLess(testId, options = {}, context = {}) { |
| 187 | let pathToFile; |
| 188 | |
| 189 | if (context.packageExportsCustomConditionTestVariant === 1) { |
| 190 | pathToFile = path.resolve( |
| 191 | __dirname, |
| 192 | "..", |
| 193 | "fixtures", |
| 194 | "node_modules/package-with-exports-and-custom-condition/style-1.less", |
| 195 | ); |
| 196 | } else if (context.packageExportsCustomConditionTestVariant === 2) { |
| 197 | pathToFile = path.resolve( |
| 198 | __dirname, |
| 199 | "..", |
| 200 | "fixtures", |
| 201 | "node_modules/package-with-exports-and-custom-condition/style-2.less", |
| 202 | ); |
| 203 | } else { |
| 204 | pathToFile = path.resolve(__dirname, "..", "fixtures", testId); |
| 205 | } |
| 206 | |
| 207 | const defaultOptions = { |
| 208 | plugins: [], |
| 209 | relativeUrls: true, |
| 210 | filename: pathToFile, |
| 211 | }; |
| 212 | const lessOptions = options.lessOptions || {}; |
| 213 | |
| 214 | let data = await fs.promises.readFile(pathToFile); |
| 215 | |
| 216 | if (typeof options.additionalData !== "undefined") { |
| 217 | data = |
| 218 | typeof options.additionalData === "function" |
| 219 | ? `${await options.additionalData(data, { |
| 220 | rootContext: path.resolve(__dirname, "../fixtures"), |
| 221 | resourcePath: pathToFile, |
| 222 | })}` |
| 223 | : `${options.additionalData}\n${data}`; |
| 224 | } |
| 225 | |
| 226 | const mergedOptions = { |
| 227 | ...defaultOptions, |
| 228 | ...lessOptions, |
| 229 | }; |
| 230 | |
| 231 | mergedOptions.plugins.unshift(new CustomImportPlugin()); |
| 232 | |
| 233 | return less.render(data.toString(), mergedOptions); |
| 234 | } |
| 235 | |
| 236 | export default getCodeFromLess; |
no outgoing calls
no test coverage detected
searching dependent graphs…