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