jiek 2.2.7 → 2.3.0

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