jiek 1.1.12 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +53 -106
- package/bin/jiek-build.js +16 -0
- package/dist/cli-only-build.cjs +716 -0
- package/dist/cli-only-build.d.cts +91 -0
- package/dist/cli-only-build.d.ts +91 -0
- package/dist/cli-only-build.js +708 -0
- package/dist/cli.cjs +219 -565
- package/dist/cli.d.cts +0 -65
- package/dist/cli.d.ts +0 -65
- package/dist/cli.js +219 -565
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/rollup/index.cjs +102 -49
- package/dist/rollup/index.js +102 -47
- package/package.json +28 -11
- package/src/cli-only-build.ts +7 -0
- package/src/cli.ts +1 -7
- package/src/commands/base.ts +13 -3
- package/src/commands/build.ts +200 -39
- package/src/commands/descriptions.ts +12 -0
- package/src/commands/meta.ts +5 -0
- package/src/rollup/base.ts +44 -0
- package/src/rollup/index.ts +127 -39
- package/src/utils/filterSupport.ts +2 -6
- package/src/rollup/plugins/globals.ts +0 -34
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
|
*/
|
@@ -41,6 +64,10 @@ interface TemplateOptions {
|
|
41
64
|
js?: OutputControl;
|
42
65
|
dts?: OutputControl;
|
43
66
|
};
|
67
|
+
/**
|
68
|
+
* Set the external dependencies of the package.
|
69
|
+
*/
|
70
|
+
external?: (string | RegExp)[];
|
44
71
|
plugins?: InputPluginOption | ((type: 'js' | 'dts', context: ConfigGenerateContext) => InputPluginOption) | {
|
45
72
|
js: InputPluginOption;
|
46
73
|
dts?: InputPluginOption;
|
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
|
*/
|
@@ -41,6 +64,10 @@ interface TemplateOptions {
|
|
41
64
|
js?: OutputControl;
|
42
65
|
dts?: OutputControl;
|
43
66
|
};
|
67
|
+
/**
|
68
|
+
* Set the external dependencies of the package.
|
69
|
+
*/
|
70
|
+
external?: (string | RegExp)[];
|
44
71
|
plugins?: InputPluginOption | ((type: 'js' | 'dts', context: ConfigGenerateContext) => InputPluginOption) | {
|
45
72
|
js: InputPluginOption;
|
46
73
|
dts?: InputPluginOption;
|
package/dist/rollup/index.cjs
CHANGED
@@ -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,13 +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,
|
4501
|
+
JIEK_EXTERNAL,
|
4507
4502
|
JIEK_WITHOUT_JS,
|
4508
4503
|
JIEK_WITHOUT_DTS,
|
4509
4504
|
JIEK_WITHOUT_MINIFY,
|
4505
|
+
JIEK_MINIFY_TYPE,
|
4510
4506
|
JIEK_NO_CLEAN,
|
4511
|
-
JIEK_ONLY_MINIFY
|
4507
|
+
JIEK_ONLY_MINIFY,
|
4508
|
+
JIEK_TSCONFIG,
|
4509
|
+
JIEK_DTSCONFIG
|
4512
4510
|
} = process.env;
|
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}$`));
|
4513
4521
|
const WORKSPACE_ROOT = JIEK_ROOT ?? getWorkspaceDir.getWorkspaceDir();
|
4514
4522
|
const COMMON_OPTIONS = {};
|
4515
4523
|
const COMMON_PLUGINS = [
|
@@ -4521,6 +4529,12 @@ const WITHOUT_MINIFY = JIEK_WITHOUT_MINIFY === "true";
|
|
4521
4529
|
const ONLY_MINIFY = JIEK_ONLY_MINIFY === "true";
|
4522
4530
|
const CLEAN = JIEK_NO_CLEAN !== "true";
|
4523
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
|
+
};
|
4524
4538
|
const config = loadConfig({
|
4525
4539
|
root: WORKSPACE_ROOT
|
4526
4540
|
}) ?? {};
|
@@ -4570,41 +4584,53 @@ const reveal = (obj, keys) => keys.reduce((acc, key) => {
|
|
4570
4584
|
throw new Error(`key ${key} not found in exports`);
|
4571
4585
|
return acc[key];
|
4572
4586
|
}, obj);
|
4573
|
-
const
|
4574
|
-
|
4575
|
-
|
4576
|
-
|
4577
|
-
|
4578
|
-
|
4579
|
-
|
4580
|
-
|
4581
|
-
|
4582
|
-
|
4583
|
-
|
4584
|
-
}] : [
|
4585
|
-
output,
|
4586
|
-
{
|
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" ? [{
|
4587
4598
|
...output,
|
4588
|
-
|
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) : (() => {
|
4589
4602
|
throw new Error("entryFileNames must be a function");
|
4590
4603
|
})(),
|
4591
|
-
file: output.file?.replace(/(\.[cm]?js)$/, ".min$1"),
|
4592
4604
|
plugins: [
|
4593
4605
|
...output.plugins ?? [],
|
4594
|
-
|
4606
|
+
minifyPlugin
|
4595
4607
|
]
|
4596
|
-
}
|
4597
|
-
|
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
|
+
};
|
4598
4623
|
const generateConfigs = (context, options = {}) => {
|
4599
4624
|
const {
|
4600
4625
|
path: path$1,
|
4601
4626
|
name,
|
4602
4627
|
input,
|
4603
4628
|
output,
|
4604
|
-
external,
|
4629
|
+
external: inputExternal,
|
4605
4630
|
pkgIsModule,
|
4606
4631
|
conditionals
|
4607
4632
|
} = context;
|
4633
|
+
const external = [...inputExternal, ...options.external ?? [], ...commandExternal ?? []];
|
4608
4634
|
const isModule = conditionals.includes("import");
|
4609
4635
|
const isCommonJS = conditionals.includes("require");
|
4610
4636
|
const isBrowser = conditionals.includes("browser");
|
@@ -4612,12 +4638,25 @@ const generateConfigs = (context, options = {}) => {
|
|
4612
4638
|
resolveWorkspacePath("tsconfig.json"),
|
4613
4639
|
resolveWorkspacePath("tsconfig.dts.json")
|
4614
4640
|
];
|
4641
|
+
JIEK_TSCONFIG && dtsTSConfigPaths.push(resolveWorkspacePath(JIEK_TSCONFIG));
|
4642
|
+
JIEK_DTSCONFIG && dtsTSConfigPaths.push(resolveWorkspacePath(JIEK_DTSCONFIG));
|
4643
|
+
const buildTSConfigPaths = [
|
4644
|
+
...dtsTSConfigPaths,
|
4645
|
+
resolveWorkspacePath("tsconfig.build.json")
|
4646
|
+
];
|
4647
|
+
JIEK_TSCONFIG && buildTSConfigPaths.push(resolveWorkspacePath(JIEK_TSCONFIG));
|
4615
4648
|
let dtsTSConfigPath;
|
4616
4649
|
dtsTSConfigPaths.forEach((p) => {
|
4617
4650
|
if (fs__default.default.existsSync(p) && fs__default.default.statSync(p).isFile()) {
|
4618
4651
|
dtsTSConfigPath = p;
|
4619
4652
|
}
|
4620
4653
|
});
|
4654
|
+
let buildTSConfigPath;
|
4655
|
+
buildTSConfigPaths.forEach((p) => {
|
4656
|
+
if (fs__default.default.existsSync(p) && fs__default.default.statSync(p).isFile()) {
|
4657
|
+
buildTSConfigPath = p;
|
4658
|
+
}
|
4659
|
+
});
|
4621
4660
|
let compilerOptions = {};
|
4622
4661
|
if (dtsTSConfigPath) {
|
4623
4662
|
const jsonCompilerOptions = getCompilerOptionsByFilePath(dtsTSConfigPath, path.resolve(input));
|
@@ -4654,6 +4693,23 @@ const generateConfigs = (context, options = {}) => {
|
|
4654
4693
|
const rollupOptions = [];
|
4655
4694
|
const commonPlugins = [];
|
4656
4695
|
if (jsOutput && !WITHOUT_JS) {
|
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
|
+
);
|
4657
4713
|
rollupOptions.push({
|
4658
4714
|
input: inputObj,
|
4659
4715
|
external,
|
@@ -4663,7 +4719,7 @@ const generateConfigs = (context, options = {}) => {
|
|
4663
4719
|
name,
|
4664
4720
|
interop: "auto",
|
4665
4721
|
entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process.cwd()}/`, "").replace(globCommonDir, pathCommonDir).replace(/(\.[cm]?)ts$/, jsOutputSuffix) : output.replace(`${jsOutdir}/`, ""),
|
4666
|
-
sourcemap
|
4722
|
+
sourcemap,
|
4667
4723
|
format: isModule ? "esm" : isCommonJS ? "cjs" : isBrowser ? "umd" : pkgIsModule ? "esm" : "cjs",
|
4668
4724
|
strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict
|
4669
4725
|
})
|
@@ -4677,9 +4733,7 @@ const generateConfigs = (context, options = {}) => {
|
|
4677
4733
|
minimize: true
|
4678
4734
|
})
|
4679
4735
|
).catch(() => void 0),
|
4680
|
-
|
4681
|
-
tsconfig: dtsTSConfigPath
|
4682
|
-
}),
|
4736
|
+
builder,
|
4683
4737
|
commonjs__default.default(),
|
4684
4738
|
progress({
|
4685
4739
|
onEvent: (event, message) => execa.sendMessage(
|
@@ -4712,7 +4766,6 @@ const generateConfigs = (context, options = {}) => {
|
|
4712
4766
|
rollupPluginDts.dts({
|
4713
4767
|
respectExternal: true,
|
4714
4768
|
compilerOptions: {
|
4715
|
-
...compilerOptions,
|
4716
4769
|
// temp directory, it not affect the output
|
4717
4770
|
// but if the user not set it and `declaration`, inputs can't generate any dts files when the input relative imports of `package.json`
|
4718
4771
|
outDir: "dist",
|
@@ -4722,7 +4775,8 @@ const generateConfigs = (context, options = {}) => {
|
|
4722
4775
|
// Expected '{', got 'type' (Note that you need plugins to import files that are not JavaScript)
|
4723
4776
|
// https://github.com/Swatinem/rollup-plugin-dts/issues/96
|
4724
4777
|
noEmit: false
|
4725
|
-
}
|
4778
|
+
},
|
4779
|
+
tsconfig: dtsTSConfigPath
|
4726
4780
|
}),
|
4727
4781
|
progress({
|
4728
4782
|
onEvent: (event, message) => execa.sendMessage(
|
@@ -4736,18 +4790,20 @@ const generateConfigs = (context, options = {}) => {
|
|
4736
4790
|
]
|
4737
4791
|
});
|
4738
4792
|
}
|
4739
|
-
rollupOptions
|
4740
|
-
|
4741
|
-
|
4742
|
-
|
4743
|
-
|
4744
|
-
|
4745
|
-
|
4746
|
-
|
4747
|
-
|
4748
|
-
|
4749
|
-
|
4750
|
-
|
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
|
+
}
|
4751
4807
|
return rollupOptions;
|
4752
4808
|
};
|
4753
4809
|
function template(packageJSON) {
|
@@ -4757,9 +4813,6 @@ function template(packageJSON) {
|
|
4757
4813
|
throw new Error("package.json name is required");
|
4758
4814
|
if (!entrypoints$1)
|
4759
4815
|
throw new Error("package.json exports is required");
|
4760
|
-
const entries = JIEK_ENTRIES?.split(",").map((e) => e.trim()).map((e) => ({
|
4761
|
-
"index": "."
|
4762
|
-
})[e] ?? e);
|
4763
4816
|
const packageName = pascalCase(name);
|
4764
4817
|
const external = externalResolver(packageJSON);
|
4765
4818
|
const [filteredResolvedEntrypoints, exports] = getExports({
|
package/dist/rollup/index.js
CHANGED
@@ -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,13 +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,
|
4488
|
+
JIEK_EXTERNAL,
|
4492
4489
|
JIEK_WITHOUT_JS,
|
4493
4490
|
JIEK_WITHOUT_DTS,
|
4494
4491
|
JIEK_WITHOUT_MINIFY,
|
4492
|
+
JIEK_MINIFY_TYPE,
|
4495
4493
|
JIEK_NO_CLEAN,
|
4496
|
-
JIEK_ONLY_MINIFY
|
4494
|
+
JIEK_ONLY_MINIFY,
|
4495
|
+
JIEK_TSCONFIG,
|
4496
|
+
JIEK_DTSCONFIG
|
4497
4497
|
} = process.env;
|
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}$`));
|
4498
4508
|
const WORKSPACE_ROOT = JIEK_ROOT ?? getWorkspaceDir();
|
4499
4509
|
const COMMON_OPTIONS = {};
|
4500
4510
|
const COMMON_PLUGINS = [
|
@@ -4506,6 +4516,12 @@ const WITHOUT_MINIFY = JIEK_WITHOUT_MINIFY === "true";
|
|
4506
4516
|
const ONLY_MINIFY = JIEK_ONLY_MINIFY === "true";
|
4507
4517
|
const CLEAN = JIEK_NO_CLEAN !== "true";
|
4508
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
|
+
};
|
4509
4525
|
const config = loadConfig({
|
4510
4526
|
root: WORKSPACE_ROOT
|
4511
4527
|
}) ?? {};
|
@@ -4555,41 +4571,53 @@ const reveal = (obj, keys) => keys.reduce((acc, key) => {
|
|
4555
4571
|
throw new Error(`key ${key} not found in exports`);
|
4556
4572
|
return acc[key];
|
4557
4573
|
}, obj);
|
4558
|
-
const
|
4559
|
-
|
4560
|
-
|
4561
|
-
|
4562
|
-
|
4563
|
-
|
4564
|
-
|
4565
|
-
|
4566
|
-
|
4567
|
-
|
4568
|
-
|
4569
|
-
}] : [
|
4570
|
-
output,
|
4571
|
-
{
|
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" ? [{
|
4572
4585
|
...output,
|
4573
|
-
|
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) : (() => {
|
4574
4589
|
throw new Error("entryFileNames must be a function");
|
4575
4590
|
})(),
|
4576
|
-
file: output.file?.replace(/(\.[cm]?js)$/, ".min$1"),
|
4577
4591
|
plugins: [
|
4578
4592
|
...output.plugins ?? [],
|
4579
|
-
|
4593
|
+
minifyPlugin
|
4580
4594
|
]
|
4581
|
-
}
|
4582
|
-
|
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
|
+
};
|
4583
4610
|
const generateConfigs = (context, options = {}) => {
|
4584
4611
|
const {
|
4585
4612
|
path,
|
4586
4613
|
name,
|
4587
4614
|
input,
|
4588
4615
|
output,
|
4589
|
-
external,
|
4616
|
+
external: inputExternal,
|
4590
4617
|
pkgIsModule,
|
4591
4618
|
conditionals
|
4592
4619
|
} = context;
|
4620
|
+
const external = [...inputExternal, ...options.external ?? [], ...commandExternal ?? []];
|
4593
4621
|
const isModule = conditionals.includes("import");
|
4594
4622
|
const isCommonJS = conditionals.includes("require");
|
4595
4623
|
const isBrowser = conditionals.includes("browser");
|
@@ -4597,12 +4625,25 @@ const generateConfigs = (context, options = {}) => {
|
|
4597
4625
|
resolveWorkspacePath("tsconfig.json"),
|
4598
4626
|
resolveWorkspacePath("tsconfig.dts.json")
|
4599
4627
|
];
|
4628
|
+
JIEK_TSCONFIG && dtsTSConfigPaths.push(resolveWorkspacePath(JIEK_TSCONFIG));
|
4629
|
+
JIEK_DTSCONFIG && dtsTSConfigPaths.push(resolveWorkspacePath(JIEK_DTSCONFIG));
|
4630
|
+
const buildTSConfigPaths = [
|
4631
|
+
...dtsTSConfigPaths,
|
4632
|
+
resolveWorkspacePath("tsconfig.build.json")
|
4633
|
+
];
|
4634
|
+
JIEK_TSCONFIG && buildTSConfigPaths.push(resolveWorkspacePath(JIEK_TSCONFIG));
|
4600
4635
|
let dtsTSConfigPath;
|
4601
4636
|
dtsTSConfigPaths.forEach((p) => {
|
4602
4637
|
if (fs.existsSync(p) && fs.statSync(p).isFile()) {
|
4603
4638
|
dtsTSConfigPath = p;
|
4604
4639
|
}
|
4605
4640
|
});
|
4641
|
+
let buildTSConfigPath;
|
4642
|
+
buildTSConfigPaths.forEach((p) => {
|
4643
|
+
if (fs.existsSync(p) && fs.statSync(p).isFile()) {
|
4644
|
+
buildTSConfigPath = p;
|
4645
|
+
}
|
4646
|
+
});
|
4606
4647
|
let compilerOptions = {};
|
4607
4648
|
if (dtsTSConfigPath) {
|
4608
4649
|
const jsonCompilerOptions = getCompilerOptionsByFilePath(dtsTSConfigPath, resolve(input));
|
@@ -4639,6 +4680,23 @@ const generateConfigs = (context, options = {}) => {
|
|
4639
4680
|
const rollupOptions = [];
|
4640
4681
|
const commonPlugins = [];
|
4641
4682
|
if (jsOutput && !WITHOUT_JS) {
|
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
|
+
);
|
4642
4700
|
rollupOptions.push({
|
4643
4701
|
input: inputObj,
|
4644
4702
|
external,
|
@@ -4648,7 +4706,7 @@ const generateConfigs = (context, options = {}) => {
|
|
4648
4706
|
name,
|
4649
4707
|
interop: "auto",
|
4650
4708
|
entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process.cwd()}/`, "").replace(globCommonDir, pathCommonDir).replace(/(\.[cm]?)ts$/, jsOutputSuffix) : output.replace(`${jsOutdir}/`, ""),
|
4651
|
-
sourcemap
|
4709
|
+
sourcemap,
|
4652
4710
|
format: isModule ? "esm" : isCommonJS ? "cjs" : isBrowser ? "umd" : pkgIsModule ? "esm" : "cjs",
|
4653
4711
|
strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict
|
4654
4712
|
})
|
@@ -4662,9 +4720,7 @@ const generateConfigs = (context, options = {}) => {
|
|
4662
4720
|
minimize: true
|
4663
4721
|
})
|
4664
4722
|
).catch(() => void 0),
|
4665
|
-
|
4666
|
-
tsconfig: dtsTSConfigPath
|
4667
|
-
}),
|
4723
|
+
builder,
|
4668
4724
|
commonjs(),
|
4669
4725
|
progress({
|
4670
4726
|
onEvent: (event, message) => sendMessage(
|
@@ -4697,7 +4753,6 @@ const generateConfigs = (context, options = {}) => {
|
|
4697
4753
|
dts({
|
4698
4754
|
respectExternal: true,
|
4699
4755
|
compilerOptions: {
|
4700
|
-
...compilerOptions,
|
4701
4756
|
// temp directory, it not affect the output
|
4702
4757
|
// but if the user not set it and `declaration`, inputs can't generate any dts files when the input relative imports of `package.json`
|
4703
4758
|
outDir: "dist",
|
@@ -4707,7 +4762,8 @@ const generateConfigs = (context, options = {}) => {
|
|
4707
4762
|
// Expected '{', got 'type' (Note that you need plugins to import files that are not JavaScript)
|
4708
4763
|
// https://github.com/Swatinem/rollup-plugin-dts/issues/96
|
4709
4764
|
noEmit: false
|
4710
|
-
}
|
4765
|
+
},
|
4766
|
+
tsconfig: dtsTSConfigPath
|
4711
4767
|
}),
|
4712
4768
|
progress({
|
4713
4769
|
onEvent: (event, message) => sendMessage(
|
@@ -4721,18 +4777,20 @@ const generateConfigs = (context, options = {}) => {
|
|
4721
4777
|
]
|
4722
4778
|
});
|
4723
4779
|
}
|
4724
|
-
rollupOptions
|
4725
|
-
|
4726
|
-
|
4727
|
-
|
4728
|
-
|
4729
|
-
|
4730
|
-
|
4731
|
-
|
4732
|
-
|
4733
|
-
|
4734
|
-
|
4735
|
-
|
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
|
+
}
|
4736
4794
|
return rollupOptions;
|
4737
4795
|
};
|
4738
4796
|
function template(packageJSON) {
|
@@ -4742,9 +4800,6 @@ function template(packageJSON) {
|
|
4742
4800
|
throw new Error("package.json name is required");
|
4743
4801
|
if (!entrypoints)
|
4744
4802
|
throw new Error("package.json exports is required");
|
4745
|
-
const entries = JIEK_ENTRIES?.split(",").map((e) => e.trim()).map((e) => ({
|
4746
|
-
"index": "."
|
4747
|
-
})[e] ?? e);
|
4748
4803
|
const packageName = pascalCase(name);
|
4749
4804
|
const external = externalResolver(packageJSON);
|
4750
4805
|
const [filteredResolvedEntrypoints, exports] = getExports({
|