@maizzle/framework
Version:
Maizzle is a framework that helps you quickly build HTML emails with Tailwind CSS.
39 lines (38 loc) • 1.33 kB
JavaScript
import { createRequire } from "node:module";
//#region src/plugins/postcss/resolveMaizzleImports.ts
const SUBPATH_RE = new RegExp(`^@maizzle/tailwindcss(?:/|$)`);
const requireFromFramework = createRequire(import.meta.url);
/**
* Rewrite `@import "@maizzle/tailwindcss"` (and subpaths like
* `@maizzle/tailwindcss/mso`) to absolute file paths so postcss/Tailwind
* can resolve them regardless of where the user's template lives or how
* their package manager hoists dependencies.
*
* Resolution order: prefer the user's project copy (so explicit installs
* win), then fall back to the copy bundled with the framework.
*/
function resolveMaizzleImports(userRoot = process.cwd()) {
const requireFromUser = createRequire(`${userRoot}/_maizzle.js`);
function resolve(spec) {
try {
return requireFromUser.resolve(spec);
} catch {}
try {
return requireFromFramework.resolve(spec);
} catch {}
}
return {
postcssPlugin: "maizzle:resolve-tw-imports",
AtRule: { import(rule) {
const m = rule.params.match(/^\s*["']([^"']+)["']/);
if (!m) return;
const spec = m[1];
if (!SUBPATH_RE.test(spec)) return;
const abs = resolve(spec);
if (abs) rule.params = rule.params.replace(m[0], `"${abs}"`);
} }
};
}
//#endregion
export { resolveMaizzleImports };
//# sourceMappingURL=resolveMaizzleImports.js.map