Skip to content

Commit

Permalink
fix: do not use fs/promises for Node.js 12 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Oct 2, 2021
1 parent 73db492 commit c99a6a1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 7 additions & 3 deletions lib/resolveGitRepo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@

const normalize = require('normalize-path')
const debugLog = require('debug')('lint-staged:resolveGitRepo')
const fs = require('fs/promises')
const fs = require('fs')
const path = require('path')
const { promisify } = require('util')

const execGit = require('./execGit')

const fsLstat = promisify(fs.lstat)
const fsReadFile = promisify(fs.readFile)

/**
* Resolve path to the .git directory, with special handling for
* submodules and worktrees
*/
const resolveGitConfigDir = async (gitDir) => {
const defaultDir = normalize(path.join(gitDir, '.git'))
const stats = await fs.lstat(defaultDir)
const stats = await fsLstat(defaultDir)
// If .git is a directory, use it
if (stats.isDirectory()) return defaultDir
// Otherwise .git is a file containing path to real location
const file = (await fs.readFile(defaultDir)).toString()
const file = (await fsReadFile(defaultDir)).toString()
return path.resolve(gitDir, file.replace(/^gitdir: /, '')).trim()
}

Expand Down
7 changes: 5 additions & 2 deletions lib/unlink.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
'use strict'

const debug = require('debug')('lint-staged:file')
const fs = require('fs/promises')
const fs = require('fs')
const { promisify } = require('util')

const fsUnlink = promisify(fs.unlink)

/**
* Remove a file if it exists
Expand All @@ -10,7 +13,7 @@ const fs = require('fs/promises')
const unlink = async (filename) => {
debug('Removing file `%s`', filename)
try {
await fs.unlink(filename)
await fsUnlink(filename)
} catch (error) {
debug("File `%s` doesn't exist, ignoring...", filename)
}
Expand Down

0 comments on commit c99a6a1

Please sign in to comment.