jiek 2.2.7 → 2.3.1

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 (100) hide show
  1. package/bin/build.cjs +2 -0
  2. package/bin/index.cjs +2 -0
  3. package/bin-helper/index.cjs +19 -31
  4. package/dist/.internal/.chunks/filterSupport.4rM7f6jB.cjs +114 -0
  5. package/dist/.internal/.chunks/filterSupport.BXWpLBpT.js +104 -0
  6. package/dist/{cli.js → .internal/.chunks/index.B6RQz1DZ.js} +1 -737
  7. package/dist/.internal/.chunks/index.BHuJRlvZ.js +9059 -0
  8. package/dist/.internal/.chunks/index.Daihq2aI.cjs +9071 -0
  9. package/dist/{cli.cjs → .internal/.chunks/index.DlHFuTjM.cjs} +1 -759
  10. package/dist/.internal/.chunks/loadConfig.CFfzkm_p.js +110 -0
  11. package/dist/.internal/.chunks/loadConfig.OOKddvHF.cjs +117 -0
  12. package/dist/{cli-only-build.cjs → .internal/bin/common.cjs} +229 -445
  13. package/dist/.internal/bin/common.d.cts +22 -0
  14. package/dist/.internal/bin/common.d.ts +22 -0
  15. package/dist/{cli-only-build.js → .internal/bin/common.js} +224 -439
  16. package/dist/.internal/bin/parseArgv.cjs +33 -0
  17. package/dist/.internal/bin/parseArgv.d.cts +5 -0
  18. package/dist/.internal/bin/parseArgv.d.ts +5 -0
  19. package/dist/.internal/bin/parseArgv.js +27 -0
  20. package/dist/.internal/bridge.cjs +30 -0
  21. package/dist/.internal/bridge.d.cts +39 -0
  22. package/dist/.internal/bridge.d.ts +39 -0
  23. package/dist/.internal/bridge.js +27 -0
  24. package/dist/.internal/rollup/base.cjs +10 -0
  25. package/dist/{cli-only-build.d.cts → .internal/rollup/base.d.cts} +8 -15
  26. package/dist/{cli-only-build.d.ts → .internal/rollup/base.d.ts} +8 -15
  27. package/dist/.internal/rollup/base.js +7 -0
  28. package/dist/.internal/rollup/bundle-analyzer.cjs +51 -0
  29. package/dist/.internal/rollup/bundle-analyzer.d.cts +92 -0
  30. package/dist/.internal/rollup/bundle-analyzer.d.ts +92 -0
  31. package/dist/.internal/rollup/bundle-analyzer.js +45 -0
  32. package/dist/.internal/utils/filterSupport.cjs +18 -0
  33. package/dist/.internal/utils/filterSupport.d.cts +15 -0
  34. package/dist/.internal/utils/filterSupport.d.ts +15 -0
  35. package/dist/.internal/utils/filterSupport.js +8 -0
  36. package/dist/.internal/utils/getInternalModuleName.cjs +5 -0
  37. package/dist/.internal/utils/getInternalModuleName.d.cts +3 -0
  38. package/dist/.internal/utils/getInternalModuleName.d.ts +3 -0
  39. package/dist/.internal/utils/getInternalModuleName.js +3 -0
  40. package/dist/.internal/utils/intersection.cjs +5 -0
  41. package/dist/.internal/utils/intersection.d.cts +3 -0
  42. package/dist/.internal/utils/intersection.d.ts +3 -0
  43. package/dist/.internal/utils/intersection.js +3 -0
  44. package/dist/.internal/utils/loadConfig.cjs +14 -0
  45. package/dist/.internal/utils/loadConfig.d.cts +10 -0
  46. package/dist/.internal/utils/loadConfig.d.ts +10 -0
  47. package/dist/.internal/utils/loadConfig.js +9 -0
  48. package/dist/.internal/utils/recursiveListFiles.cjs +19 -0
  49. package/dist/.internal/utils/recursiveListFiles.d.cts +3 -0
  50. package/dist/.internal/utils/recursiveListFiles.d.ts +3 -0
  51. package/dist/.internal/utils/recursiveListFiles.js +13 -0
  52. package/dist/.internal/utils/resolveExports.cjs +124 -0
  53. package/dist/.internal/utils/resolveExports.d.cts +27 -0
  54. package/dist/.internal/utils/resolveExports.d.ts +27 -0
  55. package/dist/.internal/utils/resolveExports.js +117 -0
  56. package/dist/.internal/utils/ts.cjs +68 -0
  57. package/dist/.internal/utils/ts.d.cts +3 -0
  58. package/dist/.internal/utils/ts.d.ts +3 -0
  59. package/dist/.internal/utils/ts.js +62 -0
  60. package/dist/bin/build.cjs +10 -0
  61. package/dist/bin/index.cjs +522 -0
  62. package/dist/index.d.cts +16 -114
  63. package/dist/index.d.ts +16 -114
  64. package/dist/rollup/index.cjs +310 -4573
  65. package/dist/rollup/index.d.cts +7 -1
  66. package/dist/rollup/index.d.ts +7 -1
  67. package/dist/rollup/index.js +298 -4558
  68. package/package.json +16 -24
  69. package/src/bin/build.cts +5 -0
  70. package/src/bin/common.ts +3 -0
  71. package/src/bin/index.cts +7 -0
  72. package/src/bridge.ts +1 -1
  73. package/src/commands/base.ts +3 -3
  74. package/src/commands/build/analyzer.ts +5 -5
  75. package/src/commands/build/client/analyzer.tsx +1 -1
  76. package/src/commands/build/client/index.ts +5 -7
  77. package/src/commands/build.ts +244 -213
  78. package/src/commands/meta.ts +1 -1
  79. package/src/commands/publish.ts +190 -78
  80. package/src/index.ts +6 -1
  81. package/src/rollup/base.ts +2 -2
  82. package/src/rollup/index.ts +361 -124
  83. package/src/rollup/plugins/with-external.ts +23 -0
  84. package/src/rollup/utils/externalResolver.ts +20 -8
  85. package/src/utils/checkDependency.ts +1 -1
  86. package/src/utils/filterSupport.ts +17 -16
  87. package/src/utils/getInternalModuleName.ts +5 -0
  88. package/src/utils/intersection.ts +1 -0
  89. package/src/utils/{recusiveListFiles.ts → recursiveListFiles.ts} +2 -2
  90. package/src/utils/{getExports.ts → resolveExports.ts} +28 -19
  91. package/bin/jiek-build.js +0 -16
  92. package/bin/jiek.js +0 -13
  93. package/cli/package.json +0 -1
  94. package/cli-only-build/package.json +0 -1
  95. package/dist/cli.d.cts +0 -14
  96. package/dist/cli.d.ts +0 -14
  97. package/src/cli-only-build.ts +0 -11
  98. package/src/cli.ts +0 -6
  99. /package/{src/bin/build.ts → .jiek-production-tag} +0 -0
  100. /package/src/{parseArgv.ts → bin/parseArgv.ts} +0 -0
@@ -1,124 +1,43 @@
1
1
  'use strict';
2
2
 
3
+ var filterSupport = require('../.chunks/filterSupport.4rM7f6jB.cjs');
4
+ var commander = require('commander');
3
5
  var fs = require('node:fs');
4
6
  var path = require('node:path');
5
- var commander = require('commander');
6
- var jsYaml = require('js-yaml');
7
- var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
8
- var process$1 = require('node:process');
7
+ var process = require('node:process');
9
8
  var cliProgress = require('cli-progress');
10
- var execa = require('execa');
9
+ var index = require('../.chunks/index.Daihq2aI.cjs');
11
10
  var node_child_process = require('node:child_process');
12
11
  var prompts = require('@inquirer/prompts');
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');
16
+ require('@jiek/utils/getWorkspaceDir');
17
+ require('node:url');
18
+ require('node:string_decoder');
19
+ require('node:util');
20
+ require('node:tty');
21
+ require('child_process');
22
+ require('path');
23
+ require('fs');
24
+ require('node:timers/promises');
25
+ require('node:os');
26
+ require('node:events');
27
+ require('node:v8');
28
+ require('node:stream');
29
+ require('node:buffer');
30
+ require('node:stream/promises');
14
31
 
15
32
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
16
33
 
17
- var fs__default = /*#__PURE__*/_interopDefault(fs);
18
34
  var path__default = /*#__PURE__*/_interopDefault(path);
19
- var process__default = /*#__PURE__*/_interopDefault(process$1);
35
+ var process__default = /*#__PURE__*/_interopDefault(process);
20
36
  var Koa__default = /*#__PURE__*/_interopDefault(Koa);
21
37
 
22
- var require$1 = require;
23
-
24
- let root;
25
- function getRoot() {
26
- if (root) return root;
27
- const rootOption = process.env.JIEK_ROOT;
28
- root = rootOption ? path__default.default.isAbsolute(rootOption) ? rootOption : path__default.default.resolve(process.cwd(), rootOption) : void 0;
29
- return root;
30
- }
31
-
32
- let wd;
33
- let notWorkspace$1 = false;
34
- function getWD() {
35
- if (wd) return { wd, notWorkspace: notWorkspace$1 };
36
- const root = getRoot();
37
- if (root !== void 0) {
38
- const isWorkspace = getWorkspaceDir.isWorkspaceDir(root, type$1);
39
- notWorkspace$1 = !isWorkspace;
40
- wd = root;
41
- return { wd, notWorkspace: notWorkspace$1 };
42
- }
43
- try {
44
- wd = getWorkspaceDir.getWorkspaceDir(type$1);
45
- } catch (e) {
46
- if ("message" in e && e.message === "workspace root not found") {
47
- wd = root ?? process.cwd();
48
- notWorkspace$1 = true;
49
- } else {
50
- throw e;
51
- }
52
- }
53
- return { wd, notWorkspace: notWorkspace$1 };
54
- }
55
-
56
- let type$1 = "";
57
- try {
58
- require$1.resolve("@pnpm/filter-workspace-packages");
59
- type$1 = "pnpm";
60
- } catch {
61
- }
62
- async function filterPackagesGraph(filters) {
63
- return Promise.all(filters.map(async (filter) => getSelectedProjectsGraph(filter)));
64
- }
65
- async function getSelectedProjectsGraph(filter = commander.program.getOptionValue("filter")) {
66
- const { wd, notWorkspace } = getWD();
67
- let root = getRoot();
68
- if (notWorkspace) {
69
- return {
70
- wd,
71
- root,
72
- value: {
73
- [wd]: JSON.parse(fs__default.default.readFileSync(path__default.default.resolve(wd, "package.json"), "utf-8"))
74
- }
75
- };
76
- }
77
- if (type$1 === "pnpm") {
78
- const pnpmWorkspaceFilePath = path__default.default.resolve(wd, "pnpm-workspace.yaml");
79
- const pnpmWorkspaceFileContent = fs__default.default.readFileSync(pnpmWorkspaceFilePath, "utf-8");
80
- const pnpmWorkspace = jsYaml.load(pnpmWorkspaceFileContent);
81
- if (root === wd && !filter) {
82
- throw new Error("root path is workspace root, please provide a filter");
83
- }
84
- if (root === void 0) {
85
- root = process.cwd();
86
- }
87
- if (root !== wd && !filter) {
88
- const packageJSONIsExist = fs__default.default.existsSync(path__default.default.resolve(root, "package.json"));
89
- if (!packageJSONIsExist) {
90
- throw new Error("root path is not workspace root, please provide a filter");
91
- }
92
- const packageJSON = JSON.parse(fs__default.default.readFileSync(path__default.default.resolve(root, "package.json"), "utf-8"));
93
- if (!packageJSON.name) {
94
- throw new Error("root path is not workspace root, please provide a filter");
95
- }
96
- filter = packageJSON.name;
97
- }
98
- const { filterPackagesFromDir } = await import('@pnpm/filter-workspace-packages');
99
- const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{
100
- filter: filter ?? "",
101
- followProdDepsOnly: true
102
- }], {
103
- prefix: root,
104
- workspaceDir: wd,
105
- patterns: pnpmWorkspace.packages
106
- });
107
- return {
108
- wd,
109
- root,
110
- value: Object.entries(selectedProjectsGraph).reduce((acc, [key, value]) => {
111
- acc[key] = value.package.manifest;
112
- return acc;
113
- }, {})
114
- };
115
- }
116
- throw new Error(`not supported package manager ${type$1}`);
117
- }
118
-
119
38
  var name = "jiek";
120
39
  var type = "module";
121
- var version = "2.2.6";
40
+ var version = "2.3.0";
122
41
  var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
123
42
  var author = "YiJie <yijie4188@gmail.com>";
124
43
  var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
@@ -144,22 +63,16 @@ var exports$1 = {
144
63
  require: "./bin-helper/index.cjs",
145
64
  "default": "./bin-helper/index.js"
146
65
  },
147
- "./cli": "./src/cli.ts",
148
- "./cli-only-build": "./src/cli-only-build.ts",
149
66
  "./rollup": "./src/rollup/index.ts"
150
67
  };
151
68
  var imports = {
152
- "#~/*": [
153
- "./src/*",
154
- "./src/*/index.ts",
155
- "./src/*/index.tsx"
156
- ]
69
+ "#~/*": "./src/*.ts"
157
70
  };
158
71
  var bin = {
159
- jiek: "bin/jiek.js",
160
- jk: "bin/jiek.js",
161
- "jiek-build": "bin/jiek-build.js",
162
- jb: "bin/jiek-build.js"
72
+ jiek: "bin/index.cjs",
73
+ jk: "bin/index.cjs",
74
+ "jiek-build": "bin/build.cjs",
75
+ jb: "bin/build.cjs"
163
76
  };
164
77
  var files = [
165
78
  "LICENSE",
@@ -183,12 +96,12 @@ var peerDependencies = {
183
96
  "rollup-plugin-postcss": "^4.0.2",
184
97
  "rollup-plugin-swc3": "^0.12.1",
185
98
  typescript: "^4.0.0||^5.0.0",
186
- "vite-bundle-analyzer": "0.16.0-beta.1"
99
+ "vite-bundle-analyzer": "0.16.0-beta.3"
187
100
  };
188
101
  var dependencies = {
189
102
  "@inquirer/prompts": "^7.2.0",
190
103
  "@jiek/pkger": "workspace:^",
191
- "@jiek/rollup-plugin-dts": "^6.2.1",
104
+ "@jiek/rollup-plugin-dts": "^6.3.8",
192
105
  "@jiek/utils": "workspace:^",
193
106
  "@rollup/plugin-commonjs": "^28.0.0",
194
107
  "@rollup/plugin-inject": "^5.0.5",
@@ -197,7 +110,6 @@ var dependencies = {
197
110
  "cli-progress": "^3.12.0",
198
111
  commander: "^12.0.0",
199
112
  "detect-indent": "^6.1.0",
200
- execa: "~9.3.1",
201
113
  "js-yaml": "^4.1.0",
202
114
  "jsonc-parser": "^3.2.1",
203
115
  koa: "^2.15.3",
@@ -215,13 +127,17 @@ var devDependencies = {
215
127
  "@types/micromatch": "^4.0.6",
216
128
  "@types/react": "^18.3.14",
217
129
  "esbuild-register": "^3.5.0",
130
+ execa: "~9.3.1",
218
131
  micromatch: "^4.0.5",
219
132
  "node-sass": "^9.0.0",
220
133
  postcss: "^8.4.47",
221
134
  "rollup-plugin-esbuild": "^6.1.0",
222
135
  "rollup-plugin-postcss": "^4.0.2",
223
136
  "rollup-plugin-swc3": "^0.12.1",
224
- "vite-bundle-analyzer": "0.16.0-beta.1"
137
+ "vite-bundle-analyzer": "0.16.0-beta.3"
138
+ };
139
+ var publishConfig = {
140
+ directory: "./dist/.internal"
225
141
  };
226
142
  var pkg = {
227
143
  name: name,
@@ -240,7 +156,8 @@ var pkg = {
240
156
  scripts: scripts,
241
157
  peerDependencies: peerDependencies,
242
158
  dependencies: dependencies,
243
- devDependencies: devDependencies
159
+ devDependencies: devDependencies,
160
+ publishConfig: publishConfig
244
161
  };
245
162
 
246
163
  const entriesDescription = `
@@ -259,11 +176,11 @@ Support with variables: 'PKG_NAME',
259
176
  .e.g. 'dist/{{PKG_NAME}}'.
260
177
  `.trim();
261
178
 
262
- const { notWorkspace } = getWD();
179
+ const { notWorkspace } = filterSupport.getWD();
263
180
  const IS_WORKSPACE = !notWorkspace;
264
181
 
265
182
  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.");
266
- if (type$1 !== "" && IS_WORKSPACE) {
183
+ if (filterSupport.type !== "" && IS_WORKSPACE) {
267
184
  commander.program.option("-f, --filter <filter>", filterDescription);
268
185
  }
269
186
 
@@ -355,13 +272,11 @@ function Main() {
355
272
 
356
273
  function render() {
357
274
  CUSTOM_SIDE_BAR = true;
358
- window.addEventListener("client:ready", () => setTimeout(() => {
359
- window.dispatchEvent(
360
- new CustomEvent("send:ui", {
361
- detail: { type: "Main", Component: __REPLACE_INJECT__ }
362
- })
363
- );
364
- }, 0));
275
+ window.addEventListener("client:ready", () => window.dispatchEvent(
276
+ new CustomEvent("send:ui", {
277
+ detail: { type: "Main", Component: __REPLACE_INJECT__ }
278
+ })
279
+ ));
365
280
  }
366
281
  const CLIENT_CUSTOM_RENDER_SCRIPT = [
367
282
  Main.toString(),
@@ -376,10 +291,10 @@ function parseBoolean(v) {
376
291
 
377
292
  async function checkDependency(dependency) {
378
293
  try {
379
- require$1.resolve(dependency);
294
+ filterSupport.require.resolve(dependency);
380
295
  } catch {
381
296
  console.error(`The package '${dependency}' is not installed, please install it first.`);
382
- const { notWorkspace } = getWD();
297
+ const { notWorkspace } = filterSupport.getWD();
383
298
  const command = `pnpm add -${notWorkspace ? "" : "w"}D ${dependency}`;
384
299
  if (await prompts.confirm({ message: `Do you want to add it now? (${command})` })) {
385
300
  node_child_process.execSync(command, {
@@ -473,12 +388,6 @@ const useAnalyzer = async (options, server) => {
473
388
  };
474
389
  };
475
390
 
476
- const BUILDER_TYPES = ["esbuild", "swc"];
477
- const BUILDER_TYPE_PACKAGE_NAME_MAP = {
478
- esbuild: "rollup-plugin-esbuild",
479
- swc: "rollup-plugin-swc3"
480
- };
481
-
482
391
  const createServer = (port, host) => {
483
392
  const app = new Koa__default.default();
484
393
  app.listen(port, host);
@@ -503,119 +412,20 @@ const createServer = (port, host) => {
503
412
  };
504
413
  };
505
414
 
506
- function packageIsExist(name) {
507
- try {
508
- require$1.resolve(name);
509
- return true;
510
- } catch (e) {
511
- return false;
512
- }
513
- }
514
- let tsRegisterName;
515
- const registers = [
516
- process.env.JIEK_TS_REGISTER,
517
- "esbuild-register",
518
- "@swc-node/register",
519
- "ts-node/register"
520
- ].filter(Boolean);
521
- for (const register of registers) {
522
- if (packageIsExist(register)) {
523
- tsRegisterName = register;
524
- break;
525
- }
526
- }
527
-
528
- let configName = "jiek.config";
529
- function getConfigPath(root, dir) {
530
- const isSupportTsLoader = !!tsRegisterName;
531
- function configWithExtIsExist(ext) {
532
- const filenames = [
533
- path__default.default.resolve(process.cwd(), `${configName}.${ext}`),
534
- path__default.default.resolve(process.cwd(), `.${configName}.${ext}`),
535
- path__default.default.resolve(root, `${configName}.${ext}`),
536
- path__default.default.resolve(root, `.${configName}.${ext}`)
537
- ];
538
- if (dir) {
539
- filenames.unshift(...[
540
- path__default.default.resolve(dir, `${configName}.${ext}`),
541
- path__default.default.resolve(dir, `.${configName}.${ext}`)
542
- ]);
543
- }
544
- for (const filename of filenames) {
545
- if (fs__default.default.existsSync(filename) && fs__default.default.lstatSync(filename).isFile()) {
546
- return filename;
547
- }
548
- }
549
- return;
550
- }
551
- configName = configWithExtIsExist("js") ?? configName;
552
- configName = configWithExtIsExist("json") ?? configName;
553
- configName = configWithExtIsExist("yaml") ?? configName;
554
- if (isSupportTsLoader) {
555
- configName = configWithExtIsExist("ts") ?? configName;
556
- }
557
- return path__default.default.resolve(root, configName);
558
- }
559
- function loadConfig(dirOrOptions) {
560
- let dir;
561
- let root;
562
- {
563
- dir = dirOrOptions;
564
- root = getWD().wd;
565
- }
566
- let configPath = commander.program.getOptionValue("configPath");
567
- if (!configPath) {
568
- configPath = getConfigPath(root, dir);
569
- } else {
570
- if (!fs__default.default.existsSync(configPath)) {
571
- throw new Error(`config file not found: ${configPath}`);
572
- }
573
- if (!path__default.default.isAbsolute(configPath)) {
574
- configPath = path__default.default.resolve(root, configPath);
575
- }
576
- }
577
- const ext = path__default.default.extname(configPath);
578
- let module;
579
- switch (ext) {
580
- case ".js":
581
- module = require$1(configPath);
582
- break;
583
- case ".json":
584
- return require$1(configPath);
585
- case ".yaml":
586
- return jsYaml.load(fs__default.default.readFileSync(configPath, "utf-8"));
587
- case ".ts":
588
- if (tsRegisterName) {
589
- require$1(tsRegisterName);
590
- module = require$1(configPath);
591
- break;
592
- }
593
- throw new Error(
594
- "ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register"
595
- );
596
- case ".config":
597
- module = {};
598
- break;
599
- default:
600
- throw new Error(`unsupported config file type: ${ext}`);
601
- }
602
- if (!module) throw new Error("config file is empty");
603
- return module.default ?? module;
604
- }
605
-
606
415
  const FILE_TEMPLATE = (manifest) => `
607
416
  module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
608
417
  `.trimStart();
609
- const isDefault = process__default.default.env.JIEK_IS_ONLY_BUILD === "true";
418
+ const ROLLUP_BIN = filterSupport.require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
419
+ const isDefault = process__default.default.env.JIEK_BIN__FILENAME === "build.cjs";
610
420
  const description = `
611
421
  Build the package according to the 'exports' field from the package.json.
612
422
  If you want to through the options to the \`rollup\` command, you can pass the options after '--'.
613
423
  ${isDefault ? "This command is the default command." : ""}
614
424
  `.trim();
615
425
  let DEFAULT_BUILDER_TYPE;
616
- Object.entries(BUILDER_TYPE_PACKAGE_NAME_MAP).forEach(([type, packageName]) => {
426
+ Object.entries(base.BUILDER_TYPE_PACKAGE_NAME_MAP).forEach(([type, packageName]) => {
617
427
  try {
618
- require$1.resolve(packageName);
428
+ filterSupport.require.resolve(packageName);
619
429
  DEFAULT_BUILDER_TYPE = type;
620
430
  } catch {
621
431
  }
@@ -640,9 +450,9 @@ let command = isDefault ? (() => {
640
450
  }
641
451
  return c;
642
452
  })() : commander.program.command(`build [${IS_WORKSPACE ? "filters" : "entries"}]`);
643
- command = command.description(description).option("-t, --type <TYPE>", `The type of build, support ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}.`, (v) => {
644
- if (!BUILDER_TYPES.includes(v)) {
645
- throw new Error(`The value of 'type' must be ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}`);
453
+ command = command.description(description).option("-t, --type <TYPE>", `The type of build, support ${base.BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}.`, (v) => {
454
+ if (!base.BUILDER_TYPES.includes(v)) {
455
+ throw new Error(`The value of 'type' must be ${base.BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}`);
646
456
  }
647
457
  return String(v);
648
458
  }, "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(
@@ -659,6 +469,8 @@ command = command.description(description).option("-t, --type <TYPE>", `The type
659
469
  "Only output minify files, but dts files will still be output, it only replaces the js files.",
660
470
  parseBoolean
661
471
  );
472
+ command = command.option("--skipJS", 'Skip entries which end with ".js".', parseBoolean);
473
+ command = command.option("--features.keepImportAttributes", "Keep the import attributes in the output.");
662
474
  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);
663
475
  command = command.option("-w, --watch", "Watch the file changes.", parseBoolean).option("-p, --port <PORT>", "The port of the server.", Number.parseInt, 8888);
664
476
  command = registerAnalyzerCommandOptions(command);
@@ -680,11 +492,12 @@ command.action(async (commandFiltersOrEntries, options) => {
680
492
  noClean,
681
493
  onlyMin,
682
494
  tsconfig,
683
- dtsconfig
495
+ dtsconfig,
496
+ skipJS
684
497
  } = options;
685
498
  const resolvedType = type ?? DEFAULT_BUILDER_TYPE;
686
499
  if (!withoutJs) {
687
- await checkDependency(BUILDER_TYPE_PACKAGE_NAME_MAP[resolvedType]);
500
+ await checkDependency(base.BUILDER_TYPE_PACKAGE_NAME_MAP[resolvedType]);
688
501
  if (minifyType === "builder") {
689
502
  minifyType = resolvedType;
690
503
  }
@@ -713,7 +526,7 @@ command.action(async (commandFiltersOrEntries, options) => {
713
526
  ANALYZER_ENV,
714
527
  refreshAnalyzer
715
528
  } = await useAnalyzer(options, server);
716
- const { build } = loadConfig();
529
+ const { build } = loadConfig.loadConfig();
717
530
  silent = silent ?? build?.silent ?? false;
718
531
  if (withoutMin && onlyMin) {
719
532
  throw new Error("Cannot use both --without-minify and --only-minify");
@@ -743,6 +556,10 @@ command.action(async (commandFiltersOrEntries, options) => {
743
556
  JIEK_MINIFY_TYPE: minifyType,
744
557
  JIEK_TSCONFIG: tsconfig,
745
558
  JIEK_DTSCONFIG: dtsconfig,
559
+ JIEK_SKIP_JS: String(skipJS),
560
+ JIEK_FEATURES: JSON.stringify({
561
+ keepImportAttributes: options["features.keepImportAttributes"]
562
+ }),
746
563
  ...process__default.default.env
747
564
  };
748
565
  const multiBars = new cliProgress.MultiBar({
@@ -750,183 +567,179 @@ command.action(async (commandFiltersOrEntries, options) => {
750
567
  hideCursor: true,
751
568
  format: "- {bar} | {status} | {pkgName} | {input} | {message}"
752
569
  }, cliProgress.Presets.shades_classic);
753
- const buildPackage = async ({
754
- wd,
755
- value = {}
570
+ const { wd } = filterSupport.getWD();
571
+ const wdNodeModules = path__default.default.resolve(wd, "node_modules");
572
+ if (!fs.existsSync(wdNodeModules)) {
573
+ fs.mkdirSync(wdNodeModules);
574
+ }
575
+ const resolveByJiekTemp = (...paths) => path__default.default.resolve(wdNodeModules, ".jiek", ...paths);
576
+ const jiekTemp = resolveByJiekTemp();
577
+ if (!fs.existsSync(jiekTemp)) {
578
+ try {
579
+ fs.mkdirSync(jiekTemp);
580
+ } catch (e) {
581
+ if (e.code !== "EEXIST") {
582
+ throw e;
583
+ }
584
+ }
585
+ }
586
+ let i = 0;
587
+ const buildPackage = async ([pkgCWD, manifest], {
588
+ resolveByJiekTemp: resolveByJiekTemp2
756
589
  }) => {
757
- if (Object.keys(value).length === 0) {
758
- throw new Error("no package found");
590
+ if (manifest.name == null) {
591
+ throw new Error("package.json must have a name field");
759
592
  }
760
- const wdNodeModules = path__default.default.resolve(wd, "node_modules");
761
- if (!fs.existsSync(wdNodeModules)) {
762
- fs.mkdirSync(wdNodeModules);
593
+ const escapeManifestName = manifest.name.replace(/^@/g, "").replace(/\//g, "+");
594
+ const configFile = resolveByJiekTemp2(
595
+ `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
596
+ );
597
+ fs.writeFileSync(configFile, FILE_TEMPLATE(manifest));
598
+ const command2 = [ROLLUP_BIN, "--silent", "-c", configFile];
599
+ if (loadConfig.tsRegisterName != null) {
600
+ command2.unshift(`node -r ${loadConfig.tsRegisterName}`);
763
601
  }
764
- const resolveByJiekTemp = (...paths) => path__default.default.resolve(wdNodeModules, ".jiek", ...paths);
765
- const jiekTemp = resolveByJiekTemp();
766
- if (!fs.existsSync(jiekTemp)) {
767
- try {
768
- fs.mkdirSync(jiekTemp);
769
- } catch {
770
- }
602
+ if (watch) {
603
+ command2.push("--watch");
771
604
  }
772
- const rollupBinaryPath = require$1.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
773
- let i = 0;
774
- await Promise.all(
775
- Object.entries(value).map(async ([pkgCWD, manifest]) => {
776
- if (manifest.name == null) {
777
- throw new Error("package.json must have a name field");
778
- }
779
- const escapeManifestName = manifest.name.replace(/^@/g, "").replace(/\//g, "+");
780
- const configFile = resolveByJiekTemp(
781
- `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
782
- );
783
- fs.writeFileSync(configFile, FILE_TEMPLATE(manifest));
784
- const command2 = [rollupBinaryPath, "--silent", "-c", configFile];
785
- if (tsRegisterName != null) {
786
- command2.unshift(`node -r ${tsRegisterName}`);
605
+ command2.push(...passThroughOptions);
606
+ const child = index.execaCommand(command2.join(" "), {
607
+ ipc: true,
608
+ cwd: pkgCWD,
609
+ windowsHide: true,
610
+ env: {
611
+ ...env,
612
+ JIEK_NAME: manifest.name,
613
+ JIEK_ROOT: wd
614
+ }
615
+ });
616
+ const bars = {};
617
+ const times = {};
618
+ const locks = {};
619
+ let inputMaxLen = 10;
620
+ child.on("message", (e) => {
621
+ if (silent && [
622
+ "init",
623
+ "progress",
624
+ "watchChange"
625
+ ].includes(e.type)) return;
626
+ switch (e.type) {
627
+ case "init": {
628
+ const { leafMap, targetsLength } = e.data;
629
+ const leafs = Array.from(leafMap.entries()).flatMap(
630
+ ([input, pathAndConditions]) => pathAndConditions.map(([path2, ...conditions]) => ({
631
+ input,
632
+ path: path2,
633
+ conditions
634
+ }))
635
+ );
636
+ let initMessage = `Package '${manifest.name}' has ${targetsLength} targets to build`;
637
+ if (watch) {
638
+ initMessage += " and watching...";
639
+ }
640
+ console.log(initMessage);
641
+ leafs.forEach(({ input }) => {
642
+ inputMaxLen = Math.max(inputMaxLen, input.length);
643
+ });
644
+ leafs.forEach(({ input, path: path2 }) => {
645
+ const key = `${input}:${path2}`;
646
+ if (bars[key]) return;
647
+ bars[key] = multiBars.create(50, 0, {
648
+ pkgName: manifest.name,
649
+ input: input.padEnd(inputMaxLen + 5),
650
+ status: "waiting".padEnd(10)
651
+ }, {
652
+ barsize: 20,
653
+ linewrap: true
654
+ });
655
+ });
656
+ break;
787
657
  }
788
- if (watch) {
789
- command2.push("--watch");
658
+ case "progress": {
659
+ const {
660
+ path: path2,
661
+ tags,
662
+ input,
663
+ event,
664
+ message
665
+ } = e.data;
666
+ const bar = bars[`${input}:${path2}`];
667
+ if (!bar) return;
668
+ const time = times[`${input}:${path2}`];
669
+ bar.update(
670
+ {
671
+ start: 0,
672
+ resolve: 20,
673
+ end: 50
674
+ }[event ?? "start"] ?? 0,
675
+ {
676
+ input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
677
+ status: event?.padEnd(10),
678
+ message: `${tags?.join(", ")}: ${message}`
679
+ }
680
+ );
681
+ break;
790
682
  }
791
- command2.push(...passThroughOptions);
792
- const child = execa.execaCommand(command2.join(" "), {
793
- ipc: true,
794
- cwd: pkgCWD,
795
- env: {
796
- ...env,
797
- JIEK_NAME: manifest.name,
798
- JIEK_ROOT: wd
683
+ case "watchChange": {
684
+ const {
685
+ path: path2,
686
+ input
687
+ } = e.data;
688
+ const key = `${input}:${path2}`;
689
+ const bar = bars[key];
690
+ if (!bar) return;
691
+ let time = times[key] ?? 1;
692
+ if (!locks[key]) {
693
+ time += 1;
694
+ times[key] = time;
695
+ setTimeout(() => {
696
+ locks[key] = false;
697
+ }, 100);
698
+ bar.update(0, {
699
+ input: `${input}(x${time.toString().padStart(2, "0")})`.padEnd(inputMaxLen + 5),
700
+ status: "watching".padEnd(10),
701
+ message: "watching..."
702
+ });
799
703
  }
800
- });
801
- const bars = {};
802
- const times = {};
803
- const locks = {};
804
- let inputMaxLen = 10;
805
- child.on("message", (e) => {
806
- if (silent && [
807
- "init",
808
- "progress",
809
- "watchChange"
810
- ].includes(e.type)) return;
811
- switch (e.type) {
812
- case "init": {
813
- const { leafMap, targetsLength } = e.data;
814
- const leafs = Array.from(leafMap.entries()).flatMap(
815
- ([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
816
- input,
817
- path: path2,
818
- conditions
819
- }))
820
- );
821
- let initMessage = `Package '${manifest.name}' has ${targetsLength} targets to build`;
822
- if (watch) {
823
- initMessage += " and watching...";
824
- }
825
- console.log(initMessage);
826
- leafs.forEach(({ input }) => {
827
- inputMaxLen = Math.max(inputMaxLen, input.length);
828
- });
829
- leafs.forEach(({ input, path: path2 }) => {
830
- const key = `${input}:${path2}`;
831
- if (bars[key]) return;
832
- bars[key] = multiBars.create(50, 0, {
833
- pkgName: manifest.name,
834
- input: input.padEnd(inputMaxLen + 5),
835
- status: "waiting".padEnd(10)
836
- }, {
837
- barsize: 20,
838
- linewrap: true
839
- });
840
- });
841
- break;
842
- }
843
- case "progress": {
844
- const {
845
- path: path2,
846
- tags,
847
- input,
848
- event,
849
- message
850
- } = e.data;
851
- const bar = bars[`${input}:${path2}`];
852
- if (!bar) return;
853
- const time = times[`${input}:${path2}`];
854
- bar.update(
855
- {
856
- start: 0,
857
- resolve: 20,
858
- end: 50
859
- }[event ?? "start"] ?? 0,
860
- {
861
- input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
862
- status: event?.padEnd(10),
863
- message: `${tags?.join(", ")}: ${message}`
864
- }
865
- );
866
- break;
867
- }
868
- case "watchChange": {
869
- const {
870
- path: path2,
871
- input
872
- } = e.data;
873
- const key = `${input}:${path2}`;
874
- const bar = bars[key];
875
- if (!bar) return;
876
- let time = times[key] ?? 1;
877
- if (!locks[key]) {
878
- time += 1;
879
- times[key] = time;
880
- setTimeout(() => {
881
- locks[key] = false;
882
- }, 100);
883
- bar.update(0, {
884
- input: `${input}(x${time.toString().padStart(2, "0")})`.padEnd(inputMaxLen + 5),
885
- status: "watching".padEnd(10),
886
- message: "watching..."
887
- });
888
- }
889
- locks[key] = true;
890
- break;
891
- }
892
- case "modulesAnalyze": {
893
- const {
894
- data: {
895
- type: type2,
896
- modules: pkgModules
897
- }
898
- } = e;
899
- void refreshAnalyzer(
900
- pkgCWD,
901
- pkgModules.map((m) => ({
902
- ...m,
903
- type: type2,
904
- filename: `${manifest.name}/${m.filename}`,
905
- label: `${manifest.name}/${m.label}`
906
- }))
907
- );
908
- break;
909
- }
910
- case "debug": {
911
- console.log(...Array.isArray(e.data) ? e.data : [e.data]);
912
- break;
704
+ locks[key] = true;
705
+ break;
706
+ }
707
+ case "modulesAnalyze": {
708
+ const {
709
+ data: {
710
+ type: type2,
711
+ modules: pkgModules
913
712
  }
914
- }
915
- });
916
- await new Promise((resolve, reject) => {
917
- let errorStr = `rollup build failed
713
+ } = e;
714
+ void refreshAnalyzer(
715
+ pkgCWD,
716
+ pkgModules.map((m) => ({
717
+ ...m,
718
+ type: type2,
719
+ filename: `${manifest.name}/${m.filename}`,
720
+ label: `${manifest.name}/${m.label}`
721
+ }))
722
+ );
723
+ break;
724
+ }
725
+ case "debug": {
726
+ console.log(...Array.isArray(e.data) ? e.data : [e.data]);
727
+ break;
728
+ }
729
+ }
730
+ });
731
+ await new Promise((resolve, reject) => {
732
+ let errorStr = `rollup build failed
918
733
  package name: ${manifest.name}
919
734
  cwd: ${pkgCWD}
920
735
 
921
736
  `;
922
- child.stderr?.on("data", (data) => {
923
- errorStr += data;
924
- });
925
- child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(errorStr)));
926
- verbose && child.stdout?.pipe(process__default.default.stdout);
927
- });
928
- })
929
- );
737
+ child.stderr?.on("data", (data) => {
738
+ errorStr += data;
739
+ });
740
+ child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(errorStr)));
741
+ verbose && child.stdout?.pipe(process__default.default.stdout);
742
+ });
930
743
  };
931
744
  const commandFilters = IS_WORKSPACE ? commandFiltersOrEntries : void 0;
932
745
  const filters = [
@@ -936,41 +749,12 @@ cwd: ${pkgCWD}
936
749
  ])
937
750
  ];
938
751
  try {
939
- if (filters.length > 0) {
940
- const packages = await filterPackagesGraph(filters);
941
- await Promise.all(packages.map(buildPackage));
942
- } else {
943
- await buildPackage(await getSelectedProjectsGraph());
944
- }
752
+ const packages = (filters.length > 0 ? await filterSupport.filterPackagesGraph(filters) : [await filterSupport.getSelectedProjectsGraph()]).flatMap(({ value }) => Object.entries(value ?? {}));
753
+ await Promise.allSettled(
754
+ packages.map(async ([cwd, manifest]) => buildPackage([cwd, manifest], { resolveByJiekTemp }))
755
+ );
945
756
  } finally {
946
757
  multiBars.stop();
947
758
  !silent && console.log("Build complete");
948
759
  }
949
760
  });
950
-
951
- const { argv } = process__default.default;
952
- const env = {};
953
- let isPassThrough = false;
954
- const newArgv = argv.filter((arg) => {
955
- if (isPassThrough) {
956
- return true;
957
- }
958
- if (arg === "--") {
959
- isPassThrough = true;
960
- return false;
961
- }
962
- const m = /^--env\.(\w+)=(.*)$/.exec(arg);
963
- if (m) {
964
- env[m[1]] = m[2];
965
- return false;
966
- }
967
- return true;
968
- });
969
- for (const [key, value] of Object.entries(env)) {
970
- process__default.default.env[key] = value;
971
- }
972
- var parseArgv = () => commander.program.parse(newArgv);
973
-
974
- if (process__default.default.env.JIEK_IS_ONLY_BUILD === "true") {
975
- parseArgv();
976
- }