miaoda-game-devkit 0.2.1 → 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.
@@ -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,21 +337,18 @@ 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,
@@ -362,7 +358,8 @@ function defineGameVitestConfig(options) {
362
358
  // devkit 模块需要在配置和审计阶段使用 Node 内置模块。
363
359
  // 如果强制内联,Vite 会把这些模块按浏览器模块转换,
364
360
  // 最终触发 "No such built-in module: node:"。
365
- external: [/miaoda-game-devkit/]
361
+ external: [/miaoda-game-devkit/],
362
+ inline: options.inlineDependencies
366
363
  }
367
364
  },
368
365
  environment: "jsdom",
@@ -417,14 +414,16 @@ describe("defineGameVitestConfig", () => {
417
414
  it("\u63D0\u4F9B Phaser \u8FD0\u884C\u65F6\u6D4B\u8BD5\u9700\u8981\u7684\u56FA\u5B9A\u57FA\u7EBF", () => {
418
415
  const config = defineGameVitestConfig({ projectRoot, gameplayAudit });
419
416
  expect(config.resolve?.alias).toMatchObject({
420
- "@": resolve2(projectRoot, "src"),
421
- phaser: expect.stringContaining("phaser/dist/phaser.js")
417
+ "@": resolve2(projectRoot, "src")
422
418
  });
419
+ expect(config.resolve?.alias).not.toHaveProperty("phaser");
420
+ expect(config.ssr).toMatchObject({ external: ["phaser"] });
423
421
  expect(config.test).toMatchObject({
424
422
  include: ["tests/**/*.test.ts"],
425
423
  server: {
426
424
  deps: {
427
- external: [/miaoda-game-devkit/]
425
+ external: [/miaoda-game-devkit/],
426
+ inline: void 0
428
427
  }
429
428
  },
430
429
  environment: "jsdom",
@@ -454,6 +453,7 @@ describe("defineGameVitestConfig", () => {
454
453
  const config = defineGameVitestConfig({
455
454
  projectRoot,
456
455
  gameplayAudit,
456
+ inlineDependencies: [/phaser4-rex-plugins/],
457
457
  additionalSetupFiles: ["tests/custom-setup.ts"],
458
458
  testTimeout: 5e3,
459
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,21 +357,18 @@ 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,
@@ -382,7 +378,8 @@ function defineGameVitestConfig(options) {
382
378
  // devkit 模块需要在配置和审计阶段使用 Node 内置模块。
383
379
  // 如果强制内联,Vite 会把这些模块按浏览器模块转换,
384
380
  // 最终触发 "No such built-in module: node:"。
385
- external: [/miaoda-game-devkit/]
381
+ external: [/miaoda-game-devkit/],
382
+ inline: options.inlineDependencies
386
383
  }
387
384
  },
388
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,21 +333,18 @@ 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,
@@ -358,7 +354,8 @@ function defineGameVitestConfig(options) {
358
354
  // devkit 模块需要在配置和审计阶段使用 Node 内置模块。
359
355
  // 如果强制内联,Vite 会把这些模块按浏览器模块转换,
360
356
  // 最终触发 "No such built-in module: node:"。
361
- external: [/miaoda-game-devkit/]
357
+ external: [/miaoda-game-devkit/],
358
+ inline: options.inlineDependencies
362
359
  }
363
360
  },
364
361
  environment: "jsdom",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miaoda-game-devkit",
3
- "version": "0.2.1",
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",