@serveryyswys/opm 0.0.0-stage → 0.1.0
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 +674 -0
- package/NOTICE +15 -0
- package/README.md +128 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +202 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +32 -0
- package/dist/lib/build.d.ts +25 -0
- package/dist/lib/build.js +319 -0
- package/dist/lib/contract.d.ts +23 -0
- package/dist/lib/contract.js +60 -0
- package/dist/lib/dependencies.d.ts +24 -0
- package/dist/lib/dependencies.js +105 -0
- package/dist/lib/init.d.ts +19 -0
- package/dist/lib/init.js +188 -0
- package/dist/lib/js-requires.d.ts +17 -0
- package/dist/lib/js-requires.js +115 -0
- package/dist/lib/rewrite.d.ts +24 -0
- package/dist/lib/rewrite.js +197 -0
- package/dist/lib/typescript.d.ts +23 -0
- package/dist/lib/typescript.js +166 -0
- package/dist/lib/verify.d.ts +33 -0
- package/dist/lib/verify.js +160 -0
- package/dist/lib/version.d.ts +6 -0
- package/dist/lib/version.js +55 -0
- package/dist/lib/zip.d.ts +18 -0
- package/dist/lib/zip.js +143 -0
- package/package.json +38 -4
package/NOTICE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
@serveryyswys/opm
|
|
2
|
+
Copyright 2026 serveryyswys
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU General Public License as published by
|
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
7
|
+
(at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU General Public License
|
|
15
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
package/README.md
CHANGED
|
@@ -1,3 +1,129 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @serveryyswys/opm
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
把 Operit 插件工程打成 `.toolpkg` 的构建器。**脱离 Operit 生态** —— 在普通的 Node 环境、
|
|
4
|
+
普通的编辑器里就能用,不依赖 Operit 运行时,也不依赖 AI 编程环境。
|
|
5
|
+
|
|
6
|
+
## 安装
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm i -D @serveryyswys/opm @serveryyswys/node.operit
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
两个都要装:`opm` 是构建器本身,`node.operit` 提供 `BUILTINS.json` 契约表 ——
|
|
13
|
+
重写规则的**唯一真源**,opm 不自带副本(副本一定会过期,而过期的契约会把构建带偏)。
|
|
14
|
+
|
|
15
|
+
## 用法
|
|
16
|
+
|
|
17
|
+
### 先把工程准备起来(可选,但推荐)
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
opm init # 在当前目录
|
|
21
|
+
opm init ./my-plugin # 或指定目录
|
|
22
|
+
opm init --no-install # 只写文件,不跑 npm install
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
它只管三件最容易写错的事:
|
|
26
|
+
|
|
27
|
+
1. `package.json` 补上 `scripts.build = "opm build"`,以及 `@serveryyswys/opm` /
|
|
28
|
+
`@serveryyswys/node.operit` 两个 devDependency(**不覆盖**已有值);
|
|
29
|
+
2. 没有 `manifest.json` 就生成一个骨架(toolpkg 的身份靠它;`toolpkg_id` 记得改成你自己的);
|
|
30
|
+
3. 工程里有 `.ts` 才补 `tsconfig.json`,且 `outDir` 与 `manifest.main` 对齐。
|
|
31
|
+
|
|
32
|
+
默认会跑一次 `npm install`。**不指定 registry** —— 包从哪个源来,由你自己的 npm 配置决定
|
|
33
|
+
(用私有源的团队,装的就是私有源里的 `node.operit`)。
|
|
34
|
+
|
|
35
|
+
### 然后构建
|
|
36
|
+
|
|
37
|
+
两种完全等价:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
opm build # 直接调
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
// 工程的 package.json
|
|
45
|
+
"scripts": { "build": "opm build" }
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npm run build # npm 会把 node_modules/.bin/opm 放进 PATH
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
其他命令:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
opm build [项目目录] --out <名字> --dry-run [--no-install]
|
|
56
|
+
opm verify [项目目录] [--no-install] # 出包前干跑校验,**不写任何文件**
|
|
57
|
+
opm version [项目目录] # 列版本:opm / 工程 / node.operit / toolpkg
|
|
58
|
+
opm help
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`verify` 与 `build` 跑同一条流水线,区别是**完全不落盘**,所以适合放进 CI 当门禁。
|
|
62
|
+
它检查:manifest 字段(含 toolpkg_id 是否还是 `com.example.` 占位)、子包入口、
|
|
63
|
+
依赖与裸名归宿、资产齐全度,并给出归档文件数/体积/引入的包/node.operit 版本。
|
|
64
|
+
|
|
65
|
+
项目目录默认为当前目录。产物放在**项目目录的上一级**,名为 `<项目目录名>.toolpkg`。
|
|
66
|
+
|
|
67
|
+
## 它做什么
|
|
68
|
+
|
|
69
|
+
0. **补齐依赖**:`dependencies` 里声明了却没装的包,以及 `node.operit` 本身,先跑一次
|
|
70
|
+
`npm install`(同样不指定 registry)。缺依赖硬做的结果是一句"解析不到",
|
|
71
|
+
对使用者没有指导性。要跳过自动安装用 `--no-install`(它会明确告诉你缺什么)。
|
|
72
|
+
1. 读 `manifest.json`,取可达种子:`main` + 每个 `subpackages[].entry`
|
|
73
|
+
2. 顺 `require` 链递归收集被引用的文件(**可达性裁剪** —— 只有真被引用到的才进包)
|
|
74
|
+
3. **裸名重写**为归档内的显式 `.js` 相对路径
|
|
75
|
+
4. **契约拦截**:`planned` / `unsupported` 的依赖直接让构建失败,不把问题带到运行期
|
|
76
|
+
5. 入口注入 `process` / `Buffer` 全局(Operit 沙盒没有这两个全局)
|
|
77
|
+
6. 压成 zip,写 `.toolpkg`
|
|
78
|
+
|
|
79
|
+
### 哪些文件会进包
|
|
80
|
+
|
|
81
|
+
| 类别 | 处理 |
|
|
82
|
+
| --- | --- |
|
|
83
|
+
| `manifest.json` | 原样 |
|
|
84
|
+
| **JS**(入口 / 子包 / UI / 依赖) | 顺 `require` 链裁剪 + 裸名重写;**不可达的 JS 是死代码,不带** |
|
|
85
|
+
| `resources/` `i18n/` `modules/` | **无条件整目录保留**,即使里面是 `.js` |
|
|
86
|
+
| 其它非 JS 文件 | 原样带上(运行期数据,静态追不出来) |
|
|
87
|
+
| 工程元数据(`package.json`/`tsconfig.json`/`.npmrc`…)与打包产物(`*.tgz`/`*.zip`) | 不带 |
|
|
88
|
+
|
|
89
|
+
> 为什么要专门列这条:这三个规范目录**不在 require 链里**。只按 require 收集会把插件的
|
|
90
|
+
> logo、多语言文件、WASM 模块**静默丢掉**且不报错。`i18n/*.js` 尤其容易被"不可达 JS 裁剪"
|
|
91
|
+
> 误伤 —— 它是被 i18n 机制加载的**数据**,不是 require 出来的模块。
|
|
92
|
+
|
|
93
|
+
### 裸名重写的三条规则
|
|
94
|
+
|
|
95
|
+
| 请求 | 重写为 |
|
|
96
|
+
| --- | --- |
|
|
97
|
+
| `lodash` / `uuid` / `axios` | **保持原样**(运行时已内建) |
|
|
98
|
+
| Node 内建(`path`、`fs`…) | `<rel>/node_modules/@serveryyswys/node.operit/dist/<subpath>.js` |
|
|
99
|
+
| 第三方 npm 包 | 该包入口文件(解析 `main` / `exports`),归档内相对路径 |
|
|
100
|
+
|
|
101
|
+
**为什么必须显式带 `.js`**:Operit 运行时的 `buildCandidatePaths` 对命中 `/\.[a-z0-9]+$/i` 的名字
|
|
102
|
+
只试一个候选、不补扩展名。包名里的 `.operit` 正好命中那个正则,所以 `.../node.operit` 会被当成
|
|
103
|
+
完整路径而解析失败 —— 必须写成 `.../node.operit/dist/index.js`。
|
|
104
|
+
|
|
105
|
+
## 归档结构
|
|
106
|
+
|
|
107
|
+
`.toolpkg` 就是 zip,**文件直接放在归档根**(没有顶层目录),路径完全照 `manifest.json` 里写的来:
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
manifest.json
|
|
111
|
+
main.js
|
|
112
|
+
ui/xxx/index.ui.js
|
|
113
|
+
packages/*.js
|
|
114
|
+
node_modules/<被引用到的包>/**/*.js
|
|
115
|
+
node_modules/@serveryyswys/node.operit/dist/**/*.js
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## 与 Operit 内那个 OPM 的关系
|
|
119
|
+
|
|
120
|
+
Operit 生态里也有一个 OPM(`com.operit.serveryyswys.opm`,ToolPkg 形态),提供
|
|
121
|
+
init / search / install / remove / manager / build / verify 七个工具。
|
|
122
|
+
|
|
123
|
+
本包是其中 **`build` / `version` 的"脱离 Operit"版本**:同样一条流水线、
|
|
124
|
+
同样读 `node.operit` 的契约表,但宿主是普通 Node(`fs` / `child_process`),
|
|
125
|
+
没有 `Tools.*` 依赖,因此可以在传统开发环境里跑。
|
|
126
|
+
|
|
127
|
+
## 许可
|
|
128
|
+
|
|
129
|
+
Apache-2.0。见 `LICENSE` 与 `NOTICE`。
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
/**
|
|
5
|
+
* opm 命令行入口。
|
|
6
|
+
*
|
|
7
|
+
* 两种用法等价:
|
|
8
|
+
* opm build —— 直接调
|
|
9
|
+
* npm run build —— 工程的 package.json 里写 "build": "opm build"
|
|
10
|
+
* (npm 会把 node_modules/.bin/opm 放进 PATH)
|
|
11
|
+
*
|
|
12
|
+
* 失败一律走 process.exitCode,不调 process.exit():后者会和 stdout 刷新竞态,
|
|
13
|
+
* 把最后的报错截掉(node.operit 上踩过这个坑)。
|
|
14
|
+
*/
|
|
15
|
+
const node_fs_1 = require("node:fs");
|
|
16
|
+
const node_path_1 = require("node:path");
|
|
17
|
+
const build_1 = require("./lib/build");
|
|
18
|
+
const version_1 = require("./lib/version");
|
|
19
|
+
const init_1 = require("./lib/init");
|
|
20
|
+
const verify_1 = require("./lib/verify");
|
|
21
|
+
function ownVersion() {
|
|
22
|
+
try {
|
|
23
|
+
const manifest = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, '..', 'package.json'), 'utf8'));
|
|
24
|
+
return typeof manifest.version === 'string' ? manifest.version : '0.0.0';
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return '0.0.0';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function usage() {
|
|
31
|
+
return [
|
|
32
|
+
'@serveryyswys/opm ' + ownVersion() + ' —— 把 Operit 插件工程打成 .toolpkg',
|
|
33
|
+
'',
|
|
34
|
+
'用法:',
|
|
35
|
+
' opm init [项目目录] [--no-install] [--overwrite]',
|
|
36
|
+
' 把工程准备到能 build:补 scripts.build 与依赖声明、生成 manifest.json 骨架、',
|
|
37
|
+
' TS 工程补 tsconfig.json。默认跑一次 npm install(不指定 registry,走你自己的 npm 源)。',
|
|
38
|
+
'',
|
|
39
|
+
' opm build [项目目录] [--out <名字>] [--dry-run] [--no-install]',
|
|
40
|
+
' 计算可达性、重写裸名、拦截不支持的依赖,压成 .toolpkg',
|
|
41
|
+
' 产物放在项目目录的上一级,名为 <项目目录名>.toolpkg',
|
|
42
|
+
'',
|
|
43
|
+
' opm verify [项目目录] [--no-install]',
|
|
44
|
+
' 出包前干跑校验:manifest 字段、入口、依赖、裸名归宿、资产齐全度、统计。',
|
|
45
|
+
' **完全不写文件**,所以可以在 CI 里当门禁用。',
|
|
46
|
+
'',
|
|
47
|
+
' opm version [项目目录]',
|
|
48
|
+
' 列出版本:opm 自身、目标工程、node.operit、toolpkg manifest',
|
|
49
|
+
'',
|
|
50
|
+
' opm help | --version',
|
|
51
|
+
'',
|
|
52
|
+
'项目目录默认为当前目录。构建需要项目里已安装 @serveryyswys/node.operit —— ',
|
|
53
|
+
'它的 BUILTINS.json 是重写规则的唯一真源。'
|
|
54
|
+
].join('\n');
|
|
55
|
+
}
|
|
56
|
+
function parseArgs(argv) {
|
|
57
|
+
const positional = [];
|
|
58
|
+
const flags = new Map();
|
|
59
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
60
|
+
const arg = argv[index];
|
|
61
|
+
if (arg.startsWith('--')) {
|
|
62
|
+
const name = arg.slice(2);
|
|
63
|
+
const next = argv[index + 1];
|
|
64
|
+
if (next !== undefined && !next.startsWith('--')) {
|
|
65
|
+
flags.set(name, next);
|
|
66
|
+
index += 1;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
flags.set(name, 'true');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
positional.push(arg);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return { positional, flags };
|
|
77
|
+
}
|
|
78
|
+
function main(argv) {
|
|
79
|
+
const command = argv[0];
|
|
80
|
+
const { positional, flags } = parseArgs(argv.slice(1));
|
|
81
|
+
if (command === undefined || command === 'help' || command === '--help' || command === '-h') {
|
|
82
|
+
console.log(usage());
|
|
83
|
+
return 0;
|
|
84
|
+
}
|
|
85
|
+
if (command === '--version' || command === '-v') {
|
|
86
|
+
console.log(ownVersion());
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
89
|
+
if (command === 'init') {
|
|
90
|
+
const projectDir = (0, node_path_1.resolve)(positional[0] === undefined ? process.cwd() : positional[0]);
|
|
91
|
+
const result = (0, init_1.initProject)({
|
|
92
|
+
projectDir,
|
|
93
|
+
install: !flags.has('no-install'),
|
|
94
|
+
overwrite: flags.has('overwrite')
|
|
95
|
+
});
|
|
96
|
+
for (const item of result.created) {
|
|
97
|
+
console.log(' + ' + item);
|
|
98
|
+
}
|
|
99
|
+
for (const item of result.updated) {
|
|
100
|
+
console.log(' ~ ' + item);
|
|
101
|
+
}
|
|
102
|
+
for (const item of result.unchanged) {
|
|
103
|
+
console.log(' = ' + item + '(已存在,未改动)');
|
|
104
|
+
}
|
|
105
|
+
for (const note of result.notes) {
|
|
106
|
+
console.log(' · ' + note);
|
|
107
|
+
}
|
|
108
|
+
if (!result.ok) {
|
|
109
|
+
console.error('');
|
|
110
|
+
console.error('init 未能完成:');
|
|
111
|
+
for (const error of result.errors) {
|
|
112
|
+
console.error(' ✗ ' + error);
|
|
113
|
+
}
|
|
114
|
+
return 1;
|
|
115
|
+
}
|
|
116
|
+
console.log('');
|
|
117
|
+
console.log('下一步:');
|
|
118
|
+
for (const step of result.nextSteps) {
|
|
119
|
+
console.log(' ' + step);
|
|
120
|
+
}
|
|
121
|
+
return 0;
|
|
122
|
+
}
|
|
123
|
+
if (command === 'build') {
|
|
124
|
+
const projectDir = (0, node_path_1.resolve)(positional[0] === undefined ? process.cwd() : positional[0]);
|
|
125
|
+
const result = (0, build_1.buildProject)({
|
|
126
|
+
projectDir,
|
|
127
|
+
outName: flags.get('out'),
|
|
128
|
+
dryRun: flags.has('dry-run'),
|
|
129
|
+
install: !flags.has('no-install')
|
|
130
|
+
});
|
|
131
|
+
for (const note of result.notes) {
|
|
132
|
+
console.log(' · ' + note);
|
|
133
|
+
}
|
|
134
|
+
if (result.diagnostics.length > 0) {
|
|
135
|
+
const byKind = new Map();
|
|
136
|
+
for (const item of result.diagnostics) {
|
|
137
|
+
byKind.set(item.kind, (byKind.get(item.kind) ?? 0) + 1);
|
|
138
|
+
}
|
|
139
|
+
const summary = Array.from(byKind.entries()).map(([kind, count]) => kind + ' ' + count).join(' / ');
|
|
140
|
+
console.log(' 重写 ' + result.diagnostics.length + ' 处(' + summary + ')');
|
|
141
|
+
}
|
|
142
|
+
if (!result.ok) {
|
|
143
|
+
console.error('');
|
|
144
|
+
console.error('构建失败(' + result.errors.length + ' 个问题):');
|
|
145
|
+
for (const error of result.errors) {
|
|
146
|
+
console.error(' ✗ ' + error);
|
|
147
|
+
}
|
|
148
|
+
return 1;
|
|
149
|
+
}
|
|
150
|
+
console.log('');
|
|
151
|
+
console.log('✓ 已打包 ' + result.fileCount + ' 个文件');
|
|
152
|
+
console.log(' ' + result.toolpkgPath);
|
|
153
|
+
return 0;
|
|
154
|
+
}
|
|
155
|
+
if (command === 'verify') {
|
|
156
|
+
const projectDir = (0, node_path_1.resolve)(positional[0] === undefined ? process.cwd() : positional[0]);
|
|
157
|
+
const report = (0, verify_1.verifyProject)({ projectDir, install: !flags.has('no-install') });
|
|
158
|
+
console.log('检查项:');
|
|
159
|
+
for (const check of report.checks) {
|
|
160
|
+
console.log(' ' + (check.ok ? '✓' : '✗') + ' ' + check.name + ' —— ' + check.detail);
|
|
161
|
+
}
|
|
162
|
+
const stats = report.stats;
|
|
163
|
+
console.log('');
|
|
164
|
+
console.log('统计:');
|
|
165
|
+
console.log(' 归档文件 ' + stats.archiveFiles + ' 个(其中资产 ' + stats.assets + ' 个),共 ' + stats.totalBytes + ' 字节');
|
|
166
|
+
console.log(' 重写 内建 ' + stats.builtin + ' / npm 包 ' + stats.package + ' / 相对 ' + stats.relative + ' / 保持原样 ' + stats.untouched);
|
|
167
|
+
console.log(' 引入的包 ' + (stats.packages.length === 0 ? '(无)' : stats.packages.join(', ')));
|
|
168
|
+
console.log(' node.operit ' + stats.nodeOperitVersion);
|
|
169
|
+
for (const note of report.notes) {
|
|
170
|
+
console.log(' · ' + note);
|
|
171
|
+
}
|
|
172
|
+
for (const warning of report.warnings) {
|
|
173
|
+
console.log(' ! ' + warning);
|
|
174
|
+
}
|
|
175
|
+
if (!report.ok) {
|
|
176
|
+
console.error('');
|
|
177
|
+
console.error('校验未通过(' + report.errors.length + ' 个问题):');
|
|
178
|
+
for (const error of report.errors) {
|
|
179
|
+
console.error(' ✗ ' + error);
|
|
180
|
+
}
|
|
181
|
+
return 1;
|
|
182
|
+
}
|
|
183
|
+
console.log('');
|
|
184
|
+
console.log('✓ 校验通过(未写任何文件)');
|
|
185
|
+
return 0;
|
|
186
|
+
}
|
|
187
|
+
if (command === 'version') {
|
|
188
|
+
const report = (0, version_1.describeVersions)(positional[0], ownVersion());
|
|
189
|
+
for (const line of report.lines) {
|
|
190
|
+
console.log(line);
|
|
191
|
+
}
|
|
192
|
+
for (const error of report.errors) {
|
|
193
|
+
console.error(' ! ' + error);
|
|
194
|
+
}
|
|
195
|
+
return report.errors.length > 0 ? 1 : 0;
|
|
196
|
+
}
|
|
197
|
+
console.error('未知命令:' + command);
|
|
198
|
+
console.error('');
|
|
199
|
+
console.error(usage());
|
|
200
|
+
return 1;
|
|
201
|
+
}
|
|
202
|
+
process.exitCode = main(process.argv.slice(2));
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 库入口:给想在 Node 里直接调用(不走命令行)的场景。
|
|
3
|
+
*/
|
|
4
|
+
export { buildProject } from './lib/build';
|
|
5
|
+
export type { BuildOptions, BuildResult } from './lib/build';
|
|
6
|
+
export { describeVersions } from './lib/version';
|
|
7
|
+
export { verifyProject } from './lib/verify';
|
|
8
|
+
export type { VerifyReport, VerifyCheck, VerifyStats } from './lib/verify';
|
|
9
|
+
export { initProject, OPM_PACKAGE } from './lib/init';
|
|
10
|
+
export type { InitOptions, InitResult } from './lib/init';
|
|
11
|
+
export { auditDependencies, installDependencies } from './lib/dependencies';
|
|
12
|
+
export type { DependencyAudit } from './lib/dependencies';
|
|
13
|
+
export type { VersionReport } from './lib/version';
|
|
14
|
+
export { createZip, readZip } from './lib/zip';
|
|
15
|
+
export type { ZipEntry } from './lib/zip';
|
|
16
|
+
export { findRequires } from './lib/js-requires';
|
|
17
|
+
export type { RequireSite } from './lib/js-requires';
|
|
18
|
+
export { findNodeOperitDir, loadContract, NODE_OPERIT_DIR, NODE_OPERIT_PACKAGE, RUNTIME_BUILTINS } from './lib/contract';
|
|
19
|
+
export type { Contract, BuiltinEntry, BuiltinStatus } from './lib/contract';
|
|
20
|
+
export { rewriteModule, resolveRelative } from './lib/rewrite';
|
|
21
|
+
export type { Diagnostic, RewriteEnv, RewriteOutcome } from './lib/rewrite';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveRelative = exports.rewriteModule = exports.RUNTIME_BUILTINS = exports.NODE_OPERIT_PACKAGE = exports.NODE_OPERIT_DIR = exports.loadContract = exports.findNodeOperitDir = exports.findRequires = exports.readZip = exports.createZip = exports.installDependencies = exports.auditDependencies = exports.OPM_PACKAGE = exports.initProject = exports.verifyProject = exports.describeVersions = exports.buildProject = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 库入口:给想在 Node 里直接调用(不走命令行)的场景。
|
|
6
|
+
*/
|
|
7
|
+
var build_1 = require("./lib/build");
|
|
8
|
+
Object.defineProperty(exports, "buildProject", { enumerable: true, get: function () { return build_1.buildProject; } });
|
|
9
|
+
var version_1 = require("./lib/version");
|
|
10
|
+
Object.defineProperty(exports, "describeVersions", { enumerable: true, get: function () { return version_1.describeVersions; } });
|
|
11
|
+
var verify_1 = require("./lib/verify");
|
|
12
|
+
Object.defineProperty(exports, "verifyProject", { enumerable: true, get: function () { return verify_1.verifyProject; } });
|
|
13
|
+
var init_1 = require("./lib/init");
|
|
14
|
+
Object.defineProperty(exports, "initProject", { enumerable: true, get: function () { return init_1.initProject; } });
|
|
15
|
+
Object.defineProperty(exports, "OPM_PACKAGE", { enumerable: true, get: function () { return init_1.OPM_PACKAGE; } });
|
|
16
|
+
var dependencies_1 = require("./lib/dependencies");
|
|
17
|
+
Object.defineProperty(exports, "auditDependencies", { enumerable: true, get: function () { return dependencies_1.auditDependencies; } });
|
|
18
|
+
Object.defineProperty(exports, "installDependencies", { enumerable: true, get: function () { return dependencies_1.installDependencies; } });
|
|
19
|
+
var zip_1 = require("./lib/zip");
|
|
20
|
+
Object.defineProperty(exports, "createZip", { enumerable: true, get: function () { return zip_1.createZip; } });
|
|
21
|
+
Object.defineProperty(exports, "readZip", { enumerable: true, get: function () { return zip_1.readZip; } });
|
|
22
|
+
var js_requires_1 = require("./lib/js-requires");
|
|
23
|
+
Object.defineProperty(exports, "findRequires", { enumerable: true, get: function () { return js_requires_1.findRequires; } });
|
|
24
|
+
var contract_1 = require("./lib/contract");
|
|
25
|
+
Object.defineProperty(exports, "findNodeOperitDir", { enumerable: true, get: function () { return contract_1.findNodeOperitDir; } });
|
|
26
|
+
Object.defineProperty(exports, "loadContract", { enumerable: true, get: function () { return contract_1.loadContract; } });
|
|
27
|
+
Object.defineProperty(exports, "NODE_OPERIT_DIR", { enumerable: true, get: function () { return contract_1.NODE_OPERIT_DIR; } });
|
|
28
|
+
Object.defineProperty(exports, "NODE_OPERIT_PACKAGE", { enumerable: true, get: function () { return contract_1.NODE_OPERIT_PACKAGE; } });
|
|
29
|
+
Object.defineProperty(exports, "RUNTIME_BUILTINS", { enumerable: true, get: function () { return contract_1.RUNTIME_BUILTINS; } });
|
|
30
|
+
var rewrite_1 = require("./lib/rewrite");
|
|
31
|
+
Object.defineProperty(exports, "rewriteModule", { enumerable: true, get: function () { return rewrite_1.rewriteModule; } });
|
|
32
|
+
Object.defineProperty(exports, "resolveRelative", { enumerable: true, get: function () { return rewrite_1.resolveRelative; } });
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Diagnostic } from './rewrite';
|
|
2
|
+
export interface BuildOptions {
|
|
3
|
+
projectDir: string;
|
|
4
|
+
/** 产物名(不含 .toolpkg),默认取项目目录名 */
|
|
5
|
+
outName?: string;
|
|
6
|
+
/** 只分析不产包 */
|
|
7
|
+
dryRun?: boolean;
|
|
8
|
+
/** 缺依赖时是否自动 npm install(默认 true;--no-install 关掉) */
|
|
9
|
+
install?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface BuildResult {
|
|
12
|
+
ok: boolean;
|
|
13
|
+
toolpkgPath: string;
|
|
14
|
+
fileCount: number;
|
|
15
|
+
/** 会进归档的归档路径清单 */
|
|
16
|
+
files: string[];
|
|
17
|
+
/** 这些文件的正文总字节数(未压缩) */
|
|
18
|
+
totalBytes: number;
|
|
19
|
+
/** 原样带上的非 JS 资产(归档路径) */
|
|
20
|
+
assets: string[];
|
|
21
|
+
diagnostics: Diagnostic[];
|
|
22
|
+
errors: string[];
|
|
23
|
+
notes: string[];
|
|
24
|
+
}
|
|
25
|
+
export declare function buildProject(options: BuildOptions): BuildResult;
|