@samva/vite 0.1.0 → 0.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samva/vite",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Unified Vite editor for Samva email, SMS, and WhatsApp templates",
5
5
  "keywords": [
6
6
  "email",
@@ -25,6 +25,7 @@
25
25
  },
26
26
  "files": [
27
27
  "dist",
28
+ "!dist/**/*.map",
28
29
  "package.json",
29
30
  "README.md",
30
31
  "AGENTS.md",
@@ -32,6 +33,7 @@
32
33
  ],
33
34
  "type": "module",
34
35
  "exports": {
36
+ "./package.json": "./package.json",
35
37
  ".": {
36
38
  "types": "./dist/index.d.ts",
37
39
  "import": "./dist/index.js"
@@ -57,13 +59,11 @@
57
59
  "test": "vitest run --root ../.. --project packages packages/vite/tests"
58
60
  },
59
61
  "dependencies": {
60
- "@samva/markup": "0.0.0",
62
+ "@samva/markup": "^0.1.0",
61
63
  "effect": "4.0.0-beta.102"
62
64
  },
63
65
  "devDependencies": {
64
66
  "@effect/vitest": "4.0.0-beta.102",
65
- "@nucleo/ui": "0.0.1",
66
- "@samva/editor": "0.0.0",
67
67
  "@tailwindcss/vite": "^4.3.3",
68
68
  "@types/react": "19.2.18",
69
69
  "@types/react-dom": "19.2.4",
package/dist/build.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"build.js","names":[],"sources":["../src/build.ts"],"sourcesContent":["import { dirname, parse, resolve } from \"node:path\";\n\nimport type { CompileOptions } from \"@samva/markup/compile\";\nimport type { Diagnostic } from \"@samva/markup/diagnostics\";\n\nimport { discoverTemplateFiles } from \"./discovery\";\nimport {\n COMPILER_VERSION,\n compileSourcePreview,\n emitModulePreview,\n type ModulePreview,\n} from \"./emit\";\nimport { loadProjectTheme, resolveThemePath, withThemeLayer } from \"./theme\";\n\n// Programmatic build entry for the CLI (`samva templates push`). It runs the\n// same in-process chain the dev plugin runs, but headless: spin up a Vite dev\n// server in middleware mode purely as a TSX evaluator (esbuild applies the\n// @samva/markup jsxImportSource), evaluate every discovered template module, and\n// return its emitted-SML + compiled preview. `vite` is imported lazily so the\n// dep is only required when a caller actually builds (it is an optional peer).\n\nexport interface BuildTemplatesResult {\n /** One entry per discovered template file, in discovery (sorted) order. */\n readonly files: ReadonlyArray<{\n readonly id: string;\n readonly kind: \"tsx\" | \"samva\";\n readonly preview: ModulePreview;\n }>;\n /**\n * Project theme.css parse diagnostics (spans into theme.css). `buildTemplates`\n * always sets it (empty when the theme parsed or there is no theme file);\n * optional so callers constructing a result by hand needn't supply it.\n */\n readonly themeDiagnostics?: ReadonlyArray<Diagnostic> | undefined;\n}\n\nexport interface BuildTemplatesOptions {\n readonly compile?: CompileOptions | undefined;\n /**\n * Project root to discover `theme.css` from (design brief §7e), themed into\n * every compiled preview as the org-token layer. Defaults to the parent of\n * `dir` (templates live under the project root, e.g. `emails/`).\n */\n readonly root?: string | undefined;\n /**\n * Theme file override, relative to `root`. `false` disables theme discovery.\n * Default: `theme.css`.\n */\n readonly theme?: string | false | undefined;\n}\n\n/**\n * Discovers and evaluates every `.tsx`/`.samva` template under `dir`, returning\n * emitted SML + compiled artifacts per template — themed by the project's\n * `theme.css` if present. Throws if `vite` is not installed (the optional peer) —\n * the caller surfaces that as a user error.\n */\nexport const buildTemplates = async (\n dir: string,\n options: BuildTemplatesOptions = {},\n): Promise<BuildTemplatesResult> => {\n const templatesDir = resolve(dir);\n const root = options.root ?? dirname(templatesDir);\n const theme = await loadProjectTheme(resolveThemePath(root, options.theme));\n const compile = withThemeLayer(options.compile, theme.tokens);\n const files = await discoverTemplateFiles(templatesDir);\n const tsxFiles = files.filter((file) => file.kind === \"tsx\");\n\n // Only stand up Vite when there's TSX to evaluate; `.samva` compiles directly.\n const server = tsxFiles.length > 0 ? await createEvaluator(templatesDir) : undefined;\n\n // oxlint-disable-next-line samva/no-try-catch-or-throw -- Plain library boundary (not Effect domain): try/finally guarantees the Vite dev server is closed after evaluation.\n try {\n const entries = await Promise.all(\n files.map(async (file) => {\n if (file.kind === \"samva\") {\n const { readFile } = await import(\"node:fs/promises\");\n const source = await readFile(file.path, \"utf8\");\n const name = file.id.replace(/\\.samva$/, \"\");\n const template = compileSourcePreview(name, source, compile);\n const preview: ModulePreview = {\n ok: template.ok,\n compilerVersion: COMPILER_VERSION,\n templates: [template],\n diagnostics: [],\n };\n return { id: file.id, kind: file.kind, preview };\n }\n const name = parse(file.id).name;\n const evaluated = await server!\n .ssrLoadModule(file.path)\n .then((value) => ({ ok: true as const, moduleExports: value as Record<string, unknown> }))\n .catch((cause: unknown) => ({\n ok: false as const,\n message: cause instanceof Error ? cause.message : String(cause),\n }));\n if (!evaluated.ok) {\n return {\n id: file.id,\n kind: file.kind,\n preview: {\n ok: false,\n compilerVersion: COMPILER_VERSION,\n templates: [],\n diagnostics: [\n {\n code: \"module-load-error\",\n message: evaluated.message,\n span: { start: 0, end: 0 },\n },\n ],\n },\n };\n }\n return {\n id: file.id,\n kind: file.kind,\n preview: emitModulePreview(name, evaluated.moduleExports, compile),\n };\n }),\n );\n return { files: entries, themeDiagnostics: theme.diagnostics };\n } finally {\n await server?.close();\n }\n};\n\nconst createEvaluator = async (root: string) => {\n const vite = await import(\"vite\").catch(() => undefined);\n if (vite === undefined) {\n // oxlint-disable-next-line samva/no-try-catch-or-throw, samva/no-error-constructor -- Plain library boundary (not Effect domain): the optional `vite` peer is missing and the CLI catches this Error to surface a user-facing message.\n throw new Error(\n \"`vite` is required for `samva templates push`. Install it as a dev dependency (it ships as an optional peer of @samva/vite).\",\n );\n }\n return vite.createServer({\n root,\n logLevel: \"silent\",\n server: { middlewareMode: true, hmr: false, watch: null },\n oxc: { jsx: { runtime: \"automatic\", importSource: \"@samva/markup\" } },\n optimizeDeps: { noDiscovery: true, include: [] },\n });\n};\n"],"mappings":";;;;;;;;;;AAyDA,MAAa,iBAAiB,OAC5B,K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