Skip to content

Commit

Permalink
feat: use tinyspawn (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats authored Dec 14, 2023
1 parent 339ec49 commit c8eb5ba
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Any flag supported by `yt-dlp`.

#### options

Any option provided here will passed to [execa#options](https://github.com/sindresorhus/execa#options).
Any option provided here will passed to [spawn#options](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options).

### youtubedl.exec(url, [flags], [options])

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@
"dependencies": {
"bin-version-check": "~5.1.0",
"dargs": "~7.0.0",
"execa": "~5.1.1",
"is-unix": "~2.0.1",
"simple-get": "~4.0.1"
"simple-get": "~4.0.1",
"tinyspawn": "~1.2.1"
},
"devDependencies": {
"@commitlint/cli": "latest",
Expand Down
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict'

const dargs = require('dargs')
const execa = require('execa')
const $ = require('tinyspawn')

const constants = require('./constants')

const args = (url, flags = {}) =>
[].concat(url, dargs(flags, { useEquals: false })).filter(Boolean)
const args = (flags = {}) =>
dargs(flags, { useEquals: false }).filter(Boolean)

const isJSON = (str = '') => str.startsWith('{')

Expand All @@ -18,7 +18,7 @@ const parse = ({ stdout, stderr, ...details }) => {
const create = binaryPath => {
const fn = (url, flags, opts) =>
fn.exec(url, flags, opts).then(parse).catch(parse)
fn.exec = (url, flags, opts) => execa(binaryPath, args(url, flags), opts)
fn.exec = (url, flags, opts) => $(binaryPath, [url].concat(args(flags)), opts)
return fn
}

Expand Down
7 changes: 3 additions & 4 deletions test/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ const test = require('ava')
const { args } = require('..')

test('no flags', t => {
const flags = args('https://example.com')
t.deepEqual(flags, ['https://example.com'])
const flags = args()
t.deepEqual(flags, [])
})

test('parse arguments into flags', t => {
const flags = args('https://example.com', {
const flags = args({
noWarnings: true,
noCheckCertificate: true,
preferFreeFormats: true,
Expand All @@ -20,7 +20,6 @@ test('parse arguments into flags', t => {
})

t.deepEqual(flags, [
'https://example.com',
'--no-warnings',
'--no-check-certificate',
'--prefer-free-formats',
Expand Down
5 changes: 3 additions & 2 deletions test/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ const test = require('ava')

const youtubedl = require('..')

test('show help', async t => {
await t.throwsAsync(youtubedl(), { instanceOf: Error })
test('no url', async t => {
const error = await t.throwsAsync(youtubedl(''), { instanceOf: Error })
t.is(error.exitCode, 2)
})

test('unsupported URLs', async t => {
Expand Down
3 changes: 0 additions & 3 deletions test/snapshots/exec.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,4 @@ Generated by [AVA](https://avajs.dev).
'stdout',
'stderr',
'stdio',
'kill',
'cancel',
'all',
]
Binary file modified test/snapshots/exec.js.snap
Binary file not shown.

0 comments on commit c8eb5ba

Please sign in to comment.