jiek 2.0.2-alpha.12 → 2.0.2-alpha.14
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/README.md +78 -0
- package/bin/jiek-build.js +16 -0
- package/bin/jiek.js +13 -0
- package/cli-only-build.cjs +1 -1
- package/cli-only-build.js +1 -1
- package/cli.cjs +13 -13
- package/cli.js +13 -13
- package/package.json +1 -1
- package/src/cli-only-build.ts +7 -0
- package/src/cli.ts +2 -0
- package/src/commands/base.ts +18 -0
- package/src/commands/build.ts +459 -0
- package/src/commands/descriptions.ts +17 -0
- package/src/commands/meta.ts +5 -0
- package/src/commands/publish.ts +370 -0
- package/src/index.ts +8 -0
- package/src/inner.ts +11 -0
- package/src/rollup/base.ts +137 -0
- package/src/rollup/index.ts +565 -0
- package/src/rollup/plugins/progress.ts +26 -0
- package/src/rollup/plugins/skip.ts +21 -0
- package/src/rollup/utils/commonOptions.ts +9 -0
- package/src/rollup/utils/externalResolver.ts +35 -0
- package/src/rollup/utils/globalResolver.ts +13 -0
- package/src/rollup/utils/withMinify.ts +18 -0
- package/src/utils/filterSupport.ts +91 -0
- package/src/utils/getExports.ts +140 -0
- package/src/utils/getRoot.ts +16 -0
- package/src/utils/getWD.ts +31 -0
- package/src/utils/loadConfig.ts +111 -0
- package/src/utils/recusiveListFiles.ts +13 -0
- package/src/utils/ts.ts +94 -0
- package/src/utils/tsRegister.ts +26 -0
package/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Jiek
|
2
|
+
|
3
|
+
| zh-Hans
|
4
|
+
| [en](https://github.com/NWYLZW/jiek/blob/master/packages/jiek/.about/en/README.md)
|
5
|
+
|
6
|
+
[](https://npmjs.com/package/jiek)
|
7
|
+
[](https://npm.chart.dev/jiek)
|
8
|
+
|
9
|
+
> 基于 `package.json` 元数据并适用于 `Monorepo` 的**轻便**工具库编译管理套件。
|
10
|
+
|
11
|
+
- [x] 自动推断:基于 `package.json` 的相关字段自动推断出构建规则,减少配置文件的编写,更加轻便与符合标准
|
12
|
+
- `exports`:根据入口文件推断构建目标与类型
|
13
|
+
- `imports`:定义路径别名,并在构建的时候自动 bundle 进来
|
14
|
+
- `type: module`:根据选项智能决定输出文件后缀,不需要考虑 `cjs` 与 `esm` 的适配问题
|
15
|
+
- `dependencies`、`peerDependencies`、`optionalDependencies`:自动将符合规则的依赖标记为 `external`
|
16
|
+
- `devDependencies`:将标记为开发依赖的 bundle 进对应的最终产物之中
|
17
|
+
- [ ] 构建工具:支持多种构建工具,无需纠结于用 swc 还是 esbuild 又或者是 tsc
|
18
|
+
- [x] `esbuild`
|
19
|
+
- [x] `swc`
|
20
|
+
- [ ] `typescript`
|
21
|
+
- [x] 工作空间友好:支持在 pnpm 下的工作空间开发范式
|
22
|
+
- [ ] 支持更多的 PM
|
23
|
+
- [ ] 更好的工作空间任务流
|
24
|
+
- [x] 类型定义文件:支持聚合生成类型定义文件
|
25
|
+
- [x] 监听模式:适配 rollup 的监听模式
|
26
|
+
- [x] 发布适配:支持同构生成 `package.json` 等相关字段
|
27
|
+
- [ ] 根据 `package.json` 中的路径自动替换 README.md 中的相对路径链接为对应的网络链接
|
28
|
+
- [x] CommonJS:产物兼容正在使用 cjs 的用户
|
29
|
+
- [ ] 插件化
|
30
|
+
- [ ] Dotenv:支持 dotenv 配置文件
|
31
|
+
- [ ] Replacer:支持替换文件内容
|
32
|
+
|
33
|
+
## 安装
|
34
|
+
|
35
|
+
```bash
|
36
|
+
npm i -D jiek
|
37
|
+
# or
|
38
|
+
pnpm i -D jiek
|
39
|
+
# or
|
40
|
+
yarn add -D jiek
|
41
|
+
```
|
42
|
+
|
43
|
+
## 快速起步
|
44
|
+
|
45
|
+
通过一些简单的方式能又快又轻松的生成需要的产物。
|
46
|
+
|
47
|
+
- 在 `package.json` 中添加入口文件,这里需要设置为原文件路径。
|
48
|
+
|
49
|
+
你可以在 Node.js 文档中查看更多对于 [exports](https://nodejs.org/api/packages.html#exports) 的相关内容。
|
50
|
+
|
51
|
+
```json
|
52
|
+
{
|
53
|
+
...
|
54
|
+
"exports": "./src/index.ts",
|
55
|
+
...
|
56
|
+
}
|
57
|
+
```
|
58
|
+
|
59
|
+
- 假设你在工作空间下有一个包名字为 `@monorepo/utils` ,那么你可以运行 `jb utils` 来构建这个包。
|
60
|
+
|
61
|
+
- 当你完成了开发的相关步骤后,在发布阶段你可以使用 `jk -f utils publish` 来发布你的包,本工具会自动转化并填充 `package.json` 对应的字段。
|
62
|
+
|
63
|
+
你可以添加 `-p/--preview` 参数来预览待发布的 `package.json` 的内容。
|
64
|
+
|
65
|
+
## CLI
|
66
|
+
|
67
|
+
```text
|
68
|
+
Usage: jk [options] [command]
|
69
|
+
```
|
70
|
+
|
71
|
+
## 为什么不使用 X?
|
72
|
+
|
73
|
+
在这里与 `jiek` 类似的工具有:[tsup](https://github.com/egoist/tsup)、[unbuild](https://github.com/unjs/unbuild)、[bunchee](https://github.com/huozhi/bunchee)、[pkgroll](https://github.com/privatenumber/pkgroll)、[tsdown](https://github.com/sxzz/tsdown)。但是他们都有着一些共同问题没有解决,比如说:
|
74
|
+
|
75
|
+
- `monorepo` 的支持存在一定的问题,在依赖工作空间其他的包时必须重新编译相关依赖
|
76
|
+
- 编写入口文件的规则过于繁琐,不够自然
|
77
|
+
- 无法处理 `tsconfig.json` 中的 `Project Reference` 相关问题
|
78
|
+
- 根据`conditions`
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
import { existsSync } from 'node:fs'
|
3
|
+
import { createRequire } from 'node:module'
|
4
|
+
import { dirname, resolve } from 'node:path'
|
5
|
+
import process from 'node:process'
|
6
|
+
|
7
|
+
process.env.JIEK_IS_ONLY_BUILD = 'true'
|
8
|
+
|
9
|
+
const __dirname = dirname(import.meta.url.replace('file://', ''))
|
10
|
+
if (existsSync(resolve(__dirname, '../.jiek-dev-tag'))) {
|
11
|
+
const require = createRequire(import.meta.url)
|
12
|
+
require('esbuild-register')
|
13
|
+
require('../src/cli-only-build.ts')
|
14
|
+
} else {
|
15
|
+
import('jiek/cli-only-build')
|
16
|
+
}
|
package/bin/jiek.js
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
import { existsSync } from 'node:fs'
|
3
|
+
import { createRequire } from 'node:module'
|
4
|
+
import { dirname, resolve } from 'node:path'
|
5
|
+
|
6
|
+
const __dirname = dirname(import.meta.url.replace('file://', ''))
|
7
|
+
if (existsSync(resolve(__dirname, '../.jiek-dev-tag'))) {
|
8
|
+
const require = createRequire(import.meta.url)
|
9
|
+
require('esbuild-register')
|
10
|
+
require('../src/cli.ts')
|
11
|
+
} else {
|
12
|
+
import('jiek/cli')
|
13
|
+
}
|
package/cli-only-build.cjs
CHANGED
@@ -116,7 +116,7 @@ async function getSelectedProjectsGraph(filter = commander.program.getOptionValu
|
|
116
116
|
|
117
117
|
var name = "jiek";
|
118
118
|
var type = "module";
|
119
|
-
var version = "2.0.2-alpha.
|
119
|
+
var version = "2.0.2-alpha.13";
|
120
120
|
var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
|
121
121
|
var author = "YiJie <yijie4188@gmail.com>";
|
122
122
|
var repository = {
|
package/cli-only-build.js
CHANGED
@@ -108,7 +108,7 @@ async function getSelectedProjectsGraph(filter = program.getOptionValue("filter"
|
|
108
108
|
|
109
109
|
var name = "jiek";
|
110
110
|
var type = "module";
|
111
|
-
var version = "2.0.2-alpha.
|
111
|
+
var version = "2.0.2-alpha.13";
|
112
112
|
var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
|
113
113
|
var author = "YiJie <yijie4188@gmail.com>";
|
114
114
|
var repository = {
|
package/cli.cjs
CHANGED
@@ -4667,6 +4667,16 @@ async function prepublish() {
|
|
4667
4667
|
modifyVersionPackageJSON,
|
4668
4668
|
jsoncParser.modify(modifyVersionPackageJSON, ["publishConfig", "directory"], resolvedOutdir, { formattingOptions })
|
4669
4669
|
);
|
4670
|
+
if (!fs__default.default.existsSync(resolveByDir(resolvedOutdir))) {
|
4671
|
+
fs__default.default.mkdirSync(resolveByDir(resolvedOutdir));
|
4672
|
+
}
|
4673
|
+
const jiekTempDir = resolveByDir("node_modules/.jiek/.tmp");
|
4674
|
+
if (!fs__default.default.existsSync(resolveByDir(jiekTempDir))) {
|
4675
|
+
fs__default.default.mkdirSync(resolveByDir(jiekTempDir), { recursive: true });
|
4676
|
+
}
|
4677
|
+
fs__default.default.writeFileSync(resolveByDir(resolvedOutdir, "package.json"), newJSONString);
|
4678
|
+
fs__default.default.writeFileSync(resolveByDir(jiekTempDir, "package.json"), modifyVersionPackageJSON);
|
4679
|
+
fs__default.default.writeFileSync(resolveByDir("package.json"), withPublishConfigDirectoryOldJSONString);
|
4670
4680
|
if (oldJSON.files) {
|
4671
4681
|
if (!Array.isArray(oldJSON.files)) {
|
4672
4682
|
throw new Error(`${dir}/package.json files field must be an array`);
|
@@ -4676,17 +4686,17 @@ async function prepublish() {
|
|
4676
4686
|
}
|
4677
4687
|
}
|
4678
4688
|
const resolvedOutdirAbs = resolveByDir(resolvedOutdir);
|
4679
|
-
const files = oldJSON.files ?? fs__default.default.readdirSync(resolveByDir(".")).filter((file) => file === "node_modules" || resolveByDir(file) !== resolvedOutdirAbs);
|
4689
|
+
const files = (oldJSON.files ?? fs__default.default.readdirSync(resolveByDir("."))).filter((file) => file === "node_modules" || resolveByDir(file) !== resolvedOutdirAbs);
|
4680
4690
|
for (const file of files) {
|
4681
4691
|
const path2 = resolveByDir(file);
|
4682
4692
|
try {
|
4683
4693
|
const stat = fs__default.default.statSync(path2);
|
4684
4694
|
if (stat.isDirectory()) {
|
4685
|
-
fs__default.default.
|
4695
|
+
fs__default.default.cpSync(path2, resolveByDir(resolvedOutdir, file), { recursive: true });
|
4686
4696
|
continue;
|
4687
4697
|
}
|
4688
4698
|
if (stat.isFile()) {
|
4689
|
-
fs__default.default.
|
4699
|
+
fs__default.default.cpSync(path2, resolveByDir(resolvedOutdir, file));
|
4690
4700
|
continue;
|
4691
4701
|
}
|
4692
4702
|
} catch (e) {
|
@@ -4695,16 +4705,6 @@ async function prepublish() {
|
|
4695
4705
|
}
|
4696
4706
|
throw new Error(`file type of ${path2} is not supported`);
|
4697
4707
|
}
|
4698
|
-
if (!fs__default.default.existsSync(resolveByDir(resolvedOutdir))) {
|
4699
|
-
fs__default.default.mkdirSync(resolveByDir(resolvedOutdir));
|
4700
|
-
}
|
4701
|
-
const jiekTempDir = resolveByDir("node_modules/.jiek/.tmp");
|
4702
|
-
if (!fs__default.default.existsSync(resolveByDir(jiekTempDir))) {
|
4703
|
-
fs__default.default.mkdirSync(resolveByDir(jiekTempDir), { recursive: true });
|
4704
|
-
}
|
4705
|
-
fs__default.default.writeFileSync(resolveByDir(resolvedOutdir, "package.json"), newJSONString);
|
4706
|
-
fs__default.default.writeFileSync(resolveByDir(jiekTempDir, "package.json"), modifyVersionPackageJSON);
|
4707
|
-
fs__default.default.writeFileSync(resolveByDir("package.json"), withPublishConfigDirectoryOldJSONString);
|
4708
4708
|
});
|
4709
4709
|
}
|
4710
4710
|
async function postpublish() {
|
package/cli.js
CHANGED
@@ -4637,6 +4637,16 @@ async function prepublish() {
|
|
4637
4637
|
modifyVersionPackageJSON,
|
4638
4638
|
modify(modifyVersionPackageJSON, ["publishConfig", "directory"], resolvedOutdir, { formattingOptions })
|
4639
4639
|
);
|
4640
|
+
if (!fs.existsSync(resolveByDir(resolvedOutdir))) {
|
4641
|
+
fs.mkdirSync(resolveByDir(resolvedOutdir));
|
4642
|
+
}
|
4643
|
+
const jiekTempDir = resolveByDir("node_modules/.jiek/.tmp");
|
4644
|
+
if (!fs.existsSync(resolveByDir(jiekTempDir))) {
|
4645
|
+
fs.mkdirSync(resolveByDir(jiekTempDir), { recursive: true });
|
4646
|
+
}
|
4647
|
+
fs.writeFileSync(resolveByDir(resolvedOutdir, "package.json"), newJSONString);
|
4648
|
+
fs.writeFileSync(resolveByDir(jiekTempDir, "package.json"), modifyVersionPackageJSON);
|
4649
|
+
fs.writeFileSync(resolveByDir("package.json"), withPublishConfigDirectoryOldJSONString);
|
4640
4650
|
if (oldJSON.files) {
|
4641
4651
|
if (!Array.isArray(oldJSON.files)) {
|
4642
4652
|
throw new Error(`${dir}/package.json files field must be an array`);
|
@@ -4646,17 +4656,17 @@ async function prepublish() {
|
|
4646
4656
|
}
|
4647
4657
|
}
|
4648
4658
|
const resolvedOutdirAbs = resolveByDir(resolvedOutdir);
|
4649
|
-
const files = oldJSON.files ?? fs.readdirSync(resolveByDir(".")).filter((file) => file === "node_modules" || resolveByDir(file) !== resolvedOutdirAbs);
|
4659
|
+
const files = (oldJSON.files ?? fs.readdirSync(resolveByDir("."))).filter((file) => file === "node_modules" || resolveByDir(file) !== resolvedOutdirAbs);
|
4650
4660
|
for (const file of files) {
|
4651
4661
|
const path2 = resolveByDir(file);
|
4652
4662
|
try {
|
4653
4663
|
const stat = fs.statSync(path2);
|
4654
4664
|
if (stat.isDirectory()) {
|
4655
|
-
fs.
|
4665
|
+
fs.cpSync(path2, resolveByDir(resolvedOutdir, file), { recursive: true });
|
4656
4666
|
continue;
|
4657
4667
|
}
|
4658
4668
|
if (stat.isFile()) {
|
4659
|
-
fs.
|
4669
|
+
fs.cpSync(path2, resolveByDir(resolvedOutdir, file));
|
4660
4670
|
continue;
|
4661
4671
|
}
|
4662
4672
|
} catch (e) {
|
@@ -4665,16 +4675,6 @@ async function prepublish() {
|
|
4665
4675
|
}
|
4666
4676
|
throw new Error(`file type of ${path2} is not supported`);
|
4667
4677
|
}
|
4668
|
-
if (!fs.existsSync(resolveByDir(resolvedOutdir))) {
|
4669
|
-
fs.mkdirSync(resolveByDir(resolvedOutdir));
|
4670
|
-
}
|
4671
|
-
const jiekTempDir = resolveByDir("node_modules/.jiek/.tmp");
|
4672
|
-
if (!fs.existsSync(resolveByDir(jiekTempDir))) {
|
4673
|
-
fs.mkdirSync(resolveByDir(jiekTempDir), { recursive: true });
|
4674
|
-
}
|
4675
|
-
fs.writeFileSync(resolveByDir(resolvedOutdir, "package.json"), newJSONString);
|
4676
|
-
fs.writeFileSync(resolveByDir(jiekTempDir, "package.json"), modifyVersionPackageJSON);
|
4677
|
-
fs.writeFileSync(resolveByDir("package.json"), withPublishConfigDirectoryOldJSONString);
|
4678
4678
|
});
|
4679
4679
|
}
|
4680
4680
|
async function postpublish() {
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "jiek",
|
3
3
|
"type": "module",
|
4
|
-
"version": "2.0.2-alpha.
|
4
|
+
"version": "2.0.2-alpha.14",
|
5
5
|
"description": "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.",
|
6
6
|
"author": "YiJie <yijie4188@gmail.com>",
|
7
7
|
"repository": {
|
package/src/cli.ts
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
import { program } from 'commander'
|
2
|
+
import pkg from 'jiek/package.json'
|
3
|
+
|
4
|
+
import { filterDescription } from '#~/commands/descriptions.ts'
|
5
|
+
import { IS_WORKSPACE } from '#~/commands/meta.ts'
|
6
|
+
import { type } from '#~/utils/filterSupport.ts'
|
7
|
+
|
8
|
+
program
|
9
|
+
.name('jk/jiek')
|
10
|
+
.version(pkg.version)
|
11
|
+
.description(`${pkg.description} - Version ${pkg.version}`)
|
12
|
+
.option('--root <root>', 'The root path of the project')
|
13
|
+
.option('-c, --config-path <configPath>', 'Custom jiek config path')
|
14
|
+
|
15
|
+
if (type !== '' && IS_WORKSPACE) {
|
16
|
+
program
|
17
|
+
.option('-f, --filter <filter>', filterDescription)
|
18
|
+
}
|