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.
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;
4471
- const outdir = outdirEnv ? JSON.parse(outdirEnv) : "dist";
4472
- const bumper = bumperEnv ? JSON.parse(bumperEnv) : false;
4470
+ } = process$1.env;
4471
+ const outdir = outdirEnv ?? "dist";
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 {
@@ -4748,10 +4755,11 @@ async function postpublish() {
4748
4755
  }
4749
4756
  });
4750
4757
  }
4758
+ console.log(process$1.env);
4751
4759
  program.action(async () => {
4752
4760
  const {
4753
4761
  npm_lifecycle_event: NPM_LIFECYCLE_EVENT
4754
- } = process.env;
4762
+ } = process$1.env;
4755
4763
  switch (NPM_LIFECYCLE_EVENT) {
4756
4764
  case "prepublish":
4757
4765
  await prepublish();
@@ -4772,7 +4780,7 @@ Prepare package.json for publish, you can add \`jk\` to the \`prepublish\` scrip
4772
4780
  }
4773
4781
  }
4774
4782
  `.trim();
4775
- 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);
4776
4784
  const postpublishDescription = `
4777
4785
  Restore package.json after publish, you can add \`jk\` to the \`postpublish\` script in package.json, the command will automatically run \`jk postpublish\`.
4778
4786
  .e.g
@@ -9,10 +9,10 @@ var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
9
9
  var commonjs = require('@rollup/plugin-commonjs');
10
10
  var json = require('@rollup/plugin-json');
11
11
  var pluginNodeResolve = require('@rollup/plugin-node-resolve');
12
- var execa = require('execa');
13
12
  var require$$0 = require('util');
14
13
  var require$$0$1 = require('path');
15
14
  var ts = require('typescript');
15
+ var execa = require('execa');
16
16
  var node_module = require('node:module');
17
17
  var commander = require('commander');
18
18
  var jsYaml = require('js-yaml');
@@ -4140,6 +4140,53 @@ function requireMicromatch () {
4140
4140
 
4141
4141
  var micromatchExports = requireMicromatch();
4142
4142
 
4143
+ const publish = async (type, data) => {
4144
+ return execa.sendMessage({ type, data });
4145
+ };
4146
+
4147
+ const {
4148
+ JIEK_ANALYZER
4149
+ } = process__default.default.env;
4150
+ const ANALYZER = JIEK_ANALYZER != null && JSON.parse(JIEK_ANALYZER);
4151
+ function bundleAnalyzer(modulesResolved) {
4152
+ if (!ANALYZER) {
4153
+ return [];
4154
+ }
4155
+ const defaultSizes = {
4156
+ parsed: "parsed",
4157
+ stat: "stat",
4158
+ gzip: "gzip"
4159
+ }[ANALYZER.size ?? "stat"] ?? "parsed";
4160
+ let ana;
4161
+ async function initAna() {
4162
+ const { adapter, analyzer } = await import('vite-bundle-analyzer');
4163
+ ana = ana ?? adapter(analyzer({
4164
+ defaultSizes,
4165
+ analyzerMode: modulesResolved
4166
+ }));
4167
+ }
4168
+ return [
4169
+ (async () => {
4170
+ await initAna();
4171
+ return {
4172
+ name: "jiek:bundle-analyzer",
4173
+ async closeBundle(...args) {
4174
+ if (typeof ana.closeBundle !== "function")
4175
+ return;
4176
+ return ana.closeBundle?.call(this, ...args);
4177
+ }
4178
+ };
4179
+ })(),
4180
+ (async () => {
4181
+ await initAna();
4182
+ return {
4183
+ ...ana,
4184
+ name: "jiek:bundle-analyzer-output"
4185
+ };
4186
+ })()
4187
+ ];
4188
+ }
4189
+
4143
4190
  const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4144
4191
  const {
4145
4192
  JIEK_OUT_DIR
@@ -4538,7 +4585,6 @@ function externalResolver(jsonOrPath = process.cwd()) {
4538
4585
  }
4539
4586
 
4540
4587
  const {
4541
- JIEK_ANALYZER,
4542
4588
  JIEK_ROOT,
4543
4589
  JIEK_NAME,
4544
4590
  JIEK_BUILDER,
@@ -4561,7 +4607,6 @@ const resolveArrayString = (str) => {
4561
4607
  ];
4562
4608
  return arr?.length ? arr : void 0;
4563
4609
  };
4564
- const ANALYZER = JIEK_ANALYZER && JSON.parse(JIEK_ANALYZER);
4565
4610
  const entries = resolveArrayString(JIEK_ENTRIES)?.map((e) => ({ "index": "." })[e] ?? e);
4566
4611
  const commandExternal = resolveArrayString(JIEK_EXTERNAL)?.map((e) => new RegExp(`^${e}$`));
4567
4612
  const WORKSPACE_ROOT = JIEK_ROOT ?? getWorkspaceDir.getWorkspaceDir();
@@ -4636,15 +4681,9 @@ const resolvedMinifyOptions = resolveMinifyOptions(build.output?.minifyOptions ?
4636
4681
  const { type: _resolvedMinifyOptionsType, ...noTypeResolvedMinifyOptions } = resolvedMinifyOptions;
4637
4682
  const resolvedBuilderOptions = resolveBuilderOptions(build.builder ?? BUILDER_OPTIONS);
4638
4683
  const { type: _resolvedBuilderOptionsType, ...noTypeResolvedBuilderOptions } = resolvedBuilderOptions;
4639
- const withMinify = (output, minify = build?.output?.minify ?? MINIFY_DEFAULT_VALUE) => {
4684
+ const withMinify = (output, onlyOncePlugins = []) => {
4685
+ const minify = build?.output?.minify ?? MINIFY_DEFAULT_VALUE;
4640
4686
  output.plugins = output.plugins ?? [];
4641
- const onlyOncePlugins = [
4642
- // adapter(analyzer({
4643
- // analyzerMode: 'server',
4644
- // analyzerPort: 8888,
4645
- // reportTitle: 'Bundle Analysis'
4646
- // }))
4647
- ];
4648
4687
  if (minify === false) {
4649
4688
  output.plugins.push(...onlyOncePlugins);
4650
4689
  return [output];
@@ -4691,6 +4730,7 @@ const generateConfigs = (context, options = {}) => {
4691
4730
  const isModule = conditionals.includes("import");
4692
4731
  const isCommonJS = conditionals.includes("require");
4693
4732
  const isBrowser = conditionals.includes("browser");
4733
+ const format = isModule ? "esm" : isCommonJS ? "cjs" : isBrowser ? "umd" : pkgIsModule ? "esm" : "cjs";
4694
4734
  const dtsTSConfigPaths = [
4695
4735
  resolveWorkspacePath("tsconfig.json"),
4696
4736
  resolveWorkspacePath("tsconfig.dts.json")
@@ -4728,10 +4768,19 @@ const generateConfigs = (context, options = {}) => {
4728
4768
  delete compilerOptions.composite;
4729
4769
  }
4730
4770
  const exportConditions = [...conditionals, ...compilerOptions.customConditions ?? []];
4731
- const throughEventProps = {
4732
- type: "progress",
4733
- data: { name, path: path$1, exportConditions, input }
4734
- };
4771
+ const publishInEntry = (type, data) => (
4772
+ // eslint-disable-next-line ts/no-unsafe-argument
4773
+ void publish(type, {
4774
+ ...{
4775
+ type: format,
4776
+ name,
4777
+ path: path$1,
4778
+ exportConditions,
4779
+ input
4780
+ },
4781
+ ...data
4782
+ })
4783
+ );
4735
4784
  const { js: jsPlugins, dts: dtsPlugins } = resolveBuildPlugins(context, build.plugins);
4736
4785
  if (input.includes("**")) {
4737
4786
  throw new Error(
@@ -4769,55 +4818,10 @@ const generateConfigs = (context, options = {}) => {
4769
4818
  ...noTypeResolvedBuilderOptions
4770
4819
  })
4771
4820
  );
4772
- const ana = ANALYZER ? import('vite-bundle-analyzer').then(({ adapter, analyzer }) => {
4773
- const defaultSizes = {
4774
- parsed: "parsed",
4775
- stat: "stat",
4776
- gzip: "gzip"
4777
- }[ANALYZER.size ?? "stat"] ?? "parsed";
4778
- const title = `${path.join(context.name, context.path)} ${context.conditionals.join(",")}`;
4779
- const filename = title.replace("/", "_").replace(" ", "_");
4780
- switch (ANALYZER.mode ?? "server") {
4781
- case "server":
4782
- return adapter(analyzer({
4783
- defaultSizes,
4784
- analyzerMode: "server",
4785
- analyzerPort: ANALYZER.port ?? "auto",
4786
- openAnalyzer: ANALYZER.open ?? false,
4787
- reportTitle: `Bundle Analysis ${title}`
4788
- }));
4789
- case "json":
4790
- return adapter(analyzer({
4791
- defaultSizes,
4792
- analyzerMode: "json",
4793
- fileName: ANALYZER.dir ? path.join(ANALYZER.dir, filename) : filename
4794
- }));
4795
- case "static":
4796
- return adapter(analyzer({
4797
- defaultSizes,
4798
- analyzerMode: "static",
4799
- analyzerPort: ANALYZER.port ?? "auto",
4800
- openAnalyzer: ANALYZER.open ?? false,
4801
- reportTitle: `Bundle Analysis ${title}`,
4802
- fileName: ANALYZER.dir ? path.join(ANALYZER.dir, filename) : filename
4803
- }));
4804
- case void 0: {
4805
- throw new Error("Not implemented yet: undefined case");
4806
- }
4807
- default:
4808
- void execa.sendMessage(
4809
- {
4810
- ...throughEventProps,
4811
- data: {
4812
- ...throughEventProps.data,
4813
- event: "error",
4814
- message: "ANALYZER.mode not supported",
4815
- tags: ["js"]
4816
- }
4817
- }
4818
- );
4819
- }
4820
- }) : void 0;
4821
+ const [ana, anaOutputPlugin] = bundleAnalyzer((modules) => void publishInEntry("modulesAnalyze", { modules }));
4822
+ const onlyOncePlugins = [
4823
+ anaOutputPlugin
4824
+ ];
4821
4825
  rollupOptions.push({
4822
4826
  input: inputObj,
4823
4827
  external,
@@ -4828,12 +4832,12 @@ const generateConfigs = (context, options = {}) => {
4828
4832
  interop: "auto",
4829
4833
  entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process__default.default.cwd()}/`, "").replace(globCommonDir, pathCommonDir).replace(/(\.[cm]?)ts$/, jsOutputSuffix) : output.replace(`${jsOutdir}/`, ""),
4830
4834
  sourcemap,
4831
- format: isModule ? "esm" : isCommonJS ? "cjs" : isBrowser ? "umd" : pkgIsModule ? "esm" : "cjs",
4835
+ format,
4832
4836
  strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict,
4833
4837
  plugins: [
4834
- isFormatEsm(isModule)
4838
+ isFormatEsm(format === "esm")
4835
4839
  ]
4836
- })
4840
+ }, onlyOncePlugins)
4837
4841
  ],
4838
4842
  plugins: [
4839
4843
  ...commonPlugins,
@@ -4848,12 +4852,7 @@ const generateConfigs = (context, options = {}) => {
4848
4852
  builder,
4849
4853
  ana,
4850
4854
  progress({
4851
- onEvent: (event, message) => void execa.sendMessage(
4852
- {
4853
- ...throughEventProps,
4854
- data: { ...throughEventProps.data, event, message, tags: ["js"] }
4855
- }
4856
- )
4855
+ onEvent: (event, message) => void publishInEntry("progress", { event, message, tags: ["js"] })
4857
4856
  }),
4858
4857
  jsPlugins
4859
4858
  ]
@@ -4890,12 +4889,7 @@ const generateConfigs = (context, options = {}) => {
4890
4889
  tsconfig: dtsTSConfigPath
4891
4890
  }),
4892
4891
  progress({
4893
- onEvent: (event, message) => void execa.sendMessage(
4894
- {
4895
- ...throughEventProps,
4896
- data: { ...throughEventProps.data, event, message, tags: ["dts"] }
4897
- }
4898
- )
4892
+ onEvent: (event, message) => void publishInEntry("progress", { event, message, tags: ["dts"] })
4899
4893
  }),
4900
4894
  dtsPlugins
4901
4895
  ]
@@ -4905,12 +4899,7 @@ const generateConfigs = (context, options = {}) => {
4905
4899
  rollupOptions[0].plugins = [
4906
4900
  {
4907
4901
  name: "jiek-plugin-watcher",
4908
- watchChange: (id) => void execa.sendMessage(
4909
- {
4910
- type: "watchChange",
4911
- data: { id, name: JIEK_NAME, path: path$1, input }
4912
- }
4913
- )
4902
+ watchChange: (id) => void publishInEntry("watchChange", { id })
4914
4903
  },
4915
4904
  ...rollupOptions[0].plugins
4916
4905
  ];
@@ -4982,15 +4971,7 @@ function template(packageJSON) {
4982
4971
  }
4983
4972
  })
4984
4973
  );
4985
- void execa.sendMessage(
4986
- {
4987
- type: "init",
4988
- data: {
4989
- leafMap,
4990
- targetsLength: configs.length
4991
- }
4992
- }
4993
- );
4974
+ void publish("init", { leafMap, targetsLength: configs.length });
4994
4975
  return configs.map((c) => ({
4995
4976
  ...COMMON_OPTIONS,
4996
4977
  ...c,
@@ -1,5 +1,5 @@
1
1
  import fs from 'node:fs';
2
- import path, { isAbsolute, relative, resolve, dirname, extname, join } from 'node:path';
2
+ import path, { isAbsolute, relative, resolve, dirname, extname } from 'node:path';
3
3
  import process$1 from 'node:process';
4
4
  import { resolveEntrypoints, filterLeafs, DEFAULT_SKIP_VALUES, entrypoints2Exports, getAllLeafs } from '@jiek/pkger/entrypoints';
5
5
  import { dts } from '@jiek/rollup-plugin-dts';
@@ -7,10 +7,10 @@ import { isWorkspaceDir, getWorkspaceDir } from '@jiek/utils/getWorkspaceDir';
7
7
  import commonjs from '@rollup/plugin-commonjs';
8
8
  import json from '@rollup/plugin-json';
9
9
  import { nodeResolve } from '@rollup/plugin-node-resolve';
10
- import { sendMessage } from 'execa';
11
10
  import require$$0 from 'util';
12
11
  import require$$0$1 from 'path';
13
12
  import ts from 'typescript';
13
+ import { sendMessage } from 'execa';
14
14
  import { createRequire as createRequire$1, builtinModules } from 'node:module';
15
15
  import { program } from 'commander';
16
16
  import { load } from 'js-yaml';
@@ -4124,6 +4124,53 @@ function requireMicromatch () {
4124
4124
 
4125
4125
  var micromatchExports = requireMicromatch();
4126
4126
 
4127
+ const publish = async (type, data) => {
4128
+ return sendMessage({ type, data });
4129
+ };
4130
+
4131
+ const {
4132
+ JIEK_ANALYZER
4133
+ } = process$1.env;
4134
+ const ANALYZER = JIEK_ANALYZER != null && JSON.parse(JIEK_ANALYZER);
4135
+ function bundleAnalyzer(modulesResolved) {
4136
+ if (!ANALYZER) {
4137
+ return [];
4138
+ }
4139
+ const defaultSizes = {
4140
+ parsed: "parsed",
4141
+ stat: "stat",
4142
+ gzip: "gzip"
4143
+ }[ANALYZER.size ?? "stat"] ?? "parsed";
4144
+ let ana;
4145
+ async function initAna() {
4146
+ const { adapter, analyzer } = await import('vite-bundle-analyzer');
4147
+ ana = ana ?? adapter(analyzer({
4148
+ defaultSizes,
4149
+ analyzerMode: modulesResolved
4150
+ }));
4151
+ }
4152
+ return [
4153
+ (async () => {
4154
+ await initAna();
4155
+ return {
4156
+ name: "jiek:bundle-analyzer",
4157
+ async closeBundle(...args) {
4158
+ if (typeof ana.closeBundle !== "function")
4159
+ return;
4160
+ return ana.closeBundle?.call(this, ...args);
4161
+ }
4162
+ };
4163
+ })(),
4164
+ (async () => {
4165
+ await initAna();
4166
+ return {
4167
+ ...ana,
4168
+ name: "jiek:bundle-analyzer-output"
4169
+ };
4170
+ })()
4171
+ ];
4172
+ }
4173
+
4127
4174
  const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4128
4175
  const {
4129
4176
  JIEK_OUT_DIR
@@ -4522,7 +4569,6 @@ function externalResolver(jsonOrPath = process.cwd()) {
4522
4569
  }
4523
4570
 
4524
4571
  const {
4525
- JIEK_ANALYZER,
4526
4572
  JIEK_ROOT,
4527
4573
  JIEK_NAME,
4528
4574
  JIEK_BUILDER,
@@ -4545,7 +4591,6 @@ const resolveArrayString = (str) => {
4545
4591
  ];
4546
4592
  return arr?.length ? arr : void 0;
4547
4593
  };
4548
- const ANALYZER = JIEK_ANALYZER && JSON.parse(JIEK_ANALYZER);
4549
4594
  const entries = resolveArrayString(JIEK_ENTRIES)?.map((e) => ({ "index": "." })[e] ?? e);
4550
4595
  const commandExternal = resolveArrayString(JIEK_EXTERNAL)?.map((e) => new RegExp(`^${e}$`));
4551
4596
  const WORKSPACE_ROOT = JIEK_ROOT ?? getWorkspaceDir();
@@ -4620,15 +4665,9 @@ const resolvedMinifyOptions = resolveMinifyOptions(build.output?.minifyOptions ?
4620
4665
  const { type: _resolvedMinifyOptionsType, ...noTypeResolvedMinifyOptions } = resolvedMinifyOptions;
4621
4666
  const resolvedBuilderOptions = resolveBuilderOptions(build.builder ?? BUILDER_OPTIONS);
4622
4667
  const { type: _resolvedBuilderOptionsType, ...noTypeResolvedBuilderOptions } = resolvedBuilderOptions;
4623
- const withMinify = (output, minify = build?.output?.minify ?? MINIFY_DEFAULT_VALUE) => {
4668
+ const withMinify = (output, onlyOncePlugins = []) => {
4669
+ const minify = build?.output?.minify ?? MINIFY_DEFAULT_VALUE;
4624
4670
  output.plugins = output.plugins ?? [];
4625
- const onlyOncePlugins = [
4626
- // adapter(analyzer({
4627
- // analyzerMode: 'server',
4628
- // analyzerPort: 8888,
4629
- // reportTitle: 'Bundle Analysis'
4630
- // }))
4631
- ];
4632
4671
  if (minify === false) {
4633
4672
  output.plugins.push(...onlyOncePlugins);
4634
4673
  return [output];
@@ -4675,6 +4714,7 @@ const generateConfigs = (context, options = {}) => {
4675
4714
  const isModule = conditionals.includes("import");
4676
4715
  const isCommonJS = conditionals.includes("require");
4677
4716
  const isBrowser = conditionals.includes("browser");
4717
+ const format = isModule ? "esm" : isCommonJS ? "cjs" : isBrowser ? "umd" : pkgIsModule ? "esm" : "cjs";
4678
4718
  const dtsTSConfigPaths = [
4679
4719
  resolveWorkspacePath("tsconfig.json"),
4680
4720
  resolveWorkspacePath("tsconfig.dts.json")
@@ -4712,10 +4752,19 @@ const generateConfigs = (context, options = {}) => {
4712
4752
  delete compilerOptions.composite;
4713
4753
  }
4714
4754
  const exportConditions = [...conditionals, ...compilerOptions.customConditions ?? []];
4715
- const throughEventProps = {
4716
- type: "progress",
4717
- data: { name, path, exportConditions, input }
4718
- };
4755
+ const publishInEntry = (type, data) => (
4756
+ // eslint-disable-next-line ts/no-unsafe-argument
4757
+ void publish(type, {
4758
+ ...{
4759
+ type: format,
4760
+ name,
4761
+ path,
4762
+ exportConditions,
4763
+ input
4764
+ },
4765
+ ...data
4766
+ })
4767
+ );
4719
4768
  const { js: jsPlugins, dts: dtsPlugins } = resolveBuildPlugins(context, build.plugins);
4720
4769
  if (input.includes("**")) {
4721
4770
  throw new Error(
@@ -4753,55 +4802,10 @@ const generateConfigs = (context, options = {}) => {
4753
4802
  ...noTypeResolvedBuilderOptions
4754
4803
  })
4755
4804
  );
4756
- const ana = ANALYZER ? import('vite-bundle-analyzer').then(({ adapter, analyzer }) => {
4757
- const defaultSizes = {
4758
- parsed: "parsed",
4759
- stat: "stat",
4760
- gzip: "gzip"
4761
- }[ANALYZER.size ?? "stat"] ?? "parsed";
4762
- const title = `${join(context.name, context.path)} ${context.conditionals.join(",")}`;
4763
- const filename = title.replace("/", "_").replace(" ", "_");
4764
- switch (ANALYZER.mode ?? "server") {
4765
- case "server":
4766
- return adapter(analyzer({
4767
- defaultSizes,
4768
- analyzerMode: "server",
4769
- analyzerPort: ANALYZER.port ?? "auto",
4770
- openAnalyzer: ANALYZER.open ?? false,
4771
- reportTitle: `Bundle Analysis ${title}`
4772
- }));
4773
- case "json":
4774
- return adapter(analyzer({
4775
- defaultSizes,
4776
- analyzerMode: "json",
4777
- fileName: ANALYZER.dir ? join(ANALYZER.dir, filename) : filename
4778
- }));
4779
- case "static":
4780
- return adapter(analyzer({
4781
- defaultSizes,
4782
- analyzerMode: "static",
4783
- analyzerPort: ANALYZER.port ?? "auto",
4784
- openAnalyzer: ANALYZER.open ?? false,
4785
- reportTitle: `Bundle Analysis ${title}`,
4786
- fileName: ANALYZER.dir ? join(ANALYZER.dir, filename) : filename
4787
- }));
4788
- case void 0: {
4789
- throw new Error("Not implemented yet: undefined case");
4790
- }
4791
- default:
4792
- void sendMessage(
4793
- {
4794
- ...throughEventProps,
4795
- data: {
4796
- ...throughEventProps.data,
4797
- event: "error",
4798
- message: "ANALYZER.mode not supported",
4799
- tags: ["js"]
4800
- }
4801
- }
4802
- );
4803
- }
4804
- }) : void 0;
4805
+ const [ana, anaOutputPlugin] = bundleAnalyzer((modules) => void publishInEntry("modulesAnalyze", { modules }));
4806
+ const onlyOncePlugins = [
4807
+ anaOutputPlugin
4808
+ ];
4805
4809
  rollupOptions.push({
4806
4810
  input: inputObj,
4807
4811
  external,
@@ -4812,12 +4816,12 @@ const generateConfigs = (context, options = {}) => {
4812
4816
  interop: "auto",
4813
4817
  entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process$1.cwd()}/`, "").replace(globCommonDir, pathCommonDir).replace(/(\.[cm]?)ts$/, jsOutputSuffix) : output.replace(`${jsOutdir}/`, ""),
4814
4818
  sourcemap,
4815
- format: isModule ? "esm" : isCommonJS ? "cjs" : isBrowser ? "umd" : pkgIsModule ? "esm" : "cjs",
4819
+ format,
4816
4820
  strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict,
4817
4821
  plugins: [
4818
- isFormatEsm(isModule)
4822
+ isFormatEsm(format === "esm")
4819
4823
  ]
4820
- })
4824
+ }, onlyOncePlugins)
4821
4825
  ],
4822
4826
  plugins: [
4823
4827
  ...commonPlugins,
@@ -4832,12 +4836,7 @@ const generateConfigs = (context, options = {}) => {
4832
4836
  builder,
4833
4837
  ana,
4834
4838
  progress({
4835
- onEvent: (event, message) => void sendMessage(
4836
- {
4837
- ...throughEventProps,
4838
- data: { ...throughEventProps.data, event, message, tags: ["js"] }
4839
- }
4840
- )
4839
+ onEvent: (event, message) => void publishInEntry("progress", { event, message, tags: ["js"] })
4841
4840
  }),
4842
4841
  jsPlugins
4843
4842
  ]
@@ -4874,12 +4873,7 @@ const generateConfigs = (context, options = {}) => {
4874
4873
  tsconfig: dtsTSConfigPath
4875
4874
  }),
4876
4875
  progress({
4877
- onEvent: (event, message) => void sendMessage(
4878
- {
4879
- ...throughEventProps,
4880
- data: { ...throughEventProps.data, event, message, tags: ["dts"] }
4881
- }
4882
- )
4876
+ onEvent: (event, message) => void publishInEntry("progress", { event, message, tags: ["dts"] })
4883
4877
  }),
4884
4878
  dtsPlugins
4885
4879
  ]
@@ -4889,12 +4883,7 @@ const generateConfigs = (context, options = {}) => {
4889
4883
  rollupOptions[0].plugins = [
4890
4884
  {
4891
4885
  name: "jiek-plugin-watcher",
4892
- watchChange: (id) => void sendMessage(
4893
- {
4894
- type: "watchChange",
4895
- data: { id, name: JIEK_NAME, path, input }
4896
- }
4897
- )
4886
+ watchChange: (id) => void publishInEntry("watchChange", { id })
4898
4887
  },
4899
4888
  ...rollupOptions[0].plugins
4900
4889
  ];
@@ -4966,15 +4955,7 @@ function template(packageJSON) {
4966
4955
  }
4967
4956
  })
4968
4957
  );
4969
- void sendMessage(
4970
- {
4971
- type: "init",
4972
- data: {
4973
- leafMap,
4974
- targetsLength: configs.length
4975
- }
4976
- }
4977
- );
4958
+ void publish("init", { leafMap, targetsLength: configs.length });
4978
4959
  return configs.map((c) => ({
4979
4960
  ...COMMON_OPTIONS,
4980
4961
  ...c,