@mzzsfy/dsh-cron-board 0.4.1 → 0.4.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/package.json +1 -1
- package/src/client.js +3 -0
- package/test/client-id.test.mjs +25 -0
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -355,6 +355,9 @@ if (typeof window !== 'undefined' && window.__ModuleLoader__) {
|
|
|
355
355
|
if (existing) return
|
|
356
356
|
const style = document.createElement('style')
|
|
357
357
|
style.id = 'dsh-cron-board-style'
|
|
358
|
+
// 官方契约:插件自注样式必须自带 data-plugin,否则任意后续插件材质化时
|
|
359
|
+
// claimStyles 会把它归属给该插件,其 HMR 重建即整批误删本插件样式
|
|
360
|
+
style.setAttribute('data-plugin', '@mzzsfy/dsh-cron-board')
|
|
358
361
|
style.textContent = STYLE
|
|
359
362
|
document.head.appendChild(style)
|
|
360
363
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// client.js 注册 id 与样式标记守卫:loader 按 graph row id(完整包名)匹配注册,短名即加载失败;
|
|
2
|
+
// 样式注入缺 data-plugin 会被宿主 claimStyles 误归属给后续材质化插件,其 HMR 重建即整批误删。
|
|
3
|
+
import { readFileSync } from 'node:fs'
|
|
4
|
+
import { dirname, join } from 'node:path'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
|
+
import test from 'node:test'
|
|
7
|
+
import assert from 'node:assert/strict'
|
|
8
|
+
|
|
9
|
+
const PKG_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
|
|
10
|
+
const { name } = JSON.parse(readFileSync(join(PKG_ROOT, 'package.json'), 'utf8'))
|
|
11
|
+
|
|
12
|
+
test('client.js 注册 id 为完整包名', () => {
|
|
13
|
+
const source = readFileSync(join(PKG_ROOT, 'src', 'client.js'), 'utf8')
|
|
14
|
+
const match = source.match(/__ModuleLoader__\.load\(\{\s*id:\s*'([^']+)'/)
|
|
15
|
+
assert.ok(match, 'client.js 缺少 __ModuleLoader__.load 注册')
|
|
16
|
+
assert.equal(match[1], name)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test('client.js 样式注入自带 data-plugin', () => {
|
|
20
|
+
const source = readFileSync(join(PKG_ROOT, 'src', 'client.js'), 'utf8')
|
|
21
|
+
const injections = source.split("createElement('style')").length - 1
|
|
22
|
+
assert.ok(injections > 0, 'client.js 无样式注入点')
|
|
23
|
+
const marked = source.split(`setAttribute('data-plugin', '${name}')`).length - 1
|
|
24
|
+
assert.equal(marked, injections, '每个样式注入点都必须自带 data-plugin(值=注册包名),防宿主 claimStyles 误归属后随他插件 HMR 整批误删')
|
|
25
|
+
})
|