protobufjs 6.11.4 → 6.11.6

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 (118) hide show
  1. package/cli/node_modules/.package-lock.json +86 -32
  2. package/cli/node_modules/@babel/parser/package.json +66 -30
  3. package/cli/node_modules/@types/linkify-it/package.json +65 -36
  4. package/cli/node_modules/@types/markdown-it/package.json +67 -39
  5. package/cli/node_modules/@types/mdurl/package.json +53 -21
  6. package/cli/node_modules/acorn/package.json +48 -17
  7. package/cli/node_modules/acorn-jsx/package.json +42 -11
  8. package/cli/node_modules/argparse/package.json +52 -17
  9. package/cli/node_modules/bluebird/package.json +65 -38
  10. package/cli/node_modules/brace-expansion/index.js +14 -12
  11. package/cli/node_modules/brace-expansion/package.json +4 -1
  12. package/cli/node_modules/catharsis/package.json +44 -10
  13. package/cli/node_modules/deep-is/.travis.yml +5 -0
  14. package/cli/node_modules/deep-is/LICENSE +22 -0
  15. package/cli/node_modules/deep-is/README.markdown +70 -0
  16. package/cli/node_modules/deep-is/example/cmp.js +11 -0
  17. package/cli/node_modules/deep-is/index.js +102 -0
  18. package/cli/node_modules/deep-is/package.json +58 -0
  19. package/cli/node_modules/deep-is/test/NaN.js +16 -0
  20. package/cli/node_modules/deep-is/test/cmp.js +23 -0
  21. package/cli/node_modules/deep-is/test/neg-vs-pos-0.js +15 -0
  22. package/cli/node_modules/entities/package.json +95 -60
  23. package/cli/node_modules/escape-string-regexp/package.json +84 -41
  24. package/cli/node_modules/escodegen/escodegen.js +25 -66
  25. package/cli/node_modules/escodegen/package.json +11 -13
  26. package/cli/node_modules/esprima/package.json +82 -54
  27. package/cli/node_modules/estraverse/estraverse.js +1 -24
  28. package/cli/node_modules/estraverse/package.json +1 -1
  29. package/cli/node_modules/esutils/package.json +52 -21
  30. package/cli/node_modules/fast-levenshtein/LICENSE.md +25 -0
  31. package/cli/node_modules/fast-levenshtein/README.md +104 -0
  32. package/cli/node_modules/fast-levenshtein/levenshtein.js +136 -0
  33. package/cli/node_modules/fast-levenshtein/package.json +39 -0
  34. package/cli/node_modules/fs.realpath/package.json +52 -16
  35. package/cli/node_modules/graceful-fs/package.json +57 -25
  36. package/cli/node_modules/inflight/package.json +44 -15
  37. package/cli/node_modules/inherits/package.json +44 -12
  38. package/cli/node_modules/js2xmlparser/package.json +94 -62
  39. package/cli/node_modules/klaw/package.json +53 -23
  40. package/cli/node_modules/levn/LICENSE +22 -0
  41. package/cli/node_modules/levn/README.md +196 -0
  42. package/cli/node_modules/levn/lib/cast.js +298 -0
  43. package/cli/node_modules/levn/lib/coerce.js +285 -0
  44. package/cli/node_modules/levn/lib/index.js +22 -0
  45. package/cli/node_modules/levn/lib/parse-string.js +113 -0
  46. package/cli/node_modules/levn/lib/parse.js +102 -0
  47. package/cli/node_modules/levn/package.json +47 -0
  48. package/cli/node_modules/linkify-it/package.json +58 -23
  49. package/cli/node_modules/lodash/package.json +61 -10
  50. package/cli/node_modules/markdown-it/package.json +68 -33
  51. package/cli/node_modules/markdown-it-anchor/package.json +72 -30
  52. package/cli/node_modules/marked/package.json +87 -52
  53. package/cli/node_modules/mdurl/package.json +44 -9
  54. package/cli/node_modules/minimatch/README.md +37 -0
  55. package/cli/node_modules/minimatch/minimatch.js +160 -102
  56. package/cli/node_modules/minimatch/package.json +2 -2
  57. package/cli/node_modules/mkdirp/package.json +56 -22
  58. package/cli/node_modules/once/package.json +48 -14
  59. package/cli/node_modules/optionator/CHANGELOG.md +56 -0
  60. package/cli/node_modules/optionator/LICENSE +22 -0
  61. package/cli/node_modules/optionator/README.md +238 -0
  62. package/cli/node_modules/optionator/lib/help.js +260 -0
  63. package/cli/node_modules/optionator/lib/index.js +465 -0
  64. package/cli/node_modules/optionator/lib/util.js +54 -0
  65. package/cli/node_modules/optionator/package.json +44 -0
  66. package/cli/node_modules/prelude-ls/CHANGELOG.md +99 -0
  67. package/cli/node_modules/prelude-ls/LICENSE +22 -0
  68. package/cli/node_modules/prelude-ls/README.md +15 -0
  69. package/cli/node_modules/prelude-ls/lib/Func.js +65 -0
  70. package/cli/node_modules/prelude-ls/lib/List.js +686 -0
  71. package/cli/node_modules/prelude-ls/lib/Num.js +130 -0
  72. package/cli/node_modules/prelude-ls/lib/Obj.js +154 -0
  73. package/cli/node_modules/prelude-ls/lib/Str.js +92 -0
  74. package/cli/node_modules/prelude-ls/lib/index.js +178 -0
  75. package/cli/node_modules/prelude-ls/package.json +52 -0
  76. package/cli/node_modules/requizzle/package.json +52 -21
  77. package/cli/node_modules/source-map/package.json +197 -54
  78. package/cli/node_modules/strip-json-comments/package.json +80 -45
  79. package/cli/node_modules/tmp/README.md +47 -21
  80. package/cli/node_modules/tmp/lib/tmp.js +209 -147
  81. package/cli/node_modules/tmp/package.json +73 -37
  82. package/cli/node_modules/type-check/LICENSE +22 -0
  83. package/cli/node_modules/type-check/README.md +210 -0
  84. package/cli/node_modules/type-check/lib/check.js +126 -0
  85. package/cli/node_modules/type-check/lib/index.js +16 -0
  86. package/cli/node_modules/type-check/lib/parse-type.js +196 -0
  87. package/cli/node_modules/type-check/package.json +40 -0
  88. package/cli/node_modules/uc.micro/package.json +45 -9
  89. package/cli/node_modules/underscore/package.json +95 -61
  90. package/cli/node_modules/word-wrap/LICENSE +21 -0
  91. package/cli/node_modules/word-wrap/README.md +201 -0
  92. package/cli/node_modules/word-wrap/index.d.ts +50 -0
  93. package/cli/node_modules/word-wrap/index.js +61 -0
  94. package/cli/node_modules/word-wrap/package.json +77 -0
  95. package/cli/node_modules/wrappy/package.json +46 -16
  96. package/cli/node_modules/xmlcreate/package.json +87 -55
  97. package/cli/package-lock.json +842 -0
  98. package/cli/package.json +1 -1
  99. package/dist/light/protobuf.js +3 -2
  100. package/dist/light/protobuf.js.map +1 -1
  101. package/dist/light/protobuf.min.js +3 -3
  102. package/dist/light/protobuf.min.js.map +1 -1
  103. package/dist/minimal/protobuf.js +2 -2
  104. package/dist/minimal/protobuf.min.js +3 -3
  105. package/dist/minimal/protobuf.min.js.map +1 -1
  106. package/dist/protobuf.js +3 -2
  107. package/dist/protobuf.js.map +1 -1
  108. package/dist/protobuf.min.js +3 -3
  109. package/dist/protobuf.min.js.map +1 -1
  110. package/package.json +1 -1
  111. package/src/type.js +1 -0
  112. package/cli/node_modules/rimraf/CHANGELOG.md +0 -65
  113. package/cli/node_modules/rimraf/LICENSE +0 -15
  114. package/cli/node_modules/rimraf/README.md +0 -101
  115. package/cli/node_modules/rimraf/bin.js +0 -68
  116. package/cli/node_modules/rimraf/package.json +0 -32
  117. package/cli/node_modules/rimraf/rimraf.js +0 -360
  118. package/cli/node_modules/tmp/CHANGELOG.md +0 -288
@@ -14,40 +14,49 @@ const os = require('os');
14
14
  const path = require('path');
15
15
  const crypto = require('crypto');
16
16
  const _c = { fs: fs.constants, os: os.constants };
17
- const rimraf = require('rimraf');
18
17
 
19
18
  /*
20
19
  * The working inner variables.
21
20
  */
22
- const
23
- // the random characters to choose from
21
+ const // the random characters to choose from
24
22
  RANDOM_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
25
-
26
23
  TEMPLATE_PATTERN = /XXXXXX/,
27
-
28
24
  DEFAULT_TRIES = 3,
29
-
30
25
  CREATE_FLAGS = (_c.O_CREAT || _c.fs.O_CREAT) | (_c.O_EXCL || _c.fs.O_EXCL) | (_c.O_RDWR || _c.fs.O_RDWR),
31
-
32
26
  // constants are off on the windows platform and will not match the actual errno codes
33
27
  IS_WIN32 = os.platform() === 'win32',
34
28
  EBADF = _c.EBADF || _c.os.errno.EBADF,
35
29
  ENOENT = _c.ENOENT || _c.os.errno.ENOENT,
36
-
37
30
  DIR_MODE = 0o700 /* 448 */,
38
31
  FILE_MODE = 0o600 /* 384 */,
39
-
40
32
  EXIT = 'exit',
41
-
42
33
  // this will hold the objects need to be removed on exit
43
34
  _removeObjects = [],
44
-
45
35
  // API change in fs.rmdirSync leads to error when passing in a second parameter, e.g. the callback
46
- FN_RMDIR_SYNC = fs.rmdirSync.bind(fs),
47
- FN_RIMRAF_SYNC = rimraf.sync;
36
+ FN_RMDIR_SYNC = fs.rmdirSync.bind(fs);
37
+
38
+ let _gracefulCleanup = false;
48
39
 
49
- let
50
- _gracefulCleanup = false;
40
+ /**
41
+ * Recursively remove a directory and its contents.
42
+ *
43
+ * @param {string} dirPath path of directory to remove
44
+ * @param {Function} callback
45
+ * @private
46
+ */
47
+ function rimraf(dirPath, callback) {
48
+ return fs.rm(dirPath, { recursive: true }, callback);
49
+ }
50
+
51
+ /**
52
+ * Recursively remove a directory and its contents, synchronously.
53
+ *
54
+ * @param {string} dirPath path of directory to remove
55
+ * @private
56
+ */
57
+ function FN_RIMRAF_SYNC(dirPath) {
58
+ return fs.rmSync(dirPath, { recursive: true });
59
+ }
51
60
 
52
61
  /**
53
62
  * Gets a temporary file name.
@@ -56,38 +65,35 @@ let
56
65
  * @param {?tmpNameCallback} callback the callback function
57
66
  */
58
67
  function tmpName(options, callback) {
59
- const
60
- args = _parseArguments(options, callback),
68
+ const args = _parseArguments(options, callback),
61
69
  opts = args[0],
62
70
  cb = args[1];
63
71
 
64
- try {
65
- _assertAndSanitizeOptions(opts);
66
- } catch (err) {
67
- return cb(err);
68
- }
72
+ _assertAndSanitizeOptions(opts, function (err, sanitizedOptions) {
73
+ if (err) return cb(err);
69
74
 
70
- let tries = opts.tries;
71
- (function _getUniqueName() {
72
- try {
73
- const name = _generateTmpName(opts);
75
+ let tries = sanitizedOptions.tries;
76
+ (function _getUniqueName() {
77
+ try {
78
+ const name = _generateTmpName(sanitizedOptions);
74
79
 
75
- // check whether the path exists then retry if needed
76
- fs.stat(name, function (err) {
77
- /* istanbul ignore else */
78
- if (!err) {
80
+ // check whether the path exists then retry if needed
81
+ fs.stat(name, function (err) {
79
82
  /* istanbul ignore else */
80
- if (tries-- > 0) return _getUniqueName();
83
+ if (!err) {
84
+ /* istanbul ignore else */
85
+ if (tries-- > 0) return _getUniqueName();
81
86
 
82
- return cb(new Error('Could not get a unique tmp filename, max tries reached ' + name));
83
- }
87
+ return cb(new Error('Could not get a unique tmp filename, max tries reached ' + name));
88
+ }
84
89
 
85
- cb(null, name);
86
- });
87
- } catch (err) {
88
- cb(err);
89
- }
90
- }());
90
+ cb(null, name);
91
+ });
92
+ } catch (err) {
93
+ cb(err);
94
+ }
95
+ })();
96
+ });
91
97
  }
92
98
 
93
99
  /**
@@ -98,15 +104,14 @@ function tmpName(options, callback) {
98
104
  * @throws {Error} if the options are invalid or could not generate a filename
99
105
  */
100
106
  function tmpNameSync(options) {
101
- const
102
- args = _parseArguments(options),
107
+ const args = _parseArguments(options),
103
108
  opts = args[0];
104
109
 
105
- _assertAndSanitizeOptions(opts);
110
+ const sanitizedOptions = _assertAndSanitizeOptionsSync(opts);
106
111
 
107
- let tries = opts.tries;
112
+ let tries = sanitizedOptions.tries;
108
113
  do {
109
- const name = _generateTmpName(opts);
114
+ const name = _generateTmpName(sanitizedOptions);
110
115
  try {
111
116
  fs.statSync(name);
112
117
  } catch (e) {
@@ -124,8 +129,7 @@ function tmpNameSync(options) {
124
129
  * @param {?fileCallback} callback
125
130
  */
126
131
  function file(options, callback) {
127
- const
128
- args = _parseArguments(options, callback),
132
+ const args = _parseArguments(options, callback),
129
133
  opts = args[0],
130
134
  cb = args[1];
131
135
 
@@ -162,13 +166,12 @@ function file(options, callback) {
162
166
  * @throws {Error} if cannot create a file
163
167
  */
164
168
  function fileSync(options) {
165
- const
166
- args = _parseArguments(options),
169
+ const args = _parseArguments(options),
167
170
  opts = args[0];
168
171
 
169
172
  const discardOrDetachDescriptor = opts.discardDescriptor || opts.detachDescriptor;
170
173
  const name = tmpNameSync(opts);
171
- var fd = fs.openSync(name, CREATE_FLAGS, opts.mode || FILE_MODE);
174
+ let fd = fs.openSync(name, CREATE_FLAGS, opts.mode || FILE_MODE);
172
175
  /* istanbul ignore else */
173
176
  if (opts.discardDescriptor) {
174
177
  fs.closeSync(fd);
@@ -189,8 +192,7 @@ function fileSync(options) {
189
192
  * @param {?dirCallback} callback
190
193
  */
191
194
  function dir(options, callback) {
192
- const
193
- args = _parseArguments(options, callback),
195
+ const args = _parseArguments(options, callback),
194
196
  opts = args[0],
195
197
  cb = args[1];
196
198
 
@@ -217,8 +219,7 @@ function dir(options, callback) {
217
219
  * @throws {Error} if it cannot create a directory
218
220
  */
219
221
  function dirSync(options) {
220
- const
221
- args = _parseArguments(options),
222
+ const args = _parseArguments(options),
222
223
  opts = args[0];
223
224
 
224
225
  const name = tmpNameSync(opts);
@@ -269,8 +270,7 @@ function _removeFileSync(fdPath) {
269
270
  } finally {
270
271
  try {
271
272
  fs.unlinkSync(fdPath[1]);
272
- }
273
- catch (e) {
273
+ } catch (e) {
274
274
  // reraise any unanticipated error
275
275
  if (!_isENOENT(e)) rethrownException = e;
276
276
  }
@@ -342,7 +342,6 @@ function _prepareRemoveCallback(removeFunction, fileOrDirName, sync, cleanupCall
342
342
 
343
343
  // if sync is true, the next parameter will be ignored
344
344
  return function _cleanupCallback(next) {
345
-
346
345
  /* istanbul ignore else */
347
346
  if (!called) {
348
347
  // remove cleanupCallback from cache
@@ -355,7 +354,7 @@ function _prepareRemoveCallback(removeFunction, fileOrDirName, sync, cleanupCall
355
354
  if (sync || removeFunction === FN_RMDIR_SYNC || removeFunction === FN_RIMRAF_SYNC) {
356
355
  return removeFunction(fileOrDirName);
357
356
  } else {
358
- return removeFunction(fileOrDirName, next || function() {});
357
+ return removeFunction(fileOrDirName, next || function () {});
359
358
  }
360
359
  }
361
360
  };
@@ -390,8 +389,7 @@ function _garbageCollector() {
390
389
  * @private
391
390
  */
392
391
  function _randomChars(howMany) {
393
- let
394
- value = [],
392
+ let value = [],
395
393
  rnd = null;
396
394
 
397
395
  // make sure that we do not fail because we ran out of entropy
@@ -401,24 +399,13 @@ function _randomChars(howMany) {
401
399
  rnd = crypto.pseudoRandomBytes(howMany);
402
400
  }
403
401
 
404
- for (var i = 0; i < howMany; i++) {
402
+ for (let i = 0; i < howMany; i++) {
405
403
  value.push(RANDOM_CHARS[rnd[i] % RANDOM_CHARS.length]);
406
404
  }
407
405
 
408
406
  return value.join('');
409
407
  }
410
408
 
411
- /**
412
- * Helper which determines whether a string s is blank, that is undefined, or empty or null.
413
- *
414
- * @private
415
- * @param {string} s
416
- * @returns {Boolean} true whether the string s is blank, false otherwise
417
- */
418
- function _isBlank(s) {
419
- return s === null || _isUndefined(s) || !s.trim();
420
- }
421
-
422
409
  /**
423
410
  * Checks whether the `obj` parameter is defined or not.
424
411
  *
@@ -460,6 +447,51 @@ function _parseArguments(options, callback) {
460
447
  return [actualOptions, callback];
461
448
  }
462
449
 
450
+ /**
451
+ * Resolve the specified path name in respect to tmpDir.
452
+ *
453
+ * The specified name might include relative path components, e.g. ../
454
+ * so we need to resolve in order to be sure that is is located inside tmpDir
455
+ *
456
+ * @private
457
+ */
458
+ function _resolvePath(name, tmpDir, cb) {
459
+ const pathToResolve = path.isAbsolute(name) ? name : path.join(tmpDir, name);
460
+
461
+ fs.stat(pathToResolve, function (err) {
462
+ if (err) {
463
+ fs.realpath(path.dirname(pathToResolve), function (err, parentDir) {
464
+ if (err) return cb(err);
465
+
466
+ cb(null, path.join(parentDir, path.basename(pathToResolve)));
467
+ });
468
+ } else {
469
+ fs.realpath(path, cb);
470
+ }
471
+ });
472
+ }
473
+
474
+ /**
475
+ * Resolve the specified path name in respect to tmpDir.
476
+ *
477
+ * The specified name might include relative path components, e.g. ../
478
+ * so we need to resolve in order to be sure that is is located inside tmpDir
479
+ *
480
+ * @private
481
+ */
482
+ function _resolvePathSync(name, tmpDir) {
483
+ const pathToResolve = path.isAbsolute(name) ? name : path.join(tmpDir, name);
484
+
485
+ try {
486
+ fs.statSync(pathToResolve);
487
+ return fs.realpathSync(pathToResolve);
488
+ } catch (_err) {
489
+ const parentDir = fs.realpathSync(path.dirname(pathToResolve));
490
+
491
+ return path.join(parentDir, path.basename(pathToResolve));
492
+ }
493
+ }
494
+
463
495
  /**
464
496
  * Generates a new temporary name.
465
497
  *
@@ -468,16 +500,17 @@ function _parseArguments(options, callback) {
468
500
  * @private
469
501
  */
470
502
  function _generateTmpName(opts) {
471
-
472
503
  const tmpDir = opts.tmpdir;
473
504
 
474
505
  /* istanbul ignore else */
475
- if (!_isUndefined(opts.name))
506
+ if (!_isUndefined(opts.name)) {
476
507
  return path.join(tmpDir, opts.dir, opts.name);
508
+ }
477
509
 
478
510
  /* istanbul ignore else */
479
- if (!_isUndefined(opts.template))
511
+ if (!_isUndefined(opts.template)) {
480
512
  return path.join(tmpDir, opts.dir, opts.template).replace(TEMPLATE_PATTERN, _randomChars(6));
513
+ }
481
514
 
482
515
  // prefix and postfix
483
516
  const name = [
@@ -493,33 +526,32 @@ function _generateTmpName(opts) {
493
526
  }
494
527
 
495
528
  /**
496
- * Asserts whether the specified options are valid, also sanitizes options and provides sane defaults for missing
497
- * options.
529
+ * Asserts and sanitizes the basic options.
498
530
  *
499
- * @param {Options} options
500
531
  * @private
501
532
  */
502
- function _assertAndSanitizeOptions(options) {
533
+ function _assertOptionsBase(options) {
534
+ if (!_isUndefined(options.name)) {
535
+ const name = options.name;
503
536
 
504
- options.tmpdir = _getTmpDir(options);
537
+ // assert that name is not absolute and does not contain a path
538
+ if (path.isAbsolute(name)) throw new Error(`name option must not contain an absolute path, found "${name}".`);
505
539
 
506
- const tmpDir = options.tmpdir;
540
+ // must not fail on valid .<name> or ..<name> or similar such constructs
541
+ const basename = path.basename(name);
542
+ if (basename === '..' || basename === '.' || basename !== name)
543
+ throw new Error(`name option must not contain a path, found "${name}".`);
544
+ }
507
545
 
508
546
  /* istanbul ignore else */
509
- if (!_isUndefined(options.name))
510
- _assertIsRelative(options.name, 'name', tmpDir);
511
- /* istanbul ignore else */
512
- if (!_isUndefined(options.dir))
513
- _assertIsRelative(options.dir, 'dir', tmpDir);
514
- /* istanbul ignore else */
515
- if (!_isUndefined(options.template)) {
516
- _assertIsRelative(options.template, 'template', tmpDir);
517
- if (!options.template.match(TEMPLATE_PATTERN))
518
- throw new Error(`Invalid template, found "${options.template}".`);
547
+ if (!_isUndefined(options.template) && !options.template.match(TEMPLATE_PATTERN)) {
548
+ throw new Error(`Invalid template, found "${options.template}".`);
519
549
  }
550
+
520
551
  /* istanbul ignore else */
521
- if (!_isUndefined(options.tries) && isNaN(options.tries) || options.tries < 0)
552
+ if ((!_isUndefined(options.tries) && isNaN(options.tries)) || options.tries < 0) {
522
553
  throw new Error(`Invalid tries, found "${options.tries}".`);
554
+ }
523
555
 
524
556
  // if a name was specified we will try once
525
557
  options.tries = _isUndefined(options.name) ? options.tries || DEFAULT_TRIES : 1;
@@ -528,80 +560,103 @@ function _assertAndSanitizeOptions(options) {
528
560
  options.discardDescriptor = !!options.discardDescriptor;
529
561
  options.unsafeCleanup = !!options.unsafeCleanup;
530
562
 
531
- // sanitize dir, also keep (multiple) blanks if the user, purportedly sane, requests us to
532
- options.dir = _isUndefined(options.dir) ? '' : path.relative(tmpDir, _resolvePath(options.dir, tmpDir));
533
- options.template = _isUndefined(options.template) ? undefined : path.relative(tmpDir, _resolvePath(options.template, tmpDir));
534
- // sanitize further if template is relative to options.dir
535
- options.template = _isBlank(options.template) ? undefined : path.relative(options.dir, options.template);
536
-
537
563
  // for completeness' sake only, also keep (multiple) blanks if the user, purportedly sane, requests us to
538
- options.name = _isUndefined(options.name) ? undefined : _sanitizeName(options.name);
539
564
  options.prefix = _isUndefined(options.prefix) ? '' : options.prefix;
540
565
  options.postfix = _isUndefined(options.postfix) ? '' : options.postfix;
541
566
  }
542
567
 
543
568
  /**
544
- * Resolve the specified path name in respect to tmpDir.
569
+ * Gets the relative directory to tmpDir.
545
570
  *
546
- * The specified name might include relative path components, e.g. ../
547
- * so we need to resolve in order to be sure that is is located inside tmpDir
548
- *
549
- * @param name
550
- * @param tmpDir
551
- * @returns {string}
552
571
  * @private
553
572
  */
554
- function _resolvePath(name, tmpDir) {
555
- const sanitizedName = _sanitizeName(name);
556
- if (sanitizedName.startsWith(tmpDir)) {
557
- return path.resolve(sanitizedName);
558
- } else {
559
- return path.resolve(path.join(tmpDir, sanitizedName));
560
- }
573
+ function _getRelativePath(option, name, tmpDir, cb) {
574
+ if (_isUndefined(name)) return cb(null);
575
+
576
+ _resolvePath(name, tmpDir, function (err, resolvedPath) {
577
+ if (err) return cb(err);
578
+
579
+ const relativePath = path.relative(tmpDir, resolvedPath);
580
+
581
+ if (!resolvedPath.startsWith(tmpDir)) {
582
+ return cb(new Error(`${option} option must be relative to "${tmpDir}", found "${relativePath}".`));
583
+ }
584
+
585
+ cb(null, relativePath);
586
+ });
561
587
  }
562
588
 
563
589
  /**
564
- * Sanitize the specified path name by removing all quote characters.
590
+ * Gets the relative path to tmpDir.
565
591
  *
566
- * @param name
567
- * @returns {string}
568
592
  * @private
569
593
  */
570
- function _sanitizeName(name) {
571
- if (_isBlank(name)) {
572
- return name;
594
+ function _getRelativePathSync(option, name, tmpDir) {
595
+ if (_isUndefined(name)) return;
596
+
597
+ const resolvedPath = _resolvePathSync(name, tmpDir);
598
+ const relativePath = path.relative(tmpDir, resolvedPath);
599
+
600
+ if (!resolvedPath.startsWith(tmpDir)) {
601
+ throw new Error(`${option} option must be relative to "${tmpDir}", found "${relativePath}".`);
573
602
  }
574
- return name.replace(/["']/g, '');
603
+
604
+ return relativePath;
575
605
  }
576
606
 
577
607
  /**
578
- * Asserts whether specified name is relative to the specified tmpDir.
608
+ * Asserts whether the specified options are valid, also sanitizes options and provides sane defaults for missing
609
+ * options.
579
610
  *
580
- * @param {string} name
581
- * @param {string} option
582
- * @param {string} tmpDir
583
- * @throws {Error}
584
611
  * @private
585
612
  */
586
- function _assertIsRelative(name, option, tmpDir) {
587
- if (option === 'name') {
588
- // assert that name is not absolute and does not contain a path
589
- if (path.isAbsolute(name))
590
- throw new Error(`${option} option must not contain an absolute path, found "${name}".`);
591
- // must not fail on valid .<name> or ..<name> or similar such constructs
592
- let basename = path.basename(name);
593
- if (basename === '..' || basename === '.' || basename !== name)
594
- throw new Error(`${option} option must not contain a path, found "${name}".`);
595
- }
596
- else { // if (option === 'dir' || option === 'template') {
597
- // assert that dir or template are relative to tmpDir
598
- if (path.isAbsolute(name) && !name.startsWith(tmpDir)) {
599
- throw new Error(`${option} option must be relative to "${tmpDir}", found "${name}".`);
613
+ function _assertAndSanitizeOptions(options, cb) {
614
+ _getTmpDir(options, function (err, tmpDir) {
615
+ if (err) return cb(err);
616
+
617
+ options.tmpdir = tmpDir;
618
+
619
+ try {
620
+ _assertOptionsBase(options, tmpDir);
621
+ } catch (err) {
622
+ return cb(err);
600
623
  }
601
- let resolvedPath = _resolvePath(name, tmpDir);
602
- if (!resolvedPath.startsWith(tmpDir))
603
- throw new Error(`${option} option must be relative to "${tmpDir}", found "${resolvedPath}".`);
604
- }
624
+
625
+ // sanitize dir, also keep (multiple) blanks if the user, purportedly sane, requests us to
626
+ _getRelativePath('dir', options.dir, tmpDir, function (err, dir) {
627
+ if (err) return cb(err);
628
+
629
+ options.dir = _isUndefined(dir) ? '' : dir;
630
+
631
+ // sanitize further if template is relative to options.dir
632
+ _getRelativePath('template', options.template, tmpDir, function (err, template) {
633
+ if (err) return cb(err);
634
+
635
+ options.template = template;
636
+
637
+ cb(null, options);
638
+ });
639
+ });
640
+ });
641
+ }
642
+
643
+ /**
644
+ * Asserts whether the specified options are valid, also sanitizes options and provides sane defaults for missing
645
+ * options.
646
+ *
647
+ * @private
648
+ */
649
+ function _assertAndSanitizeOptionsSync(options) {
650
+ const tmpDir = (options.tmpdir = _getTmpDirSync(options));
651
+
652
+ _assertOptionsBase(options, tmpDir);
653
+
654
+ const dir = _getRelativePathSync('dir', options.dir, tmpDir);
655
+ options.dir = _isUndefined(dir) ? '' : dir;
656
+
657
+ options.template = _getRelativePathSync('template', options.template, tmpDir);
658
+
659
+ return options;
605
660
  }
606
661
 
607
662
  /**
@@ -659,11 +714,18 @@ function setGracefulCleanup() {
659
714
  * Returns the currently configured tmp dir from os.tmpdir().
660
715
  *
661
716
  * @private
662
- * @param {?Options} options
663
- * @returns {string} the currently configured tmp dir
664
717
  */
665
- function _getTmpDir(options) {
666
- return path.resolve(_sanitizeName(options && options.tmpdir || os.tmpdir()));
718
+ function _getTmpDir(options, cb) {
719
+ return fs.realpath((options && options.tmpdir) || os.tmpdir(), cb);
720
+ }
721
+
722
+ /**
723
+ * Returns the currently configured tmp dir from os.tmpdir().
724
+ *
725
+ * @private
726
+ */
727
+ function _getTmpDirSync(options) {
728
+ return fs.realpathSync((options && options.tmpdir) || os.tmpdir());
667
729
  }
668
730
 
669
731
  // Install process exit listener
@@ -764,7 +826,7 @@ Object.defineProperty(module.exports, 'tmpdir', {
764
826
  enumerable: true,
765
827
  configurable: false,
766
828
  get: function () {
767
- return _getTmpDir();
829
+ return _getTmpDirSync();
768
830
  }
769
831
  });
770
832
 
@@ -1,58 +1,94 @@
1
1
  {
2
- "name": "tmp",
3
- "version": "0.2.1",
4
- "description": "Temporary file and directory creator",
5
- "author": "KARASZI István <github@spam.raszi.hu> (http://raszi.hu/)",
6
- "contributors": [
7
- "Carsten Klein <trancesilken@gmail.com> (https://github.com/silkentrance)"
2
+ "_args": [
3
+ [
4
+ "tmp@0.2.4",
5
+ "/Users/fenster/dev/protobuf.js/cli"
6
+ ]
8
7
  ],
9
- "keywords": [
10
- "temporary",
11
- "tmp",
12
- "temp",
13
- "tempdir",
14
- "tempfile",
15
- "tmpdir",
16
- "tmpfile"
8
+ "_from": "tmp@0.2.4",
9
+ "_id": "tmp@0.2.4",
10
+ "_inBundle": false,
11
+ "_integrity": "sha512-UdiSoX6ypifLmrfQ/XfiawN6hkjSBpCjhKxxZcWlUUmoXLaCKQU0bx4HF/tdDK2uzRuchf1txGvrWBzYREssoQ==",
12
+ "_location": "/tmp",
13
+ "_phantomChildren": {},
14
+ "_requested": {
15
+ "type": "version",
16
+ "registry": true,
17
+ "raw": "tmp@0.2.4",
18
+ "name": "tmp",
19
+ "escapedName": "tmp",
20
+ "rawSpec": "0.2.4",
21
+ "saveSpec": null,
22
+ "fetchSpec": "0.2.4"
23
+ },
24
+ "_requiredBy": [
25
+ "/"
17
26
  ],
18
- "license": "MIT",
19
- "repository": "https://github.com/raszi/node-tmp.git",
20
- "homepage": "http://github.com/raszi/node-tmp",
27
+ "_resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.4.tgz",
28
+ "_spec": "0.2.4",
29
+ "_where": "/Users/fenster/dev/protobuf.js/cli",
30
+ "author": {
31
+ "name": "KARASZI István",
32
+ "email": "github@spam.raszi.hu"
33
+ },
21
34
  "bugs": {
22
35
  "url": "http://github.com/raszi/node-tmp/issues"
23
36
  },
24
- "engines": {
25
- "node": ">=8.17.0"
26
- },
27
- "dependencies": {
28
- "rimraf": "^3.0.0"
37
+ "changelog": {
38
+ "labels": {
39
+ "breaking": ":boom: Breaking Change",
40
+ "enhancement": ":rocket: Enhancement",
41
+ "bug": ":bug: Bug Fix",
42
+ "documentation": ":memo: Documentation",
43
+ "internal": ":house: Internal"
44
+ },
45
+ "cacheDir": ".changelog"
29
46
  },
47
+ "contributors": [
48
+ {
49
+ "name": "Carsten Klein",
50
+ "email": "trancesilken@gmail.com",
51
+ "url": "https://github.com/silkentrance"
52
+ }
53
+ ],
54
+ "dependencies": {},
55
+ "description": "Temporary file and directory creator",
30
56
  "devDependencies": {
31
57
  "eslint": "^6.3.0",
32
58
  "eslint-plugin-mocha": "^6.1.1",
33
59
  "istanbul": "^0.4.5",
34
60
  "lerna-changelog": "^1.0.1",
35
- "mocha": "^6.2.0"
61
+ "mocha": "^10.2.0"
62
+ },
63
+ "engines": {
64
+ "node": ">=14.14"
36
65
  },
37
- "main": "lib/tmp.js",
38
66
  "files": [
39
67
  "lib/"
40
68
  ],
41
- "changelog": {
42
- "labels": {
43
- "breaking": ":boom: Breaking Change",
44
- "enhancement": ":rocket: Enhancement",
45
- "bug": ":bug: Bug Fix",
46
- "documentation": ":memo: Documentation",
47
- "internal": ":house: Internal"
48
- },
49
- "cacheDir": ".changelog"
69
+ "homepage": "http://github.com/raszi/node-tmp",
70
+ "keywords": [
71
+ "temporary",
72
+ "tmp",
73
+ "temp",
74
+ "tempdir",
75
+ "tempfile",
76
+ "tmpdir",
77
+ "tmpfile"
78
+ ],
79
+ "license": "MIT",
80
+ "main": "lib/tmp.js",
81
+ "name": "tmp",
82
+ "repository": {
83
+ "type": "git",
84
+ "url": "git+https://github.com/raszi/node-tmp.git"
50
85
  },
51
86
  "scripts": {
52
87
  "changelog": "lerna-changelog",
53
- "lint": "eslint lib --env mocha test",
54
88
  "clean": "rm -Rf ./coverage",
55
- "test": "npm run clean && istanbul cover ./node_modules/mocha/bin/_mocha --report none --print none --dir ./coverage/json -u exports -R test/*-test.js && istanbul report --root ./coverage/json html && istanbul report text-summary",
56
- "doc": "jsdoc -c .jsdoc.json"
57
- }
89
+ "doc": "jsdoc -c .jsdoc.json",
90
+ "lint": "eslint lib --env mocha test",
91
+ "test": "npm run clean && istanbul cover ./node_modules/mocha/bin/_mocha --report none --print none --dir ./coverage/json -u exports -R test/*-test.js && istanbul report --root ./coverage/json html && istanbul report text-summary"
92
+ },
93
+ "version": "0.2.4"
58
94
  }