jiek 1.1.12 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +53 -106
- package/bin/jiek-build.js +16 -0
- package/dist/cli-only-build.cjs +716 -0
- package/dist/cli-only-build.d.cts +91 -0
- package/dist/cli-only-build.d.ts +91 -0
- package/dist/cli-only-build.js +708 -0
- package/dist/cli.cjs +219 -565
- package/dist/cli.d.cts +0 -65
- package/dist/cli.d.ts +0 -65
- package/dist/cli.js +219 -565
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/rollup/index.cjs +102 -49
- package/dist/rollup/index.js +102 -47
- package/package.json +28 -11
- package/src/cli-only-build.ts +7 -0
- package/src/cli.ts +1 -7
- package/src/commands/base.ts +13 -3
- package/src/commands/build.ts +200 -39
- package/src/commands/descriptions.ts +12 -0
- package/src/commands/meta.ts +5 -0
- package/src/rollup/base.ts +44 -0
- package/src/rollup/index.ts +127 -39
- package/src/utils/filterSupport.ts +2 -6
- package/src/rollup/plugins/globals.ts +0 -34
@@ -0,0 +1,716 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var fs = require('node:fs');
|
4
|
+
var node_module = require('node:module');
|
5
|
+
var path = require('node:path');
|
6
|
+
var filterWorkspacePackages = require('@pnpm/filter-workspace-packages');
|
7
|
+
var commander = require('commander');
|
8
|
+
var jsYaml = require('js-yaml');
|
9
|
+
var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
|
10
|
+
var cliProgress = require('cli-progress');
|
11
|
+
var execa = require('execa');
|
12
|
+
|
13
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
14
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
15
|
+
|
16
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
17
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
18
|
+
|
19
|
+
let root;
|
20
|
+
function getRoot() {
|
21
|
+
if (root)
|
22
|
+
return root;
|
23
|
+
const rootOption = commander.program.getOptionValue("root");
|
24
|
+
root = rootOption ? path__default.default.isAbsolute(rootOption) ? rootOption : path__default.default.resolve(process.cwd(), rootOption) : void 0;
|
25
|
+
return root;
|
26
|
+
}
|
27
|
+
|
28
|
+
let wd;
|
29
|
+
let notWorkspace$1 = false;
|
30
|
+
function getWD() {
|
31
|
+
if (wd)
|
32
|
+
return { wd, notWorkspace: notWorkspace$1 };
|
33
|
+
const root = getRoot();
|
34
|
+
if (root !== void 0) {
|
35
|
+
const isWorkspace = getWorkspaceDir.isWorkspaceDir(root, type$1);
|
36
|
+
notWorkspace$1 = !isWorkspace;
|
37
|
+
wd = root;
|
38
|
+
return { wd, notWorkspace: notWorkspace$1 };
|
39
|
+
}
|
40
|
+
try {
|
41
|
+
wd = getWorkspaceDir.getWorkspaceDir(type$1);
|
42
|
+
} catch (e) {
|
43
|
+
if ("message" in e && e.message === "workspace root not found") {
|
44
|
+
wd = root;
|
45
|
+
notWorkspace$1 = true;
|
46
|
+
} else {
|
47
|
+
throw e;
|
48
|
+
}
|
49
|
+
}
|
50
|
+
return { wd, notWorkspace: notWorkspace$1 };
|
51
|
+
}
|
52
|
+
|
53
|
+
let type$1 = "";
|
54
|
+
try {
|
55
|
+
const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli-only-build.cjs', document.baseURI).href)));
|
56
|
+
require$1.resolve("@pnpm/filter-workspace-packages");
|
57
|
+
type$1 = "pnpm";
|
58
|
+
} catch {
|
59
|
+
}
|
60
|
+
function filterPackagesGraph(filters) {
|
61
|
+
return Promise.all(filters.map(async (filter) => getSelectedProjectsGraph(filter)));
|
62
|
+
}
|
63
|
+
async function getSelectedProjectsGraph(filter = commander.program.getOptionValue("filter")) {
|
64
|
+
let root = getRoot();
|
65
|
+
const { wd, notWorkspace } = getWD();
|
66
|
+
if (notWorkspace) {
|
67
|
+
return {
|
68
|
+
wd,
|
69
|
+
root,
|
70
|
+
value: {
|
71
|
+
[wd]: JSON.parse(fs__default.default.readFileSync(path__default.default.resolve(wd, "package.json"), "utf-8"))
|
72
|
+
}
|
73
|
+
};
|
74
|
+
}
|
75
|
+
if (type$1 === "pnpm") {
|
76
|
+
const pnpmWorkspaceFilePath = path__default.default.resolve(wd, "pnpm-workspace.yaml");
|
77
|
+
const pnpmWorkspaceFileContent = fs__default.default.readFileSync(pnpmWorkspaceFilePath, "utf-8");
|
78
|
+
const pnpmWorkspace = jsYaml.load(pnpmWorkspaceFileContent);
|
79
|
+
if (root === wd && !filter) {
|
80
|
+
throw new Error("root path is workspace root, please provide a filter");
|
81
|
+
}
|
82
|
+
if (root === void 0) {
|
83
|
+
root = process.cwd();
|
84
|
+
}
|
85
|
+
if (root !== wd && !filter) {
|
86
|
+
const packageJSONIsExist = fs__default.default.existsSync(path__default.default.resolve(root, "package.json"));
|
87
|
+
if (!packageJSONIsExist) {
|
88
|
+
throw new Error("root path is not workspace root, please provide a filter");
|
89
|
+
}
|
90
|
+
const packageJSON = JSON.parse(fs__default.default.readFileSync(path__default.default.resolve(root, "package.json"), "utf-8"));
|
91
|
+
if (!packageJSON.name) {
|
92
|
+
throw new Error("root path is not workspace root, please provide a filter");
|
93
|
+
}
|
94
|
+
filter = packageJSON.name;
|
95
|
+
}
|
96
|
+
const { selectedProjectsGraph } = await filterWorkspacePackages.filterPackagesFromDir(wd, [{
|
97
|
+
filter: filter ?? "",
|
98
|
+
followProdDepsOnly: true
|
99
|
+
}], {
|
100
|
+
prefix: root,
|
101
|
+
workspaceDir: wd,
|
102
|
+
patterns: pnpmWorkspace.packages
|
103
|
+
});
|
104
|
+
return {
|
105
|
+
wd,
|
106
|
+
root,
|
107
|
+
value: Object.entries(selectedProjectsGraph).reduce((acc, [key, value]) => {
|
108
|
+
acc[key] = value.package.manifest;
|
109
|
+
return acc;
|
110
|
+
}, {})
|
111
|
+
};
|
112
|
+
}
|
113
|
+
throw new Error(`not supported package manager ${type$1}`);
|
114
|
+
}
|
115
|
+
|
116
|
+
var name = "jiek";
|
117
|
+
var type = "module";
|
118
|
+
var version = "2.0.0";
|
119
|
+
var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
|
120
|
+
var author = "YiJie <yijie4188@gmail.com>";
|
121
|
+
var repository = {
|
122
|
+
url: "nwylzw/jiek",
|
123
|
+
directory: "packages/jiek"
|
124
|
+
};
|
125
|
+
var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
|
126
|
+
var bugs = "https://github.com/NWYLZW/jiek/issues?q=is%3Aissue+is%3Aopen+jiek";
|
127
|
+
var bin = {
|
128
|
+
jiek: "bin/jiek.js",
|
129
|
+
jk: "bin/jiek.js",
|
130
|
+
"jiek-build": "bin/jiek-build.js",
|
131
|
+
jb: "bin/jiek-build.js"
|
132
|
+
};
|
133
|
+
var files = [
|
134
|
+
"dist",
|
135
|
+
"src",
|
136
|
+
"bin",
|
137
|
+
"LICENSE",
|
138
|
+
"README.md"
|
139
|
+
];
|
140
|
+
var scripts = {
|
141
|
+
prepublish: "jb --noMin"
|
142
|
+
};
|
143
|
+
var exports$1 = {
|
144
|
+
"./package.json": "./package.json",
|
145
|
+
".": "./src/index.ts",
|
146
|
+
"./cli": "./src/cli.ts",
|
147
|
+
"./cli-only-build": "./src/cli-only-build.ts",
|
148
|
+
"./rollup": "./src/rollup/index.ts"
|
149
|
+
};
|
150
|
+
var imports = {
|
151
|
+
"#~/*": "./src/*"
|
152
|
+
};
|
153
|
+
var dependencies = {
|
154
|
+
"@jiek/pkger": "workspace:^",
|
155
|
+
"@jiek/rollup-plugin-dts": "^6.2.1",
|
156
|
+
"@jiek/utils": "workspace:^",
|
157
|
+
"@rollup/plugin-commonjs": "^28.0.0",
|
158
|
+
"@rollup/plugin-json": "^6.0.1",
|
159
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
160
|
+
"cli-progress": "^3.12.0",
|
161
|
+
commander: "^12.0.0",
|
162
|
+
"detect-indent": "^6.1.0",
|
163
|
+
execa: "9.3.1",
|
164
|
+
inquirer: "^8.2.6",
|
165
|
+
"js-yaml": "^4.1.0",
|
166
|
+
"jsonc-parser": "^3.2.1",
|
167
|
+
rollup: "4.13.2"
|
168
|
+
};
|
169
|
+
var optionalDependencies = {
|
170
|
+
"@rollup/plugin-terser": "^0.4.4",
|
171
|
+
"@pnpm/filter-workspace-packages": "^7.2.13",
|
172
|
+
"esbuild-register": "^3.5.0",
|
173
|
+
postcss: "^8.4.47",
|
174
|
+
"rollup-plugin-postcss": "^4.0.2",
|
175
|
+
"rollup-plugin-esbuild": "^6.1.0",
|
176
|
+
"rollup-plugin-swc3": "^0.12.1",
|
177
|
+
typescript: "^4.0.0||^5.0.0"
|
178
|
+
};
|
179
|
+
var devDependencies = {
|
180
|
+
"@npm/types": "^1.0.2",
|
181
|
+
"@pnpm/filter-workspace-packages": "^7.2.13",
|
182
|
+
"@pnpm/workspace.pkgs-graph": "^2.0.15",
|
183
|
+
"@rollup/plugin-terser": "^0.4.4",
|
184
|
+
"@types/cli-progress": "^3.11.5",
|
185
|
+
"@types/inquirer": "^9.0.7",
|
186
|
+
"@types/js-yaml": "^4.0.9",
|
187
|
+
"@types/micromatch": "^4.0.6",
|
188
|
+
"esbuild-register": "^3.5.0",
|
189
|
+
micromatch: "^4.0.5",
|
190
|
+
"node-sass": "^9.0.0",
|
191
|
+
postcss: "^8.4.47",
|
192
|
+
"rollup-plugin-postcss": "^4.0.2",
|
193
|
+
"rollup-plugin-esbuild": "^6.1.0",
|
194
|
+
"rollup-plugin-swc3": "^0.12.1"
|
195
|
+
};
|
196
|
+
var publishConfig = {
|
197
|
+
exports: {
|
198
|
+
"./package.json": "./package.json",
|
199
|
+
".": {
|
200
|
+
source: "./src/index.ts",
|
201
|
+
require: "./dist/index.cjs",
|
202
|
+
"default": "./dist/index.js"
|
203
|
+
},
|
204
|
+
"./cli": {
|
205
|
+
source: "./src/cli.ts",
|
206
|
+
require: "./dist/cli.cjs",
|
207
|
+
"default": "./dist/cli.js"
|
208
|
+
},
|
209
|
+
"./cli-only-build": {
|
210
|
+
source: "./src/cli-only-build.ts",
|
211
|
+
require: "./dist/cli-only-build.cjs",
|
212
|
+
"default": "./dist/cli-only-build.js"
|
213
|
+
},
|
214
|
+
"./rollup": {
|
215
|
+
source: "./src/rollup/index.ts",
|
216
|
+
require: "./dist/rollup/index.cjs",
|
217
|
+
"default": "./dist/rollup/index.js"
|
218
|
+
}
|
219
|
+
},
|
220
|
+
main: "./dist/index.cjs",
|
221
|
+
module: "./dist/index.js",
|
222
|
+
typesVersions: {
|
223
|
+
"<5.0": {
|
224
|
+
"*": [
|
225
|
+
"*",
|
226
|
+
"./dist/*",
|
227
|
+
"./dist/*/index.d.ts",
|
228
|
+
"./dist/*/index.d.mts",
|
229
|
+
"./dist/*/index.d.cts"
|
230
|
+
]
|
231
|
+
}
|
232
|
+
}
|
233
|
+
};
|
234
|
+
var pkg = {
|
235
|
+
name: name,
|
236
|
+
type: type,
|
237
|
+
version: version,
|
238
|
+
description: description$1,
|
239
|
+
author: author,
|
240
|
+
repository: repository,
|
241
|
+
homepage: homepage,
|
242
|
+
bugs: bugs,
|
243
|
+
bin: bin,
|
244
|
+
files: files,
|
245
|
+
scripts: scripts,
|
246
|
+
exports: exports$1,
|
247
|
+
imports: imports,
|
248
|
+
dependencies: dependencies,
|
249
|
+
optionalDependencies: optionalDependencies,
|
250
|
+
devDependencies: devDependencies,
|
251
|
+
publishConfig: publishConfig
|
252
|
+
};
|
253
|
+
|
254
|
+
const entriesDescription = `
|
255
|
+
Specify the build entry-points of the package.json's 'exports' field.
|
256
|
+
Support glob pattern and array.
|
257
|
+
.e.g. '.', './*', './sub/*', './a,./b'.
|
258
|
+
`.trim();
|
259
|
+
const filterDescription = `
|
260
|
+
Filter the packages from the workspace.
|
261
|
+
Support fuzzy match and array.
|
262
|
+
.e.g. 'core,utils'.
|
263
|
+
`.trim();
|
264
|
+
const outdirDescription = `
|
265
|
+
The output directory of the build, which relative to the target subpackage root directory.
|
266
|
+
Support with variables: 'PKG_NAME',
|
267
|
+
.e.g. 'dist/{{PKG_NAME}}'.
|
268
|
+
`.trim();
|
269
|
+
|
270
|
+
const { notWorkspace } = getWD();
|
271
|
+
const IS_WORKSPACE = !notWorkspace;
|
272
|
+
|
273
|
+
commander.program.name("jk/jiek").version(pkg.version).description(`${pkg.description} - Version ${pkg.version}`).option("--root <root>", "The root path of the project").option("-c, --config-path <configPath>", "Custom jiek config path");
|
274
|
+
if (type$1 !== "" && IS_WORKSPACE) {
|
275
|
+
commander.program.option("-f, --filter <filter>", filterDescription);
|
276
|
+
}
|
277
|
+
|
278
|
+
const require$3 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli-only-build.cjs', document.baseURI).href)));
|
279
|
+
function packageIsExist(name) {
|
280
|
+
try {
|
281
|
+
require$3.resolve(name);
|
282
|
+
return true;
|
283
|
+
} catch (e) {
|
284
|
+
return false;
|
285
|
+
}
|
286
|
+
}
|
287
|
+
let tsRegisterName;
|
288
|
+
const registers = [
|
289
|
+
process.env.JIEK_TS_REGISTER,
|
290
|
+
"esbuild-register",
|
291
|
+
"@swc-node/register",
|
292
|
+
"ts-node/register"
|
293
|
+
].filter(Boolean);
|
294
|
+
for (const register of registers) {
|
295
|
+
if (packageIsExist(register)) {
|
296
|
+
tsRegisterName = register;
|
297
|
+
break;
|
298
|
+
}
|
299
|
+
}
|
300
|
+
|
301
|
+
const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli-only-build.cjs', document.baseURI).href)));
|
302
|
+
let configName = "jiek.config";
|
303
|
+
function getConfigPath(root, dir) {
|
304
|
+
const isSupportTsLoader = !!tsRegisterName;
|
305
|
+
function configWithExtIsExist(ext) {
|
306
|
+
const filenames = [
|
307
|
+
path__default.default.resolve(process.cwd(), `${configName}.${ext}`),
|
308
|
+
path__default.default.resolve(process.cwd(), `.${configName}.${ext}`),
|
309
|
+
path__default.default.resolve(root, `${configName}.${ext}`),
|
310
|
+
path__default.default.resolve(root, `.${configName}.${ext}`)
|
311
|
+
];
|
312
|
+
if (dir) {
|
313
|
+
filenames.unshift(...[
|
314
|
+
path__default.default.resolve(dir, `${configName}.${ext}`),
|
315
|
+
path__default.default.resolve(dir, `.${configName}.${ext}`)
|
316
|
+
]);
|
317
|
+
}
|
318
|
+
for (const filename of filenames) {
|
319
|
+
if (fs__default.default.existsSync(filename) && fs__default.default.lstatSync(filename).isFile()) {
|
320
|
+
return filename;
|
321
|
+
}
|
322
|
+
}
|
323
|
+
return;
|
324
|
+
}
|
325
|
+
configName = configWithExtIsExist("js") ?? configName;
|
326
|
+
configName = configWithExtIsExist("json") ?? configName;
|
327
|
+
configName = configWithExtIsExist("yaml") ?? configName;
|
328
|
+
if (isSupportTsLoader) {
|
329
|
+
configName = configWithExtIsExist("ts") ?? configName;
|
330
|
+
}
|
331
|
+
return path__default.default.resolve(root, configName);
|
332
|
+
}
|
333
|
+
function loadConfig(dirOrOptions) {
|
334
|
+
let dir;
|
335
|
+
let root;
|
336
|
+
if (typeof dirOrOptions === "object") {
|
337
|
+
dir = dirOrOptions.dir;
|
338
|
+
root = dirOrOptions.root ?? getWD().wd;
|
339
|
+
} else {
|
340
|
+
dir = dirOrOptions;
|
341
|
+
root = getWD().wd;
|
342
|
+
}
|
343
|
+
let configPath = commander.program.getOptionValue("configPath");
|
344
|
+
if (!configPath) {
|
345
|
+
configPath = getConfigPath(root, dir);
|
346
|
+
} else {
|
347
|
+
if (!fs__default.default.existsSync(configPath)) {
|
348
|
+
throw new Error(`config file not found: ${configPath}`);
|
349
|
+
}
|
350
|
+
if (!path__default.default.isAbsolute(configPath)) {
|
351
|
+
configPath = path__default.default.resolve(root, configPath);
|
352
|
+
}
|
353
|
+
}
|
354
|
+
const ext = path__default.default.extname(configPath);
|
355
|
+
let module;
|
356
|
+
switch (ext) {
|
357
|
+
case ".js":
|
358
|
+
module = require$2(configPath);
|
359
|
+
break;
|
360
|
+
case ".json":
|
361
|
+
return require$2(configPath);
|
362
|
+
case ".yaml":
|
363
|
+
return jsYaml.load(fs__default.default.readFileSync(configPath, "utf-8"));
|
364
|
+
case ".ts":
|
365
|
+
if (tsRegisterName) {
|
366
|
+
require$2(tsRegisterName);
|
367
|
+
module = require$2(configPath);
|
368
|
+
break;
|
369
|
+
}
|
370
|
+
throw new Error(
|
371
|
+
"ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register"
|
372
|
+
);
|
373
|
+
case ".config":
|
374
|
+
module = {};
|
375
|
+
break;
|
376
|
+
default:
|
377
|
+
throw new Error(`unsupported config file type: ${ext}`);
|
378
|
+
}
|
379
|
+
if (!module)
|
380
|
+
throw new Error("config file is empty");
|
381
|
+
return module.default ?? module;
|
382
|
+
}
|
383
|
+
|
384
|
+
const BUILDER_TYPES = ["esbuild", "swc"];
|
385
|
+
const BUILDER_TYPE_PACKAGE_NAME_MAP = {
|
386
|
+
esbuild: "rollup-plugin-esbuild",
|
387
|
+
swc: "rollup-plugin-swc3"
|
388
|
+
};
|
389
|
+
|
390
|
+
const FILE_TEMPLATE = (manifest) => `
|
391
|
+
module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
|
392
|
+
`.trimStart();
|
393
|
+
const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli-only-build.cjs', document.baseURI).href)));
|
394
|
+
const isDefault = process.env.JIEK_IS_ONLY_BUILD === "true";
|
395
|
+
const description = `
|
396
|
+
Build the package according to the 'exports' field from the package.json.
|
397
|
+
If you want to rewrite the \`rollup\` command options, you can pass the options after '--'.
|
398
|
+
${isDefault ? "This command is the default command." : ""}
|
399
|
+
`.trim();
|
400
|
+
async function checkDependency(dependency) {
|
401
|
+
try {
|
402
|
+
require$1.resolve(dependency);
|
403
|
+
} catch (e) {
|
404
|
+
console.error(`The package '${dependency}' is not installed, please install it first.`);
|
405
|
+
const answer = prompt("Do you want to install it now? (Y/n)", "Y");
|
406
|
+
const { notWorkspace } = getWD();
|
407
|
+
if (answer === "Y") {
|
408
|
+
await execa.execaCommand(`pnpm install -${notWorkspace ? "" : "w"}D ${dependency}`);
|
409
|
+
} else {
|
410
|
+
return;
|
411
|
+
}
|
412
|
+
}
|
413
|
+
}
|
414
|
+
let DEFAULT_BUILDER_TYPE;
|
415
|
+
Object.entries(BUILDER_TYPE_PACKAGE_NAME_MAP).forEach(([type, packageName]) => {
|
416
|
+
try {
|
417
|
+
require$1.resolve(packageName);
|
418
|
+
DEFAULT_BUILDER_TYPE = type;
|
419
|
+
} catch {
|
420
|
+
}
|
421
|
+
});
|
422
|
+
if (!DEFAULT_BUILDER_TYPE) {
|
423
|
+
DEFAULT_BUILDER_TYPE = "esbuild";
|
424
|
+
}
|
425
|
+
function parseBoolean(v) {
|
426
|
+
if (v === void 0)
|
427
|
+
return true;
|
428
|
+
return Boolean(v);
|
429
|
+
}
|
430
|
+
const buildFilterDescription = `
|
431
|
+
${filterDescription}
|
432
|
+
If you pass the --filter option, it will merge into the filters of the command.
|
433
|
+
`.trim();
|
434
|
+
const buildEntriesDescription = `
|
435
|
+
${entriesDescription}
|
436
|
+
If you pass the --entries option, it will merge into the entries of the command.
|
437
|
+
`.trim();
|
438
|
+
const command = isDefault ? commander.program.name("jb/jiek-build").helpCommand(false) : commander.program;
|
439
|
+
if (IS_WORKSPACE) {
|
440
|
+
if (isDefault) {
|
441
|
+
command.argument("[filters]", buildFilterDescription);
|
442
|
+
} else {
|
443
|
+
command.command("build [filters]");
|
444
|
+
}
|
445
|
+
} else {
|
446
|
+
if (isDefault) {
|
447
|
+
command.argument("[entries]", buildEntriesDescription);
|
448
|
+
} else {
|
449
|
+
command.command("build [entries]");
|
450
|
+
}
|
451
|
+
}
|
452
|
+
command.description(description).option("-t, --type <TYPE>", `The type of build, support ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}.`, (v) => {
|
453
|
+
if (!BUILDER_TYPES.includes(v)) {
|
454
|
+
throw new Error(`The value of 'type' must be ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}`);
|
455
|
+
}
|
456
|
+
return String(v);
|
457
|
+
}, "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("-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(
|
458
|
+
"--minType <MINTYPE>",
|
459
|
+
'The type of minify, support "builder" and "terser".',
|
460
|
+
(v) => {
|
461
|
+
if (!["builder", "terser"].includes(v)) {
|
462
|
+
throw new Error('The value of `minType` must be "builder" or "terser"');
|
463
|
+
}
|
464
|
+
return String(v);
|
465
|
+
}
|
466
|
+
).option("-nc, --noClean", "Do not clean the output directory before building.", parseBoolean).option(
|
467
|
+
"-om, --onlyMin",
|
468
|
+
"Only output minify files, but dts files will still be output, it only replaces the js files.",
|
469
|
+
parseBoolean
|
470
|
+
).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).option("-w, --watch", "Watch the file changes.", parseBoolean).option("-s, --silent", "Don't display logs.", parseBoolean).option("-v, --verbose", "Display debug logs.", parseBoolean).action(async (commandFiltersOrEntries, options) => {
|
471
|
+
let {
|
472
|
+
type,
|
473
|
+
outdir,
|
474
|
+
watch,
|
475
|
+
silent,
|
476
|
+
verbose,
|
477
|
+
entries: optionEntries,
|
478
|
+
external,
|
479
|
+
noJs: withoutJs,
|
480
|
+
noDts: withoutDts,
|
481
|
+
noMin: withoutMin,
|
482
|
+
minType: minifyType,
|
483
|
+
noClean,
|
484
|
+
onlyMin,
|
485
|
+
tsconfig,
|
486
|
+
dtsconfig
|
487
|
+
} = options;
|
488
|
+
const resolvedType = type ?? DEFAULT_BUILDER_TYPE;
|
489
|
+
if (!withoutJs) {
|
490
|
+
await checkDependency(BUILDER_TYPE_PACKAGE_NAME_MAP[resolvedType]);
|
491
|
+
if (minifyType === "builder") {
|
492
|
+
minifyType = resolvedType;
|
493
|
+
}
|
494
|
+
}
|
495
|
+
if (!withoutMin) {
|
496
|
+
await checkDependency(
|
497
|
+
{
|
498
|
+
...BUILDER_TYPE_PACKAGE_NAME_MAP,
|
499
|
+
terser: "@rollup/plugin-terser"
|
500
|
+
}[resolvedType]
|
501
|
+
);
|
502
|
+
}
|
503
|
+
let shouldPassThrough = false;
|
504
|
+
const passThroughOptions = process.argv.reduce(
|
505
|
+
(acc, value) => {
|
506
|
+
if (shouldPassThrough) {
|
507
|
+
acc.push(value);
|
508
|
+
}
|
509
|
+
if (value === "--") {
|
510
|
+
shouldPassThrough = true;
|
511
|
+
}
|
512
|
+
return acc;
|
513
|
+
},
|
514
|
+
[]
|
515
|
+
);
|
516
|
+
const { build } = loadConfig();
|
517
|
+
silent = silent ?? build?.silent ?? false;
|
518
|
+
if (withoutMin && onlyMin) {
|
519
|
+
throw new Error("Cannot use both --without-minify and --only-minify");
|
520
|
+
}
|
521
|
+
if (onlyMin && withoutJs) {
|
522
|
+
throw new Error("Cannot use --without-js and --only-minify at the same time");
|
523
|
+
}
|
524
|
+
let entries = [
|
525
|
+
optionEntries,
|
526
|
+
IS_WORKSPACE ? void 0 : commandFiltersOrEntries
|
527
|
+
].filter(Boolean).join(",");
|
528
|
+
if (entries.length === 0) {
|
529
|
+
entries = void 0;
|
530
|
+
}
|
531
|
+
const env = {
|
532
|
+
...process.env,
|
533
|
+
JIEK_BUILDER: type,
|
534
|
+
JIEK_OUT_DIR: outdir,
|
535
|
+
JIEK_CLEAN: String(!noClean),
|
536
|
+
JIEK_ENTRIES: entries,
|
537
|
+
JIEK_EXTERNAL: external,
|
538
|
+
JIEK_WITHOUT_JS: String(withoutJs),
|
539
|
+
JIEK_WITHOUT_DTS: String(withoutDts),
|
540
|
+
JIEK_WITHOUT_MINIFY: String(withoutMin),
|
541
|
+
JIEK_ONLY_MINIFY: String(onlyMin),
|
542
|
+
JIEK_MINIFY_TYPE: minifyType,
|
543
|
+
JIEK_TSCONFIG: tsconfig,
|
544
|
+
JIEK_DTSCONFIG: dtsconfig
|
545
|
+
};
|
546
|
+
const multiBars = new cliProgress.MultiBar({
|
547
|
+
clearOnComplete: false,
|
548
|
+
hideCursor: true,
|
549
|
+
format: "- {bar} | {status} | {pkgName} | {input} | {message}"
|
550
|
+
}, cliProgress.Presets.shades_classic);
|
551
|
+
const buildPackage = async ({
|
552
|
+
wd,
|
553
|
+
value = {}
|
554
|
+
}) => {
|
555
|
+
if (Object.keys(value).length === 0) {
|
556
|
+
throw new Error("no package found");
|
557
|
+
}
|
558
|
+
const wdNodeModules = path__default.default.resolve(wd, "node_modules");
|
559
|
+
if (!fs__default.default.existsSync(wdNodeModules)) {
|
560
|
+
fs__default.default.mkdirSync(wdNodeModules);
|
561
|
+
}
|
562
|
+
const jiekTempDir = (...paths) => path__default.default.resolve(wdNodeModules, ".jiek", ...paths);
|
563
|
+
if (!fs__default.default.existsSync(jiekTempDir())) {
|
564
|
+
fs__default.default.mkdirSync(jiekTempDir());
|
565
|
+
}
|
566
|
+
const rollupBinaryPath = require$1.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
567
|
+
let i = 0;
|
568
|
+
await Promise.all(
|
569
|
+
Object.entries(value).map(async ([dir, manifest]) => {
|
570
|
+
if (!manifest.name) {
|
571
|
+
throw new Error("package.json must have a name field");
|
572
|
+
}
|
573
|
+
const escapeManifestName = manifest.name.replace(/^@/g, "").replace(/\//g, "+");
|
574
|
+
const configFile = jiekTempDir(
|
575
|
+
`${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
|
576
|
+
);
|
577
|
+
fs__default.default.writeFileSync(configFile, FILE_TEMPLATE(manifest));
|
578
|
+
const command2 = [rollupBinaryPath, "--silent", "-c", configFile];
|
579
|
+
if (tsRegisterName) {
|
580
|
+
command2.unshift(`node -r ${tsRegisterName}`);
|
581
|
+
}
|
582
|
+
if (watch) {
|
583
|
+
command2.push("--watch");
|
584
|
+
}
|
585
|
+
command2.push(...passThroughOptions);
|
586
|
+
const child = execa.execaCommand(command2.join(" "), {
|
587
|
+
ipc: true,
|
588
|
+
cwd: dir,
|
589
|
+
env: {
|
590
|
+
...env,
|
591
|
+
JIEK_NAME: manifest.name,
|
592
|
+
JIEK_ROOT: wd
|
593
|
+
}
|
594
|
+
});
|
595
|
+
const bars = {};
|
596
|
+
const times = {};
|
597
|
+
const locks = {};
|
598
|
+
let inputMaxLen = 10;
|
599
|
+
child.on("message", (e) => {
|
600
|
+
if (e.type === "debug")
|
601
|
+
console.log(...Array.isArray(e.data) ? e.data : [e.data]);
|
602
|
+
});
|
603
|
+
!silent && child.on("message", (e) => {
|
604
|
+
if (e.type === "init") {
|
605
|
+
const { leafMap, targetsLength } = e.data;
|
606
|
+
const leafs = Array.from(leafMap.entries()).flatMap(
|
607
|
+
([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
|
608
|
+
input,
|
609
|
+
path: path2,
|
610
|
+
conditions
|
611
|
+
}))
|
612
|
+
);
|
613
|
+
let initMessage = `Package '${manifest.name}' has ${targetsLength} targets to build`;
|
614
|
+
if (watch) {
|
615
|
+
initMessage += " and watching...";
|
616
|
+
}
|
617
|
+
console.log(initMessage);
|
618
|
+
leafs.forEach(({ input }) => {
|
619
|
+
inputMaxLen = Math.max(inputMaxLen, input.length);
|
620
|
+
});
|
621
|
+
leafs.forEach(({ input, path: path2 }) => {
|
622
|
+
const key = `${input}:${path2}`;
|
623
|
+
if (bars[key])
|
624
|
+
return;
|
625
|
+
bars[key] = multiBars.create(50, 0, {
|
626
|
+
pkgName: manifest.name,
|
627
|
+
input: input.padEnd(inputMaxLen + 5),
|
628
|
+
status: "waiting".padEnd(10)
|
629
|
+
}, {
|
630
|
+
barsize: 20,
|
631
|
+
linewrap: true
|
632
|
+
});
|
633
|
+
});
|
634
|
+
}
|
635
|
+
if (e.type === "progress") {
|
636
|
+
const {
|
637
|
+
path: path2,
|
638
|
+
tags,
|
639
|
+
input,
|
640
|
+
event,
|
641
|
+
message
|
642
|
+
} = e.data;
|
643
|
+
const bar = bars[`${input}:${path2}`];
|
644
|
+
if (!bar)
|
645
|
+
return;
|
646
|
+
const time = times[`${input}:${path2}`];
|
647
|
+
bar.update(
|
648
|
+
{
|
649
|
+
start: 0,
|
650
|
+
resolve: 20,
|
651
|
+
end: 50
|
652
|
+
}[event ?? "start"] ?? 0,
|
653
|
+
{
|
654
|
+
input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
|
655
|
+
status: event?.padEnd(10),
|
656
|
+
message: `${tags?.join(", ")}: ${message}`
|
657
|
+
}
|
658
|
+
);
|
659
|
+
}
|
660
|
+
if (e.type === "watchChange") {
|
661
|
+
const {
|
662
|
+
path: path2,
|
663
|
+
input
|
664
|
+
} = e.data;
|
665
|
+
const key = `${input}:${path2}`;
|
666
|
+
const bar = bars[key];
|
667
|
+
if (!bar)
|
668
|
+
return;
|
669
|
+
let time = times[key] ?? 1;
|
670
|
+
if (!locks[key]) {
|
671
|
+
time += 1;
|
672
|
+
times[key] = time;
|
673
|
+
setTimeout(() => {
|
674
|
+
locks[key] = false;
|
675
|
+
}, 100);
|
676
|
+
bar.update(0, {
|
677
|
+
input: `${input}(x${time.toString().padStart(2, "0")})`.padEnd(inputMaxLen + 5),
|
678
|
+
status: "watching".padEnd(10),
|
679
|
+
message: "watching..."
|
680
|
+
});
|
681
|
+
}
|
682
|
+
locks[key] = true;
|
683
|
+
}
|
684
|
+
});
|
685
|
+
await new Promise((resolve, reject) => {
|
686
|
+
let errorStr = "";
|
687
|
+
child.stderr?.on("data", (data) => {
|
688
|
+
errorStr += data;
|
689
|
+
});
|
690
|
+
child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`rollup build failed:
|
691
|
+
${errorStr}`)));
|
692
|
+
verbose && child.stdout?.pipe(process.stdout);
|
693
|
+
});
|
694
|
+
})
|
695
|
+
);
|
696
|
+
};
|
697
|
+
const commandFilters = IS_WORKSPACE ? commandFiltersOrEntries : void 0;
|
698
|
+
const filters = [
|
699
|
+
.../* @__PURE__ */ new Set([
|
700
|
+
...commander.program.getOptionValue("filter")?.split(",").map((s) => s.trim()).filter((s) => s.length > 0) ?? [],
|
701
|
+
...commandFilters?.split(",").map((s) => s.trim()).filter((s) => s.length > 0) ?? []
|
702
|
+
])
|
703
|
+
];
|
704
|
+
try {
|
705
|
+
if (filters.length > 0) {
|
706
|
+
const packages = await filterPackagesGraph(filters);
|
707
|
+
await Promise.all(packages.map(buildPackage));
|
708
|
+
} else {
|
709
|
+
await buildPackage(await getSelectedProjectsGraph());
|
710
|
+
}
|
711
|
+
} finally {
|
712
|
+
multiBars.stop();
|
713
|
+
}
|
714
|
+
});
|
715
|
+
|
716
|
+
commander.program.parse(process.argv);
|