@nocobase/plugin-backup-restore 0.19.0-alpha.1

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 (158) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +118 -0
  3. package/README.zh-CN.md +118 -0
  4. package/client.d.ts +2 -0
  5. package/client.js +1 -0
  6. package/dist/client/Configuration.d.ts +2 -0
  7. package/dist/client/DuplicatorProvider.d.ts +2 -0
  8. package/dist/client/index.d.ts +5 -0
  9. package/dist/client/index.js +1 -0
  10. package/dist/client/locale/index.d.ts +4 -0
  11. package/dist/externalVersion.js +14 -0
  12. package/dist/index.d.ts +2 -0
  13. package/dist/index.js +39 -0
  14. package/dist/locale/en-US.json +44 -0
  15. package/dist/locale/ja-JP.d.ts +25 -0
  16. package/dist/locale/ja-JP.js +46 -0
  17. package/dist/locale/pt-BR.d.ts +26 -0
  18. package/dist/locale/pt-BR.js +48 -0
  19. package/dist/locale/zh-CN.json +50 -0
  20. package/dist/node_modules/@hapi/topo/lib/index.d.ts +60 -0
  21. package/dist/node_modules/@hapi/topo/lib/index.js +1 -0
  22. package/dist/node_modules/@hapi/topo/package.json +1 -0
  23. package/dist/node_modules/archiver/LICENSE +22 -0
  24. package/dist/node_modules/archiver/index.js +68 -0
  25. package/dist/node_modules/archiver/lib/core.js +974 -0
  26. package/dist/node_modules/archiver/lib/error.js +40 -0
  27. package/dist/node_modules/archiver/lib/plugins/json.js +110 -0
  28. package/dist/node_modules/archiver/lib/plugins/tar.js +167 -0
  29. package/dist/node_modules/archiver/lib/plugins/zip.js +120 -0
  30. package/dist/node_modules/archiver/node_modules/readable-stream/errors-browser.js +127 -0
  31. package/dist/node_modules/archiver/node_modules/readable-stream/errors.js +116 -0
  32. package/dist/node_modules/archiver/node_modules/readable-stream/experimentalWarning.js +17 -0
  33. package/dist/node_modules/archiver/node_modules/readable-stream/lib/_stream_duplex.js +126 -0
  34. package/dist/node_modules/archiver/node_modules/readable-stream/lib/_stream_passthrough.js +37 -0
  35. package/dist/node_modules/archiver/node_modules/readable-stream/lib/_stream_readable.js +1027 -0
  36. package/dist/node_modules/archiver/node_modules/readable-stream/lib/_stream_transform.js +190 -0
  37. package/dist/node_modules/archiver/node_modules/readable-stream/lib/_stream_writable.js +641 -0
  38. package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/async_iterator.js +180 -0
  39. package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/buffer_list.js +183 -0
  40. package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/destroy.js +96 -0
  41. package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +86 -0
  42. package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/from-browser.js +3 -0
  43. package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/from.js +52 -0
  44. package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/pipeline.js +86 -0
  45. package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/state.js +22 -0
  46. package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/stream-browser.js +1 -0
  47. package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/stream.js +1 -0
  48. package/dist/node_modules/archiver/node_modules/readable-stream/package.json +68 -0
  49. package/dist/node_modules/archiver/node_modules/readable-stream/readable-browser.js +9 -0
  50. package/dist/node_modules/archiver/node_modules/readable-stream/readable.js +16 -0
  51. package/dist/node_modules/archiver/node_modules/string_decoder/lib/string_decoder.js +296 -0
  52. package/dist/node_modules/archiver/node_modules/string_decoder/package.json +34 -0
  53. package/dist/node_modules/archiver/node_modules/tar-stream/extract.js +257 -0
  54. package/dist/node_modules/archiver/node_modules/tar-stream/headers.js +295 -0
  55. package/dist/node_modules/archiver/node_modules/tar-stream/index.js +2 -0
  56. package/dist/node_modules/archiver/node_modules/tar-stream/pack.js +255 -0
  57. package/dist/node_modules/archiver/node_modules/tar-stream/package.json +58 -0
  58. package/dist/node_modules/archiver/node_modules/tar-stream/sandbox.js +11 -0
  59. package/dist/node_modules/archiver/package.json +1 -0
  60. package/dist/node_modules/decompress/index.js +16 -0
  61. package/dist/node_modules/decompress/license +9 -0
  62. package/dist/node_modules/decompress/node_modules/make-dir/index.js +85 -0
  63. package/dist/node_modules/decompress/node_modules/make-dir/license +9 -0
  64. package/dist/node_modules/decompress/node_modules/make-dir/node_modules/pify/index.js +84 -0
  65. package/dist/node_modules/decompress/node_modules/make-dir/node_modules/pify/license +9 -0
  66. package/dist/node_modules/decompress/node_modules/make-dir/node_modules/pify/package.json +51 -0
  67. package/dist/node_modules/decompress/node_modules/make-dir/package.json +54 -0
  68. package/dist/node_modules/decompress/package.json +1 -0
  69. package/dist/node_modules/mkdirp/LICENSE +21 -0
  70. package/dist/node_modules/mkdirp/bin/cmd.js +68 -0
  71. package/dist/node_modules/mkdirp/index.js +1 -0
  72. package/dist/node_modules/mkdirp/lib/find-made.js +29 -0
  73. package/dist/node_modules/mkdirp/lib/mkdirp-manual.js +64 -0
  74. package/dist/node_modules/mkdirp/lib/mkdirp-native.js +39 -0
  75. package/dist/node_modules/mkdirp/lib/opts-arg.js +23 -0
  76. package/dist/node_modules/mkdirp/lib/path-arg.js +29 -0
  77. package/dist/node_modules/mkdirp/lib/use-native.js +10 -0
  78. package/dist/node_modules/mkdirp/package.json +1 -0
  79. package/dist/node_modules/mkdirp/readme.markdown +266 -0
  80. package/dist/node_modules/semver/LICENSE +15 -0
  81. package/dist/node_modules/semver/bin/semver.js +197 -0
  82. package/dist/node_modules/semver/classes/comparator.js +141 -0
  83. package/dist/node_modules/semver/classes/index.js +5 -0
  84. package/dist/node_modules/semver/classes/range.js +539 -0
  85. package/dist/node_modules/semver/classes/semver.js +302 -0
  86. package/dist/node_modules/semver/functions/clean.js +6 -0
  87. package/dist/node_modules/semver/functions/cmp.js +52 -0
  88. package/dist/node_modules/semver/functions/coerce.js +52 -0
  89. package/dist/node_modules/semver/functions/compare-build.js +7 -0
  90. package/dist/node_modules/semver/functions/compare-loose.js +3 -0
  91. package/dist/node_modules/semver/functions/compare.js +5 -0
  92. package/dist/node_modules/semver/functions/diff.js +65 -0
  93. package/dist/node_modules/semver/functions/eq.js +3 -0
  94. package/dist/node_modules/semver/functions/gt.js +3 -0
  95. package/dist/node_modules/semver/functions/gte.js +3 -0
  96. package/dist/node_modules/semver/functions/inc.js +19 -0
  97. package/dist/node_modules/semver/functions/lt.js +3 -0
  98. package/dist/node_modules/semver/functions/lte.js +3 -0
  99. package/dist/node_modules/semver/functions/major.js +3 -0
  100. package/dist/node_modules/semver/functions/minor.js +3 -0
  101. package/dist/node_modules/semver/functions/neq.js +3 -0
  102. package/dist/node_modules/semver/functions/parse.js +16 -0
  103. package/dist/node_modules/semver/functions/patch.js +3 -0
  104. package/dist/node_modules/semver/functions/prerelease.js +6 -0
  105. package/dist/node_modules/semver/functions/rcompare.js +3 -0
  106. package/dist/node_modules/semver/functions/rsort.js +3 -0
  107. package/dist/node_modules/semver/functions/satisfies.js +10 -0
  108. package/dist/node_modules/semver/functions/sort.js +3 -0
  109. package/dist/node_modules/semver/functions/valid.js +6 -0
  110. package/dist/node_modules/semver/index.js +1 -0
  111. package/dist/node_modules/semver/internal/constants.js +35 -0
  112. package/dist/node_modules/semver/internal/debug.js +9 -0
  113. package/dist/node_modules/semver/internal/identifiers.js +23 -0
  114. package/dist/node_modules/semver/internal/parse-options.js +15 -0
  115. package/dist/node_modules/semver/internal/re.js +212 -0
  116. package/dist/node_modules/semver/package.json +1 -0
  117. package/dist/node_modules/semver/preload.js +2 -0
  118. package/dist/node_modules/semver/range.bnf +16 -0
  119. package/dist/node_modules/semver/ranges/gtr.js +4 -0
  120. package/dist/node_modules/semver/ranges/intersects.js +7 -0
  121. package/dist/node_modules/semver/ranges/ltr.js +4 -0
  122. package/dist/node_modules/semver/ranges/max-satisfying.js +25 -0
  123. package/dist/node_modules/semver/ranges/min-satisfying.js +24 -0
  124. package/dist/node_modules/semver/ranges/min-version.js +61 -0
  125. package/dist/node_modules/semver/ranges/outside.js +80 -0
  126. package/dist/node_modules/semver/ranges/simplify.js +47 -0
  127. package/dist/node_modules/semver/ranges/subset.js +247 -0
  128. package/dist/node_modules/semver/ranges/to-comparators.js +8 -0
  129. package/dist/node_modules/semver/ranges/valid.js +11 -0
  130. package/dist/server/app-migrator.d.ts +17 -0
  131. package/dist/server/app-migrator.js +61 -0
  132. package/dist/server/collection-group-manager.d.ts +4 -0
  133. package/dist/server/collection-group-manager.js +29 -0
  134. package/dist/server/commands/restore-command.d.ts +2 -0
  135. package/dist/server/commands/restore-command.js +67 -0
  136. package/dist/server/dumper.d.ts +71 -0
  137. package/dist/server/dumper.js +406 -0
  138. package/dist/server/errors/restore-check-error.d.ts +3 -0
  139. package/dist/server/errors/restore-check-error.js +32 -0
  140. package/dist/server/field-value-writer.d.ts +9 -0
  141. package/dist/server/field-value-writer.js +101 -0
  142. package/dist/server/index.d.ts +1 -0
  143. package/dist/server/index.js +33 -0
  144. package/dist/server/locale/zh-CN.d.ts +9 -0
  145. package/dist/server/locale/zh-CN.js +30 -0
  146. package/dist/server/resourcers/backup-files.d.ts +25 -0
  147. package/dist/server/resourcers/backup-files.js +193 -0
  148. package/dist/server/restorer.d.ts +36 -0
  149. package/dist/server/restorer.js +326 -0
  150. package/dist/server/server.d.ts +5 -0
  151. package/dist/server/server.js +41 -0
  152. package/dist/server/utils.d.ts +5 -0
  153. package/dist/server/utils.js +78 -0
  154. package/dist/swagger/index.d.ts +392 -0
  155. package/dist/swagger/index.js +447 -0
  156. package/package.json +40 -0
  157. package/server.d.ts +2 -0
  158. package/server.js +1 -0
@@ -0,0 +1,266 @@
1
+ # mkdirp
2
+
3
+ Like `mkdir -p`, but in Node.js!
4
+
5
+ Now with a modern API and no\* bugs!
6
+
7
+ <small>\* may contain some bugs</small>
8
+
9
+ # example
10
+
11
+ ## pow.js
12
+
13
+ ```js
14
+ const mkdirp = require('mkdirp')
15
+
16
+ // return value is a Promise resolving to the first directory created
17
+ mkdirp('/tmp/foo/bar/baz').then(made =>
18
+ console.log(`made directories, starting with ${made}`))
19
+ ```
20
+
21
+ Output (where `/tmp/foo` already exists)
22
+
23
+ ```
24
+ made directories, starting with /tmp/foo/bar
25
+ ```
26
+
27
+ Or, if you don't have time to wait around for promises:
28
+
29
+ ```js
30
+ const mkdirp = require('mkdirp')
31
+
32
+ // return value is the first directory created
33
+ const made = mkdirp.sync('/tmp/foo/bar/baz')
34
+ console.log(`made directories, starting with ${made}`)
35
+ ```
36
+
37
+ And now /tmp/foo/bar/baz exists, huzzah!
38
+
39
+ # methods
40
+
41
+ ```js
42
+ const mkdirp = require('mkdirp')
43
+ ```
44
+
45
+ ## mkdirp(dir, [opts]) -> Promise<String | undefined>
46
+
47
+ Create a new directory and any necessary subdirectories at `dir` with octal
48
+ permission string `opts.mode`. If `opts` is a string or number, it will be
49
+ treated as the `opts.mode`.
50
+
51
+ If `opts.mode` isn't specified, it defaults to `0o777 &
52
+ (~process.umask())`.
53
+
54
+ Promise resolves to first directory `made` that had to be created, or
55
+ `undefined` if everything already exists. Promise rejects if any errors
56
+ are encountered. Note that, in the case of promise rejection, some
57
+ directories _may_ have been created, as recursive directory creation is not
58
+ an atomic operation.
59
+
60
+ You can optionally pass in an alternate `fs` implementation by passing in
61
+ `opts.fs`. Your implementation should have `opts.fs.mkdir(path, opts, cb)`
62
+ and `opts.fs.stat(path, cb)`.
63
+
64
+ You can also override just one or the other of `mkdir` and `stat` by
65
+ passing in `opts.stat` or `opts.mkdir`, or providing an `fs` option that
66
+ only overrides one of these.
67
+
68
+ ## mkdirp.sync(dir, opts) -> String|null
69
+
70
+ Synchronously create a new directory and any necessary subdirectories at
71
+ `dir` with octal permission string `opts.mode`. If `opts` is a string or
72
+ number, it will be treated as the `opts.mode`.
73
+
74
+ If `opts.mode` isn't specified, it defaults to `0o777 &
75
+ (~process.umask())`.
76
+
77
+ Returns the first directory that had to be created, or undefined if
78
+ everything already exists.
79
+
80
+ You can optionally pass in an alternate `fs` implementation by passing in
81
+ `opts.fs`. Your implementation should have `opts.fs.mkdirSync(path, mode)`
82
+ and `opts.fs.statSync(path)`.
83
+
84
+ You can also override just one or the other of `mkdirSync` and `statSync`
85
+ by passing in `opts.statSync` or `opts.mkdirSync`, or providing an `fs`
86
+ option that only overrides one of these.
87
+
88
+ ## mkdirp.manual, mkdirp.manualSync
89
+
90
+ Use the manual implementation (not the native one). This is the default
91
+ when the native implementation is not available or the stat/mkdir
92
+ implementation is overridden.
93
+
94
+ ## mkdirp.native, mkdirp.nativeSync
95
+
96
+ Use the native implementation (not the manual one). This is the default
97
+ when the native implementation is available and stat/mkdir are not
98
+ overridden.
99
+
100
+ # implementation
101
+
102
+ On Node.js v10.12.0 and above, use the native `fs.mkdir(p,
103
+ {recursive:true})` option, unless `fs.mkdir`/`fs.mkdirSync` has been
104
+ overridden by an option.
105
+
106
+ ## native implementation
107
+
108
+ - If the path is a root directory, then pass it to the underlying
109
+ implementation and return the result/error. (In this case, it'll either
110
+ succeed or fail, but we aren't actually creating any dirs.)
111
+ - Walk up the path statting each directory, to find the first path that
112
+ will be created, `made`.
113
+ - Call `fs.mkdir(path, { recursive: true })` (or `fs.mkdirSync`)
114
+ - If error, raise it to the caller.
115
+ - Return `made`.
116
+
117
+ ## manual implementation
118
+
119
+ - Call underlying `fs.mkdir` implementation, with `recursive: false`
120
+ - If error:
121
+ - If path is a root directory, raise to the caller and do not handle it
122
+ - If ENOENT, mkdirp parent dir, store result as `made`
123
+ - stat(path)
124
+ - If error, raise original `mkdir` error
125
+ - If directory, return `made`
126
+ - Else, raise original `mkdir` error
127
+ - else
128
+ - return `undefined` if a root dir, or `made` if set, or `path`
129
+
130
+ ## windows vs unix caveat
131
+
132
+ On Windows file systems, attempts to create a root directory (ie, a drive
133
+ letter or root UNC path) will fail. If the root directory exists, then it
134
+ will fail with `EPERM`. If the root directory does not exist, then it will
135
+ fail with `ENOENT`.
136
+
137
+ On posix file systems, attempts to create a root directory (in recursive
138
+ mode) will succeed silently, as it is treated like just another directory
139
+ that already exists. (In non-recursive mode, of course, it fails with
140
+ `EEXIST`.)
141
+
142
+ In order to preserve this system-specific behavior (and because it's not as
143
+ if we can create the parent of a root directory anyway), attempts to create
144
+ a root directory are passed directly to the `fs` implementation, and any
145
+ errors encountered are not handled.
146
+
147
+ ## native error caveat
148
+
149
+ The native implementation (as of at least Node.js v13.4.0) does not provide
150
+ appropriate errors in some cases (see
151
+ [nodejs/node#31481](https://github.com/nodejs/node/issues/31481) and
152
+ [nodejs/node#28015](https://github.com/nodejs/node/issues/28015)).
153
+
154
+ In order to work around this issue, the native implementation will fall
155
+ back to the manual implementation if an `ENOENT` error is encountered.
156
+
157
+ # choosing a recursive mkdir implementation
158
+
159
+ There are a few to choose from! Use the one that suits your needs best :D
160
+
161
+ ## use `fs.mkdir(path, {recursive: true}, cb)` if:
162
+
163
+ - You wish to optimize performance even at the expense of other factors.
164
+ - You don't need to know the first dir created.
165
+ - You are ok with getting `ENOENT` as the error when some other problem is
166
+ the actual cause.
167
+ - You can limit your platforms to Node.js v10.12 and above.
168
+ - You're ok with using callbacks instead of promises.
169
+ - You don't need/want a CLI.
170
+ - You don't need to override the `fs` methods in use.
171
+
172
+ ## use this module (mkdirp 1.x) if:
173
+
174
+ - You need to know the first directory that was created.
175
+ - You wish to use the native implementation if available, but fall back
176
+ when it's not.
177
+ - You prefer promise-returning APIs to callback-taking APIs.
178
+ - You want more useful error messages than the native recursive mkdir
179
+ provides (at least as of Node.js v13.4), and are ok with re-trying on
180
+ `ENOENT` to achieve this.
181
+ - You need (or at least, are ok with) a CLI.
182
+ - You need to override the `fs` methods in use.
183
+
184
+ ## use [`make-dir`](http://npm.im/make-dir) if:
185
+
186
+ - You do not need to know the first dir created (and wish to save a few
187
+ `stat` calls when using the native implementation for this reason).
188
+ - You wish to use the native implementation if available, but fall back
189
+ when it's not.
190
+ - You prefer promise-returning APIs to callback-taking APIs.
191
+ - You are ok with occasionally getting `ENOENT` errors for failures that
192
+ are actually related to something other than a missing file system entry.
193
+ - You don't need/want a CLI.
194
+ - You need to override the `fs` methods in use.
195
+
196
+ ## use mkdirp 0.x if:
197
+
198
+ - You need to know the first directory that was created.
199
+ - You need (or at least, are ok with) a CLI.
200
+ - You need to override the `fs` methods in use.
201
+ - You're ok with using callbacks instead of promises.
202
+ - You are not running on Windows, where the root-level ENOENT errors can
203
+ lead to infinite regress.
204
+ - You think vinyl just sounds warmer and richer for some weird reason.
205
+ - You are supporting truly ancient Node.js versions, before even the advent
206
+ of a `Promise` language primitive. (Please don't. You deserve better.)
207
+
208
+ # cli
209
+
210
+ This package also ships with a `mkdirp` command.
211
+
212
+ ```
213
+ $ mkdirp -h
214
+
215
+ usage: mkdirp [DIR1,DIR2..] {OPTIONS}
216
+
217
+ Create each supplied directory including any necessary parent directories
218
+ that don't yet exist.
219
+
220
+ If the directory already exists, do nothing.
221
+
222
+ OPTIONS are:
223
+
224
+ -m<mode> If a directory needs to be created, set the mode as an octal
225
+ --mode=<mode> permission string.
226
+
227
+ -v --version Print the mkdirp version number
228
+
229
+ -h --help Print this helpful banner
230
+
231
+ -p --print Print the first directories created for each path provided
232
+
233
+ --manual Use manual implementation, even if native is available
234
+ ```
235
+
236
+ # install
237
+
238
+ With [npm](http://npmjs.org) do:
239
+
240
+ ```
241
+ npm install mkdirp
242
+ ```
243
+
244
+ to get the library locally, or
245
+
246
+ ```
247
+ npm install -g mkdirp
248
+ ```
249
+
250
+ to get the command everywhere, or
251
+
252
+ ```
253
+ npx mkdirp ...
254
+ ```
255
+
256
+ to run the command without installing it globally.
257
+
258
+ # platform support
259
+
260
+ This module works on node v8, but only v10 and above are officially
261
+ supported, as Node v8 reached its LTS end of life 2020-01-01, which is in
262
+ the past, as of this writing.
263
+
264
+ # license
265
+
266
+ MIT
@@ -0,0 +1,15 @@
1
+ The ISC License
2
+
3
+ Copyright (c) Isaac Z. Schlueter and Contributors
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15
+ IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,197 @@
1
+ #!/usr/bin/env node
2
+ // Standalone semver comparison program.
3
+ // Exits successfully and prints matching version(s) if
4
+ // any supplied version is valid and passes all tests.
5
+
6
+ const argv = process.argv.slice(2)
7
+
8
+ let versions = []
9
+
10
+ const range = []
11
+
12
+ let inc = null
13
+
14
+ const version = require('../package.json').version
15
+
16
+ let loose = false
17
+
18
+ let includePrerelease = false
19
+
20
+ let coerce = false
21
+
22
+ let rtl = false
23
+
24
+ let identifier
25
+
26
+ let identifierBase
27
+
28
+ const semver = require('../')
29
+ const parseOptions = require('../internal/parse-options')
30
+
31
+ let reverse = false
32
+
33
+ let options = {}
34
+
35
+ const main = () => {
36
+ if (!argv.length) {
37
+ return help()
38
+ }
39
+ while (argv.length) {
40
+ let a = argv.shift()
41
+ const indexOfEqualSign = a.indexOf('=')
42
+ if (indexOfEqualSign !== -1) {
43
+ const value = a.slice(indexOfEqualSign + 1)
44
+ a = a.slice(0, indexOfEqualSign)
45
+ argv.unshift(value)
46
+ }
47
+ switch (a) {
48
+ case '-rv': case '-rev': case '--rev': case '--reverse':
49
+ reverse = true
50
+ break
51
+ case '-l': case '--loose':
52
+ loose = true
53
+ break
54
+ case '-p': case '--include-prerelease':
55
+ includePrerelease = true
56
+ break
57
+ case '-v': case '--version':
58
+ versions.push(argv.shift())
59
+ break
60
+ case '-i': case '--inc': case '--increment':
61
+ switch (argv[0]) {
62
+ case 'major': case 'minor': case 'patch': case 'prerelease':
63
+ case 'premajor': case 'preminor': case 'prepatch':
64
+ inc = argv.shift()
65
+ break
66
+ default:
67
+ inc = 'patch'
68
+ break
69
+ }
70
+ break
71
+ case '--preid':
72
+ identifier = argv.shift()
73
+ break
74
+ case '-r': case '--range':
75
+ range.push(argv.shift())
76
+ break
77
+ case '-n':
78
+ identifierBase = argv.shift()
79
+ if (identifierBase === 'false') {
80
+ identifierBase = false
81
+ }
82
+ break
83
+ case '-c': case '--coerce':
84
+ coerce = true
85
+ break
86
+ case '--rtl':
87
+ rtl = true
88
+ break
89
+ case '--ltr':
90
+ rtl = false
91
+ break
92
+ case '-h': case '--help': case '-?':
93
+ return help()
94
+ default:
95
+ versions.push(a)
96
+ break
97
+ }
98
+ }
99
+
100
+ options = parseOptions({ loose, includePrerelease, rtl })
101
+
102
+ versions = versions.map((v) => {
103
+ return coerce ? (semver.coerce(v, options) || { version: v }).version : v
104
+ }).filter((v) => {
105
+ return semver.valid(v)
106
+ })
107
+ if (!versions.length) {
108
+ return fail()
109
+ }
110
+ if (inc && (versions.length !== 1 || range.length)) {
111
+ return failInc()
112
+ }
113
+
114
+ for (let i = 0, l = range.length; i < l; i++) {
115
+ versions = versions.filter((v) => {
116
+ return semver.satisfies(v, range[i], options)
117
+ })
118
+ if (!versions.length) {
119
+ return fail()
120
+ }
121
+ }
122
+ return success(versions)
123
+ }
124
+
125
+ const failInc = () => {
126
+ console.error('--inc can only be used on a single version with no range')
127
+ fail()
128
+ }
129
+
130
+ const fail = () => process.exit(1)
131
+
132
+ const success = () => {
133
+ const compare = reverse ? 'rcompare' : 'compare'
134
+ versions.sort((a, b) => {
135
+ return semver[compare](a, b, options)
136
+ }).map((v) => {
137
+ return semver.clean(v, options)
138
+ }).map((v) => {
139
+ return inc ? semver.inc(v, inc, options, identifier, identifierBase) : v
140
+ }).forEach((v, i, _) => {
141
+ console.log(v)
142
+ })
143
+ }
144
+
145
+ const help = () => console.log(
146
+ `SemVer ${version}
147
+
148
+ A JavaScript implementation of the https://semver.org/ specification
149
+ Copyright Isaac Z. Schlueter
150
+
151
+ Usage: semver [options] <version> [<version> [...]]
152
+ Prints valid versions sorted by SemVer precedence
153
+
154
+ Options:
155
+ -r --range <range>
156
+ Print versions that match the specified range.
157
+
158
+ -i --increment [<level>]
159
+ Increment a version by the specified level. Level can
160
+ be one of: major, minor, patch, premajor, preminor,
161
+ prepatch, or prerelease. Default level is 'patch'.
162
+ Only one version may be specified.
163
+
164
+ --preid <identifier>
165
+ Identifier to be used to prefix premajor, preminor,
166
+ prepatch or prerelease version increments.
167
+
168
+ -l --loose
169
+ Interpret versions and ranges loosely
170
+
171
+ -p --include-prerelease
172
+ Always include prerelease versions in range matching
173
+
174
+ -c --coerce
175
+ Coerce a string into SemVer if possible
176
+ (does not imply --loose)
177
+
178
+ --rtl
179
+ Coerce version strings right to left
180
+
181
+ --ltr
182
+ Coerce version strings left to right (default)
183
+
184
+ -n <base>
185
+ Base number to be used for the prerelease identifier.
186
+ Can be either 0 or 1, or false to omit the number altogether.
187
+ Defaults to 0.
188
+
189
+ Program exits successfully if any valid version satisfies
190
+ all supplied ranges, and prints all satisfying versions.
191
+
192
+ If no satisfying versions are found, then exits failure.
193
+
194
+ Versions are printed in ascending order, so supplying
195
+ multiple versions to the utility will just sort them.`)
196
+
197
+ main()
@@ -0,0 +1,141 @@
1
+ const ANY = Symbol('SemVer ANY')
2
+ // hoisted class for cyclic dependency
3
+ class Comparator {
4
+ static get ANY () {
5
+ return ANY
6
+ }
7
+
8
+ constructor (comp, options) {
9
+ options = parseOptions(options)
10
+
11
+ if (comp instanceof Comparator) {
12
+ if (comp.loose === !!options.loose) {
13
+ return comp
14
+ } else {
15
+ comp = comp.value
16
+ }
17
+ }
18
+
19
+ comp = comp.trim().split(/\s+/).join(' ')
20
+ debug('comparator', comp, options)
21
+ this.options = options
22
+ this.loose = !!options.loose
23
+ this.parse(comp)
24
+
25
+ if (this.semver === ANY) {
26
+ this.value = ''
27
+ } else {
28
+ this.value = this.operator + this.semver.version
29
+ }
30
+
31
+ debug('comp', this)
32
+ }
33
+
34
+ parse (comp) {
35
+ const r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR]
36
+ const m = comp.match(r)
37
+
38
+ if (!m) {
39
+ throw new TypeError(`Invalid comparator: ${comp}`)
40
+ }
41
+
42
+ this.operator = m[1] !== undefined ? m[1] : ''
43
+ if (this.operator === '=') {
44
+ this.operator = ''
45
+ }
46
+
47
+ // if it literally is just '>' or '' then allow anything.
48
+ if (!m[2]) {
49
+ this.semver = ANY
50
+ } else {
51
+ this.semver = new SemVer(m[2], this.options.loose)
52
+ }
53
+ }
54
+
55
+ toString () {
56
+ return this.value
57
+ }
58
+
59
+ test (version) {
60
+ debug('Comparator.test', version, this.options.loose)
61
+
62
+ if (this.semver === ANY || version === ANY) {
63
+ return true
64
+ }
65
+
66
+ if (typeof version === 'string') {
67
+ try {
68
+ version = new SemVer(version, this.options)
69
+ } catch (er) {
70
+ return false
71
+ }
72
+ }
73
+
74
+ return cmp(version, this.operator, this.semver, this.options)
75
+ }
76
+
77
+ intersects (comp, options) {
78
+ if (!(comp instanceof Comparator)) {
79
+ throw new TypeError('a Comparator is required')
80
+ }
81
+
82
+ if (this.operator === '') {
83
+ if (this.value === '') {
84
+ return true
85
+ }
86
+ return new Range(comp.value, options).test(this.value)
87
+ } else if (comp.operator === '') {
88
+ if (comp.value === '') {
89
+ return true
90
+ }
91
+ return new Range(this.value, options).test(comp.semver)
92
+ }
93
+
94
+ options = parseOptions(options)
95
+
96
+ // Special cases where nothing can possibly be lower
97
+ if (options.includePrerelease &&
98
+ (this.value === '<0.0.0-0' || comp.value === '<0.0.0-0')) {
99
+ return false
100
+ }
101
+ if (!options.includePrerelease &&
102
+ (this.value.startsWith('<0.0.0') || comp.value.startsWith('<0.0.0'))) {
103
+ return false
104
+ }
105
+
106
+ // Same direction increasing (> or >=)
107
+ if (this.operator.startsWith('>') && comp.operator.startsWith('>')) {
108
+ return true
109
+ }
110
+ // Same direction decreasing (< or <=)
111
+ if (this.operator.startsWith('<') && comp.operator.startsWith('<')) {
112
+ return true
113
+ }
114
+ // same SemVer and both sides are inclusive (<= or >=)
115
+ if (
116
+ (this.semver.version === comp.semver.version) &&
117
+ this.operator.includes('=') && comp.operator.includes('=')) {
118
+ return true
119
+ }
120
+ // opposite directions less than
121
+ if (cmp(this.semver, '<', comp.semver, options) &&
122
+ this.operator.startsWith('>') && comp.operator.startsWith('<')) {
123
+ return true
124
+ }
125
+ // opposite directions greater than
126
+ if (cmp(this.semver, '>', comp.semver, options) &&
127
+ this.operator.startsWith('<') && comp.operator.startsWith('>')) {
128
+ return true
129
+ }
130
+ return false
131
+ }
132
+ }
133
+
134
+ module.exports = Comparator
135
+
136
+ const parseOptions = require('../internal/parse-options')
137
+ const { safeRe: re, t } = require('../internal/re')
138
+ const cmp = require('../functions/cmp')
139
+ const debug = require('../internal/debug')
140
+ const SemVer = require('./semver')
141
+ const Range = require('./range')
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ SemVer: require('./semver.js'),
3
+ Range: require('./range.js'),
4
+ Comparator: require('./comparator.js'),
5
+ }