create-byan-agent 2.11.0 → 2.11.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.
Files changed (58) hide show
  1. package/install/templates/_byan/mcp/byan-mcp-server/server.js +122 -9
  2. package/node_modules/byan-platform-config/README.md +107 -0
  3. package/node_modules/byan-platform-config/index.js +16 -0
  4. package/node_modules/byan-platform-config/lib/env-config.js +128 -0
  5. package/node_modules/byan-platform-config/lib/mcp-config.js +95 -0
  6. package/node_modules/byan-platform-config/lib/token-prompt.js +61 -0
  7. package/node_modules/byan-platform-config/lib/url-utils.js +27 -0
  8. package/node_modules/byan-platform-config/lib/validate.js +44 -0
  9. package/node_modules/byan-platform-config/package.json +42 -0
  10. package/node_modules/fs-extra/LICENSE +15 -0
  11. package/node_modules/fs-extra/README.md +294 -0
  12. package/node_modules/fs-extra/lib/copy/copy-sync.js +176 -0
  13. package/node_modules/fs-extra/lib/copy/copy.js +180 -0
  14. package/node_modules/fs-extra/lib/copy/index.js +7 -0
  15. package/node_modules/fs-extra/lib/empty/index.js +39 -0
  16. package/node_modules/fs-extra/lib/ensure/file.js +66 -0
  17. package/node_modules/fs-extra/lib/ensure/index.js +23 -0
  18. package/node_modules/fs-extra/lib/ensure/link.js +64 -0
  19. package/node_modules/fs-extra/lib/ensure/symlink-paths.js +101 -0
  20. package/node_modules/fs-extra/lib/ensure/symlink-type.js +34 -0
  21. package/node_modules/fs-extra/lib/ensure/symlink.js +92 -0
  22. package/node_modules/fs-extra/lib/esm.mjs +68 -0
  23. package/node_modules/fs-extra/lib/fs/index.js +146 -0
  24. package/node_modules/fs-extra/lib/index.js +16 -0
  25. package/node_modules/fs-extra/lib/json/index.js +16 -0
  26. package/node_modules/fs-extra/lib/json/jsonfile.js +11 -0
  27. package/node_modules/fs-extra/lib/json/output-json-sync.js +12 -0
  28. package/node_modules/fs-extra/lib/json/output-json.js +12 -0
  29. package/node_modules/fs-extra/lib/mkdirs/index.js +14 -0
  30. package/node_modules/fs-extra/lib/mkdirs/make-dir.js +27 -0
  31. package/node_modules/fs-extra/lib/mkdirs/utils.js +21 -0
  32. package/node_modules/fs-extra/lib/move/index.js +7 -0
  33. package/node_modules/fs-extra/lib/move/move-sync.js +55 -0
  34. package/node_modules/fs-extra/lib/move/move.js +59 -0
  35. package/node_modules/fs-extra/lib/output-file/index.js +31 -0
  36. package/node_modules/fs-extra/lib/path-exists/index.js +12 -0
  37. package/node_modules/fs-extra/lib/remove/index.js +17 -0
  38. package/node_modules/fs-extra/lib/util/async.js +29 -0
  39. package/node_modules/fs-extra/lib/util/stat.js +159 -0
  40. package/node_modules/fs-extra/lib/util/utimes.js +36 -0
  41. package/node_modules/fs-extra/package.json +71 -0
  42. package/node_modules/graceful-fs/LICENSE +15 -0
  43. package/node_modules/graceful-fs/README.md +143 -0
  44. package/node_modules/graceful-fs/clone.js +23 -0
  45. package/node_modules/graceful-fs/graceful-fs.js +448 -0
  46. package/node_modules/graceful-fs/legacy-streams.js +118 -0
  47. package/node_modules/graceful-fs/package.json +53 -0
  48. package/node_modules/graceful-fs/polyfills.js +355 -0
  49. package/node_modules/jsonfile/LICENSE +15 -0
  50. package/node_modules/jsonfile/README.md +230 -0
  51. package/node_modules/jsonfile/index.js +88 -0
  52. package/node_modules/jsonfile/package.json +40 -0
  53. package/node_modules/jsonfile/utils.js +18 -0
  54. package/node_modules/universalify/LICENSE +20 -0
  55. package/node_modules/universalify/README.md +76 -0
  56. package/node_modules/universalify/index.js +24 -0
  57. package/node_modules/universalify/package.json +34 -0
  58. package/package.json +4 -1
@@ -0,0 +1,180 @@
1
+ 'use strict'
2
+
3
+ const fs = require('../fs')
4
+ const path = require('path')
5
+ const { mkdirs } = require('../mkdirs')
6
+ const { pathExists } = require('../path-exists')
7
+ const { utimesMillis } = require('../util/utimes')
8
+ const stat = require('../util/stat')
9
+ const { asyncIteratorConcurrentProcess } = require('../util/async')
10
+
11
+ async function copy (src, dest, opts = {}) {
12
+ if (typeof opts === 'function') {
13
+ opts = { filter: opts }
14
+ }
15
+
16
+ opts.clobber = 'clobber' in opts ? !!opts.clobber : true // default to true for now
17
+ opts.overwrite = 'overwrite' in opts ? !!opts.overwrite : opts.clobber // overwrite falls back to clobber
18
+
19
+ // Warn about using preserveTimestamps on 32-bit node
20
+ if (opts.preserveTimestamps && process.arch === 'ia32') {
21
+ process.emitWarning(
22
+ 'Using the preserveTimestamps option in 32-bit node is not recommended;\n\n' +
23
+ '\tsee https://github.com/jprichardson/node-fs-extra/issues/269',
24
+ 'Warning', 'fs-extra-WARN0001'
25
+ )
26
+ }
27
+
28
+ const { srcStat, destStat } = await stat.checkPaths(src, dest, 'copy', opts)
29
+
30
+ await stat.checkParentPaths(src, srcStat, dest, 'copy')
31
+
32
+ const include = await runFilter(src, dest, opts)
33
+
34
+ if (!include) return
35
+
36
+ // check if the parent of dest exists, and create it if it doesn't exist
37
+ const destParent = path.dirname(dest)
38
+ const dirExists = await pathExists(destParent)
39
+ if (!dirExists) {
40
+ await mkdirs(destParent)
41
+ }
42
+
43
+ await getStatsAndPerformCopy(destStat, src, dest, opts)
44
+ }
45
+
46
+ async function runFilter (src, dest, opts) {
47
+ if (!opts.filter) return true
48
+ return opts.filter(src, dest)
49
+ }
50
+
51
+ async function getStatsAndPerformCopy (destStat, src, dest, opts) {
52
+ const statFn = opts.dereference ? fs.stat : fs.lstat
53
+ const srcStat = await statFn(src)
54
+
55
+ if (srcStat.isDirectory()) return onDir(srcStat, destStat, src, dest, opts)
56
+
57
+ if (
58
+ srcStat.isFile() ||
59
+ srcStat.isCharacterDevice() ||
60
+ srcStat.isBlockDevice()
61
+ ) return onFile(srcStat, destStat, src, dest, opts)
62
+
63
+ if (srcStat.isSymbolicLink()) return onLink(destStat, src, dest, opts)
64
+ if (srcStat.isSocket()) throw new Error(`Cannot copy a socket file: ${src}`)
65
+ if (srcStat.isFIFO()) throw new Error(`Cannot copy a FIFO pipe: ${src}`)
66
+ throw new Error(`Unknown file: ${src}`)
67
+ }
68
+
69
+ async function onFile (srcStat, destStat, src, dest, opts) {
70
+ if (!destStat) return copyFile(srcStat, src, dest, opts)
71
+
72
+ if (opts.overwrite) {
73
+ await fs.unlink(dest)
74
+ return copyFile(srcStat, src, dest, opts)
75
+ }
76
+ if (opts.errorOnExist) {
77
+ throw new Error(`'${dest}' already exists`)
78
+ }
79
+ }
80
+
81
+ async function copyFile (srcStat, src, dest, opts) {
82
+ await fs.copyFile(src, dest)
83
+ if (opts.preserveTimestamps) {
84
+ // Make sure the file is writable before setting the timestamp
85
+ // otherwise open fails with EPERM when invoked with 'r+'
86
+ // (through utimes call)
87
+ if (fileIsNotWritable(srcStat.mode)) {
88
+ await makeFileWritable(dest, srcStat.mode)
89
+ }
90
+
91
+ // Set timestamps and mode correspondingly
92
+
93
+ // Note that The initial srcStat.atime cannot be trusted
94
+ // because it is modified by the read(2) system call
95
+ // (See https://nodejs.org/api/fs.html#fs_stat_time_values)
96
+ const updatedSrcStat = await fs.stat(src)
97
+ await utimesMillis(dest, updatedSrcStat.atime, updatedSrcStat.mtime)
98
+ }
99
+
100
+ return fs.chmod(dest, srcStat.mode)
101
+ }
102
+
103
+ function fileIsNotWritable (srcMode) {
104
+ return (srcMode & 0o200) === 0
105
+ }
106
+
107
+ function makeFileWritable (dest, srcMode) {
108
+ return fs.chmod(dest, srcMode | 0o200)
109
+ }
110
+
111
+ async function onDir (srcStat, destStat, src, dest, opts) {
112
+ // the dest directory might not exist, create it
113
+ if (!destStat) {
114
+ await fs.mkdir(dest)
115
+ }
116
+
117
+ // iterate through the files in the current directory to copy everything
118
+ await asyncIteratorConcurrentProcess(await fs.opendir(src), async (item) => {
119
+ const srcItem = path.join(src, item.name)
120
+ const destItem = path.join(dest, item.name)
121
+
122
+ const include = await runFilter(srcItem, destItem, opts)
123
+ // only copy the item if it matches the filter function
124
+ if (include) {
125
+ const { destStat } = await stat.checkPaths(srcItem, destItem, 'copy', opts)
126
+ // If the item is a copyable file, `getStatsAndPerformCopy` will copy it
127
+ // If the item is a directory, `getStatsAndPerformCopy` will call `onDir` recursively
128
+ await getStatsAndPerformCopy(destStat, srcItem, destItem, opts)
129
+ }
130
+ })
131
+
132
+ if (!destStat) {
133
+ await fs.chmod(dest, srcStat.mode)
134
+ }
135
+ }
136
+
137
+ async function onLink (destStat, src, dest, opts) {
138
+ let resolvedSrc = await fs.readlink(src)
139
+ if (opts.dereference) {
140
+ resolvedSrc = path.resolve(process.cwd(), resolvedSrc)
141
+ }
142
+ if (!destStat) {
143
+ return fs.symlink(resolvedSrc, dest)
144
+ }
145
+
146
+ let resolvedDest = null
147
+ try {
148
+ resolvedDest = await fs.readlink(dest)
149
+ } catch (e) {
150
+ // dest exists and is a regular file or directory,
151
+ // Windows may throw UNKNOWN error. If dest already exists,
152
+ // fs throws error anyway, so no need to guard against it here.
153
+ if (e.code === 'EINVAL' || e.code === 'UNKNOWN') return fs.symlink(resolvedSrc, dest)
154
+ throw e
155
+ }
156
+ if (opts.dereference) {
157
+ resolvedDest = path.resolve(process.cwd(), resolvedDest)
158
+ }
159
+ // If both symlinks resolve to the same target, they are still distinct symlinks
160
+ // that can be copied/overwritten. Only check subdirectory constraints when
161
+ // the resolved paths are different.
162
+ if (resolvedSrc !== resolvedDest) {
163
+ if (stat.isSrcSubdir(resolvedSrc, resolvedDest)) {
164
+ throw new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`)
165
+ }
166
+
167
+ // do not copy if src is a subdir of dest since unlinking
168
+ // dest in this case would result in removing src contents
169
+ // and therefore a broken symlink would be created.
170
+ if (stat.isSrcSubdir(resolvedDest, resolvedSrc)) {
171
+ throw new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`)
172
+ }
173
+ }
174
+
175
+ // copy the link
176
+ await fs.unlink(dest)
177
+ return fs.symlink(resolvedSrc, dest)
178
+ }
179
+
180
+ module.exports = copy
@@ -0,0 +1,7 @@
1
+ 'use strict'
2
+
3
+ const u = require('universalify').fromPromise
4
+ module.exports = {
5
+ copy: u(require('./copy')),
6
+ copySync: require('./copy-sync')
7
+ }
@@ -0,0 +1,39 @@
1
+ 'use strict'
2
+
3
+ const u = require('universalify').fromPromise
4
+ const fs = require('../fs')
5
+ const path = require('path')
6
+ const mkdir = require('../mkdirs')
7
+ const remove = require('../remove')
8
+
9
+ const emptyDir = u(async function emptyDir (dir) {
10
+ let items
11
+ try {
12
+ items = await fs.readdir(dir)
13
+ } catch {
14
+ return mkdir.mkdirs(dir)
15
+ }
16
+
17
+ return Promise.all(items.map(item => remove.remove(path.join(dir, item))))
18
+ })
19
+
20
+ function emptyDirSync (dir) {
21
+ let items
22
+ try {
23
+ items = fs.readdirSync(dir)
24
+ } catch {
25
+ return mkdir.mkdirsSync(dir)
26
+ }
27
+
28
+ items.forEach(item => {
29
+ item = path.join(dir, item)
30
+ remove.removeSync(item)
31
+ })
32
+ }
33
+
34
+ module.exports = {
35
+ emptyDirSync,
36
+ emptydirSync: emptyDirSync,
37
+ emptyDir,
38
+ emptydir: emptyDir
39
+ }
@@ -0,0 +1,66 @@
1
+ 'use strict'
2
+
3
+ const u = require('universalify').fromPromise
4
+ const path = require('path')
5
+ const fs = require('../fs')
6
+ const mkdir = require('../mkdirs')
7
+
8
+ async function createFile (file) {
9
+ let stats
10
+ try {
11
+ stats = await fs.stat(file)
12
+ } catch { }
13
+ if (stats && stats.isFile()) return
14
+
15
+ const dir = path.dirname(file)
16
+
17
+ let dirStats = null
18
+ try {
19
+ dirStats = await fs.stat(dir)
20
+ } catch (err) {
21
+ // if the directory doesn't exist, make it
22
+ if (err.code === 'ENOENT') {
23
+ await mkdir.mkdirs(dir)
24
+ await fs.writeFile(file, '')
25
+ return
26
+ } else {
27
+ throw err
28
+ }
29
+ }
30
+
31
+ if (dirStats.isDirectory()) {
32
+ await fs.writeFile(file, '')
33
+ } else {
34
+ // parent is not a directory
35
+ // This is just to cause an internal ENOTDIR error to be thrown
36
+ await fs.readdir(dir)
37
+ }
38
+ }
39
+
40
+ function createFileSync (file) {
41
+ let stats
42
+ try {
43
+ stats = fs.statSync(file)
44
+ } catch { }
45
+ if (stats && stats.isFile()) return
46
+
47
+ const dir = path.dirname(file)
48
+ try {
49
+ if (!fs.statSync(dir).isDirectory()) {
50
+ // parent is not a directory
51
+ // This is just to cause an internal ENOTDIR error to be thrown
52
+ fs.readdirSync(dir)
53
+ }
54
+ } catch (err) {
55
+ // If the stat call above failed because the directory doesn't exist, create it
56
+ if (err && err.code === 'ENOENT') mkdir.mkdirsSync(dir)
57
+ else throw err
58
+ }
59
+
60
+ fs.writeFileSync(file, '')
61
+ }
62
+
63
+ module.exports = {
64
+ createFile: u(createFile),
65
+ createFileSync
66
+ }
@@ -0,0 +1,23 @@
1
+ 'use strict'
2
+
3
+ const { createFile, createFileSync } = require('./file')
4
+ const { createLink, createLinkSync } = require('./link')
5
+ const { createSymlink, createSymlinkSync } = require('./symlink')
6
+
7
+ module.exports = {
8
+ // file
9
+ createFile,
10
+ createFileSync,
11
+ ensureFile: createFile,
12
+ ensureFileSync: createFileSync,
13
+ // link
14
+ createLink,
15
+ createLinkSync,
16
+ ensureLink: createLink,
17
+ ensureLinkSync: createLinkSync,
18
+ // symlink
19
+ createSymlink,
20
+ createSymlinkSync,
21
+ ensureSymlink: createSymlink,
22
+ ensureSymlinkSync: createSymlinkSync
23
+ }
@@ -0,0 +1,64 @@
1
+ 'use strict'
2
+
3
+ const u = require('universalify').fromPromise
4
+ const path = require('path')
5
+ const fs = require('../fs')
6
+ const mkdir = require('../mkdirs')
7
+ const { pathExists } = require('../path-exists')
8
+ const { areIdentical } = require('../util/stat')
9
+
10
+ async function createLink (srcpath, dstpath) {
11
+ let dstStat
12
+ try {
13
+ dstStat = await fs.lstat(dstpath)
14
+ } catch {
15
+ // ignore error
16
+ }
17
+
18
+ let srcStat
19
+ try {
20
+ srcStat = await fs.lstat(srcpath)
21
+ } catch (err) {
22
+ err.message = err.message.replace('lstat', 'ensureLink')
23
+ throw err
24
+ }
25
+
26
+ if (dstStat && areIdentical(srcStat, dstStat)) return
27
+
28
+ const dir = path.dirname(dstpath)
29
+
30
+ const dirExists = await pathExists(dir)
31
+
32
+ if (!dirExists) {
33
+ await mkdir.mkdirs(dir)
34
+ }
35
+
36
+ await fs.link(srcpath, dstpath)
37
+ }
38
+
39
+ function createLinkSync (srcpath, dstpath) {
40
+ let dstStat
41
+ try {
42
+ dstStat = fs.lstatSync(dstpath)
43
+ } catch {}
44
+
45
+ try {
46
+ const srcStat = fs.lstatSync(srcpath)
47
+ if (dstStat && areIdentical(srcStat, dstStat)) return
48
+ } catch (err) {
49
+ err.message = err.message.replace('lstat', 'ensureLink')
50
+ throw err
51
+ }
52
+
53
+ const dir = path.dirname(dstpath)
54
+ const dirExists = fs.existsSync(dir)
55
+ if (dirExists) return fs.linkSync(srcpath, dstpath)
56
+ mkdir.mkdirsSync(dir)
57
+
58
+ return fs.linkSync(srcpath, dstpath)
59
+ }
60
+
61
+ module.exports = {
62
+ createLink: u(createLink),
63
+ createLinkSync
64
+ }
@@ -0,0 +1,101 @@
1
+ 'use strict'
2
+
3
+ const path = require('path')
4
+ const fs = require('../fs')
5
+ const { pathExists } = require('../path-exists')
6
+
7
+ const u = require('universalify').fromPromise
8
+
9
+ /**
10
+ * Function that returns two types of paths, one relative to symlink, and one
11
+ * relative to the current working directory. Checks if path is absolute or
12
+ * relative. If the path is relative, this function checks if the path is
13
+ * relative to symlink or relative to current working directory. This is an
14
+ * initiative to find a smarter `srcpath` to supply when building symlinks.
15
+ * This allows you to determine which path to use out of one of three possible
16
+ * types of source paths. The first is an absolute path. This is detected by
17
+ * `path.isAbsolute()`. When an absolute path is provided, it is checked to
18
+ * see if it exists. If it does it's used, if not an error is returned
19
+ * (callback)/ thrown (sync). The other two options for `srcpath` are a
20
+ * relative url. By default Node's `fs.symlink` works by creating a symlink
21
+ * using `dstpath` and expects the `srcpath` to be relative to the newly
22
+ * created symlink. If you provide a `srcpath` that does not exist on the file
23
+ * system it results in a broken symlink. To minimize this, the function
24
+ * checks to see if the 'relative to symlink' source file exists, and if it
25
+ * does it will use it. If it does not, it checks if there's a file that
26
+ * exists that is relative to the current working directory, if does its used.
27
+ * This preserves the expectations of the original fs.symlink spec and adds
28
+ * the ability to pass in `relative to current working direcotry` paths.
29
+ */
30
+
31
+ async function symlinkPaths (srcpath, dstpath) {
32
+ if (path.isAbsolute(srcpath)) {
33
+ try {
34
+ await fs.lstat(srcpath)
35
+ } catch (err) {
36
+ err.message = err.message.replace('lstat', 'ensureSymlink')
37
+ throw err
38
+ }
39
+
40
+ return {
41
+ toCwd: srcpath,
42
+ toDst: srcpath
43
+ }
44
+ }
45
+
46
+ const dstdir = path.dirname(dstpath)
47
+ const relativeToDst = path.join(dstdir, srcpath)
48
+
49
+ const exists = await pathExists(relativeToDst)
50
+ if (exists) {
51
+ return {
52
+ toCwd: relativeToDst,
53
+ toDst: srcpath
54
+ }
55
+ }
56
+
57
+ try {
58
+ await fs.lstat(srcpath)
59
+ } catch (err) {
60
+ err.message = err.message.replace('lstat', 'ensureSymlink')
61
+ throw err
62
+ }
63
+
64
+ return {
65
+ toCwd: srcpath,
66
+ toDst: path.relative(dstdir, srcpath)
67
+ }
68
+ }
69
+
70
+ function symlinkPathsSync (srcpath, dstpath) {
71
+ if (path.isAbsolute(srcpath)) {
72
+ const exists = fs.existsSync(srcpath)
73
+ if (!exists) throw new Error('absolute srcpath does not exist')
74
+ return {
75
+ toCwd: srcpath,
76
+ toDst: srcpath
77
+ }
78
+ }
79
+
80
+ const dstdir = path.dirname(dstpath)
81
+ const relativeToDst = path.join(dstdir, srcpath)
82
+ const exists = fs.existsSync(relativeToDst)
83
+ if (exists) {
84
+ return {
85
+ toCwd: relativeToDst,
86
+ toDst: srcpath
87
+ }
88
+ }
89
+
90
+ const srcExists = fs.existsSync(srcpath)
91
+ if (!srcExists) throw new Error('relative srcpath does not exist')
92
+ return {
93
+ toCwd: srcpath,
94
+ toDst: path.relative(dstdir, srcpath)
95
+ }
96
+ }
97
+
98
+ module.exports = {
99
+ symlinkPaths: u(symlinkPaths),
100
+ symlinkPathsSync
101
+ }
@@ -0,0 +1,34 @@
1
+ 'use strict'
2
+
3
+ const fs = require('../fs')
4
+ const u = require('universalify').fromPromise
5
+
6
+ async function symlinkType (srcpath, type) {
7
+ if (type) return type
8
+
9
+ let stats
10
+ try {
11
+ stats = await fs.lstat(srcpath)
12
+ } catch {
13
+ return 'file'
14
+ }
15
+
16
+ return (stats && stats.isDirectory()) ? 'dir' : 'file'
17
+ }
18
+
19
+ function symlinkTypeSync (srcpath, type) {
20
+ if (type) return type
21
+
22
+ let stats
23
+ try {
24
+ stats = fs.lstatSync(srcpath)
25
+ } catch {
26
+ return 'file'
27
+ }
28
+ return (stats && stats.isDirectory()) ? 'dir' : 'file'
29
+ }
30
+
31
+ module.exports = {
32
+ symlinkType: u(symlinkType),
33
+ symlinkTypeSync
34
+ }
@@ -0,0 +1,92 @@
1
+ 'use strict'
2
+
3
+ const u = require('universalify').fromPromise
4
+ const path = require('path')
5
+ const fs = require('../fs')
6
+
7
+ const { mkdirs, mkdirsSync } = require('../mkdirs')
8
+
9
+ const { symlinkPaths, symlinkPathsSync } = require('./symlink-paths')
10
+ const { symlinkType, symlinkTypeSync } = require('./symlink-type')
11
+
12
+ const { pathExists } = require('../path-exists')
13
+
14
+ const { areIdentical } = require('../util/stat')
15
+
16
+ async function createSymlink (srcpath, dstpath, type) {
17
+ let stats
18
+ try {
19
+ stats = await fs.lstat(dstpath)
20
+ } catch { }
21
+
22
+ if (stats && stats.isSymbolicLink()) {
23
+ // When srcpath is relative, resolve it relative to dstpath's directory
24
+ // (standard symlink behavior) or fall back to cwd if that doesn't exist
25
+ let srcStat
26
+ if (path.isAbsolute(srcpath)) {
27
+ srcStat = await fs.stat(srcpath)
28
+ } else {
29
+ const dstdir = path.dirname(dstpath)
30
+ const relativeToDst = path.join(dstdir, srcpath)
31
+ try {
32
+ srcStat = await fs.stat(relativeToDst)
33
+ } catch {
34
+ srcStat = await fs.stat(srcpath)
35
+ }
36
+ }
37
+
38
+ const dstStat = await fs.stat(dstpath)
39
+ if (areIdentical(srcStat, dstStat)) return
40
+ }
41
+
42
+ const relative = await symlinkPaths(srcpath, dstpath)
43
+ srcpath = relative.toDst
44
+ const toType = await symlinkType(relative.toCwd, type)
45
+ const dir = path.dirname(dstpath)
46
+
47
+ if (!(await pathExists(dir))) {
48
+ await mkdirs(dir)
49
+ }
50
+
51
+ return fs.symlink(srcpath, dstpath, toType)
52
+ }
53
+
54
+ function createSymlinkSync (srcpath, dstpath, type) {
55
+ let stats
56
+ try {
57
+ stats = fs.lstatSync(dstpath)
58
+ } catch { }
59
+ if (stats && stats.isSymbolicLink()) {
60
+ // When srcpath is relative, resolve it relative to dstpath's directory
61
+ // (standard symlink behavior) or fall back to cwd if that doesn't exist
62
+ let srcStat
63
+ if (path.isAbsolute(srcpath)) {
64
+ srcStat = fs.statSync(srcpath)
65
+ } else {
66
+ const dstdir = path.dirname(dstpath)
67
+ const relativeToDst = path.join(dstdir, srcpath)
68
+ try {
69
+ srcStat = fs.statSync(relativeToDst)
70
+ } catch {
71
+ srcStat = fs.statSync(srcpath)
72
+ }
73
+ }
74
+
75
+ const dstStat = fs.statSync(dstpath)
76
+ if (areIdentical(srcStat, dstStat)) return
77
+ }
78
+
79
+ const relative = symlinkPathsSync(srcpath, dstpath)
80
+ srcpath = relative.toDst
81
+ type = symlinkTypeSync(relative.toCwd, type)
82
+ const dir = path.dirname(dstpath)
83
+ const exists = fs.existsSync(dir)
84
+ if (exists) return fs.symlinkSync(srcpath, dstpath, type)
85
+ mkdirsSync(dir)
86
+ return fs.symlinkSync(srcpath, dstpath, type)
87
+ }
88
+
89
+ module.exports = {
90
+ createSymlink: u(createSymlink),
91
+ createSymlinkSync
92
+ }
@@ -0,0 +1,68 @@
1
+ import _copy from './copy/index.js'
2
+ import _empty from './empty/index.js'
3
+ import _ensure from './ensure/index.js'
4
+ import _json from './json/index.js'
5
+ import _mkdirs from './mkdirs/index.js'
6
+ import _move from './move/index.js'
7
+ import _outputFile from './output-file/index.js'
8
+ import _pathExists from './path-exists/index.js'
9
+ import _remove from './remove/index.js'
10
+
11
+ // NOTE: Only exports fs-extra's functions; fs functions must be imported from "node:fs" or "node:fs/promises"
12
+
13
+ export const copy = _copy.copy
14
+ export const copySync = _copy.copySync
15
+ export const emptyDirSync = _empty.emptyDirSync
16
+ export const emptydirSync = _empty.emptydirSync
17
+ export const emptyDir = _empty.emptyDir
18
+ export const emptydir = _empty.emptydir
19
+ export const createFile = _ensure.createFile
20
+ export const createFileSync = _ensure.createFileSync
21
+ export const ensureFile = _ensure.ensureFile
22
+ export const ensureFileSync = _ensure.ensureFileSync
23
+ export const createLink = _ensure.createLink
24
+ export const createLinkSync = _ensure.createLinkSync
25
+ export const ensureLink = _ensure.ensureLink
26
+ export const ensureLinkSync = _ensure.ensureLinkSync
27
+ export const createSymlink = _ensure.createSymlink
28
+ export const createSymlinkSync = _ensure.createSymlinkSync
29
+ export const ensureSymlink = _ensure.ensureSymlink
30
+ export const ensureSymlinkSync = _ensure.ensureSymlinkSync
31
+ export const readJson = _json.readJson
32
+ export const readJSON = _json.readJSON
33
+ export const readJsonSync = _json.readJsonSync
34
+ export const readJSONSync = _json.readJSONSync
35
+ export const writeJson = _json.writeJson
36
+ export const writeJSON = _json.writeJSON
37
+ export const writeJsonSync = _json.writeJsonSync
38
+ export const writeJSONSync = _json.writeJSONSync
39
+ export const outputJson = _json.outputJson
40
+ export const outputJSON = _json.outputJSON
41
+ export const outputJsonSync = _json.outputJsonSync
42
+ export const outputJSONSync = _json.outputJSONSync
43
+ export const mkdirs = _mkdirs.mkdirs
44
+ export const mkdirsSync = _mkdirs.mkdirsSync
45
+ export const mkdirp = _mkdirs.mkdirp
46
+ export const mkdirpSync = _mkdirs.mkdirpSync
47
+ export const ensureDir = _mkdirs.ensureDir
48
+ export const ensureDirSync = _mkdirs.ensureDirSync
49
+ export const move = _move.move
50
+ export const moveSync = _move.moveSync
51
+ export const outputFile = _outputFile.outputFile
52
+ export const outputFileSync = _outputFile.outputFileSync
53
+ export const pathExists = _pathExists.pathExists
54
+ export const pathExistsSync = _pathExists.pathExistsSync
55
+ export const remove = _remove.remove
56
+ export const removeSync = _remove.removeSync
57
+
58
+ export default {
59
+ ..._copy,
60
+ ..._empty,
61
+ ..._ensure,
62
+ ..._json,
63
+ ..._mkdirs,
64
+ ..._move,
65
+ ..._outputFile,
66
+ ..._pathExists,
67
+ ..._remove
68
+ }