jiek 2.0.2-alpha.5 → 2.0.2-alpha.7

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