@eldrajs/vite-plugin-theme 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/CHANGELOG.md CHANGED
@@ -5,6 +5,17 @@ Release-please writes the generated notes from commit messages and does not repl
5
5
 
6
6
  ## Unreleased
7
7
 
8
+ - **Breaking:** a theme must declare its id in `package.json` under `eldra.themeId`
9
+ (`^[a-z][a-z0-9-]{1,48}$`, `catalog` reserved). The scanner emits it as `manifest.theme.id` and
10
+ `manifestVersion` is now `2` (`ThemeManifest.manifestVersion: 2`, `theme.id: string`). A missing
11
+ or invalid id is a scan error, so the plugin build, `eldra-theme validate` and
12
+ `eldra-theme deploy` fail naming `package.json: eldra.themeId`; there is no derivation from the
13
+ package name and no v1 manifest is produced. Core stores a theme's block schemas as
14
+ `<themeId>:<blockApiId>`; block ids in `block.json` and the manifest stay bare.
15
+ A v1 `.eldra/manifest.json` left on disk from an earlier build is rejected as the previous
16
+ manifest (`previous manifest: expected manifestVersion 2`): delete it once before the first build
17
+ after upgrading. See `docs/themes.md`'s "Theme id and schema ownership".
18
+
8
19
  - The scanner now reads a theme's own message catalogue: `i18n/<tag>.json`, siblings of
9
20
  `tokens.json`, one file per locale, each a nested JSON object of strings that gets flattened to
10
21
  dotted keys (`header.menu`, `cart.empty.title`). It validates key grammar/length, value
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as ThemeManifest, C as ScanOptions, D as TemplateSeedLayoutNode, E as TemplateSeedLayout, O as TemplateSeedReusableNode, S as PageSeedTarget, T as TemplateSeedBlockNode, _ as ManifestPageSeedRegion, a as DeclaredPageSeedBlock, b as ManifestTemplateSeed, c as DeclaredSeed, d as DeclaredThemeCodePage, f as EldraThemeOptions, g as ManifestPageSeedEntry, h as ManifestPageSeedBlock, i as DeclaredPageSeed, j as ThemeMessages, k as TemplateSeedSchemaApiId, l as DeclaredTemplateSeed, m as ManifestPageSeed, n as BlockField, o as DeclaredPageSeedEntry, p as LegacyThemeTokens, r as BlockMigration, s as DeclaredPageSeedRegion, t as BlockDefinition, u as DeclaredTemplateSeedBlock, v as ManifestRoute, w as ScanResult, x as ManifestTemplateSeedBlock, y as ManifestTemplateRoles } from "./types-BRNXfpXW.js";
1
+ import { A as ThemeManifest, C as ScanOptions, D as TemplateSeedLayoutNode, E as TemplateSeedLayout, O as TemplateSeedReusableNode, S as PageSeedTarget, T as TemplateSeedBlockNode, _ as ManifestPageSeedRegion, a as DeclaredPageSeedBlock, b as ManifestTemplateSeed, c as DeclaredSeed, d as DeclaredThemeCodePage, f as EldraThemeOptions, g as ManifestPageSeedEntry, h as ManifestPageSeedBlock, i as DeclaredPageSeed, j as ThemeMessages, k as TemplateSeedSchemaApiId, l as DeclaredTemplateSeed, m as ManifestPageSeed, n as BlockField, o as DeclaredPageSeedEntry, p as LegacyThemeTokens, r as BlockMigration, s as DeclaredPageSeedRegion, t as BlockDefinition, u as DeclaredTemplateSeedBlock, v as ManifestRoute, w as ScanResult, x as ManifestTemplateSeedBlock, y as ManifestTemplateRoles } from "./types-kcnroZCz.js";
2
2
  import { Plugin } from "vite";
3
3
  //#region src/plugin.d.ts
4
4
  export default function eldraTheme(options?: EldraThemeOptions): Plugin;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as validateTemplateRoles, i as validatePageSeeds, n as scanTheme, o as validateTemplateSeeds, r as seedLayout, t as readPreviousManifest } from "./scan-DjW4f_E8.js";
1
+ import { a as validateTemplateRoles, i as validatePageSeeds, n as scanTheme, o as validateTemplateSeeds, r as seedLayout, t as readPreviousManifest } from "./scan-DmmAzjZz.js";
2
2
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
3
  import { dirname, join, relative } from "node:path";
4
4
  import { generateDesignTokenCss, generateTailwindThemeCss, normalizeThemeDesignTokens } from "@eldrajs/theme-core/design-tokens";
@@ -4,7 +4,7 @@ import { dirname, join, relative } from "node:path";
4
4
  import { DesignTokenValidationError, normalizeThemeDesignTokens } from "@eldrajs/theme-core/design-tokens";
5
5
  import { resolveLayoutBreakpoints } from "@eldrajs/theme-core/layout";
6
6
  import Ajv from "ajv";
7
- import { RICH_TEXT_TOOLBAR_CONTROLS, parseDynamicRoutePattern } from "@eldrajs/theme-core";
7
+ import { RESERVED_THEME_IDS, RICH_TEXT_TOOLBAR_CONTROLS, THEME_ID_PATTERN, parseDynamicRoutePattern } from "@eldrajs/theme-core";
8
8
  import { safeLinkHref } from "@eldrajs/theme-core/links";
9
9
  //#region src/blockSchema.ts
10
10
  const API_ID_PATTERN = "^[a-z][a-z0-9-]{1,48}$";
@@ -1531,8 +1531,9 @@ function scanTheme(opts) {
1531
1531
  const pageSeeds = validatePageSeeds(opts.templates ?? [], blocks, templates, templateRoles, errors);
1532
1532
  const messages = readMessages(themeDir, packageJson, errors);
1533
1533
  const manifest = {
1534
- manifestVersion: 1,
1534
+ manifestVersion: 2,
1535
1535
  theme: {
1536
+ id: readThemeId(packageJson, errors),
1536
1537
  name: sanitizeThemeName(typeof packageJson?.name === "string" ? packageJson.name : ""),
1537
1538
  version: typeof packageJson?.version === "string" ? packageJson.version : "0.0.0",
1538
1539
  framework: opts.framework ?? "vite",
@@ -2104,6 +2105,27 @@ function resolvePackageVersion(themeDir, packageName) {
2104
2105
  return "0.0.0";
2105
2106
  }
2106
2107
  }
2108
+ /** The theme's declared `eldra.themeId`: the stable identity Core stores the
2109
+ * theme's block schemas and entries under (`<themeId>:<apiId>`), independent of
2110
+ * the npm package name. Required; there is no derivation from `name`. Returns
2111
+ * an empty string after reporting an error, so the caller still builds the
2112
+ * rest of the manifest and every problem is reported in one pass. */
2113
+ function readThemeId(packageJson, errors) {
2114
+ const declared = isRecord(packageJson?.eldra) ? packageJson.eldra.themeId : void 0;
2115
+ if (declared === void 0) {
2116
+ errors.push("package.json: eldra.themeId — required; set \"eldra\": { \"themeId\": \"<id>\" } (lower-case letters, digits and hyphens, 2 to 49 characters, starting with a letter)");
2117
+ return "";
2118
+ }
2119
+ if (typeof declared !== "string" || !THEME_ID_PATTERN.test(declared)) {
2120
+ errors.push(`package.json: eldra.themeId — must match ${THEME_ID_PATTERN} (lower-case letters, digits and hyphens, 2 to 49 characters, starting with a letter; got ${JSON.stringify(declared)})`);
2121
+ return "";
2122
+ }
2123
+ if (RESERVED_THEME_IDS.includes(declared)) {
2124
+ errors.push(`package.json: eldra.themeId — "${declared}" is reserved`);
2125
+ return "";
2126
+ }
2127
+ return declared;
2128
+ }
2107
2129
  function sanitizeThemeName(name) {
2108
2130
  return (name.split("/").pop() ?? "").toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 49);
2109
2131
  }
@@ -2121,8 +2143,8 @@ function toRelative(themeDir, path) {
2121
2143
  function previousBlocks(manifest, errors) {
2122
2144
  const result = /* @__PURE__ */ new Map();
2123
2145
  if (manifest === void 0) return result;
2124
- if (!isRecord(manifest) || manifest.manifestVersion !== 1 || !Array.isArray(manifest.blocks)) {
2125
- errors.push("previous manifest: expected manifestVersion 1 and a blocks array");
2146
+ if (!isRecord(manifest) || manifest.manifestVersion !== 2 || !Array.isArray(manifest.blocks)) {
2147
+ errors.push("previous manifest: expected manifestVersion 2 and a blocks array");
2126
2148
  return result;
2127
2149
  }
2128
2150
  for (const [index, value] of manifest.blocks.entries()) {
package/dist/scan.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as ThemeManifest, C as ScanOptions, b as ManifestTemplateSeed, l as DeclaredTemplateSeed, v as ManifestRoute, w as ScanResult } from "./types-BRNXfpXW.js";
1
+ import { A as ThemeManifest, C as ScanOptions, b as ManifestTemplateSeed, l as DeclaredTemplateSeed, v as ManifestRoute, w as ScanResult } from "./types-kcnroZCz.js";
2
2
  //#region src/scan.d.ts
3
3
  export declare function scanTheme(opts: ScanOptions): ScanResult;
4
4
  export declare function readPreviousManifest(themeDir: string, errors: string[]): ThemeManifest | undefined;
package/dist/scan.js CHANGED
@@ -1,2 +1,2 @@
1
- import { n as scanTheme, t as readPreviousManifest } from "./scan-DjW4f_E8.js";
1
+ import { n as scanTheme, t as readPreviousManifest } from "./scan-DmmAzjZz.js";
2
2
  export { readPreviousManifest, scanTheme };
@@ -286,8 +286,12 @@ interface BlockDefinition {
286
286
  migrations?: BlockMigration[];
287
287
  }
288
288
  interface ThemeManifest {
289
- manifestVersion: 1;
289
+ /** 2: `theme.id` is required. There is no v1 reader. */
290
+ manifestVersion: 2;
290
291
  theme: {
292
+ /** The theme's stable id (`package.json` `eldra.themeId`); Core stores the theme's
293
+ * block schemas as `<id>:<blockApiId>`. Block apiIds in this manifest stay bare. */
294
+ id: string;
291
295
  name: string;
292
296
  version: string;
293
297
  framework: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eldrajs/vite-plugin-theme",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Vite plugin for Eldra themes: scans blocks/*/block.json, validates them, emits the theme manifest and the virtual modules the runtime reads (blocks, manifest, block fields, breakpoints, tokens CSS).",
5
5
  "keywords": [
6
6
  "cms",
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "ajv": "^8.17.1",
44
- "@eldrajs/theme-core": "^0.1.0"
44
+ "@eldrajs/theme-core": "^0.2.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@tailwindcss/vite": "^4.1.14",