Skip to content

Commit

Permalink
feat: move preinstall command into a separate script (#143)
Browse files Browse the repository at this point in the history
It's more flexible and offer granular error handling than run a npx command wrapped by bash
  • Loading branch information
Kikobeats committed Mar 3, 2023
1 parent c6cfc30 commit 54125f3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"youtube-downloader"
],
"dependencies": {
"bin-version-check": "~5.0.0",
"dargs": "~7.0.0",
"execa": "~5.1.0",
"is-unix": "~2.0.1",
Expand Down Expand Up @@ -137,7 +138,7 @@
"lint": "standard",
"postinstall": "node scripts/postinstall.js",
"postrelease": "npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)",
"preinstall": "[[ -n \"${YOUTUBE_DL_SKIP_PYTHON_CHECK}\" ]] || (npx bin-version-check-cli python3 \"> =3.7\" || npx bin-version-check-cli python \"> =3.7\")",
"preinstall": "node scripts/preinstall.mjs",
"prerelease": "npm run update:check",
"pretest": "npm run lint",
"release": "standard-version -a",
Expand Down
20 changes: 20 additions & 0 deletions scripts/preinstall.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import binaryVersionCheck from 'bin-version-check'

const throwError = error => {
throw new Error(
`youtube-dl-exec needs Python. ${error.message}. You can skip this check passing \`YOUTUBE_DL_SKIP_PYTHON_CHECK=1\``
)
}

const pReflect = p =>
Promise.resolve(p)
.then(() => ({ isError: false }))
.catch(error => ({ isError: true, error }))

if (process.env.YOUTUBE_DL_SKIP_PYTHON_CHECK !== undefined) process.exit(0)

let result = await pReflect(binaryVersionCheck('python3', '>=3.7'))
if (!result.isError) process.exit(0)

result = await pReflect(binaryVersionCheck('python', '>=3.7'))
if (result.isError) throwError(result.error)

0 comments on commit 54125f3

Please sign in to comment.