jiek 2.1.10 → 2.1.12

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.
@@ -2,6 +2,7 @@
2
2
 
3
3
  var fs = require('node:fs');
4
4
  var path = require('node:path');
5
+ var process$1 = require('node:process');
5
6
  var entrypoints = require('@jiek/pkger/entrypoints');
6
7
  var rollupPluginDts = require('@jiek/rollup-plugin-dts');
7
8
  var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
@@ -15,19 +16,23 @@ var ts = require('typescript');
15
16
  var node_module = require('node:module');
16
17
  var commander = require('commander');
17
18
  var jsYaml = require('js-yaml');
18
- require('@pnpm/filter-workspace-packages');
19
19
  var jsoncParser = require('jsonc-parser');
20
+ var inject = require('@rollup/plugin-inject');
21
+ var replace = require('@rollup/plugin-replace');
20
22
 
21
23
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
22
24
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
23
25
 
24
26
  var fs__default = /*#__PURE__*/_interopDefault(fs);
25
27
  var path__default = /*#__PURE__*/_interopDefault(path);
28
+ var process__default = /*#__PURE__*/_interopDefault(process$1);
26
29
  var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
27
30
  var json__default = /*#__PURE__*/_interopDefault(json);
28
31
  var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
29
32
  var require$$0__default$1 = /*#__PURE__*/_interopDefault(require$$0$1);
30
33
  var ts__default = /*#__PURE__*/_interopDefault(ts);
34
+ var inject__default = /*#__PURE__*/_interopDefault(inject);
35
+ var replace__default = /*#__PURE__*/_interopDefault(replace);
31
36
 
32
37
  var utils$1 = {};
33
38
 
@@ -4135,16 +4140,6 @@ function requireMicromatch () {
4135
4140
 
4136
4141
  var micromatchExports = requireMicromatch();
4137
4142
 
4138
- const recusiveListFiles = (dir) => fs__default.default.readdirSync(dir).reduce((acc, file) => {
4139
- const filePath = path.resolve(dir, file);
4140
- if (fs__default.default.statSync(filePath).isDirectory()) {
4141
- if (filePath.endsWith("/node_modules"))
4142
- return acc;
4143
- return [...acc, ...recusiveListFiles(filePath)];
4144
- }
4145
- return [...acc, filePath];
4146
- }, []);
4147
-
4148
4143
  const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4149
4144
  const {
4150
4145
  JIEK_OUT_DIR
@@ -4247,7 +4242,7 @@ function getRoot() {
4247
4242
 
4248
4243
  let type = "";
4249
4244
  try {
4250
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('rollup/index.cjs', document.baseURI).href)));
4245
+ const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('rollup/index.cjs', document.baseURI).href)));
4251
4246
  require$1.resolve("@pnpm/filter-workspace-packages");
4252
4247
  type = "pnpm";
4253
4248
  } catch {
@@ -4278,7 +4273,7 @@ function getWD() {
4278
4273
  return { wd, notWorkspace };
4279
4274
  }
4280
4275
 
4281
- const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('rollup/index.cjs', document.baseURI).href)));
4276
+ const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('rollup/index.cjs', document.baseURI).href)));
4282
4277
  function packageIsExist(name) {
4283
4278
  try {
4284
4279
  require$2.resolve(name);
@@ -4301,7 +4296,7 @@ for (const register of registers) {
4301
4296
  }
4302
4297
  }
4303
4298
 
4304
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('rollup/index.cjs', document.baseURI).href)));
4299
+ const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('rollup/index.cjs', document.baseURI).href)));
4305
4300
  let configName = "jiek.config";
4306
4301
  function getConfigPath(root, dir) {
4307
4302
  const isSupportTsLoader = !!tsRegisterName;
@@ -4384,6 +4379,16 @@ function loadConfig(dirOrOptions) {
4384
4379
  return module.default ?? module;
4385
4380
  }
4386
4381
 
4382
+ const recusiveListFiles = (dir) => fs__default.default.readdirSync(dir).reduce((acc, file) => {
4383
+ const filePath = path.resolve(dir, file);
4384
+ if (fs__default.default.statSync(filePath).isDirectory()) {
4385
+ if (filePath.endsWith("/node_modules"))
4386
+ return acc;
4387
+ return [...acc, ...recusiveListFiles(filePath)];
4388
+ }
4389
+ return [...acc, filePath];
4390
+ }, []);
4391
+
4387
4392
  const getTSConfig = (p) => !fs__default.default.existsSync(p) || !fs__default.default.statSync(p).isFile() ? {} : jsoncParser.parse(fs__default.default.readFileSync(p, "utf-8"), [], { allowTrailingComma: true, allowEmptyContent: true });
4388
4393
  const getExtendTSConfig = (tsconfigPath) => {
4389
4394
  tsconfigPath = path.resolve(tsconfigPath);
@@ -4443,6 +4448,44 @@ const getCompilerOptionsByFilePath = (tsconfigPath, filePath) => {
4443
4448
  return tsconfig.compilerOptions;
4444
4449
  };
4445
4450
 
4451
+ const virtualModuleName = "jiek:create-require";
4452
+ const isEsmVariableName = `IS_ESM${Math.random().toString(36).slice(2)}`;
4453
+ const INSERT_STR = `
4454
+ import { createRequire } from 'node:module'
4455
+
4456
+ export default (
4457
+ ${isEsmVariableName}
4458
+ ? /* @__PURE__ */ createRequire(import.meta.url)
4459
+ : require
4460
+ )
4461
+ `.trim();
4462
+ var createRequire = () => ({
4463
+ ...inject__default.default({
4464
+ require: virtualModuleName
4465
+ }),
4466
+ name: "create-require",
4467
+ resolveId: (source) => source === virtualModuleName ? source : null,
4468
+ load: (id) => {
4469
+ if (id !== virtualModuleName) {
4470
+ return null;
4471
+ }
4472
+ return INSERT_STR;
4473
+ }
4474
+ });
4475
+ const isFormatEsm = (isEsm) => {
4476
+ const handler = replace__default.default({
4477
+ [isEsmVariableName]: isEsm
4478
+ }).renderChunk;
4479
+ return {
4480
+ name: "create-require-insert-format",
4481
+ // Pick out renderChunk because it's used as an output plugin
4482
+ renderChunk: {
4483
+ order: "pre",
4484
+ handler: typeof handler === "function" ? handler : handler.handler
4485
+ }
4486
+ };
4487
+ };
4488
+
4446
4489
  var progress = (options = {}) => {
4447
4490
  const { onEvent } = options;
4448
4491
  return {
@@ -4495,6 +4538,7 @@ function externalResolver(jsonOrPath = process.cwd()) {
4495
4538
  }
4496
4539
 
4497
4540
  const {
4541
+ JIEK_ANALYZER,
4498
4542
  JIEK_ROOT,
4499
4543
  JIEK_NAME,
4500
4544
  JIEK_BUILDER,
@@ -4508,7 +4552,7 @@ const {
4508
4552
  JIEK_ONLY_MINIFY,
4509
4553
  JIEK_TSCONFIG,
4510
4554
  JIEK_DTSCONFIG
4511
- } = process.env;
4555
+ } = process__default.default.env;
4512
4556
  const resolveArrayString = (str) => {
4513
4557
  const arr = [
4514
4558
  ...new Set(
@@ -4517,6 +4561,7 @@ const resolveArrayString = (str) => {
4517
4561
  ];
4518
4562
  return arr?.length ? arr : void 0;
4519
4563
  };
4564
+ const ANALYZER = JIEK_ANALYZER && JSON.parse(JIEK_ANALYZER);
4520
4565
  const entries = resolveArrayString(JIEK_ENTRIES)?.map((e) => ({ "index": "." })[e] ?? e);
4521
4566
  const commandExternal = resolveArrayString(JIEK_EXTERNAL)?.map((e) => new RegExp(`^${e}$`));
4522
4567
  const WORKSPACE_ROOT = JIEK_ROOT ?? getWorkspaceDir.getWorkspaceDir();
@@ -4592,9 +4637,20 @@ const { type: _resolvedMinifyOptionsType, ...noTypeResolvedMinifyOptions } = res
4592
4637
  const resolvedBuilderOptions = resolveBuilderOptions(build.builder ?? BUILDER_OPTIONS);
4593
4638
  const { type: _resolvedBuilderOptionsType, ...noTypeResolvedBuilderOptions } = resolvedBuilderOptions;
4594
4639
  const withMinify = (output, minify = build?.output?.minify ?? MINIFY_DEFAULT_VALUE) => {
4595
- if (minify === false)
4640
+ output.plugins = output.plugins ?? [];
4641
+ const onlyOncePlugins = [
4642
+ // adapter(analyzer({
4643
+ // analyzerMode: 'server',
4644
+ // analyzerPort: 8888,
4645
+ // reportTitle: 'Bundle Analysis'
4646
+ // }))
4647
+ ];
4648
+ if (minify === false) {
4649
+ output.plugins.push(...onlyOncePlugins);
4596
4650
  return [output];
4651
+ }
4597
4652
  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));
4653
+ const notOnlyOncePlugins = output.plugins;
4598
4654
  return minify === "only-minify" ? [{
4599
4655
  ...output,
4600
4656
  // TODO replace suffix when pubish to npm and the `build.output.minify` is 'only-minify'
@@ -4603,7 +4659,7 @@ const withMinify = (output, minify = build?.output?.minify ?? MINIFY_DEFAULT_VAL
4603
4659
  throw new Error("entryFileNames must be a function");
4604
4660
  })(),
4605
4661
  plugins: [
4606
- ...output.plugins ?? [],
4662
+ ...notOnlyOncePlugins,
4607
4663
  minifyPlugin
4608
4664
  ]
4609
4665
  }] : [
@@ -4615,7 +4671,7 @@ const withMinify = (output, minify = build?.output?.minify ?? MINIFY_DEFAULT_VAL
4615
4671
  })(),
4616
4672
  file: output.file?.replace(/(\.[cm]?js)$/, ".min$1"),
4617
4673
  plugins: [
4618
- ...output.plugins ?? [],
4674
+ ...notOnlyOncePlugins,
4619
4675
  minifyPlugin
4620
4676
  ]
4621
4677
  }
@@ -4682,7 +4738,7 @@ const generateConfigs = (context, options = {}) => {
4682
4738
  'input should not include "**", please read the [documentation](https://nodejs.org/api/packages.html#subpath-patterns).'
4683
4739
  );
4684
4740
  }
4685
- const inputObj = !input.includes("*") ? input : recusiveListFiles(process.cwd()).filter((p) => /(?<!\.d)\.[cm]?tsx?$/.test(p)).map((p) => path.relative(process.cwd(), p)).filter((p) => micromatchExports.isMatch(p, input.slice(2)));
4741
+ const inputObj = !input.includes("*") ? input : recusiveListFiles(process__default.default.cwd()).filter((p) => /(?<!\.d)\.[cm]?tsx?$/.test(p)).map((p) => path.relative(process__default.default.cwd(), p)).filter((p) => micromatchExports.isMatch(p, input.slice(2)));
4686
4742
  const globCommonDir = input.includes("*") ? input.split("*")[0].replace("./", "") : "";
4687
4743
  const pathCommonDir = path$1.includes("*") ? path$1.split("*")[0].replace("./", "") : "";
4688
4744
  if (globCommonDir.length > 0 && pathCommonDir.length === 0 || globCommonDir.length === 0 && pathCommonDir.length > 0) {
@@ -4713,6 +4769,55 @@ const generateConfigs = (context, options = {}) => {
4713
4769
  ...noTypeResolvedBuilderOptions
4714
4770
  })
4715
4771
  );
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;
4716
4821
  rollupOptions.push({
4717
4822
  input: inputObj,
4718
4823
  external,
@@ -4721,10 +4826,13 @@ const generateConfigs = (context, options = {}) => {
4721
4826
  dir: jsOutdir,
4722
4827
  name,
4723
4828
  interop: "auto",
4724
- entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process.cwd()}/`, "").replace(globCommonDir, pathCommonDir).replace(/(\.[cm]?)ts$/, jsOutputSuffix) : output.replace(`${jsOutdir}/`, ""),
4829
+ entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process__default.default.cwd()}/`, "").replace(globCommonDir, pathCommonDir).replace(/(\.[cm]?)ts$/, jsOutputSuffix) : output.replace(`${jsOutdir}/`, ""),
4725
4830
  sourcemap,
4726
4831
  format: isModule ? "esm" : isCommonJS ? "cjs" : isBrowser ? "umd" : pkgIsModule ? "esm" : "cjs",
4727
- strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict
4832
+ strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict,
4833
+ plugins: [
4834
+ isFormatEsm(isModule)
4835
+ ]
4728
4836
  })
4729
4837
  ],
4730
4838
  plugins: [
@@ -4735,10 +4843,12 @@ const generateConfigs = (context, options = {}) => {
4735
4843
  minimize: true
4736
4844
  })
4737
4845
  ).catch(() => void 0),
4738
- builder,
4739
4846
  commonjs__default.default(),
4847
+ createRequire(),
4848
+ builder,
4849
+ ana,
4740
4850
  progress({
4741
- onEvent: (event, message) => execa.sendMessage(
4851
+ onEvent: (event, message) => void execa.sendMessage(
4742
4852
  {
4743
4853
  ...throughEventProps,
4744
4854
  data: { ...throughEventProps.data, event, message, tags: ["js"] }
@@ -4757,7 +4867,7 @@ const generateConfigs = (context, options = {}) => {
4757
4867
  {
4758
4868
  dir: dtsOutdir,
4759
4869
  sourcemap: typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.dts : options?.output?.sourcemap,
4760
- entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process.cwd()}/`, "").replace(globCommonDir, pathCommonDir).replace(/(\.[cm]?)ts$/, tsOutputSuffix) : output.replace(`${jsOutdir}/`, "").replace(/(\.[cm]?)js$/, tsOutputSuffix),
4870
+ entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process__default.default.cwd()}/`, "").replace(globCommonDir, pathCommonDir).replace(/(\.[cm]?)ts$/, tsOutputSuffix) : output.replace(`${jsOutdir}/`, "").replace(/(\.[cm]?)js$/, tsOutputSuffix),
4761
4871
  strict: typeof options?.output?.strict === "object" ? options.output.strict.dts : options?.output?.strict
4762
4872
  }
4763
4873
  ],
@@ -4780,7 +4890,7 @@ const generateConfigs = (context, options = {}) => {
4780
4890
  tsconfig: dtsTSConfigPath
4781
4891
  }),
4782
4892
  progress({
4783
- onEvent: (event, message) => execa.sendMessage(
4893
+ onEvent: (event, message) => void execa.sendMessage(
4784
4894
  {
4785
4895
  ...throughEventProps,
4786
4896
  data: { ...throughEventProps.data, event, message, tags: ["dts"] }
@@ -4795,7 +4905,7 @@ const generateConfigs = (context, options = {}) => {
4795
4905
  rollupOptions[0].plugins = [
4796
4906
  {
4797
4907
  name: "jiek-plugin-watcher",
4798
- watchChange: (id) => execa.sendMessage(
4908
+ watchChange: (id) => void execa.sendMessage(
4799
4909
  {
4800
4910
  type: "watchChange",
4801
4911
  data: { id, name: JIEK_NAME, path: path$1, input }
@@ -4872,7 +4982,7 @@ function template(packageJSON) {
4872
4982
  }
4873
4983
  })
4874
4984
  );
4875
- execa.sendMessage(
4985
+ void execa.sendMessage(
4876
4986
  {
4877
4987
  type: "init",
4878
4988
  data: {
@@ -1,5 +1,6 @@
1
1
  import fs from 'node:fs';
2
- import path, { resolve, isAbsolute, relative, dirname, extname } from 'node:path';
2
+ import path, { isAbsolute, relative, resolve, dirname, extname, join } from 'node:path';
3
+ import process$1 from 'node:process';
3
4
  import { resolveEntrypoints, filterLeafs, DEFAULT_SKIP_VALUES, entrypoints2Exports, getAllLeafs } from '@jiek/pkger/entrypoints';
4
5
  import { dts } from '@jiek/rollup-plugin-dts';
5
6
  import { isWorkspaceDir, getWorkspaceDir } from '@jiek/utils/getWorkspaceDir';
@@ -10,11 +11,12 @@ import { sendMessage } from 'execa';
10
11
  import require$$0 from 'util';
11
12
  import require$$0$1 from 'path';
12
13
  import ts from 'typescript';
13
- import { createRequire, builtinModules } from 'node:module';
14
+ import { createRequire as createRequire$1, builtinModules } from 'node:module';
14
15
  import { program } from 'commander';
15
16
  import { load } from 'js-yaml';
16
- import '@pnpm/filter-workspace-packages';
17
17
  import { parse } from 'jsonc-parser';
18
+ import inject from '@rollup/plugin-inject';
19
+ import replace from '@rollup/plugin-replace';
18
20
 
19
21
  var utils$1 = {};
20
22
 
@@ -4122,16 +4124,6 @@ function requireMicromatch () {
4122
4124
 
4123
4125
  var micromatchExports = requireMicromatch();
4124
4126
 
4125
- const recusiveListFiles = (dir) => fs.readdirSync(dir).reduce((acc, file) => {
4126
- const filePath = resolve(dir, file);
4127
- if (fs.statSync(filePath).isDirectory()) {
4128
- if (filePath.endsWith("/node_modules"))
4129
- return acc;
4130
- return [...acc, ...recusiveListFiles(filePath)];
4131
- }
4132
- return [...acc, filePath];
4133
- }, []);
4134
-
4135
4127
  const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4136
4128
  const {
4137
4129
  JIEK_OUT_DIR
@@ -4234,7 +4226,7 @@ function getRoot() {
4234
4226
 
4235
4227
  let type = "";
4236
4228
  try {
4237
- const require = createRequire(import.meta.url);
4229
+ const require = createRequire$1(import.meta.url);
4238
4230
  require.resolve("@pnpm/filter-workspace-packages");
4239
4231
  type = "pnpm";
4240
4232
  } catch {
@@ -4265,7 +4257,7 @@ function getWD() {
4265
4257
  return { wd, notWorkspace };
4266
4258
  }
4267
4259
 
4268
- const require$1 = createRequire(import.meta.url);
4260
+ const require$1 = createRequire$1(import.meta.url);
4269
4261
  function packageIsExist(name) {
4270
4262
  try {
4271
4263
  require$1.resolve(name);
@@ -4288,7 +4280,7 @@ for (const register of registers) {
4288
4280
  }
4289
4281
  }
4290
4282
 
4291
- const require = createRequire(import.meta.url);
4283
+ const require = createRequire$1(import.meta.url);
4292
4284
  let configName = "jiek.config";
4293
4285
  function getConfigPath(root, dir) {
4294
4286
  const isSupportTsLoader = !!tsRegisterName;
@@ -4371,6 +4363,16 @@ function loadConfig(dirOrOptions) {
4371
4363
  return module.default ?? module;
4372
4364
  }
4373
4365
 
4366
+ const recusiveListFiles = (dir) => fs.readdirSync(dir).reduce((acc, file) => {
4367
+ const filePath = resolve(dir, file);
4368
+ if (fs.statSync(filePath).isDirectory()) {
4369
+ if (filePath.endsWith("/node_modules"))
4370
+ return acc;
4371
+ return [...acc, ...recusiveListFiles(filePath)];
4372
+ }
4373
+ return [...acc, filePath];
4374
+ }, []);
4375
+
4374
4376
  const getTSConfig = (p) => !fs.existsSync(p) || !fs.statSync(p).isFile() ? {} : parse(fs.readFileSync(p, "utf-8"), [], { allowTrailingComma: true, allowEmptyContent: true });
4375
4377
  const getExtendTSConfig = (tsconfigPath) => {
4376
4378
  tsconfigPath = resolve(tsconfigPath);
@@ -4430,6 +4432,44 @@ const getCompilerOptionsByFilePath = (tsconfigPath, filePath) => {
4430
4432
  return tsconfig.compilerOptions;
4431
4433
  };
4432
4434
 
4435
+ const virtualModuleName = "jiek:create-require";
4436
+ const isEsmVariableName = `IS_ESM${Math.random().toString(36).slice(2)}`;
4437
+ const INSERT_STR = `
4438
+ import { createRequire } from 'node:module'
4439
+
4440
+ export default (
4441
+ ${isEsmVariableName}
4442
+ ? /* @__PURE__ */ createRequire(import.meta.url)
4443
+ : require
4444
+ )
4445
+ `.trim();
4446
+ var createRequire = () => ({
4447
+ ...inject({
4448
+ require: virtualModuleName
4449
+ }),
4450
+ name: "create-require",
4451
+ resolveId: (source) => source === virtualModuleName ? source : null,
4452
+ load: (id) => {
4453
+ if (id !== virtualModuleName) {
4454
+ return null;
4455
+ }
4456
+ return INSERT_STR;
4457
+ }
4458
+ });
4459
+ const isFormatEsm = (isEsm) => {
4460
+ const handler = replace({
4461
+ [isEsmVariableName]: isEsm
4462
+ }).renderChunk;
4463
+ return {
4464
+ name: "create-require-insert-format",
4465
+ // Pick out renderChunk because it's used as an output plugin
4466
+ renderChunk: {
4467
+ order: "pre",
4468
+ handler: typeof handler === "function" ? handler : handler.handler
4469
+ }
4470
+ };
4471
+ };
4472
+
4433
4473
  var progress = (options = {}) => {
4434
4474
  const { onEvent } = options;
4435
4475
  return {
@@ -4482,6 +4522,7 @@ function externalResolver(jsonOrPath = process.cwd()) {
4482
4522
  }
4483
4523
 
4484
4524
  const {
4525
+ JIEK_ANALYZER,
4485
4526
  JIEK_ROOT,
4486
4527
  JIEK_NAME,
4487
4528
  JIEK_BUILDER,
@@ -4495,7 +4536,7 @@ const {
4495
4536
  JIEK_ONLY_MINIFY,
4496
4537
  JIEK_TSCONFIG,
4497
4538
  JIEK_DTSCONFIG
4498
- } = process.env;
4539
+ } = process$1.env;
4499
4540
  const resolveArrayString = (str) => {
4500
4541
  const arr = [
4501
4542
  ...new Set(
@@ -4504,6 +4545,7 @@ const resolveArrayString = (str) => {
4504
4545
  ];
4505
4546
  return arr?.length ? arr : void 0;
4506
4547
  };
4548
+ const ANALYZER = JIEK_ANALYZER && JSON.parse(JIEK_ANALYZER);
4507
4549
  const entries = resolveArrayString(JIEK_ENTRIES)?.map((e) => ({ "index": "." })[e] ?? e);
4508
4550
  const commandExternal = resolveArrayString(JIEK_EXTERNAL)?.map((e) => new RegExp(`^${e}$`));
4509
4551
  const WORKSPACE_ROOT = JIEK_ROOT ?? getWorkspaceDir();
@@ -4579,9 +4621,20 @@ const { type: _resolvedMinifyOptionsType, ...noTypeResolvedMinifyOptions } = res
4579
4621
  const resolvedBuilderOptions = resolveBuilderOptions(build.builder ?? BUILDER_OPTIONS);
4580
4622
  const { type: _resolvedBuilderOptionsType, ...noTypeResolvedBuilderOptions } = resolvedBuilderOptions;
4581
4623
  const withMinify = (output, minify = build?.output?.minify ?? MINIFY_DEFAULT_VALUE) => {
4582
- if (minify === false)
4624
+ output.plugins = output.plugins ?? [];
4625
+ const onlyOncePlugins = [
4626
+ // adapter(analyzer({
4627
+ // analyzerMode: 'server',
4628
+ // analyzerPort: 8888,
4629
+ // reportTitle: 'Bundle Analysis'
4630
+ // }))
4631
+ ];
4632
+ if (minify === false) {
4633
+ output.plugins.push(...onlyOncePlugins);
4583
4634
  return [output];
4635
+ }
4584
4636
  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));
4637
+ const notOnlyOncePlugins = output.plugins;
4585
4638
  return minify === "only-minify" ? [{
4586
4639
  ...output,
4587
4640
  // TODO replace suffix when pubish to npm and the `build.output.minify` is 'only-minify'
@@ -4590,7 +4643,7 @@ const withMinify = (output, minify = build?.output?.minify ?? MINIFY_DEFAULT_VAL
4590
4643
  throw new Error("entryFileNames must be a function");
4591
4644
  })(),
4592
4645
  plugins: [
4593
- ...output.plugins ?? [],
4646
+ ...notOnlyOncePlugins,
4594
4647
  minifyPlugin
4595
4648
  ]
4596
4649
  }] : [
@@ -4602,7 +4655,7 @@ const withMinify = (output, minify = build?.output?.minify ?? MINIFY_DEFAULT_VAL
4602
4655
  })(),
4603
4656
  file: output.file?.replace(/(\.[cm]?js)$/, ".min$1"),
4604
4657
  plugins: [
4605
- ...output.plugins ?? [],
4658
+ ...notOnlyOncePlugins,
4606
4659
  minifyPlugin
4607
4660
  ]
4608
4661
  }
@@ -4669,7 +4722,7 @@ const generateConfigs = (context, options = {}) => {
4669
4722
  'input should not include "**", please read the [documentation](https://nodejs.org/api/packages.html#subpath-patterns).'
4670
4723
  );
4671
4724
  }
4672
- const inputObj = !input.includes("*") ? input : recusiveListFiles(process.cwd()).filter((p) => /(?<!\.d)\.[cm]?tsx?$/.test(p)).map((p) => relative(process.cwd(), p)).filter((p) => micromatchExports.isMatch(p, input.slice(2)));
4725
+ const inputObj = !input.includes("*") ? input : recusiveListFiles(process$1.cwd()).filter((p) => /(?<!\.d)\.[cm]?tsx?$/.test(p)).map((p) => relative(process$1.cwd(), p)).filter((p) => micromatchExports.isMatch(p, input.slice(2)));
4673
4726
  const globCommonDir = input.includes("*") ? input.split("*")[0].replace("./", "") : "";
4674
4727
  const pathCommonDir = path.includes("*") ? path.split("*")[0].replace("./", "") : "";
4675
4728
  if (globCommonDir.length > 0 && pathCommonDir.length === 0 || globCommonDir.length === 0 && pathCommonDir.length > 0) {
@@ -4700,6 +4753,55 @@ const generateConfigs = (context, options = {}) => {
4700
4753
  ...noTypeResolvedBuilderOptions
4701
4754
  })
4702
4755
  );
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;
4703
4805
  rollupOptions.push({
4704
4806
  input: inputObj,
4705
4807
  external,
@@ -4708,10 +4810,13 @@ const generateConfigs = (context, options = {}) => {
4708
4810
  dir: jsOutdir,
4709
4811
  name,
4710
4812
  interop: "auto",
4711
- entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process.cwd()}/`, "").replace(globCommonDir, pathCommonDir).replace(/(\.[cm]?)ts$/, jsOutputSuffix) : output.replace(`${jsOutdir}/`, ""),
4813
+ entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process$1.cwd()}/`, "").replace(globCommonDir, pathCommonDir).replace(/(\.[cm]?)ts$/, jsOutputSuffix) : output.replace(`${jsOutdir}/`, ""),
4712
4814
  sourcemap,
4713
4815
  format: isModule ? "esm" : isCommonJS ? "cjs" : isBrowser ? "umd" : pkgIsModule ? "esm" : "cjs",
4714
- strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict
4816
+ strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict,
4817
+ plugins: [
4818
+ isFormatEsm(isModule)
4819
+ ]
4715
4820
  })
4716
4821
  ],
4717
4822
  plugins: [
@@ -4722,10 +4827,12 @@ const generateConfigs = (context, options = {}) => {
4722
4827
  minimize: true
4723
4828
  })
4724
4829
  ).catch(() => void 0),
4725
- builder,
4726
4830
  commonjs(),
4831
+ createRequire(),
4832
+ builder,
4833
+ ana,
4727
4834
  progress({
4728
- onEvent: (event, message) => sendMessage(
4835
+ onEvent: (event, message) => void sendMessage(
4729
4836
  {
4730
4837
  ...throughEventProps,
4731
4838
  data: { ...throughEventProps.data, event, message, tags: ["js"] }
@@ -4744,7 +4851,7 @@ const generateConfigs = (context, options = {}) => {
4744
4851
  {
4745
4852
  dir: dtsOutdir,
4746
4853
  sourcemap: typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.dts : options?.output?.sourcemap,
4747
- entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process.cwd()}/`, "").replace(globCommonDir, pathCommonDir).replace(/(\.[cm]?)ts$/, tsOutputSuffix) : output.replace(`${jsOutdir}/`, "").replace(/(\.[cm]?)js$/, tsOutputSuffix),
4854
+ entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process$1.cwd()}/`, "").replace(globCommonDir, pathCommonDir).replace(/(\.[cm]?)ts$/, tsOutputSuffix) : output.replace(`${jsOutdir}/`, "").replace(/(\.[cm]?)js$/, tsOutputSuffix),
4748
4855
  strict: typeof options?.output?.strict === "object" ? options.output.strict.dts : options?.output?.strict
4749
4856
  }
4750
4857
  ],
@@ -4767,7 +4874,7 @@ const generateConfigs = (context, options = {}) => {
4767
4874
  tsconfig: dtsTSConfigPath
4768
4875
  }),
4769
4876
  progress({
4770
- onEvent: (event, message) => sendMessage(
4877
+ onEvent: (event, message) => void sendMessage(
4771
4878
  {
4772
4879
  ...throughEventProps,
4773
4880
  data: { ...throughEventProps.data, event, message, tags: ["dts"] }
@@ -4782,7 +4889,7 @@ const generateConfigs = (context, options = {}) => {
4782
4889
  rollupOptions[0].plugins = [
4783
4890
  {
4784
4891
  name: "jiek-plugin-watcher",
4785
- watchChange: (id) => sendMessage(
4892
+ watchChange: (id) => void sendMessage(
4786
4893
  {
4787
4894
  type: "watchChange",
4788
4895
  data: { id, name: JIEK_NAME, path, input }
@@ -4859,7 +4966,7 @@ function template(packageJSON) {
4859
4966
  }
4860
4967
  })
4861
4968
  );
4862
- sendMessage(
4969
+ void sendMessage(
4863
4970
  {
4864
4971
  type: "init",
4865
4972
  data: {