vis-dev-utils 4.0.45 → 5.0.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 (92) hide show
  1. package/babel-preset/index.cjs +102 -0
  2. package/babel-preset/index.cjs.map +1 -0
  3. package/babel-preset/{index.js → index.mjs} +58 -31
  4. package/babel-preset/index.mjs.map +1 -0
  5. package/bin/ci-utils.js +35 -41
  6. package/bin/ci-utils.js.map +1 -1
  7. package/bin/generate-examples-index.js +779 -1265
  8. package/bin/generate-examples-index.js.map +1 -1
  9. package/bin/test-e2e-interop.js +431 -3492
  10. package/bin/test-e2e-interop.js.map +1 -1
  11. package/declarations/babel-preset/index.d.ts +23 -0
  12. package/declarations/babel-preset/index.d.ts.map +1 -0
  13. package/declarations/ci-utils/index.d.ts +2 -0
  14. package/declarations/ci-utils/index.d.ts.map +1 -0
  15. package/declarations/generate-examples-index/cli.d.ts +44 -0
  16. package/declarations/generate-examples-index/cli.d.ts.map +1 -0
  17. package/declarations/generate-examples-index/content-builder/builder.d.ts +53 -0
  18. package/declarations/generate-examples-index/content-builder/builder.d.ts.map +1 -0
  19. package/declarations/generate-examples-index/content-builder/common.d.ts +47 -0
  20. package/declarations/generate-examples-index/content-builder/common.d.ts.map +1 -0
  21. package/declarations/generate-examples-index/content-builder/format.d.ts +5 -0
  22. package/declarations/generate-examples-index/content-builder/format.d.ts.map +1 -0
  23. package/declarations/generate-examples-index/content-builder/html/index.d.ts +3 -0
  24. package/declarations/generate-examples-index/content-builder/html/index.d.ts.map +1 -0
  25. package/declarations/generate-examples-index/content-builder/index.d.ts +6 -0
  26. package/declarations/generate-examples-index/content-builder/index.d.ts.map +1 -0
  27. package/declarations/generate-examples-index/content-builder/md/index.d.ts +3 -0
  28. package/declarations/generate-examples-index/content-builder/md/index.d.ts.map +1 -0
  29. package/declarations/generate-examples-index/content-builder/playground/codepen.d.ts +6 -0
  30. package/declarations/generate-examples-index/content-builder/playground/codepen.d.ts.map +1 -0
  31. package/declarations/generate-examples-index/content-builder/playground/data.d.ts +8 -0
  32. package/declarations/generate-examples-index/content-builder/playground/data.d.ts.map +1 -0
  33. package/declarations/generate-examples-index/content-builder/playground/index.d.ts +4 -0
  34. package/declarations/generate-examples-index/content-builder/playground/index.d.ts.map +1 -0
  35. package/declarations/generate-examples-index/content-builder/playground/jsfiddle.d.ts +6 -0
  36. package/declarations/generate-examples-index/content-builder/playground/jsfiddle.d.ts.map +1 -0
  37. package/declarations/generate-examples-index/content-builder/screenshots/index.d.ts +26 -0
  38. package/declarations/generate-examples-index/content-builder/screenshots/index.d.ts.map +1 -0
  39. package/declarations/generate-examples-index/index.d.ts +2 -0
  40. package/declarations/generate-examples-index/index.d.ts.map +1 -0
  41. package/declarations/generate-examples-index/paths.d.ts +16 -0
  42. package/declarations/generate-examples-index/paths.d.ts.map +1 -0
  43. package/declarations/generate-examples-index/types.d.ts +61 -0
  44. package/declarations/generate-examples-index/types.d.ts.map +1 -0
  45. package/declarations/module/constants.d.ts +2 -0
  46. package/declarations/module/constants.d.ts.map +1 -0
  47. package/declarations/{generate-rollup-configuration → module/generate-rollup-configuration}/index.d.ts +4 -3
  48. package/declarations/module/generate-rollup-configuration/index.d.ts.map +1 -0
  49. package/declarations/{header.d.ts → module/header.d.ts} +1 -3
  50. package/declarations/module/header.d.ts.map +1 -0
  51. package/declarations/module/index.d.ts.map +1 -0
  52. package/declarations/module/inspect-npm-pack.d.ts +8 -0
  53. package/declarations/module/inspect-npm-pack.d.ts.map +1 -0
  54. package/declarations/module/util.d.ts.map +1 -0
  55. package/declarations/test-e2e-interop/cli.d.ts +18 -0
  56. package/declarations/test-e2e-interop/cli.d.ts.map +1 -0
  57. package/declarations/test-e2e-interop/index.d.ts +2 -0
  58. package/declarations/test-e2e-interop/index.d.ts.map +1 -0
  59. package/declarations/test-e2e-interop/test.d.ts +23 -0
  60. package/declarations/test-e2e-interop/test.d.ts.map +1 -0
  61. package/declarations/test-e2e-interop/util.d.ts +49 -0
  62. package/declarations/test-e2e-interop/util.d.ts.map +1 -0
  63. package/dist/vis-dev-utils.cjs +871 -0
  64. package/dist/vis-dev-utils.cjs.map +1 -0
  65. package/dist/vis-dev-utils.mjs +864 -0
  66. package/dist/vis-dev-utils.mjs.map +1 -0
  67. package/package.json +85 -63
  68. package/babel-register/index.js +0 -110
  69. package/babel-register/index.js.map +0 -1
  70. package/declarations/constants.d.ts +0 -2
  71. package/declarations/constants.d.ts.map +0 -1
  72. package/declarations/generate-rollup-configuration/index.d.ts.map +0 -1
  73. package/declarations/header.d.ts.map +0 -1
  74. package/declarations/index.d.ts.map +0 -1
  75. package/declarations/inspect-npm-pack.d.ts +0 -8
  76. package/declarations/inspect-npm-pack.d.ts.map +0 -1
  77. package/declarations/util.d.ts.map +0 -1
  78. package/dist/vis-dev-utils.cjs.js +0 -777
  79. package/dist/vis-dev-utils.cjs.js.map +0 -1
  80. package/dist/vis-dev-utils.esm.js +0 -771
  81. package/dist/vis-dev-utils.esm.js.map +0 -1
  82. package/lib/header.d.ts +0 -38
  83. package/lib/header.d.ts.map +0 -1
  84. package/lib/header.js +0 -85
  85. package/lib/header.js.map +0 -1
  86. package/lib/inspect-npm-pack.d.ts +0 -8
  87. package/lib/inspect-npm-pack.d.ts.map +0 -1
  88. package/lib/inspect-npm-pack.js +0 -74
  89. package/lib/inspect-npm-pack.js.map +0 -1
  90. /package/declarations/{index.d.ts → module/index.d.ts} +0 -0
  91. /package/declarations/{util.d.ts → module/util.d.ts} +0 -0
  92. /package/eslint-shareable-config/{index.js → index.cjs} +0 -0
@@ -6,8 +6,8 @@
6
6
  *
7
7
  * Development utilities for the Vis family projects.
8
8
  *
9
- * @version 4.0.45
10
- * @date 2023-11-13T21:21:31.898Z
9
+ * @version 5.0.1
10
+ * @date 2025-07-13T10:18:37.410Z
11
11
  *
12
12
  * @copyright (c) 2011-2017 Almende B.V, http://almende.com
13
13
  * @copyright (c) 2017-2019 visjs contributors, https://github.com/visjs
@@ -26,2773 +26,170 @@
26
26
  * vis.js may be distributed under either license.
27
27
  */
28
28
 
29
- 'use strict';
30
-
31
- var _Array$from = require('@babel/runtime-corejs3/core-js-stable/array/from');
32
- var _Symbol = require('@babel/runtime-corejs3/core-js-stable/symbol');
33
- var _getIteratorMethod = require('@babel/runtime-corejs3/core-js/get-iterator-method');
34
- var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
35
- var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
36
- var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
37
- var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
38
- var _flatMapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/flat-map');
39
- var _sliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/slice');
40
- var yargs = require('yargs');
41
- var require$$1 = require('node:path');
42
- var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
43
- var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
44
- var _Set = require('@babel/runtime-corejs3/core-js-stable/set');
45
- var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
46
- var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
47
- var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
48
- var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
49
- var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
50
- var _Object$create = require('@babel/runtime-corejs3/core-js-stable/object/create');
51
- var _Object$freeze = require('@babel/runtime-corejs3/core-js-stable/object/freeze');
52
- var _Map = require('@babel/runtime-corejs3/core-js-stable/map');
53
- var _Promise = require('@babel/runtime-corejs3/core-js-stable/promise');
54
- var _everyInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/every');
55
- var _valuesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/values');
56
- var _repeatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/repeat');
57
- var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
58
- var tmp = require('tmp');
59
- var findUp = require('find-up');
60
- var require$$0$2 = require('node:fs');
61
- var require$$0 = require('node:constants');
62
- var require$$0$1 = require('node:stream');
63
- var require$$4 = require('node:util');
64
- var require$$5 = require('node:assert');
65
- var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
66
- var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
67
- var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
68
- var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
69
- var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
70
- var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
71
- var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
72
- var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
73
- var _padStartInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/pad-start');
74
- var node_child_process = require('node:child_process');
75
-
76
- var y = yargs.strict(true).usage("test-e2e-interop [options]").hide("version").config().help().option("fail-command", {
77
- demandOption: false,
78
- describe: 'This command will be run in a shell (therefore commands like "$SHELL" will work) after failure to inspect the state.',
79
- type: "string"
80
- }).option("package-script", {
81
- array: true,
82
- default: ["clean?", "build!", "test!", "generate-examples-index?"],
83
- demandOption: false,
84
- describe: 'The package scripts to run with each package, either "script-name!" to fail or "script-name?" to skip if the script doesn\'t exist in given package. By default the script is used for all packages, if you want to use it only for one add package name: "package-name script-name!". Scripts are invoked sequentially and command line order is preserved.',
85
- type: "string"
86
- }).option("project", {
87
- array: true,
88
- default: [],
89
- demandOption: false,
90
- describe: 'Projects to clone using Git, copy from directory or install from tarball. The format is "package-name URL/path".',
91
- type: "string"
92
- }).option("tmp-dir", {
93
- demandOption: false,
94
- describe: "The working directory for E2E testing. If omitted a new tmp dir will be created and then disposed of.",
95
- type: "string"
96
- }).option("logs-to-stdout", {
97
- demandOption: false,
98
- default: false,
99
- describe: "Output the logs to the stdout after the tests finished.",
100
- type: "boolean"
101
- });
102
- /**
103
- *
104
- */
105
- function parseArguments() {
106
- return y.parserConfiguration({
107
- "camel-case-expansion": false
108
- }).parseSync();
109
- }
110
-
111
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
112
-
113
- var fs$h = {};
114
-
115
- var universalify$1 = {};
116
-
117
- universalify$1.fromCallback = function (fn) {
118
- return Object.defineProperty(function (...args) {
119
- if (typeof args[args.length - 1] === 'function') fn.apply(this, args);
120
- else {
121
- return new Promise((resolve, reject) => {
122
- fn.call(
123
- this,
124
- ...args,
125
- (err, res) => (err != null) ? reject(err) : resolve(res)
126
- );
127
- })
128
- }
129
- }, 'name', { value: fn.name })
130
- };
131
-
132
- universalify$1.fromPromise = function (fn) {
133
- return Object.defineProperty(function (...args) {
134
- const cb = args[args.length - 1];
135
- if (typeof cb !== 'function') return fn.apply(this, args)
136
- else fn.apply(this, args.slice(0, -1)).then(r => cb(null, r), cb);
137
- }, 'name', { value: fn.name })
138
- };
139
-
140
- var constants = require$$0;
141
-
142
- var origCwd = process.cwd;
143
- var cwd = null;
144
-
145
- var platform = process.env.GRACEFUL_FS_PLATFORM || process.platform;
146
-
147
- process.cwd = function() {
148
- if (!cwd)
149
- cwd = origCwd.call(process);
150
- return cwd
151
- };
152
- try {
153
- process.cwd();
154
- } catch (er) {}
155
-
156
- // This check is needed until node.js 12 is required
157
- if (typeof process.chdir === 'function') {
158
- var chdir = process.chdir;
159
- process.chdir = function (d) {
160
- cwd = null;
161
- chdir.call(process, d);
162
- };
163
- if (Object.setPrototypeOf) Object.setPrototypeOf(process.chdir, chdir);
164
- }
165
-
166
- var polyfills$1 = patch$1;
167
-
168
- function patch$1 (fs) {
169
- // (re-)implement some things that are known busted or missing.
170
-
171
- // lchmod, broken prior to 0.6.2
172
- // back-port the fix here.
173
- if (constants.hasOwnProperty('O_SYMLINK') &&
174
- process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) {
175
- patchLchmod(fs);
176
- }
177
-
178
- // lutimes implementation, or no-op
179
- if (!fs.lutimes) {
180
- patchLutimes(fs);
181
- }
182
-
183
- // https://github.com/isaacs/node-graceful-fs/issues/4
184
- // Chown should not fail on einval or eperm if non-root.
185
- // It should not fail on enosys ever, as this just indicates
186
- // that a fs doesn't support the intended operation.
187
-
188
- fs.chown = chownFix(fs.chown);
189
- fs.fchown = chownFix(fs.fchown);
190
- fs.lchown = chownFix(fs.lchown);
191
-
192
- fs.chmod = chmodFix(fs.chmod);
193
- fs.fchmod = chmodFix(fs.fchmod);
194
- fs.lchmod = chmodFix(fs.lchmod);
195
-
196
- fs.chownSync = chownFixSync(fs.chownSync);
197
- fs.fchownSync = chownFixSync(fs.fchownSync);
198
- fs.lchownSync = chownFixSync(fs.lchownSync);
199
-
200
- fs.chmodSync = chmodFixSync(fs.chmodSync);
201
- fs.fchmodSync = chmodFixSync(fs.fchmodSync);
202
- fs.lchmodSync = chmodFixSync(fs.lchmodSync);
203
-
204
- fs.stat = statFix(fs.stat);
205
- fs.fstat = statFix(fs.fstat);
206
- fs.lstat = statFix(fs.lstat);
207
-
208
- fs.statSync = statFixSync(fs.statSync);
209
- fs.fstatSync = statFixSync(fs.fstatSync);
210
- fs.lstatSync = statFixSync(fs.lstatSync);
211
-
212
- // if lchmod/lchown do not exist, then make them no-ops
213
- if (fs.chmod && !fs.lchmod) {
214
- fs.lchmod = function (path, mode, cb) {
215
- if (cb) process.nextTick(cb);
216
- };
217
- fs.lchmodSync = function () {};
218
- }
219
- if (fs.chown && !fs.lchown) {
220
- fs.lchown = function (path, uid, gid, cb) {
221
- if (cb) process.nextTick(cb);
222
- };
223
- fs.lchownSync = function () {};
224
- }
225
-
226
- // on Windows, A/V software can lock the directory, causing this
227
- // to fail with an EACCES or EPERM if the directory contains newly
228
- // created files. Try again on failure, for up to 60 seconds.
229
-
230
- // Set the timeout this long because some Windows Anti-Virus, such as Parity
231
- // bit9, may lock files for up to a minute, causing npm package install
232
- // failures. Also, take care to yield the scheduler. Windows scheduling gives
233
- // CPU to a busy looping process, which can cause the program causing the lock
234
- // contention to be starved of CPU by node, so the contention doesn't resolve.
235
- if (platform === "win32") {
236
- fs.rename = typeof fs.rename !== 'function' ? fs.rename
237
- : (function (fs$rename) {
238
- function rename (from, to, cb) {
239
- var start = Date.now();
240
- var backoff = 0;
241
- fs$rename(from, to, function CB (er) {
242
- if (er
243
- && (er.code === "EACCES" || er.code === "EPERM")
244
- && Date.now() - start < 60000) {
245
- setTimeout(function() {
246
- fs.stat(to, function (stater, st) {
247
- if (stater && stater.code === "ENOENT")
248
- fs$rename(from, to, CB);
249
- else
250
- cb(er);
251
- });
252
- }, backoff);
253
- if (backoff < 100)
254
- backoff += 10;
255
- return;
256
- }
257
- if (cb) cb(er);
258
- });
259
- }
260
- if (Object.setPrototypeOf) Object.setPrototypeOf(rename, fs$rename);
261
- return rename
262
- })(fs.rename);
263
- }
264
-
265
- // if read() returns EAGAIN, then just try it again.
266
- fs.read = typeof fs.read !== 'function' ? fs.read
267
- : (function (fs$read) {
268
- function read (fd, buffer, offset, length, position, callback_) {
269
- var callback;
270
- if (callback_ && typeof callback_ === 'function') {
271
- var eagCounter = 0;
272
- callback = function (er, _, __) {
273
- if (er && er.code === 'EAGAIN' && eagCounter < 10) {
274
- eagCounter ++;
275
- return fs$read.call(fs, fd, buffer, offset, length, position, callback)
276
- }
277
- callback_.apply(this, arguments);
278
- };
279
- }
280
- return fs$read.call(fs, fd, buffer, offset, length, position, callback)
281
- }
282
-
283
- // This ensures `util.promisify` works as it does for native `fs.read`.
284
- if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read);
285
- return read
286
- })(fs.read);
287
-
288
- fs.readSync = typeof fs.readSync !== 'function' ? fs.readSync
289
- : (function (fs$readSync) { return function (fd, buffer, offset, length, position) {
290
- var eagCounter = 0;
291
- while (true) {
292
- try {
293
- return fs$readSync.call(fs, fd, buffer, offset, length, position)
294
- } catch (er) {
295
- if (er.code === 'EAGAIN' && eagCounter < 10) {
296
- eagCounter ++;
297
- continue
298
- }
299
- throw er
300
- }
301
- }
302
- }})(fs.readSync);
303
-
304
- function patchLchmod (fs) {
305
- fs.lchmod = function (path, mode, callback) {
306
- fs.open( path
307
- , constants.O_WRONLY | constants.O_SYMLINK
308
- , mode
309
- , function (err, fd) {
310
- if (err) {
311
- if (callback) callback(err);
312
- return
313
- }
314
- // prefer to return the chmod error, if one occurs,
315
- // but still try to close, and report closing errors if they occur.
316
- fs.fchmod(fd, mode, function (err) {
317
- fs.close(fd, function(err2) {
318
- if (callback) callback(err || err2);
319
- });
320
- });
321
- });
322
- };
323
-
324
- fs.lchmodSync = function (path, mode) {
325
- var fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK, mode);
326
-
327
- // prefer to return the chmod error, if one occurs,
328
- // but still try to close, and report closing errors if they occur.
329
- var threw = true;
330
- var ret;
331
- try {
332
- ret = fs.fchmodSync(fd, mode);
333
- threw = false;
334
- } finally {
335
- if (threw) {
336
- try {
337
- fs.closeSync(fd);
338
- } catch (er) {}
339
- } else {
340
- fs.closeSync(fd);
341
- }
342
- }
343
- return ret
344
- };
345
- }
346
-
347
- function patchLutimes (fs) {
348
- if (constants.hasOwnProperty("O_SYMLINK") && fs.futimes) {
349
- fs.lutimes = function (path, at, mt, cb) {
350
- fs.open(path, constants.O_SYMLINK, function (er, fd) {
351
- if (er) {
352
- if (cb) cb(er);
353
- return
354
- }
355
- fs.futimes(fd, at, mt, function (er) {
356
- fs.close(fd, function (er2) {
357
- if (cb) cb(er || er2);
358
- });
359
- });
360
- });
361
- };
362
-
363
- fs.lutimesSync = function (path, at, mt) {
364
- var fd = fs.openSync(path, constants.O_SYMLINK);
365
- var ret;
366
- var threw = true;
367
- try {
368
- ret = fs.futimesSync(fd, at, mt);
369
- threw = false;
370
- } finally {
371
- if (threw) {
372
- try {
373
- fs.closeSync(fd);
374
- } catch (er) {}
375
- } else {
376
- fs.closeSync(fd);
377
- }
378
- }
379
- return ret
380
- };
381
-
382
- } else if (fs.futimes) {
383
- fs.lutimes = function (_a, _b, _c, cb) { if (cb) process.nextTick(cb); };
384
- fs.lutimesSync = function () {};
385
- }
386
- }
387
-
388
- function chmodFix (orig) {
389
- if (!orig) return orig
390
- return function (target, mode, cb) {
391
- return orig.call(fs, target, mode, function (er) {
392
- if (chownErOk(er)) er = null;
393
- if (cb) cb.apply(this, arguments);
394
- })
395
- }
396
- }
397
-
398
- function chmodFixSync (orig) {
399
- if (!orig) return orig
400
- return function (target, mode) {
401
- try {
402
- return orig.call(fs, target, mode)
403
- } catch (er) {
404
- if (!chownErOk(er)) throw er
405
- }
406
- }
407
- }
408
-
409
-
410
- function chownFix (orig) {
411
- if (!orig) return orig
412
- return function (target, uid, gid, cb) {
413
- return orig.call(fs, target, uid, gid, function (er) {
414
- if (chownErOk(er)) er = null;
415
- if (cb) cb.apply(this, arguments);
416
- })
417
- }
418
- }
419
-
420
- function chownFixSync (orig) {
421
- if (!orig) return orig
422
- return function (target, uid, gid) {
423
- try {
424
- return orig.call(fs, target, uid, gid)
425
- } catch (er) {
426
- if (!chownErOk(er)) throw er
427
- }
428
- }
429
- }
430
-
431
- function statFix (orig) {
432
- if (!orig) return orig
433
- // Older versions of Node erroneously returned signed integers for
434
- // uid + gid.
435
- return function (target, options, cb) {
436
- if (typeof options === 'function') {
437
- cb = options;
438
- options = null;
439
- }
440
- function callback (er, stats) {
441
- if (stats) {
442
- if (stats.uid < 0) stats.uid += 0x100000000;
443
- if (stats.gid < 0) stats.gid += 0x100000000;
444
- }
445
- if (cb) cb.apply(this, arguments);
446
- }
447
- return options ? orig.call(fs, target, options, callback)
448
- : orig.call(fs, target, callback)
449
- }
450
- }
451
-
452
- function statFixSync (orig) {
453
- if (!orig) return orig
454
- // Older versions of Node erroneously returned signed integers for
455
- // uid + gid.
456
- return function (target, options) {
457
- var stats = options ? orig.call(fs, target, options)
458
- : orig.call(fs, target);
459
- if (stats) {
460
- if (stats.uid < 0) stats.uid += 0x100000000;
461
- if (stats.gid < 0) stats.gid += 0x100000000;
462
- }
463
- return stats;
464
- }
465
- }
466
-
467
- // ENOSYS means that the fs doesn't support the op. Just ignore
468
- // that, because it doesn't matter.
469
- //
470
- // if there's no getuid, or if getuid() is something other
471
- // than 0, and the error is EINVAL or EPERM, then just ignore
472
- // it.
473
- //
474
- // This specific case is a silent failure in cp, install, tar,
475
- // and most other unix tools that manage permissions.
476
- //
477
- // When running as root, or if other types of errors are
478
- // encountered, then it's strict.
479
- function chownErOk (er) {
480
- if (!er)
481
- return true
482
-
483
- if (er.code === "ENOSYS")
484
- return true
485
-
486
- var nonroot = !process.getuid || process.getuid() !== 0;
487
- if (nonroot) {
488
- if (er.code === "EINVAL" || er.code === "EPERM")
489
- return true
490
- }
491
-
492
- return false
493
- }
494
- }
495
-
496
- var Stream = require$$0$1.Stream;
497
-
498
- var legacyStreams = legacy$1;
499
-
500
- function legacy$1 (fs) {
501
- return {
502
- ReadStream: ReadStream,
503
- WriteStream: WriteStream
504
- }
505
-
506
- function ReadStream (path, options) {
507
- if (!(this instanceof ReadStream)) return new ReadStream(path, options);
508
-
509
- Stream.call(this);
510
-
511
- var self = this;
512
-
513
- this.path = path;
514
- this.fd = null;
515
- this.readable = true;
516
- this.paused = false;
517
-
518
- this.flags = 'r';
519
- this.mode = 438; /*=0666*/
520
- this.bufferSize = 64 * 1024;
521
-
522
- options = options || {};
523
-
524
- // Mixin options into this
525
- var keys = Object.keys(options);
526
- for (var index = 0, length = keys.length; index < length; index++) {
527
- var key = keys[index];
528
- this[key] = options[key];
529
- }
530
-
531
- if (this.encoding) this.setEncoding(this.encoding);
532
-
533
- if (this.start !== undefined) {
534
- if ('number' !== typeof this.start) {
535
- throw TypeError('start must be a Number');
536
- }
537
- if (this.end === undefined) {
538
- this.end = Infinity;
539
- } else if ('number' !== typeof this.end) {
540
- throw TypeError('end must be a Number');
541
- }
542
-
543
- if (this.start > this.end) {
544
- throw new Error('start must be <= end');
545
- }
546
-
547
- this.pos = this.start;
548
- }
549
-
550
- if (this.fd !== null) {
551
- process.nextTick(function() {
552
- self._read();
553
- });
554
- return;
555
- }
556
-
557
- fs.open(this.path, this.flags, this.mode, function (err, fd) {
558
- if (err) {
559
- self.emit('error', err);
560
- self.readable = false;
561
- return;
562
- }
563
-
564
- self.fd = fd;
565
- self.emit('open', fd);
566
- self._read();
567
- });
568
- }
569
-
570
- function WriteStream (path, options) {
571
- if (!(this instanceof WriteStream)) return new WriteStream(path, options);
572
-
573
- Stream.call(this);
574
-
575
- this.path = path;
576
- this.fd = null;
577
- this.writable = true;
578
-
579
- this.flags = 'w';
580
- this.encoding = 'binary';
581
- this.mode = 438; /*=0666*/
582
- this.bytesWritten = 0;
583
-
584
- options = options || {};
585
-
586
- // Mixin options into this
587
- var keys = Object.keys(options);
588
- for (var index = 0, length = keys.length; index < length; index++) {
589
- var key = keys[index];
590
- this[key] = options[key];
591
- }
592
-
593
- if (this.start !== undefined) {
594
- if ('number' !== typeof this.start) {
595
- throw TypeError('start must be a Number');
596
- }
597
- if (this.start < 0) {
598
- throw new Error('start must be >= zero');
599
- }
600
-
601
- this.pos = this.start;
602
- }
603
-
604
- this.busy = false;
605
- this._queue = [];
606
-
607
- if (this.fd === null) {
608
- this._open = fs.open;
609
- this._queue.push([this._open, this.path, this.flags, this.mode, undefined]);
610
- this.flush();
611
- }
612
- }
613
- }
614
-
615
- var clone_1 = clone$2;
616
-
617
- var getPrototypeOf = Object.getPrototypeOf || function (obj) {
618
- return obj.__proto__
619
- };
620
-
621
- function clone$2 (obj) {
622
- if (obj === null || typeof obj !== 'object')
623
- return obj
624
-
625
- if (obj instanceof Object)
626
- var copy = { __proto__: getPrototypeOf(obj) };
627
- else
628
- var copy = Object.create(null);
629
-
630
- Object.getOwnPropertyNames(obj).forEach(function (key) {
631
- Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key));
632
- });
633
-
634
- return copy
635
- }
636
-
637
- var fs$g = require$$0$2;
638
- var polyfills = polyfills$1;
639
- var legacy = legacyStreams;
640
- var clone$1 = clone_1;
641
-
642
- var util$1 = require$$4;
643
-
644
- /* istanbul ignore next - node 0.x polyfill */
645
- var gracefulQueue;
646
- var previousSymbol;
647
-
648
- /* istanbul ignore else - node 0.x polyfill */
649
- if (typeof Symbol === 'function' && typeof Symbol.for === 'function') {
650
- gracefulQueue = Symbol.for('graceful-fs.queue');
651
- // This is used in testing by future versions
652
- previousSymbol = Symbol.for('graceful-fs.previous');
653
- } else {
654
- gracefulQueue = '___graceful-fs.queue';
655
- previousSymbol = '___graceful-fs.previous';
656
- }
657
-
658
- function noop () {}
659
-
660
- function publishQueue(context, queue) {
661
- Object.defineProperty(context, gracefulQueue, {
662
- get: function() {
663
- return queue
664
- }
665
- });
666
- }
667
-
668
- var debug = noop;
669
- if (util$1.debuglog)
670
- debug = util$1.debuglog('gfs4');
671
- else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || ''))
672
- debug = function() {
673
- var m = util$1.format.apply(util$1, arguments);
674
- m = 'GFS4: ' + m.split(/\n/).join('\nGFS4: ');
675
- console.error(m);
676
- };
677
-
678
- // Once time initialization
679
- if (!fs$g[gracefulQueue]) {
680
- // This queue can be shared by multiple loaded instances
681
- var queue = commonjsGlobal[gracefulQueue] || [];
682
- publishQueue(fs$g, queue);
683
-
684
- // Patch fs.close/closeSync to shared queue version, because we need
685
- // to retry() whenever a close happens *anywhere* in the program.
686
- // This is essential when multiple graceful-fs instances are
687
- // in play at the same time.
688
- fs$g.close = (function (fs$close) {
689
- function close (fd, cb) {
690
- return fs$close.call(fs$g, fd, function (err) {
691
- // This function uses the graceful-fs shared queue
692
- if (!err) {
693
- resetQueue();
694
- }
695
-
696
- if (typeof cb === 'function')
697
- cb.apply(this, arguments);
698
- })
699
- }
700
-
701
- Object.defineProperty(close, previousSymbol, {
702
- value: fs$close
703
- });
704
- return close
705
- })(fs$g.close);
706
-
707
- fs$g.closeSync = (function (fs$closeSync) {
708
- function closeSync (fd) {
709
- // This function uses the graceful-fs shared queue
710
- fs$closeSync.apply(fs$g, arguments);
711
- resetQueue();
712
- }
713
-
714
- Object.defineProperty(closeSync, previousSymbol, {
715
- value: fs$closeSync
716
- });
717
- return closeSync
718
- })(fs$g.closeSync);
719
-
720
- if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || '')) {
721
- process.on('exit', function() {
722
- debug(fs$g[gracefulQueue]);
723
- require$$5.equal(fs$g[gracefulQueue].length, 0);
724
- });
725
- }
726
- }
727
-
728
- if (!commonjsGlobal[gracefulQueue]) {
729
- publishQueue(commonjsGlobal, fs$g[gracefulQueue]);
730
- }
731
-
732
- var gracefulFs = patch(clone$1(fs$g));
733
- if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs$g.__patched) {
734
- gracefulFs = patch(fs$g);
735
- fs$g.__patched = true;
736
- }
737
-
738
- function patch (fs) {
739
- // Everything that references the open() function needs to be in here
740
- polyfills(fs);
741
- fs.gracefulify = patch;
742
-
743
- fs.createReadStream = createReadStream;
744
- fs.createWriteStream = createWriteStream;
745
- var fs$readFile = fs.readFile;
746
- fs.readFile = readFile;
747
- function readFile (path, options, cb) {
748
- if (typeof options === 'function')
749
- cb = options, options = null;
750
-
751
- return go$readFile(path, options, cb)
752
-
753
- function go$readFile (path, options, cb, startTime) {
754
- return fs$readFile(path, options, function (err) {
755
- if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
756
- enqueue([go$readFile, [path, options, cb], err, startTime || Date.now(), Date.now()]);
757
- else {
758
- if (typeof cb === 'function')
759
- cb.apply(this, arguments);
760
- }
761
- })
762
- }
763
- }
764
-
765
- var fs$writeFile = fs.writeFile;
766
- fs.writeFile = writeFile;
767
- function writeFile (path, data, options, cb) {
768
- if (typeof options === 'function')
769
- cb = options, options = null;
770
-
771
- return go$writeFile(path, data, options, cb)
772
-
773
- function go$writeFile (path, data, options, cb, startTime) {
774
- return fs$writeFile(path, data, options, function (err) {
775
- if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
776
- enqueue([go$writeFile, [path, data, options, cb], err, startTime || Date.now(), Date.now()]);
777
- else {
778
- if (typeof cb === 'function')
779
- cb.apply(this, arguments);
780
- }
781
- })
782
- }
783
- }
784
-
785
- var fs$appendFile = fs.appendFile;
786
- if (fs$appendFile)
787
- fs.appendFile = appendFile;
788
- function appendFile (path, data, options, cb) {
789
- if (typeof options === 'function')
790
- cb = options, options = null;
791
-
792
- return go$appendFile(path, data, options, cb)
793
-
794
- function go$appendFile (path, data, options, cb, startTime) {
795
- return fs$appendFile(path, data, options, function (err) {
796
- if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
797
- enqueue([go$appendFile, [path, data, options, cb], err, startTime || Date.now(), Date.now()]);
798
- else {
799
- if (typeof cb === 'function')
800
- cb.apply(this, arguments);
801
- }
802
- })
803
- }
804
- }
805
-
806
- var fs$copyFile = fs.copyFile;
807
- if (fs$copyFile)
808
- fs.copyFile = copyFile;
809
- function copyFile (src, dest, flags, cb) {
810
- if (typeof flags === 'function') {
811
- cb = flags;
812
- flags = 0;
813
- }
814
- return go$copyFile(src, dest, flags, cb)
815
-
816
- function go$copyFile (src, dest, flags, cb, startTime) {
817
- return fs$copyFile(src, dest, flags, function (err) {
818
- if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
819
- enqueue([go$copyFile, [src, dest, flags, cb], err, startTime || Date.now(), Date.now()]);
820
- else {
821
- if (typeof cb === 'function')
822
- cb.apply(this, arguments);
823
- }
824
- })
825
- }
826
- }
827
-
828
- var fs$readdir = fs.readdir;
829
- fs.readdir = readdir;
830
- var noReaddirOptionVersions = /^v[0-5]\./;
831
- function readdir (path, options, cb) {
832
- if (typeof options === 'function')
833
- cb = options, options = null;
834
-
835
- var go$readdir = noReaddirOptionVersions.test(process.version)
836
- ? function go$readdir (path, options, cb, startTime) {
837
- return fs$readdir(path, fs$readdirCallback(
838
- path, options, cb, startTime
839
- ))
840
- }
841
- : function go$readdir (path, options, cb, startTime) {
842
- return fs$readdir(path, options, fs$readdirCallback(
843
- path, options, cb, startTime
844
- ))
845
- };
846
-
847
- return go$readdir(path, options, cb)
848
-
849
- function fs$readdirCallback (path, options, cb, startTime) {
850
- return function (err, files) {
851
- if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
852
- enqueue([
853
- go$readdir,
854
- [path, options, cb],
855
- err,
856
- startTime || Date.now(),
857
- Date.now()
858
- ]);
859
- else {
860
- if (files && files.sort)
861
- files.sort();
862
-
863
- if (typeof cb === 'function')
864
- cb.call(this, err, files);
865
- }
866
- }
867
- }
868
- }
869
-
870
- if (process.version.substr(0, 4) === 'v0.8') {
871
- var legStreams = legacy(fs);
872
- ReadStream = legStreams.ReadStream;
873
- WriteStream = legStreams.WriteStream;
874
- }
875
-
876
- var fs$ReadStream = fs.ReadStream;
877
- if (fs$ReadStream) {
878
- ReadStream.prototype = Object.create(fs$ReadStream.prototype);
879
- ReadStream.prototype.open = ReadStream$open;
880
- }
881
-
882
- var fs$WriteStream = fs.WriteStream;
883
- if (fs$WriteStream) {
884
- WriteStream.prototype = Object.create(fs$WriteStream.prototype);
885
- WriteStream.prototype.open = WriteStream$open;
886
- }
887
-
888
- Object.defineProperty(fs, 'ReadStream', {
889
- get: function () {
890
- return ReadStream
891
- },
892
- set: function (val) {
893
- ReadStream = val;
894
- },
895
- enumerable: true,
896
- configurable: true
897
- });
898
- Object.defineProperty(fs, 'WriteStream', {
899
- get: function () {
900
- return WriteStream
901
- },
902
- set: function (val) {
903
- WriteStream = val;
904
- },
905
- enumerable: true,
906
- configurable: true
907
- });
908
-
909
- // legacy names
910
- var FileReadStream = ReadStream;
911
- Object.defineProperty(fs, 'FileReadStream', {
912
- get: function () {
913
- return FileReadStream
914
- },
915
- set: function (val) {
916
- FileReadStream = val;
917
- },
918
- enumerable: true,
919
- configurable: true
920
- });
921
- var FileWriteStream = WriteStream;
922
- Object.defineProperty(fs, 'FileWriteStream', {
923
- get: function () {
924
- return FileWriteStream
925
- },
926
- set: function (val) {
927
- FileWriteStream = val;
928
- },
929
- enumerable: true,
930
- configurable: true
931
- });
932
-
933
- function ReadStream (path, options) {
934
- if (this instanceof ReadStream)
935
- return fs$ReadStream.apply(this, arguments), this
936
- else
937
- return ReadStream.apply(Object.create(ReadStream.prototype), arguments)
938
- }
939
-
940
- function ReadStream$open () {
941
- var that = this;
942
- open(that.path, that.flags, that.mode, function (err, fd) {
943
- if (err) {
944
- if (that.autoClose)
945
- that.destroy();
946
-
947
- that.emit('error', err);
948
- } else {
949
- that.fd = fd;
950
- that.emit('open', fd);
951
- that.read();
952
- }
953
- });
954
- }
955
-
956
- function WriteStream (path, options) {
957
- if (this instanceof WriteStream)
958
- return fs$WriteStream.apply(this, arguments), this
959
- else
960
- return WriteStream.apply(Object.create(WriteStream.prototype), arguments)
961
- }
962
-
963
- function WriteStream$open () {
964
- var that = this;
965
- open(that.path, that.flags, that.mode, function (err, fd) {
966
- if (err) {
967
- that.destroy();
968
- that.emit('error', err);
969
- } else {
970
- that.fd = fd;
971
- that.emit('open', fd);
972
- }
973
- });
974
- }
975
-
976
- function createReadStream (path, options) {
977
- return new fs.ReadStream(path, options)
978
- }
979
-
980
- function createWriteStream (path, options) {
981
- return new fs.WriteStream(path, options)
982
- }
983
-
984
- var fs$open = fs.open;
985
- fs.open = open;
986
- function open (path, flags, mode, cb) {
987
- if (typeof mode === 'function')
988
- cb = mode, mode = null;
989
-
990
- return go$open(path, flags, mode, cb)
991
-
992
- function go$open (path, flags, mode, cb, startTime) {
993
- return fs$open(path, flags, mode, function (err, fd) {
994
- if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
995
- enqueue([go$open, [path, flags, mode, cb], err, startTime || Date.now(), Date.now()]);
996
- else {
997
- if (typeof cb === 'function')
998
- cb.apply(this, arguments);
999
- }
1000
- })
1001
- }
1002
- }
1003
-
1004
- return fs
1005
- }
1006
-
1007
- function enqueue (elem) {
1008
- debug('ENQUEUE', elem[0].name, elem[1]);
1009
- fs$g[gracefulQueue].push(elem);
1010
- retry();
1011
- }
1012
-
1013
- // keep track of the timeout between retry() calls
1014
- var retryTimer;
1015
-
1016
- // reset the startTime and lastTime to now
1017
- // this resets the start of the 60 second overall timeout as well as the
1018
- // delay between attempts so that we'll retry these jobs sooner
1019
- function resetQueue () {
1020
- var now = Date.now();
1021
- for (var i = 0; i < fs$g[gracefulQueue].length; ++i) {
1022
- // entries that are only a length of 2 are from an older version, don't
1023
- // bother modifying those since they'll be retried anyway.
1024
- if (fs$g[gracefulQueue][i].length > 2) {
1025
- fs$g[gracefulQueue][i][3] = now; // startTime
1026
- fs$g[gracefulQueue][i][4] = now; // lastTime
1027
- }
1028
- }
1029
- // call retry to make sure we're actively processing the queue
1030
- retry();
1031
- }
1032
-
1033
- function retry () {
1034
- // clear the timer and remove it to help prevent unintended concurrency
1035
- clearTimeout(retryTimer);
1036
- retryTimer = undefined;
1037
-
1038
- if (fs$g[gracefulQueue].length === 0)
1039
- return
1040
-
1041
- var elem = fs$g[gracefulQueue].shift();
1042
- var fn = elem[0];
1043
- var args = elem[1];
1044
- // these items may be unset if they were added by an older graceful-fs
1045
- var err = elem[2];
1046
- var startTime = elem[3];
1047
- var lastTime = elem[4];
1048
-
1049
- // if we don't have a startTime we have no way of knowing if we've waited
1050
- // long enough, so go ahead and retry this item now
1051
- if (startTime === undefined) {
1052
- debug('RETRY', fn.name, args);
1053
- fn.apply(null, args);
1054
- } else if (Date.now() - startTime >= 60000) {
1055
- // it's been more than 60 seconds total, bail now
1056
- debug('TIMEOUT', fn.name, args);
1057
- var cb = args.pop();
1058
- if (typeof cb === 'function')
1059
- cb.call(null, err);
1060
- } else {
1061
- // the amount of time between the last attempt and right now
1062
- var sinceAttempt = Date.now() - lastTime;
1063
- // the amount of time between when we first tried, and when we last tried
1064
- // rounded up to at least 1
1065
- var sinceStart = Math.max(lastTime - startTime, 1);
1066
- // backoff. wait longer than the total time we've been retrying, but only
1067
- // up to a maximum of 100ms
1068
- var desiredDelay = Math.min(sinceStart * 1.2, 100);
1069
- // it's been long enough since the last retry, do it again
1070
- if (sinceAttempt >= desiredDelay) {
1071
- debug('RETRY', fn.name, args);
1072
- fn.apply(null, args.concat([startTime]));
1073
- } else {
1074
- // if we can't do this job yet, push it to the end of the queue
1075
- // and let the next iteration check again
1076
- fs$g[gracefulQueue].push(elem);
1077
- }
1078
- }
1079
-
1080
- // schedule our next run if one isn't already scheduled
1081
- if (retryTimer === undefined) {
1082
- retryTimer = setTimeout(retry, 0);
1083
- }
1084
- }
1085
-
1086
- (function (exports) {
1087
- // This is adapted from https://github.com/normalize/mz
1088
- // Copyright (c) 2014-2016 Jonathan Ong me@jongleberry.com and Contributors
1089
- const u = universalify$1.fromCallback;
1090
- const fs = gracefulFs;
1091
-
1092
- const api = [
1093
- 'access',
1094
- 'appendFile',
1095
- 'chmod',
1096
- 'chown',
1097
- 'close',
1098
- 'copyFile',
1099
- 'fchmod',
1100
- 'fchown',
1101
- 'fdatasync',
1102
- 'fstat',
1103
- 'fsync',
1104
- 'ftruncate',
1105
- 'futimes',
1106
- 'lchmod',
1107
- 'lchown',
1108
- 'link',
1109
- 'lstat',
1110
- 'mkdir',
1111
- 'mkdtemp',
1112
- 'open',
1113
- 'opendir',
1114
- 'readdir',
1115
- 'readFile',
1116
- 'readlink',
1117
- 'realpath',
1118
- 'rename',
1119
- 'rm',
1120
- 'rmdir',
1121
- 'stat',
1122
- 'symlink',
1123
- 'truncate',
1124
- 'unlink',
1125
- 'utimes',
1126
- 'writeFile'
1127
- ].filter(key => {
1128
- // Some commands are not available on some systems. Ex:
1129
- // fs.cp was added in Node.js v16.7.0
1130
- // fs.lchown is not available on at least some Linux
1131
- return typeof fs[key] === 'function'
1132
- });
1133
-
1134
- // Export cloned fs:
1135
- Object.assign(exports, fs);
1136
-
1137
- // Universalify async methods:
1138
- api.forEach(method => {
1139
- exports[method] = u(fs[method]);
1140
- });
1141
-
1142
- // We differ from mz/fs in that we still ship the old, broken, fs.exists()
1143
- // since we are a drop-in replacement for the native module
1144
- exports.exists = function (filename, callback) {
1145
- if (typeof callback === 'function') {
1146
- return fs.exists(filename, callback)
1147
- }
1148
- return new Promise(resolve => {
1149
- return fs.exists(filename, resolve)
1150
- })
1151
- };
1152
-
1153
- // fs.read(), fs.write(), fs.readv(), & fs.writev() need special treatment due to multiple callback args
1154
-
1155
- exports.read = function (fd, buffer, offset, length, position, callback) {
1156
- if (typeof callback === 'function') {
1157
- return fs.read(fd, buffer, offset, length, position, callback)
1158
- }
1159
- return new Promise((resolve, reject) => {
1160
- fs.read(fd, buffer, offset, length, position, (err, bytesRead, buffer) => {
1161
- if (err) return reject(err)
1162
- resolve({ bytesRead, buffer });
1163
- });
1164
- })
1165
- };
1166
-
1167
- // Function signature can be
1168
- // fs.write(fd, buffer[, offset[, length[, position]]], callback)
1169
- // OR
1170
- // fs.write(fd, string[, position[, encoding]], callback)
1171
- // We need to handle both cases, so we use ...args
1172
- exports.write = function (fd, buffer, ...args) {
1173
- if (typeof args[args.length - 1] === 'function') {
1174
- return fs.write(fd, buffer, ...args)
1175
- }
1176
-
1177
- return new Promise((resolve, reject) => {
1178
- fs.write(fd, buffer, ...args, (err, bytesWritten, buffer) => {
1179
- if (err) return reject(err)
1180
- resolve({ bytesWritten, buffer });
1181
- });
1182
- })
1183
- };
1184
-
1185
- // Function signature is
1186
- // s.readv(fd, buffers[, position], callback)
1187
- // We need to handle the optional arg, so we use ...args
1188
- exports.readv = function (fd, buffers, ...args) {
1189
- if (typeof args[args.length - 1] === 'function') {
1190
- return fs.readv(fd, buffers, ...args)
1191
- }
1192
-
1193
- return new Promise((resolve, reject) => {
1194
- fs.readv(fd, buffers, ...args, (err, bytesRead, buffers) => {
1195
- if (err) return reject(err)
1196
- resolve({ bytesRead, buffers });
1197
- });
1198
- })
1199
- };
1200
-
1201
- // Function signature is
1202
- // s.writev(fd, buffers[, position], callback)
1203
- // We need to handle the optional arg, so we use ...args
1204
- exports.writev = function (fd, buffers, ...args) {
1205
- if (typeof args[args.length - 1] === 'function') {
1206
- return fs.writev(fd, buffers, ...args)
1207
- }
1208
-
1209
- return new Promise((resolve, reject) => {
1210
- fs.writev(fd, buffers, ...args, (err, bytesWritten, buffers) => {
1211
- if (err) return reject(err)
1212
- resolve({ bytesWritten, buffers });
1213
- });
1214
- })
1215
- };
1216
-
1217
- // fs.realpath.native sometimes not available if fs is monkey-patched
1218
- if (typeof fs.realpath.native === 'function') {
1219
- exports.realpath.native = u(fs.realpath.native);
1220
- } else {
1221
- process.emitWarning(
1222
- 'fs.realpath.native is not a function. Is fs being monkey-patched?',
1223
- 'Warning', 'fs-extra-WARN0003'
1224
- );
1225
- }
1226
- } (fs$h));
1227
-
1228
- var makeDir$1 = {};
1229
-
1230
- var utils$1 = {};
1231
-
1232
- const path$b = require$$1;
1233
-
1234
- // https://github.com/nodejs/node/issues/8987
1235
- // https://github.com/libuv/libuv/pull/1088
1236
- utils$1.checkPath = function checkPath (pth) {
1237
- if (process.platform === 'win32') {
1238
- const pathHasInvalidWinCharacters = /[<>:"|?*]/.test(pth.replace(path$b.parse(pth).root, ''));
1239
-
1240
- if (pathHasInvalidWinCharacters) {
1241
- const error = new Error(`Path contains invalid characters: ${pth}`);
1242
- error.code = 'EINVAL';
1243
- throw error
1244
- }
1245
- }
1246
- };
1247
-
1248
- const fs$f = fs$h;
1249
- const { checkPath } = utils$1;
1250
-
1251
- const getMode = options => {
1252
- const defaults = { mode: 0o777 };
1253
- if (typeof options === 'number') return options
1254
- return ({ ...defaults, ...options }).mode
1255
- };
1256
-
1257
- makeDir$1.makeDir = async (dir, options) => {
1258
- checkPath(dir);
1259
-
1260
- return fs$f.mkdir(dir, {
1261
- mode: getMode(options),
1262
- recursive: true
1263
- })
1264
- };
1265
-
1266
- makeDir$1.makeDirSync = (dir, options) => {
1267
- checkPath(dir);
1268
-
1269
- return fs$f.mkdirSync(dir, {
1270
- mode: getMode(options),
1271
- recursive: true
1272
- })
1273
- };
1274
-
1275
- const u$a = universalify$1.fromPromise;
1276
- const { makeDir: _makeDir, makeDirSync } = makeDir$1;
1277
- const makeDir = u$a(_makeDir);
1278
-
1279
- var mkdirs$2 = {
1280
- mkdirs: makeDir,
1281
- mkdirsSync: makeDirSync,
1282
- // alias
1283
- mkdirp: makeDir,
1284
- mkdirpSync: makeDirSync,
1285
- ensureDir: makeDir,
1286
- ensureDirSync: makeDirSync
1287
- };
1288
-
1289
- const u$9 = universalify$1.fromPromise;
1290
- const fs$e = fs$h;
1291
-
1292
- function pathExists$6 (path) {
1293
- return fs$e.access(path).then(() => true).catch(() => false)
1294
- }
1295
-
1296
- var pathExists_1 = {
1297
- pathExists: u$9(pathExists$6),
1298
- pathExistsSync: fs$e.existsSync
1299
- };
1300
-
1301
- const fs$d = gracefulFs;
1302
-
1303
- function utimesMillis$1 (path, atime, mtime, callback) {
1304
- // if (!HAS_MILLIS_RES) return fs.utimes(path, atime, mtime, callback)
1305
- fs$d.open(path, 'r+', (err, fd) => {
1306
- if (err) return callback(err)
1307
- fs$d.futimes(fd, atime, mtime, futimesErr => {
1308
- fs$d.close(fd, closeErr => {
1309
- if (callback) callback(futimesErr || closeErr);
1310
- });
1311
- });
1312
- });
1313
- }
1314
-
1315
- function utimesMillisSync$1 (path, atime, mtime) {
1316
- const fd = fs$d.openSync(path, 'r+');
1317
- fs$d.futimesSync(fd, atime, mtime);
1318
- return fs$d.closeSync(fd)
1319
- }
1320
-
1321
- var utimes = {
1322
- utimesMillis: utimesMillis$1,
1323
- utimesMillisSync: utimesMillisSync$1
1324
- };
1325
-
1326
- const fs$c = fs$h;
1327
- const path$a = require$$1;
1328
- const util = require$$4;
1329
-
1330
- function getStats$2 (src, dest, opts) {
1331
- const statFunc = opts.dereference
1332
- ? (file) => fs$c.stat(file, { bigint: true })
1333
- : (file) => fs$c.lstat(file, { bigint: true });
1334
- return Promise.all([
1335
- statFunc(src),
1336
- statFunc(dest).catch(err => {
1337
- if (err.code === 'ENOENT') return null
1338
- throw err
1339
- })
1340
- ]).then(([srcStat, destStat]) => ({ srcStat, destStat }))
1341
- }
1342
-
1343
- function getStatsSync (src, dest, opts) {
1344
- let destStat;
1345
- const statFunc = opts.dereference
1346
- ? (file) => fs$c.statSync(file, { bigint: true })
1347
- : (file) => fs$c.lstatSync(file, { bigint: true });
1348
- const srcStat = statFunc(src);
1349
- try {
1350
- destStat = statFunc(dest);
1351
- } catch (err) {
1352
- if (err.code === 'ENOENT') return { srcStat, destStat: null }
1353
- throw err
1354
- }
1355
- return { srcStat, destStat }
1356
- }
1357
-
1358
- function checkPaths (src, dest, funcName, opts, cb) {
1359
- util.callbackify(getStats$2)(src, dest, opts, (err, stats) => {
1360
- if (err) return cb(err)
1361
- const { srcStat, destStat } = stats;
1362
-
1363
- if (destStat) {
1364
- if (areIdentical$2(srcStat, destStat)) {
1365
- const srcBaseName = path$a.basename(src);
1366
- const destBaseName = path$a.basename(dest);
1367
- if (funcName === 'move' &&
1368
- srcBaseName !== destBaseName &&
1369
- srcBaseName.toLowerCase() === destBaseName.toLowerCase()) {
1370
- return cb(null, { srcStat, destStat, isChangingCase: true })
1371
- }
1372
- return cb(new Error('Source and destination must not be the same.'))
1373
- }
1374
- if (srcStat.isDirectory() && !destStat.isDirectory()) {
1375
- return cb(new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`))
1376
- }
1377
- if (!srcStat.isDirectory() && destStat.isDirectory()) {
1378
- return cb(new Error(`Cannot overwrite directory '${dest}' with non-directory '${src}'.`))
1379
- }
1380
- }
1381
-
1382
- if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
1383
- return cb(new Error(errMsg(src, dest, funcName)))
1384
- }
1385
- return cb(null, { srcStat, destStat })
1386
- });
1387
- }
1388
-
1389
- function checkPathsSync (src, dest, funcName, opts) {
1390
- const { srcStat, destStat } = getStatsSync(src, dest, opts);
1391
-
1392
- if (destStat) {
1393
- if (areIdentical$2(srcStat, destStat)) {
1394
- const srcBaseName = path$a.basename(src);
1395
- const destBaseName = path$a.basename(dest);
1396
- if (funcName === 'move' &&
1397
- srcBaseName !== destBaseName &&
1398
- srcBaseName.toLowerCase() === destBaseName.toLowerCase()) {
1399
- return { srcStat, destStat, isChangingCase: true }
1400
- }
1401
- throw new Error('Source and destination must not be the same.')
1402
- }
1403
- if (srcStat.isDirectory() && !destStat.isDirectory()) {
1404
- throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`)
1405
- }
1406
- if (!srcStat.isDirectory() && destStat.isDirectory()) {
1407
- throw new Error(`Cannot overwrite directory '${dest}' with non-directory '${src}'.`)
1408
- }
1409
- }
1410
-
1411
- if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
1412
- throw new Error(errMsg(src, dest, funcName))
1413
- }
1414
- return { srcStat, destStat }
1415
- }
1416
-
1417
- // recursively check if dest parent is a subdirectory of src.
1418
- // It works for all file types including symlinks since it
1419
- // checks the src and dest inodes. It starts from the deepest
1420
- // parent and stops once it reaches the src parent or the root path.
1421
- function checkParentPaths (src, srcStat, dest, funcName, cb) {
1422
- const srcParent = path$a.resolve(path$a.dirname(src));
1423
- const destParent = path$a.resolve(path$a.dirname(dest));
1424
- if (destParent === srcParent || destParent === path$a.parse(destParent).root) return cb()
1425
- fs$c.stat(destParent, { bigint: true }, (err, destStat) => {
1426
- if (err) {
1427
- if (err.code === 'ENOENT') return cb()
1428
- return cb(err)
1429
- }
1430
- if (areIdentical$2(srcStat, destStat)) {
1431
- return cb(new Error(errMsg(src, dest, funcName)))
1432
- }
1433
- return checkParentPaths(src, srcStat, destParent, funcName, cb)
1434
- });
1435
- }
1436
-
1437
- function checkParentPathsSync (src, srcStat, dest, funcName) {
1438
- const srcParent = path$a.resolve(path$a.dirname(src));
1439
- const destParent = path$a.resolve(path$a.dirname(dest));
1440
- if (destParent === srcParent || destParent === path$a.parse(destParent).root) return
1441
- let destStat;
1442
- try {
1443
- destStat = fs$c.statSync(destParent, { bigint: true });
1444
- } catch (err) {
1445
- if (err.code === 'ENOENT') return
1446
- throw err
1447
- }
1448
- if (areIdentical$2(srcStat, destStat)) {
1449
- throw new Error(errMsg(src, dest, funcName))
1450
- }
1451
- return checkParentPathsSync(src, srcStat, destParent, funcName)
1452
- }
1453
-
1454
- function areIdentical$2 (srcStat, destStat) {
1455
- return destStat.ino && destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev
1456
- }
1457
-
1458
- // return true if dest is a subdir of src, otherwise false.
1459
- // It only checks the path strings.
1460
- function isSrcSubdir (src, dest) {
1461
- const srcArr = path$a.resolve(src).split(path$a.sep).filter(i => i);
1462
- const destArr = path$a.resolve(dest).split(path$a.sep).filter(i => i);
1463
- return srcArr.reduce((acc, cur, i) => acc && destArr[i] === cur, true)
1464
- }
1465
-
1466
- function errMsg (src, dest, funcName) {
1467
- return `Cannot ${funcName} '${src}' to a subdirectory of itself, '${dest}'.`
1468
- }
1469
-
1470
- var stat$4 = {
1471
- checkPaths,
1472
- checkPathsSync,
1473
- checkParentPaths,
1474
- checkParentPathsSync,
1475
- isSrcSubdir,
1476
- areIdentical: areIdentical$2
1477
- };
1478
-
1479
- const fs$b = gracefulFs;
1480
- const path$9 = require$$1;
1481
- const mkdirs$1 = mkdirs$2.mkdirs;
1482
- const pathExists$5 = pathExists_1.pathExists;
1483
- const utimesMillis = utimes.utimesMillis;
1484
- const stat$3 = stat$4;
1485
-
1486
- function copy$2 (src, dest, opts, cb) {
1487
- if (typeof opts === 'function' && !cb) {
1488
- cb = opts;
1489
- opts = {};
1490
- } else if (typeof opts === 'function') {
1491
- opts = { filter: opts };
1492
- }
1493
-
1494
- cb = cb || function () {};
1495
- opts = opts || {};
1496
-
1497
- opts.clobber = 'clobber' in opts ? !!opts.clobber : true; // default to true for now
1498
- opts.overwrite = 'overwrite' in opts ? !!opts.overwrite : opts.clobber; // overwrite falls back to clobber
1499
-
1500
- // Warn about using preserveTimestamps on 32-bit node
1501
- if (opts.preserveTimestamps && process.arch === 'ia32') {
1502
- process.emitWarning(
1503
- 'Using the preserveTimestamps option in 32-bit node is not recommended;\n\n' +
1504
- '\tsee https://github.com/jprichardson/node-fs-extra/issues/269',
1505
- 'Warning', 'fs-extra-WARN0001'
1506
- );
1507
- }
1508
-
1509
- stat$3.checkPaths(src, dest, 'copy', opts, (err, stats) => {
1510
- if (err) return cb(err)
1511
- const { srcStat, destStat } = stats;
1512
- stat$3.checkParentPaths(src, srcStat, dest, 'copy', err => {
1513
- if (err) return cb(err)
1514
- runFilter(src, dest, opts, (err, include) => {
1515
- if (err) return cb(err)
1516
- if (!include) return cb()
1517
-
1518
- checkParentDir(destStat, src, dest, opts, cb);
1519
- });
1520
- });
1521
- });
1522
- }
1523
-
1524
- function checkParentDir (destStat, src, dest, opts, cb) {
1525
- const destParent = path$9.dirname(dest);
1526
- pathExists$5(destParent, (err, dirExists) => {
1527
- if (err) return cb(err)
1528
- if (dirExists) return getStats$1(destStat, src, dest, opts, cb)
1529
- mkdirs$1(destParent, err => {
1530
- if (err) return cb(err)
1531
- return getStats$1(destStat, src, dest, opts, cb)
1532
- });
1533
- });
1534
- }
1535
-
1536
- function runFilter (src, dest, opts, cb) {
1537
- if (!opts.filter) return cb(null, true)
1538
- Promise.resolve(opts.filter(src, dest))
1539
- .then(include => cb(null, include), error => cb(error));
1540
- }
1541
-
1542
- function getStats$1 (destStat, src, dest, opts, cb) {
1543
- const stat = opts.dereference ? fs$b.stat : fs$b.lstat;
1544
- stat(src, (err, srcStat) => {
1545
- if (err) return cb(err)
1546
-
1547
- if (srcStat.isDirectory()) return onDir$1(srcStat, destStat, src, dest, opts, cb)
1548
- else if (srcStat.isFile() ||
1549
- srcStat.isCharacterDevice() ||
1550
- srcStat.isBlockDevice()) return onFile$1(srcStat, destStat, src, dest, opts, cb)
1551
- else if (srcStat.isSymbolicLink()) return onLink$1(destStat, src, dest, opts, cb)
1552
- else if (srcStat.isSocket()) return cb(new Error(`Cannot copy a socket file: ${src}`))
1553
- else if (srcStat.isFIFO()) return cb(new Error(`Cannot copy a FIFO pipe: ${src}`))
1554
- return cb(new Error(`Unknown file: ${src}`))
1555
- });
1556
- }
1557
-
1558
- function onFile$1 (srcStat, destStat, src, dest, opts, cb) {
1559
- if (!destStat) return copyFile$1(srcStat, src, dest, opts, cb)
1560
- return mayCopyFile$1(srcStat, src, dest, opts, cb)
1561
- }
1562
-
1563
- function mayCopyFile$1 (srcStat, src, dest, opts, cb) {
1564
- if (opts.overwrite) {
1565
- fs$b.unlink(dest, err => {
1566
- if (err) return cb(err)
1567
- return copyFile$1(srcStat, src, dest, opts, cb)
1568
- });
1569
- } else if (opts.errorOnExist) {
1570
- return cb(new Error(`'${dest}' already exists`))
1571
- } else return cb()
1572
- }
1573
-
1574
- function copyFile$1 (srcStat, src, dest, opts, cb) {
1575
- fs$b.copyFile(src, dest, err => {
1576
- if (err) return cb(err)
1577
- if (opts.preserveTimestamps) return handleTimestampsAndMode(srcStat.mode, src, dest, cb)
1578
- return setDestMode$1(dest, srcStat.mode, cb)
1579
- });
1580
- }
1581
-
1582
- function handleTimestampsAndMode (srcMode, src, dest, cb) {
1583
- // Make sure the file is writable before setting the timestamp
1584
- // otherwise open fails with EPERM when invoked with 'r+'
1585
- // (through utimes call)
1586
- if (fileIsNotWritable$1(srcMode)) {
1587
- return makeFileWritable$1(dest, srcMode, err => {
1588
- if (err) return cb(err)
1589
- return setDestTimestampsAndMode(srcMode, src, dest, cb)
1590
- })
1591
- }
1592
- return setDestTimestampsAndMode(srcMode, src, dest, cb)
1593
- }
1594
-
1595
- function fileIsNotWritable$1 (srcMode) {
1596
- return (srcMode & 0o200) === 0
1597
- }
1598
-
1599
- function makeFileWritable$1 (dest, srcMode, cb) {
1600
- return setDestMode$1(dest, srcMode | 0o200, cb)
1601
- }
1602
-
1603
- function setDestTimestampsAndMode (srcMode, src, dest, cb) {
1604
- setDestTimestamps$1(src, dest, err => {
1605
- if (err) return cb(err)
1606
- return setDestMode$1(dest, srcMode, cb)
1607
- });
1608
- }
1609
-
1610
- function setDestMode$1 (dest, srcMode, cb) {
1611
- return fs$b.chmod(dest, srcMode, cb)
1612
- }
1613
-
1614
- function setDestTimestamps$1 (src, dest, cb) {
1615
- // The initial srcStat.atime cannot be trusted
1616
- // because it is modified by the read(2) system call
1617
- // (See https://nodejs.org/api/fs.html#fs_stat_time_values)
1618
- fs$b.stat(src, (err, updatedSrcStat) => {
1619
- if (err) return cb(err)
1620
- return utimesMillis(dest, updatedSrcStat.atime, updatedSrcStat.mtime, cb)
1621
- });
1622
- }
1623
-
1624
- function onDir$1 (srcStat, destStat, src, dest, opts, cb) {
1625
- if (!destStat) return mkDirAndCopy$1(srcStat.mode, src, dest, opts, cb)
1626
- return copyDir$1(src, dest, opts, cb)
1627
- }
1628
-
1629
- function mkDirAndCopy$1 (srcMode, src, dest, opts, cb) {
1630
- fs$b.mkdir(dest, err => {
1631
- if (err) return cb(err)
1632
- copyDir$1(src, dest, opts, err => {
1633
- if (err) return cb(err)
1634
- return setDestMode$1(dest, srcMode, cb)
1635
- });
1636
- });
1637
- }
1638
-
1639
- function copyDir$1 (src, dest, opts, cb) {
1640
- fs$b.readdir(src, (err, items) => {
1641
- if (err) return cb(err)
1642
- return copyDirItems(items, src, dest, opts, cb)
1643
- });
1644
- }
1645
-
1646
- function copyDirItems (items, src, dest, opts, cb) {
1647
- const item = items.pop();
1648
- if (!item) return cb()
1649
- return copyDirItem$1(items, item, src, dest, opts, cb)
1650
- }
1651
-
1652
- function copyDirItem$1 (items, item, src, dest, opts, cb) {
1653
- const srcItem = path$9.join(src, item);
1654
- const destItem = path$9.join(dest, item);
1655
- runFilter(srcItem, destItem, opts, (err, include) => {
1656
- if (err) return cb(err)
1657
- if (!include) return copyDirItems(items, src, dest, opts, cb)
1658
-
1659
- stat$3.checkPaths(srcItem, destItem, 'copy', opts, (err, stats) => {
1660
- if (err) return cb(err)
1661
- const { destStat } = stats;
1662
- getStats$1(destStat, srcItem, destItem, opts, err => {
1663
- if (err) return cb(err)
1664
- return copyDirItems(items, src, dest, opts, cb)
1665
- });
1666
- });
1667
- });
1668
- }
1669
-
1670
- function onLink$1 (destStat, src, dest, opts, cb) {
1671
- fs$b.readlink(src, (err, resolvedSrc) => {
1672
- if (err) return cb(err)
1673
- if (opts.dereference) {
1674
- resolvedSrc = path$9.resolve(process.cwd(), resolvedSrc);
1675
- }
1676
-
1677
- if (!destStat) {
1678
- return fs$b.symlink(resolvedSrc, dest, cb)
1679
- } else {
1680
- fs$b.readlink(dest, (err, resolvedDest) => {
1681
- if (err) {
1682
- // dest exists and is a regular file or directory,
1683
- // Windows may throw UNKNOWN error. If dest already exists,
1684
- // fs throws error anyway, so no need to guard against it here.
1685
- if (err.code === 'EINVAL' || err.code === 'UNKNOWN') return fs$b.symlink(resolvedSrc, dest, cb)
1686
- return cb(err)
1687
- }
1688
- if (opts.dereference) {
1689
- resolvedDest = path$9.resolve(process.cwd(), resolvedDest);
1690
- }
1691
- if (stat$3.isSrcSubdir(resolvedSrc, resolvedDest)) {
1692
- return cb(new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`))
1693
- }
1694
-
1695
- // do not copy if src is a subdir of dest since unlinking
1696
- // dest in this case would result in removing src contents
1697
- // and therefore a broken symlink would be created.
1698
- if (stat$3.isSrcSubdir(resolvedDest, resolvedSrc)) {
1699
- return cb(new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`))
1700
- }
1701
- return copyLink$1(resolvedSrc, dest, cb)
1702
- });
1703
- }
1704
- });
1705
- }
1706
-
1707
- function copyLink$1 (resolvedSrc, dest, cb) {
1708
- fs$b.unlink(dest, err => {
1709
- if (err) return cb(err)
1710
- return fs$b.symlink(resolvedSrc, dest, cb)
1711
- });
1712
- }
1713
-
1714
- var copy_1 = copy$2;
1715
-
1716
- const fs$a = gracefulFs;
1717
- const path$8 = require$$1;
1718
- const mkdirsSync$1 = mkdirs$2.mkdirsSync;
1719
- const utimesMillisSync = utimes.utimesMillisSync;
1720
- const stat$2 = stat$4;
1721
-
1722
- function copySync$1 (src, dest, opts) {
1723
- if (typeof opts === 'function') {
1724
- opts = { filter: opts };
1725
- }
1726
-
1727
- opts = opts || {};
1728
- opts.clobber = 'clobber' in opts ? !!opts.clobber : true; // default to true for now
1729
- opts.overwrite = 'overwrite' in opts ? !!opts.overwrite : opts.clobber; // overwrite falls back to clobber
1730
-
1731
- // Warn about using preserveTimestamps on 32-bit node
1732
- if (opts.preserveTimestamps && process.arch === 'ia32') {
1733
- process.emitWarning(
1734
- 'Using the preserveTimestamps option in 32-bit node is not recommended;\n\n' +
1735
- '\tsee https://github.com/jprichardson/node-fs-extra/issues/269',
1736
- 'Warning', 'fs-extra-WARN0002'
1737
- );
1738
- }
1739
-
1740
- const { srcStat, destStat } = stat$2.checkPathsSync(src, dest, 'copy', opts);
1741
- stat$2.checkParentPathsSync(src, srcStat, dest, 'copy');
1742
- if (opts.filter && !opts.filter(src, dest)) return
1743
- const destParent = path$8.dirname(dest);
1744
- if (!fs$a.existsSync(destParent)) mkdirsSync$1(destParent);
1745
- return getStats(destStat, src, dest, opts)
1746
- }
1747
-
1748
- function getStats (destStat, src, dest, opts) {
1749
- const statSync = opts.dereference ? fs$a.statSync : fs$a.lstatSync;
1750
- const srcStat = statSync(src);
1751
-
1752
- if (srcStat.isDirectory()) return onDir(srcStat, destStat, src, dest, opts)
1753
- else if (srcStat.isFile() ||
1754
- srcStat.isCharacterDevice() ||
1755
- srcStat.isBlockDevice()) return onFile(srcStat, destStat, src, dest, opts)
1756
- else if (srcStat.isSymbolicLink()) return onLink(destStat, src, dest, opts)
1757
- else if (srcStat.isSocket()) throw new Error(`Cannot copy a socket file: ${src}`)
1758
- else if (srcStat.isFIFO()) throw new Error(`Cannot copy a FIFO pipe: ${src}`)
1759
- throw new Error(`Unknown file: ${src}`)
1760
- }
1761
-
1762
- function onFile (srcStat, destStat, src, dest, opts) {
1763
- if (!destStat) return copyFile(srcStat, src, dest, opts)
1764
- return mayCopyFile(srcStat, src, dest, opts)
1765
- }
1766
-
1767
- function mayCopyFile (srcStat, src, dest, opts) {
1768
- if (opts.overwrite) {
1769
- fs$a.unlinkSync(dest);
1770
- return copyFile(srcStat, src, dest, opts)
1771
- } else if (opts.errorOnExist) {
1772
- throw new Error(`'${dest}' already exists`)
1773
- }
1774
- }
1775
-
1776
- function copyFile (srcStat, src, dest, opts) {
1777
- fs$a.copyFileSync(src, dest);
1778
- if (opts.preserveTimestamps) handleTimestamps(srcStat.mode, src, dest);
1779
- return setDestMode(dest, srcStat.mode)
1780
- }
1781
-
1782
- function handleTimestamps (srcMode, src, dest) {
1783
- // Make sure the file is writable before setting the timestamp
1784
- // otherwise open fails with EPERM when invoked with 'r+'
1785
- // (through utimes call)
1786
- if (fileIsNotWritable(srcMode)) makeFileWritable(dest, srcMode);
1787
- return setDestTimestamps(src, dest)
1788
- }
1789
-
1790
- function fileIsNotWritable (srcMode) {
1791
- return (srcMode & 0o200) === 0
1792
- }
1793
-
1794
- function makeFileWritable (dest, srcMode) {
1795
- return setDestMode(dest, srcMode | 0o200)
1796
- }
1797
-
1798
- function setDestMode (dest, srcMode) {
1799
- return fs$a.chmodSync(dest, srcMode)
1800
- }
1801
-
1802
- function setDestTimestamps (src, dest) {
1803
- // The initial srcStat.atime cannot be trusted
1804
- // because it is modified by the read(2) system call
1805
- // (See https://nodejs.org/api/fs.html#fs_stat_time_values)
1806
- const updatedSrcStat = fs$a.statSync(src);
1807
- return utimesMillisSync(dest, updatedSrcStat.atime, updatedSrcStat.mtime)
1808
- }
1809
-
1810
- function onDir (srcStat, destStat, src, dest, opts) {
1811
- if (!destStat) return mkDirAndCopy(srcStat.mode, src, dest, opts)
1812
- return copyDir(src, dest, opts)
1813
- }
1814
-
1815
- function mkDirAndCopy (srcMode, src, dest, opts) {
1816
- fs$a.mkdirSync(dest);
1817
- copyDir(src, dest, opts);
1818
- return setDestMode(dest, srcMode)
1819
- }
1820
-
1821
- function copyDir (src, dest, opts) {
1822
- fs$a.readdirSync(src).forEach(item => copyDirItem(item, src, dest, opts));
1823
- }
1824
-
1825
- function copyDirItem (item, src, dest, opts) {
1826
- const srcItem = path$8.join(src, item);
1827
- const destItem = path$8.join(dest, item);
1828
- if (opts.filter && !opts.filter(srcItem, destItem)) return
1829
- const { destStat } = stat$2.checkPathsSync(srcItem, destItem, 'copy', opts);
1830
- return getStats(destStat, srcItem, destItem, opts)
1831
- }
1832
-
1833
- function onLink (destStat, src, dest, opts) {
1834
- let resolvedSrc = fs$a.readlinkSync(src);
1835
- if (opts.dereference) {
1836
- resolvedSrc = path$8.resolve(process.cwd(), resolvedSrc);
1837
- }
1838
-
1839
- if (!destStat) {
1840
- return fs$a.symlinkSync(resolvedSrc, dest)
1841
- } else {
1842
- let resolvedDest;
1843
- try {
1844
- resolvedDest = fs$a.readlinkSync(dest);
1845
- } catch (err) {
1846
- // dest exists and is a regular file or directory,
1847
- // Windows may throw UNKNOWN error. If dest already exists,
1848
- // fs throws error anyway, so no need to guard against it here.
1849
- if (err.code === 'EINVAL' || err.code === 'UNKNOWN') return fs$a.symlinkSync(resolvedSrc, dest)
1850
- throw err
1851
- }
1852
- if (opts.dereference) {
1853
- resolvedDest = path$8.resolve(process.cwd(), resolvedDest);
1854
- }
1855
- if (stat$2.isSrcSubdir(resolvedSrc, resolvedDest)) {
1856
- throw new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`)
1857
- }
1858
-
1859
- // prevent copy if src is a subdir of dest since unlinking
1860
- // dest in this case would result in removing src contents
1861
- // and therefore a broken symlink would be created.
1862
- if (stat$2.isSrcSubdir(resolvedDest, resolvedSrc)) {
1863
- throw new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`)
1864
- }
1865
- return copyLink(resolvedSrc, dest)
1866
- }
1867
- }
1868
-
1869
- function copyLink (resolvedSrc, dest) {
1870
- fs$a.unlinkSync(dest);
1871
- return fs$a.symlinkSync(resolvedSrc, dest)
1872
- }
1873
-
1874
- var copySync_1 = copySync$1;
1875
-
1876
- const u$8 = universalify$1.fromCallback;
1877
- var copy$1 = {
1878
- copy: u$8(copy_1),
1879
- copySync: copySync_1
1880
- };
1881
-
1882
- const fs$9 = gracefulFs;
1883
- const u$7 = universalify$1.fromCallback;
1884
-
1885
- function remove$2 (path, callback) {
1886
- fs$9.rm(path, { recursive: true, force: true }, callback);
1887
- }
1888
-
1889
- function removeSync$1 (path) {
1890
- fs$9.rmSync(path, { recursive: true, force: true });
1891
- }
1892
-
1893
- var remove_1 = {
1894
- remove: u$7(remove$2),
1895
- removeSync: removeSync$1
1896
- };
1897
-
1898
- const u$6 = universalify$1.fromPromise;
1899
- const fs$8 = fs$h;
1900
- const path$7 = require$$1;
1901
- const mkdir$3 = mkdirs$2;
1902
- const remove$1 = remove_1;
1903
-
1904
- const emptyDir = u$6(async function emptyDir (dir) {
1905
- let items;
1906
- try {
1907
- items = await fs$8.readdir(dir);
1908
- } catch {
1909
- return mkdir$3.mkdirs(dir)
1910
- }
1911
-
1912
- return Promise.all(items.map(item => remove$1.remove(path$7.join(dir, item))))
1913
- });
1914
-
1915
- function emptyDirSync (dir) {
1916
- let items;
1917
- try {
1918
- items = fs$8.readdirSync(dir);
1919
- } catch {
1920
- return mkdir$3.mkdirsSync(dir)
1921
- }
1922
-
1923
- items.forEach(item => {
1924
- item = path$7.join(dir, item);
1925
- remove$1.removeSync(item);
1926
- });
1927
- }
1928
-
1929
- var empty = {
1930
- emptyDirSync,
1931
- emptydirSync: emptyDirSync,
1932
- emptyDir,
1933
- emptydir: emptyDir
1934
- };
1935
-
1936
- const u$5 = universalify$1.fromCallback;
1937
- const path$6 = require$$1;
1938
- const fs$7 = gracefulFs;
1939
- const mkdir$2 = mkdirs$2;
1940
-
1941
- function createFile$1 (file, callback) {
1942
- function makeFile () {
1943
- fs$7.writeFile(file, '', err => {
1944
- if (err) return callback(err)
1945
- callback();
1946
- });
1947
- }
1948
-
1949
- fs$7.stat(file, (err, stats) => { // eslint-disable-line handle-callback-err
1950
- if (!err && stats.isFile()) return callback()
1951
- const dir = path$6.dirname(file);
1952
- fs$7.stat(dir, (err, stats) => {
1953
- if (err) {
1954
- // if the directory doesn't exist, make it
1955
- if (err.code === 'ENOENT') {
1956
- return mkdir$2.mkdirs(dir, err => {
1957
- if (err) return callback(err)
1958
- makeFile();
1959
- })
1960
- }
1961
- return callback(err)
1962
- }
1963
-
1964
- if (stats.isDirectory()) makeFile();
1965
- else {
1966
- // parent is not a directory
1967
- // This is just to cause an internal ENOTDIR error to be thrown
1968
- fs$7.readdir(dir, err => {
1969
- if (err) return callback(err)
1970
- });
1971
- }
1972
- });
1973
- });
1974
- }
1975
-
1976
- function createFileSync$1 (file) {
1977
- let stats;
1978
- try {
1979
- stats = fs$7.statSync(file);
1980
- } catch {}
1981
- if (stats && stats.isFile()) return
1982
-
1983
- const dir = path$6.dirname(file);
1984
- try {
1985
- if (!fs$7.statSync(dir).isDirectory()) {
1986
- // parent is not a directory
1987
- // This is just to cause an internal ENOTDIR error to be thrown
1988
- fs$7.readdirSync(dir);
1989
- }
1990
- } catch (err) {
1991
- // If the stat call above failed because the directory doesn't exist, create it
1992
- if (err && err.code === 'ENOENT') mkdir$2.mkdirsSync(dir);
1993
- else throw err
1994
- }
1995
-
1996
- fs$7.writeFileSync(file, '');
1997
- }
1998
-
1999
- var file = {
2000
- createFile: u$5(createFile$1),
2001
- createFileSync: createFileSync$1
2002
- };
2003
-
2004
- const u$4 = universalify$1.fromCallback;
2005
- const path$5 = require$$1;
2006
- const fs$6 = gracefulFs;
2007
- const mkdir$1 = mkdirs$2;
2008
- const pathExists$4 = pathExists_1.pathExists;
2009
- const { areIdentical: areIdentical$1 } = stat$4;
2010
-
2011
- function createLink$1 (srcpath, dstpath, callback) {
2012
- function makeLink (srcpath, dstpath) {
2013
- fs$6.link(srcpath, dstpath, err => {
2014
- if (err) return callback(err)
2015
- callback(null);
2016
- });
2017
- }
2018
-
2019
- fs$6.lstat(dstpath, (_, dstStat) => {
2020
- fs$6.lstat(srcpath, (err, srcStat) => {
2021
- if (err) {
2022
- err.message = err.message.replace('lstat', 'ensureLink');
2023
- return callback(err)
2024
- }
2025
- if (dstStat && areIdentical$1(srcStat, dstStat)) return callback(null)
2026
-
2027
- const dir = path$5.dirname(dstpath);
2028
- pathExists$4(dir, (err, dirExists) => {
2029
- if (err) return callback(err)
2030
- if (dirExists) return makeLink(srcpath, dstpath)
2031
- mkdir$1.mkdirs(dir, err => {
2032
- if (err) return callback(err)
2033
- makeLink(srcpath, dstpath);
2034
- });
2035
- });
2036
- });
2037
- });
2038
- }
2039
-
2040
- function createLinkSync$1 (srcpath, dstpath) {
2041
- let dstStat;
2042
- try {
2043
- dstStat = fs$6.lstatSync(dstpath);
2044
- } catch {}
2045
-
2046
- try {
2047
- const srcStat = fs$6.lstatSync(srcpath);
2048
- if (dstStat && areIdentical$1(srcStat, dstStat)) return
2049
- } catch (err) {
2050
- err.message = err.message.replace('lstat', 'ensureLink');
2051
- throw err
2052
- }
2053
-
2054
- const dir = path$5.dirname(dstpath);
2055
- const dirExists = fs$6.existsSync(dir);
2056
- if (dirExists) return fs$6.linkSync(srcpath, dstpath)
2057
- mkdir$1.mkdirsSync(dir);
2058
-
2059
- return fs$6.linkSync(srcpath, dstpath)
2060
- }
2061
-
2062
- var link = {
2063
- createLink: u$4(createLink$1),
2064
- createLinkSync: createLinkSync$1
2065
- };
2066
-
2067
- const path$4 = require$$1;
2068
- const fs$5 = gracefulFs;
2069
- const pathExists$3 = pathExists_1.pathExists;
2070
-
2071
- /**
2072
- * Function that returns two types of paths, one relative to symlink, and one
2073
- * relative to the current working directory. Checks if path is absolute or
2074
- * relative. If the path is relative, this function checks if the path is
2075
- * relative to symlink or relative to current working directory. This is an
2076
- * initiative to find a smarter `srcpath` to supply when building symlinks.
2077
- * This allows you to determine which path to use out of one of three possible
2078
- * types of source paths. The first is an absolute path. This is detected by
2079
- * `path.isAbsolute()`. When an absolute path is provided, it is checked to
2080
- * see if it exists. If it does it's used, if not an error is returned
2081
- * (callback)/ thrown (sync). The other two options for `srcpath` are a
2082
- * relative url. By default Node's `fs.symlink` works by creating a symlink
2083
- * using `dstpath` and expects the `srcpath` to be relative to the newly
2084
- * created symlink. If you provide a `srcpath` that does not exist on the file
2085
- * system it results in a broken symlink. To minimize this, the function
2086
- * checks to see if the 'relative to symlink' source file exists, and if it
2087
- * does it will use it. If it does not, it checks if there's a file that
2088
- * exists that is relative to the current working directory, if does its used.
2089
- * This preserves the expectations of the original fs.symlink spec and adds
2090
- * the ability to pass in `relative to current working direcotry` paths.
2091
- */
2092
-
2093
- function symlinkPaths$1 (srcpath, dstpath, callback) {
2094
- if (path$4.isAbsolute(srcpath)) {
2095
- return fs$5.lstat(srcpath, (err) => {
2096
- if (err) {
2097
- err.message = err.message.replace('lstat', 'ensureSymlink');
2098
- return callback(err)
2099
- }
2100
- return callback(null, {
2101
- toCwd: srcpath,
2102
- toDst: srcpath
2103
- })
2104
- })
2105
- } else {
2106
- const dstdir = path$4.dirname(dstpath);
2107
- const relativeToDst = path$4.join(dstdir, srcpath);
2108
- return pathExists$3(relativeToDst, (err, exists) => {
2109
- if (err) return callback(err)
2110
- if (exists) {
2111
- return callback(null, {
2112
- toCwd: relativeToDst,
2113
- toDst: srcpath
2114
- })
2115
- } else {
2116
- return fs$5.lstat(srcpath, (err) => {
2117
- if (err) {
2118
- err.message = err.message.replace('lstat', 'ensureSymlink');
2119
- return callback(err)
2120
- }
2121
- return callback(null, {
2122
- toCwd: srcpath,
2123
- toDst: path$4.relative(dstdir, srcpath)
2124
- })
2125
- })
2126
- }
2127
- })
2128
- }
2129
- }
2130
-
2131
- function symlinkPathsSync$1 (srcpath, dstpath) {
2132
- let exists;
2133
- if (path$4.isAbsolute(srcpath)) {
2134
- exists = fs$5.existsSync(srcpath);
2135
- if (!exists) throw new Error('absolute srcpath does not exist')
2136
- return {
2137
- toCwd: srcpath,
2138
- toDst: srcpath
2139
- }
2140
- } else {
2141
- const dstdir = path$4.dirname(dstpath);
2142
- const relativeToDst = path$4.join(dstdir, srcpath);
2143
- exists = fs$5.existsSync(relativeToDst);
2144
- if (exists) {
2145
- return {
2146
- toCwd: relativeToDst,
2147
- toDst: srcpath
2148
- }
2149
- } else {
2150
- exists = fs$5.existsSync(srcpath);
2151
- if (!exists) throw new Error('relative srcpath does not exist')
2152
- return {
2153
- toCwd: srcpath,
2154
- toDst: path$4.relative(dstdir, srcpath)
2155
- }
2156
- }
2157
- }
2158
- }
2159
-
2160
- var symlinkPaths_1 = {
2161
- symlinkPaths: symlinkPaths$1,
2162
- symlinkPathsSync: symlinkPathsSync$1
2163
- };
2164
-
2165
- const fs$4 = gracefulFs;
2166
-
2167
- function symlinkType$1 (srcpath, type, callback) {
2168
- callback = (typeof type === 'function') ? type : callback;
2169
- type = (typeof type === 'function') ? false : type;
2170
- if (type) return callback(null, type)
2171
- fs$4.lstat(srcpath, (err, stats) => {
2172
- if (err) return callback(null, 'file')
2173
- type = (stats && stats.isDirectory()) ? 'dir' : 'file';
2174
- callback(null, type);
2175
- });
2176
- }
2177
-
2178
- function symlinkTypeSync$1 (srcpath, type) {
2179
- let stats;
2180
-
2181
- if (type) return type
2182
- try {
2183
- stats = fs$4.lstatSync(srcpath);
2184
- } catch {
2185
- return 'file'
2186
- }
2187
- return (stats && stats.isDirectory()) ? 'dir' : 'file'
2188
- }
2189
-
2190
- var symlinkType_1 = {
2191
- symlinkType: symlinkType$1,
2192
- symlinkTypeSync: symlinkTypeSync$1
2193
- };
2194
-
2195
- const u$3 = universalify$1.fromCallback;
2196
- const path$3 = require$$1;
2197
- const fs$3 = fs$h;
2198
- const _mkdirs = mkdirs$2;
2199
- const mkdirs = _mkdirs.mkdirs;
2200
- const mkdirsSync = _mkdirs.mkdirsSync;
2201
-
2202
- const _symlinkPaths = symlinkPaths_1;
2203
- const symlinkPaths = _symlinkPaths.symlinkPaths;
2204
- const symlinkPathsSync = _symlinkPaths.symlinkPathsSync;
2205
-
2206
- const _symlinkType = symlinkType_1;
2207
- const symlinkType = _symlinkType.symlinkType;
2208
- const symlinkTypeSync = _symlinkType.symlinkTypeSync;
2209
-
2210
- const pathExists$2 = pathExists_1.pathExists;
2211
-
2212
- const { areIdentical } = stat$4;
2213
-
2214
- function createSymlink$1 (srcpath, dstpath, type, callback) {
2215
- callback = (typeof type === 'function') ? type : callback;
2216
- type = (typeof type === 'function') ? false : type;
2217
-
2218
- fs$3.lstat(dstpath, (err, stats) => {
2219
- if (!err && stats.isSymbolicLink()) {
2220
- Promise.all([
2221
- fs$3.stat(srcpath),
2222
- fs$3.stat(dstpath)
2223
- ]).then(([srcStat, dstStat]) => {
2224
- if (areIdentical(srcStat, dstStat)) return callback(null)
2225
- _createSymlink(srcpath, dstpath, type, callback);
2226
- });
2227
- } else _createSymlink(srcpath, dstpath, type, callback);
2228
- });
2229
- }
2230
-
2231
- function _createSymlink (srcpath, dstpath, type, callback) {
2232
- symlinkPaths(srcpath, dstpath, (err, relative) => {
2233
- if (err) return callback(err)
2234
- srcpath = relative.toDst;
2235
- symlinkType(relative.toCwd, type, (err, type) => {
2236
- if (err) return callback(err)
2237
- const dir = path$3.dirname(dstpath);
2238
- pathExists$2(dir, (err, dirExists) => {
2239
- if (err) return callback(err)
2240
- if (dirExists) return fs$3.symlink(srcpath, dstpath, type, callback)
2241
- mkdirs(dir, err => {
2242
- if (err) return callback(err)
2243
- fs$3.symlink(srcpath, dstpath, type, callback);
2244
- });
2245
- });
2246
- });
2247
- });
2248
- }
2249
-
2250
- function createSymlinkSync$1 (srcpath, dstpath, type) {
2251
- let stats;
2252
- try {
2253
- stats = fs$3.lstatSync(dstpath);
2254
- } catch {}
2255
- if (stats && stats.isSymbolicLink()) {
2256
- const srcStat = fs$3.statSync(srcpath);
2257
- const dstStat = fs$3.statSync(dstpath);
2258
- if (areIdentical(srcStat, dstStat)) return
2259
- }
2260
-
2261
- const relative = symlinkPathsSync(srcpath, dstpath);
2262
- srcpath = relative.toDst;
2263
- type = symlinkTypeSync(relative.toCwd, type);
2264
- const dir = path$3.dirname(dstpath);
2265
- const exists = fs$3.existsSync(dir);
2266
- if (exists) return fs$3.symlinkSync(srcpath, dstpath, type)
2267
- mkdirsSync(dir);
2268
- return fs$3.symlinkSync(srcpath, dstpath, type)
2269
- }
2270
-
2271
- var symlink = {
2272
- createSymlink: u$3(createSymlink$1),
2273
- createSymlinkSync: createSymlinkSync$1
2274
- };
2275
-
2276
- const { createFile, createFileSync } = file;
2277
- const { createLink, createLinkSync } = link;
2278
- const { createSymlink, createSymlinkSync } = symlink;
2279
-
2280
- var ensure = {
2281
- // file
2282
- createFile,
2283
- createFileSync,
2284
- ensureFile: createFile,
2285
- ensureFileSync: createFileSync,
2286
- // link
2287
- createLink,
2288
- createLinkSync,
2289
- ensureLink: createLink,
2290
- ensureLinkSync: createLinkSync,
2291
- // symlink
2292
- createSymlink,
2293
- createSymlinkSync,
2294
- ensureSymlink: createSymlink,
2295
- ensureSymlinkSync: createSymlinkSync
2296
- };
2297
-
2298
- function stringify$3 (obj, { EOL = '\n', finalEOL = true, replacer = null, spaces } = {}) {
2299
- const EOF = finalEOL ? EOL : '';
2300
- const str = JSON.stringify(obj, replacer, spaces);
2301
-
2302
- return str.replace(/\n/g, EOL) + EOF
2303
- }
2304
-
2305
- function stripBom$1 (content) {
2306
- // we do this because JSON.parse would convert it to a utf8 string if encoding wasn't specified
2307
- if (Buffer.isBuffer(content)) content = content.toString('utf8');
2308
- return content.replace(/^\uFEFF/, '')
2309
- }
2310
-
2311
- var utils = { stringify: stringify$3, stripBom: stripBom$1 };
2312
-
2313
- let _fs;
2314
- try {
2315
- _fs = gracefulFs;
2316
- } catch (_) {
2317
- _fs = require$$0$2;
2318
- }
2319
- const universalify = universalify$1;
2320
- const { stringify: stringify$2, stripBom } = utils;
2321
-
2322
- async function _readFile (file, options = {}) {
2323
- if (typeof options === 'string') {
2324
- options = { encoding: options };
2325
- }
2326
-
2327
- const fs = options.fs || _fs;
2328
-
2329
- const shouldThrow = 'throws' in options ? options.throws : true;
2330
-
2331
- let data = await universalify.fromCallback(fs.readFile)(file, options);
2332
-
2333
- data = stripBom(data);
2334
-
2335
- let obj;
2336
- try {
2337
- obj = JSON.parse(data, options ? options.reviver : null);
2338
- } catch (err) {
2339
- if (shouldThrow) {
2340
- err.message = `${file}: ${err.message}`;
2341
- throw err
2342
- } else {
2343
- return null
2344
- }
2345
- }
2346
-
2347
- return obj
2348
- }
2349
-
2350
- const readFile = universalify.fromPromise(_readFile);
2351
-
2352
- function readFileSync (file, options = {}) {
2353
- if (typeof options === 'string') {
2354
- options = { encoding: options };
2355
- }
2356
-
2357
- const fs = options.fs || _fs;
2358
-
2359
- const shouldThrow = 'throws' in options ? options.throws : true;
2360
-
2361
- try {
2362
- let content = fs.readFileSync(file, options);
2363
- content = stripBom(content);
2364
- return JSON.parse(content, options.reviver)
2365
- } catch (err) {
2366
- if (shouldThrow) {
2367
- err.message = `${file}: ${err.message}`;
2368
- throw err
2369
- } else {
2370
- return null
2371
- }
2372
- }
2373
- }
2374
-
2375
- async function _writeFile (file, obj, options = {}) {
2376
- const fs = options.fs || _fs;
2377
-
2378
- const str = stringify$2(obj, options);
2379
-
2380
- await universalify.fromCallback(fs.writeFile)(file, str, options);
2381
- }
2382
-
2383
- const writeFile = universalify.fromPromise(_writeFile);
2384
-
2385
- function writeFileSync (file, obj, options = {}) {
2386
- const fs = options.fs || _fs;
2387
-
2388
- const str = stringify$2(obj, options);
2389
- // not sure if fs.writeFileSync returns anything, but just in case
2390
- return fs.writeFileSync(file, str, options)
2391
- }
2392
-
2393
- const jsonfile$1 = {
2394
- readFile,
2395
- readFileSync,
2396
- writeFile,
2397
- writeFileSync
2398
- };
2399
-
2400
- var jsonfile_1 = jsonfile$1;
2401
-
2402
- const jsonFile$1 = jsonfile_1;
2403
-
2404
- var jsonfile = {
2405
- // jsonfile exports
2406
- readJson: jsonFile$1.readFile,
2407
- readJsonSync: jsonFile$1.readFileSync,
2408
- writeJson: jsonFile$1.writeFile,
2409
- writeJsonSync: jsonFile$1.writeFileSync
2410
- };
2411
-
2412
- const u$2 = universalify$1.fromCallback;
2413
- const fs$2 = gracefulFs;
2414
- const path$2 = require$$1;
2415
- const mkdir = mkdirs$2;
2416
- const pathExists$1 = pathExists_1.pathExists;
2417
-
2418
- function outputFile$1 (file, data, encoding, callback) {
2419
- if (typeof encoding === 'function') {
2420
- callback = encoding;
2421
- encoding = 'utf8';
2422
- }
2423
-
2424
- const dir = path$2.dirname(file);
2425
- pathExists$1(dir, (err, itDoes) => {
2426
- if (err) return callback(err)
2427
- if (itDoes) return fs$2.writeFile(file, data, encoding, callback)
2428
-
2429
- mkdir.mkdirs(dir, err => {
2430
- if (err) return callback(err)
2431
-
2432
- fs$2.writeFile(file, data, encoding, callback);
2433
- });
2434
- });
2435
- }
2436
-
2437
- function outputFileSync$1 (file, ...args) {
2438
- const dir = path$2.dirname(file);
2439
- if (fs$2.existsSync(dir)) {
2440
- return fs$2.writeFileSync(file, ...args)
2441
- }
2442
- mkdir.mkdirsSync(dir);
2443
- fs$2.writeFileSync(file, ...args);
2444
- }
2445
-
2446
- var outputFile_1 = {
2447
- outputFile: u$2(outputFile$1),
2448
- outputFileSync: outputFileSync$1
2449
- };
2450
-
2451
- const { stringify: stringify$1 } = utils;
2452
- const { outputFile } = outputFile_1;
2453
-
2454
- async function outputJson (file, data, options = {}) {
2455
- const str = stringify$1(data, options);
2456
-
2457
- await outputFile(file, str, options);
2458
- }
2459
-
2460
- var outputJson_1 = outputJson;
2461
-
2462
- const { stringify } = utils;
2463
- const { outputFileSync } = outputFile_1;
2464
-
2465
- function outputJsonSync (file, data, options) {
2466
- const str = stringify(data, options);
2467
-
2468
- outputFileSync(file, str, options);
2469
- }
2470
-
2471
- var outputJsonSync_1 = outputJsonSync;
2472
-
2473
- const u$1 = universalify$1.fromPromise;
2474
- const jsonFile = jsonfile;
2475
-
2476
- jsonFile.outputJson = u$1(outputJson_1);
2477
- jsonFile.outputJsonSync = outputJsonSync_1;
2478
- // aliases
2479
- jsonFile.outputJSON = jsonFile.outputJson;
2480
- jsonFile.outputJSONSync = jsonFile.outputJsonSync;
2481
- jsonFile.writeJSON = jsonFile.writeJson;
2482
- jsonFile.writeJSONSync = jsonFile.writeJsonSync;
2483
- jsonFile.readJSON = jsonFile.readJson;
2484
- jsonFile.readJSONSync = jsonFile.readJsonSync;
2485
-
2486
- var json = jsonFile;
2487
-
2488
- const fs$1 = gracefulFs;
2489
- const path$1 = require$$1;
2490
- const copy = copy$1.copy;
2491
- const remove = remove_1.remove;
2492
- const mkdirp = mkdirs$2.mkdirp;
2493
- const pathExists = pathExists_1.pathExists;
2494
- const stat$1 = stat$4;
2495
-
2496
- function move$1 (src, dest, opts, cb) {
2497
- if (typeof opts === 'function') {
2498
- cb = opts;
2499
- opts = {};
2500
- }
2501
-
2502
- opts = opts || {};
2503
-
2504
- const overwrite = opts.overwrite || opts.clobber || false;
2505
-
2506
- stat$1.checkPaths(src, dest, 'move', opts, (err, stats) => {
2507
- if (err) return cb(err)
2508
- const { srcStat, isChangingCase = false } = stats;
2509
- stat$1.checkParentPaths(src, srcStat, dest, 'move', err => {
2510
- if (err) return cb(err)
2511
- if (isParentRoot$1(dest)) return doRename$1(src, dest, overwrite, isChangingCase, cb)
2512
- mkdirp(path$1.dirname(dest), err => {
2513
- if (err) return cb(err)
2514
- return doRename$1(src, dest, overwrite, isChangingCase, cb)
2515
- });
2516
- });
2517
- });
2518
- }
2519
-
2520
- function isParentRoot$1 (dest) {
2521
- const parent = path$1.dirname(dest);
2522
- const parsedPath = path$1.parse(parent);
2523
- return parsedPath.root === parent
2524
- }
2525
-
2526
- function doRename$1 (src, dest, overwrite, isChangingCase, cb) {
2527
- if (isChangingCase) return rename$1(src, dest, overwrite, cb)
2528
- if (overwrite) {
2529
- return remove(dest, err => {
2530
- if (err) return cb(err)
2531
- return rename$1(src, dest, overwrite, cb)
2532
- })
2533
- }
2534
- pathExists(dest, (err, destExists) => {
2535
- if (err) return cb(err)
2536
- if (destExists) return cb(new Error('dest already exists.'))
2537
- return rename$1(src, dest, overwrite, cb)
2538
- });
2539
- }
2540
-
2541
- function rename$1 (src, dest, overwrite, cb) {
2542
- fs$1.rename(src, dest, err => {
2543
- if (!err) return cb()
2544
- if (err.code !== 'EXDEV') return cb(err)
2545
- return moveAcrossDevice$1(src, dest, overwrite, cb)
2546
- });
2547
- }
2548
-
2549
- function moveAcrossDevice$1 (src, dest, overwrite, cb) {
2550
- const opts = {
2551
- overwrite,
2552
- errorOnExist: true,
2553
- preserveTimestamps: true
2554
- };
2555
- copy(src, dest, opts, err => {
2556
- if (err) return cb(err)
2557
- return remove(src, cb)
2558
- });
2559
- }
2560
-
2561
- var move_1 = move$1;
2562
-
2563
- const fs = gracefulFs;
2564
- const path = require$$1;
2565
- const copySync = copy$1.copySync;
2566
- const removeSync = remove_1.removeSync;
2567
- const mkdirpSync = mkdirs$2.mkdirpSync;
2568
- const stat = stat$4;
2569
-
2570
- function moveSync (src, dest, opts) {
2571
- opts = opts || {};
2572
- const overwrite = opts.overwrite || opts.clobber || false;
2573
-
2574
- const { srcStat, isChangingCase = false } = stat.checkPathsSync(src, dest, 'move', opts);
2575
- stat.checkParentPathsSync(src, srcStat, dest, 'move');
2576
- if (!isParentRoot(dest)) mkdirpSync(path.dirname(dest));
2577
- return doRename(src, dest, overwrite, isChangingCase)
2578
- }
2579
-
2580
- function isParentRoot (dest) {
2581
- const parent = path.dirname(dest);
2582
- const parsedPath = path.parse(parent);
2583
- return parsedPath.root === parent
2584
- }
2585
-
2586
- function doRename (src, dest, overwrite, isChangingCase) {
2587
- if (isChangingCase) return rename(src, dest, overwrite)
2588
- if (overwrite) {
2589
- removeSync(dest);
2590
- return rename(src, dest, overwrite)
2591
- }
2592
- if (fs.existsSync(dest)) throw new Error('dest already exists.')
2593
- return rename(src, dest, overwrite)
2594
- }
2595
-
2596
- function rename (src, dest, overwrite) {
2597
- try {
2598
- fs.renameSync(src, dest);
2599
- } catch (err) {
2600
- if (err.code !== 'EXDEV') throw err
2601
- return moveAcrossDevice(src, dest, overwrite)
2602
- }
2603
- }
2604
-
2605
- function moveAcrossDevice (src, dest, overwrite) {
2606
- const opts = {
2607
- overwrite,
2608
- errorOnExist: true,
2609
- preserveTimestamps: true
2610
- };
2611
- copySync(src, dest, opts);
2612
- return removeSync(src)
29
+ import yargs from 'yargs';
30
+ import { hideBin } from 'yargs/helpers';
31
+ import { join, basename, resolve } from 'node:path';
32
+ import { readFile, rename, mkdir, lstat, copyFile, readdir, unlink, writeFile } from 'node:fs/promises';
33
+ import { setGracefulCleanup, dirSync } from 'tmp';
34
+ import { findUp } from 'find-up';
35
+ import fsExtra from 'fs-extra';
36
+ import { spawn, execSync } from 'node:child_process';
37
+ import { createWriteStream } from 'node:fs';
38
+
39
+ const y = yargs(hideBin(process.argv)).strict(true).usage("test-e2e-interop [options]").hide("version").config().help().option("fail-command", {
40
+ demandOption: false,
41
+ describe: 'This command will be run in a shell (therefore commands like "$SHELL" will work) after failure to inspect the state.',
42
+ type: "string"
43
+ }).option("package-script", {
44
+ array: true,
45
+ default: ["clean?", "build!", "test!", "generate-examples-index?"],
46
+ demandOption: false,
47
+ describe: `The package scripts to run with each package, either "script-name!" to fail or "script-name?" to skip if the script doesn't exist in given package. By default the script is used for all packages, if you want to use it only for one add package name: "package-name script-name!". Scripts are invoked sequentially and command line order is preserved.`,
48
+ type: "string"
49
+ }).option("project", {
50
+ array: true,
51
+ default: [],
52
+ demandOption: false,
53
+ describe: 'Projects to clone using Git, copy from directory or install from tarball. The format is "package-name URL/path".',
54
+ type: "string"
55
+ }).option("tmp-dir", {
56
+ demandOption: false,
57
+ describe: "The working directory for E2E testing. If omitted a new tmp dir will be created and then disposed of.",
58
+ type: "string"
59
+ }).option("logs-to-stdout", {
60
+ demandOption: false,
61
+ default: false,
62
+ describe: "Output the logs to the stdout after the tests finished.",
63
+ type: "boolean"
64
+ });
65
+ function parseArguments() {
66
+ return y.parserConfiguration({ "camel-case-expansion": false }).parseSync();
2613
67
  }
2614
68
 
2615
- var moveSync_1 = moveSync;
2616
-
2617
- const u = universalify$1.fromCallback;
2618
- var move = {
2619
- move: u(move_1),
2620
- moveSync: moveSync_1
2621
- };
2622
-
2623
- var lib = {
2624
- // Export promiseified graceful-fs:
2625
- ...fs$h,
2626
- // Export extra methods:
2627
- ...copy$1,
2628
- ...empty,
2629
- ...ensure,
2630
- ...json,
2631
- ...mkdirs$2,
2632
- ...move,
2633
- ...outputFile_1,
2634
- ...pathExists_1,
2635
- ...remove_1
2636
- };
2637
-
2638
- function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2639
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context8, _context9; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context8 = ownKeys(Object(t), !0)).call(_context8, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context9 = ownKeys(Object(t))).call(_context9, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
2640
- var ProjectState = /*#__PURE__*/_createClass(function ProjectState() {
2641
- var _this = this;
2642
- _classCallCheck(this, ProjectState);
2643
- /**
2644
- * This will be resolved or rejected once all the tasks associated with this
2645
- * project finish.
69
+ const INTEROP_ENV = Object.freeze({
70
+ ...process.env,
71
+ // Prevent Husky from erroring out on shallow cloned repositories.
72
+ HUSKY: "0",
73
+ // Prevent interop tests from going into infinite recursions.
74
+ VIS_INTEROP: "1"
75
+ });
76
+ class ProjectState {
77
+ /**
78
+ * This will be resolved or rejected once all the tasks associated with this
79
+ * project finish.
2646
80
  */
2647
- /**
2648
- * Run this to mark the project as successfully finished.
81
+ promise;
82
+ /**
83
+ * Run this to mark the project as successfully finished.
2649
84
  */
2650
- /**
2651
- * Run this to mark the project as failed.
85
+ resolve;
86
+ /**
87
+ * Run this to mark the project as failed.
2652
88
  */
2653
- /**
2654
- * Provide information about current state of the project.
89
+ reject;
90
+ /**
91
+ * Provide information about current state of the project.
2655
92
  */
2656
- _defineProperty(this, "stage", "pending");
2657
- this.promise = new _Promise(function (resolve, reject) {
2658
- _this.resolve = resolve;
2659
- _this.reject = reject;
2660
- });
2661
- });
2662
- /**
2663
- * Output formatted error message to stderr.
2664
- *
2665
- * @param title - Some explanatory text as to what's going on.
2666
- * @param details - The error or some other message as to what went wrong.
2667
- */
93
+ stage = "pending";
94
+ constructor() {
95
+ this.promise = new Promise((resolve, reject) => {
96
+ this.resolve = resolve;
97
+ this.reject = reject;
98
+ });
99
+ }
100
+ }
2668
101
  function logError(title, details) {
2669
- var _context;
2670
- var wrappedDetails = details != null ? "\n".concat(details instanceof Error ? details.message : details) : "";
2671
- process.stderr.write(_concatInstanceProperty(_context = "\n==> ".concat(title)).call(_context, wrappedDetails, "\n"));
102
+ const wrappedDetails = details != null ? `
103
+ ${details instanceof Error ? details.message : details}` : "";
104
+ process.stderr.write(`
105
+ ==> ${title}${wrappedDetails}
106
+ `);
2672
107
  }
2673
- /**
2674
- * @param title
2675
- * @param details
2676
- */
2677
108
  function logInfo(title, details) {
2678
- var _context2;
2679
- var wrappedDetails = details ? ":\n".concat(details) : "";
2680
- process.stdout.write(_concatInstanceProperty(_context2 = "\n==> ".concat(title)).call(_context2, wrappedDetails, "\n"));
109
+ const wrappedDetails = details ? `:
110
+ ${details}` : "";
111
+ process.stdout.write(`
112
+ ==> ${title}${wrappedDetails}
113
+ `);
2681
114
  }
2682
- /**
2683
- * @param cwd
2684
- * @param failCommand
2685
- * @param error
2686
- */
2687
115
  function execFail(cwd, failCommand, error) {
2688
116
  if (failCommand) {
2689
117
  console.error("\n\nReason for debugging:");
2690
118
  console.error(error);
2691
119
  console.error("\n\nDebuging:");
2692
120
  try {
2693
- node_child_process.execSync(failCommand, {
2694
- cwd: cwd,
121
+ execSync(failCommand, {
122
+ cwd,
2695
123
  encoding: "utf8",
2696
- env: _objectSpread(_objectSpread({}, process.env), {}, {
2697
- VIS_INTEROP: "1"
2698
- }),
124
+ env: INTEROP_ENV,
2699
125
  stdio: "inherit"
2700
126
  });
2701
- } catch (error) {
2702
- console.error(error);
2703
- console.error("The error above is the fail command exitting with non-zero status, not an actual failure in the interop test.");
127
+ } catch (error2) {
128
+ console.error(error2);
129
+ console.error(
130
+ "The error above is the fail command exitting with non-zero status, not an actual failure in the interop test."
131
+ );
2704
132
  }
2705
133
  }
2706
134
  }
2707
- /**
2708
- * @param logDir
2709
- * @param getState
2710
- */
2711
135
  function createSpawner(logDir, getState) {
2712
- var nextId = 1;
2713
- return function spawnThrow(_ref) {
2714
- var cmd = _ref.cmd,
2715
- cwd = _ref.cwd,
2716
- failCommand = _ref.failCommand;
2717
- var id = nextId++;
2718
- var getHeaderLines = function getHeaderLines() {
2719
- var _context3;
2720
- return _concatInstanceProperty(_context3 = ["time: " + new Date().toISOString(), "id: " + id, "cwd: " + cwd, "cmd: " + _mapInstanceProperty(cmd).call(cmd, function (word) {
2721
- return _JSON$stringify(word);
2722
- }).join(" "), "states:"]).call(_context3, _toConsumableArray(getState()));
2723
- };
2724
- var getLogMessage = function getLogMessage() {
2725
- var _context4;
2726
- return _mapInstanceProperty(_context4 = getHeaderLines()).call(_context4, function (line) {
2727
- return " " + line;
2728
- }).join("\n");
2729
- };
136
+ let nextId = 1;
137
+ return function spawnThrow({ cmd, cwd, failCommand }) {
138
+ const id = nextId++;
139
+ const getHeaderLines = () => [
140
+ "time: " + (/* @__PURE__ */ new Date()).toISOString(),
141
+ "id: " + id,
142
+ "cwd: " + cwd,
143
+ "cmd: " + cmd.map((word) => JSON.stringify(word)).join(" "),
144
+ "states:",
145
+ ...getState()
146
+ ];
147
+ const getLogMessage = () => getHeaderLines().map((line) => " " + line).join("\n");
2730
148
  logInfo("Start", getLogMessage());
2731
- return new _Promise(function (resolve, reject) {
2732
- var _context5;
2733
- var commandLogPath = require$$1.join(logDir, [require$$1.basename(cwd).replace(/[^a-zA-Z0-9]+/g, "-"), cmd.join("-").replace(/[^a-zA-Z0-9]+/g, "-"), "id-" + _padStartInstanceProperty(_context5 = "" + id).call(_context5, 3, "0"), "log"].join("."));
2734
- var logStream = lib.createWriteStream(commandLogPath, {
149
+ return new Promise((resolve, reject) => {
150
+ const commandLogPath = join(
151
+ logDir,
152
+ [
153
+ basename(cwd).replace(/[^a-zA-Z0-9]+/g, "-"),
154
+ cmd.join("-").replace(/[^a-zA-Z0-9]+/g, "-"),
155
+ "id-" + ("" + id).padStart(3, "0"),
156
+ "log"
157
+ ].join(".")
158
+ );
159
+ const logStream = createWriteStream(commandLogPath, {
2735
160
  flags: "a"
2736
161
  });
2737
162
  logStream.write(getHeaderLines().join("\n") + "\n\n");
2738
- var child = node_child_process.spawn(cmd[0], _sliceInstanceProperty(cmd).call(cmd, 1), {
2739
- cwd: cwd,
2740
- env: _objectSpread(_objectSpread({}, process.env), {}, {
2741
- VIS_INTEROP: "1"
2742
- }),
163
+ const child = spawn(cmd[0], cmd.slice(1), {
164
+ cwd,
165
+ env: INTEROP_ENV,
2743
166
  stdio: "pipe"
2744
167
  });
2745
168
  child.stdout.pipe(logStream);
2746
169
  child.stderr.pipe(logStream);
2747
- /**
2748
- * Add status to the file name just before the .log extension on a best
2749
- * effort basis (no errors reported)..
2750
- *
2751
- * @param code - The code or other kind of status to append.
2752
- */
2753
170
  function addStatusCodeToFilename(code) {
2754
- var newPath = _sliceInstanceProperty(commandLogPath).call(commandLogPath, 0, -4) + ".status-" + code + ".log";
2755
- lib.rename(commandLogPath, newPath).catch(function (error) {
2756
- console.error("Failed to rename log file to ".concat(newPath, "."), error);
171
+ const newPath = commandLogPath.slice(0, -4) + ".status-" + code + ".log";
172
+ rename(commandLogPath, newPath).catch((error) => {
173
+ console.error(`Failed to rename log file to ${newPath}.`, error);
2757
174
  });
2758
175
  }
2759
- var failed = false;
2760
- child.on("close", function (code) {
176
+ let failed = false;
177
+ child.on("close", (code) => {
2761
178
  if (failed) ; else if (code !== 0) {
2762
- var _context6;
2763
179
  logError("Fail", getLogMessage());
2764
- var errorMessage = _concatInstanceProperty(_context6 = "".concat(_mapInstanceProperty(cmd).call(cmd, function (word) {
2765
- return "\"".concat(word, "\"");
2766
- }).join(" "), ": exited with ")).call(_context6, code, ".");
2767
- logStream.end(function () {
2768
- _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
2769
- var commandOutput;
2770
- return _regeneratorRuntime.wrap(function _callee$(_context7) {
2771
- while (1) switch (_context7.prev = _context7.next) {
2772
- case 0:
2773
- commandOutput = "";
2774
- _context7.prev = 1;
2775
- _context7.t0 = commandOutput;
2776
- _context7.next = 5;
2777
- return lib.readFile(commandLogPath, "utf-8");
2778
- case 5:
2779
- commandOutput = _context7.t0 += _context7.sent;
2780
- _context7.next = 11;
2781
- break;
2782
- case 8:
2783
- _context7.prev = 8;
2784
- _context7.t1 = _context7["catch"](1);
2785
- commandOutput += "Failed to log command output.";
2786
- case 11:
2787
- execFail(cwd, failCommand, commandOutput + "\n\n" + errorMessage);
2788
- case 12:
2789
- case "end":
2790
- return _context7.stop();
2791
- }
2792
- }, _callee, null, [[1, 8]]);
2793
- }))();
180
+ const errorMessage = `${cmd.map((word) => `"${word}"`).join(" ")}: exited with ${code}.`;
181
+ logStream.end(() => {
182
+ (async () => {
183
+ let commandOutput = "";
184
+ try {
185
+ commandOutput += await readFile(commandLogPath, "utf-8");
186
+ } catch (error) {
187
+ commandOutput += "Failed to log command output.";
188
+ }
189
+ execFail(cwd, failCommand, commandOutput + "\n\n" + errorMessage);
190
+ })();
2794
191
  });
2795
- addStatusCodeToFilename(code !== null && code !== void 0 ? code : "null");
192
+ addStatusCodeToFilename(code ?? "null");
2796
193
  reject(new Error(errorMessage));
2797
194
  } else {
2798
195
  logInfo("Okay", getLogMessage());
@@ -2800,7 +197,7 @@ function createSpawner(logDir, getState) {
2800
197
  resolve();
2801
198
  }
2802
199
  });
2803
- child.on("error", function (error) {
200
+ child.on("error", (error) => {
2804
201
  failed = true;
2805
202
  logError("Fail", getLogMessage());
2806
203
  execFail(cwd, failCommand, error);
@@ -2811,798 +208,340 @@ function createSpawner(logDir, getState) {
2811
208
  };
2812
209
  }
2813
210
 
2814
- function _createForOfIteratorHelper$1(o, allowArrayLike) { var it = typeof _Symbol !== "undefined" && _getIteratorMethod(o) || o["@@iterator"]; if (!it) { if (_Array$isArray(o) || (it = _unsupportedIterableToArray$1(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2815
- function _unsupportedIterableToArray$1(o, minLen) { var _context33; if (!o) return; if (typeof o === "string") return _arrayLikeToArray$1(o, minLen); var n = _sliceInstanceProperty(_context33 = Object.prototype.toString.call(o)).call(_context33, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return _Array$from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen); }
2816
- function _arrayLikeToArray$1(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
2817
- // Remove all temporary files on process exit.
2818
- tmp.setGracefulCleanup();
2819
- /**
2820
- * @param tmpPath
2821
- */
2822
- function prepareTmpDir(_x) {
2823
- return _prepareTmpDir.apply(this, arguments);
2824
- }
2825
- /**
2826
- * @param projectName
2827
- */
2828
- function _prepareTmpDir() {
2829
- _prepareTmpDir = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(tmpPath) {
2830
- return _regeneratorRuntime.wrap(function _callee$(_context) {
2831
- while (1) switch (_context.prev = _context.next) {
2832
- case 0:
2833
- if (!tmpPath) {
2834
- _context.next = 6;
2835
- break;
2836
- }
2837
- _context.next = 3;
2838
- return lib.mkdirp(tmpPath);
2839
- case 3:
2840
- return _context.abrupt("return", {
2841
- name: tmpPath,
2842
- removeCallback: function removeCallback() {}
2843
- });
2844
- case 6:
2845
- return _context.abrupt("return", tmp.dirSync({
2846
- unsafeCleanup: true
2847
- }));
2848
- case 7:
2849
- case "end":
2850
- return _context.stop();
211
+ const { copy, mkdirp } = fsExtra;
212
+ setGracefulCleanup();
213
+ async function prepareTmpDir(tmpPath) {
214
+ if (tmpPath) {
215
+ await mkdirp(tmpPath);
216
+ return {
217
+ name: tmpPath,
218
+ removeCallback: () => {
2851
219
  }
2852
- }, _callee);
2853
- }));
2854
- return _prepareTmpDir.apply(this, arguments);
220
+ };
221
+ } else {
222
+ return dirSync({ unsafeCleanup: true });
223
+ }
2855
224
  }
2856
225
  function getTarballName(projectName) {
2857
- return "".concat(projectName, "-0.0.0-no-version.tgz");
2858
- }
2859
- /**
2860
- * @param root0
2861
- * @param root0.tmpRootResolve
2862
- * @param projectName
2863
- */
2864
- function getTarballPath(_ref, projectName) {
2865
- var tmpRootResolve = _ref.tmpRootResolve;
2866
- return tmpRootResolve("".concat(projectName, ".tgz"));
2867
- }
2868
- /**
2869
- * @param data
2870
- * @param projectName
2871
- */
2872
- function copyTarball(_x2, _x3) {
2873
- return _copyTarball.apply(this, arguments);
2874
- }
2875
- /**
2876
- * @param cwd
2877
- */
2878
- function _copyTarball() {
2879
- _copyTarball = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(data, projectName) {
2880
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
2881
- while (1) switch (_context2.prev = _context2.next) {
2882
- case 0:
2883
- _context2.next = 2;
2884
- return lib.copyFile(data.tmpReposResolve(projectName, getTarballName(projectName)), getTarballPath(data, projectName));
2885
- case 2:
2886
- case "end":
2887
- return _context2.stop();
2888
- }
2889
- }, _callee2);
2890
- }));
2891
- return _copyTarball.apply(this, arguments);
2892
- }
2893
- function getPackageDeps(_x4) {
2894
- return _getPackageDeps.apply(this, arguments);
2895
- }
2896
- /**
2897
- * @param data
2898
- * @param projectName
2899
- */
2900
- function _getPackageDeps() {
2901
- _getPackageDeps = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(cwd) {
2902
- var _context3;
2903
- var packageJSONPath, packageJSON;
2904
- return _regeneratorRuntime.wrap(function _callee3$(_context4) {
2905
- while (1) switch (_context4.prev = _context4.next) {
2906
- case 0:
2907
- _context4.next = 2;
2908
- return findUp("package.json", {
2909
- cwd: cwd
2910
- });
2911
- case 2:
2912
- packageJSONPath = _context4.sent;
2913
- if (!(packageJSONPath == null)) {
2914
- _context4.next = 5;
2915
- break;
2916
- }
2917
- throw new Error("Project's package.json file not found.");
2918
- case 5:
2919
- _context4.t0 = JSON;
2920
- _context4.next = 8;
2921
- return lib.readFile(packageJSONPath, "utf8");
2922
- case 8:
2923
- _context4.t1 = _context4.sent;
2924
- packageJSON = _context4.t0.parse.call(_context4.t0, _context4.t1);
2925
- return _context4.abrupt("return", _toConsumableArray(new _Set(_concatInstanceProperty(_context3 = []).call(_context3, _toConsumableArray(_Object$keys(packageJSON.dependencies || {})), _toConsumableArray(_Object$keys(packageJSON.devDependencies || {})), _toConsumableArray(_Object$keys(packageJSON.peerDependencies || {}))))));
2926
- case 11:
2927
- case "end":
2928
- return _context4.stop();
2929
- }
2930
- }, _callee3);
2931
- }));
2932
- return _getPackageDeps.apply(this, arguments);
2933
- }
2934
- function getPackageLocalDeps(_x5, _x6) {
2935
- return _getPackageLocalDeps.apply(this, arguments);
2936
- }
2937
- /**
2938
- * @param spawn
2939
- * @param data
2940
- * @param projectName
2941
- */
2942
- function _getPackageLocalDeps() {
2943
- _getPackageLocalDeps = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(data, projectName) {
2944
- var _context5;
2945
- var projectPaths, tmpReposResolve, cwd;
2946
- return _regeneratorRuntime.wrap(function _callee4$(_context6) {
2947
- while (1) switch (_context6.prev = _context6.next) {
2948
- case 0:
2949
- projectPaths = data.projectPaths, tmpReposResolve = data.tmpReposResolve;
2950
- cwd = tmpReposResolve(projectName);
2951
- _context6.t0 = _filterInstanceProperty;
2952
- _context6.next = 5;
2953
- return getPackageDeps(cwd);
2954
- case 5:
2955
- _context6.t1 = _context5 = _context6.sent;
2956
- return _context6.abrupt("return", (0, _context6.t0)(_context6.t1).call(_context5, function (depName) {
2957
- return projectPaths[depName] != null;
2958
- }));
2959
- case 7:
2960
- case "end":
2961
- return _context6.stop();
2962
- }
2963
- }, _callee4);
2964
- }));
2965
- return _getPackageLocalDeps.apply(this, arguments);
2966
- }
2967
- function clone(_x7, _x8, _x9) {
2968
- return _clone.apply(this, arguments);
2969
- }
2970
- /**
2971
- * @param cwd
2972
- * @param deps
2973
- */
2974
- function _clone() {
2975
- _clone = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(spawn, data, projectName) {
2976
- var failCommand, projectPaths, tmpReposResolve, cwd, projectPath;
2977
- return _regeneratorRuntime.wrap(function _callee5$(_context7) {
2978
- while (1) switch (_context7.prev = _context7.next) {
2979
- case 0:
2980
- failCommand = data.failCommand, projectPaths = data.projectPaths, tmpReposResolve = data.tmpReposResolve;
2981
- cwd = tmpReposResolve();
2982
- projectPath = projectPaths[projectName];
2983
- if (!/\.git$/.test(projectPath)) {
2984
- _context7.next = 8;
2985
- break;
2986
- }
2987
- _context7.next = 6;
2988
- return spawn({
2989
- cmd: ["git", "clone", projectPath, "--single-branch", "--branch", "master", "--depth", "1"],
2990
- cwd: cwd,
2991
- failCommand: failCommand
2992
- });
2993
- case 6:
2994
- _context7.next = 10;
2995
- break;
2996
- case 8:
2997
- _context7.next = 10;
2998
- return lib.copy(projectPath, tmpReposResolve(projectName), {
2999
- filter: function filter(_src, dest) {
3000
- return !/[\\/].git[\\/]/.test(dest) && !/[\\/]node_modules[\\/]/.test(dest);
3001
- }
3002
- });
3003
- case 10:
3004
- case "end":
3005
- return _context7.stop();
3006
- }
3007
- }, _callee5);
3008
- }));
3009
- return _clone.apply(this, arguments);
3010
- }
3011
- function updatePackageDepVersions(_x10, _x11) {
3012
- return _updatePackageDepVersions.apply(this, arguments);
3013
- }
3014
- /**
3015
- * @param spawn
3016
- * @param data
3017
- * @param projectName
3018
- */
3019
- function _updatePackageDepVersions() {
3020
- _updatePackageDepVersions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(cwd, deps) {
3021
- var _context8, _packageJSON$dependen, _context9, _packageJSON$devDepen, _context10, _packageJSON$peerDepe;
3022
- var packageJSONPath, packageJSON;
3023
- return _regeneratorRuntime.wrap(function _callee6$(_context11) {
3024
- while (1) switch (_context11.prev = _context11.next) {
3025
- case 0:
3026
- _context11.next = 2;
3027
- return findUp("package.json", {
3028
- cwd: cwd
3029
- });
3030
- case 2:
3031
- packageJSONPath = _context11.sent;
3032
- if (!(packageJSONPath == null)) {
3033
- _context11.next = 5;
3034
- break;
3035
- }
3036
- throw new Error("Project's package.json file not found.");
3037
- case 5:
3038
- _context11.t0 = JSON;
3039
- _context11.next = 8;
3040
- return lib.readFile(packageJSONPath, "utf8");
3041
- case 8:
3042
- _context11.t1 = _context11.sent;
3043
- packageJSON = _context11.t0.parse.call(_context11.t0, _context11.t1);
3044
- _forEachInstanceProperty(_context8 = _Object$keys((_packageJSON$dependen = packageJSON.dependencies) !== null && _packageJSON$dependen !== void 0 ? _packageJSON$dependen : {})).call(_context8, function (key) {
3045
- if (Object.prototype.hasOwnProperty.call(deps, key)) {
3046
- packageJSON.dependencies[key] = "file:" + deps[key];
3047
- }
3048
- });
3049
- _forEachInstanceProperty(_context9 = _Object$keys((_packageJSON$devDepen = packageJSON.devDependencies) !== null && _packageJSON$devDepen !== void 0 ? _packageJSON$devDepen : {})).call(_context9, function (key) {
3050
- if (Object.prototype.hasOwnProperty.call(deps, key)) {
3051
- packageJSON.devDependencies[key] = "file:" + deps[key];
3052
- }
3053
- });
3054
- _forEachInstanceProperty(_context10 = _Object$keys((_packageJSON$peerDepe = packageJSON.peerDependencies) !== null && _packageJSON$peerDepe !== void 0 ? _packageJSON$peerDepe : {})).call(_context10, function (key) {
3055
- if (Object.prototype.hasOwnProperty.call(deps, key)) {
3056
- packageJSON.peerDependencies[key] = "file:" + deps[key];
3057
- }
3058
- });
3059
- _context11.next = 15;
3060
- return lib.writeFile(packageJSONPath, _JSON$stringify(packageJSON, undefined, 4));
3061
- case 15:
3062
- case "end":
3063
- return _context11.stop();
3064
- }
3065
- }, _callee6);
3066
- }));
3067
- return _updatePackageDepVersions.apply(this, arguments);
3068
- }
3069
- function buildTestPack(_x12, _x13, _x14) {
3070
- return _buildTestPack.apply(this, arguments);
3071
- }
3072
- /**
3073
- * @param data
3074
- */
3075
- function _buildTestPack() {
3076
- _buildTestPack = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(spawn, data, projectName) {
3077
- var _context12;
3078
- var failCommand, packageScripts, tmpReposResolve, cwd, packageLockPath, _iterator, _step, _step$value, packageName, scriptName, skipIfMissing;
3079
- return _regeneratorRuntime.wrap(function _callee7$(_context13) {
3080
- while (1) switch (_context13.prev = _context13.next) {
3081
- case 0:
3082
- failCommand = data.failCommand, packageScripts = data.packageScripts, tmpReposResolve = data.tmpReposResolve;
3083
- cwd = tmpReposResolve(projectName);
3084
- _context13.t0 = updatePackageDepVersions;
3085
- _context13.t1 = cwd;
3086
- _context13.t2 = _reduceInstanceProperty;
3087
- _context13.next = 7;
3088
- return getPackageLocalDeps(data, projectName);
3089
- case 7:
3090
- _context13.t3 = _context12 = _context13.sent;
3091
- _context13.t4 = (0, _context13.t2)(_context13.t3).call(_context12, function (acc, key) {
3092
- acc[key] = getTarballPath(data, key);
3093
- return acc;
3094
- }, _Object$create(null));
3095
- _context13.next = 11;
3096
- return (0, _context13.t0)(_context13.t1, _context13.t4);
3097
- case 11:
3098
- _context13.next = 13;
3099
- return findUp("package-lock.json", {
3100
- cwd: cwd
3101
- });
3102
- case 13:
3103
- packageLockPath = _context13.sent;
3104
- if (!(packageLockPath != null)) {
3105
- _context13.next = 17;
3106
- break;
3107
- }
3108
- _context13.next = 17;
3109
- return lib.unlink(packageLockPath);
3110
- case 17:
3111
- _context13.next = 19;
3112
- return spawn({
3113
- cmd: ["npm", "install"],
3114
- cwd: cwd,
3115
- failCommand: failCommand
3116
- });
3117
- case 19:
3118
- _iterator = _createForOfIteratorHelper$1(packageScripts);
3119
- _context13.prev = 20;
3120
- _iterator.s();
3121
- case 22:
3122
- if ((_step = _iterator.n()).done) {
3123
- _context13.next = 37;
3124
- break;
3125
- }
3126
- _step$value = _step.value, packageName = _step$value.packageName, scriptName = _step$value.scriptName, skipIfMissing = _step$value.skipIfMissing;
3127
- if (!(packageName != null && packageName !== projectName)) {
3128
- _context13.next = 28;
3129
- break;
3130
- }
3131
- return _context13.abrupt("continue", 35);
3132
- case 28:
3133
- if (!skipIfMissing) {
3134
- _context13.next = 33;
3135
- break;
3136
- }
3137
- _context13.next = 31;
3138
- return spawn({
3139
- cmd: ["npm", "run", scriptName, "--if-present"],
3140
- cwd: cwd,
3141
- failCommand: failCommand
3142
- });
3143
- case 31:
3144
- _context13.next = 35;
3145
- break;
3146
- case 33:
3147
- _context13.next = 35;
3148
- return spawn({
3149
- cmd: ["npm", "run", scriptName],
3150
- cwd: cwd,
3151
- failCommand: failCommand
3152
- });
3153
- case 35:
3154
- _context13.next = 22;
3155
- break;
3156
- case 37:
3157
- _context13.next = 42;
3158
- break;
3159
- case 39:
3160
- _context13.prev = 39;
3161
- _context13.t5 = _context13["catch"](20);
3162
- _iterator.e(_context13.t5);
3163
- case 42:
3164
- _context13.prev = 42;
3165
- _iterator.f();
3166
- return _context13.finish(42);
3167
- case 45:
3168
- _context13.next = 47;
3169
- return spawn({
3170
- cmd: ["npm", "pack"],
3171
- cwd: cwd,
3172
- failCommand: failCommand
3173
- });
3174
- case 47:
3175
- _context13.next = 49;
3176
- return copyTarball(data, projectName);
3177
- case 49:
3178
- case "end":
3179
- return _context13.stop();
3180
- }
3181
- }, _callee7, null, [[20, 39, 42, 45]]);
3182
- }));
3183
- return _buildTestPack.apply(this, arguments);
3184
- }
3185
- function checkTmpPath(_x15) {
3186
- return _checkTmpPath.apply(this, arguments);
3187
- }
3188
- /**
3189
- * @param root0
3190
- * @param root0.failCommand
3191
- * @param root0.logsToStdout
3192
- * @param root0.packageScripts
3193
- * @param root0.projectPaths
3194
- * @param root0.tmpPath
3195
- */
3196
- function _checkTmpPath() {
3197
- _checkTmpPath = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(data) {
3198
- var tmpDir;
3199
- return _regeneratorRuntime.wrap(function _callee8$(_context14) {
3200
- while (1) switch (_context14.prev = _context14.next) {
3201
- case 0:
3202
- tmpDir = data.tmpRootResolve();
3203
- _context14.next = 3;
3204
- return lib.readdir(tmpDir);
3205
- case 3:
3206
- _context14.t0 = _context14.sent.length;
3207
- if (!(_context14.t0 !== 0)) {
3208
- _context14.next = 6;
3209
- break;
3210
- }
3211
- throw new Error("The tmp dir (\"".concat(tmpDir, "\") is not empty."));
3212
- case 6:
3213
- case "end":
3214
- return _context14.stop();
226
+ return `${projectName}-0.0.0-no-version.tgz`;
227
+ }
228
+ function getTarballPath({ tmpRootResolve }, projectName) {
229
+ return tmpRootResolve(`${projectName}.tgz`);
230
+ }
231
+ async function copyTarball(data, projectName) {
232
+ await copyFile(
233
+ data.tmpReposResolve(projectName, getTarballName(projectName)),
234
+ getTarballPath(data, projectName)
235
+ );
236
+ }
237
+ async function getPackageDeps(cwd) {
238
+ const packageJSONPath = await findUp("package.json", { cwd });
239
+ if (packageJSONPath == null) {
240
+ throw new Error("Project's package.json file not found.");
241
+ }
242
+ const packageJSON = JSON.parse(await readFile(packageJSONPath, "utf8"));
243
+ return [
244
+ .../* @__PURE__ */ new Set([
245
+ ...Object.keys(packageJSON.dependencies || {}),
246
+ ...Object.keys(packageJSON.devDependencies || {}),
247
+ ...Object.keys(packageJSON.peerDependencies || {})
248
+ ])
249
+ ];
250
+ }
251
+ async function getPackageLocalDeps(data, projectName) {
252
+ const { projectPaths, tmpReposResolve } = data;
253
+ const cwd = tmpReposResolve(projectName);
254
+ return (await getPackageDeps(cwd)).filter(
255
+ (depName) => projectPaths[depName] != null
256
+ );
257
+ }
258
+ async function clone(spawn, data, projectName) {
259
+ const { failCommand, projectPaths, tmpReposResolve } = data;
260
+ const cwd = tmpReposResolve();
261
+ const projectPath = projectPaths[projectName];
262
+ if (/\.git$/.test(projectPath)) {
263
+ await spawn({
264
+ cmd: [
265
+ "git",
266
+ "clone",
267
+ projectPath,
268
+ "--single-branch",
269
+ "--branch",
270
+ "master",
271
+ "--depth",
272
+ "1"
273
+ ],
274
+ cwd,
275
+ failCommand
276
+ });
277
+ } else {
278
+ await copy(projectPath, tmpReposResolve(projectName), {
279
+ filter(_src, dest) {
280
+ return !/[\\/].git[\\/]/.test(dest) && !/[\\/]node_modules[\\/]/.test(dest);
3215
281
  }
3216
- }, _callee8);
3217
- }));
3218
- return _checkTmpPath.apply(this, arguments);
3219
- }
3220
- function test(_x16) {
3221
- return _test.apply(this, arguments);
282
+ });
283
+ }
3222
284
  }
3223
- function _test() {
3224
- _test = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(_ref2) {
3225
- var _context18;
3226
- var failCommand, logsToStdout, packageScripts, projectPaths, tmpPath, data, projectStatuses, getStages, _context21, _context22, _context26, _context27, spawn, allSucceeded, _iterator3, _step3, _step3$value, projectName, promise, _context28, _context29, _context30, _context31;
3227
- return _regeneratorRuntime.wrap(function _callee11$(_context32) {
3228
- while (1) switch (_context32.prev = _context32.next) {
3229
- case 0:
3230
- getStages = function _getStages() {
3231
- var _context19;
3232
- return _mapInstanceProperty(_context19 = _toConsumableArray(projectStatuses)).call(_context19, function (_ref3) {
3233
- var _context20;
3234
- var _ref4 = _slicedToArray(_ref3, 2),
3235
- key = _ref4[0],
3236
- stage = _ref4[1].stage;
3237
- return _concatInstanceProperty(_context20 = " ".concat(key, ": ")).call(_context20, stage);
3238
- });
3239
- };
3240
- failCommand = _ref2.failCommand, logsToStdout = _ref2.logsToStdout, packageScripts = _ref2.packageScripts, projectPaths = _ref2.projectPaths, tmpPath = _ref2.tmpPath;
3241
- if (!(process.env.VIS_INTEROP === "1")) {
3242
- _context32.next = 5;
3243
- break;
3244
- }
3245
- // This would result in infinite loop otherwise.
3246
- logInfo("Skipping interop test.");
3247
- return _context32.abrupt("return", true);
3248
- case 5:
3249
- _context32.t0 = _Object$freeze;
3250
- _context32.t1 = failCommand;
3251
- _context32.t2 = packageScripts;
3252
- _context32.t3 = projectPaths;
3253
- _context32.next = 11;
3254
- return prepareTmpDir(tmpPath ? require$$1.resolve(tmpPath, "repos") : undefined);
3255
- case 11:
3256
- _context32.t4 = _context32.sent;
3257
- _context32.t5 = function tmpLogsResolve() {
3258
- var _context15;
3259
- for (var _len = arguments.length, paths = new Array(_len), _key = 0; _key < _len; _key++) {
3260
- paths[_key] = arguments[_key];
285
+ async function updatePackageDepVersions(cwd, deps) {
286
+ const packageJSONPath = await findUp("package.json", { cwd });
287
+ if (packageJSONPath == null) {
288
+ throw new Error("Project's package.json file not found.");
289
+ }
290
+ const packageJSON = JSON.parse(await readFile(packageJSONPath, "utf8"));
291
+ Object.keys(packageJSON.dependencies ?? {}).forEach((key) => {
292
+ if (Object.prototype.hasOwnProperty.call(deps, key)) {
293
+ packageJSON.dependencies[key] = "file:" + deps[key];
294
+ }
295
+ });
296
+ Object.keys(packageJSON.devDependencies ?? {}).forEach((key) => {
297
+ if (Object.prototype.hasOwnProperty.call(deps, key)) {
298
+ packageJSON.devDependencies[key] = "file:" + deps[key];
299
+ }
300
+ });
301
+ Object.keys(packageJSON.peerDependencies ?? {}).forEach((key) => {
302
+ if (Object.prototype.hasOwnProperty.call(deps, key)) {
303
+ packageJSON.peerDependencies[key] = "file:" + deps[key];
304
+ }
305
+ });
306
+ await writeFile(packageJSONPath, JSON.stringify(packageJSON, void 0, 4));
307
+ }
308
+ async function buildTestPack(spawn, data, projectName) {
309
+ const { failCommand, packageScripts, tmpReposResolve } = data;
310
+ const cwd = tmpReposResolve(projectName);
311
+ await updatePackageDepVersions(
312
+ cwd,
313
+ (await getPackageLocalDeps(data, projectName)).reduce((acc, key) => {
314
+ acc[key] = getTarballPath(data, key);
315
+ return acc;
316
+ }, /* @__PURE__ */ Object.create(null))
317
+ );
318
+ const packageLockPath = await findUp("package-lock.json", { cwd });
319
+ if (packageLockPath != null) {
320
+ await unlink(packageLockPath);
321
+ }
322
+ await spawn({
323
+ cmd: ["npm", "install"],
324
+ cwd,
325
+ failCommand
326
+ });
327
+ for (const { packageName, scriptName, skipIfMissing } of packageScripts) {
328
+ if (packageName != null && packageName !== projectName) {
329
+ continue;
330
+ } else if (skipIfMissing) {
331
+ await spawn({
332
+ cmd: ["npm", "run", scriptName, "--if-present"],
333
+ cwd,
334
+ failCommand
335
+ });
336
+ } else {
337
+ await spawn({
338
+ cmd: ["npm", "run", scriptName],
339
+ cwd,
340
+ failCommand
341
+ });
342
+ }
343
+ }
344
+ await spawn({ cmd: ["npm", "pack"], cwd, failCommand });
345
+ await copyTarball(data, projectName);
346
+ }
347
+ async function checkTmpPath(data) {
348
+ const tmpDir = data.tmpRootResolve();
349
+ if ((await readdir(tmpDir)).length !== 0) {
350
+ throw new Error(`The tmp dir ("${tmpDir}") is not empty.`);
351
+ }
352
+ }
353
+ async function test({
354
+ failCommand,
355
+ logsToStdout,
356
+ packageScripts,
357
+ projectPaths,
358
+ tmpPath
359
+ }) {
360
+ if (process.env.VIS_INTEROP === "1") {
361
+ logInfo("Skipping interop test.");
362
+ return true;
363
+ }
364
+ const data = Object.freeze({
365
+ failCommand,
366
+ packageScripts,
367
+ projectPaths,
368
+ tmpDir: await prepareTmpDir(
369
+ tmpPath ? resolve(tmpPath, "repos") : void 0
370
+ ),
371
+ tmpLogsResolve: (...paths) => resolve(data.tmpDir.name, "logs", ...paths),
372
+ tmpReposResolve: (...paths) => resolve(data.tmpDir.name, "repos", ...paths),
373
+ tmpRootResolve: (...paths) => resolve(data.tmpDir.name, ...paths),
374
+ visDevUtilsPath: process.cwd()
375
+ });
376
+ const projectStatuses = new Map(
377
+ Object.keys(data.projectPaths).map((project) => [
378
+ project,
379
+ new ProjectState()
380
+ ])
381
+ );
382
+ function getStages() {
383
+ return [...projectStatuses].map(
384
+ ([key, { stage }]) => ` ${key}: ${stage}`
385
+ );
386
+ }
387
+ try {
388
+ const spawn = createSpawner(data.tmpLogsResolve(), getStages);
389
+ await checkTmpPath(data);
390
+ await Promise.all(
391
+ ["repos", "logs"].map(
392
+ (dir) => mkdir(resolve(data.tmpDir.name, dir))
393
+ )
394
+ );
395
+ logInfo("Begin", getStages().join("\n"));
396
+ await Promise.all(
397
+ [...projectStatuses].map(async ([projectName, state]) => {
398
+ try {
399
+ state.stage = "preparing";
400
+ const projectPath = data.projectPaths[projectName];
401
+ const stats = await (async () => {
402
+ try {
403
+ return await lstat(projectPath);
404
+ } catch {
405
+ return null;
3261
406
  }
3262
- return require$$1.resolve.apply(void 0, _concatInstanceProperty(_context15 = [data.tmpDir.name, "logs"]).call(_context15, paths));
3263
- };
3264
- _context32.t6 = function tmpReposResolve() {
3265
- var _context16;
3266
- for (var _len2 = arguments.length, paths = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
3267
- paths[_key2] = arguments[_key2];
407
+ })();
408
+ if (stats?.isFile()) {
409
+ state.stage = "copying tarball";
410
+ await copyFile(projectPath, getTarballPath(data, projectName));
411
+ state.stage = "tarball copied";
412
+ } else {
413
+ state.stage = "cloning";
414
+ await clone(spawn, data, projectName);
415
+ state.stage = "gathering dependencies";
416
+ const failedDeps = [];
417
+ const localDeps = await getPackageLocalDeps(data, projectName);
418
+ state.stage = `waiting for dependencies (${localDeps.join(", ")})`;
419
+ for (const localDep of localDeps) {
420
+ const depStatus = projectStatuses.get(localDep);
421
+ if (depStatus == null) {
422
+ throw new Error(`Dependency ${localDep} not found.`);
423
+ }
424
+ try {
425
+ await depStatus.promise;
426
+ } catch {
427
+ failedDeps.push(localDep);
428
+ }
3268
429
  }
3269
- return require$$1.resolve.apply(void 0, _concatInstanceProperty(_context16 = [data.tmpDir.name, "repos"]).call(_context16, paths));
3270
- };
3271
- _context32.t7 = function tmpRootResolve() {
3272
- var _context17;
3273
- for (var _len3 = arguments.length, paths = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
3274
- paths[_key3] = arguments[_key3];
430
+ if (failedDeps.length > 0) {
431
+ state.stage = `dependencies failed: ${failedDeps.join(", ")}`;
432
+ throw new Error(state.stage);
3275
433
  }
3276
- return require$$1.resolve.apply(void 0, _concatInstanceProperty(_context17 = [data.tmpDir.name]).call(_context17, paths));
3277
- };
3278
- _context32.t8 = process.cwd();
3279
- _context32.t9 = {
3280
- failCommand: _context32.t1,
3281
- packageScripts: _context32.t2,
3282
- projectPaths: _context32.t3,
3283
- tmpDir: _context32.t4,
3284
- tmpLogsResolve: _context32.t5,
3285
- tmpReposResolve: _context32.t6,
3286
- tmpRootResolve: _context32.t7,
3287
- visDevUtilsPath: _context32.t8
3288
- };
3289
- data = (0, _context32.t0)(_context32.t9);
3290
- projectStatuses = new _Map(_mapInstanceProperty(_context18 = _Object$keys(data.projectPaths)).call(_context18, function (project) {
3291
- return [project, new ProjectState()];
3292
- }));
3293
- /**
3294
- *
3295
- */
3296
- _context32.prev = 19;
3297
- spawn = createSpawner(data.tmpLogsResolve(), getStages);
3298
- _context32.next = 23;
3299
- return checkTmpPath(data);
3300
- case 23:
3301
- _context32.next = 25;
3302
- return _Promise.all(_mapInstanceProperty(_context21 = ["repos", "logs"]).call(_context21, function (dir) {
3303
- return lib.mkdir(require$$1.resolve(data.tmpDir.name, dir));
3304
- }));
3305
- case 25:
3306
- logInfo("Begin", getStages().join("\n"));
3307
- _context32.next = 28;
3308
- return _Promise.all(_mapInstanceProperty(_context22 = _toConsumableArray(projectStatuses)).call(_context22, /*#__PURE__*/function () {
3309
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(_ref5) {
3310
- var _ref7, projectName, state, projectPath, stats, failedDeps, localDeps, _iterator2, _step2, localDep, depStatus, _context24;
3311
- return _regeneratorRuntime.wrap(function _callee10$(_context25) {
3312
- while (1) switch (_context25.prev = _context25.next) {
3313
- case 0:
3314
- _ref7 = _slicedToArray(_ref5, 2), projectName = _ref7[0], state = _ref7[1];
3315
- _context25.prev = 1;
3316
- state.stage = "preparing";
3317
- projectPath = data.projectPaths[projectName];
3318
- _context25.next = 6;
3319
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
3320
- return _regeneratorRuntime.wrap(function _callee9$(_context23) {
3321
- while (1) switch (_context23.prev = _context23.next) {
3322
- case 0:
3323
- _context23.prev = 0;
3324
- _context23.next = 3;
3325
- return lib.lstat(projectPath);
3326
- case 3:
3327
- return _context23.abrupt("return", _context23.sent);
3328
- case 6:
3329
- _context23.prev = 6;
3330
- _context23.t0 = _context23["catch"](0);
3331
- return _context23.abrupt("return", null);
3332
- case 9:
3333
- case "end":
3334
- return _context23.stop();
3335
- }
3336
- }, _callee9, null, [[0, 6]]);
3337
- }))();
3338
- case 6:
3339
- stats = _context25.sent;
3340
- if (!(stats !== null && stats !== void 0 && stats.isFile())) {
3341
- _context25.next = 14;
3342
- break;
3343
- }
3344
- // The path points to a ready to install tarball.
3345
- state.stage = "copying tarball";
3346
- _context25.next = 11;
3347
- return lib.copyFile(projectPath, getTarballPath(data, projectName));
3348
- case 11:
3349
- state.stage = "tarball copied";
3350
- _context25.next = 56;
3351
- break;
3352
- case 14:
3353
- // The path points to a repo (maybe remote) that has to be built,
3354
- // tested and packed first.
3355
- state.stage = "cloning";
3356
- _context25.next = 17;
3357
- return clone(spawn, data, projectName);
3358
- case 17:
3359
- state.stage = "gathering dependencies";
3360
- failedDeps = [];
3361
- _context25.next = 21;
3362
- return getPackageLocalDeps(data, projectName);
3363
- case 21:
3364
- localDeps = _context25.sent;
3365
- state.stage = "waiting for dependencies (".concat(localDeps.join(", "), ")");
3366
- _iterator2 = _createForOfIteratorHelper$1(localDeps);
3367
- _context25.prev = 24;
3368
- _iterator2.s();
3369
- case 26:
3370
- if ((_step2 = _iterator2.n()).done) {
3371
- _context25.next = 41;
3372
- break;
3373
- }
3374
- localDep = _step2.value;
3375
- depStatus = projectStatuses.get(localDep);
3376
- if (!(depStatus == null)) {
3377
- _context25.next = 31;
3378
- break;
3379
- }
3380
- throw new Error("Dependency ".concat(localDep, " not found."));
3381
- case 31:
3382
- _context25.prev = 31;
3383
- _context25.next = 34;
3384
- return depStatus.promise;
3385
- case 34:
3386
- _context25.next = 39;
3387
- break;
3388
- case 36:
3389
- _context25.prev = 36;
3390
- _context25.t0 = _context25["catch"](31);
3391
- failedDeps.push(localDep);
3392
- case 39:
3393
- _context25.next = 26;
3394
- break;
3395
- case 41:
3396
- _context25.next = 46;
3397
- break;
3398
- case 43:
3399
- _context25.prev = 43;
3400
- _context25.t1 = _context25["catch"](24);
3401
- _iterator2.e(_context25.t1);
3402
- case 46:
3403
- _context25.prev = 46;
3404
- _iterator2.f();
3405
- return _context25.finish(46);
3406
- case 49:
3407
- if (!(failedDeps.length > 0)) {
3408
- _context25.next = 52;
3409
- break;
3410
- }
3411
- state.stage = "dependencies failed: ".concat(failedDeps.join(", "));
3412
- throw new Error(state.stage);
3413
- case 52:
3414
- state.stage = "running CI tasks";
3415
- _context25.next = 55;
3416
- return buildTestPack(spawn, data, projectName);
3417
- case 55:
3418
- state.stage = "cloned, built, tested and packed";
3419
- case 56:
3420
- logInfo("Okay ".concat(projectName), getStages().join("\n"));
3421
- state.resolve();
3422
- _context25.next = 64;
3423
- break;
3424
- case 60:
3425
- _context25.prev = 60;
3426
- _context25.t2 = _context25["catch"](1);
3427
- logError(_concatInstanceProperty(_context24 = "Fail ".concat(projectName, " (")).call(_context24, state.stage, "):"), getStages().join("\n"));
3428
- state.reject(_context25.t2 instanceof Error ? _context25.t2 : new Error("" + _context25.t2));
3429
- case 64:
3430
- case "end":
3431
- return _context25.stop();
3432
- }
3433
- }, _callee10, null, [[1, 60], [24, 43, 46, 49], [31, 36]]);
3434
- }));
3435
- return function (_x17) {
3436
- return _ref6.apply(this, arguments);
3437
- };
3438
- }()));
3439
- case 28:
3440
- _context32.t10 = _everyInstanceProperty;
3441
- _context32.next = 31;
3442
- return _Promise.allSettled(_mapInstanceProperty(_context27 = _toConsumableArray(_valuesInstanceProperty(projectStatuses).call(projectStatuses))).call(_context27, function (status) {
3443
- return status.promise;
3444
- }));
3445
- case 31:
3446
- _context32.t11 = _context26 = _context32.sent;
3447
- allSucceeded = (0, _context32.t10)(_context32.t11).call(_context26, function (_ref9) {
3448
- var status = _ref9.status;
3449
- return status === "fulfilled";
3450
- });
3451
- if (!allSucceeded) {
3452
- _context32.next = 37;
3453
- break;
3454
- }
3455
- return _context32.abrupt("return", true);
3456
- case 37:
3457
- return _context32.abrupt("return", false);
3458
- case 38:
3459
- _context32.prev = 38;
3460
- // Wait for all the projects to finish and log the state summary and any
3461
- // errors encountered.
3462
- logInfo("End", getStages().join("\n"));
3463
- _iterator3 = _createForOfIteratorHelper$1(projectStatuses);
3464
- _context32.prev = 41;
3465
- _iterator3.s();
3466
- case 43:
3467
- if ((_step3 = _iterator3.n()).done) {
3468
- _context32.next = 55;
3469
- break;
434
+ state.stage = "running CI tasks";
435
+ await buildTestPack(spawn, data, projectName);
436
+ state.stage = "cloned, built, tested and packed";
3470
437
  }
3471
- _step3$value = _slicedToArray(_step3.value, 2), projectName = _step3$value[0], promise = _step3$value[1].promise;
3472
- _context32.prev = 45;
3473
- _context32.next = 48;
3474
- return promise;
3475
- case 48:
3476
- _context32.next = 53;
3477
- break;
3478
- case 50:
3479
- _context32.prev = 50;
3480
- _context32.t12 = _context32["catch"](45);
3481
- logError("".concat(projectName, " failed with"), _context32.t12);
3482
- case 53:
3483
- _context32.next = 43;
3484
- break;
3485
- case 55:
3486
- _context32.next = 60;
3487
- break;
3488
- case 57:
3489
- _context32.prev = 57;
3490
- _context32.t13 = _context32["catch"](41);
3491
- _iterator3.e(_context32.t13);
3492
- case 60:
3493
- _context32.prev = 60;
3494
- _iterator3.f();
3495
- return _context32.finish(60);
3496
- case 63:
3497
- if (!logsToStdout) {
3498
- _context32.next = 82;
3499
- break;
3500
- }
3501
- logInfo("Outputs");
3502
- _context32.t14 = process.stdout;
3503
- _context32.t15 = _concatInstanceProperty(_context28 = [""]);
3504
- _context32.t16 = _context28;
3505
- _context32.t17 = _toConsumableArray;
3506
- _context32.t18 = _Promise;
3507
- _context32.t19 = _mapInstanceProperty;
3508
- _context32.next = 73;
3509
- return lib.readdir(data.tmpLogsResolve());
3510
- case 73:
3511
- _context32.t20 = _context29 = _context32.sent;
3512
- _context32.t21 = (0, _context32.t19)(_context32.t20).call(_context29, function (filename) {
3513
- return lib.readFile(data.tmpLogsResolve(filename), "UTF-8");
3514
- });
3515
- _context32.next = 77;
3516
- return _context32.t18.all.call(_context32.t18, _context32.t21);
3517
- case 77:
3518
- _context32.t22 = _context32.sent;
3519
- _context32.t23 = (0, _context32.t17)(_context32.t22);
3520
- _context32.t24 = [""];
3521
- _context32.t25 = _context32.t15.call.call(_context32.t15, _context32.t16, _context32.t23, _context32.t24).join("\n\n" + _repeatInstanceProperty(_context30 = _repeatInstanceProperty(_context31 = "-").call(_context31, 80) + "\n").call(_context30, 2) + "\n");
3522
- _context32.t14.write.call(_context32.t14, _context32.t25);
3523
- case 82:
3524
- execFail(data.tmpDir.name, failCommand, "Allow the state to be inspected in debug mode before the data is lost.");
3525
- return _context32.finish(38);
3526
- case 84:
3527
- case "end":
3528
- return _context32.stop();
3529
- }
3530
- }, _callee11, null, [[19,, 38, 84], [41, 57, 60, 63], [45, 50]]);
3531
- }));
3532
- return _test.apply(this, arguments);
438
+ logInfo(`Okay ${projectName}`, getStages().join("\n"));
439
+ state.resolve();
440
+ } catch (error) {
441
+ logError(
442
+ `Fail ${projectName} (${state.stage}):`,
443
+ getStages().join("\n")
444
+ );
445
+ state.reject(error instanceof Error ? error : new Error("" + error));
446
+ }
447
+ })
448
+ );
449
+ const allSucceeded = (await Promise.allSettled(
450
+ [...projectStatuses.values()].map(
451
+ (status) => status.promise
452
+ )
453
+ )).every(({ status }) => status === "fulfilled");
454
+ if (allSucceeded) {
455
+ return true;
456
+ } else {
457
+ return false;
458
+ }
459
+ } finally {
460
+ logInfo("End", getStages().join("\n"));
461
+ for (const [projectName, { promise }] of projectStatuses) {
462
+ try {
463
+ await promise;
464
+ } catch (error) {
465
+ logError(`${projectName} failed with`, error);
466
+ }
467
+ }
468
+ if (logsToStdout) {
469
+ logInfo("Outputs");
470
+ process.stdout.write(
471
+ [
472
+ "",
473
+ ...await Promise.all(
474
+ (await readdir(data.tmpLogsResolve())).map(
475
+ (filename) => readFile(data.tmpLogsResolve(filename), "utf-8")
476
+ )
477
+ ),
478
+ ""
479
+ ].join("\n\n" + ("-".repeat(80) + "\n").repeat(2) + "\n")
480
+ );
481
+ }
482
+ execFail(
483
+ data.tmpDir.name,
484
+ failCommand,
485
+ "Allow the state to be inspected in debug mode before the data is lost."
486
+ );
487
+ }
3533
488
  }
3534
489
 
3535
- var _context, _context2;
3536
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof _Symbol !== "undefined" && _getIteratorMethod(o) || o["@@iterator"]; if (!it) { if (_Array$isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
3537
- function _unsupportedIterableToArray(o, minLen) { var _context3; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = _sliceInstanceProperty(_context3 = Object.prototype.toString.call(o)).call(_context3, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return _Array$from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
3538
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
3539
- var argv = parseArguments();
3540
- var projectPaths = _reduceInstanceProperty(_context = _mapInstanceProperty(_context2 = argv["project"]).call(_context2, function (raw) {
3541
- var _raw$split = raw.split(" ", 2),
3542
- _raw$split2 = _slicedToArray(_raw$split, 2),
3543
- name = _raw$split2[0],
3544
- path = _raw$split2[1];
490
+ const argv = parseArguments();
491
+ const projectPaths = argv["project"].map((raw) => {
492
+ const [name, path] = raw.split(" ", 2);
3545
493
  if (typeof name === "string" && typeof path === "string") {
3546
494
  if (/^[a-zA-Z0-9]+:\/\//.test(path)) {
3547
- // Remote URL, use as is.
3548
495
  return [name, path];
3549
496
  } else {
3550
- // Local path, resolve to prevent CWD issues.
3551
- return [name, require$$1.resolve(path)];
497
+ return [name, resolve(path)];
3552
498
  }
3553
499
  } else {
3554
- console.error("--project-path should be in 'project-name ./path' format, got '".concat(raw, "'."));
500
+ console.error(
501
+ `--project-path should be in 'project-name ./path' format, got '${raw}'.`
502
+ );
3555
503
  process.exit(1);
3556
504
  }
3557
- })).call(_context, function (acc, _ref) {
3558
- var _ref2 = _slicedToArray(_ref, 2),
3559
- name = _ref2[0],
3560
- path = _ref2[1];
505
+ }).reduce((acc, [name, path]) => {
3561
506
  acc[name] = path;
3562
507
  return acc;
3563
508
  }, {});
3564
- var rawPackageScriptArg = argv["package-script"];
3565
- var packageScripts = _flatMapInstanceProperty(rawPackageScriptArg).call(rawPackageScriptArg, function (raw) {
3566
- var packageScripts = [];
3567
- var packageName = null;
3568
- var _iterator = _createForOfIteratorHelper(raw.split(" ")),
3569
- _step;
3570
- try {
3571
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
3572
- var part = _step.value;
3573
- var mode = _sliceInstanceProperty(part).call(part, -1);
509
+ const rawPackageScriptArg = argv["package-script"];
510
+ const packageScripts = rawPackageScriptArg.flatMap(
511
+ (raw) => {
512
+ const packageScripts2 = [];
513
+ let packageName = null;
514
+ for (const part of raw.split(" ")) {
515
+ const mode = part.slice(-1);
3574
516
  if (mode === "?" || mode === "!") {
3575
- packageScripts.push({
3576
- packageName: packageName,
3577
- scriptName: _sliceInstanceProperty(part).call(part, 0, -1),
517
+ packageScripts2.push({
518
+ packageName,
519
+ scriptName: part.slice(0, -1),
3578
520
  skipIfMissing: mode === "?"
3579
521
  });
3580
522
  } else {
3581
523
  packageName = part;
3582
524
  }
3583
525
  }
3584
- } catch (err) {
3585
- _iterator.e(err);
3586
- } finally {
3587
- _iterator.f();
526
+ return packageScripts2;
3588
527
  }
3589
- return packageScripts;
3590
- });
3591
- var tmpPath = argv["tmp-dir"] ? require$$1.resolve(argv["tmp-dir"]) : undefined;
3592
- var failCommand = argv["fail-command"];
3593
- var logsToStdout = argv["logs-to-stdout"];
3594
- test({
3595
- failCommand: failCommand,
3596
- logsToStdout: logsToStdout,
3597
- packageScripts: packageScripts,
3598
- projectPaths: projectPaths,
3599
- tmpPath: tmpPath
3600
- }).then(function (allSucceeded) {
528
+ );
529
+ const tmpPath = argv["tmp-dir"] ? resolve(argv["tmp-dir"]) : void 0;
530
+ const failCommand = argv["fail-command"];
531
+ const logsToStdout = argv["logs-to-stdout"];
532
+ try {
533
+ const allSucceeded = await test({
534
+ failCommand,
535
+ logsToStdout,
536
+ packageScripts,
537
+ projectPaths,
538
+ tmpPath
539
+ });
3601
540
  if (!allSucceeded) {
3602
541
  process.exitCode = 1;
3603
542
  }
3604
- }).catch(function (reason) {
543
+ } catch (reason) {
3605
544
  console.error(reason);
3606
545
  process.exitCode = 2;
3607
- });
546
+ }
3608
547
  //# sourceMappingURL=test-e2e-interop.js.map