@open-slide/core 2.0.0-beta.6 → 2.0.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.
@@ -1,5 +1,5 @@
1
1
  import { r as printHeader, t as createCliLogger } from "./cli/bin.js";
2
- import { t as createViteConfig } from "./config-BQ6rD2iE.js";
2
+ import { t as createViteConfig } from "./config-hT1o6Jct.js";
3
3
  import path from "node:path";
4
4
  import { build as build$1, mergeConfig } from "vite";
5
5
  //#region src/cli/build.ts
package/dist/cli/bin.js CHANGED
@@ -1,17 +1,33 @@
1
1
  #!/usr/bin/env node
2
+ import { t as detectPackageManager } from "../update-moCkSyvg.js";
2
3
  import path from "node:path";
3
4
  import * as readline from "node:readline/promises";
4
5
  import { fileURLToPath } from "node:url";
5
6
  import chalk from "chalk";
6
7
  import { Command, Option } from "commander";
7
8
  import { existsSync, readFileSync, realpathSync } from "node:fs";
8
- import { createHash } from "node:crypto";
9
9
  import { cp, lstat, mkdir, readFile, readdir, readlink, rm, symlink } from "node:fs/promises";
10
+ import { createHash } from "node:crypto";
10
11
  import * as readline$1 from "node:readline";
11
12
  import { stripVTControlCharacters } from "node:util";
12
13
  //#region src/cli/preflight.ts
13
14
  const MIGRATION_URL = "https://open-slide.dev/docs/migrate-to-v2";
14
15
  const VITE_CONSUMERS = ["@vitejs/plugin-react", "@tailwindcss/vite"];
16
+ const DEPENDENCY_FIELDS = [
17
+ "dependencies",
18
+ "devDependencies",
19
+ "optionalDependencies",
20
+ "peerDependencies"
21
+ ];
22
+ const PROJECT_ROOT_MARKERS = [
23
+ "pnpm-workspace.yaml",
24
+ "pnpm-lock.yaml",
25
+ "yarn.lock",
26
+ "bun.lock",
27
+ "bun.lockb",
28
+ "package-lock.json",
29
+ ".git"
30
+ ];
15
31
  function locatePackage(name, fromDir) {
16
32
  let dir = fromDir;
17
33
  while (true) {
@@ -24,6 +40,7 @@ function locatePackage(name, fromDir) {
24
40
  } catch {}
25
41
  return {
26
42
  dir: realpathSync(candidate),
43
+ root: dir,
27
44
  version
28
45
  };
29
46
  }
@@ -48,17 +65,88 @@ function findViteMismatch(coreDir) {
48
65
  }
49
66
  return null;
50
67
  }
51
- function formatViteMismatch(mismatch, cwd = process.cwd()) {
52
- const rel = (dir) => path.relative(cwd, dir) || dir;
68
+ function declarationIn(dir) {
69
+ const file = path.join(dir, "package.json");
70
+ if (!existsSync(file)) return null;
71
+ try {
72
+ const pkg = JSON.parse(readFileSync(file, "utf8"));
73
+ for (const field of DEPENDENCY_FIELDS) {
74
+ const deps = pkg[field];
75
+ if (deps && Object.hasOwn(deps, "vite")) return {
76
+ file,
77
+ field
78
+ };
79
+ }
80
+ } catch {}
81
+ return null;
82
+ }
83
+ function isProjectRoot(dir) {
84
+ return PROJECT_ROOT_MARKERS.some((marker) => existsSync(path.join(dir, marker)));
85
+ }
86
+ function isAncestorOrSelf(ancestor, dir) {
87
+ const rel = path.relative(ancestor, dir);
88
+ return !rel.startsWith("..") && !path.isAbsolute(rel);
89
+ }
90
+ function findViteDeclaration(cwd, installRoot) {
91
+ if (installRoot && (isAncestorOrSelf(installRoot, cwd) || isAncestorOrSelf(cwd, installRoot))) {
92
+ const owner = declarationIn(installRoot);
93
+ if (owner) return owner;
94
+ }
95
+ const stopAt = installRoot && isAncestorOrSelf(installRoot, cwd) ? installRoot : null;
96
+ let dir = cwd;
97
+ while (dir !== stopAt) {
98
+ const found = declarationIn(dir);
99
+ if (found) return found;
100
+ const parent = path.dirname(dir);
101
+ if (parent === dir || !stopAt && isProjectRoot(dir)) return null;
102
+ dir = parent;
103
+ }
104
+ return null;
105
+ }
106
+ function removeCommand(pm) {
107
+ return pm === "npm" ? "npm uninstall vite" : `${pm} remove vite`;
108
+ }
109
+ function formatViteMismatch(mismatch, { cwd = process.cwd(), packageManager = "npm", declaration = null } = {}) {
110
+ const rel = (p) => path.relative(cwd, p) || p;
111
+ const want = chalk.bold(`vite@${mismatch.coreVite.version}`);
112
+ const got = chalk.bold(`vite@${mismatch.consumerVite.version}`);
113
+ const from = chalk.dim(rel(mismatch.consumerVite.dir));
114
+ const command = (cmd) => [
115
+ "",
116
+ ` ${chalk.dim("$")} ${chalk.cyan(cmd)}`,
117
+ ""
118
+ ];
119
+ const footer = `${chalk.dim("Migration guide")} ${chalk.cyan.underline(MIGRATION_URL)}`;
120
+ if (!declaration) return [
121
+ chalk.bold("Conflicting vite versions in node_modules"),
122
+ "",
123
+ `open-slide ships ${want}, but ${mismatch.consumer} is loading ${got}`,
124
+ `from ${from}. Make sure no package.json lists vite, then reinstall:`,
125
+ ...command(`${packageManager} install`),
126
+ footer
127
+ ].join("\n");
128
+ const dir = path.dirname(declaration.file);
129
+ const cd = path.resolve(dir) === path.resolve(cwd) ? "" : `cd ${rel(dir)} && `;
53
130
  return [
54
- `${mismatch.consumer} resolves vite@${mismatch.consumerVite.version} (${rel(mismatch.consumerVite.dir)}), but @open-slide/core ships vite@${mismatch.coreVite.version} (${rel(mismatch.coreVite.dir)}).`,
55
- "A `vite` entry in your package.json (v1 workspaces had one) shadows the copy core depends on. Remove it and reinstall.",
56
- `Migration guide: ${MIGRATION_URL}`
131
+ chalk.bold(`Remove ${chalk.yellow("vite")} from your package.json`),
132
+ "",
133
+ `${chalk.bold(declaration.field)} in ${chalk.dim(rel(declaration.file))} still lists vite, a leftover from v1.`,
134
+ `It shadows the ${want} bundled with open-slide: ${mismatch.consumer}`,
135
+ `is loading ${got} from ${from} instead.`,
136
+ ...command(cd + removeCommand(packageManager)),
137
+ footer
57
138
  ].join("\n");
58
139
  }
59
- function assertViteResolvesToCore() {
140
+ async function assertViteResolvesToCore(cwd = process.cwd()) {
60
141
  const mismatch = findViteMismatch(realpathSync(path.dirname(fileURLToPath(import.meta.url))));
61
- if (mismatch) throw new Error(formatViteMismatch(mismatch));
142
+ if (!mismatch) return;
143
+ const declaration = findViteDeclaration(cwd, mismatch.consumerVite.root);
144
+ const packageManager = await detectPackageManager(declaration ? path.dirname(declaration.file) : cwd);
145
+ throw new Error(formatViteMismatch(mismatch, {
146
+ cwd,
147
+ packageManager,
148
+ declaration
149
+ }));
62
150
  }
63
151
  //#endregion
64
152
  //#region src/cli/sync.ts
@@ -241,7 +329,9 @@ function printShortcutsHint() {
241
329
  process.stdout.write(`\n ${chalk.dim("press")} ${chalk.bold("h + enter")} ${chalk.dim("for shortcuts")}\n`);
242
330
  }
243
331
  function formatError(message) {
244
- return `\n ${chalk.red(glyph.cross)} ${message}\n`;
332
+ const [first, ...rest] = message.split("\n");
333
+ const body = rest.map((line) => line ? `\n ${line}` : "\n").join("");
334
+ return `\n ${chalk.red(glyph.cross)} ${first}${body}\n\n`;
245
335
  }
246
336
  const DROPPED = [/^vite v\d+\.\d+\.\d+ building /];
247
337
  const REWRITES = [
@@ -362,18 +452,18 @@ async function run(argv) {
362
452
  program.name("open-slide").description("Author slides in React — open-slide runs the rest.").version(readVersion(), "-v, --version", "print version").helpOption("-h, --help", "show help").showHelpAfterError(chalk.dim("(run `open-slide --help` for usage)"));
363
453
  program.command("dev").description("Start the dev server").addOption(new Option("-p, --port <port>", "port to listen on").argParser(parsePort)).addOption(new Option("--host [host]", "expose on the network (optional host)")).option("--open", "open the browser on start").option("--no-skills-check", "skip the built-in skills drift check").action(async (flags) => {
364
454
  if (flags.skillsCheck !== false) await runSkillsDriftCheck(resolveBuiltinSkillsDir());
365
- assertViteResolvesToCore();
366
- const { dev } = await import("../dev-BK641O5e.js");
455
+ await assertViteResolvesToCore();
456
+ const { dev } = await import("../dev-_YkLNJRt.js");
367
457
  await dev(flags);
368
458
  });
369
459
  program.command("build").description("Build a static site").option("--out-dir <dir>", "output directory (defaults to `dist`)").action(async (flags) => {
370
- assertViteResolvesToCore();
371
- const { build } = await import("../build-Cu5_qRyE.js");
460
+ await assertViteResolvesToCore();
461
+ const { build } = await import("../build-DOgOEZZA.js");
372
462
  await build(flags);
373
463
  });
374
464
  program.command("preview").description("Preview the production build").addOption(new Option("-p, --port <port>", "port to listen on").argParser(parsePort)).addOption(new Option("--host [host]", "expose on the network (optional host)")).option("--open", "open the browser on start").action(async (flags) => {
375
- assertViteResolvesToCore();
376
- const { preview } = await import("../preview-BuCI-RMW.js");
465
+ await assertViteResolvesToCore();
466
+ const { preview } = await import("../preview-pABcGTQh.js");
377
467
  await preview(flags);
378
468
  });
379
469
  program.command("sync:skills").description("Sync built-in skills from @open-slide/core into this workspace").option("--dry-run", "show what would change without writing").action(async (flags) => {