@decocms/blocks-cli 7.77.14 → 7.78.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": "@decocms/blocks-cli",
3
- "version": "7.77.14",
3
+ "version": "7.78.1",
4
4
  "type": "module",
5
5
  "description": "Deco codegen (generate-blocks, generate-schema, generate-invoke) and Fresh-to-TanStack migration tooling",
6
6
  "repository": {
@@ -33,7 +33,7 @@
33
33
  "lint:unused": "knip"
34
34
  },
35
35
  "dependencies": {
36
- "@decocms/blocks": "7.77.14",
36
+ "@decocms/blocks": "7.78.1",
37
37
  "ts-morph": "^27.0.0",
38
38
  "tsx": "^4.22.5"
39
39
  },
@@ -114,7 +114,17 @@ export function generatePackageJson(ctx: MigrationContext): string {
114
114
  // (in `dependencies` and `devDependencies`) needs to become its own
115
115
  // `getLatestVersion("<package>", "<fallback>")` call instead of sharing
116
116
  // this one lookup.
117
- const frameworkVersion = getLatestVersion("@decocms/blocks", "7.5.1");
117
+ //
118
+ // The lookup reads @decocms/blocks-cli, not @decocms/blocks: since v8,
119
+ // @decocms/blocks' `latest` is 8.x, which this migrator's output can't
120
+ // run on. blocks-cli only exists on the 7.x line, so its `latest` is
121
+ // always the newest 7.x of the lockstep set. (`npm view
122
+ // @decocms/blocks@7 version` is no substitute: with a range npm prints
123
+ // every matching version, unsorted.)
124
+ // A non-7.x answer (blocks-cli's `latest` moved by mistake, as the
125
+ // accidental 8.0.0 once did) falls back to the pinned 7.x.
126
+ const cliLatest = getLatestVersion("@decocms/blocks-cli", "7.78.0");
127
+ const frameworkVersion = /^7\.\d+\.\d+$/.test(cliLatest) ? cliLatest : "7.78.0";
118
128
 
119
129
  const platformPackage: Partial<Record<typeof ctx.platform, string>> = {
120
130
  vtex: "@decocms/apps-vtex",
@@ -0,0 +1,53 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+ import type { MigrationContext } from "../types";
3
+
4
+ const npmView = vi.hoisted(() => vi.fn((_cmd: string) => "7.80.3\n"));
5
+ vi.mock("node:child_process", async (importOriginal) => {
6
+ const actual = await importOriginal<typeof import("node:child_process")>();
7
+ return { ...actual, default: { ...actual, execSync: npmView }, execSync: npmView };
8
+ });
9
+
10
+ const { generatePackageJson } = await import("./package-json");
11
+
12
+ const ctx = {
13
+ siteName: "acme-store",
14
+ platform: "vtex",
15
+ importMap: {},
16
+ discoveredNpmDeps: {},
17
+ } as unknown as MigrationContext;
18
+
19
+ describe("generatePackageJson — framework version", () => {
20
+ // Since v8, @decocms/blocks' `latest` is 8.x, which the migrator's output
21
+ // can't run on. blocks-cli only ships on the 7.x line, so its `latest` is
22
+ // the newest 7.x of the lockstep set.
23
+ it("reads the version from @decocms/blocks-cli, never @decocms/blocks' latest", () => {
24
+ const pkg = JSON.parse(generatePackageJson(ctx));
25
+
26
+ expect(npmView).toHaveBeenCalledTimes(1);
27
+ expect(npmView.mock.calls[0][0]).toBe("npm view @decocms/blocks-cli version");
28
+ for (const dep of [
29
+ "@decocms/blocks",
30
+ "@decocms/blocks-admin",
31
+ "@decocms/tanstack",
32
+ "@decocms/apps-vtex",
33
+ ]) {
34
+ expect(pkg.dependencies[dep], dep).toBe("^7.80.3");
35
+ }
36
+ expect(pkg.devDependencies["@decocms/blocks-cli"]).toBe("^7.80.3");
37
+ });
38
+
39
+ it("never scaffolds 8.x, even if blocks-cli's latest is moved to it", () => {
40
+ npmView.mockImplementationOnce(() => "8.0.0\n");
41
+ const pkg = JSON.parse(generatePackageJson(ctx));
42
+ expect(pkg.dependencies["@decocms/blocks"]).toMatch(/^\^7\./);
43
+ expect(pkg.devDependencies["@decocms/blocks-cli"]).toMatch(/^\^7\./);
44
+ });
45
+
46
+ it("falls back to a 7.x version when npm can't be reached", () => {
47
+ npmView.mockImplementationOnce(() => {
48
+ throw new Error("offline");
49
+ });
50
+ const pkg = JSON.parse(generatePackageJson(ctx));
51
+ expect(pkg.dependencies["@decocms/blocks"]).toMatch(/^\^7\./);
52
+ });
53
+ });
@@ -70,6 +70,9 @@ describe("deco-upgrade-6-to-7 CLI (#367)", () => {
70
70
  expect(pkg.dependencies).not.toHaveProperty("@decocms/apps");
71
71
  expect(pkg.dependencies).toHaveProperty("@decocms/tanstack");
72
72
  expect(pkg.dependencies).toHaveProperty("@decocms/blocks");
73
+ // Never "latest": @decocms/blocks' latest is 8.x since v8.
74
+ expect(pkg.dependencies["@decocms/blocks"]).toBe("^7");
75
+ expect(pkg.dependencies["@decocms/tanstack"]).toBe("^7");
73
76
  });
74
77
 
75
78
  it("second --write run is idempotent (no-op)", () => {
@@ -68,7 +68,7 @@ function walkTsFiles(dir: string, out: string[] = []): string[] {
68
68
  /** Removes @decocms/start and @decocms/apps (bare, monolith) from a deps
69
69
  * object, and ensures the current split packages are present. Site- and
70
70
  * platform-specific version pins are left to `bun install`/`npm install`
71
- * against the fallback "latest" this writes — sites should pin exact
71
+ * against the "^7" range this writes — sites should pin exact
72
72
  * versions afterward the same way the scaffolder does. */
73
73
  function upgradeDeps(deps: Record<string, string> | undefined): {
74
74
  next: Record<string, string>;
@@ -87,7 +87,8 @@ function upgradeDeps(deps: Record<string, string> | undefined): {
87
87
  if (removed.length > 0) {
88
88
  for (const dep of FRAMEWORK_DEPS) {
89
89
  if (!next[dep]) {
90
- next[dep] = "latest";
90
+ // "^7", not "latest": @decocms/blocks' latest is 8.x since v8.
91
+ next[dep] = "^7";
91
92
  added.push(dep);
92
93
  }
93
94
  }
@@ -108,7 +109,7 @@ function upgradePackageJson(pkgPath: string, write: boolean): void {
108
109
  console.log(` package.json: removing ${removed.join(", ")}`);
109
110
  const added = [...new Set([...depsResult.added, ...devDepsResult.added])];
110
111
  if (added.length > 0) {
111
- console.log(` package.json: adding ${added.join(", ")} at "latest" — pin exact versions after install`);
112
+ console.log(` package.json: adding ${added.join(", ")} at "^7" — pin exact versions after install`);
112
113
  }
113
114
 
114
115
  if (!write) return;