@collie-lang/vite 1.2.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -218,7 +218,15 @@ function colliePlugin(options = {}) {
218
218
  if (watcher) {
219
219
  watcher.addWatchFile(filePath);
220
220
  }
221
- const source = await import_promises.default.readFile(filePath, "utf-8");
221
+ let source;
222
+ try {
223
+ source = await import_promises.default.readFile(filePath, "utf-8");
224
+ } catch (error) {
225
+ if (error?.code === "ENOENT") {
226
+ continue;
227
+ }
228
+ throw error;
229
+ }
222
230
  const document = (0, import_compiler.parseCollie)(source, { filename: filePath });
223
231
  diagnostics.push(...document.diagnostics);
224
232
  for (const template of document.templates) {
@@ -243,7 +251,10 @@ function colliePlugin(options = {}) {
243
251
  }
244
252
  const errors = diagnostics.filter((diag) => diag.severity === "error");
245
253
  if (errors.length) {
246
- const formatted = errors.map((diag) => formatDiagnostic(root, diag, root)).join("\n");
254
+ const formatted = errors.map((diag) => {
255
+ const fileForDiag = diag.filePath ?? diag.file ?? root;
256
+ return formatDiagnostic(fileForDiag, diag, root);
257
+ }).join("\n");
247
258
  throw new Error(`[collie]
248
259
  ${formatted}`);
249
260
  }
@@ -343,6 +354,31 @@ ${formatted}`));
343
354
  return {
344
355
  name: "collie",
345
356
  enforce: "pre",
357
+ config(userConfig) {
358
+ const prevExclude = userConfig.optimizeDeps?.exclude ?? [];
359
+ const exclude = Array.from(/* @__PURE__ */ new Set([...prevExclude, "@collie-lang/react"]));
360
+ const prevNoExternal = userConfig.ssr?.noExternal;
361
+ let nextNoExternal;
362
+ if (prevNoExternal === true) {
363
+ nextNoExternal = true;
364
+ } else if (Array.isArray(prevNoExternal)) {
365
+ nextNoExternal = Array.from(/* @__PURE__ */ new Set([...prevNoExternal, "@collie-lang/react"]));
366
+ } else if (prevNoExternal == null) {
367
+ nextNoExternal = ["@collie-lang/react"];
368
+ } else {
369
+ nextNoExternal = Array.from(/* @__PURE__ */ new Set([prevNoExternal, "@collie-lang/react"]));
370
+ }
371
+ return {
372
+ optimizeDeps: {
373
+ exclude
374
+ },
375
+ ...nextNoExternal ? {
376
+ ssr: {
377
+ noExternal: nextNoExternal
378
+ }
379
+ } : {}
380
+ };
381
+ },
346
382
  configResolved(config) {
347
383
  resolvedRuntime = options.jsxRuntime ?? "automatic";
348
384
  resolvedConfig = config;
@@ -368,7 +404,8 @@ ${formatted}`));
368
404
  if (cleanId.startsWith(VIRTUAL_TEMPLATE_RESOLVED_PREFIX)) {
369
405
  return cleanId;
370
406
  }
371
- if (!isVirtualCollieId(cleanId) && cleanId.endsWith(".collie")) {
407
+ const isInternalImporter = typeof importer === "string" && (importer.startsWith("\0collie:") || importer.startsWith("collie:"));
408
+ if (!isVirtualCollieId(cleanId) && cleanId.endsWith(".collie") && !isInternalImporter) {
372
409
  this.error(buildDirectImportError(cleanId, importer, resolvedConfig?.root));
373
410
  }
374
411
  return null;
@@ -423,6 +460,7 @@ ${lines.join("\n")}
423
460
  } catch (error) {
424
461
  const err = error instanceof Error ? error : new Error(String(error));
425
462
  this.error(err);
463
+ return null;
426
464
  }
427
465
  const record = templatesByEncodedId.get(encoded);
428
466
  if (!record) {
@@ -432,6 +470,7 @@ ${lines.join("\n")}
432
470
  } catch {
433
471
  }
434
472
  this.error(new Error(`[collie] Unknown template id "${decoded}".`));
473
+ return null;
435
474
  }
436
475
  const result = (0, import_compiler.compileTemplate)(record.template, {
437
476
  filename: record.filePath,
@@ -443,6 +482,7 @@ ${lines.join("\n")}
443
482
  const formatted = errors.map((diag) => formatDiagnostic(record.filePath, diag, resolvedConfig?.root)).join("\n");
444
483
  this.error(new Error(`[collie]
445
484
  ${formatted}`));
485
+ return null;
446
486
  }
447
487
  const transformed = await (0, import_vite.transformWithEsbuild)(result.code, record.filePath, {
448
488
  loader: "tsx",
@@ -457,7 +497,11 @@ ${formatted}`));
457
497
  if (isCollieFile(cleanId)) {
458
498
  const info = this.getModuleInfo(cleanId);
459
499
  const importer = info?.importers?.[0];
460
- this.error(buildDirectImportError(cleanId, importer, resolvedConfig?.root));
500
+ const isInternalImporter = typeof importer === "string" && (importer.startsWith("\0collie:") || importer.startsWith("collie:"));
501
+ if (!isInternalImporter) {
502
+ this.error(buildDirectImportError(cleanId, importer, resolvedConfig?.root));
503
+ }
504
+ return null;
461
505
  }
462
506
  return null;
463
507
  },
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import path from \"node:path\";\nimport fs from \"node:fs/promises\";\nimport fg from \"fast-glob\";\nimport type { HmrContext, ModuleNode, Plugin, ResolvedConfig } from \"vite\";\nimport { normalizePath, transformWithEsbuild } from \"vite\";\nimport type { Diagnostic, TemplateUnit } from \"@collie-lang/compiler\";\nimport { compileTemplate, parseCollie } from \"@collie-lang/compiler\";\n\ntype JsxRuntime = \"automatic\" | \"classic\";\n\nexport interface ColliePluginOptions {\n jsxRuntime?: JsxRuntime;\n}\n\ninterface TemplateLocation {\n file: string;\n line?: number;\n col?: number;\n}\n\ninterface TemplateRecord {\n id: string;\n encodedId: string;\n filePath: string;\n template: TemplateUnit;\n location: TemplateLocation;\n}\n\nconst VIRTUAL_REGISTRY_ID = \"virtual:collie/registry\";\nconst VIRTUAL_REGISTRY_RESOLVED = \"\\0collie:registry\";\nconst VIRTUAL_IDS_ID = \"virtual:collie/ids\";\nconst VIRTUAL_IDS_RESOLVED = \"\\0collie:ids\";\nconst VIRTUAL_TEMPLATE_PREFIX = \"virtual:collie/template/\";\nconst VIRTUAL_TEMPLATE_RESOLVED_PREFIX = \"\\0collie:template:\";\nconst COLLIE_GLOB = \"**/*.collie\";\nconst DEFAULT_IGNORE_GLOBS = [\"**/node_modules/**\", \"**/.git/**\", \"**/dist/**\", \"**/build/**\", \"**/.vite/**\"];\n\nfunction stripQuery(id: string): string {\n const q = id.indexOf(\"?\");\n return q === -1 ? id : id.slice(0, q);\n}\n\nfunction isCollieFile(id: string): boolean {\n return stripQuery(id).endsWith(\".collie\");\n}\n\nfunction toDisplayPath(filePath: string, root?: string): string {\n const normalized = normalizePath(filePath);\n if (!root || !path.isAbsolute(filePath)) {\n return normalized;\n }\n const relative = path.relative(root, filePath);\n if (!relative || relative.startsWith(\"..\")) {\n return normalized;\n }\n return normalizePath(relative);\n}\n\nfunction formatDiagnostic(id: string, diagnostic: Diagnostic, root?: string): string {\n const file = diagnostic.filePath ?? diagnostic.file ?? stripQuery(id);\n const displayFile = toDisplayPath(file, root);\n const range = diagnostic.range ?? diagnostic.span;\n const where = range ? `${range.start.line}:${range.start.col}` : \"\";\n const location = where ? `${displayFile}:${where}` : displayFile;\n const code = diagnostic.code ? diagnostic.code : \"COLLIE\";\n return `${location} [${code}] ${diagnostic.message}`;\n}\n\nfunction isVirtualCollieId(id: string): boolean {\n return (\n id === VIRTUAL_REGISTRY_ID ||\n id === VIRTUAL_REGISTRY_RESOLVED ||\n id === VIRTUAL_IDS_ID ||\n id === VIRTUAL_IDS_RESOLVED ||\n id.startsWith(VIRTUAL_TEMPLATE_PREFIX) ||\n id.startsWith(VIRTUAL_TEMPLATE_RESOLVED_PREFIX)\n );\n}\n\nfunction buildDirectImportError(importedId: string, importer?: string, root?: string): Error {\n const importLine = stripQuery(importedId);\n const importerLabel = importer ? toDisplayPath(importer, root) : \"<unknown>\";\n const lines = [\n \"Direct .collie imports are not supported.\",\n `Importer: ${importerLabel}`,\n `Import: ${importLine}`,\n \"Use the registry runtime instead:\",\n \"import { Collie } from '@collie-lang/react'\",\n '<Collie id=\"Your.TemplateId\" />',\n \"Templates are discovered automatically by @collie-lang/vite.\"\n ];\n return new Error(lines.join(\"\\n\"));\n}\n\nfunction encodeTemplateId(id: string): string {\n return Buffer.from(id, \"utf8\")\n .toString(\"base64\")\n .replace(/\\+/g, \"-\")\n .replace(/\\//g, \"_\")\n .replace(/=+$/g, \"\");\n}\n\nfunction decodeTemplateId(encoded: string): string {\n const normalized = encoded.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const padLength = normalized.length % 4;\n const padded = padLength === 0 ? normalized : normalized + \"=\".repeat(4 - padLength);\n return Buffer.from(padded, \"base64\").toString(\"utf8\");\n}\n\nfunction formatLocation(location: TemplateLocation, root?: string): string {\n const file = toDisplayPath(location.file, root);\n if (typeof location.line === \"number\" && typeof location.col === \"number\") {\n return `${file}:${location.line}:${location.col}`;\n }\n return file;\n}\n\nfunction formatDuplicateIdError(duplicates: Map<string, TemplateLocation[]>, root?: string): string {\n const lines = [\"[collie] Duplicate template ids detected:\"];\n const entries = Array.from(duplicates.entries()).sort((a, b) => a[0].localeCompare(b[0]));\n for (const [id, locations] of entries) {\n const formatted = locations.map((location) => formatLocation(location, root)).join(\", \");\n lines.push(`- ${id}: ${formatted}`);\n }\n return lines.join(\"\\n\");\n}\n\nfunction buildIgnoreGlobs(config?: ResolvedConfig): string[] {\n const ignore = new Set(DEFAULT_IGNORE_GLOBS);\n if (!config) {\n return Array.from(ignore);\n }\n\n const addRelativeDir = (dir?: string): void => {\n if (!dir) {\n return;\n }\n const absolute = path.isAbsolute(dir) ? dir : path.join(config.root, dir);\n const relative = normalizePath(path.relative(config.root, absolute));\n if (!relative || relative.startsWith(\"..\")) {\n return;\n }\n ignore.add(`${relative}/**`);\n };\n\n addRelativeDir(config.build?.outDir);\n addRelativeDir(config.cacheDir);\n addRelativeDir(config.publicDir);\n\n return Array.from(ignore);\n}\n\nexport default function colliePlugin(options: ColliePluginOptions = {}): Plugin {\n let resolvedRuntime: JsxRuntime = options.jsxRuntime ?? \"automatic\";\n let resolvedConfig: ResolvedConfig | undefined;\n let needsScan = true;\n const templatesById = new Map<string, TemplateRecord>();\n const templatesByEncodedId = new Map<string, TemplateRecord>();\n const fileToTemplateIds = new Map<string, Set<string>>();\n const templateIdToVirtualId = new Map<string, string>();\n\n const resetTemplates = (): void => {\n needsScan = true;\n templatesById.clear();\n templatesByEncodedId.clear();\n fileToTemplateIds.clear();\n templateIdToVirtualId.clear();\n };\n\n const trackTemplateRecord = (record: TemplateRecord): void => {\n templatesById.set(record.id, record);\n templatesByEncodedId.set(record.encodedId, record);\n templateIdToVirtualId.set(record.id, `${VIRTUAL_TEMPLATE_RESOLVED_PREFIX}${record.encodedId}`);\n const ids = fileToTemplateIds.get(record.filePath) ?? new Set<string>();\n ids.add(record.id);\n fileToTemplateIds.set(record.filePath, ids);\n };\n\n const removeFileTemplates = (filePath: string): Set<string> => {\n const ids = fileToTemplateIds.get(filePath) ?? new Set<string>();\n for (const id of ids) {\n const record = templatesById.get(id);\n if (record && record.filePath === filePath) {\n templatesById.delete(id);\n templatesByEncodedId.delete(record.encodedId);\n templateIdToVirtualId.delete(id);\n }\n }\n fileToTemplateIds.delete(filePath);\n return ids;\n };\n\n const collectModuleIds = (ids: Iterable<string>): Set<string> => {\n const moduleIds = new Set<string>();\n for (const id of ids) {\n const moduleId = templateIdToVirtualId.get(id);\n if (moduleId) {\n moduleIds.add(moduleId);\n }\n }\n return moduleIds;\n };\n\n const reportHmrError = (ctx: HmrContext, error: unknown): void => {\n const err = error instanceof Error ? error : new Error(String(error));\n ctx.server.config.logger.error(err.message);\n ctx.server.ws.send({\n type: \"error\",\n err: {\n message: err.message,\n stack: err.stack ?? \"\"\n }\n });\n };\n\n const ensureTemplates = async (watcher?: { addWatchFile: (id: string) => void }): Promise<void> => {\n if (!needsScan) {\n return;\n }\n\n if (!resolvedConfig) {\n throw new Error(\"[collie] Vite config was not resolved before scanning templates.\");\n }\n\n templatesById.clear();\n templatesByEncodedId.clear();\n fileToTemplateIds.clear();\n templateIdToVirtualId.clear();\n\n const root = resolvedConfig.root ?? process.cwd();\n const ignore = buildIgnoreGlobs(resolvedConfig);\n const filePaths = await fg(COLLIE_GLOB, {\n cwd: root,\n absolute: true,\n onlyFiles: true,\n ignore\n });\n\n const diagnostics: Diagnostic[] = [];\n const locationsById = new Map<string, TemplateLocation[]>();\n\n for (const filePath of filePaths) {\n if (watcher) {\n watcher.addWatchFile(filePath);\n }\n const source = await fs.readFile(filePath, \"utf-8\");\n const document = parseCollie(source, { filename: filePath });\n diagnostics.push(...document.diagnostics);\n\n for (const template of document.templates) {\n const location: TemplateLocation = {\n file: filePath,\n line: template.span?.start.line,\n col: template.span?.start.col\n };\n const encodedId = encodeTemplateId(template.id);\n const record: TemplateRecord = {\n id: template.id,\n encodedId,\n filePath,\n template,\n location\n };\n trackTemplateRecord(record);\n const locations = locationsById.get(template.id) ?? [];\n locations.push(location);\n locationsById.set(template.id, locations);\n }\n }\n\n const errors = diagnostics.filter((diag) => diag.severity === \"error\");\n if (errors.length) {\n const formatted = errors\n .map((diag) => formatDiagnostic(root, diag, root))\n .join(\"\\n\");\n throw new Error(`[collie]\\n${formatted}`);\n }\n\n const duplicates = new Map(\n Array.from(locationsById.entries()).filter(([, locations]) => locations.length > 1)\n );\n if (duplicates.size) {\n throw new Error(formatDuplicateIdError(duplicates, root));\n }\n\n needsScan = false;\n };\n\n const updateFileTemplates = async (ctx: HmrContext): Promise<ModuleNode[]> => {\n if (needsScan) {\n try {\n await ensureTemplates();\n } catch (error) {\n reportHmrError(ctx, error);\n return [];\n }\n }\n\n const filePath = ctx.file;\n const root = resolvedConfig?.root ?? process.cwd();\n const previousIds = fileToTemplateIds.get(filePath) ?? new Set<string>();\n const previousModuleIds = collectModuleIds(previousIds);\n\n let source: string | null = null;\n try {\n source = await fs.readFile(filePath, \"utf-8\");\n } catch (error) {\n if ((error as NodeJS.ErrnoException)?.code === \"ENOENT\") {\n removeFileTemplates(filePath);\n return invalidateModules(ctx, previousModuleIds);\n }\n reportHmrError(ctx, error);\n return [];\n }\n\n const document = parseCollie(source, { filename: filePath });\n const errors = document.diagnostics.filter((diag: Diagnostic) => diag.severity === \"error\");\n if (errors.length) {\n const formatted = errors.map((diag: Diagnostic) => formatDiagnostic(filePath, diag, root)).join(\"\\n\");\n reportHmrError(ctx, new Error(`[collie]\\n${formatted}`));\n return [];\n }\n\n const duplicates = new Map<string, TemplateLocation[]>();\n for (const template of document.templates) {\n const existing = templatesById.get(template.id);\n if (existing && existing.filePath !== filePath) {\n const locations = duplicates.get(template.id) ?? [existing.location];\n locations.push({\n file: filePath,\n line: template.span?.start.line,\n col: template.span?.start.col\n });\n duplicates.set(template.id, locations);\n }\n }\n if (duplicates.size) {\n reportHmrError(ctx, new Error(formatDuplicateIdError(duplicates, root)));\n return [];\n }\n\n removeFileTemplates(filePath);\n for (const template of document.templates) {\n const record: TemplateRecord = {\n id: template.id,\n encodedId: encodeTemplateId(template.id),\n filePath,\n template,\n location: {\n file: filePath,\n line: template.span?.start.line,\n col: template.span?.start.col\n }\n };\n trackTemplateRecord(record);\n }\n\n const nextIds = fileToTemplateIds.get(filePath) ?? new Set<string>();\n const nextModuleIds = collectModuleIds(nextIds);\n const moduleIds = new Set<string>([...previousModuleIds, ...nextModuleIds]);\n return invalidateModules(ctx, moduleIds);\n };\n\n const invalidateModules = (ctx: HmrContext, moduleIds: Iterable<string>): ModuleNode[] => {\n const modules: ModuleNode[] = [];\n const registryModule = ctx.server.moduleGraph.getModuleById(VIRTUAL_REGISTRY_RESOLVED);\n if (registryModule) {\n ctx.server.moduleGraph.invalidateModule(registryModule);\n modules.push(registryModule);\n }\n for (const moduleId of moduleIds) {\n const mod = ctx.server.moduleGraph.getModuleById(moduleId);\n if (mod) {\n ctx.server.moduleGraph.invalidateModule(mod);\n modules.push(mod);\n }\n }\n return modules;\n };\n\n return {\n name: \"collie\",\n enforce: \"pre\",\n\n configResolved(config) {\n resolvedRuntime = options.jsxRuntime ?? \"automatic\";\n resolvedConfig = config;\n resetTemplates();\n },\n\n resolveId(id, importer) {\n const cleanId = stripQuery(id);\n if (cleanId === VIRTUAL_REGISTRY_ID) {\n return VIRTUAL_REGISTRY_RESOLVED;\n }\n if (cleanId === VIRTUAL_IDS_ID) {\n return VIRTUAL_IDS_RESOLVED;\n }\n if (cleanId === VIRTUAL_REGISTRY_RESOLVED) {\n return cleanId;\n }\n if (cleanId === VIRTUAL_IDS_RESOLVED) {\n return cleanId;\n }\n if (cleanId.startsWith(VIRTUAL_TEMPLATE_PREFIX)) {\n return VIRTUAL_TEMPLATE_RESOLVED_PREFIX + cleanId.slice(VIRTUAL_TEMPLATE_PREFIX.length);\n }\n if (cleanId.startsWith(VIRTUAL_TEMPLATE_RESOLVED_PREFIX)) {\n return cleanId;\n }\n if (!isVirtualCollieId(cleanId) && cleanId.endsWith(\".collie\")) {\n this.error(buildDirectImportError(cleanId, importer, resolvedConfig?.root));\n }\n return null;\n },\n\n async load(id) {\n const cleanId = stripQuery(id);\n if (cleanId === VIRTUAL_REGISTRY_RESOLVED) {\n try {\n await ensureTemplates(this);\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error));\n this.error(err);\n }\n\n const entries = Array.from(templatesById.values()).sort((a, b) =>\n a.id.localeCompare(b.id)\n );\n const lines = entries.map(\n (record) =>\n ` ${JSON.stringify(record.id)}: () => import(${JSON.stringify(\n `${VIRTUAL_TEMPLATE_PREFIX}${record.encodedId}`\n )}),`\n );\n return {\n code: [\n \"/** @type {Record<string, () => Promise<{ render: (props: any) => any }>>} */\",\n `export const registry = {\\n${lines.join(\"\\n\")}\\n};`\n ].join(\"\\n\"),\n map: null\n };\n }\n\n if (cleanId === VIRTUAL_IDS_RESOLVED) {\n try {\n await ensureTemplates(this);\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error));\n this.error(err);\n }\n\n const ids = Array.from(templatesById.keys()).sort((a, b) => a.localeCompare(b));\n return {\n code: [\n \"/** @type {readonly string[]} */\",\n `export const ids = ${JSON.stringify(ids)};`\n ].join(\"\\n\"),\n map: null\n };\n }\n\n if (cleanId.startsWith(VIRTUAL_TEMPLATE_RESOLVED_PREFIX)) {\n const encoded = cleanId.slice(VIRTUAL_TEMPLATE_RESOLVED_PREFIX.length);\n try {\n await ensureTemplates(this);\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error));\n this.error(err);\n }\n\n const record = templatesByEncodedId.get(encoded);\n if (!record) {\n let decoded = encoded;\n try {\n decoded = decodeTemplateId(encoded);\n } catch {\n // Keep encoded value for the error message.\n }\n this.error(new Error(`[collie] Unknown template id \"${decoded}\".`));\n }\n\n const result = compileTemplate(record.template, {\n filename: record.filePath,\n jsxRuntime: resolvedRuntime,\n flavor: \"tsx\"\n });\n\n const errors = result.diagnostics.filter((diag) => diag.severity === \"error\");\n if (errors.length) {\n const formatted = errors\n .map((diag) => formatDiagnostic(record.filePath, diag, resolvedConfig?.root))\n .join(\"\\n\");\n this.error(new Error(`[collie]\\n${formatted}`));\n }\n\n const transformed = await transformWithEsbuild(result.code, record.filePath, {\n loader: \"tsx\",\n jsx: resolvedRuntime === \"classic\" ? \"transform\" : \"automatic\",\n jsxImportSource: \"react\"\n });\n\n return {\n code: transformed.code,\n map: transformed.map ?? null\n };\n }\n if (isCollieFile(cleanId)) {\n const info = this.getModuleInfo(cleanId);\n const importer = info?.importers?.[0];\n this.error(buildDirectImportError(cleanId, importer, resolvedConfig?.root));\n }\n\n return null;\n },\n\n handleHotUpdate(ctx: HmrContext) {\n if (!isCollieFile(ctx.file)) {\n return;\n }\n\n return updateFileTemplates(ctx);\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AACjB,sBAAe;AACf,uBAAe;AAEf,kBAAoD;AAEpD,sBAA6C;AAsB7C,IAAM,sBAAsB;AAC5B,IAAM,4BAA4B;AAClC,IAAM,iBAAiB;AACvB,IAAM,uBAAuB;AAC7B,IAAM,0BAA0B;AAChC,IAAM,mCAAmC;AACzC,IAAM,cAAc;AACpB,IAAM,uBAAuB,CAAC,sBAAsB,cAAc,cAAc,eAAe,aAAa;AAE5G,SAAS,WAAW,IAAoB;AACtC,QAAM,IAAI,GAAG,QAAQ,GAAG;AACxB,SAAO,MAAM,KAAK,KAAK,GAAG,MAAM,GAAG,CAAC;AACtC;AAEA,SAAS,aAAa,IAAqB;AACzC,SAAO,WAAW,EAAE,EAAE,SAAS,SAAS;AAC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jB,gBAAM,YAAY,OACf,IAAI,CAAC,SAAS,iBAAiB,OAAO,UAAU,MAAM,gBAAgB,IAAI,CAAC,EAC3E,KAAK,IAAI;AACZ,eAAK,MAAM,IAAI,MAAM;AAAA,EAAa,SAAS,EAAE,CAAC;AAAA,QAChD;AAEA,cAAM,cAAc,UAAM,kCAAqB,OAAO,MAAM,OAAO,UAAU;AAAA,UAC3E,QAAQ;AAAA,UACR,KAAK,oBAAoB,YAAY,cAAc;AAAA,UACnD,iBAAiB;AAAA,QACnB,CAAC;AAED,eAAO;AAAA,UACL,MAAM,YAAY;AAAA,UAClB,KAAK,YAAY,OAAO;AAAA,QAC1B;AAAA,MACF;AACA,UAAI,aAAa,OAAO,GAAG;AACzB,cAAM,OAAO,KAAK,cAAc,OAAO;AACvC,cAAM,WAAW,MAAM,YAAY,CAAC;AACpC,aAAK,MAAM,uBAAuB,SAAS,UAAU,gBAAgB,IAAI,CAAC;AAAA,MAC5E;AAEA,aAAO;AAAA,IACT;AAAA,IAEA,gBAAgB,KAAiB;AAC/B,UAAI,CAAC,aAAa,IAAI,IAAI,GAAG;AAC3B;AAAA,MACF;AAEA,aAAO,oBAAoB,GAAG;AAAA,IAChC;AAAA,EACF;AACF;","names":["path","fg","fs"]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import path from \"node:path\";\nimport fs from \"node:fs/promises\";\nimport fg from \"fast-glob\";\nimport type { HmrContext, ModuleNode, Plugin, ResolvedConfig } from \"vite\";\nimport { normalizePath, transformWithEsbuild } from \"vite\";\nimport type { Diagnostic, TemplateUnit } from \"@collie-lang/compiler\";\nimport { compileTemplate, parseCollie } from \"@collie-lang/compiler\";\n\ntype JsxRuntime = \"automatic\" | \"classic\";\n\nexport interface ColliePluginOptions {\n jsxRuntime?: JsxRuntime;\n}\n\ninterface TemplateLocation {\n file: string;\n line?: number;\n col?: number;\n}\n\ninterface TemplateRecord {\n id: string;\n encodedId: string;\n filePath: string;\n template: TemplateUnit;\n location: TemplateLocation;\n}\n\nconst VIRTUAL_REGISTRY_ID = \"virtual:collie/registry\";\nconst VIRTUAL_REGISTRY_RESOLVED = \"\\0collie:registry\";\nconst VIRTUAL_IDS_ID = \"virtual:collie/ids\";\nconst VIRTUAL_IDS_RESOLVED = \"\\0collie:ids\";\nconst VIRTUAL_TEMPLATE_PREFIX = \"virtual:collie/template/\";\nconst VIRTUAL_TEMPLATE_RESOLVED_PREFIX = \"\\0collie:template:\";\nconst COLLIE_GLOB = \"**/*.collie\";\nconst DEFAULT_IGNORE_GLOBS = [\"**/node_modules/**\", \"**/.git/**\", \"**/dist/**\", \"**/build/**\", \"**/.vite/**\"];\n\nfunction stripQuery(id: string): string {\n const q = id.indexOf(\"?\");\n return q === -1 ? id : id.slice(0, q);\n}\n\nfunction isCollieFile(id: string): boolean {\n return stripQuery(id).endsWith(\".collie\");\n}\n\nfunction toDisplayPath(filePath: string, root?: string): string {\n const normalized = normalizePath(filePath);\n if (!root || !path.isAbsolute(filePath)) {\n return normalized;\n }\n const relative = path.relative(root, filePath);\n if (!relative || relative.startsWith(\"..\")) {\n return normalized;\n }\n return normalizePath(relative);\n}\n\nfunction formatDiagnostic(id: string, diagnostic: Diagnostic, root?: string): string {\n const file = diagnostic.filePath ?? diagnostic.file ?? stripQuery(id);\n const displayFile = toDisplayPath(file, root);\n const range = diagnostic.range ?? diagnostic.span;\n const where = range ? `${range.start.line}:${range.start.col}` : \"\";\n const location = where ? `${displayFile}:${where}` : displayFile;\n const code = diagnostic.code ? diagnostic.code : \"COLLIE\";\n return `${location} [${code}] ${diagnostic.message}`;\n}\n\nfunction isVirtualCollieId(id: string): boolean {\n return (\n id === VIRTUAL_REGISTRY_ID ||\n id === VIRTUAL_REGISTRY_RESOLVED ||\n id === VIRTUAL_IDS_ID ||\n id === VIRTUAL_IDS_RESOLVED ||\n id.startsWith(VIRTUAL_TEMPLATE_PREFIX) ||\n id.startsWith(VIRTUAL_TEMPLATE_RESOLVED_PREFIX)\n );\n}\n\nfunction buildDirectImportError(importedId: string, importer?: string, root?: string): Error {\n const importLine = stripQuery(importedId);\n const importerLabel = importer ? toDisplayPath(importer, root) : \"<unknown>\";\n const lines = [\n \"Direct .collie imports are not supported.\",\n `Importer: ${importerLabel}`,\n `Import: ${importLine}`,\n \"Use the registry runtime instead:\",\n \"import { Collie } from '@collie-lang/react'\",\n '<Collie id=\"Your.TemplateId\" />',\n \"Templates are discovered automatically by @collie-lang/vite.\"\n ];\n return new Error(lines.join(\"\\n\"));\n}\n\nfunction encodeTemplateId(id: string): string {\n return Buffer.from(id, \"utf8\")\n .toString(\"base64\")\n .replace(/\\+/g, \"-\")\n .replace(/\\//g, \"_\")\n .replace(/=+$/g, \"\");\n}\n\nfunction decodeTemplateId(encoded: string): string {\n const normalized = encoded.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const padLength = normalized.length % 4;\n const padded = padLength === 0 ? normalized : normalized + \"=\".repeat(4 - padLength);\n return Buffer.from(padded, \"base64\").toString(\"utf8\");\n}\n\nfunction formatLocation(location: TemplateLocation, root?: string): string {\n const file = toDisplayPath(location.file, root);\n if (typeof location.line === \"number\" && typeof location.col === \"number\") {\n return `${file}:${location.line}:${location.col}`;\n }\n return file;\n}\n\nfunction formatDuplicateIdError(duplicates: Map<string, TemplateLocation[]>, root?: string): string {\n const lines = [\"[collie] Duplicate template ids detected:\"];\n const entries = Array.from(duplicates.entries()).sort((a, b) => a[0].localeCompare(b[0]));\n for (const [id, locations] of entries) {\n const formatted = locations.map((location) => formatLocation(location, root)).join(\", \");\n lines.push(`- ${id}: ${formatted}`);\n }\n return lines.join(\"\\n\");\n}\n\nfunction buildIgnoreGlobs(config?: ResolvedConfig): string[] {\n const ignore = new Set(DEFAULT_IGNORE_GLOBS);\n if (!config) {\n return Array.from(ignore);\n }\n\n const addRelativeDir = (dir?: string): void => {\n if (!dir) {\n return;\n }\n const absolute = path.isAbsolute(dir) ? dir : path.join(config.root, dir);\n const relative = normalizePath(path.relative(config.root, absolute));\n if (!relative || relative.startsWith(\"..\")) {\n return;\n }\n ignore.add(`${relative}/**`);\n };\n\n addRelativeDir(config.build?.outDir);\n addRelativeDir(config.cacheDir);\n addRelativeDir(config.publicDir);\n\n return Array.from(ignore);\n}\n\nexport default function colliePlugin(options: ColliePluginOptions = {}): Plugin {\n let resolvedRuntime: JsxRuntime = options.jsxRuntime ?? \"automatic\";\n let resolvedConfig: ResolvedConfig | undefined;\n let needsScan = true;\n const templatesById = new Map<string, TemplateRecord>();\n const templatesByEncodedId = new Map<string, TemplateRecord>();\n const fileToTemplateIds = new Map<string, Set<string>>();\n const templateIdToVirtualId = new Map<string, string>();\n\n const resetTemplates = (): void => {\n needsScan = true;\n templatesById.clear();\n templatesByEncodedId.clear();\n fileToTemplateIds.clear();\n templateIdToVirtualId.clear();\n };\n\n const trackTemplateRecord = (record: TemplateRecord): void => {\n templatesById.set(record.id, record);\n templatesByEncodedId.set(record.encodedId, record);\n templateIdToVirtualId.set(record.id, `${VIRTUAL_TEMPLATE_RESOLVED_PREFIX}${record.encodedId}`);\n const ids = fileToTemplateIds.get(record.filePath) ?? new Set<string>();\n ids.add(record.id);\n fileToTemplateIds.set(record.filePath, ids);\n };\n\n const removeFileTemplates = (filePath: string): Set<string> => {\n const ids = fileToTemplateIds.get(filePath) ?? new Set<string>();\n for (const id of ids) {\n const record = templatesById.get(id);\n if (record && record.filePath === filePath) {\n templatesById.delete(id);\n templatesByEncodedId.delete(record.encodedId);\n templateIdToVirtualId.delete(id);\n }\n }\n fileToTemplateIds.delete(filePath);\n return ids;\n };\n\n const collectModuleIds = (ids: Iterable<string>): Set<string> => {\n const moduleIds = new Set<string>();\n for (const id of ids) {\n const moduleId = templateIdToVirtualId.get(id);\n if (moduleId) {\n moduleIds.add(moduleId);\n }\n }\n return moduleIds;\n };\n\n const reportHmrError = (ctx: HmrContext, error: unknown): void => {\n const err = error instanceof Error ? error : new Error(String(error));\n ctx.server.config.logger.error(err.message);\n ctx.server.ws.send({\n type: \"error\",\n err: {\n message: err.message,\n stack: err.stack ?? \"\"\n }\n });\n };\n\n const ensureTemplates = async (watcher?: { addWatchFile: (id: string) => void }): Promise<void> => {\n if (!needsScan) {\n return;\n }\n\n if (!resolvedConfig) {\n throw new Error(\"[collie] Vite config was not resolved before scanning templates.\");\n }\n\n templatesById.clear();\n templatesByEncodedId.clear();\n fileToTemplateIds.clear();\n templateIdToVirtualId.clear();\n\n const root = resolvedConfig.root ?? process.cwd();\n const ignore = buildIgnoreGlobs(resolvedConfig);\n const filePaths = await fg(COLLIE_GLOB, {\n cwd: root,\n absolute: true,\n onlyFiles: true,\n ignore\n });\n\n const diagnostics: Diagnostic[] = [];\n const locationsById = new Map<string, TemplateLocation[]>();\n\n for (const filePath of filePaths) {\n if (watcher) {\n watcher.addWatchFile(filePath);\n }\n let source: string;\n try {\n source = await fs.readFile(filePath, \"utf-8\");\n } catch (error) {\n if ((error as NodeJS.ErrnoException)?.code === \"ENOENT\") {\n continue;\n }\n throw error;\n }\n const document = parseCollie(source, { filename: filePath });\n diagnostics.push(...document.diagnostics);\n\n for (const template of document.templates) {\n const location: TemplateLocation = {\n file: filePath,\n line: template.span?.start.line,\n col: template.span?.start.col\n };\n const encodedId = encodeTemplateId(template.id);\n const record: TemplateRecord = {\n id: template.id,\n encodedId,\n filePath,\n template,\n location\n };\n trackTemplateRecord(record);\n const locations = locationsById.get(template.id) ?? [];\n locations.push(location);\n locationsById.set(template.id, locations);\n }\n }\n\n const errors = diagnostics.filter((diag) => diag.severity === \"error\");\n if (errors.length) {\n const formatted = errors\n .map((diag) => {\n const fileForDiag = diag.filePath ?? diag.file ?? root;\n return formatDiagnostic(fileForDiag, diag, root);\n })\n .join(\"\\n\");\n throw new Error(`[collie]\\n${formatted}`);\n }\n\n const duplicates = new Map(\n Array.from(locationsById.entries()).filter(([, locations]) => locations.length > 1)\n );\n if (duplicates.size) {\n throw new Error(formatDuplicateIdError(duplicates, root));\n }\n\n needsScan = false;\n };\n\n const updateFileTemplates = async (ctx: HmrContext): Promise<ModuleNode[]> => {\n if (needsScan) {\n try {\n await ensureTemplates();\n } catch (error) {\n reportHmrError(ctx, error);\n return [];\n }\n }\n\n const filePath = ctx.file;\n const root = resolvedConfig?.root ?? process.cwd();\n const previousIds = fileToTemplateIds.get(filePath) ?? new Set<string>();\n const previousModuleIds = collectModuleIds(previousIds);\n\n let source: string | null = null;\n try {\n source = await fs.readFile(filePath, \"utf-8\");\n } catch (error) {\n if ((error as NodeJS.ErrnoException)?.code === \"ENOENT\") {\n removeFileTemplates(filePath);\n return invalidateModules(ctx, previousModuleIds);\n }\n reportHmrError(ctx, error);\n return [];\n }\n\n const document = parseCollie(source, { filename: filePath });\n const errors = document.diagnostics.filter((diag: Diagnostic) => diag.severity === \"error\");\n if (errors.length) {\n const formatted = errors.map((diag: Diagnostic) => formatDiagnostic(filePath, diag, root)).join(\"\\n\");\n reportHmrError(ctx, new Error(`[collie]\\n${formatted}`));\n return [];\n }\n\n const duplicates = new Map<string, TemplateLocation[]>();\n for (const template of document.templates) {\n const existing = templatesById.get(template.id);\n if (existing && existing.filePath !== filePath) {\n const locations = duplicates.get(template.id) ?? [existing.location];\n locations.push({\n file: filePath,\n line: template.span?.start.line,\n col: template.span?.start.col\n });\n duplicates.set(template.id, locations);\n }\n }\n if (duplicates.size) {\n reportHmrError(ctx, new Error(formatDuplicateIdError(duplicates, root)));\n return [];\n }\n\n removeFileTemplates(filePath);\n for (const template of document.templates) {\n const record: TemplateRecord = {\n id: template.id,\n encodedId: encodeTemplateId(template.id),\n filePath,\n template,\n location: {\n file: filePath,\n line: template.span?.start.line,\n col: template.span?.start.col\n }\n };\n trackTemplateRecord(record);\n }\n\n const nextIds = fileToTemplateIds.get(filePath) ?? new Set<string>();\n const nextModuleIds = collectModuleIds(nextIds);\n const moduleIds = new Set<string>([...previousModuleIds, ...nextModuleIds]);\n return invalidateModules(ctx, moduleIds);\n };\n\n const invalidateModules = (ctx: HmrContext, moduleIds: Iterable<string>): ModuleNode[] => {\n const modules: ModuleNode[] = [];\n const registryModule = ctx.server.moduleGraph.getModuleById(VIRTUAL_REGISTRY_RESOLVED);\n if (registryModule) {\n ctx.server.moduleGraph.invalidateModule(registryModule);\n modules.push(registryModule);\n }\n for (const moduleId of moduleIds) {\n const mod = ctx.server.moduleGraph.getModuleById(moduleId);\n if (mod) {\n ctx.server.moduleGraph.invalidateModule(mod);\n modules.push(mod);\n }\n }\n return modules;\n };\n\n return {\n name: \"collie\",\n enforce: \"pre\",\n\n config(userConfig) {\n const prevExclude = userConfig.optimizeDeps?.exclude ?? [];\n const exclude = Array.from(new Set([...prevExclude, \"@collie-lang/react\"]));\n\n const prevNoExternal = userConfig.ssr?.noExternal;\n\n let nextNoExternal: any;\n if (prevNoExternal === true) {\n // User already wants everything bundled for SSR; nothing to do.\n nextNoExternal = true;\n } else if (Array.isArray(prevNoExternal)) {\n nextNoExternal = Array.from(new Set([...prevNoExternal, \"@collie-lang/react\"]));\n } else if (prevNoExternal == null) {\n nextNoExternal = [\"@collie-lang/react\"];\n } else {\n // Vite allows string/RegExp/etc. Coerce to array and add ours.\n nextNoExternal = Array.from(new Set([prevNoExternal, \"@collie-lang/react\"]));\n }\n\n return {\n optimizeDeps: {\n exclude\n },\n ...(nextNoExternal\n ? {\n ssr: {\n noExternal: nextNoExternal\n }\n }\n : {})\n };\n },\n\n configResolved(config) {\n resolvedRuntime = options.jsxRuntime ?? \"automatic\";\n resolvedConfig = config;\n resetTemplates();\n },\n\n resolveId(id, importer) {\n const cleanId = stripQuery(id);\n\n if (cleanId === VIRTUAL_REGISTRY_ID) {\n return VIRTUAL_REGISTRY_RESOLVED;\n }\n\n if (cleanId === VIRTUAL_IDS_ID) {\n return VIRTUAL_IDS_RESOLVED;\n }\n\n if (cleanId === VIRTUAL_REGISTRY_RESOLVED) {\n return cleanId;\n }\n\n if (cleanId === VIRTUAL_IDS_RESOLVED) {\n return cleanId;\n }\n\n if (cleanId.startsWith(VIRTUAL_TEMPLATE_PREFIX)) {\n return VIRTUAL_TEMPLATE_RESOLVED_PREFIX + cleanId.slice(VIRTUAL_TEMPLATE_PREFIX.length);\n }\n\n if (cleanId.startsWith(VIRTUAL_TEMPLATE_RESOLVED_PREFIX)) {\n return cleanId;\n }\n\n const isInternalImporter =\n typeof importer === \"string\" &&\n (importer.startsWith(\"\\0collie:\") || importer.startsWith(\"collie:\"));\n\n if (!isVirtualCollieId(cleanId) && cleanId.endsWith(\".collie\") && !isInternalImporter) {\n this.error(buildDirectImportError(cleanId, importer, resolvedConfig?.root));\n }\n return null;\n },\n\n async load(id) {\n const cleanId = stripQuery(id);\n\n if (cleanId === VIRTUAL_REGISTRY_RESOLVED) {\n try {\n await ensureTemplates(this);\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error));\n this.error(err);\n }\n\n const entries = Array.from(templatesById.values()).sort((a, b) =>\n a.id.localeCompare(b.id)\n );\n\n const lines = entries.map(\n (record) =>\n ` ${JSON.stringify(record.id)}: () => import(${JSON.stringify(\n `${VIRTUAL_TEMPLATE_PREFIX}${record.encodedId}`\n )}),`\n );\n\n return {\n code: [\n \"/** @type {Record<string, () => Promise<{ render: (props: any) => any }>>} */\",\n `export const registry = {\\n${lines.join(\"\\n\")}\\n};`\n ].join(\"\\n\"),\n map: null\n };\n }\n\n if (cleanId === VIRTUAL_IDS_RESOLVED) {\n try {\n await ensureTemplates(this);\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error));\n this.error(err);\n }\n\n const ids = Array.from(templatesById.keys()).sort((a, b) => a.localeCompare(b));\n return {\n code: [\n \"/** @type {readonly string[]} */\",\n `export const ids = ${JSON.stringify(ids)};`\n ].join(\"\\n\"),\n map: null\n };\n }\n\n if (cleanId.startsWith(VIRTUAL_TEMPLATE_RESOLVED_PREFIX)) {\n const encoded = cleanId.slice(VIRTUAL_TEMPLATE_RESOLVED_PREFIX.length);\n\n try {\n await ensureTemplates(this);\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error));\n this.error(err);\n return null; // <-- TS: stop control-flow here\n }\n\n const record = templatesByEncodedId.get(encoded);\n\n if (!record) {\n let decoded = encoded;\n try {\n decoded = decodeTemplateId(encoded);\n } catch {\n // Keep encoded value for the error message.\n }\n this.error(new Error(`[collie] Unknown template id \"${decoded}\".`));\n return null; // <-- ✅ THIS is what fixes \"'record' is possibly 'undefined'\"\n }\n\n const result = compileTemplate(record.template, {\n filename: record.filePath,\n jsxRuntime: resolvedRuntime,\n flavor: \"tsx\"\n });\n\n const errors = result.diagnostics.filter((diag) => diag.severity === \"error\");\n if (errors.length) {\n const formatted = errors\n .map((diag) => formatDiagnostic(record.filePath, diag, resolvedConfig?.root))\n .join(\"\\n\");\n this.error(new Error(`[collie]\\n${formatted}`));\n return null; // <-- TS: stop control-flow here\n }\n\n const transformed = await transformWithEsbuild(result.code, record.filePath, {\n loader: \"tsx\",\n jsx: resolvedRuntime === \"classic\" ? \"transform\" : \"automatic\",\n jsxImportSource: \"react\"\n });\n\n return {\n code: transformed.code,\n map: transformed.map ?? null\n };\n }\n\n if (isCollieFile(cleanId)) {\n const info = this.getModuleInfo(cleanId);\n const importer = info?.importers?.[0];\n\n const isInternalImporter =\n typeof importer === \"string\" &&\n (importer.startsWith(\"\\0collie:\") || importer.startsWith(\"collie:\"));\n\n if (!isInternalImporter) {\n this.error(buildDirectImportError(cleanId, importer, resolvedConfig?.root));\n }\n\n return null;\n }\n\n return null;\n },\n\n handleHotUpdate(ctx: HmrContext) {\n if (!isCollieFile(ctx.file)) {\n return;\n }\n\n return updateFileTemplates(ctx);\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AACjB,sBAAe;AACf,uBAAe;AAEf,kBAAoD;AAEpD,sBAA6C;AAsB7C,IAAM,sBAAsB;AAC5B,IAAM,4BAA4B;AAClC,IAAM,iBAAiB;AACvB,IAAM,uBAAuB;AAC7B,IAAM,0BAA0B;AAChC,IAAM,mCAAmC;AACzC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AC5E,YAAI,OAAO,QAAQ;AACjB,gBAAM,YAAY,OACf,IAAI,CAAC,SAAS,iBAAiB,OAAO,UAAU,MAAM,gBAAgB,IAAI,CAAC,EAC3E,KAAK,IAAI;AACZ,eAAK,MAAM,IAAI,MAAM;AAAA,EAAa,SAAS,EAAE,CAAC;AAC9C,iBAAO;AAAA,QACT;AAEA,cAAM,cAAc,UAAM,kCAAqB,OAAO,MAAM,OAAO,UAAU;AAAA,UAC3E,QAAQ;AAAA,UACR,KAAK,oBAAoB,YAAY,cAAc;AAAA,UACnD,iBAAiB;AAAA,QACnB,CAAC;AAED,eAAO;AAAA,UACL,MAAM,YAAY;AAAA,UAClB,KAAK,YAAY,OAAO;AAAA,QAC1B;AAAA,MACF;AAEA,UAAI,aAAa,OAAO,GAAG;AACzB,cAAM,OAAO,KAAK,cAAc,OAAO;AACvC,cAAM,WAAW,MAAM,YAAY,CAAC;AAEpC,cAAM,qBACJ,OAAO,aAAa,aACnB,SAAS,WAAW,WAAW,KAAK,SAAS,WAAW,SAAS;AAEpE,YAAI,CAAC,oBAAoB;AACvB,eAAK,MAAM,uBAAuB,SAAS,UAAU,gBAAgB,IAAI,CAAC;AAAA,QAC5E;AAEA,eAAO;AAAA,MACT;AAEA,aAAO;AAAA,IACT;AAAA,IAEA,gBAAgB,KAAiB;AAC/B,UAAI,CAAC,aAAa,IAAI,IAAI,GAAG;AAC3B;AAAA,MACF;AAEA,aAAO,oBAAoB,GAAG;AAAA,IAChC;AAAA,EACF;AACF;","names":["path","fg","fs"]}
package/dist/index.js CHANGED
@@ -184,7 +184,15 @@ function colliePlugin(options = {}) {
184
184
  if (watcher) {
185
185
  watcher.addWatchFile(filePath);
186
186
  }
187
- const source = await fs.readFile(filePath, "utf-8");
187
+ let source;
188
+ try {
189
+ source = await fs.readFile(filePath, "utf-8");
190
+ } catch (error) {
191
+ if (error?.code === "ENOENT") {
192
+ continue;
193
+ }
194
+ throw error;
195
+ }
188
196
  const document = parseCollie(source, { filename: filePath });
189
197
  diagnostics.push(...document.diagnostics);
190
198
  for (const template of document.templates) {
@@ -209,7 +217,10 @@ function colliePlugin(options = {}) {
209
217
  }
210
218
  const errors = diagnostics.filter((diag) => diag.severity === "error");
211
219
  if (errors.length) {
212
- const formatted = errors.map((diag) => formatDiagnostic(root, diag, root)).join("\n");
220
+ const formatted = errors.map((diag) => {
221
+ const fileForDiag = diag.filePath ?? diag.file ?? root;
222
+ return formatDiagnostic(fileForDiag, diag, root);
223
+ }).join("\n");
213
224
  throw new Error(`[collie]
214
225
  ${formatted}`);
215
226
  }
@@ -309,6 +320,31 @@ ${formatted}`));
309
320
  return {
310
321
  name: "collie",
311
322
  enforce: "pre",
323
+ config(userConfig) {
324
+ const prevExclude = userConfig.optimizeDeps?.exclude ?? [];
325
+ const exclude = Array.from(/* @__PURE__ */ new Set([...prevExclude, "@collie-lang/react"]));
326
+ const prevNoExternal = userConfig.ssr?.noExternal;
327
+ let nextNoExternal;
328
+ if (prevNoExternal === true) {
329
+ nextNoExternal = true;
330
+ } else if (Array.isArray(prevNoExternal)) {
331
+ nextNoExternal = Array.from(/* @__PURE__ */ new Set([...prevNoExternal, "@collie-lang/react"]));
332
+ } else if (prevNoExternal == null) {
333
+ nextNoExternal = ["@collie-lang/react"];
334
+ } else {
335
+ nextNoExternal = Array.from(/* @__PURE__ */ new Set([prevNoExternal, "@collie-lang/react"]));
336
+ }
337
+ return {
338
+ optimizeDeps: {
339
+ exclude
340
+ },
341
+ ...nextNoExternal ? {
342
+ ssr: {
343
+ noExternal: nextNoExternal
344
+ }
345
+ } : {}
346
+ };
347
+ },
312
348
  configResolved(config) {
313
349
  resolvedRuntime = options.jsxRuntime ?? "automatic";
314
350
  resolvedConfig = config;
@@ -334,7 +370,8 @@ ${formatted}`));
334
370
  if (cleanId.startsWith(VIRTUAL_TEMPLATE_RESOLVED_PREFIX)) {
335
371
  return cleanId;
336
372
  }
337
- if (!isVirtualCollieId(cleanId) && cleanId.endsWith(".collie")) {
373
+ const isInternalImporter = typeof importer === "string" && (importer.startsWith("\0collie:") || importer.startsWith("collie:"));
374
+ if (!isVirtualCollieId(cleanId) && cleanId.endsWith(".collie") && !isInternalImporter) {
338
375
  this.error(buildDirectImportError(cleanId, importer, resolvedConfig?.root));
339
376
  }
340
377
  return null;
@@ -389,6 +426,7 @@ ${lines.join("\n")}
389
426
  } catch (error) {
390
427
  const err = error instanceof Error ? error : new Error(String(error));
391
428
  this.error(err);
429
+ return null;
392
430
  }
393
431
  const record = templatesByEncodedId.get(encoded);
394
432
  if (!record) {
@@ -398,6 +436,7 @@ ${lines.join("\n")}
398
436
  } catch {
399
437
  }
400
438
  this.error(new Error(`[collie] Unknown template id "${decoded}".`));
439
+ return null;
401
440
  }
402
441
  const result = compileTemplate(record.template, {
403
442
  filename: record.filePath,
@@ -409,6 +448,7 @@ ${lines.join("\n")}
409
448
  const formatted = errors.map((diag) => formatDiagnostic(record.filePath, diag, resolvedConfig?.root)).join("\n");
410
449
  this.error(new Error(`[collie]
411
450
  ${formatted}`));
451
+ return null;
412
452
  }
413
453
  const transformed = await transformWithEsbuild(result.code, record.filePath, {
414
454
  loader: "tsx",
@@ -423,7 +463,11 @@ ${formatted}`));
423
463
  if (isCollieFile(cleanId)) {
424
464
  const info = this.getModuleInfo(cleanId);
425
465
  const importer = info?.importers?.[0];
426
- this.error(buildDirectImportError(cleanId, importer, resolvedConfig?.root));
466
+ const isInternalImporter = typeof importer === "string" && (importer.startsWith("\0collie:") || importer.startsWith("collie:"));
467
+ if (!isInternalImporter) {
468
+ this.error(buildDirectImportError(cleanId, importer, resolvedConfig?.root));
469
+ }
470
+ return null;
427
471
  }
428
472
  return null;
429
473
  },
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import path from \"node:path\";\nimport fs from \"node:fs/promises\";\nimport fg from \"fast-glob\";\nimport type { HmrContext, ModuleNode, Plugin, ResolvedConfig } from \"vite\";\nimport { normalizePath, transformWithEsbuild } from \"vite\";\nimport type { Diagnostic, TemplateUnit } from \"@collie-lang/compiler\";\nimport { compileTemplate, parseCollie } from \"@collie-lang/compiler\";\n\ntype JsxRuntime = \"automatic\" | \"classic\";\n\nexport interface ColliePluginOptions {\n jsxRuntime?: JsxRuntime;\n}\n\ninterface TemplateLocation {\n file: string;\n line?: number;\n col?: number;\n}\n\ninterface TemplateRecord {\n id: string;\n encodedId: string;\n filePath: string;\n template: TemplateUnit;\n location: TemplateLocation;\n}\n\nconst VIRTUAL_REGISTRY_ID = \"virtual:collie/registry\";\nconst VIRTUAL_REGISTRY_RESOLVED = \"\\0collie:registry\";\nconst VIRTUAL_IDS_ID = \"virtual:collie/ids\";\nconst VIRTUAL_IDS_RESOLVED = \"\\0collie:ids\";\nconst VIRTUAL_TEMPLATE_PREFIX = \"virtual:collie/template/\";\nconst VIRTUAL_TEMPLATE_RESOLVED_PREFIX = \"\\0collie:template:\";\nconst COLLIE_GLOB = \"**/*.collie\";\nconst DEFAULT_IGNORE_GLOBS = [\"**/node_modules/**\", \"**/.git/**\", \"**/dist/**\", \"**/build/**\", \"**/.vite/**\"];\n\nfunction stripQuery(id: string): string {\n const q = id.indexOf(\"?\");\n return q === -1 ? id : id.slice(0, q);\n}\n\nfunction isCollieFile(id: string): boolean {\n return stripQuery(id).endsWith(\".collie\");\n}\n\nfunction toDisplayPath(filePath: string, root?: string): string {\n const normalized = normalizePath(filePath);\n if (!root || !path.isAbsolute(filePath)) {\n return normalized;\n }\n const relative = path.relative(root, filePath);\n if (!relative || relative.startsWith(\"..\")) {\n return normalized;\n }\n return normalizePath(relative);\n}\n\nfunction formatDiagnostic(id: string, diagnostic: Diagnostic, root?: string): string {\n const file = diagnostic.filePath ?? diagnostic.file ?? stripQuery(id);\n const displayFile = toDisplayPath(file, root);\n const range = diagnostic.range ?? diagnostic.span;\n const where = range ? `${range.start.line}:${range.start.col}` : \"\";\n const location = where ? `${displayFile}:${where}` : displayFile;\n const code = diagnostic.code ? diagnostic.code : \"COLLIE\";\n return `${location} [${code}] ${diagnostic.message}`;\n}\n\nfunction isVirtualCollieId(id: string): boolean {\n return (\n id === VIRTUAL_REGISTRY_ID ||\n id === VIRTUAL_REGISTRY_RESOLVED ||\n id === VIRTUAL_IDS_ID ||\n id === VIRTUAL_IDS_RESOLVED ||\n id.startsWith(VIRTUAL_TEMPLATE_PREFIX) ||\n id.startsWith(VIRTUAL_TEMPLATE_RESOLVED_PREFIX)\n );\n}\n\nfunction buildDirectImportError(importedId: string, importer?: string, root?: string): Error {\n const importLine = stripQuery(importedId);\n const importerLabel = importer ? toDisplayPath(importer, root) : \"<unknown>\";\n const lines = [\n \"Direct .collie imports are not supported.\",\n `Importer: ${importerLabel}`,\n `Import: ${importLine}`,\n \"Use the registry runtime instead:\",\n \"import { Collie } from '@collie-lang/react'\",\n '<Collie id=\"Your.TemplateId\" />',\n \"Templates are discovered automatically by @collie-lang/vite.\"\n ];\n return new Error(lines.join(\"\\n\"));\n}\n\nfunction encodeTemplateId(id: string): string {\n return Buffer.from(id, \"utf8\")\n .toString(\"base64\")\n .replace(/\\+/g, \"-\")\n .replace(/\\//g, \"_\")\n .replace(/=+$/g, \"\");\n}\n\nfunction decodeTemplateId(encoded: string): string {\n const normalized = encoded.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const padLength = normalized.length % 4;\n const padded = padLength === 0 ? normalized : normalized + \"=\".repeat(4 - padLength);\n return Buffer.from(padded, \"base64\").toString(\"utf8\");\n}\n\nfunction formatLocation(location: TemplateLocation, root?: string): string {\n const file = toDisplayPath(location.file, root);\n if (typeof location.line === \"number\" && typeof location.col === \"number\") {\n return `${file}:${location.line}:${location.col}`;\n }\n return file;\n}\n\nfunction formatDuplicateIdError(duplicates: Map<string, TemplateLocation[]>, root?: string): string {\n const lines = [\"[collie] Duplicate template ids detected:\"];\n const entries = Array.from(duplicates.entries()).sort((a, b) => a[0].localeCompare(b[0]));\n for (const [id, locations] of entries) {\n const formatted = locations.map((location) => formatLocation(location, root)).join(\", \");\n lines.push(`- ${id}: ${formatted}`);\n }\n return lines.join(\"\\n\");\n}\n\nfunction buildIgnoreGlobs(config?: ResolvedConfig): string[] {\n const ignore = new Set(DEFAULT_IGNORE_GLOBS);\n if (!config) {\n return Array.from(ignore);\n }\n\n const addRelativeDir = (dir?: string): void => {\n if (!dir) {\n return;\n }\n const absolute = path.isAbsolute(dir) ? dir : path.join(config.root, dir);\n const relative = normalizePath(path.relative(config.root, absolute));\n if (!relative || relative.startsWith(\"..\")) {\n return;\n }\n ignore.add(`${relative}/**`);\n };\n\n addRelativeDir(config.build?.outDir);\n addRelativeDir(config.cacheDir);\n addRelativeDir(config.publicDir);\n\n return Array.from(ignore);\n}\n\nexport default function colliePlugin(options: ColliePluginOptions = {}): Plugin {\n let resolvedRuntime: JsxRuntime = options.jsxRuntime ?? \"automatic\";\n let resolvedConfig: ResolvedConfig | undefined;\n let needsScan = true;\n const templatesById = new Map<string, TemplateRecord>();\n const templatesByEncodedId = new Map<string, TemplateRecord>();\n const fileToTemplateIds = new Map<string, Set<string>>();\n const templateIdToVirtualId = new Map<string, string>();\n\n const resetTemplates = (): void => {\n needsScan = true;\n templatesById.clear();\n templatesByEncodedId.clear();\n fileToTemplateIds.clear();\n templateIdToVirtualId.clear();\n };\n\n const trackTemplateRecord = (record: TemplateRecord): void => {\n templatesById.set(record.id, record);\n templatesByEncodedId.set(record.encodedId, record);\n templateIdToVirtualId.set(record.id, `${VIRTUAL_TEMPLATE_RESOLVED_PREFIX}${record.encodedId}`);\n const ids = fileToTemplateIds.get(record.filePath) ?? new Set<string>();\n ids.add(record.id);\n fileToTemplateIds.set(record.filePath, ids);\n };\n\n const removeFileTemplates = (filePath: string): Set<string> => {\n const ids = fileToTemplateIds.get(filePath) ?? new Set<string>();\n for (const id of ids) {\n const record = templatesById.get(id);\n if (record && record.filePath === filePath) {\n templatesById.delete(id);\n templatesByEncodedId.delete(record.encodedId);\n templateIdToVirtualId.delete(id);\n }\n }\n fileToTemplateIds.delete(filePath);\n return ids;\n };\n\n const collectModuleIds = (ids: Iterable<string>): Set<string> => {\n const moduleIds = new Set<string>();\n for (const id of ids) {\n const moduleId = templateIdToVirtualId.get(id);\n if (moduleId) {\n moduleIds.add(moduleId);\n }\n }\n return moduleIds;\n };\n\n const reportHmrError = (ctx: HmrContext, error: unknown): void => {\n const err = error instanceof Error ? error : new Error(String(error));\n ctx.server.config.logger.error(err.message);\n ctx.server.ws.send({\n type: \"error\",\n err: {\n message: err.message,\n stack: err.stack ?? \"\"\n }\n });\n };\n\n const ensureTemplates = async (watcher?: { addWatchFile: (id: string) => void }): Promise<void> => {\n if (!needsScan) {\n return;\n }\n\n if (!resolvedConfig) {\n throw new Error(\"[collie] Vite config was not resolved before scanning templates.\");\n }\n\n templatesById.clear();\n templatesByEncodedId.clear();\n fileToTemplateIds.clear();\n templateIdToVirtualId.clear();\n\n const root = resolvedConfig.root ?? process.cwd();\n const ignore = buildIgnoreGlobs(resolvedConfig);\n const filePaths = await fg(COLLIE_GLOB, {\n cwd: root,\n absolute: true,\n onlyFiles: true,\n ignore\n });\n\n const diagnostics: Diagnostic[] = [];\n const locationsById = new Map<string, TemplateLocation[]>();\n\n for (const filePath of filePaths) {\n if (watcher) {\n watcher.addWatchFile(filePath);\n }\n const source = await fs.readFile(filePath, \"utf-8\");\n const document = parseCollie(source, { filename: filePath });\n diagnostics.push(...document.diagnostics);\n\n for (const template of document.templates) {\n const location: TemplateLocation = {\n file: filePath,\n line: template.span?.start.line,\n col: template.span?.start.col\n };\n const encodedId = encodeTemplateId(template.id);\n const record: TemplateRecord = {\n id: template.id,\n encodedId,\n filePath,\n template,\n location\n };\n trackTemplateRecord(record);\n const locations = locationsById.get(template.id) ?? [];\n locations.push(location);\n locationsById.set(template.id, locations);\n }\n }\n\n const errors = diagnostics.filter((diag) => diag.severity === \"error\");\n if (errors.length) {\n const formatted = errors\n .map((diag) => formatDiagnostic(root, diag, root))\n .join(\"\\n\");\n throw new Error(`[collie]\\n${formatted}`);\n }\n\n const duplicates = new Map(\n Array.from(locationsById.entries()).filter(([, locations]) => locations.length > 1)\n );\n if (duplicates.size) {\n throw new Error(formatDuplicateIdError(duplicates, root));\n }\n\n needsScan = false;\n };\n\n const updateFileTemplates = async (ctx: HmrContext): Promise<ModuleNode[]> => {\n if (needsScan) {\n try {\n await ensureTemplates();\n } catch (error) {\n reportHmrError(ctx, error);\n return [];\n }\n }\n\n const filePath = ctx.file;\n const root = resolvedConfig?.root ?? process.cwd();\n const previousIds = fileToTemplateIds.get(filePath) ?? new Set<string>();\n const previousModuleIds = collectModuleIds(previousIds);\n\n let source: string | null = null;\n try {\n source = await fs.readFile(filePath, \"utf-8\");\n } catch (error) {\n if ((error as NodeJS.ErrnoException)?.code === \"ENOENT\") {\n removeFileTemplates(filePath);\n return invalidateModules(ctx, previousModuleIds);\n }\n reportHmrError(ctx, error);\n return [];\n }\n\n const document = parseCollie(source, { filename: filePath });\n const errors = document.diagnostics.filter((diag: Diagnostic) => diag.severity === \"error\");\n if (errors.length) {\n const formatted = errors.map((diag: Diagnostic) => formatDiagnostic(filePath, diag, root)).join(\"\\n\");\n reportHmrError(ctx, new Error(`[collie]\\n${formatted}`));\n return [];\n }\n\n const duplicates = new Map<string, TemplateLocation[]>();\n for (const template of document.templates) {\n const existing = templatesById.get(template.id);\n if (existing && existing.filePath !== filePath) {\n const locations = duplicates.get(template.id) ?? [existing.location];\n locations.push({\n file: filePath,\n line: template.span?.start.line,\n col: template.span?.start.col\n });\n duplicates.set(template.id, locations);\n }\n }\n if (duplicates.size) {\n reportHmrError(ctx, new Error(formatDuplicateIdError(duplicates, root)));\n return [];\n }\n\n removeFileTemplates(filePath);\n for (const template of document.templates) {\n const record: TemplateRecord = {\n id: template.id,\n encodedId: encodeTemplateId(template.id),\n filePath,\n template,\n location: {\n file: filePath,\n line: template.span?.start.line,\n col: template.span?.start.col\n }\n };\n trackTemplateRecord(record);\n }\n\n const nextIds = fileToTemplateIds.get(filePath) ?? new Set<string>();\n const nextModuleIds = collectModuleIds(nextIds);\n const moduleIds = new Set<string>([...previousModuleIds, ...nextModuleIds]);\n return invalidateModules(ctx, moduleIds);\n };\n\n const invalidateModules = (ctx: HmrContext, moduleIds: Iterable<string>): ModuleNode[] => {\n const modules: ModuleNode[] = [];\n const registryModule = ctx.server.moduleGraph.getModuleById(VIRTUAL_REGISTRY_RESOLVED);\n if (registryModule) {\n ctx.server.moduleGraph.invalidateModule(registryModule);\n modules.push(registryModule);\n }\n for (const moduleId of moduleIds) {\n const mod = ctx.server.moduleGraph.getModuleById(moduleId);\n if (mod) {\n ctx.server.moduleGraph.invalidateModule(mod);\n modules.push(mod);\n }\n }\n return modules;\n };\n\n return {\n name: \"collie\",\n enforce: \"pre\",\n\n configResolved(config) {\n resolvedRuntime = options.jsxRuntime ?? \"automatic\";\n resolvedConfig = config;\n resetTemplates();\n },\n\n resolveId(id, importer) {\n const cleanId = stripQuery(id);\n if (cleanId === VIRTUAL_REGISTRY_ID) {\n return VIRTUAL_REGISTRY_RESOLVED;\n }\n if (cleanId === VIRTUAL_IDS_ID) {\n return VIRTUAL_IDS_RESOLVED;\n }\n if (cleanId === VIRTUAL_REGISTRY_RESOLVED) {\n return cleanId;\n }\n if (cleanId === VIRTUAL_IDS_RESOLVED) {\n return cleanId;\n }\n if (cleanId.startsWith(VIRTUAL_TEMPLATE_PREFIX)) {\n return VIRTUAL_TEMPLATE_RESOLVED_PREFIX + cleanId.slice(VIRTUAL_TEMPLATE_PREFIX.length);\n }\n if (cleanId.startsWith(VIRTUAL_TEMPLATE_RESOLVED_PREFIX)) {\n return cleanId;\n }\n if (!isVirtualCollieId(cleanId) && cleanId.endsWith(\".collie\")) {\n this.error(buildDirectImportError(cleanId, importer, resolvedConfig?.root));\n }\n return null;\n },\n\n async load(id) {\n const cleanId = stripQuery(id);\n if (cleanId === VIRTUAL_REGISTRY_RESOLVED) {\n try {\n await ensureTemplates(this);\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error));\n this.error(err);\n }\n\n const entries = Array.from(templatesById.values()).sort((a, b) =>\n a.id.localeCompare(b.id)\n );\n const lines = entries.map(\n (record) =>\n ` ${JSON.stringify(record.id)}: () => import(${JSON.stringify(\n `${VIRTUAL_TEMPLATE_PREFIX}${record.encodedId}`\n )}),`\n );\n return {\n code: [\n \"/** @type {Record<string, () => Promise<{ render: (props: any) => any }>>} */\",\n `export const registry = {\\n${lines.join(\"\\n\")}\\n};`\n ].join(\"\\n\"),\n map: null\n };\n }\n\n if (cleanId === VIRTUAL_IDS_RESOLVED) {\n try {\n await ensureTemplates(this);\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error));\n this.error(err);\n }\n\n const ids = Array.from(templatesById.keys()).sort((a, b) => a.localeCompare(b));\n return {\n code: [\n \"/** @type {readonly string[]} */\",\n `export const ids = ${JSON.stringify(ids)};`\n ].join(\"\\n\"),\n map: null\n };\n }\n\n if (cleanId.startsWith(VIRTUAL_TEMPLATE_RESOLVED_PREFIX)) {\n const encoded = cleanId.slice(VIRTUAL_TEMPLATE_RESOLVED_PREFIX.length);\n try {\n await ensureTemplates(this);\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error));\n this.error(err);\n }\n\n const record = templatesByEncodedId.get(encoded);\n if (!record) {\n let decoded = encoded;\n try {\n decoded = decodeTemplateId(encoded);\n } catch {\n // Keep encoded value for the error message.\n }\n this.error(new Error(`[collie] Unknown template id \"${decoded}\".`));\n }\n\n const result = compileTemplate(record.template, {\n filename: record.filePath,\n jsxRuntime: resolvedRuntime,\n flavor: \"tsx\"\n });\n\n const errors = result.diagnostics.filter((diag) => diag.severity === \"error\");\n if (errors.length) {\n const formatted = errors\n .map((diag) => formatDiagnostic(record.filePath, diag, resolvedConfig?.root))\n .join(\"\\n\");\n this.error(new Error(`[collie]\\n${formatted}`));\n }\n\n const transformed = await transformWithEsbuild(result.code, record.filePath, {\n loader: \"tsx\",\n jsx: resolvedRuntime === \"classic\" ? \"transform\" : \"automatic\",\n jsxImportSource: \"react\"\n });\n\n return {\n code: transformed.code,\n map: transformed.map ?? null\n };\n }\n if (isCollieFile(cleanId)) {\n const info = this.getModuleInfo(cleanId);\n const importer = info?.importers?.[0];\n this.error(buildDirectImportError(cleanId, importer, resolvedConfig?.root));\n }\n\n return null;\n },\n\n handleHotUpdate(ctx: HmrContext) {\n if (!isCollieFile(ctx.file)) {\n return;\n }\n\n return updateFileTemplates(ctx);\n }\n };\n}\n"],"mappings":";AAAA,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,OAAO,QAAQ;AAEf,SAAS,eAAe,4BAA4B;AAEpD,SAAS,iBAAiB,mBAAmB;AAsB7C,IAAM,sBAAsB;AAC5B,IAAM,4BAA4B;AAClC,IAAM,iBAAiB;AACvB,IAAM,uBAAuB;AAC7B,IAAM,0BAA0B;AAChC,IAAM,mCAAmC;AACzC,IAAM,cAAc;AACpB,IAAM,uBAAuB,CAAC,sBAAsB,cAAc,cAAc,eAAe,aAAa;AAE5G,SAAS,WAAW,IAAoB;AACtC,QAAM,IAAI,GAAG,QAAQ,GAAG;AACxB,SAAO,MAAM,KAAK,KAAK,GAAG,MAAM,GAAG,CAAC;AACtC;AAEA,SAAS,aAAa,IAAqB;AACzC,SAAO,WAAW,EAAE,EAAE,SAAS,SAAS;AAC1C;AAEA,SAAS,cAAc,UAAkB,MAAuB;AAC9D,QAAM,aAAa,cAAc,QAAQ;AACzC,MAAI,CAAC,QAAQ,CAAC,KAAK,WAAW,QAAQ,GAAG;AACvC,WAAO;AAAA,EACT;AACA,QAAM,WAAW,KAAK,SAAS,MAAM,QAAQ;AAC7C,MAAI,CAAC,YAAY,SAAS,WAAW,IAAI,GAAG;AAC1C,WAAO;AAAA,EACT;AACA,SAAO,cAAc,QAAQ;AAC/B;AAEA,SAAS,iBAAiB,IAAY,YAAwB,MAAuB;AACnF,QAAM,OAAO,WAAW,YAAY,WAAW,QAAQ,WAAW,EAAE;AACpE,QAAM,cAAc,cAAc,MAAM,IAAI;AAC5C,QAAM,QAAQ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AACpC,aAAK,MAAM,uBAAuB,SAAS,UAAU,gBAAgB,IAAI,CAAC;AAAA,MAC5E;AAEA,aAAO;AAAA,IACT;AAAA,IAEA,gBAAgB,KAAiB;AAC/B,UAAI,CAAC,aAAa,IAAI,IAAI,GAAG;AAC3B;AAAA,MACF;AAEA,aAAO,oBAAoB,GAAG;AAAA,IAChC;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import path from \"node:path\";\nimport fs from \"node:fs/promises\";\nimport fg from \"fast-glob\";\nimport type { HmrContext, ModuleNode, Plugin, ResolvedConfig } from \"vite\";\nimport { normalizePath, transformWithEsbuild } from \"vite\";\nimport type { Diagnostic, TemplateUnit } from \"@collie-lang/compiler\";\nimport { compileTemplate, parseCollie } from \"@collie-lang/compiler\";\n\ntype JsxRuntime = \"automatic\" | \"classic\";\n\nexport interface ColliePluginOptions {\n jsxRuntime?: JsxRuntime;\n}\n\ninterface TemplateLocation {\n file: string;\n line?: number;\n col?: number;\n}\n\ninterface TemplateRecord {\n id: string;\n encodedId: string;\n filePath: string;\n template: TemplateUnit;\n location: TemplateLocation;\n}\n\nconst VIRTUAL_REGISTRY_ID = \"virtual:collie/registry\";\nconst VIRTUAL_REGISTRY_RESOLVED = \"\\0collie:registry\";\nconst VIRTUAL_IDS_ID = \"virtual:collie/ids\";\nconst VIRTUAL_IDS_RESOLVED = \"\\0collie:ids\";\nconst VIRTUAL_TEMPLATE_PREFIX = \"virtual:collie/template/\";\nconst VIRTUAL_TEMPLATE_RESOLVED_PREFIX = \"\\0collie:template:\";\nconst COLLIE_GLOB = \"**/*.collie\";\nconst DEFAULT_IGNORE_GLOBS = [\"**/node_modules/**\", \"**/.git/**\", \"**/dist/**\", \"**/build/**\", \"**/.vite/**\"];\n\nfunction stripQuery(id: string): string {\n const q = id.indexOf(\"?\");\n return q === -1 ? id : id.slice(0, q);\n}\n\nfunction isCollieFile(id: string): boolean {\n return stripQuery(id).endsWith(\".collie\");\n}\n\nfunction toDisplayPath(filePath: string, root?: string): string {\n const normalized = normalizePath(filePath);\n if (!root || !path.isAbsolute(filePath)) {\n return normalized;\n }\n const relative = path.relative(root, filePath);\n if (!relative || relative.startsWith(\"..\")) {\n return normalized;\n }\n return normalizePath(relative);\n}\n\nfunction formatDiagnostic(id: string, diagnostic: Diagnostic, root?: string): string {\n const file = diagnostic.filePath ?? diagnostic.file ?? stripQuery(id);\n const displayFile = toDisplayPath(file, root);\n const range = diagnostic.range ?? diagnostic.span;\n const where = range ? `${range.start.line}:${range.start.col}` : \"\";\n const location = where ? `${displayFile}:${where}` : displayFile;\n const code = diagnostic.code ? diagnostic.code : \"COLLIE\";\n return `${location} [${code}] ${diagnostic.message}`;\n}\n\nfunction isVirtualCollieId(id: string): boolean {\n return (\n id === VIRTUAL_REGISTRY_ID ||\n id === VIRTUAL_REGISTRY_RESOLVED ||\n id === VIRTUAL_IDS_ID ||\n id === VIRTUAL_IDS_RESOLVED ||\n id.startsWith(VIRTUAL_TEMPLATE_PREFIX) ||\n id.startsWith(VIRTUAL_TEMPLATE_RESOLVED_PREFIX)\n );\n}\n\nfunction buildDirectImportError(importedId: string, importer?: string, root?: string): Error {\n const importLine = stripQuery(importedId);\n const importerLabel = importer ? toDisplayPath(importer, root) : \"<unknown>\";\n const lines = [\n \"Direct .collie imports are not supported.\",\n `Importer: ${importerLabel}`,\n `Import: ${importLine}`,\n \"Use the registry runtime instead:\",\n \"import { Collie } from '@collie-lang/react'\",\n '<Collie id=\"Your.TemplateId\" />',\n \"Templates are discovered automatically by @collie-lang/vite.\"\n ];\n return new Error(lines.join(\"\\n\"));\n}\n\nfunction encodeTemplateId(id: string): string {\n return Buffer.from(id, \"utf8\")\n .toString(\"base64\")\n .replace(/\\+/g, \"-\")\n .replace(/\\//g, \"_\")\n .replace(/=+$/g, \"\");\n}\n\nfunction decodeTemplateId(encoded: string): string {\n const normalized = encoded.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const padLength = normalized.length % 4;\n const padded = padLength === 0 ? normalized : normalized + \"=\".repeat(4 - padLength);\n return Buffer.from(padded, \"base64\").toString(\"utf8\");\n}\n\nfunction formatLocation(location: TemplateLocation, root?: string): string {\n const file = toDisplayPath(location.file, root);\n if (typeof location.line === \"number\" && typeof location.col === \"number\") {\n return `${file}:${location.line}:${location.col}`;\n }\n return file;\n}\n\nfunction formatDuplicateIdError(duplicates: Map<string, TemplateLocation[]>, root?: string): string {\n const lines = [\"[collie] Duplicate template ids detected:\"];\n const entries = Array.from(duplicates.entries()).sort((a, b) => a[0].localeCompare(b[0]));\n for (const [id, locations] of entries) {\n const formatted = locations.map((location) => formatLocation(location, root)).join(\", \");\n lines.push(`- ${id}: ${formatted}`);\n }\n return lines.join(\"\\n\");\n}\n\nfunction buildIgnoreGlobs(config?: ResolvedConfig): string[] {\n const ignore = new Set(DEFAULT_IGNORE_GLOBS);\n if (!config) {\n return Array.from(ignore);\n }\n\n const addRelativeDir = (dir?: string): void => {\n if (!dir) {\n return;\n }\n const absolute = path.isAbsolute(dir) ? dir : path.join(config.root, dir);\n const relative = normalizePath(path.relative(config.root, absolute));\n if (!relative || relative.startsWith(\"..\")) {\n return;\n }\n ignore.add(`${relative}/**`);\n };\n\n addRelativeDir(config.build?.outDir);\n addRelativeDir(config.cacheDir);\n addRelativeDir(config.publicDir);\n\n return Array.from(ignore);\n}\n\nexport default function colliePlugin(options: ColliePluginOptions = {}): Plugin {\n let resolvedRuntime: JsxRuntime = options.jsxRuntime ?? \"automatic\";\n let resolvedConfig: ResolvedConfig | undefined;\n let needsScan = true;\n const templatesById = new Map<string, TemplateRecord>();\n const templatesByEncodedId = new Map<string, TemplateRecord>();\n const fileToTemplateIds = new Map<string, Set<string>>();\n const templateIdToVirtualId = new Map<string, string>();\n\n const resetTemplates = (): void => {\n needsScan = true;\n templatesById.clear();\n templatesByEncodedId.clear();\n fileToTemplateIds.clear();\n templateIdToVirtualId.clear();\n };\n\n const trackTemplateRecord = (record: TemplateRecord): void => {\n templatesById.set(record.id, record);\n templatesByEncodedId.set(record.encodedId, record);\n templateIdToVirtualId.set(record.id, `${VIRTUAL_TEMPLATE_RESOLVED_PREFIX}${record.encodedId}`);\n const ids = fileToTemplateIds.get(record.filePath) ?? new Set<string>();\n ids.add(record.id);\n fileToTemplateIds.set(record.filePath, ids);\n };\n\n const removeFileTemplates = (filePath: string): Set<string> => {\n const ids = fileToTemplateIds.get(filePath) ?? new Set<string>();\n for (const id of ids) {\n const record = templatesById.get(id);\n if (record && record.filePath === filePath) {\n templatesById.delete(id);\n templatesByEncodedId.delete(record.encodedId);\n templateIdToVirtualId.delete(id);\n }\n }\n fileToTemplateIds.delete(filePath);\n return ids;\n };\n\n const collectModuleIds = (ids: Iterable<string>): Set<string> => {\n const moduleIds = new Set<string>();\n for (const id of ids) {\n const moduleId = templateIdToVirtualId.get(id);\n if (moduleId) {\n moduleIds.add(moduleId);\n }\n }\n return moduleIds;\n };\n\n const reportHmrError = (ctx: HmrContext, error: unknown): void => {\n const err = error instanceof Error ? error : new Error(String(error));\n ctx.server.config.logger.error(err.message);\n ctx.server.ws.send({\n type: \"error\",\n err: {\n message: err.message,\n stack: err.stack ?? \"\"\n }\n });\n };\n\n const ensureTemplates = async (watcher?: { addWatchFile: (id: string) => void }): Promise<void> => {\n if (!needsScan) {\n return;\n }\n\n if (!resolvedConfig) {\n throw new Error(\"[collie] Vite config was not resolved before scanning templates.\");\n }\n\n templatesById.clear();\n templatesByEncodedId.clear();\n fileToTemplateIds.clear();\n templateIdToVirtualId.clear();\n\n const root = resolvedConfig.root ?? process.cwd();\n const ignore = buildIgnoreGlobs(resolvedConfig);\n const filePaths = await fg(COLLIE_GLOB, {\n cwd: root,\n absolute: true,\n onlyFiles: true,\n ignore\n });\n\n const diagnostics: Diagnostic[] = [];\n const locationsById = new Map<string, TemplateLocation[]>();\n\n for (const filePath of filePaths) {\n if (watcher) {\n watcher.addWatchFile(filePath);\n }\n let source: string;\n try {\n source = await fs.readFile(filePath, \"utf-8\");\n } catch (error) {\n if ((error as NodeJS.ErrnoException)?.code === \"ENOENT\") {\n continue;\n }\n throw error;\n }\n const document = parseCollie(source, { filename: filePath });\n diagnostics.push(...document.diagnostics);\n\n for (const template of document.templates) {\n const location: TemplateLocation = {\n file: filePath,\n line: template.span?.start.line,\n col: template.span?.start.col\n };\n const encodedId = encodeTemplateId(template.id);\n const record: TemplateRecord = {\n id: template.id,\n encodedId,\n filePath,\n template,\n location\n };\n trackTemplateRecord(record);\n const locations = locationsById.get(template.id) ?? [];\n locations.push(location);\n locationsById.set(template.id, locations);\n }\n }\n\n const errors = diagnostics.filter((diag) => diag.severity === \"error\");\n if (errors.length) {\n const formatted = errors\n .map((diag) => {\n const fileForDiag = diag.filePath ?? diag.file ?? root;\n return formatDiagnostic(fileForDiag, diag, root);\n })\n .join(\"\\n\");\n throw new Error(`[collie]\\n${formatted}`);\n }\n\n const duplicates = new Map(\n Array.from(locationsById.entries()).filter(([, locations]) => locations.length > 1)\n );\n if (duplicates.size) {\n throw new Error(formatDuplicateIdError(duplicates, root));\n }\n\n needsScan = false;\n };\n\n const updateFileTemplates = async (ctx: HmrContext): Promise<ModuleNode[]> => {\n if (needsScan) {\n try {\n await ensureTemplates();\n } catch (error) {\n reportHmrError(ctx, error);\n return [];\n }\n }\n\n const filePath = ctx.file;\n const root = resolvedConfig?.root ?? process.cwd();\n const previousIds = fileToTemplateIds.get(filePath) ?? new Set<string>();\n const previousModuleIds = collectModuleIds(previousIds);\n\n let source: string | null = null;\n try {\n source = await fs.readFile(filePath, \"utf-8\");\n } catch (error) {\n if ((error as NodeJS.ErrnoException)?.code === \"ENOENT\") {\n removeFileTemplates(filePath);\n return invalidateModules(ctx, previousModuleIds);\n }\n reportHmrError(ctx, error);\n return [];\n }\n\n const document = parseCollie(source, { filename: filePath });\n const errors = document.diagnostics.filter((diag: Diagnostic) => diag.severity === \"error\");\n if (errors.length) {\n const formatted = errors.map((diag: Diagnostic) => formatDiagnostic(filePath, diag, root)).join(\"\\n\");\n reportHmrError(ctx, new Error(`[collie]\\n${formatted}`));\n return [];\n }\n\n const duplicates = new Map<string, TemplateLocation[]>();\n for (const template of document.templates) {\n const existing = templatesById.get(template.id);\n if (existing && existing.filePath !== filePath) {\n const locations = duplicates.get(template.id) ?? [existing.location];\n locations.push({\n file: filePath,\n line: template.span?.start.line,\n col: template.span?.start.col\n });\n duplicates.set(template.id, locations);\n }\n }\n if (duplicates.size) {\n reportHmrError(ctx, new Error(formatDuplicateIdError(duplicates, root)));\n return [];\n }\n\n removeFileTemplates(filePath);\n for (const template of document.templates) {\n const record: TemplateRecord = {\n id: template.id,\n encodedId: encodeTemplateId(template.id),\n filePath,\n template,\n location: {\n file: filePath,\n line: template.span?.start.line,\n col: template.span?.start.col\n }\n };\n trackTemplateRecord(record);\n }\n\n const nextIds = fileToTemplateIds.get(filePath) ?? new Set<string>();\n const nextModuleIds = collectModuleIds(nextIds);\n const moduleIds = new Set<string>([...previousModuleIds, ...nextModuleIds]);\n return invalidateModules(ctx, moduleIds);\n };\n\n const invalidateModules = (ctx: HmrContext, moduleIds: Iterable<string>): ModuleNode[] => {\n const modules: ModuleNode[] = [];\n const registryModule = ctx.server.moduleGraph.getModuleById(VIRTUAL_REGISTRY_RESOLVED);\n if (registryModule) {\n ctx.server.moduleGraph.invalidateModule(registryModule);\n modules.push(registryModule);\n }\n for (const moduleId of moduleIds) {\n const mod = ctx.server.moduleGraph.getModuleById(moduleId);\n if (mod) {\n ctx.server.moduleGraph.invalidateModule(mod);\n modules.push(mod);\n }\n }\n return modules;\n };\n\n return {\n name: \"collie\",\n enforce: \"pre\",\n\n config(userConfig) {\n const prevExclude = userConfig.optimizeDeps?.exclude ?? [];\n const exclude = Array.from(new Set([...prevExclude, \"@collie-lang/react\"]));\n\n const prevNoExternal = userConfig.ssr?.noExternal;\n\n let nextNoExternal: any;\n if (prevNoExternal === true) {\n // User already wants everything bundled for SSR; nothing to do.\n nextNoExternal = true;\n } else if (Array.isArray(prevNoExternal)) {\n nextNoExternal = Array.from(new Set([...prevNoExternal, \"@collie-lang/react\"]));\n } else if (prevNoExternal == null) {\n nextNoExternal = [\"@collie-lang/react\"];\n } else {\n // Vite allows string/RegExp/etc. Coerce to array and add ours.\n nextNoExternal = Array.from(new Set([prevNoExternal, \"@collie-lang/react\"]));\n }\n\n return {\n optimizeDeps: {\n exclude\n },\n ...(nextNoExternal\n ? {\n ssr: {\n noExternal: nextNoExternal\n }\n }\n : {})\n };\n },\n\n configResolved(config) {\n resolvedRuntime = options.jsxRuntime ?? \"automatic\";\n resolvedConfig = config;\n resetTemplates();\n },\n\n resolveId(id, importer) {\n const cleanId = stripQuery(id);\n\n if (cleanId === VIRTUAL_REGISTRY_ID) {\n return VIRTUAL_REGISTRY_RESOLVED;\n }\n\n if (cleanId === VIRTUAL_IDS_ID) {\n return VIRTUAL_IDS_RESOLVED;\n }\n\n if (cleanId === VIRTUAL_REGISTRY_RESOLVED) {\n return cleanId;\n }\n\n if (cleanId === VIRTUAL_IDS_RESOLVED) {\n return cleanId;\n }\n\n if (cleanId.startsWith(VIRTUAL_TEMPLATE_PREFIX)) {\n return VIRTUAL_TEMPLATE_RESOLVED_PREFIX + cleanId.slice(VIRTUAL_TEMPLATE_PREFIX.length);\n }\n\n if (cleanId.startsWith(VIRTUAL_TEMPLATE_RESOLVED_PREFIX)) {\n return cleanId;\n }\n\n const isInternalImporter =\n typeof importer === \"string\" &&\n (importer.startsWith(\"\\0collie:\") || importer.startsWith(\"collie:\"));\n\n if (!isVirtualCollieId(cleanId) && cleanId.endsWith(\".collie\") && !isInternalImporter) {\n this.error(buildDirectImportError(cleanId, importer, resolvedConfig?.root));\n }\n return null;\n },\n\n async load(id) {\n const cleanId = stripQuery(id);\n\n if (cleanId === VIRTUAL_REGISTRY_RESOLVED) {\n try {\n await ensureTemplates(this);\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error));\n this.error(err);\n }\n\n const entries = Array.from(templatesById.values()).sort((a, b) =>\n a.id.localeCompare(b.id)\n );\n\n const lines = entries.map(\n (record) =>\n ` ${JSON.stringify(record.id)}: () => import(${JSON.stringify(\n `${VIRTUAL_TEMPLATE_PREFIX}${record.encodedId}`\n )}),`\n );\n\n return {\n code: [\n \"/** @type {Record<string, () => Promise<{ render: (props: any) => any }>>} */\",\n `export const registry = {\\n${lines.join(\"\\n\")}\\n};`\n ].join(\"\\n\"),\n map: null\n };\n }\n\n if (cleanId === VIRTUAL_IDS_RESOLVED) {\n try {\n await ensureTemplates(this);\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error));\n this.error(err);\n }\n\n const ids = Array.from(templatesById.keys()).sort((a, b) => a.localeCompare(b));\n return {\n code: [\n \"/** @type {readonly string[]} */\",\n `export const ids = ${JSON.stringify(ids)};`\n ].join(\"\\n\"),\n map: null\n };\n }\n\n if (cleanId.startsWith(VIRTUAL_TEMPLATE_RESOLVED_PREFIX)) {\n const encoded = cleanId.slice(VIRTUAL_TEMPLATE_RESOLVED_PREFIX.length);\n\n try {\n await ensureTemplates(this);\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error));\n this.error(err);\n return null; // <-- TS: stop control-flow here\n }\n\n const record = templatesByEncodedId.get(encoded);\n\n if (!record) {\n let decoded = encoded;\n try {\n decoded = decodeTemplateId(encoded);\n } catch {\n // Keep encoded value for the error message.\n }\n this.error(new Error(`[collie] Unknown template id \"${decoded}\".`));\n return null; // <-- ✅ THIS is what fixes \"'record' is possibly 'undefined'\"\n }\n\n const result = compileTemplate(record.template, {\n filename: record.filePath,\n jsxRuntime: resolvedRuntime,\n flavor: \"tsx\"\n });\n\n const errors = result.diagnostics.filter((diag) => diag.severity === \"error\");\n if (errors.length) {\n const formatted = errors\n .map((diag) => formatDiagnostic(record.filePath, diag, resolvedConfig?.root))\n .join(\"\\n\");\n this.error(new Error(`[collie]\\n${formatted}`));\n return null; // <-- TS: stop control-flow here\n }\n\n const transformed = await transformWithEsbuild(result.code, record.filePath, {\n loader: \"tsx\",\n jsx: resolvedRuntime === \"classic\" ? \"transform\" : \"automatic\",\n jsxImportSource: \"react\"\n });\n\n return {\n code: transformed.code,\n map: transformed.map ?? null\n };\n }\n\n if (isCollieFile(cleanId)) {\n const info = this.getModuleInfo(cleanId);\n const importer = info?.importers?.[0];\n\n const isInternalImporter =\n typeof importer === \"string\" &&\n (importer.startsWith(\"\\0collie:\") || importer.startsWith(\"collie:\"));\n\n if (!isInternalImporter) {\n this.error(buildDirectImportError(cleanId, importer, resolvedConfig?.root));\n }\n\n return null;\n }\n\n return null;\n },\n\n handleHotUpdate(ctx: HmrContext) {\n if (!isCollieFile(ctx.file)) {\n return;\n }\n\n return updateFileTemplates(ctx);\n }\n };\n}\n"],"mappings":";AAAA,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,OAAO,QAAQ;AAEf,SAAS,eAAe,4BAA4B;AAEpD,SAAS,iBAAiB,mBAAmB;AAsB7C,IAAM,sBAAsB;AAC5B,IAAM,4BAA4B;AAClC,IAAM,iBAAiB;AACvB,IAAM,uBAAuB;AAC7B,IAAM,0BAA0B;AAChC,IAAM,mCAAmC;AACzC,IAAM,cAAc;AACpB,IAAM,uBAAuB,CAAC,sBAAsB,cAAc,cAAc,eAAe,aAAa;AAE5G,SAAS,WAAW,IAAoB;AACtC,QAAM,IAAI,GAAG,QAAQ,GAAG;AACxB,SAAO,MAAM,KAAK,KAAK,GAAG,MAAM,GAAG,CAAC;AACtC;AAEA,SAAS,aAAa,IAAqB;AACzC,SAAO,WAAW,EAAE,EAAE,SAAS,SAAS;AAC1C;AAEA,SAAS,cAAc,UAAkB,MAAuB;AAC9D,QAAM,aAAa,cAAc,QAAQ;AACzC,MAAI,CAAC,QAAQ,CAAC,KAAK,WAAW,QAAQ,GAAG;AACvC,WAAO;AAAA,EACT;AACA,QAAM,WAAW,KAAK,SAAS,MAAM,QAAQ;AAC7C,MAAI,CAAC,YAAY,SAAS,WAAW,IAAI,GAAG;AAC1C,WAAO;AAAA,EACT;AACA,SAAO,cAAc,QAAQ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AS,WAAW,SAAS;AAEpE,YAAI,CAAC,oBAAoB;AACvB,eAAK,MAAM,uBAAuB,SAAS,UAAU,gBAAgB,IAAI,CAAC;AAAA,QAC5E;AAEA,eAAO;AAAA,MACT;AAEA,aAAO;AAAA,IACT;AAAA,IAEA,gBAAgB,KAAiB;AAC/B,UAAI,CAAC,aAAa,IAAI,IAAI,GAAG;AAC3B;AAAA,MACF;AAEA,aAAO,oBAAoB,GAAG;AAAA,IAChC;AAAA,EACF;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@collie-lang/vite",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "Vite plugin for Collie (.collie -> React component).",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -32,16 +32,16 @@
32
32
  "lint": "echo \"(mvp) no lint configured\""
33
33
  },
34
34
  "dependencies": {
35
- "@collie-lang/compiler": "^1.2.0",
35
+ "@collie-lang/compiler": "workspace:^",
36
36
  "fast-glob": "^3.3.3"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "vite": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"
40
40
  },
41
41
  "devDependencies": {
42
- "rimraf": "^6.0.1",
43
- "tsup": "^8.3.5",
44
- "typescript": "^5.7.2",
45
- "vite": "^7.3.0"
42
+ "rimraf": "^6.1.2",
43
+ "tsup": "^8.5.1",
44
+ "typescript": "^5.9.3",
45
+ "vite": "^7.3.1"
46
46
  }
47
47
  }