Skip to content

Commit

Permalink
Named export only, no default export
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Apr 9, 2023
1 parent 04bcedf commit c7a3fd4
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 76 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 5.0

- No default export, only named exports

# 4.4

- Provide Dirent or Stats object as second argument to filter
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ Install with `npm install rimraf`.
Hybrid module, load either with `import` or `require()`.

```js
// default export is the main rimraf function, or use named imports
import rimraf from 'rimraf'
// or
const rimraf = require('rimraf')

// other strategies exported as well
// 'rimraf' export is the one you probably want, but other
// strategies exported as well.
import { rimraf, rimrafSync, native, nativeSync } from 'rimraf'
// or
const { rimraf, rimrafSync, native, nativeSync } = require('rimraf')
Expand Down
2 changes: 1 addition & 1 deletion benchmark/create-fixture.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { writeFile: writeFile_ } = require('fs')
const writeFile = async (path, data) => new Promise((res, rej) =>
writeFile_(path, data, er => er ? rej(er) : res()))
const mkdirp = require('mkdirp')
const { mkdirp } = require('mkdirp')
const { resolve } = require('path')

const create = async (path, start, end, maxDepth, depth = 0) => {
Expand Down
2 changes: 1 addition & 1 deletion libtap-settings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// use this module for tap's recursive directory removal, so that
// the windows tests don't fail with EBUSY.
const rimraf = require('./')
const { rimraf } = require('./')
module.exports = {
rmdirRecursiveSync: path => rimraf.sync(path),
rmdirRecursive(path, cb) {
Expand Down
73 changes: 44 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "rimraf",
"version": "4.4.1",
"main": "./dist/cjs/src/index-cjs.js",
"main": "./dist/cjs/src/index.js",
"module": "./dist/mjs/index.js",
"types": "./dist/mjs/index.d.ts",
"bin": "./dist/cjs/src/bin.js",
Expand All @@ -13,7 +13,7 @@
},
"require": {
"types": "./dist/cjs/src/index.d.ts",
"default": "./dist/cjs/src/index-cjs.js"
"default": "./dist/cjs/src/index.js"
}
}
},
Expand Down Expand Up @@ -55,7 +55,7 @@
"@types/tap": "^15.0.7",
"c8": "^7.12.0",
"eslint-config-prettier": "^8.6.0",
"mkdirp": "1",
"mkdirp": "^3.0.0",
"prettier": "^2.8.2",
"tap": "^16.3.4",
"ts-node": "^10.9.1",
Expand All @@ -79,6 +79,6 @@
"node": ">=14"
},
"dependencies": {
"glob": "^9.2.0"
"glob": "^10.0.0"
}
}
2 changes: 1 addition & 1 deletion src/bin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
import { version } from '../package.json'
import rimraf from './index-cjs.js'
import { rimraf } from './index.js'
import type { RimrafAsyncOptions } from './index.js'

const runHelpForUsage = () =>
Expand Down
3 changes: 0 additions & 3 deletions src/index-cjs.ts

This file was deleted.

39 changes: 17 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,22 @@ export const rimrafSync = wrapSync((path, opt) =>
)
export const sync = rimrafSync

export const rimraf = Object.assign(
wrap((path, opt) =>
useNative(opt) ? rimrafNative(path, opt) : rimrafManual(path, opt)
),
{
// this weirdness because it's easier than explicitly declaring
rimraf: manual,
sync: rimrafSync,
rimrafSync: rimrafSync,
manual,
manualSync,
native,
nativeSync,
posix,
posixSync,
windows,
windowsSync,
moveRemove,
moveRemoveSync,
}
const rimraf_ = wrap((path, opt) =>
useNative(opt) ? rimrafNative(path, opt) : rimrafManual(path, opt)
)
export const rimraf = Object.assign(rimraf_, {
rimraf: rimraf_,
sync: rimrafSync,
rimrafSync: rimrafSync,
manual,
manualSync,
native,
nativeSync,
posix,
posixSync,
windows,
windowsSync,
moveRemove,
moveRemoveSync,
})
rimraf.rimraf = rimraf

export default rimraf
18 changes: 12 additions & 6 deletions test/bin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { basename } = require('path')
const t = require('tap')
const { readdirSync } = require('fs')

Expand All @@ -14,15 +13,22 @@ t.test('basic arg parsing stuff', t => {
console.error = (...msg) => ERRS.push(msg)

const CALLS = []
const rimraf = async (path, opt) => CALLS.push(['rimraf', path, opt])
const bin = t.mock('../dist/cjs/src/bin.js', {
'../dist/cjs/src/index.js': Object.assign(rimraf, {
const rimraf = Object.assign(
async (path, opt) => CALLS.push(['rimraf', path, opt]),
{
native: async (path, opt) => CALLS.push(['native', path, opt]),
manual: async (path, opt) => CALLS.push(['manual', path, opt]),
posix: async (path, opt) => CALLS.push(['posix', path, opt]),
windows: async (path, opt) => CALLS.push(['windows', path, opt]),
moveRemove: async (path, opt) => CALLS.push(['move-remove', path, opt]),
}),
}
)

const bin = t.mock('../dist/cjs/src/bin.js', {
'../dist/cjs/src/index.js': {
rimraf,
...rimraf,
},
}).default

t.afterEach(() => {
Expand Down Expand Up @@ -264,7 +270,7 @@ t.test('actually delete something with it', async t => {
const bin = require.resolve('../dist/cjs/src/bin.js')
const { spawnSync } = require('child_process')
const res = spawnSync(process.execPath, [bin, path])
const { statSync, readdirSync } = require('fs')
const { statSync } = require('fs')
t.throws(() => statSync(path))
t.equal(res.status, 0)
})
Expand Down
4 changes: 2 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ t.same(
types: './dist/mjs/index.d.ts',
},
require: {
default: './dist/cjs/src/index-cjs.js',
default: './dist/cjs/src/index.js',
types: './dist/cjs/src/index.d.ts',
},
},
Expand Down Expand Up @@ -73,7 +73,7 @@ t.test('mocky unit tests to select the correct function', t => {
},
}
process.env.__TESTING_RIMRAF_PLATFORM__ = 'posix'
const rimraf = t.mock('../', mocks)
const { rimraf } = t.mock('../', mocks)

t.afterEach(() => (CALLS.length = 0))
for (const useNative of [true, false]) {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig-esm.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "./tsconfig-base.json",
"exclude": ["./test", "./tap-snapshots", "src/index-cjs.ts", "src/bin.ts"],
"exclude": ["./test", "./tap-snapshots", "src/bin.ts"],
"compilerOptions": {
"module": "esnext",
"outDir": "dist/mjs"
Expand Down

0 comments on commit c7a3fd4

Please sign in to comment.