UNPKG

malinajs-unplugin

Version:
122 lines (118 loc) 4.57 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __defProps = Object.defineProperties; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropDescs = Object.getOwnPropertyDescriptors; var __getOwnPropNames = Object.getOwnPropertyNames; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); var __require = typeof require !== "undefined" ? require : (x) => { throw new Error('Dynamic require of "' + x + '" is not supported'); }; var __export = (target, all) => { __markAsModule(target); for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __reExport = (target, module2, desc) => { if (module2 && typeof module2 === "object" || typeof module2 === "function") { for (let key of __getOwnPropNames(module2)) if (!__hasOwnProp.call(target, key) && key !== "default") __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable }); } return target; }; var __toModule = (module2) => { return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2); }; // src/index.ts __export(exports, { rollupPlugin: () => rollupPlugin, unplugin: () => unplugin, vitePlugin: () => vitePlugin, webpackPlugin: () => webpackPlugin }); // node_modules/.pnpm/tsup@5.1.0_typescript@4.4.3/node_modules/tsup/assets/cjs_shims.js var importMetaUrlShim = typeof document === "undefined" ? new (require("url")).URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href; // src/index.ts var import_unplugin = __toModule(require("unplugin")); var import_malinajs = __toModule(require("malinajs")); var unplugin = (0, import_unplugin.createUnplugin)((options) => { if (!options) options = {}; if (!options.extensions) options.extensions = ["ma", "xht"]; if (options.displayVersion) console.log("! Malina.js", import_malinajs.default.version); let content_cache = {}; return { name: "malinajs", transformInclude(id) { return options.extensions.some((extension) => id.endsWith("." + extension)); }, async transform(code, id) { var _a; const compileOptions = __spreadProps(__spreadValues({}, options), { path: id, name: id.match(/([^\/\\]+)\.\w+$/)[1] }); try { const ctx = await import_malinajs.default.compile(code, compileOptions); let result = ctx.result; if ((_a = ctx == null ? void 0 : ctx.css) == null ? void 0 : _a.result) { const name = id.replace(/[^\w.\\-]/g, "") + ".malina.css"; content_cache[name] = ctx.css.result; result += ` import "${name}"; `; } return result; } catch (error) { if (options == null ? void 0 : options.warning) { if (typeof error === "string") { options.warning(error); } else if (error instanceof Error) { options.warning(error.message); } } throw error; } }, async resolveId(name) { if (content_cache[name]) return name; if (name === "malinajs") return await require("malinajs/runtime"); return null; }, load(id) { return content_cache[id] || null; } }; }); var vitePlugin = unplugin.vite; var rollupPlugin = unplugin.rollup; var webpackPlugin = unplugin.webpack; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { rollupPlugin, unplugin, vitePlugin, webpackPlugin });