@vvi/rollup-external 1.1.2

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/CHANGELOG.md ADDED
@@ -0,0 +1,89 @@
1
+ # 更新日志
2
+
3
+ ## 1.1.2 (2026-2-1)
4
+
5
+ 第二参数维护:现在该参数可以是单个字符串或字符串数组,以适应不同的使用需求
6
+
7
+ ## 1.1.1 (2026-1-18)
8
+
9
+ ### 🔧 修复
10
+
11
+ - 将 "packages.json" 文件中的 `peerDependencies` 也算 `dependencies` 依赖,不需要再显式排除
12
+
13
+ ### ✨ 添加
14
+
15
+ - 使用第二参数 `true`,打印信息(嗯,貌似没什么用的功能)
16
+
17
+ ## v1.1.0 (2025-12-29)
18
+
19
+ - 依赖维护
20
+
21
+ ## v1.0.11 (2025-8-12)
22
+
23
+ - 修复已知问题,该问题导致在 windows 上无法正确排除打包系统文件
24
+
25
+ ## v1.0.10 (2025-7-30)
26
+
27
+ ## v1.0.9 (2025-7-19)
28
+
29
+ - 更新文档
30
+
31
+ ## v1.0.8 (2025-6-22)
32
+
33
+ - 更新文档
34
+
35
+ ## v1.0.7 (2025-6-20)
36
+
37
+ - 更新文档
38
+
39
+ ## v1.0.6 (2025-6-13)
40
+
41
+ - 优化了参数校验更改后造成的无依赖时校验错误
42
+
43
+ ## v1.0.5 (2025-6-10)
44
+
45
+ - 么事。这次是阿其那
46
+
47
+ ## v1.0.4 (2025-6-10)
48
+
49
+ - 么事,修复个贤王
50
+
51
+ ## v1.0.3 (2025-6-10)
52
+
53
+ - 参数的校验
54
+
55
+ ## v1.0.2 (2025-6-5)
56
+
57
+ - 需要添加的依赖或排除的依赖添加了执行自动添加到剪切版
58
+
59
+ ## v1.0.1 (2025-6-3)
60
+
61
+ - 更新文档
62
+
63
+ ## v1.0.0 (5 🈷️ 25 日 2025 年)
64
+
65
+ - 就是闲的
66
+
67
+ ## v0.1.2 (5 🈷️ 11 日 2025 年)
68
+
69
+ - 更新文档
70
+
71
+ ## v0.1.1 (5 🈷️ 8 日 2025 年)
72
+
73
+ - 更新文档
74
+
75
+ ## v0.1.0 (5 🈷️ 3 日 2025 年)
76
+
77
+ - 嗯,优化了逻辑
78
+
79
+ ## v0.0.2 (5 🈷️ 3 日 2025 年)
80
+
81
+ - 修复文档
82
+
83
+ ## v0.0.1 (5 🈷️ 3 日 2025 年)
84
+
85
+ - 修复上一个版本的导出错误
86
+
87
+ ## 0.0.0 (5 月 3 2025 年)
88
+
89
+ - 初始化项目
package/LICENSE ADDED
@@ -0,0 +1,16 @@
1
+ # MIT License
2
+
3
+ Copyright ©️ <2025> <MrMudBean>
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+
package/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # @vvi/rollup-external
2
+
3
+ [![version](<https://img.shields.io/npm/v/@vvi/rollup-external.svg?logo=npm&logoColor=rgb(0,0,0)&label=版本号&labelColor=rgb(73,73,228)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/@vvi/rollup-external) [![issues 提交](<https://img.shields.io/badge/issues-提交-rgb(255,0,63)?logo=github>)](https://github.com/MrMudBean/rollup-external/issues)
4
+
5
+ 一个简单的 rollup 构建打包时的排除外部依赖的函数(多用于构建 npm 库包)
6
+
7
+ 因为我在构建新的 npm 库包时,常因不仔细导致包
8
+
9
+ ## 安装
10
+
11
+ ```bash
12
+ npm install --save-dev @vvi/rollup-external
13
+ ```
14
+
15
+ ## 使用
16
+
17
+ 在 `rollup.config.js` 文件中配置:
18
+
19
+ ```js
20
+ .... 其他引用
21
+ import { external } from '@vvi/rollup-external';
22
+ .... 其他代码逻辑
23
+
24
+ export default {
25
+ ... 其他配置,
26
+ external: external({
27
+ // 默认排除 package.json 中 dependencies 的依赖
28
+ // 排除 `node:`、`a-`、`color-pen` 、`@qqi`开头的依赖
29
+ exclude: ["node:", "a-" ,"color-pen", "@qqi/"],
30
+ // 忽略 `node:` 开头的包在 package.json 中未声明的 dependencies 的依赖
31
+ // 未配置改项,若项目中包含 `node:`
32
+ ignore: ["node:"],
33
+ // 一定要包含的依赖,将被打包入打包文件夹内
34
+ // 或是使用 `src/` 等路径,则报错 “依赖未被排除,打包关闭”
35
+ include: ['@qqi/copy-text','src/utils', 'src/dog']
36
+ }),
37
+ ... 其他配置,
38
+
39
+ }
40
+
41
+ ```
42
+
43
+ - 默认读取 `package.json` 中的 `dependencies` 和 `peerDependencies` 的依赖项作为 `exclude` 的值,即改值一般无需配置
44
+ - `include` 使用的全量对比,且优先级要远远高于 `exclude` 和 `ignore` 的配置,若在 `dependencies` 中配置了某依赖却又想将该依赖包含在打包文件内时可使用 `include`(但是需注意包会包含于 'node_modules' 文件夹下,保证 files 字段包含该项)
45
+ - `ignore` 用于忽略那些不包含于 'package.json' 的 `dependencies` 中却需要被排除的依赖,如 `node:`、`src/` 等路径的依赖。校验时以输入的字符串的 `startWith` 判断
46
+ - 可直接不使用参数,如果仅是想排除 'package.json' 文件中 `dependencies` 配置依赖 (怎么感觉有一股翻译腔)
47
+
48
+ ### 第二参数
49
+
50
+ 第二参数可控制在使用时在控制台展示简易日志。
51
+
52
+ 第二参数可接受的类型
53
+
54
+ - `boolean` : 为 `true` 将为每一个引入打印简易日志
55
+ - `string` : 将使用 `id.includes(str)` 的方式判定是否打印该条简易日志
56
+ - `string[]` :将为数组中的每一项使用 `id.includes(str)` 判定
package/cjs/index.js ADDED
@@ -0,0 +1,195 @@
1
+ 'use strict';
2
+
3
+ var copyText = require('@vvi/copy-text');
4
+ var node = require('@vvi/node');
5
+ var is = require('@vvi/is');
6
+ var pen$1 = require('@vvi/pen');
7
+
8
+ /** 一个展示 🖊️ */
9
+ const pen = pen$1.bgRedPen.blink.bold.yellow;
10
+ /**
11
+ * ## 依赖配置
12
+ *
13
+ * - `include` 包含的包(想打包入结果的包)。优先级最高(譬如:src/ 这种需要 rollup 处理的)
14
+ * - `ignore` 在排除的包却不需要在 dependencies 中的包,如: `node:stream` 等
15
+ * - `exclude` 排除且在依赖项中的包(在构建发布后,不会因为依赖项缺失而导致包版本失效)
16
+ *
17
+ * 注: `exclude` 是使用完全(<span style="color:#ff0;">Object.is()</span>)匹配模式
18
+ *
19
+ * @param options 配置项参数
20
+ * @param options.exclude 排除项,该项将默认包含 "package.json" 文件中的 `dependencies` 及 `peerDependencies` 的依赖包(包在忽略时使用 `Object.is` 比较)
21
+ * @param options.ignore 忽略项,该项与 `exclude` 类似,但是
22
+ * @param options.include
23
+ * @param logInfo 第二参数,可传入 `boolean`、`string`、`string[]` 类型,用户查看简单日志
24
+ * - 当传入为 `true` 时,所有的引入项都将打印日志
25
+ * - 当传入为单个字符串时,会打印包含该字符串的引入的日志(模糊匹配)
26
+ * - 当传入为字符串数组时,会分别打印包含对应字符串的引入的日志(模糊匹配)
27
+ *
28
+ */
29
+ function external(options,
30
+ /** 打印消息 */
31
+ logInfo = false) {
32
+ /** 是否打印消息 */
33
+ let logGlobal = false;
34
+ if (is.isString(logInfo))
35
+ logInfo = [logInfo];
36
+ if (logInfo === true || (is.isArray(logInfo) && logInfo.length > 0)) {
37
+ logGlobal = true;
38
+ }
39
+ const { exclude, ignore, include: _include } = parseParameter(options);
40
+ const cwd = process.cwd();
41
+ if (logGlobal) {
42
+ console.log('当前的工作路径:', pen$1.reversedPen(cwd));
43
+ }
44
+ /**
45
+ * ## 当前的状态值
46
+ *
47
+ * 该状态是值依赖是否将被排除
48
+ *
49
+ * - false 当前依赖被包含 (返回值为 `false` )
50
+ * - true 当前依赖被(返回值为 `true` )
51
+ */
52
+ const currentState = {};
53
+ /**
54
+ * # 装进到返回值中
55
+ */
56
+ const putPocket = ({ id, message, isLog }, res) => {
57
+ if (isLog) {
58
+ console.log(message);
59
+ }
60
+ currentState[id] = res;
61
+ beforeEnd(isLog);
62
+ return res;
63
+ };
64
+ /** 当前设定 */
65
+ const packageContent = node.getPackageJsonSync();
66
+ if (is.isNull(packageContent) || !packageContent?.content?.name)
67
+ throw new RangeError('package.json 文件不存在');
68
+ const packInfo = packageContent.content;
69
+ /** 已配置的依赖 */
70
+ const dependencies = Object.keys({
71
+ ...(packInfo.dependencies || {}),
72
+ ...(packInfo.peerDependencies || {}),
73
+ });
74
+ /** 包含于的依赖包的数组 */
75
+ const includeArray = _include.map((currentValue) => {
76
+ return currentValue.concat('/');
77
+ });
78
+ const ignorePkg = is.isEmptyArray(ignore)
79
+ ? dependencies
80
+ : [...ignore, ...dependencies];
81
+ /** 配置需要不打包进生产包的包名配置 (这就保证了 excludedRegExp 非空 ) */
82
+ const excludedPkg = is.isEmptyArray(exclude) ? ['node:'] : exclude;
83
+ /** 排除的依赖项的正则,仅检测是否包含为头 */
84
+ const excludedRegExp = new RegExp('^'.concat([...ignorePkg, ...excludedPkg].join('|^')));
85
+ if (logGlobal) {
86
+ console.log('排除的包', excludedPkg);
87
+ console.log('执行校验的数组', excludedRegExp);
88
+ console.log('执行包含包', _include);
89
+ console.log('执行包含的包子内容', includeArray);
90
+ }
91
+ const beforeEnd = (isLog) => isLog && (console.log(), console.groupEnd());
92
+ /**
93
+ * 实际执行的文件
94
+ */
95
+ return (id, parentId, isHandle) => {
96
+ /** 是否可打印 */
97
+ const isLog = logInfo === true ||
98
+ (is.isArray(logInfo) && logInfo.some(e => id?.includes(e)));
99
+ if (isLog) {
100
+ console.log();
101
+ console.groupCollapsed('本次检测的 id:', pen$1.magentaPen(id));
102
+ console.log('当前提供的 id 是否为文件', node.fileExist(node.pathJoin(cwd, id)) ? '✅' : '❌');
103
+ console.log(`该 id(${pen$1.cyanPen(id)})是否为文件:${node.fileExist(node.pathJoin(cwd, id)) ? '✅' : '❌'}`);
104
+ parentId &&
105
+ console.log(`该 id(${pen$1.cyanPen(id)})调用父级:${pen$1.brightYellowPen(parentId)}`);
106
+ console.log(`该 id(${pen$1.cyanPen(id)})是否已处理:${pen$1.bgBlackPen(isHandle)}`);
107
+ }
108
+ /** 有父级设定的值 */
109
+ if (parentId && is.isBoolean(currentState[parentId])) {
110
+ const res = currentState[parentId];
111
+ return putPocket({
112
+ id,
113
+ message: `跟随父级 「${parentId}」 的设定值 {${res}}`,
114
+ isLog,
115
+ }, res);
116
+ }
117
+ if (id.startsWith(cwd) && node.fileExist(id)) {
118
+ return putPocket({ id, message: '是存在的绝对路径的文件', isLog }, false);
119
+ }
120
+ else if (node.fileExist(node.pathJoin(cwd, id))) {
121
+ return putPocket({ id, message: '是存在的相对路径的文件', isLog }, false);
122
+ }
123
+ if (_include.includes(id) || includeArray.some(e => id.startsWith(e))) {
124
+ // 包存在于 included 中,直接交给 rollup 处理
125
+ return putPocket({
126
+ id,
127
+ message: `${pen$1.cyanPen(id)} 被显式声明打(进)包`,
128
+ isLog,
129
+ }, false);
130
+ }
131
+ // 重制识别位置
132
+ excludedRegExp.lastIndex = 0;
133
+ /** 是否在设定排除之外(包含要忽略的包) */
134
+ const result = excludedRegExp.test(id);
135
+ /// 保证排除的包纯在于
136
+ if (is.isTrue(result)) {
137
+ if (
138
+ // 检测到了包名存在于配置中
139
+ is.isFalse(dependencies.includes(id)) &&
140
+ ignorePkg.every(e => !id.startsWith(e))) {
141
+ const msg = `${pen(id)} ${copy(id)} 依赖被排除打包却未在 package.json 中配置`;
142
+ if (isLog) {
143
+ console.error(msg);
144
+ }
145
+ node._p(msg);
146
+ process.exit(1);
147
+ }
148
+ }
149
+ // 包不存在于配置中,但是却是非本地包
150
+ else if (/^[^./]/g.test(id)) {
151
+ const msg = `${pen(id)} ${copy(id)} 依赖未被排除,打包关闭`;
152
+ if (isLog) {
153
+ console.error(msg);
154
+ }
155
+ node._p(msg);
156
+ process.exit(1);
157
+ }
158
+ return putPocket({ id, message: '', isLog }, result);
159
+ };
160
+ }
161
+ /**
162
+ * 复制
163
+ * @param str 待赋复制的文本
164
+ */
165
+ function copy(str) {
166
+ str = node.isWindows ? str.replace(/[\\]/gm, '\\\\') : str;
167
+ return copyText.copyTextToClipboard(str) === str ? pen$1.hexPen('#666') `已复制` : '';
168
+ }
169
+ /**
170
+ * 校验是否是字符串数组并返回格式化后标准的数组
171
+ * @param arr 待转化的数组
172
+ */
173
+ function isStrArr(arr) {
174
+ if (!is.isArray(arr))
175
+ return [];
176
+ if (is.isString(arr))
177
+ return [arr];
178
+ return arr.filter(e => is.isString(e) && !is.isBusinessEmptyString(e));
179
+ }
180
+ /**
181
+ * 解析参数
182
+ * @param options 参数项
183
+ * @param options.exclude 排除项
184
+ * @param options.ignore 忽略项
185
+ * @param options.include 包含项
186
+ */
187
+ function parseParameter(options) {
188
+ return {
189
+ exclude: isStrArr(options?.exclude),
190
+ ignore: isStrArr(options?.ignore),
191
+ include: isStrArr(options?.include),
192
+ };
193
+ }
194
+
195
+ exports.external = external;
package/es/index.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * ## 依赖配置
3
+ *
4
+ * - `include` 包含的包(想打包入结果的包)。优先级最高(譬如:src/ 这种需要 rollup 处理的)
5
+ * - `ignore` 在排除的包却不需要在 dependencies 中的包,如: `node:stream` 等
6
+ * - `exclude` 排除且在依赖项中的包(在构建发布后,不会因为依赖项缺失而导致包版本失效)
7
+ *
8
+ * 注: `exclude` 是使用完全(<span style="color:#ff0;">Object.is()</span>)匹配模式
9
+ *
10
+ * @param options 配置项参数
11
+ * @param options.exclude 排除项,该项将默认包含 "package.json" 文件中的 `dependencies` 及 `peerDependencies` 的依赖包(包在忽略时使用 `Object.is` 比较)
12
+ * @param options.ignore 忽略项,该项与 `exclude` 类似,但是
13
+ * @param options.include
14
+ * @param logInfo 第二参数,可传入 `boolean`、`string`、`string[]` 类型,用户查看简单日志
15
+ * - 当传入为 `true` 时,所有的引入项都将打印日志
16
+ * - 当传入为单个字符串时,会打印包含该字符串的引入的日志(模糊匹配)
17
+ * - 当传入为字符串数组时,会分别打印包含对应字符串的引入的日志(模糊匹配)
18
+ *
19
+ */
20
+ export declare function external(options?: {
21
+ /** 排除且在依赖项中的包(在构建发布后,不会因为依赖项缺失而导致包版本失效) */
22
+ exclude?: string[] | string;
23
+ /** 在排除的包却不需要在 dependencies 中的包,如: node:stream 等 */
24
+ ignore?: string[] | string;
25
+ /**
26
+ * 包含的包(打包入结果的包)。优先级最高(譬如:src/ 这种需要 rollup 处理的)。
27
+ *
28
+ * 但是该项不像 ignore 和 exclude 是 `startsWith` 匹配,该项是完整权等匹配 */
29
+ include?: string[] | string;
30
+ },
31
+ /** 打印消息 */
32
+ logInfo?: boolean | string | string[]): (id: string, parentId: string | undefined, isHandle: boolean) => boolean;
package/es/index.js ADDED
@@ -0,0 +1,193 @@
1
+ import { copyTextToClipboard } from '@vvi/copy-text';
2
+ import { getPackageJsonSync, fileExist, pathJoin, _p, isWindows } from '@vvi/node';
3
+ import { isString, isArray, isNull, isEmptyArray, isBoolean, isTrue, isFalse, isBusinessEmptyString } from '@vvi/is';
4
+ import { bgRedPen, reversedPen, magentaPen, cyanPen, brightYellowPen, bgBlackPen, hexPen } from '@vvi/pen';
5
+
6
+ /** 一个展示 🖊️ */
7
+ const pen = bgRedPen.blink.bold.yellow;
8
+ /**
9
+ * ## 依赖配置
10
+ *
11
+ * - `include` 包含的包(想打包入结果的包)。优先级最高(譬如:src/ 这种需要 rollup 处理的)
12
+ * - `ignore` 在排除的包却不需要在 dependencies 中的包,如: `node:stream` 等
13
+ * - `exclude` 排除且在依赖项中的包(在构建发布后,不会因为依赖项缺失而导致包版本失效)
14
+ *
15
+ * 注: `exclude` 是使用完全(<span style="color:#ff0;">Object.is()</span>)匹配模式
16
+ *
17
+ * @param options 配置项参数
18
+ * @param options.exclude 排除项,该项将默认包含 "package.json" 文件中的 `dependencies` 及 `peerDependencies` 的依赖包(包在忽略时使用 `Object.is` 比较)
19
+ * @param options.ignore 忽略项,该项与 `exclude` 类似,但是
20
+ * @param options.include
21
+ * @param logInfo 第二参数,可传入 `boolean`、`string`、`string[]` 类型,用户查看简单日志
22
+ * - 当传入为 `true` 时,所有的引入项都将打印日志
23
+ * - 当传入为单个字符串时,会打印包含该字符串的引入的日志(模糊匹配)
24
+ * - 当传入为字符串数组时,会分别打印包含对应字符串的引入的日志(模糊匹配)
25
+ *
26
+ */
27
+ function external(options,
28
+ /** 打印消息 */
29
+ logInfo = false) {
30
+ /** 是否打印消息 */
31
+ let logGlobal = false;
32
+ if (isString(logInfo))
33
+ logInfo = [logInfo];
34
+ if (logInfo === true || (isArray(logInfo) && logInfo.length > 0)) {
35
+ logGlobal = true;
36
+ }
37
+ const { exclude, ignore, include: _include } = parseParameter(options);
38
+ const cwd = process.cwd();
39
+ if (logGlobal) {
40
+ console.log('当前的工作路径:', reversedPen(cwd));
41
+ }
42
+ /**
43
+ * ## 当前的状态值
44
+ *
45
+ * 该状态是值依赖是否将被排除
46
+ *
47
+ * - false 当前依赖被包含 (返回值为 `false` )
48
+ * - true 当前依赖被(返回值为 `true` )
49
+ */
50
+ const currentState = {};
51
+ /**
52
+ * # 装进到返回值中
53
+ */
54
+ const putPocket = ({ id, message, isLog }, res) => {
55
+ if (isLog) {
56
+ console.log(message);
57
+ }
58
+ currentState[id] = res;
59
+ beforeEnd(isLog);
60
+ return res;
61
+ };
62
+ /** 当前设定 */
63
+ const packageContent = getPackageJsonSync();
64
+ if (isNull(packageContent) || !packageContent?.content?.name)
65
+ throw new RangeError('package.json 文件不存在');
66
+ const packInfo = packageContent.content;
67
+ /** 已配置的依赖 */
68
+ const dependencies = Object.keys({
69
+ ...(packInfo.dependencies || {}),
70
+ ...(packInfo.peerDependencies || {}),
71
+ });
72
+ /** 包含于的依赖包的数组 */
73
+ const includeArray = _include.map((currentValue) => {
74
+ return currentValue.concat('/');
75
+ });
76
+ const ignorePkg = isEmptyArray(ignore)
77
+ ? dependencies
78
+ : [...ignore, ...dependencies];
79
+ /** 配置需要不打包进生产包的包名配置 (这就保证了 excludedRegExp 非空 ) */
80
+ const excludedPkg = isEmptyArray(exclude) ? ['node:'] : exclude;
81
+ /** 排除的依赖项的正则,仅检测是否包含为头 */
82
+ const excludedRegExp = new RegExp('^'.concat([...ignorePkg, ...excludedPkg].join('|^')));
83
+ if (logGlobal) {
84
+ console.log('排除的包', excludedPkg);
85
+ console.log('执行校验的数组', excludedRegExp);
86
+ console.log('执行包含包', _include);
87
+ console.log('执行包含的包子内容', includeArray);
88
+ }
89
+ const beforeEnd = (isLog) => isLog && (console.log(), console.groupEnd());
90
+ /**
91
+ * 实际执行的文件
92
+ */
93
+ return (id, parentId, isHandle) => {
94
+ /** 是否可打印 */
95
+ const isLog = logInfo === true ||
96
+ (isArray(logInfo) && logInfo.some(e => id?.includes(e)));
97
+ if (isLog) {
98
+ console.log();
99
+ console.groupCollapsed('本次检测的 id:', magentaPen(id));
100
+ console.log('当前提供的 id 是否为文件', fileExist(pathJoin(cwd, id)) ? '✅' : '❌');
101
+ console.log(`该 id(${cyanPen(id)})是否为文件:${fileExist(pathJoin(cwd, id)) ? '✅' : '❌'}`);
102
+ parentId &&
103
+ console.log(`该 id(${cyanPen(id)})调用父级:${brightYellowPen(parentId)}`);
104
+ console.log(`该 id(${cyanPen(id)})是否已处理:${bgBlackPen(isHandle)}`);
105
+ }
106
+ /** 有父级设定的值 */
107
+ if (parentId && isBoolean(currentState[parentId])) {
108
+ const res = currentState[parentId];
109
+ return putPocket({
110
+ id,
111
+ message: `跟随父级 「${parentId}」 的设定值 {${res}}`,
112
+ isLog,
113
+ }, res);
114
+ }
115
+ if (id.startsWith(cwd) && fileExist(id)) {
116
+ return putPocket({ id, message: '是存在的绝对路径的文件', isLog }, false);
117
+ }
118
+ else if (fileExist(pathJoin(cwd, id))) {
119
+ return putPocket({ id, message: '是存在的相对路径的文件', isLog }, false);
120
+ }
121
+ if (_include.includes(id) || includeArray.some(e => id.startsWith(e))) {
122
+ // 包存在于 included 中,直接交给 rollup 处理
123
+ return putPocket({
124
+ id,
125
+ message: `${cyanPen(id)} 被显式声明打(进)包`,
126
+ isLog,
127
+ }, false);
128
+ }
129
+ // 重制识别位置
130
+ excludedRegExp.lastIndex = 0;
131
+ /** 是否在设定排除之外(包含要忽略的包) */
132
+ const result = excludedRegExp.test(id);
133
+ /// 保证排除的包纯在于
134
+ if (isTrue(result)) {
135
+ if (
136
+ // 检测到了包名存在于配置中
137
+ isFalse(dependencies.includes(id)) &&
138
+ ignorePkg.every(e => !id.startsWith(e))) {
139
+ const msg = `${pen(id)} ${copy(id)} 依赖被排除打包却未在 package.json 中配置`;
140
+ if (isLog) {
141
+ console.error(msg);
142
+ }
143
+ _p(msg);
144
+ process.exit(1);
145
+ }
146
+ }
147
+ // 包不存在于配置中,但是却是非本地包
148
+ else if (/^[^./]/g.test(id)) {
149
+ const msg = `${pen(id)} ${copy(id)} 依赖未被排除,打包关闭`;
150
+ if (isLog) {
151
+ console.error(msg);
152
+ }
153
+ _p(msg);
154
+ process.exit(1);
155
+ }
156
+ return putPocket({ id, message: '', isLog }, result);
157
+ };
158
+ }
159
+ /**
160
+ * 复制
161
+ * @param str 待赋复制的文本
162
+ */
163
+ function copy(str) {
164
+ str = isWindows ? str.replace(/[\\]/gm, '\\\\') : str;
165
+ return copyTextToClipboard(str) === str ? hexPen('#666') `已复制` : '';
166
+ }
167
+ /**
168
+ * 校验是否是字符串数组并返回格式化后标准的数组
169
+ * @param arr 待转化的数组
170
+ */
171
+ function isStrArr(arr) {
172
+ if (!isArray(arr))
173
+ return [];
174
+ if (isString(arr))
175
+ return [arr];
176
+ return arr.filter(e => isString(e) && !isBusinessEmptyString(e));
177
+ }
178
+ /**
179
+ * 解析参数
180
+ * @param options 参数项
181
+ * @param options.exclude 排除项
182
+ * @param options.ignore 忽略项
183
+ * @param options.include 包含项
184
+ */
185
+ function parseParameter(options) {
186
+ return {
187
+ exclude: isStrArr(options?.exclude),
188
+ ignore: isStrArr(options?.ignore),
189
+ include: isStrArr(options?.include),
190
+ };
191
+ }
192
+
193
+ export { external };
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@vvi/rollup-external",
3
+ "version": "1.1.2",
4
+ "type": "module",
5
+ "main": "cjs/index.js",
6
+ "module": "es/index.js",
7
+ "types": "es/index.d.ts",
8
+ "author": {
9
+ "name": "泥豆君",
10
+ "email": "Mr.MudBean@outlook.com",
11
+ "url": "https://mudbean.cn"
12
+ },
13
+ "description": "用于 rollup 打包 📦 时排除异己的工具 🔧",
14
+ "sideEffects": false,
15
+ "license": "MIT",
16
+ "files": [
17
+ "cjs",
18
+ "es",
19
+ "LICENSE",
20
+ "README.md",
21
+ "CHANGELOG.md"
22
+ ],
23
+ "exports": {
24
+ ".": {
25
+ "import": {
26
+ "default": "./es/index.js",
27
+ "types": "./es/index.d.ts"
28
+ },
29
+ "require": {
30
+ "default": "./cjs/index.js",
31
+ "types": "./es/index.d.ts"
32
+ }
33
+ }
34
+ },
35
+ "keywords": [
36
+ "rollup-external",
37
+ "mudbean",
38
+ "vvi"
39
+ ],
40
+ "homepage": "https://npm.lmssee.com/rollup-external",
41
+ "dependencies": {
42
+ "@vvi/copy-text": "^1.1.1",
43
+ "@vvi/is": "^2.0.5",
44
+ "@vvi/log": "^1.1.5",
45
+ "@vvi/node": "^4.4.3",
46
+ "@vvi/pen": "^3.0.2"
47
+ },
48
+ "bugs": {
49
+ "url": "https://github.com/MrMudBean/rollup-external/issues",
50
+ "email": "Mr.MudBean@outlook.com"
51
+ },
52
+ "repository": {
53
+ "type": "git",
54
+ "url": "git+https://github.com/MrMudBean/rollup-external.git"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public",
58
+ "registry": "https://registry.npmjs.org/"
59
+ },
60
+ "browserslist": [
61
+ "node>=18.0.0"
62
+ ],
63
+ "engines": {
64
+ "node": ">=18.0.0"
65
+ }
66
+ }