Files
sutong a5f51a029f refactor: 包名改为 @wishesl/dsh-lan-access
与 GitHub 仓库归属 wishedl 对齐(原 @sutong 不是发布身份,npm 发布会 403)。
同时把包名改为单一来源:scripts/build-client.mjs 与 scripts/test-client.mjs
都从 package.json 读取,避免产物 id 与清单漂移。LICENSE 版权主体同步为 wishesl。
顺带修正 src/panel.js 里「Plugins 内页」的过时注释(面板早已是 Settings 顶层入口)。
2026-09-27 04:11:15 +08:00

64 lines
2.2 KiB
JavaScript

/**
* Emit the single browser artifact `client.js` from `src/panel.js` and
* `src/qrcode.js`.
*
* A bundle's client half is served as one self-contained module; it cannot
* import a sibling file or a package dependency at runtime. This script inlines
* both sources into the `window.__ModuleLoader__.load` shell, which is the same
* shape the reference plugins ship.
*
* Run: `node scripts/build-client.mjs`
*/
import { readFileSync, writeFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
const here = dirname(fileURLToPath(import.meta.url))
const root = join(here, '..')
/** The browser module id must equal the package name; read it, never restate it. */
const packageName = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')).name
/** Read a source file and turn its ESM exports into plain declarations. */
function inline(relativePath) {
const source = readFileSync(join(root, relativePath), 'utf8')
return source
.replace(/^import .*$/gm, '')
.replace(/^export (?=(?:function|const|let|class)\b)/gm, '')
.trim()
}
const qrcode = inline('src/qrcode.js')
const panel = inline('src/panel.js')
const artifact = `/**
* ${packageName} — browser half (generated by scripts/build-client.mjs).
*
* Do not edit this file: change src/panel.js or src/qrcode.js and rebuild.
*/
window.__ModuleLoader__.load({
id: ${JSON.stringify(packageName)},
factory: function (require) {
"use strict";
var React = require("react");
// ── inlined src/qrcode.js ────────────────────────────────────────────────
var __qrcode = (function () {
${qrcode.replace(/^/gm, ' ')}
return { encodeQR: encodeQR, MAX_VERSION: MAX_VERSION };
})();
var encodeQR = __qrcode.encodeQR;
// ── inlined src/panel.js ─────────────────────────────────────────────────
${panel.replace(/^/gm, ' ')}
return { inject: inject, apply: apply };
},
});
`
const out = join(root, 'client.js')
writeFileSync(out, artifact)
console.log(`wrote ${out} (${artifact.length} bytes)`)