From 794518a553abfa8c6e1332b7a89d1e050d59c729 Mon Sep 17 00:00:00 2001
From: Peter Evans <peter-evans@users.noreply.github.com>
Date: Sat, 18 Jul 2020 17:55:42 +0900
Subject: [PATCH] Move fileExistsSync to utils

---
 dist/index.js              | 94 +++++---------------------------------
 src/fs-helper.ts           | 77 -------------------------------
 src/git-command-manager.ts |  6 +--
 src/utils.ts               | 26 +++++++++++
 4 files changed, 39 insertions(+), 164 deletions(-)
 delete mode 100644 src/fs-helper.ts

diff --git a/dist/index.js b/dist/index.js
index 4fbb4e1..3139ee6 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -1818,7 +1818,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
 exports.GitCommandManager = void 0;
 const exec = __importStar(__webpack_require__(986));
 const io = __importStar(__webpack_require__(1));
-const fshelper = __importStar(__webpack_require__(618));
+const utils = __importStar(__webpack_require__(611));
 const path = __importStar(__webpack_require__(622));
 const tagsRefSpec = '+refs/tags/*:refs/tags/*';
 class GitCommandManager {
@@ -1911,7 +1911,7 @@ class GitCommandManager {
                 args.push('--no-tags');
             }
             args.push('--progress', '--no-recurse-submodules');
-            if (fshelper.fileExistsSync(path.join(this.workingDirectory, '.git', 'shallow'))) {
+            if (utils.fileExistsSync(path.join(this.workingDirectory, '.git', 'shallow'))) {
                 args.push('--unshallow');
             }
             if (options) {
@@ -6922,8 +6922,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
     return result;
 };
 Object.defineProperty(exports, "__esModule", { value: true });
-exports.parseDisplayNameEmail = exports.randomString = exports.secondsSinceEpoch = exports.getRemoteUrl = exports.getRemoteDetail = exports.getRepoPath = exports.getStringAsArray = exports.getInputAsArray = void 0;
+exports.fileExistsSync = exports.parseDisplayNameEmail = exports.randomString = exports.secondsSinceEpoch = exports.getRemoteUrl = exports.getRemoteDetail = exports.getRepoPath = exports.getStringAsArray = exports.getInputAsArray = void 0;
 const core = __importStar(__webpack_require__(470));
+const fs = __importStar(__webpack_require__(747));
 const path = __importStar(__webpack_require__(622));
 function getInputAsArray(name, options) {
     return getStringAsArray(core.getInput(name, options));
@@ -7008,86 +7009,6 @@ function parseDisplayNameEmail(displayNameEmail) {
     };
 }
 exports.parseDisplayNameEmail = parseDisplayNameEmail;
-
-
-/***/ }),
-
-/***/ 614:
-/***/ (function(module) {
-
-module.exports = require("events");
-
-/***/ }),
-
-/***/ 618:
-/***/ (function(__unusedmodule, exports, __webpack_require__) {
-
-"use strict";
-
-var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
-    if (k2 === undefined) k2 = k;
-    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
-}) : (function(o, m, k, k2) {
-    if (k2 === undefined) k2 = k;
-    o[k2] = m[k];
-}));
-var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
-    Object.defineProperty(o, "default", { enumerable: true, value: v });
-}) : function(o, v) {
-    o["default"] = v;
-});
-var __importStar = (this && this.__importStar) || function (mod) {
-    if (mod && mod.__esModule) return mod;
-    var result = {};
-    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
-    __setModuleDefault(result, mod);
-    return result;
-};
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.fileExistsSync = exports.existsSync = exports.directoryExistsSync = void 0;
-const fs = __importStar(__webpack_require__(747));
-function directoryExistsSync(path, required) {
-    if (!path) {
-        throw new Error("Arg 'path' must not be empty");
-    }
-    let stats;
-    try {
-        stats = fs.statSync(path);
-    }
-    catch (error) {
-        if (error.code === 'ENOENT') {
-            if (!required) {
-                return false;
-            }
-            throw new Error(`Directory '${path}' does not exist`);
-        }
-        throw new Error(`Encountered an error when checking whether path '${path}' exists: ${error.message}`);
-    }
-    if (stats.isDirectory()) {
-        return true;
-    }
-    else if (!required) {
-        return false;
-    }
-    throw new Error(`Directory '${path}' does not exist`);
-}
-exports.directoryExistsSync = directoryExistsSync;
-function existsSync(path) {
-    if (!path) {
-        throw new Error("Arg 'path' must not be empty");
-    }
-    try {
-        fs.statSync(path);
-    }
-    catch (error) {
-        if (error.code === 'ENOENT') {
-            return false;
-        }
-        throw new Error(`Encountered an error when checking whether path '${path}' exists: ${error.message}`);
-    }
-    return true;
-}
-exports.existsSync = existsSync;
 function fileExistsSync(path) {
     if (!path) {
         throw new Error("Arg 'path' must not be empty");
@@ -7110,6 +7031,13 @@ function fileExistsSync(path) {
 exports.fileExistsSync = fileExistsSync;
 
 
+/***/ }),
+
+/***/ 614:
+/***/ (function(module) {
+
+module.exports = require("events");
+
 /***/ }),
 
 /***/ 621:
diff --git a/src/fs-helper.ts b/src/fs-helper.ts
deleted file mode 100644
index c443404..0000000
--- a/src/fs-helper.ts
+++ /dev/null
@@ -1,77 +0,0 @@
-import * as fs from 'fs'
-
-export function directoryExistsSync(path: string, required?: boolean): boolean {
-  if (!path) {
-    throw new Error("Arg 'path' must not be empty")
-  }
-
-  let stats: fs.Stats
-  try {
-    stats = fs.statSync(path)
-  } catch (error) {
-    if (error.code === 'ENOENT') {
-      if (!required) {
-        return false
-      }
-
-      throw new Error(`Directory '${path}' does not exist`)
-    }
-
-    throw new Error(
-      `Encountered an error when checking whether path '${path}' exists: ${error.message}`
-    )
-  }
-
-  if (stats.isDirectory()) {
-    return true
-  } else if (!required) {
-    return false
-  }
-
-  throw new Error(`Directory '${path}' does not exist`)
-}
-
-export function existsSync(path: string): boolean {
-  if (!path) {
-    throw new Error("Arg 'path' must not be empty")
-  }
-
-  try {
-    fs.statSync(path)
-  } catch (error) {
-    if (error.code === 'ENOENT') {
-      return false
-    }
-
-    throw new Error(
-      `Encountered an error when checking whether path '${path}' exists: ${error.message}`
-    )
-  }
-
-  return true
-}
-
-export function fileExistsSync(path: string): boolean {
-  if (!path) {
-    throw new Error("Arg 'path' must not be empty")
-  }
-
-  let stats: fs.Stats
-  try {
-    stats = fs.statSync(path)
-  } catch (error) {
-    if (error.code === 'ENOENT') {
-      return false
-    }
-
-    throw new Error(
-      `Encountered an error when checking whether path '${path}' exists: ${error.message}`
-    )
-  }
-
-  if (!stats.isDirectory()) {
-    return true
-  }
-
-  return false
-}
diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts
index b699ad5..1c69d9c 100644
--- a/src/git-command-manager.ts
+++ b/src/git-command-manager.ts
@@ -1,6 +1,6 @@
 import * as exec from '@actions/exec'
 import * as io from '@actions/io'
-import * as fshelper from './fs-helper'
+import * as utils from './utils'
 import * as path from 'path'
 
 const tagsRefSpec = '+refs/tags/*:refs/tags/*'
@@ -117,9 +117,7 @@ export class GitCommandManager {
 
     args.push('--progress', '--no-recurse-submodules')
     if (
-      fshelper.fileExistsSync(
-        path.join(this.workingDirectory, '.git', 'shallow')
-      )
+      utils.fileExistsSync(path.join(this.workingDirectory, '.git', 'shallow'))
     ) {
       args.push('--unshallow')
     }
diff --git a/src/utils.ts b/src/utils.ts
index b8f5f32..8b1fde1 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -1,4 +1,5 @@
 import * as core from '@actions/core'
+import * as fs from 'fs'
 import * as path from 'path'
 
 export function getInputAsArray(
@@ -111,3 +112,28 @@ export function parseDisplayNameEmail(
     email: email
   }
 }
+
+export function fileExistsSync(path: string): boolean {
+  if (!path) {
+    throw new Error("Arg 'path' must not be empty")
+  }
+
+  let stats: fs.Stats
+  try {
+    stats = fs.statSync(path)
+  } catch (error) {
+    if (error.code === 'ENOENT') {
+      return false
+    }
+
+    throw new Error(
+      `Encountered an error when checking whether path '${path}' exists: ${error.message}`
+    )
+  }
+
+  if (!stats.isDirectory()) {
+    return true
+  }
+
+  return false
+}