@yoamigo.com/core 1.4.2 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/plugin.js +69 -11
  2. package/package.json +1 -1
package/dist/plugin.js CHANGED
@@ -2,10 +2,18 @@
2
2
  import react from "@vitejs/plugin-react";
3
3
  import path from "path";
4
4
  import { createRequire } from "module";
5
+ import { execFileSync } from "child_process";
6
+ import { existsSync, readFileSync, writeFileSync } from "fs";
7
+ import { fileURLToPath } from "url";
5
8
  var require2 = createRequire(import.meta.url);
6
9
  function yoamigoPlugin(options = {}) {
7
10
  const templateDir = process.cwd();
8
11
  const resolveFromTemplate = (relativePath) => path.resolve(templateDir, relativePath);
12
+ let tablerIconsPath;
13
+ try {
14
+ tablerIconsPath = path.dirname(require2.resolve("@tabler/icons-react/package.json"));
15
+ } catch {
16
+ }
9
17
  return [
10
18
  // Content HMR plugin - enables hot reloading of content.ts without full page refresh
11
19
  {
@@ -46,12 +54,6 @@ if (import.meta.hot) {
46
54
  name: "yoamigo:config",
47
55
  config(config, { mode }) {
48
56
  const isProd = mode === "production";
49
- let tablerIconsPath;
50
- try {
51
- tablerIconsPath = path.dirname(require2.resolve("@tabler/icons-react/package.json"));
52
- } catch {
53
- console.warn("[yoamigo] @tabler/icons-react not found - icon loading may fail");
54
- }
55
57
  const aliasArray = [
56
58
  // Production aliases must come FIRST for priority
57
59
  ...isProd ? [
@@ -97,14 +99,16 @@ if (import.meta.hot) {
97
99
  // Ensure single React instance across all packages (prevents "Invalid hook call" errors)
98
100
  dedupe: ["react", "react-dom"]
99
101
  },
100
- // Force Vite to pre-bundle @tabler/icons-react with the app's React instance
101
- // This prevents Symbol mismatch issues when dynamically importing icons in DEV mode
102
+ // Pre-bundle React to ensure a single instance across all packages.
103
+ // @tabler/icons-react is NOT included here it's resolved via the alias
104
+ // above to core's node_modules, so Vite doesn't need to find it in the
105
+ // template's own node_modules (which would fail with pnpm strict linking).
102
106
  optimizeDeps: {
103
107
  include: [
104
- ...tablerIconsPath ? ["@tabler/icons-react"] : [],
105
108
  "react",
106
109
  "react-dom"
107
- ]
110
+ ],
111
+ exclude: ["@tiptap/pm"]
108
112
  },
109
113
  server: {
110
114
  port: process.env.PORT ? parseInt(process.env.PORT, 10) : 5173,
@@ -154,7 +158,61 @@ if (import.meta.hot) {
154
158
  }
155
159
  };
156
160
  }
157
- }
161
+ },
162
+ // Icon auto-registration plugin — in production builds, automatically scans
163
+ // template source for icon usage and generates a registration file so that
164
+ // the prod icon registry has all needed icons without manual setup.
165
+ (function yoamigoIconsPlugin() {
166
+ let isProd = false;
167
+ const pluginDir = path.dirname(fileURLToPath(import.meta.url));
168
+ const iconScannerPath = path.resolve(pluginDir, "../bin/icon-scanner.cjs");
169
+ return {
170
+ name: "yoamigo:icons",
171
+ configResolved(config) {
172
+ isProd = config.command === "build";
173
+ },
174
+ buildStart() {
175
+ if (!isProd) return;
176
+ const srcDir = path.resolve(templateDir, "src");
177
+ const outFile = path.resolve(templateDir, "src/icons.generated.ts");
178
+ console.log("[yoamigo:icons] Scanning icons for production build...");
179
+ try {
180
+ execFileSync("node", [iconScannerPath, "-src", srcDir, "-out", outFile], {
181
+ stdio: "inherit",
182
+ cwd: templateDir
183
+ });
184
+ if (tablerIconsPath) {
185
+ let generated = readFileSync(outFile, "utf-8");
186
+ const lines = generated.split("\n");
187
+ const filtered = lines.filter((line) => {
188
+ const match = line.match(
189
+ /import\('@tabler\/icons-react\/dist\/esm\/icons\/(\w+)\.mjs'\)/
190
+ );
191
+ if (!match) return true;
192
+ const iconFile = path.join(tablerIconsPath, "dist", "esm", "icons", `${match[1]}.mjs`);
193
+ if (!existsSync(iconFile)) {
194
+ console.warn(`[yoamigo:icons] Skipping "${match[1]}" \u2014 not found in @tabler/icons-react`);
195
+ return false;
196
+ }
197
+ return true;
198
+ });
199
+ writeFileSync(outFile, filtered.join("\n"), "utf-8");
200
+ }
201
+ console.log("[yoamigo:icons] Icon registration file generated");
202
+ } catch (err) {
203
+ console.error("[yoamigo:icons] Icon scanner failed:", err);
204
+ throw err;
205
+ }
206
+ },
207
+ transform(code, id) {
208
+ if (!isProd) return;
209
+ if (!id.match(/\/main\.tsx?$/) && !id.match(/\\main\.tsx?$/)) return;
210
+ const injection = `import './icons.generated';
211
+ `;
212
+ return { code: injection + code, map: null };
213
+ }
214
+ };
215
+ })()
158
216
  ];
159
217
  }
160
218
  var plugin_default = yoamigoPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yoamigo.com/core",
3
- "version": "1.4.2",
3
+ "version": "1.5.1",
4
4
  "description": "Core components, router, and utilities for YoAmigo templates",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",