@kidecms/core 0.22.0 → 0.23.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.
@@ -69,11 +69,23 @@ const gitIsDirty = () => {
69
69
 
70
70
  const readJson = (file: string) => JSON.parse(readFileSync(file, "utf-8"));
71
71
 
72
- const updateStamp = (patch: Record<string, unknown>) => {
72
+ // Eject is where the version stamp becomes meaningful: the vendored files'
73
+ // baseline is the installed package version, and the patch-upgrade flow diffs
74
+ // against it. Package-mode scaffolds carry no stamp, so create one here.
75
+ const writeStamp = (version: string) => {
73
76
  const stampPath = path.join(cwd, ".kide-version");
74
- if (!existsSync(stampPath)) return;
75
- const stamp = readJson(stampPath);
76
- writeFileSync(stampPath, `${JSON.stringify({ ...stamp, ...patch }, null, 2)}\n`);
77
+ const existing = existsSync(stampPath) ? readJson(stampPath) : {};
78
+ const stamp = {
79
+ template: "https://github.com/mhernesniemi/kide-cms",
80
+ ...existing,
81
+ kideVersion: version,
82
+ ref: `v${version}`,
83
+ commit: null,
84
+ mode: "embedded",
85
+ corePath: "src/cms",
86
+ ejectedAt: new Date().toISOString(),
87
+ };
88
+ writeFileSync(stampPath, `${JSON.stringify(stamp, null, 2)}\n`);
77
89
  };
78
90
 
79
91
  const eject = () => {
@@ -116,9 +128,13 @@ const eject = () => {
116
128
  }
117
129
 
118
130
  rootPkg.dependencies["@kidecms/core"] = "workspace:*";
131
+ // The patch-upgrade flow starts existing at eject — make its scripts reachable.
132
+ rootPkg.scripts = rootPkg.scripts ?? {};
133
+ rootPkg.scripts["cms:upgrade"] ??= "kide upgrade";
134
+ rootPkg.scripts["cms:restore"] ??= "kide restore";
119
135
  writeFileSync(rootPkgPath, `${JSON.stringify(rootPkg, null, 2)}\n`);
120
136
 
121
- updateStamp({ mode: "embedded", ejectedAt: new Date().toISOString() });
137
+ writeStamp(version);
122
138
 
123
139
  console.log("[kide:eject] Running pnpm install...");
124
140
  try {
package/internals/push.ts CHANGED
@@ -123,7 +123,9 @@ async function main() {
123
123
  }
124
124
  }
125
125
  const { statementsToExecute, hasDataLoss } = diff;
126
- const statements = statementsToExecute.filter((stmt) => !isSearchIndexStatement(stmt));
126
+ // drizzle-kit emits each unique index twice when it recreates a table — the
127
+ // second identical CREATE crashes SQLite, so drop exact duplicates.
128
+ const statements = [...new Set(statementsToExecute)].filter((stmt) => !isSearchIndexStatement(stmt));
127
129
 
128
130
  // drizzle-kit's hasDataLoss misses plain DROP COLUMN — classify statement shapes too.
129
131
  // (`__new_` is drizzle's table-recreate pattern: create copy, insert-select, drop old.)
@@ -586,10 +586,27 @@ async function main() {
586
586
  const stamp = readStamp(cwd);
587
587
  const repo = args.repo ?? stamp?.template ?? DEFAULT_REPO;
588
588
  const corePath = args.corePath ?? stamp?.corePath ?? DEFAULT_CORE_PATH;
589
- // Package mode: managed runtime comes from the @kidecms/core dependency, so
590
- // upgrades bump that version; only project-owned template files need review.
591
589
  const mode: "embedded" | "package" =
592
590
  stamp?.mode ?? (existsSync(path.join(cwd, corePath, "core")) ? "embedded" : "package");
591
+
592
+ // Patch-based upgrades exist for vendored runtimes. A package-mode project
593
+ // gets the runtime from npm — upgrading is a dependency bump, and project
594
+ // files are the user's own (release notes flag the rare change to them).
595
+ if (mode === "package") {
596
+ console.log(
597
+ [
598
+ "[cms:upgrade] This is a package-mode project — no patch upgrade needed.",
599
+ "",
600
+ " pnpm add @kidecms/core@latest",
601
+ "",
602
+ "Then check the release notes (CHANGELOG) for schema changes (`pnpm cms:push`)",
603
+ "and for the rare change to project-owned files. `cms:upgrade` applies to",
604
+ "embedded projects and projects converted with `kide eject`.",
605
+ ].join("\n"),
606
+ );
607
+ return;
608
+ }
609
+
593
610
  const fromRef = args.fromRef ?? stamp?.ref ?? stamp?.commit ?? null;
594
611
 
595
612
  if (!fromRef) {
@@ -639,7 +656,7 @@ async function main() {
639
656
  `${JSON.stringify(changedFilesJson(repoDir, fromCommit, toCommit), null, 2)}\n`,
640
657
  );
641
658
  writeReleaseNotes(repoDir, fromCommit, toCommit, packetDir);
642
- backupFiles(cwd, packetDir, mode === "package" ? ["package.json", ".kide-version"] : [...managed, ".kide-version"]);
659
+ backupFiles(cwd, packetDir, [...managed, ".kide-version"]);
643
660
 
644
661
  let applied = false;
645
662
  let applyError: string | null = null;
@@ -669,24 +686,7 @@ async function main() {
669
686
  writeFileSync(path.join(cwd, ".kide-version"), `${JSON.stringify(nextStamp, null, 2)}\n`);
670
687
  };
671
688
 
672
- if (shouldApply && mode === "package") {
673
- // Managed runtime changes arrive via the published package — bump the
674
- // dependency instead of patching files that only exist in node_modules.
675
- const targetVersion = versionFromRef(targetRef);
676
- const pkgJsonPath = path.join(cwd, "package.json");
677
- const pkgJson = JSON.parse(readFileSync(pkgJsonPath, "utf-8"));
678
- if (!targetVersion) {
679
- applyError = `Target ref "${targetRef}" is not a release tag — cannot derive an @kidecms/core version.`;
680
- } else if (!pkgJson.dependencies?.["@kidecms/core"]) {
681
- applyError = "package.json has no @kidecms/core dependency — is this really a package-mode project?";
682
- } else {
683
- pkgJson.dependencies["@kidecms/core"] = `^${targetVersion}`;
684
- writeFileSync(pkgJsonPath, `${JSON.stringify(pkgJson, null, 2)}\n`);
685
- applied = true;
686
- stampUpgrade();
687
- }
688
- recordBackupAttemptState(cwd, packetDir);
689
- } else if (shouldApply && managedPatch.trim()) {
689
+ if (shouldApply && managedPatch.trim()) {
690
690
  const patchPath = path.join(packetDir, "managed-runtime.patch");
691
691
  const result = tryRun("git", ["apply", "--3way", relativeToCwd(cwd, patchPath)], { cwd });
692
692
  if (result.ok) {
@@ -728,11 +728,7 @@ async function main() {
728
728
  targetRef,
729
729
  corePath,
730
730
  mode,
731
- applyMode: shouldApply
732
- ? mode === "package"
733
- ? "dependency bump attempted"
734
- : "managed patch attempted"
735
- : "packet only",
731
+ applyMode: shouldApply ? "managed patch attempted" : "packet only",
736
732
  managed,
737
733
  careful,
738
734
  other,
@@ -752,11 +748,7 @@ async function main() {
752
748
  );
753
749
 
754
750
  console.log(`[cms:upgrade] Packet ready: ${packetRelative}`);
755
- if (applied && mode === "package") {
756
- console.log(
757
- `[cms:upgrade] Bumped @kidecms/core to ^${versionFromRef(targetRef)} and updated .kide-version — run \`pnpm install\`, then review careful-review.patch.`,
758
- );
759
- } else if (applied) {
751
+ if (applied) {
760
752
  console.log(`[cms:upgrade] Applied managed runtime changes and updated .kide-version to ${targetRef}.`);
761
753
  } else if (applyError) {
762
754
  console.log("[cms:upgrade] Managed patch needs help. See conflicts.json and agent-instructions.md.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kidecms/core",
3
- "version": "0.22.0",
3
+ "version": "0.23.1",
4
4
  "description": "Kide CMS runtime — core library, admin UI, routes, and middleware for Astro. Shipped as TypeScript source.",
5
5
  "keywords": [
6
6
  "cms",