* Resolve the absolute `file:` URL that `await import(specifier)` from inside * `src/` would land on. Walks the package's `exports` field preferring the * `node` / `import` / `default` conditions, falling back to `module` / `main`. * Used to key `mock.module` so the loader's dynamic `import("sass
(specifier)
| 31 | * @returns {string} `file:` URL of the package's ESM entry |
| 32 | */ |
| 33 | function resolveEsmEntry(specifier) { |
| 34 | const pkgPath = findPackageJSON( |
| 35 | specifier, |
| 36 | new URL("../src/utils.js", import.meta.url), |
| 37 | ); |
| 38 | const pkg = JSON.parse(readFileSync(pkgPath, "utf8")); |
| 39 | |
| 40 | const walk = (node) => { |
| 41 | if (typeof node === "string") return node; |
| 42 | if (Array.isArray(node)) { |
| 43 | for (const item of node) { |
| 44 | const r = walk(item); |
| 45 | if (r) return r; |
| 46 | } |
| 47 | } |
| 48 | if (node && typeof node === "object") { |
| 49 | for (const key of ["node", "import", "default"]) { |
| 50 | if (key in node) { |
| 51 | const r = walk(node[key]); |
| 52 | if (r) return r; |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | return null; |
| 57 | }; |
| 58 | |
| 59 | const entry = |
| 60 | (pkg.exports && walk(pkg.exports["."] ?? pkg.exports)) ?? |
| 61 | pkg.module ?? |
| 62 | pkg.main ?? |
| 63 | "index.js"; |
| 64 | |
| 65 | return pathToFileURL(path.join(path.dirname(pkgPath), entry)).href; |
| 66 | } |
| 67 | |
| 68 | const sassEsmURL = resolveEsmEntry("sass"); |
| 69 | const sassEmbeddedEsmURL = resolveEsmEntry("sass-embedded"); |
no test coverage detected
searching dependent graphs…