dsh-plugin-gate-kit 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsh-plugin-e2e contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,123 @@
1
- # Temporary Holding Version
1
+ # dsh-plugin-gate-kit
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ English | [简体中文](./README.zh-CN.md)
4
+
5
+ Minimum gate bootstrap for a DSH plugin repo: a **cross-OS native-package preflight** (the classic "`node_modules` was installed by another OS" trap) plus `init` to drop a `gate/preflight.mjs` into your repo.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm i -D dsh-plugin-gate-kit
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```bash
16
+ # is this node_modules safe for the current OS?
17
+ npx dsh-plugin-gate-kit preflight
18
+
19
+ # scaffold gate/preflight.mjs into a repo (idempotent)
20
+ npx dsh-plugin-gate-kit init --dir .
21
+
22
+ # preflight + what gate pieces already exist
23
+ npx dsh-plugin-gate-kit check --dir .
24
+ ```
25
+
26
+ ## Usage / API
27
+
28
+ ### CLI
29
+
30
+ | Command | What it does |
31
+ |---|---|
32
+ | `preflight` | Detect native packages belonging to a different OS. **Default** — running with no subcommand does this |
33
+ | `init` | Write `gate/preflight.mjs` (skipped if it already exists) and print wiring suggestions |
34
+ | `check` | Run the preflight **and** report which gate components and `package.json` scripts already exist |
35
+
36
+ ### Options
37
+
38
+ | Option | Default | Meaning |
39
+ |---|---|---|
40
+ | `--dir <dir>` | `.` | Directory whose `node_modules` is inspected (for `init`, where `gate/` is written). Must be a **separate token**: `--dir path`, not `--dir=path` |
41
+ | `--help`, `-h`, `help` | — | Print usage and exit `0` |
42
+
43
+ The subcommand must come **first**. `dsh-plugin-gate-kit --dir .` is rejected as `未知子命令: --dir` (exit `2`).
44
+
45
+ ### Exit codes
46
+
47
+ | Code | Meaning |
48
+ |---|---|
49
+ | `0` | `preflight` clean / `init` succeeded / `check` found no platform problems |
50
+ | `1` | Platform native-package problems found (both `preflight` and `check`) |
51
+ | `2` | Usage error: unknown subcommand |
52
+
53
+ ### Programmatic API
54
+
55
+ ```js
56
+ import { checkNative, assertNativePlatform } from 'dsh-plugin-gate-kit'
57
+
58
+ const problems = checkNative(process.cwd()) // [] = clean
59
+ assertNativePlatform(process.cwd()) // throws when problems exist
60
+ ```
61
+
62
+ | Export | Signature | Returns / does |
63
+ |---|---|---|
64
+ | `checkNative` | `checkNative(dir)` | Array of `{ type, pkg, detail }`; empty array means clean |
65
+ | `assertNativePlatform` | `assertNativePlatform(dir = process.cwd())` | Throws an `Error` listing every problem, with the fix hint |
66
+
67
+ `type` is either `'wrong-os'` (a native package for another platform) or `'missing-current'` (jscpd installed but its current-platform binary is absent).
68
+
69
+ ## What the preflight detects
70
+
71
+ It reads `<dir>/node_modules` (scoped packages included) and matches directory names against:
72
+
73
+ ```text
74
+ (?:@scope/)?<name>-(windows|linux|darwin)-(x64|arm64|ia32)(-|$)
75
+ ```
76
+
77
+ | Rule | Example | Reported as |
78
+ |---|---|---|
79
+ | Native package for a different OS | `jscpd-linux-x64-gnu` on Windows | `wrong-os` |
80
+ | jscpd present but no `jscpd-<currentOS>-*` | `jscpd` installed, no `jscpd-windows-*` | `missing-current` |
81
+
82
+ The failure message tells you the fix: **reinstall with `npm ci` on the current system** — do not edit `package.json` / `package-lock.json`. Sharing one `node_modules` between Windows and WSL is what causes the mismatch, because npm rewrites `optionalDependencies` native packages for whatever platform is installing.
83
+
84
+ A missing `node_modules` is not an error — it returns an empty array.
85
+
86
+ ### `init` output
87
+
88
+ `init` writes `gate/preflight.mjs` and then prints two wiring options:
89
+
90
+ 1. at the top of your dup-gate script: `import { assertNativePlatform } from './preflight.mjs'; assertNativePlatform()`
91
+ 2. or in `package.json`: `scripts: { "preflight": "node gate/preflight.mjs" }`
92
+
93
+ Re-running `init` prints `已存在:… (跳过)` and changes nothing.
94
+
95
+ ### `check` output
96
+
97
+ ```text
98
+ gate check: .
99
+ ✓ preflight: ok
100
+ gate 组件已存在: dup_check.mjs, lint_runner.mjs, format_check.mjs
101
+ package.json 相关 scripts: check, check:fast, lint, format, dup:check
102
+ ```
103
+
104
+ It looks for `gate/dup_check.mjs`, `gate/lint_runner.mjs`, `gate/format_check.mjs`, and any `package.json` script whose name matches `check|dup|lint|format`. This is a **report**, not a gate: missing components are listed, not failed.
105
+
106
+ ## Scope — what this package does *not* do
107
+
108
+ This is deliberately a **minimum** bootstrap. The full four-layer gate (four Git hooks + three ratchets for lint / duplication / formatting) is **out of scope**. `check` only reports which pieces are missing; it does not install or enforce them. Bring your own gate scheme, or use the scaffold as the preflight step inside it.
109
+
110
+ ## Notes
111
+
112
+ - The scaffolded `gate/preflight.mjs` is a **simplified copy**, not the package's implementation. Two real differences:
113
+ - it only implements the `wrong-os` rule (no `missing-current` / jscpd check);
114
+ - `checkNative` there returns an array of **strings**, whereas the package's export returns `{ type, pkg, detail }` objects.
115
+ If you depend on the return shape or on the jscpd rule, call the package's `checkNative` / `assertNativePlatform` instead of the generated file.
116
+ - The generated script's CLI path calls `checkNative()` with **no argument**, so running `node gate/preflight.mjs` inspects the **current working directory**, not the `--dir` you passed to `init`. Run it from the repo root, or pass a directory explicitly when importing it.
117
+ - `--dir` is read positionally; `--dir=value` silently falls back to `.`.
118
+ - `init` never overwrites an existing `gate/preflight.mjs` — delete it first if you want a fresh copy.
119
+ - Requires **Node >= 22.15.0** (repo-wide baseline).
120
+
121
+ ## License
122
+
123
+ MIT
@@ -0,0 +1,123 @@
1
+ # dsh-plugin-gate-kit
2
+
3
+ [English](./README.md) | 简体中文
4
+
5
+ DSH 插件仓库的**最小门禁引导**:跨 OS 原生包 **preflight**(「`node_modules` 被另一个系统装过」这个经典坑)+ `init` 把 `gate/preflight.mjs` 铺进仓库。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ npm i -D dsh-plugin-gate-kit
11
+ ```
12
+
13
+ ## 快速开始
14
+
15
+ ```bash
16
+ # 当前 node_modules 对这套系统安全吗?
17
+ npx dsh-plugin-gate-kit preflight
18
+
19
+ # 往仓库里铺 gate/preflight.mjs(幂等)
20
+ npx dsh-plugin-gate-kit init --dir .
21
+
22
+ # preflight + 看门禁组件现状
23
+ npx dsh-plugin-gate-kit check --dir .
24
+ ```
25
+
26
+ ## 用法 / API
27
+
28
+ ### CLI
29
+
30
+ | 命令 | 作用 |
31
+ |---|---|
32
+ | `preflight` | 检测属于其他 OS 的原生包。**默认子命令**——不带子命令直接跑就是它 |
33
+ | `init` | 写入 `gate/preflight.mjs`(已存在则跳过),并打印接入建议 |
34
+ | `check` | 跑 preflight **并**报告已有哪些门禁组件与 `package.json` scripts |
35
+
36
+ ### 选项
37
+
38
+ | 选项 | 默认值 | 含义 |
39
+ |---|---|---|
40
+ | `--dir <dir>` | `.` | 要检查 `node_modules` 的目录(`init` 时是 `gate/` 写入的位置)。必须是**独立的两个 token**:`--dir path`,不是 `--dir=path` |
41
+ | `--help`、`-h`、`help` | — | 打印用法并退出 `0` |
42
+
43
+ 子命令必须写在**最前面**。`dsh-plugin-gate-kit --dir .` 会被当成 `未知子命令: --dir`(退出 `2`)。
44
+
45
+ ### 退出码
46
+
47
+ | 码 | 含义 |
48
+ |---|---|
49
+ | `0` | `preflight` 干净 / `init` 成功 / `check` 未发现平台包问题 |
50
+ | `1` | 发现平台原生包问题(`preflight` 与 `check` 都是) |
51
+ | `2` | 用法错误:未知子命令 |
52
+
53
+ ### 编程接口
54
+
55
+ ```js
56
+ import { checkNative, assertNativePlatform } from 'dsh-plugin-gate-kit'
57
+
58
+ const problems = checkNative(process.cwd()) // [] 表示干净
59
+ assertNativePlatform(process.cwd()) // 有问题时抛错
60
+ ```
61
+
62
+ | 导出 | 签名 | 返回 / 行为 |
63
+ |---|---|---|
64
+ | `checkNative` | `checkNative(dir)` | `{ type, pkg, detail }` 数组;空数组表示干净 |
65
+ | `assertNativePlatform` | `assertNativePlatform(dir = process.cwd())` | 有问题时抛 `Error`,逐条列出并带修复提示 |
66
+
67
+ `type` 取 `'wrong-os'`(别的平台的原生包)或 `'missing-current'`(装了 jscpd 但缺当前平台的原生包)。
68
+
69
+ ## preflight 检测什么
70
+
71
+ 读 `<dir>/node_modules`(含 scoped 包),用这条正则匹配目录名:
72
+
73
+ ```text
74
+ (?:@scope/)?<name>-(windows|linux|darwin)-(x64|arm64|ia32)(-|$)
75
+ ```
76
+
77
+ | 规则 | 例子 | 记为 |
78
+ |---|---|---|
79
+ | 属于其他 OS 的原生包 | Windows 上有 `jscpd-linux-x64-gnu` | `wrong-os` |
80
+ | 装了 jscpd 但缺 `jscpd-<当前OS>-*` | 有 `jscpd`,没有 `jscpd-windows-*` | `missing-current` |
81
+
82
+ 失败信息会直接给出修复方向:**在当前系统上 `npm ci` 重装**——不要改 `package.json` / `package-lock.json`。Windows 与 WSL 共用同一份 `node_modules` 正是错位来源,因为 npm 会按「谁在装」替换 `optionalDependencies` 里的原生包。
83
+
84
+ 没有 `node_modules` 不算错误——返回空数组。
85
+
86
+ ### `init` 产出什么
87
+
88
+ `init` 写入 `gate/preflight.mjs`,随后打印两种接入方式:
89
+
90
+ 1. 在 dup 门禁脚本开头:`import { assertNativePlatform } from './preflight.mjs'; assertNativePlatform()`
91
+ 2. 或在 `package.json` 里:`scripts: { "preflight": "node gate/preflight.mjs" }`
92
+
93
+ 重复跑 `init` 会打印 `已存在:… (跳过)`,不改任何东西。
94
+
95
+ ### `check` 输出
96
+
97
+ ```text
98
+ gate check: .
99
+ ✓ preflight: ok
100
+ gate 组件已存在: dup_check.mjs, lint_runner.mjs, format_check.mjs
101
+ package.json 相关 scripts: check, check:fast, lint, format, dup:check
102
+ ```
103
+
104
+ 它会找 `gate/dup_check.mjs`、`gate/lint_runner.mjs`、`gate/format_check.mjs`,以及名字匹配 `check|dup|lint|format` 的 `package.json` scripts。这只是一份**报告**,不是门禁:缺组件只列出来,不判失败。
105
+
106
+ ## 范围——本包**不做**什么
107
+
108
+ 本包刻意只做**最小**引导。完整四层门禁(四个 Git 钩子 + lint / 重复代码 / 格式三棘轮)**不在本包范围**。`check` 只报告缺哪些组件,既不安装也不强制。门禁方案请按所在项目自备,或把这个脚手架当作方案里的 preflight 环节。
109
+
110
+ ## 注意事项
111
+
112
+ - `init` 铺出来的 `gate/preflight.mjs` 是一份**简化副本**,不是本包的实现。两处真实差异:
113
+ - 只实现了 `wrong-os` 规则(没有 `missing-current` / jscpd 检查);
114
+ - 那里的 `checkNative` 返回**字符串**数组,而本包导出返回的是 `{ type, pkg, detail }` 对象。
115
+ 如果依赖返回结构或 jscpd 规则,请用本包的 `checkNative` / `assertNativePlatform`,不要用生成出来的文件。
116
+ - 生成脚本的 CLI 分支以**无参**方式调 `checkNative()`,所以 `node gate/preflight.mjs` 检查的是**当前工作目录**,不是你传给 `init` 的 `--dir`。请在仓库根跑,或在 import 时显式传目录。
117
+ - `--dir` 是按位置读的;`--dir=value` 会静默退回 `.`。
118
+ - `init` 永不覆盖已存在的 `gate/preflight.mjs`——想要新副本请先删掉旧文件。
119
+ - 要求 **Node >= 22.15.0**(全仓统一基线)。
120
+
121
+ ## License
122
+
123
+ MIT
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env node
2
+ // dsh-plugin-gate-kit:最小门禁引导(跨 OS 原生包 preflight + `init` 铺 gate/preflight.mjs)。
3
+ // 完整四层门禁(lint/dup/format/husky 棘轮)不在本包;本包只做"跨 OS 安全"这件刚需。
4
+ import { readFileSync, existsSync, mkdirSync, writeFileSync } from 'node:fs'
5
+ import { join } from 'node:path'
6
+ import { fileURLToPath } from 'node:url'
7
+ import { checkNative } from '../src/preflight.mjs'
8
+
9
+ /**
10
+ * `init` 生成的 preflight 直接**读取本包实现源码**,而不是手抄一份副本。
11
+ * 原因:手抄的模板曾漂移——只有 wrong-os、缺 missing-current、返回结构也不同(字符串数组 vs 对象数组),
12
+ * 导致"生成的脚本"和"本包实际行为"不一致。现在生成物 = 实现,永远不会漂移。
13
+ */
14
+ function buildPreflightTemplate() {
15
+ const srcPath = fileURLToPath(new URL('../src/preflight.mjs', import.meta.url))
16
+ const body = readFileSync(srcPath, 'utf8')
17
+ return `// 平台原生包 preflight(由 dsh-plugin-gate-kit init 生成;内容直接来自 dsh-plugin-gate-kit 的实现,不会漂移)。
18
+ ${body}`
19
+ }
20
+
21
+ const args = process.argv.slice(2)
22
+ const sub = args[0] || 'preflight'
23
+ const USAGE = `用法: dsh-plugin-gate-kit <preflight|init|check> [--dir <dir>]
24
+ preflight 检测跨 OS 原生包错位(默认)
25
+ init 写入 gate/preflight.mjs
26
+ check 报告 preflight 与 gate 现状`
27
+ if (args.includes('--help') || args.includes('-h') || sub === 'help') {
28
+ console.log(USAGE)
29
+ process.exit(0)
30
+ }
31
+ const opt = (n, d) => {
32
+ // 同时支持 `--dir X` 和 `--dir=X`:此前只认空格写法,等号写法会静默退回默认值。
33
+ const eq = args.find((a) => a.startsWith('--' + n + '='))
34
+ if (eq !== undefined) return eq.slice(n.length + 3)
35
+ const i = args.indexOf('--' + n)
36
+ return i >= 0 ? args[i + 1] : d
37
+ }
38
+ const dir = opt('dir', '.')
39
+ const readJson = (p) => {
40
+ try {
41
+ return JSON.parse(readFileSync(p, 'utf8'))
42
+ } catch {
43
+ return null
44
+ }
45
+ }
46
+
47
+ if (sub === 'preflight') {
48
+ const problems = checkNative(dir)
49
+ if (!problems.length) {
50
+ console.log('[preflight] ok(' + process.platform + ')')
51
+ process.exit(0)
52
+ }
53
+ console.log('[preflight] 平台原生包不匹配:')
54
+ problems.forEach((p) => console.log(' - ' + p.pkg + ': ' + p.detail))
55
+ console.log('修复:在【当前系统】npm ci 重装;不要改 package.json/lock。')
56
+ process.exit(1)
57
+ } else if (sub === 'init') {
58
+ const gateDir = join(dir, 'gate')
59
+ mkdirSync(gateDir, { recursive: true })
60
+ const target = join(gateDir, 'preflight.mjs')
61
+ if (existsSync(target)) {
62
+ console.log('已存在:' + target + '(跳过)')
63
+ } else {
64
+ writeFileSync(target, buildPreflightTemplate())
65
+ console.log('已写入:' + target)
66
+ }
67
+ console.log('\n接入建议:')
68
+ console.log(
69
+ "1) 在 dup 门禁脚本开头 `import { assertNativePlatform } from './preflight.mjs'; assertNativePlatform()`",
70
+ )
71
+ console.log('2) 或在 package.json 加 scripts: { "preflight": "node gate/preflight.mjs" }')
72
+ process.exit(0)
73
+ } else if (sub === 'check') {
74
+ const problems = checkNative(dir)
75
+ console.log('gate check: ' + dir)
76
+ console.log(
77
+ ' ' +
78
+ (problems.length ? '✗ preflight: ' + problems.length + ' 个平台包问题' : '✓ preflight: ok'),
79
+ )
80
+ const pieces = ['dup_check.mjs', 'lint_runner.mjs', 'format_check.mjs']
81
+ const present = pieces.filter((f) => existsSync(join(dir, 'gate', f)))
82
+ console.log(
83
+ ' gate 组件已存在: ' +
84
+ (present.length
85
+ ? present.join(', ')
86
+ : '(无,可用 dsh-plugin-gate-kit init 起步,或按所在项目的门禁方案铺设全套)'),
87
+ )
88
+ const pkg = readJson(join(dir, 'package.json')) || {}
89
+ const scripts = Object.keys(pkg.scripts || {}).filter((s) => /check|dup|lint|format/.test(s))
90
+ console.log(' package.json 相关 scripts: ' + (scripts.length ? scripts.join(', ') : '(无)'))
91
+ process.exit(problems.length ? 1 : 0)
92
+ } else {
93
+ console.error('未知子命令: ' + sub + '(preflight | init | check)')
94
+ process.exit(2)
95
+ }
package/package.json CHANGED
@@ -1,6 +1,37 @@
1
1
  {
2
2
  "name": "dsh-plugin-gate-kit",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.3",
4
+ "private": false,
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "description": "Minimum gate bootstrap for DSH plugin repos: cross-OS native-package preflight (jscpd etc. platform mismatch) plus `init` to scaffold a gate/ preflight into a repo. Full four-layer gate (four hooks + three ratchets) is out of this package's scope.",
8
+ "bin": {
9
+ "dsh-plugin-gate-kit": "bin/dsh-plugin-gate-kit.mjs"
10
+ },
11
+ "exports": {
12
+ ".": "./src/index.mjs"
13
+ },
14
+ "files": [
15
+ "bin/",
16
+ "src/",
17
+ "README.md",
18
+ "README.zh-CN.md"
19
+ ],
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/metal-huang/dsh-devtools.git",
23
+ "directory": "packages/dsh-plugin-gate-kit"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public",
27
+ "registry": "https://registry.npmjs.org/"
28
+ },
29
+ "engines": {
30
+ "dsh": ">=0.2.2-rc.5",
31
+ "node": ">=22.15.0"
32
+ },
33
+ "dshTestedOn": [
34
+ "0.2.2-rc.5",
35
+ "0.2.3-alpha.2"
36
+ ]
37
+ }
package/src/index.mjs ADDED
@@ -0,0 +1 @@
1
+ export { checkNative, assertNativePlatform } from './preflight.mjs'
@@ -0,0 +1,63 @@
1
+ // 平台原生包 preflight:检测 node_modules 里被"另一个 OS"装过的原生可选包
2
+ // (如 jscpd-windows-* ↔ jscpd-linux-*),避免跨系统共用同一 node_modules 导致的迷之错误。
3
+ import { readdirSync, existsSync } from 'node:fs'
4
+ import { join } from 'node:path'
5
+ import { pathToFileURL } from 'node:url'
6
+
7
+ const OSNAME = { win32: 'windows', darwin: 'darwin', linux: 'linux' }
8
+ const NATIVE_RE = /^(?:@[^/]+\/)?[^/]+-(windows|linux|darwin)-(x64|arm64|ia32)(?:-|$)/
9
+
10
+ function listEntries(nm) {
11
+ const out = []
12
+ for (const name of readdirSync(nm)) {
13
+ if (name.startsWith('@')) {
14
+ try {
15
+ for (const s of readdirSync(join(nm, name))) out.push(name + '/' + s)
16
+ } catch {}
17
+ } else out.push(name)
18
+ }
19
+ return out
20
+ }
21
+
22
+ /** 返回问题数组(空=无问题)。 */
23
+ export function checkNative(dir) {
24
+ const nm = join(dir, 'node_modules')
25
+ if (!existsSync(nm)) return []
26
+ const cur = OSNAME[process.platform] || process.platform
27
+ const names = listEntries(nm)
28
+ const problems = []
29
+ for (const name of names) {
30
+ const base = name.includes('/') ? name.split('/').pop() : name
31
+ const m = NATIVE_RE.exec(base)
32
+ if (m && m[1] !== cur) {
33
+ problems.push({ type: 'wrong-os', pkg: name, detail: `${base} 属于 ${m[1]},当前 OS=${cur}` })
34
+ }
35
+ }
36
+ // jscpd 特例:已安装但缺当前平台原包
37
+ if (names.includes('jscpd') && !names.some((n) => n.startsWith('jscpd-' + cur + '-'))) {
38
+ problems.push({ type: 'missing-current', pkg: 'jscpd', detail: `缺 jscpd-${cur}-*(当前平台原生包缺失)` })
39
+ }
40
+ return problems
41
+ }
42
+
43
+ /** 有问题则抛错;供 gate 脚本调用。 */
44
+ export function assertNativePlatform(dir = process.cwd()) {
45
+ const problems = checkNative(dir)
46
+ if (!problems.length) return
47
+ const msg = problems.map((p) => ` - ${p.pkg}: ${p.detail}`).join('\n')
48
+ throw new Error(`平台原生包不匹配(node_modules 被另一个 OS 装过):\n${msg}\n修复:在【当前系统】npm ci 重装;不要改 package.json。`)
49
+ }
50
+
51
+ // CLI 入口:`node gate/preflight.mjs [dir]`。检查目录取第一个参数,默认当前目录
52
+ // (此前生成的脚本无参调用,总是查 cwd,导致 `init --dir X` 生成后在不同目录跑结果不一致)。
53
+ if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href) {
54
+ const target = process.argv[2] || process.cwd()
55
+ const problems = checkNative(target)
56
+ if (problems.length) {
57
+ console.error('[preflight] 平台原生包不匹配(' + target + '):')
58
+ for (const p of problems) console.error(' - ' + p.pkg + ': ' + p.detail)
59
+ console.error(' 修复:在【当前系统】npm ci 重装;不要改 package.json / package-lock。')
60
+ process.exit(1)
61
+ }
62
+ console.log('[preflight] ok(' + process.platform + ')')
63
+ }