@mindees/compiler 0.1.0 → 0.2.0

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/README.md CHANGED
@@ -10,6 +10,12 @@ manifest, and a **plugin API**.
10
10
  > is a research track (`compileToNative` throws `NotImplementedError`). APIs may
11
11
  > change before `1.0`.
12
12
 
13
+ ## Install
14
+
15
+ ```bash
16
+ pnpm add -D @mindees/compiler
17
+ ```
18
+
13
19
  ## Why the TypeScript Compiler API?
14
20
 
15
21
  Only TypeScript can **type-check** — the compiler's #1 job. It also does JSX
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { NativeTarget, compileToNative } from "./aot.js";
2
2
  import { CompileOptions, CompileResult, CompileStats, Diagnostic, DiagnosticSeverity, MdcPlugin, SourcePosition } from "./types.js";
3
3
  import { STATIC_MARKER, createFlattenTransformer } from "./flatten.js";
4
- import { RouteEntry, RouteManifest, buildRouteManifest, chunkName, fileToRoute } from "./routes.js";
4
+ import { GenerateRouteModuleOptions, RouteEntry, RouteManifest, buildRouteManifest, chunkName, fileToRoute, generateRouteModule } from "./routes.js";
5
5
  import { compile, compileChecked } from "./transform.js";
6
6
  import { hasErrors, typecheck } from "./typecheck.js";
7
7
  import { Maturity, NotImplementedError, PackageInfo, notImplemented } from "@mindees/core";
@@ -10,7 +10,7 @@ import { Maturity, NotImplementedError, PackageInfo, notImplemented } from "@min
10
10
  /** The npm package name. */
11
11
  declare const name = "@mindees/compiler";
12
12
  /** The package version. All `@mindees/*` packages share one locked version line. */
13
- declare const VERSION = "0.1.0";
13
+ declare const VERSION = "0.2.0";
14
14
  /**
15
15
  * Current maturity. The build-time optimizer — type-check gate, TSX→createElement
16
16
  * transform, tree-flattening, per-route manifest, plugin API — is implemented
@@ -25,5 +25,5 @@ declare const maturity: Maturity;
25
25
  */
26
26
  declare const info: PackageInfo;
27
27
  //#endregion
28
- export { type CompileOptions, type CompileResult, type CompileStats, type Diagnostic, type DiagnosticSeverity, type Maturity, type MdcPlugin, type NativeTarget, NotImplementedError, type PackageInfo, type RouteEntry, type RouteManifest, STATIC_MARKER, type SourcePosition, VERSION, buildRouteManifest, chunkName, compile, compileChecked, compileToNative, createFlattenTransformer, fileToRoute, hasErrors, info, maturity, name, notImplemented, typecheck };
28
+ export { type CompileOptions, type CompileResult, type CompileStats, type Diagnostic, type DiagnosticSeverity, type GenerateRouteModuleOptions, type Maturity, type MdcPlugin, type NativeTarget, NotImplementedError, type PackageInfo, type RouteEntry, type RouteManifest, STATIC_MARKER, type SourcePosition, VERSION, buildRouteManifest, chunkName, compile, compileChecked, compileToNative, createFlattenTransformer, fileToRoute, generateRouteModule, hasErrors, info, maturity, name, notImplemented, typecheck };
29
29
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;AAkCA;AAAA,cAHa,IAAA;;cAGA,OAAA;AAAO;AAQpB;;;;AAAgD;AAR5B,cAQP,QAAA,EAAU,QAAyB;;;;AAOoC;;cAAvE,IAAA,EAAM,WAAiE"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;AAoCA;AAAA,cAHa,IAAA;;cAGA,OAAA;AAAO;AAQpB;;;;AAAgD;AAR5B,cAQP,QAAA,EAAU,QAAyB;;;;AAOoC;;cAAvE,IAAA,EAAM,WAAiE"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { compileToNative } from "./aot.js";
2
2
  import { STATIC_MARKER, createFlattenTransformer } from "./flatten.js";
3
- import { buildRouteManifest, chunkName, fileToRoute } from "./routes.js";
3
+ import { buildRouteManifest, chunkName, fileToRoute, generateRouteModule } from "./routes.js";
4
4
  import { hasErrors, typecheck } from "./typecheck.js";
5
5
  import { compile, compileChecked } from "./transform.js";
6
6
  import { NotImplementedError, notImplemented } from "@mindees/core";
@@ -8,7 +8,7 @@ import { NotImplementedError, notImplemented } from "@mindees/core";
8
8
  /** The npm package name. */
9
9
  const name = "@mindees/compiler";
10
10
  /** The package version. All `@mindees/*` packages share one locked version line. */
11
- const VERSION = "0.1.0";
11
+ const VERSION = "0.2.0";
12
12
  /**
13
13
  * Current maturity. The build-time optimizer — type-check gate, TSX→createElement
14
14
  * transform, tree-flattening, per-route manifest, plugin API — is implemented
@@ -27,6 +27,6 @@ const info = Object.freeze({
27
27
  maturity
28
28
  });
29
29
  //#endregion
30
- export { NotImplementedError, STATIC_MARKER, VERSION, buildRouteManifest, chunkName, compile, compileChecked, compileToNative, createFlattenTransformer, fileToRoute, hasErrors, info, maturity, name, notImplemented, typecheck };
30
+ export { NotImplementedError, STATIC_MARKER, VERSION, buildRouteManifest, chunkName, compile, compileChecked, compileToNative, createFlattenTransformer, fileToRoute, generateRouteModule, hasErrors, info, maturity, name, notImplemented, typecheck };
31
31
 
32
32
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Maturity, PackageInfo } from '@mindees/core'\nimport { NotImplementedError, notImplemented } from '@mindees/core'\n\n/** TS → native AOT (research track). */\nexport { compileToNative, type NativeTarget } from './aot'\n/** Tree-flattening optimizer pass. */\nexport { createFlattenTransformer, STATIC_MARKER } from './flatten'\n/** Per-route code-splitting manifest. */\nexport {\n buildRouteManifest,\n chunkName,\n fileToRoute,\n type RouteEntry,\n type RouteManifest,\n} from './routes'\n/** Compile pipeline (TSX → optimized JS). */\nexport { compile, compileChecked } from './transform'\n/** The type-check gate. */\nexport { hasErrors, typecheck } from './typecheck'\n/** Shared types. */\nexport type {\n CompileOptions,\n CompileResult,\n CompileStats,\n Diagnostic,\n DiagnosticSeverity,\n MdcPlugin,\n SourcePosition,\n} from './types'\n\n/** The npm package name. */\nexport const name = '@mindees/compiler'\n\n/** The package version. All `@mindees/*` packages share one locked version line. */\nexport const VERSION = '0.1.0'\n\n/**\n * Current maturity. The build-time optimizer — type-check gate, TSX→createElement\n * transform, tree-flattening, per-route manifest, plugin API — is implemented\n * and tested on the TypeScript Compiler API. TS→native AOT is a research track\n * (throws `NotImplementedError`); the working path is TS → optimized JS.\n */\nexport const maturity: Maturity = 'experimental'\n\n/**\n * Static identity + maturity metadata for this package. Frozen so the\n * self-reported identity tooling introspects cannot be mutated at runtime,\n * matching the `readonly` fields of {@link PackageInfo}.\n */\nexport const info: PackageInfo = Object.freeze({ name, version: VERSION, maturity })\n\nexport type { Maturity, PackageInfo }\nexport { NotImplementedError, notImplemented }\n"],"mappings":";;;;;;;;AA+BA,MAAa,OAAO;;AAGpB,MAAa,UAAU;;;;;;;AAQvB,MAAa,WAAqB;;;;;;AAOlC,MAAa,OAAoB,OAAO,OAAO;CAAE;CAAM,SAAS;CAAS;AAAS,CAAC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Maturity, PackageInfo } from '@mindees/core'\nimport { NotImplementedError, notImplemented } from '@mindees/core'\n\n/** TS → native AOT (research track). */\nexport { compileToNative, type NativeTarget } from './aot'\n/** Tree-flattening optimizer pass. */\nexport { createFlattenTransformer, STATIC_MARKER } from './flatten'\n/** Per-route code-splitting manifest + file-based route codegen. */\nexport {\n buildRouteManifest,\n chunkName,\n fileToRoute,\n type GenerateRouteModuleOptions,\n generateRouteModule,\n type RouteEntry,\n type RouteManifest,\n} from './routes'\n/** Compile pipeline (TSX → optimized JS). */\nexport { compile, compileChecked } from './transform'\n/** The type-check gate. */\nexport { hasErrors, typecheck } from './typecheck'\n/** Shared types. */\nexport type {\n CompileOptions,\n CompileResult,\n CompileStats,\n Diagnostic,\n DiagnosticSeverity,\n MdcPlugin,\n SourcePosition,\n} from './types'\n\n/** The npm package name. */\nexport const name = '@mindees/compiler'\n\n/** The package version. All `@mindees/*` packages share one locked version line. */\nexport const VERSION = '0.2.0'\n\n/**\n * Current maturity. The build-time optimizer — type-check gate, TSX→createElement\n * transform, tree-flattening, per-route manifest, plugin API — is implemented\n * and tested on the TypeScript Compiler API. TS→native AOT is a research track\n * (throws `NotImplementedError`); the working path is TS → optimized JS.\n */\nexport const maturity: Maturity = 'experimental'\n\n/**\n * Static identity + maturity metadata for this package. Frozen so the\n * self-reported identity tooling introspects cannot be mutated at runtime,\n * matching the `readonly` fields of {@link PackageInfo}.\n */\nexport const info: PackageInfo = Object.freeze({ name, version: VERSION, maturity })\n\nexport type { Maturity, PackageInfo }\nexport { NotImplementedError, notImplemented }\n"],"mappings":";;;;;;;;AAiCA,MAAa,OAAO;;AAGpB,MAAa,UAAU;;;;;;;AAQvB,MAAa,WAAqB;;;;;;AAOlC,MAAa,OAAoB,OAAO,OAAO;CAAE;CAAM,SAAS;CAAS;AAAS,CAAC"}
package/dist/routes.d.ts CHANGED
@@ -53,6 +53,31 @@ declare function chunkName(file: string): string;
53
53
  * buildRouteManifest(['index.tsx', 'about.tsx', 'blog/[slug].tsx', '+not-found.tsx'])
54
54
  */
55
55
  declare function buildRouteManifest(files: readonly string[]): RouteManifest;
56
+ /** Options for {@link generateRouteModule}. */
57
+ interface GenerateRouteModuleOptions {
58
+ /** Import-specifier prefix for the route files. Default `'./app'`. */
59
+ importBase?: string;
60
+ /** Name of the exported module-map constant. Default `'routes'`. */
61
+ exportName?: string;
62
+ }
63
+ /**
64
+ * Generate a TypeScript module that statically imports every route file and exposes
65
+ * them as a module map keyed by relative path — exactly the input
66
+ * `@mindees/router`'s `createFileRouter`/`routesFromModules` consume.
67
+ *
68
+ * This is the codegen behind **file-based routing** for bundlers without
69
+ * `import.meta.glob` (e.g. an embedded-engine native bundle): scan the `app/` dir, run
70
+ * this over the file list, write the result (e.g. `routes.gen.ts`), and import the map.
71
+ * Files are sorted for deterministic output. (`_layout`/`+not-found` are intentionally
72
+ * kept — the router applies them via its conventions.)
73
+ *
74
+ * @example
75
+ * generateRouteModule(['index.tsx', 'about.tsx'], { importBase: './app' })
76
+ * // import * as _route0 from './app/about'
77
+ * // import * as _route1 from './app/index'
78
+ * // export const routes = { 'about.tsx': _route0, 'index.tsx': _route1 }
79
+ */
80
+ declare function generateRouteModule(files: readonly string[], options?: GenerateRouteModuleOptions): string;
56
81
  //#endregion
57
- export { RouteEntry, RouteManifest, buildRouteManifest, chunkName, fileToRoute };
82
+ export { GenerateRouteModuleOptions, RouteEntry, RouteManifest, buildRouteManifest, chunkName, fileToRoute, generateRouteModule };
58
83
  //# sourceMappingURL=routes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"routes.d.ts","names":[],"sources":["../src/routes.ts"],"mappings":";;AAaA;;;;;;;;;;AAUU;AAAA,UAVO,UAAA;EAca;EAZ5B,SAAA;EAakB;EAXlB,IAAA;EAWQ;EATR,KAAA;EAWQ;EATR,MAAA;EA4Bc;EA1Bd,QAAA;AAAA;;UAIe,aAAA;EACf,MAAA,EAAQ,UAAU;EAuBlB;EArBA,QAAA;AAAA;AAsBQ;AA4CV;;;;AAAsC;AAmBtC;;;AA/DU,iBAHM,WAAA,CAAY,IAAA;EAC1B,SAAA;EACA,MAAA;EACA,QAAA;AAAA;;iBA4Cc,SAAA,CAAU,IAAY;;;;;;;;iBAmBtB,kBAAA,CAAmB,KAAA,sBAA2B,aAAa"}
1
+ {"version":3,"file":"routes.d.ts","names":[],"sources":["../src/routes.ts"],"mappings":";;AAaA;;;;;;;;;;AAUU;AAAA,UAVO,UAAA;EAca;EAZ5B,SAAA;EAakB;EAXlB,IAAA;EAWQ;EATR,KAAA;EAWQ;EATR,MAAA;EA4Bc;EA1Bd,QAAA;AAAA;;UAIe,aAAA;EACf,MAAA,EAAQ,UAAU;EAuBlB;EArBA,QAAA;AAAA;AAsBQ;AA4CV;;;;AAAsC;AAmBtC;;;AA/DU,iBAHM,WAAA,CAAY,IAAA;EAC1B,SAAA;EACA,MAAA;EACA,QAAA;AAAA;;iBA4Cc,SAAA,CAAU,IAAY;AA0FtC;;;;;;;AAAA,iBAvEgB,kBAAA,CAAmB,KAAA,sBAA2B,aAAa;AAyEjC;AAAA,UA1BzB,0BAAA;;EAEf,UAAA;;EAEA,UAAU;AAAA;;;;;;;;;;;;;;;;;;iBAoBI,mBAAA,CACd,KAAA,qBACA,OAAA,GAAS,0BAA+B"}
package/dist/routes.js CHANGED
@@ -83,7 +83,34 @@ function buildRouteManifest(files) {
83
83
  if (notFound !== void 0) manifest.notFound = notFound;
84
84
  return manifest;
85
85
  }
86
+ /**
87
+ * Generate a TypeScript module that statically imports every route file and exposes
88
+ * them as a module map keyed by relative path — exactly the input
89
+ * `@mindees/router`'s `createFileRouter`/`routesFromModules` consume.
90
+ *
91
+ * This is the codegen behind **file-based routing** for bundlers without
92
+ * `import.meta.glob` (e.g. an embedded-engine native bundle): scan the `app/` dir, run
93
+ * this over the file list, write the result (e.g. `routes.gen.ts`), and import the map.
94
+ * Files are sorted for deterministic output. (`_layout`/`+not-found` are intentionally
95
+ * kept — the router applies them via its conventions.)
96
+ *
97
+ * @example
98
+ * generateRouteModule(['index.tsx', 'about.tsx'], { importBase: './app' })
99
+ * // import * as _route0 from './app/about'
100
+ * // import * as _route1 from './app/index'
101
+ * // export const routes = { 'about.tsx': _route0, 'index.tsx': _route1 }
102
+ */
103
+ function generateRouteModule(files, options = {}) {
104
+ const importBase = (options.importBase ?? "./app").replace(/\/+$/, "");
105
+ const exportName = options.exportName ?? "routes";
106
+ const routeFiles = [...files].filter((f) => ROUTE_FILE.test(f)).sort();
107
+ const imports = routeFiles.map((file, i) => `import * as _route${i} from '${importBase}/${stripExt(file)}'`);
108
+ const entries = routeFiles.map((file, i) => ` ${JSON.stringify(file)}: _route${i},`);
109
+ const header = "// AUTO-GENERATED by @mindees/compiler generateRouteModule. Do not edit; regenerate when routes change.\n";
110
+ const body = `export const ${exportName} = {\n${entries.join("\n")}\n}\n`;
111
+ return imports.length > 0 ? `${header}${imports.join("\n")}\n\n${body}` : `${header}${body}`;
112
+ }
86
113
  //#endregion
87
- export { buildRouteManifest, chunkName, fileToRoute };
114
+ export { buildRouteManifest, chunkName, fileToRoute, generateRouteModule };
88
115
 
89
116
  //# sourceMappingURL=routes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"routes.js","names":[],"sources":["../src/routes.ts"],"sourcesContent":["/**\n * Per-route code-splitting: build a route manifest from a file tree.\n *\n * MDC maps a routes directory (file-based routing, à la the Quantum Router) to a\n * **manifest** of chunks — one lazily-loadable entry per route — so the bundler\n * can split per route and the runtime can load a route's code on demand. This\n * pass is platform-agnostic: it produces the manifest; wiring it to a specific\n * bundler/runtime is the CLI's job (Phase 5) and the router's job (Phase 6).\n *\n * @module\n */\n\n/** A single route in the manifest. */\nexport interface RouteEntry {\n /** URL path, e.g. `/`, `/about`, `/blog/[slug]`. */\n routePath: string\n /** Source file implementing the route, relative to the routes dir. */\n file: string\n /** Stable chunk name for the split bundle, e.g. `route_blog_slug`. */\n chunk: string\n /** Dynamic param names parsed from the path, e.g. `[\"slug\"]`. */\n params: string[]\n /** True for a catch-all segment (`[...rest]`). */\n catchAll: boolean\n}\n\n/** The route manifest: every route plus a not-found fallback if present. */\nexport interface RouteManifest {\n routes: RouteEntry[]\n /** The `+not-found` route file, if any. */\n notFound?: string\n}\n\nconst ROUTE_FILE = /\\.(tsx|ts|jsx|js)$/\n\n/** Strip the file extension. */\nfunction stripExt(file: string): string {\n return file.replace(ROUTE_FILE, '')\n}\n\n/**\n * Convert a file path (relative, POSIX separators) to a route path + params.\n *\n * Conventions (subset of the Quantum Router, see ROADMAP Phase 6):\n * - `index` → the directory's path (`index.tsx` → `/`).\n * - `[param]` → a dynamic segment (`:param`); collected into `params`.\n * - `[...rest]` → a catch-all segment; sets `catchAll`.\n * - `(group)` → a layout group that does NOT affect the URL (removed).\n */\nexport function fileToRoute(file: string): {\n routePath: string\n params: string[]\n catchAll: boolean\n} {\n const params: string[] = []\n let catchAll = false\n\n const segments = stripExt(file)\n .split('/')\n .filter((s) => s.length > 0)\n // Drop layout groups like `(marketing)`.\n .filter((s) => !(s.startsWith('(') && s.endsWith(')')))\n .map((s) => {\n // index → empty (resolves to parent path)\n if (s === 'index') return ''\n // [...rest] → catch-all\n const restMatch = s.match(/^\\[\\.\\.\\.(.+)\\]$/)\n if (restMatch?.[1]) {\n catchAll = true\n params.push(restMatch[1])\n return `:${restMatch[1]}*`\n }\n // [param] → dynamic\n const paramMatch = s.match(/^\\[(.+)\\]$/)\n if (paramMatch?.[1]) {\n params.push(paramMatch[1])\n return `:${paramMatch[1]}`\n }\n return s\n })\n .filter((s) => s.length > 0)\n\n // A catch-all must terminate the path; `docs/[...rest]/edit` is structurally\n // invalid and would otherwise emit a nonsensical `/docs/:rest*/edit`.\n const catchAllIndex = segments.findIndex((s) => s.endsWith('*'))\n if (catchAllIndex !== -1 && catchAllIndex !== segments.length - 1) {\n throw new Error(\n `Invalid route file \"${file}\": a catch-all segment ([...x]) must be the last segment.`,\n )\n }\n\n const routePath = segments.length === 0 ? '/' : `/${segments.join('/')}`\n return { routePath, params, catchAll }\n}\n\n/** Build a stable chunk name from a route file (filesystem-safe identifier). */\nexport function chunkName(file: string): string {\n const base = stripExt(file)\n .replace(/[/\\\\]/g, '_')\n .replace(/\\[\\.\\.\\.(.+?)\\]/g, 'rest_$1')\n .replace(/\\[(.+?)\\]/g, '$1')\n .replace(/[()]/g, '')\n .replace(/[^a-zA-Z0-9_]/g, '_')\n .replace(/_+/g, '_')\n .replace(/^_|_$/g, '')\n return `route_${base || 'index'}`\n}\n\n/**\n * Build a {@link RouteManifest} from a list of route files (relative paths,\n * POSIX `/` separators). Routes are sorted for deterministic output.\n *\n * @example\n * buildRouteManifest(['index.tsx', 'about.tsx', 'blog/[slug].tsx', '+not-found.tsx'])\n */\nexport function buildRouteManifest(files: readonly string[]): RouteManifest {\n const routes: RouteEntry[] = []\n let notFound: string | undefined\n // Detect collisions (e.g. `index.tsx` and `(app)/index.tsx` both map to `/`).\n const byPath = new Map<string, string>()\n // Distinct routes must also get distinct chunk names — `chunkName` is lossy\n // (e.g. `blog/[slug]` and `blog/slug` both strip to `route_blog_slug`), so a\n // collision here would silently make two routes share one split bundle.\n const byChunk = new Map<string, string>()\n\n for (const file of [...files].sort()) {\n if (!ROUTE_FILE.test(file)) continue\n const baseName = stripExt(file).split('/').pop() ?? ''\n if (baseName === '+not-found') {\n notFound = file\n continue\n }\n // Skip layout files (`_layout`) and other reserved `_`/`+` prefixed files\n // from the navigable route table (they're handled separately by the router).\n if (baseName.startsWith('_') || baseName.startsWith('+')) continue\n\n const { routePath, params, catchAll } = fileToRoute(file)\n const prior = byPath.get(routePath)\n if (prior !== undefined) {\n throw new Error(\n `Duplicate route path \"${routePath}\": both \"${prior}\" and \"${file}\" map to it.`,\n )\n }\n byPath.set(routePath, file)\n const chunk = chunkName(file)\n const priorChunk = byChunk.get(chunk)\n if (priorChunk !== undefined) {\n throw new Error(\n `Duplicate chunk name \"${chunk}\": both \"${priorChunk}\" and \"${file}\" produce it; ` +\n 'rename one route file so their split bundles do not collide.',\n )\n }\n byChunk.set(chunk, file)\n routes.push({ routePath, file, chunk, params, catchAll })\n }\n\n const manifest: RouteManifest = { routes }\n if (notFound !== undefined) manifest.notFound = notFound\n return manifest\n}\n"],"mappings":";AAiCA,MAAM,aAAa;;AAGnB,SAAS,SAAS,MAAsB;CACtC,OAAO,KAAK,QAAQ,YAAY,EAAE;AACpC;;;;;;;;;;AAWA,SAAgB,YAAY,MAI1B;CACA,MAAM,SAAmB,CAAC;CAC1B,IAAI,WAAW;CAEf,MAAM,WAAW,SAAS,IAAI,EAC3B,MAAM,GAAG,EACT,QAAQ,MAAM,EAAE,SAAS,CAAC,EAE1B,QAAQ,MAAM,EAAE,EAAE,WAAW,GAAG,KAAK,EAAE,SAAS,GAAG,EAAE,EACrD,KAAK,MAAM;EAEV,IAAI,MAAM,SAAS,OAAO;EAE1B,MAAM,YAAY,EAAE,MAAM,kBAAkB;EAC5C,IAAI,YAAY,IAAI;GAClB,WAAW;GACX,OAAO,KAAK,UAAU,EAAE;GACxB,OAAO,IAAI,UAAU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A,GACZ,MAAM,IAAI,MACR,yBAAyB,UAAU,WAAW,MAAM,SAAS,KAAK,aACpE;EAEF,OAAO,IAAI,WAAW,IAAI;EAC1B,MAAM,QAAQ,UAAU,IAAI;EAC5B,MAAM,aAAa,QAAQ,IAAI,KAAK;EACpC,IAAI,eAAe,KAAA,GACjB,MAAM,IAAI,MACR,yBAAyB,MAAM,WAAW,WAAW,SAAS,KAAK,2EAErE;EAEF,QAAQ,IAAI,OAAO,IAAI;EACvB,OAAO,KAAK;GAAE;GAAW;GAAM;GAAO;GAAQ;EAAS,CAAC;CAC1D;CAEA,MAAM,WAA0B,EAAE,OAAO;CACzC,IAAI,aAAa,KAAA,GAAW,SAAS,WAAW;CAChD,OAAO;AACT"}
1
+ {"version":3,"file":"routes.js","names":[],"sources":["../src/routes.ts"],"sourcesContent":["/**\n * Per-route code-splitting: build a route manifest from a file tree.\n *\n * MDC maps a routes directory (file-based routing, à la the Quantum Router) to a\n * **manifest** of chunks — one lazily-loadable entry per route — so the bundler\n * can split per route and the runtime can load a route's code on demand. This\n * pass is platform-agnostic: it produces the manifest; wiring it to a specific\n * bundler/runtime is the CLI's job (Phase 5) and the router's job (Phase 6).\n *\n * @module\n */\n\n/** A single route in the manifest. */\nexport interface RouteEntry {\n /** URL path, e.g. `/`, `/about`, `/blog/[slug]`. */\n routePath: string\n /** Source file implementing the route, relative to the routes dir. */\n file: string\n /** Stable chunk name for the split bundle, e.g. `route_blog_slug`. */\n chunk: string\n /** Dynamic param names parsed from the path, e.g. `[\"slug\"]`. */\n params: string[]\n /** True for a catch-all segment (`[...rest]`). */\n catchAll: boolean\n}\n\n/** The route manifest: every route plus a not-found fallback if present. */\nexport interface RouteManifest {\n routes: RouteEntry[]\n /** The `+not-found` route file, if any. */\n notFound?: string\n}\n\nconst ROUTE_FILE = /\\.(tsx|ts|jsx|js)$/\n\n/** Strip the file extension. */\nfunction stripExt(file: string): string {\n return file.replace(ROUTE_FILE, '')\n}\n\n/**\n * Convert a file path (relative, POSIX separators) to a route path + params.\n *\n * Conventions (subset of the Quantum Router, see ROADMAP Phase 6):\n * - `index` → the directory's path (`index.tsx` → `/`).\n * - `[param]` → a dynamic segment (`:param`); collected into `params`.\n * - `[...rest]` → a catch-all segment; sets `catchAll`.\n * - `(group)` → a layout group that does NOT affect the URL (removed).\n */\nexport function fileToRoute(file: string): {\n routePath: string\n params: string[]\n catchAll: boolean\n} {\n const params: string[] = []\n let catchAll = false\n\n const segments = stripExt(file)\n .split('/')\n .filter((s) => s.length > 0)\n // Drop layout groups like `(marketing)`.\n .filter((s) => !(s.startsWith('(') && s.endsWith(')')))\n .map((s) => {\n // index → empty (resolves to parent path)\n if (s === 'index') return ''\n // [...rest] → catch-all\n const restMatch = s.match(/^\\[\\.\\.\\.(.+)\\]$/)\n if (restMatch?.[1]) {\n catchAll = true\n params.push(restMatch[1])\n return `:${restMatch[1]}*`\n }\n // [param] → dynamic\n const paramMatch = s.match(/^\\[(.+)\\]$/)\n if (paramMatch?.[1]) {\n params.push(paramMatch[1])\n return `:${paramMatch[1]}`\n }\n return s\n })\n .filter((s) => s.length > 0)\n\n // A catch-all must terminate the path; `docs/[...rest]/edit` is structurally\n // invalid and would otherwise emit a nonsensical `/docs/:rest*/edit`.\n const catchAllIndex = segments.findIndex((s) => s.endsWith('*'))\n if (catchAllIndex !== -1 && catchAllIndex !== segments.length - 1) {\n throw new Error(\n `Invalid route file \"${file}\": a catch-all segment ([...x]) must be the last segment.`,\n )\n }\n\n const routePath = segments.length === 0 ? '/' : `/${segments.join('/')}`\n return { routePath, params, catchAll }\n}\n\n/** Build a stable chunk name from a route file (filesystem-safe identifier). */\nexport function chunkName(file: string): string {\n const base = stripExt(file)\n .replace(/[/\\\\]/g, '_')\n .replace(/\\[\\.\\.\\.(.+?)\\]/g, 'rest_$1')\n .replace(/\\[(.+?)\\]/g, '$1')\n .replace(/[()]/g, '')\n .replace(/[^a-zA-Z0-9_]/g, '_')\n .replace(/_+/g, '_')\n .replace(/^_|_$/g, '')\n return `route_${base || 'index'}`\n}\n\n/**\n * Build a {@link RouteManifest} from a list of route files (relative paths,\n * POSIX `/` separators). Routes are sorted for deterministic output.\n *\n * @example\n * buildRouteManifest(['index.tsx', 'about.tsx', 'blog/[slug].tsx', '+not-found.tsx'])\n */\nexport function buildRouteManifest(files: readonly string[]): RouteManifest {\n const routes: RouteEntry[] = []\n let notFound: string | undefined\n // Detect collisions (e.g. `index.tsx` and `(app)/index.tsx` both map to `/`).\n const byPath = new Map<string, string>()\n // Distinct routes must also get distinct chunk names — `chunkName` is lossy\n // (e.g. `blog/[slug]` and `blog/slug` both strip to `route_blog_slug`), so a\n // collision here would silently make two routes share one split bundle.\n const byChunk = new Map<string, string>()\n\n for (const file of [...files].sort()) {\n if (!ROUTE_FILE.test(file)) continue\n const baseName = stripExt(file).split('/').pop() ?? ''\n if (baseName === '+not-found') {\n notFound = file\n continue\n }\n // Skip layout files (`_layout`) and other reserved `_`/`+` prefixed files\n // from the navigable route table (they're handled separately by the router).\n if (baseName.startsWith('_') || baseName.startsWith('+')) continue\n\n const { routePath, params, catchAll } = fileToRoute(file)\n const prior = byPath.get(routePath)\n if (prior !== undefined) {\n throw new Error(\n `Duplicate route path \"${routePath}\": both \"${prior}\" and \"${file}\" map to it.`,\n )\n }\n byPath.set(routePath, file)\n const chunk = chunkName(file)\n const priorChunk = byChunk.get(chunk)\n if (priorChunk !== undefined) {\n throw new Error(\n `Duplicate chunk name \"${chunk}\": both \"${priorChunk}\" and \"${file}\" produce it; ` +\n 'rename one route file so their split bundles do not collide.',\n )\n }\n byChunk.set(chunk, file)\n routes.push({ routePath, file, chunk, params, catchAll })\n }\n\n const manifest: RouteManifest = { routes }\n if (notFound !== undefined) manifest.notFound = notFound\n return manifest\n}\n\n/** Options for {@link generateRouteModule}. */\nexport interface GenerateRouteModuleOptions {\n /** Import-specifier prefix for the route files. Default `'./app'`. */\n importBase?: string\n /** Name of the exported module-map constant. Default `'routes'`. */\n exportName?: string\n}\n\n/**\n * Generate a TypeScript module that statically imports every route file and exposes\n * them as a module map keyed by relative path — exactly the input\n * `@mindees/router`'s `createFileRouter`/`routesFromModules` consume.\n *\n * This is the codegen behind **file-based routing** for bundlers without\n * `import.meta.glob` (e.g. an embedded-engine native bundle): scan the `app/` dir, run\n * this over the file list, write the result (e.g. `routes.gen.ts`), and import the map.\n * Files are sorted for deterministic output. (`_layout`/`+not-found` are intentionally\n * kept — the router applies them via its conventions.)\n *\n * @example\n * generateRouteModule(['index.tsx', 'about.tsx'], { importBase: './app' })\n * // import * as _route0 from './app/about'\n * // import * as _route1 from './app/index'\n * // export const routes = { 'about.tsx': _route0, 'index.tsx': _route1 }\n */\nexport function generateRouteModule(\n files: readonly string[],\n options: GenerateRouteModuleOptions = {},\n): string {\n const importBase = (options.importBase ?? './app').replace(/\\/+$/, '')\n const exportName = options.exportName ?? 'routes'\n const routeFiles = [...files].filter((f) => ROUTE_FILE.test(f)).sort()\n const imports = routeFiles.map(\n (file, i) => `import * as _route${i} from '${importBase}/${stripExt(file)}'`,\n )\n const entries = routeFiles.map((file, i) => ` ${JSON.stringify(file)}: _route${i},`)\n const header =\n '// AUTO-GENERATED by @mindees/compiler generateRouteModule. Do not edit; regenerate when routes change.\\n'\n const body = `export const ${exportName} = {\\n${entries.join('\\n')}\\n}\\n`\n return imports.length > 0 ? `${header}${imports.join('\\n')}\\n\\n${body}` : `${header}${body}`\n}\n"],"mappings":";AAiCA,MAAM,aAAa;;AAGnB,SAAS,SAAS,MAAsB;CACtC,OAAO,KAAK,QAAQ,YAAY,EAAE;AACpC;;;;;;;;;;AAWA,SAAgB,YAAY,MAI1B;CACA,MAAM,SAAmB,CAAC;CAC1B,IAAI,WAAW;CAEf,MAAM,WAAW,SAAS,IAAI,EAC3B,MAAM,GAAG,EACT,QAAQ,MAAM,EAAE,SAAS,CAAC,EAE1B,QAAQ,MAAM,EAAE,EAAE,WAAW,GAAG,KAAK,EAAE,SAAS,GAAG,EAAE,EACrD,KAAK,MAAM;EAEV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HANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mindees/compiler",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "MindeesNative Compiler (MDC) — build-time optimizer: type-check gate, TSX→createElement transform, tree-flattening, per-route code-splitting, and a plugin API. TS→native AOT is a research track.",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "type": "module",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "typescript": "6.0.3",
27
- "@mindees/core": "0.1.0"
27
+ "@mindees/core": "0.2.0"
28
28
  },
29
29
  "scripts": {
30
30
  "build": "tsdown",