From 3a097bd245618f36fe943394dd40cca7fcfa37a8 Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 16 Jan 2023 16:09:10 -0800 Subject: [PATCH] Remove syntax that is not supported on Node v10 Kicking myself for not bumping the engines version, but oh well. Next time. --- src/find-made.ts | 4 ++-- src/mkdirp-manual.ts | 18 ++++++++++++------ src/mkdirp-native.ts | 4 ++-- src/opts-arg.ts | 9 +++++---- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/find-made.ts b/src/find-made.ts index 4ffa4f3..b8ad884 100644 --- a/src/find-made.ts +++ b/src/find-made.ts @@ -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 } @@ -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 } diff --git a/src/mkdirp-manual.ts b/src/mkdirp-manual.ts index bbb92be..8d030f7 100644 --- a/src/mkdirp-manual.ts +++ b/src/mkdirp-manual.ts @@ -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 @@ -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 (_) { @@ -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 } }) @@ -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()) { diff --git a/src/mkdirp-native.ts b/src/mkdirp-native.ts index 2bb4cab..6bcf910 100644 --- a/src/mkdirp-native.ts +++ b/src/mkdirp-native.ts @@ -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 @@ -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 diff --git a/src/opts-arg.ts b/src/opts-arg.ts index ddc1acd..cf59463 100644 --- a/src/opts-arg.ts +++ b/src/opts-arg.ts @@ -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 @@ -91,7 +92,7 @@ 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) => @@ -99,8 +100,8 @@ export const optsArg = (opts?: MkdirpOptions): MkdirpOptionsResolved => { 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 }