diff --git a/package.json b/package.json index 7d54ba3..b040130 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "build": "rm -rf lib && tsc -p tsconfig.build.json && tsdown", "typecheck": "tsc --noEmit -p tsconfig.json", "test": "vitest run", + "verify:mount": "node scripts/verify-mount.cjs", "lint:ts": "oxlint src tests tsdown.config.ts vitest.config.ts", "dev": "tsdown --watch", "pack:plugin": "pnpm build && pnpm pack --pack-destination dist" diff --git a/scripts/verify-mount.cjs b/scripts/verify-mount.cjs new file mode 100644 index 0000000..9122e05 --- /dev/null +++ b/scripts/verify-mount.cjs @@ -0,0 +1,80 @@ +/** + * 验收验证:模拟 DSH host 的 resolveOverlayPackage + bundle 加载 + * - 确认 apes-sidebar 在 profile node_modules 可解析 + * - 确认 host entry (lib/index.js) 的命名导出 shape { name, inject, apply } + * - 确认 client entry (lib/client.js) 存在且是 __ModuleLoader__ bundle(browser artifact) + * - 确认 invariant surface 可用 + */ +const path = require('path') +const fs = require('fs') +const { createRequire } = require('module') + +const PROFILE = process.env.HOME + '/.dsh/profiles/desktop' +const req = createRequire(path.join(PROFILE, 'noop.js')) + +let pass = 0, fail = 0 +const check = (label, cond, detail = '') => { + if (cond) { pass++; console.log(' ✓', label) } + else { fail++; console.log(' ✗', label, detail) } +} + +console.log('### apes-sidebar 挂载验收') + +// 1. 包可解析 +try { + const pkgPath = req.resolve('apes-sidebar/package.json') + const pkg = req('apes-sidebar/package.json') + check('package.json 可解析', true, pkgPath) + check('name=apes-sidebar', pkg.name === 'apes-sidebar') + check('version=2.0.0', pkg.version === '2.0.0') +} catch (e) { + check('package.json 可解析', false, e.message) +} + +// 2. host entry 加载 + shape +try { + const host = req('apes-sidebar') + check('host entry 加载成功', true) + check('导出 name (string)', typeof host.name === 'string', 'got ' + typeof host.name) + check('导出 inject (string[])', Array.isArray(host.inject), 'got ' + typeof host.inject) + check('inject === [logger]', JSON.stringify(host.inject) === '["logger"]', JSON.stringify(host.inject)) + check('导出 apply (function)', typeof host.apply === 'function') + check('无 default export(namespace 规则)', !('default' in host)) + console.log(' name =', JSON.stringify(host.name)) +} catch (e) { + check('host entry 加载', false, e.message) +} + +// 3. invariant surface +try { + const inv = req('apes-sidebar/invariant') + check('invariant 可加载', true) + check('invariant.assert 是函数', typeof inv.assert === 'function') +} catch (e) { + check('invariant 可加载', false, e.message) +} + +// 4. client entry 存在 + 是 browser artifact +try { + const clientPath = req.resolve('apes-sidebar/client') + const clientSrc = fs.readFileSync(clientPath, 'utf8') + check('client entry 文件存在', true, clientPath) + check('client 是 __ModuleLoader__ bundle(line 1 window)', + clientSrc.split('\n')[0].includes('window.__ModuleLoader__.load'), + 'line1=' + clientSrc.split('\n')[0].slice(0, 50)) +} catch (e) { + check('client entry', false, e.message) +} + +// 5. peer dep dsh-better-sidebar 版本满足 ^0.18.0 +try { + const bs = req('dsh-better-sidebar/package.json') + const v = bs.version + check('dsh-better-sidebar 版本满足 ^0.18.0', + v === '0.18.0', 'got ' + v) +} catch (e) { + check('dsh-better-sidebar 版本', false, e.message) +} + +console.log('\n=== 验收结果: ' + pass + ' passed, ' + fail + ' failed ===') +process.exit(fail > 0 ? 1 : 0)