@meng-xi/vite-plugin 0.1.1 → 0.1.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/README-en.md +522 -610
- package/README.md +496 -584
- package/dist/common/compress/index.cjs +1 -0
- package/dist/common/compress/index.d.cts +23 -0
- package/dist/common/compress/index.d.mts +23 -0
- package/dist/common/compress/index.d.ts +23 -0
- package/dist/common/compress/index.mjs +1 -0
- package/dist/common/format/index.cjs +1 -1
- package/dist/common/format/index.d.cts +33 -1
- package/dist/common/format/index.d.mts +33 -1
- package/dist/common/format/index.d.ts +33 -1
- package/dist/common/format/index.mjs +1 -1
- package/dist/common/fs/index.cjs +1 -1
- package/dist/common/fs/index.d.cts +70 -2
- package/dist/common/fs/index.d.mts +70 -2
- package/dist/common/fs/index.d.ts +70 -2
- package/dist/common/fs/index.mjs +1 -1
- package/dist/common/index.cjs +1 -1
- package/dist/common/index.d.cts +4 -2
- package/dist/common/index.d.mts +4 -2
- package/dist/common/index.d.ts +4 -2
- package/dist/common/index.mjs +1 -1
- package/dist/common/path/index.cjs +1 -0
- package/dist/common/path/index.d.cts +22 -0
- package/dist/common/path/index.d.mts +22 -0
- package/dist/common/path/index.d.ts +22 -0
- package/dist/common/path/index.mjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +6 -2
- package/dist/index.d.mts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.mjs +1 -1
- package/dist/plugins/bundleAnalyzer/index.cjs +235 -0
- package/dist/plugins/bundleAnalyzer/index.d.cts +215 -0
- package/dist/plugins/bundleAnalyzer/index.d.mts +215 -0
- package/dist/plugins/bundleAnalyzer/index.d.ts +215 -0
- package/dist/plugins/bundleAnalyzer/index.mjs +235 -0
- package/dist/plugins/compressAssets/index.cjs +1 -0
- package/dist/plugins/compressAssets/index.d.cts +132 -0
- package/dist/plugins/compressAssets/index.d.mts +132 -0
- package/dist/plugins/compressAssets/index.d.ts +132 -0
- package/dist/plugins/compressAssets/index.mjs +1 -0
- package/dist/plugins/generateRouter/index.cjs +4 -4
- package/dist/plugins/generateRouter/index.mjs +1 -1
- package/dist/plugins/generateVersion/index.cjs +1 -1
- package/dist/plugins/generateVersion/index.mjs +1 -1
- package/dist/plugins/htmlInject/index.cjs +7 -7
- package/dist/plugins/index.cjs +1 -1
- package/dist/plugins/index.d.cts +2 -0
- package/dist/plugins/index.d.mts +2 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.mjs +1 -1
- package/dist/plugins/loadingManager/index.cjs +1 -1
- package/dist/plugins/loadingManager/index.mjs +1 -1
- package/package.json +24 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const node_zlib=require("node:zlib"),promises=require("node:stream/promises"),node_stream=require("node:stream");async function calculateGzipSize(e){const t=typeof e=="string"?Buffer.from(e,"utf-8"):e,r=[],n=node_zlib.createGzip({level:9}),o=new node_stream.Transform({transform(s,a,i){r.push(s),i()}});return await promises.pipeline(node_stream.Readable.from(t),n,o),Buffer.concat(r).length}exports.calculateGzipSize=calculateGzipSize;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 计算给定数据的 gzip 压缩后大小
|
|
3
|
+
*
|
|
4
|
+
* @async
|
|
5
|
+
* @param {Buffer | string} data - 待计算的数据
|
|
6
|
+
* @returns {Promise<number>} gzip 压缩后的字节大小
|
|
7
|
+
*
|
|
8
|
+
* @description 将数据通过 gzip 流压缩后计算压缩体积,
|
|
9
|
+
* 用于估算网络传输时的实际体积。
|
|
10
|
+
* 使用最高压缩级别(level: 9)以获得最小的压缩体积。
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const gzipSize = await calculateGzipSize(Buffer.from('hello world'))
|
|
15
|
+
* console.log(`gzip 大小: ${gzipSize} 字节`)
|
|
16
|
+
*
|
|
17
|
+
* const stringData = 'some long string content...'
|
|
18
|
+
* const size = await calculateGzipSize(stringData)
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare function calculateGzipSize(data: Buffer | string): Promise<number>;
|
|
22
|
+
|
|
23
|
+
export { calculateGzipSize };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 计算给定数据的 gzip 压缩后大小
|
|
3
|
+
*
|
|
4
|
+
* @async
|
|
5
|
+
* @param {Buffer | string} data - 待计算的数据
|
|
6
|
+
* @returns {Promise<number>} gzip 压缩后的字节大小
|
|
7
|
+
*
|
|
8
|
+
* @description 将数据通过 gzip 流压缩后计算压缩体积,
|
|
9
|
+
* 用于估算网络传输时的实际体积。
|
|
10
|
+
* 使用最高压缩级别(level: 9)以获得最小的压缩体积。
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const gzipSize = await calculateGzipSize(Buffer.from('hello world'))
|
|
15
|
+
* console.log(`gzip 大小: ${gzipSize} 字节`)
|
|
16
|
+
*
|
|
17
|
+
* const stringData = 'some long string content...'
|
|
18
|
+
* const size = await calculateGzipSize(stringData)
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare function calculateGzipSize(data: Buffer | string): Promise<number>;
|
|
22
|
+
|
|
23
|
+
export { calculateGzipSize };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 计算给定数据的 gzip 压缩后大小
|
|
3
|
+
*
|
|
4
|
+
* @async
|
|
5
|
+
* @param {Buffer | string} data - 待计算的数据
|
|
6
|
+
* @returns {Promise<number>} gzip 压缩后的字节大小
|
|
7
|
+
*
|
|
8
|
+
* @description 将数据通过 gzip 流压缩后计算压缩体积,
|
|
9
|
+
* 用于估算网络传输时的实际体积。
|
|
10
|
+
* 使用最高压缩级别(level: 9)以获得最小的压缩体积。
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const gzipSize = await calculateGzipSize(Buffer.from('hello world'))
|
|
15
|
+
* console.log(`gzip 大小: ${gzipSize} 字节`)
|
|
16
|
+
*
|
|
17
|
+
* const stringData = 'some long string content...'
|
|
18
|
+
* const size = await calculateGzipSize(stringData)
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare function calculateGzipSize(data: Buffer | string): Promise<number>;
|
|
22
|
+
|
|
23
|
+
export { calculateGzipSize };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createGzip as i}from"node:zlib";import{pipeline as p}from"node:stream/promises";import{Transform as m,Readable as c}from"node:stream";async function l(e){const o=typeof e=="string"?Buffer.from(e,"utf-8"):e,r=[],t=i({level:9}),f=new m({transform(n,u,a){r.push(n),a()}});return await p(c.from(o),t,f),Buffer.concat(r).length}export{l as calculateGzipSize};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const crypto=require("crypto");function padNumber(e,t=2){return e.toString().padStart(t,"0")}function generateRandomHash(e=8){const t=Math.max(1,Math.min(64,e));return crypto.randomBytes(Math.ceil(t/2)).toString("hex").slice(0,t)}function getDateFormatParams(e=new Date){return{YYYY:e.getFullYear().toString(),YY:e.getFullYear().toString().slice(-2),MM:padNumber(e.getMonth()+1),DD:padNumber(e.getDate()),HH:padNumber(e.getHours()),mm:padNumber(e.getMinutes()),ss:padNumber(e.getSeconds()),SSS:padNumber(e.getMilliseconds(),3),timestamp:e.getTime().toString()}}function formatDate(e,t){const r=getDateFormatParams(e);let
|
|
1
|
+
"use strict";const crypto=require("crypto"),a=require("node:path");function _interopDefaultCompat(e){return e&&typeof e=="object"&&"default"in e?e.default:e}const a__default=_interopDefaultCompat(a);function padNumber(e,t=2){return e.toString().padStart(t,"0")}function generateRandomHash(e=8){const t=Math.max(1,Math.min(64,e));return crypto.randomBytes(Math.ceil(t/2)).toString("hex").slice(0,t)}function getDateFormatParams(e=new Date){return{YYYY:e.getFullYear().toString(),YY:e.getFullYear().toString().slice(-2),MM:padNumber(e.getMonth()+1),DD:padNumber(e.getDate()),HH:padNumber(e.getHours()),mm:padNumber(e.getMinutes()),ss:padNumber(e.getSeconds()),SSS:padNumber(e.getMilliseconds(),3),timestamp:e.getTime().toString()}}function formatDate(e,t){const r=getDateFormatParams(e);let o=t;for(const[n,s]of Object.entries(r))o=o.replace(new RegExp(`\\{${n}\\}`,"g"),s);return o}function parseTemplate(e,t){let r=e;for(const[o,n]of Object.entries(t))r=r.replace(new RegExp(`\\{${o}\\}`,"g"),n);return r}function toCamelCase(e,t=/[/-]/){return e.replace(/^\/+/,"").split(t).filter(Boolean).map((r,o)=>o===0?r.toLowerCase():r.charAt(0).toUpperCase()+r.slice(1).toLowerCase()).join("")}function toPascalCase(e,t=/[/-]/){return e.replace(/^\/+/,"").split(t).filter(Boolean).map(r=>r.charAt(0).toUpperCase()+r.slice(1).toLowerCase()).join("")}function stripJsonComments(e){return e.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"")}function escapeHtmlAttr(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function formatFileSize(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/(1024*1024)).toFixed(2)}MB`}function getExtension(e){return a__default.extname(e).toLowerCase()}exports.escapeHtmlAttr=escapeHtmlAttr,exports.formatDate=formatDate,exports.formatFileSize=formatFileSize,exports.generateRandomHash=generateRandomHash,exports.getDateFormatParams=getDateFormatParams,exports.getExtension=getExtension,exports.padNumber=padNumber,exports.parseTemplate=parseTemplate,exports.stripJsonComments=stripJsonComments,exports.toCamelCase=toCamelCase,exports.toPascalCase=toPascalCase;
|
|
@@ -151,6 +151,38 @@ declare function stripJsonComments(jsonString: string): string;
|
|
|
151
151
|
* ```
|
|
152
152
|
*/
|
|
153
153
|
declare function escapeHtmlAttr(str: string): string;
|
|
154
|
+
/**
|
|
155
|
+
* 将字节数格式化为人类可读的文件大小字符串
|
|
156
|
+
*
|
|
157
|
+
* @param {number} bytes - 文件大小(字节)
|
|
158
|
+
* @returns {string} 格式化后的文件大小字符串
|
|
159
|
+
*
|
|
160
|
+
* @description 转换规则:
|
|
161
|
+
* - 小于 1KB:显示为 `xB`(如 `512B`)
|
|
162
|
+
* - 小于 1MB:显示为 `x.xKB`(如 `1.5KB`)
|
|
163
|
+
* - 大于等于 1MB:显示为 `x.xxMB`(如 `2.35MB`)
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* formatFileSize(512) // '512B'
|
|
168
|
+
* formatFileSize(1536) // '1.5KB'
|
|
169
|
+
* formatFileSize(2461726) // '2.35MB'
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
declare function formatFileSize(bytes: number): string;
|
|
173
|
+
/**
|
|
174
|
+
* 获取文件扩展名
|
|
175
|
+
*
|
|
176
|
+
* @param {string} filePath - 文件路径
|
|
177
|
+
* @returns {string} 小写的文件扩展名(如 '.js')
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* getExtension('dist/app.js') // '.js'
|
|
182
|
+
* getExtension('dist/style.CSS') // '.css'
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
declare function getExtension(filePath: string): string;
|
|
154
186
|
|
|
155
|
-
export { escapeHtmlAttr, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, stripJsonComments, toCamelCase, toPascalCase };
|
|
187
|
+
export { escapeHtmlAttr, formatDate, formatFileSize, generateRandomHash, getDateFormatParams, getExtension, padNumber, parseTemplate, stripJsonComments, toCamelCase, toPascalCase };
|
|
156
188
|
export type { DateFormatOptions };
|
|
@@ -151,6 +151,38 @@ declare function stripJsonComments(jsonString: string): string;
|
|
|
151
151
|
* ```
|
|
152
152
|
*/
|
|
153
153
|
declare function escapeHtmlAttr(str: string): string;
|
|
154
|
+
/**
|
|
155
|
+
* 将字节数格式化为人类可读的文件大小字符串
|
|
156
|
+
*
|
|
157
|
+
* @param {number} bytes - 文件大小(字节)
|
|
158
|
+
* @returns {string} 格式化后的文件大小字符串
|
|
159
|
+
*
|
|
160
|
+
* @description 转换规则:
|
|
161
|
+
* - 小于 1KB:显示为 `xB`(如 `512B`)
|
|
162
|
+
* - 小于 1MB:显示为 `x.xKB`(如 `1.5KB`)
|
|
163
|
+
* - 大于等于 1MB:显示为 `x.xxMB`(如 `2.35MB`)
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* formatFileSize(512) // '512B'
|
|
168
|
+
* formatFileSize(1536) // '1.5KB'
|
|
169
|
+
* formatFileSize(2461726) // '2.35MB'
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
declare function formatFileSize(bytes: number): string;
|
|
173
|
+
/**
|
|
174
|
+
* 获取文件扩展名
|
|
175
|
+
*
|
|
176
|
+
* @param {string} filePath - 文件路径
|
|
177
|
+
* @returns {string} 小写的文件扩展名(如 '.js')
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* getExtension('dist/app.js') // '.js'
|
|
182
|
+
* getExtension('dist/style.CSS') // '.css'
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
declare function getExtension(filePath: string): string;
|
|
154
186
|
|
|
155
|
-
export { escapeHtmlAttr, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, stripJsonComments, toCamelCase, toPascalCase };
|
|
187
|
+
export { escapeHtmlAttr, formatDate, formatFileSize, generateRandomHash, getDateFormatParams, getExtension, padNumber, parseTemplate, stripJsonComments, toCamelCase, toPascalCase };
|
|
156
188
|
export type { DateFormatOptions };
|
|
@@ -151,6 +151,38 @@ declare function stripJsonComments(jsonString: string): string;
|
|
|
151
151
|
* ```
|
|
152
152
|
*/
|
|
153
153
|
declare function escapeHtmlAttr(str: string): string;
|
|
154
|
+
/**
|
|
155
|
+
* 将字节数格式化为人类可读的文件大小字符串
|
|
156
|
+
*
|
|
157
|
+
* @param {number} bytes - 文件大小(字节)
|
|
158
|
+
* @returns {string} 格式化后的文件大小字符串
|
|
159
|
+
*
|
|
160
|
+
* @description 转换规则:
|
|
161
|
+
* - 小于 1KB:显示为 `xB`(如 `512B`)
|
|
162
|
+
* - 小于 1MB:显示为 `x.xKB`(如 `1.5KB`)
|
|
163
|
+
* - 大于等于 1MB:显示为 `x.xxMB`(如 `2.35MB`)
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* formatFileSize(512) // '512B'
|
|
168
|
+
* formatFileSize(1536) // '1.5KB'
|
|
169
|
+
* formatFileSize(2461726) // '2.35MB'
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
declare function formatFileSize(bytes: number): string;
|
|
173
|
+
/**
|
|
174
|
+
* 获取文件扩展名
|
|
175
|
+
*
|
|
176
|
+
* @param {string} filePath - 文件路径
|
|
177
|
+
* @returns {string} 小写的文件扩展名(如 '.js')
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* getExtension('dist/app.js') // '.js'
|
|
182
|
+
* getExtension('dist/style.CSS') // '.css'
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
declare function getExtension(filePath: string): string;
|
|
154
186
|
|
|
155
|
-
export { escapeHtmlAttr, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, stripJsonComments, toCamelCase, toPascalCase };
|
|
187
|
+
export { escapeHtmlAttr, formatDate, formatFileSize, generateRandomHash, getDateFormatParams, getExtension, padNumber, parseTemplate, stripJsonComments, toCamelCase, toPascalCase };
|
|
156
188
|
export type { DateFormatOptions };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{randomBytes as
|
|
1
|
+
import{randomBytes as c}from"crypto";import l from"node:path";function o(e,t=2){return e.toString().padStart(t,"0")}function p(e=8){const t=Math.max(1,Math.min(64,e));return c(Math.ceil(t/2)).toString("hex").slice(0,t)}function i(e=new Date){return{YYYY:e.getFullYear().toString(),YY:e.getFullYear().toString().slice(-2),MM:o(e.getMonth()+1),DD:o(e.getDate()),HH:o(e.getHours()),mm:o(e.getMinutes()),ss:o(e.getSeconds()),SSS:o(e.getMilliseconds(),3),timestamp:e.getTime().toString()}}function g(e,t){const r=i(e);let n=t;for(const[a,s]of Object.entries(r))n=n.replace(new RegExp(`\\{${a}\\}`,"g"),s);return n}function m(e,t){let r=e;for(const[n,a]of Object.entries(t))r=r.replace(new RegExp(`\\{${n}\\}`,"g"),a);return r}function u(e,t=/[/-]/){return e.replace(/^\/+/,"").split(t).filter(Boolean).map((r,n)=>n===0?r.toLowerCase():r.charAt(0).toUpperCase()+r.slice(1).toLowerCase()).join("")}function f(e,t=/[/-]/){return e.replace(/^\/+/,"").split(t).filter(Boolean).map(r=>r.charAt(0).toUpperCase()+r.slice(1).toLowerCase()).join("")}function S(e){return e.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"")}function C(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function x(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/(1024*1024)).toFixed(2)}MB`}function M(e){return l.extname(e).toLowerCase()}export{C as escapeHtmlAttr,g as formatDate,x as formatFileSize,p as generateRandomHash,i as getDateFormatParams,M as getExtension,o as padNumber,m as parseTemplate,S as stripJsonComments,u as toCamelCase,f as toPascalCase};
|
package/dist/common/fs/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const s=require("fs"),
|
|
1
|
+
"use strict";const s=require("fs"),f=require("path");function _interopDefaultCompat(u){return u&&typeof u=="object"&&"default"in u?u.default:u}const s__default=_interopDefaultCompat(s),f__default=_interopDefaultCompat(f),S=10;async function checkSourceExists(u){try{await s__default.promises.access(u,s__default.constants.F_OK)}catch(t){const e=t;throw e.code==="ENOENT"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6E90\u6587\u4EF6\u4E0D\u5B58\u5728 - ${u}`):e.code==="EACCES"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BBF\u95EE\u6E90\u6587\u4EF6 - ${u}`):new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u68C0\u67E5\u6E90\u6587\u4EF6\u65F6\u51FA\u9519 - ${u}\uFF0C\u9519\u8BEF\uFF1A${e.message}`)}}async function ensureTargetDir(u){try{await s__default.promises.mkdir(u,{recursive:!0})}catch(t){const e=t;throw e.code==="EACCES"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u521B\u5EFA\u76EE\u6807\u76EE\u5F55 - ${u}`):new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u521B\u5EFA\u76EE\u6807\u76EE\u5F55\u65F6\u51FA\u9519 - ${u}\uFF0C\u9519\u8BEF\uFF1A${e.message}`)}}async function readDirRecursive(u,t){const e=await s__default.promises.readdir(u,{withFileTypes:!0}),r=[];for(const n of e){const a=f__default.join(u,n.name),F=n.isFile(),c=n.isDirectory();if(r.push({path:a,isFile:F,isDirectory:c}),c&&t){const l=await readDirRecursive(a,t);r.push(...l)}}return r}async function shouldUpdateFile(u,t){try{const[e,r]=await Promise.all([s__default.promises.stat(u),s__default.promises.stat(t)]);return e.mtimeMs>r.mtimeMs||e.size!==r.size}catch{return!0}}async function fileExists(u){try{return await s__default.promises.access(u,s__default.constants.F_OK),!0}catch{return!1}}async function runWithConcurrency(u,t,e){const r=[];let n=0;async function a(){for(;n<u.length;){const c=n++,l=await t(u[c]);r[c]=l}}const F=Array(Math.min(e,u.length)).fill(null).map(()=>a());return await Promise.all(F),r}async function copySourceToTarget(u,t,e){const r=Date.now(),{recursive:n,overwrite:a,incremental:F=!1,parallelLimit:c=S}=e;let l=0,p=0,E=0;if((await s__default.promises.stat(u)).isDirectory()){await ensureTargetDir(t);const o=await readDirRecursive(u,n),w=o.filter(i=>i.isFile);E=o.filter(i=>i.isDirectory).length;const h=new Set;for(const i of w){const D=f__default.relative(u,i.path),y=f__default.dirname(f__default.join(t,D));h.add(y)}await Promise.all([...h].map(i=>ensureTargetDir(i)));const A=await runWithConcurrency(w,async i=>{const D=f__default.relative(u,i.path),y=f__default.join(t,D);let m=a;return m||(m=!await fileExists(y)),F&&m&&(m=await shouldUpdateFile(i.path,y)),m?(await s__default.promises.copyFile(i.path,y),{copied:!0,skipped:!1}):{copied:!1,skipped:!0}},c);for(const i of A)i.copied&&l++,i.skipped&&p++}else{await ensureTargetDir(f__default.dirname(t));let o=a;o||(o=!await fileExists(t)),F&&o&&(o=await shouldUpdateFile(u,t)),o?(await s__default.promises.copyFile(u,t),l++):p++}const d=Date.now()-r;return{copiedFiles:l,skippedFiles:p,copiedDirs:E,executionTime:d}}async function writeFileContent(u,t){try{await s__default.promises.writeFile(u,t,"utf-8")}catch(e){const r=e;throw r.code==="EACCES"?new Error(`\u5199\u5165\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u5199\u5165\u6587\u4EF6 - ${u}`):new Error(`\u5199\u5165\u6587\u4EF6\u5931\u8D25\uFF1A\u5199\u5165\u6587\u4EF6\u65F6\u51FA\u9519 - ${u}\uFF0C\u9519\u8BEF\uFF1A${r.message}`)}}async function readFileContent(u){try{return await s__default.promises.readFile(u,"utf-8")}catch(t){const e=t;throw e.code==="EACCES"?new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BFB\u53D6\u6587\u4EF6 - ${u}`):new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u8BFB\u53D6\u6587\u4EF6\u65F6\u51FA\u9519 - ${u}\uFF0C\u9519\u8BEF\uFF1A${e.message}`)}}function readFileSync(u){try{return s__default.readFileSync(u,"utf-8")}catch(t){const e=t;throw e.code==="EACCES"?new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BFB\u53D6\u6587\u4EF6 - ${u}`):new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u8BFB\u53D6\u6587\u4EF6\u65F6\u51FA\u9519 - ${u}\uFF0C\u9519\u8BEF\uFF1A${e.message}`)}}async function scanDirectory(u,t={}){const{includeExtensions:e=[],excludePatterns:r=[],filter:n}=t,a=[];async function F(c){const l=await s__default.promises.readdir(c,{withFileTypes:!0});for(const p of l){const E=f__default.join(c,p.name);if(p.isDirectory()){await F(E);continue}if(!p.isFile()||r.some(w=>w.startsWith("*")?E.endsWith(w.slice(1)):E.includes(w)))continue;const d=f__default.extname(p.name).toLowerCase();if(e.length>0&&!e.includes(d))continue;const o=await s__default.promises.stat(E);n&&!n(E,d,o.size)||a.push({filePath:E,size:o.size,extension:d})}}return await F(u),a}async function writeJsonReport(u,t,e=2){await writeFileContent(u,JSON.stringify(t,null,e))}exports.checkSourceExists=checkSourceExists,exports.copySourceToTarget=copySourceToTarget,exports.ensureTargetDir=ensureTargetDir,exports.fileExists=fileExists,exports.readDirRecursive=readDirRecursive,exports.readFileContent=readFileContent,exports.readFileSync=readFileSync,exports.runWithConcurrency=runWithConcurrency,exports.scanDirectory=scanDirectory,exports.shouldUpdateFile=shouldUpdateFile,exports.writeFileContent=writeFileContent,exports.writeJsonReport=writeJsonReport;
|
|
@@ -145,6 +145,74 @@ declare function readFileContent(filePath: string): Promise<string>;
|
|
|
145
145
|
* @deprecated 请使用异步版本 readFileContent
|
|
146
146
|
*/
|
|
147
147
|
declare function readFileSync(filePath: string): string;
|
|
148
|
+
/**
|
|
149
|
+
* 扫描目录中的文件信息
|
|
150
|
+
*/
|
|
151
|
+
interface ScannedFile {
|
|
152
|
+
/** 文件绝对路径 */
|
|
153
|
+
filePath: string;
|
|
154
|
+
/** 文件大小(字节) */
|
|
155
|
+
size: number;
|
|
156
|
+
/** 文件扩展名(小写,含点号,如 '.js') */
|
|
157
|
+
extension: string;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* 目录扫描选项
|
|
161
|
+
*/
|
|
162
|
+
interface ScanDirectoryOptions {
|
|
163
|
+
/** 包含的文件扩展名列表,为空则包含所有 */
|
|
164
|
+
includeExtensions?: string[];
|
|
165
|
+
/** 排除的路径模式列表 */
|
|
166
|
+
excludePatterns?: string[];
|
|
167
|
+
/** 自定义文件过滤函数,返回 true 表示包含该文件 */
|
|
168
|
+
filter?: (filePath: string, extension: string, size: number) => boolean;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* 递归扫描目录,收集所有文件信息
|
|
172
|
+
*
|
|
173
|
+
* @async
|
|
174
|
+
* @param {string} dirPath - 要扫描的目录路径
|
|
175
|
+
* @param {ScanDirectoryOptions} options - 扫描选项
|
|
176
|
+
* @returns {Promise<ScannedFile[]>} 文件信息列表
|
|
177
|
+
*
|
|
178
|
+
* @description 递归遍历指定目录下的所有文件,收集每个文件的大小和扩展名信息,
|
|
179
|
+
* 支持按扩展名、路径模式和自定义过滤函数进行过滤。
|
|
180
|
+
* 这是通用的目录扫描函数,可被不同插件复用。
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* // 扫描所有 .js 文件
|
|
185
|
+
* const jsFiles = await scanDirectory('dist', { includeExtensions: ['.js'] })
|
|
186
|
+
*
|
|
187
|
+
* // 排除 node_modules
|
|
188
|
+
* const files = await scanDirectory('dist', { excludePatterns: ['node_modules'] })
|
|
189
|
+
*
|
|
190
|
+
* // 使用自定义过滤
|
|
191
|
+
* const largeFiles = await scanDirectory('dist', {
|
|
192
|
+
* filter: (filePath, ext, size) => size > 1024
|
|
193
|
+
* })
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
declare function scanDirectory(dirPath: string, options?: ScanDirectoryOptions): Promise<ScannedFile[]>;
|
|
197
|
+
/**
|
|
198
|
+
* 将数据写入 JSON 文件
|
|
199
|
+
*
|
|
200
|
+
* @async
|
|
201
|
+
* @param {string} filePath - 输出文件路径
|
|
202
|
+
* @param {object} data - 要序列化的数据对象
|
|
203
|
+
* @param {number} [indent=2] - JSON 缩进空格数
|
|
204
|
+
* @returns {Promise<void>}
|
|
205
|
+
*
|
|
206
|
+
* @description 将任意数据对象序列化为 JSON 格式并写入文件。
|
|
207
|
+
* 内部使用 writeFileContent 确保统一的错误处理。
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* await writeJsonReport('dist/report.json', { timestamp: Date.now(), stats: [] })
|
|
212
|
+
* await writeJsonReport('dist/report.json', data, 4)
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
declare function writeJsonReport(filePath: string, data: object, indent?: number): Promise<void>;
|
|
148
216
|
|
|
149
|
-
export { checkSourceExists, copySourceToTarget, ensureTargetDir, fileExists, readDirRecursive, readFileContent, readFileSync, runWithConcurrency, shouldUpdateFile, writeFileContent };
|
|
150
|
-
export type { CopyOptions, CopyResult };
|
|
217
|
+
export { checkSourceExists, copySourceToTarget, ensureTargetDir, fileExists, readDirRecursive, readFileContent, readFileSync, runWithConcurrency, scanDirectory, shouldUpdateFile, writeFileContent, writeJsonReport };
|
|
218
|
+
export type { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile };
|
|
@@ -145,6 +145,74 @@ declare function readFileContent(filePath: string): Promise<string>;
|
|
|
145
145
|
* @deprecated 请使用异步版本 readFileContent
|
|
146
146
|
*/
|
|
147
147
|
declare function readFileSync(filePath: string): string;
|
|
148
|
+
/**
|
|
149
|
+
* 扫描目录中的文件信息
|
|
150
|
+
*/
|
|
151
|
+
interface ScannedFile {
|
|
152
|
+
/** 文件绝对路径 */
|
|
153
|
+
filePath: string;
|
|
154
|
+
/** 文件大小(字节) */
|
|
155
|
+
size: number;
|
|
156
|
+
/** 文件扩展名(小写,含点号,如 '.js') */
|
|
157
|
+
extension: string;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* 目录扫描选项
|
|
161
|
+
*/
|
|
162
|
+
interface ScanDirectoryOptions {
|
|
163
|
+
/** 包含的文件扩展名列表,为空则包含所有 */
|
|
164
|
+
includeExtensions?: string[];
|
|
165
|
+
/** 排除的路径模式列表 */
|
|
166
|
+
excludePatterns?: string[];
|
|
167
|
+
/** 自定义文件过滤函数,返回 true 表示包含该文件 */
|
|
168
|
+
filter?: (filePath: string, extension: string, size: number) => boolean;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* 递归扫描目录,收集所有文件信息
|
|
172
|
+
*
|
|
173
|
+
* @async
|
|
174
|
+
* @param {string} dirPath - 要扫描的目录路径
|
|
175
|
+
* @param {ScanDirectoryOptions} options - 扫描选项
|
|
176
|
+
* @returns {Promise<ScannedFile[]>} 文件信息列表
|
|
177
|
+
*
|
|
178
|
+
* @description 递归遍历指定目录下的所有文件,收集每个文件的大小和扩展名信息,
|
|
179
|
+
* 支持按扩展名、路径模式和自定义过滤函数进行过滤。
|
|
180
|
+
* 这是通用的目录扫描函数,可被不同插件复用。
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* // 扫描所有 .js 文件
|
|
185
|
+
* const jsFiles = await scanDirectory('dist', { includeExtensions: ['.js'] })
|
|
186
|
+
*
|
|
187
|
+
* // 排除 node_modules
|
|
188
|
+
* const files = await scanDirectory('dist', { excludePatterns: ['node_modules'] })
|
|
189
|
+
*
|
|
190
|
+
* // 使用自定义过滤
|
|
191
|
+
* const largeFiles = await scanDirectory('dist', {
|
|
192
|
+
* filter: (filePath, ext, size) => size > 1024
|
|
193
|
+
* })
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
declare function scanDirectory(dirPath: string, options?: ScanDirectoryOptions): Promise<ScannedFile[]>;
|
|
197
|
+
/**
|
|
198
|
+
* 将数据写入 JSON 文件
|
|
199
|
+
*
|
|
200
|
+
* @async
|
|
201
|
+
* @param {string} filePath - 输出文件路径
|
|
202
|
+
* @param {object} data - 要序列化的数据对象
|
|
203
|
+
* @param {number} [indent=2] - JSON 缩进空格数
|
|
204
|
+
* @returns {Promise<void>}
|
|
205
|
+
*
|
|
206
|
+
* @description 将任意数据对象序列化为 JSON 格式并写入文件。
|
|
207
|
+
* 内部使用 writeFileContent 确保统一的错误处理。
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* await writeJsonReport('dist/report.json', { timestamp: Date.now(), stats: [] })
|
|
212
|
+
* await writeJsonReport('dist/report.json', data, 4)
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
declare function writeJsonReport(filePath: string, data: object, indent?: number): Promise<void>;
|
|
148
216
|
|
|
149
|
-
export { checkSourceExists, copySourceToTarget, ensureTargetDir, fileExists, readDirRecursive, readFileContent, readFileSync, runWithConcurrency, shouldUpdateFile, writeFileContent };
|
|
150
|
-
export type { CopyOptions, CopyResult };
|
|
217
|
+
export { checkSourceExists, copySourceToTarget, ensureTargetDir, fileExists, readDirRecursive, readFileContent, readFileSync, runWithConcurrency, scanDirectory, shouldUpdateFile, writeFileContent, writeJsonReport };
|
|
218
|
+
export type { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile };
|
|
@@ -145,6 +145,74 @@ declare function readFileContent(filePath: string): Promise<string>;
|
|
|
145
145
|
* @deprecated 请使用异步版本 readFileContent
|
|
146
146
|
*/
|
|
147
147
|
declare function readFileSync(filePath: string): string;
|
|
148
|
+
/**
|
|
149
|
+
* 扫描目录中的文件信息
|
|
150
|
+
*/
|
|
151
|
+
interface ScannedFile {
|
|
152
|
+
/** 文件绝对路径 */
|
|
153
|
+
filePath: string;
|
|
154
|
+
/** 文件大小(字节) */
|
|
155
|
+
size: number;
|
|
156
|
+
/** 文件扩展名(小写,含点号,如 '.js') */
|
|
157
|
+
extension: string;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* 目录扫描选项
|
|
161
|
+
*/
|
|
162
|
+
interface ScanDirectoryOptions {
|
|
163
|
+
/** 包含的文件扩展名列表,为空则包含所有 */
|
|
164
|
+
includeExtensions?: string[];
|
|
165
|
+
/** 排除的路径模式列表 */
|
|
166
|
+
excludePatterns?: string[];
|
|
167
|
+
/** 自定义文件过滤函数,返回 true 表示包含该文件 */
|
|
168
|
+
filter?: (filePath: string, extension: string, size: number) => boolean;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* 递归扫描目录,收集所有文件信息
|
|
172
|
+
*
|
|
173
|
+
* @async
|
|
174
|
+
* @param {string} dirPath - 要扫描的目录路径
|
|
175
|
+
* @param {ScanDirectoryOptions} options - 扫描选项
|
|
176
|
+
* @returns {Promise<ScannedFile[]>} 文件信息列表
|
|
177
|
+
*
|
|
178
|
+
* @description 递归遍历指定目录下的所有文件,收集每个文件的大小和扩展名信息,
|
|
179
|
+
* 支持按扩展名、路径模式和自定义过滤函数进行过滤。
|
|
180
|
+
* 这是通用的目录扫描函数,可被不同插件复用。
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* // 扫描所有 .js 文件
|
|
185
|
+
* const jsFiles = await scanDirectory('dist', { includeExtensions: ['.js'] })
|
|
186
|
+
*
|
|
187
|
+
* // 排除 node_modules
|
|
188
|
+
* const files = await scanDirectory('dist', { excludePatterns: ['node_modules'] })
|
|
189
|
+
*
|
|
190
|
+
* // 使用自定义过滤
|
|
191
|
+
* const largeFiles = await scanDirectory('dist', {
|
|
192
|
+
* filter: (filePath, ext, size) => size > 1024
|
|
193
|
+
* })
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
declare function scanDirectory(dirPath: string, options?: ScanDirectoryOptions): Promise<ScannedFile[]>;
|
|
197
|
+
/**
|
|
198
|
+
* 将数据写入 JSON 文件
|
|
199
|
+
*
|
|
200
|
+
* @async
|
|
201
|
+
* @param {string} filePath - 输出文件路径
|
|
202
|
+
* @param {object} data - 要序列化的数据对象
|
|
203
|
+
* @param {number} [indent=2] - JSON 缩进空格数
|
|
204
|
+
* @returns {Promise<void>}
|
|
205
|
+
*
|
|
206
|
+
* @description 将任意数据对象序列化为 JSON 格式并写入文件。
|
|
207
|
+
* 内部使用 writeFileContent 确保统一的错误处理。
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* await writeJsonReport('dist/report.json', { timestamp: Date.now(), stats: [] })
|
|
212
|
+
* await writeJsonReport('dist/report.json', data, 4)
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
declare function writeJsonReport(filePath: string, data: object, indent?: number): Promise<void>;
|
|
148
216
|
|
|
149
|
-
export { checkSourceExists, copySourceToTarget, ensureTargetDir, fileExists, readDirRecursive, readFileContent, readFileSync, runWithConcurrency, shouldUpdateFile, writeFileContent };
|
|
150
|
-
export type { CopyOptions, CopyResult };
|
|
217
|
+
export { checkSourceExists, copySourceToTarget, ensureTargetDir, fileExists, readDirRecursive, readFileContent, readFileSync, runWithConcurrency, scanDirectory, shouldUpdateFile, writeFileContent, writeJsonReport };
|
|
218
|
+
export type { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile };
|
package/dist/common/fs/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import r from"fs";import w from"path";const T=10;async function k(u){try{await r.promises.access(u,r.constants.F_OK)}catch(t){const e=t;throw e.code==="ENOENT"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6E90\u6587\u4EF6\u4E0D\u5B58\u5728 - ${u}`):e.code==="EACCES"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BBF\u95EE\u6E90\u6587\u4EF6 - ${u}`):new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u68C0\u67E5\u6E90\u6587\u4EF6\u65F6\u51FA\u9519 - ${u}\uFF0C\u9519\u8BEF\uFF1A${e.message}`)}}async function D(u){try{await r.promises.mkdir(u,{recursive:!0})}catch(t){const e=t;throw e.code==="EACCES"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u521B\u5EFA\u76EE\u6807\u76EE\u5F55 - ${u}`):new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u521B\u5EFA\u76EE\u6807\u76EE\u5F55\u65F6\u51FA\u9519 - ${u}\uFF0C\u9519\u8BEF\uFF1A${e.message}`)}}async function h(u,t){const e=await r.promises.readdir(u,{withFileTypes:!0}),i=[];for(const n of e){const a=w.join(u,n.name),F=n.isFile(),c=n.isDirectory();if(i.push({path:a,isFile:F,isDirectory:c}),c&&t){const E=await h(a,t);i.push(...E)}}return i}async function B(u,t){try{const[e,i]=await Promise.all([r.promises.stat(u),r.promises.stat(t)]);return e.mtimeMs>i.mtimeMs||e.size!==i.size}catch{return!0}}async function C(u){try{return await r.promises.access(u,r.constants.F_OK),!0}catch{return!1}}async function g(u,t,e){const i=[];let n=0;async function a(){for(;n<u.length;){const c=n++,E=await t(u[c]);i[c]=E}}const F=Array(Math.min(e,u.length)).fill(null).map(()=>a());return await Promise.all(F),i}async function v(u,t,e){const i=Date.now(),{recursive:n,overwrite:a,incremental:F=!1,parallelLimit:c=T}=e;let E=0,p=0,l=0;if((await r.promises.stat(u)).isDirectory()){await D(t);const o=await h(u,n),f=o.filter(s=>s.isFile);l=o.filter(s=>s.isDirectory).length;const $=new Set;for(const s of f){const A=w.relative(u,s.path),y=w.dirname(w.join(t,A));$.add(y)}await Promise.all([...$].map(s=>D(s)));const x=await g(f,async s=>{const A=w.relative(u,s.path),y=w.join(t,A);let d=a;return d||(d=!await C(y)),F&&d&&(d=await B(s.path,y)),d?(await r.promises.copyFile(s.path,y),{copied:!0,skipped:!1}):{copied:!1,skipped:!0}},c);for(const s of x)s.copied&&E++,s.skipped&&p++}else{await D(w.dirname(t));let o=a;o||(o=!await C(t)),F&&o&&(o=await B(u,t)),o?(await r.promises.copyFile(u,t),E++):p++}const m=Date.now()-i;return{copiedFiles:E,skippedFiles:p,copiedDirs:l,executionTime:m}}async function S(u,t){try{await r.promises.writeFile(u,t,"utf-8")}catch(e){const i=e;throw i.code==="EACCES"?new Error(`\u5199\u5165\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u5199\u5165\u6587\u4EF6 - ${u}`):new Error(`\u5199\u5165\u6587\u4EF6\u5931\u8D25\uFF1A\u5199\u5165\u6587\u4EF6\u65F6\u51FA\u9519 - ${u}\uFF0C\u9519\u8BEF\uFF1A${i.message}`)}}async function z(u){try{return await r.promises.readFile(u,"utf-8")}catch(t){const e=t;throw e.code==="EACCES"?new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BFB\u53D6\u6587\u4EF6 - ${u}`):new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u8BFB\u53D6\u6587\u4EF6\u65F6\u51FA\u9519 - ${u}\uFF0C\u9519\u8BEF\uFF1A${e.message}`)}}function P(u){try{return r.readFileSync(u,"utf-8")}catch(t){const e=t;throw e.code==="EACCES"?new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BFB\u53D6\u6587\u4EF6 - ${u}`):new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u8BFB\u53D6\u6587\u4EF6\u65F6\u51FA\u9519 - ${u}\uFF0C\u9519\u8BEF\uFF1A${e.message}`)}}async function j(u,t={}){const{includeExtensions:e=[],excludePatterns:i=[],filter:n}=t,a=[];async function F(c){const E=await r.promises.readdir(c,{withFileTypes:!0});for(const p of E){const l=w.join(c,p.name);if(p.isDirectory()){await F(l);continue}if(!p.isFile()||i.some(f=>f.startsWith("*")?l.endsWith(f.slice(1)):l.includes(f)))continue;const m=w.extname(p.name).toLowerCase();if(e.length>0&&!e.includes(m))continue;const o=await r.promises.stat(l);n&&!n(l,m,o.size)||a.push({filePath:l,size:o.size,extension:m})}}return await F(u),a}async function O(u,t,e=2){await S(u,JSON.stringify(t,null,e))}export{k as checkSourceExists,v as copySourceToTarget,D as ensureTargetDir,C as fileExists,h as readDirRecursive,z as readFileContent,P as readFileSync,g as runWithConcurrency,j as scanDirectory,B as shouldUpdateFile,S as writeFileContent,O as writeJsonReport};
|
package/dist/common/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const common_compress_index=require("./compress/index.cjs"),common_format_index=require("./format/index.cjs"),common_fs_index=require("./fs/index.cjs"),common_html_index=require("./html/index.cjs"),common_object_index=require("./object/index.cjs"),common_path_index=require("./path/index.cjs"),common_script_index=require("./script/index.cjs"),validator=require("../shared/vite-plugin.Bcg6RW2N.cjs"),common_validation_index=require("./validation/index.cjs");require("node:zlib"),require("node:stream/promises"),require("node:stream"),require("crypto"),require("node:path"),require("fs"),require("path"),exports.calculateGzipSize=common_compress_index.calculateGzipSize,exports.escapeHtmlAttr=common_format_index.escapeHtmlAttr,exports.formatDate=common_format_index.formatDate,exports.formatFileSize=common_format_index.formatFileSize,exports.generateRandomHash=common_format_index.generateRandomHash,exports.getDateFormatParams=common_format_index.getDateFormatParams,exports.getExtension=common_format_index.getExtension,exports.padNumber=common_format_index.padNumber,exports.parseTemplate=common_format_index.parseTemplate,exports.stripJsonComments=common_format_index.stripJsonComments,exports.toCamelCase=common_format_index.toCamelCase,exports.toPascalCase=common_format_index.toPascalCase,exports.checkSourceExists=common_fs_index.checkSourceExists,exports.copySourceToTarget=common_fs_index.copySourceToTarget,exports.ensureTargetDir=common_fs_index.ensureTargetDir,exports.fileExists=common_fs_index.fileExists,exports.readDirRecursive=common_fs_index.readDirRecursive,exports.readFileContent=common_fs_index.readFileContent,exports.readFileSync=common_fs_index.readFileSync,exports.runWithConcurrency=common_fs_index.runWithConcurrency,exports.scanDirectory=common_fs_index.scanDirectory,exports.shouldUpdateFile=common_fs_index.shouldUpdateFile,exports.writeFileContent=common_fs_index.writeFileContent,exports.writeJsonReport=common_fs_index.writeJsonReport,exports.injectBeforeTag=common_html_index.injectBeforeTag,exports.injectBeforeTagWithFallback=common_html_index.injectBeforeTagWithFallback,exports.injectHeadAndBody=common_html_index.injectHeadAndBody,exports.injectHtmlByPriority=common_html_index.injectHtmlByPriority,exports.deepMerge=common_object_index.deepMerge,exports.isNodeModule=common_path_index.isNodeModule,exports.containsScriptTag=common_script_index.containsScriptTag,exports.makeCallback=common_script_index.makeCallback,exports.validateIdentifierName=common_script_index.validateIdentifierName,exports.Validator=validator.Validator,exports.validateCallbackFields=common_validation_index.validateCallbackFields,exports.validateEnumValue=common_validation_index.validateEnumValue,exports.validateGlobalName=common_validation_index.validateGlobalName,exports.validateNestedDuration=common_validation_index.validateNestedDuration,exports.validateNoScriptInTemplate=common_validation_index.validateNoScriptInTemplate,exports.validateNonNegativeNumber=common_validation_index.validateNonNegativeNumber;
|
package/dist/common/index.d.cts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { DateFormatOptions, escapeHtmlAttr, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, stripJsonComments, toCamelCase, toPascalCase } from './format/index.cjs';
|
|
1
|
+
export { calculateGzipSize } from './compress/index.cjs';
|
|
2
|
+
export { DateFormatOptions, escapeHtmlAttr, formatDate, formatFileSize, generateRandomHash, getDateFormatParams, getExtension, padNumber, parseTemplate, stripJsonComments, toCamelCase, toPascalCase } from './format/index.cjs';
|
|
3
|
+
export { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile, checkSourceExists, copySourceToTarget, ensureTargetDir, fileExists, readDirRecursive, readFileContent, readFileSync, runWithConcurrency, scanDirectory, shouldUpdateFile, writeFileContent, writeJsonReport } from './fs/index.cjs';
|
|
3
4
|
export { DualInjectResult, HtmlInjectResult, injectBeforeTag, injectBeforeTagWithFallback, injectHeadAndBody, injectHtmlByPriority } from './html/index.cjs';
|
|
4
5
|
export { deepMerge } from './object/index.cjs';
|
|
6
|
+
export { isNodeModule } from './path/index.cjs';
|
|
5
7
|
export { containsScriptTag, makeCallback, validateIdentifierName } from './script/index.cjs';
|
|
6
8
|
export { V as Validator } from '../shared/vite-plugin.DRRlWY8P.cjs';
|
|
7
9
|
export { validateCallbackFields, validateEnumValue, validateGlobalName, validateNestedDuration, validateNoScriptInTemplate, validateNonNegativeNumber } from './validation/index.cjs';
|
package/dist/common/index.d.mts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { DateFormatOptions, escapeHtmlAttr, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, stripJsonComments, toCamelCase, toPascalCase } from './format/index.mjs';
|
|
1
|
+
export { calculateGzipSize } from './compress/index.mjs';
|
|
2
|
+
export { DateFormatOptions, escapeHtmlAttr, formatDate, formatFileSize, generateRandomHash, getDateFormatParams, getExtension, padNumber, parseTemplate, stripJsonComments, toCamelCase, toPascalCase } from './format/index.mjs';
|
|
3
|
+
export { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile, checkSourceExists, copySourceToTarget, ensureTargetDir, fileExists, readDirRecursive, readFileContent, readFileSync, runWithConcurrency, scanDirectory, shouldUpdateFile, writeFileContent, writeJsonReport } from './fs/index.mjs';
|
|
3
4
|
export { DualInjectResult, HtmlInjectResult, injectBeforeTag, injectBeforeTagWithFallback, injectHeadAndBody, injectHtmlByPriority } from './html/index.mjs';
|
|
4
5
|
export { deepMerge } from './object/index.mjs';
|
|
6
|
+
export { isNodeModule } from './path/index.mjs';
|
|
5
7
|
export { containsScriptTag, makeCallback, validateIdentifierName } from './script/index.mjs';
|
|
6
8
|
export { V as Validator } from '../shared/vite-plugin.DRRlWY8P.mjs';
|
|
7
9
|
export { validateCallbackFields, validateEnumValue, validateGlobalName, validateNestedDuration, validateNoScriptInTemplate, validateNonNegativeNumber } from './validation/index.mjs';
|
package/dist/common/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { DateFormatOptions, escapeHtmlAttr, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, stripJsonComments, toCamelCase, toPascalCase } from './format/index.js';
|
|
1
|
+
export { calculateGzipSize } from './compress/index.js';
|
|
2
|
+
export { DateFormatOptions, escapeHtmlAttr, formatDate, formatFileSize, generateRandomHash, getDateFormatParams, getExtension, padNumber, parseTemplate, stripJsonComments, toCamelCase, toPascalCase } from './format/index.js';
|
|
3
|
+
export { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile, checkSourceExists, copySourceToTarget, ensureTargetDir, fileExists, readDirRecursive, readFileContent, readFileSync, runWithConcurrency, scanDirectory, shouldUpdateFile, writeFileContent, writeJsonReport } from './fs/index.js';
|
|
3
4
|
export { DualInjectResult, HtmlInjectResult, injectBeforeTag, injectBeforeTagWithFallback, injectHeadAndBody, injectHtmlByPriority } from './html/index.js';
|
|
4
5
|
export { deepMerge } from './object/index.js';
|
|
6
|
+
export { isNodeModule } from './path/index.js';
|
|
5
7
|
export { containsScriptTag, makeCallback, validateIdentifierName } from './script/index.js';
|
|
6
8
|
export { V as Validator } from '../shared/vite-plugin.DRRlWY8P.js';
|
|
7
9
|
export { validateCallbackFields, validateEnumValue, validateGlobalName, validateNestedDuration, validateNoScriptInTemplate, validateNonNegativeNumber } from './validation/index.js';
|
package/dist/common/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{
|
|
1
|
+
export{calculateGzipSize}from"./compress/index.mjs";export{escapeHtmlAttr,formatDate,formatFileSize,generateRandomHash,getDateFormatParams,getExtension,padNumber,parseTemplate,stripJsonComments,toCamelCase,toPascalCase}from"./format/index.mjs";export{checkSourceExists,copySourceToTarget,ensureTargetDir,fileExists,readDirRecursive,readFileContent,readFileSync,runWithConcurrency,scanDirectory,shouldUpdateFile,writeFileContent,writeJsonReport}from"./fs/index.mjs";export{injectBeforeTag,injectBeforeTagWithFallback,injectHeadAndBody,injectHtmlByPriority}from"./html/index.mjs";export{deepMerge}from"./object/index.mjs";export{isNodeModule}from"./path/index.mjs";export{containsScriptTag,makeCallback,validateIdentifierName}from"./script/index.mjs";export{V as Validator}from"../shared/vite-plugin.DcExl6jd.mjs";export{validateCallbackFields,validateEnumValue,validateGlobalName,validateNestedDuration,validateNoScriptInTemplate,validateNonNegativeNumber}from"./validation/index.mjs";import"node:zlib";import"node:stream/promises";import"node:stream";import"crypto";import"node:path";import"fs";import"path";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function isNodeModule(s){return s.includes("node_modules")||s.startsWith("\0")||s.startsWith("virtual:")}exports.isNodeModule=isNodeModule;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 判断模块 ID 是否来自 node_modules
|
|
3
|
+
*
|
|
4
|
+
* @param {string} moduleId - 模块标识符
|
|
5
|
+
* @returns {boolean} 是否来自 node_modules
|
|
6
|
+
*
|
|
7
|
+
* @description 检测规则:
|
|
8
|
+
* - 路径中包含 `node_modules` 的模块
|
|
9
|
+
* - 以 `\0` 开头的虚拟模块(Rollup 内部模块)
|
|
10
|
+
* - 以 `virtual:` 开头的虚拟模块
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* isNodeModule('node_modules/lodash/index.js') // true
|
|
15
|
+
* isNodeModule('src/utils/helper.ts') // false
|
|
16
|
+
* isNodeModule('\0some-virtual-module') // true
|
|
17
|
+
* isNodeModule('virtual:import-meta-env') // true
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare function isNodeModule(moduleId: string): boolean;
|
|
21
|
+
|
|
22
|
+
export { isNodeModule };
|