-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update all the stuff #80
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
env: | ||
FORCE_COLOR: 2 | ||
|
||
jobs: | ||
test: | ||
name: Node ${{ matrix.node }} on ${{ matrix.os }} | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
node: [12, 14, 16, 18] | ||
os: [ubuntu-latest, windows-latest] | ||
|
||
steps: | ||
- name: Clone repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
|
||
- name: Install npm dependencies | ||
run: npm install | ||
|
||
- name: Run tests | ||
run: npm run test-ci |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
yarn.lock | ||
/coverage |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,17 @@ | ||
'use strict'; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const url = require('url'); | ||
const pify = require('pify'); | ||
const importLazy = require('import-lazy')(require); | ||
|
||
const binCheck = importLazy('bin-check'); | ||
const binVersionCheck = importLazy('bin-version-check'); | ||
const download = importLazy('download'); | ||
const osFilterObj = importLazy('os-filter-obj'); | ||
|
||
const statAsync = pify(fs.stat); | ||
const chmodAsync = pify(fs.chmod); | ||
import {promises as fs} from 'node:fs'; | ||
import path from 'node:path'; | ||
import binCheck from 'bin-check'; | ||
import binVersionCheck from 'bin-version-check'; | ||
import download from 'download'; | ||
import osFilterObject from 'os-filter-obj'; | ||
|
||
/** | ||
* Initialize a new `BinWrapper` | ||
* | ||
* @param {Object} options | ||
* @api public | ||
*/ | ||
module.exports = class BinWrapper { | ||
export default class BinWrapper { | ||
constructor(options = {}) { | ||
this.options = options; | ||
|
||
|
@@ -47,7 +39,7 @@ module.exports = class BinWrapper { | |
this._src.push({ | ||
url: src, | ||
os, | ||
arch | ||
arch, | ||
}); | ||
|
||
return this; | ||
|
@@ -138,8 +130,6 @@ module.exports = class BinWrapper { | |
if (this.version()) { | ||
return binVersionCheck(this.path(), this.version()); | ||
} | ||
|
||
return Promise.resolve(); | ||
}); | ||
} | ||
|
||
|
@@ -149,12 +139,12 @@ module.exports = class BinWrapper { | |
* @api private | ||
*/ | ||
findExisting() { | ||
return statAsync(this.path()).catch(error => { | ||
return fs.stat(this.path()).catch(error => { | ||
if (error && error.code === 'ENOENT') { | ||
return this.download(); | ||
} | ||
|
||
return Promise.reject(error); | ||
throw error; | ||
}); | ||
} | ||
|
||
|
@@ -164,45 +154,33 @@ module.exports = class BinWrapper { | |
* @api private | ||
*/ | ||
download() { | ||
const files = osFilterObj(this.src() || []); | ||
const urls = []; | ||
const files = osFilterObject(this.src() || []); | ||
|
||
if (files.length === 0) { | ||
return Promise.reject(new Error('No binary found matching your system. It\'s probably not supported.')); | ||
} | ||
|
||
files.forEach(file => urls.push(file.url)); | ||
const urls = []; | ||
for (const file of files) { | ||
urls.push(file.url); | ||
} | ||
|
||
return Promise.all(urls.map(url => download(url, this.dest(), { | ||
extract: true, | ||
strip: this.options.strip | ||
strip: this.options.strip, | ||
}))).then(result => { | ||
const resultingFiles = flatten(result.map((item, index) => { | ||
const resultingFiles = result.flatMap((item, index) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switched this to |
||
if (Array.isArray(item)) { | ||
return item.map(file => file.path); | ||
} | ||
|
||
const parsedUrl = url.parse(files[index].url); | ||
const parsedUrl = new URL(files[index].url); | ||
const parsedPath = path.parse(parsedUrl.pathname); | ||
|
||
return parsedPath.base; | ||
})); | ||
}); | ||
|
||
return Promise.all(resultingFiles.map(fileName => { | ||
return chmodAsync(path.join(this.dest(), fileName), 0o755); | ||
})); | ||
return Promise.all(resultingFiles.map(fileName => fs.chmod(path.join(this.dest(), fileName), 0o755))); | ||
}); | ||
} | ||
}; | ||
|
||
function flatten(arr) { | ||
return arr.reduce((acc, elem) => { | ||
if (Array.isArray(elem)) { | ||
acc.push(...elem); | ||
} else { | ||
acc.push(elem); | ||
} | ||
|
||
return acc; | ||
}, []); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,10 +10,18 @@ | |
"url": "https://github.com/kevva" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
"node": "^12.20.0 || ^14.14.0 || >=16.0.0" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
"ava": "ava", | ||
"xo": "xo", | ||
"test": "npm run xo && npm run ava", | ||
"test-ci": "npm run xo && c8 ava" | ||
}, | ||
"main": "index.js", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unsure if |
||
"type": "module", | ||
"exports": { | ||
".": "./index.js" | ||
}, | ||
"files": [ | ||
"index.js" | ||
|
@@ -24,21 +32,26 @@ | |
"local", | ||
"wrapper" | ||
], | ||
"c8": { | ||
"reporter": [ | ||
"lcovonly", | ||
"text" | ||
] | ||
}, | ||
"dependencies": { | ||
"bin-check": "^4.1.0", | ||
"bin-version-check": "^4.0.0", | ||
"download": "^7.1.0", | ||
"import-lazy": "^3.1.0", | ||
"os-filter-obj": "^2.0.0", | ||
"pify": "^4.0.1" | ||
"bin-version-check": "^5.0.0", | ||
"download": "^8.0.0", | ||
"os-filter-obj": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"ava": "^4.3.0", | ||
"c8": "^7.11.3", | ||
"executable": "^4.1.1", | ||
"nock": "^10.0.2", | ||
"path-exists": "^3.0.0", | ||
"rimraf": "^2.6.2", | ||
"tempy": "^0.2.1", | ||
"xo": "*" | ||
"nock": "^13.2.6", | ||
"path-exists": "^5.0.0", | ||
"rimraf": "^3.0.2", | ||
"tempy": "^2.0.0", | ||
"xo": "^0.49.0" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
index.js