jiek 2.1.11 → 2.1.13-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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.13";
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
- prepublish: "jb -nm && jk",
162
+ prepublish: "pnpm test ./tests/publish.spec.ts && 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,48 @@ 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
- const jiekTempDir = (...paths) => path.resolve(wdNodeModules, ".jiek", ...paths);
515
- if (!fs.existsSync(jiekTempDir())) {
516
- fs.mkdirSync(jiekTempDir());
603
+ const resolveByJiekTemp = (...paths) => path.resolve(wdNodeModules, ".jiek", ...paths);
604
+ const jiekTemp = resolveByJiekTemp();
605
+ if (!existsSync(jiekTemp)) {
606
+ try {
607
+ mkdirSync(jiekTemp);
608
+ } catch {
609
+ }
517
610
  }
518
611
  const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
519
612
  let i = 0;
520
613
  await Promise.all(
521
614
  Object.entries(value).map(async ([dir, manifest]) => {
522
- if (!manifest.name) {
615
+ if (manifest.name == null) {
523
616
  throw new Error("package.json must have a name field");
524
617
  }
618
+ if (analyzer) {
619
+ const anaDir = path.resolve(dir, analyzer.dir);
620
+ if (!existsSync(anaDir)) {
621
+ mkdirSync(anaDir, { recursive: true });
622
+ }
623
+ const gitIgnorePath = path.resolve(anaDir, ".gitignore");
624
+ if (!existsSync(gitIgnorePath)) {
625
+ writeFileSync(gitIgnorePath, "*\n!.gitignore\n");
626
+ }
627
+ const npmIgnorePath = path.resolve(anaDir, ".npmignore");
628
+ if (!existsSync(npmIgnorePath)) {
629
+ writeFileSync(npmIgnorePath, "*\n");
630
+ }
631
+ if (!statSync(anaDir).isDirectory()) {
632
+ throw new Error(`The directory '${anaDir}' is not a directory.`);
633
+ }
634
+ }
525
635
  const escapeManifestName = manifest.name.replace(/^@/g, "").replace(/\//g, "+");
526
- const configFile = jiekTempDir(
636
+ const configFile = resolveByJiekTemp(
527
637
  `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
528
638
  );
529
- fs.writeFileSync(configFile, FILE_TEMPLATE(manifest));
639
+ writeFileSync(configFile, FILE_TEMPLATE(manifest));
530
640
  const command2 = [rollupBinaryPath, "--silent", "-c", configFile];
531
- if (tsRegisterName) {
641
+ if (tsRegisterName != null) {
532
642
  command2.unshift(`node -r ${tsRegisterName}`);
533
643
  }
534
644
  if (watch) {
@@ -549,89 +659,141 @@ command.description(description).option("-t, --type <TYPE>", `The type of build,
549
659
  const locks = {};
550
660
  let inputMaxLen = 10;
551
661
  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,
662
+ if (silent && [
663
+ "init",
664
+ "progress",
665
+ "watchChange"
666
+ ].includes(e.type))
667
+ return;
668
+ switch (e.type) {
669
+ case "init": {
670
+ const { leafMap, targetsLength } = e.data;
671
+ const leafs = Array.from(leafMap.entries()).flatMap(
672
+ ([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
673
+ input,
674
+ path: path2,
675
+ conditions
676
+ }))
677
+ );
678
+ let initMessage = `Package '${manifest.name}' has ${targetsLength} targets to build`;
679
+ if (watch) {
680
+ initMessage += " and watching...";
681
+ }
682
+ console.log(initMessage);
683
+ leafs.forEach(({ input }) => {
684
+ inputMaxLen = Math.max(inputMaxLen, input.length);
685
+ });
686
+ leafs.forEach(({ input, path: path2 }) => {
687
+ const key = `${input}:${path2}`;
688
+ if (bars[key])
689
+ return;
690
+ bars[key] = multiBars.create(50, 0, {
691
+ pkgName: manifest.name,
692
+ input: input.padEnd(inputMaxLen + 5),
693
+ status: "waiting".padEnd(10)
694
+ }, {
695
+ barsize: 20,
696
+ linewrap: true
697
+ });
698
+ });
699
+ break;
700
+ }
701
+ case "progress": {
702
+ const {
561
703
  path: path2,
562
- conditions
563
- }))
564
- );
565
- let initMessage = `Package '${manifest.name}' has ${targetsLength} targets to build`;
566
- if (watch) {
567
- initMessage += " and watching...";
704
+ tags,
705
+ input,
706
+ event,
707
+ message
708
+ } = e.data;
709
+ const bar = bars[`${input}:${path2}`];
710
+ if (!bar)
711
+ return;
712
+ const time = times[`${input}:${path2}`];
713
+ bar.update(
714
+ {
715
+ start: 0,
716
+ resolve: 20,
717
+ end: 50
718
+ }[event ?? "start"] ?? 0,
719
+ {
720
+ input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
721
+ status: event?.padEnd(10),
722
+ message: `${tags?.join(", ")}: ${message}`
723
+ }
724
+ );
725
+ break;
568
726
  }
569
- console.log(initMessage);
570
- leafs.forEach(({ input }) => {
571
- inputMaxLen = Math.max(inputMaxLen, input.length);
572
- });
573
- leafs.forEach(({ input, path: path2 }) => {
727
+ case "watchChange": {
728
+ const {
729
+ path: path2,
730
+ input
731
+ } = e.data;
574
732
  const key = `${input}:${path2}`;
575
- if (bars[key])
733
+ const bar = bars[key];
734
+ if (!bar)
576
735
  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}`
736
+ let time = times[key] ?? 1;
737
+ if (!locks[key]) {
738
+ time += 1;
739
+ times[key] = time;
740
+ setTimeout(() => {
741
+ locks[key] = false;
742
+ }, 100);
743
+ bar.update(0, {
744
+ input: `${input}(x${time.toString().padStart(2, "0")})`.padEnd(inputMaxLen + 5),
745
+ status: "watching".padEnd(10),
746
+ message: "watching..."
747
+ });
609
748
  }
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..."
749
+ locks[key] = true;
750
+ break;
751
+ }
752
+ case "modulesAnalyze": {
753
+ const {
754
+ data: {
755
+ type: type2,
756
+ path: path2,
757
+ modules: pkgModules
758
+ }
759
+ } = e;
760
+ pkgModules.forEach((m) => {
761
+ const newM = {
762
+ ...m,
763
+ filename: `${manifest.name}/${m.filename}`,
764
+ label: `${manifest.name}/${m.label}`
765
+ };
766
+ const pushOrReplace = (arr) => {
767
+ const index = arr.findIndex(({ filename }) => filename === newM.filename);
768
+ if (index === -1) {
769
+ arr.push(newM);
770
+ } else {
771
+ arr[index] = newM;
772
+ }
773
+ };
774
+ pushOrReplace(modules);
775
+ if (type2 === "esm") {
776
+ pushOrReplace(esmModules);
777
+ }
778
+ if (type2 === "cjs") {
779
+ pushOrReplace(cjsModules);
780
+ }
632
781
  });
782
+ void refreshAnalyzer();
783
+ void refreshAnalyzer(
784
+ `/${type2}`,
785
+ {
786
+ cjs: cjsModules,
787
+ esm: esmModules
788
+ }[type2]
789
+ );
790
+ void refreshAnalyzer(`/${type2}/${manifest.name}/${path2.slice(2)}`, pkgModules);
791
+ break;
792
+ }
793
+ case "debug": {
794
+ console.log(...Array.isArray(e.data) ? e.data : [e.data]);
795
+ break;
633
796
  }
634
- locks[key] = true;
635
797
  }
636
798
  });
637
799
  await new Promise((resolve, reject) => {
@@ -641,7 +803,7 @@ command.description(description).option("-t, --type <TYPE>", `The type of build,
641
803
  });
642
804
  child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`rollup build failed:
643
805
  ${errorStr}`)));
644
- verbose && child.stdout?.pipe(process.stdout);
806
+ verbose && child.stdout?.pipe(process$1.stdout);
645
807
  });
646
808
  })
647
809
  );
@@ -662,11 +824,43 @@ ${errorStr}`)));
662
824
  }
663
825
  } finally {
664
826
  multiBars.stop();
827
+ let message = "The build is complete";
828
+ if (analyzer) {
829
+ message += ` and the analyzer is running at http://localhost:${options.port}/ana in ${analyzer.mode} mode.
830
+ `;
831
+ message += analyzer.open ? " The browser will open automatically.\n" : "";
832
+ if (anaPaths.size > 0) {
833
+ message += `The analyzer has ${anaPaths.size} pages:
834
+ ${Array.from(anaPaths).map((p) => `http://localhost:${options.port}${p}`).join("\n")}`;
835
+ }
836
+ }
837
+ !silent && console.log(message);
665
838
  }
666
839
  });
667
840
 
668
- if (process.env.JIEK_IS_ONLY_BUILD === "true") {
669
- import('commander').then(({ program }) => {
670
- program.parse(process.argv);
671
- });
841
+ const { argv } = process$1;
842
+ const env = {};
843
+ let isPassThrough = false;
844
+ const newArgv = argv.filter((arg) => {
845
+ if (isPassThrough) {
846
+ return true;
847
+ }
848
+ if (arg === "--") {
849
+ isPassThrough = true;
850
+ return false;
851
+ }
852
+ const m = /^--env\.(\w+)=(.*)$/.exec(arg);
853
+ if (m) {
854
+ env[m[1]] = m[2];
855
+ return false;
856
+ }
857
+ return true;
858
+ });
859
+ for (const [key, value] of Object.entries(env)) {
860
+ process$1.env[key] = value;
861
+ }
862
+ var parseArgv = () => program.parse(newArgv);
863
+
864
+ if (process$1.env.JIEK_IS_ONLY_BUILD === "true") {
865
+ parseArgv();
672
866
  }