jiek 2.1.13 → 2.2.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.
package/bin-helper.cjs CHANGED
@@ -1,6 +1,31 @@
1
- const {
2
- JIEK_BIN__FILEPATH: binFilePath
3
- } = process.env
1
+ const process = require('node:process')
2
+
3
+ /**
4
+ * @type {string | undefined}
5
+ */
6
+ let binFilePath
7
+
8
+ try {
9
+ // eslint-disable-next-line unicorn/error-message
10
+ throw new Error()
11
+ } catch (e) {
12
+ const { stack } = e
13
+ const lines = stack.split('\n')
14
+ for (const line of lines) {
15
+ if (
16
+ line === 'Error' || line.includes(' (node:') || line.includes(` (${__filename}`)
17
+ ) {
18
+ continue
19
+ }
20
+ const match = line.match(/\(([^)]+)\)$/)
21
+ if (match) {
22
+ binFilePath = match[1].replace(/:\d+:\d+$/, '')
23
+ }
24
+ break
25
+ }
26
+ }
27
+
28
+ binFilePath = binFilePath ?? process.env.JIEK_BIN__FILEPATH
4
29
 
5
30
  const {
6
31
  basename,
@@ -120,7 +120,7 @@ async function getSelectedProjectsGraph(filter = commander.program.getOptionValu
120
120
 
121
121
  var name = "jiek";
122
122
  var type = "module";
123
- var version = "2.1.12";
123
+ var version = "2.2.0";
124
124
  var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
125
125
  var author = "YiJie <yijie4188@gmail.com>";
126
126
  var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
@@ -169,7 +169,7 @@ var files = [
169
169
  "src"
170
170
  ];
171
171
  var scripts = {
172
- prepublish: "jb -nm && jk",
172
+ prepublish: "pnpm test && jb -nm && jk",
173
173
  postpublish: "jk",
174
174
  test: "vitest run"
175
175
  };
@@ -610,9 +610,13 @@ command.action(async (commandFiltersOrEntries, options) => {
610
610
  if (!fs.existsSync(wdNodeModules)) {
611
611
  fs.mkdirSync(wdNodeModules);
612
612
  }
613
- const jiekTempDir = (...paths) => path__default.default.resolve(wdNodeModules, ".jiek", ...paths);
614
- if (!fs.existsSync(jiekTempDir())) {
615
- fs.mkdirSync(jiekTempDir());
613
+ const resolveByJiekTemp = (...paths) => path__default.default.resolve(wdNodeModules, ".jiek", ...paths);
614
+ const jiekTemp = resolveByJiekTemp();
615
+ if (!fs.existsSync(jiekTemp)) {
616
+ try {
617
+ fs.mkdirSync(jiekTemp);
618
+ } catch {
619
+ }
616
620
  }
617
621
  const rollupBinaryPath = require$1.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
618
622
  let i = 0;
@@ -639,7 +643,7 @@ command.action(async (commandFiltersOrEntries, options) => {
639
643
  }
640
644
  }
641
645
  const escapeManifestName = manifest.name.replace(/^@/g, "").replace(/\//g, "+");
642
- const configFile = jiekTempDir(
646
+ const configFile = resolveByJiekTemp(
643
647
  `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
644
648
  );
645
649
  fs.writeFileSync(configFile, FILE_TEMPLATE(manifest));
@@ -110,7 +110,7 @@ async function getSelectedProjectsGraph(filter = program.getOptionValue("filter"
110
110
 
111
111
  var name = "jiek";
112
112
  var type = "module";
113
- var version = "2.1.12";
113
+ var version = "2.2.0";
114
114
  var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
115
115
  var author = "YiJie <yijie4188@gmail.com>";
116
116
  var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
@@ -159,7 +159,7 @@ var files = [
159
159
  "src"
160
160
  ];
161
161
  var scripts = {
162
- prepublish: "jb -nm && jk",
162
+ prepublish: "pnpm test && jb -nm && jk",
163
163
  postpublish: "jk",
164
164
  test: "vitest run"
165
165
  };
@@ -600,9 +600,13 @@ command.action(async (commandFiltersOrEntries, options) => {
600
600
  if (!existsSync(wdNodeModules)) {
601
601
  mkdirSync(wdNodeModules);
602
602
  }
603
- const jiekTempDir = (...paths) => path.resolve(wdNodeModules, ".jiek", ...paths);
604
- if (!existsSync(jiekTempDir())) {
605
- 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
+ }
606
610
  }
607
611
  const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
608
612
  let i = 0;
@@ -629,7 +633,7 @@ command.action(async (commandFiltersOrEntries, options) => {
629
633
  }
630
634
  }
631
635
  const escapeManifestName = manifest.name.replace(/^@/g, "").replace(/\//g, "+");
632
- const configFile = jiekTempDir(
636
+ const configFile = resolveByJiekTemp(
633
637
  `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
634
638
  );
635
639
  writeFileSync(configFile, FILE_TEMPLATE(manifest));
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;
4501
+ } = process__default.default.env;
4502
4502
  const outdir = outdirEnv ? JSON.parse(outdirEnv) : "dist";
4503
- const bumper$1 = bumperEnv ? JSON.parse(bumperEnv) : false;
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 {
@@ -4782,7 +4789,7 @@ async function postpublish() {
4782
4789
  commander.program.action(async () => {
4783
4790
  const {
4784
4791
  npm_lifecycle_event: NPM_LIFECYCLE_EVENT
4785
- } = process.env;
4792
+ } = process__default.default.env;
4786
4793
  switch (NPM_LIFECYCLE_EVENT) {
4787
4794
  case "prepublish":
4788
4795
  await prepublish();
@@ -4803,7 +4810,7 @@ Prepare package.json for publish, you can add \`jk\` to the \`prepublish\` scrip
4803
4810
  }
4804
4811
  }
4805
4812
  `.trim();
4806
- commander.program.command("prepublish").description(prepublishDescription).action(prepublish);
4813
+ commander.program.command("prepublish").description(prepublishDescription).option("-b, --bumper <bumper>", "bump version").option("-no-b, --no-bumper", "no bump version").action(prepublish);
4807
4814
  const postpublishDescription = `
4808
4815
  Restore package.json after publish, you can add \`jk\` to the \`postpublish\` script in package.json, the command will automatically run \`jk postpublish\`.
4809
4816
  .e.g
package/dist/cli.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as childProcess from 'node:child_process';
2
2
  import fs from 'node:fs';
3
3
  import path, { isAbsolute, relative, resolve } from 'node:path';
4
+ import process$1 from 'node:process';
4
5
  import { TAGS, bump } from '@jiek/utils/bumper';
5
6
  import { program } from 'commander';
6
7
  import detectIndent from 'detect-indent';
@@ -12,7 +13,6 @@ import { resolveEntrypoints, filterLeafs, DEFAULT_SKIP_VALUES, entrypoints2Expor
12
13
  import require$$0 from 'util';
13
14
  import require$$0$1 from 'path';
14
15
  import 'jiek/cli-only-build';
15
- import process$1 from 'node:process';
16
16
 
17
17
  let root;
18
18
  function getRoot() {
@@ -4434,7 +4434,7 @@ async function forEachSelectedProjectsGraphEntries(callback) {
4434
4434
  }
4435
4435
  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 }) => {
4436
4436
  let shouldPassThrough = false;
4437
- const passThroughOptions = process.argv.reduce(
4437
+ const passThroughOptions = process$1.argv.reduce(
4438
4438
  (acc, value) => {
4439
4439
  if (shouldPassThrough) {
4440
4440
  acc.push(value);
@@ -4456,20 +4456,20 @@ program.command("publish").description(description).aliases(["pub", "p"]).option
4456
4456
  cwd: dir,
4457
4457
  stdio: "inherit",
4458
4458
  env: {
4459
- ...process.env,
4459
+ ...process$1.env,
4460
4460
  JIEK_PUBLISH_OUTDIR: JSON.stringify(outdir),
4461
4461
  JIEK_PUBLISH_BUMPER: JSON.stringify(bumper)
4462
4462
  }
4463
4463
  });
4464
4464
  });
4465
4465
  });
4466
- async function prepublish() {
4466
+ async function prepublish({ bumper } = {}) {
4467
4467
  const {
4468
4468
  JIEK_PUBLISH_OUTDIR: outdirEnv,
4469
4469
  JIEK_PUBLISH_BUMPER: bumperEnv
4470
- } = process.env;
4470
+ } = process$1.env;
4471
4471
  const outdir = outdirEnv ? JSON.parse(outdirEnv) : "dist";
4472
- const bumper = bumperEnv ? JSON.parse(bumperEnv) : false;
4472
+ bumper = bumper ?? (bumperEnv ? JSON.parse(bumperEnv) : false);
4473
4473
  const generateNewManifest = (dir, manifest) => {
4474
4474
  const { name, type, exports: entrypoints = {} } = manifest;
4475
4475
  if (!name) {
@@ -4556,8 +4556,8 @@ async function prepublish() {
4556
4556
  break;
4557
4557
  case "object": {
4558
4558
  const indexExports = index;
4559
- indexPublishConfig.main = indexExports["require"] ?? indexExports["default"];
4560
- indexPublishConfig.module = indexExports["import"] ?? indexExports["module"] ?? indexExports["default"];
4559
+ indexPublishConfig.main = indexExports.require ?? indexExports.default;
4560
+ indexPublishConfig.module = indexExports.import ?? indexExports.module ?? indexExports.default;
4561
4561
  break;
4562
4562
  }
4563
4563
  }
@@ -4577,7 +4577,7 @@ async function prepublish() {
4577
4577
  }
4578
4578
  }
4579
4579
  }
4580
- if (oldJSON["devDependencies"]) {
4580
+ if (oldJSON.devDependencies) {
4581
4581
  newJSONString = applyEdits(
4582
4582
  newJSONString,
4583
4583
  modify(
@@ -4588,8 +4588,8 @@ async function prepublish() {
4588
4588
  )
4589
4589
  );
4590
4590
  }
4591
- if (oldJSON["peerDependencies"]) {
4592
- const peerDependenciesMeta = Object.keys(oldJSON["peerDependencies"]).reduce(
4591
+ if (oldJSON.peerDependencies) {
4592
+ const peerDependenciesMeta = Object.keys(oldJSON.peerDependencies).reduce(
4593
4593
  (acc, key) => {
4594
4594
  acc[key] = { optional: true };
4595
4595
  return acc;
@@ -4606,7 +4606,7 @@ async function prepublish() {
4606
4606
  )
4607
4607
  );
4608
4608
  }
4609
- if (oldJSON["files"]) {
4609
+ if (oldJSON.files) {
4610
4610
  newJSONString = applyEdits(
4611
4611
  newJSONString,
4612
4612
  modify(
@@ -4623,16 +4623,16 @@ async function prepublish() {
4623
4623
  const [manifest, resolvedOutdir] = generateNewManifest(dir, originalManifest);
4624
4624
  const resolveByDir = (...paths) => path.resolve(dir, ...paths);
4625
4625
  const oldJSONString = fs.readFileSync(resolveByDir("package.json"), "utf-8");
4626
- const oldJSON = JSON.parse(oldJSONString) ?? "0.0.0";
4626
+ const oldJSON = JSON.parse(oldJSONString);
4627
4627
  if (typeof oldJSON.version !== "string") {
4628
- throw new Error(`${dir}/package.json must have a version field with a string value`);
4628
+ throw new TypeError(`${dir}/package.json must have a version field with a string value`);
4629
4629
  }
4630
4630
  const { indent = " " } = detectIndent(oldJSONString);
4631
4631
  const formattingOptions = {
4632
4632
  tabSize: indent.length,
4633
4633
  insertSpaces: true
4634
4634
  };
4635
- const newVersion = bumper ? bump(oldJSON.version, bumper) : oldJSON.version;
4635
+ const newVersion = bumper ? bump(oldJSON.version, bumper === true ? "patch" : bumper) : oldJSON.version;
4636
4636
  const modifyVersionPackageJSON = applyEdits(
4637
4637
  oldJSONString,
4638
4638
  modify(oldJSONString, ["version"], newVersion, { formattingOptions })
@@ -4703,15 +4703,22 @@ async function prepublish() {
4703
4703
  }
4704
4704
  }
4705
4705
  if (oldJSON.files) {
4706
- if (!Array.isArray(oldJSON.files)) {
4707
- throw new Error(`${dir}/package.json files field must be an array`);
4708
- }
4709
- if (Array.isArray(oldJSON.files) && oldJSON.files.every((file) => typeof file !== "string")) {
4710
- throw new Error(`${dir}/package.json files field must be an array of string`);
4706
+ if (Array.isArray(oldJSON.files)) {
4707
+ if (oldJSON.files.every((file) => typeof file !== "string")) {
4708
+ throw new TypeError(`${dir}/package.json files field must be an array of string`);
4709
+ }
4710
+ } else {
4711
+ throw new TypeError(`${dir}/package.json files field must be an array`);
4711
4712
  }
4712
4713
  }
4713
4714
  const resolvedOutdirAbs = resolveByDir(resolvedOutdir);
4714
- const files = (oldJSON.files ?? fs.readdirSync(resolveByDir("."))).filter((file) => file === "node_modules" || resolveByDir(file) !== resolvedOutdirAbs);
4715
+ const files = (oldJSON.files ?? fs.readdirSync(resolveByDir("."))).filter(
4716
+ (file) => ![
4717
+ "node_modules",
4718
+ "package.json",
4719
+ "pnpm-lock.yaml"
4720
+ ].includes(file) && resolveByDir(file) !== resolvedOutdirAbs
4721
+ );
4715
4722
  for (const file of files) {
4716
4723
  const path2 = resolveByDir(file);
4717
4724
  try {
@@ -4751,7 +4758,7 @@ async function postpublish() {
4751
4758
  program.action(async () => {
4752
4759
  const {
4753
4760
  npm_lifecycle_event: NPM_LIFECYCLE_EVENT
4754
- } = process.env;
4761
+ } = process$1.env;
4755
4762
  switch (NPM_LIFECYCLE_EVENT) {
4756
4763
  case "prepublish":
4757
4764
  await prepublish();
@@ -4772,7 +4779,7 @@ Prepare package.json for publish, you can add \`jk\` to the \`prepublish\` scrip
4772
4779
  }
4773
4780
  }
4774
4781
  `.trim();
4775
- program.command("prepublish").description(prepublishDescription).action(prepublish);
4782
+ program.command("prepublish").description(prepublishDescription).option("-b, --bumper <bumper>", "bump version").option("-no-b, --no-bumper", "no bump version").action(prepublish);
4776
4783
  const postpublishDescription = `
4777
4784
  Restore package.json after publish, you can add \`jk\` to the \`postpublish\` script in package.json, the command will automatically run \`jk postpublish\`.
4778
4785
  .e.g
@@ -4684,12 +4684,12 @@ const { type: _resolvedBuilderOptionsType, ...noTypeResolvedBuilderOptions } = r
4684
4684
  const withMinify = (output, onlyOncePlugins = []) => {
4685
4685
  const minify = build?.output?.minify ?? MINIFY_DEFAULT_VALUE;
4686
4686
  output.plugins = output.plugins ?? [];
4687
+ const notOnlyOncePlugins = [...output.plugins];
4688
+ output.plugins.push(...onlyOncePlugins);
4687
4689
  if (minify === false) {
4688
- output.plugins.push(...onlyOncePlugins);
4689
4690
  return [output];
4690
4691
  }
4691
4692
  const minifyPlugin = resolvedMinifyOptions.type === "esbuild" ? import('rollup-plugin-esbuild').then(({ minify: minify2 }) => minify2(noTypeResolvedMinifyOptions)) : resolvedMinifyOptions.type === "swc" ? import('rollup-plugin-swc3').then(({ minify: minify2 }) => minify2(noTypeResolvedMinifyOptions)) : import('@rollup/plugin-terser').then(({ default: minify2 }) => minify2(noTypeResolvedMinifyOptions));
4692
- const notOnlyOncePlugins = output.plugins;
4693
4693
  return minify === "only-minify" ? [{
4694
4694
  ...output,
4695
4695
  // TODO replace suffix when pubish to npm and the `build.output.minify` is 'only-minify'
@@ -4698,6 +4698,7 @@ const withMinify = (output, onlyOncePlugins = []) => {
4698
4698
  throw new Error("entryFileNames must be a function");
4699
4699
  })(),
4700
4700
  plugins: [
4701
+ ...output.plugins,
4701
4702
  ...notOnlyOncePlugins,
4702
4703
  minifyPlugin
4703
4704
  ]
@@ -4668,12 +4668,12 @@ const { type: _resolvedBuilderOptionsType, ...noTypeResolvedBuilderOptions } = r
4668
4668
  const withMinify = (output, onlyOncePlugins = []) => {
4669
4669
  const minify = build?.output?.minify ?? MINIFY_DEFAULT_VALUE;
4670
4670
  output.plugins = output.plugins ?? [];
4671
+ const notOnlyOncePlugins = [...output.plugins];
4672
+ output.plugins.push(...onlyOncePlugins);
4671
4673
  if (minify === false) {
4672
- output.plugins.push(...onlyOncePlugins);
4673
4674
  return [output];
4674
4675
  }
4675
4676
  const minifyPlugin = resolvedMinifyOptions.type === "esbuild" ? import('rollup-plugin-esbuild').then(({ minify: minify2 }) => minify2(noTypeResolvedMinifyOptions)) : resolvedMinifyOptions.type === "swc" ? import('rollup-plugin-swc3').then(({ minify: minify2 }) => minify2(noTypeResolvedMinifyOptions)) : import('@rollup/plugin-terser').then(({ default: minify2 }) => minify2(noTypeResolvedMinifyOptions));
4676
- const notOnlyOncePlugins = output.plugins;
4677
4677
  return minify === "only-minify" ? [{
4678
4678
  ...output,
4679
4679
  // TODO replace suffix when pubish to npm and the `build.output.minify` is 'only-minify'
@@ -4682,6 +4682,7 @@ const withMinify = (output, onlyOncePlugins = []) => {
4682
4682
  throw new Error("entryFileNames must be a function");
4683
4683
  })(),
4684
4684
  plugins: [
4685
+ ...output.plugins,
4685
4686
  ...notOnlyOncePlugins,
4686
4687
  minifyPlugin
4687
4688
  ]
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jiek",
3
3
  "type": "module",
4
- "version": "2.1.13",
4
+ "version": "2.2.1",
5
5
  "description": "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.",
6
6
  "author": "YiJie <yijie4188@gmail.com>",
7
7
  "homepage": "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme",
@@ -83,8 +83,8 @@
83
83
  "jsonc-parser": "^3.2.1",
84
84
  "koa": "^2.15.3",
85
85
  "rollup": "^4.0.0",
86
- "@jiek/pkger": "^0.2.1",
87
- "@jiek/utils": "^0.2.3"
86
+ "@jiek/utils": "^0.2.3",
87
+ "@jiek/pkger": "^0.2.1"
88
88
  },
89
89
  "peerDependenciesMeta": {
90
90
  "@pnpm/filter-workspace-packages": {
@@ -116,7 +116,7 @@
116
116
  }
117
117
  },
118
118
  "scripts": {
119
- "prepublish": "jb -nm && jk",
119
+ "prepublish": "pnpm test && jb -nm && jk",
120
120
  "test": "vitest run"
121
121
  },
122
122
  "typesVersions": {
package/src/bridge.ts CHANGED
@@ -2,6 +2,8 @@ import type { Module } from '#~/rollup/bundle-analyzer.ts'
2
2
 
3
3
  import { sendMessage } from 'execa'
4
4
 
5
+ export const bridgeDisabledRef = { value: false }
6
+
5
7
  export interface RollupBuildEntryCtx {
6
8
  type: 'esm' | 'cjs'
7
9
  name: string
@@ -38,5 +40,7 @@ export type RollupBuildEvent = keyof RollupBuildEventMap extends infer K
38
40
  : never
39
41
 
40
42
  export const publish = async <K extends keyof RollupBuildEventMap>(type: K, data: RollupBuildEventMap[K]) => {
43
+ if (bridgeDisabledRef.value) return Promise.resolve()
44
+
41
45
  return sendMessage({ type, data })
42
46
  }
@@ -376,9 +376,12 @@ command
376
376
  if (!existsSync(wdNodeModules)) {
377
377
  mkdirSync(wdNodeModules)
378
378
  }
379
- const jiekTempDir = (...paths: string[]) => path.resolve(wdNodeModules, '.jiek', ...paths)
380
- if (!existsSync(jiekTempDir())) {
381
- mkdirSync(jiekTempDir())
379
+ const resolveByJiekTemp = (...paths: string[]) => path.resolve(wdNodeModules, '.jiek', ...paths)
380
+ const jiekTemp = resolveByJiekTemp()
381
+ if (!existsSync(jiekTemp)) {
382
+ try {
383
+ mkdirSync(jiekTemp)
384
+ } catch {}
382
385
  }
383
386
 
384
387
  const rollupBinaryPath = require.resolve('rollup')
@@ -409,7 +412,7 @@ command
409
412
 
410
413
  // TODO support auto build child packages in workspaces
411
414
  const escapeManifestName = manifest.name.replace(/^@/g, '').replace(/\//g, '+')
412
- const configFile = jiekTempDir(
415
+ const configFile = resolveByJiekTemp(
413
416
  `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
414
417
  )
415
418
  writeFileSync(configFile, FILE_TEMPLATE(manifest))
@@ -1,8 +1,10 @@
1
+ /* eslint-disable ts/strict-boolean-expressions */
1
2
  import * as childProcess from 'node:child_process'
2
3
  import fs from 'node:fs'
3
4
  import path from 'node:path'
5
+ import process from 'node:process'
4
6
 
5
- import { bump, type BumperType, TAGS } from '@jiek/utils/bumper'
7
+ import { type BumperType, TAGS, bump } from '@jiek/utils/bumper'
6
8
  import { program } from 'commander'
7
9
  import detectIndent from 'detect-indent'
8
10
  import { applyEdits, modify } from 'jsonc-parser'
@@ -91,13 +93,19 @@ program
91
93
  })
92
94
  })
93
95
 
94
- async function prepublish() {
96
+ async function prepublish({ bumper }: {
97
+ bumper?: boolean | BumperType
98
+ } = {}) {
95
99
  const {
96
100
  JIEK_PUBLISH_OUTDIR: outdirEnv,
97
101
  JIEK_PUBLISH_BUMPER: bumperEnv
98
102
  } = process.env
99
- const outdir = outdirEnv ? JSON.parse(outdirEnv) : 'dist'
100
- const bumper = bumperEnv ? JSON.parse(bumperEnv) : false
103
+ const outdir = outdirEnv
104
+ ? JSON.parse(outdirEnv) as string
105
+ : 'dist'
106
+ bumper = bumper ?? (
107
+ bumperEnv ? JSON.parse(bumperEnv) as string | boolean : false
108
+ )
101
109
 
102
110
  const generateNewManifest = (dir: string, manifest: NonNullable<ProjectsGraph['value']>[string]) => {
103
111
  const { name, type, exports: entrypoints = {} } = manifest
@@ -188,6 +196,7 @@ async function prepublish() {
188
196
  const index = exports?.['.']
189
197
  const indexPublishConfig: Record<string, string> = {}
190
198
  if (index) {
199
+ // eslint-disable-next-line ts/switch-exhaustiveness-check
191
200
  switch (typeof index) {
192
201
  case 'string':
193
202
  indexPublishConfig[
@@ -196,8 +205,8 @@ async function prepublish() {
196
205
  break
197
206
  case 'object': {
198
207
  const indexExports = index as Record<string, string>
199
- indexPublishConfig.main = indexExports['require'] ?? indexExports['default']
200
- indexPublishConfig.module = indexExports['import'] ?? indexExports['module'] ?? indexExports['default']
208
+ indexPublishConfig.main = indexExports.require ?? indexExports.default
209
+ indexPublishConfig.module = indexExports.import ?? indexExports.module ?? indexExports.default
201
210
  break
202
211
  }
203
212
  }
@@ -216,7 +225,7 @@ async function prepublish() {
216
225
  }
217
226
  }
218
227
  }
219
- if (oldJSON['devDependencies']) {
228
+ if (oldJSON.devDependencies) {
220
229
  newJSONString = applyEdits(
221
230
  newJSONString,
222
231
  modify(
@@ -227,8 +236,8 @@ async function prepublish() {
227
236
  )
228
237
  )
229
238
  }
230
- if (oldJSON['peerDependencies']) {
231
- const peerDependenciesMeta = Object.keys(oldJSON['peerDependencies']).reduce(
239
+ if (oldJSON.peerDependencies) {
240
+ const peerDependenciesMeta = Object.keys(oldJSON.peerDependencies).reduce(
232
241
  (acc, key) => {
233
242
  acc[key] = { optional: true }
234
243
  return acc
@@ -245,7 +254,7 @@ async function prepublish() {
245
254
  )
246
255
  )
247
256
  }
248
- if (oldJSON['files']) {
257
+ if (oldJSON.files) {
249
258
  newJSONString = applyEdits(
250
259
  newJSONString,
251
260
  modify(
@@ -264,9 +273,9 @@ async function prepublish() {
264
273
  const resolveByDir = (...paths: string[]) => path.resolve(dir, ...paths)
265
274
 
266
275
  const oldJSONString = fs.readFileSync(resolveByDir('package.json'), 'utf-8')
267
- const oldJSON = JSON.parse(oldJSONString) ?? '0.0.0'
276
+ const oldJSON = JSON.parse(oldJSONString) as Record<string, unknown>
268
277
  if (typeof oldJSON.version !== 'string') {
269
- throw new Error(`${dir}/package.json must have a version field with a string value`)
278
+ throw new TypeError(`${dir}/package.json must have a version field with a string value`)
270
279
  }
271
280
 
272
281
  // TODO detectIndent by editorconfig
@@ -276,7 +285,9 @@ async function prepublish() {
276
285
  insertSpaces: true
277
286
  }
278
287
 
279
- const newVersion = bumper ? bump(oldJSON.version, bumper) : oldJSON.version
288
+ const newVersion = bumper
289
+ ? bump(oldJSON.version, bumper === true ? 'patch' : bumper)
290
+ : oldJSON.version
280
291
  const modifyVersionPackageJSON = applyEdits(
281
292
  oldJSONString,
282
293
  modify(oldJSONString, ['version'], newVersion, { formattingOptions })
@@ -357,17 +368,24 @@ async function prepublish() {
357
368
  }
358
369
 
359
370
  if (oldJSON.files) {
360
- if (!Array.isArray(oldJSON.files)) {
361
- throw new Error(`${dir}/package.json files field must be an array`)
362
- }
363
- if (Array.isArray(oldJSON.files) && oldJSON.files.every((file: unknown) => typeof file !== 'string')) {
364
- throw new Error(`${dir}/package.json files field must be an array of string`)
371
+ if (Array.isArray(oldJSON.files)) {
372
+ if (oldJSON.files.every((file: unknown) => typeof file !== 'string')) {
373
+ throw new TypeError(`${dir}/package.json files field must be an array of string`)
374
+ }
375
+ } else {
376
+ throw new TypeError(`${dir}/package.json files field must be an array`)
365
377
  }
366
378
  }
367
379
  const resolvedOutdirAbs = resolveByDir(resolvedOutdir)
368
380
  const files = (
369
381
  (oldJSON.files as undefined | string[]) ?? fs.readdirSync(resolveByDir('.'))
370
- ).filter(file => file === 'node_modules' || resolveByDir(file) !== resolvedOutdirAbs)
382
+ ).filter(file =>
383
+ ![
384
+ 'node_modules',
385
+ 'package.json',
386
+ 'pnpm-lock.yaml'
387
+ ].includes(file) && resolveByDir(file) !== resolvedOutdirAbs
388
+ )
371
389
 
372
390
  for (const file of files) {
373
391
  const path = resolveByDir(file)
@@ -398,6 +416,7 @@ async function postpublish() {
398
416
  if (fs.existsSync(jiekTempPackageJSON)) {
399
417
  fs.copyFileSync(jiekTempPackageJSON, packageJSON)
400
418
  fs.rmSync(jiekTempPackageJSON)
419
+ // eslint-disable-next-line no-console
401
420
  console.log(`${dir}/package.json has been restored`)
402
421
  } else {
403
422
  throw new Error(
@@ -412,6 +431,7 @@ program
412
431
  const {
413
432
  npm_lifecycle_event: NPM_LIFECYCLE_EVENT
414
433
  } = process.env
434
+ // eslint-disable-next-line ts/switch-exhaustiveness-check
415
435
  switch (NPM_LIFECYCLE_EVENT) {
416
436
  case 'prepublish':
417
437
  await prepublish()
@@ -436,6 +456,8 @@ Prepare package.json for publish, you can add \`jk\` to the \`prepublish\` scrip
436
456
  program
437
457
  .command('prepublish')
438
458
  .description(prepublishDescription)
459
+ .option('-b, --bumper <bumper>', 'bump version')
460
+ .option('-no-b, --no-bumper', 'no bump version')
439
461
  .action(prepublish)
440
462
 
441
463
  const postpublishDescription = `
@@ -199,9 +199,12 @@ const withMinify = (
199
199
  onlyOncePlugins: OutputPluginOption[] = []
200
200
  ): OutputOptions[] => {
201
201
  const minify = build?.output?.minify ?? MINIFY_DEFAULT_VALUE
202
+
202
203
  output.plugins = output.plugins ?? []
204
+ const notOnlyOncePlugins = [...output.plugins]
205
+ output.plugins.push(...onlyOncePlugins)
206
+
203
207
  if (minify === false) {
204
- output.plugins.push(...onlyOncePlugins)
205
208
  return [output]
206
209
  }
207
210
 
@@ -213,7 +216,6 @@ const withMinify = (
213
216
  ? import('rollup-plugin-swc3').then(({ minify }) => minify(noTypeResolvedMinifyOptions as any))
214
217
  // eslint-disable-next-line ts/no-unsafe-argument
215
218
  : import('@rollup/plugin-terser').then(({ default: minify }) => minify(noTypeResolvedMinifyOptions as any))
216
- const notOnlyOncePlugins = output.plugins
217
219
  return minify === 'only-minify'
218
220
  ? [{
219
221
  ...output,
@@ -226,6 +228,7 @@ const withMinify = (
226
228
  throw new Error('entryFileNames must be a function')
227
229
  })(),
228
230
  plugins: [
231
+ ...output.plugins,
229
232
  ...notOnlyOncePlugins,
230
233
  minifyPlugin
231
234
  ]