jiek 2.0.2-alpha.2 → 2.0.2-alpha.3

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