ProxiedFS.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.ProxiedFS = void 0;
  4. const FakeFS_1 = require("./FakeFS");
  5. class ProxiedFS extends FakeFS_1.FakeFS {
  6. getExtractHint(hints) {
  7. return this.baseFs.getExtractHint(hints);
  8. }
  9. resolve(path) {
  10. return this.mapFromBase(this.baseFs.resolve(this.mapToBase(path)));
  11. }
  12. getRealPath() {
  13. return this.mapFromBase(this.baseFs.getRealPath());
  14. }
  15. async openPromise(p, flags, mode) {
  16. return this.baseFs.openPromise(this.mapToBase(p), flags, mode);
  17. }
  18. openSync(p, flags, mode) {
  19. return this.baseFs.openSync(this.mapToBase(p), flags, mode);
  20. }
  21. async opendirPromise(p, opts) {
  22. return Object.assign(await this.baseFs.opendirPromise(this.mapToBase(p), opts), { path: p });
  23. }
  24. opendirSync(p, opts) {
  25. return Object.assign(this.baseFs.opendirSync(this.mapToBase(p), opts), { path: p });
  26. }
  27. async readPromise(fd, buffer, offset, length, position) {
  28. return await this.baseFs.readPromise(fd, buffer, offset, length, position);
  29. }
  30. readSync(fd, buffer, offset, length, position) {
  31. return this.baseFs.readSync(fd, buffer, offset, length, position);
  32. }
  33. async writePromise(fd, buffer, offset, length, position) {
  34. if (typeof buffer === `string`) {
  35. return await this.baseFs.writePromise(fd, buffer, offset);
  36. }
  37. else {
  38. return await this.baseFs.writePromise(fd, buffer, offset, length, position);
  39. }
  40. }
  41. writeSync(fd, buffer, offset, length, position) {
  42. if (typeof buffer === `string`) {
  43. return this.baseFs.writeSync(fd, buffer, offset);
  44. }
  45. else {
  46. return this.baseFs.writeSync(fd, buffer, offset, length, position);
  47. }
  48. }
  49. async closePromise(fd) {
  50. return this.baseFs.closePromise(fd);
  51. }
  52. closeSync(fd) {
  53. this.baseFs.closeSync(fd);
  54. }
  55. createReadStream(p, opts) {
  56. return this.baseFs.createReadStream(p !== null ? this.mapToBase(p) : p, opts);
  57. }
  58. createWriteStream(p, opts) {
  59. return this.baseFs.createWriteStream(p !== null ? this.mapToBase(p) : p, opts);
  60. }
  61. async realpathPromise(p) {
  62. return this.mapFromBase(await this.baseFs.realpathPromise(this.mapToBase(p)));
  63. }
  64. realpathSync(p) {
  65. return this.mapFromBase(this.baseFs.realpathSync(this.mapToBase(p)));
  66. }
  67. async existsPromise(p) {
  68. return this.baseFs.existsPromise(this.mapToBase(p));
  69. }
  70. existsSync(p) {
  71. return this.baseFs.existsSync(this.mapToBase(p));
  72. }
  73. accessSync(p, mode) {
  74. return this.baseFs.accessSync(this.mapToBase(p), mode);
  75. }
  76. async accessPromise(p, mode) {
  77. return this.baseFs.accessPromise(this.mapToBase(p), mode);
  78. }
  79. async statPromise(p, opts) {
  80. return this.baseFs.statPromise(this.mapToBase(p), opts);
  81. }
  82. statSync(p, opts) {
  83. return this.baseFs.statSync(this.mapToBase(p), opts);
  84. }
  85. async fstatPromise(fd, opts) {
  86. return this.baseFs.fstatPromise(fd, opts);
  87. }
  88. fstatSync(fd, opts) {
  89. return this.baseFs.fstatSync(fd, opts);
  90. }
  91. lstatPromise(p, opts) {
  92. return this.baseFs.lstatPromise(this.mapToBase(p), opts);
  93. }
  94. lstatSync(p, opts) {
  95. return this.baseFs.lstatSync(this.mapToBase(p), opts);
  96. }
  97. async fchmodPromise(fd, mask) {
  98. return this.baseFs.fchmodPromise(fd, mask);
  99. }
  100. fchmodSync(fd, mask) {
  101. return this.baseFs.fchmodSync(fd, mask);
  102. }
  103. async chmodPromise(p, mask) {
  104. return this.baseFs.chmodPromise(this.mapToBase(p), mask);
  105. }
  106. chmodSync(p, mask) {
  107. return this.baseFs.chmodSync(this.mapToBase(p), mask);
  108. }
  109. async fchownPromise(fd, uid, gid) {
  110. return this.baseFs.fchownPromise(fd, uid, gid);
  111. }
  112. fchownSync(fd, uid, gid) {
  113. return this.baseFs.fchownSync(fd, uid, gid);
  114. }
  115. async chownPromise(p, uid, gid) {
  116. return this.baseFs.chownPromise(this.mapToBase(p), uid, gid);
  117. }
  118. chownSync(p, uid, gid) {
  119. return this.baseFs.chownSync(this.mapToBase(p), uid, gid);
  120. }
  121. async renamePromise(oldP, newP) {
  122. return this.baseFs.renamePromise(this.mapToBase(oldP), this.mapToBase(newP));
  123. }
  124. renameSync(oldP, newP) {
  125. return this.baseFs.renameSync(this.mapToBase(oldP), this.mapToBase(newP));
  126. }
  127. async copyFilePromise(sourceP, destP, flags = 0) {
  128. return this.baseFs.copyFilePromise(this.mapToBase(sourceP), this.mapToBase(destP), flags);
  129. }
  130. copyFileSync(sourceP, destP, flags = 0) {
  131. return this.baseFs.copyFileSync(this.mapToBase(sourceP), this.mapToBase(destP), flags);
  132. }
  133. async appendFilePromise(p, content, opts) {
  134. return this.baseFs.appendFilePromise(this.fsMapToBase(p), content, opts);
  135. }
  136. appendFileSync(p, content, opts) {
  137. return this.baseFs.appendFileSync(this.fsMapToBase(p), content, opts);
  138. }
  139. async writeFilePromise(p, content, opts) {
  140. return this.baseFs.writeFilePromise(this.fsMapToBase(p), content, opts);
  141. }
  142. writeFileSync(p, content, opts) {
  143. return this.baseFs.writeFileSync(this.fsMapToBase(p), content, opts);
  144. }
  145. async unlinkPromise(p) {
  146. return this.baseFs.unlinkPromise(this.mapToBase(p));
  147. }
  148. unlinkSync(p) {
  149. return this.baseFs.unlinkSync(this.mapToBase(p));
  150. }
  151. async utimesPromise(p, atime, mtime) {
  152. return this.baseFs.utimesPromise(this.mapToBase(p), atime, mtime);
  153. }
  154. utimesSync(p, atime, mtime) {
  155. return this.baseFs.utimesSync(this.mapToBase(p), atime, mtime);
  156. }
  157. async mkdirPromise(p, opts) {
  158. return this.baseFs.mkdirPromise(this.mapToBase(p), opts);
  159. }
  160. mkdirSync(p, opts) {
  161. return this.baseFs.mkdirSync(this.mapToBase(p), opts);
  162. }
  163. async rmdirPromise(p, opts) {
  164. return this.baseFs.rmdirPromise(this.mapToBase(p), opts);
  165. }
  166. rmdirSync(p, opts) {
  167. return this.baseFs.rmdirSync(this.mapToBase(p), opts);
  168. }
  169. async linkPromise(existingP, newP) {
  170. return this.baseFs.linkPromise(this.mapToBase(existingP), this.mapToBase(newP));
  171. }
  172. linkSync(existingP, newP) {
  173. return this.baseFs.linkSync(this.mapToBase(existingP), this.mapToBase(newP));
  174. }
  175. async symlinkPromise(target, p, type) {
  176. const mappedP = this.mapToBase(p);
  177. if (this.pathUtils.isAbsolute(target))
  178. return this.baseFs.symlinkPromise(this.mapToBase(target), mappedP, type);
  179. const mappedAbsoluteTarget = this.mapToBase(this.pathUtils.join(this.pathUtils.dirname(p), target));
  180. const mappedTarget = this.baseFs.pathUtils.relative(this.baseFs.pathUtils.dirname(mappedP), mappedAbsoluteTarget);
  181. return this.baseFs.symlinkPromise(mappedTarget, mappedP, type);
  182. }
  183. symlinkSync(target, p, type) {
  184. const mappedP = this.mapToBase(p);
  185. if (this.pathUtils.isAbsolute(target))
  186. return this.baseFs.symlinkSync(this.mapToBase(target), mappedP, type);
  187. const mappedAbsoluteTarget = this.mapToBase(this.pathUtils.join(this.pathUtils.dirname(p), target));
  188. const mappedTarget = this.baseFs.pathUtils.relative(this.baseFs.pathUtils.dirname(mappedP), mappedAbsoluteTarget);
  189. return this.baseFs.symlinkSync(mappedTarget, mappedP, type);
  190. }
  191. async readFilePromise(p, encoding) {
  192. // This weird condition is required to tell TypeScript that the signatures are proper (otherwise it thinks that only the generic one is covered)
  193. if (encoding === `utf8`) {
  194. return this.baseFs.readFilePromise(this.fsMapToBase(p), encoding);
  195. }
  196. else {
  197. return this.baseFs.readFilePromise(this.fsMapToBase(p), encoding);
  198. }
  199. }
  200. readFileSync(p, encoding) {
  201. // This weird condition is required to tell TypeScript that the signatures are proper (otherwise it thinks that only the generic one is covered)
  202. if (encoding === `utf8`) {
  203. return this.baseFs.readFileSync(this.fsMapToBase(p), encoding);
  204. }
  205. else {
  206. return this.baseFs.readFileSync(this.fsMapToBase(p), encoding);
  207. }
  208. }
  209. async readdirPromise(p, opts) {
  210. return this.baseFs.readdirPromise(this.mapToBase(p), opts);
  211. }
  212. readdirSync(p, opts) {
  213. return this.baseFs.readdirSync(this.mapToBase(p), opts);
  214. }
  215. async readlinkPromise(p) {
  216. return this.mapFromBase(await this.baseFs.readlinkPromise(this.mapToBase(p)));
  217. }
  218. readlinkSync(p) {
  219. return this.mapFromBase(this.baseFs.readlinkSync(this.mapToBase(p)));
  220. }
  221. async truncatePromise(p, len) {
  222. return this.baseFs.truncatePromise(this.mapToBase(p), len);
  223. }
  224. truncateSync(p, len) {
  225. return this.baseFs.truncateSync(this.mapToBase(p), len);
  226. }
  227. async ftruncatePromise(fd, len) {
  228. return this.baseFs.ftruncatePromise(fd, len);
  229. }
  230. ftruncateSync(fd, len) {
  231. return this.baseFs.ftruncateSync(fd, len);
  232. }
  233. watch(p, a, b) {
  234. return this.baseFs.watch(this.mapToBase(p),
  235. // @ts-expect-error
  236. a, b);
  237. }
  238. watchFile(p, a, b) {
  239. return this.baseFs.watchFile(this.mapToBase(p),
  240. // @ts-expect-error
  241. a, b);
  242. }
  243. unwatchFile(p, cb) {
  244. return this.baseFs.unwatchFile(this.mapToBase(p), cb);
  245. }
  246. fsMapToBase(p) {
  247. if (typeof p === `number`) {
  248. return p;
  249. }
  250. else {
  251. return this.mapToBase(p);
  252. }
  253. }
  254. }
  255. exports.ProxiedFS = ProxiedFS;