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.
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');
@@ -39,6 +40,7 @@ function _interopNamespace(e) {
39
40
  var childProcess__namespace = /*#__PURE__*/_interopNamespace(childProcess);
40
41
  var fs__default = /*#__PURE__*/_interopDefault(fs);
41
42
  var path__default = /*#__PURE__*/_interopDefault(path);
43
+ var process__default = /*#__PURE__*/_interopDefault(process$1);
42
44
  var detectIndent__default = /*#__PURE__*/_interopDefault(detectIndent);
43
45
  var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
44
46
  var require$$0__default$1 = /*#__PURE__*/_interopDefault(require$$0$1);
@@ -79,7 +81,7 @@ function getWD() {
79
81
 
80
82
  let type = "";
81
83
  try {
82
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
84
+ const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
83
85
  require$1.resolve("@pnpm/filter-workspace-packages");
84
86
  type = "pnpm";
85
87
  } catch {
@@ -4335,7 +4337,7 @@ function getExports({
4335
4337
  ];
4336
4338
  }
4337
4339
 
4338
- const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
4340
+ const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
4339
4341
  function packageIsExist(name) {
4340
4342
  try {
4341
4343
  require$2.resolve(name);
@@ -4358,7 +4360,7 @@ for (const register of registers) {
4358
4360
  }
4359
4361
  }
4360
4362
 
4361
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
4363
+ const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
4362
4364
  let configName = "jiek.config";
4363
4365
  function getConfigPath(root, dir) {
4364
4366
  const isSupportTsLoader = !!tsRegisterName;
@@ -4463,7 +4465,7 @@ async function forEachSelectedProjectsGraphEntries(callback) {
4463
4465
  }
4464
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 }) => {
4465
4467
  let shouldPassThrough = false;
4466
- const passThroughOptions = process.argv.reduce(
4468
+ const passThroughOptions = process__default.default.argv.reduce(
4467
4469
  (acc, value) => {
4468
4470
  if (shouldPassThrough) {
4469
4471
  acc.push(value);
@@ -4485,20 +4487,20 @@ commander.program.command("publish").description(description).aliases(["pub", "p
4485
4487
  cwd: dir,
4486
4488
  stdio: "inherit",
4487
4489
  env: {
4488
- ...process.env,
4490
+ ...process__default.default.env,
4489
4491
  JIEK_PUBLISH_OUTDIR: JSON.stringify(outdir),
4490
4492
  JIEK_PUBLISH_BUMPER: JSON.stringify(bumper$1)
4491
4493
  }
4492
4494
  });
4493
4495
  });
4494
4496
  });
4495
- async function prepublish() {
4497
+ async function prepublish({ bumper: bumper$1 } = {}) {
4496
4498
  const {
4497
4499
  JIEK_PUBLISH_OUTDIR: outdirEnv,
4498
4500
  JIEK_PUBLISH_BUMPER: bumperEnv
4499
- } = process.env;
4500
- const outdir = outdirEnv ? JSON.parse(outdirEnv) : "dist";
4501
- 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);
4502
4504
  const generateNewManifest = (dir, manifest) => {
4503
4505
  const { name, type, exports: entrypoints = {} } = manifest;
4504
4506
  if (!name) {
@@ -4585,8 +4587,8 @@ async function prepublish() {
4585
4587
  break;
4586
4588
  case "object": {
4587
4589
  const indexExports = index;
4588
- indexPublishConfig.main = indexExports["require"] ?? indexExports["default"];
4589
- indexPublishConfig.module = indexExports["import"] ?? indexExports["module"] ?? indexExports["default"];
4590
+ indexPublishConfig.main = indexExports.require ?? indexExports.default;
4591
+ indexPublishConfig.module = indexExports.import ?? indexExports.module ?? indexExports.default;
4590
4592
  break;
4591
4593
  }
4592
4594
  }
@@ -4606,8 +4608,19 @@ async function prepublish() {
4606
4608
  }
4607
4609
  }
4608
4610
  }
4609
- if (oldJSON["peerDependencies"]) {
4610
- const peerDependenciesMeta = Object.keys(oldJSON["peerDependencies"]).reduce(
4611
+ if (oldJSON.devDependencies) {
4612
+ newJSONString = jsoncParser.applyEdits(
4613
+ newJSONString,
4614
+ jsoncParser.modify(
4615
+ newJSONString,
4616
+ ["devDependencies"],
4617
+ void 0,
4618
+ { formattingOptions }
4619
+ )
4620
+ );
4621
+ }
4622
+ if (oldJSON.peerDependencies) {
4623
+ const peerDependenciesMeta = Object.keys(oldJSON.peerDependencies).reduce(
4611
4624
  (acc, key) => {
4612
4625
  acc[key] = { optional: true };
4613
4626
  return acc;
@@ -4624,7 +4637,7 @@ async function prepublish() {
4624
4637
  )
4625
4638
  );
4626
4639
  }
4627
- if (oldJSON["files"]) {
4640
+ if (oldJSON.files) {
4628
4641
  newJSONString = jsoncParser.applyEdits(
4629
4642
  newJSONString,
4630
4643
  jsoncParser.modify(
@@ -4641,16 +4654,16 @@ async function prepublish() {
4641
4654
  const [manifest, resolvedOutdir] = generateNewManifest(dir, originalManifest);
4642
4655
  const resolveByDir = (...paths) => path__default.default.resolve(dir, ...paths);
4643
4656
  const oldJSONString = fs__default.default.readFileSync(resolveByDir("package.json"), "utf-8");
4644
- const oldJSON = JSON.parse(oldJSONString) ?? "0.0.0";
4657
+ const oldJSON = JSON.parse(oldJSONString);
4645
4658
  if (typeof oldJSON.version !== "string") {
4646
- 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`);
4647
4660
  }
4648
4661
  const { indent = " " } = detectIndent__default.default(oldJSONString);
4649
4662
  const formattingOptions = {
4650
4663
  tabSize: indent.length,
4651
4664
  insertSpaces: true
4652
4665
  };
4653
- 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;
4654
4667
  const modifyVersionPackageJSON = jsoncParser.applyEdits(
4655
4668
  oldJSONString,
4656
4669
  jsoncParser.modify(oldJSONString, ["version"], newVersion, { formattingOptions })
@@ -4721,15 +4734,22 @@ async function prepublish() {
4721
4734
  }
4722
4735
  }
4723
4736
  if (oldJSON.files) {
4724
- if (!Array.isArray(oldJSON.files)) {
4725
- throw new Error(`${dir}/package.json files field must be an array`);
4726
- }
4727
- if (Array.isArray(oldJSON.files) && oldJSON.files.every((file) => typeof file !== "string")) {
4728
- 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`);
4729
4743
  }
4730
4744
  }
4731
4745
  const resolvedOutdirAbs = resolveByDir(resolvedOutdir);
4732
- 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
+ );
4733
4753
  for (const file of files) {
4734
4754
  const path2 = resolveByDir(file);
4735
4755
  try {
@@ -4766,10 +4786,11 @@ async function postpublish() {
4766
4786
  }
4767
4787
  });
4768
4788
  }
4789
+ console.log(process__default.default.env);
4769
4790
  commander.program.action(async () => {
4770
4791
  const {
4771
4792
  npm_lifecycle_event: NPM_LIFECYCLE_EVENT
4772
- } = process.env;
4793
+ } = process__default.default.env;
4773
4794
  switch (NPM_LIFECYCLE_EVENT) {
4774
4795
  case "prepublish":
4775
4796
  await prepublish();
@@ -4790,7 +4811,7 @@ Prepare package.json for publish, you can add \`jk\` to the \`prepublish\` scrip
4790
4811
  }
4791
4812
  }
4792
4813
  `.trim();
4793
- 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);
4794
4815
  const postpublishDescription = `
4795
4816
  Restore package.json after publish, you can add \`jk\` to the \`postpublish\` script in package.json, the command will automatically run \`jk postpublish\`.
4796
4817
  .e.g
@@ -4802,4 +4823,27 @@ Restore package.json after publish, you can add \`jk\` to the \`postpublish\` sc
4802
4823
  `.trim();
4803
4824
  commander.program.command("postpublish").description(postpublishDescription).action(postpublish);
4804
4825
 
4805
- commander.program.parse(process.argv);
4826
+ const { argv } = process__default.default;
4827
+ const env = {};
4828
+ let isPassThrough = false;
4829
+ const newArgv = argv.filter((arg) => {
4830
+ if (isPassThrough) {
4831
+ return true;
4832
+ }
4833
+ if (arg === "--") {
4834
+ isPassThrough = true;
4835
+ return false;
4836
+ }
4837
+ const m = /^--env\.(\w+)=(.*)$/.exec(arg);
4838
+ if (m) {
4839
+ env[m[1]] = m[2];
4840
+ return false;
4841
+ }
4842
+ return true;
4843
+ });
4844
+ for (const [key, value] of Object.entries(env)) {
4845
+ process__default.default.env[key] = value;
4846
+ }
4847
+ var parseArgv = () => commander.program.parse(newArgv);
4848
+
4849
+ parseArgv();
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';
@@ -4433,7 +4434,7 @@ async function forEachSelectedProjectsGraphEntries(callback) {
4433
4434
  }
4434
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 }) => {
4435
4436
  let shouldPassThrough = false;
4436
- const passThroughOptions = process.argv.reduce(
4437
+ const passThroughOptions = process$1.argv.reduce(
4437
4438
  (acc, value) => {
4438
4439
  if (shouldPassThrough) {
4439
4440
  acc.push(value);
@@ -4455,20 +4456,20 @@ program.command("publish").description(description).aliases(["pub", "p"]).option
4455
4456
  cwd: dir,
4456
4457
  stdio: "inherit",
4457
4458
  env: {
4458
- ...process.env,
4459
+ ...process$1.env,
4459
4460
  JIEK_PUBLISH_OUTDIR: JSON.stringify(outdir),
4460
4461
  JIEK_PUBLISH_BUMPER: JSON.stringify(bumper)
4461
4462
  }
4462
4463
  });
4463
4464
  });
4464
4465
  });
4465
- async function prepublish() {
4466
+ async function prepublish({ bumper } = {}) {
4466
4467
  const {
4467
4468
  JIEK_PUBLISH_OUTDIR: outdirEnv,
4468
4469
  JIEK_PUBLISH_BUMPER: bumperEnv
4469
- } = process.env;
4470
- const outdir = outdirEnv ? JSON.parse(outdirEnv) : "dist";
4471
- const bumper = bumperEnv ? JSON.parse(bumperEnv) : false;
4470
+ } = process$1.env;
4471
+ const outdir = outdirEnv ?? "dist";
4472
+ bumper = bumper ?? (bumperEnv ? JSON.parse(bumperEnv) : false);
4472
4473
  const generateNewManifest = (dir, manifest) => {
4473
4474
  const { name, type, exports: entrypoints = {} } = manifest;
4474
4475
  if (!name) {
@@ -4555,8 +4556,8 @@ async function prepublish() {
4555
4556
  break;
4556
4557
  case "object": {
4557
4558
  const indexExports = index;
4558
- indexPublishConfig.main = indexExports["require"] ?? indexExports["default"];
4559
- indexPublishConfig.module = indexExports["import"] ?? indexExports["module"] ?? indexExports["default"];
4559
+ indexPublishConfig.main = indexExports.require ?? indexExports.default;
4560
+ indexPublishConfig.module = indexExports.import ?? indexExports.module ?? indexExports.default;
4560
4561
  break;
4561
4562
  }
4562
4563
  }
@@ -4576,8 +4577,19 @@ async function prepublish() {
4576
4577
  }
4577
4578
  }
4578
4579
  }
4579
- if (oldJSON["peerDependencies"]) {
4580
- const peerDependenciesMeta = Object.keys(oldJSON["peerDependencies"]).reduce(
4580
+ if (oldJSON.devDependencies) {
4581
+ newJSONString = applyEdits(
4582
+ newJSONString,
4583
+ modify(
4584
+ newJSONString,
4585
+ ["devDependencies"],
4586
+ void 0,
4587
+ { formattingOptions }
4588
+ )
4589
+ );
4590
+ }
4591
+ if (oldJSON.peerDependencies) {
4592
+ const peerDependenciesMeta = Object.keys(oldJSON.peerDependencies).reduce(
4581
4593
  (acc, key) => {
4582
4594
  acc[key] = { optional: true };
4583
4595
  return acc;
@@ -4594,7 +4606,7 @@ async function prepublish() {
4594
4606
  )
4595
4607
  );
4596
4608
  }
4597
- if (oldJSON["files"]) {
4609
+ if (oldJSON.files) {
4598
4610
  newJSONString = applyEdits(
4599
4611
  newJSONString,
4600
4612
  modify(
@@ -4611,16 +4623,16 @@ async function prepublish() {
4611
4623
  const [manifest, resolvedOutdir] = generateNewManifest(dir, originalManifest);
4612
4624
  const resolveByDir = (...paths) => path.resolve(dir, ...paths);
4613
4625
  const oldJSONString = fs.readFileSync(resolveByDir("package.json"), "utf-8");
4614
- const oldJSON = JSON.parse(oldJSONString) ?? "0.0.0";
4626
+ const oldJSON = JSON.parse(oldJSONString);
4615
4627
  if (typeof oldJSON.version !== "string") {
4616
- 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`);
4617
4629
  }
4618
4630
  const { indent = " " } = detectIndent(oldJSONString);
4619
4631
  const formattingOptions = {
4620
4632
  tabSize: indent.length,
4621
4633
  insertSpaces: true
4622
4634
  };
4623
- const newVersion = bumper ? bump(oldJSON.version, bumper) : oldJSON.version;
4635
+ const newVersion = bumper ? bump(oldJSON.version, bumper === true ? "patch" : bumper) : oldJSON.version;
4624
4636
  const modifyVersionPackageJSON = applyEdits(
4625
4637
  oldJSONString,
4626
4638
  modify(oldJSONString, ["version"], newVersion, { formattingOptions })
@@ -4691,15 +4703,22 @@ async function prepublish() {
4691
4703
  }
4692
4704
  }
4693
4705
  if (oldJSON.files) {
4694
- if (!Array.isArray(oldJSON.files)) {
4695
- throw new Error(`${dir}/package.json files field must be an array`);
4696
- }
4697
- if (Array.isArray(oldJSON.files) && oldJSON.files.every((file) => typeof file !== "string")) {
4698
- 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`);
4699
4712
  }
4700
4713
  }
4701
4714
  const resolvedOutdirAbs = resolveByDir(resolvedOutdir);
4702
- 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
+ );
4703
4722
  for (const file of files) {
4704
4723
  const path2 = resolveByDir(file);
4705
4724
  try {
@@ -4736,10 +4755,11 @@ async function postpublish() {
4736
4755
  }
4737
4756
  });
4738
4757
  }
4758
+ console.log(process$1.env);
4739
4759
  program.action(async () => {
4740
4760
  const {
4741
4761
  npm_lifecycle_event: NPM_LIFECYCLE_EVENT
4742
- } = process.env;
4762
+ } = process$1.env;
4743
4763
  switch (NPM_LIFECYCLE_EVENT) {
4744
4764
  case "prepublish":
4745
4765
  await prepublish();
@@ -4760,7 +4780,7 @@ Prepare package.json for publish, you can add \`jk\` to the \`prepublish\` scrip
4760
4780
  }
4761
4781
  }
4762
4782
  `.trim();
4763
- program.command("prepublish").description(prepublishDescription).action(prepublish);
4783
+ program.command("prepublish").description(prepublishDescription).option("-b, --bumper <bumper>", "bump version").option("-no-b, --no-bumper", "no bump version").action(prepublish);
4764
4784
  const postpublishDescription = `
4765
4785
  Restore package.json after publish, you can add \`jk\` to the \`postpublish\` script in package.json, the command will automatically run \`jk postpublish\`.
4766
4786
  .e.g
@@ -4772,4 +4792,27 @@ Restore package.json after publish, you can add \`jk\` to the \`postpublish\` sc
4772
4792
  `.trim();
4773
4793
  program.command("postpublish").description(postpublishDescription).action(postpublish);
4774
4794
 
4775
- program.parse(process.argv);
4795
+ const { argv } = process$1;
4796
+ const env = {};
4797
+ let isPassThrough = false;
4798
+ const newArgv = argv.filter((arg) => {
4799
+ if (isPassThrough) {
4800
+ return true;
4801
+ }
4802
+ if (arg === "--") {
4803
+ isPassThrough = true;
4804
+ return false;
4805
+ }
4806
+ const m = /^--env\.(\w+)=(.*)$/.exec(arg);
4807
+ if (m) {
4808
+ env[m[1]] = m[2];
4809
+ return false;
4810
+ }
4811
+ return true;
4812
+ });
4813
+ for (const [key, value] of Object.entries(env)) {
4814
+ process$1.env[key] = value;
4815
+ }
4816
+ var parseArgv = () => program.parse(newArgv);
4817
+
4818
+ parseArgv();