jiek 2.2.7-alpha.1 → 2.2.7-alpha.4
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/.jiek-production-tag +0 -0
- package/bin-helper/index.cjs +1 -1
- package/dist/.internal/{getWD-BRJ3PK1S.js → .chunks/filterSupport.4rM7f6jB.cjs} +38 -29
- package/dist/.internal/{getWD-Cmxzjf-f.js → .chunks/filterSupport.BXWpLBpT.js} +37 -28
- package/dist/.internal/{+/utils/loadConfig.js → .chunks/loadConfig.CFfzkm_p.js} +24 -8
- package/dist/.internal/{+/utils/loadConfig.cjs → .chunks/loadConfig.OOKddvHF.cjs} +29 -12
- package/dist/.internal/bin/common.cjs +743 -0
- package/dist/.internal/bin/common.d.cts +18 -0
- package/dist/.internal/bin/common.d.ts +18 -0
- package/dist/.internal/bin/common.js +736 -0
- package/dist/.internal/{+/utils → utils}/filterSupport.cjs +1 -3
- package/dist/.internal/{+/utils → utils}/filterSupport.js +1 -3
- package/dist/.internal/utils/loadConfig.cjs +14 -0
- package/dist/.internal/{+/utils/getWD.js → utils/loadConfig.js} +5 -6
- package/dist/.internal/{+/utils → utils}/resolveExports.cjs +1 -1
- package/dist/.internal/{+/utils → utils}/resolveExports.js +1 -1
- package/dist/.internal/{+/utils → utils}/ts.cjs +1 -1
- package/dist/.internal/{+/utils → utils}/ts.js +1 -1
- package/dist/bin/build.cjs +3 -498
- package/dist/bin/index.cjs +56 -43
- package/dist/index.d.cts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/rollup/index.cjs +25 -31
- package/dist/rollup/index.js +25 -31
- package/package.json +12 -15
- package/src/bin/build.cts +2 -8
- package/src/bin/common.ts +3 -0
- package/src/bin/index.cts +2 -1
- package/src/commands/build.ts +9 -3
- package/src/commands/publish.ts +62 -39
- package/src/index.ts +6 -1
- package/src/rollup/index.ts +36 -33
- package/dist/.internal/+/commands/build/analyzer.cjs +0 -201
- package/dist/.internal/+/commands/build/analyzer.d.cts +0 -30
- package/dist/.internal/+/commands/build/analyzer.d.ts +0 -30
- package/dist/.internal/+/commands/build/analyzer.js +0 -195
- package/dist/.internal/+/commands/descriptions.cjs +0 -21
- package/dist/.internal/+/commands/descriptions.d.cts +0 -5
- package/dist/.internal/+/commands/descriptions.d.ts +0 -5
- package/dist/.internal/+/commands/descriptions.js +0 -17
- package/dist/.internal/+/commands/meta.cjs +0 -16
- package/dist/.internal/+/commands/meta.d.cts +0 -3
- package/dist/.internal/+/commands/meta.d.ts +0 -3
- package/dist/.internal/+/commands/meta.js +0 -15
- package/dist/.internal/+/commands/utils/optionParser.cjs +0 -8
- package/dist/.internal/+/commands/utils/optionParser.d.cts +0 -3
- package/dist/.internal/+/commands/utils/optionParser.d.ts +0 -3
- package/dist/.internal/+/commands/utils/optionParser.js +0 -6
- package/dist/.internal/+/server.cjs +0 -33
- package/dist/.internal/+/server.d.cts +0 -8
- package/dist/.internal/+/server.d.ts +0 -8
- package/dist/.internal/+/server.js +0 -27
- package/dist/.internal/+/utils/checkDependency.cjs +0 -39
- package/dist/.internal/+/utils/checkDependency.d.cts +0 -3
- package/dist/.internal/+/utils/checkDependency.d.ts +0 -3
- package/dist/.internal/+/utils/checkDependency.js +0 -34
- package/dist/.internal/+/utils/getRoot.cjs +0 -17
- package/dist/.internal/+/utils/getRoot.d.cts +0 -3
- package/dist/.internal/+/utils/getRoot.d.ts +0 -3
- package/dist/.internal/+/utils/getRoot.js +0 -11
- package/dist/.internal/+/utils/getWD.cjs +0 -15
- package/dist/.internal/+/utils/getWD.d.cts +0 -6
- package/dist/.internal/+/utils/getWD.d.ts +0 -6
- package/dist/.internal/+/utils/tsRegister.cjs +0 -25
- package/dist/.internal/+/utils/tsRegister.d.cts +0 -3
- package/dist/.internal/+/utils/tsRegister.d.ts +0 -3
- package/dist/.internal/+/utils/tsRegister.js +0 -26
- package/dist/.internal/jiek_create-require-CWFWNQHj.js +0 -5
- package/dist/.internal/jiek_create-require-CxSGbkTB.js +0 -5
- package/dist/.internal/package.json +0 -10
- /package/dist/.internal/{index-B6RQz1DZ.js → .chunks/index.B6RQz1DZ.js} +0 -0
- /package/dist/.internal/{index-DlHFuTjM.js → .chunks/index.DlHFuTjM.cjs} +0 -0
- /package/dist/.internal/{+/bin → bin}/parseArgv.cjs +0 -0
- /package/dist/.internal/{+/bin → bin}/parseArgv.d.cts +0 -0
- /package/dist/.internal/{+/bin → bin}/parseArgv.d.ts +0 -0
- /package/dist/.internal/{+/bin → bin}/parseArgv.js +0 -0
- /package/dist/.internal/{+/bridge.cjs → bridge.cjs} +0 -0
- /package/dist/.internal/{+/bridge.d.cts → bridge.d.cts} +0 -0
- /package/dist/.internal/{+/bridge.d.ts → bridge.d.ts} +0 -0
- /package/dist/.internal/{+/bridge.js → bridge.js} +0 -0
- /package/dist/.internal/{+/rollup → rollup}/base.cjs +0 -0
- /package/dist/.internal/{+/rollup → rollup}/base.d.cts +0 -0
- /package/dist/.internal/{+/rollup → rollup}/base.d.ts +0 -0
- /package/dist/.internal/{+/rollup → rollup}/base.js +0 -0
- /package/dist/.internal/{+/rollup → rollup}/bundle-analyzer.cjs +0 -0
- /package/dist/.internal/{+/rollup → rollup}/bundle-analyzer.d.cts +0 -0
- /package/dist/.internal/{+/rollup → rollup}/bundle-analyzer.d.ts +0 -0
- /package/dist/.internal/{+/rollup → rollup}/bundle-analyzer.js +0 -0
- /package/dist/.internal/{+/utils → utils}/filterSupport.d.cts +0 -0
- /package/dist/.internal/{+/utils → utils}/filterSupport.d.ts +0 -0
- /package/dist/.internal/{+/utils → utils}/getInternalModuleName.cjs +0 -0
- /package/dist/.internal/{+/utils → utils}/getInternalModuleName.d.cts +0 -0
- /package/dist/.internal/{+/utils → utils}/getInternalModuleName.d.ts +0 -0
- /package/dist/.internal/{+/utils → utils}/getInternalModuleName.js +0 -0
- /package/dist/.internal/{+/utils → utils}/intersection.cjs +0 -0
- /package/dist/.internal/{+/utils → utils}/intersection.d.cts +0 -0
- /package/dist/.internal/{+/utils → utils}/intersection.d.ts +0 -0
- /package/dist/.internal/{+/utils → utils}/intersection.js +0 -0
- /package/dist/.internal/{+/utils → utils}/loadConfig.d.cts +0 -0
- /package/dist/.internal/{+/utils → utils}/loadConfig.d.ts +0 -0
- /package/dist/.internal/{+/utils → utils}/recursiveListFiles.cjs +0 -0
- /package/dist/.internal/{+/utils → utils}/recursiveListFiles.d.cts +0 -0
- /package/dist/.internal/{+/utils → utils}/recursiveListFiles.d.ts +0 -0
- /package/dist/.internal/{+/utils → utils}/recursiveListFiles.js +0 -0
- /package/dist/.internal/{+/utils → utils}/resolveExports.d.cts +0 -0
- /package/dist/.internal/{+/utils → utils}/resolveExports.d.ts +0 -0
- /package/dist/.internal/{+/utils → utils}/ts.d.cts +0 -0
- /package/dist/.internal/{+/utils → utils}/ts.d.ts +0 -0
@@ -0,0 +1,743 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var filterSupport = require('../.chunks/filterSupport.4rM7f6jB.cjs');
|
4
|
+
var commander = require('commander');
|
5
|
+
var fs = require('node:fs');
|
6
|
+
var path = require('node:path');
|
7
|
+
var process = require('node:process');
|
8
|
+
var cliProgress = require('cli-progress');
|
9
|
+
var execa = require('execa');
|
10
|
+
var node_child_process = require('node:child_process');
|
11
|
+
var prompts = require('@inquirer/prompts');
|
12
|
+
var base = require('../rollup/base.cjs');
|
13
|
+
var Koa = require('koa');
|
14
|
+
var loadConfig = require('../.chunks/loadConfig.OOKddvHF.cjs');
|
15
|
+
require('js-yaml');
|
16
|
+
require('@jiek/utils/getWorkspaceDir');
|
17
|
+
|
18
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
19
|
+
|
20
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
21
|
+
var process__default = /*#__PURE__*/_interopDefault(process);
|
22
|
+
var Koa__default = /*#__PURE__*/_interopDefault(Koa);
|
23
|
+
|
24
|
+
var name = "jiek";
|
25
|
+
var type = "module";
|
26
|
+
var version = "2.2.7-alpha.3";
|
27
|
+
var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
|
28
|
+
var author = "YiJie <yijie4188@gmail.com>";
|
29
|
+
var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
|
30
|
+
var repository = {
|
31
|
+
url: "nwylzw/jiek",
|
32
|
+
directory: "packages/jiek"
|
33
|
+
};
|
34
|
+
var bugs = "https://github.com/NWYLZW/jiek/issues?q=is%3Aissue+is%3Aopen+jiek";
|
35
|
+
var keywords = [
|
36
|
+
"cli",
|
37
|
+
"zero-config",
|
38
|
+
"bundler",
|
39
|
+
"library",
|
40
|
+
"monorepo",
|
41
|
+
"builder",
|
42
|
+
"rollup",
|
43
|
+
"workspace"
|
44
|
+
];
|
45
|
+
var exports$1 = {
|
46
|
+
"./package.json": "./package.json",
|
47
|
+
".": "./src/index.ts",
|
48
|
+
"./bin-helper": {
|
49
|
+
require: "./bin-helper/index.cjs",
|
50
|
+
"default": "./bin-helper/index.js"
|
51
|
+
},
|
52
|
+
"./rollup": "./src/rollup/index.ts"
|
53
|
+
};
|
54
|
+
var imports = {
|
55
|
+
"#~/*": "./src/*.ts"
|
56
|
+
};
|
57
|
+
var bin = {
|
58
|
+
jiek: "bin/index.cjs",
|
59
|
+
jk: "bin/index.cjs",
|
60
|
+
"jiek-build": "bin/build.cjs",
|
61
|
+
jb: "bin/build.cjs"
|
62
|
+
};
|
63
|
+
var files = [
|
64
|
+
"LICENSE",
|
65
|
+
"README.md",
|
66
|
+
"bin",
|
67
|
+
"bin-helper",
|
68
|
+
"dist",
|
69
|
+
"src"
|
70
|
+
];
|
71
|
+
var scripts = {
|
72
|
+
prepublish: "jb -nm && jk",
|
73
|
+
postpublish: "jk",
|
74
|
+
test: "vitest run"
|
75
|
+
};
|
76
|
+
var peerDependencies = {
|
77
|
+
"@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0||>=1000.0.0",
|
78
|
+
"@rollup/plugin-terser": "^0.4.4",
|
79
|
+
"esbuild-register": "^3.5.0",
|
80
|
+
postcss: "^8.4.47",
|
81
|
+
"rollup-plugin-esbuild": "^6.1.0",
|
82
|
+
"rollup-plugin-postcss": "^4.0.2",
|
83
|
+
"rollup-plugin-swc3": "^0.12.1",
|
84
|
+
typescript: "^4.0.0||^5.0.0",
|
85
|
+
"vite-bundle-analyzer": "0.16.0-beta.3"
|
86
|
+
};
|
87
|
+
var dependencies = {
|
88
|
+
"@inquirer/prompts": "^7.2.0",
|
89
|
+
"@jiek/pkger": "workspace:^",
|
90
|
+
"@jiek/rollup-plugin-dts": "^6.3.8",
|
91
|
+
"@jiek/utils": "workspace:^",
|
92
|
+
"@rollup/plugin-commonjs": "^28.0.0",
|
93
|
+
"@rollup/plugin-inject": "^5.0.5",
|
94
|
+
"@rollup/plugin-json": "^6.0.1",
|
95
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
96
|
+
"cli-progress": "^3.12.0",
|
97
|
+
commander: "^12.0.0",
|
98
|
+
"detect-indent": "^6.1.0",
|
99
|
+
execa: "~9.3.1",
|
100
|
+
"js-yaml": "^4.1.0",
|
101
|
+
"jsonc-parser": "^3.2.1",
|
102
|
+
koa: "^2.15.3",
|
103
|
+
rollup: "^4.0.0"
|
104
|
+
};
|
105
|
+
var devDependencies = {
|
106
|
+
"@npm/types": "^1.0.2",
|
107
|
+
"@pnpm/filter-workspace-packages": "^7.2.13",
|
108
|
+
"@pnpm/workspace.pkgs-graph": "^2.0.15",
|
109
|
+
"@rollup/plugin-terser": "^0.4.4",
|
110
|
+
"@types/cli-progress": "^3.11.5",
|
111
|
+
"@types/inquirer": "^9.0.7",
|
112
|
+
"@types/js-yaml": "^4.0.9",
|
113
|
+
"@types/koa": "^2.15.0",
|
114
|
+
"@types/micromatch": "^4.0.6",
|
115
|
+
"@types/react": "^18.3.14",
|
116
|
+
"esbuild-register": "^3.5.0",
|
117
|
+
micromatch: "^4.0.5",
|
118
|
+
"node-sass": "^9.0.0",
|
119
|
+
postcss: "^8.4.47",
|
120
|
+
"rollup-plugin-esbuild": "^6.1.0",
|
121
|
+
"rollup-plugin-postcss": "^4.0.2",
|
122
|
+
"rollup-plugin-swc3": "^0.12.1",
|
123
|
+
"vite-bundle-analyzer": "0.16.0-beta.3"
|
124
|
+
};
|
125
|
+
var publishConfig = {
|
126
|
+
directory: "./dist/.internal"
|
127
|
+
};
|
128
|
+
var pkg = {
|
129
|
+
name: name,
|
130
|
+
type: type,
|
131
|
+
version: version,
|
132
|
+
description: description$1,
|
133
|
+
author: author,
|
134
|
+
homepage: homepage,
|
135
|
+
repository: repository,
|
136
|
+
bugs: bugs,
|
137
|
+
keywords: keywords,
|
138
|
+
exports: exports$1,
|
139
|
+
imports: imports,
|
140
|
+
bin: bin,
|
141
|
+
files: files,
|
142
|
+
scripts: scripts,
|
143
|
+
peerDependencies: peerDependencies,
|
144
|
+
dependencies: dependencies,
|
145
|
+
devDependencies: devDependencies,
|
146
|
+
publishConfig: publishConfig
|
147
|
+
};
|
148
|
+
|
149
|
+
const entriesDescription = `
|
150
|
+
Specify the build entry-points of the package.json's 'exports' field.
|
151
|
+
Support glob pattern and array.
|
152
|
+
.e.g. '.', './*', './sub/*', './a,./b'.
|
153
|
+
`.trim();
|
154
|
+
const filterDescription = `
|
155
|
+
Filter the packages from the workspace.
|
156
|
+
Support fuzzy match and array.
|
157
|
+
.e.g. 'core,utils'.
|
158
|
+
`.trim();
|
159
|
+
const outdirDescription = `
|
160
|
+
The output directory of the build, which relative to the target subpackage root directory.
|
161
|
+
Support with variables: 'PKG_NAME',
|
162
|
+
.e.g. 'dist/{{PKG_NAME}}'.
|
163
|
+
`.trim();
|
164
|
+
|
165
|
+
const { notWorkspace } = filterSupport.getWD();
|
166
|
+
const IS_WORKSPACE = !notWorkspace;
|
167
|
+
|
168
|
+
commander.program.name("jk/jiek").version(pkg.version).description(`${pkg.description} - Version ${pkg.version}`).option("-c, --config-path <configPath>", "Custom jiek config path").option("--env.<name>=<value>", "Set the environment variable.");
|
169
|
+
if (filterSupport.type !== "" && IS_WORKSPACE) {
|
170
|
+
commander.program.option("-f, --filter <filter>", filterDescription);
|
171
|
+
}
|
172
|
+
|
173
|
+
function Main() {
|
174
|
+
const { useState, useMemo, useEffect, useCallback } = React;
|
175
|
+
const [path, setPath] = useState(() => location.pathname.replace(/^\/ana\/?/, ""));
|
176
|
+
const [pkgName, entry] = useMemo(() => {
|
177
|
+
const pkgName2 = /^(@[^/]+\/[^/]+|[^/]+)\/?/.exec(path)?.[1];
|
178
|
+
return [
|
179
|
+
pkgName2,
|
180
|
+
pkgName2 != null ? path.replace(`${pkgName2}/`, "") : void 0
|
181
|
+
];
|
182
|
+
}, [path]);
|
183
|
+
const push = useCallback((newPath) => {
|
184
|
+
setPath(newPath);
|
185
|
+
document.title = `${document.title.replace(/ - \/.*/, "")} - /${newPath}`;
|
186
|
+
history.pushState(null, "", `/ana/${newPath}`);
|
187
|
+
}, []);
|
188
|
+
const filterModules = useCallback((startWith) => {
|
189
|
+
const modules = analyzeModule.filter((m) => m.filename.startsWith(startWith));
|
190
|
+
dispatchEvent(new CustomEvent("send:filter", { detail: { analyzeModule: modules } }));
|
191
|
+
}, []);
|
192
|
+
useEffect(() => {
|
193
|
+
if (path !== "") {
|
194
|
+
document.title = `${document.title.replace(/ - \/.*/, "")} - /${path}`;
|
195
|
+
} else {
|
196
|
+
document.title = document.title.replace(/ - \/.*/, "");
|
197
|
+
}
|
198
|
+
filterModules(path);
|
199
|
+
}, [path, filterModules]);
|
200
|
+
useEffect(() => {
|
201
|
+
const offGraphClick = listen("graph:click", ({ detail }) => {
|
202
|
+
if (!detail) return;
|
203
|
+
let root = detail.node;
|
204
|
+
while (root.parent) {
|
205
|
+
root = root.parent;
|
206
|
+
}
|
207
|
+
if (root.filename === path) return;
|
208
|
+
push(root.filename);
|
209
|
+
});
|
210
|
+
return () => {
|
211
|
+
offGraphClick();
|
212
|
+
};
|
213
|
+
}, [push]);
|
214
|
+
function listen(type, listener) {
|
215
|
+
window.addEventListener(type, listener);
|
216
|
+
return () => {
|
217
|
+
window.removeEventListener(type, listener);
|
218
|
+
};
|
219
|
+
}
|
220
|
+
return /* @__PURE__ */ React.createElement(
|
221
|
+
"div",
|
222
|
+
{
|
223
|
+
style: {
|
224
|
+
padding: "12px 55px"
|
225
|
+
}
|
226
|
+
},
|
227
|
+
"/",
|
228
|
+
/* @__PURE__ */ React.createElement(
|
229
|
+
"select",
|
230
|
+
{
|
231
|
+
style: {
|
232
|
+
appearance: "none",
|
233
|
+
border: "none",
|
234
|
+
background: "none"
|
235
|
+
},
|
236
|
+
value: pkgName,
|
237
|
+
onChange: (e) => push(e.target.value)
|
238
|
+
},
|
239
|
+
/* @__PURE__ */ React.createElement("option", { value: "" }, "All"),
|
240
|
+
analyzeModule.map((m) => /^(@[^/]+\/[^/]+|[^/]+)\/?/.exec(m.filename)?.[1]).filter((v, i, a) => a.indexOf(v) === i).map((v) => /* @__PURE__ */ React.createElement("option", { key: v, value: v }, v))
|
241
|
+
),
|
242
|
+
pkgName != null && /* @__PURE__ */ React.createElement(React.Fragment, null, "/", /* @__PURE__ */ React.createElement(
|
243
|
+
"select",
|
244
|
+
{
|
245
|
+
style: {
|
246
|
+
appearance: "none",
|
247
|
+
border: "none",
|
248
|
+
background: "none"
|
249
|
+
},
|
250
|
+
value: entry,
|
251
|
+
onChange: (e) => push(`${pkgName}/${e.target.value}`)
|
252
|
+
},
|
253
|
+
/* @__PURE__ */ React.createElement("option", { value: "" }, "All"),
|
254
|
+
analyzeModule.filter((m) => m.filename.startsWith(`${pkgName}/`)).map((m) => m.filename.replace(`${pkgName}/`, "")).filter((v, i, a) => a.indexOf(v) === i).map((v) => /* @__PURE__ */ React.createElement("option", { key: v, value: v }, v))
|
255
|
+
))
|
256
|
+
);
|
257
|
+
}
|
258
|
+
|
259
|
+
function render() {
|
260
|
+
CUSTOM_SIDE_BAR = true;
|
261
|
+
window.addEventListener("client:ready", () => window.dispatchEvent(
|
262
|
+
new CustomEvent("send:ui", {
|
263
|
+
detail: { type: "Main", Component: __REPLACE_INJECT__ }
|
264
|
+
})
|
265
|
+
));
|
266
|
+
}
|
267
|
+
const CLIENT_CUSTOM_RENDER_SCRIPT = [
|
268
|
+
Main.toString(),
|
269
|
+
render.toString().replace("__REPLACE_INJECT__", Main.name),
|
270
|
+
`(${render.name})()`
|
271
|
+
].join("\n");
|
272
|
+
|
273
|
+
function parseBoolean(v) {
|
274
|
+
if (v === void 0) return true;
|
275
|
+
return Boolean(v);
|
276
|
+
}
|
277
|
+
|
278
|
+
async function checkDependency(dependency) {
|
279
|
+
try {
|
280
|
+
filterSupport.require.resolve(dependency);
|
281
|
+
} catch {
|
282
|
+
console.error(`The package '${dependency}' is not installed, please install it first.`);
|
283
|
+
const { notWorkspace } = filterSupport.getWD();
|
284
|
+
const command = `pnpm add -${notWorkspace ? "" : "w"}D ${dependency}`;
|
285
|
+
if (await prompts.confirm({ message: `Do you want to add it now? (${command})` })) {
|
286
|
+
node_child_process.execSync(command, {
|
287
|
+
stdio: "inherit",
|
288
|
+
cwd: process__default.default.cwd(),
|
289
|
+
env: process__default.default.env
|
290
|
+
});
|
291
|
+
} else {
|
292
|
+
console.warn(`You can run the command '${command}' to install it manually.`);
|
293
|
+
process__default.default.exit(1);
|
294
|
+
}
|
295
|
+
}
|
296
|
+
}
|
297
|
+
|
298
|
+
const registerAnalyzerCommandOptions = (command) => command.option("--ana", "Enable the bundle analyzer.", parseBoolean).option("--ana.dir <DIR>", "The directory of the bundle analyzer.", ".jk-analyses").option(
|
299
|
+
"--ana.mode <MODE>",
|
300
|
+
'The mode of the bundle analyzer, support "static", "json" and "server".',
|
301
|
+
"server"
|
302
|
+
).option("--ana.open", "Open the bundle analyzer in the browser.", parseBoolean).option(
|
303
|
+
"--ana.size <SIZE>",
|
304
|
+
'The default size of the bundle analyzer, support "stat", "parsed" and "gzip".',
|
305
|
+
"parsed"
|
306
|
+
);
|
307
|
+
const useAnalyzer = async (options, server) => {
|
308
|
+
const modules = [];
|
309
|
+
let bundleAnalyzerModule;
|
310
|
+
const analyzer = options.ana ? {
|
311
|
+
dir: options["ana.dir"],
|
312
|
+
mode: options["ana.mode"],
|
313
|
+
open: options["ana.open"],
|
314
|
+
size: options["ana.size"]
|
315
|
+
} : void 0;
|
316
|
+
if (options.ana && ![
|
317
|
+
"stat",
|
318
|
+
"parsed",
|
319
|
+
"gzip"
|
320
|
+
].includes(analyzer?.size ?? "")) {
|
321
|
+
throw new Error('The value of `ana.size` must be "stat", "parsed" or "gzip"');
|
322
|
+
}
|
323
|
+
if (analyzer) {
|
324
|
+
await checkDependency("vite-bundle-analyzer");
|
325
|
+
bundleAnalyzerModule = await import('vite-bundle-analyzer');
|
326
|
+
}
|
327
|
+
const refreshAnalyzer = async (cwd, applyModules) => {
|
328
|
+
if (!(analyzer && server && bundleAnalyzerModule)) return;
|
329
|
+
if (analyzer.mode === "json") {
|
330
|
+
const anaDir = path__default.default.resolve(cwd, analyzer.dir);
|
331
|
+
if (!fs.existsSync(anaDir)) {
|
332
|
+
fs.mkdirSync(anaDir, { recursive: true });
|
333
|
+
}
|
334
|
+
const gitIgnorePath = path__default.default.resolve(anaDir, ".gitignore");
|
335
|
+
if (!fs.existsSync(gitIgnorePath)) {
|
336
|
+
fs.writeFileSync(gitIgnorePath, "*\n!.gitignore\n");
|
337
|
+
}
|
338
|
+
const npmIgnorePath = path__default.default.resolve(anaDir, ".npmignore");
|
339
|
+
if (!fs.existsSync(npmIgnorePath)) {
|
340
|
+
fs.writeFileSync(npmIgnorePath, "*\n");
|
341
|
+
}
|
342
|
+
if (!fs.statSync(anaDir).isDirectory()) {
|
343
|
+
throw new Error(`The directory '${anaDir}' is not a directory.`);
|
344
|
+
}
|
345
|
+
}
|
346
|
+
const { renderView, injectHTMLTag } = bundleAnalyzerModule;
|
347
|
+
applyModules.forEach((m) => {
|
348
|
+
const index = modules.findIndex(({ filename }) => filename === m.filename);
|
349
|
+
if (index === -1) {
|
350
|
+
modules.push(m);
|
351
|
+
} else {
|
352
|
+
modules[index] = m;
|
353
|
+
}
|
354
|
+
});
|
355
|
+
let html = await renderView(modules, {
|
356
|
+
title: `Jiek Analyzer`,
|
357
|
+
mode: analyzer.size
|
358
|
+
});
|
359
|
+
html = injectHTMLTag({
|
360
|
+
html,
|
361
|
+
injectTo: "body",
|
362
|
+
descriptors: [
|
363
|
+
{ kind: "script", text: CLIENT_CUSTOM_RENDER_SCRIPT }
|
364
|
+
]
|
365
|
+
});
|
366
|
+
void server.renderTo("/ana", html);
|
367
|
+
};
|
368
|
+
return {
|
369
|
+
modules,
|
370
|
+
refreshAnalyzer,
|
371
|
+
ANALYZER_ENV: {
|
372
|
+
JIEK_ANALYZER: analyzer ? JSON.stringify(analyzer) : void 0
|
373
|
+
}
|
374
|
+
};
|
375
|
+
};
|
376
|
+
|
377
|
+
const createServer = (port, host) => {
|
378
|
+
const app = new Koa__default.default();
|
379
|
+
app.listen(port, host);
|
380
|
+
const streams = /* @__PURE__ */ new Map();
|
381
|
+
app.use(async (ctx) => {
|
382
|
+
let stream = streams.get(ctx.path);
|
383
|
+
if (stream == null) {
|
384
|
+
const maybeKey = streams.keys().find((p) => ctx.path.startsWith(p));
|
385
|
+
stream = maybeKey != null ? streams.get(maybeKey) : void 0;
|
386
|
+
}
|
387
|
+
if (stream != null) {
|
388
|
+
ctx.body = stream;
|
389
|
+
}
|
390
|
+
});
|
391
|
+
return {
|
392
|
+
port,
|
393
|
+
host,
|
394
|
+
rootUrl: `http://${host}:${port}`,
|
395
|
+
renderTo: async (path, stream) => {
|
396
|
+
streams.set(path, stream);
|
397
|
+
}
|
398
|
+
};
|
399
|
+
};
|
400
|
+
|
401
|
+
const FILE_TEMPLATE = (manifest) => `
|
402
|
+
module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
|
403
|
+
`.trimStart();
|
404
|
+
const ROLLUP_BIN = filterSupport.require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
405
|
+
const isDefault = process__default.default.env.JIEK_BIN__FILENAME === "build.cjs";
|
406
|
+
const description = `
|
407
|
+
Build the package according to the 'exports' field from the package.json.
|
408
|
+
If you want to through the options to the \`rollup\` command, you can pass the options after '--'.
|
409
|
+
${isDefault ? "This command is the default command." : ""}
|
410
|
+
`.trim();
|
411
|
+
let DEFAULT_BUILDER_TYPE;
|
412
|
+
Object.entries(base.BUILDER_TYPE_PACKAGE_NAME_MAP).forEach(([type, packageName]) => {
|
413
|
+
try {
|
414
|
+
filterSupport.require.resolve(packageName);
|
415
|
+
DEFAULT_BUILDER_TYPE = type;
|
416
|
+
} catch {
|
417
|
+
}
|
418
|
+
});
|
419
|
+
if (!DEFAULT_BUILDER_TYPE) {
|
420
|
+
DEFAULT_BUILDER_TYPE = "esbuild";
|
421
|
+
}
|
422
|
+
const buildFilterDescription = `
|
423
|
+
${filterDescription}
|
424
|
+
If you pass the --filter option, it will merge into the filters of the command.
|
425
|
+
`.trim();
|
426
|
+
const buildEntriesDescription = `
|
427
|
+
${entriesDescription}
|
428
|
+
If you pass the --entries option, it will merge into the entries of the command.
|
429
|
+
`.trim();
|
430
|
+
let command = isDefault ? (() => {
|
431
|
+
const c = commander.program.name("jb/jiek-build").helpCommand(false);
|
432
|
+
if (IS_WORKSPACE) {
|
433
|
+
c.argument("[filters]", buildFilterDescription);
|
434
|
+
} else {
|
435
|
+
c.argument("[entries]", buildEntriesDescription);
|
436
|
+
}
|
437
|
+
return c;
|
438
|
+
})() : commander.program.command(`build [${IS_WORKSPACE ? "filters" : "entries"}]`);
|
439
|
+
command = command.description(description).option("-t, --type <TYPE>", `The type of build, support ${base.BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}.`, (v) => {
|
440
|
+
if (!base.BUILDER_TYPES.includes(v)) {
|
441
|
+
throw new Error(`The value of 'type' must be ${base.BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}`);
|
442
|
+
}
|
443
|
+
return String(v);
|
444
|
+
}, "esbuild").option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").option("-e, --entries <ENTRIES>", entriesDescription).option("--external <EXTERNAL>", "Specify the external dependencies of the package.", String).option("--noConvert", "Specify the `crossModuleConvertor` option to false.", parseBoolean).option("-nj, --noJs", "Do not output js files.", parseBoolean).option("-nd, --noDts", "Do not output dts files.", parseBoolean).option("-nm, --noMin", "Do not output minify files.", parseBoolean).option(
|
445
|
+
"--minType <MINTYPE>",
|
446
|
+
'The type of minify, support "builder" and "terser".',
|
447
|
+
(v) => {
|
448
|
+
if (!["builder", "terser"].includes(v)) {
|
449
|
+
throw new Error('The value of `minType` must be "builder" or "terser"');
|
450
|
+
}
|
451
|
+
return String(v);
|
452
|
+
}
|
453
|
+
).option("-nc, --noClean", "Do not clean the output directory before building.", parseBoolean).option(
|
454
|
+
"-om, --onlyMin",
|
455
|
+
"Only output minify files, but dts files will still be output, it only replaces the js files.",
|
456
|
+
parseBoolean
|
457
|
+
);
|
458
|
+
command = command.option("--features.keepImportAttributes", "Keep the import attributes in the output.");
|
459
|
+
command = command.option("--tsconfig <TSCONFIG>", "The path of the tsconfig file which is used to generate js and dts files.", String).option("--dtsconfig <DTSCONFIG>", "The path of the tsconfig file which is used to generate dts files.", String);
|
460
|
+
command = command.option("-w, --watch", "Watch the file changes.", parseBoolean).option("-p, --port <PORT>", "The port of the server.", Number.parseInt, 8888);
|
461
|
+
command = registerAnalyzerCommandOptions(command);
|
462
|
+
command = command.option("-s, --silent", "Don't display logs.", parseBoolean).option("-v, --verbose", "Display debug logs.", parseBoolean);
|
463
|
+
command.action(async (commandFiltersOrEntries, options) => {
|
464
|
+
let {
|
465
|
+
type,
|
466
|
+
outdir,
|
467
|
+
watch,
|
468
|
+
silent,
|
469
|
+
verbose,
|
470
|
+
entries: optionEntries,
|
471
|
+
external,
|
472
|
+
noConvert,
|
473
|
+
noJs: withoutJs,
|
474
|
+
noDts: withoutDts,
|
475
|
+
noMin: withoutMin,
|
476
|
+
minType: minifyType,
|
477
|
+
noClean,
|
478
|
+
onlyMin,
|
479
|
+
tsconfig,
|
480
|
+
dtsconfig
|
481
|
+
} = options;
|
482
|
+
const resolvedType = type ?? DEFAULT_BUILDER_TYPE;
|
483
|
+
if (!withoutJs) {
|
484
|
+
await checkDependency(base.BUILDER_TYPE_PACKAGE_NAME_MAP[resolvedType]);
|
485
|
+
if (minifyType === "builder") {
|
486
|
+
minifyType = resolvedType;
|
487
|
+
}
|
488
|
+
}
|
489
|
+
if (!withoutMin && minifyType === "terser") {
|
490
|
+
await checkDependency("@rollup/plugin-terser");
|
491
|
+
}
|
492
|
+
let shouldPassThrough = false;
|
493
|
+
const passThroughOptions = process__default.default.argv.reduce(
|
494
|
+
(acc, value) => {
|
495
|
+
if (shouldPassThrough) {
|
496
|
+
acc.push(value);
|
497
|
+
}
|
498
|
+
if (value === "--") {
|
499
|
+
shouldPassThrough = true;
|
500
|
+
}
|
501
|
+
return acc;
|
502
|
+
},
|
503
|
+
[]
|
504
|
+
);
|
505
|
+
const shouldCreateServer = [
|
506
|
+
options.ana === true && options["ana.mode"] === "server"
|
507
|
+
].some(Boolean);
|
508
|
+
const server = shouldCreateServer ? createServer(options.port, "localhost") : void 0;
|
509
|
+
const {
|
510
|
+
ANALYZER_ENV,
|
511
|
+
refreshAnalyzer
|
512
|
+
} = await useAnalyzer(options, server);
|
513
|
+
const { build } = loadConfig.loadConfig();
|
514
|
+
silent = silent ?? build?.silent ?? false;
|
515
|
+
if (withoutMin && onlyMin) {
|
516
|
+
throw new Error("Cannot use both --without-minify and --only-minify");
|
517
|
+
}
|
518
|
+
if (onlyMin && withoutJs) {
|
519
|
+
throw new Error("Cannot use --without-js and --only-minify at the same time");
|
520
|
+
}
|
521
|
+
let entries = [
|
522
|
+
optionEntries,
|
523
|
+
IS_WORKSPACE ? void 0 : commandFiltersOrEntries
|
524
|
+
].filter(Boolean).join(",");
|
525
|
+
if (entries.length === 0) {
|
526
|
+
entries = void 0;
|
527
|
+
}
|
528
|
+
const env = {
|
529
|
+
...ANALYZER_ENV,
|
530
|
+
JIEK_BUILDER: type,
|
531
|
+
JIEK_OUT_DIR: outdir,
|
532
|
+
JIEK_CLEAN: String(!noClean),
|
533
|
+
JIEK_ENTRIES: entries,
|
534
|
+
JIEK_EXTERNAL: external,
|
535
|
+
JIEK_CROSS_MODULE_CONVERTOR: String(!noConvert),
|
536
|
+
JIEK_WITHOUT_JS: String(withoutJs),
|
537
|
+
JIEK_WITHOUT_DTS: String(withoutDts),
|
538
|
+
JIEK_WITHOUT_MINIFY: String(withoutMin),
|
539
|
+
JIEK_ONLY_MINIFY: String(onlyMin),
|
540
|
+
JIEK_MINIFY_TYPE: minifyType,
|
541
|
+
JIEK_TSCONFIG: tsconfig,
|
542
|
+
JIEK_DTSCONFIG: dtsconfig,
|
543
|
+
JIEK_FEATURES: JSON.stringify({
|
544
|
+
keepImportAttributes: options["features.keepImportAttributes"]
|
545
|
+
}),
|
546
|
+
...process__default.default.env
|
547
|
+
};
|
548
|
+
const multiBars = new cliProgress.MultiBar({
|
549
|
+
clearOnComplete: false,
|
550
|
+
hideCursor: true,
|
551
|
+
format: "- {bar} | {status} | {pkgName} | {input} | {message}"
|
552
|
+
}, cliProgress.Presets.shades_classic);
|
553
|
+
const { wd } = filterSupport.getWD();
|
554
|
+
const wdNodeModules = path__default.default.resolve(wd, "node_modules");
|
555
|
+
if (!fs.existsSync(wdNodeModules)) {
|
556
|
+
fs.mkdirSync(wdNodeModules);
|
557
|
+
}
|
558
|
+
const resolveByJiekTemp = (...paths) => path__default.default.resolve(wdNodeModules, ".jiek", ...paths);
|
559
|
+
const jiekTemp = resolveByJiekTemp();
|
560
|
+
if (!fs.existsSync(jiekTemp)) {
|
561
|
+
try {
|
562
|
+
fs.mkdirSync(jiekTemp);
|
563
|
+
} catch (e) {
|
564
|
+
if (e.code !== "EEXIST") {
|
565
|
+
throw e;
|
566
|
+
}
|
567
|
+
}
|
568
|
+
}
|
569
|
+
let i = 0;
|
570
|
+
const buildPackage = async ([pkgCWD, manifest], {
|
571
|
+
resolveByJiekTemp: resolveByJiekTemp2
|
572
|
+
}) => {
|
573
|
+
if (manifest.name == null) {
|
574
|
+
throw new Error("package.json must have a name field");
|
575
|
+
}
|
576
|
+
const escapeManifestName = manifest.name.replace(/^@/g, "").replace(/\//g, "+");
|
577
|
+
const configFile = resolveByJiekTemp2(
|
578
|
+
`${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
|
579
|
+
);
|
580
|
+
fs.writeFileSync(configFile, FILE_TEMPLATE(manifest));
|
581
|
+
const command2 = [ROLLUP_BIN, "--silent", "-c", configFile];
|
582
|
+
if (loadConfig.tsRegisterName != null) {
|
583
|
+
command2.unshift(`node -r ${loadConfig.tsRegisterName}`);
|
584
|
+
}
|
585
|
+
if (watch) {
|
586
|
+
command2.push("--watch");
|
587
|
+
}
|
588
|
+
command2.push(...passThroughOptions);
|
589
|
+
const child = execa.execaCommand(command2.join(" "), {
|
590
|
+
ipc: true,
|
591
|
+
cwd: pkgCWD,
|
592
|
+
windowsHide: true,
|
593
|
+
env: {
|
594
|
+
...env,
|
595
|
+
JIEK_NAME: manifest.name,
|
596
|
+
JIEK_ROOT: wd
|
597
|
+
}
|
598
|
+
});
|
599
|
+
const bars = {};
|
600
|
+
const times = {};
|
601
|
+
const locks = {};
|
602
|
+
let inputMaxLen = 10;
|
603
|
+
child.on("message", (e) => {
|
604
|
+
if (silent && [
|
605
|
+
"init",
|
606
|
+
"progress",
|
607
|
+
"watchChange"
|
608
|
+
].includes(e.type)) return;
|
609
|
+
switch (e.type) {
|
610
|
+
case "init": {
|
611
|
+
const { leafMap, targetsLength } = e.data;
|
612
|
+
const leafs = Array.from(leafMap.entries()).flatMap(
|
613
|
+
([input, pathAndConditions]) => pathAndConditions.map(([path2, ...conditions]) => ({
|
614
|
+
input,
|
615
|
+
path: path2,
|
616
|
+
conditions
|
617
|
+
}))
|
618
|
+
);
|
619
|
+
let initMessage = `Package '${manifest.name}' has ${targetsLength} targets to build`;
|
620
|
+
if (watch) {
|
621
|
+
initMessage += " and watching...";
|
622
|
+
}
|
623
|
+
console.log(initMessage);
|
624
|
+
leafs.forEach(({ input }) => {
|
625
|
+
inputMaxLen = Math.max(inputMaxLen, input.length);
|
626
|
+
});
|
627
|
+
leafs.forEach(({ input, path: path2 }) => {
|
628
|
+
const key = `${input}:${path2}`;
|
629
|
+
if (bars[key]) return;
|
630
|
+
bars[key] = multiBars.create(50, 0, {
|
631
|
+
pkgName: manifest.name,
|
632
|
+
input: input.padEnd(inputMaxLen + 5),
|
633
|
+
status: "waiting".padEnd(10)
|
634
|
+
}, {
|
635
|
+
barsize: 20,
|
636
|
+
linewrap: true
|
637
|
+
});
|
638
|
+
});
|
639
|
+
break;
|
640
|
+
}
|
641
|
+
case "progress": {
|
642
|
+
const {
|
643
|
+
path: path2,
|
644
|
+
tags,
|
645
|
+
input,
|
646
|
+
event,
|
647
|
+
message
|
648
|
+
} = e.data;
|
649
|
+
const bar = bars[`${input}:${path2}`];
|
650
|
+
if (!bar) return;
|
651
|
+
const time = times[`${input}:${path2}`];
|
652
|
+
bar.update(
|
653
|
+
{
|
654
|
+
start: 0,
|
655
|
+
resolve: 20,
|
656
|
+
end: 50
|
657
|
+
}[event ?? "start"] ?? 0,
|
658
|
+
{
|
659
|
+
input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
|
660
|
+
status: event?.padEnd(10),
|
661
|
+
message: `${tags?.join(", ")}: ${message}`
|
662
|
+
}
|
663
|
+
);
|
664
|
+
break;
|
665
|
+
}
|
666
|
+
case "watchChange": {
|
667
|
+
const {
|
668
|
+
path: path2,
|
669
|
+
input
|
670
|
+
} = e.data;
|
671
|
+
const key = `${input}:${path2}`;
|
672
|
+
const bar = bars[key];
|
673
|
+
if (!bar) return;
|
674
|
+
let time = times[key] ?? 1;
|
675
|
+
if (!locks[key]) {
|
676
|
+
time += 1;
|
677
|
+
times[key] = time;
|
678
|
+
setTimeout(() => {
|
679
|
+
locks[key] = false;
|
680
|
+
}, 100);
|
681
|
+
bar.update(0, {
|
682
|
+
input: `${input}(x${time.toString().padStart(2, "0")})`.padEnd(inputMaxLen + 5),
|
683
|
+
status: "watching".padEnd(10),
|
684
|
+
message: "watching..."
|
685
|
+
});
|
686
|
+
}
|
687
|
+
locks[key] = true;
|
688
|
+
break;
|
689
|
+
}
|
690
|
+
case "modulesAnalyze": {
|
691
|
+
const {
|
692
|
+
data: {
|
693
|
+
type: type2,
|
694
|
+
modules: pkgModules
|
695
|
+
}
|
696
|
+
} = e;
|
697
|
+
void refreshAnalyzer(
|
698
|
+
pkgCWD,
|
699
|
+
pkgModules.map((m) => ({
|
700
|
+
...m,
|
701
|
+
type: type2,
|
702
|
+
filename: `${manifest.name}/${m.filename}`,
|
703
|
+
label: `${manifest.name}/${m.label}`
|
704
|
+
}))
|
705
|
+
);
|
706
|
+
break;
|
707
|
+
}
|
708
|
+
case "debug": {
|
709
|
+
console.log(...Array.isArray(e.data) ? e.data : [e.data]);
|
710
|
+
break;
|
711
|
+
}
|
712
|
+
}
|
713
|
+
});
|
714
|
+
await new Promise((resolve, reject) => {
|
715
|
+
let errorStr = `rollup build failed
|
716
|
+
package name: ${manifest.name}
|
717
|
+
cwd: ${pkgCWD}
|
718
|
+
|
719
|
+
`;
|
720
|
+
child.stderr?.on("data", (data) => {
|
721
|
+
errorStr += data;
|
722
|
+
});
|
723
|
+
child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(errorStr)));
|
724
|
+
verbose && child.stdout?.pipe(process__default.default.stdout);
|
725
|
+
});
|
726
|
+
};
|
727
|
+
const commandFilters = IS_WORKSPACE ? commandFiltersOrEntries : void 0;
|
728
|
+
const filters = [
|
729
|
+
.../* @__PURE__ */ new Set([
|
730
|
+
...commander.program.getOptionValue("filter")?.split(",").map((s) => s.trim()).filter((s) => s.length > 0) ?? [],
|
731
|
+
...commandFilters?.split(",").map((s) => s.trim()).filter((s) => s.length > 0) ?? []
|
732
|
+
])
|
733
|
+
];
|
734
|
+
try {
|
735
|
+
const packages = (filters.length > 0 ? await filterSupport.filterPackagesGraph(filters) : [await filterSupport.getSelectedProjectsGraph()]).flatMap(({ value }) => Object.entries(value ?? {}));
|
736
|
+
await Promise.allSettled(
|
737
|
+
packages.map(async ([cwd, manifest]) => buildPackage([cwd, manifest], { resolveByJiekTemp }))
|
738
|
+
);
|
739
|
+
} finally {
|
740
|
+
multiBars.stop();
|
741
|
+
!silent && console.log("Build complete");
|
742
|
+
}
|
743
|
+
});
|