miaoda-wx-minigame-devkit 0.1.0-beta.2 → 0.1.0-beta.3

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/README.md CHANGED
@@ -5,10 +5,10 @@
5
5
  - `biome.jsonc`:共享 Biome 配置,负责 lint 与 import 排序。代码格式化不在 Biome 职责内,由 `bun fmt`(Prettier 兼容,4 空格缩进)统一负责,避免两套格式化规则冲突。
6
6
  - `tsconfig-base.json`:共享 TypeScript 编译策略(严格模式、bundler 解析、ES2017 目标、noEmit)。
7
7
  - `oxlint.config.js`:通过内置 `no-undef` 检查 `src/` 的运行环境,允许微信小游戏全局,不启用浏览器或 Node 环境。以 `./oxlint` 导出,供调用方的 `oxlint.config.ts` 导入。
8
- - `wxdk` CLI:依次执行 Biome 和 Oxlint;二进制均由 devkit 依赖提供。
8
+ - `devkit-lint` CLI:依次执行类型检查、Biome 和 Oxlint,全部跑完后输出简报;TypeScript 7(原生编译器)与另外两个工具均由 devkit 依赖提供。
9
9
  - `rspack` 子入口:公开小游戏构建 API;扫描、清单合并和分包公共代码处理属于内部实现。
10
10
 
11
- 当前版本为 `0.1.0-beta.1`,发布到 npm 官方源,dist-tag 为 `beta`。
11
+ 当前版本为 `0.1.0-beta.3`,发布到 npm 官方源,dist-tag 为 `beta`。
12
12
 
13
13
  ## lint 使用
14
14
 
@@ -23,10 +23,23 @@
23
23
  然后:
24
24
 
25
25
  ```bash
26
- pnpm --filter wx-minigame-template lint # 实际执行 wxdk lint .
27
- wxdk lint . --fix # 顺带自动修复
26
+ pnpm --filter wx-minigame-template lint # 实际执行 devkit-lint
27
+ devkit-lint src --fix # 只检查 src,并顺带自动修复
28
28
  ```
29
29
 
30
+ 三个阶段都会执行,前面的失败不影响后续。结束后输出简报,退出码 0 表示全部通过,1 表示有阶段失败或命令自身出错:
31
+
32
+ ```text
33
+ --------- LINT SUMMARY ---------
34
+ tsc: FAIL
35
+ biome: OK
36
+ oxlint: OK
37
+ -------------------------------
38
+ RESULT: FAILED — Found errors in: tsc
39
+ ```
40
+
41
+ 类型检查读取当前目录的 `tsconfig.json`;目标路径参数只作用于 Biome 与 Oxlint。
42
+
30
43
  调用方的 `biome.json` 与 `tsconfig.json` 通过 `extends` 继承共享配置;Oxlint 的 JSON 配置只支持相对路径 `extends`,调用方改用 `oxlint.config.ts` 导入 `miaoda-wx-minigame-devkit/oxlint` 导出的配置对象(需 Node ≥ 23 或 22.6+ 的类型剥离支持)。仅运行 lint 不需要安装 Rspack。
31
44
 
32
45
  ## Devkit 构建
@@ -56,7 +69,7 @@ import {
56
69
 
57
70
  `createWxMinigamePlugin()` 是平台插件,用于把小游戏约定接入调用方已有的 Rspack compiler:动态 entry、CommonJS output、runtime/splitChunks、分包公共代码和 `game.json` 产物。它不是完整的 TypeScript 编译 preset。若自行组装 Rspack 配置,必须自行配置 TypeScript 的 builtin SWC loader、es2017 target、压缩和其他编译选项;通常推荐直接使用 `buildWxMinigame`。
58
71
 
59
- `@rspack/core` 为精确版本 `2.3.2` 的 optional peer dependency,devkit 开发依赖使用同一版本,模板也直接声明该版本。构建需要它;仅 lint 不需要安装 Rspack。Rspack 版本固定是因为分包插件依赖 CommonJS entry 产物中的 `C(exports)` / `X(...)` 结构,升级时要重审产物并运行仓库的 `scripts/subpackages.test.ts` VM 链路测试。
72
+ `@rspack/core` 为精确版本 `2.3.6` 的 optional peer dependency,devkit 开发依赖使用同一版本,模板也直接声明该版本。构建需要它;仅 lint 不需要安装 Rspack。Rspack 版本固定是因为分包插件依赖 CommonJS entry 产物中的 `C(exports)` / `X(...)` 结构,升级时要重审产物并运行仓库的 `scripts/subpackages.test.ts` VM 链路测试。
60
73
 
61
74
  ## 发布产物的转换
62
75
 
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+ // devkit-lint — 微信小游戏 devkit 的检查命令。三个阶段依次执行:类型检查、
3
+ // Biome、Oxlint。调用方项目的 tsconfig.json、biome.json 与 oxlint.config.ts
4
+ // 继承 devkit 的共享配置,三个工具也由 devkit 依赖提供。
5
+ //
6
+ // 每个阶段都会跑完(前面的失败不影响后续),最后输出简报。退出码 0 表示
7
+ // 全部通过,1 表示有阶段失败或命令自身出错,调用方(尤其是 Agent)只需看
8
+ // 简报和退出码,不需要再用管道过滤输出。
9
+ import { spawnSync } from 'node:child_process';
10
+ import { existsSync } from 'node:fs';
11
+ import { createRequire } from 'node:module';
12
+ import path from 'node:path';
13
+ import { fileURLToPath } from 'node:url';
14
+
15
+ const pkgRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
16
+ const requireFromDevkit = createRequire(path.join(pkgRoot, 'package.json'));
17
+
18
+ const argv = process.argv.slice(2);
19
+ const fix = argv.includes('--fix');
20
+ const paths = argv.filter((arg) => !arg.startsWith('--'));
21
+ const targets = paths.length > 0 ? paths : ['.'];
22
+ const results = [];
23
+
24
+ // 从 devkit 自己的依赖定位工具入口,workspace 链接与发布后的独立安装都适用。
25
+ // typescript 的 exports 不暴露 bin/tsc,因此统一从 package.json 所在目录拼路径。
26
+ function toolEntry(packageName, relativePath) {
27
+ try {
28
+ const packageDir = path.dirname(requireFromDevkit.resolve(`${packageName}/package.json`));
29
+ return path.join(packageDir, relativePath);
30
+ } catch {
31
+ return undefined;
32
+ }
33
+ }
34
+
35
+ // 每个阶段独立结算:入口缺失、进程启动失败或退出码非零都记为该阶段失败。
36
+ function run(name, entry, args) {
37
+ if (!entry) {
38
+ console.error(`${name} 失败:devkit 依赖中找不到 ${name},请重新安装依赖`);
39
+ results.push({ name, ok: false });
40
+ return;
41
+ }
42
+ const result = spawnSync(process.execPath, [entry, ...args], { stdio: 'inherit' });
43
+ if (result.error) {
44
+ console.error(`${name} 启动失败:${result.error.message}`);
45
+ }
46
+ results.push({ name, ok: !result.error && result.status === 0 });
47
+ }
48
+
49
+ let crashed;
50
+ try {
51
+ // 类型检查读取当前目录的 tsconfig.json,目标路径参数只作用于 Biome 与 Oxlint。
52
+ if (existsSync('tsconfig.json')) {
53
+ run('tsc', toolEntry('typescript', 'bin/tsc'), ['--noEmit']);
54
+ } else {
55
+ console.error('tsc 失败:当前目录缺少 tsconfig.json');
56
+ results.push({ name: 'tsc', ok: false });
57
+ }
58
+ run('biome', toolEntry('@biomejs/biome', 'bin/biome'), [
59
+ 'check',
60
+ ...targets,
61
+ ...(fix ? ['--write'] : []),
62
+ ]);
63
+ run('oxlint', toolEntry('oxlint', 'bin/oxlint'), targets);
64
+ } catch (error) {
65
+ crashed = error instanceof Error ? error.message : String(error);
66
+ console.error(`devkit-lint 执行出错:${crashed}`);
67
+ }
68
+
69
+ const failed = results.filter(({ ok }) => !ok).map(({ name }) => name);
70
+
71
+ console.log('\n--------- LINT SUMMARY ---------');
72
+ for (const { name, ok } of results) {
73
+ console.log(`${name}: ${ok ? 'OK' : 'FAIL'}`);
74
+ }
75
+ console.log('-------------------------------');
76
+ if (failed.length > 0 || crashed) {
77
+ console.log(
78
+ `RESULT: FAILED — Found errors in: ${[...failed, ...(crashed ? ['devkit-lint'] : [])].join(', ')}`,
79
+ );
80
+ process.exitCode = 1;
81
+ } else {
82
+ console.log('RESULT: PASSED — All checks passed.');
83
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "miaoda-wx-minigame-devkit",
3
- "version": "0.1.0-beta.2",
4
- "description": "微信小游戏 devkit:共享配置、wxdk CLI 与 Rspack 构建插件",
3
+ "version": "0.1.0-beta.3",
4
+ "description": "微信小游戏 devkit:共享配置、devkit-lint CLI 与 Rspack 构建插件",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "files": [
@@ -12,7 +12,7 @@
12
12
  "tsconfig-base.json"
13
13
  ],
14
14
  "bin": {
15
- "wxdk": "bin/wxdk.js"
15
+ "devkit-lint": "bin/devkit-lint.js"
16
16
  },
17
17
  "exports": {
18
18
  "./biome": "./biome.jsonc",
@@ -25,13 +25,14 @@
25
25
  },
26
26
  "scripts": {
27
27
  "build": "rslib build",
28
- "lint": "node bin/wxdk.js lint .",
28
+ "lint": "node bin/devkit-lint.js .",
29
29
  "prepare": "pnpm build",
30
30
  "prepublishOnly": "pnpm build"
31
31
  },
32
32
  "dependencies": {
33
33
  "@biomejs/biome": "^2.6.4",
34
- "oxlint": "^1.90.0"
34
+ "oxlint": "^1.90.0",
35
+ "typescript": "7.0.2"
35
36
  },
36
37
  "optionalDependencies": {
37
38
  "@biomejs/cli-linux-x64": "^2.6.4",
package/bin/wxdk.js DELETED
@@ -1,70 +0,0 @@
1
- #!/usr/bin/env node
2
- // wxdk — 微信小游戏 devkit CLI。当前唯一职责是 lint:调用方项目的
3
- // biome.json 与 oxlint.config.ts 继承共享配置;Biome 负责 lint 与 import
4
- // 排序(格式化由仓库根的 bun fmt/Prettier 负责,4 空格缩进),
5
- // Oxlint 负责 src/ 运行环境边界。两者的二进制均由 devkit 提供。
6
- import { spawn } from 'node:child_process';
7
- import { createRequire } from 'node:module';
8
- import path from 'node:path';
9
- import { fileURLToPath } from 'node:url';
10
-
11
- const pkgRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
12
- const requireFromDevkit = createRequire(path.join(pkgRoot, 'package.json'));
13
-
14
- const argv = process.argv.slice(2);
15
- const command = argv[0] ?? 'help';
16
-
17
- try {
18
- if (command === 'lint') {
19
- await lint(argv.slice(1));
20
- } else {
21
- printHelp();
22
- if (command !== 'help') {
23
- process.exitCode = 1;
24
- }
25
- }
26
- } catch (error) {
27
- console.error(error instanceof Error ? error.message : error);
28
- process.exitCode = 1;
29
- }
30
-
31
- async function lint(args) {
32
- const fix = args.includes('--fix');
33
- const paths = args.filter((arg) => !arg.startsWith('--'));
34
- const biomeBin = requireFromDevkit.resolve('@biomejs/biome/bin/biome');
35
-
36
- await run(
37
- biomeBin,
38
- ['check', ...(paths.length > 0 ? paths : ['.']), ...(fix ? ['--write'] : [])],
39
- 'Biome',
40
- );
41
- const oxlintRoot = path.dirname(requireFromDevkit.resolve('oxlint/package.json'));
42
- await run(path.join(oxlintRoot, 'bin/oxlint'), paths.length > 0 ? paths : ['.'], 'Oxlint');
43
- }
44
-
45
- async function run(binary, args, tool) {
46
- const exitCode = await new Promise((resolve, reject) => {
47
- const child = spawn(process.execPath, [binary, ...args], {
48
- stdio: 'inherit',
49
- });
50
- child.on('exit', (code) => {
51
- resolve(code ?? 1);
52
- });
53
- child.on('error', reject);
54
- });
55
-
56
- if (exitCode !== 0) {
57
- throw new Error(`${tool} 检查失败,退出码 ${exitCode}`);
58
- }
59
- }
60
-
61
- function printHelp() {
62
- console.log(`wxdk — 微信小游戏 devkit CLI
63
-
64
- 用法: wxdk <command> [paths...] [flags]
65
-
66
- 命令:
67
- lint 依次执行 Biome 和 Oxlint,默认检查当前目录
68
- --fix 修复 Biome 可自动修复的问题(Oxlint 仍只检查)
69
- `);
70
- }