@cdk8s/projen-common 0.0.237 → 0.0.239

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 (85) hide show
  1. package/.jsii +166 -70
  2. package/.projenrc.ts +17 -0
  3. package/API.md +6745 -54
  4. package/git-hooks/prepare-commit-msg +0 -0
  5. package/git-hooks/setup.sh +0 -0
  6. package/lib/index.d.ts +1 -37
  7. package/lib/index.js +12 -86
  8. package/lib/projects/index.d.ts +2 -0
  9. package/lib/projects/index.js +7 -0
  10. package/lib/projects/jsii.d.ts +48 -0
  11. package/lib/projects/jsii.js +71 -0
  12. package/lib/projects/typescript.d.ts +34 -0
  13. package/lib/projects/typescript.js +89 -0
  14. package/node_modules/codemaker/LICENSE +202 -0
  15. package/node_modules/codemaker/NOTICE +2 -0
  16. package/node_modules/codemaker/README.md +120 -0
  17. package/node_modules/codemaker/jest.config.mjs +3 -0
  18. package/node_modules/codemaker/lib/case-utils.d.ts +4 -0
  19. package/node_modules/codemaker/lib/case-utils.js +29 -0
  20. package/node_modules/codemaker/lib/codemaker.d.ts +107 -0
  21. package/node_modules/codemaker/lib/codemaker.js +164 -0
  22. package/node_modules/codemaker/lib/filebuff.d.ts +11 -0
  23. package/node_modules/codemaker/lib/filebuff.js +26 -0
  24. package/node_modules/codemaker/lib/index.d.ts +3 -0
  25. package/node_modules/codemaker/lib/index.js +19 -0
  26. package/node_modules/codemaker/node_modules/camelcase/index.d.ts +103 -0
  27. package/node_modules/codemaker/node_modules/camelcase/index.js +113 -0
  28. package/node_modules/codemaker/node_modules/camelcase/license +9 -0
  29. package/node_modules/codemaker/node_modules/camelcase/package.json +44 -0
  30. package/node_modules/codemaker/node_modules/camelcase/readme.md +144 -0
  31. package/node_modules/codemaker/package.json +41 -0
  32. package/node_modules/decamelize/index.d.ts +59 -0
  33. package/node_modules/decamelize/index.js +65 -0
  34. package/node_modules/decamelize/license +9 -0
  35. package/node_modules/decamelize/package.json +40 -0
  36. package/node_modules/decamelize/readme.md +92 -0
  37. package/node_modules/fs-extra/LICENSE +15 -0
  38. package/node_modules/fs-extra/README.md +262 -0
  39. package/node_modules/fs-extra/lib/copy/copy-sync.js +169 -0
  40. package/node_modules/fs-extra/lib/copy/copy.js +235 -0
  41. package/node_modules/fs-extra/lib/copy/index.js +7 -0
  42. package/node_modules/fs-extra/lib/empty/index.js +39 -0
  43. package/node_modules/fs-extra/lib/ensure/file.js +69 -0
  44. package/node_modules/fs-extra/lib/ensure/index.js +23 -0
  45. package/node_modules/fs-extra/lib/ensure/link.js +64 -0
  46. package/node_modules/fs-extra/lib/ensure/symlink-paths.js +99 -0
  47. package/node_modules/fs-extra/lib/ensure/symlink-type.js +31 -0
  48. package/node_modules/fs-extra/lib/ensure/symlink.js +82 -0
  49. package/node_modules/fs-extra/lib/fs/index.js +128 -0
  50. package/node_modules/fs-extra/lib/index.js +16 -0
  51. package/node_modules/fs-extra/lib/json/index.js +16 -0
  52. package/node_modules/fs-extra/lib/json/jsonfile.js +11 -0
  53. package/node_modules/fs-extra/lib/json/output-json-sync.js +12 -0
  54. package/node_modules/fs-extra/lib/json/output-json.js +12 -0
  55. package/node_modules/fs-extra/lib/mkdirs/index.js +14 -0
  56. package/node_modules/fs-extra/lib/mkdirs/make-dir.js +27 -0
  57. package/node_modules/fs-extra/lib/mkdirs/utils.js +21 -0
  58. package/node_modules/fs-extra/lib/move/index.js +7 -0
  59. package/node_modules/fs-extra/lib/move/move-sync.js +54 -0
  60. package/node_modules/fs-extra/lib/move/move.js +75 -0
  61. package/node_modules/fs-extra/lib/output-file/index.js +40 -0
  62. package/node_modules/fs-extra/lib/path-exists/index.js +12 -0
  63. package/node_modules/fs-extra/lib/remove/index.js +22 -0
  64. package/node_modules/fs-extra/lib/remove/rimraf.js +302 -0
  65. package/node_modules/fs-extra/lib/util/stat.js +154 -0
  66. package/node_modules/fs-extra/lib/util/utimes.js +26 -0
  67. package/node_modules/fs-extra/package.json +67 -0
  68. package/node_modules/graceful-fs/LICENSE +15 -0
  69. package/node_modules/graceful-fs/README.md +143 -0
  70. package/node_modules/graceful-fs/clone.js +23 -0
  71. package/node_modules/graceful-fs/graceful-fs.js +448 -0
  72. package/node_modules/graceful-fs/legacy-streams.js +118 -0
  73. package/node_modules/graceful-fs/package.json +50 -0
  74. package/node_modules/graceful-fs/polyfills.js +355 -0
  75. package/node_modules/jsonfile/CHANGELOG.md +171 -0
  76. package/node_modules/jsonfile/LICENSE +15 -0
  77. package/node_modules/jsonfile/README.md +230 -0
  78. package/node_modules/jsonfile/index.js +88 -0
  79. package/node_modules/jsonfile/package.json +40 -0
  80. package/node_modules/jsonfile/utils.js +14 -0
  81. package/node_modules/universalify/LICENSE +20 -0
  82. package/node_modules/universalify/README.md +76 -0
  83. package/node_modules/universalify/index.js +24 -0
  84. package/node_modules/universalify/package.json +34 -0
  85. package/package.json +17 -9
@@ -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,69 @@
1
+ 'use strict'
2
+
3
+ const u = require('universalify').fromCallback
4
+ const path = require('path')
5
+ const fs = require('graceful-fs')
6
+ const mkdir = require('../mkdirs')
7
+
8
+ function createFile (file, callback) {
9
+ function makeFile () {
10
+ fs.writeFile(file, '', err => {
11
+ if (err) return callback(err)
12
+ callback()
13
+ })
14
+ }
15
+
16
+ fs.stat(file, (err, stats) => { // eslint-disable-line handle-callback-err
17
+ if (!err && stats.isFile()) return callback()
18
+ const dir = path.dirname(file)
19
+ fs.stat(dir, (err, stats) => {
20
+ if (err) {
21
+ // if the directory doesn't exist, make it
22
+ if (err.code === 'ENOENT') {
23
+ return mkdir.mkdirs(dir, err => {
24
+ if (err) return callback(err)
25
+ makeFile()
26
+ })
27
+ }
28
+ return callback(err)
29
+ }
30
+
31
+ if (stats.isDirectory()) makeFile()
32
+ else {
33
+ // parent is not a directory
34
+ // This is just to cause an internal ENOTDIR error to be thrown
35
+ fs.readdir(dir, err => {
36
+ if (err) return callback(err)
37
+ })
38
+ }
39
+ })
40
+ })
41
+ }
42
+
43
+ function createFileSync (file) {
44
+ let stats
45
+ try {
46
+ stats = fs.statSync(file)
47
+ } catch {}
48
+ if (stats && stats.isFile()) return
49
+
50
+ const dir = path.dirname(file)
51
+ try {
52
+ if (!fs.statSync(dir).isDirectory()) {
53
+ // parent is not a directory
54
+ // This is just to cause an internal ENOTDIR error to be thrown
55
+ fs.readdirSync(dir)
56
+ }
57
+ } catch (err) {
58
+ // If the stat call above failed because the directory doesn't exist, create it
59
+ if (err && err.code === 'ENOENT') mkdir.mkdirsSync(dir)
60
+ else throw err
61
+ }
62
+
63
+ fs.writeFileSync(file, '')
64
+ }
65
+
66
+ module.exports = {
67
+ createFile: u(createFile),
68
+ createFileSync
69
+ }
@@ -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').fromCallback
4
+ const path = require('path')
5
+ const fs = require('graceful-fs')
6
+ const mkdir = require('../mkdirs')
7
+ const pathExists = require('../path-exists').pathExists
8
+ const { areIdentical } = require('../util/stat')
9
+
10
+ function createLink (srcpath, dstpath, callback) {
11
+ function makeLink (srcpath, dstpath) {
12
+ fs.link(srcpath, dstpath, err => {
13
+ if (err) return callback(err)
14
+ callback(null)
15
+ })
16
+ }
17
+
18
+ fs.lstat(dstpath, (_, dstStat) => {
19
+ fs.lstat(srcpath, (err, srcStat) => {
20
+ if (err) {
21
+ err.message = err.message.replace('lstat', 'ensureLink')
22
+ return callback(err)
23
+ }
24
+ if (dstStat && areIdentical(srcStat, dstStat)) return callback(null)
25
+
26
+ const dir = path.dirname(dstpath)
27
+ pathExists(dir, (err, dirExists) => {
28
+ if (err) return callback(err)
29
+ if (dirExists) return makeLink(srcpath, dstpath)
30
+ mkdir.mkdirs(dir, err => {
31
+ if (err) return callback(err)
32
+ makeLink(srcpath, dstpath)
33
+ })
34
+ })
35
+ })
36
+ })
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,99 @@
1
+ 'use strict'
2
+
3
+ const path = require('path')
4
+ const fs = require('graceful-fs')
5
+ const pathExists = require('../path-exists').pathExists
6
+
7
+ /**
8
+ * Function that returns two types of paths, one relative to symlink, and one
9
+ * relative to the current working directory. Checks if path is absolute or
10
+ * relative. If the path is relative, this function checks if the path is
11
+ * relative to symlink or relative to current working directory. This is an
12
+ * initiative to find a smarter `srcpath` to supply when building symlinks.
13
+ * This allows you to determine which path to use out of one of three possible
14
+ * types of source paths. The first is an absolute path. This is detected by
15
+ * `path.isAbsolute()`. When an absolute path is provided, it is checked to
16
+ * see if it exists. If it does it's used, if not an error is returned
17
+ * (callback)/ thrown (sync). The other two options for `srcpath` are a
18
+ * relative url. By default Node's `fs.symlink` works by creating a symlink
19
+ * using `dstpath` and expects the `srcpath` to be relative to the newly
20
+ * created symlink. If you provide a `srcpath` that does not exist on the file
21
+ * system it results in a broken symlink. To minimize this, the function
22
+ * checks to see if the 'relative to symlink' source file exists, and if it
23
+ * does it will use it. If it does not, it checks if there's a file that
24
+ * exists that is relative to the current working directory, if does its used.
25
+ * This preserves the expectations of the original fs.symlink spec and adds
26
+ * the ability to pass in `relative to current working direcotry` paths.
27
+ */
28
+
29
+ function symlinkPaths (srcpath, dstpath, callback) {
30
+ if (path.isAbsolute(srcpath)) {
31
+ return fs.lstat(srcpath, (err) => {
32
+ if (err) {
33
+ err.message = err.message.replace('lstat', 'ensureSymlink')
34
+ return callback(err)
35
+ }
36
+ return callback(null, {
37
+ toCwd: srcpath,
38
+ toDst: srcpath
39
+ })
40
+ })
41
+ } else {
42
+ const dstdir = path.dirname(dstpath)
43
+ const relativeToDst = path.join(dstdir, srcpath)
44
+ return pathExists(relativeToDst, (err, exists) => {
45
+ if (err) return callback(err)
46
+ if (exists) {
47
+ return callback(null, {
48
+ toCwd: relativeToDst,
49
+ toDst: srcpath
50
+ })
51
+ } else {
52
+ return fs.lstat(srcpath, (err) => {
53
+ if (err) {
54
+ err.message = err.message.replace('lstat', 'ensureSymlink')
55
+ return callback(err)
56
+ }
57
+ return callback(null, {
58
+ toCwd: srcpath,
59
+ toDst: path.relative(dstdir, srcpath)
60
+ })
61
+ })
62
+ }
63
+ })
64
+ }
65
+ }
66
+
67
+ function symlinkPathsSync (srcpath, dstpath) {
68
+ let exists
69
+ if (path.isAbsolute(srcpath)) {
70
+ exists = fs.existsSync(srcpath)
71
+ if (!exists) throw new Error('absolute srcpath does not exist')
72
+ return {
73
+ toCwd: srcpath,
74
+ toDst: srcpath
75
+ }
76
+ } else {
77
+ const dstdir = path.dirname(dstpath)
78
+ const relativeToDst = path.join(dstdir, srcpath)
79
+ exists = fs.existsSync(relativeToDst)
80
+ if (exists) {
81
+ return {
82
+ toCwd: relativeToDst,
83
+ toDst: srcpath
84
+ }
85
+ } else {
86
+ exists = fs.existsSync(srcpath)
87
+ if (!exists) throw new Error('relative srcpath does not exist')
88
+ return {
89
+ toCwd: srcpath,
90
+ toDst: path.relative(dstdir, srcpath)
91
+ }
92
+ }
93
+ }
94
+ }
95
+
96
+ module.exports = {
97
+ symlinkPaths,
98
+ symlinkPathsSync
99
+ }
@@ -0,0 +1,31 @@
1
+ 'use strict'
2
+
3
+ const fs = require('graceful-fs')
4
+
5
+ function symlinkType (srcpath, type, callback) {
6
+ callback = (typeof type === 'function') ? type : callback
7
+ type = (typeof type === 'function') ? false : type
8
+ if (type) return callback(null, type)
9
+ fs.lstat(srcpath, (err, stats) => {
10
+ if (err) return callback(null, 'file')
11
+ type = (stats && stats.isDirectory()) ? 'dir' : 'file'
12
+ callback(null, type)
13
+ })
14
+ }
15
+
16
+ function symlinkTypeSync (srcpath, type) {
17
+ let stats
18
+
19
+ if (type) return type
20
+ try {
21
+ stats = fs.lstatSync(srcpath)
22
+ } catch {
23
+ return 'file'
24
+ }
25
+ return (stats && stats.isDirectory()) ? 'dir' : 'file'
26
+ }
27
+
28
+ module.exports = {
29
+ symlinkType,
30
+ symlinkTypeSync
31
+ }
@@ -0,0 +1,82 @@
1
+ 'use strict'
2
+
3
+ const u = require('universalify').fromCallback
4
+ const path = require('path')
5
+ const fs = require('../fs')
6
+ const _mkdirs = require('../mkdirs')
7
+ const mkdirs = _mkdirs.mkdirs
8
+ const mkdirsSync = _mkdirs.mkdirsSync
9
+
10
+ const _symlinkPaths = require('./symlink-paths')
11
+ const symlinkPaths = _symlinkPaths.symlinkPaths
12
+ const symlinkPathsSync = _symlinkPaths.symlinkPathsSync
13
+
14
+ const _symlinkType = require('./symlink-type')
15
+ const symlinkType = _symlinkType.symlinkType
16
+ const symlinkTypeSync = _symlinkType.symlinkTypeSync
17
+
18
+ const pathExists = require('../path-exists').pathExists
19
+
20
+ const { areIdentical } = require('../util/stat')
21
+
22
+ function createSymlink (srcpath, dstpath, type, callback) {
23
+ callback = (typeof type === 'function') ? type : callback
24
+ type = (typeof type === 'function') ? false : type
25
+
26
+ fs.lstat(dstpath, (err, stats) => {
27
+ if (!err && stats.isSymbolicLink()) {
28
+ Promise.all([
29
+ fs.stat(srcpath),
30
+ fs.stat(dstpath)
31
+ ]).then(([srcStat, dstStat]) => {
32
+ if (areIdentical(srcStat, dstStat)) return callback(null)
33
+ _createSymlink(srcpath, dstpath, type, callback)
34
+ })
35
+ } else _createSymlink(srcpath, dstpath, type, callback)
36
+ })
37
+ }
38
+
39
+ function _createSymlink (srcpath, dstpath, type, callback) {
40
+ symlinkPaths(srcpath, dstpath, (err, relative) => {
41
+ if (err) return callback(err)
42
+ srcpath = relative.toDst
43
+ symlinkType(relative.toCwd, type, (err, type) => {
44
+ if (err) return callback(err)
45
+ const dir = path.dirname(dstpath)
46
+ pathExists(dir, (err, dirExists) => {
47
+ if (err) return callback(err)
48
+ if (dirExists) return fs.symlink(srcpath, dstpath, type, callback)
49
+ mkdirs(dir, err => {
50
+ if (err) return callback(err)
51
+ fs.symlink(srcpath, dstpath, type, callback)
52
+ })
53
+ })
54
+ })
55
+ })
56
+ }
57
+
58
+ function createSymlinkSync (srcpath, dstpath, type) {
59
+ let stats
60
+ try {
61
+ stats = fs.lstatSync(dstpath)
62
+ } catch {}
63
+ if (stats && stats.isSymbolicLink()) {
64
+ const srcStat = fs.statSync(srcpath)
65
+ const dstStat = fs.statSync(dstpath)
66
+ if (areIdentical(srcStat, dstStat)) return
67
+ }
68
+
69
+ const relative = symlinkPathsSync(srcpath, dstpath)
70
+ srcpath = relative.toDst
71
+ type = symlinkTypeSync(relative.toCwd, type)
72
+ const dir = path.dirname(dstpath)
73
+ const exists = fs.existsSync(dir)
74
+ if (exists) return fs.symlinkSync(srcpath, dstpath, type)
75
+ mkdirsSync(dir)
76
+ return fs.symlinkSync(srcpath, dstpath, type)
77
+ }
78
+
79
+ module.exports = {
80
+ createSymlink: u(createSymlink),
81
+ createSymlinkSync
82
+ }
@@ -0,0 +1,128 @@
1
+ 'use strict'
2
+ // This is adapted from https://github.com/normalize/mz
3
+ // Copyright (c) 2014-2016 Jonathan Ong me@jongleberry.com and Contributors
4
+ const u = require('universalify').fromCallback
5
+ const fs = require('graceful-fs')
6
+
7
+ const api = [
8
+ 'access',
9
+ 'appendFile',
10
+ 'chmod',
11
+ 'chown',
12
+ 'close',
13
+ 'copyFile',
14
+ 'fchmod',
15
+ 'fchown',
16
+ 'fdatasync',
17
+ 'fstat',
18
+ 'fsync',
19
+ 'ftruncate',
20
+ 'futimes',
21
+ 'lchmod',
22
+ 'lchown',
23
+ 'link',
24
+ 'lstat',
25
+ 'mkdir',
26
+ 'mkdtemp',
27
+ 'open',
28
+ 'opendir',
29
+ 'readdir',
30
+ 'readFile',
31
+ 'readlink',
32
+ 'realpath',
33
+ 'rename',
34
+ 'rm',
35
+ 'rmdir',
36
+ 'stat',
37
+ 'symlink',
38
+ 'truncate',
39
+ 'unlink',
40
+ 'utimes',
41
+ 'writeFile'
42
+ ].filter(key => {
43
+ // Some commands are not available on some systems. Ex:
44
+ // fs.opendir was added in Node.js v12.12.0
45
+ // fs.rm was added in Node.js v14.14.0
46
+ // fs.lchown is not available on at least some Linux
47
+ return typeof fs[key] === 'function'
48
+ })
49
+
50
+ // Export cloned fs:
51
+ Object.assign(exports, fs)
52
+
53
+ // Universalify async methods:
54
+ api.forEach(method => {
55
+ exports[method] = u(fs[method])
56
+ })
57
+
58
+ // We differ from mz/fs in that we still ship the old, broken, fs.exists()
59
+ // since we are a drop-in replacement for the native module
60
+ exports.exists = function (filename, callback) {
61
+ if (typeof callback === 'function') {
62
+ return fs.exists(filename, callback)
63
+ }
64
+ return new Promise(resolve => {
65
+ return fs.exists(filename, resolve)
66
+ })
67
+ }
68
+
69
+ // fs.read(), fs.write(), & fs.writev() need special treatment due to multiple callback args
70
+
71
+ exports.read = function (fd, buffer, offset, length, position, callback) {
72
+ if (typeof callback === 'function') {
73
+ return fs.read(fd, buffer, offset, length, position, callback)
74
+ }
75
+ return new Promise((resolve, reject) => {
76
+ fs.read(fd, buffer, offset, length, position, (err, bytesRead, buffer) => {
77
+ if (err) return reject(err)
78
+ resolve({ bytesRead, buffer })
79
+ })
80
+ })
81
+ }
82
+
83
+ // Function signature can be
84
+ // fs.write(fd, buffer[, offset[, length[, position]]], callback)
85
+ // OR
86
+ // fs.write(fd, string[, position[, encoding]], callback)
87
+ // We need to handle both cases, so we use ...args
88
+ exports.write = function (fd, buffer, ...args) {
89
+ if (typeof args[args.length - 1] === 'function') {
90
+ return fs.write(fd, buffer, ...args)
91
+ }
92
+
93
+ return new Promise((resolve, reject) => {
94
+ fs.write(fd, buffer, ...args, (err, bytesWritten, buffer) => {
95
+ if (err) return reject(err)
96
+ resolve({ bytesWritten, buffer })
97
+ })
98
+ })
99
+ }
100
+
101
+ // fs.writev only available in Node v12.9.0+
102
+ if (typeof fs.writev === 'function') {
103
+ // Function signature is
104
+ // s.writev(fd, buffers[, position], callback)
105
+ // We need to handle the optional arg, so we use ...args
106
+ exports.writev = function (fd, buffers, ...args) {
107
+ if (typeof args[args.length - 1] === 'function') {
108
+ return fs.writev(fd, buffers, ...args)
109
+ }
110
+
111
+ return new Promise((resolve, reject) => {
112
+ fs.writev(fd, buffers, ...args, (err, bytesWritten, buffers) => {
113
+ if (err) return reject(err)
114
+ resolve({ bytesWritten, buffers })
115
+ })
116
+ })
117
+ }
118
+ }
119
+
120
+ // fs.realpath.native sometimes not available if fs is monkey-patched
121
+ if (typeof fs.realpath.native === 'function') {
122
+ exports.realpath.native = u(fs.realpath.native)
123
+ } else {
124
+ process.emitWarning(
125
+ 'fs.realpath.native is not a function. Is fs being monkey-patched?',
126
+ 'Warning', 'fs-extra-WARN0003'
127
+ )
128
+ }
@@ -0,0 +1,16 @@
1
+ 'use strict'
2
+
3
+ module.exports = {
4
+ // Export promiseified graceful-fs:
5
+ ...require('./fs'),
6
+ // Export extra methods:
7
+ ...require('./copy'),
8
+ ...require('./empty'),
9
+ ...require('./ensure'),
10
+ ...require('./json'),
11
+ ...require('./mkdirs'),
12
+ ...require('./move'),
13
+ ...require('./output-file'),
14
+ ...require('./path-exists'),
15
+ ...require('./remove')
16
+ }
@@ -0,0 +1,16 @@
1
+ 'use strict'
2
+
3
+ const u = require('universalify').fromPromise
4
+ const jsonFile = require('./jsonfile')
5
+
6
+ jsonFile.outputJson = u(require('./output-json'))
7
+ jsonFile.outputJsonSync = require('./output-json-sync')
8
+ // aliases
9
+ jsonFile.outputJSON = jsonFile.outputJson
10
+ jsonFile.outputJSONSync = jsonFile.outputJsonSync
11
+ jsonFile.writeJSON = jsonFile.writeJson
12
+ jsonFile.writeJSONSync = jsonFile.writeJsonSync
13
+ jsonFile.readJSON = jsonFile.readJson
14
+ jsonFile.readJSONSync = jsonFile.readJsonSync
15
+
16
+ module.exports = jsonFile
@@ -0,0 +1,11 @@
1
+ 'use strict'
2
+
3
+ const jsonFile = require('jsonfile')
4
+
5
+ module.exports = {
6
+ // jsonfile exports
7
+ readJson: jsonFile.readFile,
8
+ readJsonSync: jsonFile.readFileSync,
9
+ writeJson: jsonFile.writeFile,
10
+ writeJsonSync: jsonFile.writeFileSync
11
+ }
@@ -0,0 +1,12 @@
1
+ 'use strict'
2
+
3
+ const { stringify } = require('jsonfile/utils')
4
+ const { outputFileSync } = require('../output-file')
5
+
6
+ function outputJsonSync (file, data, options) {
7
+ const str = stringify(data, options)
8
+
9
+ outputFileSync(file, str, options)
10
+ }
11
+
12
+ module.exports = outputJsonSync
@@ -0,0 +1,12 @@
1
+ 'use strict'
2
+
3
+ const { stringify } = require('jsonfile/utils')
4
+ const { outputFile } = require('../output-file')
5
+
6
+ async function outputJson (file, data, options = {}) {
7
+ const str = stringify(data, options)
8
+
9
+ await outputFile(file, str, options)
10
+ }
11
+
12
+ module.exports = outputJson
@@ -0,0 +1,14 @@
1
+ 'use strict'
2
+ const u = require('universalify').fromPromise
3
+ const { makeDir: _makeDir, makeDirSync } = require('./make-dir')
4
+ const makeDir = u(_makeDir)
5
+
6
+ module.exports = {
7
+ mkdirs: makeDir,
8
+ mkdirsSync: makeDirSync,
9
+ // alias
10
+ mkdirp: makeDir,
11
+ mkdirpSync: makeDirSync,
12
+ ensureDir: makeDir,
13
+ ensureDirSync: makeDirSync
14
+ }
@@ -0,0 +1,27 @@
1
+ 'use strict'
2
+ const fs = require('../fs')
3
+ const { checkPath } = require('./utils')
4
+
5
+ const getMode = options => {
6
+ const defaults = { mode: 0o777 }
7
+ if (typeof options === 'number') return options
8
+ return ({ ...defaults, ...options }).mode
9
+ }
10
+
11
+ module.exports.makeDir = async (dir, options) => {
12
+ checkPath(dir)
13
+
14
+ return fs.mkdir(dir, {
15
+ mode: getMode(options),
16
+ recursive: true
17
+ })
18
+ }
19
+
20
+ module.exports.makeDirSync = (dir, options) => {
21
+ checkPath(dir)
22
+
23
+ return fs.mkdirSync(dir, {
24
+ mode: getMode(options),
25
+ recursive: true
26
+ })
27
+ }
@@ -0,0 +1,21 @@
1
+ // Adapted from https://github.com/sindresorhus/make-dir
2
+ // Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+ // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6
+ 'use strict'
7
+ const path = require('path')
8
+
9
+ // https://github.com/nodejs/node/issues/8987
10
+ // https://github.com/libuv/libuv/pull/1088
11
+ module.exports.checkPath = function checkPath (pth) {
12
+ if (process.platform === 'win32') {
13
+ const pathHasInvalidWinCharacters = /[<>:"|?*]/.test(pth.replace(path.parse(pth).root, ''))
14
+
15
+ if (pathHasInvalidWinCharacters) {
16
+ const error = new Error(`Path contains invalid characters: ${pth}`)
17
+ error.code = 'EINVAL'
18
+ throw error
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,7 @@
1
+ 'use strict'
2
+
3
+ const u = require('universalify').fromCallback
4
+ module.exports = {
5
+ move: u(require('./move')),
6
+ moveSync: require('./move-sync')
7
+ }