jiek 2.0.2-alpha.5 → 2.0.2-alpha.6

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