jiek 2.1.12 → 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,4 +1,4 @@
1
- import fs, { existsSync, statSync } 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';
@@ -8,6 +8,7 @@ import process$1 from 'node:process';
8
8
  import { confirm } from '@inquirer/prompts';
9
9
  import { MultiBar, Presets } from 'cli-progress';
10
10
  import { execaCommand } from 'execa';
11
+ import Koa from 'koa';
11
12
 
12
13
  let root;
13
14
  function getRoot() {
@@ -109,7 +110,7 @@ async function getSelectedProjectsGraph(filter = program.getOptionValue("filter"
109
110
 
110
111
  var name = "jiek";
111
112
  var type = "module";
112
- var version = "2.1.11";
113
+ var version = "2.1.13";
113
114
  var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
114
115
  var author = "YiJie <yijie4188@gmail.com>";
115
116
  var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
@@ -118,6 +119,16 @@ var repository = {
118
119
  directory: "packages/jiek"
119
120
  };
120
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
+ ];
121
132
  var exports = {
122
133
  "./package.json": "./package.json",
123
134
  ".": "./src/index.ts",
@@ -148,7 +159,7 @@ var files = [
148
159
  "src"
149
160
  ];
150
161
  var scripts = {
151
- prepublish: "jb -nm && jk",
162
+ prepublish: "pnpm test ./tests/publish.spec.ts && jb -nm && jk",
152
163
  postpublish: "jk",
153
164
  test: "vitest run"
154
165
  };
@@ -161,7 +172,7 @@ var peerDependencies = {
161
172
  "rollup-plugin-postcss": "^4.0.2",
162
173
  "rollup-plugin-swc3": "^0.12.1",
163
174
  typescript: "^4.0.0||^5.0.0",
164
- "vite-bundle-analyzer": "^0.15.1"
175
+ "vite-bundle-analyzer": "^0.15.2"
165
176
  };
166
177
  var dependencies = {
167
178
  "@inquirer/prompts": "^7.1.0",
@@ -179,6 +190,7 @@ var dependencies = {
179
190
  execa: "~9.3.1",
180
191
  "js-yaml": "^4.1.0",
181
192
  "jsonc-parser": "^3.2.1",
193
+ koa: "^2.15.3",
182
194
  rollup: "^4.0.0"
183
195
  };
184
196
  var devDependencies = {
@@ -189,6 +201,7 @@ var devDependencies = {
189
201
  "@types/cli-progress": "^3.11.5",
190
202
  "@types/inquirer": "^9.0.7",
191
203
  "@types/js-yaml": "^4.0.9",
204
+ "@types/koa": "^2.15.0",
192
205
  "@types/micromatch": "^4.0.6",
193
206
  "esbuild-register": "^3.5.0",
194
207
  micromatch: "^4.0.5",
@@ -197,7 +210,7 @@ var devDependencies = {
197
210
  "rollup-plugin-esbuild": "^6.1.0",
198
211
  "rollup-plugin-postcss": "^4.0.2",
199
212
  "rollup-plugin-swc3": "^0.12.1",
200
- "vite-bundle-analyzer": "^0.15.1"
213
+ "vite-bundle-analyzer": "^0.15.2"
201
214
  };
202
215
  var pkg = {
203
216
  name: name,
@@ -208,6 +221,7 @@ var pkg = {
208
221
  homepage: homepage,
209
222
  repository: repository,
210
223
  bugs: bugs,
224
+ keywords: keywords,
211
225
  exports: exports,
212
226
  imports: imports,
213
227
  bin: bin,
@@ -242,6 +256,32 @@ if (type$1 !== "" && IS_WORKSPACE) {
242
256
  program.option("-f, --filter <filter>", filterDescription);
243
257
  }
244
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
+
245
285
  const require$2 = createRequire(import.meta.url);
246
286
  function packageIsExist(name) {
247
287
  try {
@@ -345,12 +385,6 @@ function loadConfig(dirOrOptions) {
345
385
  return module.default ?? module;
346
386
  }
347
387
 
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
388
  const FILE_TEMPLATE = (manifest) => `
355
389
  module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
356
390
  `.trimStart();
@@ -429,8 +463,8 @@ command = command.description(description).option("-t, --type <TYPE>", `The type
429
463
  parseBoolean
430
464
  );
431
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);
432
- command = command.option("-w, --watch", "Watch the file changes.", parseBoolean);
433
- 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(
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(
434
468
  "--ana.size <SIZE>",
435
469
  'The default size of the bundle analyzer, support "stat", "parsed" and "gzip".',
436
470
  "parsed"
@@ -482,16 +516,43 @@ command.action(async (commandFiltersOrEntries, options) => {
482
516
  },
483
517
  []
484
518
  );
519
+ const modules = [];
520
+ const cjsModules = [];
521
+ const esmModules = [];
522
+ let render;
485
523
  const analyzer = options.ana ? {
486
524
  dir: options["ana.dir"],
487
525
  mode: options["ana.mode"],
488
- port: options["ana.port"],
489
526
  open: options["ana.open"],
490
527
  size: options["ana.size"]
491
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");
492
537
  if (analyzer) {
493
538
  await checkDependency("vite-bundle-analyzer");
539
+ const { renderView } = await import('vite-bundle-analyzer');
540
+ render = renderView;
494
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
+ };
495
556
  const { build } = loadConfig();
496
557
  silent = silent ?? build?.silent ?? false;
497
558
  if (withoutMin && onlyMin) {
@@ -536,12 +597,16 @@ command.action(async (commandFiltersOrEntries, options) => {
536
597
  throw new Error("no package found");
537
598
  }
538
599
  const wdNodeModules = path.resolve(wd, "node_modules");
539
- if (!fs.existsSync(wdNodeModules)) {
540
- fs.mkdirSync(wdNodeModules);
600
+ if (!existsSync(wdNodeModules)) {
601
+ mkdirSync(wdNodeModules);
541
602
  }
542
- const jiekTempDir = (...paths) => path.resolve(wdNodeModules, ".jiek", ...paths);
543
- if (!fs.existsSync(jiekTempDir())) {
544
- 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
+ }
545
610
  }
546
611
  const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
547
612
  let i = 0;
@@ -553,25 +618,25 @@ command.action(async (commandFiltersOrEntries, options) => {
553
618
  if (analyzer) {
554
619
  const anaDir = path.resolve(dir, analyzer.dir);
555
620
  if (!existsSync(anaDir)) {
556
- fs.mkdirSync(anaDir, { recursive: true });
621
+ mkdirSync(anaDir, { recursive: true });
557
622
  }
558
623
  const gitIgnorePath = path.resolve(anaDir, ".gitignore");
559
624
  if (!existsSync(gitIgnorePath)) {
560
- fs.writeFileSync(gitIgnorePath, "*\n!.gitignore\n");
625
+ writeFileSync(gitIgnorePath, "*\n!.gitignore\n");
561
626
  }
562
627
  const npmIgnorePath = path.resolve(anaDir, ".npmignore");
563
628
  if (!existsSync(npmIgnorePath)) {
564
- fs.writeFileSync(npmIgnorePath, "*\n");
629
+ writeFileSync(npmIgnorePath, "*\n");
565
630
  }
566
631
  if (!statSync(anaDir).isDirectory()) {
567
632
  throw new Error(`The directory '${anaDir}' is not a directory.`);
568
633
  }
569
634
  }
570
635
  const escapeManifestName = manifest.name.replace(/^@/g, "").replace(/\//g, "+");
571
- const configFile = jiekTempDir(
636
+ const configFile = resolveByJiekTemp(
572
637
  `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
573
638
  );
574
- fs.writeFileSync(configFile, FILE_TEMPLATE(manifest));
639
+ writeFileSync(configFile, FILE_TEMPLATE(manifest));
575
640
  const command2 = [rollupBinaryPath, "--silent", "-c", configFile];
576
641
  if (tsRegisterName != null) {
577
642
  command2.unshift(`node -r ${tsRegisterName}`);
@@ -594,89 +659,141 @@ command.action(async (commandFiltersOrEntries, options) => {
594
659
  const locks = {};
595
660
  let inputMaxLen = 10;
596
661
  child.on("message", (e) => {
597
- if (e.type === "debug")
598
- console.log(...Array.isArray(e.data) ? e.data : [e.data]);
599
- });
600
- !silent && child.on("message", (e) => {
601
- if (e.type === "init") {
602
- const { leafMap, targetsLength } = e.data;
603
- const leafs = Array.from(leafMap.entries()).flatMap(
604
- ([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
605
- 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 {
606
703
  path: path2,
607
- conditions
608
- }))
609
- );
610
- let initMessage = `Package '${manifest.name}' has ${targetsLength} targets to build`;
611
- if (watch) {
612
- 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;
613
726
  }
614
- console.log(initMessage);
615
- leafs.forEach(({ input }) => {
616
- inputMaxLen = Math.max(inputMaxLen, input.length);
617
- });
618
- leafs.forEach(({ input, path: path2 }) => {
727
+ case "watchChange": {
728
+ const {
729
+ path: path2,
730
+ input
731
+ } = e.data;
619
732
  const key = `${input}:${path2}`;
620
- if (bars[key])
733
+ const bar = bars[key];
734
+ if (!bar)
621
735
  return;
622
- bars[key] = multiBars.create(50, 0, {
623
- pkgName: manifest.name,
624
- input: input.padEnd(inputMaxLen + 5),
625
- status: "waiting".padEnd(10)
626
- }, {
627
- barsize: 20,
628
- linewrap: true
629
- });
630
- });
631
- }
632
- if (e.type === "progress") {
633
- const {
634
- path: path2,
635
- tags,
636
- input,
637
- event,
638
- message
639
- } = e.data;
640
- const bar = bars[`${input}:${path2}`];
641
- if (!bar)
642
- return;
643
- const time = times[`${input}:${path2}`];
644
- bar.update(
645
- {
646
- start: 0,
647
- resolve: 20,
648
- end: 50
649
- }[event ?? "start"] ?? 0,
650
- {
651
- input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
652
- status: event?.padEnd(10),
653
- 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
+ });
654
748
  }
655
- );
656
- }
657
- if (e.type === "watchChange") {
658
- const {
659
- path: path2,
660
- input
661
- } = e.data;
662
- const key = `${input}:${path2}`;
663
- const bar = bars[key];
664
- if (!bar)
665
- return;
666
- let time = times[key] ?? 1;
667
- if (!locks[key]) {
668
- time += 1;
669
- times[key] = time;
670
- setTimeout(() => {
671
- locks[key] = false;
672
- }, 100);
673
- bar.update(0, {
674
- input: `${input}(x${time.toString().padStart(2, "0")})`.padEnd(inputMaxLen + 5),
675
- status: "watching".padEnd(10),
676
- 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
+ }
677
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;
678
796
  }
679
- locks[key] = true;
680
797
  }
681
798
  });
682
799
  await new Promise((resolve, reject) => {
@@ -707,6 +824,17 @@ ${errorStr}`)));
707
824
  }
708
825
  } finally {
709
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);
710
838
  }
711
839
  });
712
840
 
package/dist/cli.cjs CHANGED
@@ -3,6 +3,7 @@
3
3
  var childProcess = require('node:child_process');
4
4
  var fs = require('node:fs');
5
5
  var path = require('node:path');
6
+ var process$1 = require('node:process');
6
7
  var bumper = require('@jiek/utils/bumper');
7
8
  var commander = require('commander');
8
9
  var detectIndent = require('detect-indent');
@@ -14,7 +15,6 @@ var entrypoints = require('@jiek/pkger/entrypoints');
14
15
  var require$$0 = require('util');
15
16
  var require$$0$1 = require('path');
16
17
  require('jiek/cli-only-build');
17
- var process$1 = require('node:process');
18
18
 
19
19
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
20
20
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -40,10 +40,10 @@ function _interopNamespace(e) {
40
40
  var childProcess__namespace = /*#__PURE__*/_interopNamespace(childProcess);
41
41
  var fs__default = /*#__PURE__*/_interopDefault(fs);
42
42
  var path__default = /*#__PURE__*/_interopDefault(path);
43
+ var process__default = /*#__PURE__*/_interopDefault(process$1);
43
44
  var detectIndent__default = /*#__PURE__*/_interopDefault(detectIndent);
44
45
  var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
45
46
  var require$$0__default$1 = /*#__PURE__*/_interopDefault(require$$0$1);
46
- var process__default = /*#__PURE__*/_interopDefault(process$1);
47
47
 
48
48
  let root;
49
49
  function getRoot() {
@@ -4465,7 +4465,7 @@ async function forEachSelectedProjectsGraphEntries(callback) {
4465
4465
  }
4466
4466
  commander.program.command("publish").description(description).aliases(["pub", "p"]).option("-b, --bumper <bumper>", "bump version", "patch").option("-no-b, --no-bumper", "no bump version").option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").action(async ({ outdir, bumper: bumper$1 }) => {
4467
4467
  let shouldPassThrough = false;
4468
- const passThroughOptions = process.argv.reduce(
4468
+ const passThroughOptions = process__default.default.argv.reduce(
4469
4469
  (acc, value) => {
4470
4470
  if (shouldPassThrough) {
4471
4471
  acc.push(value);
@@ -4487,20 +4487,20 @@ commander.program.command("publish").description(description).aliases(["pub", "p
4487
4487
  cwd: dir,
4488
4488
  stdio: "inherit",
4489
4489
  env: {
4490
- ...process.env,
4490
+ ...process__default.default.env,
4491
4491
  JIEK_PUBLISH_OUTDIR: JSON.stringify(outdir),
4492
4492
  JIEK_PUBLISH_BUMPER: JSON.stringify(bumper$1)
4493
4493
  }
4494
4494
  });
4495
4495
  });
4496
4496
  });
4497
- async function prepublish() {
4497
+ async function prepublish({ bumper: bumper$1 } = {}) {
4498
4498
  const {
4499
4499
  JIEK_PUBLISH_OUTDIR: outdirEnv,
4500
4500
  JIEK_PUBLISH_BUMPER: bumperEnv
4501
- } = process.env;
4502
- const outdir = outdirEnv ? JSON.parse(outdirEnv) : "dist";
4503
- const bumper$1 = bumperEnv ? JSON.parse(bumperEnv) : false;
4501
+ } = process__default.default.env;
4502
+ const outdir = outdirEnv ?? "dist";
4503
+ bumper$1 = bumper$1 ?? (bumperEnv ? JSON.parse(bumperEnv) : false);
4504
4504
  const generateNewManifest = (dir, manifest) => {
4505
4505
  const { name, type, exports: entrypoints = {} } = manifest;
4506
4506
  if (!name) {
@@ -4587,8 +4587,8 @@ async function prepublish() {
4587
4587
  break;
4588
4588
  case "object": {
4589
4589
  const indexExports = index;
4590
- indexPublishConfig.main = indexExports["require"] ?? indexExports["default"];
4591
- indexPublishConfig.module = indexExports["import"] ?? indexExports["module"] ?? indexExports["default"];
4590
+ indexPublishConfig.main = indexExports.require ?? indexExports.default;
4591
+ indexPublishConfig.module = indexExports.import ?? indexExports.module ?? indexExports.default;
4592
4592
  break;
4593
4593
  }
4594
4594
  }
@@ -4608,7 +4608,7 @@ async function prepublish() {
4608
4608
  }
4609
4609
  }
4610
4610
  }
4611
- if (oldJSON["devDependencies"]) {
4611
+ if (oldJSON.devDependencies) {
4612
4612
  newJSONString = jsoncParser.applyEdits(
4613
4613
  newJSONString,
4614
4614
  jsoncParser.modify(
@@ -4619,8 +4619,8 @@ async function prepublish() {
4619
4619
  )
4620
4620
  );
4621
4621
  }
4622
- if (oldJSON["peerDependencies"]) {
4623
- const peerDependenciesMeta = Object.keys(oldJSON["peerDependencies"]).reduce(
4622
+ if (oldJSON.peerDependencies) {
4623
+ const peerDependenciesMeta = Object.keys(oldJSON.peerDependencies).reduce(
4624
4624
  (acc, key) => {
4625
4625
  acc[key] = { optional: true };
4626
4626
  return acc;
@@ -4637,7 +4637,7 @@ async function prepublish() {
4637
4637
  )
4638
4638
  );
4639
4639
  }
4640
- if (oldJSON["files"]) {
4640
+ if (oldJSON.files) {
4641
4641
  newJSONString = jsoncParser.applyEdits(
4642
4642
  newJSONString,
4643
4643
  jsoncParser.modify(
@@ -4654,16 +4654,16 @@ async function prepublish() {
4654
4654
  const [manifest, resolvedOutdir] = generateNewManifest(dir, originalManifest);
4655
4655
  const resolveByDir = (...paths) => path__default.default.resolve(dir, ...paths);
4656
4656
  const oldJSONString = fs__default.default.readFileSync(resolveByDir("package.json"), "utf-8");
4657
- const oldJSON = JSON.parse(oldJSONString) ?? "0.0.0";
4657
+ const oldJSON = JSON.parse(oldJSONString);
4658
4658
  if (typeof oldJSON.version !== "string") {
4659
- throw new Error(`${dir}/package.json must have a version field with a string value`);
4659
+ throw new TypeError(`${dir}/package.json must have a version field with a string value`);
4660
4660
  }
4661
4661
  const { indent = " " } = detectIndent__default.default(oldJSONString);
4662
4662
  const formattingOptions = {
4663
4663
  tabSize: indent.length,
4664
4664
  insertSpaces: true
4665
4665
  };
4666
- const newVersion = bumper$1 ? bumper.bump(oldJSON.version, bumper$1) : oldJSON.version;
4666
+ const newVersion = bumper$1 ? bumper.bump(oldJSON.version, bumper$1 === true ? "patch" : bumper$1) : oldJSON.version;
4667
4667
  const modifyVersionPackageJSON = jsoncParser.applyEdits(
4668
4668
  oldJSONString,
4669
4669
  jsoncParser.modify(oldJSONString, ["version"], newVersion, { formattingOptions })
@@ -4734,15 +4734,22 @@ async function prepublish() {
4734
4734
  }
4735
4735
  }
4736
4736
  if (oldJSON.files) {
4737
- if (!Array.isArray(oldJSON.files)) {
4738
- throw new Error(`${dir}/package.json files field must be an array`);
4739
- }
4740
- if (Array.isArray(oldJSON.files) && oldJSON.files.every((file) => typeof file !== "string")) {
4741
- throw new Error(`${dir}/package.json files field must be an array of string`);
4737
+ if (Array.isArray(oldJSON.files)) {
4738
+ if (oldJSON.files.every((file) => typeof file !== "string")) {
4739
+ throw new TypeError(`${dir}/package.json files field must be an array of string`);
4740
+ }
4741
+ } else {
4742
+ throw new TypeError(`${dir}/package.json files field must be an array`);
4742
4743
  }
4743
4744
  }
4744
4745
  const resolvedOutdirAbs = resolveByDir(resolvedOutdir);
4745
- const files = (oldJSON.files ?? fs__default.default.readdirSync(resolveByDir("."))).filter((file) => file === "node_modules" || resolveByDir(file) !== resolvedOutdirAbs);
4746
+ const files = (oldJSON.files ?? fs__default.default.readdirSync(resolveByDir("."))).filter(
4747
+ (file) => ![
4748
+ "node_modules",
4749
+ "package.json",
4750
+ "pnpm-lock.yaml"
4751
+ ].includes(file) && resolveByDir(file) !== resolvedOutdirAbs
4752
+ );
4746
4753
  for (const file of files) {
4747
4754
  const path2 = resolveByDir(file);
4748
4755
  try {
@@ -4779,10 +4786,11 @@ async function postpublish() {
4779
4786
  }
4780
4787
  });
4781
4788
  }
4789
+ console.log(process__default.default.env);
4782
4790
  commander.program.action(async () => {
4783
4791
  const {
4784
4792
  npm_lifecycle_event: NPM_LIFECYCLE_EVENT
4785
- } = process.env;
4793
+ } = process__default.default.env;
4786
4794
  switch (NPM_LIFECYCLE_EVENT) {
4787
4795
  case "prepublish":
4788
4796
  await prepublish();
@@ -4803,7 +4811,7 @@ Prepare package.json for publish, you can add \`jk\` to the \`prepublish\` scrip
4803
4811
  }
4804
4812
  }
4805
4813
  `.trim();
4806
- commander.program.command("prepublish").description(prepublishDescription).action(prepublish);
4814
+ commander.program.command("prepublish").description(prepublishDescription).option("-b, --bumper <bumper>", "bump version").option("-no-b, --no-bumper", "no bump version").action(prepublish);
4807
4815
  const postpublishDescription = `
4808
4816
  Restore package.json after publish, you can add \`jk\` to the \`postpublish\` script in package.json, the command will automatically run \`jk postpublish\`.
4809
4817
  .e.g