From f4ad8c1f032daa54ca27b83361c2c10985004709 Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 16 Jan 2023 15:59:47 -0800 Subject: [PATCH] remove unused bin, format with prettier --- .gitignore | 1 + .prettierignore | 9 ++++++ CHANGELOG.md | 4 +-- bin/cmd.js | 68 -------------------------------------------- readme.markdown | 25 ++++++++-------- src/index-cjs.ts | 4 +-- src/mkdirp-native.ts | 2 +- test/cmd.ts | 6 +--- test/index.ts | 5 +++- 9 files changed, 33 insertions(+), 91 deletions(-) create mode 100644 .prettierignore delete mode 100755 bin/cmd.js diff --git a/.gitignore b/.gitignore index 44585e7..92b0528 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ !.gitattributes !/tsconfig*.json !/fixup.sh +!/.prettierignore diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..9fdb805 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,9 @@ +/node_modules +/example +/.github +/dist +.env +/tap-snapshots +/.nyc_output +/coverage +/benchmark diff --git a/CHANGELOG.md b/CHANGELOG.md index 4824a70..be68abf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,11 @@ Export hybrid module with TypeScript types. ## 1.0 -Full rewrite. Essentially a brand new module. +Full rewrite. Essentially a brand new module. - Return a promise instead of taking a callback. - Use native `fs.mkdir(path, { recursive: true })` when available. -- Drop support for outdated Node.js versions. (Technically still works on +- Drop support for outdated Node.js versions. (Technically still works on Node.js v8, but only 10 and above are officially supported.) ## 0.x diff --git a/bin/cmd.js b/bin/cmd.js deleted file mode 100755 index 6e0aa8d..0000000 --- a/bin/cmd.js +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env node - -const usage = () => ` -usage: mkdirp [DIR1,DIR2..] {OPTIONS} - - Create each supplied directory including any necessary parent directories - that don't yet exist. - - If the directory already exists, do nothing. - -OPTIONS are: - - -m If a directory needs to be created, set the mode as an octal - --mode= permission string. - - -v --version Print the mkdirp version number - - -h --help Print this helpful banner - - -p --print Print the first directories created for each path provided - - --manual Use manual implementation, even if native is available -` - -const dirs = [] -const opts = {} -let print = false -let dashdash = false -let manual = false -for (const arg of process.argv.slice(2)) { - if (dashdash) - dirs.push(arg) - else if (arg === '--') - dashdash = true - else if (arg === '--manual') - manual = true - else if (/^-h/.test(arg) || /^--help/.test(arg)) { - console.log(usage()) - process.exit(0) - } else if (arg === '-v' || arg === '--version') { - console.log(require('../package.json').version) - process.exit(0) - } else if (arg === '-p' || arg === '--print') { - print = true - } else if (/^-m/.test(arg) || /^--mode=/.test(arg)) { - const mode = parseInt(arg.replace(/^(-m|--mode=)/, ''), 8) - if (isNaN(mode)) { - console.error(`invalid mode argument: ${arg}\nMust be an octal number.`) - process.exit(1) - } - opts.mode = mode - } else - dirs.push(arg) -} - -const mkdirp = require('../') -const impl = manual ? mkdirp.manual : mkdirp -if (dirs.length === 0) - console.error(usage()) - -Promise.all(dirs.map(dir => impl(dir, opts))) - .then(made => print ? made.forEach(m => m && console.log(m)) : null) - .catch(er => { - console.error(er.message) - if (er.code) - console.error(' code: ' + er.code) - process.exit(1) - }) diff --git a/readme.markdown b/readme.markdown index 9ad91fc..df654b8 100644 --- a/readme.markdown +++ b/readme.markdown @@ -18,7 +18,8 @@ const { mkdirp } = require('mkdirp') // return value is a Promise resolving to the first directory created mkdirp('/tmp/foo/bar/baz').then(made => - console.log(`made directories, starting with ${made}`)) + console.log(`made directories, starting with ${made}`) +) ``` Output (where `/tmp/foo` already exists) @@ -54,8 +55,8 @@ or number, it will be treated as the `opts.mode`. If `opts.mode` isn't specified, it defaults to `0o777`. Promise resolves to first directory `made` that had to be -created, or `undefined` if everything already exists. Promise -rejects if any errors are encountered. Note that, in the case of +created, or `undefined` if everything already exists. Promise +rejects if any errors are encountered. Note that, in the case of promise rejection, some directories _may_ have been created, as recursive directory creation is not an atomic operation. @@ -89,13 +90,13 @@ providing an `fs` option that only overrides one of these. ## `mkdirp.manual`, `mkdirp.manualSync` -Use the manual implementation (not the native one). This is the +Use the manual implementation (not the native one). This is the default when the native implementation is not available or the stat/mkdir implementation is overridden. ## `mkdirp.native`, `mkdirp.nativeSync` -Use the native implementation (not the manual one). This is the +Use the native implementation (not the manual one). This is the default when the native implementation is available and stat/mkdir are not overridden. @@ -108,7 +109,7 @@ been overridden by an option. ## native implementation - If the path is a root directory, then pass it to the underlying - implementation and return the result/error. (In this case, + implementation and return the result/error. (In this case, it'll either succeed or fail, but we aren't actually creating any dirs.) - Walk up the path statting each directory, to find the first @@ -120,7 +121,7 @@ been overridden by an option. ## manual implementation - Call underlying `fs.mkdir` implementation, with `recursive: - false` +false` - If error: - If path is a root directory, raise to the caller and do not handle it @@ -135,13 +136,13 @@ been overridden by an option. ## windows vs unix caveat On Windows file systems, attempts to create a root directory (ie, -a drive letter or root UNC path) will fail. If the root -directory exists, then it will fail with `EPERM`. If the root +a drive letter or root UNC path) will fail. If the root +directory exists, then it will fail with `EPERM`. If the root directory does not exist, then it will fail with `ENOENT`. On posix file systems, attempts to create a root directory (in recursive mode) will succeed silently, as it is treated like just -another directory that already exists. (In non-recursive mode, +another directory that already exists. (In non-recursive mode, of course, it fails with `EEXIST`.) In order to preserve this system-specific behavior (and because @@ -164,7 +165,7 @@ is encountered. # choosing a recursive mkdir implementation -There are a few to choose from! Use the one that suits your +There are a few to choose from! Use the one that suits your needs best :D ## use `fs.mkdir(path, {recursive: true}, cb)` if: @@ -216,7 +217,7 @@ needs best :D - You think vinyl just sounds warmer and richer for some weird reason. - You are supporting truly ancient Node.js versions, before even - the advent of a `Promise` language primitive. (Please don't. + the advent of a `Promise` language primitive. (Please don't. You deserve better.) # cli diff --git a/src/index-cjs.ts b/src/index-cjs.ts index b6dfa56..0f8b591 100644 --- a/src/index-cjs.ts +++ b/src/index-cjs.ts @@ -1,3 +1,3 @@ -import mkdirp from './index.js'; +import mkdirp from './index.js' -export = mkdirp; +export = Object.assign(mkdirp, { default: mkdirp }) diff --git a/src/mkdirp-native.ts b/src/mkdirp-native.ts index 3657a5b..2bb4cab 100644 --- a/src/mkdirp-native.ts +++ b/src/mkdirp-native.ts @@ -42,7 +42,7 @@ export const mkdirpNative = Object.assign( return findMade(opts, path).then((made?: string | undefined) => opts .mkdirAsync(path, opts) - .then((m) => made || m) + .then(m => made || m) .catch(er => { const fer = er as NodeJS.ErrnoException if (fer?.code === 'ENOENT') { diff --git a/test/cmd.ts b/test/cmd.ts index 1a396a1..3b2c0cd 100644 --- a/test/cmd.ts +++ b/test/cmd.ts @@ -19,11 +19,7 @@ fakeMkdirp.manual = (path: string, opts: MkdirpOptions) => fakeMkdirp.mkdirp = fakeMkdirp if (process.argv[2] === 'RUN') { - process.argv = [ - process.execPath, - cmd, - ...process.argv.slice(3), - ] + process.argv = [process.execPath, cmd, ...process.argv.slice(3)] t.mock(cmd, { '../dist/cjs/src/index.js': fakeMkdirp, '../dist/cjs/package.json': { diff --git a/test/index.ts b/test/index.ts index 14c4fc4..4448d1a 100644 --- a/test/index.ts +++ b/test/index.ts @@ -1,7 +1,10 @@ import { mkdir, mkdirSync, statSync } from 'fs' import t from 'tap' import mkdirp from '../dist/cjs/src/index.js' -import { MkdirpOptions, MkdirpOptionsResolved } from '../dist/cjs/src/opts-arg.js' +import { + MkdirpOptions, + MkdirpOptionsResolved, +} from '../dist/cjs/src/opts-arg.js' // node before 10.13 didn't native recursive mkdir const doNative = !/^v([0-8]\.|10.([0-9]\.|10\.|11\.([0-9]|1[01])$))/.test(