-
-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor + chore cleanup #322
Open
lukekarrys
wants to merge
9
commits into
isaacs:main
Choose a base branch
from
lukekarrys:lk/refactor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
56cb4cb
benchmark: convert to esm
lukekarrys 768b1bc
benchmark: add options to filter and compare benchmarks
lukekarrys 9b3b6bf
Configure tap coverage-map
lukekarrys ec31e8b
Use tap.intercept to test bin
lukekarrys c40bef9
Mock process.platform with t.intercept
lukekarrys c1b5c88
Use the same ignoreENOENT and fixEPERM utils everywhere
lukekarrys 604153a
Do not pass unnecessary rest args to fs functions
lukekarrys ab09f16
Create separate dir for integration tests
lukekarrys 9e6fc9b
Add linting and update dependencies
lukekarrys File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
import platform from './platform.js' | ||
|
||
import { rimrafPosix, rimrafPosixSync } from './rimraf-posix.js' | ||
import { rimrafWindows, rimrafWindowsSync } from './rimraf-windows.js' | ||
|
||
export const rimrafManual = platform === 'win32' ? rimrafWindows : rimrafPosix | ||
export const rimrafManual = | ||
process.platform === 'win32' ? rimrafWindows : rimrafPosix | ||
export const rimrafManualSync = | ||
platform === 'win32' ? rimrafWindowsSync : rimrafPosixSync | ||
process.platform === 'win32' ? rimrafWindowsSync : rimrafPosixSync |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
import { RimrafAsyncOptions, RimrafOptions } from './index.js' | ||
import platform from './platform.js' | ||
|
||
const version = process.env.__TESTING_RIMRAF_NODE_VERSION__ || process.version | ||
const versArr = version.replace(/^v/, '').split('.') | ||
|
||
/* c8 ignore start */ | ||
const [major = 0, minor = 0] = versArr.map(v => parseInt(v, 10)) | ||
/* c8 ignore stop */ | ||
/* c8 ignore next */ | ||
const [major = 0, minor = 0] = process.version | ||
.replace(/^v/, '') | ||
.split('.') | ||
.map(v => parseInt(v, 10)) | ||
const hasNative = major > 14 || (major === 14 && minor >= 14) | ||
|
||
// we do NOT use native by default on Windows, because Node's native | ||
// rm implementation is less advanced. Change this code if that changes. | ||
export const useNative: (opt?: RimrafAsyncOptions) => boolean = | ||
!hasNative || platform === 'win32' ? | ||
!hasNative || process.platform === 'win32' ? | ||
() => false | ||
: opt => !opt?.signal && !opt?.filter | ||
export const useNativeSync: (opt?: RimrafOptions) => boolean = | ||
!hasNative || platform === 'win32' ? | ||
!hasNative || process.platform === 'win32' ? | ||
() => false | ||
: opt => !opt?.signal && !opt?.filter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,81 @@ | ||
import * as PATH from 'path' | ||
import t from 'tap' | ||
import { fileURLToPath } from 'url' | ||
import { inspect } from 'util' | ||
|
||
if (!process.env.__TESTING_RIMRAF_PLATFORM__) { | ||
const fake = process.platform === 'win32' ? 'posix' : 'win32' | ||
t.spawn( | ||
process.execPath, | ||
[...process.execArgv, fileURLToPath(import.meta.url)], | ||
{ | ||
name: fake, | ||
env: { | ||
...process.env, | ||
__TESTING_RIMRAF_PLATFORM__: fake, | ||
}, | ||
}, | ||
) | ||
} | ||
for (const platform of ['win32', 'posix'] as const) { | ||
t.test(platform, async t => { | ||
t.intercept(process, 'platform', { value: platform }) | ||
const path = PATH[platform] || PATH | ||
const { default: pathArg } = (await t.mockImport('../src/path-arg.js', { | ||
path, | ||
})) as typeof import('../src/path-arg.js') | ||
|
||
const platform = process.env.__TESTING_RIMRAF_PLATFORM__ || process.platform | ||
const path = PATH[platform as 'win32' | 'posix'] || PATH | ||
const { default: pathArg } = (await t.mockImport('../dist/esm/path-arg.js', { | ||
path, | ||
})) as typeof import('../dist/esm/path-arg.js') | ||
t.equal(pathArg('a/b/c'), path.resolve('a/b/c')) | ||
t.throws( | ||
() => pathArg('a\0b'), | ||
Error('path must be a string without null bytes'), | ||
) | ||
if (platform === 'win32') { | ||
const badPaths = [ | ||
'c:\\a\\b:c', | ||
'c:\\a\\b*c', | ||
'c:\\a\\b?c', | ||
'c:\\a\\b<c', | ||
'c:\\a\\b>c', | ||
'c:\\a\\b|c', | ||
'c:\\a\\b"c', | ||
] | ||
for (const path of badPaths) { | ||
const er = Object.assign(new Error('Illegal characters in path'), { | ||
path, | ||
code: 'EINVAL', | ||
}) | ||
t.throws(() => pathArg(path), er) | ||
} | ||
} | ||
|
||
const { resolve } = path | ||
t.throws(() => pathArg('/'), { code: 'ERR_PRESERVE_ROOT' }) | ||
|
||
t.equal(pathArg('a/b/c'), resolve('a/b/c')) | ||
t.throws( | ||
() => pathArg('a\0b'), | ||
Error('path must be a string without null bytes'), | ||
) | ||
if (platform === 'win32') { | ||
const badPaths = [ | ||
'c:\\a\\b:c', | ||
'c:\\a\\b*c', | ||
'c:\\a\\b?c', | ||
'c:\\a\\b<c', | ||
'c:\\a\\b>c', | ||
'c:\\a\\b|c', | ||
'c:\\a\\b"c', | ||
] | ||
for (const path of badPaths) { | ||
const er = Object.assign(new Error('Illegal characters in path'), { | ||
path, | ||
code: 'EINVAL', | ||
t.throws(() => pathArg('/', { preserveRoot: undefined }), { | ||
code: 'ERR_PRESERVE_ROOT', | ||
}) | ||
t.throws(() => pathArg(path), er) | ||
} | ||
} | ||
|
||
t.throws(() => pathArg('/'), { code: 'ERR_PRESERVE_ROOT' }) | ||
|
||
t.throws(() => pathArg('/', { preserveRoot: undefined }), { | ||
code: 'ERR_PRESERVE_ROOT', | ||
}) | ||
t.equal(pathArg('/', { preserveRoot: false }), resolve('/')) | ||
t.equal(pathArg('/', { preserveRoot: false }), path.resolve('/')) | ||
|
||
//@ts-expect-error | ||
t.throws(() => pathArg({}), { | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
path: {}, | ||
message: | ||
'The "path" argument must be of type string. ' + | ||
'Received an instance of Object', | ||
name: 'TypeError', | ||
}) | ||
//@ts-expect-error | ||
t.throws(() => pathArg([]), { | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
path: [], | ||
message: | ||
'The "path" argument must be of type string. ' + | ||
'Received an instance of Array', | ||
name: 'TypeError', | ||
}) | ||
//@ts-expect-error | ||
t.throws(() => pathArg(Object.create(null) as {}), { | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
path: Object.create(null), | ||
message: | ||
'The "path" argument must be of type string. ' + | ||
`Received ${inspect(Object.create(null))}`, | ||
name: 'TypeError', | ||
}) | ||
//@ts-expect-error | ||
t.throws(() => pathArg(true), { | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
path: true, | ||
message: | ||
'The "path" argument must be of type string. ' + | ||
`Received type boolean true`, | ||
name: 'TypeError', | ||
}) | ||
//@ts-expect-error | ||
t.throws(() => pathArg({}), { | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
path: {}, | ||
message: | ||
'The "path" argument must be of type string. ' + | ||
'Received an instance of Object', | ||
name: 'TypeError', | ||
}) | ||
//@ts-expect-error | ||
t.throws(() => pathArg([]), { | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
path: [], | ||
message: | ||
'The "path" argument must be of type string. ' + | ||
'Received an instance of Array', | ||
name: 'TypeError', | ||
}) | ||
//@ts-expect-error | ||
t.throws(() => pathArg(Object.create(null) as object), { | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
path: Object.create(null) as object, | ||
message: | ||
'The "path" argument must be of type string. ' + | ||
`Received ${inspect(Object.create(null))}`, | ||
name: 'TypeError', | ||
}) | ||
//@ts-expect-error | ||
t.throws(() => pathArg(true), { | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
path: true, | ||
message: | ||
'The "path" argument must be of type string. ' + | ||
`Received type boolean true`, | ||
name: 'TypeError', | ||
}) | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,20 @@ | ||
import t from 'tap' | ||
import { fileURLToPath } from 'url' | ||
import { rimrafManual, rimrafManualSync } from '../dist/esm/rimraf-manual.js' | ||
import { rimrafPosix, rimrafPosixSync } from '../dist/esm/rimraf-posix.js' | ||
import { rimrafWindows, rimrafWindowsSync } from '../dist/esm/rimraf-windows.js' | ||
import { rimrafPosix, rimrafPosixSync } from '../src/rimraf-posix.js' | ||
import { rimrafWindows, rimrafWindowsSync } from '../src/rimraf-windows.js' | ||
|
||
if (!process.env.__TESTING_RIMRAF_PLATFORM__) { | ||
const otherPlatform = process.platform !== 'win32' ? 'win32' : 'posix' | ||
t.spawn( | ||
process.execPath, | ||
[...process.execArgv, fileURLToPath(import.meta.url)], | ||
{ | ||
name: otherPlatform, | ||
env: { | ||
...process.env, | ||
__TESTING_RIMRAF_PLATFORM__: otherPlatform, | ||
}, | ||
}, | ||
) | ||
} | ||
for (const platform of ['win32', 'posix']) { | ||
t.test(platform, async t => { | ||
t.intercept(process, 'platform', { value: platform }) | ||
const { rimrafManual, rimrafManualSync } = (await t.mockImport( | ||
'../src/rimraf-manual.js', | ||
)) as typeof import('../src/rimraf-manual.js') | ||
|
||
const platform = process.env.__TESTING_RIMRAF_PLATFORM__ || process.platform | ||
const [expectManual, expectManualSync] = | ||
platform === 'win32' ? | ||
[rimrafWindows, rimrafWindowsSync] | ||
: [rimrafPosix, rimrafPosixSync] | ||
|
||
const [expectManual, expectManualSync] = | ||
platform === 'win32' ? | ||
[rimrafWindows, rimrafWindowsSync] | ||
: [rimrafPosix, rimrafPosixSync] | ||
t.equal(rimrafManual, expectManual, 'got expected implementation') | ||
t.equal(rimrafManualSync, expectManualSync, 'got expected implementation') | ||
t.equal(rimrafManual, expectManual, 'got expected implementation') | ||
t.equal(rimrafManualSync, expectManualSync, 'got expected implementation') | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@isaacs is it worth removing this version check is
use-native
now thatv14.14.0
is no longer supported byengines
?