@wolfstar/create-http-framework 2.8.1 → 2.9.0-next-20261006173153

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/index.js CHANGED
@@ -220,6 +220,10 @@ function runCommand(command, args, dir) {
220
220
  //#endregion
221
221
  //#region src/tools/projectFiles.ts
222
222
  const caret = (version) => `^${version}`;
223
+ /** The compatibility version a generated project runs on: the default of `@wolfstar/schema`'s current latest version. */
224
+ const GENERATED_COMPATIBILITY_VERSION = 6;
225
+ /** From this version on `stars prepare` splits `.stars/tsconfig.json` into an app and a node config (`SPLIT_TSCONFIG_VERSION`). */
226
+ const SPLIT_TSCONFIG_VERSION = 6;
223
227
  const FRAMEWORK_LINT_PLUGIN = "@wolfstar/eslint-plugin-http-framework";
224
228
  /** The rules of {@link FRAMEWORK_LINT_PLUGIN}, listed for oxlint, whose JSON configuration cannot import them. */
225
229
  const FRAMEWORK_LINT_RULES = [
@@ -247,6 +251,7 @@ function buildScripts(ctx) {
247
251
  dev: "stars dev",
248
252
  ...ctx.language === "ts" && (ctx.buildTool === "tsdown" || isViteBuild(ctx.buildTool)) ? { postinstall: "stars prepare" } : {},
249
253
  ...ctx.language === "js" ? {} : { build: "stars build" },
254
+ ...splitsTsconfig(ctx) ? { typecheck: "stars typecheck" } : {},
250
255
  start: `node ${entryFile(ctx)}`
251
256
  };
252
257
  if (ctx.linter === "oxlint") {
@@ -350,34 +355,73 @@ const sharedCompilerOptions = {
350
355
  experimentalDecorators: true,
351
356
  emitDecoratorMetadata: true
352
357
  };
353
- /** Writes the tsconfig(s). The tsc branches use a composite build so `tsc -b src` resolves `src/tsconfig.json`. */
354
- function writeTsconfig(targetDir, ctx) {
355
- if (ctx.language === "js") return;
356
- if (isViteBuild(ctx.buildTool)) {
357
- writeFile(join(targetDir, "tsconfig.json"), json({
358
- extends: "./.stars/tsconfig.json",
359
- compilerOptions: { types: ["node"] },
360
- include: ["src/**/*.ts", ".stars/*.d.ts"],
361
- exclude: [
362
- "node_modules",
363
- "dist",
364
- ".output"
365
- ]
366
- }));
367
- return;
368
- }
369
- if (ctx.buildTool === "tsdown") {
370
- writeFile(join(targetDir, "tsconfig.json"), json({
371
- extends: "./.stars/tsconfig.json",
372
- compilerOptions: {
373
- outDir: "./dist",
374
- rootDir: "./src"
375
- },
376
- include: ["src/**/*.ts", ".stars/*.d.ts"],
377
- exclude: ["node_modules", "dist"]
378
- }));
358
+ /** Whether the root `tsconfig.json` is the solution-style one that references `.stars/tsconfig.{app,node}.json`. */
359
+ function splitsTsconfig(ctx) {
360
+ return ctx.language === "ts" && (ctx.buildTool === "tsdown" || isViteBuild(ctx.buildTool)) && (ctx.compatibilityVersion ?? 6) >= 6;
361
+ }
362
+ /** The root `tsconfig.json` of compatibility versions 5 and below: it extends the single generated config. */
363
+ function legacyTsconfig(ctx) {
364
+ if (isViteBuild(ctx.buildTool)) return {
365
+ extends: "./.stars/tsconfig.json",
366
+ compilerOptions: { types: ["node"] },
367
+ include: ["src/**/*.ts", ".stars/*.d.ts"],
368
+ exclude: [
369
+ "node_modules",
370
+ "dist",
371
+ ".output"
372
+ ]
373
+ };
374
+ return {
375
+ extends: "./.stars/tsconfig.json",
376
+ compilerOptions: {
377
+ outDir: "./dist",
378
+ rootDir: "./src"
379
+ },
380
+ include: ["src/**/*.ts", ".stars/*.d.ts"],
381
+ exclude: ["node_modules", "dist"]
382
+ };
383
+ }
384
+ /** The solution-style root `tsconfig.json`, the way a Nuxt 4 project has it: only the generated projects are checked. */
385
+ const solutionTsconfig = {
386
+ files: [],
387
+ references: [{ path: "./.stars/tsconfig.app.json" }, { path: "./.stars/tsconfig.node.json" }]
388
+ };
389
+ const parseJson = (content) => {
390
+ try {
391
+ return JSON.parse(content);
392
+ } catch {
379
393
  return;
380
394
  }
395
+ };
396
+ /**
397
+ * Writes the root `tsconfig.json` of a `tsdown` or Vite project. An existing one is only replaced when it is what the
398
+ * generator wrote before (this version's, or the `extends` one of compatibility version 5 and below): `tsconfig.json`
399
+ * is where a project keeps its own options. Compared as JSON, since the formatter run after generation rewrites the
400
+ * whitespace.
401
+ *
402
+ * @returns Whether an existing, hand-edited file was kept.
403
+ */
404
+ function writeBundlerTsconfig(targetDir, ctx) {
405
+ const path = join(targetDir, "tsconfig.json");
406
+ const next = splitsTsconfig(ctx) ? solutionTsconfig : legacyTsconfig(ctx);
407
+ const existing = existsSync(path) ? parseJson(readFileSync(path, "utf-8")) : null;
408
+ const generated = [
409
+ next,
410
+ legacyTsconfig(ctx),
411
+ solutionTsconfig
412
+ ].map((candidate) => JSON.stringify(candidate));
413
+ if (existing !== null && !generated.includes(JSON.stringify(existing))) return true;
414
+ writeFile(path, json(next));
415
+ return false;
416
+ }
417
+ /**
418
+ * Writes the tsconfig(s). The tsc branches use a composite build so `tsc -b src` resolves `src/tsconfig.json`.
419
+ *
420
+ * @returns The files kept because they were hand-edited.
421
+ */
422
+ function writeTsconfig(targetDir, ctx) {
423
+ if (ctx.language === "js") return [];
424
+ if (isViteBuild(ctx.buildTool) || ctx.buildTool === "tsdown") return writeBundlerTsconfig(targetDir, ctx) ? ["tsconfig.json"] : [];
381
425
  writeFile(join(targetDir, "tsconfig.json"), json({
382
426
  files: [],
383
427
  references: [{ path: "./src" }]
@@ -392,6 +436,7 @@ function writeTsconfig(targetDir, ctx) {
392
436
  },
393
437
  include: ["**/*.ts"]
394
438
  }));
439
+ return [];
395
440
  }
396
441
  /**
397
442
  * Writes the `stars.config.*` file read by the `stars` CLI (`dev`, `build`, `info`, `codegen` scripts). Conventional
@@ -473,12 +518,14 @@ function writeFormatterConfig(targetDir, ctx) {
473
518
  }));
474
519
  }
475
520
  /** Generates every config-style file in code so the output is always valid, formatted JSON/TS. */
521
+ /** @returns The generated files that were kept because the project hand-edited them. */
476
522
  function writeProjectFiles(targetDir, ctx) {
477
523
  writeFile(join(targetDir, "package.json"), packageJson(ctx));
478
- writeTsconfig(targetDir, ctx);
524
+ const kept = writeTsconfig(targetDir, ctx);
479
525
  writeStarsConfig(targetDir, ctx);
480
526
  writeLinterConfig(targetDir, ctx);
481
527
  writeFormatterConfig(targetDir, ctx);
528
+ return kept;
482
529
  }
483
530
 
484
531
  //#endregion
@@ -550,6 +597,7 @@ function toRenderContext(context) {
550
597
  nitro: typescript && isNitroBuild(context.buildTool),
551
598
  autoImports: typescript && context.buildTool === "tsdown",
552
599
  registersEnv: Boolean(context.autoEnv) && typescript && (context.buildTool === "tsdown" || context.buildTool === "vite"),
600
+ typecheckScript: typescript && (context.buildTool === "tsdown" || isViteBuild(context.buildTool)) && (context.compatibilityVersion ?? 5) >= 6,
553
601
  commands
554
602
  };
555
603
  }
@@ -1223,9 +1271,10 @@ async function main() {
1223
1271
  sharder: wantsSharder,
1224
1272
  buildTool,
1225
1273
  tunnel: wantsTunnel,
1226
- autoEnv: true
1274
+ autoEnv: true,
1275
+ compatibilityVersion: 6
1227
1276
  }, (path) => keptDocs.push(path));
1228
- writeProjectFiles(targetDir, {
1277
+ const keptProjectFiles = writeProjectFiles(targetDir, {
1229
1278
  name: projectName,
1230
1279
  port,
1231
1280
  i18n: wantsI18n,
@@ -1237,6 +1286,7 @@ async function main() {
1237
1286
  redis: wantsRedis,
1238
1287
  sharder: wantsSharder,
1239
1288
  tunnel: wantsTunnel,
1289
+ compatibilityVersion: 6,
1240
1290
  packageManager,
1241
1291
  language,
1242
1292
  buildTool,
@@ -1246,6 +1296,7 @@ async function main() {
1246
1296
  });
1247
1297
  s.stop("Project files generated.");
1248
1298
  for (const file of keptDocs) log.warn(`Kept your existing "${file}" as it is — delete it and run again to get the generated one.`);
1299
+ for (const file of keptProjectFiles) log.warn(`Kept your edited "${file}" as it is. If it extends ./.stars/tsconfig.json, that file is gone: \`stars prepare\` now writes ./.stars/tsconfig.app.json and ./.stars/tsconfig.node.json, so make it reference them.`);
1249
1300
  for (const file of preservedFiles) log.warn(`Kept hand-edited "${file}" even though its feature is now disabled — remove it manually if it's no longer needed.`);
1250
1301
  if (wantsI18n) try {
1251
1302
  s.start("Generating i18n types...");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wolfstar/create-http-framework",
3
- "version": "2.8.1",
3
+ "version": "2.9.0-next-20261006173153",
4
4
  "description": "Create a new WolfStar HTTP Framework bot project",
5
5
  "keywords": [
6
6
  "cli",
@@ -11,6 +11,9 @@ HTTP{{#if gateway}} and gateway events over a WebSocket (`@wolfstar/plugin-gatew
11
11
  {{#if typescript}}
12
12
  - `npm run build` — build once (`stars build`).
13
13
  {{/if}}
14
+ {{#if typecheckScript}}
15
+ - `npm run typecheck` — type-check the bot and the files Node runs (`stars typecheck`). A bare `tsc` on the root `tsconfig.json` checks nothing: it only references `.stars/`.
16
+ {{/if}}
14
17
  - `npm start` — run the built bot.
15
18
  - `npx stars doctor` — check the runtime, the credentials and the generated files. Run it first when something is off.
16
19
  - `npx stars info --json` — the resolved configuration.
@@ -44,6 +44,9 @@ The `dev` and `build` scripts are powered by the [`stars`](https://www.npmjs.com
44
44
 
45
45
  - `npm run dev` — build, run and restart the bot on changes, with an interactive terminal dashboard: status, log channels and levels you can filter, and a prompt before changed commands are redeployed (`npm run dev -- --no-tui` for plain logs).
46
46
  - `npm run build` — {{#if nitro}}build the deployable `.output/` directory{{else}}compile the project{{/if}} (TypeScript projects only).
47
+ {{#if typecheckScript}}
48
+ - `npm run typecheck` — type-check the bot and the files Node runs.
49
+ {{/if}}
47
50
  - `npm start` — run the bot.
48
51
  - `npx stars info` — print the resolved configuration.
49
52
  - `npx stars doctor` — check the runtime, the credentials, the interactions endpoint and the generated files.