FsHelper.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. var __importStar = (this && this.__importStar) || function (mod) {
  3. if (mod && mod.__esModule) return mod;
  4. var result = {};
  5. if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  6. result["default"] = mod;
  7. return result;
  8. };
  9. Object.defineProperty(exports, "__esModule", { value: true });
  10. var fs = __importStar(require("fs"));
  11. function fileExistsSync(filePath) {
  12. try {
  13. fs.statSync(filePath);
  14. }
  15. catch (err) {
  16. if (err.code === 'ENOENT') {
  17. return false;
  18. }
  19. else {
  20. throw err;
  21. }
  22. }
  23. return true;
  24. }
  25. exports.fileExistsSync = fileExistsSync;
  26. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  27. function throwIfIsInvalidSourceFileError(filepath, error) {
  28. if (fileExistsSync(filepath) &&
  29. // check the error type due to file system lag
  30. !(error instanceof Error) &&
  31. !(error.constructor.name === 'FatalError') &&
  32. !(error.message && error.message.trim().startsWith('Invalid source file'))) {
  33. // it's not because file doesn't exist - throw error
  34. throw error;
  35. }
  36. }
  37. exports.throwIfIsInvalidSourceFileError = throwIfIsInvalidSourceFileError;
  38. //# sourceMappingURL=FsHelper.js.map