vize 0.443.0 → 0.457.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/dist/cli.mjs CHANGED
@@ -115,25 +115,6 @@ const DEFAULT_SCRIPTS = {
115
115
  "vize:musea": "vize musea",
116
116
  "vize:ready": "vize ready src"
117
117
  };
118
- const DEFAULT_VIZE_CONFIG = `import { defineConfig } from "vize";
119
-
120
- export default defineConfig({
121
- compiler: {
122
- templateSyntax: "standard",
123
- },
124
- linter: {
125
- preset: "happy-path",
126
- },
127
- typeChecker: {
128
- enabled: true,
129
- strict: true,
130
- jsxTypecheck: true,
131
- },
132
- vite: {
133
- scanPatterns: ["src/**/*.vue"],
134
- },
135
- });
136
- `;
137
118
  const DEFAULT_OXLINT_CONFIG = `import { defineConfig } from "oxlint";
138
119
  import { configs } from "oxlint-plugin-vize";
139
120
 
@@ -246,39 +227,6 @@ const INIT_LINT_PRESET = "happy-path";
246
227
  const INIT_LINT_HELP_LEVEL = "short";
247
228
  /** VS Code extension id published from `editors/vscode`. */
248
229
  const VSCODE_EXTENSION_ID = "ubugeeei.vize";
249
- /**
250
- * Builds `vize.config.ts` from the selected features.
251
- *
252
- * Only selected features contribute a block, so a project that asked for the
253
- * formatter alone does not silently get a type checker it never opted into.
254
- */
255
- function renderVizeConfig(features) {
256
- const blocks = [` compiler: {
257
- templateSyntax: "standard",
258
- },`];
259
- if (features.lint) blocks.push(` linter: {
260
- enabled: true,
261
- preset: "${INIT_LINT_PRESET}",
262
- },`);
263
- if (features.fmt) blocks.push(` formatter: {
264
- singleAttributePerLine: false,
265
- sortBlocks: true,
266
- },`);
267
- if (features.typecheck) blocks.push(` typeChecker: {
268
- enabled: true,
269
- strict: true,
270
- jsxTypecheck: true,
271
- },`);
272
- if (features.vite) blocks.push(` vite: {
273
- scanPatterns: ["src/**/*.vue"],
274
- },`);
275
- return `import { defineConfig } from "vize";
276
-
277
- export default defineConfig({
278
- ${blocks.join("\n")}
279
- });
280
- `;
281
- }
282
230
  /** Minimum project config written only when typechecking is selected and no config exists. */
283
231
  function renderTypecheckTsconfig(typescript, nuxtMajor) {
284
232
  if (nuxtMajor !== void 0) {
@@ -984,8 +932,23 @@ const VITE_CONFIG_FILES$1 = [
984
932
  * command in its corsa-not-found message; if the two ever disagreed, a user
985
933
  * would be told to run `pnpm add` by one half of the toolchain and `npm install`
986
934
  * by the other.
935
+ *
936
+ * A workspace package has no lockfile of its own, so the search continues in
937
+ * the parent directories and the nearest answer wins. It stops at the
938
+ * repository root: a lockfile above the directory that holds `.git` belongs to
939
+ * something else.
987
940
  */
988
941
  function detectPackageManager(root) {
942
+ let directory = path.resolve(root);
943
+ for (;;) {
944
+ const detected = detectPackageManagerIn(directory);
945
+ if (detected !== null) return detected;
946
+ const parent = path.dirname(directory);
947
+ if (parent === directory || fs.existsSync(path.join(directory, ".git"))) return null;
948
+ directory = parent;
949
+ }
950
+ }
951
+ function detectPackageManagerIn(root) {
989
952
  const exists = (name) => fs.existsSync(path.join(root, name));
990
953
  if (exists("pnpm-lock.yaml")) return "pnpm";
991
954
  if (exists("bun.lockb") || exists("bun.lock")) return "bun";
@@ -1359,14 +1322,13 @@ const FEATURE_SCRIPTS = {
1359
1322
  editor: []
1360
1323
  };
1361
1324
  /**
1362
- * Plans `vize.config.ts` and the fmt/typecheck feature results.
1325
+ * Plans the typecheck scaffold and the fmt/typecheck feature results.
1363
1326
  *
1364
- * Only selected features contribute a block, so asking for the formatter alone
1365
- * does not hand the project a type checker it never opted into. An existing Vize
1366
- * config is never rewritten: merging into a user's config is exactly the kind of
1367
- * guess that loses their settings.
1327
+ * CLI tools use project settings and sensible defaults without a dedicated
1328
+ * config. Only typechecking needs a tsconfig scaffold; existing project and Vize
1329
+ * configs keep their exact contents.
1368
1330
  */
1369
- function planVizeConfig(detection, selection, draft) {
1331
+ function planToolSettings(detection, selection, draft) {
1370
1332
  if (selection.typecheck && detection.tsconfig === null) {
1371
1333
  draft.files.push({
1372
1334
  filename: path.join(detection.root, "tsconfig.json"),
@@ -1380,24 +1342,15 @@ function planVizeConfig(detection, selection, draft) {
1380
1342
  continue;
1381
1343
  }
1382
1344
  const scaffoldsTsconfig = id === "typecheck" && detection.tsconfig === null;
1345
+ const addsScripts = FEATURE_SCRIPTS[id].some((name) => !(name in detection.scripts));
1346
+ const detail = scaffoldsTsconfig ? "writes tsconfig.json" : id === "typecheck" ? "uses tsconfig.json and project settings" : "uses project settings and formatter defaults";
1383
1347
  draft.features.push({
1384
1348
  id,
1385
- outcome: scaffoldsTsconfig || detection.vizeConfig === null ? "configured" : "unchanged",
1386
- detail: scaffoldsTsconfig ? detection.vizeConfig === null ? "writes tsconfig.json and vize.config.ts" : `writes tsconfig.json; ${detection.vizeConfig} already exists and was left unchanged` : detection.vizeConfig === null ? "writes vize.config.ts" : `${detection.vizeConfig} already exists and was left unchanged`,
1349
+ outcome: scaffoldsTsconfig || addsScripts ? "configured" : "unchanged",
1350
+ detail: detection.vizeConfig === null ? detail : `${detail}; ${detection.vizeConfig} already exists and was left unchanged`,
1387
1351
  snippet: null
1388
1352
  });
1389
1353
  }
1390
- if (!(selection.lint || selection.fmt || selection.typecheck) || detection.vizeConfig !== null) return;
1391
- draft.files.push({
1392
- filename: path.join(detection.root, "vize.config.ts"),
1393
- source: renderVizeConfig({
1394
- lint: selection.lint,
1395
- fmt: selection.fmt,
1396
- typecheck: selection.typecheck,
1397
- vite: detection.framework === "vite"
1398
- })
1399
- });
1400
- draft.createdFiles.push("vize.config.ts");
1401
1354
  }
1402
1355
  /**
1403
1356
  * Adds the scripts the selected features need.
@@ -1485,7 +1438,7 @@ function planInit(options) {
1485
1438
  });
1486
1439
  draft.updatedFiles.push(filename);
1487
1440
  }
1488
- planVizeConfig(detection, selection, draft);
1441
+ planToolSettings(detection, selection, draft);
1489
1442
  for (const id of ["fmt", "typecheck"]) if (selection[id]) addAll(draft.dependencies, FEATURE_DEPENDENCIES[id]);
1490
1443
  draft.features.push(selection.editor ? planEditorFile(detection, draft.files, draft.createdFiles, draft.updatedFiles) : skipped("editor"));
1491
1444
  const addedScripts = planScripts(detection, selection, draft);
@@ -1957,7 +1910,9 @@ function setupProject(options) {
1957
1910
  const createdFiles = [];
1958
1911
  const preservedFiles = [];
1959
1912
  const plannedFiles = [];
1960
- planGeneratedConfig(root, VIZE_CONFIG_FILES, "vize.config.ts", DEFAULT_VIZE_CONFIG, plannedFiles, createdFiles, preservedFiles);
1913
+ const detection = detectProject(root);
1914
+ for (const filename of VIZE_CONFIG_FILES) if (fs.existsSync(path.join(root, filename))) preservedFiles.push(filename);
1915
+ planGeneratedConfig(root, ["tsconfig.json"], "tsconfig.json", renderTypecheckTsconfig(detection.typescript, detection.framework === "nuxt" ? detection.nuxtMajor : void 0), plannedFiles, createdFiles, preservedFiles);
1961
1916
  const existingOxlintConfig = DISCOVERED_OXLINT_CONFIG_FILES.find((candidate) => fs.existsSync(path.join(root, candidate)));
1962
1917
  const viteMigration = planViteMigration(root, existingOxlintConfig === void 0);
1963
1918
  if (viteMigration.file) plannedFiles.push(viteMigration.file);