Skip to content

Commit

Permalink
chore: remove debug dependency (nodejs#25)
Browse files Browse the repository at this point in the history
Part of: nodejs#19
  • Loading branch information
RafaelGSS authored and trivikr committed Nov 1, 2024
1 parent 7a6c304 commit 0c3247d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 58 deletions.
67 changes: 46 additions & 21 deletions is-vulnerable.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const { danger, allGood, bold, vulnerableWarning, separator } = require('./ascii')
const { request, stream, setGlobalDispatcher, Agent } = require('undici')
const EE = require('events')
const { request } = require('https')
const { pipeline } = require('stream')
const fs = require('fs')
const path = require('path')
const satisfies = require('semver/functions/satisfies')
const nv = require('@pkgjs/nv')

setGlobalDispatcher(new Agent({ connections: 20 }))

const CORE_RAW_URL = 'https://raw.githubusercontent.com/nodejs/security-wg/main/vuln/core/index.json'

let lastETagValue
Expand Down Expand Up @@ -38,28 +36,55 @@ function updateLastETag (etag) {
}

async function fetchCoreIndex () {
const abortRequest = new EE()
await stream(CORE_RAW_URL, { signal: abortRequest }, ({ statusCode }) => {
if (statusCode !== 200) {
console.error('Request to Github failed. Aborting...')
abortRequest.emit('abort')
process.nextTick(() => { process.exit(1) })
}
return fs.createWriteStream(coreLocalFile, { flags: 'w', autoClose: true })
await new Promise((resolve) => {
request(CORE_RAW_URL, (res) => {
if (res.statusCode !== 200) {
console.error('Request to Github failed. Aborting...')
process.nextTick(() => { process.exit(1) })
}

const file = fs.createWriteStream(coreLocalFile)
pipeline(res, file, (err) => {
if (err) {
console.error(`Problem with request: ${err.message}`)
process.nextTick(() => { process.exit(1) })
} else {
resolve()
}
})
})
})
return readLocal(coreLocalFile)
}

async function getCoreIndex () {
const { headers } = await request(CORE_RAW_URL, { method: 'HEAD' })
if (!lastETagValue || lastETagValue !== headers.etag || !fs.existsSync(coreLocalFile)) {
updateLastETag(headers.etag)
debug('Creating local core.json')
return fetchCoreIndex()
} else {
debug(`No updates from upstream. Getting a cached version: ${coreLocalFile}`)
return readLocal(coreLocalFile)
}
return new Promise((resolve) => {
const req = request(CORE_RAW_URL, { method: 'HEAD' }, (res) => {
if (res.statusCode !== 200) {
console.error('Request to Github failed. Aborting...')
process.nextTick(() => { process.exit(1) })
}

res.on('data', () => {})

const { etag } = res.headers
if (!lastETagValue || lastETagValue !== etag || !fs.existsSync(coreLocalFile)) {
updateLastETag(etag)
debug('Creating local core.json')
resolve(fetchCoreIndex())
} else {
debug(`No updates from upstream. Getting a cached version: ${coreLocalFile}`)
resolve(readLocal(coreLocalFile))
}
})

req.on('error', (e) => {
console.error(`Problem with request: ${e.message}`)
process.nextTick(() => { process.exit(1) })
})

req.end()
})
}

const checkPlatform = platform => {
Expand Down
37 changes: 2 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
"dependencies": {
"@actions/core": "^1.10.0",
"@pkgjs/nv": "^0.2.1",
"semver": "^7.3.8",
"undici": "^5.15.1"
"semver": "^7.3.8"
},
"devDependencies": {
"standard": "^17.0.0",
Expand Down

0 comments on commit 0c3247d

Please sign in to comment.