jiek 2.2.1 → 2.2.3
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-only-build.cjs +242 -141
- package/dist/cli-only-build.d.cts +11 -0
- package/dist/cli-only-build.d.ts +11 -0
- package/dist/cli-only-build.js +252 -151
- package/dist/cli.cjs +6 -12
- package/dist/cli.js +6 -12
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/rollup/index.cjs +54 -35
- package/dist/rollup/index.js +54 -35
- package/package.json +9 -5
- package/src/commands/build/analyzer.ts +122 -0
- package/src/commands/build/client/analyzer.tsx +121 -0
- package/src/commands/build/client/index.ts +28 -0
- package/src/commands/build.ts +25 -153
- package/src/commands/utils/optionParser.ts +4 -0
- package/src/rollup/base.ts +11 -0
- package/src/rollup/index.ts +44 -4
- package/src/server.ts +9 -1
- package/src/utils/checkDependency.ts +22 -0
- package/src/utils/ts.ts +3 -3
package/dist/cli.js
CHANGED
@@ -16,8 +16,7 @@ import 'jiek/cli-only-build';
|
|
16
16
|
|
17
17
|
let root;
|
18
18
|
function getRoot() {
|
19
|
-
if (root)
|
20
|
-
return root;
|
19
|
+
if (root) return root;
|
21
20
|
const rootOption = process.env.JIEK_ROOT;
|
22
21
|
root = rootOption ? path.isAbsolute(rootOption) ? rootOption : path.resolve(process.cwd(), rootOption) : void 0;
|
23
22
|
return root;
|
@@ -26,8 +25,7 @@ function getRoot() {
|
|
26
25
|
let wd;
|
27
26
|
let notWorkspace = false;
|
28
27
|
function getWD() {
|
29
|
-
if (wd)
|
30
|
-
return { wd, notWorkspace };
|
28
|
+
if (wd) return { wd, notWorkspace };
|
31
29
|
const root = getRoot();
|
32
30
|
if (root !== void 0) {
|
33
31
|
const isWorkspace = isWorkspaceDir(root, type);
|
@@ -4407,8 +4405,7 @@ function loadConfig(dirOrOptions) {
|
|
4407
4405
|
default:
|
4408
4406
|
throw new Error(`unsupported config file type: ${ext}`);
|
4409
4407
|
}
|
4410
|
-
if (!module)
|
4411
|
-
throw new Error("config file is empty");
|
4408
|
+
if (!module) throw new Error("config file is empty");
|
4412
4409
|
return module.default ?? module;
|
4413
4410
|
}
|
4414
4411
|
|
@@ -4520,10 +4517,8 @@ async function prepublish({ bumper } = {}) {
|
|
4520
4517
|
)
|
4521
4518
|
);
|
4522
4519
|
for (const [key, value] of Object.entries(manifest)) {
|
4523
|
-
if (key === "version")
|
4524
|
-
|
4525
|
-
if (JSON.stringify(value) === JSON.stringify(oldJSON[key]))
|
4526
|
-
continue;
|
4520
|
+
if (key === "version") continue;
|
4521
|
+
if (JSON.stringify(value) === JSON.stringify(oldJSON[key])) continue;
|
4527
4522
|
if (key !== "exports") {
|
4528
4523
|
newJSONString = applyEdits(
|
4529
4524
|
newJSONString,
|
@@ -4562,8 +4557,7 @@ async function prepublish({ bumper } = {}) {
|
|
4562
4557
|
}
|
4563
4558
|
}
|
4564
4559
|
for (const [k, v] of Object.entries(indexPublishConfig)) {
|
4565
|
-
if (v === void 0)
|
4566
|
-
continue;
|
4560
|
+
if (v === void 0) continue;
|
4567
4561
|
newJSONString = applyEdits(
|
4568
4562
|
newJSONString,
|
4569
4563
|
modify(
|
package/dist/index.d.cts
CHANGED
@@ -40,6 +40,17 @@ interface TemplateOptions {
|
|
40
40
|
} & rollup_plugin_esbuild.Options) | ({
|
41
41
|
type: 'swc';
|
42
42
|
} & rollup_plugin_swc3.PluginOptions);
|
43
|
+
features?: {
|
44
|
+
/**
|
45
|
+
* When use esbuild type builder, it will inject `supported.import-attributes` option.
|
46
|
+
* When use swc type builder, it will inject `jsc.experimental.keepImportAttributes` option.
|
47
|
+
*
|
48
|
+
* And it will auto set the rollup output externalImportAttributes and importAttributesKey options.
|
49
|
+
*
|
50
|
+
* @default true
|
51
|
+
*/
|
52
|
+
keepImportAttributes?: boolean | 'assert';
|
53
|
+
};
|
43
54
|
output?: {
|
44
55
|
/**
|
45
56
|
* @default true
|
package/dist/index.d.ts
CHANGED
@@ -40,6 +40,17 @@ interface TemplateOptions {
|
|
40
40
|
} & rollup_plugin_esbuild.Options) | ({
|
41
41
|
type: 'swc';
|
42
42
|
} & rollup_plugin_swc3.PluginOptions);
|
43
|
+
features?: {
|
44
|
+
/**
|
45
|
+
* When use esbuild type builder, it will inject `supported.import-attributes` option.
|
46
|
+
* When use swc type builder, it will inject `jsc.experimental.keepImportAttributes` option.
|
47
|
+
*
|
48
|
+
* And it will auto set the rollup output externalImportAttributes and importAttributesKey options.
|
49
|
+
*
|
50
|
+
* @default true
|
51
|
+
*/
|
52
|
+
keepImportAttributes?: boolean | 'assert';
|
53
|
+
};
|
43
54
|
output?: {
|
44
55
|
/**
|
45
56
|
* @default true
|
package/dist/rollup/index.cjs
CHANGED
@@ -4171,8 +4171,7 @@ function bundleAnalyzer(modulesResolved) {
|
|
4171
4171
|
return {
|
4172
4172
|
name: "jiek:bundle-analyzer",
|
4173
4173
|
async closeBundle(...args) {
|
4174
|
-
if (typeof ana.closeBundle !== "function")
|
4175
|
-
return;
|
4174
|
+
if (typeof ana.closeBundle !== "function") return;
|
4176
4175
|
return ana.closeBundle?.call(this, ...args);
|
4177
4176
|
}
|
4178
4177
|
};
|
@@ -4280,8 +4279,7 @@ function getExports({
|
|
4280
4279
|
|
4281
4280
|
let root;
|
4282
4281
|
function getRoot() {
|
4283
|
-
if (root)
|
4284
|
-
return root;
|
4282
|
+
if (root) return root;
|
4285
4283
|
const rootOption = process.env.JIEK_ROOT;
|
4286
4284
|
root = rootOption ? path__default.default.isAbsolute(rootOption) ? rootOption : path__default.default.resolve(process.cwd(), rootOption) : void 0;
|
4287
4285
|
return root;
|
@@ -4298,8 +4296,7 @@ try {
|
|
4298
4296
|
let wd;
|
4299
4297
|
let notWorkspace = false;
|
4300
4298
|
function getWD() {
|
4301
|
-
if (wd)
|
4302
|
-
return { wd, notWorkspace };
|
4299
|
+
if (wd) return { wd, notWorkspace };
|
4303
4300
|
const root = getRoot();
|
4304
4301
|
if (root !== void 0) {
|
4305
4302
|
const isWorkspace = getWorkspaceDir.isWorkspaceDir(root, type);
|
@@ -4421,16 +4418,14 @@ function loadConfig(dirOrOptions) {
|
|
4421
4418
|
default:
|
4422
4419
|
throw new Error(`unsupported config file type: ${ext}`);
|
4423
4420
|
}
|
4424
|
-
if (!module)
|
4425
|
-
throw new Error("config file is empty");
|
4421
|
+
if (!module) throw new Error("config file is empty");
|
4426
4422
|
return module.default ?? module;
|
4427
4423
|
}
|
4428
4424
|
|
4429
4425
|
const recusiveListFiles = (dir) => fs__default.default.readdirSync(dir).reduce((acc, file) => {
|
4430
4426
|
const filePath = path.resolve(dir, file);
|
4431
4427
|
if (fs__default.default.statSync(filePath).isDirectory()) {
|
4432
|
-
if (filePath.endsWith("/node_modules"))
|
4433
|
-
return acc;
|
4428
|
+
if (filePath.endsWith("/node_modules")) return acc;
|
4434
4429
|
return [...acc, ...recusiveListFiles(filePath)];
|
4435
4430
|
}
|
4436
4431
|
return [...acc, filePath];
|
@@ -4443,10 +4438,9 @@ const getExtendTSConfig = (tsconfigPath) => {
|
|
4443
4438
|
const { extends: exts, ...tsconfig } = getTSConfig(tsconfigPath);
|
4444
4439
|
const resolvePaths = (paths) => paths?.map((p) => path.resolve(tsconfigPathDirname, p)) ?? [];
|
4445
4440
|
const extendsPaths = resolvePaths(
|
4446
|
-
exts ? Array.isArray(exts) ? exts : [exts] : []
|
4441
|
+
exts !== void 0 ? Array.isArray(exts) ? exts : [exts] : []
|
4447
4442
|
);
|
4448
|
-
if (extendsPaths.length === 0)
|
4449
|
-
return tsconfig;
|
4443
|
+
if (extendsPaths.length === 0) return tsconfig;
|
4450
4444
|
return extendsPaths.map(getExtendTSConfig).concat(tsconfig).reduce((acc, { compilerOptions = {}, references: _, ...curr }) => ({
|
4451
4445
|
...acc,
|
4452
4446
|
...curr,
|
@@ -4473,24 +4467,20 @@ const getCompilerOptionsByFilePath = (tsconfigPath, filePath) => {
|
|
4473
4467
|
tsconfig.include,
|
4474
4468
|
tsconfig.exclude
|
4475
4469
|
].map(resolvePaths);
|
4476
|
-
if (exclude.length > 0 && exclude.some((i) => micromatchExports.isMatch(filePath, i)))
|
4477
|
-
|
4478
|
-
if (tsconfig.files?.length === 0 && tsconfig.include?.length === 0)
|
4479
|
-
return;
|
4470
|
+
if (exclude.length > 0 && exclude.some((i) => micromatchExports.isMatch(filePath, i))) return;
|
4471
|
+
if (tsconfig.files?.length === 0 && tsconfig.include?.length === 0) return;
|
4480
4472
|
let isInclude = false;
|
4481
|
-
isInclude
|
4482
|
-
isInclude
|
4473
|
+
isInclude ||= files.length > 0 && files.includes(filePath);
|
4474
|
+
isInclude ||= include.length > 0 && include.some((i) => micromatchExports.isMatch(filePath, i));
|
4483
4475
|
if (isInclude) {
|
4484
4476
|
return tsconfig.compilerOptions ?? {};
|
4485
4477
|
} else {
|
4486
|
-
if (tsconfig.files && tsconfig.files.length > 0 || tsconfig.include && tsconfig.include.length > 0)
|
4487
|
-
return;
|
4478
|
+
if (tsconfig.files && tsconfig.files.length > 0 || tsconfig.include && tsconfig.include.length > 0) return;
|
4488
4479
|
}
|
4489
4480
|
references.reverse();
|
4490
4481
|
for (const ref of references) {
|
4491
4482
|
const compilerOptions = getCompilerOptionsByFilePath(ref, filePath);
|
4492
|
-
if (compilerOptions)
|
4493
|
-
return compilerOptions;
|
4483
|
+
if (compilerOptions) return compilerOptions;
|
4494
4484
|
}
|
4495
4485
|
return tsconfig.compilerOptions;
|
4496
4486
|
};
|
@@ -4669,10 +4659,8 @@ const resolveOutputControls = (context, output) => ({
|
|
4669
4659
|
const resolveWorkspacePath = (p) => path.resolve(WORKSPACE_ROOT, p);
|
4670
4660
|
const pascalCase = (str) => str.replace(/[@|/-](\w)/g, (_, $1) => $1.toUpperCase()).replace(/(?:^|-)(\w)/g, (_, $1) => $1.toUpperCase());
|
4671
4661
|
const reveal = (obj, keys) => keys.reduce((acc, key) => {
|
4672
|
-
if (typeof acc === "string")
|
4673
|
-
|
4674
|
-
if (!(key in acc))
|
4675
|
-
throw new Error(`key ${key} not found in exports`);
|
4662
|
+
if (typeof acc === "string") throw new Error("key not found in exports");
|
4663
|
+
if (!(key in acc)) throw new Error(`key ${key} not found in exports`);
|
4676
4664
|
return acc[key];
|
4677
4665
|
}, obj);
|
4678
4666
|
const resolveMinifyOptions = (minifyOptions) => typeof minifyOptions === "string" ? { type: minifyOptions } : minifyOptions ?? { type: "esbuild" };
|
@@ -4692,7 +4680,7 @@ const withMinify = (output, onlyOncePlugins = []) => {
|
|
4692
4680
|
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));
|
4693
4681
|
return minify === "only-minify" ? [{
|
4694
4682
|
...output,
|
4695
|
-
// TODO replace suffix when
|
4683
|
+
// TODO replace suffix when publish to npm and the `build.output.minify` is 'only-minify'
|
4696
4684
|
// TODO resolve dts output file name
|
4697
4685
|
entryFileNames: (chunkInfo) => typeof output.entryFileNames === "function" ? output.entryFileNames(chunkInfo) : (() => {
|
4698
4686
|
throw new Error("entryFileNames must be a function");
|
@@ -4799,15 +4787,39 @@ const generateConfigs = (context, options = {}) => {
|
|
4799
4787
|
const { js: jsOutput, dts: dtsOutput } = resolveOutputControls(context, build.output);
|
4800
4788
|
const rollupOptions = [];
|
4801
4789
|
const commonPlugins = [
|
4802
|
-
pluginNodeResolve.nodeResolve({
|
4790
|
+
pluginNodeResolve.nodeResolve({
|
4791
|
+
exportConditions,
|
4792
|
+
extensions: [
|
4793
|
+
".js",
|
4794
|
+
".cjs",
|
4795
|
+
".mjs",
|
4796
|
+
".jsx",
|
4797
|
+
".cjsx",
|
4798
|
+
".mjsx",
|
4799
|
+
".ts",
|
4800
|
+
".cts",
|
4801
|
+
".mts",
|
4802
|
+
".tsx",
|
4803
|
+
".ctsx",
|
4804
|
+
".mtsx"
|
4805
|
+
]
|
4806
|
+
})
|
4803
4807
|
];
|
4804
4808
|
if (jsOutput && !WITHOUT_JS) {
|
4805
4809
|
const sourcemap = typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.js : options?.output?.sourcemap;
|
4810
|
+
const features = Object.assign({
|
4811
|
+
keepImportAttributes: true
|
4812
|
+
}, build.features);
|
4806
4813
|
const builder = resolvedBuilderOptions.type === "esbuild" ? import('rollup-plugin-esbuild').then(
|
4807
4814
|
({ default: esbuild }) => esbuild({
|
4808
4815
|
sourceMap: sourcemap === "hidden" ? false : !!sourcemap,
|
4809
4816
|
tsconfig: buildTSConfigPath,
|
4810
|
-
|
4817
|
+
target: "node22",
|
4818
|
+
...noTypeResolvedBuilderOptions,
|
4819
|
+
supported: {
|
4820
|
+
"import-attributes": features.keepImportAttributes !== false,
|
4821
|
+
...resolvedBuilderOptions.supported
|
4822
|
+
}
|
4811
4823
|
})
|
4812
4824
|
) : import('rollup-plugin-swc3').then(
|
4813
4825
|
({ default: swc }) => swc({
|
@@ -4816,7 +4828,14 @@ const generateConfigs = (context, options = {}) => {
|
|
4816
4828
|
inline: "inline"
|
4817
4829
|
}[sourcemap] ?? void 0,
|
4818
4830
|
tsconfig: buildTSConfigPath,
|
4819
|
-
...noTypeResolvedBuilderOptions
|
4831
|
+
...noTypeResolvedBuilderOptions,
|
4832
|
+
jsc: {
|
4833
|
+
...resolvedBuilderOptions.jsc,
|
4834
|
+
experimental: {
|
4835
|
+
...resolvedBuilderOptions.jsc?.experimental,
|
4836
|
+
keepImportAttributes: features.keepImportAttributes !== false
|
4837
|
+
}
|
4838
|
+
}
|
4820
4839
|
})
|
4821
4840
|
);
|
4822
4841
|
const [ana, anaOutputPlugin] = bundleAnalyzer((modules) => void publishInEntry("modulesAnalyze", { modules }));
|
@@ -4835,6 +4854,8 @@ const generateConfigs = (context, options = {}) => {
|
|
4835
4854
|
sourcemap,
|
4836
4855
|
format,
|
4837
4856
|
strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict,
|
4857
|
+
externalImportAttributes: features.keepImportAttributes !== false,
|
4858
|
+
importAttributesKey: features.keepImportAttributes === false || features.keepImportAttributes === void 0 ? void 0 : features.keepImportAttributes === true ? "with" : features.keepImportAttributes,
|
4838
4859
|
plugins: [
|
4839
4860
|
isFormatEsm(format === "esm")
|
4840
4861
|
]
|
@@ -4910,10 +4931,8 @@ const generateConfigs = (context, options = {}) => {
|
|
4910
4931
|
function template(packageJSON) {
|
4911
4932
|
const { name, type, exports: entrypoints$1 } = packageJSON;
|
4912
4933
|
const pkgIsModule = type === "module";
|
4913
|
-
if (!name)
|
4914
|
-
|
4915
|
-
if (!entrypoints$1)
|
4916
|
-
throw new Error("package.json exports is required");
|
4934
|
+
if (!name) throw new Error("package.json name is required");
|
4935
|
+
if (!entrypoints$1) throw new Error("package.json exports is required");
|
4917
4936
|
const packageName = pascalCase(name);
|
4918
4937
|
const external = externalResolver(packageJSON);
|
4919
4938
|
const [filteredResolvedEntrypoints, exports] = getExports({
|
package/dist/rollup/index.js
CHANGED
@@ -4155,8 +4155,7 @@ function bundleAnalyzer(modulesResolved) {
|
|
4155
4155
|
return {
|
4156
4156
|
name: "jiek:bundle-analyzer",
|
4157
4157
|
async closeBundle(...args) {
|
4158
|
-
if (typeof ana.closeBundle !== "function")
|
4159
|
-
return;
|
4158
|
+
if (typeof ana.closeBundle !== "function") return;
|
4160
4159
|
return ana.closeBundle?.call(this, ...args);
|
4161
4160
|
}
|
4162
4161
|
};
|
@@ -4264,8 +4263,7 @@ function getExports({
|
|
4264
4263
|
|
4265
4264
|
let root;
|
4266
4265
|
function getRoot() {
|
4267
|
-
if (root)
|
4268
|
-
return root;
|
4266
|
+
if (root) return root;
|
4269
4267
|
const rootOption = process.env.JIEK_ROOT;
|
4270
4268
|
root = rootOption ? path.isAbsolute(rootOption) ? rootOption : path.resolve(process.cwd(), rootOption) : void 0;
|
4271
4269
|
return root;
|
@@ -4282,8 +4280,7 @@ try {
|
|
4282
4280
|
let wd;
|
4283
4281
|
let notWorkspace = false;
|
4284
4282
|
function getWD() {
|
4285
|
-
if (wd)
|
4286
|
-
return { wd, notWorkspace };
|
4283
|
+
if (wd) return { wd, notWorkspace };
|
4287
4284
|
const root = getRoot();
|
4288
4285
|
if (root !== void 0) {
|
4289
4286
|
const isWorkspace = isWorkspaceDir(root, type);
|
@@ -4405,16 +4402,14 @@ function loadConfig(dirOrOptions) {
|
|
4405
4402
|
default:
|
4406
4403
|
throw new Error(`unsupported config file type: ${ext}`);
|
4407
4404
|
}
|
4408
|
-
if (!module)
|
4409
|
-
throw new Error("config file is empty");
|
4405
|
+
if (!module) throw new Error("config file is empty");
|
4410
4406
|
return module.default ?? module;
|
4411
4407
|
}
|
4412
4408
|
|
4413
4409
|
const recusiveListFiles = (dir) => fs.readdirSync(dir).reduce((acc, file) => {
|
4414
4410
|
const filePath = resolve(dir, file);
|
4415
4411
|
if (fs.statSync(filePath).isDirectory()) {
|
4416
|
-
if (filePath.endsWith("/node_modules"))
|
4417
|
-
return acc;
|
4412
|
+
if (filePath.endsWith("/node_modules")) return acc;
|
4418
4413
|
return [...acc, ...recusiveListFiles(filePath)];
|
4419
4414
|
}
|
4420
4415
|
return [...acc, filePath];
|
@@ -4427,10 +4422,9 @@ const getExtendTSConfig = (tsconfigPath) => {
|
|
4427
4422
|
const { extends: exts, ...tsconfig } = getTSConfig(tsconfigPath);
|
4428
4423
|
const resolvePaths = (paths) => paths?.map((p) => resolve(tsconfigPathDirname, p)) ?? [];
|
4429
4424
|
const extendsPaths = resolvePaths(
|
4430
|
-
exts ? Array.isArray(exts) ? exts : [exts] : []
|
4425
|
+
exts !== void 0 ? Array.isArray(exts) ? exts : [exts] : []
|
4431
4426
|
);
|
4432
|
-
if (extendsPaths.length === 0)
|
4433
|
-
return tsconfig;
|
4427
|
+
if (extendsPaths.length === 0) return tsconfig;
|
4434
4428
|
return extendsPaths.map(getExtendTSConfig).concat(tsconfig).reduce((acc, { compilerOptions = {}, references: _, ...curr }) => ({
|
4435
4429
|
...acc,
|
4436
4430
|
...curr,
|
@@ -4457,24 +4451,20 @@ const getCompilerOptionsByFilePath = (tsconfigPath, filePath) => {
|
|
4457
4451
|
tsconfig.include,
|
4458
4452
|
tsconfig.exclude
|
4459
4453
|
].map(resolvePaths);
|
4460
|
-
if (exclude.length > 0 && exclude.some((i) => micromatchExports.isMatch(filePath, i)))
|
4461
|
-
|
4462
|
-
if (tsconfig.files?.length === 0 && tsconfig.include?.length === 0)
|
4463
|
-
return;
|
4454
|
+
if (exclude.length > 0 && exclude.some((i) => micromatchExports.isMatch(filePath, i))) return;
|
4455
|
+
if (tsconfig.files?.length === 0 && tsconfig.include?.length === 0) return;
|
4464
4456
|
let isInclude = false;
|
4465
|
-
isInclude
|
4466
|
-
isInclude
|
4457
|
+
isInclude ||= files.length > 0 && files.includes(filePath);
|
4458
|
+
isInclude ||= include.length > 0 && include.some((i) => micromatchExports.isMatch(filePath, i));
|
4467
4459
|
if (isInclude) {
|
4468
4460
|
return tsconfig.compilerOptions ?? {};
|
4469
4461
|
} else {
|
4470
|
-
if (tsconfig.files && tsconfig.files.length > 0 || tsconfig.include && tsconfig.include.length > 0)
|
4471
|
-
return;
|
4462
|
+
if (tsconfig.files && tsconfig.files.length > 0 || tsconfig.include && tsconfig.include.length > 0) return;
|
4472
4463
|
}
|
4473
4464
|
references.reverse();
|
4474
4465
|
for (const ref of references) {
|
4475
4466
|
const compilerOptions = getCompilerOptionsByFilePath(ref, filePath);
|
4476
|
-
if (compilerOptions)
|
4477
|
-
return compilerOptions;
|
4467
|
+
if (compilerOptions) return compilerOptions;
|
4478
4468
|
}
|
4479
4469
|
return tsconfig.compilerOptions;
|
4480
4470
|
};
|
@@ -4653,10 +4643,8 @@ const resolveOutputControls = (context, output) => ({
|
|
4653
4643
|
const resolveWorkspacePath = (p) => resolve(WORKSPACE_ROOT, p);
|
4654
4644
|
const pascalCase = (str) => str.replace(/[@|/-](\w)/g, (_, $1) => $1.toUpperCase()).replace(/(?:^|-)(\w)/g, (_, $1) => $1.toUpperCase());
|
4655
4645
|
const reveal = (obj, keys) => keys.reduce((acc, key) => {
|
4656
|
-
if (typeof acc === "string")
|
4657
|
-
|
4658
|
-
if (!(key in acc))
|
4659
|
-
throw new Error(`key ${key} not found in exports`);
|
4646
|
+
if (typeof acc === "string") throw new Error("key not found in exports");
|
4647
|
+
if (!(key in acc)) throw new Error(`key ${key} not found in exports`);
|
4660
4648
|
return acc[key];
|
4661
4649
|
}, obj);
|
4662
4650
|
const resolveMinifyOptions = (minifyOptions) => typeof minifyOptions === "string" ? { type: minifyOptions } : minifyOptions ?? { type: "esbuild" };
|
@@ -4676,7 +4664,7 @@ const withMinify = (output, onlyOncePlugins = []) => {
|
|
4676
4664
|
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));
|
4677
4665
|
return minify === "only-minify" ? [{
|
4678
4666
|
...output,
|
4679
|
-
// TODO replace suffix when
|
4667
|
+
// TODO replace suffix when publish to npm and the `build.output.minify` is 'only-minify'
|
4680
4668
|
// TODO resolve dts output file name
|
4681
4669
|
entryFileNames: (chunkInfo) => typeof output.entryFileNames === "function" ? output.entryFileNames(chunkInfo) : (() => {
|
4682
4670
|
throw new Error("entryFileNames must be a function");
|
@@ -4783,15 +4771,39 @@ const generateConfigs = (context, options = {}) => {
|
|
4783
4771
|
const { js: jsOutput, dts: dtsOutput } = resolveOutputControls(context, build.output);
|
4784
4772
|
const rollupOptions = [];
|
4785
4773
|
const commonPlugins = [
|
4786
|
-
nodeResolve({
|
4774
|
+
nodeResolve({
|
4775
|
+
exportConditions,
|
4776
|
+
extensions: [
|
4777
|
+
".js",
|
4778
|
+
".cjs",
|
4779
|
+
".mjs",
|
4780
|
+
".jsx",
|
4781
|
+
".cjsx",
|
4782
|
+
".mjsx",
|
4783
|
+
".ts",
|
4784
|
+
".cts",
|
4785
|
+
".mts",
|
4786
|
+
".tsx",
|
4787
|
+
".ctsx",
|
4788
|
+
".mtsx"
|
4789
|
+
]
|
4790
|
+
})
|
4787
4791
|
];
|
4788
4792
|
if (jsOutput && !WITHOUT_JS) {
|
4789
4793
|
const sourcemap = typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.js : options?.output?.sourcemap;
|
4794
|
+
const features = Object.assign({
|
4795
|
+
keepImportAttributes: true
|
4796
|
+
}, build.features);
|
4790
4797
|
const builder = resolvedBuilderOptions.type === "esbuild" ? import('rollup-plugin-esbuild').then(
|
4791
4798
|
({ default: esbuild }) => esbuild({
|
4792
4799
|
sourceMap: sourcemap === "hidden" ? false : !!sourcemap,
|
4793
4800
|
tsconfig: buildTSConfigPath,
|
4794
|
-
|
4801
|
+
target: "node22",
|
4802
|
+
...noTypeResolvedBuilderOptions,
|
4803
|
+
supported: {
|
4804
|
+
"import-attributes": features.keepImportAttributes !== false,
|
4805
|
+
...resolvedBuilderOptions.supported
|
4806
|
+
}
|
4795
4807
|
})
|
4796
4808
|
) : import('rollup-plugin-swc3').then(
|
4797
4809
|
({ default: swc }) => swc({
|
@@ -4800,7 +4812,14 @@ const generateConfigs = (context, options = {}) => {
|
|
4800
4812
|
inline: "inline"
|
4801
4813
|
}[sourcemap] ?? void 0,
|
4802
4814
|
tsconfig: buildTSConfigPath,
|
4803
|
-
...noTypeResolvedBuilderOptions
|
4815
|
+
...noTypeResolvedBuilderOptions,
|
4816
|
+
jsc: {
|
4817
|
+
...resolvedBuilderOptions.jsc,
|
4818
|
+
experimental: {
|
4819
|
+
...resolvedBuilderOptions.jsc?.experimental,
|
4820
|
+
keepImportAttributes: features.keepImportAttributes !== false
|
4821
|
+
}
|
4822
|
+
}
|
4804
4823
|
})
|
4805
4824
|
);
|
4806
4825
|
const [ana, anaOutputPlugin] = bundleAnalyzer((modules) => void publishInEntry("modulesAnalyze", { modules }));
|
@@ -4819,6 +4838,8 @@ const generateConfigs = (context, options = {}) => {
|
|
4819
4838
|
sourcemap,
|
4820
4839
|
format,
|
4821
4840
|
strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict,
|
4841
|
+
externalImportAttributes: features.keepImportAttributes !== false,
|
4842
|
+
importAttributesKey: features.keepImportAttributes === false || features.keepImportAttributes === void 0 ? void 0 : features.keepImportAttributes === true ? "with" : features.keepImportAttributes,
|
4822
4843
|
plugins: [
|
4823
4844
|
isFormatEsm(format === "esm")
|
4824
4845
|
]
|
@@ -4894,10 +4915,8 @@ const generateConfigs = (context, options = {}) => {
|
|
4894
4915
|
function template(packageJSON) {
|
4895
4916
|
const { name, type, exports: entrypoints } = packageJSON;
|
4896
4917
|
const pkgIsModule = type === "module";
|
4897
|
-
if (!name)
|
4898
|
-
|
4899
|
-
if (!entrypoints)
|
4900
|
-
throw new Error("package.json exports is required");
|
4918
|
+
if (!name) throw new Error("package.json name is required");
|
4919
|
+
if (!entrypoints) throw new Error("package.json exports is required");
|
4901
4920
|
const packageName = pascalCase(name);
|
4902
4921
|
const external = externalResolver(packageJSON);
|
4903
4922
|
const [filteredResolvedEntrypoints, exports] = getExports({
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "jiek",
|
3
3
|
"type": "module",
|
4
|
-
"version": "2.2.
|
4
|
+
"version": "2.2.3",
|
5
5
|
"description": "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.",
|
6
6
|
"author": "YiJie <yijie4188@gmail.com>",
|
7
7
|
"homepage": "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme",
|
@@ -48,7 +48,11 @@
|
|
48
48
|
}
|
49
49
|
},
|
50
50
|
"imports": {
|
51
|
-
"#~/*":
|
51
|
+
"#~/*": [
|
52
|
+
"./src/*",
|
53
|
+
"./src/*/index.ts",
|
54
|
+
"./src/*/index.tsx"
|
55
|
+
]
|
52
56
|
},
|
53
57
|
"bin": {
|
54
58
|
"jiek": "bin/jiek.js",
|
@@ -65,7 +69,7 @@
|
|
65
69
|
"rollup-plugin-postcss": "^4.0.2",
|
66
70
|
"rollup-plugin-swc3": "^0.12.1",
|
67
71
|
"typescript": "^4.0.0||^5.0.0",
|
68
|
-
"vite-bundle-analyzer": "
|
72
|
+
"vite-bundle-analyzer": "0.16.0-beta.1"
|
69
73
|
},
|
70
74
|
"dependencies": {
|
71
75
|
"@inquirer/prompts": "^7.1.0",
|
@@ -83,8 +87,8 @@
|
|
83
87
|
"jsonc-parser": "^3.2.1",
|
84
88
|
"koa": "^2.15.3",
|
85
89
|
"rollup": "^4.0.0",
|
86
|
-
"@jiek/
|
87
|
-
"@jiek/
|
90
|
+
"@jiek/pkger": "^0.2.1",
|
91
|
+
"@jiek/utils": "^0.2.3"
|
88
92
|
},
|
89
93
|
"peerDependenciesMeta": {
|
90
94
|
"@pnpm/filter-workspace-packages": {
|
@@ -0,0 +1,122 @@
|
|
1
|
+
import type { Command } from 'commander'
|
2
|
+
|
3
|
+
import { CLIENT_CUSTOM_RENDER_SCRIPT } from '#~/commands/build/client/index.ts'
|
4
|
+
import { parseBoolean } from '#~/commands/utils/optionParser.ts'
|
5
|
+
import type { Module } from '#~/rollup/bundle-analyzer.ts'
|
6
|
+
import type { createServer } from '#~/server.ts'
|
7
|
+
import { checkDependency } from '#~/utils/checkDependency.ts'
|
8
|
+
import { existsSync, mkdirSync, statSync, writeFileSync } from 'node:fs'
|
9
|
+
import path from 'node:path'
|
10
|
+
|
11
|
+
export interface AnalyzerBuildOptions {
|
12
|
+
ana?: boolean
|
13
|
+
/**
|
14
|
+
* @default '.jk-analyses'
|
15
|
+
*/
|
16
|
+
'ana.dir': string
|
17
|
+
/**
|
18
|
+
* @default 'server'
|
19
|
+
*/
|
20
|
+
'ana.mode': string
|
21
|
+
'ana.open'?: boolean
|
22
|
+
/**
|
23
|
+
* @default 'parsed'
|
24
|
+
*/
|
25
|
+
'ana.size': string
|
26
|
+
}
|
27
|
+
|
28
|
+
export const registerAnalyzerCommandOptions = (command: Command) =>
|
29
|
+
command
|
30
|
+
.option('--ana', 'Enable the bundle analyzer.', parseBoolean)
|
31
|
+
.option('--ana.dir <DIR>', 'The directory of the bundle analyzer.', '.jk-analyses')
|
32
|
+
.option(
|
33
|
+
'--ana.mode <MODE>',
|
34
|
+
'The mode of the bundle analyzer, support "static", "json" and "server".',
|
35
|
+
'server'
|
36
|
+
)
|
37
|
+
.option('--ana.open', 'Open the bundle analyzer in the browser.', parseBoolean)
|
38
|
+
.option(
|
39
|
+
'--ana.size <SIZE>',
|
40
|
+
'The default size of the bundle analyzer, support "stat", "parsed" and "gzip".',
|
41
|
+
'parsed'
|
42
|
+
)
|
43
|
+
|
44
|
+
export const useAnalyzer = async (options: AnalyzerBuildOptions, server?: ReturnType<typeof createServer>) => {
|
45
|
+
const modules: Module[] = []
|
46
|
+
let bundleAnalyzerModule: typeof import('vite-bundle-analyzer') | undefined
|
47
|
+
const analyzer = options.ana
|
48
|
+
? {
|
49
|
+
dir: options['ana.dir'],
|
50
|
+
mode: options['ana.mode'],
|
51
|
+
open: options['ana.open'],
|
52
|
+
size: options['ana.size']
|
53
|
+
}
|
54
|
+
: undefined
|
55
|
+
if (
|
56
|
+
options.ana
|
57
|
+
&& ![
|
58
|
+
'stat',
|
59
|
+
'parsed',
|
60
|
+
'gzip'
|
61
|
+
].includes(analyzer?.size ?? '')
|
62
|
+
) {
|
63
|
+
throw new Error('The value of `ana.size` must be "stat", "parsed" or "gzip"')
|
64
|
+
}
|
65
|
+
|
66
|
+
if (analyzer) {
|
67
|
+
await checkDependency('vite-bundle-analyzer')
|
68
|
+
bundleAnalyzerModule = await import('vite-bundle-analyzer')
|
69
|
+
}
|
70
|
+
|
71
|
+
const refreshAnalyzer = async (cwd: string, applyModules: typeof modules) => {
|
72
|
+
if (!(analyzer && server && bundleAnalyzerModule)) return
|
73
|
+
|
74
|
+
if (analyzer.mode === 'json') {
|
75
|
+
const anaDir = path.resolve(cwd, analyzer.dir)
|
76
|
+
if (!existsSync(anaDir)) {
|
77
|
+
mkdirSync(anaDir, { recursive: true })
|
78
|
+
}
|
79
|
+
const gitIgnorePath = path.resolve(anaDir, '.gitignore')
|
80
|
+
if (!existsSync(gitIgnorePath)) {
|
81
|
+
writeFileSync(gitIgnorePath, '*\n!.gitignore\n')
|
82
|
+
}
|
83
|
+
const npmIgnorePath = path.resolve(anaDir, '.npmignore')
|
84
|
+
if (!existsSync(npmIgnorePath)) {
|
85
|
+
writeFileSync(npmIgnorePath, '*\n')
|
86
|
+
}
|
87
|
+
if (!statSync(anaDir).isDirectory()) {
|
88
|
+
throw new Error(`The directory '${anaDir}' is not a directory.`)
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
const { renderView, injectHTMLTag } = bundleAnalyzerModule
|
93
|
+
applyModules.forEach(m => {
|
94
|
+
const index = modules.findIndex(({ filename }) => filename === m.filename)
|
95
|
+
if (index === -1) {
|
96
|
+
modules.push(m)
|
97
|
+
} else {
|
98
|
+
modules[index] = m
|
99
|
+
}
|
100
|
+
})
|
101
|
+
let html = await renderView(modules, {
|
102
|
+
title: `Jiek Analyzer`,
|
103
|
+
mode: analyzer.size as 'stat' | 'parsed' | 'gzip'
|
104
|
+
})
|
105
|
+
html = injectHTMLTag({
|
106
|
+
html,
|
107
|
+
injectTo: 'body',
|
108
|
+
descriptors: [
|
109
|
+
{ kind: 'script', text: CLIENT_CUSTOM_RENDER_SCRIPT }
|
110
|
+
]
|
111
|
+
})
|
112
|
+
void server.renderTo('/ana', html)
|
113
|
+
}
|
114
|
+
|
115
|
+
return {
|
116
|
+
modules,
|
117
|
+
refreshAnalyzer,
|
118
|
+
ANALYZER_ENV: {
|
119
|
+
JIEK_ANALYZER: analyzer ? JSON.stringify(analyzer) : undefined
|
120
|
+
}
|
121
|
+
}
|
122
|
+
}
|