jiek 2.2.6 → 2.2.7-alpha.3

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 (136) hide show
  1. package/bin/build.cjs +2 -0
  2. package/bin/index.cjs +2 -0
  3. package/bin-helper/index.cjs +31 -0
  4. package/bin-helper/index.d.cts +1 -0
  5. package/bin-helper/index.d.ts +1 -0
  6. package/bin-helper/package.json +5 -1
  7. package/dist/.internal/.chunks/getWD.D6wq8Qc2.js +95 -0
  8. package/dist/.internal/.chunks/getWD.ZF0avqDB.cjs +105 -0
  9. package/dist/{cli.js → .internal/.chunks/index.B6RQz1DZ.js} +1 -735
  10. package/dist/{cli.cjs → .internal/.chunks/index.DlHFuTjM.cjs} +1 -757
  11. package/dist/.internal/.chunks/jiek_create-require.CWFWNQHj.cjs +5 -0
  12. package/dist/.internal/.chunks/jiek_create-require.CxSGbkTB.js +5 -0
  13. package/dist/.internal/bin/parseArgv.cjs +33 -0
  14. package/dist/.internal/bin/parseArgv.d.cts +5 -0
  15. package/dist/.internal/bin/parseArgv.d.ts +5 -0
  16. package/dist/.internal/bin/parseArgv.js +27 -0
  17. package/dist/.internal/bridge.cjs +12 -0
  18. package/dist/.internal/bridge.d.cts +39 -0
  19. package/dist/.internal/bridge.d.ts +39 -0
  20. package/dist/.internal/bridge.js +9 -0
  21. package/dist/.internal/commands/build/analyzer.cjs +201 -0
  22. package/dist/.internal/commands/build/analyzer.d.cts +30 -0
  23. package/dist/.internal/commands/build/analyzer.d.ts +30 -0
  24. package/dist/.internal/commands/build/analyzer.js +195 -0
  25. package/dist/.internal/commands/descriptions.cjs +21 -0
  26. package/dist/.internal/commands/descriptions.d.cts +5 -0
  27. package/dist/.internal/commands/descriptions.d.ts +5 -0
  28. package/dist/.internal/commands/descriptions.js +17 -0
  29. package/dist/.internal/commands/meta.cjs +16 -0
  30. package/dist/.internal/commands/meta.d.cts +3 -0
  31. package/dist/.internal/commands/meta.d.ts +3 -0
  32. package/dist/.internal/commands/meta.js +15 -0
  33. package/dist/.internal/commands/utils/optionParser.cjs +8 -0
  34. package/dist/.internal/commands/utils/optionParser.d.cts +3 -0
  35. package/dist/.internal/commands/utils/optionParser.d.ts +3 -0
  36. package/dist/.internal/commands/utils/optionParser.js +6 -0
  37. package/dist/.internal/rollup/base.cjs +10 -0
  38. package/dist/{cli-only-build.d.cts → .internal/rollup/base.d.cts} +8 -15
  39. package/dist/{cli-only-build.d.ts → .internal/rollup/base.d.ts} +8 -15
  40. package/dist/.internal/rollup/base.js +7 -0
  41. package/dist/.internal/rollup/bundle-analyzer.cjs +51 -0
  42. package/dist/.internal/rollup/bundle-analyzer.d.cts +92 -0
  43. package/dist/.internal/rollup/bundle-analyzer.d.ts +92 -0
  44. package/dist/.internal/rollup/bundle-analyzer.js +45 -0
  45. package/dist/.internal/server.cjs +33 -0
  46. package/dist/.internal/server.d.cts +8 -0
  47. package/dist/.internal/server.d.ts +8 -0
  48. package/dist/.internal/server.js +27 -0
  49. package/dist/.internal/utils/checkDependency.cjs +39 -0
  50. package/dist/.internal/utils/checkDependency.d.cts +3 -0
  51. package/dist/.internal/utils/checkDependency.d.ts +3 -0
  52. package/dist/.internal/utils/checkDependency.js +34 -0
  53. package/dist/.internal/utils/filterSupport.cjs +20 -0
  54. package/dist/.internal/utils/filterSupport.d.cts +15 -0
  55. package/dist/.internal/utils/filterSupport.d.ts +15 -0
  56. package/dist/.internal/utils/filterSupport.js +10 -0
  57. package/dist/.internal/utils/getInternalModuleName.cjs +5 -0
  58. package/dist/.internal/utils/getInternalModuleName.d.cts +3 -0
  59. package/dist/.internal/utils/getInternalModuleName.d.ts +3 -0
  60. package/dist/.internal/utils/getInternalModuleName.js +3 -0
  61. package/dist/.internal/utils/getRoot.cjs +17 -0
  62. package/dist/.internal/utils/getRoot.d.cts +3 -0
  63. package/dist/.internal/utils/getRoot.d.ts +3 -0
  64. package/dist/.internal/utils/getRoot.js +11 -0
  65. package/dist/.internal/utils/getWD.cjs +15 -0
  66. package/dist/.internal/utils/getWD.d.cts +6 -0
  67. package/dist/.internal/utils/getWD.d.ts +6 -0
  68. package/dist/.internal/utils/getWD.js +10 -0
  69. package/dist/.internal/utils/intersection.cjs +5 -0
  70. package/dist/.internal/utils/intersection.d.cts +3 -0
  71. package/dist/.internal/utils/intersection.d.ts +3 -0
  72. package/dist/.internal/utils/intersection.js +3 -0
  73. package/dist/.internal/utils/loadConfig.cjs +100 -0
  74. package/dist/.internal/utils/loadConfig.d.cts +10 -0
  75. package/dist/.internal/utils/loadConfig.d.ts +10 -0
  76. package/dist/.internal/utils/loadConfig.js +94 -0
  77. package/dist/.internal/utils/recursiveListFiles.cjs +19 -0
  78. package/dist/.internal/utils/recursiveListFiles.d.cts +3 -0
  79. package/dist/.internal/utils/recursiveListFiles.d.ts +3 -0
  80. package/dist/.internal/utils/recursiveListFiles.js +13 -0
  81. package/dist/.internal/utils/resolveExports.cjs +118 -0
  82. package/dist/.internal/utils/resolveExports.d.cts +26 -0
  83. package/dist/.internal/utils/resolveExports.d.ts +26 -0
  84. package/dist/.internal/utils/resolveExports.js +111 -0
  85. package/dist/.internal/utils/ts.cjs +68 -0
  86. package/dist/.internal/utils/ts.d.cts +3 -0
  87. package/dist/.internal/utils/ts.d.ts +3 -0
  88. package/dist/.internal/utils/ts.js +62 -0
  89. package/dist/.internal/utils/tsRegister.cjs +25 -0
  90. package/dist/.internal/utils/tsRegister.d.cts +3 -0
  91. package/dist/.internal/utils/tsRegister.d.ts +3 -0
  92. package/dist/.internal/utils/tsRegister.js +26 -0
  93. package/dist/bin/build.cjs +515 -0
  94. package/dist/bin/index.cjs +497 -0
  95. package/dist/index.d.cts +12 -114
  96. package/dist/index.d.ts +12 -114
  97. package/dist/rollup/index.cjs +280 -4573
  98. package/dist/rollup/index.d.cts +7 -1
  99. package/dist/rollup/index.d.ts +7 -1
  100. package/dist/rollup/index.js +268 -4558
  101. package/package.json +20 -26
  102. package/src/bin/build.cts +11 -0
  103. package/src/bin/index.cts +6 -0
  104. package/src/bridge.ts +1 -1
  105. package/src/commands/base.ts +3 -3
  106. package/src/commands/build/analyzer.ts +5 -5
  107. package/src/commands/build/client/analyzer.tsx +1 -1
  108. package/src/commands/build/client/index.ts +5 -7
  109. package/src/commands/build.ts +226 -211
  110. package/src/commands/meta.ts +1 -1
  111. package/src/commands/publish.ts +112 -32
  112. package/src/index.ts +6 -1
  113. package/src/rollup/base.ts +2 -2
  114. package/src/rollup/index.ts +321 -124
  115. package/src/rollup/plugins/with-external.ts +23 -0
  116. package/src/rollup/utils/externalResolver.ts +20 -8
  117. package/src/utils/checkDependency.ts +1 -1
  118. package/src/utils/filterSupport.ts +17 -16
  119. package/src/utils/getInternalModuleName.ts +5 -0
  120. package/src/utils/intersection.ts +1 -0
  121. package/src/utils/{recusiveListFiles.ts → recursiveListFiles.ts} +2 -2
  122. package/src/utils/{getExports.ts → resolveExports.ts} +16 -14
  123. package/bin/jiek-build.js +0 -16
  124. package/bin/jiek.js +0 -13
  125. package/bin-helper.cjs +0 -43
  126. package/cli/package.json +0 -1
  127. package/cli-only-build/package.json +0 -1
  128. package/dist/cli-only-build.cjs +0 -977
  129. package/dist/cli-only-build.js +0 -969
  130. package/dist/cli.d.cts +0 -14
  131. package/dist/cli.d.ts +0 -14
  132. package/src/bin/build.ts +0 -0
  133. package/src/cli-only-build.ts +0 -11
  134. package/src/cli.ts +0 -6
  135. /package/{bin-helper.js → bin-helper/index.js} +0 -0
  136. /package/src/{parseArgv.ts → bin/parseArgv.ts} +0 -0
@@ -0,0 +1,515 @@
1
+ 'use strict';
2
+
3
+ var fs = require('node:fs');
4
+ var path = require('node:path');
5
+ var process = require('node:process');
6
+ var commander = require('commander');
7
+ require('js-yaml');
8
+ require('#~/utils/getRoot');
9
+ var getWD = require('#~/utils/getWD');
10
+ var descriptions = require('#~/commands/descriptions');
11
+ var meta = require('#~/commands/meta');
12
+ var filterSupport = require('#~/utils/filterSupport');
13
+ var cliProgress = require('cli-progress');
14
+ var execa = require('execa');
15
+ var analyzer = require('#~/commands/build/analyzer');
16
+ var optionParser = require('#~/commands/utils/optionParser');
17
+ var base = require('#~/rollup/base');
18
+ var server = require('#~/server');
19
+ var checkDependency = require('#~/utils/checkDependency');
20
+ var loadConfig = require('#~/utils/loadConfig');
21
+ var tsRegister = require('#~/utils/tsRegister');
22
+ var parseArgv = require('#~/bin/parseArgv');
23
+
24
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
25
+
26
+ var path__default = /*#__PURE__*/_interopDefault(path);
27
+ var process__default = /*#__PURE__*/_interopDefault(process);
28
+ var parseArgv__default = /*#__PURE__*/_interopDefault(parseArgv);
29
+
30
+ var require$1 = require;
31
+
32
+ let type$1 = "";
33
+ try {
34
+ require$1.resolve("@pnpm/filter-workspace-packages");
35
+ type$1 = "pnpm";
36
+ } catch {
37
+ }
38
+
39
+ var name = "jiek";
40
+ var type = "module";
41
+ var version = "2.2.7-alpha.2";
42
+ var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
43
+ var author = "YiJie <yijie4188@gmail.com>";
44
+ var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
45
+ var repository = {
46
+ url: "nwylzw/jiek",
47
+ directory: "packages/jiek"
48
+ };
49
+ var bugs = "https://github.com/NWYLZW/jiek/issues?q=is%3Aissue+is%3Aopen+jiek";
50
+ var keywords = [
51
+ "cli",
52
+ "zero-config",
53
+ "bundler",
54
+ "library",
55
+ "monorepo",
56
+ "builder",
57
+ "rollup",
58
+ "workspace"
59
+ ];
60
+ var exports$1 = {
61
+ "./package.json": "./package.json",
62
+ ".": "./src/index.ts",
63
+ "./bin-helper": {
64
+ require: "./bin-helper/index.cjs",
65
+ "default": "./bin-helper/index.js"
66
+ },
67
+ "./rollup": "./src/rollup/index.ts"
68
+ };
69
+ var imports = {
70
+ "#~/*": "./src/*.ts"
71
+ };
72
+ var bin = {
73
+ jiek: "bin/index.cjs",
74
+ jk: "bin/index.cjs",
75
+ "jiek-build": "bin/build.cjs",
76
+ jb: "bin/build.cjs"
77
+ };
78
+ var files = [
79
+ "LICENSE",
80
+ "README.md",
81
+ "bin",
82
+ "bin-helper",
83
+ "dist",
84
+ "src"
85
+ ];
86
+ var scripts = {
87
+ prepublish: "jb -nm && jk",
88
+ postpublish: "jk",
89
+ test: "vitest run"
90
+ };
91
+ var peerDependencies = {
92
+ "@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0||>=1000.0.0",
93
+ "@rollup/plugin-terser": "^0.4.4",
94
+ "esbuild-register": "^3.5.0",
95
+ postcss: "^8.4.47",
96
+ "rollup-plugin-esbuild": "^6.1.0",
97
+ "rollup-plugin-postcss": "^4.0.2",
98
+ "rollup-plugin-swc3": "^0.12.1",
99
+ typescript: "^4.0.0||^5.0.0",
100
+ "vite-bundle-analyzer": "0.16.0-beta.3"
101
+ };
102
+ var dependencies = {
103
+ "@inquirer/prompts": "^7.2.0",
104
+ "@jiek/pkger": "workspace:^",
105
+ "@jiek/rollup-plugin-dts": "^6.3.8",
106
+ "@jiek/utils": "workspace:^",
107
+ "@rollup/plugin-commonjs": "^28.0.0",
108
+ "@rollup/plugin-inject": "^5.0.5",
109
+ "@rollup/plugin-json": "^6.0.1",
110
+ "@rollup/plugin-node-resolve": "^15.3.0",
111
+ "cli-progress": "^3.12.0",
112
+ commander: "^12.0.0",
113
+ "detect-indent": "^6.1.0",
114
+ execa: "~9.3.1",
115
+ "js-yaml": "^4.1.0",
116
+ "jsonc-parser": "^3.2.1",
117
+ koa: "^2.15.3",
118
+ rollup: "^4.0.0"
119
+ };
120
+ var devDependencies = {
121
+ "@npm/types": "^1.0.2",
122
+ "@pnpm/filter-workspace-packages": "^7.2.13",
123
+ "@pnpm/workspace.pkgs-graph": "^2.0.15",
124
+ "@rollup/plugin-terser": "^0.4.4",
125
+ "@types/cli-progress": "^3.11.5",
126
+ "@types/inquirer": "^9.0.7",
127
+ "@types/js-yaml": "^4.0.9",
128
+ "@types/koa": "^2.15.0",
129
+ "@types/micromatch": "^4.0.6",
130
+ "@types/react": "^18.3.14",
131
+ "esbuild-register": "^3.5.0",
132
+ micromatch: "^4.0.5",
133
+ "node-sass": "^9.0.0",
134
+ postcss: "^8.4.47",
135
+ "rollup-plugin-esbuild": "^6.1.0",
136
+ "rollup-plugin-postcss": "^4.0.2",
137
+ "rollup-plugin-swc3": "^0.12.1",
138
+ "vite-bundle-analyzer": "0.16.0-beta.3"
139
+ };
140
+ var publishConfig = {
141
+ directory: "./dist/.internal"
142
+ };
143
+ var pkg = {
144
+ name: name,
145
+ type: type,
146
+ version: version,
147
+ description: description$1,
148
+ author: author,
149
+ homepage: homepage,
150
+ repository: repository,
151
+ bugs: bugs,
152
+ keywords: keywords,
153
+ exports: exports$1,
154
+ imports: imports,
155
+ bin: bin,
156
+ files: files,
157
+ scripts: scripts,
158
+ peerDependencies: peerDependencies,
159
+ dependencies: dependencies,
160
+ devDependencies: devDependencies,
161
+ publishConfig: publishConfig
162
+ };
163
+
164
+ 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.");
165
+ if (filterSupport.type !== "" && meta.IS_WORKSPACE) {
166
+ commander.program.option("-f, --filter <filter>", descriptions.filterDescription);
167
+ }
168
+
169
+ const FILE_TEMPLATE = (manifest) => `
170
+ module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
171
+ `.trimStart();
172
+ const ROLLUP_BIN = require$1.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
173
+ const isDefault = process__default.default.env.JIEK_BIN__FILENAME === "build.cjs";
174
+ const description = `
175
+ Build the package according to the 'exports' field from the package.json.
176
+ If you want to through the options to the \`rollup\` command, you can pass the options after '--'.
177
+ ${isDefault ? "This command is the default command." : ""}
178
+ `.trim();
179
+ let DEFAULT_BUILDER_TYPE;
180
+ Object.entries(base.BUILDER_TYPE_PACKAGE_NAME_MAP).forEach(([type, packageName]) => {
181
+ try {
182
+ require$1.resolve(packageName);
183
+ DEFAULT_BUILDER_TYPE = type;
184
+ } catch {
185
+ }
186
+ });
187
+ if (!DEFAULT_BUILDER_TYPE) {
188
+ DEFAULT_BUILDER_TYPE = "esbuild";
189
+ }
190
+ const buildFilterDescription = `
191
+ ${descriptions.filterDescription}
192
+ If you pass the --filter option, it will merge into the filters of the command.
193
+ `.trim();
194
+ const buildEntriesDescription = `
195
+ ${descriptions.entriesDescription}
196
+ If you pass the --entries option, it will merge into the entries of the command.
197
+ `.trim();
198
+ let command = isDefault ? (() => {
199
+ const c = commander.program.name("jb/jiek-build").helpCommand(false);
200
+ if (meta.IS_WORKSPACE) {
201
+ c.argument("[filters]", buildFilterDescription);
202
+ } else {
203
+ c.argument("[entries]", buildEntriesDescription);
204
+ }
205
+ return c;
206
+ })() : commander.program.command(`build [${meta.IS_WORKSPACE ? "filters" : "entries"}]`);
207
+ command = command.description(description).option("-t, --type <TYPE>", `The type of build, support ${base.BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}.`, (v) => {
208
+ if (!base.BUILDER_TYPES.includes(v)) {
209
+ throw new Error(`The value of 'type' must be ${base.BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}`);
210
+ }
211
+ return String(v);
212
+ }, "esbuild").option("-o, --outdir <OUTDIR>", descriptions.outdirDescription, String, "dist").option("-e, --entries <ENTRIES>", descriptions.entriesDescription).option("--external <EXTERNAL>", "Specify the external dependencies of the package.", String).option("--noConvert", "Specify the `crossModuleConvertor` option to false.", optionParser.parseBoolean).option("-nj, --noJs", "Do not output js files.", optionParser.parseBoolean).option("-nd, --noDts", "Do not output dts files.", optionParser.parseBoolean).option("-nm, --noMin", "Do not output minify files.", optionParser.parseBoolean).option(
213
+ "--minType <MINTYPE>",
214
+ 'The type of minify, support "builder" and "terser".',
215
+ (v) => {
216
+ if (!["builder", "terser"].includes(v)) {
217
+ throw new Error('The value of `minType` must be "builder" or "terser"');
218
+ }
219
+ return String(v);
220
+ }
221
+ ).option("-nc, --noClean", "Do not clean the output directory before building.", optionParser.parseBoolean).option(
222
+ "-om, --onlyMin",
223
+ "Only output minify files, but dts files will still be output, it only replaces the js files.",
224
+ optionParser.parseBoolean
225
+ );
226
+ command = command.option("--features.keepImportAttributes", "Keep the import attributes in the output.");
227
+ 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);
228
+ command = command.option("-w, --watch", "Watch the file changes.", optionParser.parseBoolean).option("-p, --port <PORT>", "The port of the server.", Number.parseInt, 8888);
229
+ command = analyzer.registerAnalyzerCommandOptions(command);
230
+ command = command.option("-s, --silent", "Don't display logs.", optionParser.parseBoolean).option("-v, --verbose", "Display debug logs.", optionParser.parseBoolean);
231
+ command.action(async (commandFiltersOrEntries, options) => {
232
+ let {
233
+ type,
234
+ outdir,
235
+ watch,
236
+ silent,
237
+ verbose,
238
+ entries: optionEntries,
239
+ external,
240
+ noConvert,
241
+ noJs: withoutJs,
242
+ noDts: withoutDts,
243
+ noMin: withoutMin,
244
+ minType: minifyType,
245
+ noClean,
246
+ onlyMin,
247
+ tsconfig,
248
+ dtsconfig
249
+ } = options;
250
+ const resolvedType = type ?? DEFAULT_BUILDER_TYPE;
251
+ if (!withoutJs) {
252
+ await checkDependency.checkDependency(base.BUILDER_TYPE_PACKAGE_NAME_MAP[resolvedType]);
253
+ if (minifyType === "builder") {
254
+ minifyType = resolvedType;
255
+ }
256
+ }
257
+ if (!withoutMin && minifyType === "terser") {
258
+ await checkDependency.checkDependency("@rollup/plugin-terser");
259
+ }
260
+ let shouldPassThrough = false;
261
+ const passThroughOptions = process__default.default.argv.reduce(
262
+ (acc, value) => {
263
+ if (shouldPassThrough) {
264
+ acc.push(value);
265
+ }
266
+ if (value === "--") {
267
+ shouldPassThrough = true;
268
+ }
269
+ return acc;
270
+ },
271
+ []
272
+ );
273
+ const shouldCreateServer = [
274
+ options.ana === true && options["ana.mode"] === "server"
275
+ ].some(Boolean);
276
+ const server$1 = shouldCreateServer ? server.createServer(options.port, "localhost") : void 0;
277
+ const {
278
+ ANALYZER_ENV,
279
+ refreshAnalyzer
280
+ } = await analyzer.useAnalyzer(options, server$1);
281
+ const { build } = loadConfig.loadConfig();
282
+ silent = silent ?? build?.silent ?? false;
283
+ if (withoutMin && onlyMin) {
284
+ throw new Error("Cannot use both --without-minify and --only-minify");
285
+ }
286
+ if (onlyMin && withoutJs) {
287
+ throw new Error("Cannot use --without-js and --only-minify at the same time");
288
+ }
289
+ let entries = [
290
+ optionEntries,
291
+ meta.IS_WORKSPACE ? void 0 : commandFiltersOrEntries
292
+ ].filter(Boolean).join(",");
293
+ if (entries.length === 0) {
294
+ entries = void 0;
295
+ }
296
+ const env = {
297
+ ...ANALYZER_ENV,
298
+ JIEK_BUILDER: type,
299
+ JIEK_OUT_DIR: outdir,
300
+ JIEK_CLEAN: String(!noClean),
301
+ JIEK_ENTRIES: entries,
302
+ JIEK_EXTERNAL: external,
303
+ JIEK_CROSS_MODULE_CONVERTOR: String(!noConvert),
304
+ JIEK_WITHOUT_JS: String(withoutJs),
305
+ JIEK_WITHOUT_DTS: String(withoutDts),
306
+ JIEK_WITHOUT_MINIFY: String(withoutMin),
307
+ JIEK_ONLY_MINIFY: String(onlyMin),
308
+ JIEK_MINIFY_TYPE: minifyType,
309
+ JIEK_TSCONFIG: tsconfig,
310
+ JIEK_DTSCONFIG: dtsconfig,
311
+ JIEK_FEATURES: JSON.stringify({
312
+ keepImportAttributes: options["features.keepImportAttributes"]
313
+ }),
314
+ ...process__default.default.env
315
+ };
316
+ const multiBars = new cliProgress.MultiBar({
317
+ clearOnComplete: false,
318
+ hideCursor: true,
319
+ format: "- {bar} | {status} | {pkgName} | {input} | {message}"
320
+ }, cliProgress.Presets.shades_classic);
321
+ const { wd } = getWD.getWD();
322
+ const wdNodeModules = path__default.default.resolve(wd, "node_modules");
323
+ if (!fs.existsSync(wdNodeModules)) {
324
+ fs.mkdirSync(wdNodeModules);
325
+ }
326
+ const resolveByJiekTemp = (...paths) => path__default.default.resolve(wdNodeModules, ".jiek", ...paths);
327
+ const jiekTemp = resolveByJiekTemp();
328
+ if (!fs.existsSync(jiekTemp)) {
329
+ try {
330
+ fs.mkdirSync(jiekTemp);
331
+ } catch (e) {
332
+ if (e.code !== "EEXIST") {
333
+ throw e;
334
+ }
335
+ }
336
+ }
337
+ let i = 0;
338
+ const buildPackage = async ([pkgCWD, manifest], {
339
+ resolveByJiekTemp: resolveByJiekTemp2
340
+ }) => {
341
+ if (manifest.name == null) {
342
+ throw new Error("package.json must have a name field");
343
+ }
344
+ const escapeManifestName = manifest.name.replace(/^@/g, "").replace(/\//g, "+");
345
+ const configFile = resolveByJiekTemp2(
346
+ `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
347
+ );
348
+ fs.writeFileSync(configFile, FILE_TEMPLATE(manifest));
349
+ const command2 = [ROLLUP_BIN, "--silent", "-c", configFile];
350
+ if (tsRegister.tsRegisterName != null) {
351
+ command2.unshift(`node -r ${tsRegister.tsRegisterName}`);
352
+ }
353
+ if (watch) {
354
+ command2.push("--watch");
355
+ }
356
+ command2.push(...passThroughOptions);
357
+ const child = execa.execaCommand(command2.join(" "), {
358
+ ipc: true,
359
+ cwd: pkgCWD,
360
+ windowsHide: true,
361
+ env: {
362
+ ...env,
363
+ JIEK_NAME: manifest.name,
364
+ JIEK_ROOT: wd
365
+ }
366
+ });
367
+ const bars = {};
368
+ const times = {};
369
+ const locks = {};
370
+ let inputMaxLen = 10;
371
+ child.on("message", (e) => {
372
+ if (silent && [
373
+ "init",
374
+ "progress",
375
+ "watchChange"
376
+ ].includes(e.type)) return;
377
+ switch (e.type) {
378
+ case "init": {
379
+ const { leafMap, targetsLength } = e.data;
380
+ const leafs = Array.from(leafMap.entries()).flatMap(
381
+ ([input, pathAndConditions]) => pathAndConditions.map(([path2, ...conditions]) => ({
382
+ input,
383
+ path: path2,
384
+ conditions
385
+ }))
386
+ );
387
+ let initMessage = `Package '${manifest.name}' has ${targetsLength} targets to build`;
388
+ if (watch) {
389
+ initMessage += " and watching...";
390
+ }
391
+ console.log(initMessage);
392
+ leafs.forEach(({ input }) => {
393
+ inputMaxLen = Math.max(inputMaxLen, input.length);
394
+ });
395
+ leafs.forEach(({ input, path: path2 }) => {
396
+ const key = `${input}:${path2}`;
397
+ if (bars[key]) return;
398
+ bars[key] = multiBars.create(50, 0, {
399
+ pkgName: manifest.name,
400
+ input: input.padEnd(inputMaxLen + 5),
401
+ status: "waiting".padEnd(10)
402
+ }, {
403
+ barsize: 20,
404
+ linewrap: true
405
+ });
406
+ });
407
+ break;
408
+ }
409
+ case "progress": {
410
+ const {
411
+ path: path2,
412
+ tags,
413
+ input,
414
+ event,
415
+ message
416
+ } = e.data;
417
+ const bar = bars[`${input}:${path2}`];
418
+ if (!bar) return;
419
+ const time = times[`${input}:${path2}`];
420
+ bar.update(
421
+ {
422
+ start: 0,
423
+ resolve: 20,
424
+ end: 50
425
+ }[event ?? "start"] ?? 0,
426
+ {
427
+ input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
428
+ status: event?.padEnd(10),
429
+ message: `${tags?.join(", ")}: ${message}`
430
+ }
431
+ );
432
+ break;
433
+ }
434
+ case "watchChange": {
435
+ const {
436
+ path: path2,
437
+ input
438
+ } = e.data;
439
+ const key = `${input}:${path2}`;
440
+ const bar = bars[key];
441
+ if (!bar) return;
442
+ let time = times[key] ?? 1;
443
+ if (!locks[key]) {
444
+ time += 1;
445
+ times[key] = time;
446
+ setTimeout(() => {
447
+ locks[key] = false;
448
+ }, 100);
449
+ bar.update(0, {
450
+ input: `${input}(x${time.toString().padStart(2, "0")})`.padEnd(inputMaxLen + 5),
451
+ status: "watching".padEnd(10),
452
+ message: "watching..."
453
+ });
454
+ }
455
+ locks[key] = true;
456
+ break;
457
+ }
458
+ case "modulesAnalyze": {
459
+ const {
460
+ data: {
461
+ type: type2,
462
+ modules: pkgModules
463
+ }
464
+ } = e;
465
+ void refreshAnalyzer(
466
+ pkgCWD,
467
+ pkgModules.map((m) => ({
468
+ ...m,
469
+ type: type2,
470
+ filename: `${manifest.name}/${m.filename}`,
471
+ label: `${manifest.name}/${m.label}`
472
+ }))
473
+ );
474
+ break;
475
+ }
476
+ case "debug": {
477
+ console.log(...Array.isArray(e.data) ? e.data : [e.data]);
478
+ break;
479
+ }
480
+ }
481
+ });
482
+ await new Promise((resolve, reject) => {
483
+ let errorStr = `rollup build failed
484
+ package name: ${manifest.name}
485
+ cwd: ${pkgCWD}
486
+
487
+ `;
488
+ child.stderr?.on("data", (data) => {
489
+ errorStr += data;
490
+ });
491
+ child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(errorStr)));
492
+ verbose && child.stdout?.pipe(process__default.default.stdout);
493
+ });
494
+ };
495
+ const commandFilters = meta.IS_WORKSPACE ? commandFiltersOrEntries : void 0;
496
+ const filters = [
497
+ .../* @__PURE__ */ new Set([
498
+ ...commander.program.getOptionValue("filter")?.split(",").map((s) => s.trim()).filter((s) => s.length > 0) ?? [],
499
+ ...commandFilters?.split(",").map((s) => s.trim()).filter((s) => s.length > 0) ?? []
500
+ ])
501
+ ];
502
+ try {
503
+ const packages = (filters.length > 0 ? await filterSupport.filterPackagesGraph(filters) : [await filterSupport.getSelectedProjectsGraph()]).flatMap(({ value }) => Object.entries(value ?? {}));
504
+ await Promise.allSettled(
505
+ packages.map(async ([cwd, manifest]) => buildPackage([cwd, manifest], { resolveByJiekTemp }))
506
+ );
507
+ } finally {
508
+ multiBars.stop();
509
+ !silent && console.log("Build complete");
510
+ }
511
+ });
512
+
513
+ if (process__default.default.env.JIEK_BIN__FILENAME === "build.cjs") {
514
+ parseArgv__default.default();
515
+ }