jiek 2.3.2 → 2.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/dist/.internal/.chunks/{filterSupport.4rM7f6jB.cjs → getWD.Bdo2NGCR.cjs} +30 -30
  2. package/dist/.internal/.chunks/{filterSupport.BXWpLBpT.js → getWD.DGvwAHMY.js} +29 -29
  3. package/dist/.internal/.chunks/{loadConfig.OOKddvHF.cjs → loadConfig.8xhNFEJe.cjs} +30 -12
  4. package/dist/.internal/.chunks/{loadConfig.CFfzkm_p.js → loadConfig.BjzxLOdC.js} +26 -9
  5. package/dist/.internal/bin/common.cjs +92 -97
  6. package/dist/.internal/bin/common.d.cts +2 -0
  7. package/dist/.internal/bin/common.d.ts +2 -0
  8. package/dist/.internal/bin/common.js +93 -98
  9. package/dist/.internal/bin/parseArgv.cjs +2 -2
  10. package/dist/.internal/bin/parseArgv.js +2 -2
  11. package/dist/.internal/commands/utils/createAreaManagement.cjs +108 -0
  12. package/dist/.internal/commands/utils/createAreaManagement.d.cts +18 -0
  13. package/dist/.internal/commands/utils/createAreaManagement.d.ts +18 -0
  14. package/dist/.internal/commands/utils/createAreaManagement.js +106 -0
  15. package/dist/.internal/polyfill.cjs +13 -0
  16. package/dist/.internal/polyfill.d.cts +1 -0
  17. package/dist/.internal/polyfill.d.ts +1 -0
  18. package/dist/.internal/polyfill.js +11 -0
  19. package/dist/.internal/rollup/base.d.cts +27 -4
  20. package/dist/.internal/rollup/base.d.ts +27 -4
  21. package/dist/.internal/utils/filterSupport.cjs +1 -1
  22. package/dist/.internal/utils/filterSupport.js +2 -2
  23. package/dist/.internal/utils/loadConfig.cjs +3 -3
  24. package/dist/.internal/utils/loadConfig.d.cts +1 -0
  25. package/dist/.internal/utils/loadConfig.d.ts +1 -0
  26. package/dist/.internal/utils/loadConfig.js +4 -4
  27. package/dist/.internal/utils/pascalCase.cjs +5 -0
  28. package/dist/.internal/utils/pascalCase.d.cts +3 -0
  29. package/dist/.internal/utils/pascalCase.d.ts +3 -0
  30. package/dist/.internal/utils/pascalCase.js +3 -0
  31. package/dist/.internal/utils/reveal.cjs +9 -0
  32. package/dist/.internal/utils/reveal.d.cts +3 -0
  33. package/dist/.internal/utils/reveal.d.ts +3 -0
  34. package/dist/.internal/utils/reveal.js +7 -0
  35. package/dist/bin/index.cjs +101 -43
  36. package/dist/index.d.cts +7 -0
  37. package/dist/index.d.ts +7 -0
  38. package/dist/rollup/index.cjs +91 -31
  39. package/dist/rollup/index.js +90 -30
  40. package/package.json +6 -2
  41. package/src/bin/build.cts +0 -5
  42. package/src/bin/common.ts +0 -3
  43. package/src/bin/index.cts +0 -7
  44. package/src/bin/parseArgv.ts +0 -26
  45. package/src/bridge.ts +0 -46
  46. package/src/commands/base.ts +0 -18
  47. package/src/commands/build/analyzer.ts +0 -122
  48. package/src/commands/build/client/analyzer.tsx +0 -121
  49. package/src/commands/build/client/index.ts +0 -26
  50. package/src/commands/build.ts +0 -544
  51. package/src/commands/descriptions.ts +0 -17
  52. package/src/commands/meta.ts +0 -5
  53. package/src/commands/publish.ts +0 -628
  54. package/src/commands/utils/optionParser.ts +0 -4
  55. package/src/index.ts +0 -12
  56. package/src/inner.ts +0 -11
  57. package/src/rollup/base.ts +0 -151
  58. package/src/rollup/bundle-analyzer.ts +0 -62
  59. package/src/rollup/index.ts +0 -892
  60. package/src/rollup/plugins/create-require.ts +0 -23
  61. package/src/rollup/plugins/progress.ts +0 -26
  62. package/src/rollup/plugins/replace.ts +0 -96
  63. package/src/rollup/plugins/skip.ts +0 -21
  64. package/src/rollup/plugins/with-external.ts +0 -23
  65. package/src/rollup/utils/commonOptions.ts +0 -9
  66. package/src/rollup/utils/externalResolver.ts +0 -47
  67. package/src/rollup/utils/globalResolver.ts +0 -13
  68. package/src/rollup/utils/withMinify.ts +0 -18
  69. package/src/rollup-plugin-utils.ts +0 -32
  70. package/src/server.ts +0 -30
  71. package/src/utils/checkDependency.ts +0 -26
  72. package/src/utils/filterSupport.ts +0 -90
  73. package/src/utils/getInternalModuleName.ts +0 -5
  74. package/src/utils/getRoot.ts +0 -14
  75. package/src/utils/getWD.ts +0 -31
  76. package/src/utils/intersection.ts +0 -1
  77. package/src/utils/loadConfig.ts +0 -108
  78. package/src/utils/recursiveListFiles.ts +0 -13
  79. package/src/utils/resolveExports.ts +0 -165
  80. package/src/utils/ts.ts +0 -94
  81. package/src/utils/tsRegister.ts +0 -22
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var filterSupport = require('../.chunks/filterSupport.4rM7f6jB.cjs');
4
3
  var commander = require('commander');
4
+ var filterSupport = require('../.chunks/getWD.Bdo2NGCR.cjs');
5
5
  var fs = require('node:fs');
6
6
  var path = require('node:path');
7
7
  var process = require('node:process');
@@ -11,9 +11,9 @@ var node_child_process = require('node:child_process');
11
11
  var prompts = require('@inquirer/prompts');
12
12
  var base = require('../rollup/base.cjs');
13
13
  var Koa = require('koa');
14
- var loadConfig = require('../.chunks/loadConfig.OOKddvHF.cjs');
15
- require('js-yaml');
14
+ var loadConfig = require('../.chunks/loadConfig.8xhNFEJe.cjs');
16
15
  require('@jiek/utils/getWorkspaceDir');
16
+ require('js-yaml');
17
17
  require('node:url');
18
18
  require('node:string_decoder');
19
19
  require('node:util');
@@ -37,8 +37,8 @@ var Koa__default = /*#__PURE__*/_interopDefault(Koa);
37
37
 
38
38
  var name = "jiek";
39
39
  var type = "module";
40
- var version = "2.3.1";
41
- var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
40
+ var version = "2.3.3";
41
+ var description = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
42
42
  var author = "YiJie <yijie4188@gmail.com>";
43
43
  var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
44
44
  var repository = {
@@ -80,8 +80,7 @@ var files = [
80
80
  "README.md",
81
81
  "bin",
82
82
  "bin-helper",
83
- "dist",
84
- "src"
83
+ "dist"
85
84
  ];
86
85
  var scripts = {
87
86
  prepublish: "pnpm test && jb -nm && jk",
@@ -89,6 +88,7 @@ var scripts = {
89
88
  test: "vitest run"
90
89
  };
91
90
  var peerDependencies = {
91
+ "@ast-grep/napi": "^0.32.3",
92
92
  "@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0||>=1000.0.0",
93
93
  "@rollup/plugin-terser": "^0.4.4",
94
94
  "esbuild-register": "^3.5.0",
@@ -118,6 +118,7 @@ var dependencies = {
118
118
  rollup: "^4.0.0"
119
119
  };
120
120
  var devDependencies = {
121
+ "@ast-grep/napi": "^0.32.3",
121
122
  "@npm/types": "^1.0.2",
122
123
  "@pnpm/filter-workspace-packages": "^7.2.13",
123
124
  "@pnpm/workspace.pkgs-graph": "^2.0.15",
@@ -136,13 +137,13 @@ var devDependencies = {
136
137
  "rollup-plugin-esbuild": "^6.1.0",
137
138
  "rollup-plugin-postcss": "^4.0.2",
138
139
  "rollup-plugin-swc3": "^0.12.1",
139
- "vite-bundle-analyzer": "0.16.0-beta.3"
140
+ "vite-bundle-analyzer": "^0.16.0-beta.4"
140
141
  };
141
142
  var pkg = {
142
143
  name: name,
143
144
  type: type,
144
145
  version: version,
145
- description: description$1,
146
+ description: description,
146
147
  author: author,
147
148
  homepage: homepage,
148
149
  repository: repository,
@@ -163,7 +164,7 @@ Specify the build entry-points of the package.json's 'exports' field.
163
164
  Support glob pattern and array.
164
165
  .e.g. '.', './*', './sub/*', './a,./b'.
165
166
  `.trim();
166
- const filterDescription = `
167
+ const filtersDescription = `
167
168
  Filter the packages from the workspace.
168
169
  Support fuzzy match and array.
169
170
  .e.g. 'core,utils'.
@@ -179,7 +180,7 @@ const IS_WORKSPACE = !notWorkspace;
179
180
 
180
181
  commander.program.name("jk/jiek").version(pkg.version).description(`${pkg.description} - Version ${pkg.version}`).option("-c, --config-path <configPath>", "Custom jiek config path").option("--env.<name>=<value>", "Set the environment variable.");
181
182
  if (filterSupport.type !== "" && IS_WORKSPACE) {
182
- commander.program.option("-f, --filter <filter>", filterDescription);
183
+ commander.program.option("-f, --filter <filter>", filtersDescription);
183
184
  }
184
185
 
185
186
  function Main() {
@@ -410,70 +411,20 @@ const createServer = (port, host) => {
410
411
  };
411
412
  };
412
413
 
413
- const FILE_TEMPLATE = (manifest) => `
414
- module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
415
- `.trimStart();
416
- const ROLLUP_BIN = filterSupport.require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
417
- const isDefault = process__default.default.env.JIEK_BIN__FILENAME === "build.cjs";
418
- const description = `
419
- Build the package according to the 'exports' field from the package.json.
420
- If you want to through the options to the \`rollup\` command, you can pass the options after '--'.
421
- ${isDefault ? "This command is the default command." : ""}
422
- `.trim();
423
- let DEFAULT_BUILDER_TYPE;
424
- Object.entries(base.BUILDER_TYPE_PACKAGE_NAME_MAP).forEach(([type, packageName]) => {
425
- try {
426
- filterSupport.require.resolve(packageName);
427
- DEFAULT_BUILDER_TYPE = type;
428
- } catch {
429
- }
430
- });
431
- if (!DEFAULT_BUILDER_TYPE) {
432
- DEFAULT_BUILDER_TYPE = "esbuild";
433
- }
434
- const buildFilterDescription = `
435
- ${filterDescription}
436
- If you pass the --filter option, it will merge into the filters of the command.
437
- `.trim();
438
- const buildEntriesDescription = `
439
- ${entriesDescription}
440
- If you pass the --entries option, it will merge into the entries of the command.
441
- `.trim();
442
- let command = isDefault ? (() => {
443
- const c = commander.program.name("jb/jiek-build").helpCommand(false);
444
- if (IS_WORKSPACE) {
445
- c.argument("[filters]", buildFilterDescription);
446
- } else {
447
- c.argument("[entries]", buildEntriesDescription);
448
- }
449
- return c;
450
- })() : commander.program.command(`build [${IS_WORKSPACE ? "filters" : "entries"}]`);
451
- command = command.description(description).option("-t, --type <TYPE>", `The type of build, support ${base.BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}.`, (v) => {
452
- if (!base.BUILDER_TYPES.includes(v)) {
453
- throw new Error(`The value of 'type' must be ${base.BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}`);
454
- }
455
- return String(v);
456
- }, "esbuild").option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").option("-e, --entries <ENTRIES>", entriesDescription).option("--external <EXTERNAL>", "Specify the external dependencies of the package.", String).option("--noConvert", "Specify the `crossModuleConvertor` option to false.", parseBoolean).option("-nj, --noJs", "Do not output js files.", parseBoolean).option("-nd, --noDts", "Do not output dts files.", parseBoolean).option("-nm, --noMin", "Do not output minify files.", parseBoolean).option(
457
- "--minType <MINTYPE>",
458
- 'The type of minify, support "builder" and "terser".',
459
- (v) => {
460
- if (!["builder", "terser"].includes(v)) {
461
- throw new Error('The value of `minType` must be "builder" or "terser"');
414
+ async function action(filtersOrEntries, options) {
415
+ const FILE_TEMPLATE = (manifest) => `module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})`;
416
+ const ROLLUP_BIN = filterSupport.require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
417
+ let DEFAULT_BUILDER_TYPE;
418
+ Object.entries(base.BUILDER_TYPE_PACKAGE_NAME_MAP).forEach(([type2, packageName]) => {
419
+ try {
420
+ filterSupport.require.resolve(packageName);
421
+ DEFAULT_BUILDER_TYPE = type2;
422
+ } catch {
462
423
  }
463
- return String(v);
424
+ });
425
+ if (!DEFAULT_BUILDER_TYPE) {
426
+ DEFAULT_BUILDER_TYPE = "esbuild";
464
427
  }
465
- ).option("-nc, --noClean", "Do not clean the output directory before building.", parseBoolean).option(
466
- "-om, --onlyMin",
467
- "Only output minify files, but dts files will still be output, it only replaces the js files.",
468
- parseBoolean
469
- );
470
- command = command.option("--skipJS", 'Skip entries which end with ".js".', parseBoolean);
471
- command = command.option("--features.keepImportAttributes", "Keep the import attributes in the output.");
472
- command = command.option("--tsconfig <TSCONFIG>", "The path of the tsconfig file which is used to generate js and dts files.", String).option("--dtsconfig <DTSCONFIG>", "The path of the tsconfig file which is used to generate dts files.", String);
473
- command = command.option("-w, --watch", "Watch the file changes.", parseBoolean).option("-p, --port <PORT>", "The port of the server.", Number.parseInt, 8888);
474
- command = registerAnalyzerCommandOptions(command);
475
- command = command.option("-s, --silent", "Don't display logs.", parseBoolean).option("-v, --verbose", "Display debug logs.", parseBoolean);
476
- command.action(async (commandFiltersOrEntries, options) => {
477
428
  let {
478
429
  type,
479
430
  outdir,
@@ -534,7 +485,7 @@ command.action(async (commandFiltersOrEntries, options) => {
534
485
  }
535
486
  let entries = [
536
487
  optionEntries,
537
- IS_WORKSPACE ? void 0 : commandFiltersOrEntries
488
+ IS_WORKSPACE ? void 0 : filtersOrEntries
538
489
  ].filter(Boolean).join(",");
539
490
  if (entries.length === 0) {
540
491
  entries = void 0;
@@ -561,9 +512,8 @@ command.action(async (commandFiltersOrEntries, options) => {
561
512
  ...process__default.default.env
562
513
  };
563
514
  const multiBars = new cliProgress.MultiBar({
564
- clearOnComplete: false,
565
515
  hideCursor: true,
566
- format: "- {bar} | {status} | {pkgName} | {input} | {message}"
516
+ format: "- {pkgName} | {status} | {input} | {message}"
567
517
  }, cliProgress.Presets.shades_classic);
568
518
  const { wd } = filterSupport.getWD();
569
519
  const wdNodeModules = path__default.default.resolve(wd, "node_modules");
@@ -593,15 +543,15 @@ command.action(async (commandFiltersOrEntries, options) => {
593
543
  `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
594
544
  );
595
545
  fs.writeFileSync(configFile, FILE_TEMPLATE(manifest));
596
- const command2 = [ROLLUP_BIN, "--silent", "-c", configFile];
546
+ const command = [ROLLUP_BIN, "--silent", "-c", configFile];
597
547
  if (loadConfig.tsRegisterName != null) {
598
- command2.unshift(`node -r ${loadConfig.tsRegisterName}`);
548
+ command.unshift(`node -r ${loadConfig.tsRegisterName}`);
599
549
  }
600
550
  if (watch) {
601
- command2.push("--watch");
551
+ command.push("--watch");
602
552
  }
603
- command2.push(...passThroughOptions);
604
- const child = index.execaCommand(command2.join(" "), {
553
+ command.push(...passThroughOptions);
554
+ const child = index.execaCommand(command.join(" "), {
605
555
  ipc: true,
606
556
  cwd: pkgCWD,
607
557
  windowsHide: true,
@@ -642,12 +592,11 @@ command.action(async (commandFiltersOrEntries, options) => {
642
592
  leafs.forEach(({ input, path: path2 }) => {
643
593
  const key = `${input}:${path2}`;
644
594
  if (bars[key]) return;
645
- bars[key] = multiBars.create(50, 0, {
595
+ bars[key] = multiBars.create(0, 0, {
646
596
  pkgName: manifest.name,
647
597
  input: input.padEnd(inputMaxLen + 5),
648
598
  status: "waiting".padEnd(10)
649
599
  }, {
650
- barsize: 20,
651
600
  linewrap: true
652
601
  });
653
602
  });
@@ -664,18 +613,11 @@ command.action(async (commandFiltersOrEntries, options) => {
664
613
  const bar = bars[`${input}:${path2}`];
665
614
  if (!bar) return;
666
615
  const time = times[`${input}:${path2}`];
667
- bar.update(
668
- {
669
- start: 0,
670
- resolve: 20,
671
- end: 50
672
- }[event ?? "start"] ?? 0,
673
- {
674
- input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
675
- status: event?.padEnd(10),
676
- message: `${tags?.join(", ")}: ${message}`
677
- }
678
- );
616
+ bar.update(0, {
617
+ input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
618
+ status: event?.padEnd(10),
619
+ message: `${tags?.join(", ")}: ${message}`
620
+ });
679
621
  break;
680
622
  }
681
623
  case "watchChange": {
@@ -739,7 +681,7 @@ cwd: ${pkgCWD}
739
681
  verbose && child.stdout?.pipe(process__default.default.stdout);
740
682
  });
741
683
  };
742
- const commandFilters = IS_WORKSPACE ? commandFiltersOrEntries : void 0;
684
+ const commandFilters = IS_WORKSPACE ? filtersOrEntries : void 0;
743
685
  const filters = [
744
686
  .../* @__PURE__ */ new Set([
745
687
  ...commander.program.getOptionValue("filter")?.split(",").map((s) => s.trim()).filter((s) => s.length > 0) ?? [],
@@ -755,4 +697,57 @@ cwd: ${pkgCWD}
755
697
  multiBars.stop();
756
698
  !silent && console.log("Build complete");
757
699
  }
758
- });
700
+ }
701
+ function registerCommand() {
702
+ let command = process__default.default.env.JIEK_BIN__FILENAME === "build.cjs" ? (() => {
703
+ const c = commander.program.name("jb/jiek-build").helpCommand(false);
704
+ if (IS_WORKSPACE) {
705
+ c.argument(
706
+ "[filters]",
707
+ `${filtersDescription}
708
+ If you pass the --filter option, it will merge into the filters of the command.`
709
+ );
710
+ } else {
711
+ c.argument(
712
+ "[entries]",
713
+ `${entriesDescription}
714
+ If you pass the --entries option, it will merge into the entries of the command.`
715
+ );
716
+ }
717
+ return c;
718
+ })() : commander.program.command(`build [${IS_WORKSPACE ? "filters" : "entries"}]`);
719
+ command = command.description(`
720
+ Build the package according to the 'exports' field from the package.json.
721
+ If you want to through the options to the \`rollup\` command, you can pass the options after '--'.
722
+ `.trim()).option("-t, --type <TYPE>", `The type of build, support ${base.BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}.`, (v) => {
723
+ if (!base.BUILDER_TYPES.includes(v)) {
724
+ throw new Error(`The value of 'type' must be ${base.BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}`);
725
+ }
726
+ return String(v);
727
+ }, "esbuild").option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").option("-e, --entries <ENTRIES>", entriesDescription).option("--external <EXTERNAL>", "Specify the external dependencies of the package.", String).option("--noConvert", "Specify the `crossModuleConvertor` option to false.", parseBoolean).option("-nj, --noJs", "Do not output js files.", parseBoolean).option("-nd, --noDts", "Do not output dts files.", parseBoolean).option("-nm, --noMin", "Do not output minify files.", parseBoolean).option(
728
+ "--minType <MINTYPE>",
729
+ 'The type of minify, support "builder" and "terser".',
730
+ (v) => {
731
+ if (!["builder", "terser"].includes(v)) {
732
+ throw new Error('The value of `minType` must be "builder" or "terser"');
733
+ }
734
+ return String(v);
735
+ }
736
+ ).option("-nc, --noClean", "Do not clean the output directory before building.", parseBoolean).option(
737
+ "-om, --onlyMin",
738
+ "Only output minify files, but dts files will still be output, it only replaces the js files.",
739
+ parseBoolean
740
+ );
741
+ command = command.option("--skipJS", 'Skip entries which end with ".js".', parseBoolean);
742
+ command = command.option("--features.keepImportAttributes", "Keep the import attributes in the output.");
743
+ command = command.option(
744
+ "--tsconfig <TSCONFIG>",
745
+ "The path of the tsconfig file which is used to generate js and dts files.",
746
+ String
747
+ ).option("--dtsconfig <DTSCONFIG>", "The path of the tsconfig file which is used to generate dts files.", String);
748
+ command = command.option("-w, --watch", "Watch the file changes.", parseBoolean).option("-p, --port <PORT>", "The port of the server.", Number.parseInt, 8888);
749
+ command = registerAnalyzerCommandOptions(command);
750
+ command = command.option("-s, --silent", "Don't display logs.", parseBoolean).option("-v, --verbose", "Display debug logs.", parseBoolean);
751
+ command.action(action);
752
+ }
753
+ registerCommand();
@@ -3,6 +3,8 @@ import '@rollup/plugin-terser';
3
3
  import 'rollup-plugin-swc3';
4
4
  import 'rollup-plugin-esbuild';
5
5
  import 'rollup';
6
+ import '@ast-grep/napi';
7
+ import 'jiek/rollup-plugin-utils';
6
8
 
7
9
  declare module 'jiek' {
8
10
  interface Config {
@@ -3,6 +3,8 @@ import '@rollup/plugin-terser';
3
3
  import 'rollup-plugin-swc3';
4
4
  import 'rollup-plugin-esbuild';
5
5
  import 'rollup';
6
+ import '@ast-grep/napi';
7
+ import 'jiek/rollup-plugin-utils';
6
8
 
7
9
  declare module 'jiek' {
8
10
  interface Config {
@@ -1,5 +1,5 @@
1
- import { g as getWD, t as type$1, r as require, f as filterPackagesGraph, a as getSelectedProjectsGraph } from '../.chunks/filterSupport.BXWpLBpT.js';
2
1
  import { program } from 'commander';
2
+ import { g as getWD, t as type$1, r as require, f as filterPackagesGraph, a as getSelectedProjectsGraph } from '../.chunks/getWD.DGvwAHMY.js';
3
3
  import { existsSync, mkdirSync, writeFileSync, statSync } from 'node:fs';
4
4
  import path from 'node:path';
5
5
  import process from 'node:process';
@@ -7,12 +7,12 @@ import { MultiBar, Presets } from 'cli-progress';
7
7
  import { e as execaCommand } from '../.chunks/index.BHuJRlvZ.js';
8
8
  import { execSync } from 'node:child_process';
9
9
  import { confirm } from '@inquirer/prompts';
10
- import { BUILDER_TYPE_PACKAGE_NAME_MAP, BUILDER_TYPES } from '../rollup/base.js';
10
+ import { BUILDER_TYPES, BUILDER_TYPE_PACKAGE_NAME_MAP } from '../rollup/base.js';
11
11
  import Koa from 'koa';
12
- import { l as loadConfig, t as tsRegisterName } from '../.chunks/loadConfig.CFfzkm_p.js';
12
+ import { l as loadConfig, t as tsRegisterName } from '../.chunks/loadConfig.BjzxLOdC.js';
13
+ import '@jiek/utils/getWorkspaceDir';
13
14
  import 'node:module';
14
15
  import 'js-yaml';
15
- import '@jiek/utils/getWorkspaceDir';
16
16
  import 'node:url';
17
17
  import 'node:string_decoder';
18
18
  import 'node:util';
@@ -30,8 +30,8 @@ import 'node:stream/promises';
30
30
 
31
31
  var name = "jiek";
32
32
  var type = "module";
33
- var version = "2.3.1";
34
- var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
33
+ var version = "2.3.3";
34
+ var description = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
35
35
  var author = "YiJie <yijie4188@gmail.com>";
36
36
  var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
37
37
  var repository = {
@@ -73,8 +73,7 @@ var files = [
73
73
  "README.md",
74
74
  "bin",
75
75
  "bin-helper",
76
- "dist",
77
- "src"
76
+ "dist"
78
77
  ];
79
78
  var scripts = {
80
79
  prepublish: "pnpm test && jb -nm && jk",
@@ -82,6 +81,7 @@ var scripts = {
82
81
  test: "vitest run"
83
82
  };
84
83
  var peerDependencies = {
84
+ "@ast-grep/napi": "^0.32.3",
85
85
  "@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0||>=1000.0.0",
86
86
  "@rollup/plugin-terser": "^0.4.4",
87
87
  "esbuild-register": "^3.5.0",
@@ -111,6 +111,7 @@ var dependencies = {
111
111
  rollup: "^4.0.0"
112
112
  };
113
113
  var devDependencies = {
114
+ "@ast-grep/napi": "^0.32.3",
114
115
  "@npm/types": "^1.0.2",
115
116
  "@pnpm/filter-workspace-packages": "^7.2.13",
116
117
  "@pnpm/workspace.pkgs-graph": "^2.0.15",
@@ -129,13 +130,13 @@ var devDependencies = {
129
130
  "rollup-plugin-esbuild": "^6.1.0",
130
131
  "rollup-plugin-postcss": "^4.0.2",
131
132
  "rollup-plugin-swc3": "^0.12.1",
132
- "vite-bundle-analyzer": "0.16.0-beta.3"
133
+ "vite-bundle-analyzer": "^0.16.0-beta.4"
133
134
  };
134
135
  var pkg = {
135
136
  name: name,
136
137
  type: type,
137
138
  version: version,
138
- description: description$1,
139
+ description: description,
139
140
  author: author,
140
141
  homepage: homepage,
141
142
  repository: repository,
@@ -156,7 +157,7 @@ Specify the build entry-points of the package.json's 'exports' field.
156
157
  Support glob pattern and array.
157
158
  .e.g. '.', './*', './sub/*', './a,./b'.
158
159
  `.trim();
159
- const filterDescription = `
160
+ const filtersDescription = `
160
161
  Filter the packages from the workspace.
161
162
  Support fuzzy match and array.
162
163
  .e.g. 'core,utils'.
@@ -172,7 +173,7 @@ const IS_WORKSPACE = !notWorkspace;
172
173
 
173
174
  program.name("jk/jiek").version(pkg.version).description(`${pkg.description} - Version ${pkg.version}`).option("-c, --config-path <configPath>", "Custom jiek config path").option("--env.<name>=<value>", "Set the environment variable.");
174
175
  if (type$1 !== "" && IS_WORKSPACE) {
175
- program.option("-f, --filter <filter>", filterDescription);
176
+ program.option("-f, --filter <filter>", filtersDescription);
176
177
  }
177
178
 
178
179
  function Main() {
@@ -403,70 +404,20 @@ const createServer = (port, host) => {
403
404
  };
404
405
  };
405
406
 
406
- const FILE_TEMPLATE = (manifest) => `
407
- module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
408
- `.trimStart();
409
- const ROLLUP_BIN = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
410
- const isDefault = process.env.JIEK_BIN__FILENAME === "build.cjs";
411
- const description = `
412
- Build the package according to the 'exports' field from the package.json.
413
- If you want to through the options to the \`rollup\` command, you can pass the options after '--'.
414
- ${isDefault ? "This command is the default command." : ""}
415
- `.trim();
416
- let DEFAULT_BUILDER_TYPE;
417
- Object.entries(BUILDER_TYPE_PACKAGE_NAME_MAP).forEach(([type, packageName]) => {
418
- try {
419
- require.resolve(packageName);
420
- DEFAULT_BUILDER_TYPE = type;
421
- } catch {
422
- }
423
- });
424
- if (!DEFAULT_BUILDER_TYPE) {
425
- DEFAULT_BUILDER_TYPE = "esbuild";
426
- }
427
- const buildFilterDescription = `
428
- ${filterDescription}
429
- If you pass the --filter option, it will merge into the filters of the command.
430
- `.trim();
431
- const buildEntriesDescription = `
432
- ${entriesDescription}
433
- If you pass the --entries option, it will merge into the entries of the command.
434
- `.trim();
435
- let command = isDefault ? (() => {
436
- const c = program.name("jb/jiek-build").helpCommand(false);
437
- if (IS_WORKSPACE) {
438
- c.argument("[filters]", buildFilterDescription);
439
- } else {
440
- c.argument("[entries]", buildEntriesDescription);
441
- }
442
- return c;
443
- })() : program.command(`build [${IS_WORKSPACE ? "filters" : "entries"}]`);
444
- command = command.description(description).option("-t, --type <TYPE>", `The type of build, support ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}.`, (v) => {
445
- if (!BUILDER_TYPES.includes(v)) {
446
- throw new Error(`The value of 'type' must be ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}`);
447
- }
448
- return String(v);
449
- }, "esbuild").option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").option("-e, --entries <ENTRIES>", entriesDescription).option("--external <EXTERNAL>", "Specify the external dependencies of the package.", String).option("--noConvert", "Specify the `crossModuleConvertor` option to false.", parseBoolean).option("-nj, --noJs", "Do not output js files.", parseBoolean).option("-nd, --noDts", "Do not output dts files.", parseBoolean).option("-nm, --noMin", "Do not output minify files.", parseBoolean).option(
450
- "--minType <MINTYPE>",
451
- 'The type of minify, support "builder" and "terser".',
452
- (v) => {
453
- if (!["builder", "terser"].includes(v)) {
454
- throw new Error('The value of `minType` must be "builder" or "terser"');
407
+ async function action(filtersOrEntries, options) {
408
+ const FILE_TEMPLATE = (manifest) => `module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})`;
409
+ const ROLLUP_BIN = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
410
+ let DEFAULT_BUILDER_TYPE;
411
+ Object.entries(BUILDER_TYPE_PACKAGE_NAME_MAP).forEach(([type2, packageName]) => {
412
+ try {
413
+ require.resolve(packageName);
414
+ DEFAULT_BUILDER_TYPE = type2;
415
+ } catch {
455
416
  }
456
- return String(v);
417
+ });
418
+ if (!DEFAULT_BUILDER_TYPE) {
419
+ DEFAULT_BUILDER_TYPE = "esbuild";
457
420
  }
458
- ).option("-nc, --noClean", "Do not clean the output directory before building.", parseBoolean).option(
459
- "-om, --onlyMin",
460
- "Only output minify files, but dts files will still be output, it only replaces the js files.",
461
- parseBoolean
462
- );
463
- command = command.option("--skipJS", 'Skip entries which end with ".js".', parseBoolean);
464
- command = command.option("--features.keepImportAttributes", "Keep the import attributes in the output.");
465
- command = command.option("--tsconfig <TSCONFIG>", "The path of the tsconfig file which is used to generate js and dts files.", String).option("--dtsconfig <DTSCONFIG>", "The path of the tsconfig file which is used to generate dts files.", String);
466
- command = command.option("-w, --watch", "Watch the file changes.", parseBoolean).option("-p, --port <PORT>", "The port of the server.", Number.parseInt, 8888);
467
- command = registerAnalyzerCommandOptions(command);
468
- command = command.option("-s, --silent", "Don't display logs.", parseBoolean).option("-v, --verbose", "Display debug logs.", parseBoolean);
469
- command.action(async (commandFiltersOrEntries, options) => {
470
421
  let {
471
422
  type,
472
423
  outdir,
@@ -527,7 +478,7 @@ command.action(async (commandFiltersOrEntries, options) => {
527
478
  }
528
479
  let entries = [
529
480
  optionEntries,
530
- IS_WORKSPACE ? void 0 : commandFiltersOrEntries
481
+ IS_WORKSPACE ? void 0 : filtersOrEntries
531
482
  ].filter(Boolean).join(",");
532
483
  if (entries.length === 0) {
533
484
  entries = void 0;
@@ -554,9 +505,8 @@ command.action(async (commandFiltersOrEntries, options) => {
554
505
  ...process.env
555
506
  };
556
507
  const multiBars = new MultiBar({
557
- clearOnComplete: false,
558
508
  hideCursor: true,
559
- format: "- {bar} | {status} | {pkgName} | {input} | {message}"
509
+ format: "- {pkgName} | {status} | {input} | {message}"
560
510
  }, Presets.shades_classic);
561
511
  const { wd } = getWD();
562
512
  const wdNodeModules = path.resolve(wd, "node_modules");
@@ -586,15 +536,15 @@ command.action(async (commandFiltersOrEntries, options) => {
586
536
  `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
587
537
  );
588
538
  writeFileSync(configFile, FILE_TEMPLATE(manifest));
589
- const command2 = [ROLLUP_BIN, "--silent", "-c", configFile];
539
+ const command = [ROLLUP_BIN, "--silent", "-c", configFile];
590
540
  if (tsRegisterName != null) {
591
- command2.unshift(`node -r ${tsRegisterName}`);
541
+ command.unshift(`node -r ${tsRegisterName}`);
592
542
  }
593
543
  if (watch) {
594
- command2.push("--watch");
544
+ command.push("--watch");
595
545
  }
596
- command2.push(...passThroughOptions);
597
- const child = execaCommand(command2.join(" "), {
546
+ command.push(...passThroughOptions);
547
+ const child = execaCommand(command.join(" "), {
598
548
  ipc: true,
599
549
  cwd: pkgCWD,
600
550
  windowsHide: true,
@@ -635,12 +585,11 @@ command.action(async (commandFiltersOrEntries, options) => {
635
585
  leafs.forEach(({ input, path: path2 }) => {
636
586
  const key = `${input}:${path2}`;
637
587
  if (bars[key]) return;
638
- bars[key] = multiBars.create(50, 0, {
588
+ bars[key] = multiBars.create(0, 0, {
639
589
  pkgName: manifest.name,
640
590
  input: input.padEnd(inputMaxLen + 5),
641
591
  status: "waiting".padEnd(10)
642
592
  }, {
643
- barsize: 20,
644
593
  linewrap: true
645
594
  });
646
595
  });
@@ -657,18 +606,11 @@ command.action(async (commandFiltersOrEntries, options) => {
657
606
  const bar = bars[`${input}:${path2}`];
658
607
  if (!bar) return;
659
608
  const time = times[`${input}:${path2}`];
660
- bar.update(
661
- {
662
- start: 0,
663
- resolve: 20,
664
- end: 50
665
- }[event ?? "start"] ?? 0,
666
- {
667
- input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
668
- status: event?.padEnd(10),
669
- message: `${tags?.join(", ")}: ${message}`
670
- }
671
- );
609
+ bar.update(0, {
610
+ input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
611
+ status: event?.padEnd(10),
612
+ message: `${tags?.join(", ")}: ${message}`
613
+ });
672
614
  break;
673
615
  }
674
616
  case "watchChange": {
@@ -732,7 +674,7 @@ cwd: ${pkgCWD}
732
674
  verbose && child.stdout?.pipe(process.stdout);
733
675
  });
734
676
  };
735
- const commandFilters = IS_WORKSPACE ? commandFiltersOrEntries : void 0;
677
+ const commandFilters = IS_WORKSPACE ? filtersOrEntries : void 0;
736
678
  const filters = [
737
679
  .../* @__PURE__ */ new Set([
738
680
  ...program.getOptionValue("filter")?.split(",").map((s) => s.trim()).filter((s) => s.length > 0) ?? [],
@@ -748,4 +690,57 @@ cwd: ${pkgCWD}
748
690
  multiBars.stop();
749
691
  !silent && console.log("Build complete");
750
692
  }
751
- });
693
+ }
694
+ function registerCommand() {
695
+ let command = process.env.JIEK_BIN__FILENAME === "build.cjs" ? (() => {
696
+ const c = program.name("jb/jiek-build").helpCommand(false);
697
+ if (IS_WORKSPACE) {
698
+ c.argument(
699
+ "[filters]",
700
+ `${filtersDescription}
701
+ If you pass the --filter option, it will merge into the filters of the command.`
702
+ );
703
+ } else {
704
+ c.argument(
705
+ "[entries]",
706
+ `${entriesDescription}
707
+ If you pass the --entries option, it will merge into the entries of the command.`
708
+ );
709
+ }
710
+ return c;
711
+ })() : program.command(`build [${IS_WORKSPACE ? "filters" : "entries"}]`);
712
+ command = command.description(`
713
+ Build the package according to the 'exports' field from the package.json.
714
+ If you want to through the options to the \`rollup\` command, you can pass the options after '--'.
715
+ `.trim()).option("-t, --type <TYPE>", `The type of build, support ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}.`, (v) => {
716
+ if (!BUILDER_TYPES.includes(v)) {
717
+ throw new Error(`The value of 'type' must be ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}`);
718
+ }
719
+ return String(v);
720
+ }, "esbuild").option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").option("-e, --entries <ENTRIES>", entriesDescription).option("--external <EXTERNAL>", "Specify the external dependencies of the package.", String).option("--noConvert", "Specify the `crossModuleConvertor` option to false.", parseBoolean).option("-nj, --noJs", "Do not output js files.", parseBoolean).option("-nd, --noDts", "Do not output dts files.", parseBoolean).option("-nm, --noMin", "Do not output minify files.", parseBoolean).option(
721
+ "--minType <MINTYPE>",
722
+ 'The type of minify, support "builder" and "terser".',
723
+ (v) => {
724
+ if (!["builder", "terser"].includes(v)) {
725
+ throw new Error('The value of `minType` must be "builder" or "terser"');
726
+ }
727
+ return String(v);
728
+ }
729
+ ).option("-nc, --noClean", "Do not clean the output directory before building.", parseBoolean).option(
730
+ "-om, --onlyMin",
731
+ "Only output minify files, but dts files will still be output, it only replaces the js files.",
732
+ parseBoolean
733
+ );
734
+ command = command.option("--skipJS", 'Skip entries which end with ".js".', parseBoolean);
735
+ command = command.option("--features.keepImportAttributes", "Keep the import attributes in the output.");
736
+ command = command.option(
737
+ "--tsconfig <TSCONFIG>",
738
+ "The path of the tsconfig file which is used to generate js and dts files.",
739
+ String
740
+ ).option("--dtsconfig <DTSCONFIG>", "The path of the tsconfig file which is used to generate dts files.", String);
741
+ command = command.option("-w, --watch", "Watch the file changes.", parseBoolean).option("-p, --port <PORT>", "The port of the server.", Number.parseInt, 8888);
742
+ command = registerAnalyzerCommandOptions(command);
743
+ command = command.option("-s, --silent", "Don't display logs.", parseBoolean).option("-v, --verbose", "Display debug logs.", parseBoolean);
744
+ command.action(action);
745
+ }
746
+ registerCommand();