aboutsummaryrefslogtreecommitdiff
path: root/node_modules/loader-utils
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-08-14 05:01:11 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-08-14 05:02:09 +0200
commit363723fc84f7b8477592e0105aeb331ec9a017af (patch)
tree29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/loader-utils
parent5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff)
downloadwallet-core-363723fc84f7b8477592e0105aeb331ec9a017af.tar.xz
node_modules
Diffstat (limited to 'node_modules/loader-utils')
-rw-r--r--node_modules/loader-utils/CHANGELOG.md18
-rw-r--r--node_modules/loader-utils/LICENSE4
-rw-r--r--node_modules/loader-utils/README.md100
-rw-r--r--node_modules/loader-utils/index.js331
-rw-r--r--node_modules/loader-utils/lib/getCurrentRequest.js13
-rw-r--r--node_modules/loader-utils/lib/getHashDigest.js53
-rw-r--r--node_modules/loader-utils/lib/getOptions.js17
-rw-r--r--node_modules/loader-utils/lib/getRemainingRequest.js13
-rw-r--r--node_modules/loader-utils/lib/index.js23
-rw-r--r--node_modules/loader-utils/lib/interpolateName.js95
-rw-r--r--node_modules/loader-utils/lib/isUrlRequest.js14
-rw-r--r--node_modules/loader-utils/lib/parseQuery.js54
-rw-r--r--node_modules/loader-utils/lib/parseString.js19
-rw-r--r--node_modules/loader-utils/lib/stringifyRequest.js40
-rw-r--r--node_modules/loader-utils/lib/urlToRequest.js49
-rw-r--r--node_modules/loader-utils/package.json20
16 files changed, 479 insertions, 384 deletions
diff --git a/node_modules/loader-utils/CHANGELOG.md b/node_modules/loader-utils/CHANGELOG.md
new file mode 100644
index 000000000..30545e99f
--- /dev/null
+++ b/node_modules/loader-utils/CHANGELOG.md
@@ -0,0 +1,18 @@
+# Change Log
+
+All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
+
+<a name="1.1.0"></a>
+# [1.1.0](https://github.com/webpack/loader-utils/compare/v1.0.4...v1.1.0) (2017-03-16)
+
+
+### Features
+
+* **automatic-release:** Generation of automatic release ([7484d13](https://github.com/webpack/loader-utils/commit/7484d13))
+* **parseQuery:** export parseQuery ([ddf64e4](https://github.com/webpack/loader-utils/commit/ddf64e4))
+
+
+
+# Change Log
+
+All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
diff --git a/node_modules/loader-utils/LICENSE b/node_modules/loader-utils/LICENSE
index c4bdf1b81..8c11fc728 100644
--- a/node_modules/loader-utils/LICENSE
+++ b/node_modules/loader-utils/LICENSE
@@ -1,6 +1,4 @@
-(The MIT License)
-
-Copyright (c) 2012 - 2015 Tobias Koppers
+Copyright JS Foundation and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
diff --git a/node_modules/loader-utils/README.md b/node_modules/loader-utils/README.md
index 305fa9029..84bf788cc 100644
--- a/node_modules/loader-utils/README.md
+++ b/node_modules/loader-utils/README.md
@@ -2,57 +2,69 @@
## Methods
-### `getLoaderConfig`
+### `getOptions`
-Recommended way to retrieve the loader config:
+Recommended way to retrieve the options of a loader invocation:
```javascript
// inside your loader
-config = loaderUtils.getLoaderConfig(this, "myLoader");
+const options = loaderUtils.getOptions(this);
```
-Tries to read the loader config from the `webpack.config.js` under the given property name (`"myLoader"` in this case) and merges the result with the loader query. For example, if your `webpack.config.js` had this property...
+1. If `this.query` is a string:
+ - Tries to parse the query string and returns a new object
+ - Throws if it's not a valid query string
+2. If `this.query` is object-like, it just returns `this.query`
+3. In any other case, it just returns `null`
+
+**Please note:** The returned `options` object is *read-only*. It may be re-used across multiple invocations.
+If you pass it on to another library, make sure to make a *deep copy* of it:
```javascript
-cheesecakeLoader: {
- type: "delicious",
- slices: 4
-}
+const options = Object.assign(
+ {},
+ loaderUtils.getOptions(this), // it is safe to pass null to Object.assign()
+ defaultOptions
+);
+// don't forget nested objects or arrays
+options.obj = Object.assign({}, options.obj);
+options.arr = options.arr.slice();
+someLibrary(options);
```
-...and your loader was called with `?slices=8`, `getLoaderConfig(this, "cheesecakeLoader")` would return
+[clone-deep](https://www.npmjs.com/package/clone-deep) is a good library to make a deep copy of the options.
-```javascript
-{
- type: "delicious",
- slices: 8
-}
-```
+#### Options as query strings
-It is recommended that you use the camelCased loader name as your default config property name.
+If the loader options have been passed as loader query string (`loader?some&params`), the string is parsed by using [`parseQuery`](#parsequery).
### `parseQuery`
+Parses a passed string (e.g. `loaderContext.resourceQuery`) as a query string, and returns an object.
+
``` javascript
-var query = loaderUtils.parseQuery(this.query);
-assert(typeof query == "object");
-if(query.flag)
- // ...
+const params = loaderUtils.parseQuery(this.resourceQuery); // resource: `file?param1=foo`
+if (params.param1 === "foo") {
+ // do something
+}
```
+The string is parsed like this:
+
``` text
-null -> {}
-? -> {}
-?flag -> { flag: true }
-?+flag -> { flag: true }
-?-flag -> { flag: false }
-?xyz=test -> { xyz: "test" }
-?xyz[]=a -> { xyz: ["a"] }
-?flag1&flag2 -> { flag1: true, flag2: true }
-?+flag1,-flag2 -> { flag1: true, flag2: false }
-?xyz[]=a,xyz[]=b -> { xyz: ["a", "b"] }
-?a%2C%26b=c%2C%26d -> { "a,&b": "c,&d" }
-?{json:5,data:{a:1}} -> { json: 5, data: { a: 1 } }
+ -> Error
+? -> {}
+?flag -> { flag: true }
+?+flag -> { flag: true }
+?-flag -> { flag: false }
+?xyz=test -> { xyz: "test" }
+?xyz=1 -> { xyz: "1" } // numbers are NOT parsed
+?xyz[]=a -> { xyz: ["a"] }
+?flag1&flag2 -> { flag1: true, flag2: true }
+?+flag1,-flag2 -> { flag1: true, flag2: false }
+?xyz[]=a,xyz[]=b -> { xyz: ["a", "b"] }
+?a%2C%26b=c%2C%26d -> { "a,&b": "c,&d" }
+?{data:{a:1},isJSON5:true} -> { data: { a: 1 }, isJSON5: true }
```
### `stringifyRequest`
@@ -104,8 +116,8 @@ loaderUtils.stringifyRequest(this, "\\\\network-drive\\test.js");
Converts some resource URL to a webpack module request.
```javascript
-var url = "path/to/module.js";
-var request = loaderUtils.urlToRequest(url); // "./path/to/module.js"
+const url = "path/to/module.js";
+const request = loaderUtils.urlToRequest(url); // "./path/to/module.js"
```
#### Module URLs
@@ -113,8 +125,8 @@ var request = loaderUtils.urlToRequest(url); // "./path/to/module.js"
Any URL containing a `~` will be interpreted as a module request. Anything after the `~` will be considered the request path.
```javascript
-var url = "~path/to/module.js";
-var request = loaderUtils.urlToRequest(url); // "path/to/module.js"
+const url = "~path/to/module.js";
+const request = loaderUtils.urlToRequest(url); // "path/to/module.js"
```
#### Root-relative URLs
@@ -122,17 +134,17 @@ var request = loaderUtils.urlToRequest(url); // "path/to/module.js"
URLs that are root-relative (start with `/`) can be resolved relative to some arbitrary path by using the `root` parameter:
```javascript
-var url = "/path/to/module.js";
-var root = "./root";
-var request = loaderUtils.urlToRequest(url, root); // "./root/path/to/module.js"
+const url = "/path/to/module.js";
+const root = "./root";
+const request = loaderUtils.urlToRequest(url, root); // "./root/path/to/module.js"
```
To convert a root-relative URL into a module URL, specify a `root` value that starts with `~`:
```javascript
-var url = "/path/to/module.js";
-var root = "~";
-var request = loaderUtils.urlToRequest(url, root); // "path/to/module.js"
+const url = "/path/to/module.js";
+const root = "~";
+const request = loaderUtils.urlToRequest(url, root); // "path/to/module.js"
```
### `interpolateName`
@@ -141,7 +153,7 @@ Interpolates a filename template using multiple placeholders and/or a regular ex
The template and regular expression are set as query params called `name` and `regExp` on the current loader's context.
```javascript
-var interpolatedName = loaderUtils.interpolateName(loaderContext, name, options);
+const interpolatedName = loaderUtils.interpolateName(loaderContext, name, options);
```
The following tokens are replaced in the `name` parameter:
@@ -204,7 +216,7 @@ loaderUtils.interpolateName(loaderContext, "script-[1].[ext]", { regExp: "page-(
### `getHashDigest`
``` javascript
-var digestString = loaderUtils.getHashDigest(buffer, hashType, digestType, maxLength);
+const digestString = loaderUtils.getHashDigest(buffer, hashType, digestType, maxLength);
```
* `buffer` the content that should be hashed
diff --git a/node_modules/loader-utils/index.js b/node_modules/loader-utils/index.js
deleted file mode 100644
index 49e1d18f7..000000000
--- a/node_modules/loader-utils/index.js
+++ /dev/null
@@ -1,331 +0,0 @@
-var JSON5 = require("json5");
-var path = require("path");
-var util = require("util");
-var os = require("os");
-var assign = require("object-assign");
-var emojiRegex = /[\uD800-\uDFFF]./;
-var emojiList = require("emojis-list").filter(function(emoji) {
- return emojiRegex.test(emoji)
-});
-var matchAbsolutePath = /^\/|^[A-Z]:[/\\]|^\\\\/i; // node 0.10 does not support path.isAbsolute()
-var matchAbsoluteWin32Path = /^[A-Z]:[/\\]|^\\\\/i;
-var matchRelativePath = /^\.\.?[/\\]/;
-
-var baseEncodeTables = {
- 26: "abcdefghijklmnopqrstuvwxyz",
- 32: "123456789abcdefghjkmnpqrstuvwxyz", // no 0lio
- 36: "0123456789abcdefghijklmnopqrstuvwxyz",
- 49: "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ", // no lIO
- 52: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
- 58: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ", // no 0lIO
- 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
- 64: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_"
-};
-var emojiCache = {};
-var parseQueryDeprecationWarning = util.deprecate(function() {},
- "loaderUtils.parseQuery() received a non-string value which can be problematic, " +
- "see https://github.com/webpack/loader-utils/issues/56" + os.EOL +
- "parseQuery() will be replaced with getOptions() in the next major version of loader-utils."
-);
-
-function encodeStringToEmoji(content, length) {
- if (emojiCache[content]) return emojiCache[content];
- length = length || 1;
- var emojis = [];
- do {
- var index = Math.floor(Math.random() * emojiList.length);
- emojis.push(emojiList[index]);
- emojiList.splice(index, 1);
- } while (--length > 0);
- var emojiEncoding = emojis.join('');
- emojiCache[content] = emojiEncoding;
- return emojiEncoding;
-}
-
-function encodeBufferToBase(buffer, base) {
- var encodeTable = baseEncodeTables[base];
- if (!encodeTable) throw new Error("Unknown encoding base" + base);
-
- var readLength = buffer.length;
-
- var Big = require('big.js');
- Big.RM = Big.DP = 0;
- var b = new Big(0);
- for (var i = readLength - 1; i >= 0; i--) {
- b = b.times(256).plus(buffer[i]);
- }
-
- var output = "";
- while (b.gt(0)) {
- output = encodeTable[b.mod(base)] + output;
- b = b.div(base);
- }
-
- Big.DP = 20;
- Big.RM = 1;
-
- return output;
-}
-
-exports.parseQuery = function parseQuery(query) {
- var specialValues = {
- 'null': null,
- 'true': true,
- 'false': false
- };
- if(!query) return {};
- if(typeof query !== "string") {
- parseQueryDeprecationWarning();
- return query;
- }
- if(query.substr(0, 1) !== "?")
- throw new Error("a valid query string passed to parseQuery should begin with '?'");
- query = query.substr(1);
- var queryLength = query.length;
- if(query.substr(0, 1) === "{" && query.substr(-1) === "}") {
- return JSON5.parse(query);
- }
- var queryArgs = query.split(/[,\&]/g);
- var result = {};
- queryArgs.forEach(function(arg) {
- var idx = arg.indexOf("=");
- if(idx >= 0) {
- var name = arg.substr(0, idx);
- var value = decodeURIComponent(arg.substr(idx+1));
- if (specialValues.hasOwnProperty(value)) {
- value = specialValues[value];
- }
- if(name.substr(-2) === "[]") {
- name = decodeURIComponent(name.substr(0, name.length-2));
- if(!Array.isArray(result[name]))
- result[name] = [];
- result[name].push(value);
- } else {
- name = decodeURIComponent(name);
- result[name] = value;
- }
- } else {
- if(arg.substr(0, 1) === "-") {
- result[decodeURIComponent(arg.substr(1))] = false;
- } else if(arg.substr(0, 1) === "+") {
- result[decodeURIComponent(arg.substr(1))] = true;
- } else {
- result[decodeURIComponent(arg)] = true;
- }
- }
- });
- return result;
-};
-
-exports.getLoaderConfig = function(loaderContext, defaultConfigKey) {
- var query = exports.parseQuery(loaderContext.query);
- var configKey = query.config || defaultConfigKey;
- if (configKey) {
- var config = loaderContext.options[configKey] || {};
- delete query.config;
- return assign({}, config, query);
- }
-
- return query;
-};
-
-exports.stringifyRequest = function(loaderContext, request) {
- var splitted = request.split("!");
- var context = loaderContext.context || (loaderContext.options && loaderContext.options.context);
- return JSON.stringify(splitted.map(function(part) {
- // First, separate singlePath from query, because the query might contain paths again
- var splittedPart = part.match(/^(.*?)(\?.*)/);
- var singlePath = splittedPart ? splittedPart[1] : part;
- var query = splittedPart ? splittedPart[2] : "";
- if(matchAbsolutePath.test(singlePath) && context) {
- singlePath = path.relative(context, singlePath);
- if(matchAbsolutePath.test(singlePath)) {
- // If singlePath still matches an absolute path, singlePath was on a different drive than context.
- // In this case, we leave the path platform-specific without replacing any separators.
- // @see https://github.com/webpack/loader-utils/pull/14
- return singlePath + query;
- }
- if(matchRelativePath.test(singlePath) === false) {
- // Ensure that the relative path starts at least with ./ otherwise it would be a request into the modules directory (like node_modules).
- singlePath = "./" + singlePath;
- }
- }
- return singlePath.replace(/\\/g, "/") + query;
- }).join("!"));
-};
-
-function dotRequest(obj) {
- return obj.request;
-}
-
-exports.getRemainingRequest = function(loaderContext) {
- if(loaderContext.remainingRequest)
- return loaderContext.remainingRequest;
- var request = loaderContext.loaders.slice(loaderContext.loaderIndex+1).map(dotRequest).concat([loaderContext.resource]);
- return request.join("!");
-};
-
-exports.getCurrentRequest = function(loaderContext) {
- if(loaderContext.currentRequest)
- return loaderContext.currentRequest;
- var request = loaderContext.loaders.slice(loaderContext.loaderIndex).map(dotRequest).concat([loaderContext.resource]);
- return request.join("!");
-};
-
-exports.isUrlRequest = function(url, root) {
- // An URL is not an request if
- // 1. it's a Data Url
- // 2. it's an absolute url or and protocol-relative
- // 3. it's some kind of url for a template
- if(/^data:|^chrome-extension:|^(https?:)?\/\/|^[\{\}\[\]#*;,'§\$%&\(=?`´\^°<>]/.test(url)) return false;
- // 4. It's also not an request if root isn't set and it's a root-relative url
- if((root === undefined || root === false) && /^\//.test(url)) return false;
- return true;
-};
-
-exports.urlToRequest = function(url, root) {
- var moduleRequestRegex = /^[^?]*~/;
- var request;
-
- if(matchAbsoluteWin32Path.test(url)) {
- // absolute windows path, keep it
- request = url;
- } else if(root !== undefined && root !== false && /^\//.test(url)) {
- // if root is set and the url is root-relative
- switch(typeof root) {
- // 1. root is a string: root is prefixed to the url
- case "string":
- // special case: `~` roots convert to module request
- if (moduleRequestRegex.test(root)) {
- request = root.replace(/([^~\/])$/, "$1/") + url.slice(1);
- } else {
- request = root + url;
- }
- break;
- // 2. root is `true`: absolute paths are allowed
- // *nix only, windows-style absolute paths are always allowed as they doesn't start with a `/`
- case "boolean":
- request = url;
- break;
- default:
- throw new Error("Unexpected parameters to loader-utils 'urlToRequest': url = " + url + ", root = " + root + ".");
- }
- } else if(/^\.\.?\//.test(url)) {
- // A relative url stays
- request = url;
- } else {
- // every other url is threaded like a relative url
- request = "./" + url;
- }
-
- // A `~` makes the url an module
- if (moduleRequestRegex.test(request)) {
- request = request.replace(moduleRequestRegex, "");
- }
-
- return request;
-};
-
-exports.parseString = function parseString(str) {
- try {
- if(str[0] === '"') return JSON.parse(str);
- if(str[0] === "'" && str.substr(str.length - 1) === "'") {
- return parseString(str.replace(/\\.|"/g, function(x) {
- if(x === '"') return '\\"';
- return x;
- }).replace(/^'|'$/g, '"'));
- }
- return JSON.parse('"' + str + '"');
- } catch(e) {
- return str;
- }
-};
-
-exports.getHashDigest = function getHashDigest(buffer, hashType, digestType, maxLength) {
- hashType = hashType || "md5";
- maxLength = maxLength || 9999;
- var hash = require("crypto").createHash(hashType);
- hash.update(buffer);
- if (digestType === "base26" || digestType === "base32" || digestType === "base36" ||
- digestType === "base49" || digestType === "base52" || digestType === "base58" ||
- digestType === "base62" || digestType === "base64") {
- return encodeBufferToBase(hash.digest(), digestType.substr(4)).substr(0, maxLength);
- } else {
- return hash.digest(digestType || "hex").substr(0, maxLength);
- }
-};
-
-exports.interpolateName = function interpolateName(loaderContext, name, options) {
- var filename;
- if (typeof name === "function") {
- filename = name(loaderContext.resourcePath);
- } else {
- filename = name || "[hash].[ext]";
- }
- var context = options.context;
- var content = options.content;
- var regExp = options.regExp;
- var ext = "bin";
- var basename = "file";
- var directory = "";
- var folder = "";
- if(loaderContext.resourcePath) {
- var resourcePath = loaderContext.resourcePath;
- var idx = resourcePath.lastIndexOf(".");
- var i = resourcePath.lastIndexOf("\\");
- var j = resourcePath.lastIndexOf("/");
- var p = i < 0 ? j : j < 0 ? i : i < j ? i : j;
- if(idx >= 0) {
- ext = resourcePath.substr(idx+1);
- resourcePath = resourcePath.substr(0, idx);
- }
- if(p >= 0) {
- basename = resourcePath.substr(p+1);
- resourcePath = resourcePath.substr(0, p+1);
- }
- if (typeof context !== 'undefined') {
- directory = path.relative(context, resourcePath + "_").replace(/\\/g, "/").replace(/\.\.(\/)?/g, "_$1");
- directory = directory.substr(0, directory.length-1);
- }
- else {
- directory = resourcePath.replace(/\\/g, "/").replace(/\.\.(\/)?/g, "_$1");
- }
- if (directory.length === 1) {
- directory = "";
- } else if (directory.length > 1) {
- folder = path.basename(directory);
- }
- }
- var url = filename;
- if(content) {
- // Match hash template
- url = url.replace(/\[(?:(\w+):)?hash(?::([a-z]+\d*))?(?::(\d+))?\]/ig, function() {
- return exports.getHashDigest(content, arguments[1], arguments[2], parseInt(arguments[3], 10));
- }).replace(/\[emoji(?::(\d+))?\]/ig, function() {
- return encodeStringToEmoji(content, arguments[1]);
- });
- }
- url = url.replace(/\[ext\]/ig, function() {
- return ext;
- }).replace(/\[name\]/ig, function() {
- return basename;
- }).replace(/\[path\]/ig, function() {
- return directory;
- }).replace(/\[folder\]/ig, function() {
- return folder;
- });
- if(regExp && loaderContext.resourcePath) {
- var re = new RegExp(regExp);
- var match = loaderContext.resourcePath.match(re);
- if(match) {
- for (var i = 0; i < match.length; i++) {
- var re = new RegExp("\\[" + i + "\\]", "ig");
- url = url.replace(re, match[i]);
- }
- }
- }
- if(typeof loaderContext.options === "object" && typeof loaderContext.options.customInterpolateName === "function") {
- url = loaderContext.options.customInterpolateName.call(loaderContext, url, name, options);
- }
- return url;
-};
diff --git a/node_modules/loader-utils/lib/getCurrentRequest.js b/node_modules/loader-utils/lib/getCurrentRequest.js
new file mode 100644
index 000000000..f05e112ac
--- /dev/null
+++ b/node_modules/loader-utils/lib/getCurrentRequest.js
@@ -0,0 +1,13 @@
+"use strict";
+
+function getCurrentRequest(loaderContext) {
+ if(loaderContext.currentRequest)
+ return loaderContext.currentRequest;
+ const request = loaderContext.loaders
+ .slice(loaderContext.loaderIndex)
+ .map(obj => obj.request)
+ .concat([loaderContext.resource]);
+ return request.join("!");
+}
+
+module.exports = getCurrentRequest;
diff --git a/node_modules/loader-utils/lib/getHashDigest.js b/node_modules/loader-utils/lib/getHashDigest.js
new file mode 100644
index 000000000..6f4a427e5
--- /dev/null
+++ b/node_modules/loader-utils/lib/getHashDigest.js
@@ -0,0 +1,53 @@
+"use strict";
+
+const baseEncodeTables = {
+ 26: "abcdefghijklmnopqrstuvwxyz",
+ 32: "123456789abcdefghjkmnpqrstuvwxyz", // no 0lio
+ 36: "0123456789abcdefghijklmnopqrstuvwxyz",
+ 49: "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ", // no lIO
+ 52: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
+ 58: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ", // no 0lIO
+ 62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
+ 64: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_"
+};
+
+function encodeBufferToBase(buffer, base) {
+ const encodeTable = baseEncodeTables[base];
+ if(!encodeTable) throw new Error("Unknown encoding base" + base);
+
+ const readLength = buffer.length;
+
+ const Big = require("big.js");
+ Big.RM = Big.DP = 0;
+ let b = new Big(0);
+ for(let i = readLength - 1; i >= 0; i--) {
+ b = b.times(256).plus(buffer[i]);
+ }
+
+ let output = "";
+ while(b.gt(0)) {
+ output = encodeTable[b.mod(base)] + output;
+ b = b.div(base);
+ }
+
+ Big.DP = 20;
+ Big.RM = 1;
+
+ return output;
+}
+
+function getHashDigest(buffer, hashType, digestType, maxLength) {
+ hashType = hashType || "md5";
+ maxLength = maxLength || 9999;
+ const hash = require("crypto").createHash(hashType);
+ hash.update(buffer);
+ if(digestType === "base26" || digestType === "base32" || digestType === "base36" ||
+ digestType === "base49" || digestType === "base52" || digestType === "base58" ||
+ digestType === "base62" || digestType === "base64") {
+ return encodeBufferToBase(hash.digest(), digestType.substr(4)).substr(0, maxLength);
+ } else {
+ return hash.digest(digestType || "hex").substr(0, maxLength);
+ }
+}
+
+module.exports = getHashDigest;
diff --git a/node_modules/loader-utils/lib/getOptions.js b/node_modules/loader-utils/lib/getOptions.js
new file mode 100644
index 000000000..24bcae47b
--- /dev/null
+++ b/node_modules/loader-utils/lib/getOptions.js
@@ -0,0 +1,17 @@
+"use strict";
+
+const parseQuery = require("./parseQuery");
+
+function getOptions(loaderContext) {
+ const query = loaderContext.query;
+ if(typeof query === "string" && query !== "") {
+ return parseQuery(loaderContext.query);
+ }
+ if(!query || typeof query !== "object") {
+ // Not object-like queries are not supported.
+ return null;
+ }
+ return query;
+}
+
+module.exports = getOptions;
diff --git a/node_modules/loader-utils/lib/getRemainingRequest.js b/node_modules/loader-utils/lib/getRemainingRequest.js
new file mode 100644
index 000000000..f48c71a49
--- /dev/null
+++ b/node_modules/loader-utils/lib/getRemainingRequest.js
@@ -0,0 +1,13 @@
+"use strict";
+
+function getRemainingRequest(loaderContext) {
+ if(loaderContext.remainingRequest)
+ return loaderContext.remainingRequest;
+ const request = loaderContext.loaders
+ .slice(loaderContext.loaderIndex + 1)
+ .map(obj => obj.request)
+ .concat([loaderContext.resource]);
+ return request.join("!");
+}
+
+module.exports = getRemainingRequest;
diff --git a/node_modules/loader-utils/lib/index.js b/node_modules/loader-utils/lib/index.js
new file mode 100644
index 000000000..a5950922f
--- /dev/null
+++ b/node_modules/loader-utils/lib/index.js
@@ -0,0 +1,23 @@
+"use strict";
+
+const getOptions = require("./getOptions");
+const parseQuery = require("./parseQuery");
+const stringifyRequest = require("./stringifyRequest");
+const getRemainingRequest = require("./getRemainingRequest");
+const getCurrentRequest = require("./getCurrentRequest");
+const isUrlRequest = require("./isUrlRequest");
+const urlToRequest = require("./urlToRequest");
+const parseString = require("./parseString");
+const getHashDigest = require("./getHashDigest");
+const interpolateName = require("./interpolateName");
+
+exports.getOptions = getOptions;
+exports.parseQuery = parseQuery;
+exports.stringifyRequest = stringifyRequest;
+exports.getRemainingRequest = getRemainingRequest;
+exports.getCurrentRequest = getCurrentRequest;
+exports.isUrlRequest = isUrlRequest;
+exports.urlToRequest = urlToRequest;
+exports.parseString = parseString;
+exports.getHashDigest = getHashDigest;
+exports.interpolateName = interpolateName;
diff --git a/node_modules/loader-utils/lib/interpolateName.js b/node_modules/loader-utils/lib/interpolateName.js
new file mode 100644
index 000000000..5e5b65326
--- /dev/null
+++ b/node_modules/loader-utils/lib/interpolateName.js
@@ -0,0 +1,95 @@
+"use strict";
+
+const path = require("path");
+const emojisList = require("emojis-list");
+const getHashDigest = require("./getHashDigest");
+
+const emojiRegex = /[\uD800-\uDFFF]./;
+const emojiList = emojisList.filter(emoji => emojiRegex.test(emoji));
+const emojiCache = {};
+
+function encodeStringToEmoji(content, length) {
+ if(emojiCache[content]) return emojiCache[content];
+ length = length || 1;
+ const emojis = [];
+ do {
+ const index = Math.floor(Math.random() * emojiList.length);
+ emojis.push(emojiList[index]);
+ emojiList.splice(index, 1);
+ } while(--length > 0);
+ const emojiEncoding = emojis.join("");
+ emojiCache[content] = emojiEncoding;
+ return emojiEncoding;
+}
+
+function interpolateName(loaderContext, name, options) {
+ let filename;
+ if(typeof name === "function") {
+ filename = name(loaderContext.resourcePath);
+ } else {
+ filename = name || "[hash].[ext]";
+ }
+ const context = options.context;
+ const content = options.content;
+ const regExp = options.regExp;
+ let ext = "bin";
+ let basename = "file";
+ let directory = "";
+ let folder = "";
+ if(loaderContext.resourcePath) {
+ const parsed = path.parse(loaderContext.resourcePath);
+ let resourcePath = loaderContext.resourcePath;
+
+ if(parsed.ext) {
+ ext = parsed.ext.substr(1);
+ }
+ if(parsed.dir) {
+ basename = parsed.name;
+ resourcePath = parsed.dir + path.sep;
+ }
+ if(typeof context !== "undefined") {
+ directory = path.relative(context, resourcePath + "_").replace(/\\/g, "/").replace(/\.\.(\/)?/g, "_$1");
+ directory = directory.substr(0, directory.length - 1);
+ } else {
+ directory = resourcePath.replace(/\\/g, "/").replace(/\.\.(\/)?/g, "_$1");
+ }
+ if(directory.length === 1) {
+ directory = "";
+ } else if(directory.length > 1) {
+ folder = path.basename(directory);
+ }
+ }
+ let url = filename;
+ if(content) {
+ // Match hash template
+ url = url
+ .replace(
+ /\[(?:(\w+):)?hash(?::([a-z]+\d*))?(?::(\d+))?\]/ig,
+ (all, hashType, digestType, maxLength) => getHashDigest(content, hashType, digestType, parseInt(maxLength, 10))
+ )
+ .replace(
+ /\[emoji(?::(\d+))?\]/ig,
+ (all, length) => encodeStringToEmoji(content, length)
+ );
+ }
+ url = url
+ .replace(/\[ext\]/ig, () => ext)
+ .replace(/\[name\]/ig, () => basename)
+ .replace(/\[path\]/ig, () => directory)
+ .replace(/\[folder\]/ig, () => folder);
+ if(regExp && loaderContext.resourcePath) {
+ const match = loaderContext.resourcePath.match(new RegExp(regExp));
+ match && match.forEach((matched, i) => {
+ url = url.replace(
+ new RegExp("\\[" + i + "\\]", "ig"),
+ matched
+ );
+ });
+ }
+ if(typeof loaderContext.options === "object" && typeof loaderContext.options.customInterpolateName === "function") {
+ url = loaderContext.options.customInterpolateName.call(loaderContext, url, name, options);
+ }
+ return url;
+}
+
+module.exports = interpolateName;
diff --git a/node_modules/loader-utils/lib/isUrlRequest.js b/node_modules/loader-utils/lib/isUrlRequest.js
new file mode 100644
index 000000000..bee968ee8
--- /dev/null
+++ b/node_modules/loader-utils/lib/isUrlRequest.js
@@ -0,0 +1,14 @@
+"use strict";
+
+function isUrlRequest(url, root) {
+ // An URL is not an request if
+ // 1. it's a Data Url
+ // 2. it's an absolute url or and protocol-relative
+ // 3. it's some kind of url for a template
+ if(/^data:|^chrome-extension:|^(https?:)?\/\/|^[\{\}\[\]#*;,'§\$%&\(=?`´\^°<>]/.test(url)) return false;
+ // 4. It's also not an request if root isn't set and it's a root-relative url
+ if((root === undefined || root === false) && /^\//.test(url)) return false;
+ return true;
+}
+
+module.exports = isUrlRequest;
diff --git a/node_modules/loader-utils/lib/parseQuery.js b/node_modules/loader-utils/lib/parseQuery.js
new file mode 100644
index 000000000..5748cded8
--- /dev/null
+++ b/node_modules/loader-utils/lib/parseQuery.js
@@ -0,0 +1,54 @@
+"use strict";
+
+const JSON5 = require("json5");
+
+const specialValues = {
+ "null": null,
+ "true": true,
+ "false": false
+};
+
+function parseQuery(query) {
+ if(query.substr(0, 1) !== "?") {
+ throw new Error("A valid query string passed to parseQuery should begin with '?'");
+ }
+ query = query.substr(1);
+ if(!query) {
+ return {};
+ }
+ if(query.substr(0, 1) === "{" && query.substr(-1) === "}") {
+ return JSON5.parse(query);
+ }
+ const queryArgs = query.split(/[,&]/g);
+ const result = {};
+ queryArgs.forEach(arg => {
+ const idx = arg.indexOf("=");
+ if(idx >= 0) {
+ let name = arg.substr(0, idx);
+ let value = decodeURIComponent(arg.substr(idx + 1));
+ if(specialValues.hasOwnProperty(value)) {
+ value = specialValues[value];
+ }
+ if(name.substr(-2) === "[]") {
+ name = decodeURIComponent(name.substr(0, name.length - 2));
+ if(!Array.isArray(result[name]))
+ result[name] = [];
+ result[name].push(value);
+ } else {
+ name = decodeURIComponent(name);
+ result[name] = value;
+ }
+ } else {
+ if(arg.substr(0, 1) === "-") {
+ result[decodeURIComponent(arg.substr(1))] = false;
+ } else if(arg.substr(0, 1) === "+") {
+ result[decodeURIComponent(arg.substr(1))] = true;
+ } else {
+ result[decodeURIComponent(arg)] = true;
+ }
+ }
+ });
+ return result;
+}
+
+module.exports = parseQuery;
diff --git a/node_modules/loader-utils/lib/parseString.js b/node_modules/loader-utils/lib/parseString.js
new file mode 100644
index 000000000..ca69dfd06
--- /dev/null
+++ b/node_modules/loader-utils/lib/parseString.js
@@ -0,0 +1,19 @@
+"use strict";
+
+function parseString(str) {
+ try {
+ if(str[0] === "\"") return JSON.parse(str);
+ if(str[0] === "'" && str.substr(str.length - 1) === "'") {
+ return parseString(
+ str
+ .replace(/\\.|"/g, x => x === "\"" ? "\\\"" : x)
+ .replace(/^'|'$/g, "\"")
+ );
+ }
+ return JSON.parse("\"" + str + "\"");
+ } catch(e) {
+ return str;
+ }
+}
+
+module.exports = parseString;
diff --git a/node_modules/loader-utils/lib/stringifyRequest.js b/node_modules/loader-utils/lib/stringifyRequest.js
new file mode 100644
index 000000000..46e9ae2e9
--- /dev/null
+++ b/node_modules/loader-utils/lib/stringifyRequest.js
@@ -0,0 +1,40 @@
+"use strict";
+
+const path = require("path");
+
+const matchRelativePath = /^\.\.?[/\\]/;
+
+function isAbsolutePath(str) {
+ return path.posix.isAbsolute(str) || path.win32.isAbsolute(str);
+}
+
+function isRelativePath(str) {
+ return matchRelativePath.test(str);
+}
+
+function stringifyRequest(loaderContext, request) {
+ const splitted = request.split("!");
+ const context = loaderContext.context || (loaderContext.options && loaderContext.options.context);
+ return JSON.stringify(splitted.map(part => {
+ // First, separate singlePath from query, because the query might contain paths again
+ const splittedPart = part.match(/^(.*?)(\?.*)/);
+ let singlePath = splittedPart ? splittedPart[1] : part;
+ const query = splittedPart ? splittedPart[2] : "";
+ if(isAbsolutePath(singlePath) && context) {
+ singlePath = path.relative(context, singlePath);
+ if(isAbsolutePath(singlePath)) {
+ // If singlePath still matches an absolute path, singlePath was on a different drive than context.
+ // In this case, we leave the path platform-specific without replacing any separators.
+ // @see https://github.com/webpack/loader-utils/pull/14
+ return singlePath + query;
+ }
+ if(isRelativePath(singlePath) === false) {
+ // Ensure that the relative path starts at least with ./ otherwise it would be a request into the modules directory (like node_modules).
+ singlePath = "./" + singlePath;
+ }
+ }
+ return singlePath.replace(/\\/g, "/") + query;
+ }).join("!"));
+}
+
+module.exports = stringifyRequest;
diff --git a/node_modules/loader-utils/lib/urlToRequest.js b/node_modules/loader-utils/lib/urlToRequest.js
new file mode 100644
index 000000000..06c3cd046
--- /dev/null
+++ b/node_modules/loader-utils/lib/urlToRequest.js
@@ -0,0 +1,49 @@
+"use strict";
+
+// we can't use path.win32.isAbsolute because it also matches paths starting with a forward slash
+const matchNativeWin32Path = /^[A-Z]:[/\\]|^\\\\/i;
+
+function urlToRequest(url, root) {
+ const moduleRequestRegex = /^[^?]*~/;
+ let request;
+
+ if(matchNativeWin32Path.test(url)) {
+ // absolute windows path, keep it
+ request = url;
+ } else if(root !== undefined && root !== false && /^\//.test(url)) {
+ // if root is set and the url is root-relative
+ switch(typeof root) {
+ // 1. root is a string: root is prefixed to the url
+ case "string":
+ // special case: `~` roots convert to module request
+ if(moduleRequestRegex.test(root)) {
+ request = root.replace(/([^~\/])$/, "$1/") + url.slice(1);
+ } else {
+ request = root + url;
+ }
+ break;
+ // 2. root is `true`: absolute paths are allowed
+ // *nix only, windows-style absolute paths are always allowed as they doesn't start with a `/`
+ case "boolean":
+ request = url;
+ break;
+ default:
+ throw new Error("Unexpected parameters to loader-utils 'urlToRequest': url = " + url + ", root = " + root + ".");
+ }
+ } else if(/^\.\.?\//.test(url)) {
+ // A relative url stays
+ request = url;
+ } else {
+ // every other url is threaded like a relative url
+ request = "./" + url;
+ }
+
+ // A `~` makes the url an module
+ if(moduleRequestRegex.test(request)) {
+ request = request.replace(moduleRequestRegex, "");
+ }
+
+ return request;
+}
+
+module.exports = urlToRequest;
diff --git a/node_modules/loader-utils/package.json b/node_modules/loader-utils/package.json
index 699cb0282..a547e2347 100644
--- a/node_modules/loader-utils/package.json
+++ b/node_modules/loader-utils/package.json
@@ -1,31 +1,39 @@
{
"name": "loader-utils",
- "version": "0.2.17",
+ "version": "1.1.0",
"author": "Tobias Koppers @sokra",
"description": "utils for webpack loaders",
"dependencies": {
"big.js": "^3.1.3",
"emojis-list": "^2.0.0",
- "json5": "^0.5.0",
- "object-assign": "^4.0.1"
+ "json5": "^0.5.0"
},
"scripts": {
"test": "mocha",
+ "posttest": "npm run lint",
+ "lint": "eslint lib test",
"travis": "npm run cover -- --report lcovonly",
"cover": "istanbul cover -x *.runtime.js node_modules/mocha/bin/_mocha",
- "publish-patch": "mocha && npm version patch && git push && git push --tags && npm publish"
+ "release": "npm test && standard-version"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/webpack/loader-utils.git"
},
+ "engines": {
+ "node": ">=4.0.0"
+ },
"devDependencies": {
"coveralls": "^2.11.2",
+ "eslint": "^3.15.0",
+ "eslint-plugin-node": "^4.0.1",
"istanbul": "^0.3.14",
- "mocha": "^1.21.4"
+ "mocha": "^1.21.4",
+ "standard-version": "^4.0.0"
},
+ "main": "lib/index.js",
"files": [
- "index.js"
+ "lib"
]
}