tool cache
This commit is contained in:
+1
-4
@@ -5,10 +5,7 @@ inputs:
|
|||||||
xmake-version:
|
xmake-version:
|
||||||
required: true
|
required: true
|
||||||
default: latest
|
default: latest
|
||||||
description: The version to use.
|
description: The version to use. Should be a semver range or 'latest'
|
||||||
outputs:
|
|
||||||
time: # id of output
|
|
||||||
description: 'The time we greeted you'
|
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
main: 'index.js'
|
main: 'index.js'
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
const core = require('@actions/core')
|
const core = require('@actions/core')
|
||||||
|
const exec = require('@actions/exec').exec
|
||||||
|
const fs = require('fs').promises
|
||||||
|
const toolCache = require('@actions/tool-cache')
|
||||||
const os = require('os')
|
const os = require('os')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const child_process = require('child_process')
|
|
||||||
const fetch = require('node-fetch')
|
|
||||||
const fs = require('fs')
|
|
||||||
const git = require('simple-git/promise')
|
|
||||||
const semver = require('semver')
|
const semver = require('semver')
|
||||||
const octokit = require('@octokit/rest')
|
const octokit = require('@octokit/rest')
|
||||||
|
|
||||||
@@ -18,7 +17,7 @@ async function fetchVersions() {
|
|||||||
*/
|
*/
|
||||||
const versions = {}
|
const versions = {}
|
||||||
tags.data.forEach(tag => {
|
tags.data.forEach(tag => {
|
||||||
const ver = semver.valid(tag.name)
|
const ver = semver.clean(tag.name)
|
||||||
if (ver) {
|
if (ver) {
|
||||||
versions[ver] = tag.commit.sha
|
versions[ver] = tag.commit.sha
|
||||||
}
|
}
|
||||||
@@ -27,18 +26,16 @@ async function fetchVersions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function download(sha) {
|
async function download(sha) {
|
||||||
const folder = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'xmake'))
|
const folder = await fs.mkdtemp(path.join(os.tmpdir(), 'xmake'))
|
||||||
console.log(folder)
|
await exec('git', ['init'])
|
||||||
const repo = git(folder)
|
await exec('git', ['remote', 'add', 'origin', 'https://github.com/xmake-io/xmake.git'])
|
||||||
await repo.init()
|
await exec('git', ['fetch'])
|
||||||
await repo.addRemote('origin', 'https://github.com/xmake-io/xmake.git');
|
await exec('git', ['checkout', sha])
|
||||||
await repo.fetch()
|
await exec('git', ['submodule', 'update', '--init', '--recursive'])
|
||||||
await repo.checkout(sha)
|
|
||||||
await repo.submoduleUpdate(['--init', '--recursive'])
|
|
||||||
return folder
|
return folder
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getSha() {
|
async function selectVersion() {
|
||||||
let version = core.getInput('xmake-version') || 'latest'
|
let version = core.getInput('xmake-version') || 'latest'
|
||||||
if (version.toLowerCase() === 'latest') version = ''
|
if (version.toLowerCase() === 'latest') version = ''
|
||||||
version = semver.validRange(version)
|
version = semver.validRange(version)
|
||||||
@@ -47,26 +44,32 @@ async function getSha() {
|
|||||||
const versions = await fetchVersions()
|
const versions = await fetchVersions()
|
||||||
const ver = semver.maxSatisfying(Object.keys(versions), version)
|
const ver = semver.maxSatisfying(Object.keys(versions), version)
|
||||||
if (!ver) throw new Error(`No matched releases of xmake-version: ${version}`)
|
if (!ver) throw new Error(`No matched releases of xmake-version: ${version}`)
|
||||||
return versions[ver]
|
|
||||||
}
|
|
||||||
|
|
||||||
function exec(command) {
|
core.info(`Selected xmake ${ver}`)
|
||||||
return new Promise((resolve, reject) =>
|
core.debug(`SHA: ${versions[ver]}`)
|
||||||
child_process.exec(command, {}, (error, stdout, stderr) => {
|
return { version, sha: versions[ver] }
|
||||||
if (error) reject(error)
|
|
||||||
resolve({ stdout, stderr })
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
const folder = await core.group("download xmake", async () => await download(await getSha()))
|
let version = ''
|
||||||
await core.group("install xmake", async () => {
|
let sha = ''
|
||||||
await exec(`make -C ${folder} build`)
|
const folder = await core.group("download xmake", async () => {
|
||||||
await exec(`make -C ${folder} install prefix=/home/runner/.local`)
|
const v = await selectVersion()
|
||||||
|
version = v.version
|
||||||
|
sha = v.sha
|
||||||
|
return await download(sha)
|
||||||
|
})
|
||||||
|
await core.group("install xmake", async () => {
|
||||||
|
let toolDir = toolCache.find('xmake', version)
|
||||||
|
if (!toolDir) {
|
||||||
|
await exec('make', ['build'], { cwd: folder })
|
||||||
|
const prefix = path.join(os.tmpdir(), `xmake-${version}-${sha}`)
|
||||||
|
await exec('make', ['install', `prefix=${prefix}`], { cwd: folder })
|
||||||
|
toolDir = await toolCache.cacheDir(prefix, 'xmake', version)
|
||||||
|
}
|
||||||
|
core.addPath(path.join(toolDir, 'bin'))
|
||||||
})
|
})
|
||||||
core.addPath("/home/runner/.local/bin")
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error.message)
|
core.setFailed(error.message)
|
||||||
}
|
}
|
||||||
|
|||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||||
|
|
||||||
|
case `uname` in
|
||||||
|
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -x "$basedir/node" ]; then
|
||||||
|
"$basedir/node" "$basedir/../uuid/bin/uuid" "$@"
|
||||||
|
ret=$?
|
||||||
|
else
|
||||||
|
node "$basedir/../uuid/bin/uuid" "$@"
|
||||||
|
ret=$?
|
||||||
|
fi
|
||||||
|
exit $ret
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
@ECHO off
|
||||||
|
SETLOCAL
|
||||||
|
CALL :find_dp0
|
||||||
|
|
||||||
|
IF EXIST "%dp0%\node.exe" (
|
||||||
|
SET "_prog=%dp0%\node.exe"
|
||||||
|
) ELSE (
|
||||||
|
SET "_prog=node"
|
||||||
|
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||||
|
)
|
||||||
|
|
||||||
|
"%_prog%" "%dp0%\..\uuid\bin\uuid" %*
|
||||||
|
ENDLOCAL
|
||||||
|
EXIT /b %errorlevel%
|
||||||
|
:find_dp0
|
||||||
|
SET dp0=%~dp0
|
||||||
|
EXIT /b
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
#!/usr/bin/env pwsh
|
||||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||||
|
|
||||||
|
$exe=""
|
||||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||||
|
# Fix case when both the Windows and Linux builds of Node
|
||||||
|
# are installed in the same directory
|
||||||
|
$exe=".exe"
|
||||||
|
}
|
||||||
|
$ret=0
|
||||||
|
if (Test-Path "$basedir/node$exe") {
|
||||||
|
& "$basedir/node$exe" "$basedir/../uuid/bin/uuid" $args
|
||||||
|
$ret=$LASTEXITCODE
|
||||||
|
} else {
|
||||||
|
& "node$exe" "$basedir/../uuid/bin/uuid" $args
|
||||||
|
$ret=$LASTEXITCODE
|
||||||
|
}
|
||||||
|
exit $ret
|
||||||
+60
@@ -0,0 +1,60 @@
|
|||||||
|
# `@actions/exec`
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
#### Basic
|
||||||
|
|
||||||
|
You can use this package to execute your tools on the command line 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 use it in conjunction with the `which` function from `@actions/io` to execute tools that are not in the PATH:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const exec = require('@actions/exec');
|
||||||
|
const io = require('@actions/io');
|
||||||
|
|
||||||
|
const pythonPath: string = await io.which('python', true)
|
||||||
|
|
||||||
|
await exec.exec(`"${pythonPath}"`, ['main.py']);
|
||||||
|
```
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
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
@@ -0,0 +1,37 @@
|
|||||||
|
"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
@@ -0,0 +1 @@
|
|||||||
|
{"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
@@ -0,0 +1,35 @@
|
|||||||
|
/// <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;
|
||||||
|
};
|
||||||
|
}
|
||||||
Generated
Vendored
-1
@@ -1,4 +1,3 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
//# sourceMappingURL=interfaces.js.map
|
//# sourceMappingURL=interfaces.js.map
|
||||||
Generated
Vendored
+1
-1
@@ -1 +1 @@
|
|||||||
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";AAAA,uDAAuD"}
|
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":""}
|
||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
/// <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[];
|
||||||
+574
@@ -0,0 +1,574 @@
|
|||||||
|
"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");
|
||||||
|
/* 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* () {
|
||||||
|
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
|
||||||
+1
File diff suppressed because one or more lines are too long
Generated
Vendored
+21
-24
@@ -1,16 +1,16 @@
|
|||||||
{
|
{
|
||||||
"_from": "@actions/github",
|
"_from": "@actions/exec",
|
||||||
"_id": "@actions/github@1.1.0",
|
"_id": "@actions/exec@1.0.1",
|
||||||
"_inBundle": false,
|
"_inBundle": false,
|
||||||
"_integrity": "sha512-cHf6PyoNMdei13jEdGPhKprIMFmjVVW/dnM5/9QmQDJ1ZTaGVyezUSCUIC/ySNLRvDUpeFwPYMdThSEJldSbUw==",
|
"_integrity": "sha512-nvFkxwiicvpzNiCBF4wFBDfnBvi7xp/as7LE1hBxBxKG2L29+gkIPBiLKMVORL+Hg3JNf07AKRfl0V5djoypjQ==",
|
||||||
"_location": "/@actions/github",
|
"_location": "/@actions/exec",
|
||||||
"_phantomChildren": {},
|
"_phantomChildren": {},
|
||||||
"_requested": {
|
"_requested": {
|
||||||
"type": "tag",
|
"type": "tag",
|
||||||
"registry": true,
|
"registry": true,
|
||||||
"raw": "@actions/github",
|
"raw": "@actions/exec",
|
||||||
"name": "@actions/github",
|
"name": "@actions/exec",
|
||||||
"escapedName": "@actions%2fgithub",
|
"escapedName": "@actions%2fexec",
|
||||||
"scope": "@actions",
|
"scope": "@actions",
|
||||||
"rawSpec": "",
|
"rawSpec": "",
|
||||||
"saveSpec": null,
|
"saveSpec": null,
|
||||||
@@ -18,24 +18,21 @@
|
|||||||
},
|
},
|
||||||
"_requiredBy": [
|
"_requiredBy": [
|
||||||
"#USER",
|
"#USER",
|
||||||
"/"
|
"/",
|
||||||
|
"/@actions/tool-cache"
|
||||||
],
|
],
|
||||||
"_resolved": "https://registry.npmjs.org/@actions/github/-/github-1.1.0.tgz",
|
"_resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.0.1.tgz",
|
||||||
"_shasum": "06f34e6b0cf07eb2b3641de3e680dbfae6bcd400",
|
"_shasum": "1624b541165697e7008d7c87bc1f69f191263c6c",
|
||||||
"_spec": "@actions/github",
|
"_spec": "@actions/exec",
|
||||||
"_where": "C:\\Users\\lzy\\Documents\\Source\\OpportunityLiu\\github-action-setup-xmake",
|
"_where": "C:\\Users\\lzy\\Documents\\Source\\OpportunityLiu\\github-action-setup-xmake",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/actions/toolkit/issues"
|
"url": "https://github.com/actions/toolkit/issues"
|
||||||
},
|
},
|
||||||
"bundleDependencies": false,
|
"bundleDependencies": false,
|
||||||
"dependencies": {
|
|
||||||
"@octokit/graphql": "^2.0.1",
|
|
||||||
"@octokit/rest": "^16.15.0"
|
|
||||||
},
|
|
||||||
"deprecated": false,
|
"deprecated": false,
|
||||||
"description": "Actions github lib",
|
"description": "Actions exec lib",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"jest": "^24.7.1"
|
"@actions/io": "^1.0.1"
|
||||||
},
|
},
|
||||||
"directories": {
|
"directories": {
|
||||||
"lib": "lib",
|
"lib": "lib",
|
||||||
@@ -45,14 +42,15 @@
|
|||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
"gitHead": "a2ab4bcf78e4f7080f0d45856e6eeba16f0bbc52",
|
"gitHead": "a2ab4bcf78e4f7080f0d45856e6eeba16f0bbc52",
|
||||||
"homepage": "https://github.com/actions/toolkit/tree/master/packages/github",
|
"homepage": "https://github.com/actions/toolkit/tree/master/packages/exec",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"github",
|
"github",
|
||||||
"actions"
|
"actions",
|
||||||
|
"exec"
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "lib/github.js",
|
"main": "lib/exec.js",
|
||||||
"name": "@actions/github",
|
"name": "@actions/exec",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
@@ -61,9 +59,8 @@
|
|||||||
"url": "git+https://github.com/actions/toolkit.git"
|
"url": "git+https://github.com/actions/toolkit.git"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"test": "echo \"Error: run tests from root\" && exit 1",
|
||||||
"test": "jest",
|
|
||||||
"tsc": "tsc"
|
"tsc": "tsc"
|
||||||
},
|
},
|
||||||
"version": "1.1.0"
|
"version": "1.0.1"
|
||||||
}
|
}
|
||||||
-50
@@ -1,50 +0,0 @@
|
|||||||
# `@actions/github`
|
|
||||||
|
|
||||||
> A hydrated Octokit client.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
Returns an Octokit client. See https://octokit.github.io/rest.js for the API.
|
|
||||||
|
|
||||||
```js
|
|
||||||
const github = require('@actions/github');
|
|
||||||
const core = require('@actions/core');
|
|
||||||
|
|
||||||
// This should be a token with access to your repository scoped in as a secret.
|
|
||||||
const myToken = core.getInput('myToken');
|
|
||||||
|
|
||||||
const octokit = new github.GitHub(myToken);
|
|
||||||
|
|
||||||
const { data: pullRequest } = await octokit.pulls.get({
|
|
||||||
owner: 'octokit',
|
|
||||||
repo: 'rest.js',
|
|
||||||
pull_number: 123,
|
|
||||||
mediaType: {
|
|
||||||
format: 'diff'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(pullRequest);
|
|
||||||
```
|
|
||||||
|
|
||||||
You can pass client options (except `auth`, which is handled by the token argument), as specified by [Octokit](https://octokit.github.io/rest.js/), as a second argument to the `GitHub` constructor.
|
|
||||||
|
|
||||||
You can also make GraphQL requests. See https://github.com/octokit/graphql.js for the API.
|
|
||||||
|
|
||||||
```js
|
|
||||||
const result = await octokit.graphql(query, variables);
|
|
||||||
```
|
|
||||||
|
|
||||||
Finally, you can get the context of the current action:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const github = require('@actions/github');
|
|
||||||
|
|
||||||
const context = github.context;
|
|
||||||
|
|
||||||
const newIssue = await octokit.issues.create({
|
|
||||||
...context.repo,
|
|
||||||
title: 'New issue!',
|
|
||||||
body: 'Hello Universe!'
|
|
||||||
});
|
|
||||||
```
|
|
||||||
-26
@@ -1,26 +0,0 @@
|
|||||||
import { WebhookPayload } from './interfaces';
|
|
||||||
export declare class Context {
|
|
||||||
/**
|
|
||||||
* Webhook payload object that triggered the workflow
|
|
||||||
*/
|
|
||||||
payload: WebhookPayload;
|
|
||||||
eventName: string;
|
|
||||||
sha: string;
|
|
||||||
ref: string;
|
|
||||||
workflow: string;
|
|
||||||
action: string;
|
|
||||||
actor: string;
|
|
||||||
/**
|
|
||||||
* Hydrate the context from the environment
|
|
||||||
*/
|
|
||||||
constructor();
|
|
||||||
readonly issue: {
|
|
||||||
owner: string;
|
|
||||||
repo: string;
|
|
||||||
number: number;
|
|
||||||
};
|
|
||||||
readonly repo: {
|
|
||||||
owner: string;
|
|
||||||
repo: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
-45
@@ -1,45 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
const fs_1 = require("fs");
|
|
||||||
const os_1 = require("os");
|
|
||||||
class Context {
|
|
||||||
/**
|
|
||||||
* Hydrate the context from the environment
|
|
||||||
*/
|
|
||||||
constructor() {
|
|
||||||
this.payload = {};
|
|
||||||
if (process.env.GITHUB_EVENT_PATH) {
|
|
||||||
if (fs_1.existsSync(process.env.GITHUB_EVENT_PATH)) {
|
|
||||||
this.payload = JSON.parse(fs_1.readFileSync(process.env.GITHUB_EVENT_PATH, { encoding: 'utf8' }));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
process.stdout.write(`GITHUB_EVENT_PATH ${process.env.GITHUB_EVENT_PATH} does not exist${os_1.EOL}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.eventName = process.env.GITHUB_EVENT_NAME;
|
|
||||||
this.sha = process.env.GITHUB_SHA;
|
|
||||||
this.ref = process.env.GITHUB_REF;
|
|
||||||
this.workflow = process.env.GITHUB_WORKFLOW;
|
|
||||||
this.action = process.env.GITHUB_ACTION;
|
|
||||||
this.actor = process.env.GITHUB_ACTOR;
|
|
||||||
}
|
|
||||||
get issue() {
|
|
||||||
const payload = this.payload;
|
|
||||||
return Object.assign(Object.assign({}, this.repo), { number: (payload.issue || payload.pullRequest || payload).number });
|
|
||||||
}
|
|
||||||
get repo() {
|
|
||||||
if (process.env.GITHUB_REPOSITORY) {
|
|
||||||
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
|
|
||||||
return { owner, repo };
|
|
||||||
}
|
|
||||||
if (this.payload.repository) {
|
|
||||||
return {
|
|
||||||
owner: this.payload.repository.owner.login,
|
|
||||||
repo: this.payload.repository.name
|
|
||||||
};
|
|
||||||
}
|
|
||||||
throw new Error("context.repo requires a GITHUB_REPOSITORY environment variable like 'owner/repo'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.Context = Context;
|
|
||||||
//# sourceMappingURL=context.js.map
|
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;AAEA,2BAA2C;AAC3C,2BAAsB;AAEtB,MAAa,OAAO;IAalB;;OAEG;IACH;QACE,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;QACjB,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE;YACjC,IAAI,eAAU,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,EAAE;gBAC7C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CACvB,iBAAY,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAChE,CAAA;aACF;iBAAM;gBACL,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,qBACE,OAAO,CAAC,GAAG,CAAC,iBACd,kBAAkB,QAAG,EAAE,CACxB,CAAA;aACF;SACF;QACD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,iBAA2B,CAAA;QACxD,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,UAAoB,CAAA;QAC3C,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,UAAoB,CAAA;QAC3C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,eAAyB,CAAA;QACrD,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,aAAuB,CAAA;QACjD,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,YAAsB,CAAA;IACjD,CAAC;IAED,IAAI,KAAK;QACP,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAA;QAE5B,uCACK,IAAI,CAAC,IAAI,KACZ,MAAM,EAAE,CAAC,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,CAAC,MAAM,IACjE;IACH,CAAC;IAED,IAAI,IAAI;QACN,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE;YACjC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAC9D,OAAO,EAAC,KAAK,EAAE,IAAI,EAAC,CAAA;SACrB;QAED,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;YAC3B,OAAO;gBACL,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK;gBAC1C,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI;aACnC,CAAA;SACF;QAED,MAAM,IAAI,KAAK,CACb,kFAAkF,CACnF,CAAA;IACH,CAAC;CACF;AAjED,0BAiEC"}
|
|
||||||
-8
@@ -1,8 +0,0 @@
|
|||||||
import { GraphQlQueryResponse, Variables } from '@octokit/graphql';
|
|
||||||
import Octokit from '@octokit/rest';
|
|
||||||
import * as Context from './context';
|
|
||||||
export declare const context: Context.Context;
|
|
||||||
export declare class GitHub extends Octokit {
|
|
||||||
graphql: (query: string, variables?: Variables) => Promise<GraphQlQueryResponse>;
|
|
||||||
constructor(token: string, opts?: Omit<Octokit.Options, 'auth'>);
|
|
||||||
}
|
|
||||||
-29
@@ -1,29 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
||||||
};
|
|
||||||
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 });
|
|
||||||
// Originally pulled from https://github.com/JasonEtco/actions-toolkit/blob/master/src/github.ts
|
|
||||||
const graphql_1 = require("@octokit/graphql");
|
|
||||||
const rest_1 = __importDefault(require("@octokit/rest"));
|
|
||||||
const Context = __importStar(require("./context"));
|
|
||||||
// We need this in order to extend Octokit
|
|
||||||
rest_1.default.prototype = new rest_1.default();
|
|
||||||
exports.context = new Context.Context();
|
|
||||||
class GitHub extends rest_1.default {
|
|
||||||
constructor(token, opts = {}) {
|
|
||||||
super(Object.assign(Object.assign({}, opts), { auth: `token ${token}` }));
|
|
||||||
this.graphql = graphql_1.defaults({
|
|
||||||
headers: { authorization: `token ${token}` }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.GitHub = GitHub;
|
|
||||||
//# sourceMappingURL=github.js.map
|
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
{"version":3,"file":"github.js","sourceRoot":"","sources":["../src/github.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gGAAgG;AAChG,8CAA0E;AAC1E,yDAAmC;AACnC,mDAAoC;AAEpC,0CAA0C;AAC1C,cAAO,CAAC,SAAS,GAAG,IAAI,cAAO,EAAE,CAAA;AAEpB,QAAA,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,EAAE,CAAA;AAE5C,MAAa,MAAO,SAAQ,cAAO;IAMjC,YAAY,KAAa,EAAE,OAAsC,EAAE;QACjE,KAAK,iCAAK,IAAI,KAAE,IAAI,EAAE,SAAS,KAAK,EAAE,IAAE,CAAA;QACxC,IAAI,CAAC,OAAO,GAAG,kBAAQ,CAAC;YACtB,OAAO,EAAE,EAAC,aAAa,EAAE,SAAS,KAAK,EAAE,EAAC;SAC3C,CAAC,CAAA;IACJ,CAAC;CACF;AAZD,wBAYC"}
|
|
||||||
-36
@@ -1,36 +0,0 @@
|
|||||||
export interface PayloadRepository {
|
|
||||||
[key: string]: any;
|
|
||||||
full_name?: string;
|
|
||||||
name: string;
|
|
||||||
owner: {
|
|
||||||
[key: string]: any;
|
|
||||||
login: string;
|
|
||||||
name?: string;
|
|
||||||
};
|
|
||||||
html_url?: string;
|
|
||||||
}
|
|
||||||
export interface WebhookPayload {
|
|
||||||
[key: string]: any;
|
|
||||||
repository?: PayloadRepository;
|
|
||||||
issue?: {
|
|
||||||
[key: string]: any;
|
|
||||||
number: number;
|
|
||||||
html_url?: string;
|
|
||||||
body?: string;
|
|
||||||
};
|
|
||||||
pull_request?: {
|
|
||||||
[key: string]: any;
|
|
||||||
number: number;
|
|
||||||
html_url?: string;
|
|
||||||
body?: string;
|
|
||||||
};
|
|
||||||
sender?: {
|
|
||||||
[key: string]: any;
|
|
||||||
type: string;
|
|
||||||
};
|
|
||||||
action?: string;
|
|
||||||
installation?: {
|
|
||||||
id: number;
|
|
||||||
[key: string]: any;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
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.
|
||||||
+53
@@ -0,0 +1,53 @@
|
|||||||
|
# `@actions/io`
|
||||||
|
|
||||||
|
> Core functions for cli filesystem scenarios
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
#### mkdir -p
|
||||||
|
|
||||||
|
Recursively make a directory. Follows rules specified in [man mkdir](https://linux.die.net/man/1/mkdir) with the `-p` option specified:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const io = require('@actions/io');
|
||||||
|
|
||||||
|
await io.mkdirP('path/to/make');
|
||||||
|
```
|
||||||
|
|
||||||
|
#### cp/mv
|
||||||
|
|
||||||
|
Copy or move files or folders. Follows rules specified in [man cp](https://linux.die.net/man/1/cp) and [man mv](https://linux.die.net/man/1/mv):
|
||||||
|
|
||||||
|
```js
|
||||||
|
const io = require('@actions/io');
|
||||||
|
|
||||||
|
// Recursive must be true for directories
|
||||||
|
const options = { recursive: true, force: false }
|
||||||
|
|
||||||
|
await io.cp('path/to/directory', 'path/to/dest', options);
|
||||||
|
await io.mv('path/to/file', 'path/to/dest');
|
||||||
|
```
|
||||||
|
|
||||||
|
#### rm -rf
|
||||||
|
|
||||||
|
Remove a file or folder recursively. Follows rules specified in [man rm](https://linux.die.net/man/1/rm) with the `-r` and `-f` rules specified.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const io = require('@actions/io');
|
||||||
|
|
||||||
|
await io.rmRF('path/to/directory');
|
||||||
|
await io.rmRF('path/to/file');
|
||||||
|
```
|
||||||
|
|
||||||
|
#### which
|
||||||
|
|
||||||
|
Get the path to a tool and resolves via paths. Follows the rules specified in [man which](https://linux.die.net/man/1/which).
|
||||||
|
|
||||||
|
```js
|
||||||
|
const exec = require('@actions/exec');
|
||||||
|
const io = require('@actions/io');
|
||||||
|
|
||||||
|
const pythonPath: string = await io.which('python', true)
|
||||||
|
|
||||||
|
await exec.exec(`"${pythonPath}"`, ['main.py']);
|
||||||
|
```
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
/// <reference types="node" />
|
||||||
|
import * as fs from 'fs';
|
||||||
|
export declare const chmod: typeof fs.promises.chmod, copyFile: typeof fs.promises.copyFile, lstat: typeof fs.promises.lstat, mkdir: typeof fs.promises.mkdir, readdir: typeof fs.promises.readdir, readlink: typeof fs.promises.readlink, rename: typeof fs.promises.rename, rmdir: typeof fs.promises.rmdir, stat: typeof fs.promises.stat, symlink: typeof fs.promises.symlink, unlink: typeof fs.promises.unlink;
|
||||||
|
export declare const IS_WINDOWS: boolean;
|
||||||
|
export declare function exists(fsPath: string): Promise<boolean>;
|
||||||
|
export declare function isDirectory(fsPath: string, useStat?: boolean): Promise<boolean>;
|
||||||
|
/**
|
||||||
|
* On OSX/Linux, true if path starts with '/'. On Windows, true for paths like:
|
||||||
|
* \, \hello, \\hello\share, C:, and C:\hello (and corresponding alternate separator cases).
|
||||||
|
*/
|
||||||
|
export declare function isRooted(p: string): boolean;
|
||||||
|
/**
|
||||||
|
* Recursively create a directory at `fsPath`.
|
||||||
|
*
|
||||||
|
* This implementation is optimistic, meaning it attempts to create the full
|
||||||
|
* path first, and backs up the path stack from there.
|
||||||
|
*
|
||||||
|
* @param fsPath The path to create
|
||||||
|
* @param maxDepth The maximum recursion depth
|
||||||
|
* @param depth The current recursion depth
|
||||||
|
*/
|
||||||
|
export declare function mkdirP(fsPath: string, maxDepth?: number, depth?: number): Promise<void>;
|
||||||
|
/**
|
||||||
|
* Best effort attempt to determine whether a file exists and is executable.
|
||||||
|
* @param filePath file path to check
|
||||||
|
* @param extensions additional file extensions to try
|
||||||
|
* @return if file exists and is executable, returns the file path. otherwise empty string.
|
||||||
|
*/
|
||||||
|
export declare function tryGetExecutablePath(filePath: string, extensions: string[]): Promise<string>;
|
||||||
+195
@@ -0,0 +1,195 @@
|
|||||||
|
"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());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
var _a;
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const assert_1 = require("assert");
|
||||||
|
const fs = require("fs");
|
||||||
|
const path = 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;
|
||||||
|
exports.IS_WINDOWS = process.platform === 'win32';
|
||||||
|
function exists(fsPath) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
try {
|
||||||
|
yield exports.stat(fsPath);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
if (err.code === 'ENOENT') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.exists = exists;
|
||||||
|
function isDirectory(fsPath, useStat = false) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const stats = useStat ? yield exports.stat(fsPath) : yield exports.lstat(fsPath);
|
||||||
|
return stats.isDirectory();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.isDirectory = isDirectory;
|
||||||
|
/**
|
||||||
|
* On OSX/Linux, true if path starts with '/'. On Windows, true for paths like:
|
||||||
|
* \, \hello, \\hello\share, C:, and C:\hello (and corresponding alternate separator cases).
|
||||||
|
*/
|
||||||
|
function isRooted(p) {
|
||||||
|
p = normalizeSeparators(p);
|
||||||
|
if (!p) {
|
||||||
|
throw new Error('isRooted() parameter "p" cannot be empty');
|
||||||
|
}
|
||||||
|
if (exports.IS_WINDOWS) {
|
||||||
|
return (p.startsWith('\\') || /^[A-Z]:/i.test(p) // e.g. \ or \hello or \\hello
|
||||||
|
); // e.g. C: or C:\hello
|
||||||
|
}
|
||||||
|
return p.startsWith('/');
|
||||||
|
}
|
||||||
|
exports.isRooted = isRooted;
|
||||||
|
/**
|
||||||
|
* Recursively create a directory at `fsPath`.
|
||||||
|
*
|
||||||
|
* This implementation is optimistic, meaning it attempts to create the full
|
||||||
|
* path first, and backs up the path stack from there.
|
||||||
|
*
|
||||||
|
* @param fsPath The path to create
|
||||||
|
* @param maxDepth The maximum recursion depth
|
||||||
|
* @param depth The current recursion depth
|
||||||
|
*/
|
||||||
|
function mkdirP(fsPath, maxDepth = 1000, depth = 1) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
assert_1.ok(fsPath, 'a path argument must be provided');
|
||||||
|
fsPath = path.resolve(fsPath);
|
||||||
|
if (depth >= maxDepth)
|
||||||
|
return exports.mkdir(fsPath);
|
||||||
|
try {
|
||||||
|
yield exports.mkdir(fsPath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
switch (err.code) {
|
||||||
|
case 'ENOENT': {
|
||||||
|
yield mkdirP(path.dirname(fsPath), maxDepth, depth + 1);
|
||||||
|
yield exports.mkdir(fsPath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
let stats;
|
||||||
|
try {
|
||||||
|
stats = yield exports.stat(fsPath);
|
||||||
|
}
|
||||||
|
catch (err2) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
if (!stats.isDirectory())
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.mkdirP = mkdirP;
|
||||||
|
/**
|
||||||
|
* Best effort attempt to determine whether a file exists and is executable.
|
||||||
|
* @param filePath file path to check
|
||||||
|
* @param extensions additional file extensions to try
|
||||||
|
* @return if file exists and is executable, returns the file path. otherwise empty string.
|
||||||
|
*/
|
||||||
|
function tryGetExecutablePath(filePath, extensions) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
let stats = undefined;
|
||||||
|
try {
|
||||||
|
// test file exists
|
||||||
|
stats = yield exports.stat(filePath);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
if (err.code !== 'ENOENT') {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(`Unexpected error attempting to determine if executable file exists '${filePath}': ${err}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (stats && stats.isFile()) {
|
||||||
|
if (exports.IS_WINDOWS) {
|
||||||
|
// on Windows, test for valid extension
|
||||||
|
const upperExt = path.extname(filePath).toUpperCase();
|
||||||
|
if (extensions.some(validExt => validExt.toUpperCase() === upperExt)) {
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (isUnixExecutable(stats)) {
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// try each extension
|
||||||
|
const originalFilePath = filePath;
|
||||||
|
for (const extension of extensions) {
|
||||||
|
filePath = originalFilePath + extension;
|
||||||
|
stats = undefined;
|
||||||
|
try {
|
||||||
|
stats = yield exports.stat(filePath);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
if (err.code !== 'ENOENT') {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(`Unexpected error attempting to determine if executable file exists '${filePath}': ${err}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (stats && stats.isFile()) {
|
||||||
|
if (exports.IS_WINDOWS) {
|
||||||
|
// preserve the case of the actual file (since an extension was appended)
|
||||||
|
try {
|
||||||
|
const directory = path.dirname(filePath);
|
||||||
|
const upperName = path.basename(filePath).toUpperCase();
|
||||||
|
for (const actualName of yield exports.readdir(directory)) {
|
||||||
|
if (upperName === actualName.toUpperCase()) {
|
||||||
|
filePath = path.join(directory, actualName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(`Unexpected error attempting to determine the actual case of the file '${filePath}': ${err}`);
|
||||||
|
}
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (isUnixExecutable(stats)) {
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.tryGetExecutablePath = tryGetExecutablePath;
|
||||||
|
function normalizeSeparators(p) {
|
||||||
|
p = p || '';
|
||||||
|
if (exports.IS_WINDOWS) {
|
||||||
|
// convert slashes on Windows
|
||||||
|
p = p.replace(/\//g, '\\');
|
||||||
|
// remove redundant slashes
|
||||||
|
return p.replace(/\\\\+/g, '\\');
|
||||||
|
}
|
||||||
|
// remove redundant slashes
|
||||||
|
return p.replace(/\/\/+/g, '/');
|
||||||
|
}
|
||||||
|
// on Mac/Linux, test the execute bit
|
||||||
|
// R W X R W X R W X
|
||||||
|
// 256 128 64 32 16 8 4 2 1
|
||||||
|
function isUnixExecutable(stats) {
|
||||||
|
return ((stats.mode & 1) > 0 ||
|
||||||
|
((stats.mode & 8) > 0 && stats.gid === process.getgid()) ||
|
||||||
|
((stats.mode & 64) > 0 && stats.uid === process.getuid()));
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=io-util.js.map
|
||||||
+1
@@ -0,0 +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,CAAC,MAAM,YAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,aAAK,CAAC,MAAM,CAAC,CAAA;QAChE,OAAO,KAAK,CAAC,WAAW,EAAE,CAAA;IAC5B,CAAC;CAAA;AAND,kCAMC;AAED;;;GAGG;AACH,SAAgB,QAAQ,CAAC,CAAS;IAChC,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAAA;IAC1B,IAAI,CAAC,CAAC,EAAE;QACN,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAA;KAC5D;IAED,IAAI,kBAAU,EAAE;QACd,OAAO,CACL,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,8BAA8B;SACxE,CAAA,CAAC,sBAAsB;KACzB;IAED,OAAO,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;AAC1B,CAAC;AAbD,4BAaC;AAED;;;;;;;;;GASG;AACH,SAAsB,MAAM,CAC1B,MAAc,EACd,WAAmB,IAAI,EACvB,QAAgB,CAAC;;QAEjB,WAAE,CAAC,MAAM,EAAE,kCAAkC,CAAC,CAAA;QAE9C,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAE7B,IAAI,KAAK,IAAI,QAAQ;YAAE,OAAO,aAAK,CAAC,MAAM,CAAC,CAAA;QAE3C,IAAI;YACF,MAAM,aAAK,CAAC,MAAM,CAAC,CAAA;YACnB,OAAM;SACP;QAAC,OAAO,GAAG,EAAE;YACZ,QAAQ,GAAG,CAAC,IAAI,EAAE;gBAChB,KAAK,QAAQ,CAAC,CAAC;oBACb,MAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,KAAK,GAAG,CAAC,CAAC,CAAA;oBACvD,MAAM,aAAK,CAAC,MAAM,CAAC,CAAA;oBACnB,OAAM;iBACP;gBACD,OAAO,CAAC,CAAC;oBACP,IAAI,KAAe,CAAA;oBAEnB,IAAI;wBACF,KAAK,GAAG,MAAM,YAAI,CAAC,MAAM,CAAC,CAAA;qBAC3B;oBAAC,OAAO,IAAI,EAAE;wBACb,MAAM,GAAG,CAAA;qBACV;oBAED,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE;wBAAE,MAAM,GAAG,CAAA;iBACpC;aACF;SACF;IACH,CAAC;CAAA;AAlCD,wBAkCC;AAED;;;;;GAKG;AACH,SAAsB,oBAAoB,CACxC,QAAgB,EAChB,UAAoB;;QAEpB,IAAI,KAAK,GAAyB,SAAS,CAAA;QAC3C,IAAI;YACF,mBAAmB;YACnB,KAAK,GAAG,MAAM,YAAI,CAAC,QAAQ,CAAC,CAAA;SAC7B;QAAC,OAAO,GAAG,EAAE;YACZ,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE;gBACzB,sCAAsC;gBACtC,OAAO,CAAC,GAAG,CACT,uEAAuE,QAAQ,MAAM,GAAG,EAAE,CAC3F,CAAA;aACF;SACF;QACD,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,EAAE,EAAE;YAC3B,IAAI,kBAAU,EAAE;gBACd,uCAAuC;gBACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAA;gBACrD,IAAI,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,WAAW,EAAE,KAAK,QAAQ,CAAC,EAAE;oBACpE,OAAO,QAAQ,CAAA;iBAChB;aACF;iBAAM;gBACL,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE;oBAC3B,OAAO,QAAQ,CAAA;iBAChB;aACF;SACF;QAED,qBAAqB;QACrB,MAAM,gBAAgB,GAAG,QAAQ,CAAA;QACjC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE;YAClC,QAAQ,GAAG,gBAAgB,GAAG,SAAS,CAAA;YAEvC,KAAK,GAAG,SAAS,CAAA;YACjB,IAAI;gBACF,KAAK,GAAG,MAAM,YAAI,CAAC,QAAQ,CAAC,CAAA;aAC7B;YAAC,OAAO,GAAG,EAAE;gBACZ,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE;oBACzB,sCAAsC;oBACtC,OAAO,CAAC,GAAG,CACT,uEAAuE,QAAQ,MAAM,GAAG,EAAE,CAC3F,CAAA;iBACF;aACF;YAED,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,EAAE,EAAE;gBAC3B,IAAI,kBAAU,EAAE;oBACd,yEAAyE;oBACzE,IAAI;wBACF,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;wBACxC,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAA;wBACvD,KAAK,MAAM,UAAU,IAAI,MAAM,eAAO,CAAC,SAAS,CAAC,EAAE;4BACjD,IAAI,SAAS,KAAK,UAAU,CAAC,WAAW,EAAE,EAAE;gCAC1C,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,CAAA;gCAC3C,MAAK;6BACN;yBACF;qBACF;oBAAC,OAAO,GAAG,EAAE;wBACZ,sCAAsC;wBACtC,OAAO,CAAC,GAAG,CACT,yEAAyE,QAAQ,MAAM,GAAG,EAAE,CAC7F,CAAA;qBACF;oBAED,OAAO,QAAQ,CAAA;iBAChB;qBAAM;oBACL,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE;wBAC3B,OAAO,QAAQ,CAAA;qBAChB;iBACF;aACF;SACF;QAED,OAAO,EAAE,CAAA;IACX,CAAC;CAAA;AA5ED,oDA4EC;AAED,SAAS,mBAAmB,CAAC,CAAS;IACpC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;IACX,IAAI,kBAAU,EAAE;QACd,6BAA6B;QAC7B,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QAE1B,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"}
|
||||||
+56
@@ -0,0 +1,56 @@
|
|||||||
|
/**
|
||||||
|
* Interface for cp/mv options
|
||||||
|
*/
|
||||||
|
export interface CopyOptions {
|
||||||
|
/** Optional. Whether to recursively copy all subdirectories. Defaults to false */
|
||||||
|
recursive?: boolean;
|
||||||
|
/** Optional. Whether to overwrite existing files in the destination. Defaults to true */
|
||||||
|
force?: boolean;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Interface for cp/mv options
|
||||||
|
*/
|
||||||
|
export interface MoveOptions {
|
||||||
|
/** Optional. Whether to overwrite existing files in the destination. Defaults to true */
|
||||||
|
force?: boolean;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Copies a file or folder.
|
||||||
|
* Based off of shelljs - https://github.com/shelljs/shelljs/blob/9237f66c52e5daa40458f94f9565e18e8132f5a6/src/cp.js
|
||||||
|
*
|
||||||
|
* @param source source path
|
||||||
|
* @param dest destination path
|
||||||
|
* @param options optional. See CopyOptions.
|
||||||
|
*/
|
||||||
|
export declare function cp(source: string, dest: string, options?: CopyOptions): Promise<void>;
|
||||||
|
/**
|
||||||
|
* Moves a path.
|
||||||
|
*
|
||||||
|
* @param source source path
|
||||||
|
* @param dest destination path
|
||||||
|
* @param options optional. See MoveOptions.
|
||||||
|
*/
|
||||||
|
export declare function mv(source: string, dest: string, options?: MoveOptions): Promise<void>;
|
||||||
|
/**
|
||||||
|
* Remove a path recursively with force
|
||||||
|
*
|
||||||
|
* @param inputPath path to remove
|
||||||
|
*/
|
||||||
|
export declare function rmRF(inputPath: string): Promise<void>;
|
||||||
|
/**
|
||||||
|
* Make a directory. Creates the full path with folders in between
|
||||||
|
* Will throw if it fails
|
||||||
|
*
|
||||||
|
* @param fsPath path to create
|
||||||
|
* @returns Promise<void>
|
||||||
|
*/
|
||||||
|
export declare function mkdirP(fsPath: string): Promise<void>;
|
||||||
|
/**
|
||||||
|
* Returns path of a tool had the tool actually been invoked. Resolves via paths.
|
||||||
|
* If you check and the tool does not exist, it will throw.
|
||||||
|
*
|
||||||
|
* @param tool name of the tool
|
||||||
|
* @param check whether to check if tool exists
|
||||||
|
* @returns Promise<string> path to tool
|
||||||
|
*/
|
||||||
|
export declare function which(tool: string, check?: boolean): Promise<string>;
|
||||||
+290
@@ -0,0 +1,290 @@
|
|||||||
|
"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 childProcess = require("child_process");
|
||||||
|
const path = require("path");
|
||||||
|
const util_1 = require("util");
|
||||||
|
const ioUtil = require("./io-util");
|
||||||
|
const exec = util_1.promisify(childProcess.exec);
|
||||||
|
/**
|
||||||
|
* Copies a file or folder.
|
||||||
|
* Based off of shelljs - https://github.com/shelljs/shelljs/blob/9237f66c52e5daa40458f94f9565e18e8132f5a6/src/cp.js
|
||||||
|
*
|
||||||
|
* @param source source path
|
||||||
|
* @param dest destination path
|
||||||
|
* @param options optional. See CopyOptions.
|
||||||
|
*/
|
||||||
|
function cp(source, dest, options = {}) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const { force, recursive } = readCopyOptions(options);
|
||||||
|
const destStat = (yield ioUtil.exists(dest)) ? yield ioUtil.stat(dest) : null;
|
||||||
|
// Dest is an existing file, but not forcing
|
||||||
|
if (destStat && destStat.isFile() && !force) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// If dest is an existing directory, should copy inside.
|
||||||
|
const newDest = destStat && destStat.isDirectory()
|
||||||
|
? path.join(dest, path.basename(source))
|
||||||
|
: dest;
|
||||||
|
if (!(yield ioUtil.exists(source))) {
|
||||||
|
throw new Error(`no such file or directory: ${source}`);
|
||||||
|
}
|
||||||
|
const sourceStat = yield ioUtil.stat(source);
|
||||||
|
if (sourceStat.isDirectory()) {
|
||||||
|
if (!recursive) {
|
||||||
|
throw new Error(`Failed to copy. ${source} is a directory, but tried to copy without recursive flag.`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
yield cpDirRecursive(source, newDest, 0, force);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (path.relative(source, newDest) === '') {
|
||||||
|
// a file cannot be copied to itself
|
||||||
|
throw new Error(`'${newDest}' and '${source}' are the same file`);
|
||||||
|
}
|
||||||
|
yield copyFile(source, newDest, force);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.cp = cp;
|
||||||
|
/**
|
||||||
|
* Moves a path.
|
||||||
|
*
|
||||||
|
* @param source source path
|
||||||
|
* @param dest destination path
|
||||||
|
* @param options optional. See MoveOptions.
|
||||||
|
*/
|
||||||
|
function mv(source, dest, options = {}) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (yield ioUtil.exists(dest)) {
|
||||||
|
let destExists = true;
|
||||||
|
if (yield ioUtil.isDirectory(dest)) {
|
||||||
|
// If dest is directory copy src into dest
|
||||||
|
dest = path.join(dest, path.basename(source));
|
||||||
|
destExists = yield ioUtil.exists(dest);
|
||||||
|
}
|
||||||
|
if (destExists) {
|
||||||
|
if (options.force == null || options.force) {
|
||||||
|
yield rmRF(dest);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new Error('Destination already exists');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
yield mkdirP(path.dirname(dest));
|
||||||
|
yield ioUtil.rename(source, dest);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.mv = mv;
|
||||||
|
/**
|
||||||
|
* Remove a path recursively with force
|
||||||
|
*
|
||||||
|
* @param inputPath path to remove
|
||||||
|
*/
|
||||||
|
function rmRF(inputPath) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (ioUtil.IS_WINDOWS) {
|
||||||
|
// Node doesn't provide a delete operation, only an unlink function. This means that if the file is being used by another
|
||||||
|
// program (e.g. antivirus), it won't be deleted. To address this, we shell out the work to rd/del.
|
||||||
|
try {
|
||||||
|
if (yield ioUtil.isDirectory(inputPath, true)) {
|
||||||
|
yield exec(`rd /s /q "${inputPath}"`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
yield exec(`del /f /a "${inputPath}"`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
// if you try to delete a file that doesn't exist, desired result is achieved
|
||||||
|
// other errors are valid
|
||||||
|
if (err.code !== 'ENOENT')
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
// Shelling out fails to remove a symlink folder with missing source, this unlink catches that
|
||||||
|
try {
|
||||||
|
yield ioUtil.unlink(inputPath);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
// if you try to delete a file that doesn't exist, desired result is achieved
|
||||||
|
// other errors are valid
|
||||||
|
if (err.code !== 'ENOENT')
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let isDir = false;
|
||||||
|
try {
|
||||||
|
isDir = yield ioUtil.isDirectory(inputPath);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
// if you try to delete a file that doesn't exist, desired result is achieved
|
||||||
|
// other errors are valid
|
||||||
|
if (err.code !== 'ENOENT')
|
||||||
|
throw err;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isDir) {
|
||||||
|
yield exec(`rm -rf "${inputPath}"`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
yield ioUtil.unlink(inputPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.rmRF = rmRF;
|
||||||
|
/**
|
||||||
|
* Make a directory. Creates the full path with folders in between
|
||||||
|
* Will throw if it fails
|
||||||
|
*
|
||||||
|
* @param fsPath path to create
|
||||||
|
* @returns Promise<void>
|
||||||
|
*/
|
||||||
|
function mkdirP(fsPath) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
yield ioUtil.mkdirP(fsPath);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.mkdirP = mkdirP;
|
||||||
|
/**
|
||||||
|
* Returns path of a tool had the tool actually been invoked. Resolves via paths.
|
||||||
|
* If you check and the tool does not exist, it will throw.
|
||||||
|
*
|
||||||
|
* @param tool name of the tool
|
||||||
|
* @param check whether to check if tool exists
|
||||||
|
* @returns Promise<string> path to tool
|
||||||
|
*/
|
||||||
|
function which(tool, check) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (!tool) {
|
||||||
|
throw new Error("parameter 'tool' is required");
|
||||||
|
}
|
||||||
|
// recursive when check=true
|
||||||
|
if (check) {
|
||||||
|
const result = yield which(tool, false);
|
||||||
|
if (!result) {
|
||||||
|
if (ioUtil.IS_WINDOWS) {
|
||||||
|
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 verify the file has a valid extension for an executable file.`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
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.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// 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('/') || (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}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.which = which;
|
||||||
|
function readCopyOptions(options) {
|
||||||
|
const force = options.force == null ? true : options.force;
|
||||||
|
const recursive = Boolean(options.recursive);
|
||||||
|
return { force, recursive };
|
||||||
|
}
|
||||||
|
function cpDirRecursive(sourceDir, destDir, currentDepth, force) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
// Ensure there is not a run away recursive copy
|
||||||
|
if (currentDepth >= 255)
|
||||||
|
return;
|
||||||
|
currentDepth++;
|
||||||
|
yield mkdirP(destDir);
|
||||||
|
const files = yield ioUtil.readdir(sourceDir);
|
||||||
|
for (const fileName of files) {
|
||||||
|
const srcFile = `${sourceDir}/${fileName}`;
|
||||||
|
const destFile = `${destDir}/${fileName}`;
|
||||||
|
const srcFileStat = yield ioUtil.lstat(srcFile);
|
||||||
|
if (srcFileStat.isDirectory()) {
|
||||||
|
// Recurse
|
||||||
|
yield cpDirRecursive(srcFile, destFile, currentDepth, force);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
yield copyFile(srcFile, destFile, force);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Change the mode for the newly created directory
|
||||||
|
yield ioUtil.chmod(destDir, (yield ioUtil.stat(sourceDir)).mode);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// Buffered file copy
|
||||||
|
function copyFile(srcFile, destFile, force) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if ((yield ioUtil.lstat(srcFile)).isSymbolicLink()) {
|
||||||
|
// unlink/re-link it
|
||||||
|
try {
|
||||||
|
yield ioUtil.lstat(destFile);
|
||||||
|
yield ioUtil.unlink(destFile);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
// Try to override file permission
|
||||||
|
if (e.code === 'EPERM') {
|
||||||
|
yield ioUtil.chmod(destFile, '0666');
|
||||||
|
yield ioUtil.unlink(destFile);
|
||||||
|
}
|
||||||
|
// other errors = it doesn't exist, no work to do
|
||||||
|
}
|
||||||
|
// Copy over symlink
|
||||||
|
const symlinkFull = yield ioUtil.readlink(srcFile);
|
||||||
|
yield ioUtil.symlink(symlinkFull, destFile, ioUtil.IS_WINDOWS ? 'junction' : null);
|
||||||
|
}
|
||||||
|
else if (!(yield ioUtil.exists(destFile)) || force) {
|
||||||
|
yield ioUtil.copyFile(srcFile, destFile);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=io.js.map
|
||||||
+1
File diff suppressed because one or more lines are too long
+62
@@ -0,0 +1,62 @@
|
|||||||
|
{
|
||||||
|
"_from": "@actions/io",
|
||||||
|
"_id": "@actions/io@1.0.1",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha512-rhq+tfZukbtaus7xyUtwKfuiCRXd1hWSfmJNEpFgBQJ4woqPEpsBw04awicjwz9tyG2/MVhAEMfVn664Cri5zA==",
|
||||||
|
"_location": "/@actions/io",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "tag",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "@actions/io",
|
||||||
|
"name": "@actions/io",
|
||||||
|
"escapedName": "@actions%2fio",
|
||||||
|
"scope": "@actions",
|
||||||
|
"rawSpec": "",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "latest"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"#USER",
|
||||||
|
"/"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/@actions/io/-/io-1.0.1.tgz",
|
||||||
|
"_shasum": "81a9418fe2bbdef2d2717a8e9f85188b9c565aca",
|
||||||
|
"_spec": "@actions/io",
|
||||||
|
"_where": "C:\\Users\\lzy\\Documents\\Source\\OpportunityLiu\\github-action-setup-xmake",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/actions/toolkit/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "Actions io lib",
|
||||||
|
"directories": {
|
||||||
|
"lib": "lib",
|
||||||
|
"test": "__tests__"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"lib"
|
||||||
|
],
|
||||||
|
"gitHead": "a2ab4bcf78e4f7080f0d45856e6eeba16f0bbc52",
|
||||||
|
"homepage": "https://github.com/actions/toolkit/tree/master/packages/io",
|
||||||
|
"keywords": [
|
||||||
|
"github",
|
||||||
|
"actions",
|
||||||
|
"io"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"main": "lib/io.js",
|
||||||
|
"name": "@actions/io",
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/actions/toolkit.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: run tests from root\" && exit 1",
|
||||||
|
"tsc": "tsc"
|
||||||
|
},
|
||||||
|
"version": "1.0.1"
|
||||||
|
}
|
||||||
+82
@@ -0,0 +1,82 @@
|
|||||||
|
# `@actions/tool-cache`
|
||||||
|
|
||||||
|
> Functions necessary for downloading and caching tools.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
#### Download
|
||||||
|
|
||||||
|
You can use this to download tools (or other files) from a download URL:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const tc = require('@actions/tool-cache');
|
||||||
|
|
||||||
|
const node12Path = await tc.downloadTool('https://nodejs.org/dist/v12.7.0/node-v12.7.0-linux-x64.tar.gz');
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Extract
|
||||||
|
|
||||||
|
These can then be extracted in platform specific ways:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const tc = require('@actions/tool-cache');
|
||||||
|
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
const node12Path = tc.downloadTool('https://nodejs.org/dist/v12.7.0/node-v12.7.0-win-x64.zip');
|
||||||
|
const node12ExtractedFolder = await tc.extractZip(node12Path, 'path/to/extract/to');
|
||||||
|
|
||||||
|
// Or alternately
|
||||||
|
const node12Path = 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');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
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');
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Cache
|
||||||
|
|
||||||
|
Finally, you can cache these directories in our tool-cache. This is useful if you want to switch back and forth between versions of a tool, or save a tool between runs for private runners (private runners are still in development but are on the roadmap).
|
||||||
|
|
||||||
|
You'll often want to add it to the path as part of this step:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const tc = require('@actions/tool-cache');
|
||||||
|
const core = require('@actions/core');
|
||||||
|
|
||||||
|
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 cachedPath = await tc.cacheDir(node12ExtractedFolder, 'node', '12.7.0');
|
||||||
|
core.addPath(cachedPath);
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also cache files for reuse.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const tc = require('@actions/tool-cache');
|
||||||
|
|
||||||
|
tc.cacheFile('path/to/exe', 'destFileName.exe', 'myExeName', '1.1.0');
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Find
|
||||||
|
|
||||||
|
Finally, you can find directories and files you've previously cached:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const tc = require('@actions/tool-cache');
|
||||||
|
const core = require('@actions/core');
|
||||||
|
|
||||||
|
const nodeDirectory = tc.find('node', '12.x', 'x64');
|
||||||
|
core.addPath(nodeDirectory);
|
||||||
|
```
|
||||||
|
|
||||||
|
You can even find all cached versions of a tool:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const tc = require('@actions/tool-cache');
|
||||||
|
|
||||||
|
const allNodeVersions = tc.findAllVersions('node');
|
||||||
|
console.log(`Versions of node available: ${allNodeVersions}`);
|
||||||
|
```
|
||||||
+79
@@ -0,0 +1,79 @@
|
|||||||
|
export declare class HTTPError extends Error {
|
||||||
|
readonly httpStatusCode: number | undefined;
|
||||||
|
constructor(httpStatusCode: number | undefined);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Download a tool from an url and stream it into a file
|
||||||
|
*
|
||||||
|
* @param url url of tool to download
|
||||||
|
* @returns path to downloaded tool
|
||||||
|
*/
|
||||||
|
export declare function downloadTool(url: string): Promise<string>;
|
||||||
|
/**
|
||||||
|
* Extract a .7z file
|
||||||
|
*
|
||||||
|
* @param file path to the .7z file
|
||||||
|
* @param dest destination directory. Optional.
|
||||||
|
* @param _7zPath path to 7zr.exe. Optional, for long path support. Most .7z archives do not have this
|
||||||
|
* problem. If your .7z archive contains very long paths, you can pass the path to 7zr.exe which will
|
||||||
|
* gracefully handle long paths. By default 7zdec.exe is used because it is a very small program and is
|
||||||
|
* bundled with the tool lib. However it does not support long paths. 7zr.exe is the reduced command line
|
||||||
|
* interface, it is smaller than the full command line interface, and it does support long paths. At the
|
||||||
|
* time of this writing, it is freely available from the LZMA SDK that is available on the 7zip website.
|
||||||
|
* Be sure to check the current license agreement. If 7zr.exe is bundled with your action, then the path
|
||||||
|
* to 7zr.exe can be pass to this function.
|
||||||
|
* @returns path to the destination directory
|
||||||
|
*/
|
||||||
|
export declare function extract7z(file: string, dest?: string, _7zPath?: string): Promise<string>;
|
||||||
|
/**
|
||||||
|
* Extract a tar
|
||||||
|
*
|
||||||
|
* @param file path to the tar
|
||||||
|
* @param dest destination directory. Optional.
|
||||||
|
* @param flags flags for the tar. Optional.
|
||||||
|
* @returns path to the destination directory
|
||||||
|
*/
|
||||||
|
export declare function extractTar(file: string, dest?: string, flags?: string): Promise<string>;
|
||||||
|
/**
|
||||||
|
* Extract a zip
|
||||||
|
*
|
||||||
|
* @param file path to the zip
|
||||||
|
* @param dest destination directory. Optional.
|
||||||
|
* @returns path to the destination directory
|
||||||
|
*/
|
||||||
|
export declare function extractZip(file: string, dest?: string): Promise<string>;
|
||||||
|
/**
|
||||||
|
* Caches a directory and installs it into the tool cacheDir
|
||||||
|
*
|
||||||
|
* @param sourceDir the directory to cache into tools
|
||||||
|
* @param tool tool name
|
||||||
|
* @param version version of the tool. semver format
|
||||||
|
* @param arch architecture of the tool. Optional. Defaults to machine architecture
|
||||||
|
*/
|
||||||
|
export declare function cacheDir(sourceDir: string, tool: string, version: string, arch?: string): Promise<string>;
|
||||||
|
/**
|
||||||
|
* Caches a downloaded file (GUID) and installs it
|
||||||
|
* into the tool cache with a given targetName
|
||||||
|
*
|
||||||
|
* @param sourceFile the file to cache into tools. Typically a result of downloadTool which is a guid.
|
||||||
|
* @param targetFile the name of the file name in the tools directory
|
||||||
|
* @param tool tool name
|
||||||
|
* @param version version of the tool. semver format
|
||||||
|
* @param arch architecture of the tool. Optional. Defaults to machine architecture
|
||||||
|
*/
|
||||||
|
export declare function cacheFile(sourceFile: string, targetFile: string, tool: string, version: string, arch?: string): Promise<string>;
|
||||||
|
/**
|
||||||
|
* Finds the path to a tool version in the local installed tool cache
|
||||||
|
*
|
||||||
|
* @param toolName name of the tool
|
||||||
|
* @param versionSpec version of the tool
|
||||||
|
* @param arch optional arch. defaults to arch of computer
|
||||||
|
*/
|
||||||
|
export declare function find(toolName: string, versionSpec: string, arch?: string): string;
|
||||||
|
/**
|
||||||
|
* Finds the paths to all versions of a tool that are installed in the local tool cache
|
||||||
|
*
|
||||||
|
* @param toolName name of the tool
|
||||||
|
* @param arch optional arch. defaults to arch of computer
|
||||||
|
*/
|
||||||
|
export declare function findAllVersions(toolName: string, arch?: string): string[];
|
||||||
+438
@@ -0,0 +1,438 @@
|
|||||||
|
"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 core = require("@actions/core");
|
||||||
|
const io = require("@actions/io");
|
||||||
|
const fs = require("fs");
|
||||||
|
const os = require("os");
|
||||||
|
const path = require("path");
|
||||||
|
const httpm = require("typed-rest-client/HttpClient");
|
||||||
|
const semver = require("semver");
|
||||||
|
const uuidV4 = require("uuid/v4");
|
||||||
|
const exec_1 = require("@actions/exec/lib/exec");
|
||||||
|
const assert_1 = require("assert");
|
||||||
|
class HTTPError extends Error {
|
||||||
|
constructor(httpStatusCode) {
|
||||||
|
super(`Unexpected HTTP response: ${httpStatusCode}`);
|
||||||
|
this.httpStatusCode = httpStatusCode;
|
||||||
|
Object.setPrototypeOf(this, new.target.prototype);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.HTTPError = HTTPError;
|
||||||
|
const IS_WINDOWS = process.platform === 'win32';
|
||||||
|
const userAgent = 'actions/tool-cache';
|
||||||
|
// On load grab temp directory and cache directory and remove them from env (currently don't want to expose this)
|
||||||
|
let tempDirectory = process.env['RUNNER_TEMP'] || '';
|
||||||
|
let cacheRoot = process.env['RUNNER_TOOL_CACHE'] || '';
|
||||||
|
// If directories not found, place them in common temp locations
|
||||||
|
if (!tempDirectory || !cacheRoot) {
|
||||||
|
let baseLocation;
|
||||||
|
if (IS_WINDOWS) {
|
||||||
|
// On windows use the USERPROFILE env variable
|
||||||
|
baseLocation = process.env['USERPROFILE'] || 'C:\\';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (process.platform === 'darwin') {
|
||||||
|
baseLocation = '/Users';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
baseLocation = '/home';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!tempDirectory) {
|
||||||
|
tempDirectory = path.join(baseLocation, 'actions', 'temp');
|
||||||
|
}
|
||||||
|
if (!cacheRoot) {
|
||||||
|
cacheRoot = path.join(baseLocation, 'actions', 'cache');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Download a tool from an url and stream it into a file
|
||||||
|
*
|
||||||
|
* @param url url of tool to download
|
||||||
|
* @returns path to downloaded tool
|
||||||
|
*/
|
||||||
|
function downloadTool(url) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
// Wrap in a promise so that we can resolve from within stream callbacks
|
||||||
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
||||||
|
try {
|
||||||
|
const http = new httpm.HttpClient(userAgent, [], {
|
||||||
|
allowRetries: true,
|
||||||
|
maxRetries: 3
|
||||||
|
});
|
||||||
|
const destPath = path.join(tempDirectory, uuidV4());
|
||||||
|
yield io.mkdirP(tempDirectory);
|
||||||
|
core.debug(`Downloading ${url}`);
|
||||||
|
core.debug(`Downloading ${destPath}`);
|
||||||
|
if (fs.existsSync(destPath)) {
|
||||||
|
throw new Error(`Destination file path ${destPath} already exists`);
|
||||||
|
}
|
||||||
|
const response = yield http.get(url);
|
||||||
|
if (response.message.statusCode !== 200) {
|
||||||
|
const err = new HTTPError(response.message.statusCode);
|
||||||
|
core.debug(`Failed to download from "${url}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
const file = fs.createWriteStream(destPath);
|
||||||
|
file.on('open', () => __awaiter(this, void 0, void 0, function* () {
|
||||||
|
try {
|
||||||
|
const stream = response.message.pipe(file);
|
||||||
|
stream.on('close', () => {
|
||||||
|
core.debug('download complete');
|
||||||
|
resolve(destPath);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
core.debug(`Failed to download from "${url}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`);
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
file.on('error', err => {
|
||||||
|
file.end();
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.downloadTool = downloadTool;
|
||||||
|
/**
|
||||||
|
* Extract a .7z file
|
||||||
|
*
|
||||||
|
* @param file path to the .7z file
|
||||||
|
* @param dest destination directory. Optional.
|
||||||
|
* @param _7zPath path to 7zr.exe. Optional, for long path support. Most .7z archives do not have this
|
||||||
|
* problem. If your .7z archive contains very long paths, you can pass the path to 7zr.exe which will
|
||||||
|
* gracefully handle long paths. By default 7zdec.exe is used because it is a very small program and is
|
||||||
|
* bundled with the tool lib. However it does not support long paths. 7zr.exe is the reduced command line
|
||||||
|
* interface, it is smaller than the full command line interface, and it does support long paths. At the
|
||||||
|
* time of this writing, it is freely available from the LZMA SDK that is available on the 7zip website.
|
||||||
|
* Be sure to check the current license agreement. If 7zr.exe is bundled with your action, then the path
|
||||||
|
* to 7zr.exe can be pass to this function.
|
||||||
|
* @returns path to the destination directory
|
||||||
|
*/
|
||||||
|
function extract7z(file, dest, _7zPath) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
assert_1.ok(IS_WINDOWS, 'extract7z() not supported on current OS');
|
||||||
|
assert_1.ok(file, 'parameter "file" is required');
|
||||||
|
dest = dest || (yield _createExtractFolder(dest));
|
||||||
|
const originalCwd = process.cwd();
|
||||||
|
process.chdir(dest);
|
||||||
|
if (_7zPath) {
|
||||||
|
try {
|
||||||
|
const args = [
|
||||||
|
'x',
|
||||||
|
'-bb1',
|
||||||
|
'-bd',
|
||||||
|
'-sccUTF-8',
|
||||||
|
file
|
||||||
|
];
|
||||||
|
const options = {
|
||||||
|
silent: true
|
||||||
|
};
|
||||||
|
yield exec_1.exec(`"${_7zPath}"`, args, options);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
process.chdir(originalCwd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const escapedScript = path
|
||||||
|
.join(__dirname, '..', 'scripts', 'Invoke-7zdec.ps1')
|
||||||
|
.replace(/'/g, "''")
|
||||||
|
.replace(/"|\n|\r/g, ''); // double-up single quotes, remove double quotes and newlines
|
||||||
|
const escapedFile = file.replace(/'/g, "''").replace(/"|\n|\r/g, '');
|
||||||
|
const escapedTarget = dest.replace(/'/g, "''").replace(/"|\n|\r/g, '');
|
||||||
|
const command = `& '${escapedScript}' -Source '${escapedFile}' -Target '${escapedTarget}'`;
|
||||||
|
const args = [
|
||||||
|
'-NoLogo',
|
||||||
|
'-Sta',
|
||||||
|
'-NoProfile',
|
||||||
|
'-NonInteractive',
|
||||||
|
'-ExecutionPolicy',
|
||||||
|
'Unrestricted',
|
||||||
|
'-Command',
|
||||||
|
command
|
||||||
|
];
|
||||||
|
const options = {
|
||||||
|
silent: true
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
const powershellPath = yield io.which('powershell', true);
|
||||||
|
yield exec_1.exec(`"${powershellPath}"`, args, options);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
process.chdir(originalCwd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dest;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.extract7z = extract7z;
|
||||||
|
/**
|
||||||
|
* Extract a tar
|
||||||
|
*
|
||||||
|
* @param file path to the tar
|
||||||
|
* @param dest destination directory. Optional.
|
||||||
|
* @param flags flags for the tar. Optional.
|
||||||
|
* @returns path to the destination directory
|
||||||
|
*/
|
||||||
|
function extractTar(file, dest, flags = 'xz') {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (!file) {
|
||||||
|
throw new Error("parameter 'file' is required");
|
||||||
|
}
|
||||||
|
dest = dest || (yield _createExtractFolder(dest));
|
||||||
|
const tarPath = yield io.which('tar', true);
|
||||||
|
yield exec_1.exec(`"${tarPath}"`, [flags, '-C', dest, '-f', file]);
|
||||||
|
return dest;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.extractTar = extractTar;
|
||||||
|
/**
|
||||||
|
* Extract a zip
|
||||||
|
*
|
||||||
|
* @param file path to the zip
|
||||||
|
* @param dest destination directory. Optional.
|
||||||
|
* @returns path to the destination directory
|
||||||
|
*/
|
||||||
|
function extractZip(file, dest) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (!file) {
|
||||||
|
throw new Error("parameter 'file' is required");
|
||||||
|
}
|
||||||
|
dest = dest || (yield _createExtractFolder(dest));
|
||||||
|
if (IS_WINDOWS) {
|
||||||
|
yield extractZipWin(file, dest);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
yield extractZipNix(file, dest);
|
||||||
|
}
|
||||||
|
return dest;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.extractZip = extractZip;
|
||||||
|
function extractZipWin(file, dest) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
// build the powershell command
|
||||||
|
const escapedFile = file.replace(/'/g, "''").replace(/"|\n|\r/g, ''); // double-up single quotes, remove double quotes and newlines
|
||||||
|
const escapedDest = dest.replace(/'/g, "''").replace(/"|\n|\r/g, '');
|
||||||
|
const command = `$ErrorActionPreference = 'Stop' ; try { Add-Type -AssemblyName System.IO.Compression.FileSystem } catch { } ; [System.IO.Compression.ZipFile]::ExtractToDirectory('${escapedFile}', '${escapedDest}')`;
|
||||||
|
// run powershell
|
||||||
|
const powershellPath = yield io.which('powershell');
|
||||||
|
const args = [
|
||||||
|
'-NoLogo',
|
||||||
|
'-Sta',
|
||||||
|
'-NoProfile',
|
||||||
|
'-NonInteractive',
|
||||||
|
'-ExecutionPolicy',
|
||||||
|
'Unrestricted',
|
||||||
|
'-Command',
|
||||||
|
command
|
||||||
|
];
|
||||||
|
yield exec_1.exec(`"${powershellPath}"`, args);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function extractZipNix(file, dest) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const unzipPath = yield io.which('unzip');
|
||||||
|
yield exec_1.exec(`"${unzipPath}"`, [file], { cwd: dest });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Caches a directory and installs it into the tool cacheDir
|
||||||
|
*
|
||||||
|
* @param sourceDir the directory to cache into tools
|
||||||
|
* @param tool tool name
|
||||||
|
* @param version version of the tool. semver format
|
||||||
|
* @param arch architecture of the tool. Optional. Defaults to machine architecture
|
||||||
|
*/
|
||||||
|
function cacheDir(sourceDir, tool, version, arch) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
version = semver.clean(version) || version;
|
||||||
|
arch = arch || os.arch();
|
||||||
|
core.debug(`Caching tool ${tool} ${version} ${arch}`);
|
||||||
|
core.debug(`source dir: ${sourceDir}`);
|
||||||
|
if (!fs.statSync(sourceDir).isDirectory()) {
|
||||||
|
throw new Error('sourceDir is not a directory');
|
||||||
|
}
|
||||||
|
// Create the tool dir
|
||||||
|
const destPath = yield _createToolPath(tool, version, arch);
|
||||||
|
// copy each child item. do not move. move can fail on Windows
|
||||||
|
// due to anti-virus software having an open handle on a file.
|
||||||
|
for (const itemName of fs.readdirSync(sourceDir)) {
|
||||||
|
const s = path.join(sourceDir, itemName);
|
||||||
|
yield io.cp(s, destPath, { recursive: true });
|
||||||
|
}
|
||||||
|
// write .complete
|
||||||
|
_completeToolPath(tool, version, arch);
|
||||||
|
return destPath;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.cacheDir = cacheDir;
|
||||||
|
/**
|
||||||
|
* Caches a downloaded file (GUID) and installs it
|
||||||
|
* into the tool cache with a given targetName
|
||||||
|
*
|
||||||
|
* @param sourceFile the file to cache into tools. Typically a result of downloadTool which is a guid.
|
||||||
|
* @param targetFile the name of the file name in the tools directory
|
||||||
|
* @param tool tool name
|
||||||
|
* @param version version of the tool. semver format
|
||||||
|
* @param arch architecture of the tool. Optional. Defaults to machine architecture
|
||||||
|
*/
|
||||||
|
function cacheFile(sourceFile, targetFile, tool, version, arch) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
version = semver.clean(version) || version;
|
||||||
|
arch = arch || os.arch();
|
||||||
|
core.debug(`Caching tool ${tool} ${version} ${arch}`);
|
||||||
|
core.debug(`source file: ${sourceFile}`);
|
||||||
|
if (!fs.statSync(sourceFile).isFile()) {
|
||||||
|
throw new Error('sourceFile is not a file');
|
||||||
|
}
|
||||||
|
// create the tool dir
|
||||||
|
const destFolder = yield _createToolPath(tool, version, arch);
|
||||||
|
// copy instead of move. move can fail on Windows due to
|
||||||
|
// anti-virus software having an open handle on a file.
|
||||||
|
const destPath = path.join(destFolder, targetFile);
|
||||||
|
core.debug(`destination file ${destPath}`);
|
||||||
|
yield io.cp(sourceFile, destPath);
|
||||||
|
// write .complete
|
||||||
|
_completeToolPath(tool, version, arch);
|
||||||
|
return destFolder;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.cacheFile = cacheFile;
|
||||||
|
/**
|
||||||
|
* Finds the path to a tool version in the local installed tool cache
|
||||||
|
*
|
||||||
|
* @param toolName name of the tool
|
||||||
|
* @param versionSpec version of the tool
|
||||||
|
* @param arch optional arch. defaults to arch of computer
|
||||||
|
*/
|
||||||
|
function find(toolName, versionSpec, arch) {
|
||||||
|
if (!toolName) {
|
||||||
|
throw new Error('toolName parameter is required');
|
||||||
|
}
|
||||||
|
if (!versionSpec) {
|
||||||
|
throw new Error('versionSpec parameter is required');
|
||||||
|
}
|
||||||
|
arch = arch || os.arch();
|
||||||
|
// attempt to resolve an explicit version
|
||||||
|
if (!_isExplicitVersion(versionSpec)) {
|
||||||
|
const localVersions = findAllVersions(toolName, arch);
|
||||||
|
const match = _evaluateVersions(localVersions, versionSpec);
|
||||||
|
versionSpec = match;
|
||||||
|
}
|
||||||
|
// check for the explicit version in the cache
|
||||||
|
let toolPath = '';
|
||||||
|
if (versionSpec) {
|
||||||
|
versionSpec = semver.clean(versionSpec) || '';
|
||||||
|
const cachePath = path.join(cacheRoot, toolName, versionSpec, arch);
|
||||||
|
core.debug(`checking cache: ${cachePath}`);
|
||||||
|
if (fs.existsSync(cachePath) && fs.existsSync(`${cachePath}.complete`)) {
|
||||||
|
core.debug(`Found tool in cache ${toolName} ${versionSpec} ${arch}`);
|
||||||
|
toolPath = cachePath;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.debug('not found');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return toolPath;
|
||||||
|
}
|
||||||
|
exports.find = find;
|
||||||
|
/**
|
||||||
|
* Finds the paths to all versions of a tool that are installed in the local tool cache
|
||||||
|
*
|
||||||
|
* @param toolName name of the tool
|
||||||
|
* @param arch optional arch. defaults to arch of computer
|
||||||
|
*/
|
||||||
|
function findAllVersions(toolName, arch) {
|
||||||
|
const versions = [];
|
||||||
|
arch = arch || os.arch();
|
||||||
|
const toolPath = path.join(cacheRoot, toolName);
|
||||||
|
if (fs.existsSync(toolPath)) {
|
||||||
|
const children = fs.readdirSync(toolPath);
|
||||||
|
for (const child of children) {
|
||||||
|
if (_isExplicitVersion(child)) {
|
||||||
|
const fullPath = path.join(toolPath, child, arch || '');
|
||||||
|
if (fs.existsSync(fullPath) && fs.existsSync(`${fullPath}.complete`)) {
|
||||||
|
versions.push(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return versions;
|
||||||
|
}
|
||||||
|
exports.findAllVersions = findAllVersions;
|
||||||
|
function _createExtractFolder(dest) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (!dest) {
|
||||||
|
// create a temp dir
|
||||||
|
dest = path.join(tempDirectory, uuidV4());
|
||||||
|
}
|
||||||
|
yield io.mkdirP(dest);
|
||||||
|
return dest;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function _createToolPath(tool, version, arch) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const folderPath = path.join(cacheRoot, tool, semver.clean(version) || version, arch || '');
|
||||||
|
core.debug(`destination ${folderPath}`);
|
||||||
|
const markerPath = `${folderPath}.complete`;
|
||||||
|
yield io.rmRF(folderPath);
|
||||||
|
yield io.rmRF(markerPath);
|
||||||
|
yield io.mkdirP(folderPath);
|
||||||
|
return folderPath;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function _completeToolPath(tool, version, arch) {
|
||||||
|
const folderPath = path.join(cacheRoot, tool, semver.clean(version) || version, arch || '');
|
||||||
|
const markerPath = `${folderPath}.complete`;
|
||||||
|
fs.writeFileSync(markerPath, '');
|
||||||
|
core.debug('finished caching tool');
|
||||||
|
}
|
||||||
|
function _isExplicitVersion(versionSpec) {
|
||||||
|
const c = semver.clean(versionSpec) || '';
|
||||||
|
core.debug(`isExplicit: ${c}`);
|
||||||
|
const valid = semver.valid(c) != null;
|
||||||
|
core.debug(`explicit? ${valid}`);
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
function _evaluateVersions(versions, versionSpec) {
|
||||||
|
let version = '';
|
||||||
|
core.debug(`evaluating ${versions.length} versions`);
|
||||||
|
versions = versions.sort((a, b) => {
|
||||||
|
if (semver.gt(a, b)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
});
|
||||||
|
for (let i = versions.length - 1; i >= 0; i--) {
|
||||||
|
const potential = versions[i];
|
||||||
|
const satisfied = semver.satisfies(potential, versionSpec);
|
||||||
|
if (satisfied) {
|
||||||
|
version = potential;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (version) {
|
||||||
|
core.debug(`matched: ${version}`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.debug('match not found');
|
||||||
|
}
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=tool-cache.js.map
|
||||||
+1
File diff suppressed because one or more lines are too long
+76
@@ -0,0 +1,76 @@
|
|||||||
|
{
|
||||||
|
"_from": "@actions/tool-cache",
|
||||||
|
"_id": "@actions/tool-cache@1.1.2",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha512-IJczPaZr02ECa3Lgws/TJEVco9tjOujiQSZbO3dHuXXjhd5vrUtfOgGwhmz3/f97L910OraPZ8SknofUk6RvOQ==",
|
||||||
|
"_location": "/@actions/tool-cache",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "tag",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "@actions/tool-cache",
|
||||||
|
"name": "@actions/tool-cache",
|
||||||
|
"escapedName": "@actions%2ftool-cache",
|
||||||
|
"scope": "@actions",
|
||||||
|
"rawSpec": "",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "latest"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"#USER",
|
||||||
|
"/"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/@actions/tool-cache/-/tool-cache-1.1.2.tgz",
|
||||||
|
"_shasum": "304d44cecb9547324731e03ca004a3905e6530d2",
|
||||||
|
"_spec": "@actions/tool-cache",
|
||||||
|
"_where": "C:\\Users\\lzy\\Documents\\Source\\OpportunityLiu\\github-action-setup-xmake",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/actions/toolkit/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"dependencies": {
|
||||||
|
"@actions/core": "^1.1.0",
|
||||||
|
"@actions/exec": "^1.0.1",
|
||||||
|
"@actions/io": "^1.0.1",
|
||||||
|
"semver": "^6.1.0",
|
||||||
|
"typed-rest-client": "^1.4.0",
|
||||||
|
"uuid": "^3.3.2"
|
||||||
|
},
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "Actions tool-cache lib",
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/nock": "^10.0.3",
|
||||||
|
"@types/semver": "^6.0.0",
|
||||||
|
"@types/uuid": "^3.4.4",
|
||||||
|
"nock": "^10.0.6"
|
||||||
|
},
|
||||||
|
"directories": {
|
||||||
|
"lib": "lib",
|
||||||
|
"test": "__tests__"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"lib",
|
||||||
|
"scripts"
|
||||||
|
],
|
||||||
|
"homepage": "https://github.com/actions/toolkit/tree/master/packages/exec",
|
||||||
|
"keywords": [
|
||||||
|
"github",
|
||||||
|
"actions",
|
||||||
|
"exec"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"main": "lib/tool-cache.js",
|
||||||
|
"name": "@actions/tool-cache",
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/actions/toolkit.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: run tests from root\" && exit 1",
|
||||||
|
"tsc": "tsc"
|
||||||
|
},
|
||||||
|
"version": "1.1.2"
|
||||||
|
}
|
||||||
+60
@@ -0,0 +1,60 @@
|
|||||||
|
[CmdletBinding()]
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory = $true)]
|
||||||
|
[string]$Source,
|
||||||
|
|
||||||
|
[Parameter(Mandatory = $true)]
|
||||||
|
[string]$Target)
|
||||||
|
|
||||||
|
# This script translates the output from 7zdec into UTF8. Node has limited
|
||||||
|
# built-in support for encodings.
|
||||||
|
#
|
||||||
|
# 7zdec uses the system default code page. The system default code page varies
|
||||||
|
# depending on the locale configuration. On an en-US box, the system default code
|
||||||
|
# page is Windows-1252.
|
||||||
|
#
|
||||||
|
# Note, on a typical en-US box, testing with the 'ç' character is a good way to
|
||||||
|
# determine whether data is passed correctly between processes. This is because
|
||||||
|
# the 'ç' character has a different code point across each of the common encodings
|
||||||
|
# on a typical en-US box, i.e.
|
||||||
|
# 1) the default console-output code page (IBM437)
|
||||||
|
# 2) the system default code page (i.e. CP_ACP) (Windows-1252)
|
||||||
|
# 3) UTF8
|
||||||
|
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
|
||||||
|
# Redefine the wrapper over STDOUT to use UTF8. Node expects UTF8 by default.
|
||||||
|
$stdout = [System.Console]::OpenStandardOutput()
|
||||||
|
$utf8 = New-Object System.Text.UTF8Encoding($false) # do not emit BOM
|
||||||
|
$writer = New-Object System.IO.StreamWriter($stdout, $utf8)
|
||||||
|
[System.Console]::SetOut($writer)
|
||||||
|
|
||||||
|
# All subsequent output must be written using [System.Console]::WriteLine(). In
|
||||||
|
# PowerShell 4, Write-Host and Out-Default do not consider the updated stream writer.
|
||||||
|
|
||||||
|
Set-Location -LiteralPath $Target
|
||||||
|
|
||||||
|
# Print the ##command.
|
||||||
|
$_7zdec = Join-Path -Path "$PSScriptRoot" -ChildPath "externals/7zdec.exe"
|
||||||
|
[System.Console]::WriteLine("##[command]$_7zdec x `"$Source`"")
|
||||||
|
|
||||||
|
# The $OutputEncoding variable instructs PowerShell how to interpret the output
|
||||||
|
# from the external command.
|
||||||
|
$OutputEncoding = [System.Text.Encoding]::Default
|
||||||
|
|
||||||
|
# Note, the output from 7zdec.exe needs to be iterated over. Otherwise PowerShell.exe
|
||||||
|
# will launch the external command in such a way that it inherits the streams.
|
||||||
|
& $_7zdec x $Source 2>&1 |
|
||||||
|
ForEach-Object {
|
||||||
|
if ($_ -is [System.Management.Automation.ErrorRecord]) {
|
||||||
|
[System.Console]::WriteLine($_.Exception.Message)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[System.Console]::WriteLine($_)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[System.Console]::WriteLine("##[debug]7zdec.exe exit code '$LASTEXITCODE'")
|
||||||
|
[System.Console]::Out.Flush()
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
exit $LASTEXITCODE
|
||||||
|
}
|
||||||
BIN
Binary file not shown.
-292
@@ -1,292 +0,0 @@
|
|||||||
# graphql.js
|
|
||||||
|
|
||||||
> GitHub GraphQL API client for browsers and Node
|
|
||||||
|
|
||||||
[](https://www.npmjs.com/package/@octokit/graphql)
|
|
||||||
[](https://travis-ci.com/octokit/graphql.js)
|
|
||||||
[](https://coveralls.io/github/octokit/graphql.js)
|
|
||||||
[](https://greenkeeper.io/)
|
|
||||||
|
|
||||||
<!-- toc -->
|
|
||||||
|
|
||||||
- [Usage](#usage)
|
|
||||||
- [Errors](#errors)
|
|
||||||
- [Writing tests](#writing-tests)
|
|
||||||
- [License](#license)
|
|
||||||
|
|
||||||
<!-- tocstop -->
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
Send a simple query
|
|
||||||
|
|
||||||
```js
|
|
||||||
const graphql = require('@octokit/graphql')
|
|
||||||
const { repository } = await graphql(`{
|
|
||||||
repository(owner:"octokit", name:"graphql.js") {
|
|
||||||
issues(last:3) {
|
|
||||||
edges {
|
|
||||||
node {
|
|
||||||
title
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}`, {
|
|
||||||
headers: {
|
|
||||||
authorization: `token secret123`
|
|
||||||
}
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
⚠️ Do not use [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) in the query strings as they make your code vulnerable to query injection attacks (see [#2](https://github.com/octokit/graphql.js/issues/2)). Use variables instead:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const graphql = require('@octokit/graphql')
|
|
||||||
const { lastIssues } = await graphql(`query lastIssues($owner: String!, $repo: String!, $num: Int = 3) {
|
|
||||||
repository(owner:$owner, name:$repo) {
|
|
||||||
issues(last:$num) {
|
|
||||||
edges {
|
|
||||||
node {
|
|
||||||
title
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}`, {
|
|
||||||
owner: 'octokit',
|
|
||||||
repo: 'graphql.js'
|
|
||||||
headers: {
|
|
||||||
authorization: `token secret123`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
Create two new clients and set separate default configs for them.
|
|
||||||
|
|
||||||
```js
|
|
||||||
const graphql1 = require('@octokit/graphql').defaults({
|
|
||||||
headers: {
|
|
||||||
authorization: `token secret123`
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const graphql2 = require('@octokit/graphql').defaults({
|
|
||||||
headers: {
|
|
||||||
authorization: `token foobar`
|
|
||||||
}
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
Create two clients, the second inherits config from the first.
|
|
||||||
|
|
||||||
```js
|
|
||||||
const graphql1 = require('@octokit/graphql').defaults({
|
|
||||||
headers: {
|
|
||||||
authorization: `token secret123`
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const graphql2 = graphql1.defaults({
|
|
||||||
headers: {
|
|
||||||
'user-agent': 'my-user-agent/v1.2.3'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
Create a new client with default options and run query
|
|
||||||
|
|
||||||
```js
|
|
||||||
const graphql = require('@octokit/graphql').defaults({
|
|
||||||
headers: {
|
|
||||||
authorization: `token secret123`
|
|
||||||
}
|
|
||||||
})
|
|
||||||
const { repository } = await graphql(`{
|
|
||||||
repository(owner:"octokit", name:"graphql.js") {
|
|
||||||
issues(last:3) {
|
|
||||||
edges {
|
|
||||||
node {
|
|
||||||
title
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}`)
|
|
||||||
```
|
|
||||||
|
|
||||||
Pass query together with headers and variables
|
|
||||||
|
|
||||||
```js
|
|
||||||
const graphql = require('@octokit/graphql')
|
|
||||||
const { lastIssues } = await graphql({
|
|
||||||
query: `query lastIssues($owner: String!, $repo: String!, $num: Int = 3) {
|
|
||||||
repository(owner:$owner, name:$repo) {
|
|
||||||
issues(last:$num) {
|
|
||||||
edges {
|
|
||||||
node {
|
|
||||||
title
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}`,
|
|
||||||
owner: 'octokit',
|
|
||||||
repo: 'graphql.js'
|
|
||||||
headers: {
|
|
||||||
authorization: `token secret123`
|
|
||||||
}
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
Use with GitHub Enterprise
|
|
||||||
|
|
||||||
```js
|
|
||||||
const graphql = require('@octokit/graphql').defaults({
|
|
||||||
baseUrl: 'https://github-enterprise.acme-inc.com/api',
|
|
||||||
headers: {
|
|
||||||
authorization: `token secret123`
|
|
||||||
}
|
|
||||||
})
|
|
||||||
const { repository } = await graphql(`{
|
|
||||||
repository(owner:"acme-project", name:"acme-repo") {
|
|
||||||
issues(last:3) {
|
|
||||||
edges {
|
|
||||||
node {
|
|
||||||
title
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}`)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Errors
|
|
||||||
|
|
||||||
In case of a GraphQL error, `error.message` is set to the first error from the response’s `errors` array. All errors can be accessed at `error.errors`. `error.request` has the request options such as query, variables and headers set for easier debugging.
|
|
||||||
|
|
||||||
```js
|
|
||||||
const graphql = require('@octokit/graphql').defaults({
|
|
||||||
headers: {
|
|
||||||
authorization: `token secret123`
|
|
||||||
}
|
|
||||||
})
|
|
||||||
const query = `{
|
|
||||||
viewer {
|
|
||||||
bioHtml
|
|
||||||
}
|
|
||||||
}`
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result = await graphql(query)
|
|
||||||
} catch (error) {
|
|
||||||
// server responds with
|
|
||||||
// {
|
|
||||||
// "data": null,
|
|
||||||
// "errors": [{
|
|
||||||
// "message": "Field 'bioHtml' doesn't exist on type 'User'",
|
|
||||||
// "locations": [{
|
|
||||||
// "line": 3,
|
|
||||||
// "column": 5
|
|
||||||
// }]
|
|
||||||
// }]
|
|
||||||
// }
|
|
||||||
|
|
||||||
console.log('Request failed:', error.request) // { query, variables: {}, headers: { authorization: 'token secret123' } }
|
|
||||||
console.log(error.message) // Field 'bioHtml' doesn't exist on type 'User'
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Partial responses
|
|
||||||
|
|
||||||
A GraphQL query may respond with partial data accompanied by errors. In this case we will throw an error but the partial data will still be accessible through `error.data`
|
|
||||||
|
|
||||||
```js
|
|
||||||
const graphql = require('@octokit/graphql').defaults({
|
|
||||||
headers: {
|
|
||||||
authorization: `token secret123`
|
|
||||||
}
|
|
||||||
})
|
|
||||||
const query = `{
|
|
||||||
repository(name: "probot", owner: "probot") {
|
|
||||||
name
|
|
||||||
ref(qualifiedName: "master") {
|
|
||||||
target {
|
|
||||||
... on Commit {
|
|
||||||
history(first: 25, after: "invalid cursor") {
|
|
||||||
nodes {
|
|
||||||
message
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}`
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result = await graphql(query)
|
|
||||||
} catch (error) {
|
|
||||||
// server responds with
|
|
||||||
// {
|
|
||||||
// "data": {
|
|
||||||
// "repository": {
|
|
||||||
// "name": "probot",
|
|
||||||
// "ref": null
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// "errors": [
|
|
||||||
// {
|
|
||||||
// "type": "INVALID_CURSOR_ARGUMENTS",
|
|
||||||
// "path": [
|
|
||||||
// "repository",
|
|
||||||
// "ref",
|
|
||||||
// "target",
|
|
||||||
// "history"
|
|
||||||
// ],
|
|
||||||
// "locations": [
|
|
||||||
// {
|
|
||||||
// "line": 7,
|
|
||||||
// "column": 11
|
|
||||||
// }
|
|
||||||
// ],
|
|
||||||
// "message": "`invalid cursor` does not appear to be a valid cursor."
|
|
||||||
// }
|
|
||||||
// ]
|
|
||||||
// }
|
|
||||||
|
|
||||||
console.log('Request failed:', error.request) // { query, variables: {}, headers: { authorization: 'token secret123' } }
|
|
||||||
console.log(error.message) // `invalid cursor` does not appear to be a valid cursor.
|
|
||||||
console.log(error.data) // { repository: { name: 'probot', ref: null } }
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Writing tests
|
|
||||||
|
|
||||||
You can pass a replacement for [the built-in fetch implementation](https://github.com/bitinn/node-fetch) as `request.fetch` option. For example, using [fetch-mock](http://www.wheresrhys.co.uk/fetch-mock/) works great to write tests
|
|
||||||
|
|
||||||
```js
|
|
||||||
const assert = require('assert')
|
|
||||||
const fetchMock = require('fetch-mock/es5/server')
|
|
||||||
|
|
||||||
const graphql = require('@octokit/graphql')
|
|
||||||
|
|
||||||
graphql('{ viewer { login } }', {
|
|
||||||
headers: {
|
|
||||||
authorization: 'token secret123'
|
|
||||||
},
|
|
||||||
request: {
|
|
||||||
fetch: fetchMock.sandbox()
|
|
||||||
.post('https://api.github.com/graphql', (url, options) => {
|
|
||||||
assert.strictEqual(options.headers.authorization, 'token secret123')
|
|
||||||
assert.strictEqual(options.body, '{"query":"{ viewer { login } }"}', 'Sends correct query')
|
|
||||||
return { data: {} }
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
[MIT](LICENSE)
|
|
||||||
-15
@@ -1,15 +0,0 @@
|
|||||||
const { request } = require('@octokit/request')
|
|
||||||
const getUserAgent = require('universal-user-agent')
|
|
||||||
|
|
||||||
const version = require('./package.json').version
|
|
||||||
const userAgent = `octokit-graphql.js/${version} ${getUserAgent()}`
|
|
||||||
|
|
||||||
const withDefaults = require('./lib/with-defaults')
|
|
||||||
|
|
||||||
module.exports = withDefaults(request, {
|
|
||||||
method: 'POST',
|
|
||||||
url: '/graphql',
|
|
||||||
headers: {
|
|
||||||
'user-agent': userAgent
|
|
||||||
}
|
|
||||||
})
|
|
||||||
-16
@@ -1,16 +0,0 @@
|
|||||||
module.exports = class GraphqlError extends Error {
|
|
||||||
constructor (request, response) {
|
|
||||||
const message = response.data.errors[0].message
|
|
||||||
super(message)
|
|
||||||
|
|
||||||
Object.assign(this, response.data)
|
|
||||||
this.name = 'GraphqlError'
|
|
||||||
this.request = request
|
|
||||||
|
|
||||||
// Maintains proper stack trace (only available on V8)
|
|
||||||
/* istanbul ignore next */
|
|
||||||
if (Error.captureStackTrace) {
|
|
||||||
Error.captureStackTrace(this, this.constructor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-36
@@ -1,36 +0,0 @@
|
|||||||
module.exports = graphql
|
|
||||||
|
|
||||||
const GraphqlError = require('./error')
|
|
||||||
|
|
||||||
const NON_VARIABLE_OPTIONS = ['method', 'baseUrl', 'url', 'headers', 'request', 'query']
|
|
||||||
|
|
||||||
function graphql (request, query, options) {
|
|
||||||
if (typeof query === 'string') {
|
|
||||||
options = Object.assign({ query }, options)
|
|
||||||
} else {
|
|
||||||
options = query
|
|
||||||
}
|
|
||||||
|
|
||||||
const requestOptions = Object.keys(options).reduce((result, key) => {
|
|
||||||
if (NON_VARIABLE_OPTIONS.includes(key)) {
|
|
||||||
result[key] = options[key]
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!result.variables) {
|
|
||||||
result.variables = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
result.variables[key] = options[key]
|
|
||||||
return result
|
|
||||||
}, {})
|
|
||||||
|
|
||||||
return request(requestOptions)
|
|
||||||
.then(response => {
|
|
||||||
if (response.data.errors) {
|
|
||||||
throw new GraphqlError(requestOptions, response)
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.data.data
|
|
||||||
})
|
|
||||||
}
|
|
||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
module.exports = withDefaults
|
|
||||||
|
|
||||||
const graphql = require('./graphql')
|
|
||||||
|
|
||||||
function withDefaults (request, newDefaults) {
|
|
||||||
const newRequest = request.defaults(newDefaults)
|
|
||||||
const newApi = function (query, options) {
|
|
||||||
return graphql(newRequest, query, options)
|
|
||||||
}
|
|
||||||
|
|
||||||
newApi.defaults = withDefaults.bind(null, newRequest)
|
|
||||||
return newApi
|
|
||||||
}
|
|
||||||
-119
@@ -1,119 +0,0 @@
|
|||||||
{
|
|
||||||
"_from": "@octokit/graphql@^2.0.1",
|
|
||||||
"_id": "@octokit/graphql@2.1.3",
|
|
||||||
"_inBundle": false,
|
|
||||||
"_integrity": "sha512-XoXJqL2ondwdnMIW3wtqJWEwcBfKk37jO/rYkoxNPEVeLBDGsGO1TCWggrAlq3keGt/O+C/7VepXnukUxwt5vA==",
|
|
||||||
"_location": "/@octokit/graphql",
|
|
||||||
"_phantomChildren": {},
|
|
||||||
"_requested": {
|
|
||||||
"type": "range",
|
|
||||||
"registry": true,
|
|
||||||
"raw": "@octokit/graphql@^2.0.1",
|
|
||||||
"name": "@octokit/graphql",
|
|
||||||
"escapedName": "@octokit%2fgraphql",
|
|
||||||
"scope": "@octokit",
|
|
||||||
"rawSpec": "^2.0.1",
|
|
||||||
"saveSpec": null,
|
|
||||||
"fetchSpec": "^2.0.1"
|
|
||||||
},
|
|
||||||
"_requiredBy": [
|
|
||||||
"/@actions/github"
|
|
||||||
],
|
|
||||||
"_resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-2.1.3.tgz",
|
|
||||||
"_shasum": "60c058a0ed5fa242eca6f938908d95fd1a2f4b92",
|
|
||||||
"_spec": "@octokit/graphql@^2.0.1",
|
|
||||||
"_where": "C:\\Users\\lzy\\Documents\\Source\\OpportunityLiu\\github-action-setup-xmake\\node_modules\\@actions\\github",
|
|
||||||
"author": {
|
|
||||||
"name": "Gregor Martynus",
|
|
||||||
"url": "https://github.com/gr2m"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/octokit/graphql.js/issues"
|
|
||||||
},
|
|
||||||
"bundleDependencies": false,
|
|
||||||
"bundlesize": [
|
|
||||||
{
|
|
||||||
"path": "./dist/octokit-graphql.min.js.gz",
|
|
||||||
"maxSize": "5KB"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"dependencies": {
|
|
||||||
"@octokit/request": "^5.0.0",
|
|
||||||
"universal-user-agent": "^2.0.3"
|
|
||||||
},
|
|
||||||
"deprecated": false,
|
|
||||||
"description": "GitHub GraphQL API client for browsers and Node",
|
|
||||||
"devDependencies": {
|
|
||||||
"chai": "^4.2.0",
|
|
||||||
"compression-webpack-plugin": "^2.0.0",
|
|
||||||
"coveralls": "^3.0.3",
|
|
||||||
"cypress": "^3.1.5",
|
|
||||||
"fetch-mock": "^7.3.1",
|
|
||||||
"mkdirp": "^0.5.1",
|
|
||||||
"mocha": "^6.0.0",
|
|
||||||
"npm-run-all": "^4.1.3",
|
|
||||||
"nyc": "^14.0.0",
|
|
||||||
"semantic-release": "^15.13.3",
|
|
||||||
"simple-mock": "^0.8.0",
|
|
||||||
"standard": "^12.0.1",
|
|
||||||
"webpack": "^4.29.6",
|
|
||||||
"webpack-bundle-analyzer": "^3.1.0",
|
|
||||||
"webpack-cli": "^3.2.3"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"lib"
|
|
||||||
],
|
|
||||||
"homepage": "https://github.com/octokit/graphql.js#readme",
|
|
||||||
"keywords": [
|
|
||||||
"octokit",
|
|
||||||
"github",
|
|
||||||
"api",
|
|
||||||
"graphql"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"main": "index.js",
|
|
||||||
"name": "@octokit/graphql",
|
|
||||||
"publishConfig": {
|
|
||||||
"access": "public"
|
|
||||||
},
|
|
||||||
"release": {
|
|
||||||
"publish": [
|
|
||||||
"@semantic-release/npm",
|
|
||||||
{
|
|
||||||
"path": "@semantic-release/github",
|
|
||||||
"assets": [
|
|
||||||
"dist/*",
|
|
||||||
"!dist/*.map.gz"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/octokit/graphql.js.git"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"build": "npm-run-all build:*",
|
|
||||||
"build:development": "webpack --mode development --entry . --output-library=octokitGraphql --output=./dist/octokit-graphql.js --profile --json > dist/bundle-stats.json",
|
|
||||||
"build:production": "webpack --mode production --entry . --plugin=compression-webpack-plugin --output-library=octokitGraphql --output-path=./dist --output-filename=octokit-graphql.min.js --devtool source-map",
|
|
||||||
"bundle-report": "webpack-bundle-analyzer dist/bundle-stats.json --mode=static --no-open --report dist/bundle-report.html",
|
|
||||||
"coverage": "nyc report --reporter=html && open coverage/index.html",
|
|
||||||
"coverage:upload": "nyc report --reporter=text-lcov | coveralls",
|
|
||||||
"prebuild": "mkdirp dist/",
|
|
||||||
"pretest": "standard",
|
|
||||||
"test": "nyc mocha test/*-test.js",
|
|
||||||
"test:browser": "cypress run --browser chrome"
|
|
||||||
},
|
|
||||||
"standard": {
|
|
||||||
"globals": [
|
|
||||||
"describe",
|
|
||||||
"before",
|
|
||||||
"beforeEach",
|
|
||||||
"afterEach",
|
|
||||||
"after",
|
|
||||||
"it",
|
|
||||||
"expect"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"version": "2.1.3"
|
|
||||||
}
|
|
||||||
-395
@@ -1,395 +0,0 @@
|
|||||||
|
|
||||||
3.1.0 / 2017-09-26
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Add `DEBUG_HIDE_DATE` env var (#486)
|
|
||||||
* Remove ReDoS regexp in %o formatter (#504)
|
|
||||||
* Remove "component" from package.json
|
|
||||||
* Remove `component.json`
|
|
||||||
* Ignore package-lock.json
|
|
||||||
* Examples: fix colors printout
|
|
||||||
* Fix: browser detection
|
|
||||||
* Fix: spelling mistake (#496, @EdwardBetts)
|
|
||||||
|
|
||||||
3.0.1 / 2017-08-24
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix: Disable colors in Edge and Internet Explorer (#489)
|
|
||||||
|
|
||||||
3.0.0 / 2017-08-08
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Breaking: Remove DEBUG_FD (#406)
|
|
||||||
* Breaking: Use `Date#toISOString()` instead to `Date#toUTCString()` when output is not a TTY (#418)
|
|
||||||
* Breaking: Make millisecond timer namespace specific and allow 'always enabled' output (#408)
|
|
||||||
* Addition: document `enabled` flag (#465)
|
|
||||||
* Addition: add 256 colors mode (#481)
|
|
||||||
* Addition: `enabled()` updates existing debug instances, add `destroy()` function (#440)
|
|
||||||
* Update: component: update "ms" to v2.0.0
|
|
||||||
* Update: separate the Node and Browser tests in Travis-CI
|
|
||||||
* Update: refactor Readme, fixed documentation, added "Namespace Colors" section, redid screenshots
|
|
||||||
* Update: separate Node.js and web browser examples for organization
|
|
||||||
* Update: update "browserify" to v14.4.0
|
|
||||||
* Fix: fix Readme typo (#473)
|
|
||||||
|
|
||||||
2.6.9 / 2017-09-22
|
|
||||||
==================
|
|
||||||
|
|
||||||
* remove ReDoS regexp in %o formatter (#504)
|
|
||||||
|
|
||||||
2.6.8 / 2017-05-18
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix: Check for undefined on browser globals (#462, @marbemac)
|
|
||||||
|
|
||||||
2.6.7 / 2017-05-16
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix: Update ms to 2.0.0 to fix regular expression denial of service vulnerability (#458, @hubdotcom)
|
|
||||||
* Fix: Inline extend function in node implementation (#452, @dougwilson)
|
|
||||||
* Docs: Fix typo (#455, @msasad)
|
|
||||||
|
|
||||||
2.6.5 / 2017-04-27
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix: null reference check on window.documentElement.style.WebkitAppearance (#447, @thebigredgeek)
|
|
||||||
* Misc: clean up browser reference checks (#447, @thebigredgeek)
|
|
||||||
* Misc: add npm-debug.log to .gitignore (@thebigredgeek)
|
|
||||||
|
|
||||||
|
|
||||||
2.6.4 / 2017-04-20
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix: bug that would occur if process.env.DEBUG is a non-string value. (#444, @LucianBuzzo)
|
|
||||||
* Chore: ignore bower.json in npm installations. (#437, @joaovieira)
|
|
||||||
* Misc: update "ms" to v0.7.3 (@tootallnate)
|
|
||||||
|
|
||||||
2.6.3 / 2017-03-13
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix: Electron reference to `process.env.DEBUG` (#431, @paulcbetts)
|
|
||||||
* Docs: Changelog fix (@thebigredgeek)
|
|
||||||
|
|
||||||
2.6.2 / 2017-03-10
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix: DEBUG_MAX_ARRAY_LENGTH (#420, @slavaGanzin)
|
|
||||||
* Docs: Add backers and sponsors from Open Collective (#422, @piamancini)
|
|
||||||
* Docs: Add Slackin invite badge (@tootallnate)
|
|
||||||
|
|
||||||
2.6.1 / 2017-02-10
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix: Module's `export default` syntax fix for IE8 `Expected identifier` error
|
|
||||||
* Fix: Whitelist DEBUG_FD for values 1 and 2 only (#415, @pi0)
|
|
||||||
* Fix: IE8 "Expected identifier" error (#414, @vgoma)
|
|
||||||
* Fix: Namespaces would not disable once enabled (#409, @musikov)
|
|
||||||
|
|
||||||
2.6.0 / 2016-12-28
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix: added better null pointer checks for browser useColors (@thebigredgeek)
|
|
||||||
* Improvement: removed explicit `window.debug` export (#404, @tootallnate)
|
|
||||||
* Improvement: deprecated `DEBUG_FD` environment variable (#405, @tootallnate)
|
|
||||||
|
|
||||||
2.5.2 / 2016-12-25
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix: reference error on window within webworkers (#393, @KlausTrainer)
|
|
||||||
* Docs: fixed README typo (#391, @lurch)
|
|
||||||
* Docs: added notice about v3 api discussion (@thebigredgeek)
|
|
||||||
|
|
||||||
2.5.1 / 2016-12-20
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix: babel-core compatibility
|
|
||||||
|
|
||||||
2.5.0 / 2016-12-20
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix: wrong reference in bower file (@thebigredgeek)
|
|
||||||
* Fix: webworker compatibility (@thebigredgeek)
|
|
||||||
* Fix: output formatting issue (#388, @kribblo)
|
|
||||||
* Fix: babel-loader compatibility (#383, @escwald)
|
|
||||||
* Misc: removed built asset from repo and publications (@thebigredgeek)
|
|
||||||
* Misc: moved source files to /src (#378, @yamikuronue)
|
|
||||||
* Test: added karma integration and replaced babel with browserify for browser tests (#378, @yamikuronue)
|
|
||||||
* Test: coveralls integration (#378, @yamikuronue)
|
|
||||||
* Docs: simplified language in the opening paragraph (#373, @yamikuronue)
|
|
||||||
|
|
||||||
2.4.5 / 2016-12-17
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix: `navigator` undefined in Rhino (#376, @jochenberger)
|
|
||||||
* Fix: custom log function (#379, @hsiliev)
|
|
||||||
* Improvement: bit of cleanup + linting fixes (@thebigredgeek)
|
|
||||||
* Improvement: rm non-maintainted `dist/` dir (#375, @freewil)
|
|
||||||
* Docs: simplified language in the opening paragraph. (#373, @yamikuronue)
|
|
||||||
|
|
||||||
2.4.4 / 2016-12-14
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix: work around debug being loaded in preload scripts for electron (#368, @paulcbetts)
|
|
||||||
|
|
||||||
2.4.3 / 2016-12-14
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix: navigation.userAgent error for react native (#364, @escwald)
|
|
||||||
|
|
||||||
2.4.2 / 2016-12-14
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix: browser colors (#367, @tootallnate)
|
|
||||||
* Misc: travis ci integration (@thebigredgeek)
|
|
||||||
* Misc: added linting and testing boilerplate with sanity check (@thebigredgeek)
|
|
||||||
|
|
||||||
2.4.1 / 2016-12-13
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix: typo that broke the package (#356)
|
|
||||||
|
|
||||||
2.4.0 / 2016-12-13
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix: bower.json references unbuilt src entry point (#342, @justmatt)
|
|
||||||
* Fix: revert "handle regex special characters" (@tootallnate)
|
|
||||||
* Feature: configurable util.inspect()`options for NodeJS (#327, @tootallnate)
|
|
||||||
* Feature: %O`(big O) pretty-prints objects (#322, @tootallnate)
|
|
||||||
* Improvement: allow colors in workers (#335, @botverse)
|
|
||||||
* Improvement: use same color for same namespace. (#338, @lchenay)
|
|
||||||
|
|
||||||
2.3.3 / 2016-11-09
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix: Catch `JSON.stringify()` errors (#195, Jovan Alleyne)
|
|
||||||
* Fix: Returning `localStorage` saved values (#331, Levi Thomason)
|
|
||||||
* Improvement: Don't create an empty object when no `process` (Nathan Rajlich)
|
|
||||||
|
|
||||||
2.3.2 / 2016-11-09
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix: be super-safe in index.js as well (@TooTallNate)
|
|
||||||
* Fix: should check whether process exists (Tom Newby)
|
|
||||||
|
|
||||||
2.3.1 / 2016-11-09
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix: Added electron compatibility (#324, @paulcbetts)
|
|
||||||
* Improvement: Added performance optimizations (@tootallnate)
|
|
||||||
* Readme: Corrected PowerShell environment variable example (#252, @gimre)
|
|
||||||
* Misc: Removed yarn lock file from source control (#321, @fengmk2)
|
|
||||||
|
|
||||||
2.3.0 / 2016-11-07
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Fix: Consistent placement of ms diff at end of output (#215, @gorangajic)
|
|
||||||
* Fix: Escaping of regex special characters in namespace strings (#250, @zacronos)
|
|
||||||
* Fix: Fixed bug causing crash on react-native (#282, @vkarpov15)
|
|
||||||
* Feature: Enabled ES6+ compatible import via default export (#212 @bucaran)
|
|
||||||
* Feature: Added %O formatter to reflect Chrome's console.log capability (#279, @oncletom)
|
|
||||||
* Package: Update "ms" to 0.7.2 (#315, @DevSide)
|
|
||||||
* Package: removed superfluous version property from bower.json (#207 @kkirsche)
|
|
||||||
* Readme: fix USE_COLORS to DEBUG_COLORS
|
|
||||||
* Readme: Doc fixes for format string sugar (#269, @mlucool)
|
|
||||||
* Readme: Updated docs for DEBUG_FD and DEBUG_COLORS environment variables (#232, @mattlyons0)
|
|
||||||
* Readme: doc fixes for PowerShell (#271 #243, @exoticknight @unreadable)
|
|
||||||
* Readme: better docs for browser support (#224, @matthewmueller)
|
|
||||||
* Tooling: Added yarn integration for development (#317, @thebigredgeek)
|
|
||||||
* Misc: Renamed History.md to CHANGELOG.md (@thebigredgeek)
|
|
||||||
* Misc: Added license file (#226 #274, @CantemoInternal @sdaitzman)
|
|
||||||
* Misc: Updated contributors (@thebigredgeek)
|
|
||||||
|
|
||||||
2.2.0 / 2015-05-09
|
|
||||||
==================
|
|
||||||
|
|
||||||
* package: update "ms" to v0.7.1 (#202, @dougwilson)
|
|
||||||
* README: add logging to file example (#193, @DanielOchoa)
|
|
||||||
* README: fixed a typo (#191, @amir-s)
|
|
||||||
* browser: expose `storage` (#190, @stephenmathieson)
|
|
||||||
* Makefile: add a `distclean` target (#189, @stephenmathieson)
|
|
||||||
|
|
||||||
2.1.3 / 2015-03-13
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Updated stdout/stderr example (#186)
|
|
||||||
* Updated example/stdout.js to match debug current behaviour
|
|
||||||
* Renamed example/stderr.js to stdout.js
|
|
||||||
* Update Readme.md (#184)
|
|
||||||
* replace high intensity foreground color for bold (#182, #183)
|
|
||||||
|
|
||||||
2.1.2 / 2015-03-01
|
|
||||||
==================
|
|
||||||
|
|
||||||
* dist: recompile
|
|
||||||
* update "ms" to v0.7.0
|
|
||||||
* package: update "browserify" to v9.0.3
|
|
||||||
* component: fix "ms.js" repo location
|
|
||||||
* changed bower package name
|
|
||||||
* updated documentation about using debug in a browser
|
|
||||||
* fix: security error on safari (#167, #168, @yields)
|
|
||||||
|
|
||||||
2.1.1 / 2014-12-29
|
|
||||||
==================
|
|
||||||
|
|
||||||
* browser: use `typeof` to check for `console` existence
|
|
||||||
* browser: check for `console.log` truthiness (fix IE 8/9)
|
|
||||||
* browser: add support for Chrome apps
|
|
||||||
* Readme: added Windows usage remarks
|
|
||||||
* Add `bower.json` to properly support bower install
|
|
||||||
|
|
||||||
2.1.0 / 2014-10-15
|
|
||||||
==================
|
|
||||||
|
|
||||||
* node: implement `DEBUG_FD` env variable support
|
|
||||||
* package: update "browserify" to v6.1.0
|
|
||||||
* package: add "license" field to package.json (#135, @panuhorsmalahti)
|
|
||||||
|
|
||||||
2.0.0 / 2014-09-01
|
|
||||||
==================
|
|
||||||
|
|
||||||
* package: update "browserify" to v5.11.0
|
|
||||||
* node: use stderr rather than stdout for logging (#29, @stephenmathieson)
|
|
||||||
|
|
||||||
1.0.4 / 2014-07-15
|
|
||||||
==================
|
|
||||||
|
|
||||||
* dist: recompile
|
|
||||||
* example: remove `console.info()` log usage
|
|
||||||
* example: add "Content-Type" UTF-8 header to browser example
|
|
||||||
* browser: place %c marker after the space character
|
|
||||||
* browser: reset the "content" color via `color: inherit`
|
|
||||||
* browser: add colors support for Firefox >= v31
|
|
||||||
* debug: prefer an instance `log()` function over the global one (#119)
|
|
||||||
* Readme: update documentation about styled console logs for FF v31 (#116, @wryk)
|
|
||||||
|
|
||||||
1.0.3 / 2014-07-09
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Add support for multiple wildcards in namespaces (#122, @seegno)
|
|
||||||
* browser: fix lint
|
|
||||||
|
|
||||||
1.0.2 / 2014-06-10
|
|
||||||
==================
|
|
||||||
|
|
||||||
* browser: update color palette (#113, @gscottolson)
|
|
||||||
* common: make console logging function configurable (#108, @timoxley)
|
|
||||||
* node: fix %o colors on old node <= 0.8.x
|
|
||||||
* Makefile: find node path using shell/which (#109, @timoxley)
|
|
||||||
|
|
||||||
1.0.1 / 2014-06-06
|
|
||||||
==================
|
|
||||||
|
|
||||||
* browser: use `removeItem()` to clear localStorage
|
|
||||||
* browser, node: don't set DEBUG if namespaces is undefined (#107, @leedm777)
|
|
||||||
* package: add "contributors" section
|
|
||||||
* node: fix comment typo
|
|
||||||
* README: list authors
|
|
||||||
|
|
||||||
1.0.0 / 2014-06-04
|
|
||||||
==================
|
|
||||||
|
|
||||||
* make ms diff be global, not be scope
|
|
||||||
* debug: ignore empty strings in enable()
|
|
||||||
* node: make DEBUG_COLORS able to disable coloring
|
|
||||||
* *: export the `colors` array
|
|
||||||
* npmignore: don't publish the `dist` dir
|
|
||||||
* Makefile: refactor to use browserify
|
|
||||||
* package: add "browserify" as a dev dependency
|
|
||||||
* Readme: add Web Inspector Colors section
|
|
||||||
* node: reset terminal color for the debug content
|
|
||||||
* node: map "%o" to `util.inspect()`
|
|
||||||
* browser: map "%j" to `JSON.stringify()`
|
|
||||||
* debug: add custom "formatters"
|
|
||||||
* debug: use "ms" module for humanizing the diff
|
|
||||||
* Readme: add "bash" syntax highlighting
|
|
||||||
* browser: add Firebug color support
|
|
||||||
* browser: add colors for WebKit browsers
|
|
||||||
* node: apply log to `console`
|
|
||||||
* rewrite: abstract common logic for Node & browsers
|
|
||||||
* add .jshintrc file
|
|
||||||
|
|
||||||
0.8.1 / 2014-04-14
|
|
||||||
==================
|
|
||||||
|
|
||||||
* package: re-add the "component" section
|
|
||||||
|
|
||||||
0.8.0 / 2014-03-30
|
|
||||||
==================
|
|
||||||
|
|
||||||
* add `enable()` method for nodejs. Closes #27
|
|
||||||
* change from stderr to stdout
|
|
||||||
* remove unnecessary index.js file
|
|
||||||
|
|
||||||
0.7.4 / 2013-11-13
|
|
||||||
==================
|
|
||||||
|
|
||||||
* remove "browserify" key from package.json (fixes something in browserify)
|
|
||||||
|
|
||||||
0.7.3 / 2013-10-30
|
|
||||||
==================
|
|
||||||
|
|
||||||
* fix: catch localStorage security error when cookies are blocked (Chrome)
|
|
||||||
* add debug(err) support. Closes #46
|
|
||||||
* add .browser prop to package.json. Closes #42
|
|
||||||
|
|
||||||
0.7.2 / 2013-02-06
|
|
||||||
==================
|
|
||||||
|
|
||||||
* fix package.json
|
|
||||||
* fix: Mobile Safari (private mode) is broken with debug
|
|
||||||
* fix: Use unicode to send escape character to shell instead of octal to work with strict mode javascript
|
|
||||||
|
|
||||||
0.7.1 / 2013-02-05
|
|
||||||
==================
|
|
||||||
|
|
||||||
* add repository URL to package.json
|
|
||||||
* add DEBUG_COLORED to force colored output
|
|
||||||
* add browserify support
|
|
||||||
* fix component. Closes #24
|
|
||||||
|
|
||||||
0.7.0 / 2012-05-04
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Added .component to package.json
|
|
||||||
* Added debug.component.js build
|
|
||||||
|
|
||||||
0.6.0 / 2012-03-16
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Added support for "-" prefix in DEBUG [Vinay Pulim]
|
|
||||||
* Added `.enabled` flag to the node version [TooTallNate]
|
|
||||||
|
|
||||||
0.5.0 / 2012-02-02
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Added: humanize diffs. Closes #8
|
|
||||||
* Added `debug.disable()` to the CS variant
|
|
||||||
* Removed padding. Closes #10
|
|
||||||
* Fixed: persist client-side variant again. Closes #9
|
|
||||||
|
|
||||||
0.4.0 / 2012-02-01
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Added browser variant support for older browsers [TooTallNate]
|
|
||||||
* Added `debug.enable('project:*')` to browser variant [TooTallNate]
|
|
||||||
* Added padding to diff (moved it to the right)
|
|
||||||
|
|
||||||
0.3.0 / 2012-01-26
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Added millisecond diff when isatty, otherwise UTC string
|
|
||||||
|
|
||||||
0.2.0 / 2012-01-22
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Added wildcard support
|
|
||||||
|
|
||||||
0.1.0 / 2011-12-02
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Added: remove colors unless stderr isatty [TooTallNate]
|
|
||||||
|
|
||||||
0.0.1 / 2010-01-03
|
|
||||||
==================
|
|
||||||
|
|
||||||
* Initial release
|
|
||||||
-19
@@ -1,19 +0,0 @@
|
|||||||
(The MIT License)
|
|
||||||
|
|
||||||
Copyright (c) 2014 TJ Holowaychuk <tj@vision-media.ca>
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
-455
@@ -1,455 +0,0 @@
|
|||||||
# debug
|
|
||||||
[](https://travis-ci.org/visionmedia/debug) [](https://coveralls.io/github/visionmedia/debug?branch=master) [](https://visionmedia-community-slackin.now.sh/) [](#backers)
|
|
||||||
[](#sponsors)
|
|
||||||
|
|
||||||
<img width="647" src="https://user-images.githubusercontent.com/71256/29091486-fa38524c-7c37-11e7-895f-e7ec8e1039b6.png">
|
|
||||||
|
|
||||||
A tiny JavaScript debugging utility modelled after Node.js core's debugging
|
|
||||||
technique. Works in Node.js and web browsers.
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ npm install debug
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
`debug` exposes a function; simply pass this function the name of your module, and it will return a decorated version of `console.error` for you to pass debug statements to. This will allow you to toggle the debug output for different parts of your module as well as the module as a whole.
|
|
||||||
|
|
||||||
Example [_app.js_](./examples/node/app.js):
|
|
||||||
|
|
||||||
```js
|
|
||||||
var debug = require('debug')('http')
|
|
||||||
, http = require('http')
|
|
||||||
, name = 'My App';
|
|
||||||
|
|
||||||
// fake app
|
|
||||||
|
|
||||||
debug('booting %o', name);
|
|
||||||
|
|
||||||
http.createServer(function(req, res){
|
|
||||||
debug(req.method + ' ' + req.url);
|
|
||||||
res.end('hello\n');
|
|
||||||
}).listen(3000, function(){
|
|
||||||
debug('listening');
|
|
||||||
});
|
|
||||||
|
|
||||||
// fake worker of some kind
|
|
||||||
|
|
||||||
require('./worker');
|
|
||||||
```
|
|
||||||
|
|
||||||
Example [_worker.js_](./examples/node/worker.js):
|
|
||||||
|
|
||||||
```js
|
|
||||||
var a = require('debug')('worker:a')
|
|
||||||
, b = require('debug')('worker:b');
|
|
||||||
|
|
||||||
function work() {
|
|
||||||
a('doing lots of uninteresting work');
|
|
||||||
setTimeout(work, Math.random() * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
work();
|
|
||||||
|
|
||||||
function workb() {
|
|
||||||
b('doing some work');
|
|
||||||
setTimeout(workb, Math.random() * 2000);
|
|
||||||
}
|
|
||||||
|
|
||||||
workb();
|
|
||||||
```
|
|
||||||
|
|
||||||
The `DEBUG` environment variable is then used to enable these based on space or
|
|
||||||
comma-delimited names.
|
|
||||||
|
|
||||||
Here are some examples:
|
|
||||||
|
|
||||||
<img width="647" alt="screen shot 2017-08-08 at 12 53 04 pm" src="https://user-images.githubusercontent.com/71256/29091703-a6302cdc-7c38-11e7-8304-7c0b3bc600cd.png">
|
|
||||||
<img width="647" alt="screen shot 2017-08-08 at 12 53 38 pm" src="https://user-images.githubusercontent.com/71256/29091700-a62a6888-7c38-11e7-800b-db911291ca2b.png">
|
|
||||||
<img width="647" alt="screen shot 2017-08-08 at 12 53 25 pm" src="https://user-images.githubusercontent.com/71256/29091701-a62ea114-7c38-11e7-826a-2692bedca740.png">
|
|
||||||
|
|
||||||
#### Windows command prompt notes
|
|
||||||
|
|
||||||
##### CMD
|
|
||||||
|
|
||||||
On Windows the environment variable is set using the `set` command.
|
|
||||||
|
|
||||||
```cmd
|
|
||||||
set DEBUG=*,-not_this
|
|
||||||
```
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```cmd
|
|
||||||
set DEBUG=* & node app.js
|
|
||||||
```
|
|
||||||
|
|
||||||
##### PowerShell (VS Code default)
|
|
||||||
|
|
||||||
PowerShell uses different syntax to set environment variables.
|
|
||||||
|
|
||||||
```cmd
|
|
||||||
$env:DEBUG = "*,-not_this"
|
|
||||||
```
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```cmd
|
|
||||||
$env:DEBUG='app';node app.js
|
|
||||||
```
|
|
||||||
|
|
||||||
Then, run the program to be debugged as usual.
|
|
||||||
|
|
||||||
npm script example:
|
|
||||||
```js
|
|
||||||
"windowsDebug": "@powershell -Command $env:DEBUG='*';node app.js",
|
|
||||||
```
|
|
||||||
|
|
||||||
## Namespace Colors
|
|
||||||
|
|
||||||
Every debug instance has a color generated for it based on its namespace name.
|
|
||||||
This helps when visually parsing the debug output to identify which debug instance
|
|
||||||
a debug line belongs to.
|
|
||||||
|
|
||||||
#### Node.js
|
|
||||||
|
|
||||||
In Node.js, colors are enabled when stderr is a TTY. You also _should_ install
|
|
||||||
the [`supports-color`](https://npmjs.org/supports-color) module alongside debug,
|
|
||||||
otherwise debug will only use a small handful of basic colors.
|
|
||||||
|
|
||||||
<img width="521" src="https://user-images.githubusercontent.com/71256/29092181-47f6a9e6-7c3a-11e7-9a14-1928d8a711cd.png">
|
|
||||||
|
|
||||||
#### Web Browser
|
|
||||||
|
|
||||||
Colors are also enabled on "Web Inspectors" that understand the `%c` formatting
|
|
||||||
option. These are WebKit web inspectors, Firefox ([since version
|
|
||||||
31](https://hacks.mozilla.org/2014/05/editable-box-model-multiple-selection-sublime-text-keys-much-more-firefox-developer-tools-episode-31/))
|
|
||||||
and the Firebug plugin for Firefox (any version).
|
|
||||||
|
|
||||||
<img width="524" src="https://user-images.githubusercontent.com/71256/29092033-b65f9f2e-7c39-11e7-8e32-f6f0d8e865c1.png">
|
|
||||||
|
|
||||||
|
|
||||||
## Millisecond diff
|
|
||||||
|
|
||||||
When actively developing an application it can be useful to see when the time spent between one `debug()` call and the next. Suppose for example you invoke `debug()` before requesting a resource, and after as well, the "+NNNms" will show you how much time was spent between calls.
|
|
||||||
|
|
||||||
<img width="647" src="https://user-images.githubusercontent.com/71256/29091486-fa38524c-7c37-11e7-895f-e7ec8e1039b6.png">
|
|
||||||
|
|
||||||
When stdout is not a TTY, `Date#toISOString()` is used, making it more useful for logging the debug information as shown below:
|
|
||||||
|
|
||||||
<img width="647" src="https://user-images.githubusercontent.com/71256/29091956-6bd78372-7c39-11e7-8c55-c948396d6edd.png">
|
|
||||||
|
|
||||||
|
|
||||||
## Conventions
|
|
||||||
|
|
||||||
If you're using this in one or more of your libraries, you _should_ use the name of your library so that developers may toggle debugging as desired without guessing names. If you have more than one debuggers you _should_ prefix them with your library name and use ":" to separate features. For example "bodyParser" from Connect would then be "connect:bodyParser". If you append a "*" to the end of your name, it will always be enabled regardless of the setting of the DEBUG environment variable. You can then use it for normal output as well as debug output.
|
|
||||||
|
|
||||||
## Wildcards
|
|
||||||
|
|
||||||
The `*` character may be used as a wildcard. Suppose for example your library has
|
|
||||||
debuggers named "connect:bodyParser", "connect:compress", "connect:session",
|
|
||||||
instead of listing all three with
|
|
||||||
`DEBUG=connect:bodyParser,connect:compress,connect:session`, you may simply do
|
|
||||||
`DEBUG=connect:*`, or to run everything using this module simply use `DEBUG=*`.
|
|
||||||
|
|
||||||
You can also exclude specific debuggers by prefixing them with a "-" character.
|
|
||||||
For example, `DEBUG=*,-connect:*` would include all debuggers except those
|
|
||||||
starting with "connect:".
|
|
||||||
|
|
||||||
## Environment Variables
|
|
||||||
|
|
||||||
When running through Node.js, you can set a few environment variables that will
|
|
||||||
change the behavior of the debug logging:
|
|
||||||
|
|
||||||
| Name | Purpose |
|
|
||||||
|-----------|-------------------------------------------------|
|
|
||||||
| `DEBUG` | Enables/disables specific debugging namespaces. |
|
|
||||||
| `DEBUG_HIDE_DATE` | Hide date from debug output (non-TTY). |
|
|
||||||
| `DEBUG_COLORS`| Whether or not to use colors in the debug output. |
|
|
||||||
| `DEBUG_DEPTH` | Object inspection depth. |
|
|
||||||
| `DEBUG_SHOW_HIDDEN` | Shows hidden properties on inspected objects. |
|
|
||||||
|
|
||||||
|
|
||||||
__Note:__ The environment variables beginning with `DEBUG_` end up being
|
|
||||||
converted into an Options object that gets used with `%o`/`%O` formatters.
|
|
||||||
See the Node.js documentation for
|
|
||||||
[`util.inspect()`](https://nodejs.org/api/util.html#util_util_inspect_object_options)
|
|
||||||
for the complete list.
|
|
||||||
|
|
||||||
## Formatters
|
|
||||||
|
|
||||||
Debug uses [printf-style](https://wikipedia.org/wiki/Printf_format_string) formatting.
|
|
||||||
Below are the officially supported formatters:
|
|
||||||
|
|
||||||
| Formatter | Representation |
|
|
||||||
|-----------|----------------|
|
|
||||||
| `%O` | Pretty-print an Object on multiple lines. |
|
|
||||||
| `%o` | Pretty-print an Object all on a single line. |
|
|
||||||
| `%s` | String. |
|
|
||||||
| `%d` | Number (both integer and float). |
|
|
||||||
| `%j` | JSON. Replaced with the string '[Circular]' if the argument contains circular references. |
|
|
||||||
| `%%` | Single percent sign ('%'). This does not consume an argument. |
|
|
||||||
|
|
||||||
|
|
||||||
### Custom formatters
|
|
||||||
|
|
||||||
You can add custom formatters by extending the `debug.formatters` object.
|
|
||||||
For example, if you wanted to add support for rendering a Buffer as hex with
|
|
||||||
`%h`, you could do something like:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const createDebug = require('debug')
|
|
||||||
createDebug.formatters.h = (v) => {
|
|
||||||
return v.toString('hex')
|
|
||||||
}
|
|
||||||
|
|
||||||
// …elsewhere
|
|
||||||
const debug = createDebug('foo')
|
|
||||||
debug('this is hex: %h', new Buffer('hello world'))
|
|
||||||
// foo this is hex: 68656c6c6f20776f726c6421 +0ms
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Browser Support
|
|
||||||
|
|
||||||
You can build a browser-ready script using [browserify](https://github.com/substack/node-browserify),
|
|
||||||
or just use the [browserify-as-a-service](https://wzrd.in/) [build](https://wzrd.in/standalone/debug@latest),
|
|
||||||
if you don't want to build it yourself.
|
|
||||||
|
|
||||||
Debug's enable state is currently persisted by `localStorage`.
|
|
||||||
Consider the situation shown below where you have `worker:a` and `worker:b`,
|
|
||||||
and wish to debug both. You can enable this using `localStorage.debug`:
|
|
||||||
|
|
||||||
```js
|
|
||||||
localStorage.debug = 'worker:*'
|
|
||||||
```
|
|
||||||
|
|
||||||
And then refresh the page.
|
|
||||||
|
|
||||||
```js
|
|
||||||
a = debug('worker:a');
|
|
||||||
b = debug('worker:b');
|
|
||||||
|
|
||||||
setInterval(function(){
|
|
||||||
a('doing some work');
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
setInterval(function(){
|
|
||||||
b('doing some work');
|
|
||||||
}, 1200);
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Output streams
|
|
||||||
|
|
||||||
By default `debug` will log to stderr, however this can be configured per-namespace by overriding the `log` method:
|
|
||||||
|
|
||||||
Example [_stdout.js_](./examples/node/stdout.js):
|
|
||||||
|
|
||||||
```js
|
|
||||||
var debug = require('debug');
|
|
||||||
var error = debug('app:error');
|
|
||||||
|
|
||||||
// by default stderr is used
|
|
||||||
error('goes to stderr!');
|
|
||||||
|
|
||||||
var log = debug('app:log');
|
|
||||||
// set this namespace to log via console.log
|
|
||||||
log.log = console.log.bind(console); // don't forget to bind to console!
|
|
||||||
log('goes to stdout');
|
|
||||||
error('still goes to stderr!');
|
|
||||||
|
|
||||||
// set all output to go via console.info
|
|
||||||
// overrides all per-namespace log settings
|
|
||||||
debug.log = console.info.bind(console);
|
|
||||||
error('now goes to stdout via console.info');
|
|
||||||
log('still goes to stdout, but via console.info now');
|
|
||||||
```
|
|
||||||
|
|
||||||
## Extend
|
|
||||||
You can simply extend debugger
|
|
||||||
```js
|
|
||||||
const log = require('debug')('auth');
|
|
||||||
|
|
||||||
//creates new debug instance with extended namespace
|
|
||||||
const logSign = log.extend('sign');
|
|
||||||
const logLogin = log.extend('login');
|
|
||||||
|
|
||||||
log('hello'); // auth hello
|
|
||||||
logSign('hello'); //auth:sign hello
|
|
||||||
logLogin('hello'); //auth:login hello
|
|
||||||
```
|
|
||||||
|
|
||||||
## Set dynamically
|
|
||||||
|
|
||||||
You can also enable debug dynamically by calling the `enable()` method :
|
|
||||||
|
|
||||||
```js
|
|
||||||
let debug = require('debug');
|
|
||||||
|
|
||||||
console.log(1, debug.enabled('test'));
|
|
||||||
|
|
||||||
debug.enable('test');
|
|
||||||
console.log(2, debug.enabled('test'));
|
|
||||||
|
|
||||||
debug.disable();
|
|
||||||
console.log(3, debug.enabled('test'));
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
print :
|
|
||||||
```
|
|
||||||
1 false
|
|
||||||
2 true
|
|
||||||
3 false
|
|
||||||
```
|
|
||||||
|
|
||||||
Usage :
|
|
||||||
`enable(namespaces)`
|
|
||||||
`namespaces` can include modes separated by a colon and wildcards.
|
|
||||||
|
|
||||||
Note that calling `enable()` completely overrides previously set DEBUG variable :
|
|
||||||
|
|
||||||
```
|
|
||||||
$ DEBUG=foo node -e 'var dbg = require("debug"); dbg.enable("bar"); console.log(dbg.enabled("foo"))'
|
|
||||||
=> false
|
|
||||||
```
|
|
||||||
|
|
||||||
`disable()`
|
|
||||||
|
|
||||||
Will disable all namespaces. The functions returns the namespaces currently
|
|
||||||
enabled (and skipped). This can be useful if you want to disable debugging
|
|
||||||
temporarily without knowing what was enabled to begin with.
|
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
|
||||||
let debug = require('debug');
|
|
||||||
debug.enable('foo:*,-foo:bar');
|
|
||||||
let namespaces = debug.disable();
|
|
||||||
debug.enable(namespaces);
|
|
||||||
```
|
|
||||||
|
|
||||||
Note: There is no guarantee that the string will be identical to the initial
|
|
||||||
enable string, but semantically they will be identical.
|
|
||||||
|
|
||||||
## Checking whether a debug target is enabled
|
|
||||||
|
|
||||||
After you've created a debug instance, you can determine whether or not it is
|
|
||||||
enabled by checking the `enabled` property:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
const debug = require('debug')('http');
|
|
||||||
|
|
||||||
if (debug.enabled) {
|
|
||||||
// do stuff...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also manually toggle this property to force the debug instance to be
|
|
||||||
enabled or disabled.
|
|
||||||
|
|
||||||
|
|
||||||
## Authors
|
|
||||||
|
|
||||||
- TJ Holowaychuk
|
|
||||||
- Nathan Rajlich
|
|
||||||
- Andrew Rhyne
|
|
||||||
|
|
||||||
## Backers
|
|
||||||
|
|
||||||
Support us with a monthly donation and help us continue our activities. [[Become a backer](https://opencollective.com/debug#backer)]
|
|
||||||
|
|
||||||
<a href="https://opencollective.com/debug/backer/0/website" target="_blank"><img src="https://opencollective.com/debug/backer/0/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/1/website" target="_blank"><img src="https://opencollective.com/debug/backer/1/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/2/website" target="_blank"><img src="https://opencollective.com/debug/backer/2/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/3/website" target="_blank"><img src="https://opencollective.com/debug/backer/3/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/4/website" target="_blank"><img src="https://opencollective.com/debug/backer/4/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/5/website" target="_blank"><img src="https://opencollective.com/debug/backer/5/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/6/website" target="_blank"><img src="https://opencollective.com/debug/backer/6/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/7/website" target="_blank"><img src="https://opencollective.com/debug/backer/7/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/8/website" target="_blank"><img src="https://opencollective.com/debug/backer/8/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/9/website" target="_blank"><img src="https://opencollective.com/debug/backer/9/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/10/website" target="_blank"><img src="https://opencollective.com/debug/backer/10/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/11/website" target="_blank"><img src="https://opencollective.com/debug/backer/11/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/12/website" target="_blank"><img src="https://opencollective.com/debug/backer/12/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/13/website" target="_blank"><img src="https://opencollective.com/debug/backer/13/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/14/website" target="_blank"><img src="https://opencollective.com/debug/backer/14/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/15/website" target="_blank"><img src="https://opencollective.com/debug/backer/15/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/16/website" target="_blank"><img src="https://opencollective.com/debug/backer/16/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/17/website" target="_blank"><img src="https://opencollective.com/debug/backer/17/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/18/website" target="_blank"><img src="https://opencollective.com/debug/backer/18/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/19/website" target="_blank"><img src="https://opencollective.com/debug/backer/19/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/20/website" target="_blank"><img src="https://opencollective.com/debug/backer/20/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/21/website" target="_blank"><img src="https://opencollective.com/debug/backer/21/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/22/website" target="_blank"><img src="https://opencollective.com/debug/backer/22/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/23/website" target="_blank"><img src="https://opencollective.com/debug/backer/23/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/24/website" target="_blank"><img src="https://opencollective.com/debug/backer/24/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/25/website" target="_blank"><img src="https://opencollective.com/debug/backer/25/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/26/website" target="_blank"><img src="https://opencollective.com/debug/backer/26/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/27/website" target="_blank"><img src="https://opencollective.com/debug/backer/27/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/28/website" target="_blank"><img src="https://opencollective.com/debug/backer/28/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/backer/29/website" target="_blank"><img src="https://opencollective.com/debug/backer/29/avatar.svg"></a>
|
|
||||||
|
|
||||||
|
|
||||||
## Sponsors
|
|
||||||
|
|
||||||
Become a sponsor and get your logo on our README on Github with a link to your site. [[Become a sponsor](https://opencollective.com/debug#sponsor)]
|
|
||||||
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/0/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/0/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/1/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/1/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/2/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/2/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/3/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/3/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/4/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/4/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/5/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/5/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/6/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/6/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/7/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/7/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/8/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/8/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/9/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/9/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/10/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/10/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/11/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/11/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/12/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/12/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/13/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/13/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/14/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/14/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/15/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/15/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/16/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/16/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/17/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/17/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/18/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/18/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/19/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/19/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/20/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/20/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/21/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/21/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/22/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/22/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/23/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/23/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/24/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/24/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/25/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/25/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/26/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/26/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/27/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/27/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/28/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/28/avatar.svg"></a>
|
|
||||||
<a href="https://opencollective.com/debug/sponsor/29/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/29/avatar.svg"></a>
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
(The MIT License)
|
|
||||||
|
|
||||||
Copyright (c) 2014-2017 TJ Holowaychuk <tj@vision-media.ca>
|
|
||||||
|
|
||||||
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.
|
|
||||||
-912
@@ -1,912 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
|
||||||
|
|
||||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
|
||||||
|
|
||||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
|
||||||
|
|
||||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
|
||||||
|
|
||||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
||||||
|
|
||||||
(function (f) {
|
|
||||||
if ((typeof exports === "undefined" ? "undefined" : _typeof(exports)) === "object" && typeof module !== "undefined") {
|
|
||||||
module.exports = f();
|
|
||||||
} else if (typeof define === "function" && define.amd) {
|
|
||||||
define([], f);
|
|
||||||
} else {
|
|
||||||
var g;
|
|
||||||
|
|
||||||
if (typeof window !== "undefined") {
|
|
||||||
g = window;
|
|
||||||
} else if (typeof global !== "undefined") {
|
|
||||||
g = global;
|
|
||||||
} else if (typeof self !== "undefined") {
|
|
||||||
g = self;
|
|
||||||
} else {
|
|
||||||
g = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
g.debug = f();
|
|
||||||
}
|
|
||||||
})(function () {
|
|
||||||
var define, module, exports;
|
|
||||||
return function () {
|
|
||||||
function r(e, n, t) {
|
|
||||||
function o(i, f) {
|
|
||||||
if (!n[i]) {
|
|
||||||
if (!e[i]) {
|
|
||||||
var c = "function" == typeof require && require;
|
|
||||||
if (!f && c) return c(i, !0);
|
|
||||||
if (u) return u(i, !0);
|
|
||||||
var a = new Error("Cannot find module '" + i + "'");
|
|
||||||
throw a.code = "MODULE_NOT_FOUND", a;
|
|
||||||
}
|
|
||||||
|
|
||||||
var p = n[i] = {
|
|
||||||
exports: {}
|
|
||||||
};
|
|
||||||
e[i][0].call(p.exports, function (r) {
|
|
||||||
var n = e[i][1][r];
|
|
||||||
return o(n || r);
|
|
||||||
}, p, p.exports, r, e, n, t);
|
|
||||||
}
|
|
||||||
|
|
||||||
return n[i].exports;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) {
|
|
||||||
o(t[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}()({
|
|
||||||
1: [function (require, module, exports) {
|
|
||||||
/**
|
|
||||||
* Helpers.
|
|
||||||
*/
|
|
||||||
var s = 1000;
|
|
||||||
var m = s * 60;
|
|
||||||
var h = m * 60;
|
|
||||||
var d = h * 24;
|
|
||||||
var w = d * 7;
|
|
||||||
var y = d * 365.25;
|
|
||||||
/**
|
|
||||||
* Parse or format the given `val`.
|
|
||||||
*
|
|
||||||
* Options:
|
|
||||||
*
|
|
||||||
* - `long` verbose formatting [false]
|
|
||||||
*
|
|
||||||
* @param {String|Number} val
|
|
||||||
* @param {Object} [options]
|
|
||||||
* @throws {Error} throw an error if val is not a non-empty string or a number
|
|
||||||
* @return {String|Number}
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = function (val, options) {
|
|
||||||
options = options || {};
|
|
||||||
|
|
||||||
var type = _typeof(val);
|
|
||||||
|
|
||||||
if (type === 'string' && val.length > 0) {
|
|
||||||
return parse(val);
|
|
||||||
} else if (type === 'number' && isNaN(val) === false) {
|
|
||||||
return options.long ? fmtLong(val) : fmtShort(val);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val));
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* Parse the given `str` and return milliseconds.
|
|
||||||
*
|
|
||||||
* @param {String} str
|
|
||||||
* @return {Number}
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
function parse(str) {
|
|
||||||
str = String(str);
|
|
||||||
|
|
||||||
if (str.length > 100) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var match = /^((?:\d+)?\-?\d?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(str);
|
|
||||||
|
|
||||||
if (!match) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var n = parseFloat(match[1]);
|
|
||||||
var type = (match[2] || 'ms').toLowerCase();
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case 'years':
|
|
||||||
case 'year':
|
|
||||||
case 'yrs':
|
|
||||||
case 'yr':
|
|
||||||
case 'y':
|
|
||||||
return n * y;
|
|
||||||
|
|
||||||
case 'weeks':
|
|
||||||
case 'week':
|
|
||||||
case 'w':
|
|
||||||
return n * w;
|
|
||||||
|
|
||||||
case 'days':
|
|
||||||
case 'day':
|
|
||||||
case 'd':
|
|
||||||
return n * d;
|
|
||||||
|
|
||||||
case 'hours':
|
|
||||||
case 'hour':
|
|
||||||
case 'hrs':
|
|
||||||
case 'hr':
|
|
||||||
case 'h':
|
|
||||||
return n * h;
|
|
||||||
|
|
||||||
case 'minutes':
|
|
||||||
case 'minute':
|
|
||||||
case 'mins':
|
|
||||||
case 'min':
|
|
||||||
case 'm':
|
|
||||||
return n * m;
|
|
||||||
|
|
||||||
case 'seconds':
|
|
||||||
case 'second':
|
|
||||||
case 'secs':
|
|
||||||
case 'sec':
|
|
||||||
case 's':
|
|
||||||
return n * s;
|
|
||||||
|
|
||||||
case 'milliseconds':
|
|
||||||
case 'millisecond':
|
|
||||||
case 'msecs':
|
|
||||||
case 'msec':
|
|
||||||
case 'ms':
|
|
||||||
return n;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Short format for `ms`.
|
|
||||||
*
|
|
||||||
* @param {Number} ms
|
|
||||||
* @return {String}
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
function fmtShort(ms) {
|
|
||||||
var msAbs = Math.abs(ms);
|
|
||||||
|
|
||||||
if (msAbs >= d) {
|
|
||||||
return Math.round(ms / d) + 'd';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msAbs >= h) {
|
|
||||||
return Math.round(ms / h) + 'h';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msAbs >= m) {
|
|
||||||
return Math.round(ms / m) + 'm';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msAbs >= s) {
|
|
||||||
return Math.round(ms / s) + 's';
|
|
||||||
}
|
|
||||||
|
|
||||||
return ms + 'ms';
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Long format for `ms`.
|
|
||||||
*
|
|
||||||
* @param {Number} ms
|
|
||||||
* @return {String}
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
function fmtLong(ms) {
|
|
||||||
var msAbs = Math.abs(ms);
|
|
||||||
|
|
||||||
if (msAbs >= d) {
|
|
||||||
return plural(ms, msAbs, d, 'day');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msAbs >= h) {
|
|
||||||
return plural(ms, msAbs, h, 'hour');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msAbs >= m) {
|
|
||||||
return plural(ms, msAbs, m, 'minute');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msAbs >= s) {
|
|
||||||
return plural(ms, msAbs, s, 'second');
|
|
||||||
}
|
|
||||||
|
|
||||||
return ms + ' ms';
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Pluralization helper.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
function plural(ms, msAbs, n, name) {
|
|
||||||
var isPlural = msAbs >= n * 1.5;
|
|
||||||
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
|
||||||
}
|
|
||||||
}, {}],
|
|
||||||
2: [function (require, module, exports) {
|
|
||||||
// shim for using process in browser
|
|
||||||
var process = module.exports = {}; // cached from whatever global is present so that test runners that stub it
|
|
||||||
// don't break things. But we need to wrap it in a try catch in case it is
|
|
||||||
// wrapped in strict mode code which doesn't define any globals. It's inside a
|
|
||||||
// function because try/catches deoptimize in certain engines.
|
|
||||||
|
|
||||||
var cachedSetTimeout;
|
|
||||||
var cachedClearTimeout;
|
|
||||||
|
|
||||||
function defaultSetTimout() {
|
|
||||||
throw new Error('setTimeout has not been defined');
|
|
||||||
}
|
|
||||||
|
|
||||||
function defaultClearTimeout() {
|
|
||||||
throw new Error('clearTimeout has not been defined');
|
|
||||||
}
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
try {
|
|
||||||
if (typeof setTimeout === 'function') {
|
|
||||||
cachedSetTimeout = setTimeout;
|
|
||||||
} else {
|
|
||||||
cachedSetTimeout = defaultSetTimout;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
cachedSetTimeout = defaultSetTimout;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (typeof clearTimeout === 'function') {
|
|
||||||
cachedClearTimeout = clearTimeout;
|
|
||||||
} else {
|
|
||||||
cachedClearTimeout = defaultClearTimeout;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
cachedClearTimeout = defaultClearTimeout;
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
function runTimeout(fun) {
|
|
||||||
if (cachedSetTimeout === setTimeout) {
|
|
||||||
//normal enviroments in sane situations
|
|
||||||
return setTimeout(fun, 0);
|
|
||||||
} // if setTimeout wasn't available but was latter defined
|
|
||||||
|
|
||||||
|
|
||||||
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
|
||||||
cachedSetTimeout = setTimeout;
|
|
||||||
return setTimeout(fun, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// when when somebody has screwed with setTimeout but no I.E. maddness
|
|
||||||
return cachedSetTimeout(fun, 0);
|
|
||||||
} catch (e) {
|
|
||||||
try {
|
|
||||||
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
|
||||||
return cachedSetTimeout.call(null, fun, 0);
|
|
||||||
} catch (e) {
|
|
||||||
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
|
|
||||||
return cachedSetTimeout.call(this, fun, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function runClearTimeout(marker) {
|
|
||||||
if (cachedClearTimeout === clearTimeout) {
|
|
||||||
//normal enviroments in sane situations
|
|
||||||
return clearTimeout(marker);
|
|
||||||
} // if clearTimeout wasn't available but was latter defined
|
|
||||||
|
|
||||||
|
|
||||||
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
|
||||||
cachedClearTimeout = clearTimeout;
|
|
||||||
return clearTimeout(marker);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// when when somebody has screwed with setTimeout but no I.E. maddness
|
|
||||||
return cachedClearTimeout(marker);
|
|
||||||
} catch (e) {
|
|
||||||
try {
|
|
||||||
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
|
||||||
return cachedClearTimeout.call(null, marker);
|
|
||||||
} catch (e) {
|
|
||||||
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
|
|
||||||
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
|
|
||||||
return cachedClearTimeout.call(this, marker);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var queue = [];
|
|
||||||
var draining = false;
|
|
||||||
var currentQueue;
|
|
||||||
var queueIndex = -1;
|
|
||||||
|
|
||||||
function cleanUpNextTick() {
|
|
||||||
if (!draining || !currentQueue) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
draining = false;
|
|
||||||
|
|
||||||
if (currentQueue.length) {
|
|
||||||
queue = currentQueue.concat(queue);
|
|
||||||
} else {
|
|
||||||
queueIndex = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (queue.length) {
|
|
||||||
drainQueue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function drainQueue() {
|
|
||||||
if (draining) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var timeout = runTimeout(cleanUpNextTick);
|
|
||||||
draining = true;
|
|
||||||
var len = queue.length;
|
|
||||||
|
|
||||||
while (len) {
|
|
||||||
currentQueue = queue;
|
|
||||||
queue = [];
|
|
||||||
|
|
||||||
while (++queueIndex < len) {
|
|
||||||
if (currentQueue) {
|
|
||||||
currentQueue[queueIndex].run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
queueIndex = -1;
|
|
||||||
len = queue.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentQueue = null;
|
|
||||||
draining = false;
|
|
||||||
runClearTimeout(timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
process.nextTick = function (fun) {
|
|
||||||
var args = new Array(arguments.length - 1);
|
|
||||||
|
|
||||||
if (arguments.length > 1) {
|
|
||||||
for (var i = 1; i < arguments.length; i++) {
|
|
||||||
args[i - 1] = arguments[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
queue.push(new Item(fun, args));
|
|
||||||
|
|
||||||
if (queue.length === 1 && !draining) {
|
|
||||||
runTimeout(drainQueue);
|
|
||||||
}
|
|
||||||
}; // v8 likes predictible objects
|
|
||||||
|
|
||||||
|
|
||||||
function Item(fun, array) {
|
|
||||||
this.fun = fun;
|
|
||||||
this.array = array;
|
|
||||||
}
|
|
||||||
|
|
||||||
Item.prototype.run = function () {
|
|
||||||
this.fun.apply(null, this.array);
|
|
||||||
};
|
|
||||||
|
|
||||||
process.title = 'browser';
|
|
||||||
process.browser = true;
|
|
||||||
process.env = {};
|
|
||||||
process.argv = [];
|
|
||||||
process.version = ''; // empty string to avoid regexp issues
|
|
||||||
|
|
||||||
process.versions = {};
|
|
||||||
|
|
||||||
function noop() {}
|
|
||||||
|
|
||||||
process.on = noop;
|
|
||||||
process.addListener = noop;
|
|
||||||
process.once = noop;
|
|
||||||
process.off = noop;
|
|
||||||
process.removeListener = noop;
|
|
||||||
process.removeAllListeners = noop;
|
|
||||||
process.emit = noop;
|
|
||||||
process.prependListener = noop;
|
|
||||||
process.prependOnceListener = noop;
|
|
||||||
|
|
||||||
process.listeners = function (name) {
|
|
||||||
return [];
|
|
||||||
};
|
|
||||||
|
|
||||||
process.binding = function (name) {
|
|
||||||
throw new Error('process.binding is not supported');
|
|
||||||
};
|
|
||||||
|
|
||||||
process.cwd = function () {
|
|
||||||
return '/';
|
|
||||||
};
|
|
||||||
|
|
||||||
process.chdir = function (dir) {
|
|
||||||
throw new Error('process.chdir is not supported');
|
|
||||||
};
|
|
||||||
|
|
||||||
process.umask = function () {
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
}, {}],
|
|
||||||
3: [function (require, module, exports) {
|
|
||||||
/**
|
|
||||||
* This is the common logic for both the Node.js and web browser
|
|
||||||
* implementations of `debug()`.
|
|
||||||
*/
|
|
||||||
function setup(env) {
|
|
||||||
createDebug.debug = createDebug;
|
|
||||||
createDebug.default = createDebug;
|
|
||||||
createDebug.coerce = coerce;
|
|
||||||
createDebug.disable = disable;
|
|
||||||
createDebug.enable = enable;
|
|
||||||
createDebug.enabled = enabled;
|
|
||||||
createDebug.humanize = require('ms');
|
|
||||||
Object.keys(env).forEach(function (key) {
|
|
||||||
createDebug[key] = env[key];
|
|
||||||
});
|
|
||||||
/**
|
|
||||||
* Active `debug` instances.
|
|
||||||
*/
|
|
||||||
|
|
||||||
createDebug.instances = [];
|
|
||||||
/**
|
|
||||||
* The currently active debug mode names, and names to skip.
|
|
||||||
*/
|
|
||||||
|
|
||||||
createDebug.names = [];
|
|
||||||
createDebug.skips = [];
|
|
||||||
/**
|
|
||||||
* Map of special "%n" handling functions, for the debug "format" argument.
|
|
||||||
*
|
|
||||||
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
|
||||||
*/
|
|
||||||
|
|
||||||
createDebug.formatters = {};
|
|
||||||
/**
|
|
||||||
* Selects a color for a debug namespace
|
|
||||||
* @param {String} namespace The namespace string for the for the debug instance to be colored
|
|
||||||
* @return {Number|String} An ANSI color code for the given namespace
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
|
|
||||||
function selectColor(namespace) {
|
|
||||||
var hash = 0;
|
|
||||||
|
|
||||||
for (var i = 0; i < namespace.length; i++) {
|
|
||||||
hash = (hash << 5) - hash + namespace.charCodeAt(i);
|
|
||||||
hash |= 0; // Convert to 32bit integer
|
|
||||||
}
|
|
||||||
|
|
||||||
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
||||||
}
|
|
||||||
|
|
||||||
createDebug.selectColor = selectColor;
|
|
||||||
/**
|
|
||||||
* Create a debugger with the given `namespace`.
|
|
||||||
*
|
|
||||||
* @param {String} namespace
|
|
||||||
* @return {Function}
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
function createDebug(namespace) {
|
|
||||||
var prevTime;
|
|
||||||
|
|
||||||
function debug() {
|
|
||||||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
||||||
args[_key] = arguments[_key];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disabled?
|
|
||||||
if (!debug.enabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var self = debug; // Set `diff` timestamp
|
|
||||||
|
|
||||||
var curr = Number(new Date());
|
|
||||||
var ms = curr - (prevTime || curr);
|
|
||||||
self.diff = ms;
|
|
||||||
self.prev = prevTime;
|
|
||||||
self.curr = curr;
|
|
||||||
prevTime = curr;
|
|
||||||
args[0] = createDebug.coerce(args[0]);
|
|
||||||
|
|
||||||
if (typeof args[0] !== 'string') {
|
|
||||||
// Anything else let's inspect with %O
|
|
||||||
args.unshift('%O');
|
|
||||||
} // Apply any `formatters` transformations
|
|
||||||
|
|
||||||
|
|
||||||
var index = 0;
|
|
||||||
args[0] = args[0].replace(/%([a-zA-Z%])/g, function (match, format) {
|
|
||||||
// If we encounter an escaped % then don't increase the array index
|
|
||||||
if (match === '%%') {
|
|
||||||
return match;
|
|
||||||
}
|
|
||||||
|
|
||||||
index++;
|
|
||||||
var formatter = createDebug.formatters[format];
|
|
||||||
|
|
||||||
if (typeof formatter === 'function') {
|
|
||||||
var val = args[index];
|
|
||||||
match = formatter.call(self, val); // Now we need to remove `args[index]` since it's inlined in the `format`
|
|
||||||
|
|
||||||
args.splice(index, 1);
|
|
||||||
index--;
|
|
||||||
}
|
|
||||||
|
|
||||||
return match;
|
|
||||||
}); // Apply env-specific formatting (colors, etc.)
|
|
||||||
|
|
||||||
createDebug.formatArgs.call(self, args);
|
|
||||||
var logFn = self.log || createDebug.log;
|
|
||||||
logFn.apply(self, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
debug.namespace = namespace;
|
|
||||||
debug.enabled = createDebug.enabled(namespace);
|
|
||||||
debug.useColors = createDebug.useColors();
|
|
||||||
debug.color = selectColor(namespace);
|
|
||||||
debug.destroy = destroy;
|
|
||||||
debug.extend = extend; // Debug.formatArgs = formatArgs;
|
|
||||||
// debug.rawLog = rawLog;
|
|
||||||
// env-specific initialization logic for debug instances
|
|
||||||
|
|
||||||
if (typeof createDebug.init === 'function') {
|
|
||||||
createDebug.init(debug);
|
|
||||||
}
|
|
||||||
|
|
||||||
createDebug.instances.push(debug);
|
|
||||||
return debug;
|
|
||||||
}
|
|
||||||
|
|
||||||
function destroy() {
|
|
||||||
var index = createDebug.instances.indexOf(this);
|
|
||||||
|
|
||||||
if (index !== -1) {
|
|
||||||
createDebug.instances.splice(index, 1);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function extend(namespace, delimiter) {
|
|
||||||
var newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
|
||||||
newDebug.log = this.log;
|
|
||||||
return newDebug;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Enables a debug mode by namespaces. This can include modes
|
|
||||||
* separated by a colon and wildcards.
|
|
||||||
*
|
|
||||||
* @param {String} namespaces
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
function enable(namespaces) {
|
|
||||||
createDebug.save(namespaces);
|
|
||||||
createDebug.names = [];
|
|
||||||
createDebug.skips = [];
|
|
||||||
var i;
|
|
||||||
var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
|
||||||
var len = split.length;
|
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
|
||||||
if (!split[i]) {
|
|
||||||
// ignore empty strings
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespaces = split[i].replace(/\*/g, '.*?');
|
|
||||||
|
|
||||||
if (namespaces[0] === '-') {
|
|
||||||
createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
|
||||||
} else {
|
|
||||||
createDebug.names.push(new RegExp('^' + namespaces + '$'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < createDebug.instances.length; i++) {
|
|
||||||
var instance = createDebug.instances[i];
|
|
||||||
instance.enabled = createDebug.enabled(instance.namespace);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Disable debug output.
|
|
||||||
*
|
|
||||||
* @return {String} namespaces
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
function disable() {
|
|
||||||
var namespaces = [].concat(_toConsumableArray(createDebug.names.map(toNamespace)), _toConsumableArray(createDebug.skips.map(toNamespace).map(function (namespace) {
|
|
||||||
return '-' + namespace;
|
|
||||||
}))).join(',');
|
|
||||||
createDebug.enable('');
|
|
||||||
return namespaces;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Returns true if the given mode name is enabled, false otherwise.
|
|
||||||
*
|
|
||||||
* @param {String} name
|
|
||||||
* @return {Boolean}
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
function enabled(name) {
|
|
||||||
if (name[name.length - 1] === '*') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var i;
|
|
||||||
var len;
|
|
||||||
|
|
||||||
for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
|
||||||
if (createDebug.skips[i].test(name)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0, len = createDebug.names.length; i < len; i++) {
|
|
||||||
if (createDebug.names[i].test(name)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Convert regexp to namespace
|
|
||||||
*
|
|
||||||
* @param {RegExp} regxep
|
|
||||||
* @return {String} namespace
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
function toNamespace(regexp) {
|
|
||||||
return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, '*');
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Coerce `val`.
|
|
||||||
*
|
|
||||||
* @param {Mixed} val
|
|
||||||
* @return {Mixed}
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
function coerce(val) {
|
|
||||||
if (val instanceof Error) {
|
|
||||||
return val.stack || val.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
createDebug.enable(createDebug.load());
|
|
||||||
return createDebug;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = setup;
|
|
||||||
}, {
|
|
||||||
"ms": 1
|
|
||||||
}],
|
|
||||||
4: [function (require, module, exports) {
|
|
||||||
(function (process) {
|
|
||||||
/* eslint-env browser */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the web browser implementation of `debug()`.
|
|
||||||
*/
|
|
||||||
exports.log = log;
|
|
||||||
exports.formatArgs = formatArgs;
|
|
||||||
exports.save = save;
|
|
||||||
exports.load = load;
|
|
||||||
exports.useColors = useColors;
|
|
||||||
exports.storage = localstorage();
|
|
||||||
/**
|
|
||||||
* Colors.
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.colors = ['#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC', '#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF', '#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC', '#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF', '#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC', '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033', '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366', '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933', '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC', '#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF', '#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33'];
|
|
||||||
/**
|
|
||||||
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
|
||||||
* and the Firebug extension (any Firefox version) are known
|
|
||||||
* to support "%c" CSS customizations.
|
|
||||||
*
|
|
||||||
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
|
||||||
*/
|
|
||||||
// eslint-disable-next-line complexity
|
|
||||||
|
|
||||||
function useColors() {
|
|
||||||
// NB: In an Electron preload script, document will be defined but not fully
|
|
||||||
// initialized. Since we know we're in Chrome, we'll just detect this case
|
|
||||||
// explicitly
|
|
||||||
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
|
||||||
return true;
|
|
||||||
} // Internet Explorer and Edge do not support colors.
|
|
||||||
|
|
||||||
|
|
||||||
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
|
||||||
return false;
|
|
||||||
} // Is webkit? http://stackoverflow.com/a/16459606/376773
|
|
||||||
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
|
||||||
|
|
||||||
|
|
||||||
return typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
|
|
||||||
typeof window !== 'undefined' && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
|
||||||
typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
|
|
||||||
typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Colorize log arguments if enabled.
|
|
||||||
*
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
function formatArgs(args) {
|
|
||||||
args[0] = (this.useColors ? '%c' : '') + this.namespace + (this.useColors ? ' %c' : ' ') + args[0] + (this.useColors ? '%c ' : ' ') + '+' + module.exports.humanize(this.diff);
|
|
||||||
|
|
||||||
if (!this.useColors) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var c = 'color: ' + this.color;
|
|
||||||
args.splice(1, 0, c, 'color: inherit'); // The final "%c" is somewhat tricky, because there could be other
|
|
||||||
// arguments passed either before or after the %c, so we need to
|
|
||||||
// figure out the correct index to insert the CSS into
|
|
||||||
|
|
||||||
var index = 0;
|
|
||||||
var lastC = 0;
|
|
||||||
args[0].replace(/%[a-zA-Z%]/g, function (match) {
|
|
||||||
if (match === '%%') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
index++;
|
|
||||||
|
|
||||||
if (match === '%c') {
|
|
||||||
// We only are interested in the *last* %c
|
|
||||||
// (the user may have provided their own)
|
|
||||||
lastC = index;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
args.splice(lastC, 0, c);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Invokes `console.log()` when available.
|
|
||||||
* No-op when `console.log` is not a "function".
|
|
||||||
*
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
function log() {
|
|
||||||
var _console;
|
|
||||||
|
|
||||||
// This hackery is required for IE8/9, where
|
|
||||||
// the `console.log` function doesn't have 'apply'
|
|
||||||
return (typeof console === "undefined" ? "undefined" : _typeof(console)) === 'object' && console.log && (_console = console).log.apply(_console, arguments);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Save `namespaces`.
|
|
||||||
*
|
|
||||||
* @param {String} namespaces
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
function save(namespaces) {
|
|
||||||
try {
|
|
||||||
if (namespaces) {
|
|
||||||
exports.storage.setItem('debug', namespaces);
|
|
||||||
} else {
|
|
||||||
exports.storage.removeItem('debug');
|
|
||||||
}
|
|
||||||
} catch (error) {// Swallow
|
|
||||||
// XXX (@Qix-) should we be logging these?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Load `namespaces`.
|
|
||||||
*
|
|
||||||
* @return {String} returns the previously persisted debug modes
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
function load() {
|
|
||||||
var r;
|
|
||||||
|
|
||||||
try {
|
|
||||||
r = exports.storage.getItem('debug');
|
|
||||||
} catch (error) {} // Swallow
|
|
||||||
// XXX (@Qix-) should we be logging these?
|
|
||||||
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
|
||||||
|
|
||||||
|
|
||||||
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
|
||||||
r = process.env.DEBUG;
|
|
||||||
}
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Localstorage attempts to return the localstorage.
|
|
||||||
*
|
|
||||||
* This is necessary because safari throws
|
|
||||||
* when a user disables cookies/localstorage
|
|
||||||
* and you attempt to access it.
|
|
||||||
*
|
|
||||||
* @return {LocalStorage}
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
function localstorage() {
|
|
||||||
try {
|
|
||||||
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
|
|
||||||
// The Browser also has localStorage in the global context.
|
|
||||||
return localStorage;
|
|
||||||
} catch (error) {// Swallow
|
|
||||||
// XXX (@Qix-) should we be logging these?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = require('./common')(exports);
|
|
||||||
var formatters = module.exports.formatters;
|
|
||||||
/**
|
|
||||||
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
|
||||||
*/
|
|
||||||
|
|
||||||
formatters.j = function (v) {
|
|
||||||
try {
|
|
||||||
return JSON.stringify(v);
|
|
||||||
} catch (error) {
|
|
||||||
return '[UnexpectedJSONParseError]: ' + error.message;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}).call(this, require('_process'));
|
|
||||||
}, {
|
|
||||||
"./common": 3,
|
|
||||||
"_process": 2
|
|
||||||
}]
|
|
||||||
}, {}, [4])(4);
|
|
||||||
});
|
|
||||||
-102
@@ -1,102 +0,0 @@
|
|||||||
{
|
|
||||||
"_from": "debug@^4.0.1",
|
|
||||||
"_id": "debug@4.1.1",
|
|
||||||
"_inBundle": false,
|
|
||||||
"_integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
|
|
||||||
"_location": "/debug",
|
|
||||||
"_phantomChildren": {},
|
|
||||||
"_requested": {
|
|
||||||
"type": "range",
|
|
||||||
"registry": true,
|
|
||||||
"raw": "debug@^4.0.1",
|
|
||||||
"name": "debug",
|
|
||||||
"escapedName": "debug",
|
|
||||||
"rawSpec": "^4.0.1",
|
|
||||||
"saveSpec": null,
|
|
||||||
"fetchSpec": "^4.0.1"
|
|
||||||
},
|
|
||||||
"_requiredBy": [
|
|
||||||
"/simple-git"
|
|
||||||
],
|
|
||||||
"_resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
|
|
||||||
"_shasum": "3b72260255109c6b589cee050f1d516139664791",
|
|
||||||
"_spec": "debug@^4.0.1",
|
|
||||||
"_where": "C:\\Users\\lzy\\Documents\\Source\\OpportunityLiu\\github-action-setup-xmake\\node_modules\\simple-git",
|
|
||||||
"author": {
|
|
||||||
"name": "TJ Holowaychuk",
|
|
||||||
"email": "tj@vision-media.ca"
|
|
||||||
},
|
|
||||||
"browser": "./src/browser.js",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/visionmedia/debug/issues"
|
|
||||||
},
|
|
||||||
"bundleDependencies": false,
|
|
||||||
"contributors": [
|
|
||||||
{
|
|
||||||
"name": "Nathan Rajlich",
|
|
||||||
"email": "nathan@tootallnate.net",
|
|
||||||
"url": "http://n8.io"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Andrew Rhyne",
|
|
||||||
"email": "rhyneandrew@gmail.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"dependencies": {
|
|
||||||
"ms": "^2.1.1"
|
|
||||||
},
|
|
||||||
"deprecated": false,
|
|
||||||
"description": "small debugging utility",
|
|
||||||
"devDependencies": {
|
|
||||||
"@babel/cli": "^7.0.0",
|
|
||||||
"@babel/core": "^7.0.0",
|
|
||||||
"@babel/preset-env": "^7.0.0",
|
|
||||||
"browserify": "14.4.0",
|
|
||||||
"chai": "^3.5.0",
|
|
||||||
"concurrently": "^3.1.0",
|
|
||||||
"coveralls": "^3.0.2",
|
|
||||||
"istanbul": "^0.4.5",
|
|
||||||
"karma": "^3.0.0",
|
|
||||||
"karma-chai": "^0.1.0",
|
|
||||||
"karma-mocha": "^1.3.0",
|
|
||||||
"karma-phantomjs-launcher": "^1.0.2",
|
|
||||||
"mocha": "^5.2.0",
|
|
||||||
"mocha-lcov-reporter": "^1.2.0",
|
|
||||||
"rimraf": "^2.5.4",
|
|
||||||
"xo": "^0.23.0"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"src",
|
|
||||||
"dist/debug.js",
|
|
||||||
"LICENSE",
|
|
||||||
"README.md"
|
|
||||||
],
|
|
||||||
"homepage": "https://github.com/visionmedia/debug#readme",
|
|
||||||
"keywords": [
|
|
||||||
"debug",
|
|
||||||
"log",
|
|
||||||
"debugger"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"main": "./src/index.js",
|
|
||||||
"name": "debug",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git://github.com/visionmedia/debug.git"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"build": "npm run build:debug && npm run build:test",
|
|
||||||
"build:debug": "babel -o dist/debug.js dist/debug.es6.js > dist/debug.js",
|
|
||||||
"build:test": "babel -d dist test.js",
|
|
||||||
"clean": "rimraf dist coverage",
|
|
||||||
"lint": "xo",
|
|
||||||
"prebuild:debug": "mkdir -p dist && browserify --standalone debug -o dist/debug.es6.js .",
|
|
||||||
"pretest:browser": "npm run build",
|
|
||||||
"test": "npm run test:node && npm run test:browser",
|
|
||||||
"test:browser": "karma start --single-run",
|
|
||||||
"test:coverage": "cat ./coverage/lcov.info | coveralls",
|
|
||||||
"test:node": "istanbul cover _mocha -- test.js"
|
|
||||||
},
|
|
||||||
"unpkg": "./dist/debug.js",
|
|
||||||
"version": "4.1.1"
|
|
||||||
}
|
|
||||||
-264
@@ -1,264 +0,0 @@
|
|||||||
/* eslint-env browser */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the web browser implementation of `debug()`.
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.log = log;
|
|
||||||
exports.formatArgs = formatArgs;
|
|
||||||
exports.save = save;
|
|
||||||
exports.load = load;
|
|
||||||
exports.useColors = useColors;
|
|
||||||
exports.storage = localstorage();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Colors.
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.colors = [
|
|
||||||
'#0000CC',
|
|
||||||
'#0000FF',
|
|
||||||
'#0033CC',
|
|
||||||
'#0033FF',
|
|
||||||
'#0066CC',
|
|
||||||
'#0066FF',
|
|
||||||
'#0099CC',
|
|
||||||
'#0099FF',
|
|
||||||
'#00CC00',
|
|
||||||
'#00CC33',
|
|
||||||
'#00CC66',
|
|
||||||
'#00CC99',
|
|
||||||
'#00CCCC',
|
|
||||||
'#00CCFF',
|
|
||||||
'#3300CC',
|
|
||||||
'#3300FF',
|
|
||||||
'#3333CC',
|
|
||||||
'#3333FF',
|
|
||||||
'#3366CC',
|
|
||||||
'#3366FF',
|
|
||||||
'#3399CC',
|
|
||||||
'#3399FF',
|
|
||||||
'#33CC00',
|
|
||||||
'#33CC33',
|
|
||||||
'#33CC66',
|
|
||||||
'#33CC99',
|
|
||||||
'#33CCCC',
|
|
||||||
'#33CCFF',
|
|
||||||
'#6600CC',
|
|
||||||
'#6600FF',
|
|
||||||
'#6633CC',
|
|
||||||
'#6633FF',
|
|
||||||
'#66CC00',
|
|
||||||
'#66CC33',
|
|
||||||
'#9900CC',
|
|
||||||
'#9900FF',
|
|
||||||
'#9933CC',
|
|
||||||
'#9933FF',
|
|
||||||
'#99CC00',
|
|
||||||
'#99CC33',
|
|
||||||
'#CC0000',
|
|
||||||
'#CC0033',
|
|
||||||
'#CC0066',
|
|
||||||
'#CC0099',
|
|
||||||
'#CC00CC',
|
|
||||||
'#CC00FF',
|
|
||||||
'#CC3300',
|
|
||||||
'#CC3333',
|
|
||||||
'#CC3366',
|
|
||||||
'#CC3399',
|
|
||||||
'#CC33CC',
|
|
||||||
'#CC33FF',
|
|
||||||
'#CC6600',
|
|
||||||
'#CC6633',
|
|
||||||
'#CC9900',
|
|
||||||
'#CC9933',
|
|
||||||
'#CCCC00',
|
|
||||||
'#CCCC33',
|
|
||||||
'#FF0000',
|
|
||||||
'#FF0033',
|
|
||||||
'#FF0066',
|
|
||||||
'#FF0099',
|
|
||||||
'#FF00CC',
|
|
||||||
'#FF00FF',
|
|
||||||
'#FF3300',
|
|
||||||
'#FF3333',
|
|
||||||
'#FF3366',
|
|
||||||
'#FF3399',
|
|
||||||
'#FF33CC',
|
|
||||||
'#FF33FF',
|
|
||||||
'#FF6600',
|
|
||||||
'#FF6633',
|
|
||||||
'#FF9900',
|
|
||||||
'#FF9933',
|
|
||||||
'#FFCC00',
|
|
||||||
'#FFCC33'
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
|
||||||
* and the Firebug extension (any Firefox version) are known
|
|
||||||
* to support "%c" CSS customizations.
|
|
||||||
*
|
|
||||||
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
|
||||||
*/
|
|
||||||
|
|
||||||
// eslint-disable-next-line complexity
|
|
||||||
function useColors() {
|
|
||||||
// NB: In an Electron preload script, document will be defined but not fully
|
|
||||||
// initialized. Since we know we're in Chrome, we'll just detect this case
|
|
||||||
// explicitly
|
|
||||||
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Internet Explorer and Edge do not support colors.
|
|
||||||
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Is webkit? http://stackoverflow.com/a/16459606/376773
|
|
||||||
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
|
||||||
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
|
||||||
// Is firebug? http://stackoverflow.com/a/398120/376773
|
|
||||||
(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
|
||||||
// Is firefox >= v31?
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
|
||||||
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
|
|
||||||
// Double check webkit in userAgent just in case we are in a worker
|
|
||||||
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Colorize log arguments if enabled.
|
|
||||||
*
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
function formatArgs(args) {
|
|
||||||
args[0] = (this.useColors ? '%c' : '') +
|
|
||||||
this.namespace +
|
|
||||||
(this.useColors ? ' %c' : ' ') +
|
|
||||||
args[0] +
|
|
||||||
(this.useColors ? '%c ' : ' ') +
|
|
||||||
'+' + module.exports.humanize(this.diff);
|
|
||||||
|
|
||||||
if (!this.useColors) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const c = 'color: ' + this.color;
|
|
||||||
args.splice(1, 0, c, 'color: inherit');
|
|
||||||
|
|
||||||
// The final "%c" is somewhat tricky, because there could be other
|
|
||||||
// arguments passed either before or after the %c, so we need to
|
|
||||||
// figure out the correct index to insert the CSS into
|
|
||||||
let index = 0;
|
|
||||||
let lastC = 0;
|
|
||||||
args[0].replace(/%[a-zA-Z%]/g, match => {
|
|
||||||
if (match === '%%') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
index++;
|
|
||||||
if (match === '%c') {
|
|
||||||
// We only are interested in the *last* %c
|
|
||||||
// (the user may have provided their own)
|
|
||||||
lastC = index;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
args.splice(lastC, 0, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Invokes `console.log()` when available.
|
|
||||||
* No-op when `console.log` is not a "function".
|
|
||||||
*
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
function log(...args) {
|
|
||||||
// This hackery is required for IE8/9, where
|
|
||||||
// the `console.log` function doesn't have 'apply'
|
|
||||||
return typeof console === 'object' &&
|
|
||||||
console.log &&
|
|
||||||
console.log(...args);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save `namespaces`.
|
|
||||||
*
|
|
||||||
* @param {String} namespaces
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
function save(namespaces) {
|
|
||||||
try {
|
|
||||||
if (namespaces) {
|
|
||||||
exports.storage.setItem('debug', namespaces);
|
|
||||||
} else {
|
|
||||||
exports.storage.removeItem('debug');
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
// Swallow
|
|
||||||
// XXX (@Qix-) should we be logging these?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load `namespaces`.
|
|
||||||
*
|
|
||||||
* @return {String} returns the previously persisted debug modes
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
function load() {
|
|
||||||
let r;
|
|
||||||
try {
|
|
||||||
r = exports.storage.getItem('debug');
|
|
||||||
} catch (error) {
|
|
||||||
// Swallow
|
|
||||||
// XXX (@Qix-) should we be logging these?
|
|
||||||
}
|
|
||||||
|
|
||||||
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
|
||||||
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
|
||||||
r = process.env.DEBUG;
|
|
||||||
}
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Localstorage attempts to return the localstorage.
|
|
||||||
*
|
|
||||||
* This is necessary because safari throws
|
|
||||||
* when a user disables cookies/localstorage
|
|
||||||
* and you attempt to access it.
|
|
||||||
*
|
|
||||||
* @return {LocalStorage}
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
|
|
||||||
function localstorage() {
|
|
||||||
try {
|
|
||||||
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
|
|
||||||
// The Browser also has localStorage in the global context.
|
|
||||||
return localStorage;
|
|
||||||
} catch (error) {
|
|
||||||
// Swallow
|
|
||||||
// XXX (@Qix-) should we be logging these?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = require('./common')(exports);
|
|
||||||
|
|
||||||
const {formatters} = module.exports;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
|
||||||
*/
|
|
||||||
|
|
||||||
formatters.j = function (v) {
|
|
||||||
try {
|
|
||||||
return JSON.stringify(v);
|
|
||||||
} catch (error) {
|
|
||||||
return '[UnexpectedJSONParseError]: ' + error.message;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
-266
@@ -1,266 +0,0 @@
|
|||||||
|
|
||||||
/**
|
|
||||||
* This is the common logic for both the Node.js and web browser
|
|
||||||
* implementations of `debug()`.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function setup(env) {
|
|
||||||
createDebug.debug = createDebug;
|
|
||||||
createDebug.default = createDebug;
|
|
||||||
createDebug.coerce = coerce;
|
|
||||||
createDebug.disable = disable;
|
|
||||||
createDebug.enable = enable;
|
|
||||||
createDebug.enabled = enabled;
|
|
||||||
createDebug.humanize = require('ms');
|
|
||||||
|
|
||||||
Object.keys(env).forEach(key => {
|
|
||||||
createDebug[key] = env[key];
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Active `debug` instances.
|
|
||||||
*/
|
|
||||||
createDebug.instances = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The currently active debug mode names, and names to skip.
|
|
||||||
*/
|
|
||||||
|
|
||||||
createDebug.names = [];
|
|
||||||
createDebug.skips = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map of special "%n" handling functions, for the debug "format" argument.
|
|
||||||
*
|
|
||||||
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
|
||||||
*/
|
|
||||||
createDebug.formatters = {};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Selects a color for a debug namespace
|
|
||||||
* @param {String} namespace The namespace string for the for the debug instance to be colored
|
|
||||||
* @return {Number|String} An ANSI color code for the given namespace
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
function selectColor(namespace) {
|
|
||||||
let hash = 0;
|
|
||||||
|
|
||||||
for (let i = 0; i < namespace.length; i++) {
|
|
||||||
hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
|
|
||||||
hash |= 0; // Convert to 32bit integer
|
|
||||||
}
|
|
||||||
|
|
||||||
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
||||||
}
|
|
||||||
createDebug.selectColor = selectColor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a debugger with the given `namespace`.
|
|
||||||
*
|
|
||||||
* @param {String} namespace
|
|
||||||
* @return {Function}
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
function createDebug(namespace) {
|
|
||||||
let prevTime;
|
|
||||||
|
|
||||||
function debug(...args) {
|
|
||||||
// Disabled?
|
|
||||||
if (!debug.enabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const self = debug;
|
|
||||||
|
|
||||||
// Set `diff` timestamp
|
|
||||||
const curr = Number(new Date());
|
|
||||||
const ms = curr - (prevTime || curr);
|
|
||||||
self.diff = ms;
|
|
||||||
self.prev = prevTime;
|
|
||||||
self.curr = curr;
|
|
||||||
prevTime = curr;
|
|
||||||
|
|
||||||
args[0] = createDebug.coerce(args[0]);
|
|
||||||
|
|
||||||
if (typeof args[0] !== 'string') {
|
|
||||||
// Anything else let's inspect with %O
|
|
||||||
args.unshift('%O');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply any `formatters` transformations
|
|
||||||
let index = 0;
|
|
||||||
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
|
||||||
// If we encounter an escaped % then don't increase the array index
|
|
||||||
if (match === '%%') {
|
|
||||||
return match;
|
|
||||||
}
|
|
||||||
index++;
|
|
||||||
const formatter = createDebug.formatters[format];
|
|
||||||
if (typeof formatter === 'function') {
|
|
||||||
const val = args[index];
|
|
||||||
match = formatter.call(self, val);
|
|
||||||
|
|
||||||
// Now we need to remove `args[index]` since it's inlined in the `format`
|
|
||||||
args.splice(index, 1);
|
|
||||||
index--;
|
|
||||||
}
|
|
||||||
return match;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Apply env-specific formatting (colors, etc.)
|
|
||||||
createDebug.formatArgs.call(self, args);
|
|
||||||
|
|
||||||
const logFn = self.log || createDebug.log;
|
|
||||||
logFn.apply(self, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
debug.namespace = namespace;
|
|
||||||
debug.enabled = createDebug.enabled(namespace);
|
|
||||||
debug.useColors = createDebug.useColors();
|
|
||||||
debug.color = selectColor(namespace);
|
|
||||||
debug.destroy = destroy;
|
|
||||||
debug.extend = extend;
|
|
||||||
// Debug.formatArgs = formatArgs;
|
|
||||||
// debug.rawLog = rawLog;
|
|
||||||
|
|
||||||
// env-specific initialization logic for debug instances
|
|
||||||
if (typeof createDebug.init === 'function') {
|
|
||||||
createDebug.init(debug);
|
|
||||||
}
|
|
||||||
|
|
||||||
createDebug.instances.push(debug);
|
|
||||||
|
|
||||||
return debug;
|
|
||||||
}
|
|
||||||
|
|
||||||
function destroy() {
|
|
||||||
const index = createDebug.instances.indexOf(this);
|
|
||||||
if (index !== -1) {
|
|
||||||
createDebug.instances.splice(index, 1);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function extend(namespace, delimiter) {
|
|
||||||
const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
|
||||||
newDebug.log = this.log;
|
|
||||||
return newDebug;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables a debug mode by namespaces. This can include modes
|
|
||||||
* separated by a colon and wildcards.
|
|
||||||
*
|
|
||||||
* @param {String} namespaces
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
function enable(namespaces) {
|
|
||||||
createDebug.save(namespaces);
|
|
||||||
|
|
||||||
createDebug.names = [];
|
|
||||||
createDebug.skips = [];
|
|
||||||
|
|
||||||
let i;
|
|
||||||
const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
|
||||||
const len = split.length;
|
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
|
||||||
if (!split[i]) {
|
|
||||||
// ignore empty strings
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespaces = split[i].replace(/\*/g, '.*?');
|
|
||||||
|
|
||||||
if (namespaces[0] === '-') {
|
|
||||||
createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
|
||||||
} else {
|
|
||||||
createDebug.names.push(new RegExp('^' + namespaces + '$'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < createDebug.instances.length; i++) {
|
|
||||||
const instance = createDebug.instances[i];
|
|
||||||
instance.enabled = createDebug.enabled(instance.namespace);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disable debug output.
|
|
||||||
*
|
|
||||||
* @return {String} namespaces
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
function disable() {
|
|
||||||
const namespaces = [
|
|
||||||
...createDebug.names.map(toNamespace),
|
|
||||||
...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
|
|
||||||
].join(',');
|
|
||||||
createDebug.enable('');
|
|
||||||
return namespaces;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the given mode name is enabled, false otherwise.
|
|
||||||
*
|
|
||||||
* @param {String} name
|
|
||||||
* @return {Boolean}
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
function enabled(name) {
|
|
||||||
if (name[name.length - 1] === '*') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
let i;
|
|
||||||
let len;
|
|
||||||
|
|
||||||
for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
|
||||||
if (createDebug.skips[i].test(name)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0, len = createDebug.names.length; i < len; i++) {
|
|
||||||
if (createDebug.names[i].test(name)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert regexp to namespace
|
|
||||||
*
|
|
||||||
* @param {RegExp} regxep
|
|
||||||
* @return {String} namespace
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
function toNamespace(regexp) {
|
|
||||||
return regexp.toString()
|
|
||||||
.substring(2, regexp.toString().length - 2)
|
|
||||||
.replace(/\.\*\?$/, '*');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Coerce `val`.
|
|
||||||
*
|
|
||||||
* @param {Mixed} val
|
|
||||||
* @return {Mixed}
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
function coerce(val) {
|
|
||||||
if (val instanceof Error) {
|
|
||||||
return val.stack || val.message;
|
|
||||||
}
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
createDebug.enable(createDebug.load());
|
|
||||||
|
|
||||||
return createDebug;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = setup;
|
|
||||||
-10
@@ -1,10 +0,0 @@
|
|||||||
/**
|
|
||||||
* Detect Electron renderer / nwjs process, which is node, but we should
|
|
||||||
* treat as a browser.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
|
|
||||||
module.exports = require('./browser.js');
|
|
||||||
} else {
|
|
||||||
module.exports = require('./node.js');
|
|
||||||
}
|
|
||||||
-257
@@ -1,257 +0,0 @@
|
|||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const tty = require('tty');
|
|
||||||
const util = require('util');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the Node.js implementation of `debug()`.
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.init = init;
|
|
||||||
exports.log = log;
|
|
||||||
exports.formatArgs = formatArgs;
|
|
||||||
exports.save = save;
|
|
||||||
exports.load = load;
|
|
||||||
exports.useColors = useColors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Colors.
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.colors = [6, 2, 3, 4, 5, 1];
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
|
|
||||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
||||||
const supportsColor = require('supports-color');
|
|
||||||
|
|
||||||
if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
|
|
||||||
exports.colors = [
|
|
||||||
20,
|
|
||||||
21,
|
|
||||||
26,
|
|
||||||
27,
|
|
||||||
32,
|
|
||||||
33,
|
|
||||||
38,
|
|
||||||
39,
|
|
||||||
40,
|
|
||||||
41,
|
|
||||||
42,
|
|
||||||
43,
|
|
||||||
44,
|
|
||||||
45,
|
|
||||||
56,
|
|
||||||
57,
|
|
||||||
62,
|
|
||||||
63,
|
|
||||||
68,
|
|
||||||
69,
|
|
||||||
74,
|
|
||||||
75,
|
|
||||||
76,
|
|
||||||
77,
|
|
||||||
78,
|
|
||||||
79,
|
|
||||||
80,
|
|
||||||
81,
|
|
||||||
92,
|
|
||||||
93,
|
|
||||||
98,
|
|
||||||
99,
|
|
||||||
112,
|
|
||||||
113,
|
|
||||||
128,
|
|
||||||
129,
|
|
||||||
134,
|
|
||||||
135,
|
|
||||||
148,
|
|
||||||
149,
|
|
||||||
160,
|
|
||||||
161,
|
|
||||||
162,
|
|
||||||
163,
|
|
||||||
164,
|
|
||||||
165,
|
|
||||||
166,
|
|
||||||
167,
|
|
||||||
168,
|
|
||||||
169,
|
|
||||||
170,
|
|
||||||
171,
|
|
||||||
172,
|
|
||||||
173,
|
|
||||||
178,
|
|
||||||
179,
|
|
||||||
184,
|
|
||||||
185,
|
|
||||||
196,
|
|
||||||
197,
|
|
||||||
198,
|
|
||||||
199,
|
|
||||||
200,
|
|
||||||
201,
|
|
||||||
202,
|
|
||||||
203,
|
|
||||||
204,
|
|
||||||
205,
|
|
||||||
206,
|
|
||||||
207,
|
|
||||||
208,
|
|
||||||
209,
|
|
||||||
214,
|
|
||||||
215,
|
|
||||||
220,
|
|
||||||
221
|
|
||||||
];
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
// Swallow - we only care if `supports-color` is available; it doesn't have to be.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build up the default `inspectOpts` object from the environment variables.
|
|
||||||
*
|
|
||||||
* $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.inspectOpts = Object.keys(process.env).filter(key => {
|
|
||||||
return /^debug_/i.test(key);
|
|
||||||
}).reduce((obj, key) => {
|
|
||||||
// Camel-case
|
|
||||||
const prop = key
|
|
||||||
.substring(6)
|
|
||||||
.toLowerCase()
|
|
||||||
.replace(/_([a-z])/g, (_, k) => {
|
|
||||||
return k.toUpperCase();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Coerce string value into JS value
|
|
||||||
let val = process.env[key];
|
|
||||||
if (/^(yes|on|true|enabled)$/i.test(val)) {
|
|
||||||
val = true;
|
|
||||||
} else if (/^(no|off|false|disabled)$/i.test(val)) {
|
|
||||||
val = false;
|
|
||||||
} else if (val === 'null') {
|
|
||||||
val = null;
|
|
||||||
} else {
|
|
||||||
val = Number(val);
|
|
||||||
}
|
|
||||||
|
|
||||||
obj[prop] = val;
|
|
||||||
return obj;
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is stdout a TTY? Colored output is enabled when `true`.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function useColors() {
|
|
||||||
return 'colors' in exports.inspectOpts ?
|
|
||||||
Boolean(exports.inspectOpts.colors) :
|
|
||||||
tty.isatty(process.stderr.fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds ANSI color escape codes if enabled.
|
|
||||||
*
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
function formatArgs(args) {
|
|
||||||
const {namespace: name, useColors} = this;
|
|
||||||
|
|
||||||
if (useColors) {
|
|
||||||
const c = this.color;
|
|
||||||
const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
|
|
||||||
const prefix = ` ${colorCode};1m${name} \u001B[0m`;
|
|
||||||
|
|
||||||
args[0] = prefix + args[0].split('\n').join('\n' + prefix);
|
|
||||||
args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
|
|
||||||
} else {
|
|
||||||
args[0] = getDate() + name + ' ' + args[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDate() {
|
|
||||||
if (exports.inspectOpts.hideDate) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
return new Date().toISOString() + ' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Invokes `util.format()` with the specified arguments and writes to stderr.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function log(...args) {
|
|
||||||
return process.stderr.write(util.format(...args) + '\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save `namespaces`.
|
|
||||||
*
|
|
||||||
* @param {String} namespaces
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
function save(namespaces) {
|
|
||||||
if (namespaces) {
|
|
||||||
process.env.DEBUG = namespaces;
|
|
||||||
} else {
|
|
||||||
// If you set a process.env field to null or undefined, it gets cast to the
|
|
||||||
// string 'null' or 'undefined'. Just delete instead.
|
|
||||||
delete process.env.DEBUG;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load `namespaces`.
|
|
||||||
*
|
|
||||||
* @return {String} returns the previously persisted debug modes
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
|
|
||||||
function load() {
|
|
||||||
return process.env.DEBUG;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Init logic for `debug` instances.
|
|
||||||
*
|
|
||||||
* Create a new `inspectOpts` object in case `useColors` is set
|
|
||||||
* differently for a particular `debug` instance.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function init(debug) {
|
|
||||||
debug.inspectOpts = {};
|
|
||||||
|
|
||||||
const keys = Object.keys(exports.inspectOpts);
|
|
||||||
for (let i = 0; i < keys.length; i++) {
|
|
||||||
debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = require('./common')(exports);
|
|
||||||
|
|
||||||
const {formatters} = module.exports;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map %o to `util.inspect()`, all on a single line.
|
|
||||||
*/
|
|
||||||
|
|
||||||
formatters.o = function (v) {
|
|
||||||
this.inspectOpts.colors = this.useColors;
|
|
||||||
return util.inspect(v, this.inspectOpts)
|
|
||||||
.replace(/\s*\n\s*/g, ' ');
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map %O to `util.inspect()`, allowing multiple lines if needed.
|
|
||||||
*/
|
|
||||||
|
|
||||||
formatters.O = function (v) {
|
|
||||||
this.inspectOpts.colors = this.useColors;
|
|
||||||
return util.inspect(v, this.inspectOpts);
|
|
||||||
};
|
|
||||||
-162
@@ -1,162 +0,0 @@
|
|||||||
/**
|
|
||||||
* Helpers.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var s = 1000;
|
|
||||||
var m = s * 60;
|
|
||||||
var h = m * 60;
|
|
||||||
var d = h * 24;
|
|
||||||
var w = d * 7;
|
|
||||||
var y = d * 365.25;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse or format the given `val`.
|
|
||||||
*
|
|
||||||
* Options:
|
|
||||||
*
|
|
||||||
* - `long` verbose formatting [false]
|
|
||||||
*
|
|
||||||
* @param {String|Number} val
|
|
||||||
* @param {Object} [options]
|
|
||||||
* @throws {Error} throw an error if val is not a non-empty string or a number
|
|
||||||
* @return {String|Number}
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = function(val, options) {
|
|
||||||
options = options || {};
|
|
||||||
var type = typeof val;
|
|
||||||
if (type === 'string' && val.length > 0) {
|
|
||||||
return parse(val);
|
|
||||||
} else if (type === 'number' && isFinite(val)) {
|
|
||||||
return options.long ? fmtLong(val) : fmtShort(val);
|
|
||||||
}
|
|
||||||
throw new Error(
|
|
||||||
'val is not a non-empty string or a valid number. val=' +
|
|
||||||
JSON.stringify(val)
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the given `str` and return milliseconds.
|
|
||||||
*
|
|
||||||
* @param {String} str
|
|
||||||
* @return {Number}
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
|
|
||||||
function parse(str) {
|
|
||||||
str = String(str);
|
|
||||||
if (str.length > 100) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
|
||||||
str
|
|
||||||
);
|
|
||||||
if (!match) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var n = parseFloat(match[1]);
|
|
||||||
var type = (match[2] || 'ms').toLowerCase();
|
|
||||||
switch (type) {
|
|
||||||
case 'years':
|
|
||||||
case 'year':
|
|
||||||
case 'yrs':
|
|
||||||
case 'yr':
|
|
||||||
case 'y':
|
|
||||||
return n * y;
|
|
||||||
case 'weeks':
|
|
||||||
case 'week':
|
|
||||||
case 'w':
|
|
||||||
return n * w;
|
|
||||||
case 'days':
|
|
||||||
case 'day':
|
|
||||||
case 'd':
|
|
||||||
return n * d;
|
|
||||||
case 'hours':
|
|
||||||
case 'hour':
|
|
||||||
case 'hrs':
|
|
||||||
case 'hr':
|
|
||||||
case 'h':
|
|
||||||
return n * h;
|
|
||||||
case 'minutes':
|
|
||||||
case 'minute':
|
|
||||||
case 'mins':
|
|
||||||
case 'min':
|
|
||||||
case 'm':
|
|
||||||
return n * m;
|
|
||||||
case 'seconds':
|
|
||||||
case 'second':
|
|
||||||
case 'secs':
|
|
||||||
case 'sec':
|
|
||||||
case 's':
|
|
||||||
return n * s;
|
|
||||||
case 'milliseconds':
|
|
||||||
case 'millisecond':
|
|
||||||
case 'msecs':
|
|
||||||
case 'msec':
|
|
||||||
case 'ms':
|
|
||||||
return n;
|
|
||||||
default:
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Short format for `ms`.
|
|
||||||
*
|
|
||||||
* @param {Number} ms
|
|
||||||
* @return {String}
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
|
|
||||||
function fmtShort(ms) {
|
|
||||||
var msAbs = Math.abs(ms);
|
|
||||||
if (msAbs >= d) {
|
|
||||||
return Math.round(ms / d) + 'd';
|
|
||||||
}
|
|
||||||
if (msAbs >= h) {
|
|
||||||
return Math.round(ms / h) + 'h';
|
|
||||||
}
|
|
||||||
if (msAbs >= m) {
|
|
||||||
return Math.round(ms / m) + 'm';
|
|
||||||
}
|
|
||||||
if (msAbs >= s) {
|
|
||||||
return Math.round(ms / s) + 's';
|
|
||||||
}
|
|
||||||
return ms + 'ms';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Long format for `ms`.
|
|
||||||
*
|
|
||||||
* @param {Number} ms
|
|
||||||
* @return {String}
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
|
|
||||||
function fmtLong(ms) {
|
|
||||||
var msAbs = Math.abs(ms);
|
|
||||||
if (msAbs >= d) {
|
|
||||||
return plural(ms, msAbs, d, 'day');
|
|
||||||
}
|
|
||||||
if (msAbs >= h) {
|
|
||||||
return plural(ms, msAbs, h, 'hour');
|
|
||||||
}
|
|
||||||
if (msAbs >= m) {
|
|
||||||
return plural(ms, msAbs, m, 'minute');
|
|
||||||
}
|
|
||||||
if (msAbs >= s) {
|
|
||||||
return plural(ms, msAbs, s, 'second');
|
|
||||||
}
|
|
||||||
return ms + ' ms';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pluralization helper.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function plural(ms, msAbs, n, name) {
|
|
||||||
var isPlural = msAbs >= n * 1.5;
|
|
||||||
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
|
||||||
}
|
|
||||||
-69
@@ -1,69 +0,0 @@
|
|||||||
{
|
|
||||||
"_from": "ms@^2.1.1",
|
|
||||||
"_id": "ms@2.1.2",
|
|
||||||
"_inBundle": false,
|
|
||||||
"_integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
|
|
||||||
"_location": "/ms",
|
|
||||||
"_phantomChildren": {},
|
|
||||||
"_requested": {
|
|
||||||
"type": "range",
|
|
||||||
"registry": true,
|
|
||||||
"raw": "ms@^2.1.1",
|
|
||||||
"name": "ms",
|
|
||||||
"escapedName": "ms",
|
|
||||||
"rawSpec": "^2.1.1",
|
|
||||||
"saveSpec": null,
|
|
||||||
"fetchSpec": "^2.1.1"
|
|
||||||
},
|
|
||||||
"_requiredBy": [
|
|
||||||
"/debug"
|
|
||||||
],
|
|
||||||
"_resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
|
||||||
"_shasum": "d09d1f357b443f493382a8eb3ccd183872ae6009",
|
|
||||||
"_spec": "ms@^2.1.1",
|
|
||||||
"_where": "C:\\Users\\lzy\\Documents\\Source\\OpportunityLiu\\github-action-setup-xmake\\node_modules\\debug",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/zeit/ms/issues"
|
|
||||||
},
|
|
||||||
"bundleDependencies": false,
|
|
||||||
"deprecated": false,
|
|
||||||
"description": "Tiny millisecond conversion utility",
|
|
||||||
"devDependencies": {
|
|
||||||
"eslint": "4.12.1",
|
|
||||||
"expect.js": "0.3.1",
|
|
||||||
"husky": "0.14.3",
|
|
||||||
"lint-staged": "5.0.0",
|
|
||||||
"mocha": "4.0.1"
|
|
||||||
},
|
|
||||||
"eslintConfig": {
|
|
||||||
"extends": "eslint:recommended",
|
|
||||||
"env": {
|
|
||||||
"node": true,
|
|
||||||
"es6": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"index.js"
|
|
||||||
],
|
|
||||||
"homepage": "https://github.com/zeit/ms#readme",
|
|
||||||
"license": "MIT",
|
|
||||||
"lint-staged": {
|
|
||||||
"*.js": [
|
|
||||||
"npm run lint",
|
|
||||||
"prettier --single-quote --write",
|
|
||||||
"git add"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"main": "./index",
|
|
||||||
"name": "ms",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/zeit/ms.git"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"lint": "eslint lib/* bin/*",
|
|
||||||
"precommit": "lint-staged",
|
|
||||||
"test": "mocha tests.js"
|
|
||||||
},
|
|
||||||
"version": "2.1.2"
|
|
||||||
}
|
|
||||||
-60
@@ -1,60 +0,0 @@
|
|||||||
# ms
|
|
||||||
|
|
||||||
[](https://travis-ci.org/zeit/ms)
|
|
||||||
[](https://spectrum.chat/zeit)
|
|
||||||
|
|
||||||
Use this package to easily convert various time formats to milliseconds.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
```js
|
|
||||||
ms('2 days') // 172800000
|
|
||||||
ms('1d') // 86400000
|
|
||||||
ms('10h') // 36000000
|
|
||||||
ms('2.5 hrs') // 9000000
|
|
||||||
ms('2h') // 7200000
|
|
||||||
ms('1m') // 60000
|
|
||||||
ms('5s') // 5000
|
|
||||||
ms('1y') // 31557600000
|
|
||||||
ms('100') // 100
|
|
||||||
ms('-3 days') // -259200000
|
|
||||||
ms('-1h') // -3600000
|
|
||||||
ms('-200') // -200
|
|
||||||
```
|
|
||||||
|
|
||||||
### Convert from Milliseconds
|
|
||||||
|
|
||||||
```js
|
|
||||||
ms(60000) // "1m"
|
|
||||||
ms(2 * 60000) // "2m"
|
|
||||||
ms(-3 * 60000) // "-3m"
|
|
||||||
ms(ms('10 hours')) // "10h"
|
|
||||||
```
|
|
||||||
|
|
||||||
### Time Format Written-Out
|
|
||||||
|
|
||||||
```js
|
|
||||||
ms(60000, { long: true }) // "1 minute"
|
|
||||||
ms(2 * 60000, { long: true }) // "2 minutes"
|
|
||||||
ms(-3 * 60000, { long: true }) // "-3 minutes"
|
|
||||||
ms(ms('10 hours'), { long: true }) // "10 hours"
|
|
||||||
```
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- Works both in [Node.js](https://nodejs.org) and in the browser
|
|
||||||
- If a number is supplied to `ms`, a string with a unit is returned
|
|
||||||
- If a string that contains the number is supplied, it returns it as a number (e.g.: it returns `100` for `'100'`)
|
|
||||||
- If you pass a string with a number and a valid unit, the number of equivalent milliseconds is returned
|
|
||||||
|
|
||||||
## Related Packages
|
|
||||||
|
|
||||||
- [ms.macro](https://github.com/knpwrs/ms.macro) - Run `ms` as a macro at build-time.
|
|
||||||
|
|
||||||
## Caught a Bug?
|
|
||||||
|
|
||||||
1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device
|
|
||||||
2. Link the package to the global module directory: `npm link`
|
|
||||||
3. Within the module you want to test your local development instance of ms, just link it to the dependencies: `npm link ms`. Instead of the default one from npm, Node.js will now use your clone of ms!
|
|
||||||
|
|
||||||
As always, you can run the tests using: `npm test`
|
|
||||||
-20
@@ -1,20 +0,0 @@
|
|||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Steve King
|
|
||||||
|
|
||||||
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.
|
|
||||||
-75
@@ -1,75 +0,0 @@
|
|||||||
{
|
|
||||||
"_from": "simple-git",
|
|
||||||
"_id": "simple-git@1.126.0",
|
|
||||||
"_inBundle": false,
|
|
||||||
"_integrity": "sha512-47mqHxgZnN8XRa9HbpWprzUv3Ooqz9RY/LSZgvA7jCkW8jcwLahMz7LKugY91KZehfG0sCVPtgXiU72hd6b1Bw==",
|
|
||||||
"_location": "/simple-git",
|
|
||||||
"_phantomChildren": {},
|
|
||||||
"_requested": {
|
|
||||||
"type": "tag",
|
|
||||||
"registry": true,
|
|
||||||
"raw": "simple-git",
|
|
||||||
"name": "simple-git",
|
|
||||||
"escapedName": "simple-git",
|
|
||||||
"rawSpec": "",
|
|
||||||
"saveSpec": null,
|
|
||||||
"fetchSpec": "latest"
|
|
||||||
},
|
|
||||||
"_requiredBy": [
|
|
||||||
"#USER",
|
|
||||||
"/"
|
|
||||||
],
|
|
||||||
"_resolved": "https://registry.npmjs.org/simple-git/-/simple-git-1.126.0.tgz",
|
|
||||||
"_shasum": "0c345372275139c8433b8277f4b3e155092aa434",
|
|
||||||
"_spec": "simple-git",
|
|
||||||
"_where": "C:\\Users\\lzy\\Documents\\Source\\OpportunityLiu\\github-action-setup-xmake",
|
|
||||||
"author": {
|
|
||||||
"name": "Steve King",
|
|
||||||
"email": "steve@mydev.co"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/steveukx/git-js/issues"
|
|
||||||
},
|
|
||||||
"bundleDependencies": false,
|
|
||||||
"contributors": [
|
|
||||||
{
|
|
||||||
"name": "Steve King",
|
|
||||||
"email": "steve@mydev.co"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"dependencies": {
|
|
||||||
"debug": "^4.0.1"
|
|
||||||
},
|
|
||||||
"deprecated": false,
|
|
||||||
"description": "Simple GIT interface for node.js",
|
|
||||||
"devDependencies": {
|
|
||||||
"@kwsites/test-runner": "^0.1.1",
|
|
||||||
"sinon": "^7.3.2"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"promise.*",
|
|
||||||
"src/",
|
|
||||||
"typings/"
|
|
||||||
],
|
|
||||||
"homepage": "https://github.com/steveukx/git-js#readme",
|
|
||||||
"keywords": [
|
|
||||||
"git",
|
|
||||||
"source control",
|
|
||||||
"vcs"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"main": "./src/index.js",
|
|
||||||
"name": "simple-git",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git://github.com/steveukx/git-js.git"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"postversion": "npm publish && git push && git push --tags",
|
|
||||||
"preversion": "yarn test",
|
|
||||||
"test": "runner test/**/test*.js ",
|
|
||||||
"test:integration": "runner test/integration/test*.js",
|
|
||||||
"test:unit": "runner test/unit/test*.js"
|
|
||||||
},
|
|
||||||
"version": "1.126.0"
|
|
||||||
}
|
|
||||||
-576
@@ -1,576 +0,0 @@
|
|||||||
import * as resp from "./typings/response";
|
|
||||||
|
|
||||||
declare function simplegit(basePath?: string): simplegit.SimpleGit;
|
|
||||||
|
|
||||||
declare namespace simplegit {
|
|
||||||
|
|
||||||
interface SimpleGit {
|
|
||||||
/**
|
|
||||||
* Adds one or more files to source control
|
|
||||||
*
|
|
||||||
* @param {string|string[]} files
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
add(files: string | string[]): Promise<void>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add an annotated tag to the head of the current branch
|
|
||||||
*
|
|
||||||
* @param {string} tagName
|
|
||||||
* @param {string} tagMessage
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
addAnnotatedTag(tagName: string, tagMessage: string): Promise<void>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add config to local git instance
|
|
||||||
*
|
|
||||||
* @param {string} key configuration key (e.g user.name)
|
|
||||||
* @param {string} value for the given key (e.g your name)
|
|
||||||
* @returns {Promise<string>}
|
|
||||||
*/
|
|
||||||
addConfig(key: string, value: string): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a remote to the list of remotes.
|
|
||||||
*
|
|
||||||
* @param {string} remoteName Name of the repository - eg "upstream"
|
|
||||||
* @param {string} remoteRepo Fully qualified SSH or HTTP(S) path to the remote repo
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
addRemote(remoteName: string, remoteRepo: string): Promise<void>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a lightweight tag to the head of the current branch
|
|
||||||
*
|
|
||||||
* @param {string} name
|
|
||||||
* @returns {Promise<string>}
|
|
||||||
*/
|
|
||||||
addTag(name: string): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Equivalent to `catFile` but will return the native `Buffer` of content from the git command's stdout.
|
|
||||||
*
|
|
||||||
* @param {string[]} options
|
|
||||||
*/
|
|
||||||
binaryCatFile(options: string[]): Promise<any>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List all branches
|
|
||||||
*
|
|
||||||
* @param {Object | string[]} [options]
|
|
||||||
* @returns {Promise<BranchSummary>}
|
|
||||||
*/
|
|
||||||
branch(options: Options | string[]): Promise<BranchSummary>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of local branches
|
|
||||||
*
|
|
||||||
* @returns {Promise<BranchSummary>}
|
|
||||||
*/
|
|
||||||
branchLocal(): Promise<BranchSummary>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a list of objects in a tree based on commit hash.
|
|
||||||
* Passing in an object hash returns the object's content, size, and type.
|
|
||||||
*
|
|
||||||
* Passing "-p" will instruct cat-file to determine the object type, and display its formatted contents.
|
|
||||||
*
|
|
||||||
* @param {string[]} [options]
|
|
||||||
* @returns {Promise<string>}
|
|
||||||
*
|
|
||||||
* @see https://git-scm.com/docs/git-cat-file
|
|
||||||
*/
|
|
||||||
catFile(options: string[]): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if a pathname or pathnames are excluded by .gitignore
|
|
||||||
*
|
|
||||||
* @param {string|string[]} pathnames
|
|
||||||
*/
|
|
||||||
checkIgnore(pathnames: string[]): Promise<string[]>;
|
|
||||||
|
|
||||||
checkIgnore(path: string): Promise<string[]>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates that the current repo is a Git repo.
|
|
||||||
*
|
|
||||||
* @returns {Promise<boolean>}
|
|
||||||
*/
|
|
||||||
checkIsRepo(): Promise<boolean>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checkout a tag or revision, any number of additional arguments can be passed to the `git* checkout` command
|
|
||||||
by supplying either a string or array of strings as the `what` parameter.
|
|
||||||
*
|
|
||||||
* @param {(string | string[])} what one or more commands to pass to `git checkout`.
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
checkout(what: string | string[]): Promise<void>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checkout a remote branch.
|
|
||||||
*
|
|
||||||
* @param {string} branchName name of branch.
|
|
||||||
* @param {string} startPoint (e.g origin/development).
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
checkoutBranch(branchName: string, startPoint: string): Promise<void>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internally uses pull and tags to get the list of tags then checks out the latest tag.
|
|
||||||
*/
|
|
||||||
checkoutLatestTag(branchName: string, startPoint: string): Promise<void>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checkout a local branch
|
|
||||||
*
|
|
||||||
* @param {string} branchName name of branch.
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
checkoutLocalBranch(branchName: string): Promise<void>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} mode Required parameter "n" or "f"
|
|
||||||
* @param {string[]} options
|
|
||||||
*/
|
|
||||||
clean(
|
|
||||||
mode: 'd' | 'f' | 'i' | 'n' | 'q' | 'x' | 'X',
|
|
||||||
options?: string[]
|
|
||||||
): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clears the queue of pending commands and returns the wrapper instance for chaining.
|
|
||||||
*/
|
|
||||||
clearQueue(): this;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clone a repository into a new directory.
|
|
||||||
*
|
|
||||||
* @param {string} repoPath repository url to clone e.g. https://github.com/steveukx/git-js.git
|
|
||||||
* @param {string} localPath local folder path to clone to.
|
|
||||||
* @param {string[]} [options] options supported by [git](https://git-scm.com/docs/git-clone).
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
clone(repoPath: string, localPath: string, options?: Options | string[]): Promise<string>;
|
|
||||||
clone(repoPath: string, options?: Options | string[]): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Commits changes in the current working directory - when specific file paths are supplied, only changes on those
|
|
||||||
* files will be committed.
|
|
||||||
*
|
|
||||||
* @param {string|string[]} message
|
|
||||||
* @param {string|string[]} [files]
|
|
||||||
* @param {Object} [options]
|
|
||||||
*/
|
|
||||||
commit(
|
|
||||||
message: string | string[],
|
|
||||||
files?: string | string[],
|
|
||||||
options?: Options
|
|
||||||
): Promise<resp.CommitSummary>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the path to a custom git binary, should either be `git` when there is an installation of git available on
|
|
||||||
* the system path, or a fully qualified path to the executable.
|
|
||||||
*
|
|
||||||
* @param {string} command
|
|
||||||
*/
|
|
||||||
customBinary(command: string): this;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the working directory of the subsequent commands.
|
|
||||||
*
|
|
||||||
* @param {string} workingDirectory
|
|
||||||
*/
|
|
||||||
cwd<path extends string>(workingDirectory: path): Promise<path>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete a local branch
|
|
||||||
*
|
|
||||||
* @param {string} branchName name of branch
|
|
||||||
*/
|
|
||||||
deleteLocalBranch(branchName: string):
|
|
||||||
Promise<resp.BranchDeletionSummary>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the diff of the current repo compared to the last commit with a set of options supplied as a string.
|
|
||||||
*
|
|
||||||
* @param {string[]} [options] options supported by [git](https://git-scm.com/docs/git-diff).
|
|
||||||
* @returns {Promise<string>} raw string result.
|
|
||||||
*/
|
|
||||||
diff(options?: string[]): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a summary of the diff for files in the repo, uses the `git diff --stat` format to calculate changes.
|
|
||||||
*
|
|
||||||
* in order to get staged (only): `--cached` or `--staged`.
|
|
||||||
*
|
|
||||||
* @param {string[]} [options] options supported by [git](https://git-scm.com/docs/git-diff).
|
|
||||||
* @returns {Promise<DiffResult>} Parsed diff summary result.
|
|
||||||
*/
|
|
||||||
diffSummary(options?: string[]): Promise<DiffResult>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets an environment variable for the spawned child process, either supply both a name and value as strings or
|
|
||||||
* a single object to entirely replace the current environment variables.
|
|
||||||
*
|
|
||||||
* @param {string|Object} name
|
|
||||||
* @param {string} [value]
|
|
||||||
*/
|
|
||||||
env(name: string, value: string): this;
|
|
||||||
|
|
||||||
env(env: object): this;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the local working copy database with changes from the default remote repo and branch.
|
|
||||||
*
|
|
||||||
* @param {string | string[]} [remote] remote to fetch from.
|
|
||||||
* @param {string} [branch] branch to fetch from.
|
|
||||||
* @param {string[]} [options] options supported by [git](https://git-scm.com/docs/git-fetch).
|
|
||||||
* @returns {Promise<FetchResult>} Parsed fetch result.
|
|
||||||
*/
|
|
||||||
fetch(remote?: string | string[], branch?: string, options?: Options): Promise<FetchResult>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the currently available remotes, setting the optional verbose argument to true includes additional
|
|
||||||
* detail on the remotes themselves.
|
|
||||||
*
|
|
||||||
* @param {boolean} [verbose=false]
|
|
||||||
*/
|
|
||||||
getRemotes(verbose: false | undefined): Promise<resp.RemoteWithoutRefs[]>;
|
|
||||||
|
|
||||||
getRemotes(verbose: true): Promise<resp.RemoteWithRefs[]>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize a git repo
|
|
||||||
*
|
|
||||||
* @param {Boolean} [bare=false]
|
|
||||||
*/
|
|
||||||
init(bare?: boolean): Promise<void>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List remote
|
|
||||||
*
|
|
||||||
* @param {string[]} [args]
|
|
||||||
*/
|
|
||||||
listRemote(args: string[]): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show commit logs from `HEAD` to the first commit.
|
|
||||||
* If provided between `options.from` and `options.to` tags or branch.
|
|
||||||
*
|
|
||||||
* You can provide `options.file`, which is the path to a file in your repository. Then only this file will be considered.
|
|
||||||
*
|
|
||||||
* To use a custom splitter in the log format, set `options.splitter` to be the string the log should be split on.
|
|
||||||
*
|
|
||||||
* By default the following fields will be part of the result:
|
|
||||||
* `hash`: full commit hash
|
|
||||||
* `date`: author date, ISO 8601-like format
|
|
||||||
* `message`: subject + ref names, like the --decorate option of git-log
|
|
||||||
* `author_name`: author name
|
|
||||||
* `author_email`: author mail
|
|
||||||
* You can specify `options.format` to be an mapping from key to a format option like `%H` (for commit hash).
|
|
||||||
* The fields specified in `options.format` will be the fields in the result.
|
|
||||||
*
|
|
||||||
* Options can also be supplied as a standard options object for adding custom properties supported by the git log command.
|
|
||||||
* For any other set of options, supply options as an array of strings to be appended to the git log command.
|
|
||||||
*
|
|
||||||
* @param {LogOptions} [options]
|
|
||||||
*
|
|
||||||
* @returns Promise<ListLogSummary>
|
|
||||||
*
|
|
||||||
* @see https://git-scm.com/docs/git-log
|
|
||||||
*/
|
|
||||||
log<T = resp.DefaultLogFields>(options?: LogOptions<T>): Promise<resp.ListLogSummary<T>>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Runs a merge, `options` can be either an array of arguments
|
|
||||||
* supported by the [`git merge`](https://git-scm.com/docs/git-merge)
|
|
||||||
* or an options object.
|
|
||||||
*
|
|
||||||
* Conflicts during the merge result in an error response,
|
|
||||||
* the response type whether it was an error or success will be a MergeSummary instance.
|
|
||||||
* When successful, the MergeSummary has all detail from a the PullSummary
|
|
||||||
*
|
|
||||||
* @param {Options | string[]} [options] options supported by [git](https://git-scm.com/docs/git-merge).
|
|
||||||
* @returns {Promise<any>}
|
|
||||||
*
|
|
||||||
* @see https://github.com/steveukx/git-js/blob/master/src/responses/MergeSummary.js
|
|
||||||
* @see https://github.com/steveukx/git-js/blob/master/src/responses/PullSummary.js
|
|
||||||
*/
|
|
||||||
merge(options: Options | string[]): Promise<any>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Merges from one branch to another, equivalent to running `git merge ${from} $[to}`, the `options` argument can
|
|
||||||
* either be an array of additional parameters to pass to the command or null / omitted to be ignored.
|
|
||||||
*
|
|
||||||
* @param {string} from branch to merge from.
|
|
||||||
* @param {string} to branch to merge to.
|
|
||||||
* @param {string[]} [options] options supported by [git](https://git-scm.com/docs/git-merge).
|
|
||||||
* @returns {Promise<string>}
|
|
||||||
*/
|
|
||||||
mergeFromTo(from: string, to: string, options?: string[]): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mirror a git repo
|
|
||||||
*
|
|
||||||
* @param {string} repoPath
|
|
||||||
* @param {string} localPath
|
|
||||||
*/
|
|
||||||
mirror(repoPath: string, localPath: string): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Moves one or more files to a new destination.
|
|
||||||
*
|
|
||||||
* @see https://git-scm.com/docs/git-mv
|
|
||||||
*
|
|
||||||
* @param {string|string[]} from
|
|
||||||
* @param {string} to
|
|
||||||
*/
|
|
||||||
mv(from: string | string[], to: string): Promise<resp.MoveSummary>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a handler function to be called whenever a new child process is created, the handler function will be called
|
|
||||||
* with the name of the command being run and the stdout & stderr streams used by the ChildProcess.
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* require('simple-git')
|
|
||||||
* .outputHandler(function (command, stdout, stderr) {
|
|
||||||
* stdout.pipe(process.stdout);
|
|
||||||
* })
|
|
||||||
* .checkout('https://github.com/user/repo.git');
|
|
||||||
*
|
|
||||||
* @see http://nodejs.org/api/child_process.html#child_process_class_childprocess
|
|
||||||
* @see http://nodejs.org/api/stream.html#stream_class_stream_readable
|
|
||||||
* @param {Function} outputHandler
|
|
||||||
*/
|
|
||||||
outputHandler(handler: outputHandler | void): this;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch from and integrate with another repository or a local branch.
|
|
||||||
*
|
|
||||||
* @param {string} [remote] remote to pull from.
|
|
||||||
* @param {string} [branch] branch to pull from.
|
|
||||||
* @param {Options} [options] options supported by [git](https://git-scm.com/docs/git-pull).
|
|
||||||
* @returns {Promise<PullResult>} Parsed pull result.
|
|
||||||
*/
|
|
||||||
pull(remote?: string, branch?: string, options?: Options): Promise<PullResult>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update remote refs along with associated objects.
|
|
||||||
*
|
|
||||||
* @param {string} [remote] remote to push to.
|
|
||||||
* @param {string} [branch] branch to push to.
|
|
||||||
* @param {Options} [options] options supported by [git](https://git-scm.com/docs/git-push).
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
push(remote?: string, branch?: string, options?: Options): Promise<void>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pushes the current tag changes to a remote which can be either a URL or named remote. When not specified uses the
|
|
||||||
* default configured remote spec.
|
|
||||||
*
|
|
||||||
* @param {string} [remote]
|
|
||||||
*/
|
|
||||||
pushTags(remote?: string): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes any command against the git binary.
|
|
||||||
*
|
|
||||||
* @param {string[]|Object} commands
|
|
||||||
*/
|
|
||||||
raw(commands: string | string[]): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rebases the current working copy. Options can be supplied either as an array of string parameters
|
|
||||||
* to be sent to the `git rebase` command, or a standard options object.
|
|
||||||
*
|
|
||||||
* @param {Object|String[]} [options]
|
|
||||||
*/
|
|
||||||
rebase(options?: Options | string[]): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call any `git remote` function with arguments passed as an array of strings.
|
|
||||||
*
|
|
||||||
* @param {string[]} options
|
|
||||||
*/
|
|
||||||
remote(options: string[]): Promise<void | string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes an entry from the list of remotes.
|
|
||||||
*
|
|
||||||
* @param {string} remoteName Name of the repository - eg "upstream"
|
|
||||||
* @returns {*}
|
|
||||||
*/
|
|
||||||
removeRemote(remote: string): Promise<void>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reset a repo
|
|
||||||
*
|
|
||||||
* @param {string|string[]} [mode=soft] Either an array of arguments supported by the 'git reset' command, or the string value 'soft' or 'hard' to set the reset mode.
|
|
||||||
*/
|
|
||||||
reset(mode?: 'soft' | 'mixed' | 'hard' | 'merge' | 'keep'): Promise<null>;
|
|
||||||
|
|
||||||
reset(commands?: string[]): Promise<void>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Revert one or more commits in the local working copy
|
|
||||||
*
|
|
||||||
* @param {string} commit The commit to revert. Can be any hash, offset (eg: `HEAD~2`) or range (eg: `master~5..master~2`)
|
|
||||||
* @param {Object} [options] Optional options object
|
|
||||||
*/
|
|
||||||
revert(commit: String, options?: Options): Promise<void>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wraps `git rev-parse`. Primarily used to convert friendly commit references (ie branch names) to SHA1 hashes.
|
|
||||||
*
|
|
||||||
* Options should be an array of string options compatible with the `git rev-parse`
|
|
||||||
*
|
|
||||||
* @param {string[]} [options]
|
|
||||||
*
|
|
||||||
* @returns Promise<string>
|
|
||||||
*
|
|
||||||
* @see http://git-scm.com/docs/git-rev-parse
|
|
||||||
*/
|
|
||||||
revparse(options?: string[]): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes the named files from source control.
|
|
||||||
*
|
|
||||||
* @param {string|string[]} files
|
|
||||||
*/
|
|
||||||
rm(paths: string | string[]): Promise<void>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes the named files from source control but keeps them on disk rather than deleting them entirely. To
|
|
||||||
* completely remove the files, use `rm`.
|
|
||||||
*
|
|
||||||
* @param {string|string[]} files
|
|
||||||
*/
|
|
||||||
rmKeepLocal(paths: string | string[]): Promise<void>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show various types of objects, for example the file at a certain commit
|
|
||||||
*
|
|
||||||
* @param {string[]} [options]
|
|
||||||
*/
|
|
||||||
show(options?: string[]): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disables/enables the use of the console for printing warnings and errors, by default messages are not shown in
|
|
||||||
* a production environment.
|
|
||||||
*
|
|
||||||
* @param {boolean} silence
|
|
||||||
* @returns {simplegit.SimpleGit}
|
|
||||||
*/
|
|
||||||
silent(silence?: boolean): simplegit.SimpleGit;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stash the local repo
|
|
||||||
*
|
|
||||||
* @param {Object|Array} [options]
|
|
||||||
*/
|
|
||||||
stash(options?: Options | any[]): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List the stash(s) of the local repo
|
|
||||||
*
|
|
||||||
* @param {Object|Array} [options]
|
|
||||||
*/
|
|
||||||
stashList(options?: Options | string[]): Promise<resp.ListLogSummary>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show the working tree status.
|
|
||||||
*
|
|
||||||
* @returns {Promise<StatusResult>} Parsed status result.
|
|
||||||
*/
|
|
||||||
status(): Promise<StatusResult>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call any `git submodule` function with arguments passed as an array of strings.
|
|
||||||
*
|
|
||||||
* @param {string[]} options
|
|
||||||
*/
|
|
||||||
subModule(options: string[]): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a submodule
|
|
||||||
*
|
|
||||||
* @param {string} repo
|
|
||||||
* @param {string} path
|
|
||||||
*/
|
|
||||||
submoduleAdd(repo: string, path: string): Promise<void>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize submodules
|
|
||||||
*
|
|
||||||
* @param {string[]} [args]
|
|
||||||
*/
|
|
||||||
submoduleInit(options?: string[]): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update submodules
|
|
||||||
*
|
|
||||||
* @param {string[]} [args]
|
|
||||||
*/
|
|
||||||
submoduleUpdate(options?: string[]): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List all tags. When using git 2.7.0 or above, include an options object with `"--sort": "property-name"` to
|
|
||||||
* sort the tags by that property instead of using the default semantic versioning sort.
|
|
||||||
*
|
|
||||||
* Note, supplying this option when it is not supported by your Git version will cause the operation to fail.
|
|
||||||
*
|
|
||||||
* @param {Object} [options]
|
|
||||||
*/
|
|
||||||
tag(options?: Options | string[]): Promise<string>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a list of tagged versions.
|
|
||||||
*
|
|
||||||
* @param {Options} options
|
|
||||||
* @returns {Promise<TagResult>} Parsed tag list.
|
|
||||||
*/
|
|
||||||
tags(options?: Options): Promise<TagResult>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates repository server info
|
|
||||||
*/
|
|
||||||
updateServerInfo(): Promise<string>;
|
|
||||||
}
|
|
||||||
|
|
||||||
type Options = { [key: string]: null | string | any };
|
|
||||||
|
|
||||||
type LogOptions<T = resp.DefaultLogFields> = Options & {
|
|
||||||
format?: T;
|
|
||||||
file?: string;
|
|
||||||
from?: string;
|
|
||||||
multiLine?: boolean;
|
|
||||||
symmetric?: boolean;
|
|
||||||
to?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
// responses
|
|
||||||
// ---------------------
|
|
||||||
interface BranchSummary extends resp.BranchSummary {}
|
|
||||||
|
|
||||||
interface CommitSummary extends resp.CommitSummary {}
|
|
||||||
|
|
||||||
interface PullResult extends resp.PullResult {}
|
|
||||||
|
|
||||||
interface FetchResult extends resp.FetchResult {}
|
|
||||||
|
|
||||||
interface StatusResult extends resp.StatusResult {}
|
|
||||||
|
|
||||||
interface DiffResult extends resp.DiffResult {}
|
|
||||||
|
|
||||||
interface TagResult extends resp.TagResult {}
|
|
||||||
|
|
||||||
type outputHandler = (
|
|
||||||
command: string,
|
|
||||||
stdout: NodeJS.ReadableStream,
|
|
||||||
stderr: NodeJS.ReadableStream
|
|
||||||
) => void
|
|
||||||
}
|
|
||||||
|
|
||||||
export = simplegit;
|
|
||||||
-83
@@ -1,83 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
if (typeof Promise === 'undefined') {
|
|
||||||
throw new ReferenceError("Promise wrappers must be enabled to use the promise API");
|
|
||||||
}
|
|
||||||
|
|
||||||
function isAsyncCall (fn) {
|
|
||||||
return /^[^\)]+then\s*\)/.test(fn) || /\._run\(/.test(fn);
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = function (baseDir) {
|
|
||||||
|
|
||||||
var Git = require('./src/git');
|
|
||||||
var gitFactory = require('./src');
|
|
||||||
var git;
|
|
||||||
|
|
||||||
|
|
||||||
var chain = Promise.resolve();
|
|
||||||
|
|
||||||
try {
|
|
||||||
git = gitFactory(baseDir);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
chain = Promise.reject(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Object.keys(Git.prototype).reduce(function (promiseApi, fn) {
|
|
||||||
if (/^_|then/.test(fn)) {
|
|
||||||
return promiseApi;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isAsyncCall(Git.prototype[fn])) {
|
|
||||||
promiseApi[fn] = git ? asyncWrapper(fn, git) : function () {
|
|
||||||
return chain;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
promiseApi[fn] = git ? syncWrapper(fn, git, promiseApi) : function () {
|
|
||||||
return promiseApi;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return promiseApi;
|
|
||||||
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
function asyncWrapper (fn, git) {
|
|
||||||
return function () {
|
|
||||||
var args = [].slice.call(arguments);
|
|
||||||
|
|
||||||
if (typeof args[args.length] === 'function') {
|
|
||||||
throw new TypeError(
|
|
||||||
"Promise interface requires that handlers are not supplied inline, " +
|
|
||||||
"trailing function not allowed in call to " + fn);
|
|
||||||
}
|
|
||||||
|
|
||||||
return chain.then(function () {
|
|
||||||
return new Promise(function (resolve, reject) {
|
|
||||||
args.push(function (err, result) {
|
|
||||||
if (err) {
|
|
||||||
reject(new Error(err));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
resolve(result);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
git[fn].apply(git, args);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function syncWrapper (fn, git, api) {
|
|
||||||
return function () {
|
|
||||||
git[fn].apply(git, arguments);
|
|
||||||
|
|
||||||
return api;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
-353
@@ -1,353 +0,0 @@
|
|||||||
# Simple Git
|
|
||||||
[](https://www.npmjs.com/package/simple-git) [](https://travis-ci.org/steveukx/git-js)
|
|
||||||
|
|
||||||
A light weight interface for running git commands in any [node.js](http://nodejs.org) application.
|
|
||||||
|
|
||||||
# Installation
|
|
||||||
|
|
||||||
Easiest through [npm](http://npmjs.org): `npm install simple-git`
|
|
||||||
|
|
||||||
# Dependencies
|
|
||||||
|
|
||||||
Requires [git](http://git-scm.com/downloads) to be installed and that it can be called using the command `git`.
|
|
||||||
|
|
||||||
# Usage
|
|
||||||
|
|
||||||
Include into your app using:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const simpleGit = require('simple-git')(workingDirPath);
|
|
||||||
```
|
|
||||||
|
|
||||||
> where the `workingDirPath` is optional, defaulting to the current directory.
|
|
||||||
|
|
||||||
Use `simpleGit` by chaining any of its functions together. Each function accepts an optional final argument which will
|
|
||||||
be called when that step has been completed. When it is called it has two arguments - firstly an error object (or null
|
|
||||||
when no error occurred) and secondly the data generated by that call.
|
|
||||||
|
|
||||||
| API | What it does |
|
|
||||||
|-----|--------------|
|
|
||||||
| `.add([fileA, ...], handlerFn)` | adds one or more files to be under source control |
|
|
||||||
| `.addAnnotatedTag(tagName, tagMessage, handlerFn)` | adds an annotated tag to the head of the current branch |
|
|
||||||
| `.addConfig(key, value[, handlerFn])` | add a local configuration property |
|
|
||||||
| `.addRemote(name, repo, handlerFn)` | adds a new named remote to be tracked as `name` at the path `repo` |
|
|
||||||
| `.addTag(name, handlerFn)` | adds a lightweight tag to the head of the current branch |
|
|
||||||
| `.branch([options, ][handlerFn])` | gets a list of all branches, calls `handlerFn` with two arguments, an error object and [BranchSummary](src/responses/BranchSummary.js) instance. When supplied, the options can be either an array of arguments supported by the [branch](https://git-scm.com/docs/git-branch) command or a standard [options](#how-to-specify-options) object. |
|
|
||||||
| `.branchLocal([handlerFn])` | gets a list of local branches, calls `handlerFn` with two arguments, an error object and [BranchSummary](src/responses/BranchSummary.js) instance |
|
|
||||||
| `.catFile(options[, handlerFn])` | generate `cat-file` detail, `options` should be an array of strings as supported arguments to the [cat-file](https://git-scm.com/docs/git-cat-file) command |
|
|
||||||
| `.checkIgnore([filepath, ...], handlerFn)` | checks if filepath excluded by .gitignore rules |
|
|
||||||
| `.checkIsRepo(handlerFn)` | Determines whether the current working directory is part of a git repository, the handler will be called with standard error object and a boolean response. |
|
|
||||||
| `.checkout(checkoutWhat, handlerFn)` | checks out the supplied tag, revision or branch. `checkoutWhat` can be one or more strings to be used as parameters appended to the `git checkout` command. |
|
|
||||||
| `.checkoutBranch(branchName, startPoint, handlerFn)` | checks out a new branch from the supplied start point |
|
|
||||||
| `.checkoutLatestTag(handlerFn)` | convenience method to pull then checkout the latest tag |
|
|
||||||
| `.checkoutLocalBranch(branchName, handlerFn)` | checks out a new local branch |
|
|
||||||
| `.clean(mode [, options [, handlerFn]])` | clean the working tree. Mode should be "n" - dry run or "f" - force |
|
|
||||||
| `.clearQueue()` | immediately clears the queue of pending tasks (note: any command currently in progress will still call its completion callback) |
|
|
||||||
| `.clone(repoPath, [localPath, [options]], [handlerFn])` | clone a remote repo at `repoPath` to a local directory at `localPath` (can be omitted to use the default of a directory with the same name as the repo name) with an optional array of additional arguments to include between `git clone` and the trailing `repo local` arguments |
|
|
||||||
| `.commit(message, handlerFn)` | commits changes in the current working directory with the supplied message where the message can be either a single string or array of strings to be passed as separate arguments (the `git` command line interface converts these to be separated by double line breaks) |
|
|
||||||
| `.commit(message, [fileA, ...], options, handlerFn)` | commits changes on the named files with the supplied message, when supplied, the optional options object can contain any other parameters to pass to the commit command, setting the value of the property to be a string will add `name=value` to the command string, setting any other type of value will result in just the key from the object being passed (ie: just `name`), an example of setting the author is below |
|
|
||||||
| `.customBinary(gitPath)` | sets the command to use to reference git, allows for using a git binary not available on the path environment variable |
|
|
||||||
| `.cwd(workingDirectory)` | Sets the current working directory for all commands after this step in the chain |
|
|
||||||
| `.deleteLocalBranch(branchName, handlerFn)` | deletes a local branch |
|
|
||||||
| `.diff(options, handlerFn)` | get the diff of the current repo compared to the last commit with a set of options supplied as a string |
|
|
||||||
| `.diff(handlerFn)` | get the diff for all file in the current repo compared to the last commit |
|
|
||||||
| `.diffSummary(handlerFn)` | gets a summary of the diff for files in the repo, uses the `git diff --stat` format to calculate changes. Handler is called with a nullable error object and an instance of the [DiffSummary](src/responses/DiffSummary.js) |
|
|
||||||
| `.diffSummary(options, handlerFn)` | includes options in the call to `diff --stat options` and returns a [DiffSummary](src/responses/DiffSummary.js) |
|
|
||||||
| `.env(name, value)` | Set environment variables to be passed to the spawned child processes, [see usage in detail below](#environment-variables). |
|
|
||||||
| `.exec(handlerFn)` | calls a simple function in the current step |
|
|
||||||
| `.fetch([options, ] handlerFn)` | update the local working copy database with changes from the default remote repo and branch, when supplied the options argument can be a standard [options object](#how-to-specify-options) either an array of string commands as supported by the [git fetch](https://git-scm.com/docs/git-fetch). On success, the returned data will be an instance of the [FetchSummary](src/responses/FetchSummary.js) |
|
|
||||||
| `.fetch(remote, branch, handlerFn)` | update the local working copy database with changes from a remote repo |
|
|
||||||
| `.fetch(handlerFn)` | update the local working copy database with changes from the default remote repo and branch |
|
|
||||||
| `.getRemotes([verbose], handlerFn)` | gets a list of the named remotes, when the verbose option is supplied as true, includes the URLs and purpose of each ref |
|
|
||||||
| `.init(bare, handlerFn)` | initialize a repository, optional `bare` parameter makes intialized repository bare |
|
|
||||||
| `.listRemote([args], handlerFn)` | lists remote repositories - there are so many optional arguments in the underlying `git ls-remote` call, just supply any you want to use as the optional `args` array of strings eg: `git.listRemote(['--heads', '--tags'], console.log.bind(console))` |
|
|
||||||
| `.log([options], handlerFn)` | list commits between `options.from` and `options.to` tags or branch (if not specified will show all history). Additionally you can provide `options.file`, which is the path to a file in your repository. Then only this file will be considered. `options.symmetric` allows you to specify whether you want to use [symmetric revision range](https://git-scm.com/docs/gitrevisions#_dotted_range_notations) (To be compatible, by default, its value is true). For any other set of options, supply `options` as an array of strings to be appended to the `git log` command. To use a custom splitter in the log format, set `options.splitter` to be the string the log should be split on. Set `options.multiLine` to true to include a multi-line body in the output format. Options can also be supplied as a standard [options](#how-to-specify-options) object for adding custom properties supported by the [git log](https://git-scm.com/docs/git-log) command. |
|
|
||||||
| `.mergeFromTo(from, to, [[options,] handlerFn])` | merge from one branch to another, when supplied the options should be an array of additional parameters to pass into the [git merge](https://git-scm.com/docs/git-merge) command |
|
|
||||||
| `.merge(options, handlerFn)` | runs a merge, `options` can be either an array of arguments supported by the [git merge](https://git-scm.com/docs/git-merge) command or an [options](#how-to-specify-options) object. Conflicts during the merge result in an error response, the response type whether it was an error or success will be a [MergeSummary](src/responses/MergeSummary.js) instance. When successful, the MergeSummary has all detail from a the [PullSummary](src/responses/PullSummary.js) |
|
|
||||||
| `.mirror(repoPath, localPath, handlerFn])` | clone and mirror the repo to local |
|
|
||||||
| `.mv(from, to, handlerFn])` | rename or move a single file at `from` to `to`. On success the `handlerFn` will be called with a [MoveSummary](src/responses/MoveSummary.js) |
|
|
||||||
| `.mv(from, to, handlerFn])` | move all files in the `from` array to the `to` directory. On success the `handlerFn` will be called with a [MoveSummary](src/responses/MoveSummary.js) |
|
|
||||||
| `.outputHandler(handlerFn)` | attaches a handler that will be called with the name of the command being run and the `stdout` and `stderr` [readable streams](http://nodejs.org/api/stream.html#stream_class_stream_readable) created by the [child process](http://nodejs.org/api/child_process.html#child_process_class_childprocess) running that command |
|
|
||||||
| `.pull(handlerFn)` | Pulls all updates from the default tracked repo |
|
|
||||||
| `.pull(remote, branch, handlerFn)` | pull all updates from the specified remote branch (eg 'origin'/'master') |
|
|
||||||
| `.pull(remote, branch, options, handlerFn)` | Pulls from named remote with any necessary options |
|
|
||||||
| `.push(remote, branch[, options] handlerFn)` | pushes to a named remote/branch, supports additional [options](#how-to-specify-options) from the [git push](https://git-scm.com/docs/git-push) command. |
|
|
||||||
| `.pushTags(remote, handlerFn)` | pushes tags to a named remote |
|
|
||||||
| `.raw(args[, handlerFn])` | Execute any arbitrary array of commands supported by the underlying git binary. When the git process returns a non-zero signal on exit and it printed something to `stderr`, the commmand will be treated as an error, otherwise treated as a success. |
|
|
||||||
| `.rebase([options,] handlerFn)` | Rebases the repo, `options` should be supplied as an array of string parameters supported by the [git rebase](https://git-scm.com/docs/git-rebase) command, or an object of options (see details below for option formats). |
|
|
||||||
| `.removeRemote(name, handlerFn)` | removes the named remote |
|
|
||||||
| `.reset([resetMode,] handlerFn)` | resets the repository, the optional first argument can either be an array of options supported by the `git reset` command or one of the string constants `mixed`, `hard`, or `soft`, if omitted the reset will be a soft reset to head, handlerFn: (err) |
|
|
||||||
| `.revert(commit [, options [, handlerFn]])` | reverts one or more commits in the working copy. The commit can be any regular commit-ish value (hash, name or offset such as `HEAD~2`) or a range of commits (eg: `master~5..master~2`). When supplied the [options](#how-to-specify-options) argument contain any options accepted by [git-revert](https://git-scm.com/docs/git-revert). |
|
|
||||||
| `.revparse([options], handlerFn)` | wraps git rev-parse. Primarily used to convert friendly commit references (ie branch names) to SHA1 hashes. Options should be an array of string options compatible with the [git rev-parse](http://git-scm.com/docs/git-rev-parse) |
|
|
||||||
| `.rm([fileA, ...], handlerFn)` | removes any number of files from source control |
|
|
||||||
| `.rmKeepLocal([fileA, ...], handlerFn)` | removes files from source control but leaves them on disk |
|
|
||||||
| `.silent(isSilent)` | sets whether the console should be used for logging errors (defaults to `true` when the `NODE_ENV` contains the string `prod`) |
|
|
||||||
| `.stash([options, ][ handlerFn])` | Stash the working directory, optional first argument can be an array of string arguments or [options](#how-to-specify-options) object to pass to the [git stash](https://git-scm.com/docs/git-stash) command. |
|
|
||||||
| `.stashList([options, ][handlerFn])` | Retrieves the stash list, optional first argument can be an object specifying `options.splitter` to override the default value of `;;;;`, alternatively options can be a set of arguments as supported by the `git stash list` command. |
|
|
||||||
| `.subModule(args [, handlerFn])` | Run a `git submodule` command with on or more arguments passed in as an `args` array |
|
|
||||||
| `.submoduleAdd(repo, path[, handlerFn])` | adds a new sub module |
|
|
||||||
| `.submoduleInit([args, ][handlerFn])` | inits sub modules, args should be an array of string arguments to pass to the `git submodule init` command |
|
|
||||||
| `.submoduleUpdate([args, ][handlerFn])` | updates sub modules, args should be an array of string arguments to pass to the `git submodule update` command |
|
|
||||||
| `.tag(args[], handlerFn)` | Runs any supported [git tag](https://git-scm.com/docs/git-tag) commands with arguments passed as an array of strings . |
|
|
||||||
| `.tags([options, ] handlerFn)` | list all tags, use the optional [options](#how-to-specify-options) object to set any options allows by the [git tag](https://git-scm.com/docs/git-tag) command. Tags will be sorted by semantic version number by default, for git versions 2.7 and above, use the `--sort` option to set a custom sort. |
|
|
||||||
| `.show([options], handlerFn)` | Show various types of objects, for example the file content at a certain commit. `options` is the single value string or array of string commands you want to run |
|
|
||||||
| `.status(handlerFn)` | gets the status of the current repo |
|
|
||||||
|
|
||||||
# How to Specify Options
|
|
||||||
|
|
||||||
For `.pull` or `.commit` options are included as an object, the keys of which will all be merged as trailing
|
|
||||||
arguments in the command string. When the value of the property in the options object is a `string`, that name value
|
|
||||||
pair will be included in the command string as `name=value`. For example:
|
|
||||||
|
|
||||||
```js
|
|
||||||
// results in 'git pull origin master --no-rebase'
|
|
||||||
git().pull('origin', 'master', {'--no-rebase': null})
|
|
||||||
|
|
||||||
// results in 'git pull origin master --rebase=true'
|
|
||||||
git().pull('origin', 'master', {'--rebase': 'true'})
|
|
||||||
```
|
|
||||||
|
|
||||||
# Release History
|
|
||||||
|
|
||||||
Bumped to a new major revision in the 1.x branch, now uses `ChildProcess.spawn` in place of `ChildProcess.exec` to
|
|
||||||
add escaping to the arguments passed to each of the tasks.
|
|
||||||
|
|
||||||
# Deprecated APIs
|
|
||||||
|
|
||||||
Use of these APIs is deprecated and should be avoided as support for them will be removed in future release:
|
|
||||||
|
|
||||||
`.then(func)` In versions 1.72 and below, it was possible to add a regular function call to the queue of tasks to be
|
|
||||||
run. As this name clashes with the use of Promises, in version 1.73.0 it is renamed to `.exec(fn)` and a warning will
|
|
||||||
be logged to `stdout` if `.then` is used. From version 2.0 the library will support promises without the need to wrap
|
|
||||||
or use the alternative require `require('simple-git/promise')`.
|
|
||||||
|
|
||||||
`.log([from, to], handlerFn)` list commits between `from` and `to` tags or branch, switch to supplying the revisions
|
|
||||||
as an options object instead.
|
|
||||||
|
|
||||||
# Complex Requests
|
|
||||||
|
|
||||||
When no suitable wrapper exists in the interface for creating a request, it is possible to run a command directly
|
|
||||||
using `git.raw([...], handler)`. The array of commands are passed directly to the `git` binary:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const git = require('simple-git');
|
|
||||||
const path = '/path/to/repo';
|
|
||||||
|
|
||||||
git(path).raw(
|
|
||||||
[
|
|
||||||
'config',
|
|
||||||
'--global',
|
|
||||||
'advice.pushNonFastForward',
|
|
||||||
'false'
|
|
||||||
], (err, result) => {
|
|
||||||
|
|
||||||
// err is null unless this command failed
|
|
||||||
// result is the raw output of this command
|
|
||||||
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
# Authentication
|
|
||||||
|
|
||||||
The easiest way to supply a username / password to the remote host is to include it in the URL, for example:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const USER = 'something';
|
|
||||||
const PASS = 'somewhere';
|
|
||||||
const REPO = 'github.com/username/private-repo';
|
|
||||||
|
|
||||||
const git = require('simple-git/promise');
|
|
||||||
const remote = `https://${USER}:${PASS}@${REPO}`;
|
|
||||||
|
|
||||||
git().silent(true)
|
|
||||||
.clone(remote)
|
|
||||||
.then(() => console.log('finished'))
|
|
||||||
.catch((err) => console.error('failed: ', err));
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
Be sure to enable silent mode to prevent fatal errors from being logged to stdout.
|
|
||||||
|
|
||||||
# Environment Variables
|
|
||||||
|
|
||||||
Pass one or more environment variables to the child processes spawned by `simple-git` with the `.env` method which
|
|
||||||
supports passing either an object of name=value pairs or setting a single variable at a time:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const GIT_SSH_COMMAND = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no";
|
|
||||||
|
|
||||||
const git = require('simple-git');
|
|
||||||
|
|
||||||
git()
|
|
||||||
.env('GIT_SSH_COMMAND', GIT_SSH_COMMAND)
|
|
||||||
.status((err, status) => { /* */ })
|
|
||||||
|
|
||||||
|
|
||||||
const gitP = require('simple-git/promise');
|
|
||||||
|
|
||||||
gitP().env({ ...process.env, GIT_SSH_COMMAND })
|
|
||||||
.status()
|
|
||||||
.then(status => { })
|
|
||||||
.catch(err => {});
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
Note - when passing environment variables into the child process, these will replace the standard `process.env`
|
|
||||||
variables, the example above creates a new object based on `process.env` but with the `GIT_SSH_COMMAND` property
|
|
||||||
added.
|
|
||||||
|
|
||||||
# TypeScript
|
|
||||||
|
|
||||||
To import with TypeScript:
|
|
||||||
|
|
||||||
```
|
|
||||||
import * as simplegit from 'simple-git/promise';
|
|
||||||
|
|
||||||
const git = simplegit();
|
|
||||||
git.status().then((status: StatusSummary) => { ... })
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
# Response Object Revisions
|
|
||||||
|
|
||||||
| ListLogLine | v1.110.0 | The default format expression used in `.log` splits ref data out of the `message` into a property of its own:
|
|
||||||
`{ message: 'Some commit message (some-branch-name)' }` becomes `{ message: 'Some commit message', refs: 'some-branch-name' }` |
|
|
||||||
| ListLogLine | v1.110.0 | The commit body content is now included in the default format expression and can be used to identify the content of merge conflicts eg:
|
|
||||||
`{ body: '# Conflicts:\n# some-file.txt' }` |
|
|
||||||
|
|
||||||
# Troubleshooting
|
|
||||||
|
|
||||||
### Every command returns ENOENT error message
|
|
||||||
|
|
||||||
There are a few potential reasons:
|
|
||||||
|
|
||||||
- `git` isn't available as a binary for the user running the main `node` process, custom paths to the binary can be used
|
|
||||||
with the `.customBinary(...)` api option.
|
|
||||||
- the working directory passed in to the main `simple-git` function isn't accessible, check it is read/write accessible
|
|
||||||
by the user running the `node` process.
|
|
||||||
|
|
||||||
### Log response properties are out of order
|
|
||||||
|
|
||||||
The properties of `git.log` are fetched using a `;` as a delimiter. If your commit messages use the `;` character,
|
|
||||||
supply a custom `splitter` in the options, for example: `git.log({ splitter: '|||' })`
|
|
||||||
|
|
||||||
# Examples
|
|
||||||
|
|
||||||
### async await with simple-git/promise:
|
|
||||||
|
|
||||||
```js
|
|
||||||
async function status (workingDir) {
|
|
||||||
const git = require('simple-git/promise');
|
|
||||||
|
|
||||||
let statusSummary = null;
|
|
||||||
try {
|
|
||||||
statusSummary = await git(workingDir).status();
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
// handle the error
|
|
||||||
}
|
|
||||||
|
|
||||||
return statusSummary;
|
|
||||||
}
|
|
||||||
|
|
||||||
// using the async function
|
|
||||||
status(__dirname + '/some-repo').then(status => console.log(status));
|
|
||||||
```
|
|
||||||
|
|
||||||
### Initialise a git repo if necessary
|
|
||||||
```js
|
|
||||||
const gitP = require('simple-git/promise');
|
|
||||||
const git = gitP(__dirname);
|
|
||||||
|
|
||||||
git.checkIsRepo()
|
|
||||||
.then(isRepo => !isRepo && initialiseRepo(git))
|
|
||||||
.then(() => git.fetch());
|
|
||||||
|
|
||||||
function initialiseRepo (git) {
|
|
||||||
return git.init()
|
|
||||||
.then(() => git.addRemote('origin', 'https://some.git.repo'))
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Update repo and get a list of tags
|
|
||||||
```js
|
|
||||||
require('simple-git')(__dirname + '/some-repo')
|
|
||||||
.pull()
|
|
||||||
.tags((err, tags) => console.log("Latest available tag: %s", tags.latest));
|
|
||||||
|
|
||||||
// update repo and when there are changes, restart the app
|
|
||||||
require('simple-git')()
|
|
||||||
.pull((err, update) => {
|
|
||||||
if(update && update.summary.changes) {
|
|
||||||
require('child_process').exec('npm restart');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
### Starting a new repo
|
|
||||||
```js
|
|
||||||
require('simple-git')()
|
|
||||||
.init()
|
|
||||||
.add('./*')
|
|
||||||
.commit("first commit!")
|
|
||||||
.addRemote('origin', 'https://github.com/user/repo.git')
|
|
||||||
.push('origin', 'master');
|
|
||||||
```
|
|
||||||
|
|
||||||
### push with `-u`
|
|
||||||
```js
|
|
||||||
require('simple-git')()
|
|
||||||
.add('./*')
|
|
||||||
.commit("first commit!")
|
|
||||||
.addRemote('origin', 'some-repo-url')
|
|
||||||
.push(['-u', 'origin', 'master'], () => console.log('done'));
|
|
||||||
```
|
|
||||||
|
|
||||||
### Piping to the console for long running tasks
|
|
||||||
```js
|
|
||||||
require('simple-git')()
|
|
||||||
.outputHandler((command, stdout, stderr) => {
|
|
||||||
stdout.pipe(process.stdout);
|
|
||||||
stderr.pipe(process.stderr);
|
|
||||||
})
|
|
||||||
.checkout('https://github.com/user/repo.git');
|
|
||||||
```
|
|
||||||
|
|
||||||
### Update repo and print messages when there are changes, restart the app
|
|
||||||
```js
|
|
||||||
require('simple-git')()
|
|
||||||
.exec(() => console.log('Starting pull...'))
|
|
||||||
.pull((err, update) => {
|
|
||||||
if(update && update.summary.changes) {
|
|
||||||
require('child_process').exec('npm restart');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.exec(() => console.log('pull done.'));
|
|
||||||
```
|
|
||||||
|
|
||||||
### Get a full commits list, and then only between 0.11.0 and 0.12.0 tags
|
|
||||||
```js
|
|
||||||
require('simple-git')()
|
|
||||||
.log((err, log) => console.log(log))
|
|
||||||
.log('0.11.0', '0.12.0', (err, log) => console.log(log));
|
|
||||||
```
|
|
||||||
|
|
||||||
### Set the local configuration for author, then author for an individual commit
|
|
||||||
```js
|
|
||||||
require('simple-git')()
|
|
||||||
.addConfig('user.name', 'Some One')
|
|
||||||
.addConfig('user.email', 'some@one.com')
|
|
||||||
.commit('committed as "Some One"', 'file-one')
|
|
||||||
.commit('committed as "Another Person"', 'file-two', { '--author': '"Another Person <another@person.com>"' });
|
|
||||||
```
|
|
||||||
|
|
||||||
### Get remote repositories
|
|
||||||
```js
|
|
||||||
require('simple-git')()
|
|
||||||
.listRemote(['--get-url'], (err, data) => {
|
|
||||||
if (!err) {
|
|
||||||
console.log('Remote url for repository at ' + __dirname + ':');
|
|
||||||
console.log(data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
```
|
|
||||||
-1591
File diff suppressed because it is too large
Load Diff
-14
@@ -1,14 +0,0 @@
|
|||||||
|
|
||||||
var Git = require('./git');
|
|
||||||
|
|
||||||
module.exports = function (baseDir) {
|
|
||||||
|
|
||||||
var dependencies = require('./util/dependencies');
|
|
||||||
|
|
||||||
if (baseDir && !dependencies.exists(baseDir, dependencies.exists.FOLDER)) {
|
|
||||||
throw new Error("Cannot use simple-git on a directory that does not exist.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Git(baseDir || process.cwd(), dependencies.childProcess(), dependencies.buffer());
|
|
||||||
};
|
|
||||||
|
|
||||||
-26
@@ -1,26 +0,0 @@
|
|||||||
|
|
||||||
module.exports = BranchDeletion;
|
|
||||||
|
|
||||||
function BranchDeletion (branch, hash) {
|
|
||||||
this.branch = branch;
|
|
||||||
this.hash = hash;
|
|
||||||
this.success = hash !== null;
|
|
||||||
}
|
|
||||||
|
|
||||||
BranchDeletion.deleteSuccessRegex = /(\S+)\s+\(\S+\s([^\)]+)\)/;
|
|
||||||
BranchDeletion.deleteErrorRegex = /^error[^']+'([^']+)'/;
|
|
||||||
|
|
||||||
BranchDeletion.parse = function (data, asArray) {
|
|
||||||
var result;
|
|
||||||
var branchDeletions = data.trim().split('\n').map(function (line) {
|
|
||||||
if (result = BranchDeletion.deleteSuccessRegex.exec(line)) {
|
|
||||||
return new BranchDeletion(result[1], result[2]);
|
|
||||||
}
|
|
||||||
else if (result = BranchDeletion.deleteErrorRegex.exec(line)) {
|
|
||||||
return new BranchDeletion(result[1], null);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.filter(Boolean);
|
|
||||||
|
|
||||||
return asArray ? branchDeletions : branchDeletions.pop();
|
|
||||||
};
|
|
||||||
-52
@@ -1,52 +0,0 @@
|
|||||||
|
|
||||||
module.exports = BranchSummary;
|
|
||||||
|
|
||||||
function BranchSummary () {
|
|
||||||
this.detached = false;
|
|
||||||
this.current = '';
|
|
||||||
this.all = [];
|
|
||||||
this.branches = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
BranchSummary.prototype.push = function (current, detached, name, commit, label) {
|
|
||||||
if (current) {
|
|
||||||
this.detached = detached;
|
|
||||||
this.current = name;
|
|
||||||
}
|
|
||||||
this.all.push(name);
|
|
||||||
this.branches[name] = {
|
|
||||||
current: current,
|
|
||||||
name: name,
|
|
||||||
commit: commit,
|
|
||||||
label: label
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
BranchSummary.detachedRegex = /^(\*?\s+)\((?:HEAD )?detached (?:from|at) (\S+)\)\s+([a-z0-9]+)\s(.*)$/;
|
|
||||||
BranchSummary.branchRegex = /^(\*?\s+)(\S+)\s+([a-z0-9]+)\s(.*)$/;
|
|
||||||
|
|
||||||
BranchSummary.parse = function (commit) {
|
|
||||||
var branchSummary = new BranchSummary();
|
|
||||||
|
|
||||||
commit.split('\n')
|
|
||||||
.forEach(function (line) {
|
|
||||||
var detached = true;
|
|
||||||
var branch = BranchSummary.detachedRegex.exec(line);
|
|
||||||
if (!branch) {
|
|
||||||
detached = false;
|
|
||||||
branch = BranchSummary.branchRegex.exec(line);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (branch) {
|
|
||||||
branchSummary.push(
|
|
||||||
branch[1].charAt(0) === '*',
|
|
||||||
detached,
|
|
||||||
branch[2],
|
|
||||||
branch[3],
|
|
||||||
branch[4]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return branchSummary;
|
|
||||||
};
|
|
||||||
-60
@@ -1,60 +0,0 @@
|
|||||||
|
|
||||||
module.exports = CommitSummary;
|
|
||||||
|
|
||||||
function CommitSummary () {
|
|
||||||
this.branch = '';
|
|
||||||
this.commit = '';
|
|
||||||
this.summary = {
|
|
||||||
changes: 0,
|
|
||||||
insertions: 0,
|
|
||||||
deletions: 0
|
|
||||||
};
|
|
||||||
this.author = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var COMMIT_BRANCH_MESSAGE_REGEX = /\[([^\s]+) ([^\]]+)/;
|
|
||||||
var COMMIT_AUTHOR_MESSAGE_REGEX = /\s*Author:\s(.+)/i;
|
|
||||||
|
|
||||||
function setBranchFromCommit (commitSummary, commitData) {
|
|
||||||
if (commitData) {
|
|
||||||
commitSummary.branch = commitData[1];
|
|
||||||
commitSummary.commit = commitData[2];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function setSummaryFromCommit (commitSummary, commitData) {
|
|
||||||
if (commitSummary.branch && commitData) {
|
|
||||||
commitSummary.summary.changes = commitData[1] || 0;
|
|
||||||
commitSummary.summary.insertions = commitData[2] || 0;
|
|
||||||
commitSummary.summary.deletions = commitData[3] || 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function setAuthorFromCommit (commitSummary, commitData) {
|
|
||||||
var parts = commitData[1].split('<');
|
|
||||||
var email = parts.pop();
|
|
||||||
|
|
||||||
if (email.indexOf('@') <= 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
commitSummary.author = {
|
|
||||||
email: email.substr(0, email.length - 1),
|
|
||||||
name: parts.join('<').trim()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
CommitSummary.parse = function (commit) {
|
|
||||||
var lines = commit.trim().split('\n');
|
|
||||||
var commitSummary = new CommitSummary();
|
|
||||||
|
|
||||||
setBranchFromCommit(commitSummary, COMMIT_BRANCH_MESSAGE_REGEX.exec(lines.shift()));
|
|
||||||
|
|
||||||
if (COMMIT_AUTHOR_MESSAGE_REGEX.test(lines[0])) {
|
|
||||||
setAuthorFromCommit(commitSummary, COMMIT_AUTHOR_MESSAGE_REGEX.exec(lines.shift()));
|
|
||||||
}
|
|
||||||
|
|
||||||
setSummaryFromCommit(commitSummary, /(\d+)[^,]*(?:,\s*(\d+)[^,]*)?(?:,\s*(\d+))?/g.exec(lines.shift()));
|
|
||||||
|
|
||||||
return commitSummary;
|
|
||||||
};
|
|
||||||
-92
@@ -1,92 +0,0 @@
|
|||||||
|
|
||||||
module.exports = DiffSummary;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The DiffSummary is returned as a response to getting `git().status()`
|
|
||||||
*
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
function DiffSummary () {
|
|
||||||
this.files = [];
|
|
||||||
this.insertions = 0;
|
|
||||||
this.deletions = 0;
|
|
||||||
this.changed = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of lines added
|
|
||||||
* @type {number}
|
|
||||||
*/
|
|
||||||
DiffSummary.prototype.insertions = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of lines deleted
|
|
||||||
* @type {number}
|
|
||||||
*/
|
|
||||||
DiffSummary.prototype.deletions = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of files changed
|
|
||||||
* @type {number}
|
|
||||||
*/
|
|
||||||
DiffSummary.prototype.changed = 0;
|
|
||||||
|
|
||||||
DiffSummary.parse = function (text) {
|
|
||||||
var line, handler;
|
|
||||||
|
|
||||||
var lines = text.trim().split('\n');
|
|
||||||
var status = new DiffSummary();
|
|
||||||
|
|
||||||
var summary = lines.pop();
|
|
||||||
if (summary) {
|
|
||||||
summary.trim().split(', ').forEach(function (text) {
|
|
||||||
var summary = /(\d+)\s([a-z]+)/.exec(text);
|
|
||||||
if (!summary) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (/files?/.test(summary[2])) {
|
|
||||||
status.changed = parseInt(summary[1], 10);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
status[summary[2].replace(/s$/, '') + 's'] = parseInt(summary[1], 10);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
while (line = lines.shift()) {
|
|
||||||
textFileChange(line, status.files) || binaryFileChange(line, status.files);
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
|
||||||
};
|
|
||||||
|
|
||||||
function textFileChange (line, files) {
|
|
||||||
line = line.trim().match(/^(.+)\s+\|\s+(\d+)(\s+[+\-]+)?$/);
|
|
||||||
|
|
||||||
if (line) {
|
|
||||||
var alterations = (line[3] || '').trim();
|
|
||||||
files.push({
|
|
||||||
file: line[1].trim(),
|
|
||||||
changes: parseInt(line[2], 10),
|
|
||||||
insertions: alterations.replace(/-/g, '').length,
|
|
||||||
deletions: alterations.replace(/\+/g, '').length,
|
|
||||||
binary: false
|
|
||||||
});
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function binaryFileChange (line, files) {
|
|
||||||
line = line.match(/^(.+) \|\s+Bin ([0-9.]+) -> ([0-9.]+) ([a-z]+)$/);
|
|
||||||
if (line) {
|
|
||||||
files.push({
|
|
||||||
file: line[1].trim(),
|
|
||||||
before: +line[2],
|
|
||||||
after: +line[3],
|
|
||||||
binary: true
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-55
@@ -1,55 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
function FetchSummary (raw) {
|
|
||||||
this.raw = raw;
|
|
||||||
|
|
||||||
this.remote = null;
|
|
||||||
this.branches = [];
|
|
||||||
this.tags = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
FetchSummary.parsers = [
|
|
||||||
[
|
|
||||||
/From (.+)$/, function (fetchSummary, matches) {
|
|
||||||
fetchSummary.remote = matches[0];
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
/\* \[new branch\]\s+(\S+)\s*\-> (.+)$/, function (fetchSummary, matches) {
|
|
||||||
fetchSummary.branches.push({
|
|
||||||
name: matches[0],
|
|
||||||
tracking: matches[1]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
/\* \[new tag\]\s+(\S+)\s*\-> (.+)$/, function (fetchSummary, matches) {
|
|
||||||
fetchSummary.tags.push({
|
|
||||||
name: matches[0],
|
|
||||||
tracking: matches[1]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
FetchSummary.parse = function (data) {
|
|
||||||
var fetchSummary = new FetchSummary(data);
|
|
||||||
|
|
||||||
String(data)
|
|
||||||
.trim()
|
|
||||||
.split('\n')
|
|
||||||
.forEach(function (line) {
|
|
||||||
var original = line.trim();
|
|
||||||
FetchSummary.parsers.some(function (parser) {
|
|
||||||
var parsed = parser[0].exec(original);
|
|
||||||
if (parsed) {
|
|
||||||
parser[1](fetchSummary, parsed.slice(1));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return fetchSummary;
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = FetchSummary;
|
|
||||||
-22
@@ -1,22 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
function FileStatusSummary (path, index, working_dir) {
|
|
||||||
this.path = path;
|
|
||||||
this.index = index;
|
|
||||||
this.working_dir = working_dir;
|
|
||||||
|
|
||||||
if ('R' === index + working_dir) {
|
|
||||||
var detail = FileStatusSummary.fromPathRegex.exec(path) || [null, path, path];
|
|
||||||
this.from = detail[1];
|
|
||||||
this.path = detail[2];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FileStatusSummary.fromPathRegex = /^(.+) -> (.+)$/;
|
|
||||||
|
|
||||||
FileStatusSummary.prototype = {
|
|
||||||
path: '',
|
|
||||||
from: ''
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = FileStatusSummary;
|
|
||||||
-72
@@ -1,72 +0,0 @@
|
|||||||
|
|
||||||
module.exports = ListLogSummary;
|
|
||||||
|
|
||||||
var DiffSummary = require('./DiffSummary');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The ListLogSummary is returned as a response to getting `git().log()` or `git().stashList()`
|
|
||||||
*
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
function ListLogSummary (all) {
|
|
||||||
this.all = all;
|
|
||||||
this.latest = all.length && all[0] || null;
|
|
||||||
this.total = all.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Detail for each of the log lines
|
|
||||||
* @type {ListLogLine[]}
|
|
||||||
*/
|
|
||||||
ListLogSummary.prototype.all = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Most recent entry in the log
|
|
||||||
* @type {ListLogLine}
|
|
||||||
*/
|
|
||||||
ListLogSummary.prototype.latest = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of items in the log
|
|
||||||
* @type {number}
|
|
||||||
*/
|
|
||||||
ListLogSummary.prototype.total = 0;
|
|
||||||
|
|
||||||
function ListLogLine (line, fields) {
|
|
||||||
for (var k = 0; k < fields.length; k++) {
|
|
||||||
this[fields[k]] = line[k] || '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* When the log was generated with a summary, the `diff` property contains as much detail
|
|
||||||
* as was provided in the log (whether generated with `--stat` or `--shortstat`.
|
|
||||||
* @type {DiffSummary}
|
|
||||||
*/
|
|
||||||
ListLogLine.prototype.diff = null;
|
|
||||||
|
|
||||||
ListLogSummary.START_BOUNDARY = 'òòòòòò ';
|
|
||||||
|
|
||||||
ListLogSummary.COMMIT_BOUNDARY = ' òò';
|
|
||||||
|
|
||||||
ListLogSummary.SPLITTER = ' ò ';
|
|
||||||
|
|
||||||
ListLogSummary.parse = function (text, splitter, fields) {
|
|
||||||
fields = fields || ['hash', 'date', 'message', 'refs', 'author_name', 'author_email'];
|
|
||||||
return new ListLogSummary(
|
|
||||||
text
|
|
||||||
.trim()
|
|
||||||
.split(ListLogSummary.START_BOUNDARY)
|
|
||||||
.filter(function(item) { return !!item.trim(); })
|
|
||||||
.map(function (item) {
|
|
||||||
var lineDetail = item.trim().split(ListLogSummary.COMMIT_BOUNDARY);
|
|
||||||
var listLogLine = new ListLogLine(lineDetail[0].trim().split(splitter), fields);
|
|
||||||
|
|
||||||
if (lineDetail.length > 1 && !!lineDetail[1].trim()) {
|
|
||||||
listLogLine.diff = DiffSummary.parse(lineDetail[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return listLogLine;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
};
|
|
||||||
-81
@@ -1,81 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
module.exports = MergeSummary;
|
|
||||||
|
|
||||||
var PullSummary = require('./PullSummary');
|
|
||||||
|
|
||||||
function MergeConflict (reason, file) {
|
|
||||||
this.reason = reason;
|
|
||||||
this.file = file;
|
|
||||||
}
|
|
||||||
|
|
||||||
MergeConflict.prototype.toString = function () {
|
|
||||||
return this.file + ':' + this.reason;
|
|
||||||
};
|
|
||||||
|
|
||||||
function MergeSummary () {
|
|
||||||
PullSummary.call(this);
|
|
||||||
|
|
||||||
this.conflicts = [];
|
|
||||||
this.merges = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
MergeSummary.prototype = Object.create(PullSummary.prototype);
|
|
||||||
|
|
||||||
MergeSummary.prototype.result = 'success';
|
|
||||||
|
|
||||||
MergeSummary.prototype.toString = function () {
|
|
||||||
if (this.conflicts.length) {
|
|
||||||
return 'CONFLICTS: ' + this.conflicts.join(', ');
|
|
||||||
}
|
|
||||||
return 'OK';
|
|
||||||
};
|
|
||||||
|
|
||||||
Object.defineProperty(MergeSummary.prototype, 'failed', {
|
|
||||||
get: function () {
|
|
||||||
return this.conflicts.length > 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
MergeSummary.parsers = [
|
|
||||||
{
|
|
||||||
test: /^Auto-merging\s+(.+)$/,
|
|
||||||
handle: function (result, mergeSummary) {
|
|
||||||
mergeSummary.merges.push(result[1]);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
test: /^CONFLICT\s+\((.+)\).+ in (.+)$/,
|
|
||||||
handle: function (result, mergeSummary) {
|
|
||||||
mergeSummary.conflicts.push(new MergeConflict(result[1], result[2]));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
test: /^Automatic merge failed;\s+(.+)$/,
|
|
||||||
handle: function (result, mergeSummary) {
|
|
||||||
mergeSummary.reason = result[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
MergeSummary.parse = function (output) {
|
|
||||||
let mergeSummary = new MergeSummary();
|
|
||||||
|
|
||||||
output.trim().split('\n').forEach(function (line) {
|
|
||||||
for (var i = 0, iMax = MergeSummary.parsers.length; i < iMax; i++) {
|
|
||||||
let parser = MergeSummary.parsers[i];
|
|
||||||
|
|
||||||
var result = parser.test.exec(line);
|
|
||||||
if (result) {
|
|
||||||
parser.handle(result, mergeSummary);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let pullSummary = PullSummary.parse(output);
|
|
||||||
if (pullSummary.summary.changes) {
|
|
||||||
Object.assign(mergeSummary, pullSummary);
|
|
||||||
}
|
|
||||||
|
|
||||||
return mergeSummary;
|
|
||||||
};
|
|
||||||
-32
@@ -1,32 +0,0 @@
|
|||||||
|
|
||||||
module.exports = MoveSummary;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The MoveSummary is returned as a response to getting `git().status()`
|
|
||||||
*
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
function MoveSummary () {
|
|
||||||
this.moves = [];
|
|
||||||
this.sources = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
MoveSummary.SUMMARY_REGEX = /^Renaming (.+) to (.+)$/;
|
|
||||||
|
|
||||||
MoveSummary.parse = function (text) {
|
|
||||||
var lines = text.split('\n');
|
|
||||||
var summary = new MoveSummary();
|
|
||||||
|
|
||||||
for (var i = 0, iMax = lines.length, line; i < iMax; i++) {
|
|
||||||
line = MoveSummary.SUMMARY_REGEX.exec(lines[i].trim());
|
|
||||||
|
|
||||||
if (line) {
|
|
||||||
summary.moves.push({
|
|
||||||
from: line[1],
|
|
||||||
to: line[2]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return summary;
|
|
||||||
};
|
|
||||||
-137
@@ -1,137 +0,0 @@
|
|||||||
|
|
||||||
module.exports = PullSummary;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The PullSummary is returned as a response to getting `git().pull()`
|
|
||||||
*
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
function PullSummary () {
|
|
||||||
this.files = [];
|
|
||||||
this.insertions = {};
|
|
||||||
this.deletions = {};
|
|
||||||
|
|
||||||
this.summary = {
|
|
||||||
changes: 0,
|
|
||||||
insertions: 0,
|
|
||||||
deletions: 0
|
|
||||||
};
|
|
||||||
|
|
||||||
this.created = [];
|
|
||||||
this.deleted = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Array of files that were created
|
|
||||||
* @type {string[]}
|
|
||||||
*/
|
|
||||||
PullSummary.prototype.created = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Array of files that were deleted
|
|
||||||
* @type {string[]}
|
|
||||||
*/
|
|
||||||
PullSummary.prototype.deleted = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The array of file paths/names that have been modified in any part of the pulled content
|
|
||||||
* @type {string[]}
|
|
||||||
*/
|
|
||||||
PullSummary.prototype.files = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A map of file path to number to show the number of insertions per file.
|
|
||||||
* @type {Object}
|
|
||||||
*/
|
|
||||||
PullSummary.prototype.insertions = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A map of file path to number to show the number of deletions per file.
|
|
||||||
* @type {Object}
|
|
||||||
*/
|
|
||||||
PullSummary.prototype.deletions = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Overall summary of changes/insertions/deletions and the number associated with each
|
|
||||||
* across all content that was pulled.
|
|
||||||
* @type {Object}
|
|
||||||
*/
|
|
||||||
PullSummary.prototype.summary = null;
|
|
||||||
|
|
||||||
PullSummary.FILE_UPDATE_REGEX = /^\s*(.+?)\s+\|\s+\d+\s*(\+*)(-*)/;
|
|
||||||
PullSummary.SUMMARY_REGEX = /(\d+)\D+((\d+)\D+\(\+\))?(\D+(\d+)\D+\(-\))?/;
|
|
||||||
PullSummary.ACTION_REGEX = /(create|delete) mode \d+ (.+)/;
|
|
||||||
|
|
||||||
PullSummary.parse = function (text) {
|
|
||||||
var pullSummary = new PullSummary;
|
|
||||||
var lines = text.split('\n');
|
|
||||||
|
|
||||||
while (lines.length) {
|
|
||||||
var line = lines.shift().trim();
|
|
||||||
if (!line) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
update(pullSummary, line) || summary(pullSummary, line) || action(pullSummary, line);
|
|
||||||
}
|
|
||||||
|
|
||||||
return pullSummary;
|
|
||||||
};
|
|
||||||
|
|
||||||
function update (pullSummary, line) {
|
|
||||||
|
|
||||||
var update = PullSummary.FILE_UPDATE_REGEX.exec(line);
|
|
||||||
if (!update) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
pullSummary.files.push(update[1]);
|
|
||||||
|
|
||||||
var insertions = update[2].length;
|
|
||||||
if (insertions) {
|
|
||||||
pullSummary.insertions[update[1]] = insertions;
|
|
||||||
}
|
|
||||||
|
|
||||||
var deletions = update[3].length;
|
|
||||||
if (deletions) {
|
|
||||||
pullSummary.deletions[update[1]] = deletions;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function summary (pullSummary, line) {
|
|
||||||
if (!pullSummary.files.length) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var update = PullSummary.SUMMARY_REGEX.exec(line);
|
|
||||||
if (!update || (update[3] === undefined && update[5] === undefined)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
pullSummary.summary.changes = +update[1] || 0;
|
|
||||||
pullSummary.summary.insertions = +update[3] || 0;
|
|
||||||
pullSummary.summary.deletions = +update[5] || 0;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function action (pullSummary, line) {
|
|
||||||
|
|
||||||
var match = PullSummary.ACTION_REGEX.exec(line);
|
|
||||||
if (!match) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var file = match[2];
|
|
||||||
|
|
||||||
if (pullSummary.files.indexOf(file) < 0) {
|
|
||||||
pullSummary.files.push(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
var container = (match[1] === 'create') ? pullSummary.created : pullSummary.deleted;
|
|
||||||
container.push(file);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
-181
@@ -1,181 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
var FileStatusSummary = require('./FileStatusSummary');
|
|
||||||
|
|
||||||
module.exports = StatusSummary;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The StatusSummary is returned as a response to getting `git().status()`
|
|
||||||
*
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
function StatusSummary () {
|
|
||||||
this.not_added = [];
|
|
||||||
this.conflicted = [];
|
|
||||||
this.created = [];
|
|
||||||
this.deleted = [];
|
|
||||||
this.modified = [];
|
|
||||||
this.renamed = [];
|
|
||||||
this.files = [];
|
|
||||||
this.staged = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of commits ahead of the tracked branch
|
|
||||||
* @type {number}
|
|
||||||
*/
|
|
||||||
StatusSummary.prototype.ahead = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of commits behind the tracked branch
|
|
||||||
* @type {number}
|
|
||||||
*/
|
|
||||||
StatusSummary.prototype.behind = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Name of the current branch
|
|
||||||
* @type {null}
|
|
||||||
*/
|
|
||||||
StatusSummary.prototype.current = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Name of the branch being tracked
|
|
||||||
* @type {string}
|
|
||||||
*/
|
|
||||||
StatusSummary.prototype.tracking = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* All files represented as an array of objects containing the `path` and status in `index` and
|
|
||||||
* in the `working_dir`.
|
|
||||||
*
|
|
||||||
* @type {Array}
|
|
||||||
*/
|
|
||||||
StatusSummary.prototype.files = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets whether this StatusSummary represents a clean working branch.
|
|
||||||
*
|
|
||||||
* @return {boolean}
|
|
||||||
*/
|
|
||||||
StatusSummary.prototype.isClean = function () {
|
|
||||||
return 0 === Object.keys(this).filter(function (name) {
|
|
||||||
return Array.isArray(this[name]) && this[name].length;
|
|
||||||
}, this).length;
|
|
||||||
};
|
|
||||||
|
|
||||||
StatusSummary.parsers = {
|
|
||||||
'##': function (line, status) {
|
|
||||||
var aheadReg = /ahead (\d+)/;
|
|
||||||
var behindReg = /behind (\d+)/;
|
|
||||||
var currentReg = /^(.+?(?=(?:\.{3}|\s|$)))/;
|
|
||||||
var trackingReg = /\.{3}(\S*)/;
|
|
||||||
var regexResult;
|
|
||||||
|
|
||||||
regexResult = aheadReg.exec(line);
|
|
||||||
status.ahead = regexResult && +regexResult[1] || 0;
|
|
||||||
|
|
||||||
regexResult = behindReg.exec(line);
|
|
||||||
status.behind = regexResult && +regexResult[1] || 0;
|
|
||||||
|
|
||||||
regexResult = currentReg.exec(line);
|
|
||||||
status.current = regexResult && regexResult[1];
|
|
||||||
|
|
||||||
regexResult = trackingReg.exec(line);
|
|
||||||
status.tracking = regexResult && regexResult[1];
|
|
||||||
},
|
|
||||||
|
|
||||||
'??': function (line, status) {
|
|
||||||
status.not_added.push(line);
|
|
||||||
},
|
|
||||||
|
|
||||||
A: function (line, status) {
|
|
||||||
status.created.push(line);
|
|
||||||
},
|
|
||||||
|
|
||||||
AM: function (line, status) {
|
|
||||||
status.created.push(line);
|
|
||||||
},
|
|
||||||
|
|
||||||
D: function (line, status) {
|
|
||||||
status.deleted.push(line);
|
|
||||||
},
|
|
||||||
|
|
||||||
M: function (line, status, indexState) {
|
|
||||||
status.modified.push(line);
|
|
||||||
|
|
||||||
if (indexState === 'M') {
|
|
||||||
status.staged.push(line);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
R: function (line, status) {
|
|
||||||
var detail = /^(.+) -> (.+)$/.exec(line) || [null, line, line];
|
|
||||||
|
|
||||||
status.renamed.push({
|
|
||||||
from: detail[1],
|
|
||||||
to: detail[2]
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
UU: function (line, status) {
|
|
||||||
status.conflicted.push(line);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
StatusSummary.parsers.MM = StatusSummary.parsers.M;
|
|
||||||
|
|
||||||
StatusSummary.parse = function (text) {
|
|
||||||
var file, linestr;
|
|
||||||
|
|
||||||
var lines = text.trim().split('\n');
|
|
||||||
var status = new StatusSummary();
|
|
||||||
|
|
||||||
while (linestr = lines.shift()) {
|
|
||||||
file = splitLine(linestr);
|
|
||||||
|
|
||||||
if (!file) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file.handler) {
|
|
||||||
file.handler(file.path, status, file.index, file.workingDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file.code !== '##') {
|
|
||||||
status.files.push(new FileStatusSummary(file.path, file.index, file.workingDir));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
function splitLine (lineStr) {
|
|
||||||
var line = lineStr.trim().match(/(..?)(\s+)(.*)/);
|
|
||||||
if (!line || !line[1].trim()) {
|
|
||||||
line = lineStr.trim().match(/(..?)\s+(.*)/);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!line) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var code = line[1];
|
|
||||||
if (line[2].length > 1) {
|
|
||||||
code += ' ';
|
|
||||||
}
|
|
||||||
if (code.length === 1 && line[2].length === 1) {
|
|
||||||
code = ' ' + code;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
raw: code,
|
|
||||||
code: code.trim(),
|
|
||||||
index: code.charAt(0),
|
|
||||||
workingDir: code.charAt(1),
|
|
||||||
handler: StatusSummary.parsers[code.trim()],
|
|
||||||
path: line[3]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
-50
@@ -1,50 +0,0 @@
|
|||||||
|
|
||||||
module.exports = TagList;
|
|
||||||
|
|
||||||
function TagList (tagList, latest) {
|
|
||||||
this.latest = latest;
|
|
||||||
this.all = tagList
|
|
||||||
}
|
|
||||||
|
|
||||||
TagList.parse = function (data, customSort) {
|
|
||||||
var number = function (input) {
|
|
||||||
if (typeof input === 'string') {
|
|
||||||
return parseInt(input.replace(/^\D+/g, ''), 10) || 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
var tags = data
|
|
||||||
.trim()
|
|
||||||
.split('\n')
|
|
||||||
.map(function (item) { return item.trim(); })
|
|
||||||
.filter(Boolean);
|
|
||||||
|
|
||||||
if (!customSort) {
|
|
||||||
tags.sort(function (tagA, tagB) {
|
|
||||||
var partsA = tagA.split('.');
|
|
||||||
var partsB = tagB.split('.');
|
|
||||||
|
|
||||||
if (partsA.length === 1 || partsB.length === 1) {
|
|
||||||
return tagA - tagB > 0 ? 1 : -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0, l = Math.max(partsA.length, partsB.length); i < l; i++) {
|
|
||||||
var a = number(partsA[i]);
|
|
||||||
var b = number(partsB[i]);
|
|
||||||
|
|
||||||
var diff = a - b;
|
|
||||||
if (diff) {
|
|
||||||
return diff > 0 ? 1 : -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var latest = customSort ? tags[0] : tags.filter(function (tag) { return tag.indexOf('.') >= 0; }).pop();
|
|
||||||
|
|
||||||
return new TagList(tags, latest);
|
|
||||||
};
|
|
||||||
-15
@@ -1,15 +0,0 @@
|
|||||||
|
|
||||||
module.exports = {
|
|
||||||
BranchDeleteSummary: require('./BranchDeleteSummary'),
|
|
||||||
BranchSummary: require('./BranchSummary'),
|
|
||||||
CommitSummary: require('./CommitSummary'),
|
|
||||||
DiffSummary: require('./DiffSummary'),
|
|
||||||
FetchSummary: require('./FetchSummary'),
|
|
||||||
FileStatusSummary: require('./FileStatusSummary'),
|
|
||||||
ListLogSummary: require('./ListLogSummary'),
|
|
||||||
MergeSummary: require('./MergeSummary'),
|
|
||||||
MoveSummary: require('./MoveSummary'),
|
|
||||||
PullSummary: require('./PullSummary'),
|
|
||||||
StatusSummary: require('./StatusSummary'),
|
|
||||||
TagList: require('./TagList'),
|
|
||||||
};
|
|
||||||
-10
@@ -1,10 +0,0 @@
|
|||||||
|
|
||||||
module.exports = function deferred () {
|
|
||||||
var d = {};
|
|
||||||
d.promise = new Promise(function (resolve, reject) {
|
|
||||||
d.resolve = resolve;
|
|
||||||
d.reject = reject
|
|
||||||
});
|
|
||||||
|
|
||||||
return d;
|
|
||||||
};
|
|
||||||
-12
@@ -1,12 +0,0 @@
|
|||||||
/**
|
|
||||||
* Exports the utilities `simple-git` depends upon to allow for mocking during a test
|
|
||||||
*/
|
|
||||||
module.exports = {
|
|
||||||
|
|
||||||
buffer: function () { return require('buffer').Buffer; },
|
|
||||||
|
|
||||||
childProcess: function () { return require('child_process'); },
|
|
||||||
|
|
||||||
exists: require('./exists')
|
|
||||||
|
|
||||||
};
|
|
||||||
-33
@@ -1,33 +0,0 @@
|
|||||||
|
|
||||||
var fs = require('fs');
|
|
||||||
|
|
||||||
function exists (path, isFile, isDirectory) {
|
|
||||||
try {
|
|
||||||
var matches = false;
|
|
||||||
var stat = fs.statSync(path);
|
|
||||||
|
|
||||||
matches = matches || isFile && stat.isFile();
|
|
||||||
matches = matches || isDirectory && stat.isDirectory();
|
|
||||||
|
|
||||||
return matches;
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
if (e.code === 'ENOENT') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = function (path, type) {
|
|
||||||
if (!type) {
|
|
||||||
return exists(path, true, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return exists(path, type & 1, type & 2);
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.FILE = 1;
|
|
||||||
|
|
||||||
module.exports.FOLDER = 2;
|
|
||||||
-178
@@ -1,178 +0,0 @@
|
|||||||
|
|
||||||
export interface BranchDeletionSummary {
|
|
||||||
branch: string;
|
|
||||||
hash: any;
|
|
||||||
success: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface BranchSummary {
|
|
||||||
detached: boolean;
|
|
||||||
current: string;
|
|
||||||
all: string[];
|
|
||||||
branches: {[key: string]: {
|
|
||||||
current: string,
|
|
||||||
name: string,
|
|
||||||
commit: string,
|
|
||||||
label: string
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CommitSummary {
|
|
||||||
author: null | {
|
|
||||||
email: string;
|
|
||||||
name: string;
|
|
||||||
};
|
|
||||||
branch: string;
|
|
||||||
commit: string;
|
|
||||||
summary: {
|
|
||||||
changes: number;
|
|
||||||
insertions: number;
|
|
||||||
deletions: number;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DiffResultTextFile {
|
|
||||||
file: string;
|
|
||||||
changes: number,
|
|
||||||
insertions: number;
|
|
||||||
deletions: number;
|
|
||||||
binary: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DiffResultBinaryFile {
|
|
||||||
file: string;
|
|
||||||
before: number;
|
|
||||||
after: number;
|
|
||||||
binary: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DiffResult {
|
|
||||||
/** The total number of files changed as reported in the summary line */
|
|
||||||
changed: number;
|
|
||||||
|
|
||||||
/** When present in the diff, lists the details of each file changed */
|
|
||||||
files: Array<DiffResultTextFile | DiffResultBinaryFile>;
|
|
||||||
|
|
||||||
/** The number of files changed with insertions */
|
|
||||||
insertions: number;
|
|
||||||
|
|
||||||
/** The number of files changed with deletions */
|
|
||||||
deletions: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FetchResult {
|
|
||||||
raw: string;
|
|
||||||
remote: string | null;
|
|
||||||
branches: {
|
|
||||||
name: string;
|
|
||||||
tracking: string;
|
|
||||||
}[];
|
|
||||||
tags: {
|
|
||||||
name: string;
|
|
||||||
tracking: string;
|
|
||||||
}[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface MoveSummary {
|
|
||||||
moves: any[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PullResult {
|
|
||||||
|
|
||||||
/** Array of all files that are referenced in the pull */
|
|
||||||
files: string[];
|
|
||||||
|
|
||||||
/** Map of file names to the number of insertions in that file */
|
|
||||||
insertions: {[key: string]: number};
|
|
||||||
|
|
||||||
/** Map of file names to the number of deletions in that file */
|
|
||||||
deletions: any;
|
|
||||||
|
|
||||||
summary: {
|
|
||||||
changes: number;
|
|
||||||
insertions: number;
|
|
||||||
deletions: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Array of file names that have been created */
|
|
||||||
created: string[];
|
|
||||||
|
|
||||||
/** Array of file names that have been deleted */
|
|
||||||
deleted: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface RemoteWithoutRefs {
|
|
||||||
name: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface RemoteWithRefs extends RemoteWithoutRefs {
|
|
||||||
refs: {
|
|
||||||
fetch: string;
|
|
||||||
push: string;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StatusResultRenamed {
|
|
||||||
from: string;
|
|
||||||
to: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StatusResult {
|
|
||||||
not_added: string[];
|
|
||||||
conflicted: string[];
|
|
||||||
created: string[];
|
|
||||||
deleted: string[];
|
|
||||||
modified: string[];
|
|
||||||
renamed: StatusResultRenamed[];
|
|
||||||
staged: string[];
|
|
||||||
files: {
|
|
||||||
path: string;
|
|
||||||
index: string;
|
|
||||||
working_dir: string;
|
|
||||||
}[];
|
|
||||||
ahead: number;
|
|
||||||
behind: number;
|
|
||||||
current: string;
|
|
||||||
tracking: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets whether this represents a clean working branch.
|
|
||||||
*/
|
|
||||||
isClean(): boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface TagResult {
|
|
||||||
all: string[];
|
|
||||||
latest: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DefaultLogFields {
|
|
||||||
hash: string;
|
|
||||||
date: string;
|
|
||||||
message: string;
|
|
||||||
refs: string;
|
|
||||||
body: string;
|
|
||||||
author_name: string;
|
|
||||||
author_email: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The ListLogLine represents a single entry in the `git.log`, the properties on the object
|
|
||||||
* are mixed in depending on the names used in the format (see `DefaultLogFields`), but some
|
|
||||||
* properties are dependent on the command used.
|
|
||||||
*/
|
|
||||||
export interface ListLogLine {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* When using a `--stat=4096` or `--shortstat` options in the `git.log` or `git.stashList`,
|
|
||||||
* each entry in the `ListLogSummary` will also have a `diff` property representing as much
|
|
||||||
* detail as was given in the response.
|
|
||||||
*/
|
|
||||||
diff?: DiffResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ListLogSummary<T = DefaultLogFields> {
|
|
||||||
all: ReadonlyArray<T & ListLogLine>;
|
|
||||||
total: number;
|
|
||||||
latest: T & ListLogLine;
|
|
||||||
}
|
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
/.idea
|
||||||
|
/node_modules
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
- 0.0.4 (2016/01/23)
|
||||||
|
- supported Node v0.12 or later.
|
||||||
|
|
||||||
|
- 0.0.3 (2014/01/20)
|
||||||
|
- fixed package.json
|
||||||
|
|
||||||
|
- 0.0.1 (2012/02/18)
|
||||||
|
- supported Node v0.6.x (0.6.11 or later).
|
||||||
|
|
||||||
|
- 0.0.0 (2012/02/11)
|
||||||
|
- first release.
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
The MIT License
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2018 Octokit contributors
|
Copyright (c) 2012 Koichi Kobayashi
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
+179
@@ -0,0 +1,179 @@
|
|||||||
|
# node-tunnel - HTTP/HTTPS Agents for tunneling proxies
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
var tunnel = require('tunnel');
|
||||||
|
|
||||||
|
var tunnelingAgent = tunnel.httpsOverHttp({
|
||||||
|
proxy: {
|
||||||
|
host: 'localhost',
|
||||||
|
port: 3128
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var req = https.request({
|
||||||
|
host: 'example.com',
|
||||||
|
port: 443,
|
||||||
|
agent: tunnelingAgent
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
$ npm install tunnel
|
||||||
|
|
||||||
|
## Usages
|
||||||
|
|
||||||
|
### HTTP over HTTP tunneling
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
var tunnelingAgent = tunnel.httpOverHttp({
|
||||||
|
maxSockets: poolSize, // Defaults to 5
|
||||||
|
|
||||||
|
proxy: { // Proxy settings
|
||||||
|
host: proxyHost, // Defaults to 'localhost'
|
||||||
|
port: proxyPort, // Defaults to 80
|
||||||
|
localAddress: localAddress, // Local interface if necessary
|
||||||
|
|
||||||
|
// Basic authorization for proxy server if necessary
|
||||||
|
proxyAuth: 'user:password',
|
||||||
|
|
||||||
|
// Header fields for proxy server if necessary
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'Node'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var req = http.request({
|
||||||
|
host: 'example.com',
|
||||||
|
port: 80,
|
||||||
|
agent: tunnelingAgent
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### HTTPS over HTTP tunneling
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
var tunnelingAgent = tunnel.httpsOverHttp({
|
||||||
|
maxSockets: poolSize, // Defaults to 5
|
||||||
|
|
||||||
|
// CA for origin server if necessary
|
||||||
|
ca: [ fs.readFileSync('origin-server-ca.pem')],
|
||||||
|
|
||||||
|
// Client certification for origin server if necessary
|
||||||
|
key: fs.readFileSync('origin-server-key.pem'),
|
||||||
|
cert: fs.readFileSync('origin-server-cert.pem'),
|
||||||
|
|
||||||
|
proxy: { // Proxy settings
|
||||||
|
host: proxyHost, // Defaults to 'localhost'
|
||||||
|
port: proxyPort, // Defaults to 80
|
||||||
|
localAddress: localAddress, // Local interface if necessary
|
||||||
|
|
||||||
|
// Basic authorization for proxy server if necessary
|
||||||
|
proxyAuth: 'user:password',
|
||||||
|
|
||||||
|
// Header fields for proxy server if necessary
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'Node'
|
||||||
|
},
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var req = https.request({
|
||||||
|
host: 'example.com',
|
||||||
|
port: 443,
|
||||||
|
agent: tunnelingAgent
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### HTTP over HTTPS tunneling
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
var tunnelingAgent = tunnel.httpOverHttps({
|
||||||
|
maxSockets: poolSize, // Defaults to 5
|
||||||
|
|
||||||
|
proxy: { // Proxy settings
|
||||||
|
host: proxyHost, // Defaults to 'localhost'
|
||||||
|
port: proxyPort, // Defaults to 443
|
||||||
|
localAddress: localAddress, // Local interface if necessary
|
||||||
|
|
||||||
|
// Basic authorization for proxy server if necessary
|
||||||
|
proxyAuth: 'user:password',
|
||||||
|
|
||||||
|
// Header fields for proxy server if necessary
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'Node'
|
||||||
|
},
|
||||||
|
|
||||||
|
// CA for proxy server if necessary
|
||||||
|
ca: [ fs.readFileSync('origin-server-ca.pem')],
|
||||||
|
|
||||||
|
// Server name for verification if necessary
|
||||||
|
servername: 'example.com',
|
||||||
|
|
||||||
|
// Client certification for proxy server if necessary
|
||||||
|
key: fs.readFileSync('origin-server-key.pem'),
|
||||||
|
cert: fs.readFileSync('origin-server-cert.pem'),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var req = http.request({
|
||||||
|
host: 'example.com',
|
||||||
|
port: 80,
|
||||||
|
agent: tunnelingAgent
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### HTTPS over HTTPS tunneling
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
var tunnelingAgent = tunnel.httpsOverHttps({
|
||||||
|
maxSockets: poolSize, // Defaults to 5
|
||||||
|
|
||||||
|
// CA for origin server if necessary
|
||||||
|
ca: [ fs.readFileSync('origin-server-ca.pem')],
|
||||||
|
|
||||||
|
// Client certification for origin server if necessary
|
||||||
|
key: fs.readFileSync('origin-server-key.pem'),
|
||||||
|
cert: fs.readFileSync('origin-server-cert.pem'),
|
||||||
|
|
||||||
|
proxy: { // Proxy settings
|
||||||
|
host: proxyHost, // Defaults to 'localhost'
|
||||||
|
port: proxyPort, // Defaults to 443
|
||||||
|
localAddress: localAddress, // Local interface if necessary
|
||||||
|
|
||||||
|
// Basic authorization for proxy server if necessary
|
||||||
|
proxyAuth: 'user:password',
|
||||||
|
|
||||||
|
// Header fields for proxy server if necessary
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'Node'
|
||||||
|
}
|
||||||
|
|
||||||
|
// CA for proxy server if necessary
|
||||||
|
ca: [ fs.readFileSync('origin-server-ca.pem')],
|
||||||
|
|
||||||
|
// Server name for verification if necessary
|
||||||
|
servername: 'example.com',
|
||||||
|
|
||||||
|
// Client certification for proxy server if necessary
|
||||||
|
key: fs.readFileSync('origin-server-key.pem'),
|
||||||
|
cert: fs.readFileSync('origin-server-cert.pem'),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var req = https.request({
|
||||||
|
host: 'example.com',
|
||||||
|
port: 443,
|
||||||
|
agent: tunnelingAgent
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## CONTRIBUTORS
|
||||||
|
* [Aleksis Brezas (abresas)](https://github.com/abresas)
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Licensed under the [MIT](https://github.com/koichik/node-tunnel/blob/master/LICENSE) license.
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
module.exports = require('./lib/tunnel');
|
||||||
+247
@@ -0,0 +1,247 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var net = require('net');
|
||||||
|
var tls = require('tls');
|
||||||
|
var http = require('http');
|
||||||
|
var https = require('https');
|
||||||
|
var events = require('events');
|
||||||
|
var assert = require('assert');
|
||||||
|
var util = require('util');
|
||||||
|
|
||||||
|
|
||||||
|
exports.httpOverHttp = httpOverHttp;
|
||||||
|
exports.httpsOverHttp = httpsOverHttp;
|
||||||
|
exports.httpOverHttps = httpOverHttps;
|
||||||
|
exports.httpsOverHttps = httpsOverHttps;
|
||||||
|
|
||||||
|
|
||||||
|
function httpOverHttp(options) {
|
||||||
|
var agent = new TunnelingAgent(options);
|
||||||
|
agent.request = http.request;
|
||||||
|
return agent;
|
||||||
|
}
|
||||||
|
|
||||||
|
function httpsOverHttp(options) {
|
||||||
|
var agent = new TunnelingAgent(options);
|
||||||
|
agent.request = http.request;
|
||||||
|
agent.createSocket = createSecureSocket;
|
||||||
|
return agent;
|
||||||
|
}
|
||||||
|
|
||||||
|
function httpOverHttps(options) {
|
||||||
|
var agent = new TunnelingAgent(options);
|
||||||
|
agent.request = https.request;
|
||||||
|
return agent;
|
||||||
|
}
|
||||||
|
|
||||||
|
function httpsOverHttps(options) {
|
||||||
|
var agent = new TunnelingAgent(options);
|
||||||
|
agent.request = https.request;
|
||||||
|
agent.createSocket = createSecureSocket;
|
||||||
|
return agent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function TunnelingAgent(options) {
|
||||||
|
var self = this;
|
||||||
|
self.options = options || {};
|
||||||
|
self.proxyOptions = self.options.proxy || {};
|
||||||
|
self.maxSockets = self.options.maxSockets || http.Agent.defaultMaxSockets;
|
||||||
|
self.requests = [];
|
||||||
|
self.sockets = [];
|
||||||
|
|
||||||
|
self.on('free', function onFree(socket, host, port, localAddress) {
|
||||||
|
var options = toOptions(host, port, localAddress);
|
||||||
|
for (var i = 0, len = self.requests.length; i < len; ++i) {
|
||||||
|
var pending = self.requests[i];
|
||||||
|
if (pending.host === options.host && pending.port === options.port) {
|
||||||
|
// Detect the request to connect same origin server,
|
||||||
|
// reuse the connection.
|
||||||
|
self.requests.splice(i, 1);
|
||||||
|
pending.request.onSocket(socket);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
socket.destroy();
|
||||||
|
self.removeSocket(socket);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
util.inherits(TunnelingAgent, events.EventEmitter);
|
||||||
|
|
||||||
|
TunnelingAgent.prototype.addRequest = function addRequest(req, host, port, localAddress) {
|
||||||
|
var self = this;
|
||||||
|
var options = mergeOptions({request: req}, self.options, toOptions(host, port, localAddress));
|
||||||
|
|
||||||
|
if (self.sockets.length >= this.maxSockets) {
|
||||||
|
// We are over limit so we'll add it to the queue.
|
||||||
|
self.requests.push(options);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we are under maxSockets create a new one.
|
||||||
|
self.createSocket(options, function(socket) {
|
||||||
|
socket.on('free', onFree);
|
||||||
|
socket.on('close', onCloseOrRemove);
|
||||||
|
socket.on('agentRemove', onCloseOrRemove);
|
||||||
|
req.onSocket(socket);
|
||||||
|
|
||||||
|
function onFree() {
|
||||||
|
self.emit('free', socket, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onCloseOrRemove(err) {
|
||||||
|
self.removeSocket(socket);
|
||||||
|
socket.removeListener('free', onFree);
|
||||||
|
socket.removeListener('close', onCloseOrRemove);
|
||||||
|
socket.removeListener('agentRemove', onCloseOrRemove);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
TunnelingAgent.prototype.createSocket = function createSocket(options, cb) {
|
||||||
|
var self = this;
|
||||||
|
var placeholder = {};
|
||||||
|
self.sockets.push(placeholder);
|
||||||
|
|
||||||
|
var connectOptions = mergeOptions({}, self.proxyOptions, {
|
||||||
|
method: 'CONNECT',
|
||||||
|
path: options.host + ':' + options.port,
|
||||||
|
agent: false
|
||||||
|
});
|
||||||
|
if (connectOptions.proxyAuth) {
|
||||||
|
connectOptions.headers = connectOptions.headers || {};
|
||||||
|
connectOptions.headers['Proxy-Authorization'] = 'Basic ' +
|
||||||
|
new Buffer(connectOptions.proxyAuth).toString('base64');
|
||||||
|
}
|
||||||
|
|
||||||
|
debug('making CONNECT request');
|
||||||
|
var connectReq = self.request(connectOptions);
|
||||||
|
connectReq.useChunkedEncodingByDefault = false; // for v0.6
|
||||||
|
connectReq.once('response', onResponse); // for v0.6
|
||||||
|
connectReq.once('upgrade', onUpgrade); // for v0.6
|
||||||
|
connectReq.once('connect', onConnect); // for v0.7 or later
|
||||||
|
connectReq.once('error', onError);
|
||||||
|
connectReq.end();
|
||||||
|
|
||||||
|
function onResponse(res) {
|
||||||
|
// Very hacky. This is necessary to avoid http-parser leaks.
|
||||||
|
res.upgrade = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onUpgrade(res, socket, head) {
|
||||||
|
// Hacky.
|
||||||
|
process.nextTick(function() {
|
||||||
|
onConnect(res, socket, head);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function onConnect(res, socket, head) {
|
||||||
|
connectReq.removeAllListeners();
|
||||||
|
socket.removeAllListeners();
|
||||||
|
|
||||||
|
if (res.statusCode === 200) {
|
||||||
|
assert.equal(head.length, 0);
|
||||||
|
debug('tunneling connection has established');
|
||||||
|
self.sockets[self.sockets.indexOf(placeholder)] = socket;
|
||||||
|
cb(socket);
|
||||||
|
} else {
|
||||||
|
debug('tunneling socket could not be established, statusCode=%d',
|
||||||
|
res.statusCode);
|
||||||
|
var error = new Error('tunneling socket could not be established, ' +
|
||||||
|
'statusCode=' + res.statusCode);
|
||||||
|
error.code = 'ECONNRESET';
|
||||||
|
options.request.emit('error', error);
|
||||||
|
self.removeSocket(placeholder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onError(cause) {
|
||||||
|
connectReq.removeAllListeners();
|
||||||
|
|
||||||
|
debug('tunneling socket could not be established, cause=%s\n',
|
||||||
|
cause.message, cause.stack);
|
||||||
|
var error = new Error('tunneling socket could not be established, ' +
|
||||||
|
'cause=' + cause.message);
|
||||||
|
error.code = 'ECONNRESET';
|
||||||
|
options.request.emit('error', error);
|
||||||
|
self.removeSocket(placeholder);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TunnelingAgent.prototype.removeSocket = function removeSocket(socket) {
|
||||||
|
var pos = this.sockets.indexOf(socket)
|
||||||
|
if (pos === -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.sockets.splice(pos, 1);
|
||||||
|
|
||||||
|
var pending = this.requests.shift();
|
||||||
|
if (pending) {
|
||||||
|
// If we have pending requests and a socket gets closed a new one
|
||||||
|
// needs to be created to take over in the pool for the one that closed.
|
||||||
|
this.createSocket(pending, function(socket) {
|
||||||
|
pending.request.onSocket(socket);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function createSecureSocket(options, cb) {
|
||||||
|
var self = this;
|
||||||
|
TunnelingAgent.prototype.createSocket.call(self, options, function(socket) {
|
||||||
|
var hostHeader = options.request.getHeader('host');
|
||||||
|
var tlsOptions = mergeOptions({}, self.options, {
|
||||||
|
socket: socket,
|
||||||
|
servername: hostHeader ? hostHeader.replace(/:.*$/, '') : options.host
|
||||||
|
});
|
||||||
|
|
||||||
|
// 0 is dummy port for v0.6
|
||||||
|
var secureSocket = tls.connect(0, tlsOptions);
|
||||||
|
self.sockets[self.sockets.indexOf(socket)] = secureSocket;
|
||||||
|
cb(secureSocket);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function toOptions(host, port, localAddress) {
|
||||||
|
if (typeof host === 'string') { // since v0.10
|
||||||
|
return {
|
||||||
|
host: host,
|
||||||
|
port: port,
|
||||||
|
localAddress: localAddress
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return host; // for v0.11 or later
|
||||||
|
}
|
||||||
|
|
||||||
|
function mergeOptions(target) {
|
||||||
|
for (var i = 1, len = arguments.length; i < len; ++i) {
|
||||||
|
var overrides = arguments[i];
|
||||||
|
if (typeof overrides === 'object') {
|
||||||
|
var keys = Object.keys(overrides);
|
||||||
|
for (var j = 0, keyLen = keys.length; j < keyLen; ++j) {
|
||||||
|
var k = keys[j];
|
||||||
|
if (overrides[k] !== undefined) {
|
||||||
|
target[k] = overrides[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var debug;
|
||||||
|
if (process.env.NODE_DEBUG && /\btunnel\b/.test(process.env.NODE_DEBUG)) {
|
||||||
|
debug = function() {
|
||||||
|
var args = Array.prototype.slice.call(arguments);
|
||||||
|
if (typeof args[0] === 'string') {
|
||||||
|
args[0] = 'TUNNEL: ' + args[0];
|
||||||
|
} else {
|
||||||
|
args.unshift('TUNNEL:');
|
||||||
|
}
|
||||||
|
console.error.apply(console, args);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
debug = function() {};
|
||||||
|
}
|
||||||
|
exports.debug = debug; // for test
|
||||||
+64
@@ -0,0 +1,64 @@
|
|||||||
|
{
|
||||||
|
"_from": "tunnel@0.0.4",
|
||||||
|
"_id": "tunnel@0.0.4",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha1-LTeFoVjBdMmhbcLARuxfxfF0IhM=",
|
||||||
|
"_location": "/tunnel",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "version",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "tunnel@0.0.4",
|
||||||
|
"name": "tunnel",
|
||||||
|
"escapedName": "tunnel",
|
||||||
|
"rawSpec": "0.0.4",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "0.0.4"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"/typed-rest-client"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.4.tgz",
|
||||||
|
"_shasum": "2d3785a158c174c9a16dc2c046ec5fc5f1742213",
|
||||||
|
"_spec": "tunnel@0.0.4",
|
||||||
|
"_where": "C:\\Users\\lzy\\Documents\\Source\\OpportunityLiu\\github-action-setup-xmake\\node_modules\\typed-rest-client",
|
||||||
|
"author": {
|
||||||
|
"name": "Koichi Kobayashi",
|
||||||
|
"email": "koichik@improvement.jp"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/koichik/node-tunnel/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "Node HTTP/HTTPS Agents for tunneling proxies",
|
||||||
|
"devDependencies": {
|
||||||
|
"mocha": "*",
|
||||||
|
"should": "*"
|
||||||
|
},
|
||||||
|
"directories": {
|
||||||
|
"lib": "./lib"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.6.11 <=0.7.0 || >=0.7.3"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/koichik/node-tunnel/",
|
||||||
|
"keywords": [
|
||||||
|
"http",
|
||||||
|
"https",
|
||||||
|
"agent",
|
||||||
|
"proxy",
|
||||||
|
"tunnel"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"main": "./index.js",
|
||||||
|
"name": "tunnel",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/koichik/node-tunnel.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "./node_modules/mocha/bin/mocha"
|
||||||
|
},
|
||||||
|
"version": "0.0.4"
|
||||||
|
}
|
||||||
+108
@@ -0,0 +1,108 @@
|
|||||||
|
var http = require('http');
|
||||||
|
var net = require('net');
|
||||||
|
var should = require('should');
|
||||||
|
var tunnel = require('../index');
|
||||||
|
|
||||||
|
describe('HTTP over HTTP', function() {
|
||||||
|
it('should finish without error', function(done) {
|
||||||
|
var serverPort = 3000;
|
||||||
|
var proxyPort = 3001;
|
||||||
|
var poolSize = 3;
|
||||||
|
var N = 10;
|
||||||
|
var serverConnect = 0;
|
||||||
|
var proxyConnect = 0;
|
||||||
|
var clientConnect = 0;
|
||||||
|
var server;
|
||||||
|
var proxy;
|
||||||
|
var agent;
|
||||||
|
|
||||||
|
server = http.createServer(function(req, res) {
|
||||||
|
tunnel.debug('SERVER: got request');
|
||||||
|
++serverConnect;
|
||||||
|
res.writeHead(200);
|
||||||
|
res.end('Hello' + req.url);
|
||||||
|
tunnel.debug('SERVER: sending response');
|
||||||
|
});
|
||||||
|
server.listen(serverPort, setupProxy);
|
||||||
|
|
||||||
|
function setupProxy() {
|
||||||
|
proxy = http.createServer(function(req, res) {
|
||||||
|
should.fail();
|
||||||
|
});
|
||||||
|
proxy.on('upgrade', onConnect); // for v0.6
|
||||||
|
proxy.on('connect', onConnect); // for v0.7 or later
|
||||||
|
|
||||||
|
function onConnect(req, clientSocket, head) {
|
||||||
|
tunnel.debug('PROXY: got CONNECT request');
|
||||||
|
|
||||||
|
req.method.should.equal('CONNECT');
|
||||||
|
req.url.should.equal('localhost:' + serverPort);
|
||||||
|
req.headers.should.not.have.property('transfer-encoding');
|
||||||
|
req.headers.should.have.property('proxy-authorization',
|
||||||
|
'Basic ' + new Buffer('user:password').toString('base64'));
|
||||||
|
++proxyConnect;
|
||||||
|
|
||||||
|
tunnel.debug('PROXY: creating a tunnel');
|
||||||
|
var serverSocket = net.connect(serverPort, function() {
|
||||||
|
tunnel.debug('PROXY: replying to client CONNECT request');
|
||||||
|
clientSocket.write('HTTP/1.1 200 Connection established\r\n\r\n');
|
||||||
|
clientSocket.pipe(serverSocket);
|
||||||
|
serverSocket.write(head);
|
||||||
|
serverSocket.pipe(clientSocket);
|
||||||
|
// workaround, see joyent/node#2524
|
||||||
|
serverSocket.on('end', function() {
|
||||||
|
clientSocket.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
proxy.listen(proxyPort, setupClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupClient() {
|
||||||
|
agent = tunnel.httpOverHttp({
|
||||||
|
maxSockets: poolSize,
|
||||||
|
proxy: {
|
||||||
|
port: proxyPort,
|
||||||
|
proxyAuth: 'user:password'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (var i = 0; i < N; ++i) {
|
||||||
|
doClientRequest(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
function doClientRequest(i) {
|
||||||
|
tunnel.debug('CLIENT: Making HTTP request (%d)', i);
|
||||||
|
var req = http.get({
|
||||||
|
port: serverPort,
|
||||||
|
path: '/' + i,
|
||||||
|
agent: agent
|
||||||
|
}, function(res) {
|
||||||
|
tunnel.debug('CLIENT: got HTTP response (%d)', i);
|
||||||
|
res.setEncoding('utf8');
|
||||||
|
res.on('data', function(data) {
|
||||||
|
data.should.equal('Hello/' + i);
|
||||||
|
});
|
||||||
|
res.on('end', function() {
|
||||||
|
++clientConnect;
|
||||||
|
if (clientConnect === N) {
|
||||||
|
proxy.close();
|
||||||
|
server.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
server.on('close', function() {
|
||||||
|
serverConnect.should.equal(N);
|
||||||
|
proxyConnect.should.equal(poolSize);
|
||||||
|
clientConnect.should.equal(N);
|
||||||
|
|
||||||
|
agent.sockets.should.be.empty;
|
||||||
|
agent.requests.should.be.empty;
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
+130
@@ -0,0 +1,130 @@
|
|||||||
|
var http = require('http');
|
||||||
|
var https = require('https');
|
||||||
|
var net = require('net');
|
||||||
|
var fs = require('fs');
|
||||||
|
var path = require('path');
|
||||||
|
var should = require('should');
|
||||||
|
var tunnel = require('../index');
|
||||||
|
|
||||||
|
function readPem(file) {
|
||||||
|
return fs.readFileSync(path.join('test/keys', file + '.pem'));
|
||||||
|
}
|
||||||
|
|
||||||
|
var proxyKey = readPem('proxy1-key');
|
||||||
|
var proxyCert = readPem('proxy1-cert');
|
||||||
|
var proxyCA = readPem('ca2-cert');
|
||||||
|
var clientKey = readPem('client1-key');
|
||||||
|
var clientCert = readPem('client1-cert');
|
||||||
|
var clientCA = readPem('ca3-cert');
|
||||||
|
|
||||||
|
describe('HTTP over HTTPS', function() {
|
||||||
|
it('should finish without error', function(done) {
|
||||||
|
var serverPort = 3004;
|
||||||
|
var proxyPort = 3005;
|
||||||
|
var poolSize = 3;
|
||||||
|
var N = 10;
|
||||||
|
var serverConnect = 0;
|
||||||
|
var proxyConnect = 0;
|
||||||
|
var clientConnect = 0;
|
||||||
|
var server;
|
||||||
|
var proxy;
|
||||||
|
var agent;
|
||||||
|
|
||||||
|
server = http.createServer(function(req, res) {
|
||||||
|
tunnel.debug('SERVER: got request');
|
||||||
|
++serverConnect;
|
||||||
|
res.writeHead(200);
|
||||||
|
res.end('Hello' + req.url);
|
||||||
|
tunnel.debug('SERVER: sending response');
|
||||||
|
});
|
||||||
|
server.listen(serverPort, setupProxy);
|
||||||
|
|
||||||
|
function setupProxy() {
|
||||||
|
proxy = https.createServer({
|
||||||
|
key: proxyKey,
|
||||||
|
cert: proxyCert,
|
||||||
|
ca: [clientCA],
|
||||||
|
requestCert: true,
|
||||||
|
rejectUnauthorized: true
|
||||||
|
}, function(req, res) {
|
||||||
|
should.fail();
|
||||||
|
});
|
||||||
|
proxy.on('upgrade', onConnect); // for v0.6
|
||||||
|
proxy.on('connect', onConnect); // for v0.7 or later
|
||||||
|
|
||||||
|
function onConnect(req, clientSocket, head) {
|
||||||
|
tunnel.debug('PROXY: got CONNECT request');
|
||||||
|
|
||||||
|
req.method.should.equal('CONNECT');
|
||||||
|
req.url.should.equal('localhost:' + serverPort);
|
||||||
|
req.headers.should.not.have.property('transfer-encoding');
|
||||||
|
++proxyConnect;
|
||||||
|
|
||||||
|
tunnel.debug('PROXY: creating a tunnel');
|
||||||
|
var serverSocket = net.connect(serverPort, function() {
|
||||||
|
tunnel.debug('PROXY: replying to client CONNECT request');
|
||||||
|
clientSocket.write('HTTP/1.1 200 Connection established\r\n\r\n');
|
||||||
|
clientSocket.pipe(serverSocket);
|
||||||
|
serverSocket.write(head);
|
||||||
|
serverSocket.pipe(clientSocket);
|
||||||
|
// workaround, see joyent/node#2524
|
||||||
|
serverSocket.on('end', function() {
|
||||||
|
clientSocket.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
proxy.listen(proxyPort, setupClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupClient() {
|
||||||
|
agent = tunnel.httpOverHttps({
|
||||||
|
maxSockets: poolSize,
|
||||||
|
proxy: {
|
||||||
|
port: proxyPort,
|
||||||
|
key: clientKey,
|
||||||
|
cert: clientCert,
|
||||||
|
ca: [proxyCA],
|
||||||
|
rejectUnauthorized: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (var i = 0; i < N; ++i) {
|
||||||
|
doClientRequest(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
function doClientRequest(i) {
|
||||||
|
tunnel.debug('CLIENT: Making HTTP request (%d)', i);
|
||||||
|
var req = http.get({
|
||||||
|
port: serverPort,
|
||||||
|
path: '/' + i,
|
||||||
|
agent: agent
|
||||||
|
}, function(res) {
|
||||||
|
tunnel.debug('CLIENT: got HTTP response (%d)', i);
|
||||||
|
res.setEncoding('utf8');
|
||||||
|
res.on('data', function(data) {
|
||||||
|
data.should.equal('Hello/' + i);
|
||||||
|
});
|
||||||
|
res.on('end', function() {
|
||||||
|
++clientConnect;
|
||||||
|
if (clientConnect === N) {
|
||||||
|
proxy.close();
|
||||||
|
server.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
server.on('close', function() {
|
||||||
|
serverConnect.should.equal(N);
|
||||||
|
proxyConnect.should.equal(poolSize);
|
||||||
|
clientConnect.should.equal(N);
|
||||||
|
|
||||||
|
var name = 'localhost:' + serverPort;
|
||||||
|
agent.sockets.should.be.empty;
|
||||||
|
agent.requests.should.be.empty;
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
+130
@@ -0,0 +1,130 @@
|
|||||||
|
var http = require('http');
|
||||||
|
var https = require('https');
|
||||||
|
var net = require('net');
|
||||||
|
var fs = require('fs');
|
||||||
|
var path = require('path');
|
||||||
|
var should = require('should');
|
||||||
|
var tunnel = require('../index');
|
||||||
|
|
||||||
|
function readPem(file) {
|
||||||
|
return fs.readFileSync(path.join('test/keys', file + '.pem'));
|
||||||
|
}
|
||||||
|
|
||||||
|
var serverKey = readPem('server1-key');
|
||||||
|
var serverCert = readPem('server1-cert');
|
||||||
|
var serverCA = readPem('ca1-cert');
|
||||||
|
var clientKey = readPem('client1-key');
|
||||||
|
var clientCert = readPem('client1-cert');
|
||||||
|
var clientCA = readPem('ca3-cert');
|
||||||
|
|
||||||
|
|
||||||
|
describe('HTTPS over HTTP', function() {
|
||||||
|
it('should finish without error', function(done) {
|
||||||
|
var serverPort = 3002;
|
||||||
|
var proxyPort = 3003;
|
||||||
|
var poolSize = 3;
|
||||||
|
var N = 10;
|
||||||
|
var serverConnect = 0;
|
||||||
|
var proxyConnect = 0;
|
||||||
|
var clientConnect = 0;
|
||||||
|
var server;
|
||||||
|
var proxy;
|
||||||
|
var agent;
|
||||||
|
|
||||||
|
server = https.createServer({
|
||||||
|
key: serverKey,
|
||||||
|
cert: serverCert,
|
||||||
|
ca: [clientCA],
|
||||||
|
requestCert: true,
|
||||||
|
rejectUnauthorized: true
|
||||||
|
}, function(req, res) {
|
||||||
|
tunnel.debug('SERVER: got request');
|
||||||
|
++serverConnect;
|
||||||
|
res.writeHead(200);
|
||||||
|
res.end('Hello' + req.url);
|
||||||
|
tunnel.debug('SERVER: sending response');
|
||||||
|
});
|
||||||
|
server.listen(serverPort, setupProxy);
|
||||||
|
|
||||||
|
function setupProxy() {
|
||||||
|
proxy = http.createServer(function(req, res) {
|
||||||
|
should.fail();
|
||||||
|
});
|
||||||
|
proxy.on('upgrade', onConnect); // for v0.6
|
||||||
|
proxy.on('connect', onConnect); // for v0.7 or later
|
||||||
|
|
||||||
|
function onConnect(req, clientSocket, head) {
|
||||||
|
tunnel.debug('PROXY: got CONNECT request');
|
||||||
|
|
||||||
|
req.method.should.equal('CONNECT');
|
||||||
|
req.url.should.equal('localhost:' + serverPort);
|
||||||
|
req.headers.should.not.have.property('transfer-encoding');
|
||||||
|
++proxyConnect;
|
||||||
|
|
||||||
|
var serverSocket = net.connect(serverPort, function() {
|
||||||
|
tunnel.debug('PROXY: replying to client CONNECT request');
|
||||||
|
clientSocket.write('HTTP/1.1 200 Connection established\r\n\r\n');
|
||||||
|
clientSocket.pipe(serverSocket);
|
||||||
|
serverSocket.write(head);
|
||||||
|
serverSocket.pipe(clientSocket);
|
||||||
|
// workaround, see joyent/node#2524
|
||||||
|
serverSocket.on('end', function() {
|
||||||
|
clientSocket.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
proxy.listen(proxyPort, setupClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupClient() {
|
||||||
|
agent = tunnel.httpsOverHttp({
|
||||||
|
maxSockets: poolSize,
|
||||||
|
key: clientKey,
|
||||||
|
cert: clientCert,
|
||||||
|
ca: [serverCA],
|
||||||
|
rejectUnauthorized: true,
|
||||||
|
proxy: {
|
||||||
|
port: proxyPort
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (var i = 0; i < N; ++i) {
|
||||||
|
doClientRequest(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
function doClientRequest(i) {
|
||||||
|
tunnel.debug('CLIENT: Making HTTPS request (%d)', i);
|
||||||
|
var req = https.get({
|
||||||
|
port: serverPort,
|
||||||
|
path: '/' + i,
|
||||||
|
agent: agent
|
||||||
|
}, function(res) {
|
||||||
|
tunnel.debug('CLIENT: got HTTPS response (%d)', i);
|
||||||
|
res.setEncoding('utf8');
|
||||||
|
res.on('data', function(data) {
|
||||||
|
data.should.equal('Hello/' + i);
|
||||||
|
});
|
||||||
|
res.on('end', function() {
|
||||||
|
++clientConnect;
|
||||||
|
if (clientConnect === N) {
|
||||||
|
proxy.close();
|
||||||
|
server.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
server.on('close', function() {
|
||||||
|
serverConnect.should.equal(N);
|
||||||
|
proxyConnect.should.equal(poolSize);
|
||||||
|
clientConnect.should.equal(N);
|
||||||
|
|
||||||
|
var name = 'localhost:' + serverPort;
|
||||||
|
agent.sockets.should.be.empty;
|
||||||
|
agent.requests.should.be.empty;
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
+261
@@ -0,0 +1,261 @@
|
|||||||
|
var http = require('http');
|
||||||
|
var https = require('https');
|
||||||
|
var net = require('net');
|
||||||
|
var fs = require('fs');
|
||||||
|
var path = require('path');
|
||||||
|
var should = require('should');
|
||||||
|
var tunnel = require('../index');
|
||||||
|
|
||||||
|
function readPem(file) {
|
||||||
|
return fs.readFileSync(path.join('test/keys', file + '.pem'));
|
||||||
|
}
|
||||||
|
|
||||||
|
var serverKey = readPem('server2-key');
|
||||||
|
var serverCert = readPem('server2-cert');
|
||||||
|
var serverCA = readPem('ca1-cert');
|
||||||
|
var proxyKey = readPem('proxy2-key');
|
||||||
|
var proxyCert = readPem('proxy2-cert');
|
||||||
|
var proxyCA = readPem('ca2-cert');
|
||||||
|
var client1Key = readPem('client1-key');
|
||||||
|
var client1Cert = readPem('client1-cert');
|
||||||
|
var client1CA = readPem('ca3-cert');
|
||||||
|
var client2Key = readPem('client2-key');
|
||||||
|
var client2Cert = readPem('client2-cert');
|
||||||
|
var client2CA = readPem('ca4-cert');
|
||||||
|
|
||||||
|
describe('HTTPS over HTTPS authentication failed', function() {
|
||||||
|
it('should finish without error', function(done) {
|
||||||
|
var serverPort = 3008;
|
||||||
|
var proxyPort = 3009;
|
||||||
|
var serverConnect = 0;
|
||||||
|
var proxyConnect = 0;
|
||||||
|
var clientRequest = 0;
|
||||||
|
var clientConnect = 0;
|
||||||
|
var clientError = 0;
|
||||||
|
var server;
|
||||||
|
var proxy;
|
||||||
|
|
||||||
|
server = https.createServer({
|
||||||
|
key: serverKey,
|
||||||
|
cert: serverCert,
|
||||||
|
ca: [client1CA],
|
||||||
|
requestCert: true,
|
||||||
|
rejectUnauthorized: true
|
||||||
|
}, function(req, res) {
|
||||||
|
tunnel.debug('SERVER: got request', req.url);
|
||||||
|
++serverConnect;
|
||||||
|
req.on('data', function(data) {
|
||||||
|
});
|
||||||
|
req.on('end', function() {
|
||||||
|
res.writeHead(200);
|
||||||
|
res.end('Hello, ' + serverConnect);
|
||||||
|
tunnel.debug('SERVER: sending response');
|
||||||
|
});
|
||||||
|
req.resume();
|
||||||
|
});
|
||||||
|
//server.addContext('server2', {
|
||||||
|
// key: serverKey,
|
||||||
|
// cert: serverCert,
|
||||||
|
// ca: [client1CA],
|
||||||
|
//});
|
||||||
|
server.listen(serverPort, setupProxy);
|
||||||
|
|
||||||
|
function setupProxy() {
|
||||||
|
proxy = https.createServer({
|
||||||
|
key: proxyKey,
|
||||||
|
cert: proxyCert,
|
||||||
|
ca: [client2CA],
|
||||||
|
requestCert: true,
|
||||||
|
rejectUnauthorized: true
|
||||||
|
}, function(req, res) {
|
||||||
|
should.fail();
|
||||||
|
});
|
||||||
|
//proxy.addContext('proxy2', {
|
||||||
|
// key: proxyKey,
|
||||||
|
// cert: proxyCert,
|
||||||
|
// ca: [client2CA],
|
||||||
|
//});
|
||||||
|
proxy.on('upgrade', onConnect); // for v0.6
|
||||||
|
proxy.on('connect', onConnect); // for v0.7 or later
|
||||||
|
|
||||||
|
function onConnect(req, clientSocket, head) {
|
||||||
|
req.method.should.equal('CONNECT');
|
||||||
|
req.url.should.equal('localhost:' + serverPort);
|
||||||
|
req.headers.should.not.have.property('transfer-encoding');
|
||||||
|
++proxyConnect;
|
||||||
|
|
||||||
|
var serverSocket = net.connect(serverPort, function() {
|
||||||
|
tunnel.debug('PROXY: replying to client CONNECT request');
|
||||||
|
clientSocket.write('HTTP/1.1 200 Connection established\r\n\r\n');
|
||||||
|
clientSocket.pipe(serverSocket);
|
||||||
|
serverSocket.write(head);
|
||||||
|
serverSocket.pipe(clientSocket);
|
||||||
|
// workaround, see #2524
|
||||||
|
serverSocket.on('end', function() {
|
||||||
|
clientSocket.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
proxy.listen(proxyPort, setupClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupClient() {
|
||||||
|
function doRequest(name, options, host) {
|
||||||
|
tunnel.debug('CLIENT: Making HTTPS request (%s)', name);
|
||||||
|
++clientRequest;
|
||||||
|
var agent = tunnel.httpsOverHttps(options);
|
||||||
|
var req = https.get({
|
||||||
|
host: 'localhost',
|
||||||
|
port: serverPort,
|
||||||
|
path: '/' + encodeURIComponent(name),
|
||||||
|
headers: {
|
||||||
|
host: host ? host : 'localhost',
|
||||||
|
},
|
||||||
|
rejectUnauthorized: true,
|
||||||
|
agent: agent
|
||||||
|
}, function(res) {
|
||||||
|
tunnel.debug('CLIENT: got HTTPS response (%s)', name);
|
||||||
|
++clientConnect;
|
||||||
|
res.on('data', function(data) {
|
||||||
|
});
|
||||||
|
res.on('end', function() {
|
||||||
|
req.emit('finish');
|
||||||
|
});
|
||||||
|
res.resume();
|
||||||
|
});
|
||||||
|
req.on('error', function(err) {
|
||||||
|
tunnel.debug('CLIENT: failed HTTP response (%s)', name, err);
|
||||||
|
++clientError;
|
||||||
|
req.emit('finish');
|
||||||
|
});
|
||||||
|
req.on('finish', function() {
|
||||||
|
if (clientConnect + clientError === clientRequest) {
|
||||||
|
proxy.close();
|
||||||
|
server.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
doRequest('no cert origin nor proxy', { // invalid
|
||||||
|
maxSockets: 1,
|
||||||
|
ca: [serverCA],
|
||||||
|
rejectUnauthorized: true,
|
||||||
|
// no certificate for origin server
|
||||||
|
proxy: {
|
||||||
|
port: proxyPort,
|
||||||
|
ca: [proxyCA],
|
||||||
|
rejectUnauthorized: true,
|
||||||
|
headers: {
|
||||||
|
host: 'proxy2'
|
||||||
|
}
|
||||||
|
// no certificate for proxy
|
||||||
|
}
|
||||||
|
}, 'server2');
|
||||||
|
|
||||||
|
doRequest('no cert proxy', { // invalid
|
||||||
|
maxSockets: 1,
|
||||||
|
ca: [serverCA],
|
||||||
|
rejectUnauthorized: true,
|
||||||
|
// client certification for origin server
|
||||||
|
key: client1Key,
|
||||||
|
cert: client1Cert,
|
||||||
|
proxy: {
|
||||||
|
port: proxyPort,
|
||||||
|
ca: [proxyCA],
|
||||||
|
rejectUnauthorized: true,
|
||||||
|
headers: {
|
||||||
|
host: 'proxy2'
|
||||||
|
}
|
||||||
|
// no certificate for proxy
|
||||||
|
}
|
||||||
|
}, 'server2');
|
||||||
|
|
||||||
|
doRequest('no cert origin', { // invalid
|
||||||
|
maxSockets: 1,
|
||||||
|
ca: [serverCA],
|
||||||
|
rejectUnauthorized: true,
|
||||||
|
// no certificate for origin server
|
||||||
|
proxy: {
|
||||||
|
port: proxyPort,
|
||||||
|
servername: 'proxy2',
|
||||||
|
ca: [proxyCA],
|
||||||
|
rejectUnauthorized: true,
|
||||||
|
headers: {
|
||||||
|
host: 'proxy2'
|
||||||
|
},
|
||||||
|
// client certification for proxy
|
||||||
|
key: client2Key,
|
||||||
|
cert: client2Cert
|
||||||
|
}
|
||||||
|
}, 'server2');
|
||||||
|
|
||||||
|
doRequest('invalid proxy server name', { // invalid
|
||||||
|
maxSockets: 1,
|
||||||
|
ca: [serverCA],
|
||||||
|
rejectUnauthorized: true,
|
||||||
|
// client certification for origin server
|
||||||
|
key: client1Key,
|
||||||
|
cert: client1Cert,
|
||||||
|
proxy: {
|
||||||
|
port: proxyPort,
|
||||||
|
ca: [proxyCA],
|
||||||
|
rejectUnauthorized: true,
|
||||||
|
// client certification for proxy
|
||||||
|
key: client2Key,
|
||||||
|
cert: client2Cert,
|
||||||
|
}
|
||||||
|
}, 'server2');
|
||||||
|
|
||||||
|
doRequest('invalid origin server name', { // invalid
|
||||||
|
maxSockets: 1,
|
||||||
|
ca: [serverCA],
|
||||||
|
rejectUnauthorized: true,
|
||||||
|
// client certification for origin server
|
||||||
|
key: client1Key,
|
||||||
|
cert: client1Cert,
|
||||||
|
proxy: {
|
||||||
|
port: proxyPort,
|
||||||
|
servername: 'proxy2',
|
||||||
|
ca: [proxyCA],
|
||||||
|
rejectUnauthorized: true,
|
||||||
|
headers: {
|
||||||
|
host: 'proxy2'
|
||||||
|
},
|
||||||
|
// client certification for proxy
|
||||||
|
key: client2Key,
|
||||||
|
cert: client2Cert
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
doRequest('valid', { // valid
|
||||||
|
maxSockets: 1,
|
||||||
|
ca: [serverCA],
|
||||||
|
rejectUnauthorized: true,
|
||||||
|
// client certification for origin server
|
||||||
|
key: client1Key,
|
||||||
|
cert: client1Cert,
|
||||||
|
proxy: {
|
||||||
|
port: proxyPort,
|
||||||
|
servername: 'proxy2',
|
||||||
|
ca: [proxyCA],
|
||||||
|
rejectUnauthorized: true,
|
||||||
|
headers: {
|
||||||
|
host: 'proxy2'
|
||||||
|
},
|
||||||
|
// client certification for proxy
|
||||||
|
key: client2Key,
|
||||||
|
cert: client2Cert
|
||||||
|
}
|
||||||
|
}, 'server2');
|
||||||
|
}
|
||||||
|
|
||||||
|
server.on('close', function() {
|
||||||
|
serverConnect.should.equal(1);
|
||||||
|
proxyConnect.should.equal(3);
|
||||||
|
clientConnect.should.equal(1);
|
||||||
|
clientError.should.equal(5);
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
+146
@@ -0,0 +1,146 @@
|
|||||||
|
var http = require('http');
|
||||||
|
var https = require('https');
|
||||||
|
var net = require('net');
|
||||||
|
var fs = require('fs');
|
||||||
|
var path = require('path');
|
||||||
|
var should = require('should');
|
||||||
|
var tunnel = require('../index.js');
|
||||||
|
|
||||||
|
function readPem(file) {
|
||||||
|
return fs.readFileSync(path.join('test/keys', file + '.pem'));
|
||||||
|
}
|
||||||
|
|
||||||
|
var serverKey = readPem('server1-key');
|
||||||
|
var serverCert = readPem('server1-cert');
|
||||||
|
var serverCA = readPem('ca1-cert');
|
||||||
|
var proxyKey = readPem('proxy1-key');
|
||||||
|
var proxyCert = readPem('proxy1-cert');
|
||||||
|
var proxyCA = readPem('ca2-cert');
|
||||||
|
var client1Key = readPem('client1-key');
|
||||||
|
var client1Cert = readPem('client1-cert');
|
||||||
|
var client1CA = readPem('ca3-cert');
|
||||||
|
var client2Key = readPem('client2-key');
|
||||||
|
var client2Cert = readPem('client2-cert');
|
||||||
|
var client2CA = readPem('ca4-cert');
|
||||||
|
|
||||||
|
describe('HTTPS over HTTPS', function() {
|
||||||
|
it('should finish without error', function(done) {
|
||||||
|
var serverPort = 3006;
|
||||||
|
var proxyPort = 3007;
|
||||||
|
var poolSize = 3;
|
||||||
|
var N = 5;
|
||||||
|
var serverConnect = 0;
|
||||||
|
var proxyConnect = 0;
|
||||||
|
var clientConnect = 0;
|
||||||
|
var server;
|
||||||
|
var proxy;
|
||||||
|
var agent;
|
||||||
|
|
||||||
|
server = https.createServer({
|
||||||
|
key: serverKey,
|
||||||
|
cert: serverCert,
|
||||||
|
ca: [client1CA],
|
||||||
|
requestCert: true,
|
||||||
|
rejectUnauthorized: true
|
||||||
|
}, function(req, res) {
|
||||||
|
tunnel.debug('SERVER: got request');
|
||||||
|
++serverConnect;
|
||||||
|
res.writeHead(200);
|
||||||
|
res.end('Hello' + req.url);
|
||||||
|
tunnel.debug('SERVER: sending response');
|
||||||
|
});
|
||||||
|
server.listen(serverPort, setupProxy);
|
||||||
|
|
||||||
|
function setupProxy() {
|
||||||
|
proxy = https.createServer({
|
||||||
|
key: proxyKey,
|
||||||
|
cert: proxyCert,
|
||||||
|
ca: [client2CA],
|
||||||
|
requestCert: true,
|
||||||
|
rejectUnauthorized: true
|
||||||
|
}, function(req, res) {
|
||||||
|
should.fail();
|
||||||
|
});
|
||||||
|
proxy.on('upgrade', onConnect); // for v0.6
|
||||||
|
proxy.on('connect', onConnect); // for v0.7 or later
|
||||||
|
|
||||||
|
function onConnect(req, clientSocket, head) {
|
||||||
|
tunnel.debug('PROXY: got CONNECT request');
|
||||||
|
req.method.should.equal('CONNECT');
|
||||||
|
req.url.should.equal('localhost:' + serverPort);
|
||||||
|
req.headers.should.not.have.property('transfer-encoding');
|
||||||
|
++proxyConnect;
|
||||||
|
|
||||||
|
var serverSocket = net.connect(serverPort, function() {
|
||||||
|
tunnel.debug('PROXY: replying to client CONNECT request');
|
||||||
|
clientSocket.write('HTTP/1.1 200 Connection established\r\n\r\n');
|
||||||
|
clientSocket.pipe(serverSocket);
|
||||||
|
serverSocket.write(head);
|
||||||
|
serverSocket.pipe(clientSocket);
|
||||||
|
// workaround, see joyent/node#2524
|
||||||
|
serverSocket.on('end', function() {
|
||||||
|
clientSocket.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
proxy.listen(proxyPort, setupClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupClient() {
|
||||||
|
agent = tunnel.httpsOverHttps({
|
||||||
|
maxSockets: poolSize,
|
||||||
|
// client certification for origin server
|
||||||
|
key: client1Key,
|
||||||
|
cert: client1Cert,
|
||||||
|
ca: [serverCA],
|
||||||
|
rejectUnauthroized: true,
|
||||||
|
proxy: {
|
||||||
|
port: proxyPort,
|
||||||
|
// client certification for proxy
|
||||||
|
key: client2Key,
|
||||||
|
cert: client2Cert,
|
||||||
|
ca: [proxyCA],
|
||||||
|
rejectUnauthroized: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (var i = 0; i < N; ++i) {
|
||||||
|
doClientRequest(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
function doClientRequest(i) {
|
||||||
|
tunnel.debug('CLIENT: Making HTTPS request (%d)', i);
|
||||||
|
var req = https.get({
|
||||||
|
port: serverPort,
|
||||||
|
path: '/' + i,
|
||||||
|
agent: agent
|
||||||
|
}, function(res) {
|
||||||
|
tunnel.debug('CLIENT: got HTTPS response (%d)', i);
|
||||||
|
res.setEncoding('utf8');
|
||||||
|
res.on('data', function(data) {
|
||||||
|
data.should.equal('Hello/' + i);
|
||||||
|
});
|
||||||
|
res.on('end', function() {
|
||||||
|
++clientConnect;
|
||||||
|
if (clientConnect === N) {
|
||||||
|
proxy.close();
|
||||||
|
server.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
server.on('close', function() {
|
||||||
|
serverConnect.should.equal(N);
|
||||||
|
proxyConnect.should.equal(poolSize);
|
||||||
|
clientConnect.should.equal(N);
|
||||||
|
|
||||||
|
var name = 'localhost:' + serverPort;
|
||||||
|
agent.sockets.should.be.empty;
|
||||||
|
agent.requests.should.be.empty;
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
+157
@@ -0,0 +1,157 @@
|
|||||||
|
all: server1-cert.pem server2-cert.pem proxy1-cert.pem proxy2-cert.pem client1-cert.pem client2-cert.pem
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create Certificate Authority: ca1
|
||||||
|
# ('password' is used for the CA password.)
|
||||||
|
#
|
||||||
|
ca1-cert.pem: ca1.cnf
|
||||||
|
openssl req -new -x509 -days 9999 -config ca1.cnf -keyout ca1-key.pem -out ca1-cert.pem
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create Certificate Authority: ca2
|
||||||
|
# ('password' is used for the CA password.)
|
||||||
|
#
|
||||||
|
ca2-cert.pem: ca2.cnf
|
||||||
|
openssl req -new -x509 -days 9999 -config ca2.cnf -keyout ca2-key.pem -out ca2-cert.pem
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create Certificate Authority: ca3
|
||||||
|
# ('password' is used for the CA password.)
|
||||||
|
#
|
||||||
|
ca3-cert.pem: ca3.cnf
|
||||||
|
openssl req -new -x509 -days 9999 -config ca3.cnf -keyout ca3-key.pem -out ca3-cert.pem
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create Certificate Authority: ca4
|
||||||
|
# ('password' is used for the CA password.)
|
||||||
|
#
|
||||||
|
ca4-cert.pem: ca4.cnf
|
||||||
|
openssl req -new -x509 -days 9999 -config ca4.cnf -keyout ca4-key.pem -out ca4-cert.pem
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# server1 is signed by ca1.
|
||||||
|
#
|
||||||
|
server1-key.pem:
|
||||||
|
openssl genrsa -out server1-key.pem 1024
|
||||||
|
|
||||||
|
server1-csr.pem: server1.cnf server1-key.pem
|
||||||
|
openssl req -new -config server1.cnf -key server1-key.pem -out server1-csr.pem
|
||||||
|
|
||||||
|
server1-cert.pem: server1-csr.pem ca1-cert.pem ca1-key.pem
|
||||||
|
openssl x509 -req \
|
||||||
|
-days 9999 \
|
||||||
|
-passin "pass:password" \
|
||||||
|
-in server1-csr.pem \
|
||||||
|
-CA ca1-cert.pem \
|
||||||
|
-CAkey ca1-key.pem \
|
||||||
|
-CAcreateserial \
|
||||||
|
-out server1-cert.pem
|
||||||
|
|
||||||
|
#
|
||||||
|
# server2 is signed by ca1.
|
||||||
|
#
|
||||||
|
server2-key.pem:
|
||||||
|
openssl genrsa -out server2-key.pem 1024
|
||||||
|
|
||||||
|
server2-csr.pem: server2.cnf server2-key.pem
|
||||||
|
openssl req -new -config server2.cnf -key server2-key.pem -out server2-csr.pem
|
||||||
|
|
||||||
|
server2-cert.pem: server2-csr.pem ca1-cert.pem ca1-key.pem
|
||||||
|
openssl x509 -req \
|
||||||
|
-days 9999 \
|
||||||
|
-passin "pass:password" \
|
||||||
|
-in server2-csr.pem \
|
||||||
|
-CA ca1-cert.pem \
|
||||||
|
-CAkey ca1-key.pem \
|
||||||
|
-CAcreateserial \
|
||||||
|
-out server2-cert.pem
|
||||||
|
|
||||||
|
server2-verify: server2-cert.pem ca1-cert.pem
|
||||||
|
openssl verify -CAfile ca1-cert.pem server2-cert.pem
|
||||||
|
|
||||||
|
#
|
||||||
|
# proxy1 is signed by ca2.
|
||||||
|
#
|
||||||
|
proxy1-key.pem:
|
||||||
|
openssl genrsa -out proxy1-key.pem 1024
|
||||||
|
|
||||||
|
proxy1-csr.pem: proxy1.cnf proxy1-key.pem
|
||||||
|
openssl req -new -config proxy1.cnf -key proxy1-key.pem -out proxy1-csr.pem
|
||||||
|
|
||||||
|
proxy1-cert.pem: proxy1-csr.pem ca2-cert.pem ca2-key.pem
|
||||||
|
openssl x509 -req \
|
||||||
|
-days 9999 \
|
||||||
|
-passin "pass:password" \
|
||||||
|
-in proxy1-csr.pem \
|
||||||
|
-CA ca2-cert.pem \
|
||||||
|
-CAkey ca2-key.pem \
|
||||||
|
-CAcreateserial \
|
||||||
|
-out proxy1-cert.pem
|
||||||
|
|
||||||
|
#
|
||||||
|
# proxy2 is signed by ca2.
|
||||||
|
#
|
||||||
|
proxy2-key.pem:
|
||||||
|
openssl genrsa -out proxy2-key.pem 1024
|
||||||
|
|
||||||
|
proxy2-csr.pem: proxy2.cnf proxy2-key.pem
|
||||||
|
openssl req -new -config proxy2.cnf -key proxy2-key.pem -out proxy2-csr.pem
|
||||||
|
|
||||||
|
proxy2-cert.pem: proxy2-csr.pem ca2-cert.pem ca2-key.pem
|
||||||
|
openssl x509 -req \
|
||||||
|
-days 9999 \
|
||||||
|
-passin "pass:password" \
|
||||||
|
-in proxy2-csr.pem \
|
||||||
|
-CA ca2-cert.pem \
|
||||||
|
-CAkey ca2-key.pem \
|
||||||
|
-CAcreateserial \
|
||||||
|
-out proxy2-cert.pem
|
||||||
|
|
||||||
|
proxy2-verify: proxy2-cert.pem ca2-cert.pem
|
||||||
|
openssl verify -CAfile ca2-cert.pem proxy2-cert.pem
|
||||||
|
|
||||||
|
#
|
||||||
|
# client1 is signed by ca3.
|
||||||
|
#
|
||||||
|
client1-key.pem:
|
||||||
|
openssl genrsa -out client1-key.pem 1024
|
||||||
|
|
||||||
|
client1-csr.pem: client1.cnf client1-key.pem
|
||||||
|
openssl req -new -config client1.cnf -key client1-key.pem -out client1-csr.pem
|
||||||
|
|
||||||
|
client1-cert.pem: client1-csr.pem ca3-cert.pem ca3-key.pem
|
||||||
|
openssl x509 -req \
|
||||||
|
-days 9999 \
|
||||||
|
-passin "pass:password" \
|
||||||
|
-in client1-csr.pem \
|
||||||
|
-CA ca3-cert.pem \
|
||||||
|
-CAkey ca3-key.pem \
|
||||||
|
-CAcreateserial \
|
||||||
|
-out client1-cert.pem
|
||||||
|
|
||||||
|
#
|
||||||
|
# client2 is signed by ca4.
|
||||||
|
#
|
||||||
|
client2-key.pem:
|
||||||
|
openssl genrsa -out client2-key.pem 1024
|
||||||
|
|
||||||
|
client2-csr.pem: client2.cnf client2-key.pem
|
||||||
|
openssl req -new -config client2.cnf -key client2-key.pem -out client2-csr.pem
|
||||||
|
|
||||||
|
client2-cert.pem: client2-csr.pem ca4-cert.pem ca4-key.pem
|
||||||
|
openssl x509 -req \
|
||||||
|
-days 9999 \
|
||||||
|
-passin "pass:password" \
|
||||||
|
-in client2-csr.pem \
|
||||||
|
-CA ca4-cert.pem \
|
||||||
|
-CAkey ca4-key.pem \
|
||||||
|
-CAcreateserial \
|
||||||
|
-out client2-cert.pem
|
||||||
|
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.pem *.srl
|
||||||
|
|
||||||
|
test: client-verify server2-verify proxy1-verify proxy2-verify client-verify
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIICKjCCAZMCCQDQ8o4kHKdCPDANBgkqhkiG9w0BAQUFADB6MQswCQYDVQQGEwJV
|
||||||
|
UzELMAkGA1UECBMCQ0ExCzAJBgNVBAcTAlNGMQ8wDQYDVQQKEwZKb3llbnQxEDAO
|
||||||
|
BgNVBAsTB05vZGUuanMxDDAKBgNVBAMTA2NhMTEgMB4GCSqGSIb3DQEJARYRcnlA
|
||||||
|
dGlueWNsb3Vkcy5vcmcwHhcNMTEwMzE0MTgyOTEyWhcNMzgwNzI5MTgyOTEyWjB9
|
||||||
|
MQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExCzAJBgNVBAcTAlNGMQ8wDQYDVQQK
|
||||||
|
EwZKb3llbnQxEDAOBgNVBAsTB05vZGUuanMxDzANBgNVBAMTBmFnZW50MTEgMB4G
|
||||||
|
CSqGSIb3DQEJARYRcnlAdGlueWNsb3Vkcy5vcmcwXDANBgkqhkiG9w0BAQEFAANL
|
||||||
|
ADBIAkEAnzpAqcoXZxWJz/WFK7BXwD23jlREyG11x7gkydteHvn6PrVBbB5yfu6c
|
||||||
|
bk8w3/Ar608AcyMQ9vHjkLQKH7cjEQIDAQABMA0GCSqGSIb3DQEBBQUAA4GBAKha
|
||||||
|
HqjCfTIut+m/idKy3AoFh48tBHo3p9Nl5uBjQJmahKdZAaiksL24Pl+NzPQ8LIU+
|
||||||
|
FyDHFp6OeJKN6HzZ72Bh9wpBVu6Uj1hwhZhincyTXT80wtSI/BoUAW8Ls2kwPdus
|
||||||
|
64LsJhhxqj2m4vPKNRbHB2QxnNrGi30CUf3kt3Ia
|
||||||
|
-----END CERTIFICATE-----
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
-----BEGIN CERTIFICATE REQUEST-----
|
||||||
|
MIIBXTCCAQcCAQAwfTELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMQswCQYDVQQH
|
||||||
|
EwJTRjEPMA0GA1UEChMGSm95ZW50MRAwDgYDVQQLEwdOb2RlLmpzMQ8wDQYDVQQD
|
||||||
|
EwZhZ2VudDExIDAeBgkqhkiG9w0BCQEWEXJ5QHRpbnljbG91ZHMub3JnMFwwDQYJ
|
||||||
|
KoZIhvcNAQEBBQADSwAwSAJBAJ86QKnKF2cVic/1hSuwV8A9t45URMhtdce4JMnb
|
||||||
|
Xh75+j61QWwecn7unG5PMN/wK+tPAHMjEPbx45C0Ch+3IxECAwEAAaAlMCMGCSqG
|
||||||
|
SIb3DQEJBzEWExRBIGNoYWxsZW5nZSBwYXNzd29yZDANBgkqhkiG9w0BAQUFAANB
|
||||||
|
AF+AfG64hNyYHum46m6i7RgnUBrJSOynGjs23TekV4he3QdMSAAPPqbll8W14+y3
|
||||||
|
vOo7/yQ2v2uTqxCjakUNPPs=
|
||||||
|
-----END CERTIFICATE REQUEST-----
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
MIIBOwIBAAJBAJ86QKnKF2cVic/1hSuwV8A9t45URMhtdce4JMnbXh75+j61QWwe
|
||||||
|
cn7unG5PMN/wK+tPAHMjEPbx45C0Ch+3IxECAwEAAQJBAI2cU1IuR+4IO87WPyAB
|
||||||
|
76kruoo87AeNQkjjvuQ/00+b/6IS45mcEP5Kw0NukbqBhIw2di9uQ9J51DJ/ZfQr
|
||||||
|
+YECIQDUHaN3ZjIdJ7/w8Yq9Zzz+3kY2F/xEz6e4ftOFW8bY2QIhAMAref+WYckC
|
||||||
|
oECgOLAvAxB1lI4j7oCbAaawfxKdnPj5AiEAi95rXx09aGpAsBGmSdScrPdG1v6j
|
||||||
|
83/2ebrvoZ1uFqkCIB0AssnrRVjUB6GZTNTyU3ERfdkx/RX1zvr8WkFR/lXpAiB7
|
||||||
|
cUZ1i8ZkZrPrdVgw2cb28UJM7qZHQnXcMHTXFFvxeQ==
|
||||||
|
-----END RSA PRIVATE KEY-----
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
[ req ]
|
||||||
|
default_bits = 1024
|
||||||
|
days = 999
|
||||||
|
distinguished_name = req_distinguished_name
|
||||||
|
attributes = req_attributes
|
||||||
|
prompt = no
|
||||||
|
|
||||||
|
[ req_distinguished_name ]
|
||||||
|
C = US
|
||||||
|
ST = CA
|
||||||
|
L = SF
|
||||||
|
O = Joyent
|
||||||
|
OU = Node.js
|
||||||
|
CN = agent1
|
||||||
|
emailAddress = ry@tinyclouds.org
|
||||||
|
|
||||||
|
[ req_attributes ]
|
||||||
|
challengePassword = A challenge password
|
||||||
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user