* Resolve the absolute filesystem path of a package's ESM entry, walking * the `exports` field's `node` / `import` / `default` conditions. Used by * the "sass_string" / "sass_file_url" fixtures so the loader's * `await import( )` returns a real ESM namespace (with `info`, * `compileStringAs
(specifier)
| 15 | * @returns {string} absolute filesystem path |
| 16 | */ |
| 17 | function resolveEsmPath(specifier) { |
| 18 | const pkgPath = findPackageJSON( |
| 19 | specifier, |
| 20 | new URL("../../src/utils.js", import.meta.url), |
| 21 | ); |
| 22 | const pkg = JSON.parse(readFileSync(pkgPath, "utf8")); |
| 23 | |
| 24 | const walk = (node) => { |
| 25 | if (typeof node === "string") return node; |
| 26 | if (Array.isArray(node)) { |
| 27 | for (const item of node) { |
| 28 | const r = walk(item); |
| 29 | if (r) return r; |
| 30 | } |
| 31 | } |
| 32 | if (node && typeof node === "object") { |
| 33 | for (const key of ["node", "import", "default"]) { |
| 34 | if (key in node) { |
| 35 | const r = walk(node[key]); |
| 36 | if (r) return r; |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | return null; |
| 41 | }; |
| 42 | |
| 43 | const entry = |
| 44 | (pkg.exports && walk(pkg.exports["."] ?? pkg.exports)) ?? |
| 45 | pkg.module ?? |
| 46 | pkg.main ?? |
| 47 | "index.js"; |
| 48 | |
| 49 | return path.join(path.dirname(pkgPath), entry); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @param {"dart-sass" | "sass" | "sass-embedded" | "sass_string" | "sass_file_url"} implementationName implementation name |
no test coverage detected
searching dependent graphs…