fortiplugin-bundle-adapter 0.0.5 → 0.0.7

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.
package/dist/index.cjs CHANGED
@@ -45,7 +45,8 @@ var import_node_path = require("path");
45
45
  var t = __toESM(require("@babel/types"));
46
46
  var DEFAULTS = {
47
47
  runtimeKey: "imports",
48
- depsParam: "deps"
48
+ depsParam: "deps",
49
+ onMissingDefault: "skip"
49
50
  };
50
51
  var DEFAULT_EXPORT_ERROR = "PROBLEM!!, No known default function was found, your code either possesses NO named default export or this export format is currently not supported.";
51
52
  function shouldInject(id, opts) {
@@ -55,19 +56,31 @@ function shouldInject(id, opts) {
55
56
  for (const p of prefixes) if (id.startsWith(p)) return true;
56
57
  return false;
57
58
  }
59
+ function programHasDefaultExport(p) {
60
+ for (const stmt of p.body) {
61
+ if (t.isExportDefaultDeclaration(stmt)) return true;
62
+ if (t.isExportNamedDeclaration(stmt) && stmt.specifiers?.length) {
63
+ for (const spec of stmt.specifiers) {
64
+ const exported = t.isIdentifier(spec.exported) ? spec.exported.name : spec.exported.value;
65
+ if (exported === "default") return true;
66
+ }
67
+ }
68
+ }
69
+ return false;
70
+ }
58
71
  function getImportedName(spec) {
59
72
  return t.isIdentifier(spec.imported) ? spec.imported.name : spec.imported.value;
60
73
  }
61
74
  function makeImportMapExpr(depsIdent, runtimeKey) {
62
- const hasKey = t.binaryExpression(
63
- "in",
64
- t.stringLiteral(runtimeKey),
65
- depsIdent
66
- );
75
+ const hasKey = t.binaryExpression("in", t.stringLiteral(runtimeKey), depsIdent);
67
76
  const isObj = t.logicalExpression(
68
77
  "&&",
69
78
  t.binaryExpression("!==", depsIdent, t.nullLiteral()),
70
- t.binaryExpression("===", t.unaryExpression("typeof", depsIdent), t.stringLiteral("object"))
79
+ t.binaryExpression(
80
+ "===",
81
+ t.unaryExpression("typeof", depsIdent),
82
+ t.stringLiteral("object")
83
+ )
71
84
  );
72
85
  const test = t.logicalExpression("&&", isObj, hasKey);
73
86
  const depsKey = t.memberExpression(depsIdent, t.identifier(runtimeKey));
@@ -78,8 +91,10 @@ function fortiPrepTransform(_api, rawOpts = {}) {
78
91
  const opts = {
79
92
  ...rawOpts,
80
93
  runtimeKey: rawOpts.runtimeKey ?? DEFAULTS.runtimeKey,
81
- depsParam: rawOpts.depsParam ?? DEFAULTS.depsParam
94
+ depsParam: rawOpts.depsParam ?? DEFAULTS.depsParam,
95
+ onMissingDefault: rawOpts.onMissingDefault ?? DEFAULTS.onMissingDefault
82
96
  };
97
+ let enabled = true;
83
98
  const keptImports = [];
84
99
  const keptNamedExports = [];
85
100
  const injectedImportsById = /* @__PURE__ */ new Map();
@@ -93,73 +108,22 @@ function fortiPrepTransform(_api, rawOpts = {}) {
93
108
  return {
94
109
  name: "fortiplugin-prep/transform",
95
110
  visitor: {
96
- ImportDeclaration(path2) {
97
- const node = path2.node;
98
- const importId = node.source.value;
99
- if (!shouldInject(importId, opts)) {
100
- keptImports.push(node);
101
- path2.remove();
102
- return;
103
- }
104
- for (const s of node.specifiers) {
105
- if (t.isImportDefaultSpecifier(s)) {
106
- captureImport(importId, { kind: "default", local: s.local.name });
107
- } else if (t.isImportNamespaceSpecifier(s)) {
108
- captureImport(importId, { kind: "namespace", local: s.local.name });
109
- } else if (t.isImportSpecifier(s)) {
110
- captureImport(importId, {
111
- kind: "named",
112
- imported: getImportedName(s),
113
- local: s.local.name
114
- });
115
- }
116
- }
117
- path2.remove();
118
- },
119
- ExportDefaultDeclaration(path2) {
120
- const decl = path2.node.declaration;
121
- if (t.isIdentifier(decl)) {
122
- defaultExportLocalName = decl.name;
123
- path2.remove();
124
- return;
125
- }
126
- const id = path2.scope.generateUidIdentifier("defaultExport");
127
- path2.replaceWith(
128
- t.variableDeclaration("const", [t.variableDeclarator(id, decl)])
129
- );
130
- defaultExportLocalName = id.name;
131
- },
132
- ExportNamedDeclaration(path2) {
133
- const node = path2.node;
134
- keptNamedExports.push(node);
135
- if (node.specifiers?.length) {
136
- let foundExplicitDefault = false;
137
- node.specifiers = node.specifiers.filter((spec) => {
138
- const exported = t.isIdentifier(spec.exported) ? spec.exported.name : spec.exported.value;
139
- if (exported === "default") {
140
- const local = spec?.local?.name;
141
- if (local) defaultExportLocalName = local;
142
- foundExplicitDefault = true;
143
- return false;
144
- }
145
- return true;
146
- });
147
- if (!foundExplicitDefault && !defaultExportLocalName && node.specifiers.length === 1) {
148
- const only = node.specifiers[0];
149
- if (only?.local?.name) {
150
- defaultExportLocalName = only.local.name;
151
- returnDefaultProperty = true;
152
- node.specifiers = [];
153
- }
154
- }
155
- }
156
- path2.remove();
157
- },
158
111
  Program: {
112
+ enter(path2) {
113
+ const hasDefault = programHasDefaultExport(path2.node);
114
+ if (!hasDefault && (opts.onMissingDefault ?? DEFAULTS.onMissingDefault) === "skip") {
115
+ enabled = false;
116
+ }
117
+ },
159
118
  exit(path2) {
119
+ if (!enabled) return;
160
120
  const program = path2.node;
161
121
  if (!defaultExportLocalName) {
162
- throw path2.buildCodeFrameError(DEFAULT_EXPORT_ERROR);
122
+ const behavior = opts.onMissingDefault ?? DEFAULTS.onMissingDefault;
123
+ if (behavior === "throw") {
124
+ throw path2.buildCodeFrameError(DEFAULT_EXPORT_ERROR);
125
+ }
126
+ defaultExportLocalName = null;
163
127
  }
164
128
  const depsIdent = t.identifier(opts.depsParam ?? DEFAULTS.depsParam);
165
129
  const runtimeKey = opts.runtimeKey ?? DEFAULTS.runtimeKey;
@@ -248,23 +212,93 @@ function fortiPrepTransform(_api, rawOpts = {}) {
248
212
  );
249
213
  }
250
214
  }
251
- const returnExpr = returnDefaultProperty ? t.memberExpression(
252
- t.identifier(defaultExportLocalName),
253
- t.identifier("default")
254
- ) : t.identifier(defaultExportLocalName);
215
+ const returnExpr = defaultExportLocalName == null ? t.nullLiteral() : returnDefaultProperty ? t.memberExpression(t.identifier(defaultExportLocalName), t.identifier("default")) : t.identifier(defaultExportLocalName);
255
216
  const wrapperBody = [];
256
217
  wrapperBody.push(...injectedStmts);
257
218
  wrapperBody.push(...program.body);
258
219
  wrapperBody.push(t.returnStatement(returnExpr));
259
220
  const wrapper = t.exportDefaultDeclaration(
260
- t.functionDeclaration(
261
- null,
262
- [depsIdent],
263
- t.blockStatement(wrapperBody)
264
- )
221
+ t.functionDeclaration(null, [depsIdent], t.blockStatement(wrapperBody))
265
222
  );
266
223
  program.body = [...keptImports, wrapper, ...keptNamedExports];
267
224
  }
225
+ },
226
+ ImportDeclaration(path2) {
227
+ if (!enabled) return;
228
+ const node = path2.node;
229
+ const importId = node.source.value;
230
+ if (!shouldInject(importId, opts)) {
231
+ keptImports.push(node);
232
+ path2.remove();
233
+ return;
234
+ }
235
+ for (const s of node.specifiers) {
236
+ if (t.isImportDefaultSpecifier(s)) {
237
+ captureImport(importId, { kind: "default", local: s.local.name });
238
+ } else if (t.isImportNamespaceSpecifier(s)) {
239
+ captureImport(importId, { kind: "namespace", local: s.local.name });
240
+ } else if (t.isImportSpecifier(s)) {
241
+ captureImport(importId, {
242
+ kind: "named",
243
+ imported: getImportedName(s),
244
+ local: s.local.name
245
+ });
246
+ }
247
+ }
248
+ path2.remove();
249
+ },
250
+ ExportDefaultDeclaration(path2) {
251
+ if (!enabled) return;
252
+ const decl = path2.node.declaration;
253
+ if (t.isIdentifier(decl)) {
254
+ defaultExportLocalName = decl.name;
255
+ path2.remove();
256
+ return;
257
+ }
258
+ if (t.isFunctionDeclaration(decl) || t.isClassDeclaration(decl)) {
259
+ if (!decl.id) {
260
+ decl.id = path2.scope.generateUidIdentifier("defaultExport");
261
+ }
262
+ defaultExportLocalName = decl.id.name;
263
+ path2.replaceWith(decl);
264
+ return;
265
+ }
266
+ const id = path2.scope.generateUidIdentifier("defaultExport");
267
+ path2.replaceWith(
268
+ t.variableDeclaration("const", [
269
+ t.variableDeclarator(id, decl)
270
+ ])
271
+ );
272
+ defaultExportLocalName = id.name;
273
+ },
274
+ ExportNamedDeclaration(path2) {
275
+ if (!enabled) return;
276
+ const node = path2.node;
277
+ if (node.specifiers?.length) {
278
+ let foundExplicitDefault = false;
279
+ node.specifiers = node.specifiers.filter((spec) => {
280
+ const exported = t.isIdentifier(spec.exported) ? spec.exported.name : spec.exported.value;
281
+ if (exported === "default") {
282
+ const local = spec?.local?.name;
283
+ if (local) defaultExportLocalName = local;
284
+ foundExplicitDefault = true;
285
+ return false;
286
+ }
287
+ return true;
288
+ });
289
+ if (!foundExplicitDefault && !defaultExportLocalName && node.specifiers.length === 1) {
290
+ const only = node.specifiers[0];
291
+ if (only?.local?.name) {
292
+ defaultExportLocalName = only.local.name;
293
+ returnDefaultProperty = true;
294
+ node.specifiers = [];
295
+ }
296
+ }
297
+ }
298
+ if (node.declaration || node.specifiers && node.specifiers.length > 0) {
299
+ keptNamedExports.push(node);
300
+ }
301
+ path2.remove();
268
302
  }
269
303
  }
270
304
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/vite/prep.ts","../src/babel/transform.ts","../src/utils/generate-plugin-inputs.ts"],"sourcesContent":["// src/index.ts\r\nexport {default} from \"./vite/prep\";\r\nexport type {FortiPrepOptions} from \"./vite/prep\";\r\nexport type {FortiPrepTransformOptions} from \"./babel/transform\";\r\n\r\n// ✅ add this:\r\nexport {default as fortiPrepTransform} from \"./babel/transform\";\r\nexport {generatePluginInputs as discoverEntrypoints} from './utils/generate-plugin-inputs'","import { transformSync } from \"@babel/core\";\r\nimport { readFileSync, writeFileSync } from \"node:fs\";\r\nimport { dirname, resolve as resolvePath } from \"node:path\";\r\nimport type {NormalizedOutputOptions, OutputBundle, OutputOptions} from \"rollup\";\r\nimport type { Plugin as VitePlugin } from \"vite\";\r\n\r\nimport fortiPrepTransform, {\r\n type FortiPrepTransformOptions,\r\n} from \"../babel/transform\";\r\n\r\nexport type FortiPrepOptions = FortiPrepTransformOptions & {\r\n /**\r\n * Which emitted entry file extensions should be rewritten.\r\n * Default: [\".js\", \".mjs\"]\r\n */\r\n entryExtensions?: string[];\r\n\r\n /**\r\n * Vite plugin name\r\n * Default: \"fortiplugin-prep\"\r\n */\r\n pluginName?: string;\r\n};\r\n\r\nconst DEFAULT_INJECTED_IDS = [\"react\", \"react/jsx-runtime\"] as const;\r\nconst DEFAULT_INJECTED_PREFIXES = [\"@inertiajs/\", \"@host/\"] as const;\r\n\r\nfunction resolveOutDir(outputOptions: OutputOptions): string | null {\r\n if (outputOptions.dir) return outputOptions.dir;\r\n if (outputOptions.file) return dirname(outputOptions.file);\r\n return null;\r\n}\r\n\r\nfunction shouldInject(id: string, opts: FortiPrepTransformOptions): boolean {\r\n const ids = opts.injectedIds ?? [];\r\n const prefixes = opts.injectedPrefixes ?? [];\r\n if (ids.includes(id)) return true;\r\n for (const p of prefixes) if (id.startsWith(p)) return true;\r\n return false;\r\n}\r\n\r\n/**\r\n * FortiPlugin bundle adapter:\r\n * - marks injected imports as Rollup externals (so they survive into output)\r\n * - rewrites built entry chunks to remove those imports and load them from runtime deps\r\n */\r\nexport default function prep(options: FortiPrepOptions = {}): VitePlugin {\r\n const injectedIds = options.injectedIds ?? [...DEFAULT_INJECTED_IDS];\r\n const injectedPrefixes = options.injectedPrefixes ?? [...DEFAULT_INJECTED_PREFIXES];\r\n\r\n const runtimeKey = options.runtimeKey ?? \"imports\";\r\n const depsParam = options.depsParam ?? \"deps\";\r\n\r\n const entryExtensions = options.entryExtensions ?? [\".js\", \".mjs\"];\r\n const pluginName = options.pluginName ?? \"fortiplugin-prep\";\r\n\r\n const transformOptions: FortiPrepTransformOptions = {\r\n injectedIds,\r\n injectedPrefixes,\r\n runtimeKey,\r\n depsParam,\r\n };\r\n\r\n return {\r\n name: pluginName,\r\n apply: \"build\",\r\n\r\n config() {\r\n return {\r\n define: {\r\n \"process.env.NODE_ENV\": '\"production\"',\r\n },\r\n build: {\r\n rollupOptions: {\r\n // Ensure virtual imports don't need to resolve.\r\n external: (id: string) => shouldInject(id, transformOptions),\r\n },\r\n },\r\n };\r\n },\r\n\r\n writeBundle(outputOptions: NormalizedOutputOptions, bundle: OutputBundle) {\r\n const outDir = resolveOutDir(outputOptions);\r\n if (!outDir) return;\r\n\r\n for (const [fileName, item] of Object.entries(bundle)) {\r\n if (item.type !== \"chunk\") continue;\r\n if (!item.isEntry) continue;\r\n\r\n if (!entryExtensions.some((ext) => fileName.endsWith(ext))) continue;\r\n\r\n const absPath = resolvePath(outDir, fileName);\r\n const input = readFileSync(absPath, \"utf-8\");\r\n\r\n const result = transformSync(input, {\r\n filename: absPath,\r\n sourceType: \"module\",\r\n // Fresh plugin instance per file (Babel calls plugin factory per file when passed as [fn, opts])\r\n plugins: [[fortiPrepTransform as any, transformOptions]],\r\n generatorOpts: {\r\n compact: false,\r\n comments: true,\r\n retainLines: false,\r\n },\r\n });\r\n\r\n if (!result?.code) continue;\r\n writeFileSync(absPath, result.code, \"utf-8\");\r\n }\r\n },\r\n };\r\n}","// noinspection JSUnusedGlobalSymbols,GrazieInspection\r\n\r\nimport type {PluginObj} from \"@babel/core\";\r\nimport * as t from \"@babel/types\";\r\nimport type {NodePath} from \"@babel/traverse\";\r\n\r\nexport type FortiPrepTransformOptions = {\r\n /**\r\n * Exact import ids to inject (removed from bundle and loaded from runtime deps).\r\n * Example: [\"react\", \"react/jsx-runtime\", \"@host/ui\"]\r\n */\r\n injectedIds?: string[];\r\n\r\n /**\r\n * Prefix import ids to inject.\r\n * Example: [\"@host/\", \"@inertiajs/\"]\r\n */\r\n injectedPrefixes?: string[];\r\n\r\n /**\r\n * The key on the deps object used as the import map.\r\n * Wrapper supports passing deps.imports OR passing the import map directly.\r\n *\r\n * Default: \"imports\"\r\n */\r\n runtimeKey?: string;\r\n\r\n /**\r\n * Wrapper function parameter name.\r\n * Default: \"deps\"\r\n */\r\n depsParam?: string;\r\n};\r\n\r\nconst DEFAULTS: Required<Pick<FortiPrepTransformOptions, \"runtimeKey\" | \"depsParam\">> = {\r\n runtimeKey: \"imports\",\r\n depsParam: \"deps\",\r\n};\r\n\r\nconst DEFAULT_EXPORT_ERROR =\r\n \"PROBLEM!!, No known default function was found, your code either possesses NO named default export or this export format is currently not supported.\";\r\n\r\nfunction shouldInject(id: string, opts: FortiPrepTransformOptions): boolean {\r\n const ids = opts.injectedIds ?? [];\r\n const prefixes = opts.injectedPrefixes ?? [];\r\n if (ids.includes(id)) return true;\r\n for (const p of prefixes) if (id.startsWith(p)) return true;\r\n return false;\r\n}\r\n\r\ntype CapturedImport =\r\n | { kind: \"default\"; local: string }\r\n | { kind: \"namespace\"; local: string }\r\n | { kind: \"named\"; imported: string; local: string };\r\n\r\nfunction getImportedName(spec: t.ImportSpecifier): string {\r\n return t.isIdentifier(spec.imported) ? spec.imported.name : spec.imported.value;\r\n}\r\n\r\nfunction makeImportMapExpr(\r\n depsIdent: t.Identifier,\r\n runtimeKey: string\r\n): t.Expression {\r\n // Support both:\r\n // factory({ imports: { ... } })\r\n // and:\r\n // factory({ ... }) // direct import map\r\n //\r\n // const __imports =\r\n // deps && typeof deps === \"object\" && \"imports\" in deps\r\n // ? deps.imports\r\n // : (deps ?? {});\r\n const hasKey = t.binaryExpression(\r\n \"in\",\r\n t.stringLiteral(runtimeKey),\r\n depsIdent\r\n );\r\n\r\n const isObj = t.logicalExpression(\r\n \"&&\",\r\n t.binaryExpression(\"!==\", depsIdent, t.nullLiteral()),\r\n t.binaryExpression(\"===\", t.unaryExpression(\"typeof\", depsIdent), t.stringLiteral(\"object\"))\r\n );\r\n\r\n const test = t.logicalExpression(\"&&\", isObj, hasKey);\r\n\r\n const depsKey = t.memberExpression(depsIdent, t.identifier(runtimeKey));\r\n const fallback = t.logicalExpression(\"||\", depsIdent, t.objectExpression([]));\r\n\r\n return t.conditionalExpression(test, depsKey, fallback);\r\n}\r\n\r\n/**\r\n * Babel plugin factory (Babel calls this per-file when used as `[plugin, options]`).\r\n */\r\nexport default function fortiPrepTransform(\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n _api: unknown,\r\n rawOpts: FortiPrepTransformOptions = {}\r\n): PluginObj {\r\n const opts: FortiPrepTransformOptions = {\r\n ...rawOpts,\r\n runtimeKey: rawOpts.runtimeKey ?? DEFAULTS.runtimeKey,\r\n depsParam: rawOpts.depsParam ?? DEFAULTS.depsParam,\r\n };\r\n\r\n // per-file state (because Babel calls the plugin per file)\r\n const keptImports: t.ImportDeclaration[] = [];\r\n const keptNamedExports: t.ExportNamedDeclaration[] = [];\r\n\r\n const injectedImportsById = new Map<string, CapturedImport[]>();\r\n\r\n let defaultExportLocalName: string | null = null;\r\n let returnDefaultProperty = false;\r\n\r\n function captureImport(importId: string, entry: CapturedImport) {\r\n const list = injectedImportsById.get(importId) ?? [];\r\n list.push(entry);\r\n injectedImportsById.set(importId, list);\r\n }\r\n\r\n return {\r\n name: \"fortiplugin-prep/transform\",\r\n visitor: {\r\n ImportDeclaration(path: NodePath<t.ImportDeclaration>) {\r\n const node = path.node;\r\n const importId = node.source.value;\r\n\r\n if (!shouldInject(importId, opts)) {\r\n keptImports.push(node);\r\n path.remove();\r\n return;\r\n }\r\n\r\n // Remove injected import and capture its specifiers to recreate inside wrapper.\r\n for (const s of node.specifiers) {\r\n if (t.isImportDefaultSpecifier(s)) {\r\n captureImport(importId, {kind: \"default\", local: s.local.name});\r\n } else if (t.isImportNamespaceSpecifier(s)) {\r\n captureImport(importId, {kind: \"namespace\", local: s.local.name});\r\n } else if (t.isImportSpecifier(s)) {\r\n captureImport(importId, {\r\n kind: \"named\",\r\n imported: getImportedName(s),\r\n local: s.local.name,\r\n });\r\n }\r\n }\r\n\r\n // side-effect only imports (import \"@host/ui\") become no-ops at runtime\r\n path.remove();\r\n },\r\n\r\n ExportDefaultDeclaration(path: NodePath<t.ExportDefaultDeclaration>) {\r\n const decl = path.node.declaration;\r\n\r\n // export default Foo;\r\n if (t.isIdentifier(decl)) {\r\n defaultExportLocalName = decl.name;\r\n path.remove();\r\n return;\r\n }\r\n\r\n // export default (expr/anon fn/class)\r\n // Hoist into a const (inside wrapper) so we can `return <id>`\r\n const id = path.scope.generateUidIdentifier(\"defaultExport\");\r\n path.replaceWith(\r\n t.variableDeclaration(\"const\", [t.variableDeclarator(id, decl as any)])\r\n );\r\n defaultExportLocalName = id.name;\r\n },\r\n\r\n ExportNamedDeclaration(path: NodePath<t.ExportNamedDeclaration>) {\r\n const node = path.node;\r\n keptNamedExports.push(node);\r\n\r\n // Detect Rollup-style: export { Foo as default }\r\n if (node.specifiers?.length) {\r\n let foundExplicitDefault = false;\r\n\r\n node.specifiers = node.specifiers.filter((spec) => {\r\n const exported =\r\n t.isIdentifier(spec.exported) ? spec.exported.name : spec.exported.value;\r\n\r\n if (exported === \"default\") {\r\n const local = (spec as any)?.local?.name as string | undefined;\r\n if (local) defaultExportLocalName = local;\r\n foundExplicitDefault = true;\r\n return false; // remove\r\n }\r\n\r\n return true;\r\n });\r\n\r\n // Minified fallback behavior:\r\n // If no default specifier found and exactly one spec exists,\r\n // treat it as the container and return `<local>.default`.\r\n if (!foundExplicitDefault && !defaultExportLocalName && node.specifiers.length === 1) {\r\n const only = node.specifiers[0] as any;\r\n if (only?.local?.name) {\r\n defaultExportLocalName = only.local.name;\r\n returnDefaultProperty = true;\r\n node.specifiers = [];\r\n }\r\n }\r\n }\r\n\r\n path.remove();\r\n },\r\n\r\n Program: {\r\n exit(path: NodePath<t.Program>) {\r\n const program = path.node;\r\n\r\n if (!defaultExportLocalName) {\r\n throw path.buildCodeFrameError(DEFAULT_EXPORT_ERROR);\r\n }\r\n\r\n const depsIdent = t.identifier(opts.depsParam ?? DEFAULTS.depsParam);\r\n const runtimeKey = opts.runtimeKey ?? DEFAULTS.runtimeKey;\r\n\r\n // const __imports = (deps has runtimeKey) ? deps[runtimeKey] : (deps || {});\r\n const importsIdent = t.identifier(\"__imports\");\r\n const importsInit = makeImportMapExpr(depsIdent, runtimeKey);\r\n const importsDecl = t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(importsIdent, importsInit),\r\n ]);\r\n\r\n // helper:\r\n // const __default = (m) => (m && typeof m === \"object\" && \"default\" in m ? m.default : m);\r\n const defaultHelperIdent = t.identifier(\"__default\");\r\n const defaultHelperDecl = t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(\r\n defaultHelperIdent,\r\n t.arrowFunctionExpression(\r\n [t.identifier(\"m\")],\r\n t.conditionalExpression(\r\n t.logicalExpression(\r\n \"&&\",\r\n t.logicalExpression(\r\n \"&&\",\r\n t.identifier(\"m\"),\r\n t.binaryExpression(\r\n \"===\",\r\n t.unaryExpression(\"typeof\", t.identifier(\"m\")),\r\n t.stringLiteral(\"object\")\r\n )\r\n ),\r\n t.binaryExpression(\"in\", t.stringLiteral(\"default\"), t.identifier(\"m\"))\r\n ),\r\n t.memberExpression(t.identifier(\"m\"), t.identifier(\"default\")),\r\n t.identifier(\"m\")\r\n )\r\n )\r\n ),\r\n ]);\r\n\r\n // Build injected module locals inside wrapper\r\n const injectedStmts: t.Statement[] = [importsDecl, defaultHelperDecl];\r\n\r\n for (const [importId, specs] of injectedImportsById.entries()) {\r\n const modIdent = t.identifier(\r\n `__m_${importId.replace(/[^a-zA-Z0-9_$]/g, \"_\")}`\r\n );\r\n\r\n // const __m_xxx = __imports[\"<importId>\"];\r\n injectedStmts.push(\r\n t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(\r\n modIdent,\r\n t.memberExpression(importsIdent, t.stringLiteral(importId), true)\r\n ),\r\n ])\r\n );\r\n\r\n const named: Array<{ imported: string; local: string }> = [];\r\n\r\n for (const s of specs) {\r\n if (s.kind === \"default\") {\r\n // const Local = __default(__m_xxx);\r\n injectedStmts.push(\r\n t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(\r\n t.identifier(s.local),\r\n t.callExpression(defaultHelperIdent, [modIdent])\r\n ),\r\n ])\r\n );\r\n } else if (s.kind === \"namespace\") {\r\n // const Local = __m_xxx;\r\n injectedStmts.push(\r\n t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(t.identifier(s.local), modIdent),\r\n ])\r\n );\r\n } else {\r\n named.push({imported: s.imported, local: s.local});\r\n }\r\n }\r\n\r\n if (named.length) {\r\n // const { A, B: C } = (__m_xxx ?? {});\r\n injectedStmts.push(\r\n t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(\r\n t.objectPattern(\r\n named.map(({imported, local}) =>\r\n t.objectProperty(\r\n t.identifier(imported),\r\n t.identifier(local),\r\n false,\r\n imported === local\r\n )\r\n )\r\n ),\r\n t.logicalExpression(\"||\", modIdent, t.objectExpression([]))\r\n ),\r\n ])\r\n );\r\n }\r\n }\r\n\r\n const returnExpr = returnDefaultProperty\r\n ? t.memberExpression(\r\n t.identifier(defaultExportLocalName),\r\n t.identifier(\"default\")\r\n )\r\n : t.identifier(defaultExportLocalName);\r\n\r\n // Wrapper body:\r\n // injectedStmts...\r\n // <original body>\r\n // return <defaultExport>\r\n const wrapperBody: t.Statement[] = [];\r\n wrapperBody.push(...injectedStmts);\r\n wrapperBody.push(...program.body);\r\n wrapperBody.push(t.returnStatement(returnExpr));\r\n\r\n const wrapper = t.exportDefaultDeclaration(\r\n t.functionDeclaration(\r\n null,\r\n [depsIdent],\r\n t.blockStatement(wrapperBody)\r\n )\r\n );\r\n\r\n // Final program:\r\n // kept imports at module scope\r\n // export default function(deps) { ... }\r\n // kept named exports (same as your old behavior)\r\n program.body = [...keptImports, wrapper, ...keptNamedExports] as any;\r\n },\r\n },\r\n },\r\n };\r\n}","// src/utils/generate-plugin-inputs.ts\r\nimport path from \"node:path\";\r\nimport * as fs from \"node:fs\";\r\n\r\nconst EXT_PATTERN = /\\.(tsx?|jsx?)$/i;\r\n\r\nexport type PluginInputs = Record<string, string>;\r\n\r\nexport type GeneratePluginInputsOptions = {\r\n /**\r\n * If true, also generates `app.tsx` that imports every discovered entry\r\n * (handy for dev/HMR).\r\n *\r\n * Default: true\r\n */\r\n writeAppEntry?: boolean;\r\n\r\n /**\r\n * Name of the generated app entry file (inside srcRoot).\r\n *\r\n * Default: \"app.tsx\"\r\n */\r\n appEntryName?: string;\r\n\r\n /**\r\n * Adds the generated app entry to the returned Rollup inputs map.\r\n *\r\n * Default: true\r\n */\r\n includeAppEntryInInputs?: boolean;\r\n\r\n /**\r\n * Key name used for the generated app entry in Rollup inputs.\r\n *\r\n * Default: \"__app_entry\"\r\n */\r\n appEntryKey?: string;\r\n\r\n /**\r\n * Extra directory names to ignore (case-insensitive).\r\n */\r\n ignoreDirs?: string[];\r\n\r\n /**\r\n * Extra “component-like” directory names to ignore (case-insensitive, exact match).\r\n */\r\n componentLikeDirs?: string[];\r\n\r\n /**\r\n * Whether to print discovered inputs to console.\r\n *\r\n * Default: true\r\n */\r\n verbose?: boolean;\r\n};\r\n\r\n// folders you typically never want as rollup inputs\r\nconst DEFAULT_IGNORE_DIRS = new Set<string>([\r\n \"node_modules\",\r\n \".git\",\r\n \".vite\",\r\n \".internal\",\r\n \"dist\",\r\n \"build\",\r\n \"public\",\r\n]);\r\n\r\n// “component-like” folders that should NOT produce entrypoints\r\n// Strict: exact folder-name matches only (case-insensitive)\r\nconst DEFAULT_COMPONENT_LIKE_DIRS = new Set<string>([\r\n \"component\",\r\n \"components\",\r\n \"ui\",\r\n \"uis\",\r\n \"widget\",\r\n \"widgets\",\r\n \"atom\",\r\n \"atoms\",\r\n \"molecule\",\r\n \"molecules\",\r\n \"organism\",\r\n \"organisms\",\r\n \"layout\",\r\n \"layouts\",\r\n \"partial\",\r\n \"partials\",\r\n]);\r\n\r\nfunction normalizeName(x: unknown): string {\r\n return String(x ?? \"\").toLowerCase();\r\n}\r\n\r\nfunction makeIgnoreSets(opts?: GeneratePluginInputsOptions): {\r\n ignoreDirs: Set<string>;\r\n componentLikeDirs: Set<string>;\r\n} {\r\n const ignoreDirs = new Set(DEFAULT_IGNORE_DIRS);\r\n const componentLikeDirs = new Set(DEFAULT_COMPONENT_LIKE_DIRS);\r\n\r\n for (const d of opts?.ignoreDirs ?? []) ignoreDirs.add(normalizeName(d));\r\n for (const d of opts?.componentLikeDirs ?? []) componentLikeDirs.add(normalizeName(d));\r\n\r\n return { ignoreDirs, componentLikeDirs };\r\n}\r\n\r\nfunction isIgnoredDir(\r\n dirName: string,\r\n sets: { ignoreDirs: Set<string>; componentLikeDirs: Set<string> }\r\n): boolean {\r\n const name = normalizeName(dirName);\r\n return sets.ignoreDirs.has(name) || sets.componentLikeDirs.has(name);\r\n}\r\n\r\n/**\r\n * Creates an app.tsx file that simply imports every discovered entry.\r\n * Helpful for HMR / dev mode.\r\n */\r\nfunction writeAppEntryFile(inputs: PluginInputs, srcRoot: string, appEntryName: string): void {\r\n const app = path.join(srcRoot, appEntryName);\r\n const lines: string[] = [\"// Auto-generated – do not edit\", \"\"];\r\n\r\n const entries = Object.entries(inputs).sort(([a], [b]) => a.localeCompare(b));\r\n\r\n for (const [name, full] of entries) {\r\n const rel =\r\n \"./\" + path.relative(srcRoot, full).replace(/\\\\/g, \"/\").replace(EXT_PATTERN, \"\");\r\n\r\n const variable = name.replace(/[^a-zA-Z0-9_$]/g, \"_\").replace(/^(\\d)/, \"_$1\");\r\n\r\n lines.push(`import * as ${variable} from '${rel}';`);\r\n lines.push(`console.log('${name} loaded:', ${variable});`, \"\");\r\n }\r\n\r\n fs.writeFileSync(app, lines.join(\"\\n\"), \"utf8\");\r\n // eslint-disable-next-line no-console\r\n console.log(`✅ Generated ${appEntryName} in ${srcRoot}`);\r\n}\r\n\r\n/**\r\n * Convert a relative path like \"foo/bar/index.tsx\" to a dot key.\r\n * If `collapseIndex` is true, \"foo/bar/index\" becomes \"foo.bar\".\r\n * Otherwise it becomes \"foo.bar.index\".\r\n */\r\nfunction pathToKey(relNoExt: string, opts: { collapseIndex: boolean }): string {\r\n let normalized = relNoExt.replace(/\\\\/g, \"/\");\r\n\r\n if (opts.collapseIndex) {\r\n normalized = normalized.replace(/\\/index$/i, \"\");\r\n }\r\n\r\n let key = normalized.split(\"/\").filter(Boolean).join(\".\");\r\n if (!key) key = \"index\";\r\n return key;\r\n}\r\n\r\n/**\r\n * Recursively collect entry files under dirPath.\r\n *\r\n * Rule:\r\n * - Prefer collapsing \".../index.tsx\" => \"...\" for nicer keys\r\n * - BUT if that key would collide with another entry, fallback to explicit \"...index\"\r\n * (e.g. \"foo.index\") for the index file ONLY.\r\n */\r\nfunction crawl(\r\n dirPath: string,\r\n baseDir: string,\r\n acc: PluginInputs,\r\n sets: { ignoreDirs: Set<string>; componentLikeDirs: Set<string> },\r\n appEntryAbsPath: string\r\n): void {\r\n if (!fs.existsSync(dirPath)) return;\r\n\r\n for (const item of fs.readdirSync(dirPath)) {\r\n const full = path.join(dirPath, item);\r\n const stat = fs.statSync(full);\r\n\r\n if (stat.isDirectory()) {\r\n if (isIgnoredDir(item, sets)) continue;\r\n crawl(full, baseDir, acc, sets, appEntryAbsPath);\r\n continue;\r\n }\r\n\r\n if (!EXT_PATTERN.test(item)) continue;\r\n\r\n // Don't include the generated entry itself (prevents self-import)\r\n if (path.resolve(full) === path.resolve(appEntryAbsPath)) {\r\n continue;\r\n }\r\n\r\n const relNoExt = path.relative(baseDir, full).replace(EXT_PATTERN, \"\");\r\n const isIndexFile = /(^|[\\\\/])index$/i.test(relNoExt);\r\n\r\n // Preferred key: collapse \".../index\" => \"...\"\r\n const preferred = pathToKey(relNoExt, { collapseIndex: true });\r\n\r\n // Explicit key: keep \".../index\" => \"...index\"\r\n // Example: \"foo/index\" => \"foo.index\"\r\n const explicit = pathToKey(relNoExt, { collapseIndex: false });\r\n\r\n let name = preferred;\r\n\r\n // If preferred collides, ONLY the index file switches to explicit path key.\r\n const existing = acc[name];\r\n if (existing && path.resolve(existing) !== path.resolve(full)) {\r\n if (isIndexFile) {\r\n // Use foo.index (or deeper.path.index) instead of suffixing __2\r\n if (!acc[explicit]) {\r\n // eslint-disable-next-line no-console\r\n console.warn(\r\n `⚠️ Key collision for \"${preferred}\" — using \"${explicit}\" for index file`,\r\n { existing: acc[preferred], incoming: full }\r\n );\r\n name = explicit;\r\n } else {\r\n // Extremely rare: even explicit collides (e.g. duplicate paths via symlinks)\r\n let i = 2;\r\n let next = `${explicit}__${i}`;\r\n while (acc[next]) {\r\n i += 1;\r\n next = `${explicit}__${i}`;\r\n }\r\n // eslint-disable-next-line no-console\r\n console.warn(`⚠️ Key collision for \"${explicit}\" — using \"${next}\"`, {\r\n existing: acc[explicit],\r\n incoming: full,\r\n });\r\n name = next;\r\n }\r\n } else {\r\n // Non-index collision: suffix like original behavior\r\n let i = 2;\r\n let next = `${name}__${i}`;\r\n while (acc[next]) {\r\n i += 1;\r\n next = `${name}__${i}`;\r\n }\r\n // eslint-disable-next-line no-console\r\n console.warn(`⚠️ Input key collision \"${name}\" -> using \"${next}\"`, {\r\n existing: acc[name],\r\n incoming: full,\r\n });\r\n name = next;\r\n }\r\n }\r\n\r\n acc[name] = full;\r\n }\r\n}\r\n\r\n/**\r\n * Discover integration pages/components and return a Rollup input map.\r\n *\r\n * @param srcRoot absolute or relative path to the source folder (e.g. \"resources/embed/ts\")\r\n * @param options\r\n * @returns Rollup input map: { [key]: absolutePath }\r\n */\r\nexport function generatePluginInputs(\r\n srcRoot: string = path.resolve(process.cwd(), \"ts\"),\r\n options: GeneratePluginInputsOptions = {}\r\n): PluginInputs {\r\n const {\r\n writeAppEntry = true,\r\n appEntryName = \"app.tsx\",\r\n includeAppEntryInInputs = true,\r\n appEntryKey = \"__app_entry\",\r\n verbose = true,\r\n } = options;\r\n\r\n const absRoot = path.resolve(srcRoot);\r\n const inputs: PluginInputs = {};\r\n\r\n const sets = makeIgnoreSets(options);\r\n const appEntryAbsPath = path.join(absRoot, appEntryName);\r\n\r\n // Crawl everything under absRoot (no folder assumptions)\r\n crawl(absRoot, absRoot, inputs, sets, appEntryAbsPath);\r\n\r\n if (verbose) {\r\n // eslint-disable-next-line no-console\r\n console.log(\"✅ Integrations discovered:\", inputs);\r\n }\r\n\r\n if (writeAppEntry) {\r\n writeAppEntryFile(inputs, absRoot, appEntryName);\r\n }\r\n\r\n if (!includeAppEntryInInputs) return inputs;\r\n\r\n return { ...inputs, [appEntryKey]: appEntryAbsPath };\r\n}"],"mappings":";;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QACxB;AAEA,gBAAQ,KAAK,qCAA2B,IAAI,eAAe,IAAI,KAAK;AAAA,UAChE,UAAU,IAAI,IAAI;AAAA,UAClB,UAAU;AAAA,QACd,CAAC;AACD,eAAO;AAAA,MACX;AAAA,IACJ;AAEA,QAAI,IAAI,IAAI;AAAA,EAChB;AACJ;AASO,SAAS,qBACZ,UAAkB,kBAAAA,QAAK,QAAQ,QAAQ,IAAI,GAAG,IAAI,GAClD,UAAuC,CAAC,GAC5B;AACZ,QAAM;AAAA,IACF,gBAAgB;AAAA,IAChB,eAAe;AAAA,IACf,0BAA0B;AAAA,IAC1B,cAAc;AAAA,IACd,UAAU;AAAA,EACd,IAAI;AAEJ,QAAM,UAAU,kBAAAA,QAAK,QAAQ,OAAO;AACpC,QAAM,SAAuB,CAAC;AAE9B,QAAM,OAAO,eAAe,OAAO;AACnC,QAAM,kBAAkB,kBAAAA,QAAK,KAAK,SAAS,YAAY;AAGvD,QAAM,SAAS,SAAS,QAAQ,MAAM,eAAe;AAErD,MAAI,SAAS;AAET,YAAQ,IAAI,mCAA8B,MAAM;AAAA,EACpD;AAEA,MAAI,eAAe;AACf,sBAAkB,QAAQ,SAAS,YAAY;AAAA,EACnD;AAEA,MAAI,CAAC,wBAAyB,QAAO;AAErC,SAAO,EAAE,GAAG,QAAQ,CAAC,WAAW,GAAG,gBAAgB;AACvD;","names":["path","shouldInject","resolvePath","import_node_path","path"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/vite/prep.ts","../src/babel/transform.ts","../src/utils/generate-plugin-inputs.ts"],"sourcesContent":["// src/index.ts\r\nexport {default} from \"./vite/prep\";\r\nexport type {FortiPrepOptions} from \"./vite/prep\";\r\nexport type {FortiPrepTransformOptions} from \"./babel/transform\";\r\n\r\n// ✅ add this:\r\nexport {default as fortiPrepTransform} from \"./babel/transform\";\r\nexport {generatePluginInputs as discoverEntrypoints} from './utils/generate-plugin-inputs'","import { transformSync } from \"@babel/core\";\r\nimport { readFileSync, writeFileSync } from \"node:fs\";\r\nimport { dirname, resolve as resolvePath } from \"node:path\";\r\nimport type {NormalizedOutputOptions, OutputBundle, OutputOptions} from \"rollup\";\r\nimport type { Plugin as VitePlugin } from \"vite\";\r\n\r\nimport fortiPrepTransform, {\r\n type FortiPrepTransformOptions,\r\n} from \"../babel/transform\";\r\n\r\nexport type FortiPrepOptions = FortiPrepTransformOptions & {\r\n /**\r\n * Which emitted entry file extensions should be rewritten.\r\n * Default: [\".js\", \".mjs\"]\r\n */\r\n entryExtensions?: string[];\r\n\r\n /**\r\n * Vite plugin name\r\n * Default: \"fortiplugin-prep\"\r\n */\r\n pluginName?: string;\r\n};\r\n\r\nconst DEFAULT_INJECTED_IDS = [\"react\", \"react/jsx-runtime\"] as const;\r\nconst DEFAULT_INJECTED_PREFIXES = [\"@inertiajs/\", \"@host/\"] as const;\r\n\r\nfunction resolveOutDir(outputOptions: OutputOptions): string | null {\r\n if (outputOptions.dir) return outputOptions.dir;\r\n if (outputOptions.file) return dirname(outputOptions.file);\r\n return null;\r\n}\r\n\r\nfunction shouldInject(id: string, opts: FortiPrepTransformOptions): boolean {\r\n const ids = opts.injectedIds ?? [];\r\n const prefixes = opts.injectedPrefixes ?? [];\r\n if (ids.includes(id)) return true;\r\n for (const p of prefixes) if (id.startsWith(p)) return true;\r\n return false;\r\n}\r\n\r\n/**\r\n * FortiPlugin bundle adapter:\r\n * - marks injected imports as Rollup externals (so they survive into output)\r\n * - rewrites built entry chunks to remove those imports and load them from runtime deps\r\n */\r\nexport default function prep(options: FortiPrepOptions = {}): VitePlugin {\r\n const injectedIds = options.injectedIds ?? [...DEFAULT_INJECTED_IDS];\r\n const injectedPrefixes = options.injectedPrefixes ?? [...DEFAULT_INJECTED_PREFIXES];\r\n\r\n const runtimeKey = options.runtimeKey ?? \"imports\";\r\n const depsParam = options.depsParam ?? \"deps\";\r\n\r\n const entryExtensions = options.entryExtensions ?? [\".js\", \".mjs\"];\r\n const pluginName = options.pluginName ?? \"fortiplugin-prep\";\r\n\r\n const transformOptions: FortiPrepTransformOptions = {\r\n injectedIds,\r\n injectedPrefixes,\r\n runtimeKey,\r\n depsParam,\r\n };\r\n\r\n return {\r\n name: pluginName,\r\n apply: \"build\",\r\n\r\n config() {\r\n return {\r\n define: {\r\n \"process.env.NODE_ENV\": '\"production\"',\r\n },\r\n build: {\r\n rollupOptions: {\r\n // Ensure virtual imports don't need to resolve.\r\n external: (id: string) => shouldInject(id, transformOptions),\r\n },\r\n },\r\n };\r\n },\r\n\r\n writeBundle(outputOptions: NormalizedOutputOptions, bundle: OutputBundle) {\r\n const outDir = resolveOutDir(outputOptions);\r\n if (!outDir) return;\r\n\r\n for (const [fileName, item] of Object.entries(bundle)) {\r\n if (item.type !== \"chunk\") continue;\r\n if (!item.isEntry) continue;\r\n\r\n if (!entryExtensions.some((ext) => fileName.endsWith(ext))) continue;\r\n\r\n const absPath = resolvePath(outDir, fileName);\r\n const input = readFileSync(absPath, \"utf-8\");\r\n\r\n const result = transformSync(input, {\r\n filename: absPath,\r\n sourceType: \"module\",\r\n // Fresh plugin instance per file (Babel calls plugin factory per file when passed as [fn, opts])\r\n plugins: [[fortiPrepTransform as any, transformOptions]],\r\n generatorOpts: {\r\n compact: false,\r\n comments: true,\r\n retainLines: false,\r\n },\r\n });\r\n\r\n if (!result?.code) continue;\r\n writeFileSync(absPath, result.code, \"utf-8\");\r\n }\r\n },\r\n };\r\n}","// noinspection JSUnusedGlobalSymbols,GrazieInspection\r\n\r\nimport type {PluginObj} from \"@babel/core\";\r\nimport * as t from \"@babel/types\";\r\nimport type {NodePath} from \"@babel/traverse\";\r\n\r\nexport type FortiPrepTransformOptions = {\r\n /**\r\n * Exact import ids to inject (removed from bundle and loaded from runtime deps).\r\n * Example: [\"react\", \"react/jsx-runtime\", \"@host/ui\"]\r\n */\r\n injectedIds?: string[];\r\n\r\n /**\r\n * Prefix import ids to inject.\r\n * Example: [\"@host/\", \"@inertiajs/\"]\r\n */\r\n injectedPrefixes?: string[];\r\n\r\n /**\r\n * The key on the deps object used as the import map.\r\n * Wrapper supports passing deps.imports OR passing the import map directly.\r\n *\r\n * Default: \"imports\"\r\n */\r\n runtimeKey?: string;\r\n\r\n /**\r\n * Wrapper function parameter name.\r\n * Default: \"deps\"\r\n */\r\n depsParam?: string;\r\n\r\n /**\r\n * What to do if we can't determine a default export to return.\r\n *\r\n * - \"skip\": do nothing (leave file untouched) ✅ default\r\n * - \"return-null\": still wrap, but return null\r\n * - \"throw\": fail the build (old behavior)\r\n */\r\n onMissingDefault?: \"skip\" | \"return-null\" | \"throw\";\r\n};\r\n\r\nconst DEFAULTS: Required<\r\n Pick<FortiPrepTransformOptions, \"runtimeKey\" | \"depsParam\" | \"onMissingDefault\">\r\n> = {\r\n runtimeKey: \"imports\",\r\n depsParam: \"deps\",\r\n onMissingDefault: \"skip\",\r\n};\r\n\r\nconst DEFAULT_EXPORT_ERROR =\r\n \"PROBLEM!!, No known default function was found, your code either possesses NO named default export or this export format is currently not supported.\";\r\n\r\nfunction shouldInject(id: string, opts: FortiPrepTransformOptions): boolean {\r\n const ids = opts.injectedIds ?? [];\r\n const prefixes = opts.injectedPrefixes ?? [];\r\n if (ids.includes(id)) return true;\r\n for (const p of prefixes) if (id.startsWith(p)) return true;\r\n return false;\r\n}\r\n\r\nfunction programHasDefaultExport(p: t.Program): boolean {\r\n for (const stmt of p.body) {\r\n if (t.isExportDefaultDeclaration(stmt)) return true;\r\n\r\n // Rollup-style: export { Foo as default }\r\n if (t.isExportNamedDeclaration(stmt) && stmt.specifiers?.length) {\r\n for (const spec of stmt.specifiers) {\r\n const exported = t.isIdentifier(spec.exported)\r\n ? spec.exported.name\r\n : spec.exported.value;\r\n if (exported === \"default\") return true;\r\n }\r\n }\r\n }\r\n return false;\r\n}\r\n\r\ntype CapturedImport =\r\n | { kind: \"default\"; local: string }\r\n | { kind: \"namespace\"; local: string }\r\n | { kind: \"named\"; imported: string; local: string };\r\n\r\nfunction getImportedName(spec: t.ImportSpecifier): string {\r\n return t.isIdentifier(spec.imported) ? spec.imported.name : spec.imported.value;\r\n}\r\n\r\nfunction makeImportMapExpr(depsIdent: t.Identifier, runtimeKey: string): t.Expression {\r\n // Support both:\r\n // factory({ imports: { ... } })\r\n // and:\r\n // factory({ ... }) // direct import map\r\n //\r\n // const __imports =\r\n // deps && typeof deps === \"object\" && \"imports\" in deps\r\n // ? deps.imports\r\n // : (deps || {});\r\n const hasKey = t.binaryExpression(\"in\", t.stringLiteral(runtimeKey), depsIdent);\r\n\r\n const isObj = t.logicalExpression(\r\n \"&&\",\r\n t.binaryExpression(\"!==\", depsIdent, t.nullLiteral()),\r\n t.binaryExpression(\r\n \"===\",\r\n t.unaryExpression(\"typeof\", depsIdent),\r\n t.stringLiteral(\"object\")\r\n )\r\n );\r\n\r\n const test = t.logicalExpression(\"&&\", isObj, hasKey);\r\n\r\n const depsKey = t.memberExpression(depsIdent, t.identifier(runtimeKey));\r\n const fallback = t.logicalExpression(\"||\", depsIdent, t.objectExpression([]));\r\n\r\n return t.conditionalExpression(test, depsKey, fallback);\r\n}\r\n\r\n/**\r\n * Babel plugin factory (Babel calls this per-file when used as `[plugin, options]`).\r\n */\r\nexport default function fortiPrepTransform(\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n _api: unknown,\r\n rawOpts: FortiPrepTransformOptions = {}\r\n): PluginObj {\r\n const opts: FortiPrepTransformOptions = {\r\n ...rawOpts,\r\n runtimeKey: rawOpts.runtimeKey ?? DEFAULTS.runtimeKey,\r\n depsParam: rawOpts.depsParam ?? DEFAULTS.depsParam,\r\n onMissingDefault: rawOpts.onMissingDefault ?? DEFAULTS.onMissingDefault,\r\n };\r\n\r\n // If false, we do NOTHING to this file (silent ignore).\r\n let enabled = true;\r\n\r\n // per-file state (because Babel calls the plugin per file)\r\n const keptImports: t.ImportDeclaration[] = [];\r\n const keptNamedExports: t.ExportNamedDeclaration[] = [];\r\n\r\n const injectedImportsById = new Map<string, CapturedImport[]>();\r\n\r\n let defaultExportLocalName: string | null = null;\r\n let returnDefaultProperty = false;\r\n\r\n function captureImport(importId: string, entry: CapturedImport) {\r\n const list = injectedImportsById.get(importId) ?? [];\r\n list.push(entry);\r\n injectedImportsById.set(importId, list);\r\n }\r\n\r\n return {\r\n name: \"fortiplugin-prep/transform\",\r\n visitor: {\r\n Program: {\r\n enter(path: NodePath<t.Program>) {\r\n // If there's no default export and behavior is \"skip\", silently do nothing.\r\n const hasDefault = programHasDefaultExport(path.node);\r\n if (!hasDefault && (opts.onMissingDefault ?? DEFAULTS.onMissingDefault) === \"skip\") {\r\n enabled = false;\r\n }\r\n },\r\n\r\n exit(path: NodePath<t.Program>) {\r\n if (!enabled) return;\r\n\r\n const program = path.node;\r\n\r\n // If we still couldn't resolve the default export name, decide behavior.\r\n if (!defaultExportLocalName) {\r\n const behavior = opts.onMissingDefault ?? DEFAULTS.onMissingDefault;\r\n\r\n if (behavior === \"throw\") {\r\n throw path.buildCodeFrameError(DEFAULT_EXPORT_ERROR);\r\n }\r\n\r\n // \"return-null\": wrap but return null.\r\n // (Note: \"skip\" mode should have disabled earlier, but this is a safe fallback.)\r\n defaultExportLocalName = null;\r\n }\r\n\r\n const depsIdent = t.identifier(opts.depsParam ?? DEFAULTS.depsParam);\r\n const runtimeKey = opts.runtimeKey ?? DEFAULTS.runtimeKey;\r\n\r\n // const __imports = (deps has runtimeKey) ? deps[runtimeKey] : (deps || {});\r\n const importsIdent = t.identifier(\"__imports\");\r\n const importsInit = makeImportMapExpr(depsIdent, runtimeKey);\r\n const importsDecl = t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(importsIdent, importsInit),\r\n ]);\r\n\r\n // const __default = (m) => (m && typeof m === \"object\" && \"default\" in m ? m.default : m);\r\n const defaultHelperIdent = t.identifier(\"__default\");\r\n const defaultHelperDecl = t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(\r\n defaultHelperIdent,\r\n t.arrowFunctionExpression(\r\n [t.identifier(\"m\")],\r\n t.conditionalExpression(\r\n t.logicalExpression(\r\n \"&&\",\r\n t.logicalExpression(\r\n \"&&\",\r\n t.identifier(\"m\"),\r\n t.binaryExpression(\r\n \"===\",\r\n t.unaryExpression(\"typeof\", t.identifier(\"m\")),\r\n t.stringLiteral(\"object\")\r\n )\r\n ),\r\n t.binaryExpression(\"in\", t.stringLiteral(\"default\"), t.identifier(\"m\"))\r\n ),\r\n t.memberExpression(t.identifier(\"m\"), t.identifier(\"default\")),\r\n t.identifier(\"m\")\r\n )\r\n )\r\n ),\r\n ]);\r\n\r\n // Build injected module locals inside wrapper\r\n const injectedStmts: t.Statement[] = [importsDecl, defaultHelperDecl];\r\n\r\n for (const [importId, specs] of injectedImportsById.entries()) {\r\n const modIdent = t.identifier(\r\n `__m_${importId.replace(/[^a-zA-Z0-9_$]/g, \"_\")}`\r\n );\r\n\r\n // const __m_xxx = __imports[\"<importId>\"];\r\n injectedStmts.push(\r\n t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(\r\n modIdent,\r\n t.memberExpression(importsIdent, t.stringLiteral(importId), true)\r\n ),\r\n ])\r\n );\r\n\r\n const named: Array<{ imported: string; local: string }> = [];\r\n\r\n for (const s of specs) {\r\n if (s.kind === \"default\") {\r\n // const Local = __default(__m_xxx);\r\n injectedStmts.push(\r\n t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(\r\n t.identifier(s.local),\r\n t.callExpression(defaultHelperIdent, [modIdent])\r\n ),\r\n ])\r\n );\r\n } else if (s.kind === \"namespace\") {\r\n // const Local = __m_xxx;\r\n injectedStmts.push(\r\n t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(t.identifier(s.local), modIdent),\r\n ])\r\n );\r\n } else {\r\n named.push({imported: s.imported, local: s.local});\r\n }\r\n }\r\n\r\n if (named.length) {\r\n // const { A, B: C } = (__m_xxx || {});\r\n injectedStmts.push(\r\n t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(\r\n t.objectPattern(\r\n named.map(({imported, local}) =>\r\n t.objectProperty(\r\n t.identifier(imported),\r\n t.identifier(local),\r\n false,\r\n imported === local\r\n )\r\n )\r\n ),\r\n t.logicalExpression(\"||\", modIdent, t.objectExpression([]))\r\n ),\r\n ])\r\n );\r\n }\r\n }\r\n\r\n const returnExpr =\r\n defaultExportLocalName == null\r\n ? t.nullLiteral()\r\n : returnDefaultProperty\r\n ? t.memberExpression(t.identifier(defaultExportLocalName), t.identifier(\"default\"))\r\n : t.identifier(defaultExportLocalName);\r\n\r\n // Wrapper body:\r\n // injectedStmts...\r\n // <original body>\r\n // return <defaultExport>\r\n const wrapperBody: t.Statement[] = [];\r\n wrapperBody.push(...injectedStmts);\r\n wrapperBody.push(...program.body);\r\n wrapperBody.push(t.returnStatement(returnExpr));\r\n\r\n const wrapper = t.exportDefaultDeclaration(\r\n t.functionDeclaration(null, [depsIdent], t.blockStatement(wrapperBody))\r\n );\r\n\r\n // Final program:\r\n // kept imports at module scope\r\n // export default function(deps) { ... }\r\n // kept named exports (same as your old behavior)\r\n program.body = [...keptImports, wrapper, ...keptNamedExports] as any;\r\n },\r\n },\r\n\r\n ImportDeclaration(path: NodePath<t.ImportDeclaration>) {\r\n if (!enabled) return;\r\n\r\n const node = path.node;\r\n const importId = node.source.value;\r\n\r\n if (!shouldInject(importId, opts)) {\r\n keptImports.push(node);\r\n path.remove();\r\n return;\r\n }\r\n\r\n // Remove injected import and capture its specifiers to recreate inside wrapper.\r\n for (const s of node.specifiers) {\r\n if (t.isImportDefaultSpecifier(s)) {\r\n captureImport(importId, {kind: \"default\", local: s.local.name});\r\n } else if (t.isImportNamespaceSpecifier(s)) {\r\n captureImport(importId, {kind: \"namespace\", local: s.local.name});\r\n } else if (t.isImportSpecifier(s)) {\r\n captureImport(importId, {\r\n kind: \"named\",\r\n imported: getImportedName(s),\r\n local: s.local.name,\r\n });\r\n }\r\n }\r\n\r\n // side-effect-only injected imports (import \"@host/ui\") become no-ops at runtime\r\n path.remove();\r\n },\r\n\r\n ExportDefaultDeclaration(path: NodePath<t.ExportDefaultDeclaration>) {\r\n if (!enabled) return;\r\n\r\n const decl = path.node.declaration;\r\n\r\n // export default Foo;\r\n if (t.isIdentifier(decl)) {\r\n defaultExportLocalName = decl.name;\r\n path.remove();\r\n return;\r\n }\r\n\r\n // export default function (...) {}\r\n // export default class {...}\r\n // Keep as declaration (valid) and remember its id.\r\n if (t.isFunctionDeclaration(decl) || t.isClassDeclaration(decl)) {\r\n if (!decl.id) {\r\n decl.id = path.scope.generateUidIdentifier(\"defaultExport\");\r\n }\r\n defaultExportLocalName = decl.id.name;\r\n path.replaceWith(decl);\r\n return;\r\n }\r\n\r\n // export default (expr/arrow/etc)\r\n const id = path.scope.generateUidIdentifier(\"defaultExport\");\r\n path.replaceWith(\r\n t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(id, decl as t.Expression),\r\n ])\r\n );\r\n defaultExportLocalName = id.name;\r\n },\r\n\r\n ExportNamedDeclaration(path: NodePath<t.ExportNamedDeclaration>) {\r\n if (!enabled) return;\r\n\r\n const node = path.node;\r\n\r\n // Detect Rollup-style: export { Foo as default }\r\n if (node.specifiers?.length) {\r\n let foundExplicitDefault = false;\r\n\r\n node.specifiers = node.specifiers.filter((spec) => {\r\n const exported = t.isIdentifier(spec.exported)\r\n ? spec.exported.name\r\n : spec.exported.value;\r\n\r\n if (exported === \"default\") {\r\n const local = (spec as any)?.local?.name as string | undefined;\r\n if (local) defaultExportLocalName = local;\r\n foundExplicitDefault = true;\r\n return false; // remove the default specifier\r\n }\r\n\r\n return true;\r\n });\r\n\r\n // Minified fallback behavior:\r\n // If no default specifier found and exactly one spec exists,\r\n // treat it as the container and return `<local>.default`.\r\n if (\r\n !foundExplicitDefault &&\r\n !defaultExportLocalName &&\r\n node.specifiers.length === 1\r\n ) {\r\n const only = node.specifiers[0] as any;\r\n if (only?.local?.name) {\r\n defaultExportLocalName = only.local.name;\r\n returnDefaultProperty = true;\r\n node.specifiers = [];\r\n }\r\n }\r\n }\r\n\r\n // Keep named exports after wrapper (same as prior behavior),\r\n // BUT do not keep empty export declarations.\r\n if (node.declaration || (node.specifiers && node.specifiers.length > 0)) {\r\n keptNamedExports.push(node);\r\n }\r\n\r\n path.remove();\r\n },\r\n },\r\n };\r\n}","// src/utils/generate-plugin-inputs.ts\r\nimport path from \"node:path\";\r\nimport * as fs from \"node:fs\";\r\n\r\nconst EXT_PATTERN = /\\.(tsx?|jsx?)$/i;\r\n\r\nexport type PluginInputs = Record<string, string>;\r\n\r\nexport type GeneratePluginInputsOptions = {\r\n /**\r\n * If true, also generates `app.tsx` that imports every discovered entry\r\n * (handy for dev/HMR).\r\n *\r\n * Default: true\r\n */\r\n writeAppEntry?: boolean;\r\n\r\n /**\r\n * Name of the generated app entry file (inside srcRoot).\r\n *\r\n * Default: \"app.tsx\"\r\n */\r\n appEntryName?: string;\r\n\r\n /**\r\n * Adds the generated app entry to the returned Rollup inputs map.\r\n *\r\n * Default: true\r\n */\r\n includeAppEntryInInputs?: boolean;\r\n\r\n /**\r\n * Key name used for the generated app entry in Rollup inputs.\r\n *\r\n * Default: \"__app_entry\"\r\n */\r\n appEntryKey?: string;\r\n\r\n /**\r\n * Extra directory names to ignore (case-insensitive).\r\n */\r\n ignoreDirs?: string[];\r\n\r\n /**\r\n * Extra “component-like” directory names to ignore (case-insensitive, exact match).\r\n */\r\n componentLikeDirs?: string[];\r\n\r\n /**\r\n * Whether to print discovered inputs to console.\r\n *\r\n * Default: true\r\n */\r\n verbose?: boolean;\r\n};\r\n\r\n// folders you typically never want as rollup inputs\r\nconst DEFAULT_IGNORE_DIRS = new Set<string>([\r\n \"node_modules\",\r\n \".git\",\r\n \".vite\",\r\n \".internal\",\r\n \"dist\",\r\n \"build\",\r\n \"public\",\r\n]);\r\n\r\n// “component-like” folders that should NOT produce entrypoints\r\n// Strict: exact folder-name matches only (case-insensitive)\r\nconst DEFAULT_COMPONENT_LIKE_DIRS = new Set<string>([\r\n \"component\",\r\n \"components\",\r\n \"ui\",\r\n \"uis\",\r\n \"widget\",\r\n \"widgets\",\r\n \"atom\",\r\n \"atoms\",\r\n \"molecule\",\r\n \"molecules\",\r\n \"organism\",\r\n \"organisms\",\r\n \"layout\",\r\n \"layouts\",\r\n \"partial\",\r\n \"partials\",\r\n]);\r\n\r\nfunction normalizeName(x: unknown): string {\r\n return String(x ?? \"\").toLowerCase();\r\n}\r\n\r\nfunction makeIgnoreSets(opts?: GeneratePluginInputsOptions): {\r\n ignoreDirs: Set<string>;\r\n componentLikeDirs: Set<string>;\r\n} {\r\n const ignoreDirs = new Set(DEFAULT_IGNORE_DIRS);\r\n const componentLikeDirs = new Set(DEFAULT_COMPONENT_LIKE_DIRS);\r\n\r\n for (const d of opts?.ignoreDirs ?? []) ignoreDirs.add(normalizeName(d));\r\n for (const d of opts?.componentLikeDirs ?? []) componentLikeDirs.add(normalizeName(d));\r\n\r\n return { ignoreDirs, componentLikeDirs };\r\n}\r\n\r\nfunction isIgnoredDir(\r\n dirName: string,\r\n sets: { ignoreDirs: Set<string>; componentLikeDirs: Set<string> }\r\n): boolean {\r\n const name = normalizeName(dirName);\r\n return sets.ignoreDirs.has(name) || sets.componentLikeDirs.has(name);\r\n}\r\n\r\n/**\r\n * Creates an app.tsx file that simply imports every discovered entry.\r\n * Helpful for HMR / dev mode.\r\n */\r\nfunction writeAppEntryFile(inputs: PluginInputs, srcRoot: string, appEntryName: string): void {\r\n const app = path.join(srcRoot, appEntryName);\r\n const lines: string[] = [\"// Auto-generated – do not edit\", \"\"];\r\n\r\n const entries = Object.entries(inputs).sort(([a], [b]) => a.localeCompare(b));\r\n\r\n for (const [name, full] of entries) {\r\n const rel =\r\n \"./\" + path.relative(srcRoot, full).replace(/\\\\/g, \"/\").replace(EXT_PATTERN, \"\");\r\n\r\n const variable = name.replace(/[^a-zA-Z0-9_$]/g, \"_\").replace(/^(\\d)/, \"_$1\");\r\n\r\n lines.push(`import * as ${variable} from '${rel}';`);\r\n lines.push(`console.log('${name} loaded:', ${variable});`, \"\");\r\n }\r\n\r\n fs.writeFileSync(app, lines.join(\"\\n\"), \"utf8\");\r\n // eslint-disable-next-line no-console\r\n console.log(`✅ Generated ${appEntryName} in ${srcRoot}`);\r\n}\r\n\r\n/**\r\n * Convert a relative path like \"foo/bar/index.tsx\" to a dot key.\r\n * If `collapseIndex` is true, \"foo/bar/index\" becomes \"foo.bar\".\r\n * Otherwise it becomes \"foo.bar.index\".\r\n */\r\nfunction pathToKey(relNoExt: string, opts: { collapseIndex: boolean }): string {\r\n let normalized = relNoExt.replace(/\\\\/g, \"/\");\r\n\r\n if (opts.collapseIndex) {\r\n normalized = normalized.replace(/\\/index$/i, \"\");\r\n }\r\n\r\n let key = normalized.split(\"/\").filter(Boolean).join(\".\");\r\n if (!key) key = \"index\";\r\n return key;\r\n}\r\n\r\n/**\r\n * Recursively collect entry files under dirPath.\r\n *\r\n * Rule:\r\n * - Prefer collapsing \".../index.tsx\" => \"...\" for nicer keys\r\n * - BUT if that key would collide with another entry, fallback to explicit \"...index\"\r\n * (e.g. \"foo.index\") for the index file ONLY.\r\n */\r\nfunction crawl(\r\n dirPath: string,\r\n baseDir: string,\r\n acc: PluginInputs,\r\n sets: { ignoreDirs: Set<string>; componentLikeDirs: Set<string> },\r\n appEntryAbsPath: string\r\n): void {\r\n if (!fs.existsSync(dirPath)) return;\r\n\r\n for (const item of fs.readdirSync(dirPath)) {\r\n const full = path.join(dirPath, item);\r\n const stat = fs.statSync(full);\r\n\r\n if (stat.isDirectory()) {\r\n if (isIgnoredDir(item, sets)) continue;\r\n crawl(full, baseDir, acc, sets, appEntryAbsPath);\r\n continue;\r\n }\r\n\r\n if (!EXT_PATTERN.test(item)) continue;\r\n\r\n // Don't include the generated entry itself (prevents self-import)\r\n if (path.resolve(full) === path.resolve(appEntryAbsPath)) {\r\n continue;\r\n }\r\n\r\n const relNoExt = path.relative(baseDir, full).replace(EXT_PATTERN, \"\");\r\n const isIndexFile = /(^|[\\\\/])index$/i.test(relNoExt);\r\n\r\n // Preferred key: collapse \".../index\" => \"...\"\r\n const preferred = pathToKey(relNoExt, { collapseIndex: true });\r\n\r\n // Explicit key: keep \".../index\" => \"...index\"\r\n // Example: \"foo/index\" => \"foo.index\"\r\n const explicit = pathToKey(relNoExt, { collapseIndex: false });\r\n\r\n let name = preferred;\r\n\r\n // If preferred collides, ONLY the index file switches to explicit path key.\r\n const existing = acc[name];\r\n if (existing && path.resolve(existing) !== path.resolve(full)) {\r\n if (isIndexFile) {\r\n // Use foo.index (or deeper.path.index) instead of suffixing __2\r\n if (!acc[explicit]) {\r\n // eslint-disable-next-line no-console\r\n console.warn(\r\n `⚠️ Key collision for \"${preferred}\" — using \"${explicit}\" for index file`,\r\n { existing: acc[preferred], incoming: full }\r\n );\r\n name = explicit;\r\n } else {\r\n // Extremely rare: even explicit collides (e.g. duplicate paths via symlinks)\r\n let i = 2;\r\n let next = `${explicit}__${i}`;\r\n while (acc[next]) {\r\n i += 1;\r\n next = `${explicit}__${i}`;\r\n }\r\n // eslint-disable-next-line no-console\r\n console.warn(`⚠️ Key collision for \"${explicit}\" — using \"${next}\"`, {\r\n existing: acc[explicit],\r\n incoming: full,\r\n });\r\n name = next;\r\n }\r\n } else {\r\n // Non-index collision: suffix like original behavior\r\n let i = 2;\r\n let next = `${name}__${i}`;\r\n while (acc[next]) {\r\n i += 1;\r\n next = `${name}__${i}`;\r\n }\r\n // eslint-disable-next-line no-console\r\n console.warn(`⚠️ Input key collision \"${name}\" -> using \"${next}\"`, {\r\n existing: acc[name],\r\n incoming: full,\r\n });\r\n name = next;\r\n }\r\n }\r\n\r\n acc[name] = full;\r\n }\r\n}\r\n\r\n/**\r\n * Discover integration pages/components and return a Rollup input map.\r\n *\r\n * @param srcRoot absolute or relative path to the source folder (e.g. \"resources/embed/ts\")\r\n * @param options\r\n * @returns Rollup input map: { [key]: absolutePath }\r\n */\r\nexport function generatePluginInputs(\r\n srcRoot: string = path.resolve(process.cwd(), \"ts\"),\r\n options: GeneratePluginInputsOptions = {}\r\n): PluginInputs {\r\n const {\r\n writeAppEntry = true,\r\n appEntryName = \"app.tsx\",\r\n includeAppEntryInInputs = true,\r\n appEntryKey = \"__app_entry\",\r\n verbose = true,\r\n } = options;\r\n\r\n const absRoot = path.resolve(srcRoot);\r\n const inputs: PluginInputs = {};\r\n\r\n const sets = makeIgnoreSets(options);\r\n const appEntryAbsPath = path.join(absRoot, appEntryName);\r\n\r\n // Crawl everything under absRoot (no folder assumptions)\r\n crawl(absRoot, absRoot, inputs, sets, appEntryAbsPath);\r\n\r\n if (verbose) {\r\n // eslint-disable-next-line no-console\r\n console.log(\"✅ Integrations discovered:\", inputs);\r\n }\r\n\r\n if (writeAppEntry) {\r\n writeAppEntryFile(inputs, absRoot, appEntryName);\r\n }\r\n\r\n if (!includeAppEntryInInputs) return inputs;\r\n\r\n return { ...inputs, [appEntryKey]: appEntryAbsPath };\r\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA8B;AAC9B,qBAA4C;AAC5C,uBAAgD;;;ACChD,QAAmB;AAwCnB,IAAM,WAEF;AAAA,EACA,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,kBAAkB;AACtB;AAEA,IAAM,uBACF;AAEJ,SAAS,aAAa,IAAY,MAA0C;AACxE,QAAM,MAAM,KAAK,eAAe,CAAC;AACjC,QAAM,WAAW,KAAK,oBAAoB,CAAC;AAC3C,MAAI,IAAI,SAAS,EAAE,EAAG,QAAO;AAC7B,aAAW,KAAK,SAAU,KAAI,GAAG,WAAW,CAAC,EAAG,QAAO;AACvD,SAAO;AACX;AAEA,SAAS,wBAAwB,GAAuB;AACpD,aAAW,QAAQ,EAAE,MAAM;AACvB,QAAM,6BAA2B,IAAI,EAAG,QAAO;AAG/C,QAAM,2BAAyB,IAAI,KAAK,KAAK,YAAY,QAAQ;AAC7D,iBAAW,QAAQ,KAAK,YAAY;AAChC,cAAM,WAAa,eAAa,KAAK,QAAQ,IACvC,KAAK,SAAS,OACd,KAAK,S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package/dist/index.d.mts CHANGED
@@ -24,6 +24,14 @@ type FortiPrepTransformOptions = {
24
24
  * Default: "deps"
25
25
  */
26
26
  depsParam?: string;
27
+ /**
28
+ * What to do if we can't determine a default export to return.
29
+ *
30
+ * - "skip": do nothing (leave file untouched) ✅ default
31
+ * - "return-null": still wrap, but return null
32
+ * - "throw": fail the build (old behavior)
33
+ */
34
+ onMissingDefault?: "skip" | "return-null" | "throw";
27
35
  };
28
36
  /**
29
37
  * Babel plugin factory (Babel calls this per-file when used as `[plugin, options]`).
package/dist/index.d.ts CHANGED
@@ -24,6 +24,14 @@ type FortiPrepTransformOptions = {
24
24
  * Default: "deps"
25
25
  */
26
26
  depsParam?: string;
27
+ /**
28
+ * What to do if we can't determine a default export to return.
29
+ *
30
+ * - "skip": do nothing (leave file untouched) ✅ default
31
+ * - "return-null": still wrap, but return null
32
+ * - "throw": fail the build (old behavior)
33
+ */
34
+ onMissingDefault?: "skip" | "return-null" | "throw";
27
35
  };
28
36
  /**
29
37
  * Babel plugin factory (Babel calls this per-file when used as `[plugin, options]`).
package/dist/index.mjs CHANGED
@@ -7,7 +7,8 @@ import { dirname, resolve as resolvePath } from "path";
7
7
  import * as t from "@babel/types";
8
8
  var DEFAULTS = {
9
9
  runtimeKey: "imports",
10
- depsParam: "deps"
10
+ depsParam: "deps",
11
+ onMissingDefault: "skip"
11
12
  };
12
13
  var DEFAULT_EXPORT_ERROR = "PROBLEM!!, No known default function was found, your code either possesses NO named default export or this export format is currently not supported.";
13
14
  function shouldInject(id, opts) {
@@ -17,19 +18,31 @@ function shouldInject(id, opts) {
17
18
  for (const p of prefixes) if (id.startsWith(p)) return true;
18
19
  return false;
19
20
  }
21
+ function programHasDefaultExport(p) {
22
+ for (const stmt of p.body) {
23
+ if (t.isExportDefaultDeclaration(stmt)) return true;
24
+ if (t.isExportNamedDeclaration(stmt) && stmt.specifiers?.length) {
25
+ for (const spec of stmt.specifiers) {
26
+ const exported = t.isIdentifier(spec.exported) ? spec.exported.name : spec.exported.value;
27
+ if (exported === "default") return true;
28
+ }
29
+ }
30
+ }
31
+ return false;
32
+ }
20
33
  function getImportedName(spec) {
21
34
  return t.isIdentifier(spec.imported) ? spec.imported.name : spec.imported.value;
22
35
  }
23
36
  function makeImportMapExpr(depsIdent, runtimeKey) {
24
- const hasKey = t.binaryExpression(
25
- "in",
26
- t.stringLiteral(runtimeKey),
27
- depsIdent
28
- );
37
+ const hasKey = t.binaryExpression("in", t.stringLiteral(runtimeKey), depsIdent);
29
38
  const isObj = t.logicalExpression(
30
39
  "&&",
31
40
  t.binaryExpression("!==", depsIdent, t.nullLiteral()),
32
- t.binaryExpression("===", t.unaryExpression("typeof", depsIdent), t.stringLiteral("object"))
41
+ t.binaryExpression(
42
+ "===",
43
+ t.unaryExpression("typeof", depsIdent),
44
+ t.stringLiteral("object")
45
+ )
33
46
  );
34
47
  const test = t.logicalExpression("&&", isObj, hasKey);
35
48
  const depsKey = t.memberExpression(depsIdent, t.identifier(runtimeKey));
@@ -40,8 +53,10 @@ function fortiPrepTransform(_api, rawOpts = {}) {
40
53
  const opts = {
41
54
  ...rawOpts,
42
55
  runtimeKey: rawOpts.runtimeKey ?? DEFAULTS.runtimeKey,
43
- depsParam: rawOpts.depsParam ?? DEFAULTS.depsParam
56
+ depsParam: rawOpts.depsParam ?? DEFAULTS.depsParam,
57
+ onMissingDefault: rawOpts.onMissingDefault ?? DEFAULTS.onMissingDefault
44
58
  };
59
+ let enabled = true;
45
60
  const keptImports = [];
46
61
  const keptNamedExports = [];
47
62
  const injectedImportsById = /* @__PURE__ */ new Map();
@@ -55,73 +70,22 @@ function fortiPrepTransform(_api, rawOpts = {}) {
55
70
  return {
56
71
  name: "fortiplugin-prep/transform",
57
72
  visitor: {
58
- ImportDeclaration(path2) {
59
- const node = path2.node;
60
- const importId = node.source.value;
61
- if (!shouldInject(importId, opts)) {
62
- keptImports.push(node);
63
- path2.remove();
64
- return;
65
- }
66
- for (const s of node.specifiers) {
67
- if (t.isImportDefaultSpecifier(s)) {
68
- captureImport(importId, { kind: "default", local: s.local.name });
69
- } else if (t.isImportNamespaceSpecifier(s)) {
70
- captureImport(importId, { kind: "namespace", local: s.local.name });
71
- } else if (t.isImportSpecifier(s)) {
72
- captureImport(importId, {
73
- kind: "named",
74
- imported: getImportedName(s),
75
- local: s.local.name
76
- });
77
- }
78
- }
79
- path2.remove();
80
- },
81
- ExportDefaultDeclaration(path2) {
82
- const decl = path2.node.declaration;
83
- if (t.isIdentifier(decl)) {
84
- defaultExportLocalName = decl.name;
85
- path2.remove();
86
- return;
87
- }
88
- const id = path2.scope.generateUidIdentifier("defaultExport");
89
- path2.replaceWith(
90
- t.variableDeclaration("const", [t.variableDeclarator(id, decl)])
91
- );
92
- defaultExportLocalName = id.name;
93
- },
94
- ExportNamedDeclaration(path2) {
95
- const node = path2.node;
96
- keptNamedExports.push(node);
97
- if (node.specifiers?.length) {
98
- let foundExplicitDefault = false;
99
- node.specifiers = node.specifiers.filter((spec) => {
100
- const exported = t.isIdentifier(spec.exported) ? spec.exported.name : spec.exported.value;
101
- if (exported === "default") {
102
- const local = spec?.local?.name;
103
- if (local) defaultExportLocalName = local;
104
- foundExplicitDefault = true;
105
- return false;
106
- }
107
- return true;
108
- });
109
- if (!foundExplicitDefault && !defaultExportLocalName && node.specifiers.length === 1) {
110
- const only = node.specifiers[0];
111
- if (only?.local?.name) {
112
- defaultExportLocalName = only.local.name;
113
- returnDefaultProperty = true;
114
- node.specifiers = [];
115
- }
116
- }
117
- }
118
- path2.remove();
119
- },
120
73
  Program: {
74
+ enter(path2) {
75
+ const hasDefault = programHasDefaultExport(path2.node);
76
+ if (!hasDefault && (opts.onMissingDefault ?? DEFAULTS.onMissingDefault) === "skip") {
77
+ enabled = false;
78
+ }
79
+ },
121
80
  exit(path2) {
81
+ if (!enabled) return;
122
82
  const program = path2.node;
123
83
  if (!defaultExportLocalName) {
124
- throw path2.buildCodeFrameError(DEFAULT_EXPORT_ERROR);
84
+ const behavior = opts.onMissingDefault ?? DEFAULTS.onMissingDefault;
85
+ if (behavior === "throw") {
86
+ throw path2.buildCodeFrameError(DEFAULT_EXPORT_ERROR);
87
+ }
88
+ defaultExportLocalName = null;
125
89
  }
126
90
  const depsIdent = t.identifier(opts.depsParam ?? DEFAULTS.depsParam);
127
91
  const runtimeKey = opts.runtimeKey ?? DEFAULTS.runtimeKey;
@@ -210,23 +174,93 @@ function fortiPrepTransform(_api, rawOpts = {}) {
210
174
  );
211
175
  }
212
176
  }
213
- const returnExpr = returnDefaultProperty ? t.memberExpression(
214
- t.identifier(defaultExportLocalName),
215
- t.identifier("default")
216
- ) : t.identifier(defaultExportLocalName);
177
+ const returnExpr = defaultExportLocalName == null ? t.nullLiteral() : returnDefaultProperty ? t.memberExpression(t.identifier(defaultExportLocalName), t.identifier("default")) : t.identifier(defaultExportLocalName);
217
178
  const wrapperBody = [];
218
179
  wrapperBody.push(...injectedStmts);
219
180
  wrapperBody.push(...program.body);
220
181
  wrapperBody.push(t.returnStatement(returnExpr));
221
182
  const wrapper = t.exportDefaultDeclaration(
222
- t.functionDeclaration(
223
- null,
224
- [depsIdent],
225
- t.blockStatement(wrapperBody)
226
- )
183
+ t.functionDeclaration(null, [depsIdent], t.blockStatement(wrapperBody))
227
184
  );
228
185
  program.body = [...keptImports, wrapper, ...keptNamedExports];
229
186
  }
187
+ },
188
+ ImportDeclaration(path2) {
189
+ if (!enabled) return;
190
+ const node = path2.node;
191
+ const importId = node.source.value;
192
+ if (!shouldInject(importId, opts)) {
193
+ keptImports.push(node);
194
+ path2.remove();
195
+ return;
196
+ }
197
+ for (const s of node.specifiers) {
198
+ if (t.isImportDefaultSpecifier(s)) {
199
+ captureImport(importId, { kind: "default", local: s.local.name });
200
+ } else if (t.isImportNamespaceSpecifier(s)) {
201
+ captureImport(importId, { kind: "namespace", local: s.local.name });
202
+ } else if (t.isImportSpecifier(s)) {
203
+ captureImport(importId, {
204
+ kind: "named",
205
+ imported: getImportedName(s),
206
+ local: s.local.name
207
+ });
208
+ }
209
+ }
210
+ path2.remove();
211
+ },
212
+ ExportDefaultDeclaration(path2) {
213
+ if (!enabled) return;
214
+ const decl = path2.node.declaration;
215
+ if (t.isIdentifier(decl)) {
216
+ defaultExportLocalName = decl.name;
217
+ path2.remove();
218
+ return;
219
+ }
220
+ if (t.isFunctionDeclaration(decl) || t.isClassDeclaration(decl)) {
221
+ if (!decl.id) {
222
+ decl.id = path2.scope.generateUidIdentifier("defaultExport");
223
+ }
224
+ defaultExportLocalName = decl.id.name;
225
+ path2.replaceWith(decl);
226
+ return;
227
+ }
228
+ const id = path2.scope.generateUidIdentifier("defaultExport");
229
+ path2.replaceWith(
230
+ t.variableDeclaration("const", [
231
+ t.variableDeclarator(id, decl)
232
+ ])
233
+ );
234
+ defaultExportLocalName = id.name;
235
+ },
236
+ ExportNamedDeclaration(path2) {
237
+ if (!enabled) return;
238
+ const node = path2.node;
239
+ if (node.specifiers?.length) {
240
+ let foundExplicitDefault = false;
241
+ node.specifiers = node.specifiers.filter((spec) => {
242
+ const exported = t.isIdentifier(spec.exported) ? spec.exported.name : spec.exported.value;
243
+ if (exported === "default") {
244
+ const local = spec?.local?.name;
245
+ if (local) defaultExportLocalName = local;
246
+ foundExplicitDefault = true;
247
+ return false;
248
+ }
249
+ return true;
250
+ });
251
+ if (!foundExplicitDefault && !defaultExportLocalName && node.specifiers.length === 1) {
252
+ const only = node.specifiers[0];
253
+ if (only?.local?.name) {
254
+ defaultExportLocalName = only.local.name;
255
+ returnDefaultProperty = true;
256
+ node.specifiers = [];
257
+ }
258
+ }
259
+ }
260
+ if (node.declaration || node.specifiers && node.specifiers.length > 0) {
261
+ keptNamedExports.push(node);
262
+ }
263
+ path2.remove();
230
264
  }
231
265
  }
232
266
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/vite/prep.ts","../src/babel/transform.ts","../src/utils/generate-plugin-inputs.ts"],"sourcesContent":["import { transformSync } from \"@babel/core\";\r\nimport { readFileSync, writeFileSync } from \"node:fs\";\r\nimport { dirname, resolve as resolvePath } from \"node:path\";\r\nimport type {NormalizedOutputOptions, OutputBundle, OutputOptions} from \"rollup\";\r\nimport type { Plugin as VitePlugin } from \"vite\";\r\n\r\nimport fortiPrepTransform, {\r\n type FortiPrepTransformOptions,\r\n} from \"../babel/transform\";\r\n\r\nexport type FortiPrepOptions = FortiPrepTransformOptions & {\r\n /**\r\n * Which emitted entry file extensions should be rewritten.\r\n * Default: [\".js\", \".mjs\"]\r\n */\r\n entryExtensions?: string[];\r\n\r\n /**\r\n * Vite plugin name\r\n * Default: \"fortiplugin-prep\"\r\n */\r\n pluginName?: string;\r\n};\r\n\r\nconst DEFAULT_INJECTED_IDS = [\"react\", \"react/jsx-runtime\"] as const;\r\nconst DEFAULT_INJECTED_PREFIXES = [\"@inertiajs/\", \"@host/\"] as const;\r\n\r\nfunction resolveOutDir(outputOptions: OutputOptions): string | null {\r\n if (outputOptions.dir) return outputOptions.dir;\r\n if (outputOptions.file) return dirname(outputOptions.file);\r\n return null;\r\n}\r\n\r\nfunction shouldInject(id: string, opts: FortiPrepTransformOptions): boolean {\r\n const ids = opts.injectedIds ?? [];\r\n const prefixes = opts.injectedPrefixes ?? [];\r\n if (ids.includes(id)) return true;\r\n for (const p of prefixes) if (id.startsWith(p)) return true;\r\n return false;\r\n}\r\n\r\n/**\r\n * FortiPlugin bundle adapter:\r\n * - marks injected imports as Rollup externals (so they survive into output)\r\n * - rewrites built entry chunks to remove those imports and load them from runtime deps\r\n */\r\nexport default function prep(options: FortiPrepOptions = {}): VitePlugin {\r\n const injectedIds = options.injectedIds ?? [...DEFAULT_INJECTED_IDS];\r\n const injectedPrefixes = options.injectedPrefixes ?? [...DEFAULT_INJECTED_PREFIXES];\r\n\r\n const runtimeKey = options.runtimeKey ?? \"imports\";\r\n const depsParam = options.depsParam ?? \"deps\";\r\n\r\n const entryExtensions = options.entryExtensions ?? [\".js\", \".mjs\"];\r\n const pluginName = options.pluginName ?? \"fortiplugin-prep\";\r\n\r\n const transformOptions: FortiPrepTransformOptions = {\r\n injectedIds,\r\n injectedPrefixes,\r\n runtimeKey,\r\n depsParam,\r\n };\r\n\r\n return {\r\n name: pluginName,\r\n apply: \"build\",\r\n\r\n config() {\r\n return {\r\n define: {\r\n \"process.env.NODE_ENV\": '\"production\"',\r\n },\r\n build: {\r\n rollupOptions: {\r\n // Ensure virtual imports don't need to resolve.\r\n external: (id: string) => shouldInject(id, transformOptions),\r\n },\r\n },\r\n };\r\n },\r\n\r\n writeBundle(outputOptions: NormalizedOutputOptions, bundle: OutputBundle) {\r\n const outDir = resolveOutDir(outputOptions);\r\n if (!outDir) return;\r\n\r\n for (const [fileName, item] of Object.entries(bundle)) {\r\n if (item.type !== \"chunk\") continue;\r\n if (!item.isEntry) continue;\r\n\r\n if (!entryExtensions.some((ext) => fileName.endsWith(ext))) continue;\r\n\r\n const absPath = resolvePath(outDir, fileName);\r\n const input = readFileSync(absPath, \"utf-8\");\r\n\r\n const result = transformSync(input, {\r\n filename: absPath,\r\n sourceType: \"module\",\r\n // Fresh plugin instance per file (Babel calls plugin factory per file when passed as [fn, opts])\r\n plugins: [[fortiPrepTransform as any, transformOptions]],\r\n generatorOpts: {\r\n compact: false,\r\n comments: true,\r\n retainLines: false,\r\n },\r\n });\r\n\r\n if (!result?.code) continue;\r\n writeFileSync(absPath, result.code, \"utf-8\");\r\n }\r\n },\r\n };\r\n}","// noinspection JSUnusedGlobalSymbols,GrazieInspection\r\n\r\nimport type {PluginObj} from \"@babel/core\";\r\nimport * as t from \"@babel/types\";\r\nimport type {NodePath} from \"@babel/traverse\";\r\n\r\nexport type FortiPrepTransformOptions = {\r\n /**\r\n * Exact import ids to inject (removed from bundle and loaded from runtime deps).\r\n * Example: [\"react\", \"react/jsx-runtime\", \"@host/ui\"]\r\n */\r\n injectedIds?: string[];\r\n\r\n /**\r\n * Prefix import ids to inject.\r\n * Example: [\"@host/\", \"@inertiajs/\"]\r\n */\r\n injectedPrefixes?: string[];\r\n\r\n /**\r\n * The key on the deps object used as the import map.\r\n * Wrapper supports passing deps.imports OR passing the import map directly.\r\n *\r\n * Default: \"imports\"\r\n */\r\n runtimeKey?: string;\r\n\r\n /**\r\n * Wrapper function parameter name.\r\n * Default: \"deps\"\r\n */\r\n depsParam?: string;\r\n};\r\n\r\nconst DEFAULTS: Required<Pick<FortiPrepTransformOptions, \"runtimeKey\" | \"depsParam\">> = {\r\n runtimeKey: \"imports\",\r\n depsParam: \"deps\",\r\n};\r\n\r\nconst DEFAULT_EXPORT_ERROR =\r\n \"PROBLEM!!, No known default function was found, your code either possesses NO named default export or this export format is currently not supported.\";\r\n\r\nfunction shouldInject(id: string, opts: FortiPrepTransformOptions): boolean {\r\n const ids = opts.injectedIds ?? [];\r\n const prefixes = opts.injectedPrefixes ?? [];\r\n if (ids.includes(id)) return true;\r\n for (const p of prefixes) if (id.startsWith(p)) return true;\r\n return false;\r\n}\r\n\r\ntype CapturedImport =\r\n | { kind: \"default\"; local: string }\r\n | { kind: \"namespace\"; local: string }\r\n | { kind: \"named\"; imported: string; local: string };\r\n\r\nfunction getImportedName(spec: t.ImportSpecifier): string {\r\n return t.isIdentifier(spec.imported) ? spec.imported.name : spec.imported.value;\r\n}\r\n\r\nfunction makeImportMapExpr(\r\n depsIdent: t.Identifier,\r\n runtimeKey: string\r\n): t.Expression {\r\n // Support both:\r\n // factory({ imports: { ... } })\r\n // and:\r\n // factory({ ... }) // direct import map\r\n //\r\n // const __imports =\r\n // deps && typeof deps === \"object\" && \"imports\" in deps\r\n // ? deps.imports\r\n // : (deps ?? {});\r\n const hasKey = t.binaryExpression(\r\n \"in\",\r\n t.stringLiteral(runtimeKey),\r\n depsIdent\r\n );\r\n\r\n const isObj = t.logicalExpression(\r\n \"&&\",\r\n t.binaryExpression(\"!==\", depsIdent, t.nullLiteral()),\r\n t.binaryExpression(\"===\", t.unaryExpression(\"typeof\", depsIdent), t.stringLiteral(\"object\"))\r\n );\r\n\r\n const test = t.logicalExpression(\"&&\", isObj, hasKey);\r\n\r\n const depsKey = t.memberExpression(depsIdent, t.identifier(runtimeKey));\r\n const fallback = t.logicalExpression(\"||\", depsIdent, t.objectExpression([]));\r\n\r\n return t.conditionalExpression(test, depsKey, fallback);\r\n}\r\n\r\n/**\r\n * Babel plugin factory (Babel calls this per-file when used as `[plugin, options]`).\r\n */\r\nexport default function fortiPrepTransform(\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n _api: unknown,\r\n rawOpts: FortiPrepTransformOptions = {}\r\n): PluginObj {\r\n const opts: FortiPrepTransformOptions = {\r\n ...rawOpts,\r\n runtimeKey: rawOpts.runtimeKey ?? DEFAULTS.runtimeKey,\r\n depsParam: rawOpts.depsParam ?? DEFAULTS.depsParam,\r\n };\r\n\r\n // per-file state (because Babel calls the plugin per file)\r\n const keptImports: t.ImportDeclaration[] = [];\r\n const keptNamedExports: t.ExportNamedDeclaration[] = [];\r\n\r\n const injectedImportsById = new Map<string, CapturedImport[]>();\r\n\r\n let defaultExportLocalName: string | null = null;\r\n let returnDefaultProperty = false;\r\n\r\n function captureImport(importId: string, entry: CapturedImport) {\r\n const list = injectedImportsById.get(importId) ?? [];\r\n list.push(entry);\r\n injectedImportsById.set(importId, list);\r\n }\r\n\r\n return {\r\n name: \"fortiplugin-prep/transform\",\r\n visitor: {\r\n ImportDeclaration(path: NodePath<t.ImportDeclaration>) {\r\n const node = path.node;\r\n const importId = node.source.value;\r\n\r\n if (!shouldInject(importId, opts)) {\r\n keptImports.push(node);\r\n path.remove();\r\n return;\r\n }\r\n\r\n // Remove injected import and capture its specifiers to recreate inside wrapper.\r\n for (const s of node.specifiers) {\r\n if (t.isImportDefaultSpecifier(s)) {\r\n captureImport(importId, {kind: \"default\", local: s.local.name});\r\n } else if (t.isImportNamespaceSpecifier(s)) {\r\n captureImport(importId, {kind: \"namespace\", local: s.local.name});\r\n } else if (t.isImportSpecifier(s)) {\r\n captureImport(importId, {\r\n kind: \"named\",\r\n imported: getImportedName(s),\r\n local: s.local.name,\r\n });\r\n }\r\n }\r\n\r\n // side-effect only imports (import \"@host/ui\") become no-ops at runtime\r\n path.remove();\r\n },\r\n\r\n ExportDefaultDeclaration(path: NodePath<t.ExportDefaultDeclaration>) {\r\n const decl = path.node.declaration;\r\n\r\n // export default Foo;\r\n if (t.isIdentifier(decl)) {\r\n defaultExportLocalName = decl.name;\r\n path.remove();\r\n return;\r\n }\r\n\r\n // export default (expr/anon fn/class)\r\n // Hoist into a const (inside wrapper) so we can `return <id>`\r\n const id = path.scope.generateUidIdentifier(\"defaultExport\");\r\n path.replaceWith(\r\n t.variableDeclaration(\"const\", [t.variableDeclarator(id, decl as any)])\r\n );\r\n defaultExportLocalName = id.name;\r\n },\r\n\r\n ExportNamedDeclaration(path: NodePath<t.ExportNamedDeclaration>) {\r\n const node = path.node;\r\n keptNamedExports.push(node);\r\n\r\n // Detect Rollup-style: export { Foo as default }\r\n if (node.specifiers?.length) {\r\n let foundExplicitDefault = false;\r\n\r\n node.specifiers = node.specifiers.filter((spec) => {\r\n const exported =\r\n t.isIdentifier(spec.exported) ? spec.exported.name : spec.exported.value;\r\n\r\n if (exported === \"default\") {\r\n const local = (spec as any)?.local?.name as string | undefined;\r\n if (local) defaultExportLocalName = local;\r\n foundExplicitDefault = true;\r\n return false; // remove\r\n }\r\n\r\n return true;\r\n });\r\n\r\n // Minified fallback behavior:\r\n // If no default specifier found and exactly one spec exists,\r\n // treat it as the container and return `<local>.default`.\r\n if (!foundExplicitDefault && !defaultExportLocalName && node.specifiers.length === 1) {\r\n const only = node.specifiers[0] as any;\r\n if (only?.local?.name) {\r\n defaultExportLocalName = only.local.name;\r\n returnDefaultProperty = true;\r\n node.specifiers = [];\r\n }\r\n }\r\n }\r\n\r\n path.remove();\r\n },\r\n\r\n Program: {\r\n exit(path: NodePath<t.Program>) {\r\n const program = path.node;\r\n\r\n if (!defaultExportLocalName) {\r\n throw path.buildCodeFrameError(DEFAULT_EXPORT_ERROR);\r\n }\r\n\r\n const depsIdent = t.identifier(opts.depsParam ?? DEFAULTS.depsParam);\r\n const runtimeKey = opts.runtimeKey ?? DEFAULTS.runtimeKey;\r\n\r\n // const __imports = (deps has runtimeKey) ? deps[runtimeKey] : (deps || {});\r\n const importsIdent = t.identifier(\"__imports\");\r\n const importsInit = makeImportMapExpr(depsIdent, runtimeKey);\r\n const importsDecl = t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(importsIdent, importsInit),\r\n ]);\r\n\r\n // helper:\r\n // const __default = (m) => (m && typeof m === \"object\" && \"default\" in m ? m.default : m);\r\n const defaultHelperIdent = t.identifier(\"__default\");\r\n const defaultHelperDecl = t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(\r\n defaultHelperIdent,\r\n t.arrowFunctionExpression(\r\n [t.identifier(\"m\")],\r\n t.conditionalExpression(\r\n t.logicalExpression(\r\n \"&&\",\r\n t.logicalExpression(\r\n \"&&\",\r\n t.identifier(\"m\"),\r\n t.binaryExpression(\r\n \"===\",\r\n t.unaryExpression(\"typeof\", t.identifier(\"m\")),\r\n t.stringLiteral(\"object\")\r\n )\r\n ),\r\n t.binaryExpression(\"in\", t.stringLiteral(\"default\"), t.identifier(\"m\"))\r\n ),\r\n t.memberExpression(t.identifier(\"m\"), t.identifier(\"default\")),\r\n t.identifier(\"m\")\r\n )\r\n )\r\n ),\r\n ]);\r\n\r\n // Build injected module locals inside wrapper\r\n const injectedStmts: t.Statement[] = [importsDecl, defaultHelperDecl];\r\n\r\n for (const [importId, specs] of injectedImportsById.entries()) {\r\n const modIdent = t.identifier(\r\n `__m_${importId.replace(/[^a-zA-Z0-9_$]/g, \"_\")}`\r\n );\r\n\r\n // const __m_xxx = __imports[\"<importId>\"];\r\n injectedStmts.push(\r\n t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(\r\n modIdent,\r\n t.memberExpression(importsIdent, t.stringLiteral(importId), true)\r\n ),\r\n ])\r\n );\r\n\r\n const named: Array<{ imported: string; local: string }> = [];\r\n\r\n for (const s of specs) {\r\n if (s.kind === \"default\") {\r\n // const Local = __default(__m_xxx);\r\n injectedStmts.push(\r\n t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(\r\n t.identifier(s.local),\r\n t.callExpression(defaultHelperIdent, [modIdent])\r\n ),\r\n ])\r\n );\r\n } else if (s.kind === \"namespace\") {\r\n // const Local = __m_xxx;\r\n injectedStmts.push(\r\n t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(t.identifier(s.local), modIdent),\r\n ])\r\n );\r\n } else {\r\n named.push({imported: s.imported, local: s.local});\r\n }\r\n }\r\n\r\n if (named.length) {\r\n // const { A, B: C } = (__m_xxx ?? {});\r\n injectedStmts.push(\r\n t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(\r\n t.objectPattern(\r\n named.map(({imported, local}) =>\r\n t.objectProperty(\r\n t.identifier(imported),\r\n t.identifier(local),\r\n false,\r\n imported === local\r\n )\r\n )\r\n ),\r\n t.logicalExpression(\"||\", modIdent, t.objectExpression([]))\r\n ),\r\n ])\r\n );\r\n }\r\n }\r\n\r\n const returnExpr = returnDefaultProperty\r\n ? t.memberExpression(\r\n t.identifier(defaultExportLocalName),\r\n t.identifier(\"default\")\r\n )\r\n : t.identifier(defaultExportLocalName);\r\n\r\n // Wrapper body:\r\n // injectedStmts...\r\n // <original body>\r\n // return <defaultExport>\r\n const wrapperBody: t.Statement[] = [];\r\n wrapperBody.push(...injectedStmts);\r\n wrapperBody.push(...program.body);\r\n wrapperBody.push(t.returnStatement(returnExpr));\r\n\r\n const wrapper = t.exportDefaultDeclaration(\r\n t.functionDeclaration(\r\n null,\r\n [depsIdent],\r\n t.blockStatement(wrapperBody)\r\n )\r\n );\r\n\r\n // Final program:\r\n // kept imports at module scope\r\n // export default function(deps) { ... }\r\n // kept named exports (same as your old behavior)\r\n program.body = [...keptImports, wrapper, ...keptNamedExports] as any;\r\n },\r\n },\r\n },\r\n };\r\n}","// src/utils/generate-plugin-inputs.ts\r\nimport path from \"node:path\";\r\nimport * as fs from \"node:fs\";\r\n\r\nconst EXT_PATTERN = /\\.(tsx?|jsx?)$/i;\r\n\r\nexport type PluginInputs = Record<string, string>;\r\n\r\nexport type GeneratePluginInputsOptions = {\r\n /**\r\n * If true, also generates `app.tsx` that imports every discovered entry\r\n * (handy for dev/HMR).\r\n *\r\n * Default: true\r\n */\r\n writeAppEntry?: boolean;\r\n\r\n /**\r\n * Name of the generated app entry file (inside srcRoot).\r\n *\r\n * Default: \"app.tsx\"\r\n */\r\n appEntryName?: string;\r\n\r\n /**\r\n * Adds the generated app entry to the returned Rollup inputs map.\r\n *\r\n * Default: true\r\n */\r\n includeAppEntryInInputs?: boolean;\r\n\r\n /**\r\n * Key name used for the generated app entry in Rollup inputs.\r\n *\r\n * Default: \"__app_entry\"\r\n */\r\n appEntryKey?: string;\r\n\r\n /**\r\n * Extra directory names to ignore (case-insensitive).\r\n */\r\n ignoreDirs?: string[];\r\n\r\n /**\r\n * Extra “component-like” directory names to ignore (case-insensitive, exact match).\r\n */\r\n componentLikeDirs?: string[];\r\n\r\n /**\r\n * Whether to print discovered inputs to console.\r\n *\r\n * Default: true\r\n */\r\n verbose?: boolean;\r\n};\r\n\r\n// folders you typically never want as rollup inputs\r\nconst DEFAULT_IGNORE_DIRS = new Set<string>([\r\n \"node_modules\",\r\n \".git\",\r\n \".vite\",\r\n \".internal\",\r\n \"dist\",\r\n \"build\",\r\n \"public\",\r\n]);\r\n\r\n// “component-like” folders that should NOT produce entrypoints\r\n// Strict: exact folder-name matches only (case-insensitive)\r\nconst DEFAULT_COMPONENT_LIKE_DIRS = new Set<string>([\r\n \"component\",\r\n \"components\",\r\n \"ui\",\r\n \"uis\",\r\n \"widget\",\r\n \"widgets\",\r\n \"atom\",\r\n \"atoms\",\r\n \"molecule\",\r\n \"molecules\",\r\n \"organism\",\r\n \"organisms\",\r\n \"layout\",\r\n \"layouts\",\r\n \"partial\",\r\n \"partials\",\r\n]);\r\n\r\nfunction normalizeName(x: unknown): string {\r\n return String(x ?? \"\").toLowerCase();\r\n}\r\n\r\nfunction makeIgnoreSets(opts?: GeneratePluginInputsOptions): {\r\n ignoreDirs: Set<string>;\r\n componentLikeDirs: Set<string>;\r\n} {\r\n const ignoreDirs = new Set(DEFAULT_IGNORE_DIRS);\r\n const componentLikeDirs = new Set(DEFAULT_COMPONENT_LIKE_DIRS);\r\n\r\n for (const d of opts?.ignoreDirs ?? []) ignoreDirs.add(normalizeName(d));\r\n for (const d of opts?.componentLikeDirs ?? []) componentLikeDirs.add(normalizeName(d));\r\n\r\n return { ignoreDirs, componentLikeDirs };\r\n}\r\n\r\nfunction isIgnoredDir(\r\n dirName: string,\r\n sets: { ignoreDirs: Set<string>; componentLikeDirs: Set<string> }\r\n): boolean {\r\n const name = normalizeName(dirName);\r\n return sets.ignoreDirs.has(name) || sets.componentLikeDirs.has(name);\r\n}\r\n\r\n/**\r\n * Creates an app.tsx file that simply imports every discovered entry.\r\n * Helpful for HMR / dev mode.\r\n */\r\nfunction writeAppEntryFile(inputs: PluginInputs, srcRoot: string, appEntryName: string): void {\r\n const app = path.join(srcRoot, appEntryName);\r\n const lines: string[] = [\"// Auto-generated – do not edit\", \"\"];\r\n\r\n const entries = Object.entries(inputs).sort(([a], [b]) => a.localeCompare(b));\r\n\r\n for (const [name, full] of entries) {\r\n const rel =\r\n \"./\" + path.relative(srcRoot, full).replace(/\\\\/g, \"/\").replace(EXT_PATTERN, \"\");\r\n\r\n const variable = name.replace(/[^a-zA-Z0-9_$]/g, \"_\").replace(/^(\\d)/, \"_$1\");\r\n\r\n lines.push(`import * as ${variable} from '${rel}';`);\r\n lines.push(`console.log('${name} loaded:', ${variable});`, \"\");\r\n }\r\n\r\n fs.writeFileSync(app, lines.join(\"\\n\"), \"utf8\");\r\n // eslint-disable-next-line no-console\r\n console.log(`✅ Generated ${appEntryName} in ${srcRoot}`);\r\n}\r\n\r\n/**\r\n * Convert a relative path like \"foo/bar/index.tsx\" to a dot key.\r\n * If `collapseIndex` is true, \"foo/bar/index\" becomes \"foo.bar\".\r\n * Otherwise it becomes \"foo.bar.index\".\r\n */\r\nfunction pathToKey(relNoExt: string, opts: { collapseIndex: boolean }): string {\r\n let normalized = relNoExt.replace(/\\\\/g, \"/\");\r\n\r\n if (opts.collapseIndex) {\r\n normalized = normalized.replace(/\\/index$/i, \"\");\r\n }\r\n\r\n let key = normalized.split(\"/\").filter(Boolean).join(\".\");\r\n if (!key) key = \"index\";\r\n return key;\r\n}\r\n\r\n/**\r\n * Recursively collect entry files under dirPath.\r\n *\r\n * Rule:\r\n * - Prefer collapsing \".../index.tsx\" => \"...\" for nicer keys\r\n * - BUT if that key would collide with another entry, fallback to explicit \"...index\"\r\n * (e.g. \"foo.index\") for the index file ONLY.\r\n */\r\nfunction crawl(\r\n dirPath: string,\r\n baseDir: string,\r\n acc: PluginInputs,\r\n sets: { ignoreDirs: Set<string>; componentLikeDirs: Set<string> },\r\n appEntryAbsPath: string\r\n): void {\r\n if (!fs.existsSync(dirPath)) return;\r\n\r\n for (const item of fs.readdirSync(dirPath)) {\r\n const full = path.join(dirPath, item);\r\n const stat = fs.statSync(full);\r\n\r\n if (stat.isDirectory()) {\r\n if (isIgnoredDir(item, sets)) continue;\r\n crawl(full, baseDir, acc, sets, appEntryAbsPath);\r\n continue;\r\n }\r\n\r\n if (!EXT_PATTERN.test(item)) continue;\r\n\r\n // Don't include the generated entry itself (prevents self-import)\r\n if (path.resolve(full) === path.resolve(appEntryAbsPath)) {\r\n continue;\r\n }\r\n\r\n const relNoExt = path.relative(baseDir, full).replace(EXT_PATTERN, \"\");\r\n const isIndexFile = /(^|[\\\\/])index$/i.test(relNoExt);\r\n\r\n // Preferred key: collapse \".../index\" => \"...\"\r\n const preferred = pathToKey(relNoExt, { collapseIndex: true });\r\n\r\n // Explicit key: keep \".../index\" => \"...index\"\r\n // Example: \"foo/index\" => \"foo.index\"\r\n const explicit = pathToKey(relNoExt, { collapseIndex: false });\r\n\r\n let name = preferred;\r\n\r\n // If preferred collides, ONLY the index file switches to explicit path key.\r\n const existing = acc[name];\r\n if (existing && path.resolve(existing) !== path.resolve(full)) {\r\n if (isIndexFile) {\r\n // Use foo.index (or deeper.path.index) instead of suffixing __2\r\n if (!acc[explicit]) {\r\n // eslint-disable-next-line no-console\r\n console.warn(\r\n `⚠️ Key collision for \"${preferred}\" — using \"${explicit}\" for index file`,\r\n { existing: acc[preferred], incoming: full }\r\n );\r\n name = explicit;\r\n } else {\r\n // Extremely rare: even explicit collides (e.g. duplicate paths via symlinks)\r\n let i = 2;\r\n let next = `${explicit}__${i}`;\r\n while (acc[next]) {\r\n i += 1;\r\n next = `${explicit}__${i}`;\r\n }\r\n // eslint-disable-next-line no-console\r\n console.warn(`⚠️ Key collision for \"${explicit}\" — using \"${next}\"`, {\r\n existing: acc[explicit],\r\n incoming: full,\r\n });\r\n name = next;\r\n }\r\n } else {\r\n // Non-index collision: suffix like original behavior\r\n let i = 2;\r\n let next = `${name}__${i}`;\r\n while (acc[next]) {\r\n i += 1;\r\n next = `${name}__${i}`;\r\n }\r\n // eslint-disable-next-line no-console\r\n console.warn(`⚠️ Input key collision \"${name}\" -> using \"${next}\"`, {\r\n existing: acc[name],\r\n incoming: full,\r\n });\r\n name = next;\r\n }\r\n }\r\n\r\n acc[name] = full;\r\n }\r\n}\r\n\r\n/**\r\n * Discover integration pages/components and return a Rollup input map.\r\n *\r\n * @param srcRoot absolute or relative path to the source folder (e.g. \"resources/embed/ts\")\r\n * @param options\r\n * @returns Rollup input map: { [key]: absolutePath }\r\n */\r\nexport function generatePluginInputs(\r\n srcRoot: string = path.resolve(process.cwd(), \"ts\"),\r\n options: GeneratePluginInputsOptions = {}\r\n): PluginInputs {\r\n const {\r\n writeAppEntry = true,\r\n appEntryName = \"app.tsx\",\r\n includeAppEntryInInputs = true,\r\n appEntryKey = \"__app_entry\",\r\n verbose = true,\r\n } = options;\r\n\r\n const absRoot = path.resolve(srcRoot);\r\n const inputs: PluginInputs = {};\r\n\r\n const sets = makeIgnoreSets(options);\r\n const appEntryAbsPath = path.join(absRoot, appEntryName);\r\n\r\n // Crawl everything under absRoot (no folder assumptions)\r\n crawl(absRoot, absRoot, inputs, sets, appEntryAbsPath);\r\n\r\n if (verbose) {\r\n // eslint-disable-next-line no-console\r\n console.log(\"✅ Integrations discovered:\", inputs);\r\n }\r\n\r\n if (writeAppEntry) {\r\n writeAppEntryFile(inputs, absRoot, appEntryName);\r\n }\r\n\r\n if (!includeAppEntryInInputs) return inputs;\r\n\r\n return { ...inputs, [appEntryKey]: appEntryAbsPath };\r\n}"],"mappings":";AAAA,SAAS,qBAAqB;AAC9B,SAAS,cAAc,qBAAqB;AAC5C,SAAS,SAAS,WAAW,mBAAmB;;;ACChD,YAAY,OAAO;AA+BnB,IAAM,WAAkF;AAAA,EACpF,YAAY;AAAA,EACZ,WAAW;AACf;AAEA,IAAM,uBACF;AAEJ,SAAS,aAAa,IAAY,MAA0C;AACxE,QAAM,MAAM,KAAK,eAAe,CAAC;AACjC,QAAM,WAAW,KAAK,oBAAoB,CAAC;AAC3C,MAAI,IAAI,SAAS,EAAE,EAAG,QAAO;AAC7B,aAAW,KAAK,SAAU,KAAI,GAAG,WAAW,CAAC,EAAG,QAAO;AACvD,SAAO;AACX;AAOA,SAAS,gBAAgB,MAAiC;AACtD,SAAS,eAAa,KAAK,QAAQ,IAAI,KAAK,SAAS,OAAO,KAAK,SAAS;AAC9E;AAEA,SAAS,kBACL,WACA,YACY;AAUZ,QAAM,SAAW;AAAA,IACb;AAAA,IACE,gBAAc,UAAU;AAAA,IAC1B;AAAA,EACJ;AAEA,QAAM,QAAU;AAAA,IACZ;AAAA,IACE,mBAAiB,OAAO,WAAa,cAAY,CAAC;AAAA,IAClD,mBAAiB,OAAS,kBAAgB,UAAU,SAAS,GAAK,gBAAc,QAAQ,CAAC;AAAA,EAC/F;AAEA,QAAM,OAAS,oBAAkB,MAAM,OAAO,MAAM;AAEpD,QAAM,UAAY,mBAAiB,WAAa,aAAW,UAAU,CAAC;AACtE,QAAM,WAAa,oBAAkB,MAA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ACtB,UAAU;AAAA,UACd,CAAC;AACD,iBAAO;AAAA,QACX;AAAA,MACJ,OAAO;AAEH,YAAI,IAAI;AACR,YAAI,OAAO,GAAG,IAAI,KAAK,CAAC;AACxB,eAAO,IAAI,IAAI,GAAG;AACd,eAAK;AACL,iBAAO,GAAG,IAAI,KAAK,CAAC;AAAA,QACxB;AAEA,gBAAQ,KAAK,qCAA2B,IAAI,eAAe,IAAI,KAAK;AAAA,UAChE,UAAU,IAAI,IAAI;AAAA,UAClB,UAAU;AAAA,QACd,CAAC;AACD,eAAO;AAAA,MACX;AAAA,IACJ;AAEA,QAAI,IAAI,IAAI;AAAA,EAChB;AACJ;AASO,SAAS,qBACZ,UAAkB,KAAK,QAAQ,QAAQ,IAAI,GAAG,IAAI,GAClD,UAAuC,CAAC,GAC5B;AACZ,QAAM;AAAA,IACF,gBAAgB;AAAA,IAChB,eAAe;AAAA,IACf,0BAA0B;AAAA,IAC1B,cAAc;AAAA,IACd,UAAU;AAAA,EACd,IAAI;AAEJ,QAAM,UAAU,KAAK,QAAQ,OAAO;AACpC,QAAM,SAAuB,CAAC;AAE9B,QAAM,OAAO,eAAe,OAAO;AACnC,QAAM,kBAAkB,KAAK,KAAK,SAAS,YAAY;AAGvD,QAAM,SAAS,SAAS,QAAQ,MAAM,eAAe;AAErD,MAAI,SAAS;AAET,YAAQ,IAAI,mCAA8B,MAAM;AAAA,EACpD;AAEA,MAAI,eAAe;AACf,sBAAkB,QAAQ,SAAS,YAAY;AAAA,EACnD;AAEA,MAAI,CAAC,wBAAyB,QAAO;AAErC,SAAO,EAAE,GAAG,QAAQ,CAAC,WAAW,GAAG,gBAAgB;AACvD;","names":["path","shouldInject"]}
1
+ {"version":3,"sources":["../src/vite/prep.ts","../src/babel/transform.ts","../src/utils/generate-plugin-inputs.ts"],"sourcesContent":["import { transformSync } from \"@babel/core\";\r\nimport { readFileSync, writeFileSync } from \"node:fs\";\r\nimport { dirname, resolve as resolvePath } from \"node:path\";\r\nimport type {NormalizedOutputOptions, OutputBundle, OutputOptions} from \"rollup\";\r\nimport type { Plugin as VitePlugin } from \"vite\";\r\n\r\nimport fortiPrepTransform, {\r\n type FortiPrepTransformOptions,\r\n} from \"../babel/transform\";\r\n\r\nexport type FortiPrepOptions = FortiPrepTransformOptions & {\r\n /**\r\n * Which emitted entry file extensions should be rewritten.\r\n * Default: [\".js\", \".mjs\"]\r\n */\r\n entryExtensions?: string[];\r\n\r\n /**\r\n * Vite plugin name\r\n * Default: \"fortiplugin-prep\"\r\n */\r\n pluginName?: string;\r\n};\r\n\r\nconst DEFAULT_INJECTED_IDS = [\"react\", \"react/jsx-runtime\"] as const;\r\nconst DEFAULT_INJECTED_PREFIXES = [\"@inertiajs/\", \"@host/\"] as const;\r\n\r\nfunction resolveOutDir(outputOptions: OutputOptions): string | null {\r\n if (outputOptions.dir) return outputOptions.dir;\r\n if (outputOptions.file) return dirname(outputOptions.file);\r\n return null;\r\n}\r\n\r\nfunction shouldInject(id: string, opts: FortiPrepTransformOptions): boolean {\r\n const ids = opts.injectedIds ?? [];\r\n const prefixes = opts.injectedPrefixes ?? [];\r\n if (ids.includes(id)) return true;\r\n for (const p of prefixes) if (id.startsWith(p)) return true;\r\n return false;\r\n}\r\n\r\n/**\r\n * FortiPlugin bundle adapter:\r\n * - marks injected imports as Rollup externals (so they survive into output)\r\n * - rewrites built entry chunks to remove those imports and load them from runtime deps\r\n */\r\nexport default function prep(options: FortiPrepOptions = {}): VitePlugin {\r\n const injectedIds = options.injectedIds ?? [...DEFAULT_INJECTED_IDS];\r\n const injectedPrefixes = options.injectedPrefixes ?? [...DEFAULT_INJECTED_PREFIXES];\r\n\r\n const runtimeKey = options.runtimeKey ?? \"imports\";\r\n const depsParam = options.depsParam ?? \"deps\";\r\n\r\n const entryExtensions = options.entryExtensions ?? [\".js\", \".mjs\"];\r\n const pluginName = options.pluginName ?? \"fortiplugin-prep\";\r\n\r\n const transformOptions: FortiPrepTransformOptions = {\r\n injectedIds,\r\n injectedPrefixes,\r\n runtimeKey,\r\n depsParam,\r\n };\r\n\r\n return {\r\n name: pluginName,\r\n apply: \"build\",\r\n\r\n config() {\r\n return {\r\n define: {\r\n \"process.env.NODE_ENV\": '\"production\"',\r\n },\r\n build: {\r\n rollupOptions: {\r\n // Ensure virtual imports don't need to resolve.\r\n external: (id: string) => shouldInject(id, transformOptions),\r\n },\r\n },\r\n };\r\n },\r\n\r\n writeBundle(outputOptions: NormalizedOutputOptions, bundle: OutputBundle) {\r\n const outDir = resolveOutDir(outputOptions);\r\n if (!outDir) return;\r\n\r\n for (const [fileName, item] of Object.entries(bundle)) {\r\n if (item.type !== \"chunk\") continue;\r\n if (!item.isEntry) continue;\r\n\r\n if (!entryExtensions.some((ext) => fileName.endsWith(ext))) continue;\r\n\r\n const absPath = resolvePath(outDir, fileName);\r\n const input = readFileSync(absPath, \"utf-8\");\r\n\r\n const result = transformSync(input, {\r\n filename: absPath,\r\n sourceType: \"module\",\r\n // Fresh plugin instance per file (Babel calls plugin factory per file when passed as [fn, opts])\r\n plugins: [[fortiPrepTransform as any, transformOptions]],\r\n generatorOpts: {\r\n compact: false,\r\n comments: true,\r\n retainLines: false,\r\n },\r\n });\r\n\r\n if (!result?.code) continue;\r\n writeFileSync(absPath, result.code, \"utf-8\");\r\n }\r\n },\r\n };\r\n}","// noinspection JSUnusedGlobalSymbols,GrazieInspection\r\n\r\nimport type {PluginObj} from \"@babel/core\";\r\nimport * as t from \"@babel/types\";\r\nimport type {NodePath} from \"@babel/traverse\";\r\n\r\nexport type FortiPrepTransformOptions = {\r\n /**\r\n * Exact import ids to inject (removed from bundle and loaded from runtime deps).\r\n * Example: [\"react\", \"react/jsx-runtime\", \"@host/ui\"]\r\n */\r\n injectedIds?: string[];\r\n\r\n /**\r\n * Prefix import ids to inject.\r\n * Example: [\"@host/\", \"@inertiajs/\"]\r\n */\r\n injectedPrefixes?: string[];\r\n\r\n /**\r\n * The key on the deps object used as the import map.\r\n * Wrapper supports passing deps.imports OR passing the import map directly.\r\n *\r\n * Default: \"imports\"\r\n */\r\n runtimeKey?: string;\r\n\r\n /**\r\n * Wrapper function parameter name.\r\n * Default: \"deps\"\r\n */\r\n depsParam?: string;\r\n\r\n /**\r\n * What to do if we can't determine a default export to return.\r\n *\r\n * - \"skip\": do nothing (leave file untouched) ✅ default\r\n * - \"return-null\": still wrap, but return null\r\n * - \"throw\": fail the build (old behavior)\r\n */\r\n onMissingDefault?: \"skip\" | \"return-null\" | \"throw\";\r\n};\r\n\r\nconst DEFAULTS: Required<\r\n Pick<FortiPrepTransformOptions, \"runtimeKey\" | \"depsParam\" | \"onMissingDefault\">\r\n> = {\r\n runtimeKey: \"imports\",\r\n depsParam: \"deps\",\r\n onMissingDefault: \"skip\",\r\n};\r\n\r\nconst DEFAULT_EXPORT_ERROR =\r\n \"PROBLEM!!, No known default function was found, your code either possesses NO named default export or this export format is currently not supported.\";\r\n\r\nfunction shouldInject(id: string, opts: FortiPrepTransformOptions): boolean {\r\n const ids = opts.injectedIds ?? [];\r\n const prefixes = opts.injectedPrefixes ?? [];\r\n if (ids.includes(id)) return true;\r\n for (const p of prefixes) if (id.startsWith(p)) return true;\r\n return false;\r\n}\r\n\r\nfunction programHasDefaultExport(p: t.Program): boolean {\r\n for (const stmt of p.body) {\r\n if (t.isExportDefaultDeclaration(stmt)) return true;\r\n\r\n // Rollup-style: export { Foo as default }\r\n if (t.isExportNamedDeclaration(stmt) && stmt.specifiers?.length) {\r\n for (const spec of stmt.specifiers) {\r\n const exported = t.isIdentifier(spec.exported)\r\n ? spec.exported.name\r\n : spec.exported.value;\r\n if (exported === \"default\") return true;\r\n }\r\n }\r\n }\r\n return false;\r\n}\r\n\r\ntype CapturedImport =\r\n | { kind: \"default\"; local: string }\r\n | { kind: \"namespace\"; local: string }\r\n | { kind: \"named\"; imported: string; local: string };\r\n\r\nfunction getImportedName(spec: t.ImportSpecifier): string {\r\n return t.isIdentifier(spec.imported) ? spec.imported.name : spec.imported.value;\r\n}\r\n\r\nfunction makeImportMapExpr(depsIdent: t.Identifier, runtimeKey: string): t.Expression {\r\n // Support both:\r\n // factory({ imports: { ... } })\r\n // and:\r\n // factory({ ... }) // direct import map\r\n //\r\n // const __imports =\r\n // deps && typeof deps === \"object\" && \"imports\" in deps\r\n // ? deps.imports\r\n // : (deps || {});\r\n const hasKey = t.binaryExpression(\"in\", t.stringLiteral(runtimeKey), depsIdent);\r\n\r\n const isObj = t.logicalExpression(\r\n \"&&\",\r\n t.binaryExpression(\"!==\", depsIdent, t.nullLiteral()),\r\n t.binaryExpression(\r\n \"===\",\r\n t.unaryExpression(\"typeof\", depsIdent),\r\n t.stringLiteral(\"object\")\r\n )\r\n );\r\n\r\n const test = t.logicalExpression(\"&&\", isObj, hasKey);\r\n\r\n const depsKey = t.memberExpression(depsIdent, t.identifier(runtimeKey));\r\n const fallback = t.logicalExpression(\"||\", depsIdent, t.objectExpression([]));\r\n\r\n return t.conditionalExpression(test, depsKey, fallback);\r\n}\r\n\r\n/**\r\n * Babel plugin factory (Babel calls this per-file when used as `[plugin, options]`).\r\n */\r\nexport default function fortiPrepTransform(\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n _api: unknown,\r\n rawOpts: FortiPrepTransformOptions = {}\r\n): PluginObj {\r\n const opts: FortiPrepTransformOptions = {\r\n ...rawOpts,\r\n runtimeKey: rawOpts.runtimeKey ?? DEFAULTS.runtimeKey,\r\n depsParam: rawOpts.depsParam ?? DEFAULTS.depsParam,\r\n onMissingDefault: rawOpts.onMissingDefault ?? DEFAULTS.onMissingDefault,\r\n };\r\n\r\n // If false, we do NOTHING to this file (silent ignore).\r\n let enabled = true;\r\n\r\n // per-file state (because Babel calls the plugin per file)\r\n const keptImports: t.ImportDeclaration[] = [];\r\n const keptNamedExports: t.ExportNamedDeclaration[] = [];\r\n\r\n const injectedImportsById = new Map<string, CapturedImport[]>();\r\n\r\n let defaultExportLocalName: string | null = null;\r\n let returnDefaultProperty = false;\r\n\r\n function captureImport(importId: string, entry: CapturedImport) {\r\n const list = injectedImportsById.get(importId) ?? [];\r\n list.push(entry);\r\n injectedImportsById.set(importId, list);\r\n }\r\n\r\n return {\r\n name: \"fortiplugin-prep/transform\",\r\n visitor: {\r\n Program: {\r\n enter(path: NodePath<t.Program>) {\r\n // If there's no default export and behavior is \"skip\", silently do nothing.\r\n const hasDefault = programHasDefaultExport(path.node);\r\n if (!hasDefault && (opts.onMissingDefault ?? DEFAULTS.onMissingDefault) === \"skip\") {\r\n enabled = false;\r\n }\r\n },\r\n\r\n exit(path: NodePath<t.Program>) {\r\n if (!enabled) return;\r\n\r\n const program = path.node;\r\n\r\n // If we still couldn't resolve the default export name, decide behavior.\r\n if (!defaultExportLocalName) {\r\n const behavior = opts.onMissingDefault ?? DEFAULTS.onMissingDefault;\r\n\r\n if (behavior === \"throw\") {\r\n throw path.buildCodeFrameError(DEFAULT_EXPORT_ERROR);\r\n }\r\n\r\n // \"return-null\": wrap but return null.\r\n // (Note: \"skip\" mode should have disabled earlier, but this is a safe fallback.)\r\n defaultExportLocalName = null;\r\n }\r\n\r\n const depsIdent = t.identifier(opts.depsParam ?? DEFAULTS.depsParam);\r\n const runtimeKey = opts.runtimeKey ?? DEFAULTS.runtimeKey;\r\n\r\n // const __imports = (deps has runtimeKey) ? deps[runtimeKey] : (deps || {});\r\n const importsIdent = t.identifier(\"__imports\");\r\n const importsInit = makeImportMapExpr(depsIdent, runtimeKey);\r\n const importsDecl = t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(importsIdent, importsInit),\r\n ]);\r\n\r\n // const __default = (m) => (m && typeof m === \"object\" && \"default\" in m ? m.default : m);\r\n const defaultHelperIdent = t.identifier(\"__default\");\r\n const defaultHelperDecl = t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(\r\n defaultHelperIdent,\r\n t.arrowFunctionExpression(\r\n [t.identifier(\"m\")],\r\n t.conditionalExpression(\r\n t.logicalExpression(\r\n \"&&\",\r\n t.logicalExpression(\r\n \"&&\",\r\n t.identifier(\"m\"),\r\n t.binaryExpression(\r\n \"===\",\r\n t.unaryExpression(\"typeof\", t.identifier(\"m\")),\r\n t.stringLiteral(\"object\")\r\n )\r\n ),\r\n t.binaryExpression(\"in\", t.stringLiteral(\"default\"), t.identifier(\"m\"))\r\n ),\r\n t.memberExpression(t.identifier(\"m\"), t.identifier(\"default\")),\r\n t.identifier(\"m\")\r\n )\r\n )\r\n ),\r\n ]);\r\n\r\n // Build injected module locals inside wrapper\r\n const injectedStmts: t.Statement[] = [importsDecl, defaultHelperDecl];\r\n\r\n for (const [importId, specs] of injectedImportsById.entries()) {\r\n const modIdent = t.identifier(\r\n `__m_${importId.replace(/[^a-zA-Z0-9_$]/g, \"_\")}`\r\n );\r\n\r\n // const __m_xxx = __imports[\"<importId>\"];\r\n injectedStmts.push(\r\n t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(\r\n modIdent,\r\n t.memberExpression(importsIdent, t.stringLiteral(importId), true)\r\n ),\r\n ])\r\n );\r\n\r\n const named: Array<{ imported: string; local: string }> = [];\r\n\r\n for (const s of specs) {\r\n if (s.kind === \"default\") {\r\n // const Local = __default(__m_xxx);\r\n injectedStmts.push(\r\n t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(\r\n t.identifier(s.local),\r\n t.callExpression(defaultHelperIdent, [modIdent])\r\n ),\r\n ])\r\n );\r\n } else if (s.kind === \"namespace\") {\r\n // const Local = __m_xxx;\r\n injectedStmts.push(\r\n t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(t.identifier(s.local), modIdent),\r\n ])\r\n );\r\n } else {\r\n named.push({imported: s.imported, local: s.local});\r\n }\r\n }\r\n\r\n if (named.length) {\r\n // const { A, B: C } = (__m_xxx || {});\r\n injectedStmts.push(\r\n t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(\r\n t.objectPattern(\r\n named.map(({imported, local}) =>\r\n t.objectProperty(\r\n t.identifier(imported),\r\n t.identifier(local),\r\n false,\r\n imported === local\r\n )\r\n )\r\n ),\r\n t.logicalExpression(\"||\", modIdent, t.objectExpression([]))\r\n ),\r\n ])\r\n );\r\n }\r\n }\r\n\r\n const returnExpr =\r\n defaultExportLocalName == null\r\n ? t.nullLiteral()\r\n : returnDefaultProperty\r\n ? t.memberExpression(t.identifier(defaultExportLocalName), t.identifier(\"default\"))\r\n : t.identifier(defaultExportLocalName);\r\n\r\n // Wrapper body:\r\n // injectedStmts...\r\n // <original body>\r\n // return <defaultExport>\r\n const wrapperBody: t.Statement[] = [];\r\n wrapperBody.push(...injectedStmts);\r\n wrapperBody.push(...program.body);\r\n wrapperBody.push(t.returnStatement(returnExpr));\r\n\r\n const wrapper = t.exportDefaultDeclaration(\r\n t.functionDeclaration(null, [depsIdent], t.blockStatement(wrapperBody))\r\n );\r\n\r\n // Final program:\r\n // kept imports at module scope\r\n // export default function(deps) { ... }\r\n // kept named exports (same as your old behavior)\r\n program.body = [...keptImports, wrapper, ...keptNamedExports] as any;\r\n },\r\n },\r\n\r\n ImportDeclaration(path: NodePath<t.ImportDeclaration>) {\r\n if (!enabled) return;\r\n\r\n const node = path.node;\r\n const importId = node.source.value;\r\n\r\n if (!shouldInject(importId, opts)) {\r\n keptImports.push(node);\r\n path.remove();\r\n return;\r\n }\r\n\r\n // Remove injected import and capture its specifiers to recreate inside wrapper.\r\n for (const s of node.specifiers) {\r\n if (t.isImportDefaultSpecifier(s)) {\r\n captureImport(importId, {kind: \"default\", local: s.local.name});\r\n } else if (t.isImportNamespaceSpecifier(s)) {\r\n captureImport(importId, {kind: \"namespace\", local: s.local.name});\r\n } else if (t.isImportSpecifier(s)) {\r\n captureImport(importId, {\r\n kind: \"named\",\r\n imported: getImportedName(s),\r\n local: s.local.name,\r\n });\r\n }\r\n }\r\n\r\n // side-effect-only injected imports (import \"@host/ui\") become no-ops at runtime\r\n path.remove();\r\n },\r\n\r\n ExportDefaultDeclaration(path: NodePath<t.ExportDefaultDeclaration>) {\r\n if (!enabled) return;\r\n\r\n const decl = path.node.declaration;\r\n\r\n // export default Foo;\r\n if (t.isIdentifier(decl)) {\r\n defaultExportLocalName = decl.name;\r\n path.remove();\r\n return;\r\n }\r\n\r\n // export default function (...) {}\r\n // export default class {...}\r\n // Keep as declaration (valid) and remember its id.\r\n if (t.isFunctionDeclaration(decl) || t.isClassDeclaration(decl)) {\r\n if (!decl.id) {\r\n decl.id = path.scope.generateUidIdentifier(\"defaultExport\");\r\n }\r\n defaultExportLocalName = decl.id.name;\r\n path.replaceWith(decl);\r\n return;\r\n }\r\n\r\n // export default (expr/arrow/etc)\r\n const id = path.scope.generateUidIdentifier(\"defaultExport\");\r\n path.replaceWith(\r\n t.variableDeclaration(\"const\", [\r\n t.variableDeclarator(id, decl as t.Expression),\r\n ])\r\n );\r\n defaultExportLocalName = id.name;\r\n },\r\n\r\n ExportNamedDeclaration(path: NodePath<t.ExportNamedDeclaration>) {\r\n if (!enabled) return;\r\n\r\n const node = path.node;\r\n\r\n // Detect Rollup-style: export { Foo as default }\r\n if (node.specifiers?.length) {\r\n let foundExplicitDefault = false;\r\n\r\n node.specifiers = node.specifiers.filter((spec) => {\r\n const exported = t.isIdentifier(spec.exported)\r\n ? spec.exported.name\r\n : spec.exported.value;\r\n\r\n if (exported === \"default\") {\r\n const local = (spec as any)?.local?.name as string | undefined;\r\n if (local) defaultExportLocalName = local;\r\n foundExplicitDefault = true;\r\n return false; // remove the default specifier\r\n }\r\n\r\n return true;\r\n });\r\n\r\n // Minified fallback behavior:\r\n // If no default specifier found and exactly one spec exists,\r\n // treat it as the container and return `<local>.default`.\r\n if (\r\n !foundExplicitDefault &&\r\n !defaultExportLocalName &&\r\n node.specifiers.length === 1\r\n ) {\r\n const only = node.specifiers[0] as any;\r\n if (only?.local?.name) {\r\n defaultExportLocalName = only.local.name;\r\n returnDefaultProperty = true;\r\n node.specifiers = [];\r\n }\r\n }\r\n }\r\n\r\n // Keep named exports after wrapper (same as prior behavior),\r\n // BUT do not keep empty export declarations.\r\n if (node.declaration || (node.specifiers && node.specifiers.length > 0)) {\r\n keptNamedExports.push(node);\r\n }\r\n\r\n path.remove();\r\n },\r\n },\r\n };\r\n}","// src/utils/generate-plugin-inputs.ts\r\nimport path from \"node:path\";\r\nimport * as fs from \"node:fs\";\r\n\r\nconst EXT_PATTERN = /\\.(tsx?|jsx?)$/i;\r\n\r\nexport type PluginInputs = Record<string, string>;\r\n\r\nexport type GeneratePluginInputsOptions = {\r\n /**\r\n * If true, also generates `app.tsx` that imports every discovered entry\r\n * (handy for dev/HMR).\r\n *\r\n * Default: true\r\n */\r\n writeAppEntry?: boolean;\r\n\r\n /**\r\n * Name of the generated app entry file (inside srcRoot).\r\n *\r\n * Default: \"app.tsx\"\r\n */\r\n appEntryName?: string;\r\n\r\n /**\r\n * Adds the generated app entry to the returned Rollup inputs map.\r\n *\r\n * Default: true\r\n */\r\n includeAppEntryInInputs?: boolean;\r\n\r\n /**\r\n * Key name used for the generated app entry in Rollup inputs.\r\n *\r\n * Default: \"__app_entry\"\r\n */\r\n appEntryKey?: string;\r\n\r\n /**\r\n * Extra directory names to ignore (case-insensitive).\r\n */\r\n ignoreDirs?: string[];\r\n\r\n /**\r\n * Extra “component-like” directory names to ignore (case-insensitive, exact match).\r\n */\r\n componentLikeDirs?: string[];\r\n\r\n /**\r\n * Whether to print discovered inputs to console.\r\n *\r\n * Default: true\r\n */\r\n verbose?: boolean;\r\n};\r\n\r\n// folders you typically never want as rollup inputs\r\nconst DEFAULT_IGNORE_DIRS = new Set<string>([\r\n \"node_modules\",\r\n \".git\",\r\n \".vite\",\r\n \".internal\",\r\n \"dist\",\r\n \"build\",\r\n \"public\",\r\n]);\r\n\r\n// “component-like” folders that should NOT produce entrypoints\r\n// Strict: exact folder-name matches only (case-insensitive)\r\nconst DEFAULT_COMPONENT_LIKE_DIRS = new Set<string>([\r\n \"component\",\r\n \"components\",\r\n \"ui\",\r\n \"uis\",\r\n \"widget\",\r\n \"widgets\",\r\n \"atom\",\r\n \"atoms\",\r\n \"molecule\",\r\n \"molecules\",\r\n \"organism\",\r\n \"organisms\",\r\n \"layout\",\r\n \"layouts\",\r\n \"partial\",\r\n \"partials\",\r\n]);\r\n\r\nfunction normalizeName(x: unknown): string {\r\n return String(x ?? \"\").toLowerCase();\r\n}\r\n\r\nfunction makeIgnoreSets(opts?: GeneratePluginInputsOptions): {\r\n ignoreDirs: Set<string>;\r\n componentLikeDirs: Set<string>;\r\n} {\r\n const ignoreDirs = new Set(DEFAULT_IGNORE_DIRS);\r\n const componentLikeDirs = new Set(DEFAULT_COMPONENT_LIKE_DIRS);\r\n\r\n for (const d of opts?.ignoreDirs ?? []) ignoreDirs.add(normalizeName(d));\r\n for (const d of opts?.componentLikeDirs ?? []) componentLikeDirs.add(normalizeName(d));\r\n\r\n return { ignoreDirs, componentLikeDirs };\r\n}\r\n\r\nfunction isIgnoredDir(\r\n dirName: string,\r\n sets: { ignoreDirs: Set<string>; componentLikeDirs: Set<string> }\r\n): boolean {\r\n const name = normalizeName(dirName);\r\n return sets.ignoreDirs.has(name) || sets.componentLikeDirs.has(name);\r\n}\r\n\r\n/**\r\n * Creates an app.tsx file that simply imports every discovered entry.\r\n * Helpful for HMR / dev mode.\r\n */\r\nfunction writeAppEntryFile(inputs: PluginInputs, srcRoot: string, appEntryName: string): void {\r\n const app = path.join(srcRoot, appEntryName);\r\n const lines: string[] = [\"// Auto-generated – do not edit\", \"\"];\r\n\r\n const entries = Object.entries(inputs).sort(([a], [b]) => a.localeCompare(b));\r\n\r\n for (const [name, full] of entries) {\r\n const rel =\r\n \"./\" + path.relative(srcRoot, full).replace(/\\\\/g, \"/\").replace(EXT_PATTERN, \"\");\r\n\r\n const variable = name.replace(/[^a-zA-Z0-9_$]/g, \"_\").replace(/^(\\d)/, \"_$1\");\r\n\r\n lines.push(`import * as ${variable} from '${rel}';`);\r\n lines.push(`console.log('${name} loaded:', ${variable});`, \"\");\r\n }\r\n\r\n fs.writeFileSync(app, lines.join(\"\\n\"), \"utf8\");\r\n // eslint-disable-next-line no-console\r\n console.log(`✅ Generated ${appEntryName} in ${srcRoot}`);\r\n}\r\n\r\n/**\r\n * Convert a relative path like \"foo/bar/index.tsx\" to a dot key.\r\n * If `collapseIndex` is true, \"foo/bar/index\" becomes \"foo.bar\".\r\n * Otherwise it becomes \"foo.bar.index\".\r\n */\r\nfunction pathToKey(relNoExt: string, opts: { collapseIndex: boolean }): string {\r\n let normalized = relNoExt.replace(/\\\\/g, \"/\");\r\n\r\n if (opts.collapseIndex) {\r\n normalized = normalized.replace(/\\/index$/i, \"\");\r\n }\r\n\r\n let key = normalized.split(\"/\").filter(Boolean).join(\".\");\r\n if (!key) key = \"index\";\r\n return key;\r\n}\r\n\r\n/**\r\n * Recursively collect entry files under dirPath.\r\n *\r\n * Rule:\r\n * - Prefer collapsing \".../index.tsx\" => \"...\" for nicer keys\r\n * - BUT if that key would collide with another entry, fallback to explicit \"...index\"\r\n * (e.g. \"foo.index\") for the index file ONLY.\r\n */\r\nfunction crawl(\r\n dirPath: string,\r\n baseDir: string,\r\n acc: PluginInputs,\r\n sets: { ignoreDirs: Set<string>; componentLikeDirs: Set<string> },\r\n appEntryAbsPath: string\r\n): void {\r\n if (!fs.existsSync(dirPath)) return;\r\n\r\n for (const item of fs.readdirSync(dirPath)) {\r\n const full = path.join(dirPath, item);\r\n const stat = fs.statSync(full);\r\n\r\n if (stat.isDirectory()) {\r\n if (isIgnoredDir(item, sets)) continue;\r\n crawl(full, baseDir, acc, sets, appEntryAbsPath);\r\n continue;\r\n }\r\n\r\n if (!EXT_PATTERN.test(item)) continue;\r\n\r\n // Don't include the generated entry itself (prevents self-import)\r\n if (path.resolve(full) === path.resolve(appEntryAbsPath)) {\r\n continue;\r\n }\r\n\r\n const relNoExt = path.relative(baseDir, full).replace(EXT_PATTERN, \"\");\r\n const isIndexFile = /(^|[\\\\/])index$/i.test(relNoExt);\r\n\r\n // Preferred key: collapse \".../index\" => \"...\"\r\n const preferred = pathToKey(relNoExt, { collapseIndex: true });\r\n\r\n // Explicit key: keep \".../index\" => \"...index\"\r\n // Example: \"foo/index\" => \"foo.index\"\r\n const explicit = pathToKey(relNoExt, { collapseIndex: false });\r\n\r\n let name = preferred;\r\n\r\n // If preferred collides, ONLY the index file switches to explicit path key.\r\n const existing = acc[name];\r\n if (existing && path.resolve(existing) !== path.resolve(full)) {\r\n if (isIndexFile) {\r\n // Use foo.index (or deeper.path.index) instead of suffixing __2\r\n if (!acc[explicit]) {\r\n // eslint-disable-next-line no-console\r\n console.warn(\r\n `⚠️ Key collision for \"${preferred}\" — using \"${explicit}\" for index file`,\r\n { existing: acc[preferred], incoming: full }\r\n );\r\n name = explicit;\r\n } else {\r\n // Extremely rare: even explicit collides (e.g. duplicate paths via symlinks)\r\n let i = 2;\r\n let next = `${explicit}__${i}`;\r\n while (acc[next]) {\r\n i += 1;\r\n next = `${explicit}__${i}`;\r\n }\r\n // eslint-disable-next-line no-console\r\n console.warn(`⚠️ Key collision for \"${explicit}\" — using \"${next}\"`, {\r\n existing: acc[explicit],\r\n incoming: full,\r\n });\r\n name = next;\r\n }\r\n } else {\r\n // Non-index collision: suffix like original behavior\r\n let i = 2;\r\n let next = `${name}__${i}`;\r\n while (acc[next]) {\r\n i += 1;\r\n next = `${name}__${i}`;\r\n }\r\n // eslint-disable-next-line no-console\r\n console.warn(`⚠️ Input key collision \"${name}\" -> using \"${next}\"`, {\r\n existing: acc[name],\r\n incoming: full,\r\n });\r\n name = next;\r\n }\r\n }\r\n\r\n acc[name] = full;\r\n }\r\n}\r\n\r\n/**\r\n * Discover integration pages/components and return a Rollup input map.\r\n *\r\n * @param srcRoot absolute or relative path to the source folder (e.g. \"resources/embed/ts\")\r\n * @param options\r\n * @returns Rollup input map: { [key]: absolutePath }\r\n */\r\nexport function generatePluginInputs(\r\n srcRoot: string = path.resolve(process.cwd(), \"ts\"),\r\n options: GeneratePluginInputsOptions = {}\r\n): PluginInputs {\r\n const {\r\n writeAppEntry = true,\r\n appEntryName = \"app.tsx\",\r\n includeAppEntryInInputs = true,\r\n appEntryKey = \"__app_entry\",\r\n verbose = true,\r\n } = options;\r\n\r\n const absRoot = path.resolve(srcRoot);\r\n const inputs: PluginInputs = {};\r\n\r\n const sets = makeIgnoreSets(options);\r\n const appEntryAbsPath = path.join(absRoot, appEntryName);\r\n\r\n // Crawl everything under absRoot (no folder assumptions)\r\n crawl(absRoot, absRoot, inputs, sets, appEntryAbsPath);\r\n\r\n if (verbose) {\r\n // eslint-disable-next-line no-console\r\n console.log(\"✅ Integrations discovered:\", inputs);\r\n }\r\n\r\n if (writeAppEntry) {\r\n writeAppEntryFile(inputs, absRoot, appEntryName);\r\n }\r\n\r\n if (!includeAppEntryInInputs) return inputs;\r\n\r\n return { ...inputs, [appEntryKey]: appEntryAbsPath };\r\n}"],"mappings":";AAAA,SAAS,qBAAqB;AAC9B,SAAS,cAAc,qBAAqB;AAC5C,SAAS,SAAS,WAAW,mBAAmB;;;ACChD,YAAY,OAAO;AAwCnB,IAAM,WAEF;AAAA,EACA,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,kBAAkB;AACtB;AAEA,IAAM,uBACF;AAEJ,SAAS,aAAa,IAAY,MAA0C;AACxE,QAAM,MAAM,KAAK,eAAe,CAAC;AACjC,QAAM,WAAW,KAAK,oBAAoB,CAAC;AAC3C,MAAI,IAAI,SAAS,EAAE,EAAG,QAAO;AAC7B,aAAW,KAAK,SAAU,KAAI,GAAG,WAAW,CAAC,EAAG,QAAO;AACvD,SAAO;AACX;AAEA,SAAS,wBAAwB,GAAuB;AACpD,aAAW,QAAQ,EAAE,MAAM;AACvB,QAAM,6BAA2B,IAAI,EAAG,QAAO;AAG/C,QAAM,2BAAyB,IAAI,KAAK,KAAK,YAAY,QAAQ;AAC7D,iBAAW,QAAQ,KAAK,YAAY;AAChC,cAAM,WAAa,eAAa,KAAK,QAAQ,IACvC,KAAK,SAAS,OACd,KAAK,SAAS;AACpB,YAAI,aAAa,UAAW,QAAO;AAAA,MACvC;AAAA,IACJ;AAAA,EACJ;AACA,SAAO;AACX;AAOA,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C;AACD,iBAAO;AAAA,QACX;AAAA,MACJ,OAAO;AAEH,YAAI,IAAI;AACR,YAAI,OAAO,GAAG,IAAI,KAAK,CAAC;AACxB,eAAO,IAAI,IAAI,GAAG;AACd,eAAK;AACL,iBAAO,GAAG,IAAI,KAAK,CAAC;AAAA,QACxB;AAEA,gBAAQ,KAAK,qCAA2B,IAAI,eAAe,IAAI,KAAK;AAAA,UAChE,UAAU,IAAI,IAAI;AAAA,UAClB,UAAU;AAAA,QACd,CAAC;AACD,eAAO;AAAA,MACX;AAAA,IACJ;AAEA,QAAI,IAAI,IAAI;AAAA,EAChB;AACJ;AASO,SAAS,qBACZ,UAAkB,KAAK,QAAQ,QAAQ,IAAI,GAAG,IAAI,GAClD,UAAuC,CAAC,GAC5B;AACZ,QAAM;AAAA,IACF,gBAAgB;AAAA,IAChB,eAAe;AAAA,IACf,0BAA0B;AAAA,IAC1B,cAAc;AAAA,IACd,UAAU;AAAA,EACd,IAAI;AAEJ,QAAM,UAAU,KAAK,QAAQ,OAAO;AACpC,QAAM,SAAuB,CAAC;AAE9B,QAAM,OAAO,eAAe,OAAO;AACnC,QAAM,kBAAkB,KAAK,KAAK,SAAS,YAAY;AAGvD,QAAM,SAAS,SAAS,QAAQ,MAAM,eAAe;AAErD,MAAI,SAAS;AAET,YAAQ,IAAI,mCAA8B,MAAM;AAAA,EACpD;AAEA,MAAI,eAAe;AACf,sBAAkB,QAAQ,SAAS,YAAY;AAAA,EACnD;AAEA,MAAI,CAAC,wBAAyB,QAAO;AAErC,SAAO,EAAE,GAAG,QAAQ,CAAC,WAAW,GAAG,gBAAgB;AACvD;","names":["path","shouldInject"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fortiplugin-bundle-adapter",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "",
5
5
  "files": [
6
6
  "dist"
@@ -22,7 +22,7 @@
22
22
  "typecheck": "tsc -p tsconfig.json",
23
23
  "test:transform": "node tests/run-transform.mjs",
24
24
  "prepublishOnly": "npm run build",
25
- "postpublish": "npm version patch && git push origin --follow-tags"
25
+ "postpublish": "npm version patch && git commit -m \"Updated package.json\" && git push origin --follow-tags"
26
26
  },
27
27
  "dependencies": {
28
28
  "@babel/core": "^7.28.5",