Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
22 changes: 12 additions & 10 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
name: Node.js CI

on: [push, pull_request]
on:
push:
pull_request:

jobs:
build:
strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
os: [ubuntu-latest, windows-latest, macOS-latest]
node-version: [22.x]
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
25 changes: 9 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,14 @@ typings/
# dotenv environment variables file
.env

# bundleDependencies
!node_modules/fs-extra/*
!node_modules/gunzip-maybe/*
!node_modules/is-root/*
!node_modules/node-gyp/*
!node_modules/npm-package-arg/*
!node_modules/npm-path/*
!node_modules/promise-each/*
!node_modules/request/*
!node_modules/semver/*
!node_modules/tar-fs/*
!node_modules/tar-stream/*
!node_modules/update-notifier/*
!node_modules/which/*
!node_modules/yargs/*

# dep
__pycache__

# Standard cache
.cache/

# Tap test artifacts
.tap/

# Temporary home directory
.tmp-home
10 changes: 6 additions & 4 deletions bin/dep.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const semver = require('semver')
const yargs = require('yargs')
const updateNotifier = require('update-notifier')
const updateNotifier = require('update-notifier').default
const commands = {
install: require('../lib/install'),
lock: require('../lib/lock'),
Expand All @@ -11,9 +11,11 @@ const commands = {
const pkgJSON = require('../package.json')
const notifier = updateNotifier({ pkg: pkgJSON })

if (!semver.satisfies(process.version, pkgJSON.engine.node)) {
process.stderr.write('dep works only on Node.js LTS versions\n')
process.stderr.write('See the schedule: https://github.com/nodejs/LTS#lts-schedule1\n')
const allowLegacyNode = ['1', 'true', 'yes'].includes((process.env.DEP_ALLOW_OLD_NODE || '').toLowerCase())

if (!allowLegacyNode && !semver.satisfies(process.version, pkgJSON.engine.node)) {
process.stderr.write(`dep requires Node.js ${pkgJSON.engine.node} (detected ${process.version})\n`)
process.stderr.write('Upgrade Node.js to continue.\n')
process.exit(1)
}

Expand Down
4 changes: 2 additions & 2 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const install = (argv) => {
'devDependencies'
]
}
var deps = Object.assign({}, optionalDependencies)
const deps = Object.assign({}, optionalDependencies)
allDependencies[only].forEach((key) => {
if (!pkgJSON[key]) return
Object.assign(deps, pkgJSON[key])
Expand All @@ -53,7 +53,7 @@ const install = (argv) => {
global.nativeBuildQueue.forEach((cwd) => {
try {
process.stdout.write('Building dependencies\n')
nodeGyp({ cwd: cwd })
nodeGyp({ cwd })
} catch (e) {
// remove the pkg since the deps could be optional
fs.removeSync(cwd)
Expand Down
4 changes: 2 additions & 2 deletions lib/install/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const installer = (dep, deps, base, resolve, reject) => {
fs.ensureDirSync(target)

const pkg = deps[dep]
var fetch
let fetch

switch (pkg.type) {
case 'git':
Expand Down Expand Up @@ -55,7 +55,7 @@ const installer = (dep, deps, base, resolve, reject) => {
if (!pkg.dependencies) return resolve()
const tasks = Object.keys(pkg.dependencies).map((item) => {
const list = pkg.dependencies
var keys = [].concat(base, dep)
const keys = [].concat(base, dep)
if (keys.length > 1) keys.splice(-1, 0, 'node_modules')
return new Promise((resolve, reject) => {
installer(item, list, keys, resolve, reject)
Expand Down
6 changes: 3 additions & 3 deletions lib/install/installer/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module.exports = (pkg, cwd) => {

git.sync(['clone', url, cwd, '--quiet'])
if (!fs.pathExistsSync(path.join(cwd, '.gitmodules'))) {
return git(['checkout', hash, '--quiet'], { cwd: cwd })
return git(['checkout', hash, '--quiet'], { cwd })
}
git.sync(['checkout', hash, '--quiet'], { cwd: cwd })
return git(['submodule', 'update', '--init', '--recursive', '--quiet'], { cwd: cwd })
git.sync(['checkout', hash, '--quiet'], { cwd })
return git(['submodule', 'update', '--init', '--recursive', '--quiet'], { cwd })
}
20 changes: 6 additions & 14 deletions lib/install/installer/registry.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
const request = require('request')
const tar = require('tar-fs')
const gunzip = require('gunzip-maybe')
const npmrc = require('../../utils/npmrc')
const { pipeline } = require('node:stream/promises')
const { requestStream } = require('../../utils/http')

module.exports = (pkg, cwd) => {
const options = {
url: pkg.tarball,
module.exports = async (pkg, cwd) => {
const extract = tar.extract(cwd, { strip: 1 })
const { stream } = await requestStream(pkg.tarball, {
headers: {
'User-Agent': npmrc.userAgent
}
}
return new Promise((resolve, reject) => {
const extract = tar.extract(cwd, { strip: 1 })
extract.on('finish', () => {
resolve()
})
request.get(options)
.pipe(gunzip())
.pipe(extract)
.on('error', reject)
})
await pipeline(stream, gunzip(), extract)
}
20 changes: 6 additions & 14 deletions lib/install/installer/remote.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
const request = require('request')
const tar = require('tar-fs')
const gunzip = require('gunzip-maybe')
const npmrc = require('../../utils/npmrc')
const { pipeline } = require('node:stream/promises')
const { requestStream } = require('../../utils/http')

module.exports = (pkg, cwd) => {
const options = {
url: pkg.url,
module.exports = async (pkg, cwd) => {
const extract = tar.extract(cwd, { strip: 1 })
const { stream } = await requestStream(pkg.url, {
headers: {
'User-Agent': npmrc.userAgent
}
}
return new Promise((resolve, reject) => {
const extract = tar.extract(cwd, { strip: 1 })
extract.on('finish', () => {
resolve()
})
request.get(options)
.pipe(gunzip())
.pipe(extract)
.on('error', reject)
})
await pipeline(stream, gunzip(), extract)
}
6 changes: 3 additions & 3 deletions lib/install/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const resolver = (dep, deps, base, resolve, reject) => {
return resolve()
}
}
for (var i = 0; base.length > i; i += 2) {
var target = tree.getter(global.dependenciesTree, base.slice(0, i))
for (let i = 0; base.length > i; i += 2) {
const target = tree.getter(global.dependenciesTree, base.slice(0, i))
if (target && target[dep] && target[dep].version) {
if (semver.satisfies(target[dep].version, deps[dep])) {
return resolve()
Expand All @@ -30,7 +30,7 @@ const resolver = (dep, deps, base, resolve, reject) => {

const tasks = Object.keys(pkg.dependencies).map((item) => {
const list = pkg.dependencies
var keys = base.length === 0
const keys = base.length === 0
? [].concat(`${dep}@${pkg.version}`)
: [].concat(base, 'dependencies', `${dep}@${pkg.version}`)
return new Promise((resolve, reject) => {
Expand Down
86 changes: 37 additions & 49 deletions lib/install/resolver/fetchers/git.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const request = require('request')
const npmrc = require('../../../utils/npmrc')
const git = require('../../../utils/git')
const semver = require('semver')
const { requestJson } = require('../../../utils/http')

const filetemplate = (hosted) => {
return hosted.filetemplate
Expand All @@ -23,54 +23,42 @@ const httpstemplate = (hosted, committish) => {
.replace('{#committish}', committish ? '#' + hosted.committish : '')
}

module.exports = (name, spec, result) => {
var hosted = result.hosted
return new Promise((resolve, reject) => {
if (!hosted.committish) {
hosted.committish = git.sync(['ls-remote', httpstemplate(hosted), 'HEAD'])
.slice(0, 6)
} else if (hosted.committish.startsWith('semver:')) {
const range = hosted.committish.replace('semver:', '')
const list = git.sync(['ls-remote', '--tags', httpstemplate(hosted)])
.split('\n')
list.forEach((str) => {
if (str.split('\t').length === 1) return
const hash = str.split('\t')[0].slice(0, 6)
const version = str.split('\t')[1].replace('refs/tags/', '')
if (version.match(/\^\{\}/)) return
if (!semver.valid(version)) return
if (semver.satisfies(version, range)) hosted.committish = hash
})
} else {
const committish = git.sync(['ls-remote', '--tags', httpstemplate(hosted)])
.split('\n')
.filter((str, i) => {
return str.indexOf(hosted.committish) !== -1
}).pop()
hosted.committish = committish
? committish.split('\t')[0]
: hosted.committish
module.exports = async (name, spec, result) => {
const hosted = result.hosted
if (!hosted.committish) {
hosted.committish = git.sync(['ls-remote', httpstemplate(hosted), 'HEAD'])
.slice(0, 6)
} else if (hosted.committish.startsWith('semver:')) {
const range = hosted.committish.replace('semver:', '')
const list = git.sync(['ls-remote', '--tags', httpstemplate(hosted)])
.split('\n')
list.forEach((str) => {
if (str.split('\t').length === 1) return
const hash = str.split('\t')[0].slice(0, 6)
const version = str.split('\t')[1].replace('refs/tags/', '')
if (version.match(/\^\{\}/)) return
if (!semver.valid(version)) return
if (semver.satisfies(version, range)) hosted.committish = hash
})
} else {
const committish = git.sync(['ls-remote', '--tags', httpstemplate(hosted)])
.split('\n')
.filter((str) => {
return str.indexOf(hosted.committish) !== -1
}).pop()
hosted.committish = committish
? committish.split('\t')[0]
: hosted.committish
}
const body = await requestJson(filetemplate(hosted), {
headers: {
'User-Agent': npmrc.userAgent
}
const options = {
url: filetemplate(hosted),
headers: {
'User-Agent': npmrc.userAgent
}
}
var body = ''
request.get(options)
.on('data', (chunk) => { body += chunk })
.on('end', () => {
try {
body = JSON.parse(body)
resolve({
type: 'git',
version: body.version,
dependencies: body.dependencies,
url: httpstemplate(hosted, true)
})
} catch (e) { return reject(e) }
})
.on('error', reject)
})
return {
type: 'git',
version: body.version,
dependencies: body.dependencies,
url: httpstemplate(hosted, true)
}
}
61 changes: 26 additions & 35 deletions lib/install/resolver/fetchers/registry.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,32 @@
const request = require('request')
const semver = require('semver')
const npmrc = require('../../../utils/npmrc')
const { requestJson } = require('../../../utils/http')

module.exports = (name, spec, result) => {
return new Promise((resolve, reject) => {
const options = {
url: npmrc.registry + result.escapedName,
headers: {
'User-Agent': npmrc.userAgent
}
module.exports = async (name, spec, result) => {
const body = await requestJson(npmrc.registry + result.escapedName, {
headers: {
'User-Agent': npmrc.userAgent
}
var body = ''
request.get(options)
.on('data', (chunk) => { body += chunk })
.on('end', () => {
try {
body = JSON.parse(body)
const versions = Object.keys(body.versions)
const version = versions.reduce((accumulator, currentValue) => {
if (semver.satisfies(accumulator, spec)) return accumulator
return currentValue
}, '')
const target = body.versions[version]
if (target.deprecated) {
process.stdout.write(
`${target.name}@${target.version}: ${target.deprecated}\n\n`
)
}
resolve({
type: 'registry',
version: target.version,
dependencies: target.dependencies,
tarball: target.dist.tarball,
shasum: target.dist.shasum
})
} catch (e) { return reject(e) }
})
.on('error', reject)
})
const versions = Object.keys(body.versions)
const version = versions.reduce((accumulator, currentValue) => {
if (semver.satisfies(accumulator, spec)) return accumulator
return currentValue
}, '')
const target = body.versions[version]
if (!target) {
throw new Error(`Unable to resolve ${name}@${spec || 'latest'} from registry ${npmrc.registry}`)
}
if (target.deprecated) {
process.stdout.write(
`${target.name}@${target.version}: ${target.deprecated}\n\n`
)
}
return {
type: 'registry',
version: target.version,
dependencies: target.dependencies,
tarball: target.dist.tarball,
shasum: target.dist.shasum
}
}
Loading
Loading