@lingfan-engine/stories-build 0.3.0 → 0.3.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/host-plugins.mjs +20 -0
- package/package.json +8 -4
- package/src/host-plugins/virtual-modules.ts +17 -7
package/host-plugins.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@lingfan-engine/stories-build/host-plugins` 的 Node 装载垫片。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要它:本包以 TypeScript 源码出口,而 Node 的类型擦除**拒绝加载
|
|
5
|
+
* node_modules 里的 .ts**(ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING)。这个子路径
|
|
6
|
+
* 的消费方恰好是 **Node 直接加载的构建配置**(`vite.config.ts` 经 `vite.plugins.ts`
|
|
7
|
+
* 引它),而 vite 默认的配置加载器会把依赖外置成真实的 ESM import——于是配置一加载
|
|
8
|
+
* 就崩在 .ts 上。垫片用本包自带依赖 `tsx` 装载真实实现,扫描逻辑仍然只有一份。
|
|
9
|
+
*
|
|
10
|
+
* 类型不走这里:`package.json` 的 `exports` 对该子路径用条件导出,`types` 条件仍指向
|
|
11
|
+
* `./src/host-plugins/index.ts`,TypeScript 侧看到的还是源码声明。
|
|
12
|
+
*/
|
|
13
|
+
import { tsImport } from "tsx/esm/api";
|
|
14
|
+
|
|
15
|
+
const mod = await tsImport("./src/host-plugins/index.ts", import.meta.url);
|
|
16
|
+
|
|
17
|
+
export const STORY_FONTS_MODULE_ID = mod.STORY_FONTS_MODULE_ID;
|
|
18
|
+
export const STORY_LIST_MODULE_ID = mod.STORY_LIST_MODULE_ID;
|
|
19
|
+
export const storyFontsVirtual = mod.storyFontsVirtual;
|
|
20
|
+
export const storyListVirtual = mod.storyListVirtual;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingfan-engine/stories-build",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Stories 创作链编译包:把 Stories.src 的多目录原生 TS 源编译成 Resources/Stories/** + project.json,并产出 cell 注册生成物",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
"./authoring": "./src/authoring.d.ts",
|
|
10
10
|
"./cell": "./src/cell/index.ts",
|
|
11
11
|
"./cli": "./src/cli/cli.ts",
|
|
12
|
-
"./host-plugins":
|
|
12
|
+
"./host-plugins": {
|
|
13
|
+
"types": "./src/host-plugins/index.ts",
|
|
14
|
+
"default": "./host-plugins.mjs"
|
|
15
|
+
},
|
|
13
16
|
"./watch": "./src/pipeline/watch.ts",
|
|
14
17
|
"./watch-cli": "./src/cli/watch-cli.ts"
|
|
15
18
|
},
|
|
@@ -20,12 +23,13 @@
|
|
|
20
23
|
"files": [
|
|
21
24
|
"src",
|
|
22
25
|
"bin",
|
|
26
|
+
"host-plugins.mjs",
|
|
23
27
|
"!src/**/*.test.ts"
|
|
24
28
|
],
|
|
25
29
|
"sideEffects": false,
|
|
26
30
|
"dependencies": {
|
|
27
|
-
"@lingfan-engine/core": "^0.3.
|
|
28
|
-
"@lingfan-engine/editor": "^0.3.
|
|
31
|
+
"@lingfan-engine/core": "^0.3.2",
|
|
32
|
+
"@lingfan-engine/editor": "^0.3.2",
|
|
29
33
|
"esbuild": "^0.28.2",
|
|
30
34
|
"tsx": "^4.23.15",
|
|
31
35
|
"typescript": "~6.0.3"
|
|
@@ -27,20 +27,30 @@ export interface HostPlugin {
|
|
|
27
27
|
readonly name: string;
|
|
28
28
|
readonly resolveId: (id: string) => string | null;
|
|
29
29
|
readonly load: (id: string) => string | null;
|
|
30
|
-
|
|
30
|
+
/** 方法签名而非函数属性:理由同 `DevServerLike`,参数按双变才吃得下各版本 vite */
|
|
31
|
+
configureServer?(server: DevServerLike): void;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* dev server 的最小结构面:只用到「加监听目录、作废模块、整页刷新」三件事。
|
|
36
|
+
*
|
|
37
|
+
* 成员一律写成**方法签名**而不是函数属性。这不是风格问题:`strictFunctionTypes`
|
|
38
|
+
* 只对函数属性做参数逆变检查,方法签名按双变处理。写成属性时 `invalidateModule`
|
|
39
|
+
* 的参数会从 `unknown` 反向要求各版本 vite 的 `ModuleNode` 可赋给 `unknown`
|
|
40
|
+
* 之外的东西——vite 5 的 `(mod: ModuleNode, seen?, timestamp?, isHmr?)` 因此
|
|
41
|
+
* 判不成 `(mod: unknown) => void`,插件对象也就进不了它的 `plugins` 数组。
|
|
42
|
+
* 同一份结构面必须同时兼容 vite 5(小程序壳)与 vite 8(浏览器 / Tauri 壳)。
|
|
43
|
+
*/
|
|
34
44
|
export interface DevServerLike {
|
|
35
45
|
readonly watcher: {
|
|
36
|
-
add
|
|
37
|
-
on
|
|
46
|
+
add(paths: readonly string[]): void;
|
|
47
|
+
on(event: "add" | "unlink", listener: (file: string) => void): void;
|
|
38
48
|
};
|
|
39
49
|
readonly moduleGraph: {
|
|
40
|
-
getModuleById
|
|
41
|
-
invalidateModule
|
|
50
|
+
getModuleById(id: string): unknown;
|
|
51
|
+
invalidateModule(mod: unknown): void;
|
|
42
52
|
};
|
|
43
|
-
readonly ws: { send
|
|
53
|
+
readonly ws: { send(payload: { type: "full-reload" }): void };
|
|
44
54
|
}
|
|
45
55
|
|
|
46
56
|
/** 资源根定位选项 */
|