Skip to content

Commit

Permalink
feat: support multiple @types/node versions at once
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeWitchBella committed Sep 16, 2021
1 parent 6ad11bc commit 70a25d5
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 10 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Autogenerated
*.d.ts

# Logs
logs
*.log
Expand Down
65 changes: 65 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/// <reference types="node" />
import * as fsPromises from "fs/promises"

type E<T extends string> = typeof fsPromises extends { [m in T]: any }
? typeof fsPromises[T]
: undefined
export const access: E<"access">
export const appendFile: E<"appendFile">
export const chmod: E<"chmod">
export const chown: E<"chown">
export const copyFile: E<"copyFile">
export const cp: E<"cp">
export const lchown: E<"lchown">
export const lutimes: E<"lutimes">
export const link: E<"link">
export const lstat: E<"lstat">
export const mkdir: E<"mkdir">
export const mkdtemp: E<"mkdtemp">
export const open: E<"open">
export const opendir: E<"opendir">
export const readdir: E<"readdir">
export const readFile: E<"readFile">
export const readlink: E<"readlink">
export const realpath: E<"realpath">
export const rename: E<"rename">
export const rmdir: E<"rmdir">
export const rm: E<"rm">
export const stat: E<"stat">
export const symlink: E<"symlink">
export const truncate: E<"truncate">
export const unlink: E<"unlink">
export const utimes: E<"utimes">
export const watch: E<"watch">
export const writeFile: E<"writeFile">
declare namespace _default {
export { access }
export { appendFile }
export { chmod }
export { chown }
export { copyFile }
export { cp }
export { lchown }
export { lutimes }
export { link }
export { lstat }
export { mkdir }
export { mkdtemp }
export { open }
export { opendir }
export { readdir }
export { readFile }
export { readlink }
export { realpath }
export { rename }
export { rmdir }
export { rm }
export { stat }
export { symlink }
export { truncate }
export { unlink }
export { utimes }
export { watch }
export { writeFile }
}
export default _default
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as fsPromises from "fs/promises"
// Adding new function:
// 1. add `export const ...` here
// 2. add it to `export default { ... }`
// 3. add it to `index.d.ts` (twice)
export const access = wrap("access")
export const appendFile = wrap("appendFile")
export const chmod = wrap("chmod")
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@isbl/fs",
"version": "0.4.0",
"version": "0.5.0",
"description": "Wrappers around node:fs with proper error stack support",
"repository": {
"type": "git",
Expand Down
15 changes: 15 additions & 0 deletions sync.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// <reference types="node" />
import * as fsSync from "fs"

type E<T extends string> = typeof fsSync extends { [m in T]: any }
? typeof fsSync[T]
: undefined
export const readdirSync: E<"readdirSync">
export const readFileSync: E<"readFileSync">
export const writeFileSync: E<"writeFileSync">
declare namespace _default {
export { readdirSync }
export { readFileSync }
export { writeFileSync }
}
export default _default
4 changes: 4 additions & 0 deletions sync.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import * as fsSync from "fs"

// Adding new function:
// 1. add `export const ...` here
// 2. add it to `export default { ... }`
// 3. add it to `sync.d.ts` (twice)
export const readdirSync = wrapSync("readdirSync")
export const readFileSync = wrapSync("readFileSync")
export const writeFileSync = wrapSync("writeFileSync")
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"target": "es2021",
"module": "ES2020",
"allowJs": true,
"declaration": true,
"emitDeclarationOnly": true,
"declaration": false,
"noEmit": true,
"strict": false,
"skipLibCheck": false
},
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
node-fetch "^2.6.1"
open "^8.2.1"

"@types/node@^16.9.1":
version "16.9.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.9.1.tgz#0611b37db4246c937feef529ddcc018cf8e35708"
integrity sha512-QpLcX9ZSsq3YYUUnD3nFDY8H7wctAhQj/TFKL8Ya8v5fMm3CFXxo8zStsLAl780ltoYoo1WvKUVGBQK+1ifr7g==
"@types/node@14.13.1":
version "14.11.11"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.11.11.tgz#359ea52236b5ccc04a71d4001c8467178a9d3699"
integrity sha512-UcaAZrL8uO5GNS+NLxkYg1RiOMgdLxCXGqs+TTupltXN8rTvUEKTOpqCV3tlcAIZJXzcBQajzmjdrvuPvnuMUw==

define-lazy-prop@^2.0.0:
version "2.0.0"
Expand Down

0 comments on commit 70a25d5

Please sign in to comment.