@ainc/fs 0.1.19 → 0.1.21
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.md +5 -19
- package/bin/download.mjs +40 -0
- package/dist/concurrency.d.ts +43 -0
- package/dist/concurrency.js +99 -0
- package/dist/dirname.js +3 -2
- package/dist/download.d.ts +30 -0
- package/dist/download.js +205 -0
- package/dist/downloadFile.d.ts +6 -0
- package/dist/downloadFile.js +83 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +12 -6
- package/dist/jsonc.js +1 -1
- package/dist/lookup.d.ts +1 -1
- package/dist/md5.d.ts +6 -0
- package/dist/md5.js +23 -0
- package/dist/relative.d.ts +7 -1
- package/dist/resolveFile.js +6 -8
- package/dist/retry.d.ts +6 -0
- package/dist/retry.js +50 -0
- package/dist/stat.d.ts +1 -1
- package/esm/concurrency.mjs +96 -0
- package/esm/copy.mjs +49 -0
- package/esm/dirname.mjs +26 -0
- package/esm/download.mjs +203 -0
- package/esm/downloadFile.mjs +81 -0
- package/esm/findUp.mjs +33 -0
- package/esm/index.mjs +26 -0
- package/esm/jsonc.mjs +29 -0
- package/esm/lookup.mjs +48 -0
- package/esm/md5.mjs +21 -0
- package/esm/mkdir.mjs +37 -0
- package/esm/readFile.mjs +21 -0
- package/esm/relative.mjs +66 -0
- package/esm/resolveFile.mjs +36 -0
- package/esm/retry.mjs +48 -0
- package/esm/rm.mjs +32 -0
- package/esm/stat.mjs +45 -0
- package/esm/stripComments.mjs +118 -0
- package/esm/writeFile.mjs +39 -0
- package/package.json +29 -10
- /package/dist/{utils/stripComments.d.ts → stripComments.d.ts} +0 -0
- /package/dist/{utils/stripComments.js → stripComments.js} +0 -0
package/esm/lookup.mjs
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*****************************************
|
|
3
|
+
* Created by edonet@163.com
|
|
4
|
+
* Created on 2025-05-29 20:56:24
|
|
5
|
+
*****************************************
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
/**
|
|
9
|
+
*****************************************
|
|
10
|
+
* 加载依赖
|
|
11
|
+
*****************************************
|
|
12
|
+
*/
|
|
13
|
+
import { resolve as resolvePath } from 'node:path';
|
|
14
|
+
import { isFile } from './stat.mjs';
|
|
15
|
+
import { dirname } from './dirname.mjs';
|
|
16
|
+
/**
|
|
17
|
+
*****************************************
|
|
18
|
+
* 查找最近的文件
|
|
19
|
+
*****************************************
|
|
20
|
+
*/
|
|
21
|
+
export function lookup(name, options) {
|
|
22
|
+
const opts = { cache: new Map(), resolve: isFile, ...options };
|
|
23
|
+
const dir = opts.from ? resolvePath(opts.from) : process.cwd();
|
|
24
|
+
// 查找文件
|
|
25
|
+
return find(name, dir, opts);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
*****************************************
|
|
29
|
+
* 查找最近的文件
|
|
30
|
+
*****************************************
|
|
31
|
+
*/
|
|
32
|
+
function find(name, dir, options) {
|
|
33
|
+
const { cache, resolve } = options;
|
|
34
|
+
if (!dir) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
// 解析路径
|
|
38
|
+
const path = resolvePath(dir, name);
|
|
39
|
+
if (cache.has(path)) {
|
|
40
|
+
return cache.get(path);
|
|
41
|
+
}
|
|
42
|
+
// 查找文件
|
|
43
|
+
const result = resolve(path, dir) || find(name, dirname(dir), options);
|
|
44
|
+
// 缓存结果
|
|
45
|
+
cache.set(path, result);
|
|
46
|
+
// 返回结果
|
|
47
|
+
return result;
|
|
48
|
+
}
|
package/esm/md5.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*****************************************
|
|
3
|
+
* Created by edonet@163.com
|
|
4
|
+
* Created on 2026-02-25 16:27:15
|
|
5
|
+
*****************************************
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
/**
|
|
9
|
+
*****************************************
|
|
10
|
+
* 加载依赖
|
|
11
|
+
*****************************************
|
|
12
|
+
*/
|
|
13
|
+
import { createHash } from 'node:crypto';
|
|
14
|
+
/**
|
|
15
|
+
*****************************************
|
|
16
|
+
* 生成 md5 签名
|
|
17
|
+
*****************************************
|
|
18
|
+
*/
|
|
19
|
+
export function md5(str) {
|
|
20
|
+
return createHash('md5').update(str, 'utf8').digest('hex');
|
|
21
|
+
}
|
package/esm/mkdir.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*****************************************
|
|
3
|
+
* Created by edonet@163.com
|
|
4
|
+
* Created on 2025-05-25 11:15:33
|
|
5
|
+
*****************************************
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
/**
|
|
9
|
+
*****************************************
|
|
10
|
+
* 创建目录
|
|
11
|
+
*****************************************
|
|
12
|
+
*/
|
|
13
|
+
import { mkdirSync, unlinkSync } from 'node:fs';
|
|
14
|
+
import { stat } from './stat.mjs';
|
|
15
|
+
/**
|
|
16
|
+
*****************************************
|
|
17
|
+
* 创建目录
|
|
18
|
+
*****************************************
|
|
19
|
+
*/
|
|
20
|
+
export function mkdir(dir, options) {
|
|
21
|
+
const stats = stat(dir);
|
|
22
|
+
if (!stats) {
|
|
23
|
+
return (mkdirSync(dir, { recursive: true }), true);
|
|
24
|
+
}
|
|
25
|
+
// 目录已存在
|
|
26
|
+
if (stats.isDirectory()) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
// 非强制模式下,返回失败
|
|
30
|
+
if (!options || !options.force) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
// 删除文件
|
|
34
|
+
unlinkSync(dir);
|
|
35
|
+
// 创建目录
|
|
36
|
+
return (mkdirSync(dir, { recursive: true }), true);
|
|
37
|
+
}
|
package/esm/readFile.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*****************************************
|
|
3
|
+
* Created by edonet@163.com
|
|
4
|
+
* Created on 2023-12-31 10:20:08
|
|
5
|
+
*****************************************
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
/**
|
|
9
|
+
*****************************************
|
|
10
|
+
* 加载依赖
|
|
11
|
+
*****************************************
|
|
12
|
+
*/
|
|
13
|
+
import { readFileSync } from 'node:fs';
|
|
14
|
+
/**
|
|
15
|
+
*****************************************
|
|
16
|
+
* 读取文件
|
|
17
|
+
*****************************************
|
|
18
|
+
*/
|
|
19
|
+
export function readFile(path) {
|
|
20
|
+
return readFileSync(path, 'utf8');
|
|
21
|
+
}
|
package/esm/relative.mjs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*****************************************
|
|
3
|
+
* Created by edonet@163.com
|
|
4
|
+
* Created on 2023-12-31 09:16:34
|
|
5
|
+
*****************************************
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
/**
|
|
9
|
+
*****************************************
|
|
10
|
+
* 加载依赖
|
|
11
|
+
*****************************************
|
|
12
|
+
*/
|
|
13
|
+
import { sep, relative as relativePath } from 'node:path';
|
|
14
|
+
/**
|
|
15
|
+
*****************************************
|
|
16
|
+
* 判断是否为相对路径
|
|
17
|
+
*****************************************
|
|
18
|
+
*/
|
|
19
|
+
export function isRelative(id) {
|
|
20
|
+
// 判断是否以 '.' 开头
|
|
21
|
+
if (id.charAt(0) !== '.') {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
// 获取字符
|
|
25
|
+
const c1 = id.charAt(1);
|
|
26
|
+
// 以 './' 开头
|
|
27
|
+
if (c1 === '/' || c1 === '') {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
else if (c1 !== '.') {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
// 获取下一字符
|
|
34
|
+
const c2 = id.charAt(2);
|
|
35
|
+
// 判断以
|
|
36
|
+
return c2 === '/' || c2 === '';
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
*****************************************
|
|
40
|
+
* 获取相对路径
|
|
41
|
+
*****************************************
|
|
42
|
+
*/
|
|
43
|
+
export const relativeFrom = sep === '/'
|
|
44
|
+
? relativePath
|
|
45
|
+
: function relativeFrom(from, to) {
|
|
46
|
+
return relativePath(from, to).replace(/\\/g, '/');
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
*****************************************
|
|
50
|
+
* 获取相对路径
|
|
51
|
+
*****************************************
|
|
52
|
+
*/
|
|
53
|
+
export function relative(from, to) {
|
|
54
|
+
const result = relativeFrom(from, to);
|
|
55
|
+
// 当前路径
|
|
56
|
+
if (!result) {
|
|
57
|
+
return './';
|
|
58
|
+
}
|
|
59
|
+
// 样式化路径
|
|
60
|
+
if (result === '.' || result === '..' || result.endsWith('/..')) {
|
|
61
|
+
return result + '/';
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
return result.charAt(0) === '.' ? result : './' + result;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*****************************************
|
|
3
|
+
* Created by edonet@163.com
|
|
4
|
+
* Created on 2023-12-31 09:29:59
|
|
5
|
+
*****************************************
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
/**
|
|
9
|
+
*****************************************
|
|
10
|
+
* 加载依赖
|
|
11
|
+
*****************************************
|
|
12
|
+
*/
|
|
13
|
+
import { resolve } from 'node:path';
|
|
14
|
+
import { isFile } from './stat.mjs';
|
|
15
|
+
/**
|
|
16
|
+
*****************************************
|
|
17
|
+
* 解析文件
|
|
18
|
+
*****************************************
|
|
19
|
+
*/
|
|
20
|
+
export function resolveFile(path, extensions) {
|
|
21
|
+
const dest = resolve(path);
|
|
22
|
+
if (isFile(dest)) {
|
|
23
|
+
return dest;
|
|
24
|
+
}
|
|
25
|
+
// 不再查找
|
|
26
|
+
if (!extensions || !extensions.length) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// 遍历扩展名
|
|
30
|
+
for (let i = 0; i < extensions.length; ++i) {
|
|
31
|
+
const file = dest + extensions[i];
|
|
32
|
+
if (isFile(file)) {
|
|
33
|
+
return file;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
package/esm/retry.mjs
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*****************************************
|
|
3
|
+
* Created by edonet@163.com
|
|
4
|
+
* Created on 2026-03-01 20:06:58
|
|
5
|
+
*****************************************
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
/**
|
|
9
|
+
*****************************************
|
|
10
|
+
* 重试
|
|
11
|
+
*****************************************
|
|
12
|
+
*/
|
|
13
|
+
export function retry(times, handler) {
|
|
14
|
+
let count = 1;
|
|
15
|
+
// 重试处理
|
|
16
|
+
for (;;) {
|
|
17
|
+
try {
|
|
18
|
+
const res = handler();
|
|
19
|
+
if (res instanceof Promise) {
|
|
20
|
+
return res.catch(tryPromise);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return res;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
if (count++ >= times) {
|
|
28
|
+
throw err;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// 异步重试
|
|
33
|
+
async function tryPromise(err) {
|
|
34
|
+
if (count++ >= times) {
|
|
35
|
+
throw err;
|
|
36
|
+
}
|
|
37
|
+
for (;;) {
|
|
38
|
+
try {
|
|
39
|
+
return await handler();
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
if (count++ >= times) {
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
package/esm/rm.mjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*****************************************
|
|
3
|
+
* Created by edonet@163.com
|
|
4
|
+
* Created on 2023-12-31 09:26:54
|
|
5
|
+
*****************************************
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
/**
|
|
9
|
+
*****************************************
|
|
10
|
+
* 加载依赖
|
|
11
|
+
*****************************************
|
|
12
|
+
*/
|
|
13
|
+
import { unlinkSync, rmSync } from 'node:fs';
|
|
14
|
+
import { stat } from './stat.mjs';
|
|
15
|
+
/**
|
|
16
|
+
*****************************************
|
|
17
|
+
* 删除文件或目录
|
|
18
|
+
*****************************************
|
|
19
|
+
*/
|
|
20
|
+
export function rm(path) {
|
|
21
|
+
const stats = stat(path);
|
|
22
|
+
// 不存在文件
|
|
23
|
+
if (!stats) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// 非目录
|
|
27
|
+
if (!stats.isDirectory()) {
|
|
28
|
+
return unlinkSync(path);
|
|
29
|
+
}
|
|
30
|
+
// 遍历文件
|
|
31
|
+
rmSync(path, { force: true, recursive: true });
|
|
32
|
+
}
|
package/esm/stat.mjs
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*****************************************
|
|
3
|
+
* Created by edonet@163.com
|
|
4
|
+
* Created on 2023-12-31 09:11:28
|
|
5
|
+
*****************************************
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
/**
|
|
9
|
+
*****************************************
|
|
10
|
+
* 加载依赖
|
|
11
|
+
*****************************************
|
|
12
|
+
*/
|
|
13
|
+
import { statSync } from 'node:fs';
|
|
14
|
+
/**
|
|
15
|
+
*****************************************
|
|
16
|
+
* 获取文件状态
|
|
17
|
+
*****************************************
|
|
18
|
+
*/
|
|
19
|
+
export function stat(path) {
|
|
20
|
+
return statSync(path, { throwIfNoEntry: false });
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
*****************************************
|
|
24
|
+
* 判断为目录
|
|
25
|
+
*****************************************
|
|
26
|
+
*/
|
|
27
|
+
export function isDir(path) {
|
|
28
|
+
const stats = stat(path);
|
|
29
|
+
// 目录存在时,返回路径
|
|
30
|
+
if (stats && stats.isDirectory()) {
|
|
31
|
+
return path;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
*****************************************
|
|
36
|
+
* 判断为文件
|
|
37
|
+
*****************************************
|
|
38
|
+
*/
|
|
39
|
+
export function isFile(path) {
|
|
40
|
+
const stats = stat(path);
|
|
41
|
+
// 文件存在时,返回路径
|
|
42
|
+
if (stats && stats.isFile()) {
|
|
43
|
+
return path;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*****************************************
|
|
3
|
+
* Created by edonet@163.com
|
|
4
|
+
* Created on 2023-01-05 21:39:42
|
|
5
|
+
*****************************************
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
/**
|
|
9
|
+
*****************************************
|
|
10
|
+
* 定义注释标识
|
|
11
|
+
*****************************************
|
|
12
|
+
*/
|
|
13
|
+
const singleComment = Symbol('singleComment');
|
|
14
|
+
const multiComment = Symbol('multiComment');
|
|
15
|
+
/**
|
|
16
|
+
*****************************************
|
|
17
|
+
* 判断是否转义
|
|
18
|
+
*****************************************
|
|
19
|
+
*/
|
|
20
|
+
function isEscaped(content, index) {
|
|
21
|
+
let backslashCount = 0;
|
|
22
|
+
let idx = index;
|
|
23
|
+
// 遍历字符
|
|
24
|
+
while (content[idx--] === '\\') {
|
|
25
|
+
backslashCount++;
|
|
26
|
+
}
|
|
27
|
+
// 返回结果
|
|
28
|
+
return backslashCount % 2 === 1;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
*****************************************
|
|
32
|
+
* 去除注释
|
|
33
|
+
*****************************************
|
|
34
|
+
*/
|
|
35
|
+
export function stripComments(content) {
|
|
36
|
+
// 校验内容
|
|
37
|
+
if (typeof content !== 'string') {
|
|
38
|
+
throw new TypeError(`Expected argument \`content\` to be a \`string\`, got \`${typeof content}\``);
|
|
39
|
+
}
|
|
40
|
+
// 定义变量
|
|
41
|
+
let isInsideString = false;
|
|
42
|
+
let isInsideComment = false;
|
|
43
|
+
let offset = 0;
|
|
44
|
+
let buffer = '';
|
|
45
|
+
let result = '';
|
|
46
|
+
let commaIndex = -1;
|
|
47
|
+
// 遍历字符
|
|
48
|
+
for (let index = 0; index < content.length; index++) {
|
|
49
|
+
const curr = content[index];
|
|
50
|
+
// 处理字符串
|
|
51
|
+
if (curr === '"' && !isInsideComment && !isEscaped(content, index - 1)) {
|
|
52
|
+
isInsideString = !isInsideString;
|
|
53
|
+
}
|
|
54
|
+
// 跳转字符串
|
|
55
|
+
if (isInsideString) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
// 退出单行注释
|
|
59
|
+
if (isInsideComment === singleComment) {
|
|
60
|
+
if (curr === '\n') {
|
|
61
|
+
isInsideComment = false;
|
|
62
|
+
offset = index;
|
|
63
|
+
}
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
// 获取下一字符
|
|
67
|
+
const next = content[index + 1];
|
|
68
|
+
// 退出多行注释
|
|
69
|
+
if (isInsideComment === multiComment) {
|
|
70
|
+
if (curr === '*' && next === '/') {
|
|
71
|
+
isInsideComment = false;
|
|
72
|
+
index += 1;
|
|
73
|
+
offset = index + 1;
|
|
74
|
+
}
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
// 处理注释起始位置
|
|
78
|
+
if (curr === '/') {
|
|
79
|
+
if (next === '/') {
|
|
80
|
+
buffer += content.slice(offset, index);
|
|
81
|
+
offset = index;
|
|
82
|
+
isInsideComment = singleComment;
|
|
83
|
+
index++;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (next === '*') {
|
|
87
|
+
buffer += content.slice(offset, index);
|
|
88
|
+
offset = index;
|
|
89
|
+
isInsideComment = multiComment;
|
|
90
|
+
index++;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// 处理末尾逗号
|
|
95
|
+
if (commaIndex !== -1) {
|
|
96
|
+
if (curr === '}' || curr === ']') {
|
|
97
|
+
buffer += content.slice(offset, index);
|
|
98
|
+
result += buffer.slice(1);
|
|
99
|
+
buffer = '';
|
|
100
|
+
offset = index;
|
|
101
|
+
commaIndex = -1;
|
|
102
|
+
}
|
|
103
|
+
else if (curr !== ' ' && curr !== '\t' && curr !== '\r' && curr !== '\n') {
|
|
104
|
+
buffer += content.slice(offset, index);
|
|
105
|
+
offset = index;
|
|
106
|
+
commaIndex = -1;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else if (curr === ',') {
|
|
110
|
+
result += buffer + content.slice(offset, index);
|
|
111
|
+
buffer = '';
|
|
112
|
+
offset = index;
|
|
113
|
+
commaIndex = index;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// 返回结果
|
|
117
|
+
return result + buffer + (isInsideComment ? '' : content.slice(offset));
|
|
118
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*****************************************
|
|
3
|
+
* Created by edonet@163.com
|
|
4
|
+
* Created on 2025-05-25 12:10:08
|
|
5
|
+
*****************************************
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
/**
|
|
9
|
+
*****************************************
|
|
10
|
+
* 加载依赖
|
|
11
|
+
*****************************************
|
|
12
|
+
*/
|
|
13
|
+
import { writeFileSync } from 'node:fs';
|
|
14
|
+
import { dirname } from 'node:path';
|
|
15
|
+
import { stat } from './stat.mjs';
|
|
16
|
+
import { rm } from './rm.mjs';
|
|
17
|
+
import { mkdir } from './mkdir.mjs';
|
|
18
|
+
/**
|
|
19
|
+
*****************************************
|
|
20
|
+
* 写入文件
|
|
21
|
+
*****************************************
|
|
22
|
+
*/
|
|
23
|
+
export function writeFile(dest, content, options) {
|
|
24
|
+
const stats = stat(dest);
|
|
25
|
+
if (stats) {
|
|
26
|
+
if (!options || !options.force) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
rm(dest);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// 创建目录
|
|
34
|
+
if (!mkdir(dirname(dest), options)) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
// 写入文件
|
|
38
|
+
return (writeFileSync(dest, content), true);
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ainc/fs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "Let's do something nice with @ainc/esb!",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"files": [
|
|
8
|
+
"bin",
|
|
9
|
+
"esm",
|
|
8
10
|
"dist"
|
|
9
11
|
],
|
|
12
|
+
"bin": {
|
|
13
|
+
"download": "./bin/download.mjs"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"require": "./dist/index.js",
|
|
19
|
+
"import": "./esm/index.mjs",
|
|
20
|
+
"default": "./esm/index.mjs"
|
|
21
|
+
},
|
|
22
|
+
"./*": {
|
|
23
|
+
"types": "./dist/*.d.ts",
|
|
24
|
+
"require": "./dist/*.js",
|
|
25
|
+
"import": "./esm/*.mjs",
|
|
26
|
+
"default": "./esm/*.mjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
10
29
|
"repository": "git@absock.net:ainc/esb.git",
|
|
11
30
|
"author": "edonet@163.com",
|
|
12
31
|
"license": "MIT",
|
|
@@ -14,21 +33,21 @@
|
|
|
14
33
|
"access": "public"
|
|
15
34
|
},
|
|
16
35
|
"dependencies": {
|
|
17
|
-
"typescript": "^5.
|
|
36
|
+
"typescript": "^5.9.3"
|
|
18
37
|
},
|
|
19
38
|
"devDependencies": {
|
|
20
|
-
"@jest/globals": "
|
|
21
|
-
"@swc/core": "^1.
|
|
22
|
-
"@swc/jest": "^0.2.
|
|
23
|
-
"@types/node": "^
|
|
24
|
-
"jest": "^
|
|
39
|
+
"@jest/globals": "30.2.0",
|
|
40
|
+
"@swc/core": "^1.15.8",
|
|
41
|
+
"@swc/jest": "^0.2.39",
|
|
42
|
+
"@types/node": "^25.0.3",
|
|
43
|
+
"jest": "^30.2.0"
|
|
25
44
|
},
|
|
26
45
|
"scripts": {
|
|
27
|
-
"
|
|
28
|
-
"build": "pnpm clean && pnpm compile",
|
|
46
|
+
"build": "pnpm clean && pnpm compile && pnpm esm",
|
|
29
47
|
"watch": "pnpm compile --watch",
|
|
48
|
+
"esm": "pnpm compile -m es2022 --outDir ./esm --declaration false && node ../../scripts/esm.js",
|
|
30
49
|
"compile": "tsc -p ./tsconfig.build.json",
|
|
31
50
|
"test": "jest",
|
|
32
|
-
"clean": "rimraf ./dist"
|
|
51
|
+
"clean": "rimraf ./dist ./esm"
|
|
33
52
|
}
|
|
34
53
|
}
|
|
File without changes
|
|
File without changes
|