dsh-notify-yimit 0.2.1 → 0.2.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.en.md +4 -3
- package/README.md +12 -2
- package/lib/client.js +146 -0
- package/lib/index.js +225 -32
- package/lib/toast-host.ps1 +487 -16
- package/lib/typert.host.js +28 -0
- package/package.json +4 -2
- package/scripts/check-prepublish.mjs +60 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 发布前守卫(prepublishOnly 调用)。
|
|
3
|
+
*
|
|
4
|
+
* 目前只做两件事,都是"发布后才会暴露、且用户端极难自查"的机械检查:
|
|
5
|
+
*
|
|
6
|
+
* 1. host 包不能出现在 dependencies —— 它们必须留在 peerDependencies,
|
|
7
|
+
* 否则 pnpm 会把 @deepseek-ai/* 复制进 profile 的 node_modules,
|
|
8
|
+
* 顶掉宿主自带的同名插件并破坏 settings namespace 注册。
|
|
9
|
+
*
|
|
10
|
+
* 2. lib/toast-host.ps1 必须带 UTF-8 BOM。该文件含大量中文,而宿主是
|
|
11
|
+
* Windows PowerShell 5.1 拉起的:PS 5.1 对**没有 BOM** 的 .ps1 会按系统
|
|
12
|
+
* ANSI 代码页解码,在中文 Windows(936/932/950)下中文会吃掉字符串收尾引号,
|
|
13
|
+
* 导致整段脚本语法错误 → 宿主秒退 → **所有自定义通知都不显示,且没有任何报错**。
|
|
14
|
+
* 只有双字节代码页(DBCS)才会破坏语法,所以英文/UTF-8 ACP 的机器上
|
|
15
|
+
* 完全测不出来 —— 必须在发布前机械拦截。
|
|
16
|
+
*
|
|
17
|
+
* 失败一律以非 0 退出码结束,让 npm publish 中止。
|
|
18
|
+
*/
|
|
19
|
+
import { readFileSync } from 'node:fs'
|
|
20
|
+
import { dirname, join } from 'node:path'
|
|
21
|
+
import { fileURLToPath } from 'node:url'
|
|
22
|
+
|
|
23
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
|
|
24
|
+
const failures = []
|
|
25
|
+
|
|
26
|
+
// ── 1. dependencies 里不允许出现 @deepseek-ai/* ──
|
|
27
|
+
try {
|
|
28
|
+
const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'))
|
|
29
|
+
const bad = Object.keys(pkg.dependencies ?? {}).filter((k) => k.startsWith('@deepseek-ai/'))
|
|
30
|
+
if (bad.length > 0) {
|
|
31
|
+
failures.push(`host 包必须放在 peerDependencies,却出现在 dependencies: ${bad.join(', ')}`)
|
|
32
|
+
}
|
|
33
|
+
} catch (error) {
|
|
34
|
+
failures.push(`读取 package.json 失败: ${String(error)}`)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ── 2. lib/toast-host.ps1 必须带 UTF-8 BOM ──
|
|
38
|
+
const HOST_SCRIPT = 'lib/toast-host.ps1'
|
|
39
|
+
try {
|
|
40
|
+
const bytes = readFileSync(join(root, HOST_SCRIPT))
|
|
41
|
+
if (!(bytes[0] === 0xEF && bytes[1] === 0xBB && bytes[2] === 0xBF)) {
|
|
42
|
+
const head = [...bytes.subarray(0, 3)].map((b) => b.toString(16).toUpperCase().padStart(2, '0')).join(' ')
|
|
43
|
+
failures.push(
|
|
44
|
+
`${HOST_SCRIPT} 缺少 UTF-8 BOM(文件头是 ${head},应为 EF BB BF)。\n` +
|
|
45
|
+
' 中文 Windows 下 PowerShell 5.1 会按 ANSI 解码 → 脚本语法错误 → 宿主秒退,\n' +
|
|
46
|
+
' 用户端表现为"所有自定义通知都不显示且无任何报错"。\n' +
|
|
47
|
+
' 请把该文件另存为「UTF-8 with BOM」后重试。'
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
} catch (error) {
|
|
51
|
+
failures.push(`读取 ${HOST_SCRIPT} 失败: ${String(error)}`)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (failures.length > 0) {
|
|
55
|
+
console.error('\n[dsh-notify-yimit] 发布前检查未通过:\n')
|
|
56
|
+
for (const f of failures) console.error(` ✗ ${f}`)
|
|
57
|
+
console.error('')
|
|
58
|
+
process.exit(1)
|
|
59
|
+
}
|
|
60
|
+
console.log('[dsh-notify-yimit] 发布前检查通过 ✓')
|