MCPcopy
hub / github.com/webpack/sass-loader / getImplementationByName

Function getImplementationByName

test/helpers/getImplementationByName.js:56–76  ·  view source on GitHub ↗

* @param {"dart-sass" | "sass" | "sass-embedded" | "sass_string" | "sass_file_url"} implementationName implementation name * @returns {Promise } a sass implementation

(implementationName)

Source from the content-addressed store, hash-verified

54 * @returns {Promise<SassImplementation>} a sass implementation
55 */
56async function getImplementationByName(implementationName) {
57 if (implementationName === "dart-sass") {
58 return import("sass");
59 } else if (implementationName === "sass-embedded") {
60 // Match the loader's `await import("sass-embedded")` so tests and loader
61 // hold the same module instance (CJS and ESM builds are cached
62 // separately).
63 return import("sass-embedded");
64 } else if (implementationName === "sass_string") {
65 // Absolute filesystem path; on Windows this is a backslash-separated
66 // path like `C:\\...` which dynamic `import()` does not accept until
67 // it's normalized to a `file:` URL. The ESM entry is used so the
68 // loader's `await import(path)` exposes named exports (`info`,
69 // `compileStringAsync`, …) directly instead of via `.default`.
70 return resolveEsmPath("sass");
71 } else if (implementationName === "sass_file_url") {
72 return pathToFileURL(resolveEsmPath("sass")).href;
73 }
74
75 throw new Error(`Can't find ${implementationName}`);
76}
77
78export default getImplementationByName;

Callers 2

createTestCaseFunction · 0.90

Calls 1

resolveEsmPathFunction · 0.85

Tested by 1

createTestCaseFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…