@deepseek-ai/dsh-lazy-require 0.1.6-alpha.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/LICENSE +21 -0
- package/README.i18n.yaml +6 -0
- package/README.md +88 -0
- package/README.zh.md +88 -0
- package/lib/index.js +24 -0
- package/lib/types/index.d.ts +10 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DeepSeek
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.i18n.yaml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
|
|
2
|
+
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
|
+
# after editing either side, bring the other along and re-record with:
|
|
4
|
+
# pnpm run verify-translation-pairing --write packages/util/lazy-require/README.md
|
|
5
|
+
README.md: d75a7626da61522939f17f6caec1f5d14e6da6c6
|
|
6
|
+
README.zh.md: 7d8e66f15957a990ae37ed04b627dd4a4f147fa0
|
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Caller-relative lazy loading for CommonJS-compatible Host dependencies whose initialization is not needed during application startup."
|
|
3
|
+
kind: "package-library"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# @deepseek-ai/dsh-lazy-require
|
|
7
|
+
|
|
8
|
+
English | [中文](README.zh.md)
|
|
9
|
+
|
|
10
|
+
## Summary
|
|
11
|
+
|
|
12
|
+
`dsh-lazy-require` keeps a CommonJS-compatible Host dependency unloaded until its first real operation. Resolution remains relative to the consuming package, and one successful module value is reused for the rest of the process realm.
|
|
13
|
+
|
|
14
|
+
## Table of Contents
|
|
15
|
+
|
|
16
|
+
- [Use this package](#use-this-package)
|
|
17
|
+
- [Understand the implementation](#understand-the-implementation)
|
|
18
|
+
- [Further Exploration](#further-exploration)
|
|
19
|
+
- [Model Experience](#model-experience)
|
|
20
|
+
- [Known Limitations and Deferred Work](#known-limitations-and-deferred-work)
|
|
21
|
+
- [Dev Note](#dev-note)
|
|
22
|
+
|
|
23
|
+
-----
|
|
24
|
+
|
|
25
|
+
<a id="use-this-package"></a>
|
|
26
|
+
## Use this package
|
|
27
|
+
|
|
28
|
+
Pass the dependency's literal specifier and the caller's `import.meta.url`:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { createLazyRequire } from '@deepseek-ai/dsh-lazy-require'
|
|
32
|
+
|
|
33
|
+
interface NativeModule { open(): void }
|
|
34
|
+
const requireNative = createLazyRequire<NativeModule>('native-package', import.meta.url)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Calling `requireNative()` loads the dependency once. A failed load is not cached.
|
|
38
|
+
|
|
39
|
+
-----
|
|
40
|
+
|
|
41
|
+
<a id="understand-the-implementation"></a>
|
|
42
|
+
## Understand the implementation
|
|
43
|
+
|
|
44
|
+
<details>
|
|
45
|
+
<summary>Implementation internals — click to expand</summary>
|
|
46
|
+
|
|
47
|
+
The utility creates Node's `require` from the supplied caller URL and caches only a successful return value. The explicit caller URL preserves package-local dependency resolution after publication.
|
|
48
|
+
|
|
49
|
+
### Source map
|
|
50
|
+
|
|
51
|
+
| File | Role |
|
|
52
|
+
|---|---|
|
|
53
|
+
| [`src/index.ts`](src/index.ts) | Caller-relative loader and successful-result cache |
|
|
54
|
+
|
|
55
|
+
</details>
|
|
56
|
+
|
|
57
|
+
-----
|
|
58
|
+
|
|
59
|
+
<a id="further-exploration"></a>
|
|
60
|
+
## Further Exploration
|
|
61
|
+
|
|
62
|
+
- [Utility package map](../README.md) — adjacent shared primitives.
|
|
63
|
+
- [NPM release sequences](../../../.agents/notes/implemented/process/2026-08-10-npm-release-sequences.md) — published dependency classification and first-use loading policy.
|
|
64
|
+
|
|
65
|
+
-----
|
|
66
|
+
|
|
67
|
+
<a id="model-experience"></a>
|
|
68
|
+
## Model Experience
|
|
69
|
+
|
|
70
|
+
None, as this Host utility registers no model-facing behavior.
|
|
71
|
+
|
|
72
|
+
#### KV Cache effect
|
|
73
|
+
|
|
74
|
+
None.
|
|
75
|
+
|
|
76
|
+
## Known Limitations and Deferred Work
|
|
77
|
+
|
|
78
|
+
<a id="known-limitations-and-deferred-work"></a>
|
|
79
|
+
|
|
80
|
+
- **CommonJS-compatible dependencies only** — ESM-only packages require an asynchronous factory owned by their caller.
|
|
81
|
+
- **WebWorker packaging needs an explicit request** — the static packer does not discover dependencies named only in `createLazyRequire()` calls. A package used in a Preview image must keep the dependency reachable through a supported literal request until the packer recognizes this helper.
|
|
82
|
+
|
|
83
|
+
No runtime invariant companion is published because the loader holds no independently observable mutable relationship.
|
|
84
|
+
|
|
85
|
+
<a id="dev-note"></a>
|
|
86
|
+
### Dev Note
|
|
87
|
+
|
|
88
|
+
None.
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "按调用方解析并惰性加载 CommonJS 兼容的 Host 依赖,使应用启动时不初始化尚未使用的依赖。"
|
|
3
|
+
kind: "package-library"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# @deepseek-ai/dsh-lazy-require
|
|
7
|
+
|
|
8
|
+
[English](README.md) | 中文
|
|
9
|
+
|
|
10
|
+
## 概述
|
|
11
|
+
|
|
12
|
+
`dsh-lazy-require` 会让 CommonJS 兼容的 Host 依赖保持未加载状态,直到首次实际操作。解析仍以消费方 package 为基准,同一进程 realm 会复用一次成功加载的模块值。
|
|
13
|
+
|
|
14
|
+
## 目录
|
|
15
|
+
|
|
16
|
+
- [使用本包](#use-this-package)
|
|
17
|
+
- [理解实现](#understand-the-implementation)
|
|
18
|
+
- [进一步探索](#further-exploration)
|
|
19
|
+
- [模型体验](#model-experience)
|
|
20
|
+
- [已知限制与延期工作](#known-limitations-and-deferred-work)
|
|
21
|
+
- [开发备注](#dev-note)
|
|
22
|
+
|
|
23
|
+
-----
|
|
24
|
+
|
|
25
|
+
<a id="use-this-package"></a>
|
|
26
|
+
## 使用本包
|
|
27
|
+
|
|
28
|
+
传入依赖的字面量 specifier 与调用方的 `import.meta.url`:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { createLazyRequire } from '@deepseek-ai/dsh-lazy-require'
|
|
32
|
+
|
|
33
|
+
interface NativeModule { open(): void }
|
|
34
|
+
const requireNative = createLazyRequire<NativeModule>('native-package', import.meta.url)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
调用 `requireNative()` 时才加载依赖,并只加载一次。失败的加载不会被缓存。
|
|
38
|
+
|
|
39
|
+
-----
|
|
40
|
+
|
|
41
|
+
<a id="understand-the-implementation"></a>
|
|
42
|
+
## 理解实现
|
|
43
|
+
|
|
44
|
+
<details>
|
|
45
|
+
<summary>实现细节——点击展开</summary>
|
|
46
|
+
|
|
47
|
+
本工具使用传入的调用方 URL 创建 Node `require`,并且只缓存成功返回的值。显式调用方 URL 会在发布后保留 package 局部的依赖解析。
|
|
48
|
+
|
|
49
|
+
### 源码地图
|
|
50
|
+
|
|
51
|
+
| 文件 | 职责 |
|
|
52
|
+
|---|---|
|
|
53
|
+
| [`src/index.ts`](src/index.ts) | 按调用方解析的 loader 与成功结果缓存 |
|
|
54
|
+
|
|
55
|
+
</details>
|
|
56
|
+
|
|
57
|
+
-----
|
|
58
|
+
|
|
59
|
+
<a id="further-exploration"></a>
|
|
60
|
+
## 进一步探索
|
|
61
|
+
|
|
62
|
+
- [工具包地图](../README.zh.md)——相邻的共享原语。
|
|
63
|
+
- [NPM 发布序列](../../../.agents/notes/implemented/process/2026-08-10-npm-release-sequences.zh.md)——发布依赖分类与首次使用加载策略。
|
|
64
|
+
|
|
65
|
+
-----
|
|
66
|
+
|
|
67
|
+
<a id="model-experience"></a>
|
|
68
|
+
## 模型体验
|
|
69
|
+
|
|
70
|
+
无,因为本 Host 工具不注册任何模型可见行为。
|
|
71
|
+
|
|
72
|
+
#### KV Cache 影响
|
|
73
|
+
|
|
74
|
+
无。
|
|
75
|
+
|
|
76
|
+
## 已知限制与延期工作
|
|
77
|
+
|
|
78
|
+
<a id="known-limitations-and-deferred-work"></a>
|
|
79
|
+
|
|
80
|
+
- **仅限兼容 CommonJS 的依赖**——仅 ESM package 需要由调用方拥有异步 factory。
|
|
81
|
+
- **WebWorker 打包需要显式请求**——静态 packer 无法发现仅在 `createLazyRequire()` 调用中命名的依赖。Preview image 使用的 package 必须通过受支持的字面量请求保持该依赖可达,直到 packer 能够识别此 helper。
|
|
82
|
+
|
|
83
|
+
本包不发布运行时 invariant companion,因为 loader 不持有可独立观测的可变关系。
|
|
84
|
+
|
|
85
|
+
<a id="dev-note"></a>
|
|
86
|
+
### 开发备注
|
|
87
|
+
|
|
88
|
+
无。
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
//#region lib/types/index.js
|
|
3
|
+
/** Caller-relative lazy loading for CommonJS-compatible Host dependencies. */
|
|
4
|
+
/**
|
|
5
|
+
* Create a successful-result cache around Node's caller-relative `require`.
|
|
6
|
+
* A failed load is not cached, so a corrected installation can be retried.
|
|
7
|
+
* @param specifier - Literal dependency specifier declared by the caller package.
|
|
8
|
+
* @param parentURL - Caller's `import.meta.url`, which owns package resolution.
|
|
9
|
+
* @returns a zero-argument loader that resolves the dependency on first use.
|
|
10
|
+
*/
|
|
11
|
+
function createLazyRequire(specifier, parentURL) {
|
|
12
|
+
const require = createRequire(parentURL);
|
|
13
|
+
let loaded = false;
|
|
14
|
+
let value;
|
|
15
|
+
return () => {
|
|
16
|
+
if (!loaded) {
|
|
17
|
+
value = require(specifier);
|
|
18
|
+
loaded = true;
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { createLazyRequire };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Caller-relative lazy loading for CommonJS-compatible Host dependencies. */
|
|
2
|
+
/**
|
|
3
|
+
* Create a successful-result cache around Node's caller-relative `require`.
|
|
4
|
+
* A failed load is not cached, so a corrected installation can be retried.
|
|
5
|
+
* @param specifier - Literal dependency specifier declared by the caller package.
|
|
6
|
+
* @param parentURL - Caller's `import.meta.url`, which owns package resolution.
|
|
7
|
+
* @returns a zero-argument loader that resolves the dependency on first use.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createLazyRequire<T>(specifier: string, parentURL: string | URL): () => T;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@deepseek-ai/dsh-lazy-require",
|
|
3
|
+
"description": "Caller-relative, success-cached lazy loading for CommonJS-compatible Host dependencies",
|
|
4
|
+
"version": "0.1.6-alpha.2",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/deepseek-ai/deepseek-harness.git",
|
|
11
|
+
"directory": "packages/util/lazy-require"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "lib/index.js",
|
|
15
|
+
"types": "lib/types/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./lib/types/index.d.ts",
|
|
19
|
+
"default": "./lib/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./src/*": "./src/*",
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"lib/index.js",
|
|
26
|
+
"lib/types/**/*.d.ts"
|
|
27
|
+
],
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@deepseek-ai/cordis": "^4.0.2"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@deepseek-ai/cordis": "^4.0.2"
|
|
34
|
+
}
|
|
35
|
+
}
|