Skip to content

Commit

Permalink
fix: types
Browse files Browse the repository at this point in the history
  • Loading branch information
zaaack committed Oct 20, 2022
1 parent 4706be9 commit 64bb07b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
16 changes: 10 additions & 6 deletions src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { debounce, Is, promiseQueue } from './utils'
const ENOENT = 'ENOENT' // not found
const EEXIST = 'EEXIST'



export type WriteOptions= _fs.WriteFileOptions

async function copy(
src: string,
dist: string,
Expand Down Expand Up @@ -84,7 +88,7 @@ function watchDir(
if (process.platform === 'linux') {
// tslint:disable-next-line:no-floating-promises
fs.iter(dir, (file) => {
fs.watch(
_fs.watch(
file,
{
recursive: false,
Expand All @@ -94,7 +98,7 @@ function watchDir(
)
})
} else {
fs.watch(dir, { recursive: true, persistent: options.persistent }, cb)
_fs.watch(dir, { recursive: true, persistent: options.persistent }, cb)
}
}
export const fs = {
Expand Down Expand Up @@ -229,12 +233,12 @@ export const fs = {
await fs.unlink(path)
}
},
async outputFile(path: string, data: any, options?: Parameters<typeof _fs.promises.writeFile>[2]) {
async outputFile(path: string, data: any, options?: WriteOptions) {
let dir = pathLib.dirname(path)
await fs.mkdirp(dir)
return fs.writeFile(path, data, options)
},
outputFileSync(path: string, data: any, options?: Parameters<typeof _fs.writeFileSync>[2]) {
outputFileSync(path: string, data: any, options?: WriteOptions) {
let dir = pathLib.dirname(path)
fs.mkdirpSync(dir)
return fs.writeFileSync(path, data, options)
Expand All @@ -245,7 +249,7 @@ export const fs = {
options?: {
space?: number
replacer?: (key: string, value: any) => any
} & Parameters<typeof _fs.promises.writeFile>[2],
} & WriteOptions,
) {
const [replacer, space] = Is.obj(options) ? [options.replacer, options.space] : [void 0, void 0]
return fs.outputFile(path, JSON.stringify(data, replacer, space), options)
Expand All @@ -256,7 +260,7 @@ export const fs = {
options?: {
space?: number
replacer?: (key: string, value: any) => any
} & Parameters<typeof _fs.writeFileSync>[2],
} & WriteOptions,
) {
const [replacer, space] = Is.obj(options) ? [options.replacer, options.space] : [void 0, void 0]
return fs.outputFileSync(path, JSON.stringify(data, replacer, space), options)
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './exec'
export * from './fs'
export * from './logger'
export { dep } from './dep-builder'
export { task, desc, option, strict, setOption, setGlobalOptions, Dependency, Task, TaskFn, TaskDep, namespace, before, after, onerror } from './task'
export { task, desc, option, strict, setOption, setGlobalOptions, namespace, before, after, onerror } from './task'
export type { Dependency, Task, TaskFn, TaskDep }from './task'
export { sleep, debounce as throttle, defaults, Is } from './utils'
export { GlobalOptions } from './task-manager'
export type { GlobalOptions } from './task-manager'
Empty file removed src/test/utils.ts
Empty file.
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// "noEmit": true, /* Do not emit outputs. */
"importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
"isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@
resolved "https://registry.npm.taobao.org/@types/marked/download/@types/marked-1.1.0.tgz#53509b5f127e0c05c19176fcf1d743a41e00ff19"
integrity sha1-U1CbXxJ+DAXBkXb88ddDpB4A/xk=

"@types/node@^14.11.2":
version "14.11.2"
resolved "https://registry.npm.taobao.org/@types/node/download/@types/node-14.11.2.tgz#2de1ed6670439387da1c9f549a2ade2b0a799256"
integrity sha1-LeHtZnBDk4faHJ9UmireKwp5klY=
"@types/node@^18.11.2":
version "18.11.2"
resolved "https://registry.npmmirror.com/@types/node/-/node-18.11.2.tgz#c59b7641832531264fda3f1ba610362dc9a7dfc8"
integrity sha512-BWN3M23gLO2jVG8g/XHIRFWiiV4/GckeFIqbU/C4V3xpoBBWSMk4OZomouN0wCkfQFPqgZikyLr7DOYDysIkkw==

ansi-regex@^5.0.0:
version "5.0.0"
Expand Down

0 comments on commit 64bb07b

Please sign in to comment.