aboutsummaryrefslogtreecommitdiff
path: root/node_modules/append-transform
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-05-28 00:38:50 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-05-28 00:40:43 +0200
commit7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027 (patch)
tree6de9a1aebd150a23b7f8c273ec657a5d0a18fe3e /node_modules/append-transform
parent963b7a41feb29cc4be090a2446bdfe0c1f1bcd81 (diff)
downloadwallet-core-7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027.tar.xz
add linting (and some initial fixes)
Diffstat (limited to 'node_modules/append-transform')
-rw-r--r--node_modules/append-transform/index.js88
-rw-r--r--node_modules/append-transform/license21
-rw-r--r--node_modules/append-transform/package.json46
-rw-r--r--node_modules/append-transform/readme.md72
4 files changed, 227 insertions, 0 deletions
diff --git a/node_modules/append-transform/index.js b/node_modules/append-transform/index.js
new file mode 100644
index 000000000..084195403
--- /dev/null
+++ b/node_modules/append-transform/index.js
@@ -0,0 +1,88 @@
+'use strict';
+
+var js = require('default-require-extensions/js');
+
+module.exports = appendTransform;
+
+var count = 0;
+
+function appendTransform(transform, ext, extensions) {
+ // Generate a unique key for this transform
+ var key = __dirname + count; // eslint-disable-line
+ count++;
+ ext = ext || '.js';
+ extensions = extensions || require.extensions;
+
+ var forwardGet;
+ var forwardSet;
+
+ var descriptor = Object.getOwnPropertyDescriptor(extensions, ext) || {value: js, configurable: true};
+
+ if (
+ ((descriptor.get || descriptor.set) && !(descriptor.get && descriptor.set)) ||
+ !descriptor.configurable
+ ) {
+ throw new Error('Somebody did bad things to require.extensions["' + ext + '"]');
+ }
+
+ if (descriptor.get) {
+ // wrap a previous append-transform install and pass through to the getter/setter pair it created
+ forwardGet = function () {
+ return descriptor.get();
+ };
+ forwardSet = function (val) {
+ descriptor.set(val);
+ return forwardGet();
+ };
+ } else {
+ forwardGet = function () {
+ return descriptor.value;
+ };
+ forwardSet = function (val) {
+ descriptor.value = val;
+ return val;
+ };
+ }
+
+ function wrapCustomHook(hook) {
+ return function (module, filename) {
+ // We wrap every added extension, but we only apply the transform to the one on top of the stack
+ if (!module[key]) {
+ module[key] = true;
+
+ var originalCompile = module._compile;
+
+ module._compile = function replacementCompile(code, filename) {
+ module._compile = originalCompile;
+ code = transform(code, filename);
+ module._compile(code, filename);
+ };
+ }
+
+ hook(module, filename);
+ };
+ }
+
+ // wrap the original
+ forwardSet(wrapCustomHook(forwardGet()));
+
+ var hooks = [forwardGet()];
+
+ function setCurrentHook(hook) {
+ var restoreIndex = hooks.indexOf(hook);
+ if (restoreIndex === -1) {
+ hooks.push(forwardSet(wrapCustomHook(hook)));
+ } else {
+ // we have already scene this hook, and it is being reverted (proxyquire, etc) - don't wrap again.
+ hooks.splice(restoreIndex + 1, hooks.length);
+ forwardSet(hook);
+ }
+ }
+
+ Object.defineProperty(extensions, ext, {
+ configurable: true,
+ enumerable: true,
+ get: forwardGet,
+ set: setCurrentHook
+ });
+}
diff --git a/node_modules/append-transform/license b/node_modules/append-transform/license
new file mode 100644
index 000000000..ad5d021ed
--- /dev/null
+++ b/node_modules/append-transform/license
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) James Talmage <james@talmage.io> (github.com/jamestalmage)
+
+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.
diff --git a/node_modules/append-transform/package.json b/node_modules/append-transform/package.json
new file mode 100644
index 000000000..bf3c937d2
--- /dev/null
+++ b/node_modules/append-transform/package.json
@@ -0,0 +1,46 @@
+{
+ "name": "append-transform",
+ "version": "0.4.0",
+ "description": "Install a transform to `require.extensions` that always runs last, even if additional extensions are added later.",
+ "license": "MIT",
+ "repository": "jamestalmage/append-transform",
+ "author": {
+ "name": "James Talmage",
+ "email": "james@talmage.io",
+ "url": "github.com/jamestalmage"
+ },
+ "engines": {
+ "node": ">=0.10.0"
+ },
+ "scripts": {
+ "test": "xo && nyc --reporter=lcov --reporter=text ava"
+ },
+ "files": [
+ "index.js"
+ ],
+ "keywords": [
+ "transform",
+ "require",
+ "append",
+ "last",
+ "coverage",
+ "source-map",
+ "extension",
+ "module"
+ ],
+ "devDependencies": {
+ "ava": "^0.7.0",
+ "coveralls": "^2.11.6",
+ "fake-module-system": "^0.3.0",
+ "nyc": "^4.0.1",
+ "xo": "^0.11.2"
+ },
+ "xo": {
+ "ignores": [
+ "test.js"
+ ]
+ },
+ "dependencies": {
+ "default-require-extensions": "^1.0.0"
+ }
+}
diff --git a/node_modules/append-transform/readme.md b/node_modules/append-transform/readme.md
new file mode 100644
index 000000000..6e2437ecb
--- /dev/null
+++ b/node_modules/append-transform/readme.md
@@ -0,0 +1,72 @@
+# append-transform [![Build Status](https://travis-ci.org/jamestalmage/append-transform.svg?branch=master)](https://travis-ci.org/jamestalmage/append-transform) [![Coverage Status](https://coveralls.io/repos/jamestalmage/append-transform/badge.svg?branch=master&service=github)](https://coveralls.io/github/jamestalmage/append-transform?branch=master)
+
+> Install a transform to `require.extensions` that always runs last, even if additional extensions are added later.
+
+The [typical require extension](https://gist.github.com/jamestalmage/df922691475cff66c7e6) looks something like this:
+
+```js
+ var myTransform = require('my-transform');
+
+ var oldExtension = require.extensions['.js'];
+ require.extensions['.js'] = function (module, filename) {
+ var oldCompile = module._compile;
+ module._compile = function (code, filename) {
+ code = myTransform(code);
+ module._compile = oldCompile;
+ module._compile(code, filename);
+ };
+ oldExtension(module, filename);
+ };
+```
+
+In **almost** all cases, that is sufficient and is the method that should be used (check out [`pirates`](https://www.npmjs.com/package/pirates) for an easy way to do it correctly). In **rare** cases you must ensure your transform remains the last one, even if other transforms are added later. For example, `nyc` uses this module to ensure its transform is applied last so it can capture the final source-map information, and ensure any language extensions it can't understand are already transpiled (ES2015 via `babel` for instance).
+
+*WARNING:* You should be sure you *actually* need this, as it takes control away from the user. Your transform remains the last one applied, even as users continue to add more transforms. This is potentially confusing. Coverage libraries like `nyc` (and `istanbul` on which it relies) have valid reasons for doing this, but you should prefer conventional transform installation via [`pirates`](https://www.npmjs.com/package/pirates).
+
+References:
+ - [Detailed Breakdown of How Require Extensions Work](https://gist.github.com/jamestalmage/df922691475cff66c7e6)
+ - The [test suite](https://github.com/jamestalmage/append-transform/blob/master/test/execution-order.js) provides a good overview of how this library manipulates the order in which transforms are applied.
+
+## Install
+
+```
+$ npm install --save append-transform
+```
+
+
+## Usage
+
+```js
+var appendTransform = require('append-transform');
+var myTransform = require('my-transform');
+
+appendTransform(function (code, filename) {
+ if (myTransform.shouldTransform(filename)) {
+ code = myTransform.transform(code);
+ }
+ return code;
+});
+```
+
+## API
+
+### appendTransform(transformFn, [extension])
+
+#### transformFn
+
+Type: `function(code: string, filename: string)`
+*Required*
+
+A callback that modifies the incoming `code` argument in some way, and returns the transformed result. `filename` is provided to filter which files the transform applies to. If a transform should not manipulate a particular file, just return `code` without modifying it. It is fairly common to avoid transforming files in `node_modules`. In that case you may want to use [`node-modules-regexp`](https://www.npmjs.com/package/node-modules-regexp) to help reliably detect `node_modules` paths and avoid transforming them.
+
+
+#### extension
+
+Type: `string`
+Default: `".js"`
+
+The extension for the types of files this transform is capable of handling.
+
+## License
+
+MIT © [James Talmage](http://github.com/jamestalmage)