@cedarjs/cli 8.0.0-canary.3612 → 8.0.0-canary.3615

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.
@@ -4,7 +4,7 @@ import { ListrEnquirerPromptAdapter } from "@listr2/prompt-adapter-enquirer";
4
4
  import execa from "execa";
5
5
  import latestVersion from "latest-version";
6
6
  import { Listr } from "listr2";
7
- import packageJson from "package-json";
7
+ import packageJson, { VersionNotFoundError } from "package-json";
8
8
  import { terminalLink } from "termi-link";
9
9
  import { colors as c } from "@cedarjs/cli-helpers/colors";
10
10
  import {
@@ -111,6 +111,13 @@ const handler = async (upgradeOptions) => {
111
111
  task: (ctx, task) => updatePrismaDeps(ctx, task, { dryRun, verbose }),
112
112
  enabled: (ctx) => !!ctx.versionToUpgradeTo && notBlockedByPreUpgradeChecks(ctx)
113
113
  },
114
+ {
115
+ title: "Updating Vite and Vitest to the versions CedarJS uses",
116
+ // Runs after the canary template sync, so the versions come from the
117
+ // target release rather than from the template on main
118
+ task: (ctx, task) => updateViteDeps(ctx, task, { dryRun, verbose }),
119
+ enabled: (ctx) => !!ctx.versionToUpgradeTo && notBlockedByPreUpgradeChecks(ctx)
120
+ },
114
121
  {
115
122
  title: "Downloading yarn patches",
116
123
  task: (ctx) => downloadYarnPatches(ctx, { dryRun, verbose }),
@@ -320,20 +327,34 @@ function updateCedarJSDepsForAllSides(ctx, options) {
320
327
  })
321
328
  );
322
329
  }
323
- async function fetchPrismaPeerVersion(cedarVersion) {
330
+ async function fetchCedarManifest(packageName, cedarVersion) {
324
331
  const version = cedarVersion.split("+")[0];
325
- let manifest;
326
332
  try {
327
- manifest = await packageJson("@cedarjs/cli", { version });
333
+ return await packageJson(packageName, { version });
328
334
  } catch (e) {
329
335
  const message = e instanceof Error ? e.message : String(e);
330
336
  throw new Error(
331
- `Failed to fetch @cedarjs/cli@${version} from the npm registry: ` + message
337
+ `Failed to fetch ${packageName}@${version} from the npm registry: ` + message
332
338
  );
333
339
  }
340
+ }
341
+ async function fetchPrismaPeerVersion(cedarVersion) {
342
+ const manifest = await fetchCedarManifest("@cedarjs/cli", cedarVersion);
334
343
  const prismaVersion = manifest.peerDependencies?.["prisma"];
335
344
  return typeof prismaVersion === "string" ? prismaVersion : void 0;
336
345
  }
346
+ async function fetchViteVersions(cedarVersion) {
347
+ const [viteManifest, testingManifest] = await Promise.all([
348
+ fetchCedarManifest("@cedarjs/vite", cedarVersion),
349
+ fetchCedarManifest("@cedarjs/testing", cedarVersion)
350
+ ]);
351
+ const vite = viteManifest.dependencies?.["vite"];
352
+ const vitest = testingManifest.peerDependencies?.["vitest"];
353
+ return {
354
+ vite: typeof vite === "string" ? vite : void 0,
355
+ vitest: typeof vitest === "string" ? vitest : void 0
356
+ };
357
+ }
337
358
  function isPrismaReleasePackage(depName) {
338
359
  return depName === "prisma" || depName === "@prisma/client" || depName.startsWith("@prisma/adapter-");
339
360
  }
@@ -444,6 +465,239 @@ async function updatePrismaDeps(ctx, task, { dryRun, verbose }) {
444
465
  task.title = task.title + "\n" + messages.join("\n");
445
466
  }
446
467
  }
468
+ async function fetchVitestReleasePackages(depNames, vitestVersion) {
469
+ const candidates = [...new Set(depNames)].filter(
470
+ (depName) => depName.startsWith("@vitest/")
471
+ );
472
+ const published = await Promise.all(
473
+ candidates.map(async (depName) => {
474
+ try {
475
+ await packageJson(depName, { version: vitestVersion });
476
+ return true;
477
+ } catch (e) {
478
+ if (e instanceof VersionNotFoundError) {
479
+ return false;
480
+ }
481
+ const message = e instanceof Error ? e.message : String(e);
482
+ throw new Error(
483
+ `Failed to fetch ${depName}@${vitestVersion} from the npm registry: ` + message
484
+ );
485
+ }
486
+ })
487
+ );
488
+ return new Set(candidates.filter((_, i) => published[i]));
489
+ }
490
+ function updateViteDependencies(pkg, versions, messages, {
491
+ dryRun,
492
+ verbose,
493
+ vitestPackages = /* @__PURE__ */ new Set()
494
+ } = {}) {
495
+ const versionFor = (depName) => {
496
+ if (depName === "vite") {
497
+ return versions.vite;
498
+ }
499
+ if (depName === "vitest" || vitestPackages.has(depName)) {
500
+ return versions.vitest;
501
+ }
502
+ return void 0;
503
+ };
504
+ let updated = false;
505
+ for (const field of ["dependencies", "devDependencies"]) {
506
+ const deps = pkg[field] ?? {};
507
+ for (const [depName, depVersion] of Object.entries(deps)) {
508
+ const version = versionFor(depName);
509
+ if (!version || depVersion === version) {
510
+ continue;
511
+ }
512
+ if (verbose || dryRun) {
513
+ messages.push(` - ${depName}: ${depVersion} => ${version}`);
514
+ }
515
+ deps[depName] = version;
516
+ updated = true;
517
+ }
518
+ }
519
+ for (const field of ["resolutions", "overrides"]) {
520
+ const pin = pkg[field]?.["vite"];
521
+ if (!versions.vite || typeof pin !== "string" || pin === versions.vite) {
522
+ continue;
523
+ }
524
+ if (verbose || dryRun) {
525
+ messages.push(` - ${field}.vite: ${pin} => ${versions.vite}`);
526
+ }
527
+ pkg[field] = { ...pkg[field], vite: versions.vite };
528
+ updated = true;
529
+ }
530
+ return updated;
531
+ }
532
+ function addVitePin(pkg, packageManager, viteVersion, messages) {
533
+ const field = packageManager === "yarn" ? "resolutions" : packageManager === "npm" ? "overrides" : void 0;
534
+ if (!field || pkg[field]?.["vite"] !== void 0) {
535
+ return false;
536
+ }
537
+ pkg[field] = { ...pkg[field], vite: viteVersion };
538
+ messages.push(` - ${field}.vite: added at ${viteVersion}`);
539
+ return true;
540
+ }
541
+ function findPnpmOverridesBlock(lines) {
542
+ const start = lines.findIndex(
543
+ (line) => /^overrides:\s*(#[^\n]*)?$/.test(line)
544
+ );
545
+ if (start === -1) {
546
+ return void 0;
547
+ }
548
+ const block = {
549
+ start,
550
+ lastEntry: start,
551
+ style: { indent: " ", keyQuote: "", valueQuote: "'" }
552
+ };
553
+ for (let i = start + 1; i < lines.length; i++) {
554
+ const line = lines[i];
555
+ if (/^[^\s#]/.test(line)) {
556
+ break;
557
+ }
558
+ const entry = /^(\s+)(['"]?)[^\s'"#:]+\2\s*:\s*(['"]?)/.exec(line);
559
+ if (!entry) {
560
+ continue;
561
+ }
562
+ if (block.lastEntry === start) {
563
+ const [, indent, keyQuote, valueQuote] = entry;
564
+ block.style = { indent, keyQuote, valueQuote };
565
+ }
566
+ block.lastEntry = i;
567
+ if (block.vite === void 0 && /^\s+(['"]?)vite\1\s*:/.test(line)) {
568
+ block.vite = i;
569
+ }
570
+ }
571
+ return block;
572
+ }
573
+ function updatePnpmViteOverride(content, viteVersion) {
574
+ const lines = content.split("\n");
575
+ const viteIndex = findPnpmOverridesBlock(lines)?.vite;
576
+ if (viteIndex === void 0) {
577
+ return void 0;
578
+ }
579
+ const match = /^(\s+)(['"]?)vite\2(\s*:\s*)(?:(['"])([^\n]*?)\4|([^'"\s#]+))([^\n]*)$/.exec(
580
+ lines[viteIndex]
581
+ );
582
+ if (!match) {
583
+ return void 0;
584
+ }
585
+ const [, indent, keyQuote, separator, quote, quotedVersion, bareVersion] = match;
586
+ const valueQuote = quote ?? "";
587
+ const version = quotedVersion ?? bareVersion;
588
+ const rest = match[7];
589
+ if (version === viteVersion) {
590
+ return void 0;
591
+ }
592
+ lines[viteIndex] = indent + keyQuote + "vite" + keyQuote + separator + valueQuote + viteVersion + valueQuote + rest;
593
+ return lines.join("\n");
594
+ }
595
+ function addPnpmViteOverride(content, viteVersion) {
596
+ const eol = content.includes("\r\n") ? "\r\n" : "\n";
597
+ const lines = content.split("\n");
598
+ const block = findPnpmOverridesBlock(lines);
599
+ if (!block) {
600
+ if (lines.some((line) => /^['"]?overrides['"]?\s*:/.test(line))) {
601
+ return void 0;
602
+ }
603
+ return content.replace(/\s*$/, "") + eol + eol + "overrides:" + eol + ` vite: '${viteVersion}'` + eol;
604
+ }
605
+ if (block.vite) {
606
+ return void 0;
607
+ }
608
+ const { indent, keyQuote, valueQuote } = block.style;
609
+ const entry = indent + keyQuote + "vite" + keyQuote + ": " + valueQuote + viteVersion + valueQuote + (eol === "\r\n" ? "\r" : "");
610
+ lines.splice(block.lastEntry + 1, 0, entry);
611
+ return lines.join("\n");
612
+ }
613
+ async function updateViteDeps(ctx, task, { dryRun, verbose }) {
614
+ if (!ctx.versionToUpgradeTo) {
615
+ throw new Error("Failed to upgrade");
616
+ }
617
+ const versions = await fetchViteVersions(String(ctx.versionToUpgradeTo));
618
+ if (!versions.vite && !versions.vitest) {
619
+ task.skip(
620
+ `CedarJS ${ctx.versionToUpgradeTo} doesn't declare Vite or Vitest versions`
621
+ );
622
+ return;
623
+ }
624
+ const messages = [];
625
+ const projectPackages = [
626
+ { basePath: getPaths().base, isRoot: true, requiresVite: false },
627
+ { basePath: getPaths().web.base, isRoot: false, requiresVite: true },
628
+ { basePath: getPaths().api.base, isRoot: false, requiresVite: true }
629
+ ];
630
+ const projectPackageJsons = projectPackages.map(({ basePath, ...rest }) => ({
631
+ ...rest,
632
+ pkgJsonPath: path.join(basePath, "package.json")
633
+ })).filter(({ pkgJsonPath }) => fs.existsSync(pkgJsonPath)).map((projectPackage) => ({
634
+ ...projectPackage,
635
+ pkg: JSON.parse(fs.readFileSync(projectPackage.pkgJsonPath, "utf-8"))
636
+ }));
637
+ const packageManager = getPackageManager();
638
+ const vitestPackages = versions.vitest ? await fetchVitestReleasePackages(
639
+ projectPackageJsons.flatMap(({ pkg }) => [
640
+ ...Object.keys(pkg.dependencies ?? {}),
641
+ ...Object.keys(pkg.devDependencies ?? {})
642
+ ]),
643
+ versions.vitest
644
+ ) : /* @__PURE__ */ new Set();
645
+ for (const {
646
+ pkgJsonPath,
647
+ isRoot,
648
+ requiresVite,
649
+ pkg
650
+ } of projectPackageJsons) {
651
+ const pkgMessages = [];
652
+ const pinned = isRoot && !!versions.vite && addVitePin(pkg, packageManager, versions.vite, pkgMessages);
653
+ const added = requiresVite && !!versions.vite && addMissingDependency(
654
+ pkg,
655
+ "devDependencies",
656
+ "vite",
657
+ versions.vite,
658
+ pkgMessages
659
+ );
660
+ const updated = updateViteDependencies(pkg, versions, pkgMessages, {
661
+ dryRun,
662
+ verbose,
663
+ vitestPackages
664
+ });
665
+ if (pinned || added || updated) {
666
+ if (pkgMessages.length > 0) {
667
+ messages.push(`Updating ${pkgJsonPath}`, ...pkgMessages);
668
+ }
669
+ if (!dryRun) {
670
+ fs.writeFileSync(pkgJsonPath, JSON.stringify(pkg, void 0, 2));
671
+ }
672
+ }
673
+ }
674
+ const pnpmWorkspacePath = path.join(getPaths().base, "pnpm-workspace.yaml");
675
+ if (versions.vite && fs.existsSync(pnpmWorkspacePath)) {
676
+ const content = fs.readFileSync(pnpmWorkspacePath, "utf-8");
677
+ const updatedContent = updatePnpmViteOverride(content, versions.vite);
678
+ const addedContent = updatedContent === void 0 && packageManager === "pnpm" ? addPnpmViteOverride(content, versions.vite) : void 0;
679
+ if (updatedContent !== void 0) {
680
+ if (verbose || dryRun) {
681
+ messages.push(
682
+ `Updating ${pnpmWorkspacePath}`,
683
+ ` - overrides.vite => ${versions.vite}`
684
+ );
685
+ }
686
+ } else if (addedContent !== void 0) {
687
+ messages.push(
688
+ `Updating ${pnpmWorkspacePath}`,
689
+ ` - overrides.vite: added at ${versions.vite}`
690
+ );
691
+ }
692
+ const newContent = updatedContent ?? addedContent;
693
+ if (newContent !== void 0 && !dryRun) {
694
+ fs.writeFileSync(pnpmWorkspacePath, newContent);
695
+ }
696
+ }
697
+ if (messages.length > 0) {
698
+ task.title = task.title + "\n" + messages.join("\n");
699
+ }
700
+ }
447
701
  function mergeTemplateDependencies(field, templatePackageJson, localPackageJson, messages, { dryRun, verbose } = {}) {
448
702
  const templateDeps = templatePackageJson[field];
449
703
  if (!templateDeps) {
@@ -612,8 +866,14 @@ async function dedupeDeps(_task, { verbose }) {
612
866
  }
613
867
  export {
614
868
  addMissingDependency,
869
+ addPnpmViteOverride,
870
+ addVitePin,
615
871
  fetchPrismaPeerVersion,
872
+ fetchViteVersions,
873
+ fetchVitestReleasePackages,
616
874
  handler,
617
875
  mergeTemplateDependencies,
618
- updatePrismaDependencies
876
+ updatePnpmViteOverride,
877
+ updatePrismaDependencies,
878
+ updateViteDependencies
619
879
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli",
3
- "version": "8.0.0-canary.3612",
3
+ "version": "8.0.0-canary.3615",
4
4
  "description": "The CedarJS Command Line",
5
5
  "repository": {
6
6
  "type": "git",
@@ -36,17 +36,17 @@
36
36
  "@babel/preset-typescript": "7.29.7",
37
37
  "@babel/traverse": "7.29.12",
38
38
  "@babel/types": "7.29.11",
39
- "@cedarjs/api-server": "8.0.0-canary.3612",
40
- "@cedarjs/babel-config": "8.0.0-canary.3612",
41
- "@cedarjs/cli-helpers": "8.0.0-canary.3612",
42
- "@cedarjs/internal": "8.0.0-canary.3612",
43
- "@cedarjs/prerender": "8.0.0-canary.3612",
44
- "@cedarjs/project-config": "8.0.0-canary.3612",
45
- "@cedarjs/structure": "8.0.0-canary.3612",
46
- "@cedarjs/telemetry": "8.0.0-canary.3612",
47
- "@cedarjs/utils": "8.0.0-canary.3612",
48
- "@cedarjs/vite": "8.0.0-canary.3612",
49
- "@cedarjs/web-server": "8.0.0-canary.3612",
39
+ "@cedarjs/api-server": "8.0.0-canary.3615",
40
+ "@cedarjs/babel-config": "8.0.0-canary.3615",
41
+ "@cedarjs/cli-helpers": "8.0.0-canary.3615",
42
+ "@cedarjs/internal": "8.0.0-canary.3615",
43
+ "@cedarjs/prerender": "8.0.0-canary.3615",
44
+ "@cedarjs/project-config": "8.0.0-canary.3615",
45
+ "@cedarjs/structure": "8.0.0-canary.3615",
46
+ "@cedarjs/telemetry": "8.0.0-canary.3615",
47
+ "@cedarjs/utils": "8.0.0-canary.3615",
48
+ "@cedarjs/vite": "8.0.0-canary.3615",
49
+ "@cedarjs/web-server": "8.0.0-canary.3615",
50
50
  "@listr2/prompt-adapter-enquirer": "4.4.3",
51
51
  "@prisma/internals": "7.10.1",
52
52
  "ansis": "4.4.0",
@@ -87,7 +87,7 @@
87
87
  "yargs": "18.2.0"
88
88
  },
89
89
  "devDependencies": {
90
- "@cedarjs/framework-tools": "8.0.0-canary.3612",
90
+ "@cedarjs/framework-tools": "8.0.0-canary.3615",
91
91
  "@prisma/dmmf": "7.10.1",
92
92
  "@types/archiver": "^7.0.0",
93
93
  "memfs": "4.80.0",