@jayyuen66/dsh-plugin-shared 0.1.8 → 0.1.9
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{asRecord as e,closeQuietly as t,packageNameOf as n,readManifest as r,singleEntryChunk as i}from"./build-artifacts.js";import{t as a}from"./canonicalize-region-paths-BxladpX3.js";import{readFile as o}from"node:fs/promises";import s from"node:path";const c=[`react`,`react/jsx-runtime`,`react-dom`,`react-dom/client`];function l(e){let t=e.replaceAll(
|
|
1
|
+
import{asRecord as e,closeQuietly as t,packageNameOf as n,readManifest as r,singleEntryChunk as i}from"./build-artifacts.js";import{t as a}from"./canonicalize-region-paths-BxladpX3.js";import{readFile as o}from"node:fs/promises";import s from"node:path";const c=[`react`,`react/jsx-runtime`,`react-dom`,`react-dom/client`];function l(e){let t=e.replaceAll(/^\/\/(?:#region .*| .*)$/gmu,e=>e.replaceAll(`\\`,`/`).replace(/^\/\/(?:#region | )?(?:(?:\.\.?\/)+)?node_modules\/\.pnpm\/[^/]+\/node_modules\//u,e=>e.startsWith(`//#region`)?`//#region node_modules/`:`// node_modules/`)),n=/node_modules\/\.pnpm\//u.exec(t);if(n!==null){let e=Math.max(0,n.index-40);throw Error(`产物里仍有 pnpm store 路径未折叠(出现在 …${JSON.stringify(t.slice(e,e+100))}…)。折叠判据与 rolldown 写下的形式不再匹配,client 产物的字节会随安装布局变化。`)}return t}async function u(e){return o(e,`utf8`)}function d(e){let t=e.name;if(typeof t!=`string`||t===``)throw Error(`package.json 的 name 缺失或非字符串。client 产物的 id 必须等于 dsh client 模块表的键(bundle 包名)。`);if(!/^(?:@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/u.test(t))throw Error(`package.json 的 name ${JSON.stringify(t)} 不符合 npm 包名字符集。`);return t}function f(e){let t=new Set(e);return e=>{if(t.has(e))return!0;let r=n(e);if(r===`react`||r===`react-dom`)throw Error(`${e} 是 react 家族说明符但不在外置清单里。外置会得到宿主模块表里没有的键(加载期报错),内联会得到第二份 React(hooks 静默失效);真要引入子路径,先把它加进外置清单并确认宿主模块表里有同名项。`);return!1}}async function p(n){let o=d(e(await r(n.root))),p=n.entry??s.join(`src`,`client-entry.ts`),m=n.minify??!1,h=n.comments??!m,g={format:`cjs`,...m?{minify:!0}:{},...h?{}:{comments:!1}},_=await n.rolldown({input:s.join(n.root,p),external:f(n.externals??c),platform:`browser`,cwd:n.root,resolve:{extensions:[`.tsx`,`.ts`,`.jsx`,`.js`,`.mjs`,`.json`]}}),v;try{let{output:e}=await _.generate(g),t=i(e,p);v=l(a(t.code.trimEnd(),n.root,process.cwd()))}catch(e){throw await t(_),e}return await _.close(),await n.verifyName?.({pkgName:o,body:v,readSource:e=>u(s.join(n.root,e))}),[n.header,`window.__ModuleLoader__.load({`,` id: ${JSON.stringify(o)},`,` factory: (require) => {`,` 'use strict';`,` const module = { exports: {} };`,` let exports = module.exports;`,v,` return module.exports;`,` },`,`});`,``].join(`
|
|
2
2
|
`)}export{c as REACT_RUNTIME_MODULES,p as buildClientBundle,f as clientExternalPredicate,l as collapseStorePaths};
|
|
@@ -6,21 +6,27 @@ import type { RolldownFactory } from "./build-artifacts.js";
|
|
|
6
6
|
*/
|
|
7
7
|
export declare const REACT_RUNTIME_MODULES: readonly string[];
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* 把注释行里的 pnpm 内容寻址段(store 目录里带「名@版_哈希」的那一层)折成普通的
|
|
10
|
+
* `node_modules/` 一层。
|
|
11
11
|
*
|
|
12
12
|
* 为什么 client 侧需要而 host 侧不需要:host 把依赖全外部化,产物里没有依赖的模块标记;
|
|
13
13
|
* client 必须把共享库的模块**内联**(浏览器解析不了裸说明符),于是 rolldown 写下的标记里
|
|
14
14
|
* 烙着依赖版本与本机 store 哈希。带着它发布,同一份源码在不同机器上产出不同字节(跨机器
|
|
15
15
|
* 不可复现),还把安装布局公开进公共 tarball。
|
|
16
16
|
*
|
|
17
|
+
* 两种注释形态都要折:workspace 软链安装下共享库模块标成 `//#region` 行;从 registry 安装时
|
|
18
|
+
* (消费仓 CI 的 frozen 安装正是这个形状)同一批模块标成 `// node_modules/…` 横幅,路径里带
|
|
19
|
+
* `.pnpm/<名>@<版>_<peer 后缀>` 那一层。只折前者时,后者的 store 段原样留在产物里,下面的
|
|
20
|
+
* 兜底判据把整次构建判红——0.1.8 就是在这个形状上红的,而伞内软链安装碰不到 `.pnpm`,
|
|
21
|
+
* 所以本地检查与发布前的全量门都看不见它。
|
|
22
|
+
*
|
|
17
23
|
* 折叠必须覆盖整段而不是只换中段:store 段之上还可能带着 `../` 前缀(依赖落在工作区根
|
|
18
24
|
* 一侧时就是这样),只换中段会留下 `../../node_modules/<包名>/…`,产物字节仍然随检出
|
|
19
|
-
*
|
|
25
|
+
* 深度变,等于没折。所以判据锚在行首、允许任意个相对段。
|
|
20
26
|
*
|
|
21
27
|
* 反斜杠先归一:Windows 上 rolldown 可能写 `\`,而这行是注释、整行只有路径,归一不会
|
|
22
28
|
* 误伤代码。折叠完再验一遍「整份产物里不剩 `.pnpm` 段」——静默未命中是这条折法最坏的
|
|
23
|
-
*
|
|
29
|
+
* 失效形态:判据锚在注释行的形状上,而 rolldown 一旦改写成别的行形态,折叠会一处都
|
|
24
30
|
* 不命中,兜底若也跟着只用同一套形状假设,就会一起静默失明。`node_modules/.pnpm/`
|
|
25
31
|
* 这个子串与行形态无关。
|
|
26
32
|
* @param code - chunk 正文
|