This commit is contained in:
eric sciple 2020-01-24 12:21:24 -05:00
parent fc725ba36b
commit 422b9fdb15
7395 changed files with 1786235 additions and 3476 deletions

21
node_modules/pirates/LICENSE generated vendored Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2016-2018 Ari Porad
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.

89
node_modules/pirates/README.md generated vendored Normal file
View file

@ -0,0 +1,89 @@
# Pirates [![Version][version-badge]][npm-link] [![Build Status][build-badge]][build-link] [![Coverage][codecov-badge]][codecov-link] [![Commitizen friendly][cz-badge]][cz-link] [![semantic-release][sr-badge]][sr-link] [![MIT License][license-badge]][license-link]
### Properly hijack require
[version-badge]: https://img.shields.io/npm/v/pirates.svg "npm version"
[downloads-badge]: https://img.shields.io/npm/dm/pirates.svg "npm downloads"
[npm-link]: http://npm.im/pirates "npm"
[codecov-badge]: https://img.shields.io/codecov/c/github/ariporad/pirates/master.svg?style=flat "codecov"
[codecov-link]: https://codecov.io/gh/ariporad/pirates "codecov"
[license-badge]: https://img.shields.io/npm/l/express.svg "MIT License"
[license-link]: http://ariporad.mit-license.org "MIT License"
[build-badge]: https://travis-ci.org/ariporad/pirates.svg "Travis CI Build Status"
[build-link]: https://travis-ci.org/ariporad/pirates "Travis CI Build Status"
[cz-badge]: https://img.shields.io/badge/commitizen-friendly-brightgreen.svg "Commitizen friendly"
[cz-link]: http://commitizen.github.io/cz-cli/ "Commitizen friendly"
[sr-badge]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
[sr-link]: https://github.com/semantic-release/semantic-release
## Why?
Two reasons:
1. Babel and istanbul were breaking each other.
2. Everyone seemed to re-invent the wheel on this, and everyone wanted a solution that was DRY, simple, easy to use,
and made everything Just Work™, while allowing multiple require hooks, in a fashion similar to calling `super`.
For some context, see [the Babel issue thread][] which started this all, then [the nyc issue thread][], where
discussion was moved (as we began to discuss just using the code nyc had developed), and finally to [#1][issue-1]
where discussion was finally moved.
[the Babel issue thread]: https://github.com/babel/babel/pull/3062 "Babel Issue Thread"
[the nyc issue thread]: https://github.com/bcoe/nyc/issues/70 "NYC Issue Thread"
[issue-1]: https://github.com/ariporad/pirates/issues/1 "Issue #1"
## Installation
npm install --save pirates
## Usage
Using pirates is really easy:
```javascript
// my-module/register.js
const addHook = require('pirates').addHook;
// Or if you use ES modules
// import { addHook } from 'pirates';
function matcher(filename) {
// Here, you can inspect the filename to determine if it should be hooked or
// not. Just return a truthy/falsey. Files in node_modules are automatically ignored,
// unless otherwise specified in options (see below).
// TODO: Implement your logic here
return true;
}
const revert = addHook(
(code, filename) => code.replace('@@foo', 'console.log(\'foo\');'),
{ exts: ['.js'], matcher }
);
// And later, if you want to un-hook require, you can just do:
revert();
```
## API
### pirates.addHook(hook, [opts={ [matcher: true], [exts: ['.js']], [ignoreNodeModules: true] }]);
Add a require hook. `hook` must be a function that takes `(code, filename)`, and returns the modified code. `opts` is
an optional options object. Available options are: `matcher`, which is a function that accepts a filename, and
returns a truthy value if the file should be hooked (defaults to a function that always returns true), falsey if
otherwise; `exts`, which is an array of extensions to hook, they should begin with `.` (defaults to `['.js']`);
`ignoreNodeModules`, if true, any file in a `node_modules` folder wont be hooked (the matcher also wont be called),
if false, then the matcher will be called for any files in `node_modules` (defaults to true).
## Projects that use Pirates
See the [wiki page](https://github.com/ariporad/pirates/wiki/Projects-using-Pirates). If you add Pirates to your project,
(And you should! It works best if everyone uses it. Then we can have a happy world full of happy require hooks!), please
add yourself to the wiki.
## License
[MIT](http://ariporad.mit-license.org)

30
node_modules/pirates/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,30 @@
/* (c) 2015 Ari Porad (@ariporad) <http://ariporad.com>. License: ariporad.mit-license.org */
declare type Hook = (code: string, filename: string) => string;
declare type Matcher = (code: string) => boolean;
declare type RevertFunction = () => void;
interface Options {
/** A matcher function, will be called with path to a file. Should return truthy if the file should be hooked, falsy otherwise. */
matcher?: Matcher;
/**
* The extensions to hook. Should start with '.' (ex. ['.js']).
*
* @default ['.js']
*/
exts?: Array<string>;
/**
* Auto-ignore node_modules. Independent of any matcher.
*
* @default true
*/
ignoreNodeModules?: boolean;
}
/**
* Add a require hook.
*
* @param {Hook} hook - The hook. Accepts the code of the module and the filename. Required.
* @param {Options} [opts] - Options
* @returns {RevertFunction} revert - Reverts the hooks.
*/
export declare function addHook(hook: Hook, opts?: Options): RevertFunction;
export {};

118
node_modules/pirates/lib/index.js generated vendored Normal file
View file

@ -0,0 +1,118 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.addHook = addHook;
var _module = _interopRequireDefault(require("module"));
var _path = _interopRequireDefault(require("path"));
var _nodeModulesRegexp = _interopRequireDefault(require("node-modules-regexp"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* (c) 2015 Ari Porad (@ariporad) <http://ariporad.com>. License: ariporad.mit-license.org */
// Guard against poorly mocked module constructors.
const Module = module.constructor.length > 1 ? module.constructor : _module.default;
const HOOK_RETURNED_NOTHING_ERROR_MESSAGE = '[Pirates] A hook returned a non-string, or nothing at all! This is a' + ' violation of intergalactic law!\n' + '--------------------\n' + 'If you have no idea what this means or what Pirates is, let me explain: ' + 'Pirates is a module that makes is easy to implement require hooks. One of' + " the require hooks you're using uses it. One of these require hooks" + " didn't return anything from it's handler, so we don't know what to" + ' do. You might want to debug this.';
function shouldCompile(filename, exts, matcher, ignoreNodeModules) {
if (typeof filename !== 'string') {
return false;
}
if (exts.indexOf(_path.default.extname(filename)) === -1) {
return false;
}
const resolvedFilename = _path.default.resolve(filename);
if (ignoreNodeModules && _nodeModulesRegexp.default.test(resolvedFilename)) {
return false;
}
if (matcher && typeof matcher === 'function') {
return !!matcher(resolvedFilename);
}
return true;
}
/**
* Add a require hook.
*
* @param {Function} hook - The hook. Accepts the code of the module and the filename. Required.
* @param {Object} [opts] - Options
* @param {String[]} [opts.exts=['.js']] - The extensions to hook. Should start with '.' (ex. ['.js']).
* @param {Function(path)} [opts.matcher] - A matcher function, will be called with path to a file. Should return truthy if the file should be hooked, falsy otherwise.
* @param {Boolean} [opts.ignoreNodeModules=true] - Auto-ignore node_modules. Independent of any matcher.
* @returns {Function} revert - Reverts the hooks.
*/
function addHook(hook, opts = {}) {
let reverted = false;
const loaders = [];
const oldLoaders = [];
let exts; // We need to do this to fix #15. Basically, if you use a non-standard extension (ie. .jsx), then
// We modify the .js loader, then use the modified .js loader for as the base for .jsx.
// This prevents that.
const originalJSLoader = Module._extensions['.js'];
const matcher = opts.matcher || null;
const ignoreNodeModules = opts.ignoreNodeModules !== false;
exts = opts.extensions || opts.exts || opts.extension || opts.ext || ['.js'];
if (!Array.isArray(exts)) {
exts = [exts];
}
exts.forEach(ext => {
if (typeof ext !== 'string') {
throw new TypeError(`Invalid Extension: ${ext}`);
}
const oldLoader = Module._extensions[ext] || originalJSLoader;
oldLoaders[ext] = oldLoader;
loaders[ext] = Module._extensions[ext] = function newLoader(mod, filename) {
let compile;
if (!reverted) {
if (shouldCompile(filename, exts, matcher, ignoreNodeModules)) {
compile = mod._compile;
mod._compile = function _compile(code) {
// reset the compile immediately as otherwise we end up having the
// compile function being changed even though this loader might be reverted
// Not reverting it here leads to long useless compile chains when doing
// addHook -> revert -> addHook -> revert -> ...
// The compile function is also anyway created new when the loader is called a second time.
mod._compile = compile;
const newCode = hook(code, filename);
if (typeof newCode !== 'string') {
throw new Error(HOOK_RETURNED_NOTHING_ERROR_MESSAGE);
}
return mod._compile(newCode, filename);
};
}
}
oldLoader(mod, filename);
};
});
return function revert() {
if (reverted) return;
reverted = true;
exts.forEach(ext => {
// if the current loader for the extension is our loader then unregister it and set the oldLoader again
// if not we can not do anything as we cannot remove a loader from within the loader-chain
if (Module._extensions[ext] === loaders[ext]) {
Module._extensions[ext] = oldLoaders[ext];
}
});
};
}

88
node_modules/pirates/package.json generated vendored Normal file
View file

@ -0,0 +1,88 @@
{
"name": "pirates",
"description": "Properly hijack require",
"main": "lib/index.js",
"types": "index.d.ts",
"scripts": {
"clean": "rimraf lib",
"build": "babel src -d lib",
"test": "yarn run lint && cross-env BABEL_ENV=test yarn run build && nyc ava",
"lint": "eslint --report-unused-disable-directives .",
"prepublish": "yarn run clean && yarn run build"
},
"files": [
"lib",
"index.d.ts"
],
"repository": {
"type": "git",
"url": "https://github.com/ariporad/pirates.git"
},
"engines": {
"node": ">= 6"
},
"author": {
"name": "Ari Porad",
"email": "ari@ariporad.com",
"url": "http://ariporad.com"
},
"dependencies": {
"node-modules-regexp": "^1.0.0"
},
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"ava": "^1.2.1",
"babel-core": "^7.0.0-0",
"babel-eslint": "^10.0.1",
"babel-plugin-istanbul": "^5.1.0",
"cross-env": "^5.0.5",
"cz-conventional-changelog": "^2.0.0",
"decache": "^4.1.0",
"eslint": "^5.1.0",
"eslint-config-prettier": "^4.0.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-prettier": "^3.0.1",
"mock-require": "^3.0.2",
"nyc": "^13.2.0",
"prettier": "^1.16.4",
"rewire": "^4.0.1",
"rimraf": "^2.6.1",
"semantic-release": "^15.7.0"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/ariporad/pirates/issues"
},
"homepage": "https://github.com/ariporad/pirates#readme",
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
},
"ava": {
"files": [
"test/*.js"
],
"sources": [
"lib/**/*.js"
]
},
"nyc": {
"include": [
"src/*.js"
],
"reporter": [
"json",
"text"
],
"sourceMap": false,
"instrument": false
},
"version": "4.0.1"
,"_resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.1.tgz"
,"_integrity": "sha512-WuNqLTbMI3tmfef2TKxlQmAiLHKtFhlsCZnPIpuv2Ow0RDVO8lfy1Opf4NUzlMXLjPl+Men7AuVdX6TA+s+uGA=="
,"_from": "pirates@4.0.1"
}