mirror of
https://github.com/bcomnes/deploy-to-neocities.git
synced 2026-01-17 06:56:30 +00:00
feat: use ncc for building
This commit is contained in:
parent
d991274fa5
commit
eb2da96745
10890
dist/index.js
vendored
Normal file
10890
dist/index.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
dist/index.js.map
vendored
Normal file
1
dist/index.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
3933
dist/sourcemap-register.js
vendored
Normal file
3933
dist/sourcemap-register.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
140
node_modules/@actions/core/README.md
generated
vendored
140
node_modules/@actions/core/README.md
generated
vendored
@ -1,140 +0,0 @@
|
||||
# `@actions/core`
|
||||
|
||||
> Core functions for setting results, logging, registering secrets and exporting variables across actions
|
||||
|
||||
## Usage
|
||||
|
||||
### Import the package
|
||||
|
||||
```js
|
||||
// javascript
|
||||
const core = require('@actions/core');
|
||||
|
||||
// typescript
|
||||
import * as core from '@actions/core';
|
||||
```
|
||||
|
||||
#### Inputs/Outputs
|
||||
|
||||
Action inputs can be read with `getInput`. Outputs can be set with `setOutput` which makes them available to be mapped into inputs of other actions to ensure they are decoupled.
|
||||
|
||||
```js
|
||||
const myInput = core.getInput('inputName', { required: true });
|
||||
|
||||
core.setOutput('outputKey', 'outputVal');
|
||||
```
|
||||
|
||||
#### Exporting variables
|
||||
|
||||
Since each step runs in a separate process, you can use `exportVariable` to add it to this step and future steps environment blocks.
|
||||
|
||||
```js
|
||||
core.exportVariable('envVar', 'Val');
|
||||
```
|
||||
|
||||
#### Setting a secret
|
||||
|
||||
Setting a secret registers the secret with the runner to ensure it is masked in logs.
|
||||
|
||||
```js
|
||||
core.setSecret('myPassword');
|
||||
```
|
||||
|
||||
#### PATH Manipulation
|
||||
|
||||
To make a tool's path available in the path for the remainder of the job (without altering the machine or containers state), use `addPath`. The runner will prepend the path given to the jobs PATH.
|
||||
|
||||
```js
|
||||
core.addPath('/path/to/mytool');
|
||||
```
|
||||
|
||||
#### Exit codes
|
||||
|
||||
You should use this library to set the failing exit code for your action. If status is not set and the script runs to completion, that will lead to a success.
|
||||
|
||||
```js
|
||||
const core = require('@actions/core');
|
||||
|
||||
try {
|
||||
// Do stuff
|
||||
}
|
||||
catch (err) {
|
||||
// setFailed logs the message and sets a failing exit code
|
||||
core.setFailed(`Action failed with error ${err}`);
|
||||
}
|
||||
|
||||
Note that `setNeutral` is not yet implemented in actions V2 but equivalent functionality is being planned.
|
||||
|
||||
```
|
||||
|
||||
#### Logging
|
||||
|
||||
Finally, this library provides some utilities for logging. Note that debug logging is hidden from the logs by default. This behavior can be toggled by enabling the [Step Debug Logs](../../docs/action-debugging.md#step-debug-logs).
|
||||
|
||||
```js
|
||||
const core = require('@actions/core');
|
||||
|
||||
const myInput = core.getInput('input');
|
||||
try {
|
||||
core.debug('Inside try block');
|
||||
|
||||
if (!myInput) {
|
||||
core.warning('myInput was not set');
|
||||
}
|
||||
|
||||
// Do stuff
|
||||
}
|
||||
catch (err) {
|
||||
core.error(`Error ${err}, action may still succeed though`);
|
||||
}
|
||||
```
|
||||
|
||||
This library can also wrap chunks of output in foldable groups.
|
||||
|
||||
```js
|
||||
const core = require('@actions/core')
|
||||
|
||||
// Manually wrap output
|
||||
core.startGroup('Do some function')
|
||||
doSomeFunction()
|
||||
core.endGroup()
|
||||
|
||||
// Wrap an asynchronous function call
|
||||
const result = await core.group('Do something async', async () => {
|
||||
const response = await doSomeHTTPRequest()
|
||||
return response
|
||||
})
|
||||
```
|
||||
|
||||
#### Action state
|
||||
|
||||
You can use this library to save state and get state for sharing information between a given wrapper action:
|
||||
|
||||
**action.yml**
|
||||
```yaml
|
||||
name: 'Wrapper action sample'
|
||||
inputs:
|
||||
name:
|
||||
default: 'GitHub'
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'main.js'
|
||||
post: 'cleanup.js'
|
||||
```
|
||||
|
||||
In action's `main.js`:
|
||||
|
||||
```js
|
||||
const core = require('@actions/core');
|
||||
|
||||
core.saveState("pidToKill", 12345);
|
||||
```
|
||||
|
||||
In action's `cleanup.js`:
|
||||
```js
|
||||
const core = require('@actions/core');
|
||||
|
||||
var pid = core.getState("pidToKill");
|
||||
|
||||
process.kill(pid);
|
||||
```
|
||||
16
node_modules/@actions/core/lib/command.d.ts
generated
vendored
16
node_modules/@actions/core/lib/command.d.ts
generated
vendored
@ -1,16 +0,0 @@
|
||||
interface CommandProperties {
|
||||
[key: string]: string;
|
||||
}
|
||||
/**
|
||||
* Commands
|
||||
*
|
||||
* Command Format:
|
||||
* ::name key=value,key=value::message
|
||||
*
|
||||
* Examples:
|
||||
* ::warning::This is the message
|
||||
* ::set-env name=MY_VAR::some value
|
||||
*/
|
||||
export declare function issueCommand(command: string, properties: CommandProperties, message: string): void;
|
||||
export declare function issue(name: string, message?: string): void;
|
||||
export {};
|
||||
78
node_modules/@actions/core/lib/command.js
generated
vendored
78
node_modules/@actions/core/lib/command.js
generated
vendored
@ -1,78 +0,0 @@
|
||||
"use strict";
|
||||
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 });
|
||||
const os = __importStar(require("os"));
|
||||
/**
|
||||
* Commands
|
||||
*
|
||||
* Command Format:
|
||||
* ::name key=value,key=value::message
|
||||
*
|
||||
* Examples:
|
||||
* ::warning::This is the message
|
||||
* ::set-env name=MY_VAR::some value
|
||||
*/
|
||||
function issueCommand(command, properties, message) {
|
||||
const cmd = new Command(command, properties, message);
|
||||
process.stdout.write(cmd.toString() + os.EOL);
|
||||
}
|
||||
exports.issueCommand = issueCommand;
|
||||
function issue(name, message = '') {
|
||||
issueCommand(name, {}, message);
|
||||
}
|
||||
exports.issue = issue;
|
||||
const CMD_STRING = '::';
|
||||
class Command {
|
||||
constructor(command, properties, message) {
|
||||
if (!command) {
|
||||
command = 'missing.command';
|
||||
}
|
||||
this.command = command;
|
||||
this.properties = properties;
|
||||
this.message = message;
|
||||
}
|
||||
toString() {
|
||||
let cmdStr = CMD_STRING + this.command;
|
||||
if (this.properties && Object.keys(this.properties).length > 0) {
|
||||
cmdStr += ' ';
|
||||
let first = true;
|
||||
for (const key in this.properties) {
|
||||
if (this.properties.hasOwnProperty(key)) {
|
||||
const val = this.properties[key];
|
||||
if (val) {
|
||||
if (first) {
|
||||
first = false;
|
||||
}
|
||||
else {
|
||||
cmdStr += ',';
|
||||
}
|
||||
cmdStr += `${key}=${escapeProperty(val)}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cmdStr += `${CMD_STRING}${escapeData(this.message)}`;
|
||||
return cmdStr;
|
||||
}
|
||||
}
|
||||
function escapeData(s) {
|
||||
return (s || '')
|
||||
.replace(/%/g, '%25')
|
||||
.replace(/\r/g, '%0D')
|
||||
.replace(/\n/g, '%0A');
|
||||
}
|
||||
function escapeProperty(s) {
|
||||
return (s || '')
|
||||
.replace(/%/g, '%25')
|
||||
.replace(/\r/g, '%0D')
|
||||
.replace(/\n/g, '%0A')
|
||||
.replace(/:/g, '%3A')
|
||||
.replace(/,/g, '%2C');
|
||||
}
|
||||
//# sourceMappingURL=command.js.map
|
||||
1
node_modules/@actions/core/lib/command.js.map
generated
vendored
1
node_modules/@actions/core/lib/command.js.map
generated
vendored
@ -1 +0,0 @@
|
||||
{"version":3,"file":"command.js","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uCAAwB;AAQxB;;;;;;;;;GASG;AACH,SAAgB,YAAY,CAC1B,OAAe,EACf,UAA6B,EAC7B,OAAe;IAEf,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAA;IACrD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAA;AAC/C,CAAC;AAPD,oCAOC;AAED,SAAgB,KAAK,CAAC,IAAY,EAAE,UAAkB,EAAE;IACtD,YAAY,CAAC,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC,CAAA;AACjC,CAAC;AAFD,sBAEC;AAED,MAAM,UAAU,GAAG,IAAI,CAAA;AAEvB,MAAM,OAAO;IAKX,YAAY,OAAe,EAAE,UAA6B,EAAE,OAAe;QACzE,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,GAAG,iBAAiB,CAAA;SAC5B;QAED,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,QAAQ;QACN,IAAI,MAAM,GAAG,UAAU,GAAG,IAAI,CAAC,OAAO,CAAA;QAEtC,IAAI,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YAC9D,MAAM,IAAI,GAAG,CAAA;YACb,IAAI,KAAK,GAAG,IAAI,CAAA;YAChB,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,UAAU,EAAE;gBACjC,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;oBACvC,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;oBAChC,IAAI,GAAG,EAAE;wBACP,IAAI,KAAK,EAAE;4BACT,KAAK,GAAG,KAAK,CAAA;yBACd;6BAAM;4BACL,MAAM,IAAI,GAAG,CAAA;yBACd;wBAED,MAAM,IAAI,GAAG,GAAG,IAAI,cAAc,CAAC,GAAG,CAAC,EAAE,CAAA;qBAC1C;iBACF;aACF;SACF;QAED,MAAM,IAAI,GAAG,UAAU,GAAG,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAA;QACpD,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAED,SAAS,UAAU,CAAC,CAAS;IAC3B,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;SACb,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;SACpB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;AAC1B,CAAC;AAED,SAAS,cAAc,CAAC,CAAS;IAC/B,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;SACb,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;SACpB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;SACpB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;AACzB,CAAC"}
|
||||
112
node_modules/@actions/core/lib/core.d.ts
generated
vendored
112
node_modules/@actions/core/lib/core.d.ts
generated
vendored
@ -1,112 +0,0 @@
|
||||
/**
|
||||
* Interface for getInput options
|
||||
*/
|
||||
export interface InputOptions {
|
||||
/** Optional. Whether the input is required. If required and not present, will throw. Defaults to false */
|
||||
required?: boolean;
|
||||
}
|
||||
/**
|
||||
* The code to exit an action
|
||||
*/
|
||||
export declare enum ExitCode {
|
||||
/**
|
||||
* A code indicating that the action was successful
|
||||
*/
|
||||
Success = 0,
|
||||
/**
|
||||
* A code indicating that the action was a failure
|
||||
*/
|
||||
Failure = 1
|
||||
}
|
||||
/**
|
||||
* Sets env variable for this action and future actions in the job
|
||||
* @param name the name of the variable to set
|
||||
* @param val the value of the variable
|
||||
*/
|
||||
export declare function exportVariable(name: string, val: string): void;
|
||||
/**
|
||||
* Registers a secret which will get masked from logs
|
||||
* @param secret value of the secret
|
||||
*/
|
||||
export declare function setSecret(secret: string): void;
|
||||
/**
|
||||
* Prepends inputPath to the PATH (for this action and future actions)
|
||||
* @param inputPath
|
||||
*/
|
||||
export declare function addPath(inputPath: string): void;
|
||||
/**
|
||||
* Gets the value of an input. The value is also trimmed.
|
||||
*
|
||||
* @param name name of the input to get
|
||||
* @param options optional. See InputOptions.
|
||||
* @returns string
|
||||
*/
|
||||
export declare function getInput(name: string, options?: InputOptions): string;
|
||||
/**
|
||||
* Sets the value of an output.
|
||||
*
|
||||
* @param name name of the output to set
|
||||
* @param value value to store
|
||||
*/
|
||||
export declare function setOutput(name: string, value: string): void;
|
||||
/**
|
||||
* Sets the action status to failed.
|
||||
* When the action exits it will be with an exit code of 1
|
||||
* @param message add error issue message
|
||||
*/
|
||||
export declare function setFailed(message: string): void;
|
||||
/**
|
||||
* Writes debug message to user log
|
||||
* @param message debug message
|
||||
*/
|
||||
export declare function debug(message: string): void;
|
||||
/**
|
||||
* Adds an error issue
|
||||
* @param message error issue message
|
||||
*/
|
||||
export declare function error(message: string): void;
|
||||
/**
|
||||
* Adds an warning issue
|
||||
* @param message warning issue message
|
||||
*/
|
||||
export declare function warning(message: string): void;
|
||||
/**
|
||||
* Writes info to log with console.log.
|
||||
* @param message info message
|
||||
*/
|
||||
export declare function info(message: string): void;
|
||||
/**
|
||||
* Begin an output group.
|
||||
*
|
||||
* Output until the next `groupEnd` will be foldable in this group
|
||||
*
|
||||
* @param name The name of the output group
|
||||
*/
|
||||
export declare function startGroup(name: string): void;
|
||||
/**
|
||||
* End an output group.
|
||||
*/
|
||||
export declare function endGroup(): void;
|
||||
/**
|
||||
* Wrap an asynchronous function call in a group.
|
||||
*
|
||||
* Returns the same type as the function itself.
|
||||
*
|
||||
* @param name The name of the group
|
||||
* @param fn The function to wrap in the group
|
||||
*/
|
||||
export declare function group<T>(name: string, fn: () => Promise<T>): Promise<T>;
|
||||
/**
|
||||
* Saves state for current action, the state can only be retrieved by this action's post job execution.
|
||||
*
|
||||
* @param name name of the state to store
|
||||
* @param value value to store
|
||||
*/
|
||||
export declare function saveState(name: string, value: string): void;
|
||||
/**
|
||||
* Gets the value of an state set by this action's main execution.
|
||||
*
|
||||
* @param name name of the state to get
|
||||
* @returns string
|
||||
*/
|
||||
export declare function getState(name: string): string;
|
||||
202
node_modules/@actions/core/lib/core.js
generated
vendored
202
node_modules/@actions/core/lib/core.js
generated
vendored
@ -1,202 +0,0 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
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 });
|
||||
const command_1 = require("./command");
|
||||
const os = __importStar(require("os"));
|
||||
const path = __importStar(require("path"));
|
||||
/**
|
||||
* The code to exit an action
|
||||
*/
|
||||
var ExitCode;
|
||||
(function (ExitCode) {
|
||||
/**
|
||||
* A code indicating that the action was successful
|
||||
*/
|
||||
ExitCode[ExitCode["Success"] = 0] = "Success";
|
||||
/**
|
||||
* A code indicating that the action was a failure
|
||||
*/
|
||||
ExitCode[ExitCode["Failure"] = 1] = "Failure";
|
||||
})(ExitCode = exports.ExitCode || (exports.ExitCode = {}));
|
||||
//-----------------------------------------------------------------------
|
||||
// Variables
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Sets env variable for this action and future actions in the job
|
||||
* @param name the name of the variable to set
|
||||
* @param val the value of the variable
|
||||
*/
|
||||
function exportVariable(name, val) {
|
||||
process.env[name] = val;
|
||||
command_1.issueCommand('set-env', { name }, val);
|
||||
}
|
||||
exports.exportVariable = exportVariable;
|
||||
/**
|
||||
* Registers a secret which will get masked from logs
|
||||
* @param secret value of the secret
|
||||
*/
|
||||
function setSecret(secret) {
|
||||
command_1.issueCommand('add-mask', {}, secret);
|
||||
}
|
||||
exports.setSecret = setSecret;
|
||||
/**
|
||||
* Prepends inputPath to the PATH (for this action and future actions)
|
||||
* @param inputPath
|
||||
*/
|
||||
function addPath(inputPath) {
|
||||
command_1.issueCommand('add-path', {}, inputPath);
|
||||
process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`;
|
||||
}
|
||||
exports.addPath = addPath;
|
||||
/**
|
||||
* Gets the value of an input. The value is also trimmed.
|
||||
*
|
||||
* @param name name of the input to get
|
||||
* @param options optional. See InputOptions.
|
||||
* @returns string
|
||||
*/
|
||||
function getInput(name, options) {
|
||||
const val = process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || '';
|
||||
if (options && options.required && !val) {
|
||||
throw new Error(`Input required and not supplied: ${name}`);
|
||||
}
|
||||
return val.trim();
|
||||
}
|
||||
exports.getInput = getInput;
|
||||
/**
|
||||
* Sets the value of an output.
|
||||
*
|
||||
* @param name name of the output to set
|
||||
* @param value value to store
|
||||
*/
|
||||
function setOutput(name, value) {
|
||||
command_1.issueCommand('set-output', { name }, value);
|
||||
}
|
||||
exports.setOutput = setOutput;
|
||||
//-----------------------------------------------------------------------
|
||||
// Results
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Sets the action status to failed.
|
||||
* When the action exits it will be with an exit code of 1
|
||||
* @param message add error issue message
|
||||
*/
|
||||
function setFailed(message) {
|
||||
process.exitCode = ExitCode.Failure;
|
||||
error(message);
|
||||
}
|
||||
exports.setFailed = setFailed;
|
||||
//-----------------------------------------------------------------------
|
||||
// Logging Commands
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Writes debug message to user log
|
||||
* @param message debug message
|
||||
*/
|
||||
function debug(message) {
|
||||
command_1.issueCommand('debug', {}, message);
|
||||
}
|
||||
exports.debug = debug;
|
||||
/**
|
||||
* Adds an error issue
|
||||
* @param message error issue message
|
||||
*/
|
||||
function error(message) {
|
||||
command_1.issue('error', message);
|
||||
}
|
||||
exports.error = error;
|
||||
/**
|
||||
* Adds an warning issue
|
||||
* @param message warning issue message
|
||||
*/
|
||||
function warning(message) {
|
||||
command_1.issue('warning', message);
|
||||
}
|
||||
exports.warning = warning;
|
||||
/**
|
||||
* Writes info to log with console.log.
|
||||
* @param message info message
|
||||
*/
|
||||
function info(message) {
|
||||
process.stdout.write(message + os.EOL);
|
||||
}
|
||||
exports.info = info;
|
||||
/**
|
||||
* Begin an output group.
|
||||
*
|
||||
* Output until the next `groupEnd` will be foldable in this group
|
||||
*
|
||||
* @param name The name of the output group
|
||||
*/
|
||||
function startGroup(name) {
|
||||
command_1.issue('group', name);
|
||||
}
|
||||
exports.startGroup = startGroup;
|
||||
/**
|
||||
* End an output group.
|
||||
*/
|
||||
function endGroup() {
|
||||
command_1.issue('endgroup');
|
||||
}
|
||||
exports.endGroup = endGroup;
|
||||
/**
|
||||
* Wrap an asynchronous function call in a group.
|
||||
*
|
||||
* Returns the same type as the function itself.
|
||||
*
|
||||
* @param name The name of the group
|
||||
* @param fn The function to wrap in the group
|
||||
*/
|
||||
function group(name, fn) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
startGroup(name);
|
||||
let result;
|
||||
try {
|
||||
result = yield fn();
|
||||
}
|
||||
finally {
|
||||
endGroup();
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
exports.group = group;
|
||||
//-----------------------------------------------------------------------
|
||||
// Wrapper action state
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Saves state for current action, the state can only be retrieved by this action's post job execution.
|
||||
*
|
||||
* @param name name of the state to store
|
||||
* @param value value to store
|
||||
*/
|
||||
function saveState(name, value) {
|
||||
command_1.issueCommand('save-state', { name }, value);
|
||||
}
|
||||
exports.saveState = saveState;
|
||||
/**
|
||||
* Gets the value of an state set by this action's main execution.
|
||||
*
|
||||
* @param name name of the state to get
|
||||
* @returns string
|
||||
*/
|
||||
function getState(name) {
|
||||
return process.env[`STATE_${name}`] || '';
|
||||
}
|
||||
exports.getState = getState;
|
||||
//# sourceMappingURL=core.js.map
|
||||
1
node_modules/@actions/core/lib/core.js.map
generated
vendored
1
node_modules/@actions/core/lib/core.js.map
generated
vendored
@ -1 +0,0 @@
|
||||
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,uCAA6C;AAE7C,uCAAwB;AACxB,2CAA4B;AAU5B;;GAEG;AACH,IAAY,QAUX;AAVD,WAAY,QAAQ;IAClB;;OAEG;IACH,6CAAW,CAAA;IAEX;;OAEG;IACH,6CAAW,CAAA;AACb,CAAC,EAVW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAUnB;AAED,yEAAyE;AACzE,YAAY;AACZ,yEAAyE;AAEzE;;;;GAIG;AACH,SAAgB,cAAc,CAAC,IAAY,EAAE,GAAW;IACtD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAA;IACvB,sBAAY,CAAC,SAAS,EAAE,EAAC,IAAI,EAAC,EAAE,GAAG,CAAC,CAAA;AACtC,CAAC;AAHD,wCAGC;AAED;;;GAGG;AACH,SAAgB,SAAS,CAAC,MAAc;IACtC,sBAAY,CAAC,UAAU,EAAE,EAAE,EAAE,MAAM,CAAC,CAAA;AACtC,CAAC;AAFD,8BAEC;AAED;;;GAGG;AACH,SAAgB,OAAO,CAAC,SAAiB;IACvC,sBAAY,CAAC,UAAU,EAAE,EAAE,EAAE,SAAS,CAAC,CAAA;IACvC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,GAAG,SAAS,GAAG,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAA;AAC7E,CAAC;AAHD,0BAGC;AAED;;;;;;GAMG;AACH,SAAgB,QAAQ,CAAC,IAAY,EAAE,OAAsB;IAC3D,MAAM,GAAG,GACP,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,IAAI,EAAE,CAAA;IACrE,IAAI,OAAO,IAAI,OAAO,CAAC,QAAQ,IAAI,CAAC,GAAG,EAAE;QACvC,MAAM,IAAI,KAAK,CAAC,oCAAoC,IAAI,EAAE,CAAC,CAAA;KAC5D;IAED,OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;AACnB,CAAC;AARD,4BAQC;AAED;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,IAAY,EAAE,KAAa;IACnD,sBAAY,CAAC,YAAY,EAAE,EAAC,IAAI,EAAC,EAAE,KAAK,CAAC,CAAA;AAC3C,CAAC;AAFD,8BAEC;AAED,yEAAyE;AACzE,UAAU;AACV,yEAAyE;AAEzE;;;;GAIG;AACH,SAAgB,SAAS,CAAC,OAAe;IACvC,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAA;IACnC,KAAK,CAAC,OAAO,CAAC,CAAA;AAChB,CAAC;AAHD,8BAGC;AAED,yEAAyE;AACzE,mBAAmB;AACnB,yEAAyE;AAEzE;;;GAGG;AACH,SAAgB,KAAK,CAAC,OAAe;IACnC,sBAAY,CAAC,OAAO,EAAE,EAAE,EAAE,OAAO,CAAC,CAAA;AACpC,CAAC;AAFD,sBAEC;AAED;;;GAGG;AACH,SAAgB,KAAK,CAAC,OAAe;IACnC,eAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AACzB,CAAC;AAFD,sBAEC;AAED;;;GAGG;AACH,SAAgB,OAAO,CAAC,OAAe;IACrC,eAAK,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;AAC3B,CAAC;AAFD,0BAEC;AAED;;;GAGG;AACH,SAAgB,IAAI,CAAC,OAAe;IAClC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,CAAA;AACxC,CAAC;AAFD,oBAEC;AAED;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,IAAY;IACrC,eAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;AACtB,CAAC;AAFD,gCAEC;AAED;;GAEG;AACH,SAAgB,QAAQ;IACtB,eAAK,CAAC,UAAU,CAAC,CAAA;AACnB,CAAC;AAFD,4BAEC;AAED;;;;;;;GAOG;AACH,SAAsB,KAAK,CAAI,IAAY,EAAE,EAAoB;;QAC/D,UAAU,CAAC,IAAI,CAAC,CAAA;QAEhB,IAAI,MAAS,CAAA;QAEb,IAAI;YACF,MAAM,GAAG,MAAM,EAAE,EAAE,CAAA;SACpB;gBAAS;YACR,QAAQ,EAAE,CAAA;SACX;QAED,OAAO,MAAM,CAAA;IACf,CAAC;CAAA;AAZD,sBAYC;AAED,yEAAyE;AACzE,uBAAuB;AACvB,yEAAyE;AAEzE;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,IAAY,EAAE,KAAa;IACnD,sBAAY,CAAC,YAAY,EAAE,EAAC,IAAI,EAAC,EAAE,KAAK,CAAC,CAAA;AAC3C,CAAC;AAFD,8BAEC;AAED;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,IAAY;IACnC,OAAO,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC,IAAI,EAAE,CAAA;AAC3C,CAAC;AAFD,4BAEC"}
|
||||
66
node_modules/@actions/core/package.json
generated
vendored
66
node_modules/@actions/core/package.json
generated
vendored
@ -1,66 +0,0 @@
|
||||
{
|
||||
"_from": "@actions/core@1.2.2",
|
||||
"_id": "@actions/core@1.2.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-IbCx7oefq+Gi6FWbSs2Fnw8VkEI6Y4gvjrYprY3RV//ksq/KPMlClOerJ4jRosyal6zkUIc8R9fS/cpRMlGClg==",
|
||||
"_location": "/@actions/core",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "@actions/core@1.2.2",
|
||||
"name": "@actions/core",
|
||||
"escapedName": "@actions%2fcore",
|
||||
"scope": "@actions",
|
||||
"rawSpec": "1.2.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.2.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.2.tgz",
|
||||
"_shasum": "3c4848d50378f9e3bcb67bcf97813382ec7369ee",
|
||||
"_spec": "@actions/core@1.2.2",
|
||||
"_where": "/Users/bret/repos/deploy-to-neocities",
|
||||
"bugs": {
|
||||
"url": "https://github.com/actions/toolkit/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "Actions core lib",
|
||||
"devDependencies": {
|
||||
"@types/node": "^12.0.2"
|
||||
},
|
||||
"directories": {
|
||||
"lib": "lib",
|
||||
"test": "__tests__"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"homepage": "https://github.com/actions/toolkit/tree/master/packages/core",
|
||||
"keywords": [
|
||||
"github",
|
||||
"actions",
|
||||
"core"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "lib/core.js",
|
||||
"name": "@actions/core",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/actions/toolkit.git",
|
||||
"directory": "packages/core"
|
||||
},
|
||||
"scripts": {
|
||||
"audit-moderate": "npm install && npm audit --audit-level=moderate",
|
||||
"test": "echo \"Error: run tests from root\" && exit 1",
|
||||
"tsc": "tsc"
|
||||
},
|
||||
"types": "lib/core.d.ts",
|
||||
"version": "1.2.2"
|
||||
}
|
||||
25
node_modules/async-folder-walker/.github/workflows/tests.yml
generated
vendored
25
node_modules/async-folder-walker/.github/workflows/tests.yml
generated
vendored
@ -1,25 +0,0 @@
|
||||
name: tests
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
node: [12]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Use Node.js ${{ matrix.node }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node }}
|
||||
- name: npm install && npm test
|
||||
run: |
|
||||
npm i
|
||||
npm test
|
||||
env:
|
||||
CI: true
|
||||
22
node_modules/async-folder-walker/.vscode/launch.json
generated
vendored
22
node_modules/async-folder-walker/.vscode/launch.json
generated
vendored
@ -1,22 +0,0 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Launch via NPM",
|
||||
"runtimeExecutable": "npm",
|
||||
"runtimeArgs": [
|
||||
"run-script",
|
||||
"debug"
|
||||
],
|
||||
"port": 9229,
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
19
node_modules/async-folder-walker/CHANGELOG.md
generated
vendored
19
node_modules/async-folder-walker/CHANGELOG.md
generated
vendored
@ -1,19 +0,0 @@
|
||||
# async-folder-walker Change Log
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## Unreleased
|
||||
|
||||
## 2.0.1 - 2019-12-27
|
||||
|
||||
* Internal tweaks
|
||||
* Docs updates
|
||||
|
||||
## 2.0.0 - 2019-12-26
|
||||
|
||||
* Remove ESM support. Fuggit. It simply offers zero benafits in a node env.
|
||||
|
||||
## 1.0.0 - 2019-11-11
|
||||
|
||||
* Initial release.
|
||||
4
node_modules/async-folder-walker/CODE_OF_CONDUCT.md
generated
vendored
4
node_modules/async-folder-walker/CODE_OF_CONDUCT.md
generated
vendored
@ -1,4 +0,0 @@
|
||||
# Code of conduct
|
||||
|
||||
- This repo is governed as a dictatorship starting with the originator of the project.
|
||||
- No malevolence tolerated whatsoever.
|
||||
11
node_modules/async-folder-walker/CONTRIBUTING.md
generated
vendored
11
node_modules/async-folder-walker/CONTRIBUTING.md
generated
vendored
@ -1,11 +0,0 @@
|
||||
# Contributing
|
||||
|
||||
- Contributors reserve the right to walk away from this project at any moment with or without notice.
|
||||
- Questions are welcome, however unless there is a official support contract established between the maintainers and the requester, support is not guaranteed.
|
||||
- Patches, ideas and changes welcome.
|
||||
- Fixes almost always welcome.
|
||||
- Features sometimes welcome. Please open an issue to discuss the issue prior to spending lots of time on the problem. It may be rejected. If you don't want to wait around for the discussion to commence, and you really want to jump into the implementation work, be prepared for fork if the idea is respectfully declined.
|
||||
- Try to stay within the style of the existing code.
|
||||
- All tests must pass.
|
||||
- Additional features or code paths must be tested.
|
||||
- Aim for 100% coverage.
|
||||
21
node_modules/async-folder-walker/LICENSE
generated
vendored
21
node_modules/async-folder-walker/LICENSE
generated
vendored
@ -1,21 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2019 Bret Comnes
|
||||
|
||||
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.
|
||||
170
node_modules/async-folder-walker/README.md
generated
vendored
170
node_modules/async-folder-walker/README.md
generated
vendored
@ -1,170 +0,0 @@
|
||||
# async-folder-walker
|
||||
[](https://github.com/bcomnes/async-folder-walker/actions)
|
||||
|
||||
A recursive async iterator of the files and directories in a given folder. Can take multiple folders, limit walk depth and filter based on path names and stat results.
|
||||
|
||||

|
||||
|
||||
```
|
||||
npm install async-folder-walker
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
``` js
|
||||
const { asyncFolderWalker, allFiles } = require('async-folder-walker')
|
||||
|
||||
async function iterateFiles () {
|
||||
const walker = asyncFolderWalker(['.git', 'node_modules'])
|
||||
for await (const file of walker) {
|
||||
console.log(file) // logs the file path!
|
||||
}
|
||||
}
|
||||
|
||||
async function getAllFiles () {
|
||||
const allFilepaths = await allFiles(['.git', 'node_modules'])
|
||||
console.log(allFilepaths)
|
||||
}
|
||||
|
||||
iterateFiles().then(() => getAllFiles())
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `const { asyncFolderWalker, allFiles } = require('async-folder-walker')`
|
||||
|
||||
Import `asyncFolderWalker` or `allFiles`.
|
||||
|
||||
### `async-gen = asyncFolderWalker(paths, [opts])`
|
||||
|
||||
Return an async generator that will iterate over all of files inside of a directory. `paths` can be a string path or an Array of string paths.
|
||||
|
||||
You can iterate over each file and directory individually using a `for-await...of` loop. Note, you must be inside an [async function statement](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function).
|
||||
|
||||
```js
|
||||
const { asyncFolderWalker } = require('async-folder-walker');
|
||||
async function iterateFiles () {
|
||||
const walker = asyncFolderWalker(['.git', 'node_modules']);
|
||||
for await (const file of walker) {
|
||||
console.log(file); // logs the file path!
|
||||
}
|
||||
}
|
||||
|
||||
iterateFiles();
|
||||
```
|
||||
|
||||
Opts include:
|
||||
|
||||
```js
|
||||
{
|
||||
fs: require('fs'),
|
||||
pathFilter: filepath => true,
|
||||
statFilter st => true,
|
||||
maxDepth: Infinity,
|
||||
shaper: ({ root, filepath, stat, relname, basename }) => filepath
|
||||
}
|
||||
```
|
||||
|
||||
The `pathFilter` function allows you to filter files from additional async stat operations. Return false to filter the file.
|
||||
|
||||
```js
|
||||
{ // exclude node_modules
|
||||
pathFilter: filepath => !filepath.includes(node_modules)
|
||||
}
|
||||
```
|
||||
|
||||
The `statFilter` function allows you to filter files based on the internal stat operation. Return false to filter the file.
|
||||
|
||||
```js
|
||||
{ // exclude all directories:
|
||||
statFilter: st => !st.isDirectory()
|
||||
}
|
||||
```
|
||||
|
||||
The `shaper` function lets you change the shape of the returned value based on data accumulaed during the iteration. To return the same shape as [okdistribute/folder-walker](https://github.com/okdistribute/folder-walker) use the following function:
|
||||
|
||||
```js
|
||||
{ // Return the same shape as folder-walker
|
||||
shaper: fwData => fwData
|
||||
}
|
||||
````
|
||||
|
||||
Example of a fwData object for a directory:
|
||||
|
||||
```js
|
||||
{
|
||||
root: '/Users/bret/repos/async-folder-walker/fixtures',
|
||||
filepath: '/Users/bret/repos/async-folder-walker/fixtures/sub-folder/sub-sub-folder',
|
||||
stat: Stats {
|
||||
dev: 16777220,
|
||||
mode: 16877,
|
||||
nlink: 3,
|
||||
uid: 501,
|
||||
gid: 20,
|
||||
rdev: 0,
|
||||
blksize: 4096,
|
||||
ino: 30244023,
|
||||
size: 96,
|
||||
blocks: 0,
|
||||
atimeMs: 1574381262779.8396,
|
||||
mtimeMs: 1574380914743.5474,
|
||||
ctimeMs: 1574380914743.5474,
|
||||
birthtimeMs: 1574380905232.5996,
|
||||
atime: 2019-11-22T00:07:42.780Z,
|
||||
mtime: 2019-11-22T00:01:54.744Z,
|
||||
ctime: 2019-11-22T00:01:54.744Z,
|
||||
birthtime: 2019-11-22T00:01:45.233Z
|
||||
},
|
||||
relname: 'sub-folder/sub-sub-folder',
|
||||
basename: 'sub-sub-folder'
|
||||
}
|
||||
```
|
||||
|
||||
and another example for a file on windows:
|
||||
|
||||
```js
|
||||
{
|
||||
root: 'D:\\a\\async-folder-walker\\async-folder-walker\\fixtures',
|
||||
filepath: 'D:\\a\\async-folder-walker\\async-folder-walker\\fixtures\\sub-folder\\sub-sub-folder\\sub-sub-folder-file.json',
|
||||
stat: Stats {
|
||||
dev: 1321874112,
|
||||
mode: 33206,
|
||||
nlink: 1,
|
||||
uid: 0,
|
||||
gid: 0,
|
||||
rdev: 0,
|
||||
blksize: 4096,
|
||||
ino: 562949953421580,
|
||||
size: 37,
|
||||
blocks: 0,
|
||||
atimeMs: 1577476819530.035,
|
||||
mtimeMs: 1577476819530.035,
|
||||
ctimeMs: 1577476819530.035,
|
||||
birthtimeMs: 1577476819530.035,
|
||||
atime: 2019-12-27T20:00:19.530Z,
|
||||
mtime: 2019-12-27T20:00:19.530Z,
|
||||
ctime: 2019-12-27T20:00:19.530Z,
|
||||
birthtime: 2019-12-27T20:00:19.530Z
|
||||
},
|
||||
relname: 'sub-folder\\sub-sub-folder\\sub-sub-folder-file.json',
|
||||
basename: 'sub-sub-folder-file.json'
|
||||
}
|
||||
```
|
||||
|
||||
The `stat` property is an instance of [fs.Stats](https://nodejs.org/api/fs.html#fs_class_fs_stats) so it has extra methods not listed here.
|
||||
|
||||
### `files = await allFiles(paths, [opts])`
|
||||
|
||||
Get an Array of all files inside of a directory. `paths` can be a single string path or an array of string paths.
|
||||
|
||||
`opts` Is the same as `asyncFolderWalker`.
|
||||
|
||||
## See also
|
||||
|
||||
This module is effectivly a rewrite of [okdistribute/folder-walker](https://github.com/okdistribute/folder-walker) using async generators instead of Node streams, and a few tweaks to the underlying options to make the results a bit more flexible.
|
||||
|
||||
- [for-await...of](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of)
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
1
node_modules/async-folder-walker/fixtures/another-folder/test.json
generated
vendored
1
node_modules/async-folder-walker/fixtures/another-folder/test.json
generated
vendored
@ -1 +0,0 @@
|
||||
{}
|
||||
3
node_modules/async-folder-walker/fixtures/sub-folder/sub-folder-file.json
generated
vendored
3
node_modules/async-folder-walker/fixtures/sub-folder/sub-folder-file.json
generated
vendored
@ -1,3 +0,0 @@
|
||||
{
|
||||
"sub-folder": "content"
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
{
|
||||
"sub-sub-folder": "content"
|
||||
}
|
||||
3
node_modules/async-folder-walker/fixtures/test.json
generated
vendored
3
node_modules/async-folder-walker/fixtures/test.json
generated
vendored
@ -1,3 +0,0 @@
|
||||
{
|
||||
"hello": "world"
|
||||
}
|
||||
179
node_modules/async-folder-walker/index.js
generated
vendored
179
node_modules/async-folder-walker/index.js
generated
vendored
@ -1,179 +0,0 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const { readdir, lstat } = fs.promises
|
||||
|
||||
/**
|
||||
* pathFilter lets you filter files based on a resolved `filepath`.
|
||||
* @callback pathFilter
|
||||
* @param {String} filepath - The resolved `filepath` of the file to test for filtering.
|
||||
*
|
||||
* @return {Boolean} Return false to filter the given `filepath` and true to include it.
|
||||
*/
|
||||
const pathFilter = filepath => true
|
||||
|
||||
/**
|
||||
* statFilter lets you filter files based on a lstat object.
|
||||
* @callback statFilter
|
||||
* @param {Object} st - A fs.Stats instance.
|
||||
*
|
||||
* @return {Boolean} Return false to filter the given `filepath` and true to include it.
|
||||
*/
|
||||
const statFilter = filepath => true
|
||||
|
||||
/**
|
||||
* FWStats is the object that the okdistribute/folder-walker module returns by default.
|
||||
*
|
||||
* @typedef FWStats
|
||||
* @property {String} root - The filepath of the directory where the walk started.
|
||||
* @property {String} filepath - The resolved filepath.
|
||||
* @property {Object} stat - A fs.Stats instance.
|
||||
* @property {String} relname - The relative path to `root`.
|
||||
* @property {String} basename - The resolved filepath of the files containing directory.
|
||||
*/
|
||||
|
||||
/**
|
||||
* shaper lets you change the shape of the returned file data from walk-time stats.
|
||||
* @callback shaper
|
||||
* @param {FWStats} fwStats - The same status object returned from folder-walker.
|
||||
*
|
||||
* @return {*} - Whatever you want returned from the directory walk.
|
||||
*/
|
||||
const shaper = ({ root, filepath, stat, relname, basename }) => filepath
|
||||
|
||||
/**
|
||||
* Options object
|
||||
*
|
||||
* @typedef Opts
|
||||
* @property {pathFilter} [pathFilter] - A pathFilter cb.
|
||||
* @property {statFilter} [statFilter] - A statFilter cb.
|
||||
* @property {Number} [maxDepth=Infinity] - The maximum number of folders to walk down into.
|
||||
* @property {shaper} [shaper] - A shaper cb.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create an async generator that iterates over all folders and directories inside of `dirs`.
|
||||
*
|
||||
* @async
|
||||
* @generator
|
||||
* @function
|
||||
* @public
|
||||
* @param {String|String[]} dirs - The path of the directory to walk, or an array of directory paths.
|
||||
* @param {?(Opts)} opts - Options used for the directory walk.
|
||||
*
|
||||
* @yields {Promise<String|any>} - An async iterator that returns anything.
|
||||
*/
|
||||
async function * asyncFolderWalker (dirs, opts) {
|
||||
opts = Object.assign({
|
||||
fs,
|
||||
pathFilter,
|
||||
statFilter,
|
||||
maxDepth: Infinity,
|
||||
shaper
|
||||
}, opts)
|
||||
|
||||
const roots = [dirs].flat().filter(opts.pathFilter)
|
||||
const pending = []
|
||||
|
||||
while (roots.length) {
|
||||
const root = roots.shift()
|
||||
pending.push(root)
|
||||
|
||||
while (pending.length) {
|
||||
const current = pending.shift()
|
||||
if (typeof current === 'undefined') continue
|
||||
const st = await lstat(current)
|
||||
if ((!st.isDirectory() || depthLimiter(current, root, opts.maxDepth)) && opts.statFilter(st)) {
|
||||
yield opts.shaper(fwShape(root, current, st))
|
||||
continue
|
||||
}
|
||||
|
||||
const files = await readdir(current)
|
||||
files.sort()
|
||||
|
||||
for (const file of files) {
|
||||
var next = path.join(current, file)
|
||||
if (opts.pathFilter(next)) pending.unshift(next)
|
||||
}
|
||||
if (current === root || !opts.statFilter(st)) continue
|
||||
else yield opts.shaper(fwShape(root, current, st))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the same shape as the folder-walker module.
|
||||
*
|
||||
* @function
|
||||
* @private
|
||||
* @param {String} root - Root filepath.
|
||||
* @param {String} name - Target filepath.
|
||||
* @param {Object} st - fs.Stat object.
|
||||
*
|
||||
* @return {FWStats} - Folder walker object.
|
||||
*/
|
||||
function fwShape (root, name, st) {
|
||||
return {
|
||||
root: root,
|
||||
filepath: name,
|
||||
stat: st,
|
||||
relname: root === name ? path.basename(name) : path.relative(root, name),
|
||||
basename: path.basename(name)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we are at maximum directory depth.
|
||||
*
|
||||
* @private
|
||||
* @function
|
||||
* @param {String} filePath - The resolved path of the target fille.
|
||||
* @param {String} relativeTo - The root directory of the current walk.
|
||||
* @param {Number} maxDepth - The maximum number of folders to descend into.
|
||||
*
|
||||
* @returns {Boolean} - Return true to signal stop descending.
|
||||
*/
|
||||
function depthLimiter (filePath, relativeTo, maxDepth) {
|
||||
if (maxDepth === Infinity) return false
|
||||
const rootDepth = relativeTo.split(path.sep).length
|
||||
const fileDepth = filePath.split(path.sep).length
|
||||
return fileDepth - rootDepth > maxDepth
|
||||
}
|
||||
|
||||
/**
|
||||
* Async iterable collector
|
||||
*
|
||||
* @async
|
||||
* @function
|
||||
* @private
|
||||
*/
|
||||
async function all (iterator) {
|
||||
const collect = []
|
||||
|
||||
for await (const result of iterator) {
|
||||
collect.push(result)
|
||||
}
|
||||
|
||||
return collect
|
||||
}
|
||||
|
||||
/**
|
||||
* allFiles gives you all files from the directory walk as an array.
|
||||
*
|
||||
* @async
|
||||
* @function
|
||||
* @public
|
||||
* @param {String|String[]} dirs - The path of the directory to walk, or an array of directory paths.
|
||||
* @param {?(Opts)} opts - Options used for the directory walk.
|
||||
*
|
||||
* @returns {Promise<String[]|any>} - An async iterator that returns anything.
|
||||
*/
|
||||
async function allFiles (...args) {
|
||||
return all(asyncFolderWalker(...args))
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
asyncFolderWalker,
|
||||
allFiles,
|
||||
all
|
||||
}
|
||||
66
node_modules/async-folder-walker/package.json
generated
vendored
66
node_modules/async-folder-walker/package.json
generated
vendored
@ -1,66 +0,0 @@
|
||||
{
|
||||
"_from": "async-folder-walker@^2.0.1",
|
||||
"_id": "async-folder-walker@2.0.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-n0PW9w3HAZW7ems0XrgIYeX+3l2vX6HhZQyXMtkeKW3uEjHT5EOlKD8NgIeZK6fREnpw50F+Cb6ig3nWsuaTPA==",
|
||||
"_location": "/async-folder-walker",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "async-folder-walker@^2.0.1",
|
||||
"name": "async-folder-walker",
|
||||
"escapedName": "async-folder-walker",
|
||||
"rawSpec": "^2.0.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^2.0.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/async-neocities"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/async-folder-walker/-/async-folder-walker-2.0.1.tgz",
|
||||
"_shasum": "cfc3007945a4bb109c5c548a0f07cd8a9cc15671",
|
||||
"_spec": "async-folder-walker@^2.0.1",
|
||||
"_where": "/Users/bret/repos/deploy-to-neocities/node_modules/async-neocities",
|
||||
"author": {
|
||||
"name": "Bret Comnes",
|
||||
"email": "bcomnes@gmail.com",
|
||||
"url": "https://bret.io"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/bcomnes/async-folder-walker/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {},
|
||||
"deprecated": false,
|
||||
"description": "WIP - nothing to see here",
|
||||
"devDependencies": {
|
||||
"dependency-check": "^4.1.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"p-temporary-directory": "^1.1.1",
|
||||
"standard": "^14.3.1",
|
||||
"tap": "^14.10.5"
|
||||
},
|
||||
"homepage": "https://github.com/bcomnes/async-folder-walker",
|
||||
"keywords": [],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "async-folder-walker",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/bcomnes/async-folder-walker.git"
|
||||
},
|
||||
"scripts": {
|
||||
"debug": "node --nolazy --inspect-brk=9229 -r esm test.js",
|
||||
"test": "run-s test:*",
|
||||
"test:deps": "dependency-check . --no-dev --no-peer",
|
||||
"test:standard": "standard",
|
||||
"test:tap": "tap"
|
||||
},
|
||||
"standard": {
|
||||
"ignore": [
|
||||
"dist"
|
||||
]
|
||||
},
|
||||
"version": "2.0.1"
|
||||
}
|
||||
102
node_modules/async-folder-walker/test.js
generated
vendored
102
node_modules/async-folder-walker/test.js
generated
vendored
@ -1,102 +0,0 @@
|
||||
const tap = require('tap')
|
||||
const { asyncFolderWalker, allFiles } = require('.')
|
||||
const path = require('path')
|
||||
const tmp = require('p-temporary-directory')
|
||||
|
||||
const fixtures = path.join(__dirname, 'fixtures')
|
||||
|
||||
tap.test('for of multiple folders', async t => {
|
||||
for await (const file of asyncFolderWalker([
|
||||
path.join(fixtures, 'sub-folder'),
|
||||
path.join(fixtures, 'another-folder')
|
||||
])) {
|
||||
t.ok(file, file)
|
||||
}
|
||||
})
|
||||
|
||||
tap.test('Array from async iterator', async t => {
|
||||
const files = await allFiles([
|
||||
path.join(fixtures, 'sub-folder'),
|
||||
path.join(fixtures, 'another-folder')
|
||||
])
|
||||
t.equal(files.length, 4, 'expected number of files are found')
|
||||
})
|
||||
|
||||
tap.skip('Shape example', async t => {
|
||||
await allFiles([fixtures], {
|
||||
shaper: fwData => {
|
||||
console.log(fwData)
|
||||
return fwData
|
||||
}
|
||||
})
|
||||
t.pass('shape printed')
|
||||
})
|
||||
|
||||
tap.test('No args', async t => {
|
||||
for await (const file of asyncFolderWalker()) {
|
||||
t.fail(file, 'no files should be found!')
|
||||
}
|
||||
t.pass('for of executed')
|
||||
})
|
||||
|
||||
tap.test('No folders', async t => {
|
||||
const [dir, cleanup] = await tmp()
|
||||
try {
|
||||
for await (const file of asyncFolderWalker(dir)) {
|
||||
t.fail(file, 'no files should be found!')
|
||||
}
|
||||
t.pass('for of executed')
|
||||
} finally {
|
||||
await cleanup()
|
||||
}
|
||||
})
|
||||
|
||||
tap.test('When you just pass a file', async t => {
|
||||
const [dir, cleanup] = await tmp()
|
||||
try {
|
||||
const theFile = path.join(fixtures, 'test.json')
|
||||
const files = await allFiles([theFile, dir])
|
||||
t.equal(files.length, 1, 'only one file is found')
|
||||
t.equal(theFile, files[0], 'only one file is found')
|
||||
} finally {
|
||||
await cleanup()
|
||||
}
|
||||
})
|
||||
|
||||
tap.test('pathFilter works', async t => {
|
||||
const filterStrig = 'sub-folder'
|
||||
const files = await allFiles(fixtures, {
|
||||
pathFilter: p => !p.includes(filterStrig)
|
||||
})
|
||||
|
||||
t.false(files.some(f => f.includes(filterStrig)), 'No paths include the excluded string')
|
||||
})
|
||||
|
||||
tap.test('statFilter works', async t => {
|
||||
const stats = await allFiles(fixtures, {
|
||||
statFilter: st => !st.isDirectory(), // Exclude files
|
||||
shaper: ({ root, filepath, stat, relname, basename }) => stat // Lets get the stats instead of paths
|
||||
})
|
||||
|
||||
for (const st of stats) {
|
||||
t.false(st.isDirectory(), 'none of the files are directories')
|
||||
}
|
||||
})
|
||||
|
||||
tap.test('dont include root directory in response', async (t) => {
|
||||
const root = process.cwd()
|
||||
for await (const file of asyncFolderWalker(root)) {
|
||||
if (file === root) t.fail('root directory should not be in results')
|
||||
}
|
||||
t.pass('The root was not included in results.')
|
||||
})
|
||||
|
||||
tap.test('dont walk past the maxDepth', async t => {
|
||||
const maxDepth = 3
|
||||
const walker = asyncFolderWalker(['.git', 'node_modules'], { maxDepth })
|
||||
for await (const file of walker) {
|
||||
const correctLength = file.split(path.sep).length - process.cwd().split(path.sep).length <= maxDepth
|
||||
if (!correctLength) t.fail('walker walked past the depth it was supposed to')
|
||||
}
|
||||
t.pass('Walker was depth limited')
|
||||
})
|
||||
128
node_modules/async-neocities/CHANGELOG.md
generated
vendored
128
node_modules/async-neocities/CHANGELOG.md
generated
vendored
@ -1,128 +0,0 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
||||
|
||||
## [v1.1.6](https://github.com/bcomnes/async-neocities/compare/v1.1.5...v1.1.6) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
- refactor: limit decimal places in statHandler [`745b5c0`](https://github.com/bcomnes/async-neocities/commit/745b5c08b446723b837cf787e5911045cd0a01ed)
|
||||
|
||||
## [v1.1.5](https://github.com/bcomnes/async-neocities/compare/v1.1.4...v1.1.5) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
- bug: Log last stats before clear [`c4c83f8`](https://github.com/bcomnes/async-neocities/commit/c4c83f8e329303404dfec6a2943d8b01783040ad)
|
||||
|
||||
## [v1.1.4](https://github.com/bcomnes/async-neocities/compare/v1.1.3...v1.1.4) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
- bug: fix logging handler logic [`f6c5921`](https://github.com/bcomnes/async-neocities/commit/f6c5921d6fd0a420c5895ed6ba2fe2f766e726fd)
|
||||
|
||||
## [v1.1.3](https://github.com/bcomnes/async-neocities/compare/v1.1.2...v1.1.3) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
- refactor: Stop logging progress when the stream has been read. [`3ce0fc4`](https://github.com/bcomnes/async-neocities/commit/3ce0fc452acbbbd28c39b53a3a9a4318a8019c09)
|
||||
|
||||
## [v1.1.2](https://github.com/bcomnes/async-neocities/compare/v1.1.1...v1.1.2) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
- bug: Fix export name of statsHandler [`8958e5e`](https://github.com/bcomnes/async-neocities/commit/8958e5eeb947376690a1ce0cefe7cce3d59be5b8)
|
||||
|
||||
## [v1.1.1](https://github.com/bcomnes/async-neocities/compare/v1.1.0...v1.1.1) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
- bug: Fix busted export of stats handler. [`510ae29`](https://github.com/bcomnes/async-neocities/commit/510ae293263955e0e34d3ab48df253fb6e093053)
|
||||
|
||||
## [v1.1.0](https://github.com/bcomnes/async-neocities/compare/v1.0.2...v1.1.0) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
- feat: Finish statsCb API and add a stats-handler.js function. [`c8e6483`](https://github.com/bcomnes/async-neocities/commit/c8e64835e594e68715ef71590b08baac374052bd)
|
||||
|
||||
## [v1.0.2](https://github.com/bcomnes/async-neocities/compare/v1.0.1...v1.0.2) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
- chore: remove total time from stats [`3c375ec`](https://github.com/bcomnes/async-neocities/commit/3c375ecf64ae8536a8e3ccce0a69cd93c8c6a306)
|
||||
|
||||
## [v1.0.1](https://github.com/bcomnes/async-neocities/compare/v1.0.0...v1.0.1) - 2020-02-13
|
||||
|
||||
### Commits
|
||||
|
||||
- bug: Fix a number of logging bugs [`96fbea2`](https://github.com/bcomnes/async-neocities/commit/96fbea2bbd27ba1ac5105fce37e624d804dcbdb6)
|
||||
|
||||
## [v1.0.0](https://github.com/bcomnes/async-neocities/compare/v0.0.10...v1.0.0) - 2020-02-12
|
||||
|
||||
### Commits
|
||||
|
||||
- feat: progress API sketch [`be8b9ec`](https://github.com/bcomnes/async-neocities/commit/be8b9ec062b5ea23157a6a841c9d66d03a85a8ca)
|
||||
- docs: update README [`ec4f5f1`](https://github.com/bcomnes/async-neocities/commit/ec4f5f154b690dba0814ec0955fee674e8e94692)
|
||||
- CHANGELOG [`c9b64ed`](https://github.com/bcomnes/async-neocities/commit/c9b64edd4d3db025adc737982477ce0d760f3254)
|
||||
|
||||
## [v0.0.10](https://github.com/bcomnes/async-neocities/compare/v0.0.9...v0.0.10) - 2020-02-10
|
||||
|
||||
### Commits
|
||||
|
||||
- dont do work unless there is work [`616a306`](https://github.com/bcomnes/async-neocities/commit/616a306ba3ca091da11c9c85bae2b07cb0b2768e)
|
||||
|
||||
## [v0.0.9](https://github.com/bcomnes/async-neocities/compare/v0.0.8...v0.0.9) - 2020-02-10
|
||||
|
||||
### Commits
|
||||
|
||||
- Use stream ctor [`e8201a0`](https://github.com/bcomnes/async-neocities/commit/e8201a053950848962a220b83ffa1a97ebab6e70)
|
||||
|
||||
## [v0.0.8](https://github.com/bcomnes/async-neocities/compare/v0.0.7...v0.0.8) - 2020-02-10
|
||||
|
||||
### Commits
|
||||
|
||||
- Fix more bugs [`95da7b7`](https://github.com/bcomnes/async-neocities/commit/95da7b7218082ab51c1463851f87428dc0c501ac)
|
||||
|
||||
## [v0.0.7](https://github.com/bcomnes/async-neocities/compare/v0.0.6...v0.0.7) - 2020-02-10
|
||||
|
||||
### Commits
|
||||
|
||||
- bugs [`71ead78`](https://github.com/bcomnes/async-neocities/commit/71ead78e0f48f619816b3ae3ea8154e8301c77ac)
|
||||
|
||||
## [v0.0.6](https://github.com/bcomnes/async-neocities/compare/v0.0.5...v0.0.6) - 2020-02-10
|
||||
|
||||
### Commits
|
||||
|
||||
- bugs [`c1d9973`](https://github.com/bcomnes/async-neocities/commit/c1d9973afef3abd7d6edfc5a6ae1c9d37f6cb34d)
|
||||
|
||||
## [v0.0.5](https://github.com/bcomnes/async-neocities/compare/v0.0.4...v0.0.5) - 2020-02-10
|
||||
|
||||
### Commits
|
||||
|
||||
- bugs [`e542111`](https://github.com/bcomnes/async-neocities/commit/e542111f3404ab923be3490e62ba16b4f6b66a70)
|
||||
|
||||
## [v0.0.4](https://github.com/bcomnes/async-neocities/compare/v0.0.3...v0.0.4) - 2020-02-10
|
||||
|
||||
### Commits
|
||||
|
||||
- bump version [`a3da5f7`](https://github.com/bcomnes/async-neocities/commit/a3da5f77cda15fb3e9ec5861b588f616d8b0055c)
|
||||
|
||||
## [v0.0.3](https://github.com/bcomnes/async-neocities/compare/v0.0.2...v0.0.3) - 2020-02-10
|
||||
|
||||
### Commits
|
||||
|
||||
- tmp releases [`16a6db4`](https://github.com/bcomnes/async-neocities/commit/16a6db49a06bebef89007b94e03dd34e6d17b298)
|
||||
|
||||
## [v0.0.2](https://github.com/bcomnes/async-neocities/compare/v0.0.1...v0.0.2) - 2020-02-10
|
||||
|
||||
## v0.0.1 - 2020-02-10
|
||||
|
||||
### Commits
|
||||
|
||||
- Init [`bb055ae`](https://github.com/bcomnes/async-neocities/commit/bb055ae8e76b0344acc929e8ffd3974d19144001)
|
||||
- fix tests [`c294b52`](https://github.com/bcomnes/async-neocities/commit/c294b528a64a50638c4374a8782b177fe3634eb2)
|
||||
- Init [`9ec8fb5`](https://github.com/bcomnes/async-neocities/commit/9ec8fb557ebf8578c9eb07dedffcb1b7eedbd3e6)
|
||||
4
node_modules/async-neocities/CODE_OF_CONDUCT.md
generated
vendored
4
node_modules/async-neocities/CODE_OF_CONDUCT.md
generated
vendored
@ -1,4 +0,0 @@
|
||||
# Code of conduct
|
||||
|
||||
- This repo is governed as a dictatorship starting with the originator of the project.
|
||||
- This is a malevolence free zone.
|
||||
26
node_modules/async-neocities/CONTRIBUTING.md
generated
vendored
26
node_modules/async-neocities/CONTRIBUTING.md
generated
vendored
@ -1,26 +0,0 @@
|
||||
# Contributing
|
||||
|
||||
## Releasing
|
||||
|
||||
Changelog, and releasing is autmated with npm scripts. To create a release:
|
||||
|
||||
- Ensure a clean working git workspace.
|
||||
- Run `npm version {patch,minor,major}`.
|
||||
- This wills update the version number and generate the changelog.
|
||||
- Run `npm publish`.
|
||||
- This will push your local git branch and tags to the default remote, perform a [gh-release](https://ghub.io/gh-release), and create an npm publication.
|
||||
|
||||
## Guidelines
|
||||
|
||||
- Patches, ideas and changes welcome.
|
||||
- Fixes almost always welcome.
|
||||
- Features sometimes welcome.
|
||||
- Please open an issue to discuss the issue prior to spending lots of time on the problem.
|
||||
- It may be rejected.
|
||||
- If you don't want to wait around for the discussion to commence, and you really want to jump into the implementation work, be prepared for fork if the idea is respectfully declined.
|
||||
- Try to stay within the style of the existing code.
|
||||
- All tests must pass.
|
||||
- Additional features or code paths must be tested.
|
||||
- Aim for 100% coverage.
|
||||
- Questions are welcome, however unless there is a official support contract established between the maintainers and the requester, support is not guaranteed.
|
||||
- Contributors reserve the right to walk away from this project at any moment with or without notice.
|
||||
21
node_modules/async-neocities/LICENSE
generated
vendored
21
node_modules/async-neocities/LICENSE
generated
vendored
@ -1,21 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2019 Bret Comnes
|
||||
|
||||
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.
|
||||
245
node_modules/async-neocities/README.md
generated
vendored
245
node_modules/async-neocities/README.md
generated
vendored
@ -1,245 +0,0 @@
|
||||
# async-neocities
|
||||
[](https://github.com/bcomnes/async-neocities/actions)
|
||||
|
||||
An api client for [neocities][nc] with an async/promise API and an efficient deploy algorithm.
|
||||
|
||||
<center><img src="logo.jpg"></center>
|
||||
|
||||
```console
|
||||
npm install async-neocities
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
``` js
|
||||
const path = require('path')
|
||||
const Neocities = require('async-neocities')
|
||||
|
||||
async function deploySite () {
|
||||
const token = await Neocities.getKey('sitename', 'password')
|
||||
|
||||
const client = new Neocities(token)
|
||||
|
||||
console.log(await client.list()) // site files
|
||||
console.log(await client.info()) // site info
|
||||
|
||||
return client.deploy(path.join(__dirname, './site-contents'))
|
||||
}
|
||||
|
||||
deploySite.then(info => { console.log('done deploying site!') })
|
||||
.catch(e => { throw e })
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `Neocities = require('async-neocities')`
|
||||
|
||||
Import the Neocities API client.
|
||||
|
||||
### `apiKey = await Neocities.getKey(sitename, password, [opts])`
|
||||
|
||||
Static class method that will get an API Key from a sitename and password.
|
||||
|
||||
`opts` include:
|
||||
|
||||
```js
|
||||
{
|
||||
url: 'https://neocities.org' // Base URL to use for requests
|
||||
}
|
||||
```
|
||||
|
||||
### `client = new Neocities(apiKey, [opts])`
|
||||
|
||||
Create a new API client for a given API key.
|
||||
|
||||
`opts` include:
|
||||
|
||||
```js
|
||||
{
|
||||
url: 'https://neocities.org' // Base URL to use for requests
|
||||
}
|
||||
```
|
||||
|
||||
### `response = await client.upload(files)`
|
||||
|
||||
Pass an array of objects with the `{ name, path }` pair to upload these files to neocities, where `name` is desired remote unix path on neocities and `path` is the local path on disk in whichever format the local operating system desires.
|
||||
|
||||
A successful `response`:
|
||||
|
||||
```js
|
||||
{
|
||||
result: 'success',
|
||||
message: 'your file(s) have been successfully uploaded'
|
||||
}
|
||||
```
|
||||
|
||||
### `response = await client.delete(filenames)`
|
||||
|
||||
Pass an array of path strings to delete on neocities. The path strings should be the unix style path of the file you want to delete.
|
||||
|
||||
A successful `response`:
|
||||
|
||||
```js
|
||||
{ result: 'success', message: 'file(s) have been deleted' }
|
||||
```
|
||||
|
||||
### `response = await client.list([queries])`
|
||||
|
||||
Get a list of files for your site. The optional `queries` object is passed through [qs][qs] and added to the request.
|
||||
|
||||
Available queries:
|
||||
|
||||
```js
|
||||
{
|
||||
path // list the contents of a subdirectory on neocities
|
||||
}
|
||||
```
|
||||
|
||||
Example `responses`:
|
||||
|
||||
```json
|
||||
{
|
||||
"result": "success",
|
||||
"files": [
|
||||
{
|
||||
"path": "index.html",
|
||||
"is_directory": false,
|
||||
"size": 1023,
|
||||
"updated_at": "Sat, 13 Feb 2016 03:04:00 -0000",
|
||||
"sha1_hash": "c8aac06f343c962a24a7eb111aad739ff48b7fb1"
|
||||
},
|
||||
{
|
||||
"path": "not_found.html",
|
||||
"is_directory": false,
|
||||
"size": 271,
|
||||
"updated_at": "Sat, 13 Feb 2016 03:04:00 -0000",
|
||||
"sha1_hash": "cfdf0bda2557c322be78302da23c32fec72ffc0b"
|
||||
},
|
||||
{
|
||||
"path": "images",
|
||||
"is_directory": true,
|
||||
"updated_at": "Sat, 13 Feb 2016 03:04:00 -0000"
|
||||
},
|
||||
{
|
||||
"path": "images/cat.png",
|
||||
"is_directory": false,
|
||||
"size": 16793,
|
||||
"updated_at": "Sat, 13 Feb 2016 03:04:00 -0000",
|
||||
"sha1_hash": "41fe08fc0dd44e79f799d03ece903e62be25dc7d"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
With the `path` query:
|
||||
|
||||
```json
|
||||
{
|
||||
"result": "success",
|
||||
"files": [
|
||||
{
|
||||
"path": "images/cat.png",
|
||||
"is_directory": false,
|
||||
"size": 16793,
|
||||
"updated_at": "Sat, 13 Feb 2016 03:04:00 -0000",
|
||||
"sha1_hash": "41fe08fc0dd44e79f799d03ece903e62be25dc7d"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### `response = await client.info([queries])`
|
||||
|
||||
Get info about your or other sites. The optional `queries` object is passed through [qs][qs] and added to the request.
|
||||
|
||||
Available queries:
|
||||
|
||||
```js
|
||||
{
|
||||
sitename // get info on a given sitename
|
||||
}
|
||||
```
|
||||
|
||||
Example `responses`:
|
||||
|
||||
```json
|
||||
{
|
||||
"result": "success",
|
||||
"info": {
|
||||
"sitename": "youpi",
|
||||
"hits": 5072,
|
||||
"created_at": "Sat, 29 Jun 2013 10:11:38 +0000",
|
||||
"last_updated": "Tue, 23 Jul 2013 20:04:03 +0000",
|
||||
"domain": null,
|
||||
"tags": []
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### `stats = await client.deploy(directory, [opts])`
|
||||
|
||||
Deploy a path to a `directory`, efficiently only uploading missing and changed files. Files are determined to be different by size, and sha1 hash, if the size is the same.
|
||||
|
||||
`opts` include:
|
||||
|
||||
```js
|
||||
{
|
||||
cleanup: false // delete orphaned files on neocities that are not in the `directory`
|
||||
statsCb: (stats) => {}
|
||||
}
|
||||
```
|
||||
|
||||
For an example of a stats handler, see [lib/stats-handler.js]('./lib/stats-handler.js').
|
||||
|
||||
### `client.get(endpoint, [quieries], [opts])`
|
||||
|
||||
Low level GET request to a given `endpoint`.
|
||||
|
||||
**NOTE**: The `/api/` prefix is automatically added: `/api/${endpoint}` so that must be omitted from `endpoint.
|
||||
|
||||
The optional `queries` object is stringified to a querystring using [`qs`][qs]a and added to the request.
|
||||
|
||||
`opts` includes:
|
||||
|
||||
```js
|
||||
{
|
||||
method: 'GET',
|
||||
headers: { ...client.defaultHeaders, ...opts.headers },
|
||||
}
|
||||
```
|
||||
|
||||
Note, that `opts` is passed internally to [`node-fetch`][nf] and you can include any options that work for that client here.
|
||||
|
||||
### `client.post(endpoint, formEntries, [opts])`
|
||||
|
||||
Low level POST request to a given `endpoint`.
|
||||
|
||||
**NOTE**: The `/api/` prefix is automatically adeded: `/api/${endpoint}` so that must be omitted from `endpoint.
|
||||
|
||||
Pass a `formEntries` array or iterator containing objects with `{name, value}` pairs to be sent with the POST request as [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData). The [form-datat][fd] module is used internally.
|
||||
|
||||
`opts` include:
|
||||
|
||||
```js
|
||||
{
|
||||
method: 'POST',
|
||||
body: new FormData(), // Don't override this.
|
||||
headers: { ...client.defafultHeaders, ...formHeaders, opts.headers }
|
||||
}
|
||||
```
|
||||
|
||||
Note, that `opts` is passed internally to [`node-fetch`][nf] and you can include any options that work for that client here.
|
||||
|
||||
## See also
|
||||
|
||||
- [Neocities API docs](https://neocities.org/api)
|
||||
- [Official Node.js API client](https://github.com/neocities/neocities-node)
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
[qs]: https://ghub.io/qs
|
||||
[nf]: https://ghub.io/node-fetch
|
||||
[fd]: https://ghub.io/form-data
|
||||
[nc]: https://neocities.org
|
||||
303
node_modules/async-neocities/index.js
generated
vendored
303
node_modules/async-neocities/index.js
generated
vendored
@ -1,303 +0,0 @@
|
||||
const { handleResponse } = require('fetch-errors')
|
||||
const { createReadStream } = require('fs')
|
||||
const afw = require('async-folder-walker')
|
||||
const FormData = require('form-data')
|
||||
const assert = require('nanoassert')
|
||||
const fetch = require('node-fetch')
|
||||
const { URL } = require('url')
|
||||
const qs = require('qs')
|
||||
const os = require('os')
|
||||
|
||||
const { neocitiesLocalDiff } = require('./lib/folder-diff')
|
||||
const pkg = require('./package.json')
|
||||
const SimpleTimer = require('./lib/timer')
|
||||
const { getStreamLength, meterStream } = require('./lib/stream-meter')
|
||||
const statsHandler = require('./lib/stats-handler')
|
||||
|
||||
const defaultURL = 'https://neocities.org'
|
||||
|
||||
// Progress API constants
|
||||
const START = 'start'
|
||||
const PROGRESS = 'progress' // progress updates
|
||||
const STOP = 'stop'
|
||||
const SKIP = 'skip'
|
||||
// Progress stages
|
||||
const INSPECTING = 'inspecting'
|
||||
const DIFFING = 'diffing'
|
||||
const APPLYING = 'applying'
|
||||
|
||||
/**
|
||||
* NeocitiesAPIClient class representing a neocities api client.
|
||||
*/
|
||||
class NeocitiesAPIClient {
|
||||
/**
|
||||
* getKey returns an apiKey from a sitename and password.
|
||||
* @param {String} sitename username/sitename to log into.
|
||||
* @param {String} password password to log in with.
|
||||
* @param {Object} [opts] Options object.
|
||||
* @param {Object} [opts.url=https://neocities.org] Base URL to request to.
|
||||
* @return {Promise<String>} An api key for the sitename..
|
||||
*/
|
||||
static getKey (sitename, password, opts) {
|
||||
assert(sitename, 'must pass sitename as first arg')
|
||||
assert(typeof sitename === 'string', 'user arg must be a string')
|
||||
assert(password, 'must pass a password as the second arg')
|
||||
assert(typeof password, 'password arg must be a string')
|
||||
|
||||
opts = Object.assign({
|
||||
url: defaultURL
|
||||
}, opts)
|
||||
|
||||
const baseURL = opts.url
|
||||
delete opts.url
|
||||
|
||||
const url = new URL('/api/key', baseURL)
|
||||
url.username = sitename
|
||||
url.password = password
|
||||
return fetch(url, opts)
|
||||
}
|
||||
|
||||
static statsHandler (...args) { return statsHandler(...args) }
|
||||
|
||||
/**
|
||||
* Create an async-neocities api client.
|
||||
* @param {string} apiKey An apiKey to make requests with.
|
||||
* @param {Object} [opts] Options object.
|
||||
* @param {Object} [opts.url=https://neocities.org] Base URL to make requests to.
|
||||
* @return {Object} An api client instance.
|
||||
*/
|
||||
constructor (apiKey, opts) {
|
||||
assert(apiKey, 'must pass apiKey as first argument')
|
||||
assert(typeof apiKey === 'string', 'apiKey must be a string')
|
||||
opts = Object.assign({
|
||||
url: defaultURL
|
||||
})
|
||||
|
||||
this.url = opts.url
|
||||
this.apiKey = apiKey
|
||||
}
|
||||
|
||||
get defaultHeaders () {
|
||||
return {
|
||||
Authorization: `Bearer ${this.apiKey}`,
|
||||
Accept: 'application/json',
|
||||
'User-Agent': `async-neocities/${pkg.version} (${os.type()})`
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic GET request to neocities.
|
||||
* @param {String} endpoint An endpoint path to GET request.
|
||||
* @param {Object} [quieries] An object that gets added to the request in the form of a query string.
|
||||
* @param {Object} [opts] Options object.
|
||||
* @param {String} [opts.method=GET] The http method to use.
|
||||
* @param {Object} [opts.headers] Headers to include in the request.
|
||||
* @return {Object} The parsed JSON from the request response.
|
||||
*/
|
||||
get (endpoint, quieries, opts) {
|
||||
assert(endpoint, 'must pass endpoint as first argument')
|
||||
opts = Object.assign({
|
||||
method: 'GET'
|
||||
}, opts)
|
||||
opts.headers = Object.assign({}, this.defaultHeaders, opts.headers)
|
||||
|
||||
let path = `/api/${endpoint}`
|
||||
if (quieries) path += `?${qs.stringify(quieries)}`
|
||||
|
||||
const url = new URL(path, this.url)
|
||||
return fetch(url, opts)
|
||||
}
|
||||
|
||||
/**
|
||||
* Low level POST request to neocities with FormData.
|
||||
* @param {String} endpoint The endpoint to make the request to.
|
||||
* @param {Array.<{name: String, value: String}>} formEntries Array of form entries.
|
||||
* @param {Object} [opts] Options object.
|
||||
* @param {String} [opts.method=POST] HTTP Method.
|
||||
* @param {Object} [opts.headers] Additional headers to send.
|
||||
* @return {Object} The parsed JSON response object.
|
||||
*/
|
||||
async post (endpoint, formEntries, opts) {
|
||||
assert(endpoint, 'must pass endpoint as first argument')
|
||||
assert(formEntries, 'must pass formEntries as second argument')
|
||||
|
||||
function createForm () {
|
||||
const form = new FormData()
|
||||
for (const { name, value } of formEntries) {
|
||||
form.append(name, value)
|
||||
}
|
||||
|
||||
return form
|
||||
}
|
||||
|
||||
opts = Object.assign({
|
||||
method: 'POST',
|
||||
statsCb: () => {}
|
||||
}, opts)
|
||||
const statsCb = opts.statsCb
|
||||
delete opts.statsCb
|
||||
|
||||
const stats = {
|
||||
totalBytes: await getStreamLength(createForm()),
|
||||
bytesWritten: 0
|
||||
}
|
||||
statsCb(stats)
|
||||
|
||||
const form = createForm()
|
||||
|
||||
opts.body = meterStream(form, bytesRead => {
|
||||
stats.bytesWritten = bytesRead
|
||||
statsCb(stats)
|
||||
})
|
||||
|
||||
opts.headers = Object.assign(
|
||||
{},
|
||||
this.defaultHeaders,
|
||||
form.getHeaders(),
|
||||
opts.headers)
|
||||
|
||||
const url = new URL(`/api/${endpoint}`, this.url)
|
||||
return fetch(url, opts)
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload files to neocities
|
||||
*/
|
||||
upload (files, opts = {}) {
|
||||
opts = {
|
||||
statsCb: () => {},
|
||||
...opts
|
||||
}
|
||||
const formEntries = files.map(({ name, path }) => {
|
||||
const streamCtor = (next) => next(createReadStream(path))
|
||||
streamCtor.path = path
|
||||
return {
|
||||
name,
|
||||
value: streamCtor
|
||||
}
|
||||
})
|
||||
|
||||
return this.post('upload', formEntries, { statsCb: opts.statsCb }).then(handleResponse)
|
||||
}
|
||||
|
||||
/**
|
||||
* delete files from your website
|
||||
*/
|
||||
delete (filenames, opts = {}) {
|
||||
assert(filenames, 'filenames is a required first argument')
|
||||
assert(Array.isArray(filenames), 'filenames argument must be an array of file paths in your website')
|
||||
opts = {
|
||||
statsCb: () => {},
|
||||
...opts
|
||||
}
|
||||
|
||||
const formEntries = filenames.map(file => ({
|
||||
name: 'filenames[]',
|
||||
value: file
|
||||
}))
|
||||
|
||||
return this.post('delete', formEntries, { statsCb: opts.statsCb }).then(handleResponse)
|
||||
}
|
||||
|
||||
list (queries) {
|
||||
// args.path: Path to list
|
||||
return this.get('list', queries).then(handleResponse)
|
||||
}
|
||||
|
||||
/**
|
||||
* info returns info on your site, or optionally on a sitename querystrign
|
||||
* @param {Object} args Querystring arguments to include (e.g. sitename)
|
||||
* @return {Promise} Fetch request promise
|
||||
*/
|
||||
info (queries) {
|
||||
// args.sitename: sitename to get info on
|
||||
return this.get('info', queries).then(handleResponse)
|
||||
}
|
||||
|
||||
/**
|
||||
* Deploy a directory to neocities, skipping already uploaded files and optionally cleaning orphaned files.
|
||||
* @param {String} directory The path of the directory to deploy.
|
||||
* @param {Object} opts Options object.
|
||||
* @param {Boolean} opts.cleanup Boolean to delete orphaned files nor not. Defaults to false.
|
||||
* @param {Boolean} opts.statsCb Get access to stat info before uploading is complete.
|
||||
* @return {Promise} Promise containing stats about the deploy
|
||||
*/
|
||||
async deploy (directory, opts) {
|
||||
opts = {
|
||||
cleanup: false, // delete remote orphaned files
|
||||
statsCb: () => {},
|
||||
...opts
|
||||
}
|
||||
|
||||
const statsCb = opts.statsCb
|
||||
const totalTime = new SimpleTimer(Date.now())
|
||||
|
||||
// INSPECTION STAGE
|
||||
statsCb({ stage: INSPECTING, status: START })
|
||||
const [localFiles, remoteFiles] = await Promise.all([
|
||||
afw.allFiles(directory, { shaper: f => f }),
|
||||
this.list().then(res => res.files)
|
||||
])
|
||||
statsCb({ stage: INSPECTING, status: STOP })
|
||||
|
||||
// DIFFING STAGE
|
||||
statsCb({ stage: DIFFING, status: START })
|
||||
const { filesToUpload, filesToDelete, filesSkipped } = await neocitiesLocalDiff(remoteFiles, localFiles)
|
||||
statsCb({ stage: DIFFING, status: STOP })
|
||||
|
||||
// APPLYING STAGE
|
||||
if (filesToUpload.length === 0 && (!opts.cleanup || filesToDelete.length === 0)) {
|
||||
statsCb({ stage: APPLYING, status: SKIP })
|
||||
return stats()
|
||||
}
|
||||
|
||||
statsCb({ stage: APPLYING, status: START })
|
||||
const work = []
|
||||
|
||||
if (filesToUpload.length > 0) {
|
||||
const uploadJob = this.upload(filesToUpload, {
|
||||
statsCb ({ totalBytes, bytesWritten }) {
|
||||
statsCb({
|
||||
stage: APPLYING,
|
||||
status: PROGRESS,
|
||||
complete: false,
|
||||
totalBytes,
|
||||
bytesWritten,
|
||||
get progress () {
|
||||
return (this.bytesWritten / this.totalBytes) || 0
|
||||
}
|
||||
})
|
||||
}
|
||||
}).then((_) => {
|
||||
statsCb({
|
||||
stage: APPLYING,
|
||||
status: PROGRESS,
|
||||
complete: true,
|
||||
progress: 1.0
|
||||
})
|
||||
})
|
||||
work.push(uploadJob)
|
||||
}
|
||||
|
||||
if (opts.cleanup && filesToDelete.length > 0) {
|
||||
work.push(this.delete(filesToDelete))
|
||||
}
|
||||
|
||||
await Promise.all(work)
|
||||
statsCb({ stage: APPLYING, status: STOP })
|
||||
|
||||
return stats()
|
||||
|
||||
function stats () {
|
||||
totalTime.stop()
|
||||
return {
|
||||
time: totalTime.elapsed,
|
||||
filesToUpload,
|
||||
filesToDelete,
|
||||
filesSkipped
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NeocitiesAPIClient
|
||||
179
node_modules/async-neocities/lib/folder-diff.js
generated
vendored
179
node_modules/async-neocities/lib/folder-diff.js
generated
vendored
@ -1,179 +0,0 @@
|
||||
const crypto = require('crypto')
|
||||
const util = require('util')
|
||||
const fs = require('fs')
|
||||
|
||||
const ppump = util.promisify(require('pump'))
|
||||
|
||||
/**
|
||||
* neocitiesLocalDiff returns an array of files to delete and update and some useful stats.
|
||||
* @param {Array} neocitiesFiles Array of files returned from the neocities list api.
|
||||
* @param {Array} localListing Array of files returned by a full data async-folder-walker run.
|
||||
* @return {Promise<Object>} Object of filesToUpload, filesToDelete and filesSkipped.
|
||||
*/
|
||||
async function neocitiesLocalDiff (neocitiesFiles, localListing) {
|
||||
const localIndex = {}
|
||||
const ncIndex = {}
|
||||
|
||||
const neoCitiesFiltered = neocitiesFiles.filter(f => !f.is_directory)
|
||||
neoCitiesFiltered.forEach(f => { ncIndex[f.path] = f }) // index
|
||||
const ncFiles = new Set(neoCitiesFiltered.map(f => f.path)) // shape
|
||||
|
||||
const localListingFiltered = localListing.filter(f => !f.stat.isDirectory()) // files only
|
||||
localListingFiltered.forEach(f => { localIndex[forceUnixRelname(f.relname)] = f }) // index
|
||||
const localFiles = new Set(localListingFiltered.map(f => forceUnixRelname(f.relname))) // shape
|
||||
|
||||
const filesToAdd = difference(localFiles, ncFiles)
|
||||
const filesToDelete = difference(ncFiles, localFiles)
|
||||
|
||||
const maybeUpdate = intersection(localFiles, ncFiles)
|
||||
const skipped = new Set()
|
||||
|
||||
for (const p of maybeUpdate) {
|
||||
const local = localIndex[p]
|
||||
const remote = ncIndex[p]
|
||||
|
||||
if (local.stat.size !== remote.size) { filesToAdd.add(p); continue }
|
||||
|
||||
const localSha1 = await sha1FromPath(local.filepath)
|
||||
if (localSha1 !== remote.sha1_hash) { filesToAdd.add(p); continue }
|
||||
|
||||
skipped.add(p)
|
||||
}
|
||||
|
||||
return {
|
||||
filesToUpload: Array.from(filesToAdd).map(p => ({
|
||||
name: forceUnixRelname(localIndex[p].relname),
|
||||
path: localIndex[p].filepath
|
||||
})),
|
||||
filesToDelete: Array.from(filesToDelete).map(p => ncIndex[p].path),
|
||||
filesSkipped: Array.from(skipped).map(p => localIndex[p])
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
neocitiesLocalDiff
|
||||
}
|
||||
|
||||
/**
|
||||
* sha1FromPath returns a sha1 hex from a path
|
||||
* @param {String} p string of the path of the file to hash
|
||||
* @return {Promise<String>} the hex representation of the sha1
|
||||
*/
|
||||
async function sha1FromPath (p) {
|
||||
const rs = fs.createReadStream(p)
|
||||
const hash = crypto.createHash('sha1')
|
||||
|
||||
await ppump(rs, hash)
|
||||
|
||||
return hash.digest('hex')
|
||||
}
|
||||
|
||||
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#Implementing_basic_set_operations
|
||||
|
||||
/**
|
||||
* difference returnss the difference betwen setA and setB.
|
||||
* @param {Set} setA LHS set
|
||||
* @param {Set} setB RHS set
|
||||
* @return {Set} The difference Set
|
||||
*/
|
||||
function difference (setA, setB) {
|
||||
const _difference = new Set(setA)
|
||||
for (const elem of setB) {
|
||||
_difference.delete(elem)
|
||||
}
|
||||
return _difference
|
||||
}
|
||||
|
||||
/**
|
||||
* intersection returns the interesction between setA and setB.
|
||||
* @param {Set} setA setA LHS set
|
||||
* @param {Set} setB setB RHS set
|
||||
* @return {Set} The intersection set between setA and setB.
|
||||
*/
|
||||
function intersection (setA, setB) {
|
||||
const _intersection = new Set()
|
||||
for (const elem of setB) {
|
||||
if (setA.has(elem)) {
|
||||
_intersection.add(elem)
|
||||
}
|
||||
}
|
||||
return _intersection
|
||||
}
|
||||
|
||||
/**
|
||||
* forceUnixRelname forces a OS dependent path to a unix style path.
|
||||
* @param {String} relname String path to convert to unix style.
|
||||
* @return {String} The unix variant of the path
|
||||
*/
|
||||
function forceUnixRelname (relname) {
|
||||
return relname.split(relname.sep).join('/')
|
||||
}
|
||||
|
||||
/**
|
||||
* Example of neocitiesFiles
|
||||
*/
|
||||
// [
|
||||
// {
|
||||
// path: 'img',
|
||||
// is_directory: true,
|
||||
// updated_at: 'Thu, 21 Nov 2019 04:06:17 -0000'
|
||||
// },
|
||||
// {
|
||||
// path: 'index.html',
|
||||
// is_directory: false,
|
||||
// size: 1094,
|
||||
// updated_at: 'Mon, 11 Nov 2019 22:23:16 -0000',
|
||||
// sha1_hash: '7f15617e87d83218223662340f4052d9bb9d096d'
|
||||
// },
|
||||
// {
|
||||
// path: 'neocities.png',
|
||||
// is_directory: false,
|
||||
// size: 13232,
|
||||
// updated_at: 'Mon, 11 Nov 2019 22:23:16 -0000',
|
||||
// sha1_hash: 'fd2ee41b1922a39a716cacb88c323d613b0955e4'
|
||||
// },
|
||||
// {
|
||||
// path: 'not_found.html',
|
||||
// is_directory: false,
|
||||
// size: 347,
|
||||
// updated_at: 'Mon, 11 Nov 2019 22:23:16 -0000',
|
||||
// sha1_hash: 'd7f004e9d3b2eaaa8827f741356f1122dc9eb030'
|
||||
// },
|
||||
// {
|
||||
// path: 'style.css',
|
||||
// is_directory: false,
|
||||
// size: 298,
|
||||
// updated_at: 'Mon, 11 Nov 2019 22:23:16 -0000',
|
||||
// sha1_hash: 'e516457acdb0d00710ab62cc257109ef67209ce8'
|
||||
// }
|
||||
// ]
|
||||
|
||||
/**
|
||||
* Example of localListing
|
||||
*/
|
||||
// [{
|
||||
// root: '/Users/bret/repos/async-folder-walker/fixtures',
|
||||
// filepath: '/Users/bret/repos/async-folder-walker/fixtures/sub-folder/sub-sub-folder',
|
||||
// stat: Stats {
|
||||
// dev: 16777220,
|
||||
// mode: 16877,
|
||||
// nlink: 3,
|
||||
// uid: 501,
|
||||
// gid: 20,
|
||||
// rdev: 0,
|
||||
// blksize: 4096,
|
||||
// ino: 30244023,
|
||||
// size: 96,
|
||||
// blocks: 0,
|
||||
// atimeMs: 1574381262779.8396,
|
||||
// mtimeMs: 1574380914743.5474,
|
||||
// ctimeMs: 1574380914743.5474,
|
||||
// birthtimeMs: 1574380905232.5996,
|
||||
// atime: 2019-11-22T00:07:42.780Z,
|
||||
// mtime: 2019-11-22T00:01:54.744Z,
|
||||
// ctime: 2019-11-22T00:01:54.744Z,
|
||||
// birthtime: 2019-11-22T00:01:45.233Z
|
||||
// },
|
||||
// relname: 'sub-folder/sub-sub-folder',
|
||||
// basename: 'sub-sub-folder'
|
||||
// }]
|
||||
65
node_modules/async-neocities/lib/folder-diff.test.js
generated
vendored
65
node_modules/async-neocities/lib/folder-diff.test.js
generated
vendored
@ -1,65 +0,0 @@
|
||||
const afw = require('async-folder-walker')
|
||||
const path = require('path')
|
||||
const tap = require('tap')
|
||||
|
||||
const { neocitiesLocalDiff } = require('./folder-diff')
|
||||
|
||||
const remoteFiles = [
|
||||
{
|
||||
path: 'img',
|
||||
is_directory: true,
|
||||
updated_at: 'Thu, 21 Nov 2019 04:06:17 -0000'
|
||||
},
|
||||
{
|
||||
path: 'index.html',
|
||||
is_directory: false,
|
||||
size: 1094,
|
||||
updated_at: 'Mon, 11 Nov 2019 22:23:16 -0000',
|
||||
sha1_hash: '7f15617e87d83218223662340f4052d9bb9d096d'
|
||||
},
|
||||
{
|
||||
path: 'neocities.png',
|
||||
is_directory: false,
|
||||
size: 13232,
|
||||
updated_at: 'Mon, 11 Nov 2019 22:23:16 -0000',
|
||||
sha1_hash: 'fd2ee41b1922a39a716cacb88c323d613b0955e4'
|
||||
},
|
||||
{
|
||||
path: 'not_found.html',
|
||||
is_directory: false,
|
||||
size: 347,
|
||||
updated_at: 'Mon, 11 Nov 2019 22:23:16 -0000',
|
||||
sha1_hash: 'd7f004e9d3b2eaaa8827f741356f1122dc9eb030'
|
||||
},
|
||||
{
|
||||
path: 'style.css',
|
||||
is_directory: false,
|
||||
size: 298,
|
||||
updated_at: 'Mon, 11 Nov 2019 22:23:16 -0000',
|
||||
sha1_hash: 'e516457acdb0d00710ab62cc257109ef67209ce8'
|
||||
}
|
||||
]
|
||||
|
||||
tap.test('test differ', async t => {
|
||||
const localFiles = await afw.allFiles(path.join(__dirname, '../fixtures'), {
|
||||
shaper: f => f
|
||||
})
|
||||
|
||||
const { filesToUpload, filesToDelete, filesSkipped } = await neocitiesLocalDiff(remoteFiles, localFiles)
|
||||
|
||||
t.true(['tootzzz.png', 'toot.gif', 'cat.png'].every(path => {
|
||||
const found = filesToUpload.find(ftu => ftu.name === path)
|
||||
t.ok(found.path && found.name, 'each file to upload has a name and path')
|
||||
return found
|
||||
}), 'every file to upload is included')
|
||||
|
||||
t.deepEqual(filesToDelete, [
|
||||
'not_found.html',
|
||||
'style.css'
|
||||
], 'filesToDelete returned correctly')
|
||||
|
||||
t.true(['neocities.png'].every(path => {
|
||||
const found = filesSkipped.find(fs => fs.relname === path)
|
||||
return found
|
||||
}), 'every file skipped is included')
|
||||
})
|
||||
60
node_modules/async-neocities/lib/stats-handler.js
generated
vendored
60
node_modules/async-neocities/lib/stats-handler.js
generated
vendored
@ -1,60 +0,0 @@
|
||||
const prettyBytes = require('pretty-bytes')
|
||||
|
||||
// Progress API constants
|
||||
const START = 'start'
|
||||
const PROGRESS = 'progress' // progress updates
|
||||
const STOP = 'stop'
|
||||
const SKIP = 'skip'
|
||||
|
||||
function statsHandler (opts = {}) {
|
||||
let progressInterval
|
||||
const lastStats = {}
|
||||
|
||||
return (stats) => {
|
||||
switch (stats.status) {
|
||||
case START: {
|
||||
console.log(`Starting ${stats.stage} stage...`)
|
||||
break
|
||||
}
|
||||
case STOP: {
|
||||
console.log(`Finished ${stats.stage} stage.`)
|
||||
break
|
||||
}
|
||||
case SKIP: {
|
||||
console.log(`Skipping ${stats.stage} stage.`)
|
||||
break
|
||||
}
|
||||
case PROGRESS: {
|
||||
progressHandler(stats)
|
||||
break
|
||||
}
|
||||
default: {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function progressHandler (stats) {
|
||||
Object.assign(lastStats, stats)
|
||||
if (!stats.complete && stats.progress < 1) {
|
||||
if (!progressInterval) {
|
||||
progressInterval = setInterval(logProgress, 500, lastStats)
|
||||
logProgress(lastStats)
|
||||
}
|
||||
} else {
|
||||
if (progressInterval) {
|
||||
clearInterval(progressInterval)
|
||||
logProgress(lastStats)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function logProgress (stats) {
|
||||
let logLine = `Stage ${stats.stage}: ${(stats.progress * 100).toFixed(2)}%`
|
||||
if (stats.bytesWritten != null && stats.totalBytes != null) {
|
||||
logLine = logLine + ` (${prettyBytes(stats.bytesWritten)} / ${prettyBytes(stats.totalBytes)})`
|
||||
}
|
||||
console.log(logLine)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = statsHandler
|
||||
38
node_modules/async-neocities/lib/stream-meter.js
generated
vendored
38
node_modules/async-neocities/lib/stream-meter.js
generated
vendored
@ -1,38 +0,0 @@
|
||||
const { Writable, Transform } = require('streamx')
|
||||
const pump = require('pump')
|
||||
const pumpify = require('pumpify')
|
||||
|
||||
function getStreamLength (readable) {
|
||||
let length = 0
|
||||
|
||||
const dummyLoad = new Writable({
|
||||
write (data, cb) {
|
||||
length += data.length
|
||||
cb(null)
|
||||
}
|
||||
})
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
pump(readable, dummyLoad, (err) => {
|
||||
if (err) return reject(err)
|
||||
resolve(length)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function meterStream (readable, statsCb) {
|
||||
let bytesRead = 0
|
||||
const meter = new Transform({
|
||||
transform (data, cb) {
|
||||
bytesRead += data.length
|
||||
statsCb(bytesRead)
|
||||
cb(null, data)
|
||||
}
|
||||
})
|
||||
return pumpify(readable, meter)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getStreamLength,
|
||||
meterStream
|
||||
}
|
||||
34
node_modules/async-neocities/lib/timer.js
generated
vendored
34
node_modules/async-neocities/lib/timer.js
generated
vendored
@ -1,34 +0,0 @@
|
||||
/**
|
||||
* Simple timer lets you record start and stop times, with an elapsed time getter.
|
||||
*/
|
||||
class SimpleTimer {
|
||||
constructor (startTime) {
|
||||
this.start = startTime || Date.now()
|
||||
this.end = null
|
||||
this.stopped = false
|
||||
}
|
||||
|
||||
get elapsed () {
|
||||
if (this.stopped) {
|
||||
return this.end - this.start
|
||||
} else {
|
||||
return Date.now() - this.start
|
||||
}
|
||||
}
|
||||
|
||||
stop () {
|
||||
if (this.stopped) return
|
||||
this.stopped = true
|
||||
this.end = Date.now()
|
||||
}
|
||||
|
||||
toString () {
|
||||
return this.elapsed
|
||||
}
|
||||
|
||||
toJSON () {
|
||||
return this.elapsed
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SimpleTimer
|
||||
84
node_modules/async-neocities/package.json
generated
vendored
84
node_modules/async-neocities/package.json
generated
vendored
@ -1,84 +0,0 @@
|
||||
{
|
||||
"_from": "async-neocities@1.1.6",
|
||||
"_id": "async-neocities@1.1.6",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-q5fTVttBaN9znGxqxxDAh/ks+bZngIJPu6zPS7nlbJLC9NnOhrcP5Mu0VntxgEBtAuaExyI6uH/C+CxKSW0LeQ==",
|
||||
"_location": "/async-neocities",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "async-neocities@1.1.6",
|
||||
"name": "async-neocities",
|
||||
"escapedName": "async-neocities",
|
||||
"rawSpec": "1.1.6",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.1.6"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/async-neocities/-/async-neocities-1.1.6.tgz",
|
||||
"_shasum": "405b45565ccbe9c4ea56e65552ae9c48c20a0309",
|
||||
"_spec": "async-neocities@1.1.6",
|
||||
"_where": "/Users/bret/repos/deploy-to-neocities",
|
||||
"author": {
|
||||
"name": "Bret Comnes",
|
||||
"email": "bcomnes@gmail.com",
|
||||
"url": "https://bret.io"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/bcomnes/async-neocities/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"async-folder-walker": "^2.0.1",
|
||||
"fetch-errors": "^2.0.1",
|
||||
"form-data": "^3.0.0",
|
||||
"nanoassert": "^2.0.0",
|
||||
"node-fetch": "^2.6.0",
|
||||
"pretty-bytes": "^5.3.0",
|
||||
"pump": "^3.0.0",
|
||||
"pumpify": "^2.0.1",
|
||||
"qs": "^6.9.1",
|
||||
"streamx": "^2.6.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "WIP - nothing to see here",
|
||||
"devDependencies": {
|
||||
"auto-changelog": "^1.16.2",
|
||||
"dependency-check": "^4.1.0",
|
||||
"gh-release": "^3.5.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"standard": "^13.1.0",
|
||||
"tap": "^14.10.2"
|
||||
},
|
||||
"homepage": "https://github.com/bcomnes/async-neocities",
|
||||
"keywords": [
|
||||
"neocities",
|
||||
"async",
|
||||
"api client",
|
||||
"static hosting"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "async-neocities",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/bcomnes/async-neocities.git"
|
||||
},
|
||||
"scripts": {
|
||||
"prepublishOnly": "git push --follow-tags && gh-release",
|
||||
"test": "run-s test:*",
|
||||
"test:deps": "dependency-check . --no-dev --no-peer",
|
||||
"test:standard": "standard",
|
||||
"test:tape": "tap",
|
||||
"version": "auto-changelog -p --template keepachangelog auto-changelog --breaking-pattern 'BREAKING:' && git add CHANGELOG.md"
|
||||
},
|
||||
"standard": {
|
||||
"ignore": [
|
||||
"dist"
|
||||
]
|
||||
},
|
||||
"version": "1.1.6"
|
||||
}
|
||||
127
node_modules/async-neocities/test.js
generated
vendored
127
node_modules/async-neocities/test.js
generated
vendored
@ -1,127 +0,0 @@
|
||||
const tap = require('tap')
|
||||
|
||||
const { readFileSync } = require('fs')
|
||||
const { resolve } = require('path')
|
||||
const NeocitiesAPIClient = require('.')
|
||||
const statsHanlder = require('./lib/stats-handler')
|
||||
|
||||
let token = process.env.NEOCITIES_API_TOKEN
|
||||
let fakeToken = false
|
||||
|
||||
if (!token) {
|
||||
try {
|
||||
const config = JSON.parse(readFileSync(resolve(__dirname, 'config.json')))
|
||||
token = config.token
|
||||
tap.test('token loaded', async t => {
|
||||
t.ok(token)
|
||||
})
|
||||
} catch (e) {
|
||||
console.warn('error loading config.json')
|
||||
console.warn('using fake token, live tests disabled')
|
||||
fakeToken = true
|
||||
token = '123456'
|
||||
}
|
||||
}
|
||||
|
||||
tap.test('basic client api', async t => {
|
||||
const client = new NeocitiesAPIClient(token)
|
||||
|
||||
t.ok(client.info, 'info method available')
|
||||
t.ok(client.list, 'list method available')
|
||||
t.ok(client.get, 'get method available')
|
||||
t.ok(client.post, 'post method available')
|
||||
})
|
||||
|
||||
if (!fakeToken) {
|
||||
tap.test('can get info about site', async t => {
|
||||
const client = new NeocitiesAPIClient(token)
|
||||
|
||||
const info = await client.info()
|
||||
// console.log(info)
|
||||
t.equal(info.result, 'success', 'info requesst successfull')
|
||||
const list = await client.list()
|
||||
// console.log(list)
|
||||
t.equal(list.result, 'success', 'list result successfull')
|
||||
})
|
||||
|
||||
// test('form data works the way I think', t => {
|
||||
// const form = new FormData();
|
||||
// const p = resolve(__dirname, 'package.json');
|
||||
// form.append('package.json', next => next(createReadStream(p)));
|
||||
//
|
||||
// const concatStream = concat((data) => {
|
||||
// console.log(data);
|
||||
// t.end();
|
||||
// });
|
||||
//
|
||||
// form.on('error', (err) => {
|
||||
// t.error(err);
|
||||
// });
|
||||
// form.pipe(concatStream);
|
||||
// });
|
||||
|
||||
tap.test('can upload and delete files', async t => {
|
||||
const client = new NeocitiesAPIClient(token)
|
||||
|
||||
const uploadResults = await client.upload([
|
||||
{
|
||||
name: 'toot.gif',
|
||||
path: resolve(__dirname, 'fixtures/toot.gif')
|
||||
},
|
||||
{
|
||||
name: 'img/tootzzz.png',
|
||||
path: resolve(__dirname, 'fixtures/tootzzz.png')
|
||||
}
|
||||
])
|
||||
|
||||
// console.log(uploadResults)
|
||||
t.equal(uploadResults.result, 'success', 'list result successfull')
|
||||
|
||||
const deleteResults = await client.delete([
|
||||
'toot.gif',
|
||||
'img/tootzzz.png'
|
||||
])
|
||||
// console.log(deleteResults)
|
||||
t.equal(deleteResults.result, 'success', 'list result successfull')
|
||||
})
|
||||
|
||||
tap.test('can deploy folders', async t => {
|
||||
const client = new NeocitiesAPIClient(token)
|
||||
|
||||
const deployStats = await client.deploy(
|
||||
resolve(__dirname, 'fixtures'),
|
||||
{
|
||||
statsCb: statsHanlder(),
|
||||
cleanup: false
|
||||
}
|
||||
)
|
||||
|
||||
t.ok(deployStats)
|
||||
|
||||
// console.dir(deployStats, { depth: 99, colors: true })
|
||||
|
||||
const redeployStats = await client.deploy(
|
||||
resolve(__dirname, 'fixtures'),
|
||||
{
|
||||
statsCb: statsHanlder(),
|
||||
cleanup: false
|
||||
}
|
||||
)
|
||||
|
||||
t.ok(redeployStats)
|
||||
|
||||
// console.dir(redeployStats, { depth: 99, colors: true })
|
||||
|
||||
const cleanupStats = await client.deploy(
|
||||
resolve(__dirname, 'fixtures/empty'),
|
||||
{
|
||||
statsCb: statsHanlder(),
|
||||
cleanup: true
|
||||
}
|
||||
)
|
||||
|
||||
t.ok(cleanupStats)
|
||||
|
||||
// console.dir(cleanupStats, { depth: 99, colors: true })
|
||||
})
|
||||
}
|
||||
21
node_modules/asynckit/LICENSE
generated
vendored
21
node_modules/asynckit/LICENSE
generated
vendored
@ -1,21 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Alex Indigo
|
||||
|
||||
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.
|
||||
233
node_modules/asynckit/README.md
generated
vendored
233
node_modules/asynckit/README.md
generated
vendored
@ -1,233 +0,0 @@
|
||||
# asynckit [](https://www.npmjs.com/package/asynckit)
|
||||
|
||||
Minimal async jobs utility library, with streams support.
|
||||
|
||||
[](https://travis-ci.org/alexindigo/asynckit)
|
||||
[](https://travis-ci.org/alexindigo/asynckit)
|
||||
[](https://ci.appveyor.com/project/alexindigo/asynckit)
|
||||
|
||||
[](https://coveralls.io/github/alexindigo/asynckit?branch=master)
|
||||
[](https://david-dm.org/alexindigo/asynckit)
|
||||
[](https://www.bithound.io/github/alexindigo/asynckit)
|
||||
|
||||
<!-- [](https://www.npmjs.com/package/reamde) -->
|
||||
|
||||
AsyncKit provides harness for `parallel` and `serial` iterators over list of items represented by arrays or objects.
|
||||
Optionally it accepts abort function (should be synchronously return by iterator for each item), and terminates left over jobs upon an error event. For specific iteration order built-in (`ascending` and `descending`) and custom sort helpers also supported, via `asynckit.serialOrdered` method.
|
||||
|
||||
It ensures async operations to keep behavior more stable and prevent `Maximum call stack size exceeded` errors, from sync iterators.
|
||||
|
||||
| compression | size |
|
||||
| :----------------- | -------: |
|
||||
| asynckit.js | 12.34 kB |
|
||||
| asynckit.min.js | 4.11 kB |
|
||||
| asynckit.min.js.gz | 1.47 kB |
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
$ npm install --save asynckit
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Parallel Jobs
|
||||
|
||||
Runs iterator over provided array in parallel. Stores output in the `result` array,
|
||||
on the matching positions. In unlikely event of an error from one of the jobs,
|
||||
will terminate rest of the active jobs (if abort function is provided)
|
||||
and return error along with salvaged data to the main callback function.
|
||||
|
||||
#### Input Array
|
||||
|
||||
```javascript
|
||||
var parallel = require('asynckit').parallel
|
||||
, assert = require('assert')
|
||||
;
|
||||
|
||||
var source = [ 1, 1, 4, 16, 64, 32, 8, 2 ]
|
||||
, expectedResult = [ 2, 2, 8, 32, 128, 64, 16, 4 ]
|
||||
, expectedTarget = [ 1, 1, 2, 4, 8, 16, 32, 64 ]
|
||||
, target = []
|
||||
;
|
||||
|
||||
parallel(source, asyncJob, function(err, result)
|
||||
{
|
||||
assert.deepEqual(result, expectedResult);
|
||||
assert.deepEqual(target, expectedTarget);
|
||||
});
|
||||
|
||||
// async job accepts one element from the array
|
||||
// and a callback function
|
||||
function asyncJob(item, cb)
|
||||
{
|
||||
// different delays (in ms) per item
|
||||
var delay = item * 25;
|
||||
|
||||
// pretend different jobs take different time to finish
|
||||
// and not in consequential order
|
||||
var timeoutId = setTimeout(function() {
|
||||
target.push(item);
|
||||
cb(null, item * 2);
|
||||
}, delay);
|
||||
|
||||
// allow to cancel "leftover" jobs upon error
|
||||
// return function, invoking of which will abort this job
|
||||
return clearTimeout.bind(null, timeoutId);
|
||||
}
|
||||
```
|
||||
|
||||
More examples could be found in [test/test-parallel-array.js](test/test-parallel-array.js).
|
||||
|
||||
#### Input Object
|
||||
|
||||
Also it supports named jobs, listed via object.
|
||||
|
||||
```javascript
|
||||
var parallel = require('asynckit/parallel')
|
||||
, assert = require('assert')
|
||||
;
|
||||
|
||||
var source = { first: 1, one: 1, four: 4, sixteen: 16, sixtyFour: 64, thirtyTwo: 32, eight: 8, two: 2 }
|
||||
, expectedResult = { first: 2, one: 2, four: 8, sixteen: 32, sixtyFour: 128, thirtyTwo: 64, eight: 16, two: 4 }
|
||||
, expectedTarget = [ 1, 1, 2, 4, 8, 16, 32, 64 ]
|
||||
, expectedKeys = [ 'first', 'one', 'two', 'four', 'eight', 'sixteen', 'thirtyTwo', 'sixtyFour' ]
|
||||
, target = []
|
||||
, keys = []
|
||||
;
|
||||
|
||||
parallel(source, asyncJob, function(err, result)
|
||||
{
|
||||
assert.deepEqual(result, expectedResult);
|
||||
assert.deepEqual(target, expectedTarget);
|
||||
assert.deepEqual(keys, expectedKeys);
|
||||
});
|
||||
|
||||
// supports full value, key, callback (shortcut) interface
|
||||
function asyncJob(item, key, cb)
|
||||
{
|
||||
// different delays (in ms) per item
|
||||
var delay = item * 25;
|
||||
|
||||
// pretend different jobs take different time to finish
|
||||
// and not in consequential order
|
||||
var timeoutId = setTimeout(function() {
|
||||
keys.push(key);
|
||||
target.push(item);
|
||||
cb(null, item * 2);
|
||||
}, delay);
|
||||
|
||||
// allow to cancel "leftover" jobs upon error
|
||||
// return function, invoking of which will abort this job
|
||||
return clearTimeout.bind(null, timeoutId);
|
||||
}
|
||||
```
|
||||
|
||||
More examples could be found in [test/test-parallel-object.js](test/test-parallel-object.js).
|
||||
|
||||
### Serial Jobs
|
||||
|
||||
Runs iterator over provided array sequentially. Stores output in the `result` array,
|
||||
on the matching positions. In unlikely event of an error from one of the jobs,
|
||||
will not proceed to the rest of the items in the list
|
||||
and return error along with salvaged data to the main callback function.
|
||||
|
||||
#### Input Array
|
||||
|
||||
```javascript
|
||||
var serial = require('asynckit/serial')
|
||||
, assert = require('assert')
|
||||
;
|
||||
|
||||
var source = [ 1, 1, 4, 16, 64, 32, 8, 2 ]
|
||||
, expectedResult = [ 2, 2, 8, 32, 128, 64, 16, 4 ]
|
||||
, expectedTarget = [ 0, 1, 2, 3, 4, 5, 6, 7 ]
|
||||
, target = []
|
||||
;
|
||||
|
||||
serial(source, asyncJob, function(err, result)
|
||||
{
|
||||
assert.deepEqual(result, expectedResult);
|
||||
assert.deepEqual(target, expectedTarget);
|
||||
});
|
||||
|
||||
// extended interface (item, key, callback)
|
||||
// also supported for arrays
|
||||
function asyncJob(item, key, cb)
|
||||
{
|
||||
target.push(key);
|
||||
|
||||
// it will be automatically made async
|
||||
// even it iterator "returns" in the same event loop
|
||||
cb(null, item * 2);
|
||||
}
|
||||
```
|
||||
|
||||
More examples could be found in [test/test-serial-array.js](test/test-serial-array.js).
|
||||
|
||||
#### Input Object
|
||||
|
||||
Also it supports named jobs, listed via object.
|
||||
|
||||
```javascript
|
||||
var serial = require('asynckit').serial
|
||||
, assert = require('assert')
|
||||
;
|
||||
|
||||
var source = [ 1, 1, 4, 16, 64, 32, 8, 2 ]
|
||||
, expectedResult = [ 2, 2, 8, 32, 128, 64, 16, 4 ]
|
||||
, expectedTarget = [ 0, 1, 2, 3, 4, 5, 6, 7 ]
|
||||
, target = []
|
||||
;
|
||||
|
||||
var source = { first: 1, one: 1, four: 4, sixteen: 16, sixtyFour: 64, thirtyTwo: 32, eight: 8, two: 2 }
|
||||
, expectedResult = { first: 2, one: 2, four: 8, sixteen: 32, sixtyFour: 128, thirtyTwo: 64, eight: 16, two: 4 }
|
||||
, expectedTarget = [ 1, 1, 4, 16, 64, 32, 8, 2 ]
|
||||
, target = []
|
||||
;
|
||||
|
||||
|
||||
serial(source, asyncJob, function(err, result)
|
||||
{
|
||||
assert.deepEqual(result, expectedResult);
|
||||
assert.deepEqual(target, expectedTarget);
|
||||
});
|
||||
|
||||
// shortcut interface (item, callback)
|
||||
// works for object as well as for the arrays
|
||||
function asyncJob(item, cb)
|
||||
{
|
||||
target.push(item);
|
||||
|
||||
// it will be automatically made async
|
||||
// even it iterator "returns" in the same event loop
|
||||
cb(null, item * 2);
|
||||
}
|
||||
```
|
||||
|
||||
More examples could be found in [test/test-serial-object.js](test/test-serial-object.js).
|
||||
|
||||
_Note: Since _object_ is an _unordered_ collection of properties,
|
||||
it may produce unexpected results with sequential iterations.
|
||||
Whenever order of the jobs' execution is important please use `serialOrdered` method._
|
||||
|
||||
### Ordered Serial Iterations
|
||||
|
||||
TBD
|
||||
|
||||
For example [compare-property](compare-property) package.
|
||||
|
||||
### Streaming interface
|
||||
|
||||
TBD
|
||||
|
||||
## Want to Know More?
|
||||
|
||||
More examples can be found in [test folder](test/).
|
||||
|
||||
Or open an [issue](https://github.com/alexindigo/asynckit/issues) with questions and/or suggestions.
|
||||
|
||||
## License
|
||||
|
||||
AsyncKit is licensed under the MIT license.
|
||||
76
node_modules/asynckit/bench.js
generated
vendored
76
node_modules/asynckit/bench.js
generated
vendored
@ -1,76 +0,0 @@
|
||||
/* eslint no-console: "off" */
|
||||
|
||||
var asynckit = require('./')
|
||||
, async = require('async')
|
||||
, assert = require('assert')
|
||||
, expected = 0
|
||||
;
|
||||
|
||||
var Benchmark = require('benchmark');
|
||||
var suite = new Benchmark.Suite;
|
||||
|
||||
var source = [];
|
||||
for (var z = 1; z < 100; z++)
|
||||
{
|
||||
source.push(z);
|
||||
expected += z;
|
||||
}
|
||||
|
||||
suite
|
||||
// add tests
|
||||
|
||||
.add('async.map', function(deferred)
|
||||
{
|
||||
var total = 0;
|
||||
|
||||
async.map(source,
|
||||
function(i, cb)
|
||||
{
|
||||
setImmediate(function()
|
||||
{
|
||||
total += i;
|
||||
cb(null, total);
|
||||
});
|
||||
},
|
||||
function(err, result)
|
||||
{
|
||||
assert.ifError(err);
|
||||
assert.equal(result[result.length - 1], expected);
|
||||
deferred.resolve();
|
||||
});
|
||||
}, {'defer': true})
|
||||
|
||||
|
||||
.add('asynckit.parallel', function(deferred)
|
||||
{
|
||||
var total = 0;
|
||||
|
||||
asynckit.parallel(source,
|
||||
function(i, cb)
|
||||
{
|
||||
setImmediate(function()
|
||||
{
|
||||
total += i;
|
||||
cb(null, total);
|
||||
});
|
||||
},
|
||||
function(err, result)
|
||||
{
|
||||
assert.ifError(err);
|
||||
assert.equal(result[result.length - 1], expected);
|
||||
deferred.resolve();
|
||||
});
|
||||
}, {'defer': true})
|
||||
|
||||
|
||||
// add listeners
|
||||
.on('cycle', function(ev)
|
||||
{
|
||||
console.log(String(ev.target));
|
||||
})
|
||||
.on('complete', function()
|
||||
{
|
||||
console.log('Fastest is ' + this.filter('fastest').map('name'));
|
||||
})
|
||||
// run async
|
||||
.run({ 'async': true });
|
||||
6
node_modules/asynckit/index.js
generated
vendored
6
node_modules/asynckit/index.js
generated
vendored
@ -1,6 +0,0 @@
|
||||
module.exports =
|
||||
{
|
||||
parallel : require('./parallel.js'),
|
||||
serial : require('./serial.js'),
|
||||
serialOrdered : require('./serialOrdered.js')
|
||||
};
|
||||
29
node_modules/asynckit/lib/abort.js
generated
vendored
29
node_modules/asynckit/lib/abort.js
generated
vendored
@ -1,29 +0,0 @@
|
||||
// API
|
||||
module.exports = abort;
|
||||
|
||||
/**
|
||||
* Aborts leftover active jobs
|
||||
*
|
||||
* @param {object} state - current state object
|
||||
*/
|
||||
function abort(state)
|
||||
{
|
||||
Object.keys(state.jobs).forEach(clean.bind(state));
|
||||
|
||||
// reset leftover jobs
|
||||
state.jobs = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up leftover job by invoking abort function for the provided job id
|
||||
*
|
||||
* @this state
|
||||
* @param {string|number} key - job id to abort
|
||||
*/
|
||||
function clean(key)
|
||||
{
|
||||
if (typeof this.jobs[key] == 'function')
|
||||
{
|
||||
this.jobs[key]();
|
||||
}
|
||||
}
|
||||
34
node_modules/asynckit/lib/async.js
generated
vendored
34
node_modules/asynckit/lib/async.js
generated
vendored
@ -1,34 +0,0 @@
|
||||
var defer = require('./defer.js');
|
||||
|
||||
// API
|
||||
module.exports = async;
|
||||
|
||||
/**
|
||||
* Runs provided callback asynchronously
|
||||
* even if callback itself is not
|
||||
*
|
||||
* @param {function} callback - callback to invoke
|
||||
* @returns {function} - augmented callback
|
||||
*/
|
||||
function async(callback)
|
||||
{
|
||||
var isAsync = false;
|
||||
|
||||
// check if async happened
|
||||
defer(function() { isAsync = true; });
|
||||
|
||||
return function async_callback(err, result)
|
||||
{
|
||||
if (isAsync)
|
||||
{
|
||||
callback(err, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
defer(function nextTick_callback()
|
||||
{
|
||||
callback(err, result);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
26
node_modules/asynckit/lib/defer.js
generated
vendored
26
node_modules/asynckit/lib/defer.js
generated
vendored
@ -1,26 +0,0 @@
|
||||
module.exports = defer;
|
||||
|
||||
/**
|
||||
* Runs provided function on next iteration of the event loop
|
||||
*
|
||||
* @param {function} fn - function to run
|
||||
*/
|
||||
function defer(fn)
|
||||
{
|
||||
var nextTick = typeof setImmediate == 'function'
|
||||
? setImmediate
|
||||
: (
|
||||
typeof process == 'object' && typeof process.nextTick == 'function'
|
||||
? process.nextTick
|
||||
: null
|
||||
);
|
||||
|
||||
if (nextTick)
|
||||
{
|
||||
nextTick(fn);
|
||||
}
|
||||
else
|
||||
{
|
||||
setTimeout(fn, 0);
|
||||
}
|
||||
}
|
||||
75
node_modules/asynckit/lib/iterate.js
generated
vendored
75
node_modules/asynckit/lib/iterate.js
generated
vendored
@ -1,75 +0,0 @@
|
||||
var async = require('./async.js')
|
||||
, abort = require('./abort.js')
|
||||
;
|
||||
|
||||
// API
|
||||
module.exports = iterate;
|
||||
|
||||
/**
|
||||
* Iterates over each job object
|
||||
*
|
||||
* @param {array|object} list - array or object (named list) to iterate over
|
||||
* @param {function} iterator - iterator to run
|
||||
* @param {object} state - current job status
|
||||
* @param {function} callback - invoked when all elements processed
|
||||
*/
|
||||
function iterate(list, iterator, state, callback)
|
||||
{
|
||||
// store current index
|
||||
var key = state['keyedList'] ? state['keyedList'][state.index] : state.index;
|
||||
|
||||
state.jobs[key] = runJob(iterator, key, list[key], function(error, output)
|
||||
{
|
||||
// don't repeat yourself
|
||||
// skip secondary callbacks
|
||||
if (!(key in state.jobs))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// clean up jobs
|
||||
delete state.jobs[key];
|
||||
|
||||
if (error)
|
||||
{
|
||||
// don't process rest of the results
|
||||
// stop still active jobs
|
||||
// and reset the list
|
||||
abort(state);
|
||||
}
|
||||
else
|
||||
{
|
||||
state.results[key] = output;
|
||||
}
|
||||
|
||||
// return salvaged results
|
||||
callback(error, state.results);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs iterator over provided job element
|
||||
*
|
||||
* @param {function} iterator - iterator to invoke
|
||||
* @param {string|number} key - key/index of the element in the list of jobs
|
||||
* @param {mixed} item - job description
|
||||
* @param {function} callback - invoked after iterator is done with the job
|
||||
* @returns {function|mixed} - job abort function or something else
|
||||
*/
|
||||
function runJob(iterator, key, item, callback)
|
||||
{
|
||||
var aborter;
|
||||
|
||||
// allow shortcut if iterator expects only two arguments
|
||||
if (iterator.length == 2)
|
||||
{
|
||||
aborter = iterator(item, async(callback));
|
||||
}
|
||||
// otherwise go with full three arguments
|
||||
else
|
||||
{
|
||||
aborter = iterator(item, key, async(callback));
|
||||
}
|
||||
|
||||
return aborter;
|
||||
}
|
||||
91
node_modules/asynckit/lib/readable_asynckit.js
generated
vendored
91
node_modules/asynckit/lib/readable_asynckit.js
generated
vendored
@ -1,91 +0,0 @@
|
||||
var streamify = require('./streamify.js')
|
||||
, defer = require('./defer.js')
|
||||
;
|
||||
|
||||
// API
|
||||
module.exports = ReadableAsyncKit;
|
||||
|
||||
/**
|
||||
* Base constructor for all streams
|
||||
* used to hold properties/methods
|
||||
*/
|
||||
function ReadableAsyncKit()
|
||||
{
|
||||
ReadableAsyncKit.super_.apply(this, arguments);
|
||||
|
||||
// list of active jobs
|
||||
this.jobs = {};
|
||||
|
||||
// add stream methods
|
||||
this.destroy = destroy;
|
||||
this._start = _start;
|
||||
this._read = _read;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys readable stream,
|
||||
* by aborting outstanding jobs
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
function destroy()
|
||||
{
|
||||
if (this.destroyed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.destroyed = true;
|
||||
|
||||
if (typeof this.terminator == 'function')
|
||||
{
|
||||
this.terminator();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts provided jobs in async manner
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function _start()
|
||||
{
|
||||
// first argument – runner function
|
||||
var runner = arguments[0]
|
||||
// take away first argument
|
||||
, args = Array.prototype.slice.call(arguments, 1)
|
||||
// second argument - input data
|
||||
, input = args[0]
|
||||
// last argument - result callback
|
||||
, endCb = streamify.callback.call(this, args[args.length - 1])
|
||||
;
|
||||
|
||||
args[args.length - 1] = endCb;
|
||||
// third argument - iterator
|
||||
args[1] = streamify.iterator.call(this, args[1]);
|
||||
|
||||
// allow time for proper setup
|
||||
defer(function()
|
||||
{
|
||||
if (!this.destroyed)
|
||||
{
|
||||
this.terminator = runner.apply(null, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
endCb(null, Array.isArray(input) ? [] : {});
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implement _read to comply with Readable streams
|
||||
* Doesn't really make sense for flowing object mode
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function _read()
|
||||
{
|
||||
|
||||
}
|
||||
25
node_modules/asynckit/lib/readable_parallel.js
generated
vendored
25
node_modules/asynckit/lib/readable_parallel.js
generated
vendored
@ -1,25 +0,0 @@
|
||||
var parallel = require('../parallel.js');
|
||||
|
||||
// API
|
||||
module.exports = ReadableParallel;
|
||||
|
||||
/**
|
||||
* Streaming wrapper to `asynckit.parallel`
|
||||
*
|
||||
* @param {array|object} list - array or object (named list) to iterate over
|
||||
* @param {function} iterator - iterator to run
|
||||
* @param {function} callback - invoked when all elements processed
|
||||
* @returns {stream.Readable#}
|
||||
*/
|
||||
function ReadableParallel(list, iterator, callback)
|
||||
{
|
||||
if (!(this instanceof ReadableParallel))
|
||||
{
|
||||
return new ReadableParallel(list, iterator, callback);
|
||||
}
|
||||
|
||||
// turn on object mode
|
||||
ReadableParallel.super_.call(this, {objectMode: true});
|
||||
|
||||
this._start(parallel, list, iterator, callback);
|
||||
}
|
||||
25
node_modules/asynckit/lib/readable_serial.js
generated
vendored
25
node_modules/asynckit/lib/readable_serial.js
generated
vendored
@ -1,25 +0,0 @@
|
||||
var serial = require('../serial.js');
|
||||
|
||||
// API
|
||||
module.exports = ReadableSerial;
|
||||
|
||||
/**
|
||||
* Streaming wrapper to `asynckit.serial`
|
||||
*
|
||||
* @param {array|object} list - array or object (named list) to iterate over
|
||||
* @param {function} iterator - iterator to run
|
||||
* @param {function} callback - invoked when all elements processed
|
||||
* @returns {stream.Readable#}
|
||||
*/
|
||||
function ReadableSerial(list, iterator, callback)
|
||||
{
|
||||
if (!(this instanceof ReadableSerial))
|
||||
{
|
||||
return new ReadableSerial(list, iterator, callback);
|
||||
}
|
||||
|
||||
// turn on object mode
|
||||
ReadableSerial.super_.call(this, {objectMode: true});
|
||||
|
||||
this._start(serial, list, iterator, callback);
|
||||
}
|
||||
29
node_modules/asynckit/lib/readable_serial_ordered.js
generated
vendored
29
node_modules/asynckit/lib/readable_serial_ordered.js
generated
vendored
@ -1,29 +0,0 @@
|
||||
var serialOrdered = require('../serialOrdered.js');
|
||||
|
||||
// API
|
||||
module.exports = ReadableSerialOrdered;
|
||||
// expose sort helpers
|
||||
module.exports.ascending = serialOrdered.ascending;
|
||||
module.exports.descending = serialOrdered.descending;
|
||||
|
||||
/**
|
||||
* Streaming wrapper to `asynckit.serialOrdered`
|
||||
*
|
||||
* @param {array|object} list - array or object (named list) to iterate over
|
||||
* @param {function} iterator - iterator to run
|
||||
* @param {function} sortMethod - custom sort function
|
||||
* @param {function} callback - invoked when all elements processed
|
||||
* @returns {stream.Readable#}
|
||||
*/
|
||||
function ReadableSerialOrdered(list, iterator, sortMethod, callback)
|
||||
{
|
||||
if (!(this instanceof ReadableSerialOrdered))
|
||||
{
|
||||
return new ReadableSerialOrdered(list, iterator, sortMethod, callback);
|
||||
}
|
||||
|
||||
// turn on object mode
|
||||
ReadableSerialOrdered.super_.call(this, {objectMode: true});
|
||||
|
||||
this._start(serialOrdered, list, iterator, sortMethod, callback);
|
||||
}
|
||||
37
node_modules/asynckit/lib/state.js
generated
vendored
37
node_modules/asynckit/lib/state.js
generated
vendored
@ -1,37 +0,0 @@
|
||||
// API
|
||||
module.exports = state;
|
||||
|
||||
/**
|
||||
* Creates initial state object
|
||||
* for iteration over list
|
||||
*
|
||||
* @param {array|object} list - list to iterate over
|
||||
* @param {function|null} sortMethod - function to use for keys sort,
|
||||
* or `null` to keep them as is
|
||||
* @returns {object} - initial state object
|
||||
*/
|
||||
function state(list, sortMethod)
|
||||
{
|
||||
var isNamedList = !Array.isArray(list)
|
||||
, initState =
|
||||
{
|
||||
index : 0,
|
||||
keyedList: isNamedList || sortMethod ? Object.keys(list) : null,
|
||||
jobs : {},
|
||||
results : isNamedList ? {} : [],
|
||||
size : isNamedList ? Object.keys(list).length : list.length
|
||||
}
|
||||
;
|
||||
|
||||
if (sortMethod)
|
||||
{
|
||||
// sort array keys based on it's values
|
||||
// sort object's keys just on own merit
|
||||
initState.keyedList.sort(isNamedList ? sortMethod : function(a, b)
|
||||
{
|
||||
return sortMethod(list[a], list[b]);
|
||||
});
|
||||
}
|
||||
|
||||
return initState;
|
||||
}
|
||||
141
node_modules/asynckit/lib/streamify.js
generated
vendored
141
node_modules/asynckit/lib/streamify.js
generated
vendored
@ -1,141 +0,0 @@
|
||||
var async = require('./async.js');
|
||||
|
||||
// API
|
||||
module.exports = {
|
||||
iterator: wrapIterator,
|
||||
callback: wrapCallback
|
||||
};
|
||||
|
||||
/**
|
||||
* Wraps iterators with long signature
|
||||
*
|
||||
* @this ReadableAsyncKit#
|
||||
* @param {function} iterator - function to wrap
|
||||
* @returns {function} - wrapped function
|
||||
*/
|
||||
function wrapIterator(iterator)
|
||||
{
|
||||
var stream = this;
|
||||
|
||||
return function(item, key, cb)
|
||||
{
|
||||
var aborter
|
||||
, wrappedCb = async(wrapIteratorCallback.call(stream, cb, key))
|
||||
;
|
||||
|
||||
stream.jobs[key] = wrappedCb;
|
||||
|
||||
// it's either shortcut (item, cb)
|
||||
if (iterator.length == 2)
|
||||
{
|
||||
aborter = iterator(item, wrappedCb);
|
||||
}
|
||||
// or long format (item, key, cb)
|
||||
else
|
||||
{
|
||||
aborter = iterator(item, key, wrappedCb);
|
||||
}
|
||||
|
||||
return aborter;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps provided callback function
|
||||
* allowing to execute snitch function before
|
||||
* real callback
|
||||
*
|
||||
* @this ReadableAsyncKit#
|
||||
* @param {function} callback - function to wrap
|
||||
* @returns {function} - wrapped function
|
||||
*/
|
||||
function wrapCallback(callback)
|
||||
{
|
||||
var stream = this;
|
||||
|
||||
var wrapped = function(error, result)
|
||||
{
|
||||
return finisher.call(stream, error, result, callback);
|
||||
};
|
||||
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps provided iterator callback function
|
||||
* makes sure snitch only called once,
|
||||
* but passes secondary calls to the original callback
|
||||
*
|
||||
* @this ReadableAsyncKit#
|
||||
* @param {function} callback - callback to wrap
|
||||
* @param {number|string} key - iteration key
|
||||
* @returns {function} wrapped callback
|
||||
*/
|
||||
function wrapIteratorCallback(callback, key)
|
||||
{
|
||||
var stream = this;
|
||||
|
||||
return function(error, output)
|
||||
{
|
||||
// don't repeat yourself
|
||||
if (!(key in stream.jobs))
|
||||
{
|
||||
callback(error, output);
|
||||
return;
|
||||
}
|
||||
|
||||
// clean up jobs
|
||||
delete stream.jobs[key];
|
||||
|
||||
return streamer.call(stream, error, {key: key, value: output}, callback);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Stream wrapper for iterator callback
|
||||
*
|
||||
* @this ReadableAsyncKit#
|
||||
* @param {mixed} error - error response
|
||||
* @param {mixed} output - iterator output
|
||||
* @param {function} callback - callback that expects iterator results
|
||||
*/
|
||||
function streamer(error, output, callback)
|
||||
{
|
||||
if (error && !this.error)
|
||||
{
|
||||
this.error = error;
|
||||
this.pause();
|
||||
this.emit('error', error);
|
||||
// send back value only, as expected
|
||||
callback(error, output && output.value);
|
||||
return;
|
||||
}
|
||||
|
||||
// stream stuff
|
||||
this.push(output);
|
||||
|
||||
// back to original track
|
||||
// send back value only, as expected
|
||||
callback(error, output && output.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stream wrapper for finishing callback
|
||||
*
|
||||
* @this ReadableAsyncKit#
|
||||
* @param {mixed} error - error response
|
||||
* @param {mixed} output - iterator output
|
||||
* @param {function} callback - callback that expects final results
|
||||
*/
|
||||
function finisher(error, output, callback)
|
||||
{
|
||||
// signal end of the stream
|
||||
// only for successfully finished streams
|
||||
if (!error)
|
||||
{
|
||||
this.push(null);
|
||||
}
|
||||
|
||||
// back to original track
|
||||
callback(error, output);
|
||||
}
|
||||
29
node_modules/asynckit/lib/terminator.js
generated
vendored
29
node_modules/asynckit/lib/terminator.js
generated
vendored
@ -1,29 +0,0 @@
|
||||
var abort = require('./abort.js')
|
||||
, async = require('./async.js')
|
||||
;
|
||||
|
||||
// API
|
||||
module.exports = terminator;
|
||||
|
||||
/**
|
||||
* Terminates jobs in the attached state context
|
||||
*
|
||||
* @this AsyncKitState#
|
||||
* @param {function} callback - final callback to invoke after termination
|
||||
*/
|
||||
function terminator(callback)
|
||||
{
|
||||
if (!Object.keys(this.jobs).length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// fast forward iteration index
|
||||
this.index = this.size;
|
||||
|
||||
// abort jobs
|
||||
abort(this);
|
||||
|
||||
// send back results we have so far
|
||||
async(callback)(null, this.results);
|
||||
}
|
||||
92
node_modules/asynckit/package.json
generated
vendored
92
node_modules/asynckit/package.json
generated
vendored
@ -1,92 +0,0 @@
|
||||
{
|
||||
"_from": "asynckit@^0.4.0",
|
||||
"_id": "asynckit@0.4.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=",
|
||||
"_location": "/asynckit",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "asynckit@^0.4.0",
|
||||
"name": "asynckit",
|
||||
"escapedName": "asynckit",
|
||||
"rawSpec": "^0.4.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^0.4.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/form-data",
|
||||
"/request/form-data"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"_shasum": "c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79",
|
||||
"_spec": "asynckit@^0.4.0",
|
||||
"_where": "/Users/bret/repos/deploy-to-neocities/node_modules/form-data",
|
||||
"author": {
|
||||
"name": "Alex Indigo",
|
||||
"email": "iam@alexindigo.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/alexindigo/asynckit/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {},
|
||||
"deprecated": false,
|
||||
"description": "Minimal async jobs utility library, with streams support",
|
||||
"devDependencies": {
|
||||
"browserify": "^13.0.0",
|
||||
"browserify-istanbul": "^2.0.0",
|
||||
"coveralls": "^2.11.9",
|
||||
"eslint": "^2.9.0",
|
||||
"istanbul": "^0.4.3",
|
||||
"obake": "^0.1.2",
|
||||
"phantomjs-prebuilt": "^2.1.7",
|
||||
"pre-commit": "^1.1.3",
|
||||
"reamde": "^1.1.0",
|
||||
"rimraf": "^2.5.2",
|
||||
"size-table": "^0.2.0",
|
||||
"tap-spec": "^4.1.1",
|
||||
"tape": "^4.5.1"
|
||||
},
|
||||
"homepage": "https://github.com/alexindigo/asynckit#readme",
|
||||
"keywords": [
|
||||
"async",
|
||||
"jobs",
|
||||
"parallel",
|
||||
"serial",
|
||||
"iterator",
|
||||
"array",
|
||||
"object",
|
||||
"stream",
|
||||
"destroy",
|
||||
"terminate",
|
||||
"abort"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "asynckit",
|
||||
"pre-commit": [
|
||||
"clean",
|
||||
"lint",
|
||||
"test",
|
||||
"browser",
|
||||
"report",
|
||||
"size"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/alexindigo/asynckit.git"
|
||||
},
|
||||
"scripts": {
|
||||
"browser": "browserify -t browserify-istanbul test/lib/browserify_adjustment.js test/test-*.js | obake --coverage | tap-spec",
|
||||
"clean": "rimraf coverage",
|
||||
"debug": "tape test/test-*.js",
|
||||
"lint": "eslint *.js lib/*.js test/*.js",
|
||||
"report": "istanbul report",
|
||||
"size": "browserify index.js | size-table asynckit",
|
||||
"test": "istanbul cover --reporter=json tape -- 'test/test-*.js' | tap-spec",
|
||||
"win-test": "tape test/test-*.js"
|
||||
},
|
||||
"version": "0.4.0"
|
||||
}
|
||||
43
node_modules/asynckit/parallel.js
generated
vendored
43
node_modules/asynckit/parallel.js
generated
vendored
@ -1,43 +0,0 @@
|
||||
var iterate = require('./lib/iterate.js')
|
||||
, initState = require('./lib/state.js')
|
||||
, terminator = require('./lib/terminator.js')
|
||||
;
|
||||
|
||||
// Public API
|
||||
module.exports = parallel;
|
||||
|
||||
/**
|
||||
* Runs iterator over provided array elements in parallel
|
||||
*
|
||||
* @param {array|object} list - array or object (named list) to iterate over
|
||||
* @param {function} iterator - iterator to run
|
||||
* @param {function} callback - invoked when all elements processed
|
||||
* @returns {function} - jobs terminator
|
||||
*/
|
||||
function parallel(list, iterator, callback)
|
||||
{
|
||||
var state = initState(list);
|
||||
|
||||
while (state.index < (state['keyedList'] || list).length)
|
||||
{
|
||||
iterate(list, iterator, state, function(error, result)
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
callback(error, result);
|
||||
return;
|
||||
}
|
||||
|
||||
// looks like it's the last one
|
||||
if (Object.keys(state.jobs).length === 0)
|
||||
{
|
||||
callback(null, state.results);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
state.index++;
|
||||
}
|
||||
|
||||
return terminator.bind(state, callback);
|
||||
}
|
||||
17
node_modules/asynckit/serial.js
generated
vendored
17
node_modules/asynckit/serial.js
generated
vendored
@ -1,17 +0,0 @@
|
||||
var serialOrdered = require('./serialOrdered.js');
|
||||
|
||||
// Public API
|
||||
module.exports = serial;
|
||||
|
||||
/**
|
||||
* Runs iterator over provided array elements in series
|
||||
*
|
||||
* @param {array|object} list - array or object (named list) to iterate over
|
||||
* @param {function} iterator - iterator to run
|
||||
* @param {function} callback - invoked when all elements processed
|
||||
* @returns {function} - jobs terminator
|
||||
*/
|
||||
function serial(list, iterator, callback)
|
||||
{
|
||||
return serialOrdered(list, iterator, null, callback);
|
||||
}
|
||||
75
node_modules/asynckit/serialOrdered.js
generated
vendored
75
node_modules/asynckit/serialOrdered.js
generated
vendored
@ -1,75 +0,0 @@
|
||||
var iterate = require('./lib/iterate.js')
|
||||
, initState = require('./lib/state.js')
|
||||
, terminator = require('./lib/terminator.js')
|
||||
;
|
||||
|
||||
// Public API
|
||||
module.exports = serialOrdered;
|
||||
// sorting helpers
|
||||
module.exports.ascending = ascending;
|
||||
module.exports.descending = descending;
|
||||
|
||||
/**
|
||||
* Runs iterator over provided sorted array elements in series
|
||||
*
|
||||
* @param {array|object} list - array or object (named list) to iterate over
|
||||
* @param {function} iterator - iterator to run
|
||||
* @param {function} sortMethod - custom sort function
|
||||
* @param {function} callback - invoked when all elements processed
|
||||
* @returns {function} - jobs terminator
|
||||
*/
|
||||
function serialOrdered(list, iterator, sortMethod, callback)
|
||||
{
|
||||
var state = initState(list, sortMethod);
|
||||
|
||||
iterate(list, iterator, state, function iteratorHandler(error, result)
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
callback(error, result);
|
||||
return;
|
||||
}
|
||||
|
||||
state.index++;
|
||||
|
||||
// are we there yet?
|
||||
if (state.index < (state['keyedList'] || list).length)
|
||||
{
|
||||
iterate(list, iterator, state, iteratorHandler);
|
||||
return;
|
||||
}
|
||||
|
||||
// done here
|
||||
callback(null, state.results);
|
||||
});
|
||||
|
||||
return terminator.bind(state, callback);
|
||||
}
|
||||
|
||||
/*
|
||||
* -- Sort methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* sort helper to sort array elements in ascending order
|
||||
*
|
||||
* @param {mixed} a - an item to compare
|
||||
* @param {mixed} b - an item to compare
|
||||
* @returns {number} - comparison result
|
||||
*/
|
||||
function ascending(a, b)
|
||||
{
|
||||
return a < b ? -1 : a > b ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* sort helper to sort array elements in descending order
|
||||
*
|
||||
* @param {mixed} a - an item to compare
|
||||
* @param {mixed} b - an item to compare
|
||||
* @returns {number} - comparison result
|
||||
*/
|
||||
function descending(a, b)
|
||||
{
|
||||
return -1 * ascending(a, b);
|
||||
}
|
||||
21
node_modules/asynckit/stream.js
generated
vendored
21
node_modules/asynckit/stream.js
generated
vendored
@ -1,21 +0,0 @@
|
||||
var inherits = require('util').inherits
|
||||
, Readable = require('stream').Readable
|
||||
, ReadableAsyncKit = require('./lib/readable_asynckit.js')
|
||||
, ReadableParallel = require('./lib/readable_parallel.js')
|
||||
, ReadableSerial = require('./lib/readable_serial.js')
|
||||
, ReadableSerialOrdered = require('./lib/readable_serial_ordered.js')
|
||||
;
|
||||
|
||||
// API
|
||||
module.exports =
|
||||
{
|
||||
parallel : ReadableParallel,
|
||||
serial : ReadableSerial,
|
||||
serialOrdered : ReadableSerialOrdered,
|
||||
};
|
||||
|
||||
inherits(ReadableAsyncKit, Readable);
|
||||
|
||||
inherits(ReadableParallel, ReadableAsyncKit);
|
||||
inherits(ReadableSerial, ReadableAsyncKit);
|
||||
inherits(ReadableSerialOrdered, ReadableAsyncKit);
|
||||
19
node_modules/combined-stream/License
generated
vendored
19
node_modules/combined-stream/License
generated
vendored
@ -1,19 +0,0 @@
|
||||
Copyright (c) 2011 Debuggable Limited <felix@debuggable.com>
|
||||
|
||||
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.
|
||||
138
node_modules/combined-stream/Readme.md
generated
vendored
138
node_modules/combined-stream/Readme.md
generated
vendored
@ -1,138 +0,0 @@
|
||||
# combined-stream
|
||||
|
||||
A stream that emits multiple other streams one after another.
|
||||
|
||||
**NB** Currently `combined-stream` works with streams version 1 only. There is ongoing effort to switch this library to streams version 2. Any help is welcome. :) Meanwhile you can explore other libraries that provide streams2 support with more or less compatibility with `combined-stream`.
|
||||
|
||||
- [combined-stream2](https://www.npmjs.com/package/combined-stream2): A drop-in streams2-compatible replacement for the combined-stream module.
|
||||
|
||||
- [multistream](https://www.npmjs.com/package/multistream): A stream that emits multiple other streams one after another.
|
||||
|
||||
## Installation
|
||||
|
||||
``` bash
|
||||
npm install combined-stream
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Here is a simple example that shows how you can use combined-stream to combine
|
||||
two files into one:
|
||||
|
||||
``` javascript
|
||||
var CombinedStream = require('combined-stream');
|
||||
var fs = require('fs');
|
||||
|
||||
var combinedStream = CombinedStream.create();
|
||||
combinedStream.append(fs.createReadStream('file1.txt'));
|
||||
combinedStream.append(fs.createReadStream('file2.txt'));
|
||||
|
||||
combinedStream.pipe(fs.createWriteStream('combined.txt'));
|
||||
```
|
||||
|
||||
While the example above works great, it will pause all source streams until
|
||||
they are needed. If you don't want that to happen, you can set `pauseStreams`
|
||||
to `false`:
|
||||
|
||||
``` javascript
|
||||
var CombinedStream = require('combined-stream');
|
||||
var fs = require('fs');
|
||||
|
||||
var combinedStream = CombinedStream.create({pauseStreams: false});
|
||||
combinedStream.append(fs.createReadStream('file1.txt'));
|
||||
combinedStream.append(fs.createReadStream('file2.txt'));
|
||||
|
||||
combinedStream.pipe(fs.createWriteStream('combined.txt'));
|
||||
```
|
||||
|
||||
However, what if you don't have all the source streams yet, or you don't want
|
||||
to allocate the resources (file descriptors, memory, etc.) for them right away?
|
||||
Well, in that case you can simply provide a callback that supplies the stream
|
||||
by calling a `next()` function:
|
||||
|
||||
``` javascript
|
||||
var CombinedStream = require('combined-stream');
|
||||
var fs = require('fs');
|
||||
|
||||
var combinedStream = CombinedStream.create();
|
||||
combinedStream.append(function(next) {
|
||||
next(fs.createReadStream('file1.txt'));
|
||||
});
|
||||
combinedStream.append(function(next) {
|
||||
next(fs.createReadStream('file2.txt'));
|
||||
});
|
||||
|
||||
combinedStream.pipe(fs.createWriteStream('combined.txt'));
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### CombinedStream.create([options])
|
||||
|
||||
Returns a new combined stream object. Available options are:
|
||||
|
||||
* `maxDataSize`
|
||||
* `pauseStreams`
|
||||
|
||||
The effect of those options is described below.
|
||||
|
||||
### combinedStream.pauseStreams = `true`
|
||||
|
||||
Whether to apply back pressure to the underlaying streams. If set to `false`,
|
||||
the underlaying streams will never be paused. If set to `true`, the
|
||||
underlaying streams will be paused right after being appended, as well as when
|
||||
`delayedStream.pipe()` wants to throttle.
|
||||
|
||||
### combinedStream.maxDataSize = `2 * 1024 * 1024`
|
||||
|
||||
The maximum amount of bytes (or characters) to buffer for all source streams.
|
||||
If this value is exceeded, `combinedStream` emits an `'error'` event.
|
||||
|
||||
### combinedStream.dataSize = `0`
|
||||
|
||||
The amount of bytes (or characters) currently buffered by `combinedStream`.
|
||||
|
||||
### combinedStream.append(stream)
|
||||
|
||||
Appends the given `stream` to the combinedStream object. If `pauseStreams` is
|
||||
set to `true, this stream will also be paused right away.
|
||||
|
||||
`streams` can also be a function that takes one parameter called `next`. `next`
|
||||
is a function that must be invoked in order to provide the `next` stream, see
|
||||
example above.
|
||||
|
||||
Regardless of how the `stream` is appended, combined-stream always attaches an
|
||||
`'error'` listener to it, so you don't have to do that manually.
|
||||
|
||||
Special case: `stream` can also be a String or Buffer.
|
||||
|
||||
### combinedStream.write(data)
|
||||
|
||||
You should not call this, `combinedStream` takes care of piping the appended
|
||||
streams into itself for you.
|
||||
|
||||
### combinedStream.resume()
|
||||
|
||||
Causes `combinedStream` to start drain the streams it manages. The function is
|
||||
idempotent, and also emits a `'resume'` event each time which usually goes to
|
||||
the stream that is currently being drained.
|
||||
|
||||
### combinedStream.pause();
|
||||
|
||||
If `combinedStream.pauseStreams` is set to `false`, this does nothing.
|
||||
Otherwise a `'pause'` event is emitted, this goes to the stream that is
|
||||
currently being drained, so you can use it to apply back pressure.
|
||||
|
||||
### combinedStream.end();
|
||||
|
||||
Sets `combinedStream.writable` to false, emits an `'end'` event, and removes
|
||||
all streams from the queue.
|
||||
|
||||
### combinedStream.destroy();
|
||||
|
||||
Same as `combinedStream.end()`, except it emits a `'close'` event instead of
|
||||
`'end'`.
|
||||
|
||||
## License
|
||||
|
||||
combined-stream is licensed under the MIT license.
|
||||
208
node_modules/combined-stream/lib/combined_stream.js
generated
vendored
208
node_modules/combined-stream/lib/combined_stream.js
generated
vendored
@ -1,208 +0,0 @@
|
||||
var util = require('util');
|
||||
var Stream = require('stream').Stream;
|
||||
var DelayedStream = require('delayed-stream');
|
||||
|
||||
module.exports = CombinedStream;
|
||||
function CombinedStream() {
|
||||
this.writable = false;
|
||||
this.readable = true;
|
||||
this.dataSize = 0;
|
||||
this.maxDataSize = 2 * 1024 * 1024;
|
||||
this.pauseStreams = true;
|
||||
|
||||
this._released = false;
|
||||
this._streams = [];
|
||||
this._currentStream = null;
|
||||
this._insideLoop = false;
|
||||
this._pendingNext = false;
|
||||
}
|
||||
util.inherits(CombinedStream, Stream);
|
||||
|
||||
CombinedStream.create = function(options) {
|
||||
var combinedStream = new this();
|
||||
|
||||
options = options || {};
|
||||
for (var option in options) {
|
||||
combinedStream[option] = options[option];
|
||||
}
|
||||
|
||||
return combinedStream;
|
||||
};
|
||||
|
||||
CombinedStream.isStreamLike = function(stream) {
|
||||
return (typeof stream !== 'function')
|
||||
&& (typeof stream !== 'string')
|
||||
&& (typeof stream !== 'boolean')
|
||||
&& (typeof stream !== 'number')
|
||||
&& (!Buffer.isBuffer(stream));
|
||||
};
|
||||
|
||||
CombinedStream.prototype.append = function(stream) {
|
||||
var isStreamLike = CombinedStream.isStreamLike(stream);
|
||||
|
||||
if (isStreamLike) {
|
||||
if (!(stream instanceof DelayedStream)) {
|
||||
var newStream = DelayedStream.create(stream, {
|
||||
maxDataSize: Infinity,
|
||||
pauseStream: this.pauseStreams,
|
||||
});
|
||||
stream.on('data', this._checkDataSize.bind(this));
|
||||
stream = newStream;
|
||||
}
|
||||
|
||||
this._handleErrors(stream);
|
||||
|
||||
if (this.pauseStreams) {
|
||||
stream.pause();
|
||||
}
|
||||
}
|
||||
|
||||
this._streams.push(stream);
|
||||
return this;
|
||||
};
|
||||
|
||||
CombinedStream.prototype.pipe = function(dest, options) {
|
||||
Stream.prototype.pipe.call(this, dest, options);
|
||||
this.resume();
|
||||
return dest;
|
||||
};
|
||||
|
||||
CombinedStream.prototype._getNext = function() {
|
||||
this._currentStream = null;
|
||||
|
||||
if (this._insideLoop) {
|
||||
this._pendingNext = true;
|
||||
return; // defer call
|
||||
}
|
||||
|
||||
this._insideLoop = true;
|
||||
try {
|
||||
do {
|
||||
this._pendingNext = false;
|
||||
this._realGetNext();
|
||||
} while (this._pendingNext);
|
||||
} finally {
|
||||
this._insideLoop = false;
|
||||
}
|
||||
};
|
||||
|
||||
CombinedStream.prototype._realGetNext = function() {
|
||||
var stream = this._streams.shift();
|
||||
|
||||
|
||||
if (typeof stream == 'undefined') {
|
||||
this.end();
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof stream !== 'function') {
|
||||
this._pipeNext(stream);
|
||||
return;
|
||||
}
|
||||
|
||||
var getStream = stream;
|
||||
getStream(function(stream) {
|
||||
var isStreamLike = CombinedStream.isStreamLike(stream);
|
||||
if (isStreamLike) {
|
||||
stream.on('data', this._checkDataSize.bind(this));
|
||||
this._handleErrors(stream);
|
||||
}
|
||||
|
||||
this._pipeNext(stream);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
CombinedStream.prototype._pipeNext = function(stream) {
|
||||
this._currentStream = stream;
|
||||
|
||||
var isStreamLike = CombinedStream.isStreamLike(stream);
|
||||
if (isStreamLike) {
|
||||
stream.on('end', this._getNext.bind(this));
|
||||
stream.pipe(this, {end: false});
|
||||
return;
|
||||
}
|
||||
|
||||
var value = stream;
|
||||
this.write(value);
|
||||
this._getNext();
|
||||
};
|
||||
|
||||
CombinedStream.prototype._handleErrors = function(stream) {
|
||||
var self = this;
|
||||
stream.on('error', function(err) {
|
||||
self._emitError(err);
|
||||
});
|
||||
};
|
||||
|
||||
CombinedStream.prototype.write = function(data) {
|
||||
this.emit('data', data);
|
||||
};
|
||||
|
||||
CombinedStream.prototype.pause = function() {
|
||||
if (!this.pauseStreams) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.pauseStreams && this._currentStream && typeof(this._currentStream.pause) == 'function') this._currentStream.pause();
|
||||
this.emit('pause');
|
||||
};
|
||||
|
||||
CombinedStream.prototype.resume = function() {
|
||||
if (!this._released) {
|
||||
this._released = true;
|
||||
this.writable = true;
|
||||
this._getNext();
|
||||
}
|
||||
|
||||
if(this.pauseStreams && this._currentStream && typeof(this._currentStream.resume) == 'function') this._currentStream.resume();
|
||||
this.emit('resume');
|
||||
};
|
||||
|
||||
CombinedStream.prototype.end = function() {
|
||||
this._reset();
|
||||
this.emit('end');
|
||||
};
|
||||
|
||||
CombinedStream.prototype.destroy = function() {
|
||||
this._reset();
|
||||
this.emit('close');
|
||||
};
|
||||
|
||||
CombinedStream.prototype._reset = function() {
|
||||
this.writable = false;
|
||||
this._streams = [];
|
||||
this._currentStream = null;
|
||||
};
|
||||
|
||||
CombinedStream.prototype._checkDataSize = function() {
|
||||
this._updateDataSize();
|
||||
if (this.dataSize <= this.maxDataSize) {
|
||||
return;
|
||||
}
|
||||
|
||||
var message =
|
||||
'DelayedStream#maxDataSize of ' + this.maxDataSize + ' bytes exceeded.';
|
||||
this._emitError(new Error(message));
|
||||
};
|
||||
|
||||
CombinedStream.prototype._updateDataSize = function() {
|
||||
this.dataSize = 0;
|
||||
|
||||
var self = this;
|
||||
this._streams.forEach(function(stream) {
|
||||
if (!stream.dataSize) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.dataSize += stream.dataSize;
|
||||
});
|
||||
|
||||
if (this._currentStream && this._currentStream.dataSize) {
|
||||
this.dataSize += this._currentStream.dataSize;
|
||||
}
|
||||
};
|
||||
|
||||
CombinedStream.prototype._emitError = function(err) {
|
||||
this._reset();
|
||||
this.emit('error', err);
|
||||
};
|
||||
59
node_modules/combined-stream/package.json
generated
vendored
59
node_modules/combined-stream/package.json
generated
vendored
@ -1,59 +0,0 @@
|
||||
{
|
||||
"_from": "combined-stream@^1.0.8",
|
||||
"_id": "combined-stream@1.0.8",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||
"_location": "/combined-stream",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "combined-stream@^1.0.8",
|
||||
"name": "combined-stream",
|
||||
"escapedName": "combined-stream",
|
||||
"rawSpec": "^1.0.8",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.0.8"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/form-data",
|
||||
"/request",
|
||||
"/request/form-data"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
"_shasum": "c3d45a8b34fd730631a110a8a2520682b31d5a7f",
|
||||
"_spec": "combined-stream@^1.0.8",
|
||||
"_where": "/Users/bret/repos/deploy-to-neocities/node_modules/form-data",
|
||||
"author": {
|
||||
"name": "Felix Geisendörfer",
|
||||
"email": "felix@debuggable.com",
|
||||
"url": "http://debuggable.com/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/felixge/node-combined-stream/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"delayed-stream": "~1.0.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "A stream that emits multiple other streams one after another.",
|
||||
"devDependencies": {
|
||||
"far": "~0.0.7"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
},
|
||||
"homepage": "https://github.com/felixge/node-combined-stream",
|
||||
"license": "MIT",
|
||||
"main": "./lib/combined_stream",
|
||||
"name": "combined-stream",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/felixge/node-combined-stream.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test/run.js"
|
||||
},
|
||||
"version": "1.0.8"
|
||||
}
|
||||
17
node_modules/combined-stream/yarn.lock
generated
vendored
17
node_modules/combined-stream/yarn.lock
generated
vendored
@ -1,17 +0,0 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
delayed-stream@~1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
|
||||
|
||||
far@~0.0.7:
|
||||
version "0.0.7"
|
||||
resolved "https://registry.yarnpkg.com/far/-/far-0.0.7.tgz#01c1fd362bcd26ce9cf161af3938aa34619f79a7"
|
||||
dependencies:
|
||||
oop "0.0.3"
|
||||
|
||||
oop@0.0.3:
|
||||
version "0.0.3"
|
||||
resolved "https://registry.yarnpkg.com/oop/-/oop-0.0.3.tgz#70fa405a5650891a194fdc82ca68dad6dabf4401"
|
||||
1
node_modules/delayed-stream/.npmignore
generated
vendored
1
node_modules/delayed-stream/.npmignore
generated
vendored
@ -1 +0,0 @@
|
||||
test
|
||||
19
node_modules/delayed-stream/License
generated
vendored
19
node_modules/delayed-stream/License
generated
vendored
@ -1,19 +0,0 @@
|
||||
Copyright (c) 2011 Debuggable Limited <felix@debuggable.com>
|
||||
|
||||
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.
|
||||
7
node_modules/delayed-stream/Makefile
generated
vendored
7
node_modules/delayed-stream/Makefile
generated
vendored
@ -1,7 +0,0 @@
|
||||
SHELL := /bin/bash
|
||||
|
||||
test:
|
||||
@./test/run.js
|
||||
|
||||
.PHONY: test
|
||||
|
||||
141
node_modules/delayed-stream/Readme.md
generated
vendored
141
node_modules/delayed-stream/Readme.md
generated
vendored
@ -1,141 +0,0 @@
|
||||
# delayed-stream
|
||||
|
||||
Buffers events from a stream until you are ready to handle them.
|
||||
|
||||
## Installation
|
||||
|
||||
``` bash
|
||||
npm install delayed-stream
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
The following example shows how to write a http echo server that delays its
|
||||
response by 1000 ms.
|
||||
|
||||
``` javascript
|
||||
var DelayedStream = require('delayed-stream');
|
||||
var http = require('http');
|
||||
|
||||
http.createServer(function(req, res) {
|
||||
var delayed = DelayedStream.create(req);
|
||||
|
||||
setTimeout(function() {
|
||||
res.writeHead(200);
|
||||
delayed.pipe(res);
|
||||
}, 1000);
|
||||
});
|
||||
```
|
||||
|
||||
If you are not using `Stream#pipe`, you can also manually release the buffered
|
||||
events by calling `delayedStream.resume()`:
|
||||
|
||||
``` javascript
|
||||
var delayed = DelayedStream.create(req);
|
||||
|
||||
setTimeout(function() {
|
||||
// Emit all buffered events and resume underlaying source
|
||||
delayed.resume();
|
||||
}, 1000);
|
||||
```
|
||||
|
||||
## Implementation
|
||||
|
||||
In order to use this meta stream properly, here are a few things you should
|
||||
know about the implementation.
|
||||
|
||||
### Event Buffering / Proxying
|
||||
|
||||
All events of the `source` stream are hijacked by overwriting the `source.emit`
|
||||
method. Until node implements a catch-all event listener, this is the only way.
|
||||
|
||||
However, delayed-stream still continues to emit all events it captures on the
|
||||
`source`, regardless of whether you have released the delayed stream yet or
|
||||
not.
|
||||
|
||||
Upon creation, delayed-stream captures all `source` events and stores them in
|
||||
an internal event buffer. Once `delayedStream.release()` is called, all
|
||||
buffered events are emitted on the `delayedStream`, and the event buffer is
|
||||
cleared. After that, delayed-stream merely acts as a proxy for the underlaying
|
||||
source.
|
||||
|
||||
### Error handling
|
||||
|
||||
Error events on `source` are buffered / proxied just like any other events.
|
||||
However, `delayedStream.create` attaches a no-op `'error'` listener to the
|
||||
`source`. This way you only have to handle errors on the `delayedStream`
|
||||
object, rather than in two places.
|
||||
|
||||
### Buffer limits
|
||||
|
||||
delayed-stream provides a `maxDataSize` property that can be used to limit
|
||||
the amount of data being buffered. In order to protect you from bad `source`
|
||||
streams that don't react to `source.pause()`, this feature is enabled by
|
||||
default.
|
||||
|
||||
## API
|
||||
|
||||
### DelayedStream.create(source, [options])
|
||||
|
||||
Returns a new `delayedStream`. Available options are:
|
||||
|
||||
* `pauseStream`
|
||||
* `maxDataSize`
|
||||
|
||||
The description for those properties can be found below.
|
||||
|
||||
### delayedStream.source
|
||||
|
||||
The `source` stream managed by this object. This is useful if you are
|
||||
passing your `delayedStream` around, and you still want to access properties
|
||||
on the `source` object.
|
||||
|
||||
### delayedStream.pauseStream = true
|
||||
|
||||
Whether to pause the underlaying `source` when calling
|
||||
`DelayedStream.create()`. Modifying this property afterwards has no effect.
|
||||
|
||||
### delayedStream.maxDataSize = 1024 * 1024
|
||||
|
||||
The amount of data to buffer before emitting an `error`.
|
||||
|
||||
If the underlaying source is emitting `Buffer` objects, the `maxDataSize`
|
||||
refers to bytes.
|
||||
|
||||
If the underlaying source is emitting JavaScript strings, the size refers to
|
||||
characters.
|
||||
|
||||
If you know what you are doing, you can set this property to `Infinity` to
|
||||
disable this feature. You can also modify this property during runtime.
|
||||
|
||||
### delayedStream.dataSize = 0
|
||||
|
||||
The amount of data buffered so far.
|
||||
|
||||
### delayedStream.readable
|
||||
|
||||
An ECMA5 getter that returns the value of `source.readable`.
|
||||
|
||||
### delayedStream.resume()
|
||||
|
||||
If the `delayedStream` has not been released so far, `delayedStream.release()`
|
||||
is called.
|
||||
|
||||
In either case, `source.resume()` is called.
|
||||
|
||||
### delayedStream.pause()
|
||||
|
||||
Calls `source.pause()`.
|
||||
|
||||
### delayedStream.pipe(dest)
|
||||
|
||||
Calls `delayedStream.resume()` and then proxies the arguments to `source.pipe`.
|
||||
|
||||
### delayedStream.release()
|
||||
|
||||
Emits and clears all events that have been buffered up so far. This does not
|
||||
resume the underlaying source, use `delayedStream.resume()` instead.
|
||||
|
||||
## License
|
||||
|
||||
delayed-stream is licensed under the MIT license.
|
||||
107
node_modules/delayed-stream/lib/delayed_stream.js
generated
vendored
107
node_modules/delayed-stream/lib/delayed_stream.js
generated
vendored
@ -1,107 +0,0 @@
|
||||
var Stream = require('stream').Stream;
|
||||
var util = require('util');
|
||||
|
||||
module.exports = DelayedStream;
|
||||
function DelayedStream() {
|
||||
this.source = null;
|
||||
this.dataSize = 0;
|
||||
this.maxDataSize = 1024 * 1024;
|
||||
this.pauseStream = true;
|
||||
|
||||
this._maxDataSizeExceeded = false;
|
||||
this._released = false;
|
||||
this._bufferedEvents = [];
|
||||
}
|
||||
util.inherits(DelayedStream, Stream);
|
||||
|
||||
DelayedStream.create = function(source, options) {
|
||||
var delayedStream = new this();
|
||||
|
||||
options = options || {};
|
||||
for (var option in options) {
|
||||
delayedStream[option] = options[option];
|
||||
}
|
||||
|
||||
delayedStream.source = source;
|
||||
|
||||
var realEmit = source.emit;
|
||||
source.emit = function() {
|
||||
delayedStream._handleEmit(arguments);
|
||||
return realEmit.apply(source, arguments);
|
||||
};
|
||||
|
||||
source.on('error', function() {});
|
||||
if (delayedStream.pauseStream) {
|
||||
source.pause();
|
||||
}
|
||||
|
||||
return delayedStream;
|
||||
};
|
||||
|
||||
Object.defineProperty(DelayedStream.prototype, 'readable', {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return this.source.readable;
|
||||
}
|
||||
});
|
||||
|
||||
DelayedStream.prototype.setEncoding = function() {
|
||||
return this.source.setEncoding.apply(this.source, arguments);
|
||||
};
|
||||
|
||||
DelayedStream.prototype.resume = function() {
|
||||
if (!this._released) {
|
||||
this.release();
|
||||
}
|
||||
|
||||
this.source.resume();
|
||||
};
|
||||
|
||||
DelayedStream.prototype.pause = function() {
|
||||
this.source.pause();
|
||||
};
|
||||
|
||||
DelayedStream.prototype.release = function() {
|
||||
this._released = true;
|
||||
|
||||
this._bufferedEvents.forEach(function(args) {
|
||||
this.emit.apply(this, args);
|
||||
}.bind(this));
|
||||
this._bufferedEvents = [];
|
||||
};
|
||||
|
||||
DelayedStream.prototype.pipe = function() {
|
||||
var r = Stream.prototype.pipe.apply(this, arguments);
|
||||
this.resume();
|
||||
return r;
|
||||
};
|
||||
|
||||
DelayedStream.prototype._handleEmit = function(args) {
|
||||
if (this._released) {
|
||||
this.emit.apply(this, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[0] === 'data') {
|
||||
this.dataSize += args[1].length;
|
||||
this._checkIfMaxDataSizeExceeded();
|
||||
}
|
||||
|
||||
this._bufferedEvents.push(args);
|
||||
};
|
||||
|
||||
DelayedStream.prototype._checkIfMaxDataSizeExceeded = function() {
|
||||
if (this._maxDataSizeExceeded) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.dataSize <= this.maxDataSize) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._maxDataSizeExceeded = true;
|
||||
var message =
|
||||
'DelayedStream#maxDataSize of ' + this.maxDataSize + ' bytes exceeded.'
|
||||
this.emit('error', new Error(message));
|
||||
};
|
||||
62
node_modules/delayed-stream/package.json
generated
vendored
62
node_modules/delayed-stream/package.json
generated
vendored
@ -1,62 +0,0 @@
|
||||
{
|
||||
"_from": "delayed-stream@~1.0.0",
|
||||
"_id": "delayed-stream@1.0.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=",
|
||||
"_location": "/delayed-stream",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "delayed-stream@~1.0.0",
|
||||
"name": "delayed-stream",
|
||||
"escapedName": "delayed-stream",
|
||||
"rawSpec": "~1.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "~1.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/combined-stream"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"_shasum": "df3ae199acadfb7d440aaae0b29e2272b24ec619",
|
||||
"_spec": "delayed-stream@~1.0.0",
|
||||
"_where": "/Users/bret/repos/deploy-to-neocities/node_modules/combined-stream",
|
||||
"author": {
|
||||
"name": "Felix Geisendörfer",
|
||||
"email": "felix@debuggable.com",
|
||||
"url": "http://debuggable.com/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/felixge/node-delayed-stream/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Mike Atkins",
|
||||
"email": "apeherder@gmail.com"
|
||||
}
|
||||
],
|
||||
"dependencies": {},
|
||||
"deprecated": false,
|
||||
"description": "Buffers events from a stream until you are ready to handle them.",
|
||||
"devDependencies": {
|
||||
"fake": "0.2.0",
|
||||
"far": "0.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
},
|
||||
"homepage": "https://github.com/felixge/node-delayed-stream",
|
||||
"license": "MIT",
|
||||
"main": "./lib/delayed_stream",
|
||||
"name": "delayed-stream",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/felixge/node-delayed-stream.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "make test"
|
||||
},
|
||||
"version": "1.0.0"
|
||||
}
|
||||
6
node_modules/duplexify/.travis.yml
generated
vendored
6
node_modules/duplexify/.travis.yml
generated
vendored
@ -1,6 +0,0 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "4"
|
||||
- "6"
|
||||
- "8"
|
||||
- "10"
|
||||
21
node_modules/duplexify/LICENSE
generated
vendored
21
node_modules/duplexify/LICENSE
generated
vendored
@ -1,21 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Mathias Buus
|
||||
|
||||
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.
|
||||
97
node_modules/duplexify/README.md
generated
vendored
97
node_modules/duplexify/README.md
generated
vendored
@ -1,97 +0,0 @@
|
||||
# duplexify
|
||||
|
||||
Turn a writeable and readable stream into a single streams2 duplex stream.
|
||||
|
||||
Similar to [duplexer2](https://github.com/deoxxa/duplexer2) except it supports both streams2 and streams1 as input
|
||||
and it allows you to set the readable and writable part asynchronously using `setReadable(stream)` and `setWritable(stream)`
|
||||
|
||||
```
|
||||
npm install duplexify
|
||||
```
|
||||
|
||||
[](http://travis-ci.org/mafintosh/duplexify)
|
||||
|
||||
## Usage
|
||||
|
||||
Use `duplexify(writable, readable, streamOptions)` (or `duplexify.obj(writable, readable)` to create an object stream)
|
||||
|
||||
``` js
|
||||
var duplexify = require('duplexify')
|
||||
|
||||
// turn writableStream and readableStream into a single duplex stream
|
||||
var dup = duplexify(writableStream, readableStream)
|
||||
|
||||
dup.write('hello world') // will write to writableStream
|
||||
dup.on('data', function(data) {
|
||||
// will read from readableStream
|
||||
})
|
||||
```
|
||||
|
||||
You can also set the readable and writable parts asynchronously
|
||||
|
||||
``` js
|
||||
var dup = duplexify()
|
||||
|
||||
dup.write('hello world') // write will buffer until the writable
|
||||
// part has been set
|
||||
|
||||
// wait a bit ...
|
||||
dup.setReadable(readableStream)
|
||||
|
||||
// maybe wait some more?
|
||||
dup.setWritable(writableStream)
|
||||
```
|
||||
|
||||
If you call `setReadable` or `setWritable` multiple times it will unregister the previous readable/writable stream.
|
||||
To disable the readable or writable part call `setReadable` or `setWritable` with `null`.
|
||||
|
||||
If the readable or writable streams emits an error or close it will destroy both streams and bubble up the event.
|
||||
You can also explicitly destroy the streams by calling `dup.destroy()`. The `destroy` method optionally takes an
|
||||
error object as argument, in which case the error is emitted as part of the `error` event.
|
||||
|
||||
``` js
|
||||
dup.on('error', function(err) {
|
||||
console.log('readable or writable emitted an error - close will follow')
|
||||
})
|
||||
|
||||
dup.on('close', function() {
|
||||
console.log('the duplex stream is destroyed')
|
||||
})
|
||||
|
||||
dup.destroy() // calls destroy on the readable and writable part (if present)
|
||||
```
|
||||
|
||||
## HTTP request example
|
||||
|
||||
Turn a node core http request into a duplex stream is as easy as
|
||||
|
||||
``` js
|
||||
var duplexify = require('duplexify')
|
||||
var http = require('http')
|
||||
|
||||
var request = function(opts) {
|
||||
var req = http.request(opts)
|
||||
var dup = duplexify(req)
|
||||
req.on('response', function(res) {
|
||||
dup.setReadable(res)
|
||||
})
|
||||
return dup
|
||||
}
|
||||
|
||||
var req = request({
|
||||
method: 'GET',
|
||||
host: 'www.google.com',
|
||||
port: 80
|
||||
})
|
||||
|
||||
req.end()
|
||||
req.pipe(process.stdout)
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
## Related
|
||||
|
||||
`duplexify` is part of the [mississippi stream utility collection](https://github.com/maxogden/mississippi) which includes more useful stream modules similar to this one.
|
||||
21
node_modules/duplexify/example.js
generated
vendored
21
node_modules/duplexify/example.js
generated
vendored
@ -1,21 +0,0 @@
|
||||
var duplexify = require('duplexify')
|
||||
var http = require('http')
|
||||
|
||||
var request = function(opts) {
|
||||
var req = http.request(opts)
|
||||
var dup = duplexify()
|
||||
dup.setWritable(req)
|
||||
req.on('response', function(res) {
|
||||
dup.setReadable(res)
|
||||
})
|
||||
return dup
|
||||
}
|
||||
|
||||
var req = request({
|
||||
method: 'GET',
|
||||
host: 'www.google.com',
|
||||
port: 80
|
||||
})
|
||||
|
||||
req.end()
|
||||
req.pipe(process.stdout)
|
||||
238
node_modules/duplexify/index.js
generated
vendored
238
node_modules/duplexify/index.js
generated
vendored
@ -1,238 +0,0 @@
|
||||
var stream = require('readable-stream')
|
||||
var eos = require('end-of-stream')
|
||||
var inherits = require('inherits')
|
||||
var shift = require('stream-shift')
|
||||
|
||||
var SIGNAL_FLUSH = (Buffer.from && Buffer.from !== Uint8Array.from)
|
||||
? Buffer.from([0])
|
||||
: new Buffer([0])
|
||||
|
||||
var onuncork = function(self, fn) {
|
||||
if (self._corked) self.once('uncork', fn)
|
||||
else fn()
|
||||
}
|
||||
|
||||
var autoDestroy = function (self, err) {
|
||||
if (self._autoDestroy) self.destroy(err)
|
||||
}
|
||||
|
||||
var destroyer = function(self, end) {
|
||||
return function(err) {
|
||||
if (err) autoDestroy(self, err.message === 'premature close' ? null : err)
|
||||
else if (end && !self._ended) self.end()
|
||||
}
|
||||
}
|
||||
|
||||
var end = function(ws, fn) {
|
||||
if (!ws) return fn()
|
||||
if (ws._writableState && ws._writableState.finished) return fn()
|
||||
if (ws._writableState) return ws.end(fn)
|
||||
ws.end()
|
||||
fn()
|
||||
}
|
||||
|
||||
var noop = function() {}
|
||||
|
||||
var toStreams2 = function(rs) {
|
||||
return new (stream.Readable)({objectMode:true, highWaterMark:16}).wrap(rs)
|
||||
}
|
||||
|
||||
var Duplexify = function(writable, readable, opts) {
|
||||
if (!(this instanceof Duplexify)) return new Duplexify(writable, readable, opts)
|
||||
stream.Duplex.call(this, opts)
|
||||
|
||||
this._writable = null
|
||||
this._readable = null
|
||||
this._readable2 = null
|
||||
|
||||
this._autoDestroy = !opts || opts.autoDestroy !== false
|
||||
this._forwardDestroy = !opts || opts.destroy !== false
|
||||
this._forwardEnd = !opts || opts.end !== false
|
||||
this._corked = 1 // start corked
|
||||
this._ondrain = null
|
||||
this._drained = false
|
||||
this._forwarding = false
|
||||
this._unwrite = null
|
||||
this._unread = null
|
||||
this._ended = false
|
||||
|
||||
this.destroyed = false
|
||||
|
||||
if (writable) this.setWritable(writable)
|
||||
if (readable) this.setReadable(readable)
|
||||
}
|
||||
|
||||
inherits(Duplexify, stream.Duplex)
|
||||
|
||||
Duplexify.obj = function(writable, readable, opts) {
|
||||
if (!opts) opts = {}
|
||||
opts.objectMode = true
|
||||
opts.highWaterMark = 16
|
||||
return new Duplexify(writable, readable, opts)
|
||||
}
|
||||
|
||||
Duplexify.prototype.cork = function() {
|
||||
if (++this._corked === 1) this.emit('cork')
|
||||
}
|
||||
|
||||
Duplexify.prototype.uncork = function() {
|
||||
if (this._corked && --this._corked === 0) this.emit('uncork')
|
||||
}
|
||||
|
||||
Duplexify.prototype.setWritable = function(writable) {
|
||||
if (this._unwrite) this._unwrite()
|
||||
|
||||
if (this.destroyed) {
|
||||
if (writable && writable.destroy) writable.destroy()
|
||||
return
|
||||
}
|
||||
|
||||
if (writable === null || writable === false) {
|
||||
this.end()
|
||||
return
|
||||
}
|
||||
|
||||
var self = this
|
||||
var unend = eos(writable, {writable:true, readable:false}, destroyer(this, this._forwardEnd))
|
||||
|
||||
var ondrain = function() {
|
||||
var ondrain = self._ondrain
|
||||
self._ondrain = null
|
||||
if (ondrain) ondrain()
|
||||
}
|
||||
|
||||
var clear = function() {
|
||||
self._writable.removeListener('drain', ondrain)
|
||||
unend()
|
||||
}
|
||||
|
||||
if (this._unwrite) process.nextTick(ondrain) // force a drain on stream reset to avoid livelocks
|
||||
|
||||
this._writable = writable
|
||||
this._writable.on('drain', ondrain)
|
||||
this._unwrite = clear
|
||||
|
||||
this.uncork() // always uncork setWritable
|
||||
}
|
||||
|
||||
Duplexify.prototype.setReadable = function(readable) {
|
||||
if (this._unread) this._unread()
|
||||
|
||||
if (this.destroyed) {
|
||||
if (readable && readable.destroy) readable.destroy()
|
||||
return
|
||||
}
|
||||
|
||||
if (readable === null || readable === false) {
|
||||
this.push(null)
|
||||
this.resume()
|
||||
return
|
||||
}
|
||||
|
||||
var self = this
|
||||
var unend = eos(readable, {writable:false, readable:true}, destroyer(this))
|
||||
|
||||
var onreadable = function() {
|
||||
self._forward()
|
||||
}
|
||||
|
||||
var onend = function() {
|
||||
self.push(null)
|
||||
}
|
||||
|
||||
var clear = function() {
|
||||
self._readable2.removeListener('readable', onreadable)
|
||||
self._readable2.removeListener('end', onend)
|
||||
unend()
|
||||
}
|
||||
|
||||
this._drained = true
|
||||
this._readable = readable
|
||||
this._readable2 = readable._readableState ? readable : toStreams2(readable)
|
||||
this._readable2.on('readable', onreadable)
|
||||
this._readable2.on('end', onend)
|
||||
this._unread = clear
|
||||
|
||||
this._forward()
|
||||
}
|
||||
|
||||
Duplexify.prototype._read = function() {
|
||||
this._drained = true
|
||||
this._forward()
|
||||
}
|
||||
|
||||
Duplexify.prototype._forward = function() {
|
||||
if (this._forwarding || !this._readable2 || !this._drained) return
|
||||
this._forwarding = true
|
||||
|
||||
var data
|
||||
|
||||
while (this._drained && (data = shift(this._readable2)) !== null) {
|
||||
if (this.destroyed) continue
|
||||
this._drained = this.push(data)
|
||||
}
|
||||
|
||||
this._forwarding = false
|
||||
}
|
||||
|
||||
Duplexify.prototype.destroy = function(err, cb) {
|
||||
if (!cb) cb = noop
|
||||
if (this.destroyed) return cb(null)
|
||||
this.destroyed = true
|
||||
|
||||
var self = this
|
||||
process.nextTick(function() {
|
||||
self._destroy(err)
|
||||
cb(null)
|
||||
})
|
||||
}
|
||||
|
||||
Duplexify.prototype._destroy = function(err) {
|
||||
if (err) {
|
||||
var ondrain = this._ondrain
|
||||
this._ondrain = null
|
||||
if (ondrain) ondrain(err)
|
||||
else this.emit('error', err)
|
||||
}
|
||||
|
||||
if (this._forwardDestroy) {
|
||||
if (this._readable && this._readable.destroy) this._readable.destroy()
|
||||
if (this._writable && this._writable.destroy) this._writable.destroy()
|
||||
}
|
||||
|
||||
this.emit('close')
|
||||
}
|
||||
|
||||
Duplexify.prototype._write = function(data, enc, cb) {
|
||||
if (this.destroyed) return
|
||||
if (this._corked) return onuncork(this, this._write.bind(this, data, enc, cb))
|
||||
if (data === SIGNAL_FLUSH) return this._finish(cb)
|
||||
if (!this._writable) return cb()
|
||||
|
||||
if (this._writable.write(data) === false) this._ondrain = cb
|
||||
else if (!this.destroyed) cb()
|
||||
}
|
||||
|
||||
Duplexify.prototype._finish = function(cb) {
|
||||
var self = this
|
||||
this.emit('preend')
|
||||
onuncork(this, function() {
|
||||
end(self._forwardEnd && self._writable, function() {
|
||||
// haxx to not emit prefinish twice
|
||||
if (self._writableState.prefinished === false) self._writableState.prefinished = true
|
||||
self.emit('prefinish')
|
||||
onuncork(self, cb)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Duplexify.prototype.end = function(data, enc, cb) {
|
||||
if (typeof data === 'function') return this.end(null, null, data)
|
||||
if (typeof enc === 'function') return this.end(data, null, enc)
|
||||
this._ended = true
|
||||
if (data) this.write(data)
|
||||
if (!this._writableState.ending) this.write(SIGNAL_FLUSH)
|
||||
return stream.Writable.prototype.end.call(this, cb)
|
||||
}
|
||||
|
||||
module.exports = Duplexify
|
||||
66
node_modules/duplexify/package.json
generated
vendored
66
node_modules/duplexify/package.json
generated
vendored
@ -1,66 +0,0 @@
|
||||
{
|
||||
"_from": "duplexify@^4.1.1",
|
||||
"_id": "duplexify@4.1.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-DY3xVEmVHTv1wSzKNbwoU6nVjzI369Y6sPoqfYr0/xlx3IdX2n94xIszTcjPO8W8ZIv0Wb0PXNcjuZyT4wiICA==",
|
||||
"_location": "/duplexify",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "duplexify@^4.1.1",
|
||||
"name": "duplexify",
|
||||
"escapedName": "duplexify",
|
||||
"rawSpec": "^4.1.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^4.1.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/pumpify"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/duplexify/-/duplexify-4.1.1.tgz",
|
||||
"_shasum": "7027dc374f157b122a8ae08c2d3ea4d2d953aa61",
|
||||
"_spec": "duplexify@^4.1.1",
|
||||
"_where": "/Users/bret/repos/deploy-to-neocities/node_modules/pumpify",
|
||||
"author": {
|
||||
"name": "Mathias Buus"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/mafintosh/duplexify/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"end-of-stream": "^1.4.1",
|
||||
"inherits": "^2.0.3",
|
||||
"readable-stream": "^3.1.1",
|
||||
"stream-shift": "^1.0.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Turn a writable and readable stream into a streams2 duplex stream with support for async initialization and streams1/streams2 input",
|
||||
"devDependencies": {
|
||||
"concat-stream": "^1.5.2",
|
||||
"tape": "^4.0.0",
|
||||
"through2": "^2.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/mafintosh/duplexify",
|
||||
"keywords": [
|
||||
"duplex",
|
||||
"streams2",
|
||||
"streams",
|
||||
"stream",
|
||||
"writable",
|
||||
"readable",
|
||||
"async"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "duplexify",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/mafintosh/duplexify.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tape test.js"
|
||||
},
|
||||
"version": "4.1.1"
|
||||
}
|
||||
338
node_modules/duplexify/test.js
generated
vendored
338
node_modules/duplexify/test.js
generated
vendored
@ -1,338 +0,0 @@
|
||||
var tape = require('tape')
|
||||
var through = require('through2')
|
||||
var concat = require('concat-stream')
|
||||
var stream = require('readable-stream')
|
||||
var net = require('net')
|
||||
var duplexify = require('./')
|
||||
|
||||
var HELLO_WORLD = (Buffer.from && Buffer.from !== Uint8Array.from)
|
||||
? Buffer.from('hello world')
|
||||
: new Buffer('hello world')
|
||||
|
||||
tape('passthrough', function(t) {
|
||||
t.plan(2)
|
||||
|
||||
var pt = through()
|
||||
var dup = duplexify(pt, pt)
|
||||
|
||||
dup.end('hello world')
|
||||
dup.on('finish', function() {
|
||||
t.ok(true, 'should finish')
|
||||
})
|
||||
dup.pipe(concat(function(data) {
|
||||
t.same(data.toString(), 'hello world', 'same in as out')
|
||||
}))
|
||||
})
|
||||
|
||||
tape('passthrough + double end', function(t) {
|
||||
t.plan(2)
|
||||
|
||||
var pt = through()
|
||||
var dup = duplexify(pt, pt)
|
||||
|
||||
dup.end('hello world')
|
||||
dup.end()
|
||||
|
||||
dup.on('finish', function() {
|
||||
t.ok(true, 'should finish')
|
||||
})
|
||||
dup.pipe(concat(function(data) {
|
||||
t.same(data.toString(), 'hello world', 'same in as out')
|
||||
}))
|
||||
})
|
||||
|
||||
tape('async passthrough + end', function(t) {
|
||||
t.plan(2)
|
||||
|
||||
var pt = through.obj({highWaterMark:1}, function(data, enc, cb) {
|
||||
setTimeout(function() {
|
||||
cb(null, data)
|
||||
}, 100)
|
||||
})
|
||||
|
||||
var dup = duplexify(pt, pt)
|
||||
|
||||
dup.write('hello ')
|
||||
dup.write('world')
|
||||
dup.end()
|
||||
|
||||
dup.on('finish', function() {
|
||||
t.ok(true, 'should finish')
|
||||
})
|
||||
dup.pipe(concat(function(data) {
|
||||
t.same(data.toString(), 'hello world', 'same in as out')
|
||||
}))
|
||||
})
|
||||
|
||||
tape('duplex', function(t) {
|
||||
var readExpected = ['read-a', 'read-b', 'read-c']
|
||||
var writeExpected = ['write-a', 'write-b', 'write-c']
|
||||
|
||||
t.plan(readExpected.length+writeExpected.length+2)
|
||||
|
||||
var readable = through.obj()
|
||||
var writable = through.obj(function(data, enc, cb) {
|
||||
t.same(data, writeExpected.shift(), 'onwrite should match')
|
||||
cb()
|
||||
})
|
||||
|
||||
var dup = duplexify.obj(writable, readable)
|
||||
|
||||
readExpected.slice().forEach(function(data) {
|
||||
readable.write(data)
|
||||
})
|
||||
readable.end()
|
||||
|
||||
writeExpected.slice().forEach(function(data) {
|
||||
dup.write(data)
|
||||
})
|
||||
dup.end()
|
||||
|
||||
dup.on('data', function(data) {
|
||||
t.same(data, readExpected.shift(), 'ondata should match')
|
||||
})
|
||||
dup.on('end', function() {
|
||||
t.ok(true, 'should end')
|
||||
})
|
||||
dup.on('finish', function() {
|
||||
t.ok(true, 'should finish')
|
||||
})
|
||||
})
|
||||
|
||||
tape('async', function(t) {
|
||||
var dup = duplexify()
|
||||
var pt = through()
|
||||
|
||||
dup.pipe(concat(function(data) {
|
||||
t.same(data.toString(), 'i was async', 'same in as out')
|
||||
t.end()
|
||||
}))
|
||||
|
||||
dup.write('i')
|
||||
dup.write(' was ')
|
||||
dup.end('async')
|
||||
|
||||
setTimeout(function() {
|
||||
dup.setWritable(pt)
|
||||
setTimeout(function() {
|
||||
dup.setReadable(pt)
|
||||
}, 50)
|
||||
}, 50)
|
||||
})
|
||||
|
||||
tape('destroy', function(t) {
|
||||
t.plan(2)
|
||||
|
||||
var write = through()
|
||||
var read = through()
|
||||
var dup = duplexify(write, read)
|
||||
|
||||
write.destroy = function() {
|
||||
t.ok(true, 'write destroyed')
|
||||
}
|
||||
|
||||
dup.on('close', function() {
|
||||
t.ok(true, 'close emitted')
|
||||
})
|
||||
|
||||
dup.destroy()
|
||||
dup.destroy() // should only work once
|
||||
})
|
||||
|
||||
tape('destroy both', function(t) {
|
||||
t.plan(3)
|
||||
|
||||
var write = through()
|
||||
var read = through()
|
||||
var dup = duplexify(write, read)
|
||||
|
||||
write.destroy = function() {
|
||||
t.ok(true, 'write destroyed')
|
||||
}
|
||||
|
||||
read.destroy = function() {
|
||||
t.ok(true, 'read destroyed')
|
||||
}
|
||||
|
||||
dup.on('close', function() {
|
||||
t.ok(true, 'close emitted')
|
||||
})
|
||||
|
||||
dup.destroy()
|
||||
dup.destroy() // should only work once
|
||||
})
|
||||
|
||||
tape('bubble read errors', function(t) {
|
||||
t.plan(2)
|
||||
|
||||
var write = through()
|
||||
var read = through()
|
||||
var dup = duplexify(write, read)
|
||||
|
||||
dup.on('error', function(err) {
|
||||
t.same(err.message, 'read-error', 'received read error')
|
||||
})
|
||||
dup.on('close', function() {
|
||||
t.ok(true, 'close emitted')
|
||||
})
|
||||
|
||||
read.emit('error', new Error('read-error'))
|
||||
write.emit('error', new Error('write-error')) // only emit first error
|
||||
})
|
||||
|
||||
tape('bubble write errors', function(t) {
|
||||
t.plan(2)
|
||||
|
||||
var write = through()
|
||||
var read = through()
|
||||
var dup = duplexify(write, read)
|
||||
|
||||
dup.on('error', function(err) {
|
||||
t.same(err.message, 'write-error', 'received write error')
|
||||
})
|
||||
dup.on('close', function() {
|
||||
t.ok(true, 'close emitted')
|
||||
})
|
||||
|
||||
write.emit('error', new Error('write-error'))
|
||||
read.emit('error', new Error('read-error')) // only emit first error
|
||||
})
|
||||
|
||||
tape('bubble errors from write()', function(t) {
|
||||
t.plan(3)
|
||||
|
||||
var errored = false
|
||||
var dup = duplexify(new stream.Writable({
|
||||
write: function(chunk, enc, next) {
|
||||
next(new Error('write-error'))
|
||||
}
|
||||
}))
|
||||
|
||||
dup.on('error', function(err) {
|
||||
errored = true
|
||||
t.same(err.message, 'write-error', 'received write error')
|
||||
})
|
||||
dup.on('close', function() {
|
||||
t.pass('close emitted')
|
||||
t.ok(errored, 'error was emitted before close')
|
||||
})
|
||||
dup.end('123')
|
||||
})
|
||||
|
||||
tape('destroy while waiting for drain', function(t) {
|
||||
t.plan(3)
|
||||
|
||||
var errored = false
|
||||
var dup = duplexify(new stream.Writable({
|
||||
highWaterMark: 0,
|
||||
write: function() {}
|
||||
}))
|
||||
|
||||
dup.on('error', function(err) {
|
||||
errored = true
|
||||
t.same(err.message, 'destroy-error', 'received destroy error')
|
||||
})
|
||||
dup.on('close', function() {
|
||||
t.pass('close emitted')
|
||||
t.ok(errored, 'error was emitted before close')
|
||||
})
|
||||
dup.write('123')
|
||||
dup.destroy(new Error('destroy-error'))
|
||||
})
|
||||
|
||||
tape('reset writable / readable', function(t) {
|
||||
t.plan(3)
|
||||
|
||||
var toUpperCase = function(data, enc, cb) {
|
||||
cb(null, data.toString().toUpperCase())
|
||||
}
|
||||
|
||||
var passthrough = through()
|
||||
var upper = through(toUpperCase)
|
||||
var dup = duplexify(passthrough, passthrough)
|
||||
|
||||
dup.once('data', function(data) {
|
||||
t.same(data.toString(), 'hello')
|
||||
dup.setWritable(upper)
|
||||
dup.setReadable(upper)
|
||||
dup.once('data', function(data) {
|
||||
t.same(data.toString(), 'HELLO')
|
||||
dup.once('data', function(data) {
|
||||
t.same(data.toString(), 'HI')
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
dup.write('hello')
|
||||
dup.write('hi')
|
||||
})
|
||||
dup.write('hello')
|
||||
})
|
||||
|
||||
tape('cork', function(t) {
|
||||
var passthrough = through()
|
||||
var dup = duplexify(passthrough, passthrough)
|
||||
var ok = false
|
||||
|
||||
dup.on('prefinish', function() {
|
||||
dup.cork()
|
||||
setTimeout(function() {
|
||||
ok = true
|
||||
dup.uncork()
|
||||
}, 100)
|
||||
})
|
||||
dup.on('finish', function() {
|
||||
t.ok(ok)
|
||||
t.end()
|
||||
})
|
||||
dup.end()
|
||||
})
|
||||
|
||||
tape('prefinish not twice', function(t) {
|
||||
var passthrough = through()
|
||||
var dup = duplexify(passthrough, passthrough)
|
||||
var prefinished = false
|
||||
|
||||
dup.on('prefinish', function() {
|
||||
t.ok(!prefinished, 'only prefinish once')
|
||||
prefinished = true
|
||||
})
|
||||
|
||||
dup.on('finish', function() {
|
||||
t.end()
|
||||
})
|
||||
|
||||
dup.end()
|
||||
})
|
||||
|
||||
tape('close', function(t) {
|
||||
var passthrough = through()
|
||||
var dup = duplexify(passthrough, passthrough)
|
||||
|
||||
passthrough.emit('close')
|
||||
dup.on('close', function() {
|
||||
t.ok(true, 'should forward close')
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
tape('works with node native streams (net)', function(t) {
|
||||
t.plan(1)
|
||||
|
||||
var server = net.createServer(function(socket) {
|
||||
var dup = duplexify(socket, socket)
|
||||
|
||||
dup.once('data', function(chunk) {
|
||||
t.same(chunk, HELLO_WORLD)
|
||||
server.close()
|
||||
socket.end()
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
server.listen(0, function () {
|
||||
var socket = net.connect(server.address().port)
|
||||
var dup = duplexify(socket, socket)
|
||||
|
||||
dup.write(HELLO_WORLD)
|
||||
})
|
||||
})
|
||||
21
node_modules/end-of-stream/LICENSE
generated
vendored
21
node_modules/end-of-stream/LICENSE
generated
vendored
@ -1,21 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Mathias Buus
|
||||
|
||||
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.
|
||||
54
node_modules/end-of-stream/README.md
generated
vendored
54
node_modules/end-of-stream/README.md
generated
vendored
@ -1,54 +0,0 @@
|
||||
# end-of-stream
|
||||
|
||||
A node module that calls a callback when a readable/writable/duplex stream has completed or failed.
|
||||
|
||||
npm install end-of-stream
|
||||
|
||||
[](https://travis-ci.org/mafintosh/end-of-stream)
|
||||
|
||||
## Usage
|
||||
|
||||
Simply pass a stream and a callback to the `eos`.
|
||||
Both legacy streams, streams2 and stream3 are supported.
|
||||
|
||||
``` js
|
||||
var eos = require('end-of-stream');
|
||||
|
||||
eos(readableStream, function(err) {
|
||||
// this will be set to the stream instance
|
||||
if (err) return console.log('stream had an error or closed early');
|
||||
console.log('stream has ended', this === readableStream);
|
||||
});
|
||||
|
||||
eos(writableStream, function(err) {
|
||||
if (err) return console.log('stream had an error or closed early');
|
||||
console.log('stream has finished', this === writableStream);
|
||||
});
|
||||
|
||||
eos(duplexStream, function(err) {
|
||||
if (err) return console.log('stream had an error or closed early');
|
||||
console.log('stream has ended and finished', this === duplexStream);
|
||||
});
|
||||
|
||||
eos(duplexStream, {readable:false}, function(err) {
|
||||
if (err) return console.log('stream had an error or closed early');
|
||||
console.log('stream has finished but might still be readable');
|
||||
});
|
||||
|
||||
eos(duplexStream, {writable:false}, function(err) {
|
||||
if (err) return console.log('stream had an error or closed early');
|
||||
console.log('stream has ended but might still be writable');
|
||||
});
|
||||
|
||||
eos(readableStream, {error:false}, function(err) {
|
||||
// do not treat emit('error', err) as a end-of-stream
|
||||
});
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
## Related
|
||||
|
||||
`end-of-stream` is part of the [mississippi stream utility collection](https://github.com/maxogden/mississippi) which includes more useful stream modules similar to this one.
|
||||
94
node_modules/end-of-stream/index.js
generated
vendored
94
node_modules/end-of-stream/index.js
generated
vendored
@ -1,94 +0,0 @@
|
||||
var once = require('once');
|
||||
|
||||
var noop = function() {};
|
||||
|
||||
var isRequest = function(stream) {
|
||||
return stream.setHeader && typeof stream.abort === 'function';
|
||||
};
|
||||
|
||||
var isChildProcess = function(stream) {
|
||||
return stream.stdio && Array.isArray(stream.stdio) && stream.stdio.length === 3
|
||||
};
|
||||
|
||||
var eos = function(stream, opts, callback) {
|
||||
if (typeof opts === 'function') return eos(stream, null, opts);
|
||||
if (!opts) opts = {};
|
||||
|
||||
callback = once(callback || noop);
|
||||
|
||||
var ws = stream._writableState;
|
||||
var rs = stream._readableState;
|
||||
var readable = opts.readable || (opts.readable !== false && stream.readable);
|
||||
var writable = opts.writable || (opts.writable !== false && stream.writable);
|
||||
var cancelled = false;
|
||||
|
||||
var onlegacyfinish = function() {
|
||||
if (!stream.writable) onfinish();
|
||||
};
|
||||
|
||||
var onfinish = function() {
|
||||
writable = false;
|
||||
if (!readable) callback.call(stream);
|
||||
};
|
||||
|
||||
var onend = function() {
|
||||
readable = false;
|
||||
if (!writable) callback.call(stream);
|
||||
};
|
||||
|
||||
var onexit = function(exitCode) {
|
||||
callback.call(stream, exitCode ? new Error('exited with error code: ' + exitCode) : null);
|
||||
};
|
||||
|
||||
var onerror = function(err) {
|
||||
callback.call(stream, err);
|
||||
};
|
||||
|
||||
var onclose = function() {
|
||||
process.nextTick(onclosenexttick);
|
||||
};
|
||||
|
||||
var onclosenexttick = function() {
|
||||
if (cancelled) return;
|
||||
if (readable && !(rs && (rs.ended && !rs.destroyed))) return callback.call(stream, new Error('premature close'));
|
||||
if (writable && !(ws && (ws.ended && !ws.destroyed))) return callback.call(stream, new Error('premature close'));
|
||||
};
|
||||
|
||||
var onrequest = function() {
|
||||
stream.req.on('finish', onfinish);
|
||||
};
|
||||
|
||||
if (isRequest(stream)) {
|
||||
stream.on('complete', onfinish);
|
||||
stream.on('abort', onclose);
|
||||
if (stream.req) onrequest();
|
||||
else stream.on('request', onrequest);
|
||||
} else if (writable && !ws) { // legacy streams
|
||||
stream.on('end', onlegacyfinish);
|
||||
stream.on('close', onlegacyfinish);
|
||||
}
|
||||
|
||||
if (isChildProcess(stream)) stream.on('exit', onexit);
|
||||
|
||||
stream.on('end', onend);
|
||||
stream.on('finish', onfinish);
|
||||
if (opts.error !== false) stream.on('error', onerror);
|
||||
stream.on('close', onclose);
|
||||
|
||||
return function() {
|
||||
cancelled = true;
|
||||
stream.removeListener('complete', onfinish);
|
||||
stream.removeListener('abort', onclose);
|
||||
stream.removeListener('request', onrequest);
|
||||
if (stream.req) stream.req.removeListener('finish', onfinish);
|
||||
stream.removeListener('end', onlegacyfinish);
|
||||
stream.removeListener('close', onlegacyfinish);
|
||||
stream.removeListener('finish', onfinish);
|
||||
stream.removeListener('exit', onexit);
|
||||
stream.removeListener('end', onend);
|
||||
stream.removeListener('error', onerror);
|
||||
stream.removeListener('close', onclose);
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = eos;
|
||||
66
node_modules/end-of-stream/package.json
generated
vendored
66
node_modules/end-of-stream/package.json
generated
vendored
@ -1,66 +0,0 @@
|
||||
{
|
||||
"_from": "end-of-stream@^1.1.0",
|
||||
"_id": "end-of-stream@1.4.4",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==",
|
||||
"_location": "/end-of-stream",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "end-of-stream@^1.1.0",
|
||||
"name": "end-of-stream",
|
||||
"escapedName": "end-of-stream",
|
||||
"rawSpec": "^1.1.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.1.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/duplexify",
|
||||
"/pump"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz",
|
||||
"_shasum": "5ae64a5f45057baf3626ec14da0ca5e4b2431eb0",
|
||||
"_spec": "end-of-stream@^1.1.0",
|
||||
"_where": "/Users/bret/repos/deploy-to-neocities/node_modules/pump",
|
||||
"author": {
|
||||
"name": "Mathias Buus",
|
||||
"email": "mathiasbuus@gmail.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/mafintosh/end-of-stream/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"once": "^1.4.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Call a callback when a readable/writable/duplex stream has completed or failed.",
|
||||
"devDependencies": {
|
||||
"tape": "^4.11.0"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"homepage": "https://github.com/mafintosh/end-of-stream",
|
||||
"keywords": [
|
||||
"stream",
|
||||
"streams",
|
||||
"callback",
|
||||
"finish",
|
||||
"close",
|
||||
"end",
|
||||
"wait"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "end-of-stream",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/mafintosh/end-of-stream.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test.js"
|
||||
},
|
||||
"version": "1.4.4"
|
||||
}
|
||||
21
node_modules/fast-fifo/LICENSE
generated
vendored
21
node_modules/fast-fifo/LICENSE
generated
vendored
@ -1,21 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2019 Mathias Buus
|
||||
|
||||
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.
|
||||
66
node_modules/fast-fifo/README.md
generated
vendored
66
node_modules/fast-fifo/README.md
generated
vendored
@ -1,66 +0,0 @@
|
||||
# fast-fifo
|
||||
|
||||
A fast fifo implementation similar to the one powering nextTick in Node.js core
|
||||
|
||||
```
|
||||
npm install fast-fifo
|
||||
```
|
||||
|
||||
Uses a linked list of growing fixed sized arrays to implement the FIFO to avoid
|
||||
allocating a wrapper object for each item.
|
||||
|
||||
## Usage
|
||||
|
||||
``` js
|
||||
const FIFO = require('fast-fifo')
|
||||
|
||||
const q = new FIFO()
|
||||
|
||||
q.push('hello')
|
||||
q.push('world')
|
||||
|
||||
q.shift() // returns hello
|
||||
q.shift() // returns world
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
#### `q = new FIFO()`
|
||||
|
||||
Create a new FIFO.
|
||||
|
||||
#### `q.push(value)`
|
||||
|
||||
Push a value to the FIFO. `value` can be anything other than undefined.
|
||||
|
||||
#### `value = q.shift()`
|
||||
|
||||
Return the oldest value from the FIFO.
|
||||
|
||||
#### `bool = q.isEmpty()`
|
||||
|
||||
Returns `true` if the FIFO is empty and false otherwise.
|
||||
|
||||
## Benchmarks
|
||||
|
||||
Included in bench.js is a simple benchmark that benchmarks this against a simple
|
||||
linked list based FIFO.
|
||||
|
||||
On my machine the benchmark looks like this:
|
||||
|
||||
```
|
||||
fifo bulk push and shift: 2881.508ms
|
||||
fifo individual push and shift: 3248.437ms
|
||||
fast-fifo bulk push and shift: 1606.972ms
|
||||
fast-fifo individual push and shift: 1328.064ms
|
||||
fifo bulk push and shift: 3266.902ms
|
||||
fifo individual push and shift: 3320.944ms
|
||||
fast-fifo bulk push and shift: 1858.307ms
|
||||
fast-fifo individual push and shift: 1516.983ms
|
||||
```
|
||||
|
||||
YMMV
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
34
node_modules/fast-fifo/bench.js
generated
vendored
34
node_modules/fast-fifo/bench.js
generated
vendored
@ -1,34 +0,0 @@
|
||||
const FastFIFO = require('./')
|
||||
const FIFO = require('fifo')
|
||||
|
||||
run(new FIFO(), 'fifo')
|
||||
run(new FastFIFO(), 'fast-fifo')
|
||||
run(new FIFO(), 'fifo')
|
||||
run(new FastFIFO(), 'fast-fifo')
|
||||
|
||||
function run (q, prefix) {
|
||||
const runs = 1024
|
||||
|
||||
console.time(prefix + ' bulk push and shift')
|
||||
|
||||
for (let j = 0; j < 1e5; j++) {
|
||||
for (let i = 0; i < runs; i++) {
|
||||
q.push(i)
|
||||
}
|
||||
for (let i = 0; i < runs; i++) {
|
||||
q.shift()
|
||||
}
|
||||
}
|
||||
|
||||
console.timeEnd(prefix + ' bulk push and shift')
|
||||
console.time(prefix + ' individual push and shift')
|
||||
|
||||
for (let j = 0; j < 1e5; j++) {
|
||||
for (let i = 0; i < runs; i++) {
|
||||
q.push(i)
|
||||
q.shift()
|
||||
}
|
||||
}
|
||||
|
||||
console.timeEnd(prefix + ' individual push and shift')
|
||||
}
|
||||
29
node_modules/fast-fifo/fixed-size.js
generated
vendored
29
node_modules/fast-fifo/fixed-size.js
generated
vendored
@ -1,29 +0,0 @@
|
||||
module.exports = class FixedFIFO {
|
||||
constructor (hwm) {
|
||||
if (!(hwm > 0) || ((hwm - 1) & hwm) !== 0) throw new Error('Max size for a FixedFIFO should be a power of two')
|
||||
this.buffer = new Array(hwm)
|
||||
this.mask = hwm - 1
|
||||
this.top = 0
|
||||
this.btm = 0
|
||||
this.next = null
|
||||
}
|
||||
|
||||
push (data) {
|
||||
if (this.buffer[this.top] !== undefined) return false
|
||||
this.buffer[this.top] = data
|
||||
this.top = (this.top + 1) & this.mask
|
||||
return true
|
||||
}
|
||||
|
||||
shift () {
|
||||
const last = this.buffer[this.btm]
|
||||
if (last === undefined) return undefined
|
||||
this.buffer[this.btm] = undefined
|
||||
this.btm = (this.btm + 1) & this.mask
|
||||
return last
|
||||
}
|
||||
|
||||
isEmpty () {
|
||||
return this.buffer[this.btm] === undefined
|
||||
}
|
||||
}
|
||||
32
node_modules/fast-fifo/index.js
generated
vendored
32
node_modules/fast-fifo/index.js
generated
vendored
@ -1,32 +0,0 @@
|
||||
const FixedFIFO = require('./fixed-size')
|
||||
|
||||
module.exports = class FastFIFO {
|
||||
constructor (hwm) {
|
||||
this.hwm = hwm || 16
|
||||
this.head = new FixedFIFO(this.hwm)
|
||||
this.tail = this.head
|
||||
}
|
||||
|
||||
push (val) {
|
||||
if (!this.head.push(val)) {
|
||||
const prev = this.head
|
||||
this.head = prev.next = new FixedFIFO(2 * this.head.buffer.length)
|
||||
this.head.push(val)
|
||||
}
|
||||
}
|
||||
|
||||
shift () {
|
||||
const val = this.tail.shift()
|
||||
if (val === undefined && this.tail.next) {
|
||||
const next = this.tail.next
|
||||
this.tail.next = null
|
||||
this.tail = next
|
||||
return this.tail.shift()
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
isEmpty () {
|
||||
return this.head.isEmpty()
|
||||
}
|
||||
}
|
||||
52
node_modules/fast-fifo/package.json
generated
vendored
52
node_modules/fast-fifo/package.json
generated
vendored
@ -1,52 +0,0 @@
|
||||
{
|
||||
"_from": "fast-fifo@^1.0.0",
|
||||
"_id": "fast-fifo@1.0.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-4VEXmjxLj7sbs8J//cn2qhRap50dGzF5n8fjay8mau+Jn4hxSeR3xPFwxMaQq/pDaq7+KQk0PAbC2+nWDkJrmQ==",
|
||||
"_location": "/fast-fifo",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "fast-fifo@^1.0.0",
|
||||
"name": "fast-fifo",
|
||||
"escapedName": "fast-fifo",
|
||||
"rawSpec": "^1.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/streamx"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/fast-fifo/-/fast-fifo-1.0.0.tgz",
|
||||
"_shasum": "9bc72e6860347bb045a876d1c5c0af11e9b984e7",
|
||||
"_spec": "fast-fifo@^1.0.0",
|
||||
"_where": "/Users/bret/repos/deploy-to-neocities/node_modules/streamx",
|
||||
"author": {
|
||||
"name": "Mathias Buus",
|
||||
"url": "@mafintosh"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/mafintosh/fast-fifo/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {},
|
||||
"deprecated": false,
|
||||
"description": "A fast fifo implementation similar to the one powering nextTick in Node.js core",
|
||||
"devDependencies": {
|
||||
"standard": "^12.0.1",
|
||||
"tape": "^4.10.1"
|
||||
},
|
||||
"homepage": "https://github.com/mafintosh/fast-fifo",
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "fast-fifo",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/mafintosh/fast-fifo.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "standard && tape test.js"
|
||||
},
|
||||
"version": "1.0.0"
|
||||
}
|
||||
38
node_modules/fast-fifo/test.js
generated
vendored
38
node_modules/fast-fifo/test.js
generated
vendored
@ -1,38 +0,0 @@
|
||||
const tape = require('tape')
|
||||
const FIFO = require('./')
|
||||
|
||||
tape('basic', function (t) {
|
||||
const q = new FIFO()
|
||||
const values = [
|
||||
1,
|
||||
4,
|
||||
4,
|
||||
0,
|
||||
null,
|
||||
{},
|
||||
Math.random(),
|
||||
'',
|
||||
'hello',
|
||||
9,
|
||||
1,
|
||||
4,
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
null,
|
||||
null,
|
||||
0,
|
||||
0,
|
||||
15,
|
||||
52.2,
|
||||
null
|
||||
]
|
||||
|
||||
t.same(q.shift(), undefined)
|
||||
t.ok(q.isEmpty())
|
||||
for (const value of values) q.push(value)
|
||||
while (!q.isEmpty()) t.same(q.shift(), values.shift())
|
||||
t.same(q.shift(), undefined)
|
||||
t.ok(q.isEmpty())
|
||||
t.end()
|
||||
})
|
||||
25
node_modules/fetch-errors/.github/workflows/tests.yml
generated
vendored
25
node_modules/fetch-errors/.github/workflows/tests.yml
generated
vendored
@ -1,25 +0,0 @@
|
||||
name: tests
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [12.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: npm install, build, and test
|
||||
run: |
|
||||
npm i
|
||||
npm test
|
||||
env:
|
||||
CI: true
|
||||
15
node_modules/fetch-errors/CHANGELOG.md
generated
vendored
15
node_modules/fetch-errors/CHANGELOG.md
generated
vendored
@ -1,15 +0,0 @@
|
||||
# fetch-errors Change Log
|
||||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## 2.0.0 - 2020-02-10
|
||||
|
||||
* Remove esm, export CJS. ESM doesn't provide any advantage in Node.js modueles.
|
||||
|
||||
## 1.0.1 - 2019-11-19
|
||||
|
||||
* Add missing devdep.
|
||||
|
||||
## 1.0.0 - 2019-11-19
|
||||
|
||||
* Initial commit
|
||||
4
node_modules/fetch-errors/CODE_OF_CONDUCT.md
generated
vendored
4
node_modules/fetch-errors/CODE_OF_CONDUCT.md
generated
vendored
@ -1,4 +0,0 @@
|
||||
# Code of conduct
|
||||
|
||||
- This repo is governed as a dictatorship starting with the originator of the project.
|
||||
- No malevolence tolerated whatsoever.
|
||||
11
node_modules/fetch-errors/CONTRIBUTING.md
generated
vendored
11
node_modules/fetch-errors/CONTRIBUTING.md
generated
vendored
@ -1,11 +0,0 @@
|
||||
# Contributing
|
||||
|
||||
- Contributors reserve the right to walk away from this project at any moment with or without notice.
|
||||
- Questions are welcome, however unless there is a official support contract established between the maintainers and the requester, support is not guaranteed.
|
||||
- Patches, ideas and changes welcome.
|
||||
- Fixes almost always welcome.
|
||||
- Features sometimes welcome. Please open an issue to discuss the issue prior to spending lots of time on the problem. It may be rejected. If you don't want to wait around for the discussion to commence, and you really want to jump into the implementation work, be prepared for fork if the idea is respectfully declined.
|
||||
- Try to stay within the style of the existing code.
|
||||
- All tests must pass.
|
||||
- Additional features or code paths must be tested.
|
||||
- Aim for 100% coverage.
|
||||
21
node_modules/fetch-errors/LICENSE
generated
vendored
21
node_modules/fetch-errors/LICENSE
generated
vendored
@ -1,21 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2019 Bret Comnes
|
||||
|
||||
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.
|
||||
100
node_modules/fetch-errors/README.md
generated
vendored
100
node_modules/fetch-errors/README.md
generated
vendored
@ -1,100 +0,0 @@
|
||||
# fetch-errors
|
||||
[](https://github.com/bcomnes/fetch-errors/actions)
|
||||
|
||||
Error subclasses for Text and JSON `fetch` response bodies, and a `handleResponse` fuction to handle fetch responses cleanly.
|
||||
|
||||
```
|
||||
npm install fetch-errors
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
``` js
|
||||
const {
|
||||
HTTPError,
|
||||
TextHTTPError,
|
||||
JSONHTTPError,
|
||||
handleResponse
|
||||
} = require('fetch-errors');
|
||||
|
||||
window.fetch('https://api.github.com/users/bcomnes/repos')
|
||||
.then(handleResponse)
|
||||
.then(json => { console.log(json); })
|
||||
.catch(err => {
|
||||
switch (err.constructor) {
|
||||
case JSONHTTPError: {
|
||||
console.error(err.message);
|
||||
console.error(err.status);
|
||||
console.error(err.json);
|
||||
console.error(err.stack);
|
||||
break;
|
||||
}
|
||||
case TextHTTPError: {
|
||||
console.error(err.message);
|
||||
console.error(err.status);
|
||||
console.error(err.data);
|
||||
console.error(err.stack);
|
||||
break;
|
||||
}
|
||||
case HTTPError: {
|
||||
console.error(err.message);
|
||||
console.error(err.status);
|
||||
console.error(err.stack);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
console.error(err);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `async handleResponse(response)`
|
||||
|
||||
Parse JSON or text bodies of [`fetch`][fetch] [`Response`][response] objects. Intended for APIs that return JSON, but falls back to `response.text()` body reading when the `json` `Content-type` is missing. If `response.ok`, returns a JS object (if JSON), or the text content of the response body. Otherwise, returns a `JSONHTTPError` or `TextHTTPError`. If if `response.json()` or `resonse.text()` will throw their [native error]() objects.
|
||||
|
||||
### `class HTTPError extends Error`
|
||||
|
||||
Additional error properties from Error
|
||||
|
||||
```js
|
||||
{
|
||||
stack, // stack trace of error
|
||||
status // status code of response
|
||||
}
|
||||
```
|
||||
|
||||
### `class TextHTTPError extends HTTPError`
|
||||
|
||||
Additional error properties from HTTPError
|
||||
|
||||
```js
|
||||
{
|
||||
data // data of text response
|
||||
}
|
||||
```
|
||||
|
||||
### `class JSONHTTPError extends HTTPError`
|
||||
|
||||
Additional error properties from HTTPError
|
||||
|
||||
```js
|
||||
{
|
||||
json // json of a JSON response
|
||||
}
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
- [netlify/micro-api-client](https://github.com/netlify/micro-api-client): These errors were extracted from netlify/micro-api-client for individual use.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
[response]: https://developer.mozilla.org/en-US/docs/Web/API/Response
|
||||
[fetch]: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
|
||||
45
node_modules/fetch-errors/index.js
generated
vendored
45
node_modules/fetch-errors/index.js
generated
vendored
@ -1,45 +0,0 @@
|
||||
async function handleResponse (response) {
|
||||
const contentType = response.headers.get('Content-Type');
|
||||
const isJSON = contentType && contentType.match(/json/);
|
||||
const data = isJSON ? await response.json() : await response.text();
|
||||
if (response.ok) return data;
|
||||
else {
|
||||
return isJSON
|
||||
? Promise.reject(new JSONHTTPError(response, data))
|
||||
: Promise.reject(new TextHTTPError(response, data));
|
||||
}
|
||||
}
|
||||
|
||||
class HTTPError extends Error {
|
||||
constructor (response) {
|
||||
super(response.statusText);
|
||||
this.name = this.constructor.name;
|
||||
if (typeof Error.captureStackTrace === 'function') {
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
} else {
|
||||
this.stack = new Error(response.statusText).stack;
|
||||
}
|
||||
this.status = response.status;
|
||||
}
|
||||
}
|
||||
|
||||
class TextHTTPError extends HTTPError {
|
||||
constructor (response, data) {
|
||||
super(response);
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
||||
class JSONHTTPError extends HTTPError {
|
||||
constructor (response, json) {
|
||||
super(response);
|
||||
this.json = json;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
handleResponse,
|
||||
HTTPError,
|
||||
TextHTTPError,
|
||||
JSONHTTPError
|
||||
};
|
||||
66
node_modules/fetch-errors/package.json
generated
vendored
66
node_modules/fetch-errors/package.json
generated
vendored
@ -1,66 +0,0 @@
|
||||
{
|
||||
"_from": "fetch-errors@^2.0.1",
|
||||
"_id": "fetch-errors@2.0.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-U+pPCefRg8OwN0VARqAOCEyJs+kbSusskhW3XQPYCQMBUUNy3VtK9OYyySlybDQmMkZzqxWlGY9SjKCve1saJw==",
|
||||
"_location": "/fetch-errors",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "fetch-errors@^2.0.1",
|
||||
"name": "fetch-errors",
|
||||
"escapedName": "fetch-errors",
|
||||
"rawSpec": "^2.0.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^2.0.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/async-neocities"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/fetch-errors/-/fetch-errors-2.0.1.tgz",
|
||||
"_shasum": "26616c7c22a0a386155ba8e53af27f98960e47dc",
|
||||
"_spec": "fetch-errors@^2.0.1",
|
||||
"_where": "/Users/bret/repos/deploy-to-neocities/node_modules/async-neocities",
|
||||
"author": {
|
||||
"name": "Bret Comnes",
|
||||
"email": "bcomnes@gmail.com",
|
||||
"url": "https://bret.io"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/bcomnes/fetch-errors/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {},
|
||||
"deprecated": false,
|
||||
"description": "WIP - nothing to see here",
|
||||
"devDependencies": {
|
||||
"dependency-check": "^4.1.0",
|
||||
"node-fetch": "^2.6.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"semistandard": "^14.2.0",
|
||||
"tape": "^4.11.0",
|
||||
"tape-promise": "^4.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/bcomnes/fetch-errors",
|
||||
"keywords": [],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "fetch-errors",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/bcomnes/fetch-errors.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "run-s test:*",
|
||||
"test:deps": "dependency-check . --no-dev --no-peer",
|
||||
"test:semistandard": "semistandard",
|
||||
"test:tape": "tape test.js"
|
||||
},
|
||||
"semistandard": {
|
||||
"ignore": [
|
||||
"dist"
|
||||
]
|
||||
},
|
||||
"version": "2.0.1"
|
||||
}
|
||||
18
node_modules/fetch-errors/test.js
generated
vendored
18
node_modules/fetch-errors/test.js
generated
vendored
@ -1,18 +0,0 @@
|
||||
const tape = require('tape');
|
||||
const ptape = require('tape-promise').default;
|
||||
const { handleResponse } = require('.');
|
||||
const fetch = require('node-fetch');
|
||||
const test = ptape(tape);
|
||||
|
||||
test('handleResponse', async t => {
|
||||
return fetch('https://api.github.com/users/bcomnes/repos')
|
||||
.then(response => {
|
||||
t.ok(response.ok);
|
||||
return response;
|
||||
})
|
||||
.then(handleResponse)
|
||||
.then(json => {
|
||||
t.ok(json);
|
||||
})
|
||||
.catch(t.error);
|
||||
});
|
||||
19
node_modules/form-data/License
generated
vendored
19
node_modules/form-data/License
generated
vendored
@ -1,19 +0,0 @@
|
||||
Copyright (c) 2012 Felix Geisendörfer (felix@debuggable.com) and contributors
|
||||
|
||||
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.
|
||||
351
node_modules/form-data/README.md
generated
vendored
351
node_modules/form-data/README.md
generated
vendored
@ -1,351 +0,0 @@
|
||||
# Form-Data [](https://www.npmjs.com/package/form-data) [](https://gitter.im/form-data/form-data)
|
||||
|
||||
A library to create readable ```"multipart/form-data"``` streams. Can be used to submit forms and file uploads to other web applications.
|
||||
|
||||
The API of this library is inspired by the [XMLHttpRequest-2 FormData Interface][xhr2-fd].
|
||||
|
||||
[xhr2-fd]: http://dev.w3.org/2006/webapi/XMLHttpRequest-2/Overview.html#the-formdata-interface
|
||||
|
||||
[](https://travis-ci.org/form-data/form-data)
|
||||
[](https://travis-ci.org/form-data/form-data)
|
||||
[](https://travis-ci.org/form-data/form-data)
|
||||
|
||||
[](https://coveralls.io/github/form-data/form-data?branch=master)
|
||||
[](https://david-dm.org/form-data/form-data)
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
npm install --save form-data
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
In this example we are constructing a form with 3 fields that contain a string,
|
||||
a buffer and a file stream.
|
||||
|
||||
``` javascript
|
||||
var FormData = require('form-data');
|
||||
var fs = require('fs');
|
||||
|
||||
var form = new FormData();
|
||||
form.append('my_field', 'my value');
|
||||
form.append('my_buffer', new Buffer(10));
|
||||
form.append('my_file', fs.createReadStream('/foo/bar.jpg'));
|
||||
```
|
||||
|
||||
Also you can use http-response stream:
|
||||
|
||||
``` javascript
|
||||
var FormData = require('form-data');
|
||||
var http = require('http');
|
||||
|
||||
var form = new FormData();
|
||||
|
||||
http.request('http://nodejs.org/images/logo.png', function(response) {
|
||||
form.append('my_field', 'my value');
|
||||
form.append('my_buffer', new Buffer(10));
|
||||
form.append('my_logo', response);
|
||||
});
|
||||
```
|
||||
|
||||
Or @mikeal's [request](https://github.com/request/request) stream:
|
||||
|
||||
``` javascript
|
||||
var FormData = require('form-data');
|
||||
var request = require('request');
|
||||
|
||||
var form = new FormData();
|
||||
|
||||
form.append('my_field', 'my value');
|
||||
form.append('my_buffer', new Buffer(10));
|
||||
form.append('my_logo', request('http://nodejs.org/images/logo.png'));
|
||||
```
|
||||
|
||||
In order to submit this form to a web application, call ```submit(url, [callback])``` method:
|
||||
|
||||
``` javascript
|
||||
form.submit('http://example.org/', function(err, res) {
|
||||
// res – response object (http.IncomingMessage) //
|
||||
res.resume();
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
For more advanced request manipulations ```submit()``` method returns ```http.ClientRequest``` object, or you can choose from one of the alternative submission methods.
|
||||
|
||||
### Custom options
|
||||
|
||||
You can provide custom options, such as `maxDataSize`:
|
||||
|
||||
``` javascript
|
||||
var FormData = require('form-data');
|
||||
|
||||
var form = new FormData({ maxDataSize: 20971520 });
|
||||
form.append('my_field', 'my value');
|
||||
form.append('my_buffer', /* something big */);
|
||||
```
|
||||
|
||||
List of available options could be found in [combined-stream](https://github.com/felixge/node-combined-stream/blob/master/lib/combined_stream.js#L7-L15)
|
||||
|
||||
### Alternative submission methods
|
||||
|
||||
You can use node's http client interface:
|
||||
|
||||
``` javascript
|
||||
var http = require('http');
|
||||
|
||||
var request = http.request({
|
||||
method: 'post',
|
||||
host: 'example.org',
|
||||
path: '/upload',
|
||||
headers: form.getHeaders()
|
||||
});
|
||||
|
||||
form.pipe(request);
|
||||
|
||||
request.on('response', function(res) {
|
||||
console.log(res.statusCode);
|
||||
});
|
||||
```
|
||||
|
||||
Or if you would prefer the `'Content-Length'` header to be set for you:
|
||||
|
||||
``` javascript
|
||||
form.submit('example.org/upload', function(err, res) {
|
||||
console.log(res.statusCode);
|
||||
});
|
||||
```
|
||||
|
||||
To use custom headers and pre-known length in parts:
|
||||
|
||||
``` javascript
|
||||
var CRLF = '\r\n';
|
||||
var form = new FormData();
|
||||
|
||||
var options = {
|
||||
header: CRLF + '--' + form.getBoundary() + CRLF + 'X-Custom-Header: 123' + CRLF + CRLF,
|
||||
knownLength: 1
|
||||
};
|
||||
|
||||
form.append('my_buffer', buffer, options);
|
||||
|
||||
form.submit('http://example.com/', function(err, res) {
|
||||
if (err) throw err;
|
||||
console.log('Done');
|
||||
});
|
||||
```
|
||||
|
||||
Form-Data can recognize and fetch all the required information from common types of streams (```fs.readStream```, ```http.response``` and ```mikeal's request```), for some other types of streams you'd need to provide "file"-related information manually:
|
||||
|
||||
``` javascript
|
||||
someModule.stream(function(err, stdout, stderr) {
|
||||
if (err) throw err;
|
||||
|
||||
var form = new FormData();
|
||||
|
||||
form.append('file', stdout, {
|
||||
filename: 'unicycle.jpg', // ... or:
|
||||
filepath: 'photos/toys/unicycle.jpg',
|
||||
contentType: 'image/jpeg',
|
||||
knownLength: 19806
|
||||
});
|
||||
|
||||
form.submit('http://example.com/', function(err, res) {
|
||||
if (err) throw err;
|
||||
console.log('Done');
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
The `filepath` property overrides `filename` and may contain a relative path. This is typically used when uploading [multiple files from a directory](https://wicg.github.io/entries-api/#dom-htmlinputelement-webkitdirectory).
|
||||
|
||||
For edge cases, like POST request to URL with query string or to pass HTTP auth credentials, object can be passed to `form.submit()` as first parameter:
|
||||
|
||||
``` javascript
|
||||
form.submit({
|
||||
host: 'example.com',
|
||||
path: '/probably.php?extra=params',
|
||||
auth: 'username:password'
|
||||
}, function(err, res) {
|
||||
console.log(res.statusCode);
|
||||
});
|
||||
```
|
||||
|
||||
In case you need to also send custom HTTP headers with the POST request, you can use the `headers` key in first parameter of `form.submit()`:
|
||||
|
||||
``` javascript
|
||||
form.submit({
|
||||
host: 'example.com',
|
||||
path: '/surelynot.php',
|
||||
headers: {'x-test-header': 'test-header-value'}
|
||||
}, function(err, res) {
|
||||
console.log(res.statusCode);
|
||||
});
|
||||
```
|
||||
|
||||
### Methods
|
||||
|
||||
- [_Void_ append( **String** _field_, **Mixed** _value_ [, **Mixed** _options_] )](https://github.com/form-data/form-data#void-append-string-field-mixed-value--mixed-options-).
|
||||
- [_Headers_ getHeaders( [**Headers** _userHeaders_] )](https://github.com/form-data/form-data#array-getheaders-array-userheaders-)
|
||||
- [_String_ getBoundary()](https://github.com/form-data/form-data#string-getboundary)
|
||||
- [_Buffer_ getBuffer()](https://github.com/form-data/form-data#buffer-getbuffer)
|
||||
- [_Integer_ getLengthSync()](https://github.com/form-data/form-data#integer-getlengthsync)
|
||||
- [_Integer_ getLength( **function** _callback_ )](https://github.com/form-data/form-data#integer-getlength-function-callback-)
|
||||
- [_Boolean_ hasKnownLength()](https://github.com/form-data/form-data#boolean-hasknownlength)
|
||||
- [_Request_ submit( _params_, **function** _callback_ )](https://github.com/form-data/form-data#request-submit-params-function-callback-)
|
||||
- [_String_ toString()](https://github.com/form-data/form-data#string-tostring)
|
||||
|
||||
#### _Void_ append( **String** _field_, **Mixed** _value_ [, **Mixed** _options_] )
|
||||
Append data to the form. You can submit about any format (string, integer, boolean, buffer, etc.). However, Arrays are not supported and need to be turned into strings by the user.
|
||||
```javascript
|
||||
var form = new FormData();
|
||||
form.append( 'my_string', 'my value' );
|
||||
form.append( 'my_integer', 1 );
|
||||
form.append( 'my_boolean', true );
|
||||
form.append( 'my_buffer', new Buffer(10) );
|
||||
form.append( 'my_array_as_json', JSON.stringify( ['bird','cute'] ) )
|
||||
```
|
||||
|
||||
You may provide a string for options, or an object.
|
||||
```javascript
|
||||
// Set filename by providing a string for options
|
||||
form.append( 'my_file', fs.createReadStream('/foo/bar.jpg'), 'bar.jpg' );
|
||||
|
||||
// provide an object.
|
||||
form.append( 'my_file', fs.createReadStream('/foo/bar.jpg'), {filename: 'bar.jpg', contentType: 'image/jpeg', knownLength: 19806} );
|
||||
```
|
||||
|
||||
#### _Headers_ getHeaders( [**Headers** _userHeaders_] )
|
||||
This method ads the correct `content-type` header to the provided array of `userHeaders`.
|
||||
|
||||
#### _String_ getBoundary()
|
||||
Return the boundary of the formData. A boundary consists of 26 `-` followed by 24 numbers
|
||||
for example:
|
||||
```javascript
|
||||
--------------------------515890814546601021194782
|
||||
```
|
||||
_Note: The boundary must be unique and may not appear in the data._
|
||||
|
||||
#### _Buffer_ getBuffer()
|
||||
Return the full formdata request package, as a Buffer. You can insert this Buffer in e.g. Axios to send multipart data.
|
||||
```javascript
|
||||
var form = new FormData();
|
||||
form.append( 'my_buffer', Buffer.from([0x4a,0x42,0x20,0x52,0x6f,0x63,0x6b,0x73]) );
|
||||
form.append( 'my_file', fs.readFileSync('/foo/bar.jpg') );
|
||||
|
||||
axios.post( 'https://example.com/path/to/api',
|
||||
form.getBuffer(),
|
||||
form.getHeaders()
|
||||
)
|
||||
```
|
||||
**Note:** Because the output is of type Buffer, you can only append types that are accepted by Buffer: *string, Buffer, ArrayBuffer, Array, or Array-like Object*. A ReadStream for example will result in an error.
|
||||
|
||||
#### _Integer_ getLengthSync()
|
||||
Same as `getLength` but synchronous.
|
||||
|
||||
_Note: getLengthSync __doesn't__ calculate streams length._
|
||||
|
||||
#### _Integer_ getLength( **function** _callback_ )
|
||||
Returns the `Content-Length` async. The callback is used to handle errors and continue once the length has been calculated
|
||||
```javascript
|
||||
this.getLength(function(err, length) {
|
||||
if (err) {
|
||||
this._error(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// add content length
|
||||
request.setHeader('Content-Length', length);
|
||||
|
||||
...
|
||||
}.bind(this));
|
||||
```
|
||||
|
||||
#### _Boolean_ hasKnownLength()
|
||||
Checks if the length of added values is known.
|
||||
|
||||
#### _Request_ submit( _params_, **function** _callback_ )
|
||||
Submit the form to a web application.
|
||||
```javascript
|
||||
var form = new FormData();
|
||||
form.append( 'my_string', 'Hello World' );
|
||||
|
||||
form.submit( 'http://example.com/', function(err, res) {
|
||||
// res – response object (http.IncomingMessage) //
|
||||
res.resume();
|
||||
} );
|
||||
```
|
||||
|
||||
#### _String_ toString()
|
||||
Returns the form data as a string. Don't use this if you are sending files or buffers, use `getBuffer()` instead.
|
||||
|
||||
### Integration with other libraries
|
||||
|
||||
#### Request
|
||||
|
||||
Form submission using [request](https://github.com/request/request):
|
||||
|
||||
```javascript
|
||||
var formData = {
|
||||
my_field: 'my_value',
|
||||
my_file: fs.createReadStream(__dirname + '/unicycle.jpg'),
|
||||
};
|
||||
|
||||
request.post({url:'http://service.com/upload', formData: formData}, function(err, httpResponse, body) {
|
||||
if (err) {
|
||||
return console.error('upload failed:', err);
|
||||
}
|
||||
console.log('Upload successful! Server responded with:', body);
|
||||
});
|
||||
```
|
||||
|
||||
For more details see [request readme](https://github.com/request/request#multipartform-data-multipart-form-uploads).
|
||||
|
||||
#### node-fetch
|
||||
|
||||
You can also submit a form using [node-fetch](https://github.com/bitinn/node-fetch):
|
||||
|
||||
```javascript
|
||||
var form = new FormData();
|
||||
|
||||
form.append('a', 1);
|
||||
|
||||
fetch('http://example.com', { method: 'POST', body: form })
|
||||
.then(function(res) {
|
||||
return res.json();
|
||||
}).then(function(json) {
|
||||
console.log(json);
|
||||
});
|
||||
```
|
||||
|
||||
#### axios
|
||||
|
||||
In Node.js you can post a file using [axios](https://github.com/axios/axios):
|
||||
```javascript
|
||||
const form = new FormData();
|
||||
const stream = fs.createReadStream(PATH_TO_FILE);
|
||||
|
||||
form.append('image', stream);
|
||||
|
||||
// In Node.js environment you need to set boundary in the header field 'Content-Type' by calling method `getHeaders`
|
||||
const formHeaders = form.getHeaders();
|
||||
|
||||
axios.post('http://example.com', form, {
|
||||
headers: {
|
||||
...formHeaders,
|
||||
},
|
||||
})
|
||||
.then(response => response)
|
||||
.catch(error => error)
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- ```getLengthSync()``` method DOESN'T calculate length for streams, use ```knownLength``` options as workaround.
|
||||
- Starting version `2.x` FormData has dropped support for `node@0.10.x`.
|
||||
- Starting version `3.x` FormData has dropped support for `node@4.x`.
|
||||
|
||||
## License
|
||||
|
||||
Form-Data is released under the [MIT](License) license.
|
||||
351
node_modules/form-data/README.md.bak
generated
vendored
351
node_modules/form-data/README.md.bak
generated
vendored
@ -1,351 +0,0 @@
|
||||
# Form-Data [](https://www.npmjs.com/package/form-data) [](https://gitter.im/form-data/form-data)
|
||||
|
||||
A library to create readable ```"multipart/form-data"``` streams. Can be used to submit forms and file uploads to other web applications.
|
||||
|
||||
The API of this library is inspired by the [XMLHttpRequest-2 FormData Interface][xhr2-fd].
|
||||
|
||||
[xhr2-fd]: http://dev.w3.org/2006/webapi/XMLHttpRequest-2/Overview.html#the-formdata-interface
|
||||
|
||||
[](https://travis-ci.org/form-data/form-data)
|
||||
[](https://travis-ci.org/form-data/form-data)
|
||||
[](https://travis-ci.org/form-data/form-data)
|
||||
|
||||
[](https://coveralls.io/github/form-data/form-data?branch=master)
|
||||
[](https://david-dm.org/form-data/form-data)
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
npm install --save form-data
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
In this example we are constructing a form with 3 fields that contain a string,
|
||||
a buffer and a file stream.
|
||||
|
||||
``` javascript
|
||||
var FormData = require('form-data');
|
||||
var fs = require('fs');
|
||||
|
||||
var form = new FormData();
|
||||
form.append('my_field', 'my value');
|
||||
form.append('my_buffer', new Buffer(10));
|
||||
form.append('my_file', fs.createReadStream('/foo/bar.jpg'));
|
||||
```
|
||||
|
||||
Also you can use http-response stream:
|
||||
|
||||
``` javascript
|
||||
var FormData = require('form-data');
|
||||
var http = require('http');
|
||||
|
||||
var form = new FormData();
|
||||
|
||||
http.request('http://nodejs.org/images/logo.png', function(response) {
|
||||
form.append('my_field', 'my value');
|
||||
form.append('my_buffer', new Buffer(10));
|
||||
form.append('my_logo', response);
|
||||
});
|
||||
```
|
||||
|
||||
Or @mikeal's [request](https://github.com/request/request) stream:
|
||||
|
||||
``` javascript
|
||||
var FormData = require('form-data');
|
||||
var request = require('request');
|
||||
|
||||
var form = new FormData();
|
||||
|
||||
form.append('my_field', 'my value');
|
||||
form.append('my_buffer', new Buffer(10));
|
||||
form.append('my_logo', request('http://nodejs.org/images/logo.png'));
|
||||
```
|
||||
|
||||
In order to submit this form to a web application, call ```submit(url, [callback])``` method:
|
||||
|
||||
``` javascript
|
||||
form.submit('http://example.org/', function(err, res) {
|
||||
// res – response object (http.IncomingMessage) //
|
||||
res.resume();
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
For more advanced request manipulations ```submit()``` method returns ```http.ClientRequest``` object, or you can choose from one of the alternative submission methods.
|
||||
|
||||
### Custom options
|
||||
|
||||
You can provide custom options, such as `maxDataSize`:
|
||||
|
||||
``` javascript
|
||||
var FormData = require('form-data');
|
||||
|
||||
var form = new FormData({ maxDataSize: 20971520 });
|
||||
form.append('my_field', 'my value');
|
||||
form.append('my_buffer', /* something big */);
|
||||
```
|
||||
|
||||
List of available options could be found in [combined-stream](https://github.com/felixge/node-combined-stream/blob/master/lib/combined_stream.js#L7-L15)
|
||||
|
||||
### Alternative submission methods
|
||||
|
||||
You can use node's http client interface:
|
||||
|
||||
``` javascript
|
||||
var http = require('http');
|
||||
|
||||
var request = http.request({
|
||||
method: 'post',
|
||||
host: 'example.org',
|
||||
path: '/upload',
|
||||
headers: form.getHeaders()
|
||||
});
|
||||
|
||||
form.pipe(request);
|
||||
|
||||
request.on('response', function(res) {
|
||||
console.log(res.statusCode);
|
||||
});
|
||||
```
|
||||
|
||||
Or if you would prefer the `'Content-Length'` header to be set for you:
|
||||
|
||||
``` javascript
|
||||
form.submit('example.org/upload', function(err, res) {
|
||||
console.log(res.statusCode);
|
||||
});
|
||||
```
|
||||
|
||||
To use custom headers and pre-known length in parts:
|
||||
|
||||
``` javascript
|
||||
var CRLF = '\r\n';
|
||||
var form = new FormData();
|
||||
|
||||
var options = {
|
||||
header: CRLF + '--' + form.getBoundary() + CRLF + 'X-Custom-Header: 123' + CRLF + CRLF,
|
||||
knownLength: 1
|
||||
};
|
||||
|
||||
form.append('my_buffer', buffer, options);
|
||||
|
||||
form.submit('http://example.com/', function(err, res) {
|
||||
if (err) throw err;
|
||||
console.log('Done');
|
||||
});
|
||||
```
|
||||
|
||||
Form-Data can recognize and fetch all the required information from common types of streams (```fs.readStream```, ```http.response``` and ```mikeal's request```), for some other types of streams you'd need to provide "file"-related information manually:
|
||||
|
||||
``` javascript
|
||||
someModule.stream(function(err, stdout, stderr) {
|
||||
if (err) throw err;
|
||||
|
||||
var form = new FormData();
|
||||
|
||||
form.append('file', stdout, {
|
||||
filename: 'unicycle.jpg', // ... or:
|
||||
filepath: 'photos/toys/unicycle.jpg',
|
||||
contentType: 'image/jpeg',
|
||||
knownLength: 19806
|
||||
});
|
||||
|
||||
form.submit('http://example.com/', function(err, res) {
|
||||
if (err) throw err;
|
||||
console.log('Done');
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
The `filepath` property overrides `filename` and may contain a relative path. This is typically used when uploading [multiple files from a directory](https://wicg.github.io/entries-api/#dom-htmlinputelement-webkitdirectory).
|
||||
|
||||
For edge cases, like POST request to URL with query string or to pass HTTP auth credentials, object can be passed to `form.submit()` as first parameter:
|
||||
|
||||
``` javascript
|
||||
form.submit({
|
||||
host: 'example.com',
|
||||
path: '/probably.php?extra=params',
|
||||
auth: 'username:password'
|
||||
}, function(err, res) {
|
||||
console.log(res.statusCode);
|
||||
});
|
||||
```
|
||||
|
||||
In case you need to also send custom HTTP headers with the POST request, you can use the `headers` key in first parameter of `form.submit()`:
|
||||
|
||||
``` javascript
|
||||
form.submit({
|
||||
host: 'example.com',
|
||||
path: '/surelynot.php',
|
||||
headers: {'x-test-header': 'test-header-value'}
|
||||
}, function(err, res) {
|
||||
console.log(res.statusCode);
|
||||
});
|
||||
```
|
||||
|
||||
### Methods
|
||||
|
||||
- [_Void_ append( **String** _field_, **Mixed** _value_ [, **Mixed** _options_] )](https://github.com/form-data/form-data#void-append-string-field-mixed-value--mixed-options-).
|
||||
- [_Headers_ getHeaders( [**Headers** _userHeaders_] )](https://github.com/form-data/form-data#array-getheaders-array-userheaders-)
|
||||
- [_String_ getBoundary()](https://github.com/form-data/form-data#string-getboundary)
|
||||
- [_Buffer_ getBuffer()](https://github.com/form-data/form-data#buffer-getbuffer)
|
||||
- [_Integer_ getLengthSync()](https://github.com/form-data/form-data#integer-getlengthsync)
|
||||
- [_Integer_ getLength( **function** _callback_ )](https://github.com/form-data/form-data#integer-getlength-function-callback-)
|
||||
- [_Boolean_ hasKnownLength()](https://github.com/form-data/form-data#boolean-hasknownlength)
|
||||
- [_Request_ submit( _params_, **function** _callback_ )](https://github.com/form-data/form-data#request-submit-params-function-callback-)
|
||||
- [_String_ toString()](https://github.com/form-data/form-data#string-tostring)
|
||||
|
||||
#### _Void_ append( **String** _field_, **Mixed** _value_ [, **Mixed** _options_] )
|
||||
Append data to the form. You can submit about any format (string, integer, boolean, buffer, etc.). However, Arrays are not supported and need to be turned into strings by the user.
|
||||
```javascript
|
||||
var form = new FormData();
|
||||
form.append( 'my_string', 'my value' );
|
||||
form.append( 'my_integer', 1 );
|
||||
form.append( 'my_boolean', true );
|
||||
form.append( 'my_buffer', new Buffer(10) );
|
||||
form.append( 'my_array_as_json', JSON.stringify( ['bird','cute'] ) )
|
||||
```
|
||||
|
||||
You may provide a string for options, or an object.
|
||||
```javascript
|
||||
// Set filename by providing a string for options
|
||||
form.append( 'my_file', fs.createReadStream('/foo/bar.jpg'), 'bar.jpg' );
|
||||
|
||||
// provide an object.
|
||||
form.append( 'my_file', fs.createReadStream('/foo/bar.jpg'), {filename: 'bar.jpg', contentType: 'image/jpeg', knownLength: 19806} );
|
||||
```
|
||||
|
||||
#### _Headers_ getHeaders( [**Headers** _userHeaders_] )
|
||||
This method ads the correct `content-type` header to the provided array of `userHeaders`.
|
||||
|
||||
#### _String_ getBoundary()
|
||||
Return the boundary of the formData. A boundary consists of 26 `-` followed by 24 numbers
|
||||
for example:
|
||||
```javascript
|
||||
--------------------------515890814546601021194782
|
||||
```
|
||||
_Note: The boundary must be unique and may not appear in the data._
|
||||
|
||||
#### _Buffer_ getBuffer()
|
||||
Return the full formdata request package, as a Buffer. You can insert this Buffer in e.g. Axios to send multipart data.
|
||||
```javascript
|
||||
var form = new FormData();
|
||||
form.append( 'my_buffer', Buffer.from([0x4a,0x42,0x20,0x52,0x6f,0x63,0x6b,0x73]) );
|
||||
form.append( 'my_file', fs.readFileSync('/foo/bar.jpg') );
|
||||
|
||||
axios.post( 'https://example.com/path/to/api',
|
||||
form.getBuffer(),
|
||||
form.getHeaders()
|
||||
)
|
||||
```
|
||||
**Note:** Because the output is of type Buffer, you can only append types that are accepted by Buffer: *string, Buffer, ArrayBuffer, Array, or Array-like Object*. A ReadStream for example will result in an error.
|
||||
|
||||
#### _Integer_ getLengthSync()
|
||||
Same as `getLength` but synchronous.
|
||||
|
||||
_Note: getLengthSync __doesn't__ calculate streams length._
|
||||
|
||||
#### _Integer_ getLength( **function** _callback_ )
|
||||
Returns the `Content-Length` async. The callback is used to handle errors and continue once the length has been calculated
|
||||
```javascript
|
||||
this.getLength(function(err, length) {
|
||||
if (err) {
|
||||
this._error(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// add content length
|
||||
request.setHeader('Content-Length', length);
|
||||
|
||||
...
|
||||
}.bind(this));
|
||||
```
|
||||
|
||||
#### _Boolean_ hasKnownLength()
|
||||
Checks if the length of added values is known.
|
||||
|
||||
#### _Request_ submit( _params_, **function** _callback_ )
|
||||
Submit the form to a web application.
|
||||
```javascript
|
||||
var form = new FormData();
|
||||
form.append( 'my_string', 'Hello World' );
|
||||
|
||||
form.submit( 'http://example.com/', function(err, res) {
|
||||
// res – response object (http.IncomingMessage) //
|
||||
res.resume();
|
||||
} );
|
||||
```
|
||||
|
||||
#### _String_ toString()
|
||||
Returns the form data as a string. Don't use this if you are sending files or buffers, use `getBuffer()` instead.
|
||||
|
||||
### Integration with other libraries
|
||||
|
||||
#### Request
|
||||
|
||||
Form submission using [request](https://github.com/request/request):
|
||||
|
||||
```javascript
|
||||
var formData = {
|
||||
my_field: 'my_value',
|
||||
my_file: fs.createReadStream(__dirname + '/unicycle.jpg'),
|
||||
};
|
||||
|
||||
request.post({url:'http://service.com/upload', formData: formData}, function(err, httpResponse, body) {
|
||||
if (err) {
|
||||
return console.error('upload failed:', err);
|
||||
}
|
||||
console.log('Upload successful! Server responded with:', body);
|
||||
});
|
||||
```
|
||||
|
||||
For more details see [request readme](https://github.com/request/request#multipartform-data-multipart-form-uploads).
|
||||
|
||||
#### node-fetch
|
||||
|
||||
You can also submit a form using [node-fetch](https://github.com/bitinn/node-fetch):
|
||||
|
||||
```javascript
|
||||
var form = new FormData();
|
||||
|
||||
form.append('a', 1);
|
||||
|
||||
fetch('http://example.com', { method: 'POST', body: form })
|
||||
.then(function(res) {
|
||||
return res.json();
|
||||
}).then(function(json) {
|
||||
console.log(json);
|
||||
});
|
||||
```
|
||||
|
||||
#### axios
|
||||
|
||||
In Node.js you can post a file using [axios](https://github.com/axios/axios):
|
||||
```javascript
|
||||
const form = new FormData();
|
||||
const stream = fs.createReadStream(PATH_TO_FILE);
|
||||
|
||||
form.append('image', stream);
|
||||
|
||||
// In Node.js environment you need to set boundary in the header field 'Content-Type' by calling method `getHeaders`
|
||||
const formHeaders = form.getHeaders();
|
||||
|
||||
axios.post('http://example.com', form, {
|
||||
headers: {
|
||||
...formHeaders,
|
||||
},
|
||||
})
|
||||
.then(response => response)
|
||||
.catch(error => error)
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- ```getLengthSync()``` method DOESN'T calculate length for streams, use ```knownLength``` options as workaround.
|
||||
- Starting version `2.x` FormData has dropped support for `node@0.10.x`.
|
||||
- Starting version `3.x` FormData has dropped support for `node@4.x`.
|
||||
|
||||
## License
|
||||
|
||||
Form-Data is released under the [MIT](License) license.
|
||||
61
node_modules/form-data/index.d.ts
generated
vendored
61
node_modules/form-data/index.d.ts
generated
vendored
@ -1,61 +0,0 @@
|
||||
// Definitions by: Carlos Ballesteros Velasco <https://github.com/soywiz>
|
||||
// Leon Yu <https://github.com/leonyu>
|
||||
// BendingBender <https://github.com/BendingBender>
|
||||
// Maple Miao <https://github.com/mapleeit>
|
||||
|
||||
/// <reference types="node" />
|
||||
import * as stream from 'stream';
|
||||
import * as http from 'http';
|
||||
|
||||
export = FormData;
|
||||
|
||||
// Extracted because @types/node doesn't export interfaces.
|
||||
interface ReadableOptions {
|
||||
highWaterMark?: number;
|
||||
encoding?: string;
|
||||
objectMode?: boolean;
|
||||
read?(this: stream.Readable, size: number): void;
|
||||
destroy?(this: stream.Readable, error: Error | null, callback: (error: Error | null) => void): void;
|
||||
autoDestroy?: boolean;
|
||||
}
|
||||
|
||||
interface Options extends ReadableOptions {
|
||||
writable?: boolean;
|
||||
readable?: boolean;
|
||||
dataSize?: number;
|
||||
maxDataSize?: number;
|
||||
pauseStreams?: boolean;
|
||||
}
|
||||
|
||||
declare class FormData extends stream.Readable {
|
||||
constructor(options?: Options);
|
||||
append(key: string, value: any, options?: FormData.AppendOptions | string): void;
|
||||
getHeaders(userHeaders?: FormData.Headers): FormData.Headers;
|
||||
submit(
|
||||
params: string | FormData.SubmitOptions,
|
||||
callback?: (error: Error | null, response: http.IncomingMessage) => void
|
||||
): http.ClientRequest;
|
||||
getBuffer(): Buffer;
|
||||
getBoundary(): string;
|
||||
getLength(callback: (err: Error | null, length: number) => void): void;
|
||||
getLengthSync(): number;
|
||||
hasKnownLength(): boolean;
|
||||
}
|
||||
|
||||
declare namespace FormData {
|
||||
interface Headers {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface AppendOptions {
|
||||
header?: string | Headers;
|
||||
knownLength?: number;
|
||||
filename?: string;
|
||||
filepath?: string;
|
||||
contentType?: string;
|
||||
}
|
||||
|
||||
interface SubmitOptions extends http.RequestOptions {
|
||||
protocol?: 'https:' | 'http:';
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user