Skip to content
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

🐞 pifs: align with Node.js v12 #146

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/pifs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Promisified [graceful-fs](https://github.com/isaacs/node-graceful-fs).

* aligned with Node.js v10
* aligned with Node.js v12
* native `util.promisify()`
* no sync methods
* no deprecated methods like `exists`
Expand Down
8 changes: 8 additions & 0 deletions packages/pifs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export const lstat = promisify(fs.lstat)
export const mkdir = promisify(fs.mkdir)
export const mkdtemp = promisify(fs.mkdtemp)
export const open = promisify(fs.open)
export const opendir = promisify(fs.opendir)
export const read = promisify(fs.read)
export const readv = promisify(fs.readv)
export const readdir = promisify(fs.readdir)
export const readFile = promisify(fs.readFile)
export const readlink = promisify(fs.readlink)
Expand All @@ -40,7 +42,9 @@ export const utimes = promisify(fs.utimes)
export const watch = fs.watch
export const watchFile = fs.watchFile
export const write = promisify(fs.write)
export const writev = promisify(fs.writev)
export const writeFile = promisify(fs.writeFile)
export const Dir = fs.Dir
export const Dirent = fs.Dirent
export const Stats = fs.Stats
export const ReadStream = fs.ReadStream
Expand Down Expand Up @@ -70,7 +74,9 @@ export default {
mkdir,
mkdtemp,
open,
opendir,
read,
readv,
readdir,
readFile,
readlink,
Expand All @@ -86,7 +92,9 @@ export default {
watch,
watchFile,
write,
writev,
writeFile,
Dir,
Dirent,
Stats,
ReadStream,
Expand Down
96 changes: 19 additions & 77 deletions packages/pifs/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,83 +1,25 @@
import test from 'tape'

if (process.version.startsWith('v12')) {
test('pifs: exports aligned with v10', async (t) => {
const originalFs = await import('fs')
const pifs = await import('../src')
let hasErrors = false

for (const name of Object.keys(pifs)) {
if (name !== 'default' && !Reflect.has(originalFs, name)) {
hasErrors = true
t.fail(`${name} doesn't exist in Node v12`)
}
}

for (const name of Object.keys(pifs.default)) {
if (name !== 'default' && !Reflect.has(originalFs.default, name)) {
hasErrors = true
t.fail(`default.${name} doesn't exist in Node v12`)
}
}

if (!hasErrors) {
t.pass('should align exported names')
}
})
}

if (process.version.startsWith('v10')) {
test('pifs: align exports with Node v10', async (t) => {
const originalFs = await import('fs')
const pifs = await import('../src')

const namesToIgnore = [
'default',
'exists',
'promises',
'_toUnixTimestamp',
'gracefulify',
'FileReadStream',
'FileWriteStream',
'F_OK',
'R_OK',
'W_OK',
'X_OK',
]
let hasErrors = false

const names = Object.keys(originalFs)
.filter((name) => !name.endsWith('Sync'))
.filter((name) => !namesToIgnore.includes(name))

for (const name of names) {
if (!Reflect.has(pifs, name)) {
hasErrors = true
t.fail(`${name} is missing`)
}

if (!Reflect.has(pifs.default, name)) {
hasErrors = true
t.fail(`default.${name} is missing`)
}
test('pifs: exports aligned with v12', async (t) => {
const originalFs = await import('fs')
const pifs = await import('../src')
let hasErrors = false

for (const name of Object.keys(pifs)) {
if (name !== 'default' && !Reflect.has(originalFs, name)) {
hasErrors = true
t.fail(`${name} doesn't exist`)
}
}

for (const name of Object.keys(pifs)) {
if (name !== 'default' && !Reflect.has(originalFs, name)) {
hasErrors = true
t.fail(`${name} is unknown`)
}
for (const name of Object.keys(pifs.default)) {
if (name !== 'default' && !Reflect.has(originalFs.default, name)) {
hasErrors = true
t.fail(`default.${name} doesn't exist`)
}
}

for (const name of Object.keys(pifs.default)) {
if (!Reflect.has(originalFs.default, name)) {
hasErrors = true
t.fail(`default.${name} is unknown`)
}
}

if (!hasErrors) {
t.pass('should align exported names')
}
})
}
if (!hasErrors) {
t.pass('should align exported names')
}
})