jiek 0.4.7-alpha.3 → 0.4.7-alpha.5

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/jiek.js CHANGED
@@ -1,10 +1,13 @@
1
1
  #!/usr/bin/env node
2
- const fs = require('node:fs')
3
- const path = require('node:path')
2
+ import { existsSync } from 'node:fs'
3
+ import { resolve, dirname } from 'node:path'
4
+ import { createRequire } from 'node:module'
4
5
 
5
- if (fs.existsSync(path.join(__dirname, '../.jiek-dev-tag'))) {
6
+ const __dirname = dirname(import.meta.url.replace('file://', ''))
7
+ if (existsSync(resolve(__dirname, '../.jiek-dev-tag'))) {
8
+ const require = createRequire(import.meta.url)
6
9
  require('esbuild-register')
7
10
  require('../src/cli.ts')
8
11
  } else {
9
- require('jiek/cli')
12
+ import('jiek/cli')
10
13
  }
@@ -1,24 +1,45 @@
1
- import fs from 'node:fs';
2
- import path, { resolve as resolve$1, relative } from 'node:path';
3
- import { filterPackagesFromDir } from '@pnpm/filter-workspace-packages';
4
- import { program } from 'commander';
5
- import { load } from 'js-yaml';
6
- import { isWorkspaceDir, getWorkspaceDir } from '@jiek/utils/getWorkspaceDir';
7
- import { MultiBar, Presets } from 'cli-progress';
8
- import { execaCommand } from 'execa';
9
- import detectIndent from 'detect-indent';
10
- import inquirer from 'inquirer';
11
- import { applyEdits, modify } from 'jsonc-parser';
12
- import { isMatch } from 'micromatch';
13
- import * as childProcess from 'node:child_process';
14
- import { bump } from '@jiek/utils/bumper';
15
- import { resolveEntrypoints, filterLeafs, DEFAULT_SKIP_VALUES, entrypoints2Exports } from '@jiek/pkger/entrypoints';
1
+ 'use strict';
2
+
3
+ var fs = require('node:fs');
4
+ var path = require('node:path');
5
+ var filterWorkspacePackages = require('@pnpm/filter-workspace-packages');
6
+ var commander = require('commander');
7
+ var jsYaml = require('js-yaml');
8
+ var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
9
+ var cliProgress = require('cli-progress');
10
+ var execa = require('execa');
11
+ var detectIndent = require('detect-indent');
12
+ var inquirer = require('inquirer');
13
+ var jsoncParser = require('jsonc-parser');
14
+ var micromatch = require('micromatch');
15
+ var childProcess = require('node:child_process');
16
+ var bumper = require('@jiek/utils/bumper');
17
+ var entrypoints = require('@jiek/pkger/entrypoints');
18
+
19
+ function _interopNamespaceDefault(e) {
20
+ var n = Object.create(null);
21
+ if (e) {
22
+ Object.keys(e).forEach(function (k) {
23
+ if (k !== 'default') {
24
+ var d = Object.getOwnPropertyDescriptor(e, k);
25
+ Object.defineProperty(n, k, d.get ? d : {
26
+ enumerable: true,
27
+ get: function () { return e[k]; }
28
+ });
29
+ }
30
+ });
31
+ }
32
+ n.default = e;
33
+ return Object.freeze(n);
34
+ }
35
+
36
+ var childProcess__namespace = /*#__PURE__*/_interopNamespaceDefault(childProcess);
16
37
 
17
38
  let root;
18
39
  function getRoot() {
19
40
  if (root)
20
41
  return root;
21
- const rootOption = program.getOptionValue("root");
42
+ const rootOption = commander.program.getOptionValue("root");
22
43
  root = rootOption ? path.isAbsolute(rootOption) ? rootOption : path.resolve(process.cwd(), rootOption) : void 0;
23
44
  return root;
24
45
  }
@@ -30,13 +51,13 @@ function getWD() {
30
51
  return { wd, notWorkspace };
31
52
  const root = getRoot();
32
53
  if (root !== void 0) {
33
- const isWorkspace = isWorkspaceDir(root, type);
54
+ const isWorkspace = getWorkspaceDir.isWorkspaceDir(root, type);
34
55
  notWorkspace = !isWorkspace;
35
56
  wd = root;
36
57
  return { wd, notWorkspace };
37
58
  }
38
59
  try {
39
- wd = getWorkspaceDir(type);
60
+ wd = getWorkspaceDir.getWorkspaceDir(type);
40
61
  } catch (e) {
41
62
  if ("message" in e && e.message === "workspace root not found") {
42
63
  wd = root;
@@ -55,16 +76,16 @@ try {
55
76
  } catch {
56
77
  }
57
78
  if (type !== "") {
58
- program.option("-f, --filter <filter>", "filter packages");
79
+ commander.program.option("-f, --filter <filter>", "filter packages");
59
80
  }
60
81
  async function getSelectedProjectsGraph() {
61
- let filter = program.getOptionValue("filter");
82
+ let filter = commander.program.getOptionValue("filter");
62
83
  const root = getRoot();
63
84
  const { wd, notWorkspace } = getWD();
64
85
  if (!notWorkspace && type === "pnpm") {
65
86
  const pnpmWorkspaceFilePath = path.resolve(wd, "pnpm-workspace.yaml");
66
87
  const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, "utf-8");
67
- const pnpmWorkspace = load(pnpmWorkspaceFileContent);
88
+ const pnpmWorkspace = jsYaml.load(pnpmWorkspaceFileContent);
68
89
  if (root === wd && !filter) {
69
90
  throw new Error("root path is workspace root, please provide a filter");
70
91
  }
@@ -79,7 +100,7 @@ async function getSelectedProjectsGraph() {
79
100
  }
80
101
  filter = packageJSON.name;
81
102
  }
82
- const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{
103
+ const { selectedProjectsGraph } = await filterWorkspacePackages.filterPackagesFromDir(wd, [{
83
104
  filter: filter ?? "",
84
105
  followProdDepsOnly: true
85
106
  }], {
@@ -107,7 +128,7 @@ async function getSelectedProjectsGraph() {
107
128
 
108
129
  var pkg = require("../package.json");
109
130
 
110
- program.version(pkg.version).description(pkg.description).option("--root <root>", "root path").option("-c, --config-path <configPath>", "config path");
131
+ commander.program.version(pkg.version).description(pkg.description).option("--root <root>", "root path").option("-c, --config-path <configPath>", "config path");
111
132
 
112
133
  let resolve;
113
134
  function actionDone() {
@@ -172,7 +193,7 @@ function getConfigPath(root, dir) {
172
193
  }
173
194
  function loadConfig(dir) {
174
195
  const { wd: root } = getWD();
175
- let configPath = program.getOptionValue("configPath");
196
+ let configPath = commander.program.getOptionValue("configPath");
176
197
  if (!configPath) {
177
198
  configPath = getConfigPath(root, dir);
178
199
  } else {
@@ -192,7 +213,7 @@ function loadConfig(dir) {
192
213
  case ".json":
193
214
  return require(configPath);
194
215
  case ".yaml":
195
- return load(fs.readFileSync(configPath, "utf-8"));
216
+ return jsYaml.load(fs.readFileSync(configPath, "utf-8"));
196
217
  case ".ts":
197
218
  if (tsRegisterName) {
198
219
  require(tsRegisterName);
@@ -217,7 +238,7 @@ const FILE_TEMPLATE = (manifest) => `
217
238
  const manifest = ${JSON.stringify(manifest, null, 2)}
218
239
  module.exports = require('jiek/rollup').template(manifest)
219
240
  `.trimStart();
220
- program.command("build").option("-s, --silent", "Don't display logs.").option("-e, --entries <ENTRIES>", "Specify the entries of the package.json's 'exports' field.(support glob)").action(async ({
241
+ commander.program.command("build").option("-s, --silent", "Don't display logs.").option("-e, --entries <ENTRIES>", "Specify the entries of the package.json's 'exports' field.(support glob)").action(async ({
221
242
  silent,
222
243
  entries
223
244
  }) => {
@@ -240,11 +261,11 @@ program.command("build").option("-s, --silent", "Don't display logs.").option("-
240
261
  fs.mkdirSync(jiekTempDir());
241
262
  }
242
263
  const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
243
- const multiBars = new MultiBar({
264
+ const multiBars = new cliProgress.MultiBar({
244
265
  clearOnComplete: false,
245
266
  hideCursor: true,
246
267
  format: "- {bar} | {status} | {input} | {message}"
247
- }, Presets.shades_classic);
268
+ }, cliProgress.Presets.shades_classic);
248
269
  let i = 0;
249
270
  await Promise.all(
250
271
  Object.entries(value).map(async ([dir, manifest]) => {
@@ -258,7 +279,7 @@ program.command("build").option("-s, --silent", "Don't display logs.").option("-
258
279
  prefix = `node -r ${tsRegisterName} `;
259
280
  }
260
281
  const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`;
261
- const child = execaCommand(command, {
282
+ const child = execa.execaCommand(command, {
262
283
  ipc: true,
263
284
  cwd: dir,
264
285
  env: {
@@ -432,12 +453,12 @@ async function getName(named, name, {
432
453
  }
433
454
  } else {
434
455
  for (const [key, value] of Object.entries(named)) {
435
- if (isMatch(relativePath, key)) {
456
+ if (micromatch.isMatch(relativePath, key)) {
436
457
  matchedKey = key;
437
458
  matchedRule = value;
438
459
  break;
439
460
  }
440
- if (isMatch(`${relativePath}/jiek_ignore_dont_use_same_file_name`, key)) {
461
+ if (micromatch.isMatch(`${relativePath}/jiek_ignore_dont_use_same_file_name`, key)) {
441
462
  isParentMatched = true;
442
463
  matchedKey = key;
443
464
  matchedRule = value;
@@ -477,8 +498,8 @@ async function getName(named, name, {
477
498
  }
478
499
  throw new Error("no matched rule");
479
500
  }
480
- program.command("init [name]").option("-t, --template <template>", "the package.json template file path or file content").action(async () => {
481
- const [, name] = program.args;
501
+ commander.program.command("init [name]").option("-t, --template <template>", "the package.json template file path or file content").action(async () => {
502
+ const [, name] = commander.program.args;
482
503
  const cwd = process.cwd();
483
504
  const { init = {} } = loadConfig() ?? {};
484
505
  const { wd } = getWD();
@@ -512,9 +533,9 @@ program.command("init [name]").option("-t, --template <template>", "the package.
512
533
  ];
513
534
  let newJSONString = templateString;
514
535
  for (const field of passFields) {
515
- newJSONString = applyEdits(
536
+ newJSONString = jsoncParser.applyEdits(
516
537
  newJSONString,
517
- modify(
538
+ jsoncParser.modify(
518
539
  newJSONString,
519
540
  [field],
520
541
  getWDPackageJSONFiled(wd, field),
@@ -545,7 +566,7 @@ program.command("init [name]").option("-t, --template <template>", "the package.
545
566
  });
546
567
  pkgName = inputName;
547
568
  }
548
- newJSONString = applyEdits(newJSONString, modify(newJSONString, ["name"], pkgName, { formattingOptions }));
569
+ newJSONString = jsoncParser.applyEdits(newJSONString, jsoncParser.modify(newJSONString, ["name"], pkgName, { formattingOptions }));
549
570
  let pkgRepo = getWDPackageJSONFiled(wd, "repository");
550
571
  if (typeof pkgRepo === "string") {
551
572
  pkgRepo = {
@@ -554,9 +575,9 @@ program.command("init [name]").option("-t, --template <template>", "the package.
554
575
  directory: pkgDir
555
576
  };
556
577
  }
557
- newJSONString = applyEdits(
578
+ newJSONString = jsoncParser.applyEdits(
558
579
  newJSONString,
559
- modify(
580
+ jsoncParser.modify(
560
581
  newJSONString,
561
582
  ["repository"],
562
583
  pkgRepo,
@@ -564,9 +585,9 @@ program.command("init [name]").option("-t, --template <template>", "the package.
564
585
  )
565
586
  );
566
587
  const homepage = `${pkgRepo?.url}/blob/master/${pkgDir}/README.md`;
567
- newJSONString = applyEdits(
588
+ newJSONString = jsoncParser.applyEdits(
568
589
  newJSONString,
569
- modify(
590
+ jsoncParser.modify(
570
591
  newJSONString,
571
592
  ["homepage"],
572
593
  homepage,
@@ -582,9 +603,9 @@ program.command("init [name]").option("-t, --template <template>", "the package.
582
603
  }
583
604
  labels.push(`scope:${pkgName}`);
584
605
  const bugs = `${pkgRepo?.url}/issues/new?template=${resolvedBug.template}&labels=${labels.join(",")}`;
585
- newJSONString = applyEdits(
606
+ newJSONString = jsoncParser.applyEdits(
586
607
  newJSONString,
587
- modify(
608
+ jsoncParser.modify(
588
609
  newJSONString,
589
610
  ["bugs"],
590
611
  bugs,
@@ -618,15 +639,17 @@ program.command("init [name]").option("-t, --template <template>", "the package.
618
639
 
619
640
  const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
620
641
  function getExports({
621
- entrypoints,
642
+ entrypoints: entrypoints$1,
622
643
  pkgIsModule,
623
644
  entries,
624
645
  config,
625
646
  dir,
626
- noFilter
647
+ noFilter,
648
+ withSource,
649
+ withSuffix
627
650
  }) {
628
- const dirResolve = (...paths) => resolve$1(dir ?? process.cwd(), ...paths);
629
- const dirRelative = (path) => relative(dir ?? process.cwd(), path);
651
+ const dirResolve = (...paths) => path.resolve(dir ?? process.cwd(), ...paths);
652
+ const dirRelative = (path$1) => path.relative(dir ?? process.cwd(), path$1);
630
653
  const { build = {} } = config ?? {};
631
654
  const {
632
655
  crossModuleConvertor = true
@@ -634,21 +657,21 @@ function getExports({
634
657
  const jsOutdir = `./${dirRelative(dirResolve(
635
658
  (typeof build?.output?.dir === "object" ? build.output.dir.js : build?.output?.dir) ?? "dist"
636
659
  ))}`;
637
- const [, resolvedEntrypoints] = resolveEntrypoints(entrypoints);
660
+ const [, resolvedEntrypoints] = entrypoints.resolveEntrypoints(entrypoints$1);
638
661
  if (entries) {
639
662
  Object.entries(resolvedEntrypoints).forEach(([key]) => {
640
- if (!entries.some((e) => isMatch(key, e, { matchBase: true }))) {
663
+ if (!entries.some((e) => micromatch.isMatch(key, e, { matchBase: true }))) {
641
664
  delete resolvedEntrypoints[key];
642
665
  }
643
666
  });
644
667
  }
645
- const filteredResolvedEntrypoints = noFilter ? resolvedEntrypoints : filterLeafs(
668
+ const filteredResolvedEntrypoints = noFilter ? resolvedEntrypoints : entrypoints.filterLeafs(
646
669
  resolvedEntrypoints,
647
670
  {
648
671
  skipValue: [
649
672
  // ignore values that filename starts with `.jk-noentry`
650
673
  /(^|\/)\.jk-noentry/,
651
- ...DEFAULT_SKIP_VALUES
674
+ ...entrypoints.DEFAULT_SKIP_VALUES
652
675
  ]
653
676
  }
654
677
  );
@@ -664,8 +687,10 @@ function getExports({
664
687
  } : {};
665
688
  return [
666
689
  filteredResolvedEntrypoints,
667
- entrypoints2Exports(filteredResolvedEntrypoints, {
690
+ entrypoints.entrypoints2Exports(filteredResolvedEntrypoints, {
668
691
  outdir: jsOutdir,
692
+ withSource,
693
+ withSuffix,
669
694
  withConditional: {
670
695
  ...crossModuleWithConditional
671
696
  }
@@ -673,7 +698,7 @@ function getExports({
673
698
  ];
674
699
  }
675
700
 
676
- program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>", "bump version", "patch").option("-p, --preview", "preview publish").action(async ({ preview, bumper, ...options }) => {
701
+ commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>", "bump version", "patch").option("-p, --preview", "preview publish").action(async ({ preview, bumper: bumper$1, ...options }) => {
677
702
  actionRestore();
678
703
  const { value = {} } = await getSelectedProjectsGraph() ?? {};
679
704
  const selectedProjectsGraphEntries = Object.entries(value);
@@ -689,7 +714,9 @@ program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>",
689
714
  pkgIsModule,
690
715
  config: loadConfig(dir),
691
716
  dir,
692
- noFilter: true
717
+ noFilter: true,
718
+ withSource: true,
719
+ withSuffix: true
693
720
  });
694
721
  newManifest.exports = {
695
722
  ...resolvedEntrypoints,
@@ -706,16 +733,16 @@ program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>",
706
733
  for (const [dir, manifest] of manifests) {
707
734
  const oldJSONString = fs.readFileSync(path.join(dir, "package.json"), "utf-8");
708
735
  const oldJSON = JSON.parse(oldJSONString) ?? "0.0.0";
709
- const newVersion = bump(oldJSON.version, bumper);
736
+ const newVersion = bumper.bump(oldJSON.version, bumper$1);
710
737
  const { indent = " " } = detectIndent(oldJSONString);
711
738
  const formattingOptions = {
712
739
  tabSize: indent.length,
713
740
  insertSpaces: true
714
741
  };
715
742
  let newJSONString = oldJSONString;
716
- newJSONString = applyEdits(
743
+ newJSONString = jsoncParser.applyEdits(
717
744
  newJSONString,
718
- modify(
745
+ jsoncParser.modify(
719
746
  newJSONString,
720
747
  ["version"],
721
748
  newVersion,
@@ -726,9 +753,9 @@ program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>",
726
753
  if (JSON.stringify(value2) === JSON.stringify(oldJSON[key]))
727
754
  continue;
728
755
  if (key !== "exports") {
729
- newJSONString = applyEdits(
756
+ newJSONString = jsoncParser.applyEdits(
730
757
  newJSONString,
731
- modify(
758
+ jsoncParser.modify(
732
759
  newJSONString,
733
760
  ["publishConfig", key],
734
761
  value2,
@@ -738,9 +765,9 @@ program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>",
738
765
  } else {
739
766
  const exports = value2;
740
767
  for (const [k, v] of Object.entries(exports)) {
741
- newJSONString = applyEdits(
768
+ newJSONString = jsoncParser.applyEdits(
742
769
  newJSONString,
743
- modify(
770
+ jsoncParser.modify(
744
771
  newJSONString,
745
772
  ["publishConfig", "exports", k],
746
773
  v,
@@ -765,9 +792,9 @@ program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>",
765
792
  for (const [k, v] of Object.entries(indexPublishConfig)) {
766
793
  if (v === void 0)
767
794
  continue;
768
- newJSONString = applyEdits(
795
+ newJSONString = jsoncParser.applyEdits(
769
796
  newJSONString,
770
- modify(
797
+ jsoncParser.modify(
771
798
  newJSONString,
772
799
  ["publishConfig", k],
773
800
  v,
@@ -786,11 +813,11 @@ program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>",
786
813
  console.warn("preview mode");
787
814
  continue;
788
815
  }
789
- childProcess.execSync(["pnpm", "publish", "--access", "public", "--no-git-checks", ...passArgs].join(" "), {
816
+ childProcess__namespace.execSync(["pnpm", "publish", "--access", "public", "--no-git-checks", ...passArgs].join(" "), {
790
817
  cwd: dir,
791
818
  stdio: "inherit"
792
819
  });
793
- const modifyVersionPackageJSON = applyEdits(oldJSONString, modify(oldJSONString, ["version"], newVersion, {}));
820
+ const modifyVersionPackageJSON = jsoncParser.applyEdits(oldJSONString, jsoncParser.modify(oldJSONString, ["version"], newVersion, {}));
794
821
  fs.writeFileSync(path.join(dir, "package.json.bak"), modifyVersionPackageJSON);
795
822
  } finally {
796
823
  fs.unlinkSync(path.join(dir, "package.json"));
@@ -800,4 +827,4 @@ program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>",
800
827
  actionDone();
801
828
  });
802
829
 
803
- program.parse(process.argv);
830
+ commander.program.parse(process.argv);