Skip to content

Commit

Permalink
fix: types (#197)
Browse files Browse the repository at this point in the history
closes #196
  • Loading branch information
Kikobeats authored Jun 19, 2024
1 parent 33dcbc3 commit 2a152c1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"dargs": "~7.0.0",
"debug-logfmt": "~1.2.2",
"is-unix": "~2.0.10",
"tinyspawn": "~1.2.9"
"tinyspawn": "~1.3.1"
},
"devDependencies": {
"@commitlint/cli": "latest",
Expand Down
5 changes: 3 additions & 2 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ChildProcess, SpawnOptions } from 'child_process';
import { SpawnOptions } from 'child_process';
import { SubprocessPromise } from 'tinyspawn';

export type Payload = {
id: string;
Expand Down Expand Up @@ -391,7 +392,7 @@ export type Flags = {
youtubeSkipDashManifest?: boolean
}

export type Exec = (url: string, flags?: Flags, options?: SpawnOptions) => ChildProcess
export type Exec = (url: string, flags?: Flags, options?: SpawnOptions) => SubprocessPromise
export type Create = (binaryPath: string) => { (url: string, flags?: Flags, options?: SpawnOptions): Promise<Payload>; exec: Exec }
export const youtubeDl: ((...args: Parameters<Exec>) => Promise<Payload>) & { exec: Exec, create: Create }

Expand Down
15 changes: 11 additions & 4 deletions test/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ await youtubedl('https://www.youtube.com/watch?v=6xKWiCMKKJg', {
addHeader: ['referer:youtube.com', 'user-agent:googlebot']
})

youtubedl.exec('https://www.youtube.com/watch?v=6xKWiCMKKJg')
youtubedl.exec('https://www.youtube.com/watch?v=6xKWiCMKKJg', { dumpSingleJson: true })
youtubedl.exec('https://www.youtube.com/watch?v=6xKWiCMKKJg', { dumpSingleJson: true }, { shell: true, killSignal: 'SIGKILL', timeout: 3000 })
/* exec */

youtubedl.create('mypath')
const promise = youtubedl.exec('https://www.youtube.com/watch?v=6xKWiCMKKJg')

promise.kill()
promise.ref()
promise.unref()

const result = await promise

console.log(result.stdout)
console.log(result.stderr)

0 comments on commit 2a152c1

Please sign in to comment.