@longzai-intelligence-builder/core 0.0.6 → 0.0.8
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/factories/create-config.factory.d.ts +3 -3
- package/dist/factories/create-config.factory.d.ts.map +1 -1
- package/dist/factories/create-config.factory.js +24 -8
- package/dist/factories/create-config.factory.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts +5 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +3 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/merge-array-config.utils.d.ts +8 -1
- package/dist/utils/merge-array-config.utils.d.ts.map +1 -1
- package/dist/utils/merge-array-config.utils.js +1 -1
- package/dist/utils/merge-array-config.utils.js.map +1 -1
- package/dist/utils/read-tsbuildinfo.utils.d.ts +10 -1
- package/dist/utils/read-tsbuildinfo.utils.d.ts.map +1 -1
- package/dist/utils/read-tsbuildinfo.utils.js +37 -1
- package/dist/utils/read-tsbuildinfo.utils.js.map +1 -1
- package/dist/utils/resolve-external.utils.d.ts +76 -0
- package/dist/utils/resolve-external.utils.d.ts.map +1 -0
- package/dist/utils/resolve-external.utils.js +179 -0
- package/dist/utils/resolve-external.utils.js.map +1 -0
- package/package.json +5 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BuilderConfig, ConfigOptions } from '../core/types';
|
|
2
2
|
/**
|
|
3
3
|
* 获取基础配置的函数类型
|
|
4
4
|
*/
|
|
@@ -9,8 +9,8 @@ type GetBaseConfigFn = () => Partial<BuilderConfig>;
|
|
|
9
9
|
* 接收一个获取基础配置的函数,返回 defineConfig 和 defineBundleConfig。
|
|
10
10
|
* esm 和 dual 各自提供不同的 getBaseConfig 即可复用此逻辑。
|
|
11
11
|
*
|
|
12
|
-
* - defineConfig: 库包,生成 dts
|
|
13
|
-
* - defineBundleConfig: CLI/应用,不生成 dts
|
|
12
|
+
* - defineConfig: 库包,生成 dts,外部化 dependencies + peerDependencies(skipNodeModulesBundle: true)
|
|
13
|
+
* - defineBundleConfig: CLI/应用,不生成 dts,打包全部依赖(skipNodeModulesBundle: false)
|
|
14
14
|
*
|
|
15
15
|
* @param getBaseConfig - 获取基础配置的函数
|
|
16
16
|
* @returns 包含 defineConfig 和 defineBundleConfig 的对象
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-config.factory.d.ts","sourceRoot":"","sources":["../../src/factories/create-config.factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAe,MAAM,cAAc,CAAC;AAI9E;;GAEG;AACH,KAAK,eAAe,GAAG,MAAM,OAAO,CAAC,aAAa,CAAC,CAAC;AAEpD;;;;;;;;;;;GAWG;AACH,iBAAS,mBAAmB,CAAC,aAAa,EAAE,eAAe;
|
|
1
|
+
{"version":3,"file":"create-config.factory.d.ts","sourceRoot":"","sources":["../../src/factories/create-config.factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAe,MAAM,cAAc,CAAC;AAI9E;;GAEG;AACH,KAAK,eAAe,GAAG,MAAM,OAAO,CAAC,aAAa,CAAC,CAAC;AAEpD;;;;;;;;;;;GAWG;AACH,iBAAS,mBAAmB,CAAC,aAAa,EAAE,eAAe;6BAgD1B,aAAa,KAAQ,aAAa;mCAmC5B,aAAa,KAAQ,aAAa;EAiBxE;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -5,8 +5,8 @@ import { mergeArrayConfig, mergeExternalConfig, resolveTsconfig } from '../utils
|
|
|
5
5
|
* 接收一个获取基础配置的函数,返回 defineConfig 和 defineBundleConfig。
|
|
6
6
|
* esm 和 dual 各自提供不同的 getBaseConfig 即可复用此逻辑。
|
|
7
7
|
*
|
|
8
|
-
* - defineConfig: 库包,生成 dts
|
|
9
|
-
* - defineBundleConfig: CLI/应用,不生成 dts
|
|
8
|
+
* - defineConfig: 库包,生成 dts,外部化 dependencies + peerDependencies(skipNodeModulesBundle: true)
|
|
9
|
+
* - defineBundleConfig: CLI/应用,不生成 dts,打包全部依赖(skipNodeModulesBundle: false)
|
|
10
10
|
*
|
|
11
11
|
* @param getBaseConfig - 获取基础配置的函数
|
|
12
12
|
* @returns 包含 defineConfig 和 defineBundleConfig 的对象
|
|
@@ -20,9 +20,12 @@ function createConfigFactory(getBaseConfig) {
|
|
|
20
20
|
*/
|
|
21
21
|
function buildConfig(options = {}) {
|
|
22
22
|
/**
|
|
23
|
-
* 从配置选项中解构出 entry 和其余选项
|
|
23
|
+
* 从配置选项中解构出 entry、deps 和其余选项
|
|
24
|
+
*
|
|
25
|
+
* deps 单独拎出,不进 restOptions,避免 defineConfig 合并时
|
|
26
|
+
* 把消费方传入的 deps 当作 base 再 merge 一次导致重复合并。
|
|
24
27
|
*/
|
|
25
|
-
const { entry = 'src/index.ts', ...restOptions } = options;
|
|
28
|
+
const { entry = 'src/index.ts', deps: userDeps, ...restOptions } = options;
|
|
26
29
|
/**
|
|
27
30
|
* 构建入口配置对象
|
|
28
31
|
*/
|
|
@@ -36,13 +39,17 @@ function createConfigFactory(getBaseConfig) {
|
|
|
36
39
|
entry: entryConfig,
|
|
37
40
|
tsconfig,
|
|
38
41
|
...restOptions,
|
|
42
|
+
deps: userDeps,
|
|
39
43
|
};
|
|
40
44
|
}
|
|
41
45
|
/**
|
|
42
46
|
* 定义库包构建配置
|
|
43
47
|
*
|
|
44
|
-
* 默认行为:生成 dts,外部化 dependencies
|
|
45
|
-
*
|
|
48
|
+
* 默认行为:生成 dts,外部化 dependencies + peerDependencies(含 workspace 与第三方依赖)
|
|
49
|
+
*
|
|
50
|
+
* external 派生由 runBuild 调用 resolveExternal 完成,默认读取当前包 package.json 的
|
|
51
|
+
* dependencies + peerDependencies 作为外部化基底,与 tsdown 默认行为一致。
|
|
52
|
+
* 支持通过 deps.alwaysBundle(强制打包)/ deps.neverBundle(补充外部化)覆盖。
|
|
46
53
|
*
|
|
47
54
|
* @param options - 配置选项
|
|
48
55
|
* @returns 完整的构建配置
|
|
@@ -52,12 +59,21 @@ function createConfigFactory(getBaseConfig) {
|
|
|
52
59
|
* 构建基础配置
|
|
53
60
|
*/
|
|
54
61
|
const config = buildConfig(options);
|
|
62
|
+
/**
|
|
63
|
+
* 预设 deps 作为合并 base,消费方 options.deps 作为 override
|
|
64
|
+
*
|
|
65
|
+
* 注意:不能 merge config.deps 与 options.deps——buildConfig 已把 options.deps
|
|
66
|
+
* 赋给 config.deps,二者相同,合并会重复杂值。
|
|
67
|
+
*/
|
|
68
|
+
const baseDeps = getBaseConfig().deps;
|
|
55
69
|
return {
|
|
56
70
|
...config,
|
|
57
71
|
deps: {
|
|
72
|
+
...baseDeps,
|
|
58
73
|
...config.deps,
|
|
59
|
-
|
|
60
|
-
|
|
74
|
+
skipNodeModulesBundle: true,
|
|
75
|
+
neverBundle: mergeExternalConfig(baseDeps?.neverBundle, options.deps?.neverBundle),
|
|
76
|
+
alwaysBundle: mergeArrayConfig(baseDeps?.alwaysBundle, options.deps?.alwaysBundle),
|
|
61
77
|
},
|
|
62
78
|
};
|
|
63
79
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-config.factory.js","sourceRoot":"","sources":["../../src/factories/create-config.factory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"create-config.factory.js","sourceRoot":"","sources":["../../src/factories/create-config.factory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAO1F;;;;;;;;;;;GAWG;AACH,SAAS,mBAAmB,CAAC,aAA8B;IACzD;;;;;OAKG;IACH,SAAS,WAAW,CAAC,OAAO,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M,CAAC,IAAI;gBACd,qBAAqB,EAAE,KAAK;aAC7B;SACF,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,CAAC;AAC9C,CAAC;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC","sourcesContent":["import type { BuilderConfig, ConfigOptions, EntryConfig } from '@/core/types';\n\nimport { mergeArrayConfig, mergeExternalConfig, resolveTsconfig } from '@/utils/index.js';\n\n/**\n * 获取基础配置的函数类型\n */\ntype GetBaseConfigFn = () => Partial<BuilderConfig>;\n\n/**\n * 通用配置创建工厂\n *\n * 接收一个获取基础配置的函数,返回 defineConfig 和 defineBundleConfig。\n * esm 和 dual 各自提供不同的 getBaseConfig 即可复用此逻辑。\n *\n * - defineConfig: 库包,生成 dts,外部化 dependencies + peerDependencies(skipNodeModulesBundle: true)\n * - defineBundleConfig: CLI/应用,不生成 dts,打包全部依赖(skipNodeModulesBundle: false)\n *\n * @param getBaseConfig - 获取基础配置的函数\n * @returns 包含 defineConfig 和 defineBundleConfig 的对象\n */\nfunction createConfigFactory(getBaseConfig: GetBaseConfigFn) {\n /**\n * 从 ConfigOptions 中提取 entry 并构建完整配置\n *\n * @param options - 配置选项\n * @returns 完整的构建配置\n */\n function buildConfig(options: ConfigOptions = {}): BuilderConfig {\n /**\n * 从配置选项中解构出 entry、deps 和其余选项\n *\n * deps 单独拎出,不进 restOptions,避免 defineConfig 合并时\n * 把消费方传入的 deps 当作 base 再 merge 一次导致重复合并。\n */\n const { entry = 'src/index.ts', deps: userDeps, ...restOptions } = options;\n\n /**\n * 构建入口配置对象\n */\n const entryConfig: EntryConfig | undefined =\n typeof entry === 'string' ? { index: entry } : entry;\n\n /**\n * 解析 tsconfig 配置\n */\n const tsconfig = resolveTsconfig();\n\n return {\n ...getBaseConfig(),\n entry: entryConfig,\n tsconfig,\n ...restOptions,\n deps: userDeps,\n };\n }\n\n /**\n * 定义库包构建配置\n *\n * 默认行为:生成 dts,外部化 dependencies + peerDependencies(含 workspace 与第三方依赖)\n *\n * external 派生由 runBuild 调用 resolveExternal 完成,默认读取当前包 package.json 的\n * dependencies + peerDependencies 作为外部化基底,与 tsdown 默认行为一致。\n * 支持通过 deps.alwaysBundle(强制打包)/ deps.neverBundle(补充外部化)覆盖。\n *\n * @param options - 配置选项\n * @returns 完整的构建配置\n */\n function defineConfig(options: ConfigOptions = {}): BuilderConfig {\n /**\n * 构建基础配置\n */\n const config = buildConfig(options);\n\n /**\n * 预设 deps 作为合并 base,消费方 options.deps 作为 override\n *\n * 注意:不能 merge config.deps 与 options.deps——buildConfig 已把 options.deps\n * 赋给 config.deps,二者相同,合并会重复杂值。\n */\n const baseDeps = getBaseConfig().deps;\n\n return {\n ...config,\n deps: {\n ...baseDeps,\n ...config.deps,\n skipNodeModulesBundle: true,\n neverBundle: mergeExternalConfig(baseDeps?.neverBundle, options.deps?.neverBundle),\n alwaysBundle: mergeArrayConfig(baseDeps?.alwaysBundle, options.deps?.alwaysBundle),\n },\n };\n }\n\n /**\n * 定义 CLI/应用构建配置\n *\n * - 不生成 dts\n * - 自动 bundle 所有 node_modules 依赖(skipNodeModulesBundle: false)\n *\n * @param options - 配置选项\n * @returns 完整的构建配置\n */\n function defineBundleConfig(options: ConfigOptions = {}): BuilderConfig {\n /**\n * 构建基础配置\n */\n const config = buildConfig(options);\n\n return {\n ...config,\n dts: false,\n deps: {\n ...config.deps,\n skipNodeModulesBundle: false,\n },\n };\n }\n\n return { defineConfig, defineBundleConfig };\n}\n\nexport { createConfigFactory };\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export type { BuildFormat, BuilderConfig, ConfigOptions, DepsOptions, DtsOptions, EntryConfig, PresetDefinition } from './core/types.js';
|
|
2
|
-
export { resolveTsconfig, readTsBuildInfoFile, mergeArrayConfig, normalizeExternal, mergeExternalConfig, } from './utils/index.js';
|
|
1
|
+
export type { BuildFormat, BuilderConfig, ConfigOptions, DepsOptions, DtsOptions, EntryConfig, PresetDefinition, } from './core/types.js';
|
|
2
|
+
export { resolveTsconfig, readTsBuildInfoFile, isTsConfigLike, mergeArrayConfig, normalizeExternal, mergeExternalConfig, resolveExternal, readPackageDependencies, matchAlwaysBundle, collectExternal, isPackageJsonLike, } from './utils/index.js';
|
|
3
|
+
export type { TsConfigLike, PackageJsonLike } from './utils/index.js';
|
|
3
4
|
export { createConfigFactory } from './factories/index.js';
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,WAAW,EACX,aAAa,EACb,aAAa,EACb,WAAW,EACX,UAAU,EACV,WAAW,EACX,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { resolveTsconfig, readTsBuildInfoFile, mergeArrayConfig, normalizeExternal, mergeExternalConfig, } from './utils/index.js';
|
|
1
|
+
export { resolveTsconfig, readTsBuildInfoFile, isTsConfigLike, mergeArrayConfig, normalizeExternal, mergeExternalConfig, resolveExternal, readPackageDependencies, matchAlwaysBundle, collectExternal, isPackageJsonLike, } from './utils/index.js';
|
|
2
2
|
export { createConfigFactory } from './factories/index.js';
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAI1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["export type {\n BuildFormat,\n BuilderConfig,\n ConfigOptions,\n DepsOptions,\n DtsOptions,\n EntryConfig,\n PresetDefinition,\n} from './core/types.js';\n\nexport {\n resolveTsconfig,\n readTsBuildInfoFile,\n isTsConfigLike,\n mergeArrayConfig,\n normalizeExternal,\n mergeExternalConfig,\n resolveExternal,\n readPackageDependencies,\n matchAlwaysBundle,\n collectExternal,\n isPackageJsonLike,\n} from './utils/index.js';\n\nexport type { TsConfigLike, PackageJsonLike } from './utils/index.js';\n\nexport { createConfigFactory } from './factories/index.js';\n"]}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export { resolveTsconfig } from './resolve-tsconfig.utils.js';
|
|
2
|
-
export { readTsBuildInfoFile } from './read-tsbuildinfo.utils.js';
|
|
3
|
-
export {
|
|
2
|
+
export { readTsBuildInfoFile, isTsConfigLike } from './read-tsbuildinfo.utils.js';
|
|
3
|
+
export type { TsConfigLike } from './read-tsbuildinfo.utils.js';
|
|
4
|
+
export { mergeArrayConfig, normalizeArrayConfig } from './merge-array-config.utils.js';
|
|
4
5
|
export { mergeExternalConfig, normalizeExternal } from './merge-external-config.utils.js';
|
|
6
|
+
export { resolveExternal, readPackageDependencies, matchAlwaysBundle, collectExternal, isPackageJsonLike, } from './resolve-external.utils.js';
|
|
7
|
+
export type { PackageJsonLike } from './resolve-external.utils.js';
|
|
5
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAElF,YAAY,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAEvF,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAE1F,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,GAClB,MAAM,6BAA6B,CAAC;AAErC,YAAY,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { resolveTsconfig } from './resolve-tsconfig.utils.js';
|
|
2
|
-
export { readTsBuildInfoFile } from './read-tsbuildinfo.utils.js';
|
|
3
|
-
export { mergeArrayConfig } from './merge-array-config.utils.js';
|
|
2
|
+
export { readTsBuildInfoFile, isTsConfigLike } from './read-tsbuildinfo.utils.js';
|
|
3
|
+
export { mergeArrayConfig, normalizeArrayConfig } from './merge-array-config.utils.js';
|
|
4
4
|
export { mergeExternalConfig, normalizeExternal } from './merge-external-config.utils.js';
|
|
5
|
+
export { resolveExternal, readPackageDependencies, matchAlwaysBundle, collectExternal, isPackageJsonLike, } from './resolve-external.utils.js';
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAIlF,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAEvF,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAE1F,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,GAClB,MAAM,6BAA6B,CAAC","sourcesContent":["export { resolveTsconfig } from './resolve-tsconfig.utils.js';\n\nexport { readTsBuildInfoFile, isTsConfigLike } from './read-tsbuildinfo.utils.js';\n\nexport type { TsConfigLike } from './read-tsbuildinfo.utils.js';\n\nexport { mergeArrayConfig, normalizeArrayConfig } from './merge-array-config.utils.js';\n\nexport { mergeExternalConfig, normalizeExternal } from './merge-external-config.utils.js';\n\nexport {\n resolveExternal,\n readPackageDependencies,\n matchAlwaysBundle,\n collectExternal,\n isPackageJsonLike,\n} from './resolve-external.utils.js';\n\nexport type { PackageJsonLike } from './resolve-external.utils.js';\n"]}
|
|
@@ -4,6 +4,13 @@
|
|
|
4
4
|
* @typeParam T - 数组元素类型
|
|
5
5
|
*/
|
|
6
6
|
type Arrayable<T> = T | T[];
|
|
7
|
+
/**
|
|
8
|
+
* 将 alwaysBundle 配置规范化为数组
|
|
9
|
+
*
|
|
10
|
+
* @param value - alwaysBundle 配置
|
|
11
|
+
* @returns 规范化后的数组
|
|
12
|
+
*/
|
|
13
|
+
declare function normalizeArrayConfig(value: Arrayable<string | RegExp> | undefined): (string | RegExp)[];
|
|
7
14
|
/**
|
|
8
15
|
* 合并两个 alwaysBundle 配置
|
|
9
16
|
*
|
|
@@ -14,5 +21,5 @@ type Arrayable<T> = T | T[];
|
|
|
14
21
|
* @returns 合并后的新数组
|
|
15
22
|
*/
|
|
16
23
|
declare function mergeArrayConfig(base: Arrayable<string | RegExp> | undefined, override: Arrayable<string | RegExp> | undefined): (string | RegExp)[];
|
|
17
|
-
export { mergeArrayConfig };
|
|
24
|
+
export { mergeArrayConfig, normalizeArrayConfig };
|
|
18
25
|
//# sourceMappingURL=merge-array-config.utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge-array-config.utils.d.ts","sourceRoot":"","sources":["../../src/utils/merge-array-config.utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,KAAK,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"merge-array-config.utils.d.ts","sourceRoot":"","sources":["../../src/utils/merge-array-config.utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,KAAK,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AAE5B;;;;;GAKG;AACH,iBAAS,oBAAoB,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,SAAS,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAKhG;AAED;;;;;;;;GAQG;AACH,iBAAS,gBAAgB,CACvB,IAAI,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,SAAS,EAC5C,QAAQ,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,SAAS,GAC/C,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAErB;AAED,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,CAAC"}
|
|
@@ -23,5 +23,5 @@ function normalizeArrayConfig(value) {
|
|
|
23
23
|
function mergeArrayConfig(base, override) {
|
|
24
24
|
return [...normalizeArrayConfig(base), ...normalizeArrayConfig(override)];
|
|
25
25
|
}
|
|
26
|
-
export { mergeArrayConfig };
|
|
26
|
+
export { mergeArrayConfig, normalizeArrayConfig };
|
|
27
27
|
//# sourceMappingURL=merge-array-config.utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge-array-config.utils.js","sourceRoot":"","sources":["../../src/utils/merge-array-config.utils.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,SAAS,oBAAoB,
|
|
1
|
+
{"version":3,"file":"merge-array-config.utils.js","sourceRoot":"","sources":["../../src/utils/merge-array-config.utils.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,KAA6C;IACzE,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IACnC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAEvC,OAAO,CAAC,KAAK,CAAC,CAAC;AACjB,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,gBAAgB,CACvB,IAA4C,EAC5C,QAAgD;IAEhD,OAAO,CAAC,GAAG,oBAAoB,CAAC,IAAI,CAAC,EAAE,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC5E,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,CAAC","sourcesContent":["/**\n * 可数组化类型,值为单值或数组的联合\n *\n * @typeParam T - 数组元素类型\n */\ntype Arrayable<T> = T | T[];\n\n/**\n * 将 alwaysBundle 配置规范化为数组\n *\n * @param value - alwaysBundle 配置\n * @returns 规范化后的数组\n */\nfunction normalizeArrayConfig(value: Arrayable<string | RegExp> | undefined): (string | RegExp)[] {\n if (value === undefined) return [];\n if (Array.isArray(value)) return value;\n\n return [value];\n}\n\n/**\n * 合并两个 alwaysBundle 配置\n *\n * 用于合并 deps.alwaysBundle。两个来源的元素都会保留,不会去重。\n *\n * @param base - 基础配置\n * @param override - 需要合并的配置\n * @returns 合并后的新数组\n */\nfunction mergeArrayConfig(\n base: Arrayable<string | RegExp> | undefined,\n override: Arrayable<string | RegExp> | undefined,\n): (string | RegExp)[] {\n return [...normalizeArrayConfig(base), ...normalizeArrayConfig(override)];\n}\n\nexport { mergeArrayConfig, normalizeArrayConfig };\n"]}
|
|
@@ -6,6 +6,15 @@ type TsConfigLike = {
|
|
|
6
6
|
tsBuildInfoFile?: string;
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* 判定未知值是否为 TsConfigLike 结构
|
|
11
|
+
*
|
|
12
|
+
* 替代 as 类型断言,用类型守卫安全窄化 JSON.parse 的 unknown 返回值。
|
|
13
|
+
*
|
|
14
|
+
* @param value - 待判定的值
|
|
15
|
+
* @returns 符合 TsConfigLike 结构则返回 true
|
|
16
|
+
*/
|
|
17
|
+
declare function isTsConfigLike(value: unknown): value is TsConfigLike;
|
|
9
18
|
/**
|
|
10
19
|
* 读取 tsconfig 文件中声明的 tsBuildInfoFile 路径
|
|
11
20
|
*
|
|
@@ -16,6 +25,6 @@ type TsConfigLike = {
|
|
|
16
25
|
* @returns tsBuildInfoFile 的声明值(相对 tsconfig 文件目录),未声明或读取失败时返回 null
|
|
17
26
|
*/
|
|
18
27
|
declare function readTsBuildInfoFile(tsconfigPath: string): Promise<string | null>;
|
|
19
|
-
export { readTsBuildInfoFile };
|
|
28
|
+
export { readTsBuildInfoFile, isTsConfigLike };
|
|
20
29
|
export type { TsConfigLike };
|
|
21
30
|
//# sourceMappingURL=read-tsbuildinfo.utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-tsbuildinfo.utils.d.ts","sourceRoot":"","sources":["../../src/utils/read-tsbuildinfo.utils.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,KAAK,YAAY,GAAG;IAClB,eAAe,CAAC,EAAE;QAChB,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,CAAC;CACH,CAAC;AAEF;;;;;;;;GAQG;AACH,iBAAe,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"read-tsbuildinfo.utils.d.ts","sourceRoot":"","sources":["../../src/utils/read-tsbuildinfo.utils.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,KAAK,YAAY,GAAG;IAClB,eAAe,CAAC,EAAE;QAChB,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,CAAC;CACH,CAAC;AAEF;;;;;;;GAOG;AACH,iBAAS,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAoB7D;AAED;;;;;;;;GAQG;AACH,iBAAe,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAoB/E;AAED,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,CAAC;AAE/C,YAAY,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -1,4 +1,31 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
|
+
/**
|
|
3
|
+
* 判定未知值是否为 TsConfigLike 结构
|
|
4
|
+
*
|
|
5
|
+
* 替代 as 类型断言,用类型守卫安全窄化 JSON.parse 的 unknown 返回值。
|
|
6
|
+
*
|
|
7
|
+
* @param value - 待判定的值
|
|
8
|
+
* @returns 符合 TsConfigLike 结构则返回 true
|
|
9
|
+
*/
|
|
10
|
+
function isTsConfigLike(value) {
|
|
11
|
+
if (typeof value !== 'object' || value === null) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* compilerOptions 可选,不存在时直接通过
|
|
16
|
+
*/
|
|
17
|
+
if (!('compilerOptions' in value)) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* compilerOptions 存在时须为对象
|
|
22
|
+
*/
|
|
23
|
+
const compilerOptions = value.compilerOptions;
|
|
24
|
+
if (compilerOptions === undefined) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return typeof compilerOptions === 'object' && compilerOptions !== null;
|
|
28
|
+
}
|
|
2
29
|
/**
|
|
3
30
|
* 读取 tsconfig 文件中声明的 tsBuildInfoFile 路径
|
|
4
31
|
*
|
|
@@ -10,13 +37,22 @@ import { readFile } from 'node:fs/promises';
|
|
|
10
37
|
*/
|
|
11
38
|
async function readTsBuildInfoFile(tsconfigPath) {
|
|
12
39
|
try {
|
|
40
|
+
/**
|
|
41
|
+
* tsconfig 文件原始内容
|
|
42
|
+
*/
|
|
13
43
|
const raw = await readFile(tsconfigPath, 'utf-8');
|
|
44
|
+
/**
|
|
45
|
+
* 解析后的 tsconfig 对象
|
|
46
|
+
*/
|
|
14
47
|
const parsed = JSON.parse(raw);
|
|
48
|
+
if (!isTsConfigLike(parsed)) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
15
51
|
return parsed.compilerOptions?.tsBuildInfoFile ?? null;
|
|
16
52
|
}
|
|
17
53
|
catch {
|
|
18
54
|
return null;
|
|
19
55
|
}
|
|
20
56
|
}
|
|
21
|
-
export { readTsBuildInfoFile };
|
|
57
|
+
export { readTsBuildInfoFile, isTsConfigLike };
|
|
22
58
|
//# sourceMappingURL=read-tsbuildinfo.utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-tsbuildinfo.utils.js","sourceRoot":"","sources":["../../src/utils/read-tsbuildinfo.utils.ts"],"names":[],"mappings":"AA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AC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,CAAC","sourcesContent":["import { readFile } from 'node:fs/promises';\n\n/**\n * tsconfig 文件的最小结构(仅读取构建清理所需字段)\n */\ntype TsConfigLike = {\n compilerOptions?: {\n tsBuildInfoFile?: string;\n };\n};\n\n/**\n * 判定未知值是否为 TsConfigLike 结构\n *\n * 替代 as 类型断言,用类型守卫安全窄化 JSON.parse 的 unknown 返回值。\n *\n * @param value - 待判定的值\n * @returns 符合 TsConfigLike 结构则返回 true\n */\nfunction isTsConfigLike(value: unknown): value is TsConfigLike {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n\n /**\n * compilerOptions 可选,不存在时直接通过\n */\n if (!('compilerOptions' in value)) {\n return true;\n }\n\n /**\n * compilerOptions 存在时须为对象\n */\n const compilerOptions = value.compilerOptions;\n if (compilerOptions === undefined) {\n return true;\n }\n return typeof compilerOptions === 'object' && compilerOptions !== null;\n}\n\n/**\n * 读取 tsconfig 文件中声明的 tsBuildInfoFile 路径\n *\n * 直接读取目标 tsconfig 的 compilerOptions.tsBuildInfoFile,\n * 不解析 extends 链(现状下各子包 build.json 均显式声明该字段)。\n *\n * @param tsconfigPath - tsconfig 文件绝对路径\n * @returns tsBuildInfoFile 的声明值(相对 tsconfig 文件目录),未声明或读取失败时返回 null\n */\nasync function readTsBuildInfoFile(tsconfigPath: string): Promise<string | null> {\n try {\n /**\n * tsconfig 文件原始内容\n */\n const raw = await readFile(tsconfigPath, 'utf-8');\n\n /**\n * 解析后的 tsconfig 对象\n */\n const parsed: unknown = JSON.parse(raw);\n\n if (!isTsConfigLike(parsed)) {\n return null;\n }\n\n return parsed.compilerOptions?.tsBuildInfoFile ?? null;\n } catch {\n return null;\n }\n}\n\nexport { readTsBuildInfoFile, isTsConfigLike };\n\nexport type { TsConfigLike };\n"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { DepsOptions } from '../core/types';
|
|
2
|
+
import type { ExternalOption } from 'rolldown';
|
|
3
|
+
/**
|
|
4
|
+
* package.json 的最小结构(仅读取 external 派生所需字段)
|
|
5
|
+
*/
|
|
6
|
+
type PackageJsonLike = {
|
|
7
|
+
dependencies?: Record<string, string>;
|
|
8
|
+
peerDependencies?: Record<string, string>;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* 判定未知值是否为 PackageJsonLike 结构
|
|
12
|
+
*
|
|
13
|
+
* 替代 as 类型断言,用类型守卫安全窄化 JSON.parse 的 unknown 返回值。
|
|
14
|
+
* dependencies / peerDependencies 可选,存在时须为对象。
|
|
15
|
+
*
|
|
16
|
+
* @param value - 待判定的值
|
|
17
|
+
* @returns 符合 PackageJsonLike 结构则返回 true
|
|
18
|
+
*/
|
|
19
|
+
declare function isPackageJsonLike(value: unknown): value is PackageJsonLike;
|
|
20
|
+
/**
|
|
21
|
+
* 判断目标依赖名是否匹配 alwaysBundle 中的某一条规则
|
|
22
|
+
*
|
|
23
|
+
* alwaysBundle 元素可为字符串(精确匹配或前缀匹配)或 RegExp。
|
|
24
|
+
* 字符串规则匹配依赖名本身或 `${依赖名}/...` 子路径,使 `'zod'` 能覆盖 `'zod/v4'`。
|
|
25
|
+
*
|
|
26
|
+
* @param id - 待判定的依赖名
|
|
27
|
+
* @param alwaysBundle - 始终打包规则数组
|
|
28
|
+
* @returns 命中则返回 true
|
|
29
|
+
*/
|
|
30
|
+
declare function matchAlwaysBundle(id: string, alwaysBundle: (string | RegExp)[]): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* 将若干 ExternalOption 来源合并为一个数组
|
|
33
|
+
*
|
|
34
|
+
* 函数类型的 external 无法与其他来源合并,遇到时跳过(由调用方决定透传策略)。
|
|
35
|
+
*
|
|
36
|
+
* @param sources - 待合并的 external 来源
|
|
37
|
+
* @returns 合并后的数组,可能为空
|
|
38
|
+
*/
|
|
39
|
+
declare function collectExternal(sources: (ExternalOption | undefined)[]): (string | RegExp)[];
|
|
40
|
+
/**
|
|
41
|
+
* 读取指定目录的 package.json 的 dependencies 与 peerDependencies 依赖名
|
|
42
|
+
*
|
|
43
|
+
* 仅读取依赖键名(用于派生 external),不解析版本号。
|
|
44
|
+
* dependencies 与 peerDependencies 均纳入(与 tsdown 默认行为一致)。
|
|
45
|
+
* 不读 devDependencies(开发依赖不进产物,无需外部化)。
|
|
46
|
+
*
|
|
47
|
+
* @param cwd - 当前包目录,默认为 process.cwd()
|
|
48
|
+
* @returns 依赖名数组,读取失败或无依赖时返回空数组
|
|
49
|
+
*/
|
|
50
|
+
declare function readPackageDependencies(cwd?: string): Promise<string[]>;
|
|
51
|
+
/**
|
|
52
|
+
* 解析最终作用于 rolldown 的 external 配置
|
|
53
|
+
*
|
|
54
|
+
* 库模式(deps.skipNodeModulesBundle !== false)默认外部化 package.json 的
|
|
55
|
+
* dependencies + peerDependencies,消费方零配置即与 tsdown 默认行为对齐。
|
|
56
|
+
*
|
|
57
|
+
* 合并优先级(后者追加,不覆盖前者):
|
|
58
|
+
* 1. package.json 派生的依赖名(默认基底)
|
|
59
|
+
* 2. deps.neverBundle(始终外部化的补充规则)
|
|
60
|
+
* 3. config.external(消费方显式声明)
|
|
61
|
+
*
|
|
62
|
+
* 随后用 deps.alwaysBundle 过滤:命中的依赖从 external 移除,强制打包进产物,
|
|
63
|
+
* 用于库包需要把某些 dependencies 内联分发的场景。
|
|
64
|
+
*
|
|
65
|
+
* 应用模式(deps.skipNodeModulesBundle === false)跳过派生,直接返回
|
|
66
|
+
* config.external(通常为 undefined,即全量打包)。
|
|
67
|
+
*
|
|
68
|
+
* @param configExternal - 消费方在 BuilderConfig.external 声明的外部依赖
|
|
69
|
+
* @param deps - 依赖处理选项
|
|
70
|
+
* @param cwd - 当前包目录,默认为 process.cwd()
|
|
71
|
+
* @returns 解析后的 external,可能为 undefined(表示不外部化,全量打包)
|
|
72
|
+
*/
|
|
73
|
+
declare function resolveExternal(configExternal: ExternalOption | undefined, deps: DepsOptions | undefined, cwd?: string): Promise<ExternalOption | undefined>;
|
|
74
|
+
export { resolveExternal, readPackageDependencies, matchAlwaysBundle, collectExternal, isPackageJsonLike, };
|
|
75
|
+
export type { PackageJsonLike };
|
|
76
|
+
//# sourceMappingURL=resolve-external.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-external.utils.d.ts","sourceRoot":"","sources":["../../src/utils/resolve-external.utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAS/C;;GAEG;AACH,KAAK,eAAe,GAAG;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C,CAAC;AAEF;;;;;;;;GAQG;AACH,iBAAS,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,eAAe,CA+BnE;AAED;;;;;;;;;GASG;AACH,iBAAS,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,GAAG,OAAO,CAWjF;AAED;;;;;;;GAOG;AACH,iBAAS,eAAe,CAAC,OAAO,EAAE,CAAC,cAAc,GAAG,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAWrF;AAED;;;;;;;;;GASG;AACH,iBAAe,uBAAuB,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA4BrF;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,iBAAe,eAAe,CAC5B,cAAc,EAAE,cAAc,GAAG,SAAS,EAC1C,IAAI,EAAE,WAAW,GAAG,SAAS,EAC7B,GAAG,GAAE,MAAsB,GAC1B,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAyCrC;AAED,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,GAClB,CAAC;AAEF,YAAY,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import process from 'node:process';
|
|
4
|
+
import { normalizeArrayConfig } from './merge-array-config.utils.js';
|
|
5
|
+
import { normalizeExternal } from './merge-external-config.utils.js';
|
|
6
|
+
/**
|
|
7
|
+
* 判定未知值是否为 PackageJsonLike 结构
|
|
8
|
+
*
|
|
9
|
+
* 替代 as 类型断言,用类型守卫安全窄化 JSON.parse 的 unknown 返回值。
|
|
10
|
+
* dependencies / peerDependencies 可选,存在时须为对象。
|
|
11
|
+
*
|
|
12
|
+
* @param value - 待判定的值
|
|
13
|
+
* @returns 符合 PackageJsonLike 结构则返回 true
|
|
14
|
+
*/
|
|
15
|
+
function isPackageJsonLike(value) {
|
|
16
|
+
if (typeof value !== 'object' || value === null) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* dependencies 可选,存在时须为对象
|
|
21
|
+
*/
|
|
22
|
+
if ('dependencies' in value) {
|
|
23
|
+
/**
|
|
24
|
+
* dependencies 字段值
|
|
25
|
+
*/
|
|
26
|
+
const deps = value.dependencies;
|
|
27
|
+
if (deps !== undefined && (typeof deps !== 'object' || deps === null)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* peerDependencies 可选,存在时须为对象
|
|
33
|
+
*/
|
|
34
|
+
if ('peerDependencies' in value) {
|
|
35
|
+
/**
|
|
36
|
+
* peerDependencies 字段值
|
|
37
|
+
*/
|
|
38
|
+
const peerDeps = value.peerDependencies;
|
|
39
|
+
if (peerDeps !== undefined && (typeof peerDeps !== 'object' || peerDeps === null)) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 判断目标依赖名是否匹配 alwaysBundle 中的某一条规则
|
|
47
|
+
*
|
|
48
|
+
* alwaysBundle 元素可为字符串(精确匹配或前缀匹配)或 RegExp。
|
|
49
|
+
* 字符串规则匹配依赖名本身或 `${依赖名}/...` 子路径,使 `'zod'` 能覆盖 `'zod/v4'`。
|
|
50
|
+
*
|
|
51
|
+
* @param id - 待判定的依赖名
|
|
52
|
+
* @param alwaysBundle - 始终打包规则数组
|
|
53
|
+
* @returns 命中则返回 true
|
|
54
|
+
*/
|
|
55
|
+
function matchAlwaysBundle(id, alwaysBundle) {
|
|
56
|
+
return alwaysBundle.some((rule) => {
|
|
57
|
+
if (rule instanceof RegExp) {
|
|
58
|
+
return rule.test(id);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 字符串规则:精确匹配或以 `${rule}/` 开头(覆盖子路径导入)
|
|
62
|
+
*/
|
|
63
|
+
return id === rule || id.startsWith(`${rule}/`);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 将若干 ExternalOption 来源合并为一个数组
|
|
68
|
+
*
|
|
69
|
+
* 函数类型的 external 无法与其他来源合并,遇到时跳过(由调用方决定透传策略)。
|
|
70
|
+
*
|
|
71
|
+
* @param sources - 待合并的 external 来源
|
|
72
|
+
* @returns 合并后的数组,可能为空
|
|
73
|
+
*/
|
|
74
|
+
function collectExternal(sources) {
|
|
75
|
+
/**
|
|
76
|
+
* 合并后的外部依赖数组
|
|
77
|
+
*/
|
|
78
|
+
const collected = [];
|
|
79
|
+
for (const source of sources) {
|
|
80
|
+
collected.push(...normalizeExternal(source));
|
|
81
|
+
}
|
|
82
|
+
return collected;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 读取指定目录的 package.json 的 dependencies 与 peerDependencies 依赖名
|
|
86
|
+
*
|
|
87
|
+
* 仅读取依赖键名(用于派生 external),不解析版本号。
|
|
88
|
+
* dependencies 与 peerDependencies 均纳入(与 tsdown 默认行为一致)。
|
|
89
|
+
* 不读 devDependencies(开发依赖不进产物,无需外部化)。
|
|
90
|
+
*
|
|
91
|
+
* @param cwd - 当前包目录,默认为 process.cwd()
|
|
92
|
+
* @returns 依赖名数组,读取失败或无依赖时返回空数组
|
|
93
|
+
*/
|
|
94
|
+
async function readPackageDependencies(cwd = process.cwd()) {
|
|
95
|
+
try {
|
|
96
|
+
/**
|
|
97
|
+
* package.json 文件绝对路径
|
|
98
|
+
*/
|
|
99
|
+
const pkgPath = resolve(cwd, 'package.json');
|
|
100
|
+
/**
|
|
101
|
+
* package.json 原始内容
|
|
102
|
+
*/
|
|
103
|
+
const raw = await readFile(pkgPath, 'utf-8');
|
|
104
|
+
/**
|
|
105
|
+
* 解析后的 package.json(仅取依赖字段)
|
|
106
|
+
*/
|
|
107
|
+
const parsed = JSON.parse(raw);
|
|
108
|
+
if (!isPackageJsonLike(parsed)) {
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
return Object.keys({
|
|
112
|
+
...parsed.dependencies,
|
|
113
|
+
...parsed.peerDependencies,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* 解析最终作用于 rolldown 的 external 配置
|
|
122
|
+
*
|
|
123
|
+
* 库模式(deps.skipNodeModulesBundle !== false)默认外部化 package.json 的
|
|
124
|
+
* dependencies + peerDependencies,消费方零配置即与 tsdown 默认行为对齐。
|
|
125
|
+
*
|
|
126
|
+
* 合并优先级(后者追加,不覆盖前者):
|
|
127
|
+
* 1. package.json 派生的依赖名(默认基底)
|
|
128
|
+
* 2. deps.neverBundle(始终外部化的补充规则)
|
|
129
|
+
* 3. config.external(消费方显式声明)
|
|
130
|
+
*
|
|
131
|
+
* 随后用 deps.alwaysBundle 过滤:命中的依赖从 external 移除,强制打包进产物,
|
|
132
|
+
* 用于库包需要把某些 dependencies 内联分发的场景。
|
|
133
|
+
*
|
|
134
|
+
* 应用模式(deps.skipNodeModulesBundle === false)跳过派生,直接返回
|
|
135
|
+
* config.external(通常为 undefined,即全量打包)。
|
|
136
|
+
*
|
|
137
|
+
* @param configExternal - 消费方在 BuilderConfig.external 声明的外部依赖
|
|
138
|
+
* @param deps - 依赖处理选项
|
|
139
|
+
* @param cwd - 当前包目录,默认为 process.cwd()
|
|
140
|
+
* @returns 解析后的 external,可能为 undefined(表示不外部化,全量打包)
|
|
141
|
+
*/
|
|
142
|
+
async function resolveExternal(configExternal, deps, cwd = process.cwd()) {
|
|
143
|
+
/**
|
|
144
|
+
* 应用模式:全量打包,仅透传消费方显式声明
|
|
145
|
+
*/
|
|
146
|
+
if (deps?.skipNodeModulesBundle === false) {
|
|
147
|
+
return configExternal;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* 消费方若以函数形式声明 external,无法与派生列表合并,直接透传
|
|
151
|
+
*/
|
|
152
|
+
if (typeof configExternal === 'function') {
|
|
153
|
+
return configExternal;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* 从 package.json 派生默认 external 基底
|
|
157
|
+
*/
|
|
158
|
+
const packageDeps = await readPackageDependencies(cwd);
|
|
159
|
+
/**
|
|
160
|
+
* 合并三处来源:package.json 依赖名 + neverBundle + config.external
|
|
161
|
+
*/
|
|
162
|
+
const merged = collectExternal([packageDeps, deps?.neverBundle, configExternal]);
|
|
163
|
+
/**
|
|
164
|
+
* alwaysBundle 命中的依赖强制打包,从 external 中剔除
|
|
165
|
+
*/
|
|
166
|
+
const alwaysBundle = normalizeArrayConfig(deps?.alwaysBundle);
|
|
167
|
+
/**
|
|
168
|
+
* 过滤后的 external 列表(移除 alwaysBundle 命中项)
|
|
169
|
+
*/
|
|
170
|
+
const filtered = merged.filter((rule) => {
|
|
171
|
+
if (typeof rule !== 'string') {
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
return !matchAlwaysBundle(rule, alwaysBundle);
|
|
175
|
+
});
|
|
176
|
+
return filtered.length > 0 ? filtered : undefined;
|
|
177
|
+
}
|
|
178
|
+
export { resolveExternal, readPackageDependencies, matchAlwaysBundle, collectExternal, isPackageJsonLike, };
|
|
179
|
+
//# sourceMappingURL=resolve-external.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-external.utils.js","sourceRoot":"","sources":["../../src/utils/resolve-external.utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAUrE;;;;;;;;GAQG;AACH,SAAS,iBAAiB,CAAC,KAAc;IACvC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACH,IAAI,cAAc,IAAI,KAAK,EAAE,CAAC;QAC5B;;WAEG;QACH,MAAM,IAAI,GAAG,KAAK,CAAC,YAAY,CAAC;QAChC,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;YACtE,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED;;OAEG;IACH,IAAI,kBAAkB,IAAI,KAAK,EAAE,CAAC;QAChC;;WAEG;QACH,MAAM,QAAQ,GAAG,KAAK,CAAC,gBAAgB,CAAC;QACxC,IAAI,QA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,iBAAiB,EACjB,eAAe,EACf,iBAAiB,GAClB,CAAC","sourcesContent":["import type { DepsOptions } from '@/core/types';\nimport type { ExternalOption } from 'rolldown';\n\nimport { readFile } from 'node:fs/promises';\nimport { resolve } from 'node:path';\nimport process from 'node:process';\n\nimport { normalizeArrayConfig } from './merge-array-config.utils.js';\nimport { normalizeExternal } from './merge-external-config.utils.js';\n\n/**\n * package.json 的最小结构(仅读取 external 派生所需字段)\n */\ntype PackageJsonLike = {\n dependencies?: Record<string, string>;\n peerDependencies?: Record<string, string>;\n};\n\n/**\n * 判定未知值是否为 PackageJsonLike 结构\n *\n * 替代 as 类型断言,用类型守卫安全窄化 JSON.parse 的 unknown 返回值。\n * dependencies / peerDependencies 可选,存在时须为对象。\n *\n * @param value - 待判定的值\n * @returns 符合 PackageJsonLike 结构则返回 true\n */\nfunction isPackageJsonLike(value: unknown): value is PackageJsonLike {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n\n /**\n * dependencies 可选,存在时须为对象\n */\n if ('dependencies' in value) {\n /**\n * dependencies 字段值\n */\n const deps = value.dependencies;\n if (deps !== undefined && (typeof deps !== 'object' || deps === null)) {\n return false;\n }\n }\n\n /**\n * peerDependencies 可选,存在时须为对象\n */\n if ('peerDependencies' in value) {\n /**\n * peerDependencies 字段值\n */\n const peerDeps = value.peerDependencies;\n if (peerDeps !== undefined && (typeof peerDeps !== 'object' || peerDeps === null)) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * 判断目标依赖名是否匹配 alwaysBundle 中的某一条规则\n *\n * alwaysBundle 元素可为字符串(精确匹配或前缀匹配)或 RegExp。\n * 字符串规则匹配依赖名本身或 `${依赖名}/...` 子路径,使 `'zod'` 能覆盖 `'zod/v4'`。\n *\n * @param id - 待判定的依赖名\n * @param alwaysBundle - 始终打包规则数组\n * @returns 命中则返回 true\n */\nfunction matchAlwaysBundle(id: string, alwaysBundle: (string | RegExp)[]): boolean {\n return alwaysBundle.some((rule) => {\n if (rule instanceof RegExp) {\n return rule.test(id);\n }\n\n /**\n * 字符串规则:精确匹配或以 `${rule}/` 开头(覆盖子路径导入)\n */\n return id === rule || id.startsWith(`${rule}/`);\n });\n}\n\n/**\n * 将若干 ExternalOption 来源合并为一个数组\n *\n * 函数类型的 external 无法与其他来源合并,遇到时跳过(由调用方决定透传策略)。\n *\n * @param sources - 待合并的 external 来源\n * @returns 合并后的数组,可能为空\n */\nfunction collectExternal(sources: (ExternalOption | undefined)[]): (string | RegExp)[] {\n /**\n * 合并后的外部依赖数组\n */\n const collected: (string | RegExp)[] = [];\n\n for (const source of sources) {\n collected.push(...normalizeExternal(source));\n }\n\n return collected;\n}\n\n/**\n * 读取指定目录的 package.json 的 dependencies 与 peerDependencies 依赖名\n *\n * 仅读取依赖键名(用于派生 external),不解析版本号。\n * dependencies 与 peerDependencies 均纳入(与 tsdown 默认行为一致)。\n * 不读 devDependencies(开发依赖不进产物,无需外部化)。\n *\n * @param cwd - 当前包目录,默认为 process.cwd()\n * @returns 依赖名数组,读取失败或无依赖时返回空数组\n */\nasync function readPackageDependencies(cwd: string = process.cwd()): Promise<string[]> {\n try {\n /**\n * package.json 文件绝对路径\n */\n const pkgPath = resolve(cwd, 'package.json');\n\n /**\n * package.json 原始内容\n */\n const raw = await readFile(pkgPath, 'utf-8');\n\n /**\n * 解析后的 package.json(仅取依赖字段)\n */\n const parsed: unknown = JSON.parse(raw);\n\n if (!isPackageJsonLike(parsed)) {\n return [];\n }\n\n return Object.keys({\n ...parsed.dependencies,\n ...parsed.peerDependencies,\n });\n } catch {\n return [];\n }\n}\n\n/**\n * 解析最终作用于 rolldown 的 external 配置\n *\n * 库模式(deps.skipNodeModulesBundle !== false)默认外部化 package.json 的\n * dependencies + peerDependencies,消费方零配置即与 tsdown 默认行为对齐。\n *\n * 合并优先级(后者追加,不覆盖前者):\n * 1. package.json 派生的依赖名(默认基底)\n * 2. deps.neverBundle(始终外部化的补充规则)\n * 3. config.external(消费方显式声明)\n *\n * 随后用 deps.alwaysBundle 过滤:命中的依赖从 external 移除,强制打包进产物,\n * 用于库包需要把某些 dependencies 内联分发的场景。\n *\n * 应用模式(deps.skipNodeModulesBundle === false)跳过派生,直接返回\n * config.external(通常为 undefined,即全量打包)。\n *\n * @param configExternal - 消费方在 BuilderConfig.external 声明的外部依赖\n * @param deps - 依赖处理选项\n * @param cwd - 当前包目录,默认为 process.cwd()\n * @returns 解析后的 external,可能为 undefined(表示不外部化,全量打包)\n */\nasync function resolveExternal(\n configExternal: ExternalOption | undefined,\n deps: DepsOptions | undefined,\n cwd: string = process.cwd(),\n): Promise<ExternalOption | undefined> {\n /**\n * 应用模式:全量打包,仅透传消费方显式声明\n */\n if (deps?.skipNodeModulesBundle === false) {\n return configExternal;\n }\n\n /**\n * 消费方若以函数形式声明 external,无法与派生列表合并,直接透传\n */\n if (typeof configExternal === 'function') {\n return configExternal;\n }\n\n /**\n * 从 package.json 派生默认 external 基底\n */\n const packageDeps = await readPackageDependencies(cwd);\n\n /**\n * 合并三处来源:package.json 依赖名 + neverBundle + config.external\n */\n const merged = collectExternal([packageDeps, deps?.neverBundle, configExternal]);\n\n /**\n * alwaysBundle 命中的依赖强制打包,从 external 中剔除\n */\n const alwaysBundle = normalizeArrayConfig(deps?.alwaysBundle);\n\n /**\n * 过滤后的 external 列表(移除 alwaysBundle 命中项)\n */\n const filtered = merged.filter((rule) => {\n if (typeof rule !== 'string') {\n return true;\n }\n return !matchAlwaysBundle(rule, alwaysBundle);\n });\n\n return filtered.length > 0 ? filtered : undefined;\n}\n\nexport {\n resolveExternal,\n readPackageDependencies,\n matchAlwaysBundle,\n collectExternal,\n isPackageJsonLike,\n};\n\nexport type { PackageJsonLike };\n"]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longzai-intelligence-builder/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
6
9
|
"type": "module",
|
|
7
10
|
"main": "./dist/index.js",
|
|
8
11
|
"types": "./dist/index.d.ts",
|
|
@@ -12,9 +15,6 @@
|
|
|
12
15
|
"import": "./dist/index.js"
|
|
13
16
|
}
|
|
14
17
|
},
|
|
15
|
-
"files": [
|
|
16
|
-
"dist"
|
|
17
|
-
],
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "tsgo --build tsconfig/build.json && resolve-aliases -p tsconfig/build.json",
|
|
20
20
|
"build:prod": "NODE_ENV=production bun run build",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"clean": "lzi-dev-cli clean"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@longzai-intelligence-builder/config": "0.0.
|
|
34
|
+
"@longzai-intelligence-builder/config": "0.0.8"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@typescript/native-preview": "^7.0.0-dev.20260707.2"
|