Compare commits
27 Commits
+28
-29
@@ -1,42 +1,41 @@
|
|||||||
root: true
|
root: true
|
||||||
parser: "@typescript-eslint/parser"
|
parser: '@typescript-eslint/parser'
|
||||||
parserOptions:
|
parserOptions:
|
||||||
project: tsconfig.json
|
project: tsconfig.json
|
||||||
plugins:
|
plugins:
|
||||||
- "@typescript-eslint"
|
- '@typescript-eslint'
|
||||||
- prettier
|
- prettier
|
||||||
extends:
|
extends:
|
||||||
- eslint:recommended
|
- eslint:recommended
|
||||||
- plugin:@typescript-eslint/eslint-recommended
|
|
||||||
- plugin:@typescript-eslint/recommended
|
- plugin:@typescript-eslint/recommended
|
||||||
- plugin:@typescript-eslint/recommended-requiring-type-checking
|
- plugin:@typescript-eslint/recommended-requiring-type-checking
|
||||||
- prettier/@typescript-eslint
|
|
||||||
- plugin:prettier/recommended
|
- plugin:prettier/recommended
|
||||||
rules:
|
rules:
|
||||||
"prettier/prettier":
|
'prettier/prettier': [1]
|
||||||
|
'@typescript-eslint/array-type': [1, { default: array-simple }]
|
||||||
|
'@typescript-eslint/explicit-function-return-type':
|
||||||
|
- 2
|
||||||
|
- allowExpressions: true
|
||||||
|
'@typescript-eslint/no-extraneous-class':
|
||||||
- 1
|
- 1
|
||||||
- singleQuote: true
|
- allowWithDecorator: true
|
||||||
trailingComma: all
|
allowStaticOnly: true
|
||||||
tabWidth: 4
|
'@typescript-eslint/no-parameter-properties':
|
||||||
endOfLine: lf
|
|
||||||
printWidth: 160
|
|
||||||
- usePrettierrc: false
|
|
||||||
"@typescript-eslint/array-type": [1, { default: array-simple }]
|
|
||||||
"@typescript-eslint/explicit-function-return-type":
|
|
||||||
[2, { allowExpressions: true }]
|
|
||||||
"@typescript-eslint/no-extra-non-null-assertion": [2]
|
|
||||||
"@typescript-eslint/no-extraneous-class": [1, { allowWithDecorator: true, allowStaticOnly: true }]
|
|
||||||
"@typescript-eslint/no-floating-promises": [1]
|
|
||||||
"@typescript-eslint/no-parameter-properties":
|
|
||||||
- 1
|
- 1
|
||||||
- allows:
|
- allows: [protected readonly, private readonly, public readonly, readonly]
|
||||||
- protected readonly
|
'@typescript-eslint/no-throw-literal': [2]
|
||||||
- private readonly
|
'no-unused-vars': [0]
|
||||||
- public readonly
|
'@typescript-eslint/no-unused-vars':
|
||||||
- readonly
|
- 1
|
||||||
"@typescript-eslint/no-throw-literal": [2]
|
- varsIgnorePattern: ^_
|
||||||
"no-unused-vars": [0]
|
argsIgnorePattern: ^_
|
||||||
"@typescript-eslint/prefer-for-of": [1]
|
'@typescript-eslint/prefer-for-of': [1]
|
||||||
"@typescript-eslint/prefer-function-type": [1]
|
'@typescript-eslint/prefer-function-type': [1]
|
||||||
"@typescript-eslint/prefer-nullish-coalescing": [1]
|
'@typescript-eslint/prefer-nullish-coalescing': [1]
|
||||||
"@typescript-eslint/prefer-optional-chain": [1]
|
'@typescript-eslint/prefer-optional-chain': [1]
|
||||||
|
'@typescript-eslint/ban-types':
|
||||||
|
- 1
|
||||||
|
- types:
|
||||||
|
object: false
|
||||||
|
no-void: [1, { allowAsStatement: true }]
|
||||||
|
eqeqeq: [1, smart]
|
||||||
|
|||||||
@@ -18,10 +18,11 @@ jobs:
|
|||||||
run: yarn test
|
run: yarn test
|
||||||
- name: release
|
- name: release
|
||||||
run: yarn release
|
run: yarn release
|
||||||
- name: "check for uncommitted changes"
|
- name: 'check for uncommitted changes'
|
||||||
# Ensure no changes
|
# Ensure no changes
|
||||||
run: |
|
run: |
|
||||||
git add . && git diff --exit-code --stat \
|
git add .
|
||||||
|| (echo "##[error] found changed files after build. please 'yarn build && npm run format'" \
|
if ! git diff --cached --color=always --exit-code -- . ':!node_modules'; then
|
||||||
"and check in all changes" \
|
echo "::error::Found changed files after build. Please run 'yarn release' and check in all changes."
|
||||||
&& exit 1)
|
exit 1
|
||||||
|
fi
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macOS-latest]
|
os: [ubuntu-latest, windows-latest, macOS-latest]
|
||||||
version: [latest, branch@master]
|
version: [latest, branch@master, branch@dev]
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
@@ -19,6 +19,7 @@ jobs:
|
|||||||
xmake-version: ${{ matrix.version }}
|
xmake-version: ${{ matrix.version }}
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: |
|
run: |
|
||||||
|
xmake --version
|
||||||
xmake create -P test
|
xmake create -P test
|
||||||
xmake build -P test
|
xmake build -P test
|
||||||
xmake run -P test
|
xmake run -P test
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
singleQuote: true
|
||||||
|
trailingComma: all
|
||||||
|
tabWidth: 2
|
||||||
|
endOfLine: lf
|
||||||
|
printWidth: 120
|
||||||
|
overrides:
|
||||||
|
- files:
|
||||||
|
- '*.js'
|
||||||
|
- '*.ts'
|
||||||
|
options:
|
||||||
|
tabWidth: 4
|
||||||
Vendored
+1
-7
@@ -1,12 +1,6 @@
|
|||||||
{
|
{
|
||||||
"npm.packageManager": "yarn",
|
"npm.packageManager": "yarn",
|
||||||
"eslint.validate": [
|
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact", "vue"],
|
||||||
"javascript",
|
|
||||||
"javascriptreact",
|
|
||||||
"typescript",
|
|
||||||
"typescriptreact",
|
|
||||||
"vue"
|
|
||||||
],
|
|
||||||
"eslint.enable": true,
|
"eslint.enable": true,
|
||||||
"files.autoSave": "off",
|
"files.autoSave": "off",
|
||||||
"eslint.format.enable": true,
|
"eslint.format.enable": true,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# GitHub Action - Setup xmake
|
# GitHub Action - Setup xmake
|
||||||
|
|
||||||
[](https://github.com/xmake-io/github-action-setup-xmake/actions)
|
[](https://github.com/xmake-io/github-action-setup-xmake/actions)
|
||||||
[](https://github.com/marketplace/actions/setup-xmake)
|
[](https://github.com/marketplace/actions/setup-xmake)
|
||||||
|
|
||||||
@@ -23,7 +24,7 @@ Use specified version:
|
|||||||
```yml
|
```yml
|
||||||
uses: xmake-io/github-action-setup-xmake@v1
|
uses: xmake-io/github-action-setup-xmake@v1
|
||||||
with:
|
with:
|
||||||
xmake-version: '2.3.1'
|
xmake-version: '2.5.3'
|
||||||
```
|
```
|
||||||
|
|
||||||
Use specified branch:
|
Use specified branch:
|
||||||
@@ -39,5 +40,5 @@ Use semver:
|
|||||||
```yml
|
```yml
|
||||||
uses: xmake-io/github-action-setup-xmake@v1
|
uses: xmake-io/github-action-setup-xmake@v1
|
||||||
with:
|
with:
|
||||||
xmake-version: '>=2.2.6 <=2.3.1'
|
xmake-version: '>=2.2.6 <=2.5.3'
|
||||||
```
|
```
|
||||||
|
|||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
# Security Policy
|
||||||
|
|
||||||
|
## Supported Versions
|
||||||
|
|
||||||
|
| Version | Supported |
|
||||||
|
| ------- | ------------------ |
|
||||||
|
| 1.0.x | :white_check_mark: |
|
||||||
|
|
||||||
|
<!--
|
||||||
|
| 5.0.x | :x: |
|
||||||
|
| 4.0.x | :white_check_mark: |
|
||||||
|
| < 4.0 | :x: |
|
||||||
|
-->
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
Use github issues to report a vulnerability.
|
||||||
@@ -14,4 +14,3 @@ inputs:
|
|||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
|
|
||||||
Vendored
+2
-7
@@ -22,21 +22,16 @@ async function lsRemote(repo) {
|
|||||||
const [ref, tag] = line.trim().split('\t');
|
const [ref, tag] = line.trim().split('\t');
|
||||||
if (ref && tag && tag.startsWith('refs/')) {
|
if (ref && tag && tag.startsWith('refs/')) {
|
||||||
const tagPath = tag.split('/').splice(1);
|
const tagPath = tag.split('/').splice(1);
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
let ldata = data;
|
||||||
let ldata = data; // eslint-disable-line @typescript-eslint/no-unsafe-assignment
|
|
||||||
for (let i = 0; i < tagPath.length - 1; i++) {
|
for (let i = 0; i < tagPath.length - 1; i++) {
|
||||||
const seg = tagPath[i];
|
const seg = tagPath[i];
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
||||||
if (typeof ldata[seg] === 'object') {
|
if (typeof ldata[seg] === 'object') {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
ldata = ldata[seg];
|
||||||
ldata = ldata[seg]; // eslint-disable-line @typescript-eslint/no-unsafe-assignment
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
||||||
ldata = ldata[seg] = {};
|
ldata = ldata[seg] = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
||||||
ldata[tagPath[tagPath.length - 1]] = ref;
|
ldata[tagPath[tagPath.length - 1]] = ref;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Vendored
+6
-3
@@ -9,10 +9,13 @@ const unix_install_1 = require("./unix-install");
|
|||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
const version = await versions_1.selectVersion();
|
const version = await versions_1.selectVersion();
|
||||||
if (os.platform() === 'win32' || os.platform() === 'cygwin')
|
if (os.platform() === 'win32' || os.platform() === 'cygwin') {
|
||||||
await win_install_1.winInstall(version);
|
const latest = await versions_1.selectVersion('latest');
|
||||||
else
|
await win_install_1.winInstall(version, latest);
|
||||||
|
}
|
||||||
|
else {
|
||||||
await unix_install_1.unixInstall(version);
|
await unix_install_1.unixInstall(version);
|
||||||
|
}
|
||||||
await exec_1.exec('xmake --version');
|
await exec_1.exec('xmake --version');
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
|||||||
Vendored
+27
-15
@@ -9,27 +9,39 @@ const os = require("os");
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
const semver = require("semver");
|
const semver = require("semver");
|
||||||
const git = require("./git");
|
const git = require("./git");
|
||||||
|
async function install(sourceDir, binDir) {
|
||||||
|
await exec_1.exec('make', ['build'], { cwd: sourceDir });
|
||||||
|
await exec_1.exec('make', ['install', `prefix=${binDir}`], { cwd: sourceDir });
|
||||||
|
}
|
||||||
async function unixInstall(version) {
|
async function unixInstall(version) {
|
||||||
const ver = version.version;
|
let toolDir;
|
||||||
let toolDir = toolCache.find('xmake', ver);
|
if (version.type !== 'local') {
|
||||||
if (!toolDir) {
|
const ver = version.version;
|
||||||
const sourceDir = await core.group(`download xmake ${String(version)}`, () => git.create(version.repo, version.sha));
|
toolDir = toolCache.find('xmake', ver);
|
||||||
toolDir = await core.group(`install xmake ${String(version)}`, async () => {
|
if (!toolDir) {
|
||||||
await exec_1.exec('make', ['build'], { cwd: sourceDir });
|
const sourceDir = await core.group(`download xmake ${String(version)}`, () => git.create(version.repo, version.sha));
|
||||||
const binDir = path.join(os.tmpdir(), `xmake-${version.sha}`);
|
toolDir = await core.group(`install xmake ${String(version)}`, async () => {
|
||||||
await exec_1.exec('make', ['install', `prefix=${binDir}`], { cwd: sourceDir });
|
const binDir = path.join(os.tmpdir(), `xmake-${version.sha}`);
|
||||||
const cacheDir = await toolCache.cacheDir(binDir, 'xmake', ver);
|
await install(sourceDir, binDir);
|
||||||
await io.rmRF(binDir);
|
const cacheDir = await toolCache.cacheDir(binDir, 'xmake', ver);
|
||||||
await git.cleanup(version.sha);
|
await io.rmRF(binDir);
|
||||||
return cacheDir;
|
await git.cleanup(version.sha);
|
||||||
|
return cacheDir;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
toolDir = await core.group(`install local xmake at '${version.path}'`, async () => {
|
||||||
|
const binDir = path.join(os.tmpdir(), `xmake-${Date.now()}`);
|
||||||
|
await install(version.path, binDir);
|
||||||
|
return binDir;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// for versions 2.3.2 and above, xmake will be installed directly into the bin directory, and no script will be used to wrap it.
|
if (version.type !== 'tags' || semver.gt(version.version, '2.3.1')) {
|
||||||
if (version.type !== 'tags' || semver.gt(ver, '2.3.1')) {
|
|
||||||
core.addPath(path.join(toolDir, 'bin'));
|
core.addPath(path.join(toolDir, 'bin'));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
core.addPath(path.join(toolDir, 'share', 'xmake')); // only for <= 2.3.1
|
core.addPath(path.join(toolDir, 'share', 'xmake'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.unixInstall = unixInstall;
|
exports.unixInstall = unixInstall;
|
||||||
|
|||||||
Vendored
+26
-14
@@ -19,6 +19,7 @@ const core = require("@actions/core");
|
|||||||
const semver = require("semver");
|
const semver = require("semver");
|
||||||
const git_1 = require("./git");
|
const git_1 = require("./git");
|
||||||
const interfaces_1 = require("./interfaces");
|
const interfaces_1 = require("./interfaces");
|
||||||
|
const p = require("path");
|
||||||
const DEFAULT_REPO = interfaces_1.Repo('xmake-io/xmake');
|
const DEFAULT_REPO = interfaces_1.Repo('xmake-io/xmake');
|
||||||
const VERSIONS = new Map();
|
const VERSIONS = new Map();
|
||||||
async function getVersions(repo) {
|
async function getVersions(repo) {
|
||||||
@@ -29,7 +30,7 @@ async function getVersions(repo) {
|
|||||||
VERSIONS.set(repo, result);
|
VERSIONS.set(repo, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
class VersionImpl {
|
class GitVersionImpl {
|
||||||
constructor(repo, version, sha, type, toString) {
|
constructor(repo, version, sha, type, toString) {
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
@@ -43,10 +44,17 @@ class VersionImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_string = new WeakMap();
|
_string = new WeakMap();
|
||||||
|
class LocalVersionImpl {
|
||||||
|
constructor(path) {
|
||||||
|
this.path = path;
|
||||||
|
this.type = 'local';
|
||||||
|
this.path = p.resolve(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
async function selectBranch(repo, branch) {
|
async function selectBranch(repo, branch) {
|
||||||
const versions = await getVersions(repo);
|
const versions = await getVersions(repo);
|
||||||
if (branch in versions.heads) {
|
if (branch in versions.heads) {
|
||||||
return new VersionImpl(repo, branch, versions.heads[branch], 'heads', `branch ${branch}`);
|
return new GitVersionImpl(repo, branch, versions.heads[branch], 'heads', `branch ${branch}`);
|
||||||
}
|
}
|
||||||
throw new Error(`Branch ${branch} not found`);
|
throw new Error(`Branch ${branch} not found`);
|
||||||
}
|
}
|
||||||
@@ -54,16 +62,15 @@ async function selectPr(repo, pr) {
|
|||||||
var _a;
|
var _a;
|
||||||
const versions = await getVersions(repo);
|
const versions = await getVersions(repo);
|
||||||
if (pr in versions.pull) {
|
if (pr in versions.pull) {
|
||||||
const prheads = versions.pull[pr];
|
const prHeads = versions.pull[pr];
|
||||||
const sha = (_a = prheads.merge) !== null && _a !== void 0 ? _a : prheads.head;
|
const sha = (_a = prHeads.merge) !== null && _a !== void 0 ? _a : prHeads.head;
|
||||||
if (sha) {
|
if (sha) {
|
||||||
return new VersionImpl(repo, `pr#${pr}`, sha, 'pull', `pull request #${pr}`);
|
return new GitVersionImpl(repo, `pr#${pr}`, sha, 'pull', `pull request #${pr}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Error(`Pull requrest #${pr} not found`);
|
throw new Error(`Pull requrest #${pr} not found`);
|
||||||
}
|
}
|
||||||
async function selectSemver(repo, version) {
|
async function selectSemver(repo, version) {
|
||||||
// check version valid
|
|
||||||
const v = new semver.Range(version);
|
const v = new semver.Range(version);
|
||||||
if (!v) {
|
if (!v) {
|
||||||
throw new Error(`Invalid semver`);
|
throw new Error(`Invalid semver`);
|
||||||
@@ -74,7 +81,7 @@ async function selectSemver(repo, version) {
|
|||||||
throw new Error(`No matched releases of xmake-version ${v.format()}`);
|
throw new Error(`No matched releases of xmake-version ${v.format()}`);
|
||||||
}
|
}
|
||||||
const sha = versions.tags[ver];
|
const sha = versions.tags[ver];
|
||||||
return new VersionImpl(repo, ver, sha, 'tags', ver);
|
return new GitVersionImpl(repo, ver, sha, 'tags', ver);
|
||||||
}
|
}
|
||||||
async function selectSha(repo, sha) {
|
async function selectSha(repo, sha) {
|
||||||
var _a;
|
var _a;
|
||||||
@@ -96,15 +103,18 @@ async function selectSha(repo, sha) {
|
|||||||
return selectPr(repo, Number.parseInt(pr));
|
return selectPr(repo, Number.parseInt(pr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Promise.resolve(new VersionImpl(repo, `sha#${shaValue}`, shaValue, 'sha', `commit ${shaValue.substr(0, 8)}`));
|
return Promise.resolve(new GitVersionImpl(repo, `sha#${shaValue}`, shaValue, 'sha', `commit ${shaValue.substr(0, 8)}`));
|
||||||
}
|
}
|
||||||
async function selectVersion(version) {
|
async function selectVersion(version) {
|
||||||
// get version string
|
|
||||||
version = (version !== null && version !== void 0 ? version : core.getInput('xmake-version')) || 'latest';
|
version = (version !== null && version !== void 0 ? version : core.getInput('xmake-version')) || 'latest';
|
||||||
if (version.toLowerCase() === 'latest')
|
if (version.toLowerCase() === 'latest')
|
||||||
version = '';
|
version = '';
|
||||||
let repo = DEFAULT_REPO;
|
let repo = DEFAULT_REPO;
|
||||||
let ret;
|
let ret;
|
||||||
|
if (version.startsWith('local#')) {
|
||||||
|
const path = version.slice('local#'.length);
|
||||||
|
ret = new LocalVersionImpl(path);
|
||||||
|
}
|
||||||
{
|
{
|
||||||
const match = /^([^/#]+\/[^/#]+)#(.+)$/.exec(version);
|
const match = /^([^/#]+\/[^/#]+)#(.+)$/.exec(version);
|
||||||
if (match) {
|
if (match) {
|
||||||
@@ -112,12 +122,10 @@ async function selectVersion(version) {
|
|||||||
version = match[2];
|
version = match[2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// select branch
|
|
||||||
if (version.startsWith('branch@')) {
|
if (version.startsWith('branch@')) {
|
||||||
const branch = version.substr('branch@'.length);
|
const branch = version.substr('branch@'.length);
|
||||||
ret = await selectBranch(repo, branch);
|
ret = await selectBranch(repo, branch);
|
||||||
}
|
}
|
||||||
// select pr
|
|
||||||
if (version.startsWith('pr@')) {
|
if (version.startsWith('pr@')) {
|
||||||
const pr = Number.parseInt(version.substr('pr@'.length));
|
const pr = Number.parseInt(version.substr('pr@'.length));
|
||||||
if (Number.isNaN(pr) || pr <= 0) {
|
if (Number.isNaN(pr) || pr <= 0) {
|
||||||
@@ -125,19 +133,23 @@ async function selectVersion(version) {
|
|||||||
}
|
}
|
||||||
ret = await selectPr(repo, pr);
|
ret = await selectPr(repo, pr);
|
||||||
}
|
}
|
||||||
// select sha
|
|
||||||
if (version.startsWith('sha@')) {
|
if (version.startsWith('sha@')) {
|
||||||
const sha = version.substr('sha@'.length);
|
const sha = version.substr('sha@'.length);
|
||||||
ret = await selectSha(repo, sha);
|
ret = await selectSha(repo, sha);
|
||||||
}
|
}
|
||||||
// select version
|
|
||||||
if (semver.validRange(version)) {
|
if (semver.validRange(version)) {
|
||||||
ret = await selectSemver(repo, version);
|
ret = await selectSemver(repo, version);
|
||||||
}
|
}
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
throw new Error(`Invalid input xmake-version ${core.getInput('xmake-version')}`);
|
throw new Error(`Invalid input xmake-version ${core.getInput('xmake-version')}`);
|
||||||
}
|
}
|
||||||
core.info(`Selected xmake ${String(ret)} (commit: ${ret.sha.substr(0, 8)})` + (repo !== DEFAULT_REPO ? ` of ${repo}` : ''));
|
if (ret.type === 'local') {
|
||||||
|
core.info(`Use local xmake at '${ret.path}'`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.info(`Selected xmake ${String(ret)} (commit: ${ret.sha.substr(0, 8)})` +
|
||||||
|
(repo !== DEFAULT_REPO ? ` of ${repo}` : ''));
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
exports.selectVersion = selectVersion;
|
exports.selectVersion = selectVersion;
|
||||||
|
|||||||
Vendored
+14
-10
@@ -8,13 +8,13 @@ const toolCache = require("@actions/tool-cache");
|
|||||||
const os = require("os");
|
const os = require("os");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const semver = require("semver");
|
const semver = require("semver");
|
||||||
function getInstallerUrl(version) {
|
function getInstallerUrl(version, latest) {
|
||||||
const ver = version.version;
|
const ver = version.version;
|
||||||
switch (version.type) {
|
switch (version.type) {
|
||||||
case 'heads': {
|
case 'heads': {
|
||||||
// we only use appveyor ci artifacts for branch version
|
const arch = os.arch() === 'x64' ? 'win64' : 'win32';
|
||||||
const arch = os.arch() === 'x64' ? 'x64' : 'x86';
|
const latestver = latest.version;
|
||||||
return `https://ci.appveyor.com/api/projects/waruqi/xmake/artifacts/xmake-installer.exe?branch=${ver}&pr=false&job=Image%3A+Visual+Studio+2017%3B+Platform%3A+${arch}`;
|
return `https://github.com/xmake-io/xmake/releases/download/${latestver}/xmake-${ver}.${arch}.exe`;
|
||||||
}
|
}
|
||||||
case 'pull': {
|
case 'pull': {
|
||||||
throw new Error('PR builds for windows is not supported');
|
throw new Error('PR builds for windows is not supported');
|
||||||
@@ -23,29 +23,33 @@ function getInstallerUrl(version) {
|
|||||||
throw new Error('Sha builds for windows is not supported');
|
throw new Error('Sha builds for windows is not supported');
|
||||||
}
|
}
|
||||||
case 'tags': {
|
case 'tags': {
|
||||||
// we cannot use appveyor ci artifacts, the old version links may be broken.
|
|
||||||
const arch = os.arch() === 'x64' ? 'win64' : 'win32';
|
const arch = os.arch() === 'x64' ? 'win64' : 'win32';
|
||||||
return semver.gt(ver, '2.2.6')
|
return semver.gt(ver, '2.2.6')
|
||||||
? `https://github.com/xmake-io/xmake/releases/download/${ver}/xmake-${ver}.${arch}.exe`
|
? `https://github.com/xmake-io/xmake/releases/download/${ver}/xmake-${ver}.${arch}.exe`
|
||||||
: `https://github.com/xmake-io/xmake/releases/download/${ver}/xmake-${ver}.exe`;
|
: `https://github.com/xmake-io/xmake/releases/download/${ver}/xmake-${ver}.exe`;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
// check that we have tested all types
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
const _ = version.type;
|
const _ = version.type;
|
||||||
throw new Error('Unknown version type');
|
throw new Error('Unknown version type');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function winInstall(version) {
|
async function winInstall(version, latest) {
|
||||||
|
if (version.type === 'local' || latest.type == 'local') {
|
||||||
|
throw new Error('Local builds for windows is not supported');
|
||||||
|
}
|
||||||
const ver = version.version;
|
const ver = version.version;
|
||||||
let toolDir = toolCache.find('xmake', ver);
|
let toolDir = toolCache.find('xmake', ver);
|
||||||
if (!toolDir) {
|
if (!toolDir) {
|
||||||
const installer = await core.group(`download xmake ${String(version)}`, async () => {
|
const installer = await core.group(`download xmake ${String(version)}`, async () => {
|
||||||
const url = getInstallerUrl(version);
|
const url = getInstallerUrl(version, latest);
|
||||||
core.info(`downloading from ${url}`);
|
core.info(`downloading from ${url}`);
|
||||||
const file = await toolCache.downloadTool(url);
|
const file = await toolCache.downloadTool(url);
|
||||||
const exe = path.format({ ...path.parse(file), ext: '.exe', base: undefined });
|
const exe = path.format({
|
||||||
|
...path.parse(file),
|
||||||
|
ext: '.exe',
|
||||||
|
base: undefined,
|
||||||
|
});
|
||||||
await io.mv(file, exe);
|
await io.mv(file, exe);
|
||||||
core.info(`downloaded to ${exe}`);
|
core.info(`downloaded to ${exe}`);
|
||||||
return exe;
|
return exe;
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
preset: 'ts-jest',
|
preset: 'ts-jest',
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
};
|
};
|
||||||
+422
-383
File diff suppressed because it is too large
Load Diff
+9
@@ -0,0 +1,9 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright 2019 GitHub
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
+57
-1
@@ -62,10 +62,10 @@ catch (err) {
|
|||||||
// setFailed logs the message and sets a failing exit code
|
// setFailed logs the message and sets a failing exit code
|
||||||
core.setFailed(`Action failed with error ${err}`);
|
core.setFailed(`Action failed with error ${err}`);
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Note that `setNeutral` is not yet implemented in actions V2 but equivalent functionality is being planned.
|
Note that `setNeutral` is not yet implemented in actions V2 but equivalent functionality is being planned.
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Logging
|
#### Logging
|
||||||
|
|
||||||
@@ -89,6 +89,7 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Do stuff
|
// Do stuff
|
||||||
|
core.info('Output to the actions build log')
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
core.error(`Error ${err}, action may still succeed though`);
|
core.error(`Error ${err}, action may still succeed though`);
|
||||||
@@ -112,6 +113,61 @@ const result = await core.group('Do something async', async () => {
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Styling output
|
||||||
|
|
||||||
|
Colored output is supported in the Action logs via standard [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code). 3/4 bit, 8 bit and 24 bit colors are all supported.
|
||||||
|
|
||||||
|
Foreground colors:
|
||||||
|
```js
|
||||||
|
// 3/4 bit
|
||||||
|
core.info('\u001b[35mThis foreground will be magenta')
|
||||||
|
|
||||||
|
// 8 bit
|
||||||
|
core.info('\u001b[38;5;6mThis foreground will be cyan')
|
||||||
|
|
||||||
|
// 24 bit
|
||||||
|
core.info('\u001b[38;2;255;0;0mThis foreground will be bright red')
|
||||||
|
```
|
||||||
|
|
||||||
|
Background colors:
|
||||||
|
```js
|
||||||
|
// 3/4 bit
|
||||||
|
core.info('\u001b[43mThis background will be yellow');
|
||||||
|
|
||||||
|
// 8 bit
|
||||||
|
core.info('\u001b[48;5;6mThis background will be cyan')
|
||||||
|
|
||||||
|
// 24 bit
|
||||||
|
core.info('\u001b[48;2;255;0;0mThis background will be bright red')
|
||||||
|
```
|
||||||
|
|
||||||
|
Special styles:
|
||||||
|
|
||||||
|
```js
|
||||||
|
core.info('\u001b[1mBold text')
|
||||||
|
core.info('\u001b[3mItalic text')
|
||||||
|
core.info('\u001b[4mUnderlined text')
|
||||||
|
```
|
||||||
|
|
||||||
|
ANSI escape codes can be combined with one another:
|
||||||
|
|
||||||
|
```js
|
||||||
|
core.info('\u001b[31;46mRed foreground with a cyan background and \u001b[1mbold text at the end');
|
||||||
|
```
|
||||||
|
|
||||||
|
> Note: Escape codes reset at the start of each line
|
||||||
|
```js
|
||||||
|
core.info('\u001b[35mThis foreground will be magenta')
|
||||||
|
core.info('This foreground will reset to the default')
|
||||||
|
```
|
||||||
|
|
||||||
|
Manually typing escape codes can be a little difficult, but you can use third party modules such as [ansi-styles](https://github.com/chalk/ansi-styles).
|
||||||
|
|
||||||
|
```js
|
||||||
|
const style = require('ansi-styles');
|
||||||
|
core.info(style.color.ansi16m.hex('#abcdef') + 'Hello world!')
|
||||||
|
```
|
||||||
|
|
||||||
#### Action state
|
#### Action state
|
||||||
|
|
||||||
You can use this library to save state and get state for sharing information between a given wrapper action:
|
You can use this library to save state and get state for sharing information between a given wrapper action:
|
||||||
|
|||||||
-5
@@ -13,9 +13,4 @@ interface CommandProperties {
|
|||||||
*/
|
*/
|
||||||
export declare function issueCommand(command: string, properties: CommandProperties, message: any): void;
|
export declare function issueCommand(command: string, properties: CommandProperties, message: any): void;
|
||||||
export declare function issue(name: string, message?: string): void;
|
export declare function issue(name: string, message?: string): void;
|
||||||
/**
|
|
||||||
* Sanitizes an input into a string so it can be passed into issueCommand safely
|
|
||||||
* @param input input to sanitize into a string
|
|
||||||
*/
|
|
||||||
export declare function toCommandValue(input: any): string;
|
|
||||||
export {};
|
export {};
|
||||||
|
|||||||
+3
-16
@@ -8,6 +8,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const os = __importStar(require("os"));
|
const os = __importStar(require("os"));
|
||||||
|
const utils_1 = require("./utils");
|
||||||
/**
|
/**
|
||||||
* Commands
|
* Commands
|
||||||
*
|
*
|
||||||
@@ -61,28 +62,14 @@ class Command {
|
|||||||
return cmdStr;
|
return cmdStr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Sanitizes an input into a string so it can be passed into issueCommand safely
|
|
||||||
* @param input input to sanitize into a string
|
|
||||||
*/
|
|
||||||
function toCommandValue(input) {
|
|
||||||
if (input === null || input === undefined) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
else if (typeof input === 'string' || input instanceof String) {
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
return JSON.stringify(input);
|
|
||||||
}
|
|
||||||
exports.toCommandValue = toCommandValue;
|
|
||||||
function escapeData(s) {
|
function escapeData(s) {
|
||||||
return toCommandValue(s)
|
return utils_1.toCommandValue(s)
|
||||||
.replace(/%/g, '%25')
|
.replace(/%/g, '%25')
|
||||||
.replace(/\r/g, '%0D')
|
.replace(/\r/g, '%0D')
|
||||||
.replace(/\n/g, '%0A');
|
.replace(/\n/g, '%0A');
|
||||||
}
|
}
|
||||||
function escapeProperty(s) {
|
function escapeProperty(s) {
|
||||||
return toCommandValue(s)
|
return utils_1.toCommandValue(s)
|
||||||
.replace(/%/g, '%25')
|
.replace(/%/g, '%25')
|
||||||
.replace(/\r/g, '%0D')
|
.replace(/\r/g, '%0D')
|
||||||
.replace(/\n/g, '%0A')
|
.replace(/\n/g, '%0A')
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
{"version":3,"file":"command.js","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uCAAwB;AAWxB;;;;;;;;;GASG;AACH,SAAgB,YAAY,CAC1B,OAAe,EACf,UAA6B,EAC7B,OAAY;IAEZ,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAA;IACrD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAA;AAC/C,CAAC;AAPD,oCAOC;AAED,SAAgB,KAAK,CAAC,IAAY,EAAE,UAAkB,EAAE;IACtD,YAAY,CAAC,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC,CAAA;AACjC,CAAC;AAFD,sBAEC;AAED,MAAM,UAAU,GAAG,IAAI,CAAA;AAEvB,MAAM,OAAO;IAKX,YAAY,OAAe,EAAE,UAA6B,EAAE,OAAe;QACzE,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,GAAG,iBAAiB,CAAA;SAC5B;QAED,IAAI,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AAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;SACpB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;AACzB,CAAC"}
|
||||||
+20
-3
@@ -17,6 +17,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const command_1 = require("./command");
|
const command_1 = require("./command");
|
||||||
|
const file_command_1 = require("./file-command");
|
||||||
|
const utils_1 = require("./utils");
|
||||||
const os = __importStar(require("os"));
|
const os = __importStar(require("os"));
|
||||||
const path = __importStar(require("path"));
|
const path = __importStar(require("path"));
|
||||||
/**
|
/**
|
||||||
@@ -43,9 +45,17 @@ var ExitCode;
|
|||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
function exportVariable(name, val) {
|
function exportVariable(name, val) {
|
||||||
const convertedVal = command_1.toCommandValue(val);
|
const convertedVal = utils_1.toCommandValue(val);
|
||||||
process.env[name] = convertedVal;
|
process.env[name] = convertedVal;
|
||||||
command_1.issueCommand('set-env', { name }, convertedVal);
|
const filePath = process.env['GITHUB_ENV'] || '';
|
||||||
|
if (filePath) {
|
||||||
|
const delimiter = '_GitHubActionsFileCommandDelimeter_';
|
||||||
|
const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`;
|
||||||
|
file_command_1.issueCommand('ENV', commandValue);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
command_1.issueCommand('set-env', { name }, convertedVal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exports.exportVariable = exportVariable;
|
exports.exportVariable = exportVariable;
|
||||||
/**
|
/**
|
||||||
@@ -61,7 +71,13 @@ exports.setSecret = setSecret;
|
|||||||
* @param inputPath
|
* @param inputPath
|
||||||
*/
|
*/
|
||||||
function addPath(inputPath) {
|
function addPath(inputPath) {
|
||||||
command_1.issueCommand('add-path', {}, inputPath);
|
const filePath = process.env['GITHUB_PATH'] || '';
|
||||||
|
if (filePath) {
|
||||||
|
file_command_1.issueCommand('PATH', inputPath);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
command_1.issueCommand('add-path', {}, inputPath);
|
||||||
|
}
|
||||||
process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`;
|
process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`;
|
||||||
}
|
}
|
||||||
exports.addPath = addPath;
|
exports.addPath = addPath;
|
||||||
@@ -88,6 +104,7 @@ exports.getInput = getInput;
|
|||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
function setOutput(name, value) {
|
function setOutput(name, value) {
|
||||||
|
process.stdout.write(os.EOL);
|
||||||
command_1.issueCommand('set-output', { name }, value);
|
command_1.issueCommand('set-output', { name }, value);
|
||||||
}
|
}
|
||||||
exports.setOutput = setOutput;
|
exports.setOutput = setOutput;
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,uCAA6D;AAE7D,uCAAwB;AACxB,2CAA4B;AAU5B;;GAEG;AACH,IAAY,QAUX;AAVD,WAAY,QAAQ;IAClB;;OAEG;IACH,6CAAW,CAAA;IAEX;;OAEG;IACH,6CAAW,CAAA;AACb,CAAC,EAVW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAUnB;AAED,yEAAyE;AACzE,YAAY;AACZ,yEAAyE;AAEzE;;;;GAIG;AACH,8DAA8D;AAC9D,SAAgB,cAAc,CAAC,IAAY,EAAE,GAAQ;IACnD,MAAM,YAAY,GAAG,wBAA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C3C,CAAC;AAFD,8BAEC;AAED;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,IAAY;IACnC,OAAO,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC,IAAI,EAAE,CAAA;AAC3C,CAAC;AAFD,4BAEC"}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
export declare function issueCommand(command: string, message: any): void;
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
"use strict";
|
||||||
|
// For internal use, subject to change.
|
||||||
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||||
|
result["default"] = mod;
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
// We use any as a valid input type
|
||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
const fs = __importStar(require("fs"));
|
||||||
|
const os = __importStar(require("os"));
|
||||||
|
const utils_1 = require("./utils");
|
||||||
|
function issueCommand(command, message) {
|
||||||
|
const filePath = process.env[`GITHUB_${command}`];
|
||||||
|
if (!filePath) {
|
||||||
|
throw new Error(`Unable to find environment variable for file command ${command}`);
|
||||||
|
}
|
||||||
|
if (!fs.existsSync(filePath)) {
|
||||||
|
throw new Error(`Missing file at path: ${filePath}`);
|
||||||
|
}
|
||||||
|
fs.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os.EOL}`, {
|
||||||
|
encoding: 'utf8'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.issueCommand = issueCommand;
|
||||||
|
//# sourceMappingURL=file-command.js.map
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"file-command.js","sourceRoot":"","sources":["../src/file-command.ts"],"names":[],"mappings":";AAAA,uCAAuC;;;;;;;;;AAEvC,mCAAmC;AACnC,uDAAuD;AAEvD,uCAAwB;AACxB,uCAAwB;AACxB,mCAAsC;AAEtC,SAAgB,YAAY,CAAC,OAAe,EAAE,OAAY;IACxD,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,OAAO,EAAE,CAAC,CAAA;IACjD,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,IAAI,KAAK,CACb,wDAAwD,OAAO,EAAE,CAClE,CAAA;KACF;IACD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAA;KACrD;IAED,EAAE,CAAC,cAAc,CAAC,QAAQ,EAAE,GAAG,sBAAc,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE;QACjE,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAA;AACJ,CAAC;AAdD,oCAcC"}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
/**
|
||||||
|
* Sanitizes an input into a string so it can be passed into issueCommand safely
|
||||||
|
* @param input input to sanitize into a string
|
||||||
|
*/
|
||||||
|
export declare function toCommandValue(input: any): string;
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
"use strict";
|
||||||
|
// We use any as a valid input type
|
||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
/**
|
||||||
|
* Sanitizes an input into a string so it can be passed into issueCommand safely
|
||||||
|
* @param input input to sanitize into a string
|
||||||
|
*/
|
||||||
|
function toCommandValue(input) {
|
||||||
|
if (input === null || input === undefined) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
else if (typeof input === 'string' || input instanceof String) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
return JSON.stringify(input);
|
||||||
|
}
|
||||||
|
exports.toCommandValue = toCommandValue;
|
||||||
|
//# sourceMappingURL=utils.js.map
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAAA,mCAAmC;AACnC,uDAAuD;;AAEvD;;;GAGG;AACH,SAAgB,cAAc,CAAC,KAAU;IACvC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE;QACzC,OAAO,EAAE,CAAA;KACV;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,YAAY,MAAM,EAAE;QAC/D,OAAO,KAAe,CAAA;KACvB;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;AAC9B,CAAC;AAPD,wCAOC"}
|
||||||
+5
-4
@@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@actions/core",
|
"name": "@actions/core",
|
||||||
"version": "1.2.4",
|
"version": "1.2.7",
|
||||||
"description": "Actions core lib",
|
"description": "Actions core lib",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"github",
|
"github",
|
||||||
"actions",
|
"actions",
|
||||||
"core"
|
"core"
|
||||||
],
|
],
|
||||||
"homepage": "https://github.com/actions/toolkit/tree/master/packages/core",
|
"homepage": "https://github.com/actions/toolkit/tree/main/packages/core",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "lib/core.js",
|
"main": "lib/core.js",
|
||||||
"types": "lib/core.d.ts",
|
"types": "lib/core.d.ts",
|
||||||
@@ -16,7 +16,8 @@
|
|||||||
"test": "__tests__"
|
"test": "__tests__"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib",
|
||||||
|
"!.DS_Store"
|
||||||
],
|
],
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
@@ -27,7 +28,7 @@
|
|||||||
"directory": "packages/core"
|
"directory": "packages/core"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"audit-moderate": "npm install && npm audit --audit-level=moderate",
|
"audit-moderate": "npm install && npm audit --json --audit-level=moderate > audit.json",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1",
|
"test": "echo \"Error: run tests from root\" && exit 1",
|
||||||
"tsc": "tsc"
|
"tsc": "tsc"
|
||||||
},
|
},
|
||||||
|
|||||||
+10
@@ -1,5 +1,15 @@
|
|||||||
## Releases
|
## Releases
|
||||||
|
|
||||||
|
## 1.0.10
|
||||||
|
|
||||||
|
Contains a bug fix where proxy is defined without a user and password. see [PR here](https://github.com/actions/http-client/pull/42)
|
||||||
|
|
||||||
|
## 1.0.9
|
||||||
|
Throw HttpClientError instead of a generic Error from the \<verb>Json() helper methods when the server responds with a non-successful status code.
|
||||||
|
|
||||||
|
## 1.0.8
|
||||||
|
Fixed security issue where a redirect (e.g. 302) to another domain would pass headers. The fix was to strip the authorization header if the hostname was different. More [details in PR #27](https://github.com/actions/http-client/pull/27)
|
||||||
|
|
||||||
## 1.0.7
|
## 1.0.7
|
||||||
Update NPM dependencies and add 429 to the list of HttpCodes
|
Update NPM dependencies and add 429 to the list of HttpCodes
|
||||||
|
|
||||||
|
|||||||
+5
@@ -42,6 +42,11 @@ export declare enum MediaTypes {
|
|||||||
* @param serverUrl The server URL where the request will be sent. For example, https://api.github.com
|
* @param serverUrl The server URL where the request will be sent. For example, https://api.github.com
|
||||||
*/
|
*/
|
||||||
export declare function getProxyUrl(serverUrl: string): string;
|
export declare function getProxyUrl(serverUrl: string): string;
|
||||||
|
export declare class HttpClientError extends Error {
|
||||||
|
constructor(message: string, statusCode: number);
|
||||||
|
statusCode: number;
|
||||||
|
result?: any;
|
||||||
|
}
|
||||||
export declare class HttpClientResponse implements ifm.IHttpClientResponse {
|
export declare class HttpClientResponse implements ifm.IHttpClientResponse {
|
||||||
constructor(message: http.IncomingMessage);
|
constructor(message: http.IncomingMessage);
|
||||||
message: http.IncomingMessage;
|
message: http.IncomingMessage;
|
||||||
|
|||||||
+19
-13
@@ -1,6 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const url = require("url");
|
|
||||||
const http = require("http");
|
const http = require("http");
|
||||||
const https = require("https");
|
const https = require("https");
|
||||||
const pm = require("./proxy");
|
const pm = require("./proxy");
|
||||||
@@ -49,7 +48,7 @@ var MediaTypes;
|
|||||||
* @param serverUrl The server URL where the request will be sent. For example, https://api.github.com
|
* @param serverUrl The server URL where the request will be sent. For example, https://api.github.com
|
||||||
*/
|
*/
|
||||||
function getProxyUrl(serverUrl) {
|
function getProxyUrl(serverUrl) {
|
||||||
let proxyUrl = pm.getProxyUrl(url.parse(serverUrl));
|
let proxyUrl = pm.getProxyUrl(new URL(serverUrl));
|
||||||
return proxyUrl ? proxyUrl.href : '';
|
return proxyUrl ? proxyUrl.href : '';
|
||||||
}
|
}
|
||||||
exports.getProxyUrl = getProxyUrl;
|
exports.getProxyUrl = getProxyUrl;
|
||||||
@@ -68,6 +67,15 @@ const HttpResponseRetryCodes = [
|
|||||||
const RetryableHttpVerbs = ['OPTIONS', 'GET', 'DELETE', 'HEAD'];
|
const RetryableHttpVerbs = ['OPTIONS', 'GET', 'DELETE', 'HEAD'];
|
||||||
const ExponentialBackoffCeiling = 10;
|
const ExponentialBackoffCeiling = 10;
|
||||||
const ExponentialBackoffTimeSlice = 5;
|
const ExponentialBackoffTimeSlice = 5;
|
||||||
|
class HttpClientError extends Error {
|
||||||
|
constructor(message, statusCode) {
|
||||||
|
super(message);
|
||||||
|
this.name = 'HttpClientError';
|
||||||
|
this.statusCode = statusCode;
|
||||||
|
Object.setPrototypeOf(this, HttpClientError.prototype);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.HttpClientError = HttpClientError;
|
||||||
class HttpClientResponse {
|
class HttpClientResponse {
|
||||||
constructor(message) {
|
constructor(message) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
@@ -86,7 +94,7 @@ class HttpClientResponse {
|
|||||||
}
|
}
|
||||||
exports.HttpClientResponse = HttpClientResponse;
|
exports.HttpClientResponse = HttpClientResponse;
|
||||||
function isHttps(requestUrl) {
|
function isHttps(requestUrl) {
|
||||||
let parsedUrl = url.parse(requestUrl);
|
let parsedUrl = new URL(requestUrl);
|
||||||
return parsedUrl.protocol === 'https:';
|
return parsedUrl.protocol === 'https:';
|
||||||
}
|
}
|
||||||
exports.isHttps = isHttps;
|
exports.isHttps = isHttps;
|
||||||
@@ -191,7 +199,7 @@ class HttpClient {
|
|||||||
if (this._disposed) {
|
if (this._disposed) {
|
||||||
throw new Error('Client has already been disposed.');
|
throw new Error('Client has already been disposed.');
|
||||||
}
|
}
|
||||||
let parsedUrl = url.parse(requestUrl);
|
let parsedUrl = new URL(requestUrl);
|
||||||
let info = this._prepareRequest(verb, parsedUrl, headers);
|
let info = this._prepareRequest(verb, parsedUrl, headers);
|
||||||
// Only perform retries on reads since writes may not be idempotent.
|
// Only perform retries on reads since writes may not be idempotent.
|
||||||
let maxTries = this._allowRetries && RetryableHttpVerbs.indexOf(verb) != -1
|
let maxTries = this._allowRetries && RetryableHttpVerbs.indexOf(verb) != -1
|
||||||
@@ -230,7 +238,7 @@ class HttpClient {
|
|||||||
// if there's no location to redirect to, we won't
|
// if there's no location to redirect to, we won't
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let parsedRedirectUrl = url.parse(redirectUrl);
|
let parsedRedirectUrl = new URL(redirectUrl);
|
||||||
if (parsedUrl.protocol == 'https:' &&
|
if (parsedUrl.protocol == 'https:' &&
|
||||||
parsedUrl.protocol != parsedRedirectUrl.protocol &&
|
parsedUrl.protocol != parsedRedirectUrl.protocol &&
|
||||||
!this._allowRedirectDowngrade) {
|
!this._allowRedirectDowngrade) {
|
||||||
@@ -346,7 +354,7 @@ class HttpClient {
|
|||||||
* @param serverUrl The server URL where the request will be sent. For example, https://api.github.com
|
* @param serverUrl The server URL where the request will be sent. For example, https://api.github.com
|
||||||
*/
|
*/
|
||||||
getAgent(serverUrl) {
|
getAgent(serverUrl) {
|
||||||
let parsedUrl = url.parse(serverUrl);
|
let parsedUrl = new URL(serverUrl);
|
||||||
return this._getAgent(parsedUrl);
|
return this._getAgent(parsedUrl);
|
||||||
}
|
}
|
||||||
_prepareRequest(method, requestUrl, headers) {
|
_prepareRequest(method, requestUrl, headers) {
|
||||||
@@ -419,7 +427,9 @@ class HttpClient {
|
|||||||
maxSockets: maxSockets,
|
maxSockets: maxSockets,
|
||||||
keepAlive: this._keepAlive,
|
keepAlive: this._keepAlive,
|
||||||
proxy: {
|
proxy: {
|
||||||
proxyAuth: proxyUrl.auth,
|
...((proxyUrl.username || proxyUrl.password) && {
|
||||||
|
proxyAuth: `${proxyUrl.username}:${proxyUrl.password}`
|
||||||
|
}),
|
||||||
host: proxyUrl.hostname,
|
host: proxyUrl.hostname,
|
||||||
port: proxyUrl.port
|
port: proxyUrl.port
|
||||||
}
|
}
|
||||||
@@ -514,12 +524,8 @@ class HttpClient {
|
|||||||
else {
|
else {
|
||||||
msg = 'Failed request: (' + statusCode + ')';
|
msg = 'Failed request: (' + statusCode + ')';
|
||||||
}
|
}
|
||||||
let err = new Error(msg);
|
let err = new HttpClientError(msg, statusCode);
|
||||||
// attach statusCode and body obj (if available) to the error object
|
err.result = response.result;
|
||||||
err['statusCode'] = statusCode;
|
|
||||||
if (response.result) {
|
|
||||||
err['result'] = response.result;
|
|
||||||
}
|
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
/// <reference types="node" />
|
/// <reference types="node" />
|
||||||
import http = require('http');
|
import http = require('http');
|
||||||
import url = require('url');
|
|
||||||
export interface IHeaders {
|
export interface IHeaders {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
@@ -27,7 +26,7 @@ export interface IHttpClientResponse {
|
|||||||
}
|
}
|
||||||
export interface IRequestInfo {
|
export interface IRequestInfo {
|
||||||
options: http.RequestOptions;
|
options: http.RequestOptions;
|
||||||
parsedUrl: url.Url;
|
parsedUrl: URL;
|
||||||
httpModule: any;
|
httpModule: any;
|
||||||
}
|
}
|
||||||
export interface IRequestOptions {
|
export interface IRequestOptions {
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@actions/http-client",
|
"name": "@actions/http-client",
|
||||||
"version": "1.0.8",
|
"version": "1.0.11",
|
||||||
"description": "Actions Http Client",
|
"description": "Actions Http Client",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
+2
-4
@@ -1,4 +1,2 @@
|
|||||||
/// <reference types="node" />
|
export declare function getProxyUrl(reqUrl: URL): URL | undefined;
|
||||||
import * as url from 'url';
|
export declare function checkBypass(reqUrl: URL): boolean;
|
||||||
export declare function getProxyUrl(reqUrl: url.Url): url.Url | undefined;
|
|
||||||
export declare function checkBypass(reqUrl: url.Url): boolean;
|
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const url = require("url");
|
|
||||||
function getProxyUrl(reqUrl) {
|
function getProxyUrl(reqUrl) {
|
||||||
let usingSsl = reqUrl.protocol === 'https:';
|
let usingSsl = reqUrl.protocol === 'https:';
|
||||||
let proxyUrl;
|
let proxyUrl;
|
||||||
@@ -15,7 +14,7 @@ function getProxyUrl(reqUrl) {
|
|||||||
proxyVar = process.env['http_proxy'] || process.env['HTTP_PROXY'];
|
proxyVar = process.env['http_proxy'] || process.env['HTTP_PROXY'];
|
||||||
}
|
}
|
||||||
if (proxyVar) {
|
if (proxyVar) {
|
||||||
proxyUrl = url.parse(proxyVar);
|
proxyUrl = new URL(proxyVar);
|
||||||
}
|
}
|
||||||
return proxyUrl;
|
return proxyUrl;
|
||||||
}
|
}
|
||||||
|
|||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright 2019 GitHub
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
+9
-2
@@ -8,11 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||||
|
result["default"] = mod;
|
||||||
|
return result;
|
||||||
|
};
|
||||||
var _a;
|
var _a;
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const assert_1 = require("assert");
|
const assert_1 = require("assert");
|
||||||
const fs = require("fs");
|
const fs = __importStar(require("fs"));
|
||||||
const path = require("path");
|
const path = __importStar(require("path"));
|
||||||
_a = fs.promises, exports.chmod = _a.chmod, exports.copyFile = _a.copyFile, exports.lstat = _a.lstat, exports.mkdir = _a.mkdir, exports.readdir = _a.readdir, exports.readlink = _a.readlink, exports.rename = _a.rename, exports.rmdir = _a.rmdir, exports.stat = _a.stat, exports.symlink = _a.symlink, exports.unlink = _a.unlink;
|
_a = fs.promises, exports.chmod = _a.chmod, exports.copyFile = _a.copyFile, exports.lstat = _a.lstat, exports.mkdir = _a.mkdir, exports.readdir = _a.readdir, exports.readlink = _a.readlink, exports.rename = _a.rename, exports.rmdir = _a.rmdir, exports.stat = _a.stat, exports.symlink = _a.symlink, exports.unlink = _a.unlink;
|
||||||
exports.IS_WINDOWS = process.platform === 'win32';
|
exports.IS_WINDOWS = process.platform === 'win32';
|
||||||
function exists(fsPath) {
|
function exists(fsPath) {
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
{"version":3,"file":"io-util.js","sourceRoot":"","sources":["../src/io-util.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAyB;AACzB,yBAAwB;AACxB,6BAA4B;AAEf,gBAYE,qTAAA;AAEF,QAAA,UAAU,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAA;AAEtD,SAAsB,MAAM,CAAC,MAAc;;QACzC,IAAI;YACF,MAAM,YAAI,CAAC,MAAM,CAAC,CAAA;SACnB;QAAC,OAAO,GAAG,EAAE;YACZ,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE;gBACzB,OAAO,KAAK,CAAA;aACb;YAED,MAAM,GAAG,CAAA;SACV;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CAAA;AAZD,wBAYC;AAED,SAAsB,WAAW,CAC/B,MAAc,EACd,UAAmB,KAAK;;QAExB,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CA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B,2BAA2B;QAC3B,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;KACjC;IAED,2BAA2B;IAC3B,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;AACjC,CAAC;AAED,qCAAqC;AACrC,6BAA6B;AAC7B,6BAA6B;AAC7B,SAAS,gBAAgB,CAAC,KAAe;IACvC,OAAO,CACL,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC;QACpB,CAAC,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC;QACxD,CAAC,CAAC,KAAK,CAAC,IAAI,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAC1D,CAAA;AACH,CAAC"}
|
||||||
+6
@@ -54,3 +54,9 @@ export declare function mkdirP(fsPath: string): Promise<void>;
|
|||||||
* @returns Promise<string> path to tool
|
* @returns Promise<string> path to tool
|
||||||
*/
|
*/
|
||||||
export declare function which(tool: string, check?: boolean): Promise<string>;
|
export declare function which(tool: string, check?: boolean): Promise<string>;
|
||||||
|
/**
|
||||||
|
* Returns a list of all occurrences of the given tool on the system path.
|
||||||
|
*
|
||||||
|
* @returns Promise<string[]> the paths of the tool
|
||||||
|
*/
|
||||||
|
export declare function findInPath(tool: string): Promise<string[]>;
|
||||||
|
|||||||
+72
-50
@@ -8,11 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||||
|
result["default"] = mod;
|
||||||
|
return result;
|
||||||
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const childProcess = require("child_process");
|
const childProcess = __importStar(require("child_process"));
|
||||||
const path = require("path");
|
const path = __importStar(require("path"));
|
||||||
const util_1 = require("util");
|
const util_1 = require("util");
|
||||||
const ioUtil = require("./io-util");
|
const ioUtil = __importStar(require("./io-util"));
|
||||||
const exec = util_1.promisify(childProcess.exec);
|
const exec = util_1.promisify(childProcess.exec);
|
||||||
/**
|
/**
|
||||||
* Copies a file or folder.
|
* Copies a file or folder.
|
||||||
@@ -180,58 +187,73 @@ function which(tool, check) {
|
|||||||
throw new Error(`Unable to locate executable file: ${tool}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.`);
|
throw new Error(`Unable to locate executable file: ${tool}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
try {
|
const matches = yield findInPath(tool);
|
||||||
// build the list of extensions to try
|
if (matches && matches.length > 0) {
|
||||||
const extensions = [];
|
return matches[0];
|
||||||
if (ioUtil.IS_WINDOWS && process.env.PATHEXT) {
|
|
||||||
for (const extension of process.env.PATHEXT.split(path.delimiter)) {
|
|
||||||
if (extension) {
|
|
||||||
extensions.push(extension);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// if it's rooted, return it if exists. otherwise return empty.
|
|
||||||
if (ioUtil.isRooted(tool)) {
|
|
||||||
const filePath = yield ioUtil.tryGetExecutablePath(tool, extensions);
|
|
||||||
if (filePath) {
|
|
||||||
return filePath;
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
// if any path separators, return empty
|
|
||||||
if (tool.includes('/') || (ioUtil.IS_WINDOWS && tool.includes('\\'))) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
// build the list of directories
|
|
||||||
//
|
|
||||||
// Note, technically "where" checks the current directory on Windows. From a toolkit perspective,
|
|
||||||
// it feels like we should not do this. Checking the current directory seems like more of a use
|
|
||||||
// case of a shell, and the which() function exposed by the toolkit should strive for consistency
|
|
||||||
// across platforms.
|
|
||||||
const directories = [];
|
|
||||||
if (process.env.PATH) {
|
|
||||||
for (const p of process.env.PATH.split(path.delimiter)) {
|
|
||||||
if (p) {
|
|
||||||
directories.push(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// return the first match
|
|
||||||
for (const directory of directories) {
|
|
||||||
const filePath = yield ioUtil.tryGetExecutablePath(directory + path.sep + tool, extensions);
|
|
||||||
if (filePath) {
|
|
||||||
return filePath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
throw new Error(`which failed with message ${err.message}`);
|
|
||||||
}
|
}
|
||||||
|
return '';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.which = which;
|
exports.which = which;
|
||||||
|
/**
|
||||||
|
* Returns a list of all occurrences of the given tool on the system path.
|
||||||
|
*
|
||||||
|
* @returns Promise<string[]> the paths of the tool
|
||||||
|
*/
|
||||||
|
function findInPath(tool) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (!tool) {
|
||||||
|
throw new Error("parameter 'tool' is required");
|
||||||
|
}
|
||||||
|
// build the list of extensions to try
|
||||||
|
const extensions = [];
|
||||||
|
if (ioUtil.IS_WINDOWS && process.env['PATHEXT']) {
|
||||||
|
for (const extension of process.env['PATHEXT'].split(path.delimiter)) {
|
||||||
|
if (extension) {
|
||||||
|
extensions.push(extension);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if it's rooted, return it if exists. otherwise return empty.
|
||||||
|
if (ioUtil.isRooted(tool)) {
|
||||||
|
const filePath = yield ioUtil.tryGetExecutablePath(tool, extensions);
|
||||||
|
if (filePath) {
|
||||||
|
return [filePath];
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
// if any path separators, return empty
|
||||||
|
if (tool.includes(path.sep)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
// build the list of directories
|
||||||
|
//
|
||||||
|
// Note, technically "where" checks the current directory on Windows. From a toolkit perspective,
|
||||||
|
// it feels like we should not do this. Checking the current directory seems like more of a use
|
||||||
|
// case of a shell, and the which() function exposed by the toolkit should strive for consistency
|
||||||
|
// across platforms.
|
||||||
|
const directories = [];
|
||||||
|
if (process.env.PATH) {
|
||||||
|
for (const p of process.env.PATH.split(path.delimiter)) {
|
||||||
|
if (p) {
|
||||||
|
directories.push(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// find all matches
|
||||||
|
const matches = [];
|
||||||
|
for (const directory of directories) {
|
||||||
|
const filePath = yield ioUtil.tryGetExecutablePath(path.join(directory, tool), extensions);
|
||||||
|
if (filePath) {
|
||||||
|
matches.push(filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return matches;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.findInPath = findInPath;
|
||||||
function readCopyOptions(options) {
|
function readCopyOptions(options) {
|
||||||
const force = options.force == null ? true : options.force;
|
const force = options.force == null ? true : options.force;
|
||||||
const recursive = Boolean(options.recursive);
|
const recursive = Boolean(options.recursive);
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
+3
-3
@@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@actions/io",
|
"name": "@actions/io",
|
||||||
"version": "1.0.2",
|
"version": "1.1.0",
|
||||||
"description": "Actions io lib",
|
"description": "Actions io lib",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"github",
|
"github",
|
||||||
"actions",
|
"actions",
|
||||||
"io"
|
"io"
|
||||||
],
|
],
|
||||||
"homepage": "https://github.com/actions/toolkit/tree/master/packages/io",
|
"homepage": "https://github.com/actions/toolkit/tree/main/packages/io",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "lib/io.js",
|
"main": "lib/io.js",
|
||||||
"types": "lib/io.d.ts",
|
"types": "lib/io.d.ts",
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
"directory": "packages/io"
|
"directory": "packages/io"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"audit-moderate": "npm install && npm audit --audit-level=moderate",
|
"audit-moderate": "npm install && npm audit --json --audit-level=moderate > audit.json",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1",
|
"test": "echo \"Error: run tests from root\" && exit 1",
|
||||||
"tsc": "tsc"
|
"tsc": "tsc"
|
||||||
},
|
},
|
||||||
|
|||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright 2019 GitHub
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
+4
@@ -29,6 +29,10 @@ if (process.platform === 'win32') {
|
|||||||
const node12Path = await tc.downloadTool('https://nodejs.org/dist/v12.7.0/node-v12.7.0-win-x64.7z');
|
const node12Path = await tc.downloadTool('https://nodejs.org/dist/v12.7.0/node-v12.7.0-win-x64.7z');
|
||||||
const node12ExtractedFolder = await tc.extract7z(node12Path, 'path/to/extract/to');
|
const node12ExtractedFolder = await tc.extract7z(node12Path, 'path/to/extract/to');
|
||||||
}
|
}
|
||||||
|
else if (process.platform === 'darwin') {
|
||||||
|
const node12Path = await tc.downloadTool('https://nodejs.org/dist/v12.7.0/node-v12.7.0.pkg');
|
||||||
|
const node12ExtractedFolder = await tc.extractXar(node12Path, 'path/to/extract/to');
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
const node12Path = await tc.downloadTool('https://nodejs.org/dist/v12.7.0/node-v12.7.0-linux-x64.tar.gz');
|
const node12Path = await tc.downloadTool('https://nodejs.org/dist/v12.7.0/node-v12.7.0-linux-x64.tar.gz');
|
||||||
const node12ExtractedFolder = await tc.extractTar(node12Path, 'path/to/extract/to');
|
const node12ExtractedFolder = await tc.extractTar(node12Path, 'path/to/extract/to');
|
||||||
|
|||||||
+9
@@ -37,6 +37,15 @@ export declare function extract7z(file: string, dest?: string, _7zPath?: string)
|
|||||||
* @returns path to the destination directory
|
* @returns path to the destination directory
|
||||||
*/
|
*/
|
||||||
export declare function extractTar(file: string, dest?: string, flags?: string | string[]): Promise<string>;
|
export declare function extractTar(file: string, dest?: string, flags?: string | string[]): Promise<string>;
|
||||||
|
/**
|
||||||
|
* Extract a xar compatible archive
|
||||||
|
*
|
||||||
|
* @param file path to the archive
|
||||||
|
* @param dest destination directory. Optional.
|
||||||
|
* @param flags flags for the xar. Optional.
|
||||||
|
* @returns path to the destination directory
|
||||||
|
*/
|
||||||
|
export declare function extractXar(file: string, dest?: string, flags?: string | string[]): Promise<string>;
|
||||||
/**
|
/**
|
||||||
* Extract a zip
|
* Extract a zip
|
||||||
*
|
*
|
||||||
|
|||||||
+38
@@ -42,6 +42,7 @@ class HTTPError extends Error {
|
|||||||
}
|
}
|
||||||
exports.HTTPError = HTTPError;
|
exports.HTTPError = HTTPError;
|
||||||
const IS_WINDOWS = process.platform === 'win32';
|
const IS_WINDOWS = process.platform === 'win32';
|
||||||
|
const IS_MAC = process.platform === 'darwin';
|
||||||
const userAgent = 'actions/tool-cache';
|
const userAgent = 'actions/tool-cache';
|
||||||
/**
|
/**
|
||||||
* Download a tool from an url and stream it into a file
|
* Download a tool from an url and stream it into a file
|
||||||
@@ -257,6 +258,36 @@ function extractTar(file, dest, flags = 'xz') {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.extractTar = extractTar;
|
exports.extractTar = extractTar;
|
||||||
|
/**
|
||||||
|
* Extract a xar compatible archive
|
||||||
|
*
|
||||||
|
* @param file path to the archive
|
||||||
|
* @param dest destination directory. Optional.
|
||||||
|
* @param flags flags for the xar. Optional.
|
||||||
|
* @returns path to the destination directory
|
||||||
|
*/
|
||||||
|
function extractXar(file, dest, flags = []) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
assert_1.ok(IS_MAC, 'extractXar() not supported on current OS');
|
||||||
|
assert_1.ok(file, 'parameter "file" is required');
|
||||||
|
dest = yield _createExtractFolder(dest);
|
||||||
|
let args;
|
||||||
|
if (flags instanceof Array) {
|
||||||
|
args = flags;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
args = [flags];
|
||||||
|
}
|
||||||
|
args.push('-x', '-C', dest, '-f', file);
|
||||||
|
if (core.isDebug()) {
|
||||||
|
args.push('-v');
|
||||||
|
}
|
||||||
|
const xarPath = yield io.which('xar', true);
|
||||||
|
yield exec_1.exec(`"${xarPath}"`, _unique(args));
|
||||||
|
return dest;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.extractXar = extractXar;
|
||||||
/**
|
/**
|
||||||
* Extract a zip
|
* Extract a zip
|
||||||
*
|
*
|
||||||
@@ -565,4 +596,11 @@ function _getGlobal(key, defaultValue) {
|
|||||||
/* eslint-enable @typescript-eslint/no-explicit-any */
|
/* eslint-enable @typescript-eslint/no-explicit-any */
|
||||||
return value !== undefined ? value : defaultValue;
|
return value !== undefined ? value : defaultValue;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Returns an array of unique values.
|
||||||
|
* @param values Values to make unique.
|
||||||
|
*/
|
||||||
|
function _unique(values) {
|
||||||
|
return Array.from(new Set(values));
|
||||||
|
}
|
||||||
//# sourceMappingURL=tool-cache.js.map
|
//# sourceMappingURL=tool-cache.js.map
|
||||||
+1
-1
File diff suppressed because one or more lines are too long
-57
@@ -1,57 +0,0 @@
|
|||||||
# `@actions/exec`
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
#### Basic
|
|
||||||
|
|
||||||
You can use this package to execute tools in a cross platform way:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const exec = require('@actions/exec');
|
|
||||||
|
|
||||||
await exec.exec('node index.js');
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Args
|
|
||||||
|
|
||||||
You can also pass in arg arrays:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const exec = require('@actions/exec');
|
|
||||||
|
|
||||||
await exec.exec('node', ['index.js', 'foo=bar']);
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Output/options
|
|
||||||
|
|
||||||
Capture output or specify [other options](https://github.com/actions/toolkit/blob/d9347d4ab99fd507c0b9104b2cf79fb44fcc827d/packages/exec/src/interfaces.ts#L5):
|
|
||||||
|
|
||||||
```js
|
|
||||||
const exec = require('@actions/exec');
|
|
||||||
|
|
||||||
let myOutput = '';
|
|
||||||
let myError = '';
|
|
||||||
|
|
||||||
const options = {};
|
|
||||||
options.listeners = {
|
|
||||||
stdout: (data: Buffer) => {
|
|
||||||
myOutput += data.toString();
|
|
||||||
},
|
|
||||||
stderr: (data: Buffer) => {
|
|
||||||
myError += data.toString();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
options.cwd = './lib';
|
|
||||||
|
|
||||||
await exec.exec('node', ['index.js', 'foo=bar'], options);
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Exec tools not in the PATH
|
|
||||||
|
|
||||||
You can specify the full path for tools not in the PATH:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const exec = require('@actions/exec');
|
|
||||||
|
|
||||||
await exec.exec('"/path/to/my-tool"', ['arg1']);
|
|
||||||
```
|
|
||||||
-12
@@ -1,12 +0,0 @@
|
|||||||
import * as im from './interfaces';
|
|
||||||
/**
|
|
||||||
* Exec a command.
|
|
||||||
* Output will be streamed to the live console.
|
|
||||||
* Returns promise with return code
|
|
||||||
*
|
|
||||||
* @param commandLine command to execute (can include additional args). Must be correctly escaped.
|
|
||||||
* @param args optional arguments for tool. Escaping is handled by the lib.
|
|
||||||
* @param options optional exec options. See ExecOptions
|
|
||||||
* @returns Promise<number> exit code
|
|
||||||
*/
|
|
||||||
export declare function exec(commandLine: string, args?: string[], options?: im.ExecOptions): Promise<number>;
|
|
||||||
-37
@@ -1,37 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
|
||||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
||||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
||||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
||||||
});
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
const tr = require("./toolrunner");
|
|
||||||
/**
|
|
||||||
* Exec a command.
|
|
||||||
* Output will be streamed to the live console.
|
|
||||||
* Returns promise with return code
|
|
||||||
*
|
|
||||||
* @param commandLine command to execute (can include additional args). Must be correctly escaped.
|
|
||||||
* @param args optional arguments for tool. Escaping is handled by the lib.
|
|
||||||
* @param options optional exec options. See ExecOptions
|
|
||||||
* @returns Promise<number> exit code
|
|
||||||
*/
|
|
||||||
function exec(commandLine, args, options) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
const commandArgs = tr.argStringToArray(commandLine);
|
|
||||||
if (commandArgs.length === 0) {
|
|
||||||
throw new Error(`Parameter 'commandLine' cannot be null or empty.`);
|
|
||||||
}
|
|
||||||
// Path to tool to execute should be first arg
|
|
||||||
const toolPath = commandArgs[0];
|
|
||||||
args = commandArgs.slice(1).concat(args || []);
|
|
||||||
const runner = new tr.ToolRunner(toolPath, args, options);
|
|
||||||
return runner.exec();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exports.exec = exec;
|
|
||||||
//# sourceMappingURL=exec.js.map
|
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
{"version":3,"file":"exec.js","sourceRoot":"","sources":["../src/exec.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,mCAAkC;AAElC;;;;;;;;;GASG;AACH,SAAsB,IAAI,CACxB,WAAmB,EACnB,IAAe,EACf,OAAwB;;QAExB,MAAM,WAAW,GAAG,EAAE,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAA;QACpD,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAA;SACpE;QACD,8CAA8C;QAC9C,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;QAC/B,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAA;QAC9C,MAAM,MAAM,GAAkB,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;QACxE,OAAO,MAAM,CAAC,IAAI,EAAE,CAAA;IACtB,CAAC;CAAA;AAdD,oBAcC"}
|
|
||||||
-35
@@ -1,35 +0,0 @@
|
|||||||
/// <reference types="node" />
|
|
||||||
import * as stream from 'stream';
|
|
||||||
/**
|
|
||||||
* Interface for exec options
|
|
||||||
*/
|
|
||||||
export interface ExecOptions {
|
|
||||||
/** optional working directory. defaults to current */
|
|
||||||
cwd?: string;
|
|
||||||
/** optional envvar dictionary. defaults to current process's env */
|
|
||||||
env?: {
|
|
||||||
[key: string]: string;
|
|
||||||
};
|
|
||||||
/** optional. defaults to false */
|
|
||||||
silent?: boolean;
|
|
||||||
/** optional out stream to use. Defaults to process.stdout */
|
|
||||||
outStream?: stream.Writable;
|
|
||||||
/** optional err stream to use. Defaults to process.stderr */
|
|
||||||
errStream?: stream.Writable;
|
|
||||||
/** optional. whether to skip quoting/escaping arguments if needed. defaults to false. */
|
|
||||||
windowsVerbatimArguments?: boolean;
|
|
||||||
/** optional. whether to fail if output to stderr. defaults to false */
|
|
||||||
failOnStdErr?: boolean;
|
|
||||||
/** optional. defaults to failing on non zero. ignore will not fail leaving it up to the caller */
|
|
||||||
ignoreReturnCode?: boolean;
|
|
||||||
/** optional. How long in ms to wait for STDIO streams to close after the exit event of the process before terminating. defaults to 10000 */
|
|
||||||
delay?: number;
|
|
||||||
/** optional. Listeners for output. Callback functions that will be called on these events */
|
|
||||||
listeners?: {
|
|
||||||
stdout?: (data: Buffer) => void;
|
|
||||||
stderr?: (data: Buffer) => void;
|
|
||||||
stdline?: (data: string) => void;
|
|
||||||
errline?: (data: string) => void;
|
|
||||||
debug?: (data: string) => void;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
-3
@@ -1,3 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
//# sourceMappingURL=interfaces.js.map
|
|
||||||
Generated
Vendored
-1
@@ -1 +0,0 @@
|
|||||||
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":""}
|
|
||||||
-37
@@ -1,37 +0,0 @@
|
|||||||
/// <reference types="node" />
|
|
||||||
import * as events from 'events';
|
|
||||||
import * as im from './interfaces';
|
|
||||||
export declare class ToolRunner extends events.EventEmitter {
|
|
||||||
constructor(toolPath: string, args?: string[], options?: im.ExecOptions);
|
|
||||||
private toolPath;
|
|
||||||
private args;
|
|
||||||
private options;
|
|
||||||
private _debug;
|
|
||||||
private _getCommandString;
|
|
||||||
private _processLineBuffer;
|
|
||||||
private _getSpawnFileName;
|
|
||||||
private _getSpawnArgs;
|
|
||||||
private _endsWith;
|
|
||||||
private _isCmdFile;
|
|
||||||
private _windowsQuoteCmdArg;
|
|
||||||
private _uvQuoteCmdArg;
|
|
||||||
private _cloneExecOptions;
|
|
||||||
private _getSpawnOptions;
|
|
||||||
/**
|
|
||||||
* Exec a tool.
|
|
||||||
* Output will be streamed to the live console.
|
|
||||||
* Returns promise with return code
|
|
||||||
*
|
|
||||||
* @param tool path to tool to exec
|
|
||||||
* @param options optional exec options. See ExecOptions
|
|
||||||
* @returns number
|
|
||||||
*/
|
|
||||||
exec(): Promise<number>;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Convert an arg string to an array of args. Handles escaping
|
|
||||||
*
|
|
||||||
* @param argString string of arguments
|
|
||||||
* @returns string[] array of arguments
|
|
||||||
*/
|
|
||||||
export declare function argStringToArray(argString: string): string[];
|
|
||||||
-587
@@ -1,587 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
|
||||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
||||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
||||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
||||||
});
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
const os = require("os");
|
|
||||||
const events = require("events");
|
|
||||||
const child = require("child_process");
|
|
||||||
const path = require("path");
|
|
||||||
const io = require("@actions/io");
|
|
||||||
const ioUtil = require("@actions/io/lib/io-util");
|
|
||||||
/* eslint-disable @typescript-eslint/unbound-method */
|
|
||||||
const IS_WINDOWS = process.platform === 'win32';
|
|
||||||
/*
|
|
||||||
* Class for running command line tools. Handles quoting and arg parsing in a platform agnostic way.
|
|
||||||
*/
|
|
||||||
class ToolRunner extends events.EventEmitter {
|
|
||||||
constructor(toolPath, args, options) {
|
|
||||||
super();
|
|
||||||
if (!toolPath) {
|
|
||||||
throw new Error("Parameter 'toolPath' cannot be null or empty.");
|
|
||||||
}
|
|
||||||
this.toolPath = toolPath;
|
|
||||||
this.args = args || [];
|
|
||||||
this.options = options || {};
|
|
||||||
}
|
|
||||||
_debug(message) {
|
|
||||||
if (this.options.listeners && this.options.listeners.debug) {
|
|
||||||
this.options.listeners.debug(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_getCommandString(options, noPrefix) {
|
|
||||||
const toolPath = this._getSpawnFileName();
|
|
||||||
const args = this._getSpawnArgs(options);
|
|
||||||
let cmd = noPrefix ? '' : '[command]'; // omit prefix when piped to a second tool
|
|
||||||
if (IS_WINDOWS) {
|
|
||||||
// Windows + cmd file
|
|
||||||
if (this._isCmdFile()) {
|
|
||||||
cmd += toolPath;
|
|
||||||
for (const a of args) {
|
|
||||||
cmd += ` ${a}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Windows + verbatim
|
|
||||||
else if (options.windowsVerbatimArguments) {
|
|
||||||
cmd += `"${toolPath}"`;
|
|
||||||
for (const a of args) {
|
|
||||||
cmd += ` ${a}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Windows (regular)
|
|
||||||
else {
|
|
||||||
cmd += this._windowsQuoteCmdArg(toolPath);
|
|
||||||
for (const a of args) {
|
|
||||||
cmd += ` ${this._windowsQuoteCmdArg(a)}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// OSX/Linux - this can likely be improved with some form of quoting.
|
|
||||||
// creating processes on Unix is fundamentally different than Windows.
|
|
||||||
// on Unix, execvp() takes an arg array.
|
|
||||||
cmd += toolPath;
|
|
||||||
for (const a of args) {
|
|
||||||
cmd += ` ${a}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
_processLineBuffer(data, strBuffer, onLine) {
|
|
||||||
try {
|
|
||||||
let s = strBuffer + data.toString();
|
|
||||||
let n = s.indexOf(os.EOL);
|
|
||||||
while (n > -1) {
|
|
||||||
const line = s.substring(0, n);
|
|
||||||
onLine(line);
|
|
||||||
// the rest of the string ...
|
|
||||||
s = s.substring(n + os.EOL.length);
|
|
||||||
n = s.indexOf(os.EOL);
|
|
||||||
}
|
|
||||||
strBuffer = s;
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
// streaming lines to console is best effort. Don't fail a build.
|
|
||||||
this._debug(`error processing line. Failed with error ${err}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_getSpawnFileName() {
|
|
||||||
if (IS_WINDOWS) {
|
|
||||||
if (this._isCmdFile()) {
|
|
||||||
return process.env['COMSPEC'] || 'cmd.exe';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this.toolPath;
|
|
||||||
}
|
|
||||||
_getSpawnArgs(options) {
|
|
||||||
if (IS_WINDOWS) {
|
|
||||||
if (this._isCmdFile()) {
|
|
||||||
let argline = `/D /S /C "${this._windowsQuoteCmdArg(this.toolPath)}`;
|
|
||||||
for (const a of this.args) {
|
|
||||||
argline += ' ';
|
|
||||||
argline += options.windowsVerbatimArguments
|
|
||||||
? a
|
|
||||||
: this._windowsQuoteCmdArg(a);
|
|
||||||
}
|
|
||||||
argline += '"';
|
|
||||||
return [argline];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this.args;
|
|
||||||
}
|
|
||||||
_endsWith(str, end) {
|
|
||||||
return str.endsWith(end);
|
|
||||||
}
|
|
||||||
_isCmdFile() {
|
|
||||||
const upperToolPath = this.toolPath.toUpperCase();
|
|
||||||
return (this._endsWith(upperToolPath, '.CMD') ||
|
|
||||||
this._endsWith(upperToolPath, '.BAT'));
|
|
||||||
}
|
|
||||||
_windowsQuoteCmdArg(arg) {
|
|
||||||
// for .exe, apply the normal quoting rules that libuv applies
|
|
||||||
if (!this._isCmdFile()) {
|
|
||||||
return this._uvQuoteCmdArg(arg);
|
|
||||||
}
|
|
||||||
// otherwise apply quoting rules specific to the cmd.exe command line parser.
|
|
||||||
// the libuv rules are generic and are not designed specifically for cmd.exe
|
|
||||||
// command line parser.
|
|
||||||
//
|
|
||||||
// for a detailed description of the cmd.exe command line parser, refer to
|
|
||||||
// http://stackoverflow.com/questions/4094699/how-does-the-windows-command-interpreter-cmd-exe-parse-scripts/7970912#7970912
|
|
||||||
// need quotes for empty arg
|
|
||||||
if (!arg) {
|
|
||||||
return '""';
|
|
||||||
}
|
|
||||||
// determine whether the arg needs to be quoted
|
|
||||||
const cmdSpecialChars = [
|
|
||||||
' ',
|
|
||||||
'\t',
|
|
||||||
'&',
|
|
||||||
'(',
|
|
||||||
')',
|
|
||||||
'[',
|
|
||||||
']',
|
|
||||||
'{',
|
|
||||||
'}',
|
|
||||||
'^',
|
|
||||||
'=',
|
|
||||||
';',
|
|
||||||
'!',
|
|
||||||
"'",
|
|
||||||
'+',
|
|
||||||
',',
|
|
||||||
'`',
|
|
||||||
'~',
|
|
||||||
'|',
|
|
||||||
'<',
|
|
||||||
'>',
|
|
||||||
'"'
|
|
||||||
];
|
|
||||||
let needsQuotes = false;
|
|
||||||
for (const char of arg) {
|
|
||||||
if (cmdSpecialChars.some(x => x === char)) {
|
|
||||||
needsQuotes = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// short-circuit if quotes not needed
|
|
||||||
if (!needsQuotes) {
|
|
||||||
return arg;
|
|
||||||
}
|
|
||||||
// the following quoting rules are very similar to the rules that by libuv applies.
|
|
||||||
//
|
|
||||||
// 1) wrap the string in quotes
|
|
||||||
//
|
|
||||||
// 2) double-up quotes - i.e. " => ""
|
|
||||||
//
|
|
||||||
// this is different from the libuv quoting rules. libuv replaces " with \", which unfortunately
|
|
||||||
// doesn't work well with a cmd.exe command line.
|
|
||||||
//
|
|
||||||
// note, replacing " with "" also works well if the arg is passed to a downstream .NET console app.
|
|
||||||
// for example, the command line:
|
|
||||||
// foo.exe "myarg:""my val"""
|
|
||||||
// is parsed by a .NET console app into an arg array:
|
|
||||||
// [ "myarg:\"my val\"" ]
|
|
||||||
// which is the same end result when applying libuv quoting rules. although the actual
|
|
||||||
// command line from libuv quoting rules would look like:
|
|
||||||
// foo.exe "myarg:\"my val\""
|
|
||||||
//
|
|
||||||
// 3) double-up slashes that precede a quote,
|
|
||||||
// e.g. hello \world => "hello \world"
|
|
||||||
// hello\"world => "hello\\""world"
|
|
||||||
// hello\\"world => "hello\\\\""world"
|
|
||||||
// hello world\ => "hello world\\"
|
|
||||||
//
|
|
||||||
// technically this is not required for a cmd.exe command line, or the batch argument parser.
|
|
||||||
// the reasons for including this as a .cmd quoting rule are:
|
|
||||||
//
|
|
||||||
// a) this is optimized for the scenario where the argument is passed from the .cmd file to an
|
|
||||||
// external program. many programs (e.g. .NET console apps) rely on the slash-doubling rule.
|
|
||||||
//
|
|
||||||
// b) it's what we've been doing previously (by deferring to node default behavior) and we
|
|
||||||
// haven't heard any complaints about that aspect.
|
|
||||||
//
|
|
||||||
// note, a weakness of the quoting rules chosen here, is that % is not escaped. in fact, % cannot be
|
|
||||||
// escaped when used on the command line directly - even though within a .cmd file % can be escaped
|
|
||||||
// by using %%.
|
|
||||||
//
|
|
||||||
// the saving grace is, on the command line, %var% is left as-is if var is not defined. this contrasts
|
|
||||||
// the line parsing rules within a .cmd file, where if var is not defined it is replaced with nothing.
|
|
||||||
//
|
|
||||||
// one option that was explored was replacing % with ^% - i.e. %var% => ^%var^%. this hack would
|
|
||||||
// often work, since it is unlikely that var^ would exist, and the ^ character is removed when the
|
|
||||||
// variable is used. the problem, however, is that ^ is not removed when %* is used to pass the args
|
|
||||||
// to an external program.
|
|
||||||
//
|
|
||||||
// an unexplored potential solution for the % escaping problem, is to create a wrapper .cmd file.
|
|
||||||
// % can be escaped within a .cmd file.
|
|
||||||
let reverse = '"';
|
|
||||||
let quoteHit = true;
|
|
||||||
for (let i = arg.length; i > 0; i--) {
|
|
||||||
// walk the string in reverse
|
|
||||||
reverse += arg[i - 1];
|
|
||||||
if (quoteHit && arg[i - 1] === '\\') {
|
|
||||||
reverse += '\\'; // double the slash
|
|
||||||
}
|
|
||||||
else if (arg[i - 1] === '"') {
|
|
||||||
quoteHit = true;
|
|
||||||
reverse += '"'; // double the quote
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
quoteHit = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
reverse += '"';
|
|
||||||
return reverse
|
|
||||||
.split('')
|
|
||||||
.reverse()
|
|
||||||
.join('');
|
|
||||||
}
|
|
||||||
_uvQuoteCmdArg(arg) {
|
|
||||||
// Tool runner wraps child_process.spawn() and needs to apply the same quoting as
|
|
||||||
// Node in certain cases where the undocumented spawn option windowsVerbatimArguments
|
|
||||||
// is used.
|
|
||||||
//
|
|
||||||
// Since this function is a port of quote_cmd_arg from Node 4.x (technically, lib UV,
|
|
||||||
// see https://github.com/nodejs/node/blob/v4.x/deps/uv/src/win/process.c for details),
|
|
||||||
// pasting copyright notice from Node within this function:
|
|
||||||
//
|
|
||||||
// Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
// of this software and associated documentation files (the "Software"), to
|
|
||||||
// deal in the Software without restriction, including without limitation the
|
|
||||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
// sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
// furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in
|
|
||||||
// all copies or substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
// IN THE SOFTWARE.
|
|
||||||
if (!arg) {
|
|
||||||
// Need double quotation for empty argument
|
|
||||||
return '""';
|
|
||||||
}
|
|
||||||
if (!arg.includes(' ') && !arg.includes('\t') && !arg.includes('"')) {
|
|
||||||
// No quotation needed
|
|
||||||
return arg;
|
|
||||||
}
|
|
||||||
if (!arg.includes('"') && !arg.includes('\\')) {
|
|
||||||
// No embedded double quotes or backslashes, so I can just wrap
|
|
||||||
// quote marks around the whole thing.
|
|
||||||
return `"${arg}"`;
|
|
||||||
}
|
|
||||||
// Expected input/output:
|
|
||||||
// input : hello"world
|
|
||||||
// output: "hello\"world"
|
|
||||||
// input : hello""world
|
|
||||||
// output: "hello\"\"world"
|
|
||||||
// input : hello\world
|
|
||||||
// output: hello\world
|
|
||||||
// input : hello\\world
|
|
||||||
// output: hello\\world
|
|
||||||
// input : hello\"world
|
|
||||||
// output: "hello\\\"world"
|
|
||||||
// input : hello\\"world
|
|
||||||
// output: "hello\\\\\"world"
|
|
||||||
// input : hello world\
|
|
||||||
// output: "hello world\\" - note the comment in libuv actually reads "hello world\"
|
|
||||||
// but it appears the comment is wrong, it should be "hello world\\"
|
|
||||||
let reverse = '"';
|
|
||||||
let quoteHit = true;
|
|
||||||
for (let i = arg.length; i > 0; i--) {
|
|
||||||
// walk the string in reverse
|
|
||||||
reverse += arg[i - 1];
|
|
||||||
if (quoteHit && arg[i - 1] === '\\') {
|
|
||||||
reverse += '\\';
|
|
||||||
}
|
|
||||||
else if (arg[i - 1] === '"') {
|
|
||||||
quoteHit = true;
|
|
||||||
reverse += '\\';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
quoteHit = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
reverse += '"';
|
|
||||||
return reverse
|
|
||||||
.split('')
|
|
||||||
.reverse()
|
|
||||||
.join('');
|
|
||||||
}
|
|
||||||
_cloneExecOptions(options) {
|
|
||||||
options = options || {};
|
|
||||||
const result = {
|
|
||||||
cwd: options.cwd || process.cwd(),
|
|
||||||
env: options.env || process.env,
|
|
||||||
silent: options.silent || false,
|
|
||||||
windowsVerbatimArguments: options.windowsVerbatimArguments || false,
|
|
||||||
failOnStdErr: options.failOnStdErr || false,
|
|
||||||
ignoreReturnCode: options.ignoreReturnCode || false,
|
|
||||||
delay: options.delay || 10000
|
|
||||||
};
|
|
||||||
result.outStream = options.outStream || process.stdout;
|
|
||||||
result.errStream = options.errStream || process.stderr;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
_getSpawnOptions(options, toolPath) {
|
|
||||||
options = options || {};
|
|
||||||
const result = {};
|
|
||||||
result.cwd = options.cwd;
|
|
||||||
result.env = options.env;
|
|
||||||
result['windowsVerbatimArguments'] =
|
|
||||||
options.windowsVerbatimArguments || this._isCmdFile();
|
|
||||||
if (options.windowsVerbatimArguments) {
|
|
||||||
result.argv0 = `"${toolPath}"`;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Exec a tool.
|
|
||||||
* Output will be streamed to the live console.
|
|
||||||
* Returns promise with return code
|
|
||||||
*
|
|
||||||
* @param tool path to tool to exec
|
|
||||||
* @param options optional exec options. See ExecOptions
|
|
||||||
* @returns number
|
|
||||||
*/
|
|
||||||
exec() {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
// root the tool path if it is unrooted and contains relative pathing
|
|
||||||
if (!ioUtil.isRooted(this.toolPath) &&
|
|
||||||
(this.toolPath.includes('/') ||
|
|
||||||
(IS_WINDOWS && this.toolPath.includes('\\')))) {
|
|
||||||
// prefer options.cwd if it is specified, however options.cwd may also need to be rooted
|
|
||||||
this.toolPath = path.resolve(process.cwd(), this.options.cwd || process.cwd(), this.toolPath);
|
|
||||||
}
|
|
||||||
// if the tool is only a file name, then resolve it from the PATH
|
|
||||||
// otherwise verify it exists (add extension on Windows if necessary)
|
|
||||||
this.toolPath = yield io.which(this.toolPath, true);
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
this._debug(`exec tool: ${this.toolPath}`);
|
|
||||||
this._debug('arguments:');
|
|
||||||
for (const arg of this.args) {
|
|
||||||
this._debug(` ${arg}`);
|
|
||||||
}
|
|
||||||
const optionsNonNull = this._cloneExecOptions(this.options);
|
|
||||||
if (!optionsNonNull.silent && optionsNonNull.outStream) {
|
|
||||||
optionsNonNull.outStream.write(this._getCommandString(optionsNonNull) + os.EOL);
|
|
||||||
}
|
|
||||||
const state = new ExecState(optionsNonNull, this.toolPath);
|
|
||||||
state.on('debug', (message) => {
|
|
||||||
this._debug(message);
|
|
||||||
});
|
|
||||||
const fileName = this._getSpawnFileName();
|
|
||||||
const cp = child.spawn(fileName, this._getSpawnArgs(optionsNonNull), this._getSpawnOptions(this.options, fileName));
|
|
||||||
const stdbuffer = '';
|
|
||||||
if (cp.stdout) {
|
|
||||||
cp.stdout.on('data', (data) => {
|
|
||||||
if (this.options.listeners && this.options.listeners.stdout) {
|
|
||||||
this.options.listeners.stdout(data);
|
|
||||||
}
|
|
||||||
if (!optionsNonNull.silent && optionsNonNull.outStream) {
|
|
||||||
optionsNonNull.outStream.write(data);
|
|
||||||
}
|
|
||||||
this._processLineBuffer(data, stdbuffer, (line) => {
|
|
||||||
if (this.options.listeners && this.options.listeners.stdline) {
|
|
||||||
this.options.listeners.stdline(line);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const errbuffer = '';
|
|
||||||
if (cp.stderr) {
|
|
||||||
cp.stderr.on('data', (data) => {
|
|
||||||
state.processStderr = true;
|
|
||||||
if (this.options.listeners && this.options.listeners.stderr) {
|
|
||||||
this.options.listeners.stderr(data);
|
|
||||||
}
|
|
||||||
if (!optionsNonNull.silent &&
|
|
||||||
optionsNonNull.errStream &&
|
|
||||||
optionsNonNull.outStream) {
|
|
||||||
const s = optionsNonNull.failOnStdErr
|
|
||||||
? optionsNonNull.errStream
|
|
||||||
: optionsNonNull.outStream;
|
|
||||||
s.write(data);
|
|
||||||
}
|
|
||||||
this._processLineBuffer(data, errbuffer, (line) => {
|
|
||||||
if (this.options.listeners && this.options.listeners.errline) {
|
|
||||||
this.options.listeners.errline(line);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
cp.on('error', (err) => {
|
|
||||||
state.processError = err.message;
|
|
||||||
state.processExited = true;
|
|
||||||
state.processClosed = true;
|
|
||||||
state.CheckComplete();
|
|
||||||
});
|
|
||||||
cp.on('exit', (code) => {
|
|
||||||
state.processExitCode = code;
|
|
||||||
state.processExited = true;
|
|
||||||
this._debug(`Exit code ${code} received from tool '${this.toolPath}'`);
|
|
||||||
state.CheckComplete();
|
|
||||||
});
|
|
||||||
cp.on('close', (code) => {
|
|
||||||
state.processExitCode = code;
|
|
||||||
state.processExited = true;
|
|
||||||
state.processClosed = true;
|
|
||||||
this._debug(`STDIO streams have closed for tool '${this.toolPath}'`);
|
|
||||||
state.CheckComplete();
|
|
||||||
});
|
|
||||||
state.on('done', (error, exitCode) => {
|
|
||||||
if (stdbuffer.length > 0) {
|
|
||||||
this.emit('stdline', stdbuffer);
|
|
||||||
}
|
|
||||||
if (errbuffer.length > 0) {
|
|
||||||
this.emit('errline', errbuffer);
|
|
||||||
}
|
|
||||||
cp.removeAllListeners();
|
|
||||||
if (error) {
|
|
||||||
reject(error);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
resolve(exitCode);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.ToolRunner = ToolRunner;
|
|
||||||
/**
|
|
||||||
* Convert an arg string to an array of args. Handles escaping
|
|
||||||
*
|
|
||||||
* @param argString string of arguments
|
|
||||||
* @returns string[] array of arguments
|
|
||||||
*/
|
|
||||||
function argStringToArray(argString) {
|
|
||||||
const args = [];
|
|
||||||
let inQuotes = false;
|
|
||||||
let escaped = false;
|
|
||||||
let arg = '';
|
|
||||||
function append(c) {
|
|
||||||
// we only escape double quotes.
|
|
||||||
if (escaped && c !== '"') {
|
|
||||||
arg += '\\';
|
|
||||||
}
|
|
||||||
arg += c;
|
|
||||||
escaped = false;
|
|
||||||
}
|
|
||||||
for (let i = 0; i < argString.length; i++) {
|
|
||||||
const c = argString.charAt(i);
|
|
||||||
if (c === '"') {
|
|
||||||
if (!escaped) {
|
|
||||||
inQuotes = !inQuotes;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
append(c);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (c === '\\' && escaped) {
|
|
||||||
append(c);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (c === '\\' && inQuotes) {
|
|
||||||
escaped = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (c === ' ' && !inQuotes) {
|
|
||||||
if (arg.length > 0) {
|
|
||||||
args.push(arg);
|
|
||||||
arg = '';
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
append(c);
|
|
||||||
}
|
|
||||||
if (arg.length > 0) {
|
|
||||||
args.push(arg.trim());
|
|
||||||
}
|
|
||||||
return args;
|
|
||||||
}
|
|
||||||
exports.argStringToArray = argStringToArray;
|
|
||||||
class ExecState extends events.EventEmitter {
|
|
||||||
constructor(options, toolPath) {
|
|
||||||
super();
|
|
||||||
this.processClosed = false; // tracks whether the process has exited and stdio is closed
|
|
||||||
this.processError = '';
|
|
||||||
this.processExitCode = 0;
|
|
||||||
this.processExited = false; // tracks whether the process has exited
|
|
||||||
this.processStderr = false; // tracks whether stderr was written to
|
|
||||||
this.delay = 10000; // 10 seconds
|
|
||||||
this.done = false;
|
|
||||||
this.timeout = null;
|
|
||||||
if (!toolPath) {
|
|
||||||
throw new Error('toolPath must not be empty');
|
|
||||||
}
|
|
||||||
this.options = options;
|
|
||||||
this.toolPath = toolPath;
|
|
||||||
if (options.delay) {
|
|
||||||
this.delay = options.delay;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CheckComplete() {
|
|
||||||
if (this.done) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (this.processClosed) {
|
|
||||||
this._setResult();
|
|
||||||
}
|
|
||||||
else if (this.processExited) {
|
|
||||||
this.timeout = setTimeout(ExecState.HandleTimeout, this.delay, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_debug(message) {
|
|
||||||
this.emit('debug', message);
|
|
||||||
}
|
|
||||||
_setResult() {
|
|
||||||
// determine whether there is an error
|
|
||||||
let error;
|
|
||||||
if (this.processExited) {
|
|
||||||
if (this.processError) {
|
|
||||||
error = new Error(`There was an error when attempting to execute the process '${this.toolPath}'. This may indicate the process failed to start. Error: ${this.processError}`);
|
|
||||||
}
|
|
||||||
else if (this.processExitCode !== 0 && !this.options.ignoreReturnCode) {
|
|
||||||
error = new Error(`The process '${this.toolPath}' failed with exit code ${this.processExitCode}`);
|
|
||||||
}
|
|
||||||
else if (this.processStderr && this.options.failOnStdErr) {
|
|
||||||
error = new Error(`The process '${this.toolPath}' failed because one or more lines were written to the STDERR stream`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// clear the timeout
|
|
||||||
if (this.timeout) {
|
|
||||||
clearTimeout(this.timeout);
|
|
||||||
this.timeout = null;
|
|
||||||
}
|
|
||||||
this.done = true;
|
|
||||||
this.emit('done', error, this.processExitCode);
|
|
||||||
}
|
|
||||||
static HandleTimeout(state) {
|
|
||||||
if (state.done) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!state.processClosed && state.processExited) {
|
|
||||||
const message = `The STDIO streams did not close within ${state.delay /
|
|
||||||
1000} seconds of the exit event from process '${state.toolPath}'. This may indicate a child process inherited the STDIO streams and has not yet exited.`;
|
|
||||||
state._debug(message);
|
|
||||||
}
|
|
||||||
state._setResult();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//# sourceMappingURL=toolrunner.js.map
|
|
||||||
Generated
Vendored
-1
File diff suppressed because one or more lines are too long
-40
@@ -1,40 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@actions/exec",
|
|
||||||
"version": "1.0.3",
|
|
||||||
"description": "Actions exec lib",
|
|
||||||
"keywords": [
|
|
||||||
"github",
|
|
||||||
"actions",
|
|
||||||
"exec"
|
|
||||||
],
|
|
||||||
"homepage": "https://github.com/actions/toolkit/tree/master/packages/exec",
|
|
||||||
"license": "MIT",
|
|
||||||
"main": "lib/exec.js",
|
|
||||||
"types": "lib/exec.d.ts",
|
|
||||||
"directories": {
|
|
||||||
"lib": "lib",
|
|
||||||
"test": "__tests__"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"lib"
|
|
||||||
],
|
|
||||||
"publishConfig": {
|
|
||||||
"access": "public"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/actions/toolkit.git",
|
|
||||||
"directory": "packages/exec"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"audit-moderate": "npm install && npm audit --audit-level=moderate",
|
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1",
|
|
||||||
"tsc": "tsc"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/actions/toolkit/issues"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@actions/io": "^1.0.1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Generated
Vendored
Regular → Executable
+4
-4
@@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@actions/tool-cache",
|
"name": "@actions/tool-cache",
|
||||||
"version": "1.5.5",
|
"version": "1.6.1",
|
||||||
"description": "Actions tool-cache lib",
|
"description": "Actions tool-cache lib",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"github",
|
"github",
|
||||||
"actions",
|
"actions",
|
||||||
"exec"
|
"exec"
|
||||||
],
|
],
|
||||||
"homepage": "https://github.com/actions/toolkit/tree/master/packages/tool-cache",
|
"homepage": "https://github.com/actions/toolkit/tree/main/packages/tool-cache",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "lib/tool-cache.js",
|
"main": "lib/tool-cache.js",
|
||||||
"types": "lib/tool-cache.d.ts",
|
"types": "lib/tool-cache.d.ts",
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
"directory": "packages/tool-cache"
|
"directory": "packages/tool-cache"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"audit-moderate": "npm install && npm audit --audit-level=moderate",
|
"audit-moderate": "npm install && npm audit --json --audit-level=moderate > audit.json",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1",
|
"test": "echo \"Error: run tests from root\" && exit 1",
|
||||||
"tsc": "tsc"
|
"tsc": "tsc"
|
||||||
},
|
},
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
"url": "https://github.com/actions/toolkit/issues"
|
"url": "https://github.com/actions/toolkit/issues"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.3",
|
"@actions/core": "^1.2.6",
|
||||||
"@actions/exec": "^1.0.0",
|
"@actions/exec": "^1.0.0",
|
||||||
"@actions/http-client": "^1.0.8",
|
"@actions/http-client": "^1.0.8",
|
||||||
"@actions/io": "^1.0.1",
|
"@actions/io": "^1.0.1",
|
||||||
|
|||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
The ISC License
|
||||||
|
|
||||||
|
Copyright (c) Isaac Z. Schlueter and Contributors
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||||
|
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
+166
@@ -0,0 +1,166 @@
|
|||||||
|
# lru cache
|
||||||
|
|
||||||
|
A cache object that deletes the least-recently-used items.
|
||||||
|
|
||||||
|
[](https://travis-ci.org/isaacs/node-lru-cache) [](https://coveralls.io/github/isaacs/node-lru-cache)
|
||||||
|
|
||||||
|
## Installation:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
npm install lru-cache --save
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
var LRU = require("lru-cache")
|
||||||
|
, options = { max: 500
|
||||||
|
, length: function (n, key) { return n * 2 + key.length }
|
||||||
|
, dispose: function (key, n) { n.close() }
|
||||||
|
, maxAge: 1000 * 60 * 60 }
|
||||||
|
, cache = new LRU(options)
|
||||||
|
, otherCache = new LRU(50) // sets just the max size
|
||||||
|
|
||||||
|
cache.set("key", "value")
|
||||||
|
cache.get("key") // "value"
|
||||||
|
|
||||||
|
// non-string keys ARE fully supported
|
||||||
|
// but note that it must be THE SAME object, not
|
||||||
|
// just a JSON-equivalent object.
|
||||||
|
var someObject = { a: 1 }
|
||||||
|
cache.set(someObject, 'a value')
|
||||||
|
// Object keys are not toString()-ed
|
||||||
|
cache.set('[object Object]', 'a different value')
|
||||||
|
assert.equal(cache.get(someObject), 'a value')
|
||||||
|
// A similar object with same keys/values won't work,
|
||||||
|
// because it's a different object identity
|
||||||
|
assert.equal(cache.get({ a: 1 }), undefined)
|
||||||
|
|
||||||
|
cache.reset() // empty the cache
|
||||||
|
```
|
||||||
|
|
||||||
|
If you put more stuff in it, then items will fall out.
|
||||||
|
|
||||||
|
If you try to put an oversized thing in it, then it'll fall out right
|
||||||
|
away.
|
||||||
|
|
||||||
|
## Options
|
||||||
|
|
||||||
|
* `max` The maximum size of the cache, checked by applying the length
|
||||||
|
function to all values in the cache. Not setting this is kind of
|
||||||
|
silly, since that's the whole purpose of this lib, but it defaults
|
||||||
|
to `Infinity`. Setting it to a non-number or negative number will
|
||||||
|
throw a `TypeError`. Setting it to 0 makes it be `Infinity`.
|
||||||
|
* `maxAge` Maximum age in ms. Items are not pro-actively pruned out
|
||||||
|
as they age, but if you try to get an item that is too old, it'll
|
||||||
|
drop it and return undefined instead of giving it to you.
|
||||||
|
Setting this to a negative value will make everything seem old!
|
||||||
|
Setting it to a non-number will throw a `TypeError`.
|
||||||
|
* `length` Function that is used to calculate the length of stored
|
||||||
|
items. If you're storing strings or buffers, then you probably want
|
||||||
|
to do something like `function(n, key){return n.length}`. The default is
|
||||||
|
`function(){return 1}`, which is fine if you want to store `max`
|
||||||
|
like-sized things. The item is passed as the first argument, and
|
||||||
|
the key is passed as the second argumnet.
|
||||||
|
* `dispose` Function that is called on items when they are dropped
|
||||||
|
from the cache. This can be handy if you want to close file
|
||||||
|
descriptors or do other cleanup tasks when items are no longer
|
||||||
|
accessible. Called with `key, value`. It's called *before*
|
||||||
|
actually removing the item from the internal cache, so if you want
|
||||||
|
to immediately put it back in, you'll have to do that in a
|
||||||
|
`nextTick` or `setTimeout` callback or it won't do anything.
|
||||||
|
* `stale` By default, if you set a `maxAge`, it'll only actually pull
|
||||||
|
stale items out of the cache when you `get(key)`. (That is, it's
|
||||||
|
not pre-emptively doing a `setTimeout` or anything.) If you set
|
||||||
|
`stale:true`, it'll return the stale value before deleting it. If
|
||||||
|
you don't set this, then it'll return `undefined` when you try to
|
||||||
|
get a stale entry, as if it had already been deleted.
|
||||||
|
* `noDisposeOnSet` By default, if you set a `dispose()` method, then
|
||||||
|
it'll be called whenever a `set()` operation overwrites an existing
|
||||||
|
key. If you set this option, `dispose()` will only be called when a
|
||||||
|
key falls out of the cache, not when it is overwritten.
|
||||||
|
* `updateAgeOnGet` When using time-expiring entries with `maxAge`,
|
||||||
|
setting this to `true` will make each item's effective time update
|
||||||
|
to the current time whenever it is retrieved from cache, causing it
|
||||||
|
to not expire. (It can still fall out of cache based on recency of
|
||||||
|
use, of course.)
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
* `set(key, value, maxAge)`
|
||||||
|
* `get(key) => value`
|
||||||
|
|
||||||
|
Both of these will update the "recently used"-ness of the key.
|
||||||
|
They do what you think. `maxAge` is optional and overrides the
|
||||||
|
cache `maxAge` option if provided.
|
||||||
|
|
||||||
|
If the key is not found, `get()` will return `undefined`.
|
||||||
|
|
||||||
|
The key and val can be any value.
|
||||||
|
|
||||||
|
* `peek(key)`
|
||||||
|
|
||||||
|
Returns the key value (or `undefined` if not found) without
|
||||||
|
updating the "recently used"-ness of the key.
|
||||||
|
|
||||||
|
(If you find yourself using this a lot, you *might* be using the
|
||||||
|
wrong sort of data structure, but there are some use cases where
|
||||||
|
it's handy.)
|
||||||
|
|
||||||
|
* `del(key)`
|
||||||
|
|
||||||
|
Deletes a key out of the cache.
|
||||||
|
|
||||||
|
* `reset()`
|
||||||
|
|
||||||
|
Clear the cache entirely, throwing away all values.
|
||||||
|
|
||||||
|
* `has(key)`
|
||||||
|
|
||||||
|
Check if a key is in the cache, without updating the recent-ness
|
||||||
|
or deleting it for being stale.
|
||||||
|
|
||||||
|
* `forEach(function(value,key,cache), [thisp])`
|
||||||
|
|
||||||
|
Just like `Array.prototype.forEach`. Iterates over all the keys
|
||||||
|
in the cache, in order of recent-ness. (Ie, more recently used
|
||||||
|
items are iterated over first.)
|
||||||
|
|
||||||
|
* `rforEach(function(value,key,cache), [thisp])`
|
||||||
|
|
||||||
|
The same as `cache.forEach(...)` but items are iterated over in
|
||||||
|
reverse order. (ie, less recently used items are iterated over
|
||||||
|
first.)
|
||||||
|
|
||||||
|
* `keys()`
|
||||||
|
|
||||||
|
Return an array of the keys in the cache.
|
||||||
|
|
||||||
|
* `values()`
|
||||||
|
|
||||||
|
Return an array of the values in the cache.
|
||||||
|
|
||||||
|
* `length`
|
||||||
|
|
||||||
|
Return total length of objects in cache taking into account
|
||||||
|
`length` options function.
|
||||||
|
|
||||||
|
* `itemCount`
|
||||||
|
|
||||||
|
Return total quantity of objects currently in cache. Note, that
|
||||||
|
`stale` (see options) items are returned as part of this item
|
||||||
|
count.
|
||||||
|
|
||||||
|
* `dump()`
|
||||||
|
|
||||||
|
Return an array of the cache entries ready for serialization and usage
|
||||||
|
with 'destinationCache.load(arr)`.
|
||||||
|
|
||||||
|
* `load(cacheEntriesArray)`
|
||||||
|
|
||||||
|
Loads another cache entries array, obtained with `sourceCache.dump()`,
|
||||||
|
into the cache. The destination cache is reset before loading new entries
|
||||||
|
|
||||||
|
* `prune()`
|
||||||
|
|
||||||
|
Manually iterates over the entire cache proactively pruning old entries
|
||||||
+334
@@ -0,0 +1,334 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
// A linked list to keep track of recently-used-ness
|
||||||
|
const Yallist = require('yallist')
|
||||||
|
|
||||||
|
const MAX = Symbol('max')
|
||||||
|
const LENGTH = Symbol('length')
|
||||||
|
const LENGTH_CALCULATOR = Symbol('lengthCalculator')
|
||||||
|
const ALLOW_STALE = Symbol('allowStale')
|
||||||
|
const MAX_AGE = Symbol('maxAge')
|
||||||
|
const DISPOSE = Symbol('dispose')
|
||||||
|
const NO_DISPOSE_ON_SET = Symbol('noDisposeOnSet')
|
||||||
|
const LRU_LIST = Symbol('lruList')
|
||||||
|
const CACHE = Symbol('cache')
|
||||||
|
const UPDATE_AGE_ON_GET = Symbol('updateAgeOnGet')
|
||||||
|
|
||||||
|
const naiveLength = () => 1
|
||||||
|
|
||||||
|
// lruList is a yallist where the head is the youngest
|
||||||
|
// item, and the tail is the oldest. the list contains the Hit
|
||||||
|
// objects as the entries.
|
||||||
|
// Each Hit object has a reference to its Yallist.Node. This
|
||||||
|
// never changes.
|
||||||
|
//
|
||||||
|
// cache is a Map (or PseudoMap) that matches the keys to
|
||||||
|
// the Yallist.Node object.
|
||||||
|
class LRUCache {
|
||||||
|
constructor (options) {
|
||||||
|
if (typeof options === 'number')
|
||||||
|
options = { max: options }
|
||||||
|
|
||||||
|
if (!options)
|
||||||
|
options = {}
|
||||||
|
|
||||||
|
if (options.max && (typeof options.max !== 'number' || options.max < 0))
|
||||||
|
throw new TypeError('max must be a non-negative number')
|
||||||
|
// Kind of weird to have a default max of Infinity, but oh well.
|
||||||
|
const max = this[MAX] = options.max || Infinity
|
||||||
|
|
||||||
|
const lc = options.length || naiveLength
|
||||||
|
this[LENGTH_CALCULATOR] = (typeof lc !== 'function') ? naiveLength : lc
|
||||||
|
this[ALLOW_STALE] = options.stale || false
|
||||||
|
if (options.maxAge && typeof options.maxAge !== 'number')
|
||||||
|
throw new TypeError('maxAge must be a number')
|
||||||
|
this[MAX_AGE] = options.maxAge || 0
|
||||||
|
this[DISPOSE] = options.dispose
|
||||||
|
this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false
|
||||||
|
this[UPDATE_AGE_ON_GET] = options.updateAgeOnGet || false
|
||||||
|
this.reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
// resize the cache when the max changes.
|
||||||
|
set max (mL) {
|
||||||
|
if (typeof mL !== 'number' || mL < 0)
|
||||||
|
throw new TypeError('max must be a non-negative number')
|
||||||
|
|
||||||
|
this[MAX] = mL || Infinity
|
||||||
|
trim(this)
|
||||||
|
}
|
||||||
|
get max () {
|
||||||
|
return this[MAX]
|
||||||
|
}
|
||||||
|
|
||||||
|
set allowStale (allowStale) {
|
||||||
|
this[ALLOW_STALE] = !!allowStale
|
||||||
|
}
|
||||||
|
get allowStale () {
|
||||||
|
return this[ALLOW_STALE]
|
||||||
|
}
|
||||||
|
|
||||||
|
set maxAge (mA) {
|
||||||
|
if (typeof mA !== 'number')
|
||||||
|
throw new TypeError('maxAge must be a non-negative number')
|
||||||
|
|
||||||
|
this[MAX_AGE] = mA
|
||||||
|
trim(this)
|
||||||
|
}
|
||||||
|
get maxAge () {
|
||||||
|
return this[MAX_AGE]
|
||||||
|
}
|
||||||
|
|
||||||
|
// resize the cache when the lengthCalculator changes.
|
||||||
|
set lengthCalculator (lC) {
|
||||||
|
if (typeof lC !== 'function')
|
||||||
|
lC = naiveLength
|
||||||
|
|
||||||
|
if (lC !== this[LENGTH_CALCULATOR]) {
|
||||||
|
this[LENGTH_CALCULATOR] = lC
|
||||||
|
this[LENGTH] = 0
|
||||||
|
this[LRU_LIST].forEach(hit => {
|
||||||
|
hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key)
|
||||||
|
this[LENGTH] += hit.length
|
||||||
|
})
|
||||||
|
}
|
||||||
|
trim(this)
|
||||||
|
}
|
||||||
|
get lengthCalculator () { return this[LENGTH_CALCULATOR] }
|
||||||
|
|
||||||
|
get length () { return this[LENGTH] }
|
||||||
|
get itemCount () { return this[LRU_LIST].length }
|
||||||
|
|
||||||
|
rforEach (fn, thisp) {
|
||||||
|
thisp = thisp || this
|
||||||
|
for (let walker = this[LRU_LIST].tail; walker !== null;) {
|
||||||
|
const prev = walker.prev
|
||||||
|
forEachStep(this, fn, walker, thisp)
|
||||||
|
walker = prev
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
forEach (fn, thisp) {
|
||||||
|
thisp = thisp || this
|
||||||
|
for (let walker = this[LRU_LIST].head; walker !== null;) {
|
||||||
|
const next = walker.next
|
||||||
|
forEachStep(this, fn, walker, thisp)
|
||||||
|
walker = next
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
keys () {
|
||||||
|
return this[LRU_LIST].toArray().map(k => k.key)
|
||||||
|
}
|
||||||
|
|
||||||
|
values () {
|
||||||
|
return this[LRU_LIST].toArray().map(k => k.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
reset () {
|
||||||
|
if (this[DISPOSE] &&
|
||||||
|
this[LRU_LIST] &&
|
||||||
|
this[LRU_LIST].length) {
|
||||||
|
this[LRU_LIST].forEach(hit => this[DISPOSE](hit.key, hit.value))
|
||||||
|
}
|
||||||
|
|
||||||
|
this[CACHE] = new Map() // hash of items by key
|
||||||
|
this[LRU_LIST] = new Yallist() // list of items in order of use recency
|
||||||
|
this[LENGTH] = 0 // length of items in the list
|
||||||
|
}
|
||||||
|
|
||||||
|
dump () {
|
||||||
|
return this[LRU_LIST].map(hit =>
|
||||||
|
isStale(this, hit) ? false : {
|
||||||
|
k: hit.key,
|
||||||
|
v: hit.value,
|
||||||
|
e: hit.now + (hit.maxAge || 0)
|
||||||
|
}).toArray().filter(h => h)
|
||||||
|
}
|
||||||
|
|
||||||
|
dumpLru () {
|
||||||
|
return this[LRU_LIST]
|
||||||
|
}
|
||||||
|
|
||||||
|
set (key, value, maxAge) {
|
||||||
|
maxAge = maxAge || this[MAX_AGE]
|
||||||
|
|
||||||
|
if (maxAge && typeof maxAge !== 'number')
|
||||||
|
throw new TypeError('maxAge must be a number')
|
||||||
|
|
||||||
|
const now = maxAge ? Date.now() : 0
|
||||||
|
const len = this[LENGTH_CALCULATOR](value, key)
|
||||||
|
|
||||||
|
if (this[CACHE].has(key)) {
|
||||||
|
if (len > this[MAX]) {
|
||||||
|
del(this, this[CACHE].get(key))
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const node = this[CACHE].get(key)
|
||||||
|
const item = node.value
|
||||||
|
|
||||||
|
// dispose of the old one before overwriting
|
||||||
|
// split out into 2 ifs for better coverage tracking
|
||||||
|
if (this[DISPOSE]) {
|
||||||
|
if (!this[NO_DISPOSE_ON_SET])
|
||||||
|
this[DISPOSE](key, item.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
item.now = now
|
||||||
|
item.maxAge = maxAge
|
||||||
|
item.value = value
|
||||||
|
this[LENGTH] += len - item.length
|
||||||
|
item.length = len
|
||||||
|
this.get(key)
|
||||||
|
trim(this)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
const hit = new Entry(key, value, len, now, maxAge)
|
||||||
|
|
||||||
|
// oversized objects fall out of cache automatically.
|
||||||
|
if (hit.length > this[MAX]) {
|
||||||
|
if (this[DISPOSE])
|
||||||
|
this[DISPOSE](key, value)
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
this[LENGTH] += hit.length
|
||||||
|
this[LRU_LIST].unshift(hit)
|
||||||
|
this[CACHE].set(key, this[LRU_LIST].head)
|
||||||
|
trim(this)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
has (key) {
|
||||||
|
if (!this[CACHE].has(key)) return false
|
||||||
|
const hit = this[CACHE].get(key).value
|
||||||
|
return !isStale(this, hit)
|
||||||
|
}
|
||||||
|
|
||||||
|
get (key) {
|
||||||
|
return get(this, key, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
peek (key) {
|
||||||
|
return get(this, key, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
pop () {
|
||||||
|
const node = this[LRU_LIST].tail
|
||||||
|
if (!node)
|
||||||
|
return null
|
||||||
|
|
||||||
|
del(this, node)
|
||||||
|
return node.value
|
||||||
|
}
|
||||||
|
|
||||||
|
del (key) {
|
||||||
|
del(this, this[CACHE].get(key))
|
||||||
|
}
|
||||||
|
|
||||||
|
load (arr) {
|
||||||
|
// reset the cache
|
||||||
|
this.reset()
|
||||||
|
|
||||||
|
const now = Date.now()
|
||||||
|
// A previous serialized cache has the most recent items first
|
||||||
|
for (let l = arr.length - 1; l >= 0; l--) {
|
||||||
|
const hit = arr[l]
|
||||||
|
const expiresAt = hit.e || 0
|
||||||
|
if (expiresAt === 0)
|
||||||
|
// the item was created without expiration in a non aged cache
|
||||||
|
this.set(hit.k, hit.v)
|
||||||
|
else {
|
||||||
|
const maxAge = expiresAt - now
|
||||||
|
// dont add already expired items
|
||||||
|
if (maxAge > 0) {
|
||||||
|
this.set(hit.k, hit.v, maxAge)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
prune () {
|
||||||
|
this[CACHE].forEach((value, key) => get(this, key, false))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const get = (self, key, doUse) => {
|
||||||
|
const node = self[CACHE].get(key)
|
||||||
|
if (node) {
|
||||||
|
const hit = node.value
|
||||||
|
if (isStale(self, hit)) {
|
||||||
|
del(self, node)
|
||||||
|
if (!self[ALLOW_STALE])
|
||||||
|
return undefined
|
||||||
|
} else {
|
||||||
|
if (doUse) {
|
||||||
|
if (self[UPDATE_AGE_ON_GET])
|
||||||
|
node.value.now = Date.now()
|
||||||
|
self[LRU_LIST].unshiftNode(node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hit.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const isStale = (self, hit) => {
|
||||||
|
if (!hit || (!hit.maxAge && !self[MAX_AGE]))
|
||||||
|
return false
|
||||||
|
|
||||||
|
const diff = Date.now() - hit.now
|
||||||
|
return hit.maxAge ? diff > hit.maxAge
|
||||||
|
: self[MAX_AGE] && (diff > self[MAX_AGE])
|
||||||
|
}
|
||||||
|
|
||||||
|
const trim = self => {
|
||||||
|
if (self[LENGTH] > self[MAX]) {
|
||||||
|
for (let walker = self[LRU_LIST].tail;
|
||||||
|
self[LENGTH] > self[MAX] && walker !== null;) {
|
||||||
|
// We know that we're about to delete this one, and also
|
||||||
|
// what the next least recently used key will be, so just
|
||||||
|
// go ahead and set it now.
|
||||||
|
const prev = walker.prev
|
||||||
|
del(self, walker)
|
||||||
|
walker = prev
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const del = (self, node) => {
|
||||||
|
if (node) {
|
||||||
|
const hit = node.value
|
||||||
|
if (self[DISPOSE])
|
||||||
|
self[DISPOSE](hit.key, hit.value)
|
||||||
|
|
||||||
|
self[LENGTH] -= hit.length
|
||||||
|
self[CACHE].delete(hit.key)
|
||||||
|
self[LRU_LIST].removeNode(node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Entry {
|
||||||
|
constructor (key, value, length, now, maxAge) {
|
||||||
|
this.key = key
|
||||||
|
this.value = value
|
||||||
|
this.length = length
|
||||||
|
this.now = now
|
||||||
|
this.maxAge = maxAge || 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const forEachStep = (self, fn, node, thisp) => {
|
||||||
|
let hit = node.value
|
||||||
|
if (isStale(self, hit)) {
|
||||||
|
del(self, node)
|
||||||
|
if (!self[ALLOW_STALE])
|
||||||
|
hit = undefined
|
||||||
|
}
|
||||||
|
if (hit)
|
||||||
|
fn.call(thisp, hit.value, hit.key, self)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = LRUCache
|
||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
"name": "lru-cache",
|
||||||
|
"description": "A cache object that deletes the least-recently-used items.",
|
||||||
|
"version": "6.0.0",
|
||||||
|
"author": "Isaac Z. Schlueter <i@izs.me>",
|
||||||
|
"keywords": [
|
||||||
|
"mru",
|
||||||
|
"lru",
|
||||||
|
"cache"
|
||||||
|
],
|
||||||
|
"scripts": {
|
||||||
|
"test": "tap",
|
||||||
|
"snap": "tap",
|
||||||
|
"preversion": "npm test",
|
||||||
|
"postversion": "npm publish",
|
||||||
|
"prepublishOnly": "git push origin --follow-tags"
|
||||||
|
},
|
||||||
|
"main": "index.js",
|
||||||
|
"repository": "git://github.com/isaacs/node-lru-cache.git",
|
||||||
|
"devDependencies": {
|
||||||
|
"benchmark": "^2.1.4",
|
||||||
|
"tap": "^14.10.7"
|
||||||
|
},
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"yallist": "^4.0.0"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"index.js"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-6
@@ -5,12 +5,7 @@ class Comparator {
|
|||||||
return ANY
|
return ANY
|
||||||
}
|
}
|
||||||
constructor (comp, options) {
|
constructor (comp, options) {
|
||||||
if (!options || typeof options !== 'object') {
|
options = parseOptions(options)
|
||||||
options = {
|
|
||||||
loose: !!options,
|
|
||||||
includePrerelease: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (comp instanceof Comparator) {
|
if (comp instanceof Comparator) {
|
||||||
if (comp.loose === !!options.loose) {
|
if (comp.loose === !!options.loose) {
|
||||||
@@ -132,6 +127,7 @@ class Comparator {
|
|||||||
|
|
||||||
module.exports = Comparator
|
module.exports = Comparator
|
||||||
|
|
||||||
|
const parseOptions = require('../internal/parse-options')
|
||||||
const {re, t} = require('../internal/re')
|
const {re, t} = require('../internal/re')
|
||||||
const cmp = require('../functions/cmp')
|
const cmp = require('../functions/cmp')
|
||||||
const debug = require('../internal/debug')
|
const debug = require('../internal/debug')
|
||||||
|
|||||||
+55
-8
@@ -1,12 +1,7 @@
|
|||||||
// hoisted class for cyclic dependency
|
// hoisted class for cyclic dependency
|
||||||
class Range {
|
class Range {
|
||||||
constructor (range, options) {
|
constructor (range, options) {
|
||||||
if (!options || typeof options !== 'object') {
|
options = parseOptions(options)
|
||||||
options = {
|
|
||||||
loose: !!options,
|
|
||||||
includePrerelease: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (range instanceof Range) {
|
if (range instanceof Range) {
|
||||||
if (
|
if (
|
||||||
@@ -46,6 +41,24 @@ class Range {
|
|||||||
throw new TypeError(`Invalid SemVer Range: ${range}`)
|
throw new TypeError(`Invalid SemVer Range: ${range}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if we have any that are not the null set, throw out null sets.
|
||||||
|
if (this.set.length > 1) {
|
||||||
|
// keep the first one, in case they're all null sets
|
||||||
|
const first = this.set[0]
|
||||||
|
this.set = this.set.filter(c => !isNullSet(c[0]))
|
||||||
|
if (this.set.length === 0)
|
||||||
|
this.set = [first]
|
||||||
|
else if (this.set.length > 1) {
|
||||||
|
// if we have any that are *, then the range is just *
|
||||||
|
for (const c of this.set) {
|
||||||
|
if (c.length === 1 && isAny(c[0])) {
|
||||||
|
this.set = [c]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.format()
|
this.format()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,8 +77,17 @@ class Range {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parseRange (range) {
|
parseRange (range) {
|
||||||
const loose = this.options.loose
|
|
||||||
range = range.trim()
|
range = range.trim()
|
||||||
|
|
||||||
|
// memoize range parsing for performance.
|
||||||
|
// this is a very hot path, and fully deterministic.
|
||||||
|
const memoOpts = Object.keys(this.options).join(',')
|
||||||
|
const memoKey = `parseRange:${memoOpts}:${range}`
|
||||||
|
const cached = cache.get(memoKey)
|
||||||
|
if (cached)
|
||||||
|
return cached
|
||||||
|
|
||||||
|
const loose = this.options.loose
|
||||||
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
|
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
|
||||||
const hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE]
|
const hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE]
|
||||||
range = range.replace(hr, hyphenReplace(this.options.includePrerelease))
|
range = range.replace(hr, hyphenReplace(this.options.includePrerelease))
|
||||||
@@ -87,15 +109,33 @@ class Range {
|
|||||||
// ready to be split into comparators.
|
// ready to be split into comparators.
|
||||||
|
|
||||||
const compRe = loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR]
|
const compRe = loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR]
|
||||||
return range
|
const rangeList = range
|
||||||
.split(' ')
|
.split(' ')
|
||||||
.map(comp => parseComparator(comp, this.options))
|
.map(comp => parseComparator(comp, this.options))
|
||||||
.join(' ')
|
.join(' ')
|
||||||
.split(/\s+/)
|
.split(/\s+/)
|
||||||
|
// >=0.0.0 is equivalent to *
|
||||||
.map(comp => replaceGTE0(comp, this.options))
|
.map(comp => replaceGTE0(comp, this.options))
|
||||||
// in loose mode, throw out any that are not valid comparators
|
// in loose mode, throw out any that are not valid comparators
|
||||||
.filter(this.options.loose ? comp => !!comp.match(compRe) : () => true)
|
.filter(this.options.loose ? comp => !!comp.match(compRe) : () => true)
|
||||||
.map(comp => new Comparator(comp, this.options))
|
.map(comp => new Comparator(comp, this.options))
|
||||||
|
|
||||||
|
// if any comparators are the null set, then replace with JUST null set
|
||||||
|
// if more than one comparator, remove any * comparators
|
||||||
|
// also, don't include the same comparator more than once
|
||||||
|
const l = rangeList.length
|
||||||
|
const rangeMap = new Map()
|
||||||
|
for (const comp of rangeList) {
|
||||||
|
if (isNullSet(comp))
|
||||||
|
return [comp]
|
||||||
|
rangeMap.set(comp.value, comp)
|
||||||
|
}
|
||||||
|
if (rangeMap.size > 1 && rangeMap.has(''))
|
||||||
|
rangeMap.delete('')
|
||||||
|
|
||||||
|
const result = [...rangeMap.values()]
|
||||||
|
cache.set(memoKey, result)
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
intersects (range, options) {
|
intersects (range, options) {
|
||||||
@@ -144,6 +184,10 @@ class Range {
|
|||||||
}
|
}
|
||||||
module.exports = Range
|
module.exports = Range
|
||||||
|
|
||||||
|
const LRU = require('lru-cache')
|
||||||
|
const cache = new LRU({ max: 1000 })
|
||||||
|
|
||||||
|
const parseOptions = require('../internal/parse-options')
|
||||||
const Comparator = require('./comparator')
|
const Comparator = require('./comparator')
|
||||||
const debug = require('../internal/debug')
|
const debug = require('../internal/debug')
|
||||||
const SemVer = require('./semver')
|
const SemVer = require('./semver')
|
||||||
@@ -155,6 +199,9 @@ const {
|
|||||||
caretTrimReplace
|
caretTrimReplace
|
||||||
} = require('../internal/re')
|
} = require('../internal/re')
|
||||||
|
|
||||||
|
const isNullSet = c => c.value === '<0.0.0-0'
|
||||||
|
const isAny = c => c.value === ''
|
||||||
|
|
||||||
// take a set of comparators and determine whether there
|
// take a set of comparators and determine whether there
|
||||||
// exists a version which can satisfy it
|
// exists a version which can satisfy it
|
||||||
const isSatisfiable = (comparators, options) => {
|
const isSatisfiable = (comparators, options) => {
|
||||||
|
|||||||
+3
-6
@@ -2,15 +2,12 @@ const debug = require('../internal/debug')
|
|||||||
const { MAX_LENGTH, MAX_SAFE_INTEGER } = require('../internal/constants')
|
const { MAX_LENGTH, MAX_SAFE_INTEGER } = require('../internal/constants')
|
||||||
const { re, t } = require('../internal/re')
|
const { re, t } = require('../internal/re')
|
||||||
|
|
||||||
|
const parseOptions = require('../internal/parse-options')
|
||||||
const { compareIdentifiers } = require('../internal/identifiers')
|
const { compareIdentifiers } = require('../internal/identifiers')
|
||||||
class SemVer {
|
class SemVer {
|
||||||
constructor (version, options) {
|
constructor (version, options) {
|
||||||
if (!options || typeof options !== 'object') {
|
options = parseOptions(options)
|
||||||
options = {
|
|
||||||
loose: !!options,
|
|
||||||
includePrerelease: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (version instanceof SemVer) {
|
if (version instanceof SemVer) {
|
||||||
if (version.loose === !!options.loose &&
|
if (version.loose === !!options.loose &&
|
||||||
version.includePrerelease === !!options.includePrerelease) {
|
version.includePrerelease === !!options.includePrerelease) {
|
||||||
|
|||||||
+2
-6
@@ -2,13 +2,9 @@ const {MAX_LENGTH} = require('../internal/constants')
|
|||||||
const { re, t } = require('../internal/re')
|
const { re, t } = require('../internal/re')
|
||||||
const SemVer = require('../classes/semver')
|
const SemVer = require('../classes/semver')
|
||||||
|
|
||||||
|
const parseOptions = require('../internal/parse-options')
|
||||||
const parse = (version, options) => {
|
const parse = (version, options) => {
|
||||||
if (!options || typeof options !== 'object') {
|
options = parseOptions(options)
|
||||||
options = {
|
|
||||||
loose: !!options,
|
|
||||||
includePrerelease: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (version instanceof SemVer) {
|
if (version instanceof SemVer) {
|
||||||
return version
|
return version
|
||||||
|
|||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
// parse out just the options we care about so we always get a consistent
|
||||||
|
// obj with keys in a consistent order.
|
||||||
|
const opts = ['includePrerelease', 'loose', 'rtl']
|
||||||
|
const parseOptions = options =>
|
||||||
|
!options ? {}
|
||||||
|
: typeof options !== 'object' ? { loose: true }
|
||||||
|
: opts.filter(k => options[k]).reduce((options, k) => {
|
||||||
|
options[k] = true
|
||||||
|
return options
|
||||||
|
}, {})
|
||||||
|
module.exports = parseOptions
|
||||||
+5
-2
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "semver",
|
"name": "semver",
|
||||||
"version": "7.3.2",
|
"version": "7.3.5",
|
||||||
"description": "The semantic version parser used by npm.",
|
"description": "The semantic version parser used by npm.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"repository": "https://github.com/npm/node-semver",
|
"repository": "https://github.com/npm/node-semver",
|
||||||
"bin": {
|
"bin": {
|
||||||
"semver": "./bin/semver.js"
|
"semver": "bin/semver.js"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"bin/**/*.js",
|
"bin/**/*.js",
|
||||||
@@ -34,5 +34,8 @@
|
|||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"lru-cache": "^6.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-2
@@ -19,6 +19,7 @@ const minVersion = (range, loose) => {
|
|||||||
for (let i = 0; i < range.set.length; ++i) {
|
for (let i = 0; i < range.set.length; ++i) {
|
||||||
const comparators = range.set[i]
|
const comparators = range.set[i]
|
||||||
|
|
||||||
|
let setMin = null
|
||||||
comparators.forEach((comparator) => {
|
comparators.forEach((comparator) => {
|
||||||
// Clone to avoid manipulating the comparator's semver object.
|
// Clone to avoid manipulating the comparator's semver object.
|
||||||
const compver = new SemVer(comparator.semver.version)
|
const compver = new SemVer(comparator.semver.version)
|
||||||
@@ -33,8 +34,8 @@ const minVersion = (range, loose) => {
|
|||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
case '':
|
case '':
|
||||||
case '>=':
|
case '>=':
|
||||||
if (!minver || gt(minver, compver)) {
|
if (!setMin || gt(compver, setMin)) {
|
||||||
minver = compver
|
setMin = compver
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case '<':
|
case '<':
|
||||||
@@ -46,6 +47,8 @@ const minVersion = (range, loose) => {
|
|||||||
throw new Error(`Unexpected operation: ${comparator.operator}`)
|
throw new Error(`Unexpected operation: ${comparator.operator}`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
if (setMin && (!minver || gt(minver, setMin)))
|
||||||
|
minver = setMin
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minver && range.test(minver)) {
|
if (minver && range.test(minver)) {
|
||||||
|
|||||||
+1
-1
@@ -32,7 +32,7 @@ const outside = (version, range, hilo, options) => {
|
|||||||
throw new TypeError('Must provide a hilo val of "<" or ">"')
|
throw new TypeError('Must provide a hilo val of "<" or ">"')
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it satisifes the range it is not outside
|
// If it satisfies the range it is not outside
|
||||||
if (satisfies(version, range, options)) {
|
if (satisfies(version, range, options)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
+78
-11
@@ -1,35 +1,49 @@
|
|||||||
const Range = require('../classes/range.js')
|
const Range = require('../classes/range.js')
|
||||||
const { ANY } = require('../classes/comparator.js')
|
const Comparator = require('../classes/comparator.js')
|
||||||
|
const { ANY } = Comparator
|
||||||
const satisfies = require('../functions/satisfies.js')
|
const satisfies = require('../functions/satisfies.js')
|
||||||
const compare = require('../functions/compare.js')
|
const compare = require('../functions/compare.js')
|
||||||
|
|
||||||
// Complex range `r1 || r2 || ...` is a subset of `R1 || R2 || ...` iff:
|
// Complex range `r1 || r2 || ...` is a subset of `R1 || R2 || ...` iff:
|
||||||
// - Every simple range `r1, r2, ...` is a subset of some `R1, R2, ...`
|
// - Every simple range `r1, r2, ...` is a null set, OR
|
||||||
|
// - Every simple range `r1, r2, ...` which is not a null set is a subset of
|
||||||
|
// some `R1, R2, ...`
|
||||||
//
|
//
|
||||||
// Simple range `c1 c2 ...` is a subset of simple range `C1 C2 ...` iff:
|
// Simple range `c1 c2 ...` is a subset of simple range `C1 C2 ...` iff:
|
||||||
// - If c is only the ANY comparator
|
// - If c is only the ANY comparator
|
||||||
// - If C is only the ANY comparator, return true
|
// - If C is only the ANY comparator, return true
|
||||||
// - Else return false
|
// - Else if in prerelease mode, return false
|
||||||
|
// - else replace c with `[>=0.0.0]`
|
||||||
|
// - If C is only the ANY comparator
|
||||||
|
// - if in prerelease mode, return true
|
||||||
|
// - else replace C with `[>=0.0.0]`
|
||||||
// - Let EQ be the set of = comparators in c
|
// - Let EQ be the set of = comparators in c
|
||||||
// - If EQ is more than one, return true (null set)
|
// - If EQ is more than one, return true (null set)
|
||||||
// - Let GT be the highest > or >= comparator in c
|
// - Let GT be the highest > or >= comparator in c
|
||||||
// - Let LT be the lowest < or <= comparator in c
|
// - Let LT be the lowest < or <= comparator in c
|
||||||
// - If GT and LT, and GT.semver > LT.semver, return true (null set)
|
// - If GT and LT, and GT.semver > LT.semver, return true (null set)
|
||||||
|
// - If any C is a = range, and GT or LT are set, return false
|
||||||
// - If EQ
|
// - If EQ
|
||||||
// - If GT, and EQ does not satisfy GT, return true (null set)
|
// - If GT, and EQ does not satisfy GT, return true (null set)
|
||||||
// - If LT, and EQ does not satisfy LT, return true (null set)
|
// - If LT, and EQ does not satisfy LT, return true (null set)
|
||||||
// - If EQ satisfies every C, return true
|
// - If EQ satisfies every C, return true
|
||||||
// - Else return false
|
// - Else return false
|
||||||
// - If GT
|
// - If GT
|
||||||
// - If GT is lower than any > or >= comp in C, return false
|
// - If GT.semver is lower than any > or >= comp in C, return false
|
||||||
// - If GT is >=, and GT.semver does not satisfy every C, return false
|
// - If GT is >=, and GT.semver does not satisfy every C, return false
|
||||||
|
// - If GT.semver has a prerelease, and not in prerelease mode
|
||||||
|
// - If no C has a prerelease and the GT.semver tuple, return false
|
||||||
// - If LT
|
// - If LT
|
||||||
// - If LT.semver is greater than that of any > comp in C, return false
|
// - If LT.semver is greater than any < or <= comp in C, return false
|
||||||
// - If LT is <=, and LT.semver does not satisfy every C, return false
|
// - If LT is <=, and LT.semver does not satisfy every C, return false
|
||||||
// - If any C is a = range, and GT or LT are set, return false
|
// - If GT.semver has a prerelease, and not in prerelease mode
|
||||||
|
// - If no C has a prerelease and the LT.semver tuple, return false
|
||||||
// - Else return true
|
// - Else return true
|
||||||
|
|
||||||
const subset = (sub, dom, options) => {
|
const subset = (sub, dom, options = {}) => {
|
||||||
|
if (sub === dom)
|
||||||
|
return true
|
||||||
|
|
||||||
sub = new Range(sub, options)
|
sub = new Range(sub, options)
|
||||||
dom = new Range(dom, options)
|
dom = new Range(dom, options)
|
||||||
let sawNonNull = false
|
let sawNonNull = false
|
||||||
@@ -52,8 +66,24 @@ const subset = (sub, dom, options) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const simpleSubset = (sub, dom, options) => {
|
const simpleSubset = (sub, dom, options) => {
|
||||||
if (sub.length === 1 && sub[0].semver === ANY)
|
if (sub === dom)
|
||||||
return dom.length === 1 && dom[0].semver === ANY
|
return true
|
||||||
|
|
||||||
|
if (sub.length === 1 && sub[0].semver === ANY) {
|
||||||
|
if (dom.length === 1 && dom[0].semver === ANY)
|
||||||
|
return true
|
||||||
|
else if (options.includePrerelease)
|
||||||
|
sub = [ new Comparator('>=0.0.0-0') ]
|
||||||
|
else
|
||||||
|
sub = [ new Comparator('>=0.0.0') ]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dom.length === 1 && dom[0].semver === ANY) {
|
||||||
|
if (options.includePrerelease)
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
dom = [ new Comparator('>=0.0.0') ]
|
||||||
|
}
|
||||||
|
|
||||||
const eqSet = new Set()
|
const eqSet = new Set()
|
||||||
let gt, lt
|
let gt, lt
|
||||||
@@ -90,26 +120,57 @@ const simpleSubset = (sub, dom, options) => {
|
|||||||
if (!satisfies(eq, String(c), options))
|
if (!satisfies(eq, String(c), options))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
let higher, lower
|
let higher, lower
|
||||||
let hasDomLT, hasDomGT
|
let hasDomLT, hasDomGT
|
||||||
|
// if the subset has a prerelease, we need a comparator in the superset
|
||||||
|
// with the same tuple and a prerelease, or it's not a subset
|
||||||
|
let needDomLTPre = lt &&
|
||||||
|
!options.includePrerelease &&
|
||||||
|
lt.semver.prerelease.length ? lt.semver : false
|
||||||
|
let needDomGTPre = gt &&
|
||||||
|
!options.includePrerelease &&
|
||||||
|
gt.semver.prerelease.length ? gt.semver : false
|
||||||
|
// exception: <1.2.3-0 is the same as <1.2.3
|
||||||
|
if (needDomLTPre && needDomLTPre.prerelease.length === 1 &&
|
||||||
|
lt.operator === '<' && needDomLTPre.prerelease[0] === 0) {
|
||||||
|
needDomLTPre = false
|
||||||
|
}
|
||||||
|
|
||||||
for (const c of dom) {
|
for (const c of dom) {
|
||||||
hasDomGT = hasDomGT || c.operator === '>' || c.operator === '>='
|
hasDomGT = hasDomGT || c.operator === '>' || c.operator === '>='
|
||||||
hasDomLT = hasDomLT || c.operator === '<' || c.operator === '<='
|
hasDomLT = hasDomLT || c.operator === '<' || c.operator === '<='
|
||||||
if (gt) {
|
if (gt) {
|
||||||
|
if (needDomGTPre) {
|
||||||
|
if (c.semver.prerelease && c.semver.prerelease.length &&
|
||||||
|
c.semver.major === needDomGTPre.major &&
|
||||||
|
c.semver.minor === needDomGTPre.minor &&
|
||||||
|
c.semver.patch === needDomGTPre.patch) {
|
||||||
|
needDomGTPre = false
|
||||||
|
}
|
||||||
|
}
|
||||||
if (c.operator === '>' || c.operator === '>=') {
|
if (c.operator === '>' || c.operator === '>=') {
|
||||||
higher = higherGT(gt, c, options)
|
higher = higherGT(gt, c, options)
|
||||||
if (higher === c)
|
if (higher === c && higher !== gt)
|
||||||
return false
|
return false
|
||||||
} else if (gt.operator === '>=' && !satisfies(gt.semver, String(c), options))
|
} else if (gt.operator === '>=' && !satisfies(gt.semver, String(c), options))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (lt) {
|
if (lt) {
|
||||||
|
if (needDomLTPre) {
|
||||||
|
if (c.semver.prerelease && c.semver.prerelease.length &&
|
||||||
|
c.semver.major === needDomLTPre.major &&
|
||||||
|
c.semver.minor === needDomLTPre.minor &&
|
||||||
|
c.semver.patch === needDomLTPre.patch) {
|
||||||
|
needDomLTPre = false
|
||||||
|
}
|
||||||
|
}
|
||||||
if (c.operator === '<' || c.operator === '<=') {
|
if (c.operator === '<' || c.operator === '<=') {
|
||||||
lower = lowerLT(lt, c, options)
|
lower = lowerLT(lt, c, options)
|
||||||
if (lower === c)
|
if (lower === c && lower !== lt)
|
||||||
return false
|
return false
|
||||||
} else if (lt.operator === '<=' && !satisfies(lt.semver, String(c), options))
|
} else if (lt.operator === '<=' && !satisfies(lt.semver, String(c), options))
|
||||||
return false
|
return false
|
||||||
@@ -127,6 +188,12 @@ const simpleSubset = (sub, dom, options) => {
|
|||||||
if (lt && hasDomGT && !gt && gtltComp !== 0)
|
if (lt && hasDomGT && !gt && gtltComp !== 0)
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
// we needed a prerelease range in a specific tuple, but didn't get one
|
||||||
|
// then this isn't a subset. eg >=1.2.3-pre is not a subset of >=1.0.0,
|
||||||
|
// because it includes prereleases in the 1.2.3 tuple
|
||||||
|
if (needDomGTPre || needDomLTPre)
|
||||||
|
return false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
The ISC License
|
||||||
|
|
||||||
|
Copyright (c) Isaac Z. Schlueter and Contributors
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||||
|
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
+204
@@ -0,0 +1,204 @@
|
|||||||
|
# yallist
|
||||||
|
|
||||||
|
Yet Another Linked List
|
||||||
|
|
||||||
|
There are many doubly-linked list implementations like it, but this
|
||||||
|
one is mine.
|
||||||
|
|
||||||
|
For when an array would be too big, and a Map can't be iterated in
|
||||||
|
reverse order.
|
||||||
|
|
||||||
|
|
||||||
|
[](https://travis-ci.org/isaacs/yallist) [](https://coveralls.io/github/isaacs/yallist)
|
||||||
|
|
||||||
|
## basic usage
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
var yallist = require('yallist')
|
||||||
|
var myList = yallist.create([1, 2, 3])
|
||||||
|
myList.push('foo')
|
||||||
|
myList.unshift('bar')
|
||||||
|
// of course pop() and shift() are there, too
|
||||||
|
console.log(myList.toArray()) // ['bar', 1, 2, 3, 'foo']
|
||||||
|
myList.forEach(function (k) {
|
||||||
|
// walk the list head to tail
|
||||||
|
})
|
||||||
|
myList.forEachReverse(function (k, index, list) {
|
||||||
|
// walk the list tail to head
|
||||||
|
})
|
||||||
|
var myDoubledList = myList.map(function (k) {
|
||||||
|
return k + k
|
||||||
|
})
|
||||||
|
// now myDoubledList contains ['barbar', 2, 4, 6, 'foofoo']
|
||||||
|
// mapReverse is also a thing
|
||||||
|
var myDoubledListReverse = myList.mapReverse(function (k) {
|
||||||
|
return k + k
|
||||||
|
}) // ['foofoo', 6, 4, 2, 'barbar']
|
||||||
|
|
||||||
|
var reduced = myList.reduce(function (set, entry) {
|
||||||
|
set += entry
|
||||||
|
return set
|
||||||
|
}, 'start')
|
||||||
|
console.log(reduced) // 'startfoo123bar'
|
||||||
|
```
|
||||||
|
|
||||||
|
## api
|
||||||
|
|
||||||
|
The whole API is considered "public".
|
||||||
|
|
||||||
|
Functions with the same name as an Array method work more or less the
|
||||||
|
same way.
|
||||||
|
|
||||||
|
There's reverse versions of most things because that's the point.
|
||||||
|
|
||||||
|
### Yallist
|
||||||
|
|
||||||
|
Default export, the class that holds and manages a list.
|
||||||
|
|
||||||
|
Call it with either a forEach-able (like an array) or a set of
|
||||||
|
arguments, to initialize the list.
|
||||||
|
|
||||||
|
The Array-ish methods all act like you'd expect. No magic length,
|
||||||
|
though, so if you change that it won't automatically prune or add
|
||||||
|
empty spots.
|
||||||
|
|
||||||
|
### Yallist.create(..)
|
||||||
|
|
||||||
|
Alias for Yallist function. Some people like factories.
|
||||||
|
|
||||||
|
#### yallist.head
|
||||||
|
|
||||||
|
The first node in the list
|
||||||
|
|
||||||
|
#### yallist.tail
|
||||||
|
|
||||||
|
The last node in the list
|
||||||
|
|
||||||
|
#### yallist.length
|
||||||
|
|
||||||
|
The number of nodes in the list. (Change this at your peril. It is
|
||||||
|
not magic like Array length.)
|
||||||
|
|
||||||
|
#### yallist.toArray()
|
||||||
|
|
||||||
|
Convert the list to an array.
|
||||||
|
|
||||||
|
#### yallist.forEach(fn, [thisp])
|
||||||
|
|
||||||
|
Call a function on each item in the list.
|
||||||
|
|
||||||
|
#### yallist.forEachReverse(fn, [thisp])
|
||||||
|
|
||||||
|
Call a function on each item in the list, in reverse order.
|
||||||
|
|
||||||
|
#### yallist.get(n)
|
||||||
|
|
||||||
|
Get the data at position `n` in the list. If you use this a lot,
|
||||||
|
probably better off just using an Array.
|
||||||
|
|
||||||
|
#### yallist.getReverse(n)
|
||||||
|
|
||||||
|
Get the data at position `n`, counting from the tail.
|
||||||
|
|
||||||
|
#### yallist.map(fn, thisp)
|
||||||
|
|
||||||
|
Create a new Yallist with the result of calling the function on each
|
||||||
|
item.
|
||||||
|
|
||||||
|
#### yallist.mapReverse(fn, thisp)
|
||||||
|
|
||||||
|
Same as `map`, but in reverse.
|
||||||
|
|
||||||
|
#### yallist.pop()
|
||||||
|
|
||||||
|
Get the data from the list tail, and remove the tail from the list.
|
||||||
|
|
||||||
|
#### yallist.push(item, ...)
|
||||||
|
|
||||||
|
Insert one or more items to the tail of the list.
|
||||||
|
|
||||||
|
#### yallist.reduce(fn, initialValue)
|
||||||
|
|
||||||
|
Like Array.reduce.
|
||||||
|
|
||||||
|
#### yallist.reduceReverse
|
||||||
|
|
||||||
|
Like Array.reduce, but in reverse.
|
||||||
|
|
||||||
|
#### yallist.reverse
|
||||||
|
|
||||||
|
Reverse the list in place.
|
||||||
|
|
||||||
|
#### yallist.shift()
|
||||||
|
|
||||||
|
Get the data from the list head, and remove the head from the list.
|
||||||
|
|
||||||
|
#### yallist.slice([from], [to])
|
||||||
|
|
||||||
|
Just like Array.slice, but returns a new Yallist.
|
||||||
|
|
||||||
|
#### yallist.sliceReverse([from], [to])
|
||||||
|
|
||||||
|
Just like yallist.slice, but the result is returned in reverse.
|
||||||
|
|
||||||
|
#### yallist.toArray()
|
||||||
|
|
||||||
|
Create an array representation of the list.
|
||||||
|
|
||||||
|
#### yallist.toArrayReverse()
|
||||||
|
|
||||||
|
Create a reversed array representation of the list.
|
||||||
|
|
||||||
|
#### yallist.unshift(item, ...)
|
||||||
|
|
||||||
|
Insert one or more items to the head of the list.
|
||||||
|
|
||||||
|
#### yallist.unshiftNode(node)
|
||||||
|
|
||||||
|
Move a Node object to the front of the list. (That is, pull it out of
|
||||||
|
wherever it lives, and make it the new head.)
|
||||||
|
|
||||||
|
If the node belongs to a different list, then that list will remove it
|
||||||
|
first.
|
||||||
|
|
||||||
|
#### yallist.pushNode(node)
|
||||||
|
|
||||||
|
Move a Node object to the end of the list. (That is, pull it out of
|
||||||
|
wherever it lives, and make it the new tail.)
|
||||||
|
|
||||||
|
If the node belongs to a list already, then that list will remove it
|
||||||
|
first.
|
||||||
|
|
||||||
|
#### yallist.removeNode(node)
|
||||||
|
|
||||||
|
Remove a node from the list, preserving referential integrity of head
|
||||||
|
and tail and other nodes.
|
||||||
|
|
||||||
|
Will throw an error if you try to have a list remove a node that
|
||||||
|
doesn't belong to it.
|
||||||
|
|
||||||
|
### Yallist.Node
|
||||||
|
|
||||||
|
The class that holds the data and is actually the list.
|
||||||
|
|
||||||
|
Call with `var n = new Node(value, previousNode, nextNode)`
|
||||||
|
|
||||||
|
Note that if you do direct operations on Nodes themselves, it's very
|
||||||
|
easy to get into weird states where the list is broken. Be careful :)
|
||||||
|
|
||||||
|
#### node.next
|
||||||
|
|
||||||
|
The next node in the list.
|
||||||
|
|
||||||
|
#### node.prev
|
||||||
|
|
||||||
|
The previous node in the list.
|
||||||
|
|
||||||
|
#### node.value
|
||||||
|
|
||||||
|
The data the node contains.
|
||||||
|
|
||||||
|
#### node.list
|
||||||
|
|
||||||
|
The list to which this node belongs. (Null if it does not belong to
|
||||||
|
any list.)
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
'use strict'
|
||||||
|
module.exports = function (Yallist) {
|
||||||
|
Yallist.prototype[Symbol.iterator] = function* () {
|
||||||
|
for (let walker = this.head; walker; walker = walker.next) {
|
||||||
|
yield walker.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"name": "yallist",
|
||||||
|
"version": "4.0.0",
|
||||||
|
"description": "Yet Another Linked List",
|
||||||
|
"main": "yallist.js",
|
||||||
|
"directories": {
|
||||||
|
"test": "test"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"yallist.js",
|
||||||
|
"iterator.js"
|
||||||
|
],
|
||||||
|
"dependencies": {},
|
||||||
|
"devDependencies": {
|
||||||
|
"tap": "^12.1.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "tap test/*.js --100",
|
||||||
|
"preversion": "npm test",
|
||||||
|
"postversion": "npm publish",
|
||||||
|
"postpublish": "git push origin --all; git push origin --tags"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/isaacs/yallist.git"
|
||||||
|
},
|
||||||
|
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
|
||||||
|
"license": "ISC"
|
||||||
|
}
|
||||||
+426
@@ -0,0 +1,426 @@
|
|||||||
|
'use strict'
|
||||||
|
module.exports = Yallist
|
||||||
|
|
||||||
|
Yallist.Node = Node
|
||||||
|
Yallist.create = Yallist
|
||||||
|
|
||||||
|
function Yallist (list) {
|
||||||
|
var self = this
|
||||||
|
if (!(self instanceof Yallist)) {
|
||||||
|
self = new Yallist()
|
||||||
|
}
|
||||||
|
|
||||||
|
self.tail = null
|
||||||
|
self.head = null
|
||||||
|
self.length = 0
|
||||||
|
|
||||||
|
if (list && typeof list.forEach === 'function') {
|
||||||
|
list.forEach(function (item) {
|
||||||
|
self.push(item)
|
||||||
|
})
|
||||||
|
} else if (arguments.length > 0) {
|
||||||
|
for (var i = 0, l = arguments.length; i < l; i++) {
|
||||||
|
self.push(arguments[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
|
||||||
|
Yallist.prototype.removeNode = function (node) {
|
||||||
|
if (node.list !== this) {
|
||||||
|
throw new Error('removing node which does not belong to this list')
|
||||||
|
}
|
||||||
|
|
||||||
|
var next = node.next
|
||||||
|
var prev = node.prev
|
||||||
|
|
||||||
|
if (next) {
|
||||||
|
next.prev = prev
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prev) {
|
||||||
|
prev.next = next
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node === this.head) {
|
||||||
|
this.head = next
|
||||||
|
}
|
||||||
|
if (node === this.tail) {
|
||||||
|
this.tail = prev
|
||||||
|
}
|
||||||
|
|
||||||
|
node.list.length--
|
||||||
|
node.next = null
|
||||||
|
node.prev = null
|
||||||
|
node.list = null
|
||||||
|
|
||||||
|
return next
|
||||||
|
}
|
||||||
|
|
||||||
|
Yallist.prototype.unshiftNode = function (node) {
|
||||||
|
if (node === this.head) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.list) {
|
||||||
|
node.list.removeNode(node)
|
||||||
|
}
|
||||||
|
|
||||||
|
var head = this.head
|
||||||
|
node.list = this
|
||||||
|
node.next = head
|
||||||
|
if (head) {
|
||||||
|
head.prev = node
|
||||||
|
}
|
||||||
|
|
||||||
|
this.head = node
|
||||||
|
if (!this.tail) {
|
||||||
|
this.tail = node
|
||||||
|
}
|
||||||
|
this.length++
|
||||||
|
}
|
||||||
|
|
||||||
|
Yallist.prototype.pushNode = function (node) {
|
||||||
|
if (node === this.tail) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.list) {
|
||||||
|
node.list.removeNode(node)
|
||||||
|
}
|
||||||
|
|
||||||
|
var tail = this.tail
|
||||||
|
node.list = this
|
||||||
|
node.prev = tail
|
||||||
|
if (tail) {
|
||||||
|
tail.next = node
|
||||||
|
}
|
||||||
|
|
||||||
|
this.tail = node
|
||||||
|
if (!this.head) {
|
||||||
|
this.head = node
|
||||||
|
}
|
||||||
|
this.length++
|
||||||
|
}
|
||||||
|
|
||||||
|
Yallist.prototype.push = function () {
|
||||||
|
for (var i = 0, l = arguments.length; i < l; i++) {
|
||||||
|
push(this, arguments[i])
|
||||||
|
}
|
||||||
|
return this.length
|
||||||
|
}
|
||||||
|
|
||||||
|
Yallist.prototype.unshift = function () {
|
||||||
|
for (var i = 0, l = arguments.length; i < l; i++) {
|
||||||
|
unshift(this, arguments[i])
|
||||||
|
}
|
||||||
|
return this.length
|
||||||
|
}
|
||||||
|
|
||||||
|
Yallist.prototype.pop = function () {
|
||||||
|
if (!this.tail) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
var res = this.tail.value
|
||||||
|
this.tail = this.tail.prev
|
||||||
|
if (this.tail) {
|
||||||
|
this.tail.next = null
|
||||||
|
} else {
|
||||||
|
this.head = null
|
||||||
|
}
|
||||||
|
this.length--
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
Yallist.prototype.shift = function () {
|
||||||
|
if (!this.head) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
var res = this.head.value
|
||||||
|
this.head = this.head.next
|
||||||
|
if (this.head) {
|
||||||
|
this.head.prev = null
|
||||||
|
} else {
|
||||||
|
this.tail = null
|
||||||
|
}
|
||||||
|
this.length--
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
Yallist.prototype.forEach = function (fn, thisp) {
|
||||||
|
thisp = thisp || this
|
||||||
|
for (var walker = this.head, i = 0; walker !== null; i++) {
|
||||||
|
fn.call(thisp, walker.value, i, this)
|
||||||
|
walker = walker.next
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Yallist.prototype.forEachReverse = function (fn, thisp) {
|
||||||
|
thisp = thisp || this
|
||||||
|
for (var walker = this.tail, i = this.length - 1; walker !== null; i--) {
|
||||||
|
fn.call(thisp, walker.value, i, this)
|
||||||
|
walker = walker.prev
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Yallist.prototype.get = function (n) {
|
||||||
|
for (var i = 0, walker = this.head; walker !== null && i < n; i++) {
|
||||||
|
// abort out of the list early if we hit a cycle
|
||||||
|
walker = walker.next
|
||||||
|
}
|
||||||
|
if (i === n && walker !== null) {
|
||||||
|
return walker.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Yallist.prototype.getReverse = function (n) {
|
||||||
|
for (var i = 0, walker = this.tail; walker !== null && i < n; i++) {
|
||||||
|
// abort out of the list early if we hit a cycle
|
||||||
|
walker = walker.prev
|
||||||
|
}
|
||||||
|
if (i === n && walker !== null) {
|
||||||
|
return walker.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Yallist.prototype.map = function (fn, thisp) {
|
||||||
|
thisp = thisp || this
|
||||||
|
var res = new Yallist()
|
||||||
|
for (var walker = this.head; walker !== null;) {
|
||||||
|
res.push(fn.call(thisp, walker.value, this))
|
||||||
|
walker = walker.next
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
Yallist.prototype.mapReverse = function (fn, thisp) {
|
||||||
|
thisp = thisp || this
|
||||||
|
var res = new Yallist()
|
||||||
|
for (var walker = this.tail; walker !== null;) {
|
||||||
|
res.push(fn.call(thisp, walker.value, this))
|
||||||
|
walker = walker.prev
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
Yallist.prototype.reduce = function (fn, initial) {
|
||||||
|
var acc
|
||||||
|
var walker = this.head
|
||||||
|
if (arguments.length > 1) {
|
||||||
|
acc = initial
|
||||||
|
} else if (this.head) {
|
||||||
|
walker = this.head.next
|
||||||
|
acc = this.head.value
|
||||||
|
} else {
|
||||||
|
throw new TypeError('Reduce of empty list with no initial value')
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; walker !== null; i++) {
|
||||||
|
acc = fn(acc, walker.value, i)
|
||||||
|
walker = walker.next
|
||||||
|
}
|
||||||
|
|
||||||
|
return acc
|
||||||
|
}
|
||||||
|
|
||||||
|
Yallist.prototype.reduceReverse = function (fn, initial) {
|
||||||
|
var acc
|
||||||
|
var walker = this.tail
|
||||||
|
if (arguments.length > 1) {
|
||||||
|
acc = initial
|
||||||
|
} else if (this.tail) {
|
||||||
|
walker = this.tail.prev
|
||||||
|
acc = this.tail.value
|
||||||
|
} else {
|
||||||
|
throw new TypeError('Reduce of empty list with no initial value')
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = this.length - 1; walker !== null; i--) {
|
||||||
|
acc = fn(acc, walker.value, i)
|
||||||
|
walker = walker.prev
|
||||||
|
}
|
||||||
|
|
||||||
|
return acc
|
||||||
|
}
|
||||||
|
|
||||||
|
Yallist.prototype.toArray = function () {
|
||||||
|
var arr = new Array(this.length)
|
||||||
|
for (var i = 0, walker = this.head; walker !== null; i++) {
|
||||||
|
arr[i] = walker.value
|
||||||
|
walker = walker.next
|
||||||
|
}
|
||||||
|
return arr
|
||||||
|
}
|
||||||
|
|
||||||
|
Yallist.prototype.toArrayReverse = function () {
|
||||||
|
var arr = new Array(this.length)
|
||||||
|
for (var i = 0, walker = this.tail; walker !== null; i++) {
|
||||||
|
arr[i] = walker.value
|
||||||
|
walker = walker.prev
|
||||||
|
}
|
||||||
|
return arr
|
||||||
|
}
|
||||||
|
|
||||||
|
Yallist.prototype.slice = function (from, to) {
|
||||||
|
to = to || this.length
|
||||||
|
if (to < 0) {
|
||||||
|
to += this.length
|
||||||
|
}
|
||||||
|
from = from || 0
|
||||||
|
if (from < 0) {
|
||||||
|
from += this.length
|
||||||
|
}
|
||||||
|
var ret = new Yallist()
|
||||||
|
if (to < from || to < 0) {
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
if (from < 0) {
|
||||||
|
from = 0
|
||||||
|
}
|
||||||
|
if (to > this.length) {
|
||||||
|
to = this.length
|
||||||
|
}
|
||||||
|
for (var i = 0, walker = this.head; walker !== null && i < from; i++) {
|
||||||
|
walker = walker.next
|
||||||
|
}
|
||||||
|
for (; walker !== null && i < to; i++, walker = walker.next) {
|
||||||
|
ret.push(walker.value)
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
Yallist.prototype.sliceReverse = function (from, to) {
|
||||||
|
to = to || this.length
|
||||||
|
if (to < 0) {
|
||||||
|
to += this.length
|
||||||
|
}
|
||||||
|
from = from || 0
|
||||||
|
if (from < 0) {
|
||||||
|
from += this.length
|
||||||
|
}
|
||||||
|
var ret = new Yallist()
|
||||||
|
if (to < from || to < 0) {
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
if (from < 0) {
|
||||||
|
from = 0
|
||||||
|
}
|
||||||
|
if (to > this.length) {
|
||||||
|
to = this.length
|
||||||
|
}
|
||||||
|
for (var i = this.length, walker = this.tail; walker !== null && i > to; i--) {
|
||||||
|
walker = walker.prev
|
||||||
|
}
|
||||||
|
for (; walker !== null && i > from; i--, walker = walker.prev) {
|
||||||
|
ret.push(walker.value)
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
Yallist.prototype.splice = function (start, deleteCount, ...nodes) {
|
||||||
|
if (start > this.length) {
|
||||||
|
start = this.length - 1
|
||||||
|
}
|
||||||
|
if (start < 0) {
|
||||||
|
start = this.length + start;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0, walker = this.head; walker !== null && i < start; i++) {
|
||||||
|
walker = walker.next
|
||||||
|
}
|
||||||
|
|
||||||
|
var ret = []
|
||||||
|
for (var i = 0; walker && i < deleteCount; i++) {
|
||||||
|
ret.push(walker.value)
|
||||||
|
walker = this.removeNode(walker)
|
||||||
|
}
|
||||||
|
if (walker === null) {
|
||||||
|
walker = this.tail
|
||||||
|
}
|
||||||
|
|
||||||
|
if (walker !== this.head && walker !== this.tail) {
|
||||||
|
walker = walker.prev
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < nodes.length; i++) {
|
||||||
|
walker = insert(this, walker, nodes[i])
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
Yallist.prototype.reverse = function () {
|
||||||
|
var head = this.head
|
||||||
|
var tail = this.tail
|
||||||
|
for (var walker = head; walker !== null; walker = walker.prev) {
|
||||||
|
var p = walker.prev
|
||||||
|
walker.prev = walker.next
|
||||||
|
walker.next = p
|
||||||
|
}
|
||||||
|
this.head = tail
|
||||||
|
this.tail = head
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
function insert (self, node, value) {
|
||||||
|
var inserted = node === self.head ?
|
||||||
|
new Node(value, null, node, self) :
|
||||||
|
new Node(value, node, node.next, self)
|
||||||
|
|
||||||
|
if (inserted.next === null) {
|
||||||
|
self.tail = inserted
|
||||||
|
}
|
||||||
|
if (inserted.prev === null) {
|
||||||
|
self.head = inserted
|
||||||
|
}
|
||||||
|
|
||||||
|
self.length++
|
||||||
|
|
||||||
|
return inserted
|
||||||
|
}
|
||||||
|
|
||||||
|
function push (self, item) {
|
||||||
|
self.tail = new Node(item, self.tail, null, self)
|
||||||
|
if (!self.head) {
|
||||||
|
self.head = self.tail
|
||||||
|
}
|
||||||
|
self.length++
|
||||||
|
}
|
||||||
|
|
||||||
|
function unshift (self, item) {
|
||||||
|
self.head = new Node(item, null, self.head, self)
|
||||||
|
if (!self.tail) {
|
||||||
|
self.tail = self.head
|
||||||
|
}
|
||||||
|
self.length++
|
||||||
|
}
|
||||||
|
|
||||||
|
function Node (value, prev, next, list) {
|
||||||
|
if (!(this instanceof Node)) {
|
||||||
|
return new Node(value, prev, next, list)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.list = list
|
||||||
|
this.value = value
|
||||||
|
|
||||||
|
if (prev) {
|
||||||
|
prev.next = this
|
||||||
|
this.prev = prev
|
||||||
|
} else {
|
||||||
|
this.prev = null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (next) {
|
||||||
|
next.prev = this
|
||||||
|
this.next = next
|
||||||
|
} else {
|
||||||
|
this.next = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// add if support for Symbol.iterator is present
|
||||||
|
require('./iterator.js')(Yallist)
|
||||||
|
} catch (er) {}
|
||||||
+20
-19
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "github-action-setup-xmake",
|
"name": "github-action-setup-xmake",
|
||||||
"version": "1.0.3",
|
"version": "1.0.10",
|
||||||
"description": "Set up your GitHub Actions workflow with a specific version of xmake",
|
"description": "Set up your GitHub Actions workflow with a specific version of xmake",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"author": "OpportunityLiu",
|
"author": "OpportunityLiu",
|
||||||
@@ -14,30 +14,31 @@
|
|||||||
"rebuild": "yarn clean && yarn build",
|
"rebuild": "yarn clean && yarn build",
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"lint": "eslint --fix src/**/*.ts",
|
"lint": "eslint --fix src/**/*.ts",
|
||||||
|
"format": "prettier --write .",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"release": "yarn rebuild && yarn lint && yarn install --production --no-bin-links"
|
"release": "yarn clean && yarn format && yarn lint && yarn build && yarn install --production --frozen-lockfile --no-bin-links"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.4",
|
"@actions/core": "^1.2.7",
|
||||||
"@actions/exec": "^1.0.4",
|
"@actions/exec": "^1.0.4",
|
||||||
"@actions/io": "^1.0.1",
|
"@actions/io": "^1.1.0",
|
||||||
"@actions/tool-cache": "^1.5.5",
|
"@actions/tool-cache": "^1.6.1",
|
||||||
"semver": "^7.3.2"
|
"semver": "^7.3.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^26.0.3",
|
"@types/jest": "^26.0.23",
|
||||||
"@types/node": "^14.0.14",
|
"@types/node": "^15.0.2",
|
||||||
"@types/semver": "^7.3.1",
|
"@types/semver": "^7.3.5",
|
||||||
"@typescript-eslint/eslint-plugin": "^3.4.0",
|
"@typescript-eslint/eslint-plugin": "^4.23.0",
|
||||||
"@typescript-eslint/parser": "^3.4.0",
|
"@typescript-eslint/parser": "^4.23.0",
|
||||||
"eslint": "^7.3.1",
|
"eslint": "^7.26.0",
|
||||||
"eslint-config-prettier": "^6.11.0",
|
"eslint-config-prettier": "^8.3.0",
|
||||||
"eslint-plugin-prettier": "^3.1.4",
|
"eslint-plugin-prettier": "^3.4.0",
|
||||||
"jest": "^26.1.0",
|
"jest": "^26.6.3",
|
||||||
"prettier": "^2.0.5",
|
"prettier": "^2.3.0",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"ts-jest": "^26.1.1",
|
"ts-jest": "^26.5.6",
|
||||||
"type-fest": "^0.16.0",
|
"type-fest": "^1.1.1",
|
||||||
"typescript": "^3.9.5"
|
"typescript": "^4.2.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -49,7 +49,11 @@ export async function create(repo: Repo, ref: Sha): Promise<string> {
|
|||||||
await io.mkdirP(opt.cwd);
|
await io.mkdirP(opt.cwd);
|
||||||
await exec('git', ['init'], opt);
|
await exec('git', ['init'], opt);
|
||||||
await exec('git', ['remote', 'add', 'origin', repoUrl(repo)], opt);
|
await exec('git', ['remote', 'add', 'origin', repoUrl(repo)], opt);
|
||||||
await exec('git', ['fetch', 'origin', '+refs/pull/*:refs/remotes/origin/pull/*', '+refs/heads/*:refs/remotes/origin/*'], opt);
|
await exec(
|
||||||
|
'git',
|
||||||
|
['fetch', 'origin', '+refs/pull/*:refs/remotes/origin/pull/*', '+refs/heads/*:refs/remotes/origin/*'],
|
||||||
|
opt,
|
||||||
|
);
|
||||||
await exec('git', ['checkout', ref], opt);
|
await exec('git', ['checkout', ref], opt);
|
||||||
await exec('git', ['submodule', 'update', '--init', '--recursive'], opt);
|
await exec('git', ['submodule', 'update', '--init', '--recursive'], opt);
|
||||||
return opt.cwd;
|
return opt.cwd;
|
||||||
|
|||||||
+6
-2
@@ -8,8 +8,12 @@ import { unixInstall } from './unix-install';
|
|||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const version = await selectVersion();
|
const version = await selectVersion();
|
||||||
if (os.platform() === 'win32' || os.platform() === 'cygwin') await winInstall(version);
|
if (os.platform() === 'win32' || os.platform() === 'cygwin') {
|
||||||
else await unixInstall(version);
|
const latest = await selectVersion('latest');
|
||||||
|
await winInstall(version, latest);
|
||||||
|
} else {
|
||||||
|
await unixInstall(version);
|
||||||
|
}
|
||||||
await exec('xmake --version');
|
await exec('xmake --version');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const ex = error as Error;
|
const ex = error as Error;
|
||||||
|
|||||||
+9
-1
@@ -33,9 +33,17 @@ export type RefDic = {
|
|||||||
>;
|
>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface Version {
|
export interface GitVersion {
|
||||||
version: string;
|
version: string;
|
||||||
sha: Sha;
|
sha: Sha;
|
||||||
type: keyof RefDic | 'sha';
|
type: keyof RefDic | 'sha';
|
||||||
repo: Repo;
|
repo: Repo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface LocalVersion {
|
||||||
|
type: 'local';
|
||||||
|
path: string;
|
||||||
|
version: undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Version = GitVersion | LocalVersion;
|
||||||
|
|||||||
+29
-13
@@ -8,23 +8,39 @@ import * as semver from 'semver';
|
|||||||
import * as git from './git';
|
import * as git from './git';
|
||||||
import { Version } from './interfaces';
|
import { Version } from './interfaces';
|
||||||
|
|
||||||
|
async function install(sourceDir: string, binDir: string): Promise<void> {
|
||||||
|
await exec('make', ['build'], { cwd: sourceDir });
|
||||||
|
await exec('make', ['install', `prefix=${binDir}`], { cwd: sourceDir });
|
||||||
|
}
|
||||||
|
|
||||||
export async function unixInstall(version: Version): Promise<void> {
|
export async function unixInstall(version: Version): Promise<void> {
|
||||||
const ver = version.version;
|
let toolDir: string;
|
||||||
let toolDir = toolCache.find('xmake', ver);
|
if (version.type !== 'local') {
|
||||||
if (!toolDir) {
|
const ver = version.version;
|
||||||
const sourceDir = await core.group(`download xmake ${String(version)}`, () => git.create(version.repo, version.sha));
|
toolDir = toolCache.find('xmake', ver);
|
||||||
toolDir = await core.group(`install xmake ${String(version)}`, async () => {
|
if (!toolDir) {
|
||||||
await exec('make', ['build'], { cwd: sourceDir });
|
const sourceDir = await core.group(`download xmake ${String(version)}`, () =>
|
||||||
const binDir = path.join(os.tmpdir(), `xmake-${version.sha}`);
|
git.create(version.repo, version.sha),
|
||||||
await exec('make', ['install', `prefix=${binDir}`], { cwd: sourceDir });
|
);
|
||||||
const cacheDir = await toolCache.cacheDir(binDir, 'xmake', ver);
|
toolDir = await core.group(`install xmake ${String(version)}`, async () => {
|
||||||
await io.rmRF(binDir);
|
const binDir = path.join(os.tmpdir(), `xmake-${version.sha}`);
|
||||||
await git.cleanup(version.sha);
|
await install(sourceDir, binDir);
|
||||||
return cacheDir;
|
const cacheDir = await toolCache.cacheDir(binDir, 'xmake', ver);
|
||||||
|
await io.rmRF(binDir);
|
||||||
|
await git.cleanup(version.sha);
|
||||||
|
return cacheDir;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// no tool cache for local install
|
||||||
|
toolDir = await core.group(`install local xmake at '${version.path}'`, async () => {
|
||||||
|
const binDir = path.join(os.tmpdir(), `xmake-${Date.now()}`);
|
||||||
|
await install(version.path, binDir);
|
||||||
|
return binDir;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// for versions 2.3.2 and above, xmake will be installed directly into the bin directory, and no script will be used to wrap it.
|
// for versions 2.3.2 and above, xmake will be installed directly into the bin directory, and no script will be used to wrap it.
|
||||||
if (version.type !== 'tags' || semver.gt(ver, '2.3.1')) {
|
if (version.type !== 'tags' || semver.gt(version.version, '2.3.1')) {
|
||||||
core.addPath(path.join(toolDir, 'bin'));
|
core.addPath(path.join(toolDir, 'bin'));
|
||||||
} else {
|
} else {
|
||||||
core.addPath(path.join(toolDir, 'share', 'xmake')); // only for <= 2.3.1
|
core.addPath(path.join(toolDir, 'share', 'xmake')); // only for <= 2.3.1
|
||||||
|
|||||||
+28
-2
@@ -271,6 +271,7 @@ jest.mock('./git', () => ({
|
|||||||
}));
|
}));
|
||||||
import { selectVersion } from './versions';
|
import { selectVersion } from './versions';
|
||||||
import { Repo } from './interfaces';
|
import { Repo } from './interfaces';
|
||||||
|
import { resolve } from 'path';
|
||||||
|
|
||||||
describe('selectVersion', () => {
|
describe('selectVersion', () => {
|
||||||
it('should return correct version for latest', async () => {
|
it('should return correct version for latest', async () => {
|
||||||
@@ -284,7 +285,9 @@ describe('selectVersion', () => {
|
|||||||
it('should throw for no matched', async () => {
|
it('should throw for no matched', async () => {
|
||||||
await expect(selectVersion('0.2.3')).rejects.toThrowError('No matched releases of xmake-version 0.2.3');
|
await expect(selectVersion('0.2.3')).rejects.toThrowError('No matched releases of xmake-version 0.2.3');
|
||||||
await expect(selectVersion('v0.2.3')).rejects.toThrowError('No matched releases of xmake-version 0.2.3');
|
await expect(selectVersion('v0.2.3')).rejects.toThrowError('No matched releases of xmake-version 0.2.3');
|
||||||
await expect(selectVersion('<0.2.3 > 0.1')).rejects.toThrowError('No matched releases of xmake-version <0.2.3 >=0.2.0');
|
await expect(selectVersion('<0.2.3 > 0.1')).rejects.toThrowError(
|
||||||
|
'No matched releases of xmake-version <0.2.3 >=0.2.0',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
it('should return correct version for given', async () => {
|
it('should return correct version for given', async () => {
|
||||||
await expect(selectVersion('v1.0.1')).resolves.toEqual({
|
await expect(selectVersion('v1.0.1')).resolves.toEqual({
|
||||||
@@ -330,7 +333,9 @@ describe('selectVersion', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should throw invalid pr', async () => {
|
it('should throw invalid pr', async () => {
|
||||||
await expect(selectVersion('pr@xxx')).rejects.toThrowError('Invalid pull requrest xxx, should be a positive integer');
|
await expect(selectVersion('pr@xxx')).rejects.toThrowError(
|
||||||
|
'Invalid pull requrest xxx, should be a positive integer',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return branch of sha', async () => {
|
it('should return branch of sha', async () => {
|
||||||
@@ -407,4 +412,25 @@ describe('selectVersion', () => {
|
|||||||
type: 'heads',
|
type: 'heads',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return local cwd', async () => {
|
||||||
|
await expect(selectVersion('local#')).resolves.toEqual({
|
||||||
|
path: process.cwd(),
|
||||||
|
type: 'local',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return absolute path', async () => {
|
||||||
|
await expect(selectVersion('local#/usr/bin')).resolves.toEqual({
|
||||||
|
path: resolve('/usr/bin'),
|
||||||
|
type: 'local',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return relative path', async () => {
|
||||||
|
await expect(selectVersion('local#xmake')).resolves.toEqual({
|
||||||
|
path: resolve('xmake'),
|
||||||
|
type: 'local',
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+40
-10
@@ -1,7 +1,8 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import { lsRemote } from './git';
|
import { lsRemote } from './git';
|
||||||
import { RefDic, Sha, Version, Repo } from './interfaces';
|
import { RefDic, Sha, Version, Repo, GitVersion, LocalVersion } from './interfaces';
|
||||||
|
import * as p from 'path';
|
||||||
|
|
||||||
const DEFAULT_REPO = Repo('xmake-io/xmake');
|
const DEFAULT_REPO = Repo('xmake-io/xmake');
|
||||||
|
|
||||||
@@ -14,8 +15,14 @@ async function getVersions(repo: Repo): Promise<RefDic> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
class VersionImpl implements Version {
|
class GitVersionImpl implements GitVersion {
|
||||||
constructor(readonly repo: Repo, readonly version: string, readonly sha: Sha, readonly type: Version['type'], toString: string) {
|
constructor(
|
||||||
|
readonly repo: Repo,
|
||||||
|
readonly version: string,
|
||||||
|
readonly sha: Sha,
|
||||||
|
readonly type: GitVersion['type'],
|
||||||
|
toString: string,
|
||||||
|
) {
|
||||||
this.#string = toString;
|
this.#string = toString;
|
||||||
}
|
}
|
||||||
readonly #string: string;
|
readonly #string: string;
|
||||||
@@ -24,10 +31,18 @@ class VersionImpl implements Version {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class LocalVersionImpl implements LocalVersion {
|
||||||
|
readonly type = 'local';
|
||||||
|
readonly version: undefined;
|
||||||
|
constructor(readonly path: string) {
|
||||||
|
this.path = p.resolve(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function selectBranch(repo: Repo, branch: string): Promise<Version> {
|
async function selectBranch(repo: Repo, branch: string): Promise<Version> {
|
||||||
const versions = await getVersions(repo);
|
const versions = await getVersions(repo);
|
||||||
if (branch in versions.heads) {
|
if (branch in versions.heads) {
|
||||||
return new VersionImpl(repo, branch, versions.heads[branch], 'heads', `branch ${branch}`);
|
return new GitVersionImpl(repo, branch, versions.heads[branch], 'heads', `branch ${branch}`);
|
||||||
}
|
}
|
||||||
throw new Error(`Branch ${branch} not found`);
|
throw new Error(`Branch ${branch} not found`);
|
||||||
}
|
}
|
||||||
@@ -35,10 +50,10 @@ async function selectBranch(repo: Repo, branch: string): Promise<Version> {
|
|||||||
async function selectPr(repo: Repo, pr: number): Promise<Version> {
|
async function selectPr(repo: Repo, pr: number): Promise<Version> {
|
||||||
const versions = await getVersions(repo);
|
const versions = await getVersions(repo);
|
||||||
if (pr in versions.pull) {
|
if (pr in versions.pull) {
|
||||||
const prheads = versions.pull[pr];
|
const prHeads = versions.pull[pr];
|
||||||
const sha = prheads.merge ?? prheads.head;
|
const sha = prHeads.merge ?? prHeads.head;
|
||||||
if (sha) {
|
if (sha) {
|
||||||
return new VersionImpl(repo, `pr#${pr}`, sha, 'pull', `pull request #${pr}`);
|
return new GitVersionImpl(repo, `pr#${pr}`, sha, 'pull', `pull request #${pr}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Error(`Pull requrest #${pr} not found`);
|
throw new Error(`Pull requrest #${pr} not found`);
|
||||||
@@ -58,7 +73,7 @@ async function selectSemver(repo: Repo, version: string): Promise<Version> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const sha = versions.tags[ver];
|
const sha = versions.tags[ver];
|
||||||
return new VersionImpl(repo, ver, sha, 'tags', ver);
|
return new GitVersionImpl(repo, ver, sha, 'tags', ver);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function selectSha(repo: Repo, sha: string): Promise<Version> {
|
async function selectSha(repo: Repo, sha: string): Promise<Version> {
|
||||||
@@ -80,7 +95,9 @@ async function selectSha(repo: Repo, sha: string): Promise<Version> {
|
|||||||
return selectPr(repo, Number.parseInt(pr));
|
return selectPr(repo, Number.parseInt(pr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Promise.resolve(new VersionImpl(repo, `sha#${shaValue}`, shaValue, 'sha', `commit ${shaValue.substr(0, 8)}`));
|
return Promise.resolve(
|
||||||
|
new GitVersionImpl(repo, `sha#${shaValue}`, shaValue, 'sha', `commit ${shaValue.substr(0, 8)}`),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function selectVersion(version?: string): Promise<Version> {
|
export async function selectVersion(version?: string): Promise<Version> {
|
||||||
@@ -90,6 +107,12 @@ export async function selectVersion(version?: string): Promise<Version> {
|
|||||||
|
|
||||||
let repo = DEFAULT_REPO;
|
let repo = DEFAULT_REPO;
|
||||||
let ret: Version | undefined;
|
let ret: Version | undefined;
|
||||||
|
// select local
|
||||||
|
if (version.startsWith('local#')) {
|
||||||
|
const path = version.slice('local#'.length);
|
||||||
|
ret = new LocalVersionImpl(path);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const match = /^([^/#]+\/[^/#]+)#(.+)$/.exec(version);
|
const match = /^([^/#]+\/[^/#]+)#(.+)$/.exec(version);
|
||||||
if (match) {
|
if (match) {
|
||||||
@@ -123,6 +146,13 @@ export async function selectVersion(version?: string): Promise<Version> {
|
|||||||
if (!ret) {
|
if (!ret) {
|
||||||
throw new Error(`Invalid input xmake-version ${core.getInput('xmake-version')}`);
|
throw new Error(`Invalid input xmake-version ${core.getInput('xmake-version')}`);
|
||||||
}
|
}
|
||||||
core.info(`Selected xmake ${String(ret)} (commit: ${ret.sha.substr(0, 8)})` + (repo !== DEFAULT_REPO ? ` of ${repo}` : ''));
|
if (ret.type === 'local') {
|
||||||
|
core.info(`Use local xmake at '${ret.path}'`);
|
||||||
|
} else {
|
||||||
|
core.info(
|
||||||
|
`Selected xmake ${String(ret)} (commit: ${ret.sha.substr(0, 8)})` +
|
||||||
|
(repo !== DEFAULT_REPO ? ` of ${repo}` : ''),
|
||||||
|
);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-10
@@ -5,15 +5,15 @@ import * as toolCache from '@actions/tool-cache';
|
|||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import { Version } from './interfaces';
|
import { Version, GitVersion } from './interfaces';
|
||||||
|
|
||||||
function getInstallerUrl(version: Version): string {
|
function getInstallerUrl(version: GitVersion, latest: GitVersion): string {
|
||||||
const ver = version.version;
|
const ver = version.version;
|
||||||
switch (version.type) {
|
switch (version.type) {
|
||||||
case 'heads': {
|
case 'heads': {
|
||||||
// we only use appveyor ci artifacts for branch version
|
const arch = os.arch() === 'x64' ? 'win64' : 'win32';
|
||||||
const arch = os.arch() === 'x64' ? 'x64' : 'x86';
|
const latestver = latest.version;
|
||||||
return `https://ci.appveyor.com/api/projects/waruqi/xmake/artifacts/xmake-installer.exe?branch=${ver}&pr=false&job=Image%3A+Visual+Studio+2017%3B+Platform%3A+${arch}`;
|
return `https://github.com/xmake-io/xmake/releases/download/${latestver}/xmake-${ver}.${arch}.exe`;
|
||||||
}
|
}
|
||||||
case 'pull': {
|
case 'pull': {
|
||||||
throw new Error('PR builds for windows is not supported');
|
throw new Error('PR builds for windows is not supported');
|
||||||
@@ -22,7 +22,6 @@ function getInstallerUrl(version: Version): string {
|
|||||||
throw new Error('Sha builds for windows is not supported');
|
throw new Error('Sha builds for windows is not supported');
|
||||||
}
|
}
|
||||||
case 'tags': {
|
case 'tags': {
|
||||||
// we cannot use appveyor ci artifacts, the old version links may be broken.
|
|
||||||
const arch = os.arch() === 'x64' ? 'win64' : 'win32';
|
const arch = os.arch() === 'x64' ? 'win64' : 'win32';
|
||||||
return semver.gt(ver, '2.2.6')
|
return semver.gt(ver, '2.2.6')
|
||||||
? `https://github.com/xmake-io/xmake/releases/download/${ver}/xmake-${ver}.${arch}.exe`
|
? `https://github.com/xmake-io/xmake/releases/download/${ver}/xmake-${ver}.${arch}.exe`
|
||||||
@@ -30,22 +29,28 @@ function getInstallerUrl(version: Version): string {
|
|||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
// check that we have tested all types
|
// check that we have tested all types
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
const _: never = version.type;
|
const _: never = version.type;
|
||||||
throw new Error('Unknown version type');
|
throw new Error('Unknown version type');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function winInstall(version: Version): Promise<void> {
|
export async function winInstall(version: Version, latest: Version): Promise<void> {
|
||||||
|
if (version.type === 'local' || latest.type == 'local') {
|
||||||
|
throw new Error('Local builds for windows is not supported');
|
||||||
|
}
|
||||||
const ver = version.version;
|
const ver = version.version;
|
||||||
let toolDir = toolCache.find('xmake', ver);
|
let toolDir = toolCache.find('xmake', ver);
|
||||||
if (!toolDir) {
|
if (!toolDir) {
|
||||||
const installer = await core.group(`download xmake ${String(version)}`, async () => {
|
const installer = await core.group(`download xmake ${String(version)}`, async () => {
|
||||||
const url = getInstallerUrl(version);
|
const url = getInstallerUrl(version, latest);
|
||||||
core.info(`downloading from ${url}`);
|
core.info(`downloading from ${url}`);
|
||||||
const file = await toolCache.downloadTool(url);
|
const file = await toolCache.downloadTool(url);
|
||||||
const exe = path.format({ ...path.parse(file), ext: '.exe', base: undefined });
|
const exe = path.format({
|
||||||
|
...path.parse(file),
|
||||||
|
ext: '.exe',
|
||||||
|
base: undefined,
|
||||||
|
});
|
||||||
await io.mv(file, exe);
|
await io.mv(file, exe);
|
||||||
core.info(`downloaded to ${exe}`);
|
core.info(`downloaded to ${exe}`);
|
||||||
return exe;
|
return exe;
|
||||||
|
|||||||
+5
-4
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"extends": "./tsconfig.json",
|
"extends": "./tsconfig.json",
|
||||||
"exclude": [
|
"compilerOptions": {
|
||||||
"**/*.spec.ts"
|
"removeComments": true
|
||||||
]
|
},
|
||||||
|
"exclude": ["**/*.spec.ts"]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user