jiek 2.1.12 → 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.
@@ -10,6 +10,7 @@ var process$1 = require('node:process');
10
10
  var prompts = require('@inquirer/prompts');
11
11
  var cliProgress = require('cli-progress');
12
12
  var execa = require('execa');
13
+ var Koa = require('koa');
13
14
 
14
15
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
15
16
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -17,6 +18,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
17
18
  var fs__default = /*#__PURE__*/_interopDefault(fs);
18
19
  var path__default = /*#__PURE__*/_interopDefault(path);
19
20
  var process__default = /*#__PURE__*/_interopDefault(process$1);
21
+ var Koa__default = /*#__PURE__*/_interopDefault(Koa);
20
22
 
21
23
  let root;
22
24
  function getRoot() {
@@ -118,7 +120,7 @@ async function getSelectedProjectsGraph(filter = commander.program.getOptionValu
118
120
 
119
121
  var name = "jiek";
120
122
  var type = "module";
121
- var version = "2.1.11";
123
+ var version = "2.1.12";
122
124
  var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
123
125
  var author = "YiJie <yijie4188@gmail.com>";
124
126
  var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
@@ -127,6 +129,16 @@ var repository = {
127
129
  directory: "packages/jiek"
128
130
  };
129
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
+ ];
130
142
  var exports$1 = {
131
143
  "./package.json": "./package.json",
132
144
  ".": "./src/index.ts",
@@ -170,7 +182,7 @@ var peerDependencies = {
170
182
  "rollup-plugin-postcss": "^4.0.2",
171
183
  "rollup-plugin-swc3": "^0.12.1",
172
184
  typescript: "^4.0.0||^5.0.0",
173
- "vite-bundle-analyzer": "^0.15.1"
185
+ "vite-bundle-analyzer": "^0.15.2"
174
186
  };
175
187
  var dependencies = {
176
188
  "@inquirer/prompts": "^7.1.0",
@@ -188,6 +200,7 @@ var dependencies = {
188
200
  execa: "~9.3.1",
189
201
  "js-yaml": "^4.1.0",
190
202
  "jsonc-parser": "^3.2.1",
203
+ koa: "^2.15.3",
191
204
  rollup: "^4.0.0"
192
205
  };
193
206
  var devDependencies = {
@@ -198,6 +211,7 @@ var devDependencies = {
198
211
  "@types/cli-progress": "^3.11.5",
199
212
  "@types/inquirer": "^9.0.7",
200
213
  "@types/js-yaml": "^4.0.9",
214
+ "@types/koa": "^2.15.0",
201
215
  "@types/micromatch": "^4.0.6",
202
216
  "esbuild-register": "^3.5.0",
203
217
  micromatch: "^4.0.5",
@@ -206,7 +220,7 @@ var devDependencies = {
206
220
  "rollup-plugin-esbuild": "^6.1.0",
207
221
  "rollup-plugin-postcss": "^4.0.2",
208
222
  "rollup-plugin-swc3": "^0.12.1",
209
- "vite-bundle-analyzer": "^0.15.1"
223
+ "vite-bundle-analyzer": "^0.15.2"
210
224
  };
211
225
  var pkg = {
212
226
  name: name,
@@ -217,6 +231,7 @@ var pkg = {
217
231
  homepage: homepage,
218
232
  repository: repository,
219
233
  bugs: bugs,
234
+ keywords: keywords,
220
235
  exports: exports$1,
221
236
  imports: imports,
222
237
  bin: bin,
@@ -251,6 +266,32 @@ if (type$1 !== "" && IS_WORKSPACE) {
251
266
  commander.program.option("-f, --filter <filter>", filterDescription);
252
267
  }
253
268
 
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
+
254
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)));
255
296
  function packageIsExist(name) {
256
297
  try {
@@ -354,12 +395,6 @@ function loadConfig(dirOrOptions) {
354
395
  return module.default ?? module;
355
396
  }
356
397
 
357
- const BUILDER_TYPES = ["esbuild", "swc"];
358
- const BUILDER_TYPE_PACKAGE_NAME_MAP = {
359
- esbuild: "rollup-plugin-esbuild",
360
- swc: "rollup-plugin-swc3"
361
- };
362
-
363
398
  const FILE_TEMPLATE = (manifest) => `
364
399
  module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
365
400
  `.trimStart();
@@ -438,8 +473,8 @@ command = command.description(description).option("-t, --type <TYPE>", `The type
438
473
  parseBoolean
439
474
  );
440
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);
441
- command = command.option("-w, --watch", "Watch the file changes.", parseBoolean);
442
- 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.port <PORT>", "The port of the bundle analyzer.", Number.parseInt).option("--ana.open", "Open the bundle analyzer in the browser.", parseBoolean).option(
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(
443
478
  "--ana.size <SIZE>",
444
479
  'The default size of the bundle analyzer, support "stat", "parsed" and "gzip".',
445
480
  "parsed"
@@ -491,16 +526,43 @@ command.action(async (commandFiltersOrEntries, options) => {
491
526
  },
492
527
  []
493
528
  );
529
+ const modules = [];
530
+ const cjsModules = [];
531
+ const esmModules = [];
532
+ let render;
494
533
  const analyzer = options.ana ? {
495
534
  dir: options["ana.dir"],
496
535
  mode: options["ana.mode"],
497
- port: options["ana.port"],
498
536
  open: options["ana.open"],
499
537
  size: options["ana.size"]
500
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");
501
547
  if (analyzer) {
502
548
  await checkDependency("vite-bundle-analyzer");
549
+ const { renderView } = await import('vite-bundle-analyzer');
550
+ render = renderView;
503
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
+ };
504
566
  const { build } = loadConfig();
505
567
  silent = silent ?? build?.silent ?? false;
506
568
  if (withoutMin && onlyMin) {
@@ -545,12 +607,12 @@ command.action(async (commandFiltersOrEntries, options) => {
545
607
  throw new Error("no package found");
546
608
  }
547
609
  const wdNodeModules = path__default.default.resolve(wd, "node_modules");
548
- if (!fs__default.default.existsSync(wdNodeModules)) {
549
- fs__default.default.mkdirSync(wdNodeModules);
610
+ if (!fs.existsSync(wdNodeModules)) {
611
+ fs.mkdirSync(wdNodeModules);
550
612
  }
551
613
  const jiekTempDir = (...paths) => path__default.default.resolve(wdNodeModules, ".jiek", ...paths);
552
- if (!fs__default.default.existsSync(jiekTempDir())) {
553
- fs__default.default.mkdirSync(jiekTempDir());
614
+ if (!fs.existsSync(jiekTempDir())) {
615
+ fs.mkdirSync(jiekTempDir());
554
616
  }
555
617
  const rollupBinaryPath = require$1.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
556
618
  let i = 0;
@@ -562,15 +624,15 @@ command.action(async (commandFiltersOrEntries, options) => {
562
624
  if (analyzer) {
563
625
  const anaDir = path__default.default.resolve(dir, analyzer.dir);
564
626
  if (!fs.existsSync(anaDir)) {
565
- fs__default.default.mkdirSync(anaDir, { recursive: true });
627
+ fs.mkdirSync(anaDir, { recursive: true });
566
628
  }
567
629
  const gitIgnorePath = path__default.default.resolve(anaDir, ".gitignore");
568
630
  if (!fs.existsSync(gitIgnorePath)) {
569
- fs__default.default.writeFileSync(gitIgnorePath, "*\n!.gitignore\n");
631
+ fs.writeFileSync(gitIgnorePath, "*\n!.gitignore\n");
570
632
  }
571
633
  const npmIgnorePath = path__default.default.resolve(anaDir, ".npmignore");
572
634
  if (!fs.existsSync(npmIgnorePath)) {
573
- fs__default.default.writeFileSync(npmIgnorePath, "*\n");
635
+ fs.writeFileSync(npmIgnorePath, "*\n");
574
636
  }
575
637
  if (!fs.statSync(anaDir).isDirectory()) {
576
638
  throw new Error(`The directory '${anaDir}' is not a directory.`);
@@ -580,7 +642,7 @@ command.action(async (commandFiltersOrEntries, options) => {
580
642
  const configFile = jiekTempDir(
581
643
  `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
582
644
  );
583
- fs__default.default.writeFileSync(configFile, FILE_TEMPLATE(manifest));
645
+ fs.writeFileSync(configFile, FILE_TEMPLATE(manifest));
584
646
  const command2 = [rollupBinaryPath, "--silent", "-c", configFile];
585
647
  if (tsRegisterName != null) {
586
648
  command2.unshift(`node -r ${tsRegisterName}`);
@@ -603,89 +665,141 @@ command.action(async (commandFiltersOrEntries, options) => {
603
665
  const locks = {};
604
666
  let inputMaxLen = 10;
605
667
  child.on("message", (e) => {
606
- if (e.type === "debug")
607
- console.log(...Array.isArray(e.data) ? e.data : [e.data]);
608
- });
609
- !silent && child.on("message", (e) => {
610
- if (e.type === "init") {
611
- const { leafMap, targetsLength } = e.data;
612
- const leafs = Array.from(leafMap.entries()).flatMap(
613
- ([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
614
- 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 {
615
709
  path: path2,
616
- conditions
617
- }))
618
- );
619
- let initMessage = `Package '${manifest.name}' has ${targetsLength} targets to build`;
620
- if (watch) {
621
- 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;
622
732
  }
623
- console.log(initMessage);
624
- leafs.forEach(({ input }) => {
625
- inputMaxLen = Math.max(inputMaxLen, input.length);
626
- });
627
- leafs.forEach(({ input, path: path2 }) => {
733
+ case "watchChange": {
734
+ const {
735
+ path: path2,
736
+ input
737
+ } = e.data;
628
738
  const key = `${input}:${path2}`;
629
- if (bars[key])
739
+ const bar = bars[key];
740
+ if (!bar)
630
741
  return;
631
- bars[key] = multiBars.create(50, 0, {
632
- pkgName: manifest.name,
633
- input: input.padEnd(inputMaxLen + 5),
634
- status: "waiting".padEnd(10)
635
- }, {
636
- barsize: 20,
637
- linewrap: true
638
- });
639
- });
640
- }
641
- if (e.type === "progress") {
642
- const {
643
- path: path2,
644
- tags,
645
- input,
646
- event,
647
- message
648
- } = e.data;
649
- const bar = bars[`${input}:${path2}`];
650
- if (!bar)
651
- return;
652
- const time = times[`${input}:${path2}`];
653
- bar.update(
654
- {
655
- start: 0,
656
- resolve: 20,
657
- end: 50
658
- }[event ?? "start"] ?? 0,
659
- {
660
- input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
661
- status: event?.padEnd(10),
662
- 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
+ });
663
754
  }
664
- );
665
- }
666
- if (e.type === "watchChange") {
667
- const {
668
- path: path2,
669
- input
670
- } = e.data;
671
- const key = `${input}:${path2}`;
672
- const bar = bars[key];
673
- if (!bar)
674
- return;
675
- let time = times[key] ?? 1;
676
- if (!locks[key]) {
677
- time += 1;
678
- times[key] = time;
679
- setTimeout(() => {
680
- locks[key] = false;
681
- }, 100);
682
- bar.update(0, {
683
- input: `${input}(x${time.toString().padStart(2, "0")})`.padEnd(inputMaxLen + 5),
684
- status: "watching".padEnd(10),
685
- 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
+ }
686
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;
687
802
  }
688
- locks[key] = true;
689
803
  }
690
804
  });
691
805
  await new Promise((resolve, reject) => {
@@ -716,6 +830,17 @@ ${errorStr}`)));
716
830
  }
717
831
  } finally {
718
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);
719
844
  }
720
845
  });
721
846