jiek 1.1.13 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.cts CHANGED
@@ -1,3 +1,6 @@
1
+ import * as _rollup_plugin_terser from '@rollup/plugin-terser';
2
+ import * as rollup_plugin_swc3 from 'rollup-plugin-swc3';
3
+ import * as rollup_plugin_esbuild from 'rollup-plugin-esbuild';
1
4
  import { InputPluginOption, OutputOptions } from 'rollup';
2
5
 
3
6
  type Mapping2ROO<K extends keyof OutputOptions> = OutputOptions[K] | {
@@ -14,6 +17,7 @@ interface ConfigGenerateContext {
14
17
  conditionals: string[];
15
18
  }
16
19
  type OutputControl = boolean | ((context: ConfigGenerateContext) => boolean);
20
+ declare const BUILDER_TYPES: readonly ["esbuild", "swc"];
17
21
  interface TemplateOptions {
18
22
  /**
19
23
  * When the user configures type: module, the generated output from entry points that don't
@@ -24,6 +28,18 @@ interface TemplateOptions {
24
28
  * @default true
25
29
  */
26
30
  crossModuleConvertor?: boolean;
31
+ /**
32
+ * Auto-detect the builder from the installed dependencies.
33
+ * If the builder is not installed, it will prompt the user to install it.
34
+ * If exists multiple builders, it will fall back to the 'esbuild'.
35
+ *
36
+ * @default 'esbuild'
37
+ */
38
+ builder?: typeof BUILDER_TYPES[number] | ({
39
+ type: 'esbuild';
40
+ } & rollup_plugin_esbuild.Options) | ({
41
+ type: 'swc';
42
+ } & rollup_plugin_swc3.PluginOptions);
27
43
  output?: {
28
44
  /**
29
45
  * @default true
@@ -32,6 +48,13 @@ interface TemplateOptions {
32
48
  * When minify is set to 'only-minify', the output will direct output minified files.
33
49
  */
34
50
  minify?: boolean | 'only-minify';
51
+ minifyOptions?: typeof BUILDER_TYPES[number] | 'terser' | ({
52
+ type: 'terser';
53
+ } & _rollup_plugin_terser.Options) | ({
54
+ type: 'esbuild';
55
+ } & Parameters<typeof rollup_plugin_esbuild.minify>[0]) | ({
56
+ type: 'swc';
57
+ } & Parameters<typeof rollup_plugin_swc3.minify>[0]);
35
58
  /**
36
59
  * @default 'dist'
37
60
  */
package/dist/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import * as _rollup_plugin_terser from '@rollup/plugin-terser';
2
+ import * as rollup_plugin_swc3 from 'rollup-plugin-swc3';
3
+ import * as rollup_plugin_esbuild from 'rollup-plugin-esbuild';
1
4
  import { InputPluginOption, OutputOptions } from 'rollup';
2
5
 
3
6
  type Mapping2ROO<K extends keyof OutputOptions> = OutputOptions[K] | {
@@ -14,6 +17,7 @@ interface ConfigGenerateContext {
14
17
  conditionals: string[];
15
18
  }
16
19
  type OutputControl = boolean | ((context: ConfigGenerateContext) => boolean);
20
+ declare const BUILDER_TYPES: readonly ["esbuild", "swc"];
17
21
  interface TemplateOptions {
18
22
  /**
19
23
  * When the user configures type: module, the generated output from entry points that don't
@@ -24,6 +28,18 @@ interface TemplateOptions {
24
28
  * @default true
25
29
  */
26
30
  crossModuleConvertor?: boolean;
31
+ /**
32
+ * Auto-detect the builder from the installed dependencies.
33
+ * If the builder is not installed, it will prompt the user to install it.
34
+ * If exists multiple builders, it will fall back to the 'esbuild'.
35
+ *
36
+ * @default 'esbuild'
37
+ */
38
+ builder?: typeof BUILDER_TYPES[number] | ({
39
+ type: 'esbuild';
40
+ } & rollup_plugin_esbuild.Options) | ({
41
+ type: 'swc';
42
+ } & rollup_plugin_swc3.PluginOptions);
27
43
  output?: {
28
44
  /**
29
45
  * @default true
@@ -32,6 +48,13 @@ interface TemplateOptions {
32
48
  * When minify is set to 'only-minify', the output will direct output minified files.
33
49
  */
34
50
  minify?: boolean | 'only-minify';
51
+ minifyOptions?: typeof BUILDER_TYPES[number] | 'terser' | ({
52
+ type: 'terser';
53
+ } & _rollup_plugin_terser.Options) | ({
54
+ type: 'esbuild';
55
+ } & Parameters<typeof rollup_plugin_esbuild.minify>[0]) | ({
56
+ type: 'swc';
57
+ } & Parameters<typeof rollup_plugin_swc3.minify>[0]);
35
58
  /**
36
59
  * @default 'dist'
37
60
  */
@@ -8,11 +8,9 @@ var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
8
8
  var commonjs = require('@rollup/plugin-commonjs');
9
9
  var json = require('@rollup/plugin-json');
10
10
  var pluginNodeResolve = require('@rollup/plugin-node-resolve');
11
- var terser = require('@rollup/plugin-terser');
12
11
  var execa = require('execa');
13
12
  var require$$0 = require('util');
14
13
  var require$$0$1 = require('path');
15
- var esbuild = require('rollup-plugin-esbuild');
16
14
  var ts = require('typescript');
17
15
  var node_module = require('node:module');
18
16
  var commander = require('commander');
@@ -27,10 +25,8 @@ var fs__default = /*#__PURE__*/_interopDefault(fs);
27
25
  var path__default = /*#__PURE__*/_interopDefault(path);
28
26
  var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
29
27
  var json__default = /*#__PURE__*/_interopDefault(json);
30
- var terser__default = /*#__PURE__*/_interopDefault(terser);
31
28
  var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
32
29
  var require$$0__default$1 = /*#__PURE__*/_interopDefault(require$$0$1);
33
- var esbuild__default = /*#__PURE__*/_interopDefault(esbuild);
34
30
  var ts__default = /*#__PURE__*/_interopDefault(ts);
35
31
 
36
32
  var utils$1 = {};
@@ -4255,9 +4251,6 @@ try {
4255
4251
  type = "pnpm";
4256
4252
  } catch {
4257
4253
  }
4258
- if (type !== "") {
4259
- commander.program.option("-f, --filter <filter>", "filter packages, support fuzzy match and array. e.g. -f core,utils");
4260
- }
4261
4254
 
4262
4255
  let wd;
4263
4256
  let notWorkspace = false;
@@ -4503,16 +4496,28 @@ function externalResolver(jsonOrPath = process.cwd()) {
4503
4496
  const {
4504
4497
  JIEK_ROOT,
4505
4498
  JIEK_NAME,
4499
+ JIEK_BUILDER,
4506
4500
  JIEK_ENTRIES,
4507
4501
  JIEK_EXTERNAL,
4508
4502
  JIEK_WITHOUT_JS,
4509
4503
  JIEK_WITHOUT_DTS,
4510
4504
  JIEK_WITHOUT_MINIFY,
4505
+ JIEK_MINIFY_TYPE,
4511
4506
  JIEK_NO_CLEAN,
4512
- JIEK_ONLY_MINIFY
4507
+ JIEK_ONLY_MINIFY,
4508
+ JIEK_TSCONFIG,
4509
+ JIEK_DTSCONFIG
4513
4510
  } = process.env;
4514
- const entries = JIEK_ENTRIES?.split(",").map((e) => e.trim()).map((e) => ({ "index": "." })[e] ?? e);
4515
- const commandExternal = JIEK_EXTERNAL?.split(",").map((e) => e.trim()).map((e) => new RegExp(`^${e}$`)) ?? [];
4511
+ const resolveArrayString = (str) => {
4512
+ const arr = [
4513
+ ...new Set(
4514
+ str?.split(",").map((e) => e.trim()).filter((e) => e.length > 0) ?? []
4515
+ )
4516
+ ];
4517
+ return arr?.length ? arr : void 0;
4518
+ };
4519
+ const entries = resolveArrayString(JIEK_ENTRIES)?.map((e) => ({ "index": "." })[e] ?? e);
4520
+ const commandExternal = resolveArrayString(JIEK_EXTERNAL)?.map((e) => new RegExp(`^${e}$`));
4516
4521
  const WORKSPACE_ROOT = JIEK_ROOT ?? getWorkspaceDir.getWorkspaceDir();
4517
4522
  const COMMON_OPTIONS = {};
4518
4523
  const COMMON_PLUGINS = [
@@ -4524,6 +4529,12 @@ const WITHOUT_MINIFY = JIEK_WITHOUT_MINIFY === "true";
4524
4529
  const ONLY_MINIFY = JIEK_ONLY_MINIFY === "true";
4525
4530
  const CLEAN = JIEK_NO_CLEAN !== "true";
4526
4531
  const MINIFY_DEFAULT_VALUE = WITHOUT_MINIFY ? false : ONLY_MINIFY ? "only-minify" : true;
4532
+ const BUILDER_OPTIONS = {
4533
+ type: JIEK_BUILDER ?? "esbuild"
4534
+ };
4535
+ const MINIFY_OPTIONS = {
4536
+ type: JIEK_MINIFY_TYPE ?? "esbuild"
4537
+ };
4527
4538
  const config = loadConfig({
4528
4539
  root: WORKSPACE_ROOT
4529
4540
  }) ?? {};
@@ -4573,31 +4584,42 @@ const reveal = (obj, keys) => keys.reduce((acc, key) => {
4573
4584
  throw new Error(`key ${key} not found in exports`);
4574
4585
  return acc[key];
4575
4586
  }, obj);
4576
- const withMinify = (output, minify = build?.output?.minify ?? MINIFY_DEFAULT_VALUE) => minify === false ? [output] : minify === "only-minify" ? [{
4577
- ...output,
4578
- // TODO replace suffix when pubish to npm and the `build.output.minify` is 'only-minify'
4579
- // TODO resolve dts output file name
4580
- entryFileNames: (chunkInfo) => typeof output.entryFileNames === "function" ? output.entryFileNames(chunkInfo) : (() => {
4581
- throw new Error("entryFileNames must be a function");
4582
- })(),
4583
- plugins: [
4584
- ...output.plugins ?? [],
4585
- terser__default.default()
4586
- ]
4587
- }] : [
4588
- output,
4589
- {
4587
+ const resolveMinifyOptions = (minifyOptions) => typeof minifyOptions === "string" ? { type: minifyOptions } : minifyOptions ?? { type: "esbuild" };
4588
+ const resolveBuilderOptions = (builder) => typeof builder === "string" ? { type: builder } : builder ?? { type: "esbuild" };
4589
+ const resolvedMinifyOptions = resolveMinifyOptions(build.output?.minifyOptions ?? MINIFY_OPTIONS);
4590
+ const { type: _resolvedMinifyOptionsType, ...noTypeResolvedMinifyOptions } = resolvedMinifyOptions;
4591
+ const resolvedBuilderOptions = resolveBuilderOptions(build.builder ?? BUILDER_OPTIONS);
4592
+ const { type: _resolvedBuilderOptionsType, ...noTypeResolvedBuilderOptions } = resolvedBuilderOptions;
4593
+ const withMinify = (output, minify = build?.output?.minify ?? MINIFY_DEFAULT_VALUE) => {
4594
+ if (minify === false)
4595
+ return [output];
4596
+ 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));
4597
+ return minify === "only-minify" ? [{
4590
4598
  ...output,
4591
- entryFileNames: (chunkInfo) => typeof output.entryFileNames === "function" ? output.entryFileNames(chunkInfo).replace(/(\.[cm]?js)$/, ".min$1") : (() => {
4599
+ // TODO replace suffix when pubish to npm and the `build.output.minify` is 'only-minify'
4600
+ // TODO resolve dts output file name
4601
+ entryFileNames: (chunkInfo) => typeof output.entryFileNames === "function" ? output.entryFileNames(chunkInfo) : (() => {
4592
4602
  throw new Error("entryFileNames must be a function");
4593
4603
  })(),
4594
- file: output.file?.replace(/(\.[cm]?js)$/, ".min$1"),
4595
4604
  plugins: [
4596
4605
  ...output.plugins ?? [],
4597
- terser__default.default()
4606
+ minifyPlugin
4598
4607
  ]
4599
- }
4600
- ];
4608
+ }] : [
4609
+ output,
4610
+ {
4611
+ ...output,
4612
+ entryFileNames: (chunkInfo) => typeof output.entryFileNames === "function" ? output.entryFileNames(chunkInfo).replace(/(\.[cm]?js)$/, ".min$1") : (() => {
4613
+ throw new Error("entryFileNames must be a function");
4614
+ })(),
4615
+ file: output.file?.replace(/(\.[cm]?js)$/, ".min$1"),
4616
+ plugins: [
4617
+ ...output.plugins ?? [],
4618
+ minifyPlugin
4619
+ ]
4620
+ }
4621
+ ];
4622
+ };
4601
4623
  const generateConfigs = (context, options = {}) => {
4602
4624
  const {
4603
4625
  path: path$1,
@@ -4608,7 +4630,7 @@ const generateConfigs = (context, options = {}) => {
4608
4630
  pkgIsModule,
4609
4631
  conditionals
4610
4632
  } = context;
4611
- const external = [...inputExternal, ...options.external ?? [], ...commandExternal];
4633
+ const external = [...inputExternal, ...options.external ?? [], ...commandExternal ?? []];
4612
4634
  const isModule = conditionals.includes("import");
4613
4635
  const isCommonJS = conditionals.includes("require");
4614
4636
  const isBrowser = conditionals.includes("browser");
@@ -4616,10 +4638,13 @@ const generateConfigs = (context, options = {}) => {
4616
4638
  resolveWorkspacePath("tsconfig.json"),
4617
4639
  resolveWorkspacePath("tsconfig.dts.json")
4618
4640
  ];
4641
+ JIEK_TSCONFIG && dtsTSConfigPaths.push(resolveWorkspacePath(JIEK_TSCONFIG));
4642
+ JIEK_DTSCONFIG && dtsTSConfigPaths.push(resolveWorkspacePath(JIEK_DTSCONFIG));
4619
4643
  const buildTSConfigPaths = [
4620
4644
  ...dtsTSConfigPaths,
4621
4645
  resolveWorkspacePath("tsconfig.build.json")
4622
4646
  ];
4647
+ JIEK_TSCONFIG && buildTSConfigPaths.push(resolveWorkspacePath(JIEK_TSCONFIG));
4623
4648
  let dtsTSConfigPath;
4624
4649
  dtsTSConfigPaths.forEach((p) => {
4625
4650
  if (fs__default.default.existsSync(p) && fs__default.default.statSync(p).isFile()) {
@@ -4669,6 +4694,22 @@ const generateConfigs = (context, options = {}) => {
4669
4694
  const commonPlugins = [];
4670
4695
  if (jsOutput && !WITHOUT_JS) {
4671
4696
  const sourcemap = typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.js : options?.output?.sourcemap;
4697
+ const builder = resolvedBuilderOptions.type === "esbuild" ? import('rollup-plugin-esbuild').then(
4698
+ ({ default: esbuild }) => esbuild({
4699
+ sourceMap: sourcemap === "hidden" ? false : !!sourcemap,
4700
+ tsconfig: buildTSConfigPath,
4701
+ ...noTypeResolvedBuilderOptions
4702
+ })
4703
+ ) : import('rollup-plugin-swc3').then(
4704
+ ({ default: swc }) => swc({
4705
+ sourceMaps: typeof sourcemap === "boolean" ? sourcemap : typeof sourcemap === "undefined" ? void 0 : {
4706
+ hidden: false,
4707
+ inline: "inline"
4708
+ }[sourcemap] ?? void 0,
4709
+ tsconfig: buildTSConfigPath,
4710
+ ...noTypeResolvedBuilderOptions
4711
+ })
4712
+ );
4672
4713
  rollupOptions.push({
4673
4714
  input: inputObj,
4674
4715
  external,
@@ -4692,10 +4733,7 @@ const generateConfigs = (context, options = {}) => {
4692
4733
  minimize: true
4693
4734
  })
4694
4735
  ).catch(() => void 0),
4695
- esbuild__default.default({
4696
- sourceMap: sourcemap === "hidden" ? false : !!sourcemap,
4697
- tsconfig: buildTSConfigPath
4698
- }),
4736
+ builder,
4699
4737
  commonjs__default.default(),
4700
4738
  progress({
4701
4739
  onEvent: (event, message) => execa.sendMessage(
@@ -4752,18 +4790,20 @@ const generateConfigs = (context, options = {}) => {
4752
4790
  ]
4753
4791
  });
4754
4792
  }
4755
- rollupOptions[0].plugins = [
4756
- {
4757
- name: "jiek-plugin-watcher",
4758
- watchChange: (id) => execa.sendMessage(
4759
- {
4760
- type: "watchChange",
4761
- data: { id, name: JIEK_NAME, path: path$1, input }
4762
- }
4763
- )
4764
- },
4765
- ...rollupOptions[0].plugins
4766
- ];
4793
+ if (rollupOptions.length > 0) {
4794
+ rollupOptions[0].plugins = [
4795
+ {
4796
+ name: "jiek-plugin-watcher",
4797
+ watchChange: (id) => execa.sendMessage(
4798
+ {
4799
+ type: "watchChange",
4800
+ data: { id, name: JIEK_NAME, path: path$1, input }
4801
+ }
4802
+ )
4803
+ },
4804
+ ...rollupOptions[0].plugins
4805
+ ];
4806
+ }
4767
4807
  return rollupOptions;
4768
4808
  };
4769
4809
  function template(packageJSON) {
@@ -6,11 +6,9 @@ import { isWorkspaceDir, getWorkspaceDir } from '@jiek/utils/getWorkspaceDir';
6
6
  import commonjs from '@rollup/plugin-commonjs';
7
7
  import json from '@rollup/plugin-json';
8
8
  import { nodeResolve } from '@rollup/plugin-node-resolve';
9
- import terser from '@rollup/plugin-terser';
10
9
  import { sendMessage } from 'execa';
11
10
  import require$$0 from 'util';
12
11
  import require$$0$1 from 'path';
13
- import esbuild from 'rollup-plugin-esbuild';
14
12
  import ts from 'typescript';
15
13
  import { createRequire, builtinModules } from 'node:module';
16
14
  import { program } from 'commander';
@@ -4240,9 +4238,6 @@ try {
4240
4238
  type = "pnpm";
4241
4239
  } catch {
4242
4240
  }
4243
- if (type !== "") {
4244
- program.option("-f, --filter <filter>", "filter packages, support fuzzy match and array. e.g. -f core,utils");
4245
- }
4246
4241
 
4247
4242
  let wd;
4248
4243
  let notWorkspace = false;
@@ -4488,16 +4483,28 @@ function externalResolver(jsonOrPath = process.cwd()) {
4488
4483
  const {
4489
4484
  JIEK_ROOT,
4490
4485
  JIEK_NAME,
4486
+ JIEK_BUILDER,
4491
4487
  JIEK_ENTRIES,
4492
4488
  JIEK_EXTERNAL,
4493
4489
  JIEK_WITHOUT_JS,
4494
4490
  JIEK_WITHOUT_DTS,
4495
4491
  JIEK_WITHOUT_MINIFY,
4492
+ JIEK_MINIFY_TYPE,
4496
4493
  JIEK_NO_CLEAN,
4497
- JIEK_ONLY_MINIFY
4494
+ JIEK_ONLY_MINIFY,
4495
+ JIEK_TSCONFIG,
4496
+ JIEK_DTSCONFIG
4498
4497
  } = process.env;
4499
- const entries = JIEK_ENTRIES?.split(",").map((e) => e.trim()).map((e) => ({ "index": "." })[e] ?? e);
4500
- const commandExternal = JIEK_EXTERNAL?.split(",").map((e) => e.trim()).map((e) => new RegExp(`^${e}$`)) ?? [];
4498
+ const resolveArrayString = (str) => {
4499
+ const arr = [
4500
+ ...new Set(
4501
+ str?.split(",").map((e) => e.trim()).filter((e) => e.length > 0) ?? []
4502
+ )
4503
+ ];
4504
+ return arr?.length ? arr : void 0;
4505
+ };
4506
+ const entries = resolveArrayString(JIEK_ENTRIES)?.map((e) => ({ "index": "." })[e] ?? e);
4507
+ const commandExternal = resolveArrayString(JIEK_EXTERNAL)?.map((e) => new RegExp(`^${e}$`));
4501
4508
  const WORKSPACE_ROOT = JIEK_ROOT ?? getWorkspaceDir();
4502
4509
  const COMMON_OPTIONS = {};
4503
4510
  const COMMON_PLUGINS = [
@@ -4509,6 +4516,12 @@ const WITHOUT_MINIFY = JIEK_WITHOUT_MINIFY === "true";
4509
4516
  const ONLY_MINIFY = JIEK_ONLY_MINIFY === "true";
4510
4517
  const CLEAN = JIEK_NO_CLEAN !== "true";
4511
4518
  const MINIFY_DEFAULT_VALUE = WITHOUT_MINIFY ? false : ONLY_MINIFY ? "only-minify" : true;
4519
+ const BUILDER_OPTIONS = {
4520
+ type: JIEK_BUILDER ?? "esbuild"
4521
+ };
4522
+ const MINIFY_OPTIONS = {
4523
+ type: JIEK_MINIFY_TYPE ?? "esbuild"
4524
+ };
4512
4525
  const config = loadConfig({
4513
4526
  root: WORKSPACE_ROOT
4514
4527
  }) ?? {};
@@ -4558,31 +4571,42 @@ const reveal = (obj, keys) => keys.reduce((acc, key) => {
4558
4571
  throw new Error(`key ${key} not found in exports`);
4559
4572
  return acc[key];
4560
4573
  }, obj);
4561
- const withMinify = (output, minify = build?.output?.minify ?? MINIFY_DEFAULT_VALUE) => minify === false ? [output] : minify === "only-minify" ? [{
4562
- ...output,
4563
- // TODO replace suffix when pubish to npm and the `build.output.minify` is 'only-minify'
4564
- // TODO resolve dts output file name
4565
- entryFileNames: (chunkInfo) => typeof output.entryFileNames === "function" ? output.entryFileNames(chunkInfo) : (() => {
4566
- throw new Error("entryFileNames must be a function");
4567
- })(),
4568
- plugins: [
4569
- ...output.plugins ?? [],
4570
- terser()
4571
- ]
4572
- }] : [
4573
- output,
4574
- {
4574
+ const resolveMinifyOptions = (minifyOptions) => typeof minifyOptions === "string" ? { type: minifyOptions } : minifyOptions ?? { type: "esbuild" };
4575
+ const resolveBuilderOptions = (builder) => typeof builder === "string" ? { type: builder } : builder ?? { type: "esbuild" };
4576
+ const resolvedMinifyOptions = resolveMinifyOptions(build.output?.minifyOptions ?? MINIFY_OPTIONS);
4577
+ const { type: _resolvedMinifyOptionsType, ...noTypeResolvedMinifyOptions } = resolvedMinifyOptions;
4578
+ const resolvedBuilderOptions = resolveBuilderOptions(build.builder ?? BUILDER_OPTIONS);
4579
+ const { type: _resolvedBuilderOptionsType, ...noTypeResolvedBuilderOptions } = resolvedBuilderOptions;
4580
+ const withMinify = (output, minify = build?.output?.minify ?? MINIFY_DEFAULT_VALUE) => {
4581
+ if (minify === false)
4582
+ return [output];
4583
+ 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));
4584
+ return minify === "only-minify" ? [{
4575
4585
  ...output,
4576
- entryFileNames: (chunkInfo) => typeof output.entryFileNames === "function" ? output.entryFileNames(chunkInfo).replace(/(\.[cm]?js)$/, ".min$1") : (() => {
4586
+ // TODO replace suffix when pubish to npm and the `build.output.minify` is 'only-minify'
4587
+ // TODO resolve dts output file name
4588
+ entryFileNames: (chunkInfo) => typeof output.entryFileNames === "function" ? output.entryFileNames(chunkInfo) : (() => {
4577
4589
  throw new Error("entryFileNames must be a function");
4578
4590
  })(),
4579
- file: output.file?.replace(/(\.[cm]?js)$/, ".min$1"),
4580
4591
  plugins: [
4581
4592
  ...output.plugins ?? [],
4582
- terser()
4593
+ minifyPlugin
4583
4594
  ]
4584
- }
4585
- ];
4595
+ }] : [
4596
+ output,
4597
+ {
4598
+ ...output,
4599
+ entryFileNames: (chunkInfo) => typeof output.entryFileNames === "function" ? output.entryFileNames(chunkInfo).replace(/(\.[cm]?js)$/, ".min$1") : (() => {
4600
+ throw new Error("entryFileNames must be a function");
4601
+ })(),
4602
+ file: output.file?.replace(/(\.[cm]?js)$/, ".min$1"),
4603
+ plugins: [
4604
+ ...output.plugins ?? [],
4605
+ minifyPlugin
4606
+ ]
4607
+ }
4608
+ ];
4609
+ };
4586
4610
  const generateConfigs = (context, options = {}) => {
4587
4611
  const {
4588
4612
  path,
@@ -4593,7 +4617,7 @@ const generateConfigs = (context, options = {}) => {
4593
4617
  pkgIsModule,
4594
4618
  conditionals
4595
4619
  } = context;
4596
- const external = [...inputExternal, ...options.external ?? [], ...commandExternal];
4620
+ const external = [...inputExternal, ...options.external ?? [], ...commandExternal ?? []];
4597
4621
  const isModule = conditionals.includes("import");
4598
4622
  const isCommonJS = conditionals.includes("require");
4599
4623
  const isBrowser = conditionals.includes("browser");
@@ -4601,10 +4625,13 @@ const generateConfigs = (context, options = {}) => {
4601
4625
  resolveWorkspacePath("tsconfig.json"),
4602
4626
  resolveWorkspacePath("tsconfig.dts.json")
4603
4627
  ];
4628
+ JIEK_TSCONFIG && dtsTSConfigPaths.push(resolveWorkspacePath(JIEK_TSCONFIG));
4629
+ JIEK_DTSCONFIG && dtsTSConfigPaths.push(resolveWorkspacePath(JIEK_DTSCONFIG));
4604
4630
  const buildTSConfigPaths = [
4605
4631
  ...dtsTSConfigPaths,
4606
4632
  resolveWorkspacePath("tsconfig.build.json")
4607
4633
  ];
4634
+ JIEK_TSCONFIG && buildTSConfigPaths.push(resolveWorkspacePath(JIEK_TSCONFIG));
4608
4635
  let dtsTSConfigPath;
4609
4636
  dtsTSConfigPaths.forEach((p) => {
4610
4637
  if (fs.existsSync(p) && fs.statSync(p).isFile()) {
@@ -4654,6 +4681,22 @@ const generateConfigs = (context, options = {}) => {
4654
4681
  const commonPlugins = [];
4655
4682
  if (jsOutput && !WITHOUT_JS) {
4656
4683
  const sourcemap = typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.js : options?.output?.sourcemap;
4684
+ const builder = resolvedBuilderOptions.type === "esbuild" ? import('rollup-plugin-esbuild').then(
4685
+ ({ default: esbuild }) => esbuild({
4686
+ sourceMap: sourcemap === "hidden" ? false : !!sourcemap,
4687
+ tsconfig: buildTSConfigPath,
4688
+ ...noTypeResolvedBuilderOptions
4689
+ })
4690
+ ) : import('rollup-plugin-swc3').then(
4691
+ ({ default: swc }) => swc({
4692
+ sourceMaps: typeof sourcemap === "boolean" ? sourcemap : typeof sourcemap === "undefined" ? void 0 : {
4693
+ hidden: false,
4694
+ inline: "inline"
4695
+ }[sourcemap] ?? void 0,
4696
+ tsconfig: buildTSConfigPath,
4697
+ ...noTypeResolvedBuilderOptions
4698
+ })
4699
+ );
4657
4700
  rollupOptions.push({
4658
4701
  input: inputObj,
4659
4702
  external,
@@ -4677,10 +4720,7 @@ const generateConfigs = (context, options = {}) => {
4677
4720
  minimize: true
4678
4721
  })
4679
4722
  ).catch(() => void 0),
4680
- esbuild({
4681
- sourceMap: sourcemap === "hidden" ? false : !!sourcemap,
4682
- tsconfig: buildTSConfigPath
4683
- }),
4723
+ builder,
4684
4724
  commonjs(),
4685
4725
  progress({
4686
4726
  onEvent: (event, message) => sendMessage(
@@ -4737,18 +4777,20 @@ const generateConfigs = (context, options = {}) => {
4737
4777
  ]
4738
4778
  });
4739
4779
  }
4740
- rollupOptions[0].plugins = [
4741
- {
4742
- name: "jiek-plugin-watcher",
4743
- watchChange: (id) => sendMessage(
4744
- {
4745
- type: "watchChange",
4746
- data: { id, name: JIEK_NAME, path, input }
4747
- }
4748
- )
4749
- },
4750
- ...rollupOptions[0].plugins
4751
- ];
4780
+ if (rollupOptions.length > 0) {
4781
+ rollupOptions[0].plugins = [
4782
+ {
4783
+ name: "jiek-plugin-watcher",
4784
+ watchChange: (id) => sendMessage(
4785
+ {
4786
+ type: "watchChange",
4787
+ data: { id, name: JIEK_NAME, path, input }
4788
+ }
4789
+ )
4790
+ },
4791
+ ...rollupOptions[0].plugins
4792
+ ];
4793
+ }
4752
4794
  return rollupOptions;
4753
4795
  };
4754
4796
  function template(packageJSON) {
package/package.json CHANGED
@@ -1,11 +1,20 @@
1
1
  {
2
2
  "name": "jiek",
3
3
  "type": "module",
4
- "version": "1.1.13",
5
- "description": "YiJie's personal kits.",
4
+ "version": "2.0.1",
5
+ "description": "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.",
6
+ "author": "YiJie <yijie4188@gmail.com>",
7
+ "repository": {
8
+ "url": "nwylzw/jiek",
9
+ "directory": "packages/jiek"
10
+ },
11
+ "homepage": "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme",
12
+ "bugs": "https://github.com/NWYLZW/jiek/issues?q=is%3Aissue+is%3Aopen+jiek",
6
13
  "bin": {
7
14
  "jiek": "bin/jiek.js",
8
- "jk": "bin/jiek.js"
15
+ "jk": "bin/jiek.js",
16
+ "jiek-build": "bin/jiek-build.js",
17
+ "jb": "bin/jiek-build.js"
9
18
  },
10
19
  "files": [
11
20
  "dist",
@@ -26,6 +35,11 @@
26
35
  "require": "./dist/cli.cjs",
27
36
  "default": "./dist/cli.js"
28
37
  },
38
+ "./cli-only-build": {
39
+ "source": "./src/cli-only-build.ts",
40
+ "require": "./dist/cli-only-build.cjs",
41
+ "default": "./dist/cli-only-build.js"
42
+ },
29
43
  "./rollup": {
30
44
  "source": "./src/rollup/index.ts",
31
45
  "require": "./dist/rollup/index.cjs",
@@ -40,8 +54,6 @@
40
54
  "@rollup/plugin-commonjs": "^28.0.0",
41
55
  "@rollup/plugin-json": "^6.0.1",
42
56
  "@rollup/plugin-node-resolve": "^15.3.0",
43
- "@rollup/plugin-terser": "^0.4.4",
44
- "autoprefixer": "^10.4.16",
45
57
  "cli-progress": "^3.12.0",
46
58
  "commander": "^12.0.0",
47
59
  "detect-indent": "^6.1.0",
@@ -50,21 +62,50 @@
50
62
  "js-yaml": "^4.1.0",
51
63
  "jsonc-parser": "^3.2.1",
52
64
  "rollup": "4.13.2",
53
- "rollup-plugin-esbuild": "^6.1.0",
54
- "typescript": "^5.0.0",
55
65
  "@jiek/pkger": "^0.2.0",
56
66
  "@jiek/utils": "^0.2.3"
57
67
  },
58
- "optionalDependencies": {
68
+ "peerDependencies": {
69
+ "@rollup/plugin-terser": "^0.4.4",
59
70
  "@pnpm/filter-workspace-packages": "^7.2.13",
60
71
  "esbuild-register": "^3.5.0",
61
72
  "postcss": "^8.4.47",
62
- "rollup-plugin-postcss": "^4.0.2"
73
+ "rollup-plugin-postcss": "^4.0.2",
74
+ "rollup-plugin-esbuild": "^6.1.0",
75
+ "rollup-plugin-swc3": "^0.12.1",
76
+ "typescript": "^4.0.0||^5.0.0"
77
+ },
78
+ "peerDependenciesMeta": {
79
+ "@rollup/plugin-terser": {
80
+ "optional": true
81
+ },
82
+ "@pnpm/filter-workspace-packages": {
83
+ "optional": true
84
+ },
85
+ "esbuild-register": {
86
+ "optional": true
87
+ },
88
+ "postcss": {
89
+ "optional": true
90
+ },
91
+ "rollup-plugin-postcss": {
92
+ "optional": true
93
+ },
94
+ "rollup-plugin-esbuild": {
95
+ "optional": true
96
+ },
97
+ "rollup-plugin-swc3": {
98
+ "optional": true
99
+ },
100
+ "typescript": {
101
+ "optional": true
102
+ }
63
103
  },
64
104
  "devDependencies": {
65
105
  "@npm/types": "^1.0.2",
66
106
  "@pnpm/filter-workspace-packages": "^7.2.13",
67
107
  "@pnpm/workspace.pkgs-graph": "^2.0.15",
108
+ "@rollup/plugin-terser": "^0.4.4",
68
109
  "@types/cli-progress": "^3.11.5",
69
110
  "@types/inquirer": "^9.0.7",
70
111
  "@types/js-yaml": "^4.0.9",
@@ -73,10 +114,12 @@
73
114
  "micromatch": "^4.0.5",
74
115
  "node-sass": "^9.0.0",
75
116
  "postcss": "^8.4.47",
76
- "rollup-plugin-postcss": "^4.0.2"
117
+ "rollup-plugin-postcss": "^4.0.2",
118
+ "rollup-plugin-esbuild": "^6.1.0",
119
+ "rollup-plugin-swc3": "^0.12.1"
77
120
  },
78
121
  "scripts": {
79
- "prepublish": "jk build --noMin"
122
+ "prepublish": "jb --noMin"
80
123
  },
81
124
  "main": "./dist/index.cjs",
82
125
  "module": "./dist/index.js",
@@ -0,0 +1,7 @@
1
+ import './utils/filterSupport'
2
+ import './commands/base'
3
+ import './commands/build'
4
+
5
+ import { program } from 'commander'
6
+
7
+ program.parse(process.argv)