Skip to content

Commit

Permalink
Remove syntax that is not supported on Node v10
Browse files Browse the repository at this point in the history
Kicking myself for not bumping the engines version, but oh well.  Next
time.
  • Loading branch information
isaacs committed Jan 17, 2023
1 parent b2008f3 commit 3a097bd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/find-made.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const findMade = async (
st => (st.isDirectory() ? path : undefined), // will fail later
er => {
const fer = er as NodeJS.ErrnoException
return fer?.code === 'ENOENT'
return fer && fer.code === 'ENOENT'
? findMade(opts, dirname(parent), parent)
: undefined
}
Expand All @@ -35,7 +35,7 @@ export const findMadeSync = (
return opts.statSync(parent).isDirectory() ? path : undefined
} catch (er) {
const fer = er as NodeJS.ErrnoException
return fer?.code === 'ENOENT'
return fer && fer.code === 'ENOENT'
? findMadeSync(opts, dirname(parent), parent)
: undefined
}
Expand Down
18 changes: 12 additions & 6 deletions src/mkdirp-manual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const mkdirpManualSync = (
// swallowed by recursive implementation on posix systems
// any other error is a failure
const fer = er as NodeJS.ErrnoException
if (fer?.code !== 'EISDIR') {
if (fer && fer.code !== 'EISDIR') {
throw er
}
return
Expand All @@ -28,9 +28,12 @@ export const mkdirpManualSync = (
return made || path
} catch (er) {
const fer = er as NodeJS.ErrnoException
if (fer?.code === 'ENOENT')
if (fer && fer.code === 'ENOENT') {
return mkdirpManualSync(path, opts, mkdirpManualSync(parent, opts, made))
if (fer?.code !== 'EEXIST' && fer?.code !== 'EROFS') throw er
}
if (fer && fer.code !== 'EEXIST' && fer && fer.code !== 'EROFS') {
throw er
}
try {
if (!opts.statSync(path).isDirectory()) throw er
} catch (_) {
Expand All @@ -53,7 +56,7 @@ export const mkdirpManual = Object.assign(
// swallowed by recursive implementation on posix systems
// any other error is a failure
const fer = er as NodeJS.ErrnoException
if (fer?.code !== 'EISDIR') {
if (fer && fer.code !== 'EISDIR') {
throw er
}
})
Expand All @@ -63,11 +66,14 @@ export const mkdirpManual = Object.assign(
() => made || path,
async er => {
const fer = er as NodeJS.ErrnoException
if (fer?.code === 'ENOENT')
if (fer && fer.code === 'ENOENT') {
return mkdirpManual(parent, opts).then(
(made?: string | undefined | void) => mkdirpManual(path, opts, made)
)
if (fer?.code !== 'EEXIST' && fer?.code !== 'EROFS') throw er
}
if (fer && fer.code !== 'EEXIST' && fer.code !== 'EROFS') {
throw er
}
return opts.statAsync(path).then(
st => {
if (st.isDirectory()) {
Expand Down
4 changes: 2 additions & 2 deletions src/mkdirp-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const mkdirpNativeSync = (
return made
} catch (er) {
const fer = er as NodeJS.ErrnoException
if (fer?.code === 'ENOENT') {
if (fer && fer.code === 'ENOENT') {
return mkdirpManualSync(path, opts)
} else {
throw er
Expand All @@ -45,7 +45,7 @@ export const mkdirpNative = Object.assign(
.then(m => made || m)
.catch(er => {
const fer = er as NodeJS.ErrnoException
if (fer?.code === 'ENOENT') {
if (fer && fer.code === 'ENOENT') {
return mkdirpManual(path, opts)
} else {
throw er
Expand Down
9 changes: 5 additions & 4 deletions src/opts-arg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ export const optsArg = (opts?: MkdirpOptions): MkdirpOptionsResolved => {
}

const resolved = opts as MkdirpOptionsResolved
const optsFs = opts.fs || {}

opts.mkdir = opts.mkdir || opts.fs?.mkdir || mkdir
opts.mkdir = opts.mkdir || optsFs.mkdir || mkdir

opts.mkdirAsync = opts.mkdirAsync
? opts.mkdirAsync
Expand All @@ -91,16 +92,16 @@ export const optsArg = (opts?: MkdirpOptions): MkdirpOptionsResolved => {
)
}

opts.stat = opts.stat || opts.fs?.stat || stat
opts.stat = opts.stat || optsFs.stat || stat
opts.statAsync = opts.statAsync
? opts.statAsync
: async (path: string) =>
new Promise((res, rej) =>
resolved.stat(path, (err, stats) => (err ? rej(err) : res(stats)))
)

opts.statSync = opts.statSync || opts.fs?.statSync || statSync
opts.mkdirSync = opts.mkdirSync || opts.fs?.mkdirSync || mkdirSync
opts.statSync = opts.statSync || optsFs.statSync || statSync
opts.mkdirSync = opts.mkdirSync || optsFs.mkdirSync || mkdirSync

return resolved
}

0 comments on commit 3a097bd

Please sign in to comment.