miaoda-game-devkit 0.2.0 → 0.2.2

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/lint.js CHANGED
@@ -33,8 +33,11 @@ function run(name, packageName, binName, args) {
33
33
  console.error(`[${name}] ${error.message}`);
34
34
  resolveResult({ name, ok: false });
35
35
  });
36
- child.once("exit", (code) => {
37
- resolveResult({ name, ok: code === 0 });
36
+ child.once("close", (code, signal) => {
37
+ if (signal) {
38
+ console.error(`[${name}] terminated by ${signal}`);
39
+ }
40
+ resolveResult({ name, ok: code === 0 && signal === null });
38
41
  });
39
42
  });
40
43
  }
@@ -14,7 +14,9 @@ var vitest_config_default = defineConfig({
14
14
  test: {
15
15
  server: {
16
16
  deps: {
17
- inline: [/miaoda-game-/]
17
+ // 合约文件运行在 Vitest 的 Node worker 中,不能被 Vite
18
+ // 按浏览器模块转换。
19
+ external: [/miaoda-game-devkit/]
18
20
  }
19
21
  },
20
22
  environment: "jsdom",
@@ -3,8 +3,7 @@ import { resolve as resolve2 } from "path";
3
3
  import { describe, expect, it } from "vitest";
4
4
 
5
5
  // src/vitest-config.ts
6
- import { createRequire } from "module";
7
- import { dirname, resolve } from "path";
6
+ import { resolve } from "path";
8
7
  import { defineConfig } from "vitest/config";
9
8
 
10
9
  // src/gameplay-audit.ts
@@ -338,28 +337,29 @@ function defineGameVitestConfig(options) {
338
337
  - ${auditIssues.join("\n- ")}`
339
338
  );
340
339
  }
341
- const projectRequire = createRequire(
342
- resolve(options.projectRoot, "package.json")
343
- );
344
- const phaserPackageRoot = dirname(
345
- projectRequire.resolve("phaser/package.json")
346
- );
347
- const phaserBrowserBuild = resolve(phaserPackageRoot, "dist/phaser.js");
348
340
  return defineConfig({
349
341
  resolve: {
350
342
  alias: {
351
343
  ...options.aliases,
352
- "@": resolve(options.projectRoot, "src"),
353
- phaser: phaserBrowserBuild
344
+ "@": resolve(options.projectRoot, "src")
354
345
  }
355
346
  },
347
+ // devkit 作为 external ESM 加载时,应用测试也必须 externalize Phaser,
348
+ // 否则 Vite alias 与 Node 条件导出会创建两个 Phaser 单例,Scene 无法启动。
349
+ ssr: {
350
+ external: ["phaser"]
351
+ },
356
352
  test: {
357
353
  include: ["tests/**/*.test.ts"],
358
354
  testTimeout: options.testTimeout,
359
355
  hookTimeout: options.hookTimeout,
360
356
  server: {
361
357
  deps: {
362
- inline: [/miaoda-game-/]
358
+ // devkit 模块需要在配置和审计阶段使用 Node 内置模块。
359
+ // 如果强制内联,Vite 会把这些模块按浏览器模块转换,
360
+ // 最终触发 "No such built-in module: node:"。
361
+ external: [/miaoda-game-devkit/],
362
+ inline: options.inlineDependencies
363
363
  }
364
364
  },
365
365
  environment: "jsdom",
@@ -414,11 +414,18 @@ describe("defineGameVitestConfig", () => {
414
414
  it("\u63D0\u4F9B Phaser \u8FD0\u884C\u65F6\u6D4B\u8BD5\u9700\u8981\u7684\u56FA\u5B9A\u57FA\u7EBF", () => {
415
415
  const config = defineGameVitestConfig({ projectRoot, gameplayAudit });
416
416
  expect(config.resolve?.alias).toMatchObject({
417
- "@": resolve2(projectRoot, "src"),
418
- phaser: expect.stringContaining("phaser/dist/phaser.js")
417
+ "@": resolve2(projectRoot, "src")
419
418
  });
419
+ expect(config.resolve?.alias).not.toHaveProperty("phaser");
420
+ expect(config.ssr).toMatchObject({ external: ["phaser"] });
420
421
  expect(config.test).toMatchObject({
421
422
  include: ["tests/**/*.test.ts"],
423
+ server: {
424
+ deps: {
425
+ external: [/miaoda-game-devkit/],
426
+ inline: void 0
427
+ }
428
+ },
422
429
  environment: "jsdom",
423
430
  environmentOptions: { jsdom: { url: "http://localhost/" } },
424
431
  setupFiles: ["miaoda-game-devkit/vitest-setup"],
@@ -446,6 +453,7 @@ describe("defineGameVitestConfig", () => {
446
453
  const config = defineGameVitestConfig({
447
454
  projectRoot,
448
455
  gameplayAudit,
456
+ inlineDependencies: [/phaser4-rex-plugins/],
449
457
  additionalSetupFiles: ["tests/custom-setup.ts"],
450
458
  testTimeout: 5e3,
451
459
  hookTimeout: 2e3
@@ -7,10 +7,12 @@ interface GameVitestConfigOptions {
7
7
  projectRoot: string;
8
8
  /** 测试前后都必须审计的生产 Scene 和玩法契约清单。 */
9
9
  gameplayAudit: GameplayAuditOptions;
10
- /** 项目需要的额外路径别名;`@` 和 `phaser` 由 devkit 统一维护。 */
10
+ /** 项目需要的额外路径别名;`@` 由 devkit 统一维护。 */
11
11
  aliases?: Record<string, string>;
12
12
  /** 在 devkit 基础 setup 之后执行的项目级 setup 文件。 */
13
13
  additionalSetupFiles?: string[];
14
+ /** 需要由 Vite 转换的项目依赖,例如包含无扩展名 import 的插件。 */
15
+ inlineDependencies?: RegExp[];
14
16
  /** 单个游戏运行时测试的超时时间。 */
15
17
  testTimeout?: number;
16
18
  /** 单个游戏测试钩子的超时时间。 */
@@ -7,10 +7,12 @@ interface GameVitestConfigOptions {
7
7
  projectRoot: string;
8
8
  /** 测试前后都必须审计的生产 Scene 和玩法契约清单。 */
9
9
  gameplayAudit: GameplayAuditOptions;
10
- /** 项目需要的额外路径别名;`@` 和 `phaser` 由 devkit 统一维护。 */
10
+ /** 项目需要的额外路径别名;`@` 由 devkit 统一维护。 */
11
11
  aliases?: Record<string, string>;
12
12
  /** 在 devkit 基础 setup 之后执行的项目级 setup 文件。 */
13
13
  additionalSetupFiles?: string[];
14
+ /** 需要由 Vite 转换的项目依赖,例如包含无扩展名 import 的插件。 */
15
+ inlineDependencies?: RegExp[];
14
16
  /** 单个游戏运行时测试的超时时间。 */
15
17
  testTimeout?: number;
16
18
  /** 单个游戏测试钩子的超时时间。 */
@@ -23,7 +23,6 @@ __export(vitest_config_exports, {
23
23
  defineGameVitestConfig: () => defineGameVitestConfig
24
24
  });
25
25
  module.exports = __toCommonJS(vitest_config_exports);
26
- var import_node_module = require("module");
27
26
  var import_node_path2 = require("path");
28
27
  var import_config = require("vitest/config");
29
28
 
@@ -358,28 +357,29 @@ function defineGameVitestConfig(options) {
358
357
  - ${auditIssues.join("\n- ")}`
359
358
  );
360
359
  }
361
- const projectRequire = (0, import_node_module.createRequire)(
362
- (0, import_node_path2.resolve)(options.projectRoot, "package.json")
363
- );
364
- const phaserPackageRoot = (0, import_node_path2.dirname)(
365
- projectRequire.resolve("phaser/package.json")
366
- );
367
- const phaserBrowserBuild = (0, import_node_path2.resolve)(phaserPackageRoot, "dist/phaser.js");
368
360
  return (0, import_config.defineConfig)({
369
361
  resolve: {
370
362
  alias: {
371
363
  ...options.aliases,
372
- "@": (0, import_node_path2.resolve)(options.projectRoot, "src"),
373
- phaser: phaserBrowserBuild
364
+ "@": (0, import_node_path2.resolve)(options.projectRoot, "src")
374
365
  }
375
366
  },
367
+ // devkit 作为 external ESM 加载时,应用测试也必须 externalize Phaser,
368
+ // 否则 Vite alias 与 Node 条件导出会创建两个 Phaser 单例,Scene 无法启动。
369
+ ssr: {
370
+ external: ["phaser"]
371
+ },
376
372
  test: {
377
373
  include: ["tests/**/*.test.ts"],
378
374
  testTimeout: options.testTimeout,
379
375
  hookTimeout: options.hookTimeout,
380
376
  server: {
381
377
  deps: {
382
- inline: [/miaoda-game-/]
378
+ // devkit 模块需要在配置和审计阶段使用 Node 内置模块。
379
+ // 如果强制内联,Vite 会把这些模块按浏览器模块转换,
380
+ // 最终触发 "No such built-in module: node:"。
381
+ external: [/miaoda-game-devkit/],
382
+ inline: options.inlineDependencies
383
383
  }
384
384
  },
385
385
  environment: "jsdom",
@@ -1,6 +1,5 @@
1
1
  // src/vitest-config.ts
2
- import { createRequire } from "module";
3
- import { dirname, resolve } from "path";
2
+ import { resolve } from "path";
4
3
  import { defineConfig } from "vitest/config";
5
4
 
6
5
  // src/gameplay-audit.ts
@@ -334,28 +333,29 @@ function defineGameVitestConfig(options) {
334
333
  - ${auditIssues.join("\n- ")}`
335
334
  );
336
335
  }
337
- const projectRequire = createRequire(
338
- resolve(options.projectRoot, "package.json")
339
- );
340
- const phaserPackageRoot = dirname(
341
- projectRequire.resolve("phaser/package.json")
342
- );
343
- const phaserBrowserBuild = resolve(phaserPackageRoot, "dist/phaser.js");
344
336
  return defineConfig({
345
337
  resolve: {
346
338
  alias: {
347
339
  ...options.aliases,
348
- "@": resolve(options.projectRoot, "src"),
349
- phaser: phaserBrowserBuild
340
+ "@": resolve(options.projectRoot, "src")
350
341
  }
351
342
  },
343
+ // devkit 作为 external ESM 加载时,应用测试也必须 externalize Phaser,
344
+ // 否则 Vite alias 与 Node 条件导出会创建两个 Phaser 单例,Scene 无法启动。
345
+ ssr: {
346
+ external: ["phaser"]
347
+ },
352
348
  test: {
353
349
  include: ["tests/**/*.test.ts"],
354
350
  testTimeout: options.testTimeout,
355
351
  hookTimeout: options.hookTimeout,
356
352
  server: {
357
353
  deps: {
358
- inline: [/miaoda-game-/]
354
+ // devkit 模块需要在配置和审计阶段使用 Node 内置模块。
355
+ // 如果强制内联,Vite 会把这些模块按浏览器模块转换,
356
+ // 最终触发 "No such built-in module: node:"。
357
+ external: [/miaoda-game-devkit/],
358
+ inline: options.inlineDependencies
359
359
  }
360
360
  },
361
361
  environment: "jsdom",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miaoda-game-devkit",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Shared lint and deterministic Phaser HEADLESS testing tools for Miaoda games",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",