jiek 2.1.11 → 2.1.13

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.
@@ -6,15 +6,19 @@ var path = require('node:path');
6
6
  var commander = require('commander');
7
7
  var jsYaml = require('js-yaml');
8
8
  var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
9
+ var process$1 = require('node:process');
9
10
  var prompts = require('@inquirer/prompts');
10
11
  var cliProgress = require('cli-progress');
11
12
  var execa = require('execa');
13
+ var Koa = require('koa');
12
14
 
13
15
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
14
16
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
15
17
 
16
18
  var fs__default = /*#__PURE__*/_interopDefault(fs);
17
19
  var path__default = /*#__PURE__*/_interopDefault(path);
20
+ var process__default = /*#__PURE__*/_interopDefault(process$1);
21
+ var Koa__default = /*#__PURE__*/_interopDefault(Koa);
18
22
 
19
23
  let root;
20
24
  function getRoot() {
@@ -52,7 +56,7 @@ function getWD() {
52
56
 
53
57
  let type$1 = "";
54
58
  try {
55
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli-only-build.cjs', document.baseURI).href)));
59
+ const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-only-build.cjs', document.baseURI).href)));
56
60
  require$1.resolve("@pnpm/filter-workspace-packages");
57
61
  type$1 = "pnpm";
58
62
  } catch {
@@ -116,15 +120,39 @@ async function getSelectedProjectsGraph(filter = commander.program.getOptionValu
116
120
 
117
121
  var name = "jiek";
118
122
  var type = "module";
119
- var version = "2.1.10";
123
+ var version = "2.1.12";
120
124
  var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
121
125
  var author = "YiJie <yijie4188@gmail.com>";
126
+ var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
122
127
  var repository = {
123
128
  url: "nwylzw/jiek",
124
129
  directory: "packages/jiek"
125
130
  };
126
- var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
127
131
  var bugs = "https://github.com/NWYLZW/jiek/issues?q=is%3Aissue+is%3Aopen+jiek";
132
+ var keywords = [
133
+ "cli",
134
+ "zero-config",
135
+ "bundler",
136
+ "library",
137
+ "monorepo",
138
+ "builder",
139
+ "rollup",
140
+ "workspace"
141
+ ];
142
+ var exports$1 = {
143
+ "./package.json": "./package.json",
144
+ ".": "./src/index.ts",
145
+ "./bin-helper": {
146
+ require: "./bin-helper.cjs",
147
+ "default": "./bin-helper.js"
148
+ },
149
+ "./cli": "./src/cli.ts",
150
+ "./cli-only-build": "./src/cli-only-build.ts",
151
+ "./rollup": "./src/rollup/index.ts"
152
+ };
153
+ var imports = {
154
+ "#~/*": "./src/*"
155
+ };
128
156
  var bin = {
129
157
  jiek: "bin/jiek.js",
130
158
  jk: "bin/jiek.js",
@@ -132,52 +160,48 @@ var bin = {
132
160
  jb: "bin/jiek-build.js"
133
161
  };
134
162
  var files = [
135
- "dist",
136
- "src",
137
- "bin",
138
163
  "LICENSE",
139
- "README.md"
164
+ "README.md",
165
+ "bin",
166
+ "bin-helper.cjs",
167
+ "bin-helper.js",
168
+ "dist",
169
+ "src"
140
170
  ];
141
171
  var scripts = {
142
172
  prepublish: "jb -nm && jk",
143
173
  postpublish: "jk",
144
174
  test: "vitest run"
145
175
  };
146
- var exports$1 = {
147
- "./package.json": "./package.json",
148
- ".": "./src/index.ts",
149
- "./cli": "./src/cli.ts",
150
- "./cli-only-build": "./src/cli-only-build.ts",
151
- "./rollup": "./src/rollup/index.ts"
152
- };
153
- var imports = {
154
- "#~/*": "./src/*"
176
+ var peerDependencies = {
177
+ "@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0",
178
+ "@rollup/plugin-terser": "^0.4.4",
179
+ "esbuild-register": "^3.5.0",
180
+ postcss: "^8.4.47",
181
+ "rollup-plugin-esbuild": "^6.1.0",
182
+ "rollup-plugin-postcss": "^4.0.2",
183
+ "rollup-plugin-swc3": "^0.12.1",
184
+ typescript: "^4.0.0||^5.0.0",
185
+ "vite-bundle-analyzer": "^0.15.2"
155
186
  };
156
187
  var dependencies = {
188
+ "@inquirer/prompts": "^7.1.0",
157
189
  "@jiek/pkger": "workspace:^",
158
190
  "@jiek/rollup-plugin-dts": "^6.2.1",
159
191
  "@jiek/utils": "workspace:^",
160
- "@inquirer/prompts": "^7.1.0",
161
192
  "@rollup/plugin-commonjs": "^28.0.0",
193
+ "@rollup/plugin-inject": "^5.0.5",
162
194
  "@rollup/plugin-json": "^6.0.1",
163
195
  "@rollup/plugin-node-resolve": "^15.3.0",
196
+ "@rollup/plugin-replace": "^6.0.1",
164
197
  "cli-progress": "^3.12.0",
165
198
  commander: "^12.0.0",
166
199
  "detect-indent": "^6.1.0",
167
- execa: "9.3.1",
200
+ execa: "~9.3.1",
168
201
  "js-yaml": "^4.1.0",
169
202
  "jsonc-parser": "^3.2.1",
170
- rollup: "4.13.2"
171
- };
172
- var peerDependencies = {
173
- "@rollup/plugin-terser": "^0.4.4",
174
- "@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0",
175
- "esbuild-register": "^3.5.0",
176
- postcss: "^8.4.47",
177
- "rollup-plugin-postcss": "^4.0.2",
178
- "rollup-plugin-esbuild": "^6.1.0",
179
- "rollup-plugin-swc3": "^0.12.1",
180
- typescript: "^4.0.0||^5.0.0"
203
+ koa: "^2.15.3",
204
+ rollup: "^4.0.0"
181
205
  };
182
206
  var devDependencies = {
183
207
  "@npm/types": "^1.0.2",
@@ -187,14 +211,16 @@ var devDependencies = {
187
211
  "@types/cli-progress": "^3.11.5",
188
212
  "@types/inquirer": "^9.0.7",
189
213
  "@types/js-yaml": "^4.0.9",
214
+ "@types/koa": "^2.15.0",
190
215
  "@types/micromatch": "^4.0.6",
191
216
  "esbuild-register": "^3.5.0",
192
217
  micromatch: "^4.0.5",
193
218
  "node-sass": "^9.0.0",
194
219
  postcss: "^8.4.47",
195
- "rollup-plugin-postcss": "^4.0.2",
196
220
  "rollup-plugin-esbuild": "^6.1.0",
197
- "rollup-plugin-swc3": "^0.12.1"
221
+ "rollup-plugin-postcss": "^4.0.2",
222
+ "rollup-plugin-swc3": "^0.12.1",
223
+ "vite-bundle-analyzer": "^0.15.2"
198
224
  };
199
225
  var pkg = {
200
226
  name: name,
@@ -202,16 +228,17 @@ var pkg = {
202
228
  version: version,
203
229
  description: description$1,
204
230
  author: author,
205
- repository: repository,
206
231
  homepage: homepage,
232
+ repository: repository,
207
233
  bugs: bugs,
234
+ keywords: keywords,
235
+ exports: exports$1,
236
+ imports: imports,
208
237
  bin: bin,
209
238
  files: files,
210
239
  scripts: scripts,
211
- exports: exports$1,
212
- imports: imports,
213
- dependencies: dependencies,
214
240
  peerDependencies: peerDependencies,
241
+ dependencies: dependencies,
215
242
  devDependencies: devDependencies
216
243
  };
217
244
 
@@ -234,12 +261,38 @@ Support with variables: 'PKG_NAME',
234
261
  const { notWorkspace } = getWD();
235
262
  const IS_WORKSPACE = !notWorkspace;
236
263
 
237
- commander.program.name("jk/jiek").version(pkg.version).description(`${pkg.description} - Version ${pkg.version}`).option("-c, --config-path <configPath>", "Custom jiek config path");
264
+ 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.");
238
265
  if (type$1 !== "" && IS_WORKSPACE) {
239
266
  commander.program.option("-f, --filter <filter>", filterDescription);
240
267
  }
241
268
 
242
- const require$3 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli-only-build.cjs', document.baseURI).href)));
269
+ const BUILDER_TYPES = ["esbuild", "swc"];
270
+ const BUILDER_TYPE_PACKAGE_NAME_MAP = {
271
+ esbuild: "rollup-plugin-esbuild",
272
+ swc: "rollup-plugin-swc3"
273
+ };
274
+
275
+ const createServer = (port, host) => {
276
+ const app = new Koa__default.default();
277
+ app.listen(port, host);
278
+ const streams = /* @__PURE__ */ new Map();
279
+ app.use(async (ctx) => {
280
+ const stream = streams.get(ctx.path);
281
+ if (stream != null) {
282
+ ctx.body = stream;
283
+ }
284
+ });
285
+ return {
286
+ port,
287
+ host,
288
+ rootUrl: `http://${host}:${port}`,
289
+ renderTo: async (path, stream) => {
290
+ streams.set(path, stream);
291
+ }
292
+ };
293
+ };
294
+
295
+ const require$3 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-only-build.cjs', document.baseURI).href)));
243
296
  function packageIsExist(name) {
244
297
  try {
245
298
  require$3.resolve(name);
@@ -262,7 +315,7 @@ for (const register of registers) {
262
315
  }
263
316
  }
264
317
 
265
- const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli-only-build.cjs', document.baseURI).href)));
318
+ const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-only-build.cjs', document.baseURI).href)));
266
319
  let configName = "jiek.config";
267
320
  function getConfigPath(root, dir) {
268
321
  const isSupportTsLoader = !!tsRegisterName;
@@ -297,10 +350,7 @@ function getConfigPath(root, dir) {
297
350
  function loadConfig(dirOrOptions) {
298
351
  let dir;
299
352
  let root;
300
- if (typeof dirOrOptions === "object") {
301
- dir = dirOrOptions.dir;
302
- root = dirOrOptions.root ?? getWD().wd;
303
- } else {
353
+ {
304
354
  dir = dirOrOptions;
305
355
  root = getWD().wd;
306
356
  }
@@ -345,17 +395,11 @@ function loadConfig(dirOrOptions) {
345
395
  return module.default ?? module;
346
396
  }
347
397
 
348
- const BUILDER_TYPES = ["esbuild", "swc"];
349
- const BUILDER_TYPE_PACKAGE_NAME_MAP = {
350
- esbuild: "rollup-plugin-esbuild",
351
- swc: "rollup-plugin-swc3"
352
- };
353
-
354
398
  const FILE_TEMPLATE = (manifest) => `
355
399
  module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
356
400
  `.trimStart();
357
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli-only-build.cjs', document.baseURI).href)));
358
- const isDefault = process.env.JIEK_IS_ONLY_BUILD === "true";
401
+ const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-only-build.cjs', document.baseURI).href)));
402
+ const isDefault = process__default.default.env.JIEK_IS_ONLY_BUILD === "true";
359
403
  const description = `
360
404
  Build the package according to the 'exports' field from the package.json.
361
405
  If you want to through the options to the \`rollup\` command, you can pass the options after '--'.
@@ -364,7 +408,7 @@ ${isDefault ? "This command is the default command." : ""}
364
408
  async function checkDependency(dependency) {
365
409
  try {
366
410
  require$1.resolve(dependency);
367
- } catch (e) {
411
+ } catch {
368
412
  console.error(`The package '${dependency}' is not installed, please install it first.`);
369
413
  const { notWorkspace } = getWD();
370
414
  const command2 = `pnpm install -${notWorkspace ? "" : "w"}D ${dependency}`;
@@ -372,7 +416,7 @@ async function checkDependency(dependency) {
372
416
  await execa.execaCommand(command2);
373
417
  } else {
374
418
  console.warn(`You can run the command '${command2}' to install it manually.`);
375
- process.exit(1);
419
+ process__default.default.exit(1);
376
420
  }
377
421
  }
378
422
  }
@@ -400,7 +444,7 @@ const buildEntriesDescription = `
400
444
  ${entriesDescription}
401
445
  If you pass the --entries option, it will merge into the entries of the command.
402
446
  `.trim();
403
- const command = isDefault ? (() => {
447
+ let command = isDefault ? (() => {
404
448
  const c = commander.program.name("jb/jiek-build").helpCommand(false);
405
449
  if (IS_WORKSPACE) {
406
450
  c.argument("[filters]", buildFilterDescription);
@@ -409,7 +453,7 @@ const command = isDefault ? (() => {
409
453
  }
410
454
  return c;
411
455
  })() : commander.program.command(`build [${IS_WORKSPACE ? "filters" : "entries"}]`);
412
- command.description(description).option("-t, --type <TYPE>", `The type of build, support ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}.`, (v) => {
456
+ command = command.description(description).option("-t, --type <TYPE>", `The type of build, support ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}.`, (v) => {
413
457
  if (!BUILDER_TYPES.includes(v)) {
414
458
  throw new Error(`The value of 'type' must be ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}`);
415
459
  }
@@ -427,7 +471,16 @@ command.description(description).option("-t, --type <TYPE>", `The type of build,
427
471
  "-om, --onlyMin",
428
472
  "Only output minify files, but dts files will still be output, it only replaces the js files.",
429
473
  parseBoolean
430
- ).option("--tsconfig <TSCONFIG>", "The path of the tsconfig file which is used to generate js and dts files.", String).option("--dtsconfig <DTSCONFIG>", "The path of the tsconfig file which is used to generate dts files.", String).option("-w, --watch", "Watch the file changes.", parseBoolean).option("-s, --silent", "Don't display logs.", parseBoolean).option("-v, --verbose", "Display debug logs.", parseBoolean).action(async (commandFiltersOrEntries, options) => {
474
+ );
475
+ 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);
476
+ command = command.option("-w, --watch", "Watch the file changes.", parseBoolean).option("-p, --port <PORT>", "The port of the server.", Number.parseInt, 8888);
477
+ command = command.option("--ana", "Enable the bundle analyzer.", parseBoolean).option("--ana.dir <DIR>", "The directory of the bundle analyzer.", ".jk-analyses").option("--ana.mode <MODE>", 'The mode of the bundle analyzer, support "static", "json" and "server".', "server").option("--ana.open", "Open the bundle analyzer in the browser.", parseBoolean).option(
478
+ "--ana.size <SIZE>",
479
+ 'The default size of the bundle analyzer, support "stat", "parsed" and "gzip".',
480
+ "parsed"
481
+ );
482
+ command = command.option("-s, --silent", "Don't display logs.", parseBoolean).option("-v, --verbose", "Display debug logs.", parseBoolean);
483
+ command.action(async (commandFiltersOrEntries, options) => {
431
484
  let {
432
485
  type,
433
486
  outdir,
@@ -461,7 +514,7 @@ command.description(description).option("-t, --type <TYPE>", `The type of build,
461
514
  );
462
515
  }
463
516
  let shouldPassThrough = false;
464
- const passThroughOptions = process.argv.reduce(
517
+ const passThroughOptions = process__default.default.argv.reduce(
465
518
  (acc, value) => {
466
519
  if (shouldPassThrough) {
467
520
  acc.push(value);
@@ -473,6 +526,43 @@ command.description(description).option("-t, --type <TYPE>", `The type of build,
473
526
  },
474
527
  []
475
528
  );
529
+ const modules = [];
530
+ const cjsModules = [];
531
+ const esmModules = [];
532
+ let render;
533
+ const analyzer = options.ana ? {
534
+ dir: options["ana.dir"],
535
+ mode: options["ana.mode"],
536
+ open: options["ana.open"],
537
+ size: options["ana.size"]
538
+ } : void 0;
539
+ if (options.ana && ![
540
+ "stat",
541
+ "parsed",
542
+ "gzip"
543
+ ].includes(analyzer?.size ?? "")) {
544
+ throw new Error('The value of `ana.size` must be "stat", "parsed" or "gzip"');
545
+ }
546
+ const server = analyzer && createServer(options.port, "localhost");
547
+ if (analyzer) {
548
+ await checkDependency("vite-bundle-analyzer");
549
+ const { renderView } = await import('vite-bundle-analyzer');
550
+ render = renderView;
551
+ }
552
+ const anaPaths = /* @__PURE__ */ new Set();
553
+ const refreshAnalyzer = async (subPath = "", renderModules = modules) => {
554
+ if (!(analyzer && server && render))
555
+ return;
556
+ const p = `/ana${subPath}`;
557
+ anaPaths.add(p);
558
+ void server.renderTo(
559
+ p,
560
+ await render(renderModules, {
561
+ title: `Jiek Analyzer - ${subPath}`,
562
+ mode: analyzer.size
563
+ })
564
+ );
565
+ };
476
566
  const { build } = loadConfig();
477
567
  silent = silent ?? build?.silent ?? false;
478
568
  if (withoutMin && onlyMin) {
@@ -489,7 +579,7 @@ command.description(description).option("-t, --type <TYPE>", `The type of build,
489
579
  entries = void 0;
490
580
  }
491
581
  const env = {
492
- ...process.env,
582
+ JIEK_ANALYZER: analyzer && JSON.stringify(analyzer),
493
583
  JIEK_BUILDER: type,
494
584
  JIEK_OUT_DIR: outdir,
495
585
  JIEK_CLEAN: String(!noClean),
@@ -501,7 +591,8 @@ command.description(description).option("-t, --type <TYPE>", `The type of build,
501
591
  JIEK_ONLY_MINIFY: String(onlyMin),
502
592
  JIEK_MINIFY_TYPE: minifyType,
503
593
  JIEK_TSCONFIG: tsconfig,
504
- JIEK_DTSCONFIG: dtsconfig
594
+ JIEK_DTSCONFIG: dtsconfig,
595
+ ...process__default.default.env
505
596
  };
506
597
  const multiBars = new cliProgress.MultiBar({
507
598
  clearOnComplete: false,
@@ -516,27 +607,44 @@ command.description(description).option("-t, --type <TYPE>", `The type of build,
516
607
  throw new Error("no package found");
517
608
  }
518
609
  const wdNodeModules = path__default.default.resolve(wd, "node_modules");
519
- if (!fs__default.default.existsSync(wdNodeModules)) {
520
- fs__default.default.mkdirSync(wdNodeModules);
610
+ if (!fs.existsSync(wdNodeModules)) {
611
+ fs.mkdirSync(wdNodeModules);
521
612
  }
522
613
  const jiekTempDir = (...paths) => path__default.default.resolve(wdNodeModules, ".jiek", ...paths);
523
- if (!fs__default.default.existsSync(jiekTempDir())) {
524
- fs__default.default.mkdirSync(jiekTempDir());
614
+ if (!fs.existsSync(jiekTempDir())) {
615
+ fs.mkdirSync(jiekTempDir());
525
616
  }
526
617
  const rollupBinaryPath = require$1.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
527
618
  let i = 0;
528
619
  await Promise.all(
529
620
  Object.entries(value).map(async ([dir, manifest]) => {
530
- if (!manifest.name) {
621
+ if (manifest.name == null) {
531
622
  throw new Error("package.json must have a name field");
532
623
  }
624
+ if (analyzer) {
625
+ const anaDir = path__default.default.resolve(dir, analyzer.dir);
626
+ if (!fs.existsSync(anaDir)) {
627
+ fs.mkdirSync(anaDir, { recursive: true });
628
+ }
629
+ const gitIgnorePath = path__default.default.resolve(anaDir, ".gitignore");
630
+ if (!fs.existsSync(gitIgnorePath)) {
631
+ fs.writeFileSync(gitIgnorePath, "*\n!.gitignore\n");
632
+ }
633
+ const npmIgnorePath = path__default.default.resolve(anaDir, ".npmignore");
634
+ if (!fs.existsSync(npmIgnorePath)) {
635
+ fs.writeFileSync(npmIgnorePath, "*\n");
636
+ }
637
+ if (!fs.statSync(anaDir).isDirectory()) {
638
+ throw new Error(`The directory '${anaDir}' is not a directory.`);
639
+ }
640
+ }
533
641
  const escapeManifestName = manifest.name.replace(/^@/g, "").replace(/\//g, "+");
534
642
  const configFile = jiekTempDir(
535
643
  `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
536
644
  );
537
- fs__default.default.writeFileSync(configFile, FILE_TEMPLATE(manifest));
645
+ fs.writeFileSync(configFile, FILE_TEMPLATE(manifest));
538
646
  const command2 = [rollupBinaryPath, "--silent", "-c", configFile];
539
- if (tsRegisterName) {
647
+ if (tsRegisterName != null) {
540
648
  command2.unshift(`node -r ${tsRegisterName}`);
541
649
  }
542
650
  if (watch) {
@@ -557,89 +665,141 @@ command.description(description).option("-t, --type <TYPE>", `The type of build,
557
665
  const locks = {};
558
666
  let inputMaxLen = 10;
559
667
  child.on("message", (e) => {
560
- if (e.type === "debug")
561
- console.log(...Array.isArray(e.data) ? e.data : [e.data]);
562
- });
563
- !silent && child.on("message", (e) => {
564
- if (e.type === "init") {
565
- const { leafMap, targetsLength } = e.data;
566
- const leafs = Array.from(leafMap.entries()).flatMap(
567
- ([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
568
- input,
668
+ if (silent && [
669
+ "init",
670
+ "progress",
671
+ "watchChange"
672
+ ].includes(e.type))
673
+ return;
674
+ switch (e.type) {
675
+ case "init": {
676
+ const { leafMap, targetsLength } = e.data;
677
+ const leafs = Array.from(leafMap.entries()).flatMap(
678
+ ([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
679
+ input,
680
+ path: path2,
681
+ conditions
682
+ }))
683
+ );
684
+ let initMessage = `Package '${manifest.name}' has ${targetsLength} targets to build`;
685
+ if (watch) {
686
+ initMessage += " and watching...";
687
+ }
688
+ console.log(initMessage);
689
+ leafs.forEach(({ input }) => {
690
+ inputMaxLen = Math.max(inputMaxLen, input.length);
691
+ });
692
+ leafs.forEach(({ input, path: path2 }) => {
693
+ const key = `${input}:${path2}`;
694
+ if (bars[key])
695
+ return;
696
+ bars[key] = multiBars.create(50, 0, {
697
+ pkgName: manifest.name,
698
+ input: input.padEnd(inputMaxLen + 5),
699
+ status: "waiting".padEnd(10)
700
+ }, {
701
+ barsize: 20,
702
+ linewrap: true
703
+ });
704
+ });
705
+ break;
706
+ }
707
+ case "progress": {
708
+ const {
569
709
  path: path2,
570
- conditions
571
- }))
572
- );
573
- let initMessage = `Package '${manifest.name}' has ${targetsLength} targets to build`;
574
- if (watch) {
575
- initMessage += " and watching...";
710
+ tags,
711
+ input,
712
+ event,
713
+ message
714
+ } = e.data;
715
+ const bar = bars[`${input}:${path2}`];
716
+ if (!bar)
717
+ return;
718
+ const time = times[`${input}:${path2}`];
719
+ bar.update(
720
+ {
721
+ start: 0,
722
+ resolve: 20,
723
+ end: 50
724
+ }[event ?? "start"] ?? 0,
725
+ {
726
+ input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
727
+ status: event?.padEnd(10),
728
+ message: `${tags?.join(", ")}: ${message}`
729
+ }
730
+ );
731
+ break;
576
732
  }
577
- console.log(initMessage);
578
- leafs.forEach(({ input }) => {
579
- inputMaxLen = Math.max(inputMaxLen, input.length);
580
- });
581
- leafs.forEach(({ input, path: path2 }) => {
733
+ case "watchChange": {
734
+ const {
735
+ path: path2,
736
+ input
737
+ } = e.data;
582
738
  const key = `${input}:${path2}`;
583
- if (bars[key])
739
+ const bar = bars[key];
740
+ if (!bar)
584
741
  return;
585
- bars[key] = multiBars.create(50, 0, {
586
- pkgName: manifest.name,
587
- input: input.padEnd(inputMaxLen + 5),
588
- status: "waiting".padEnd(10)
589
- }, {
590
- barsize: 20,
591
- linewrap: true
592
- });
593
- });
594
- }
595
- if (e.type === "progress") {
596
- const {
597
- path: path2,
598
- tags,
599
- input,
600
- event,
601
- message
602
- } = e.data;
603
- const bar = bars[`${input}:${path2}`];
604
- if (!bar)
605
- return;
606
- const time = times[`${input}:${path2}`];
607
- bar.update(
608
- {
609
- start: 0,
610
- resolve: 20,
611
- end: 50
612
- }[event ?? "start"] ?? 0,
613
- {
614
- input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
615
- status: event?.padEnd(10),
616
- message: `${tags?.join(", ")}: ${message}`
742
+ let time = times[key] ?? 1;
743
+ if (!locks[key]) {
744
+ time += 1;
745
+ times[key] = time;
746
+ setTimeout(() => {
747
+ locks[key] = false;
748
+ }, 100);
749
+ bar.update(0, {
750
+ input: `${input}(x${time.toString().padStart(2, "0")})`.padEnd(inputMaxLen + 5),
751
+ status: "watching".padEnd(10),
752
+ message: "watching..."
753
+ });
617
754
  }
618
- );
619
- }
620
- if (e.type === "watchChange") {
621
- const {
622
- path: path2,
623
- input
624
- } = e.data;
625
- const key = `${input}:${path2}`;
626
- const bar = bars[key];
627
- if (!bar)
628
- return;
629
- let time = times[key] ?? 1;
630
- if (!locks[key]) {
631
- time += 1;
632
- times[key] = time;
633
- setTimeout(() => {
634
- locks[key] = false;
635
- }, 100);
636
- bar.update(0, {
637
- input: `${input}(x${time.toString().padStart(2, "0")})`.padEnd(inputMaxLen + 5),
638
- status: "watching".padEnd(10),
639
- message: "watching..."
755
+ locks[key] = true;
756
+ break;
757
+ }
758
+ case "modulesAnalyze": {
759
+ const {
760
+ data: {
761
+ type: type2,
762
+ path: path2,
763
+ modules: pkgModules
764
+ }
765
+ } = e;
766
+ pkgModules.forEach((m) => {
767
+ const newM = {
768
+ ...m,
769
+ filename: `${manifest.name}/${m.filename}`,
770
+ label: `${manifest.name}/${m.label}`
771
+ };
772
+ const pushOrReplace = (arr) => {
773
+ const index = arr.findIndex(({ filename }) => filename === newM.filename);
774
+ if (index === -1) {
775
+ arr.push(newM);
776
+ } else {
777
+ arr[index] = newM;
778
+ }
779
+ };
780
+ pushOrReplace(modules);
781
+ if (type2 === "esm") {
782
+ pushOrReplace(esmModules);
783
+ }
784
+ if (type2 === "cjs") {
785
+ pushOrReplace(cjsModules);
786
+ }
640
787
  });
788
+ void refreshAnalyzer();
789
+ void refreshAnalyzer(
790
+ `/${type2}`,
791
+ {
792
+ cjs: cjsModules,
793
+ esm: esmModules
794
+ }[type2]
795
+ );
796
+ void refreshAnalyzer(`/${type2}/${manifest.name}/${path2.slice(2)}`, pkgModules);
797
+ break;
798
+ }
799
+ case "debug": {
800
+ console.log(...Array.isArray(e.data) ? e.data : [e.data]);
801
+ break;
641
802
  }
642
- locks[key] = true;
643
803
  }
644
804
  });
645
805
  await new Promise((resolve, reject) => {
@@ -649,7 +809,7 @@ command.description(description).option("-t, --type <TYPE>", `The type of build,
649
809
  });
650
810
  child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`rollup build failed:
651
811
  ${errorStr}`)));
652
- verbose && child.stdout?.pipe(process.stdout);
812
+ verbose && child.stdout?.pipe(process__default.default.stdout);
653
813
  });
654
814
  })
655
815
  );
@@ -670,11 +830,43 @@ ${errorStr}`)));
670
830
  }
671
831
  } finally {
672
832
  multiBars.stop();
833
+ let message = "The build is complete";
834
+ if (analyzer) {
835
+ message += ` and the analyzer is running at http://localhost:${options.port}/ana in ${analyzer.mode} mode.
836
+ `;
837
+ message += analyzer.open ? " The browser will open automatically.\n" : "";
838
+ if (anaPaths.size > 0) {
839
+ message += `The analyzer has ${anaPaths.size} pages:
840
+ ${Array.from(anaPaths).map((p) => `http://localhost:${options.port}${p}`).join("\n")}`;
841
+ }
842
+ }
843
+ !silent && console.log(message);
673
844
  }
674
845
  });
675
846
 
676
- if (process.env.JIEK_IS_ONLY_BUILD === "true") {
677
- import('commander').then(({ program }) => {
678
- program.parse(process.argv);
679
- });
847
+ const { argv } = process__default.default;
848
+ const env = {};
849
+ let isPassThrough = false;
850
+ const newArgv = argv.filter((arg) => {
851
+ if (isPassThrough) {
852
+ return true;
853
+ }
854
+ if (arg === "--") {
855
+ isPassThrough = true;
856
+ return false;
857
+ }
858
+ const m = /^--env\.(\w+)=(.*)$/.exec(arg);
859
+ if (m) {
860
+ env[m[1]] = m[2];
861
+ return false;
862
+ }
863
+ return true;
864
+ });
865
+ for (const [key, value] of Object.entries(env)) {
866
+ process__default.default.env[key] = value;
867
+ }
868
+ var parseArgv = () => commander.program.parse(newArgv);
869
+
870
+ if (process__default.default.env.JIEK_IS_ONLY_BUILD === "true") {
871
+ parseArgv();
680
872
  }