Updated the files.

This commit is contained in:
Batuhan Berk Başoğlu 2024-02-08 19:38:41 -05:00
parent 1553e6b971
commit 753967d4f5
23418 changed files with 3784666 additions and 0 deletions

28
my-app/node_modules/adjust-sourcemap-loader/.jshintrc generated vendored Executable file
View file

@ -0,0 +1,28 @@
{
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"forin": false,
"freeze": false,
"immed": true,
"indent": 2,
"latedef": "nofunc",
"newcap": true,
"noarg": true,
"noempty": true,
"nonbsp": true,
"nonew": true,
"plusplus": false,
"quotmark": "single",
"undef": true,
"unused": true,
"strict": true,
"maxparams": 20,
"maxdepth": 5,
"maxlen": 120,
"scripturl": true,
"node": true,
"esnext": true,
"jasmine": true
}

1
my-app/node_modules/adjust-sourcemap-loader/.nvmrc generated vendored Executable file
View file

@ -0,0 +1 @@
8.9

21
my-app/node_modules/adjust-sourcemap-loader/LICENSE generated vendored Executable file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2019 Ben Holloway
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.

View file

@ -0,0 +1,43 @@
'use strict';
var path = require('path'),
fs = require('fs');
/**
* Codec for absolute paths.
* @type {{name:string, decode: function, encode: function, root: function}}
*/
module.exports = {
name : 'absolute',
decode: decode,
encode: encode,
root : root
};
/**
* Decode the given uri.
* Any path with leading slash is tested in an absolute sense.
* @this {{options: object}} A loader or compilation
* @param {string} uri A source uri to decode
* @returns {boolean|string} False where unmatched else the decoded path
*/
function decode(uri) {
return path.isAbsolute(uri) && fs.existsSync(uri) && fs.statSync(uri).isFile() && uri;
}
/**
* Encode the given file path.
* @this {{options: object}} A loader or compilation
* @returns {string} A uri
*/
function encode(absolute) {
return absolute;
}
/**
* The source-map root where relevant.
* @this {{options: object}} A loader or compilation
* @returns {string|undefined} The source-map root applicable to any encoded uri
*/
function root() {
}

View file

@ -0,0 +1,21 @@
'use strict';
/**
* Codec for code generated by the Bower plugin.
* @type {{name:string, decode:function, abstract:boolean}}
*/
module.exports = {
name : 'bowerComponent',
decode : decode,
abstract: true
};
/**
* Validate the given uri (abstract).
* @this {{options: object}} A loader or compilation
* @param {string} uri A source uri to decode
* @returns {boolean|string} False where unmatched else True
*/
function decode(uri) {
return /^\/?([\w-]+)\s+\(bower component\)$/.test(uri);
}

14
my-app/node_modules/adjust-sourcemap-loader/codec/index.js generated vendored Executable file
View file

@ -0,0 +1,14 @@
module.exports = [
require('./webpack-protocol'),
require('./webpack-bootstrap'),
require('./bower-component'),
require('./npm-module'),
/* insert here any additional special character CODECs */
require('./output-relative'),
require('./output-root-relative'),
require('./project-relative'),
require('./project-root-relative'),
require('./source-relative'),
require('./source-root-relative'),
require('./absolute')
];

View file

@ -0,0 +1,35 @@
'use strict';
var path = require('path'),
fs = require('fs');
var loaderUtils = require('loader-utils');
var getContextDirectory = require('./utility/get-context-directory');
/**
* Codec for relative paths with respect to the context directory.
* @type {{name:string, decode: function}}
*/
module.exports = {
name : 'npmModule',
decode: decode
};
/**
* Decode the given uri.
* Include only module paths containing `~`.
* @this {{options: object}} A loader or compilation
* @param {string} uri A source uri to decode
* @returns {boolean|string} False where unmatched else the decoded path
*/
function decode(uri) {
/* jshint validthis:true */
if (/~/.test(uri)) {
var relative = loaderUtils.urlToRequest(uri),
base = getContextDirectory.call(this),
absFile = path.normalize(path.join(base, 'node_modules', relative)),
isValid = !!absFile && fs.existsSync(absFile) && fs.statSync(absFile).isFile();
return isValid && absFile;
}
}

View file

@ -0,0 +1,49 @@
'use strict';
var path = require('path'),
fs = require('fs');
var getOutputDirectory = require('./utility/get-output-directory');
/**
* Codec for relative paths with respect to the output directory.
* @type {{name:string, decode: function, encode: function, root: function}}
*/
module.exports = {
name : 'outputRelative',
decode: decode,
encode: encode,
root : getOutputDirectory
};
/**
* Decode the given uri.
* Any path with without leading slash is tested against output directory.
* @this {{options: object}} A loader or compilation
* @param {string} uri A source uri to decode
* @returns {boolean|string} False where unmatched else the decoded path
*/
function decode(uri) {
/* jshint validthis:true */
var base = !uri.startsWith('/') && getOutputDirectory.call(this),
absFile = !!base && path.normalize(path.join(base, uri)),
isValid = !!absFile && fs.existsSync(absFile) && fs.statSync(absFile).isFile();
return isValid && absFile;
}
/**
* Encode the given file path.
* @this {{options: object}} A loader or compilation
* @param {string} absolute An absolute file path to encode
* @returns {string} A uri without leading slash
*/
function encode(absolute) {
/* jshint validthis:true */
var base = getOutputDirectory.call(this);
if (!base) {
throw new Error('Cannot locate the Webpack output directory');
}
else {
return path.relative(base, absolute);
}
}

View file

@ -0,0 +1,37 @@
'use strict';
var relative = require('./output-relative');
/**
* Codec for relative paths with respect to the output directory.
* @type {{name:string, decode: function, encode: function, root: function}}
*/
module.exports = {
name : 'outputRootRelative',
decode: decode,
encode: encode,
root : relative.root
};
/**
* Decode the given uri.
* Any path with leading slash is tested against output directory.
* @this {{options: object}} A loader or compilation
* @param {string} uri A source uri to decode
* @returns {boolean|string} False where unmatched else the decoded path
*/
function decode(uri) {
/* jshint validthis:true */
return uri.startsWith('/') && relative.decode.call(this, uri.slice(1));
}
/**
* Encode the given file path.
* @this {{options: object}} A loader or compilation
* @param {string} absolute An absolute file path to encode
* @returns {string} A uri with leading slash
*/
function encode(absolute) {
/* jshint validthis:true */
return '/' + relative.encode.call(this, absolute);
}

View file

@ -0,0 +1,50 @@
'use strict';
var path = require('path'),
fs = require('fs');
var getContextDirectory = require('./utility/get-context-directory'),
enhancedRelative = require('./utility/enhanced-relative');
/**
* Codec for relative paths with respect to the project directory.
* @type {{name:string, decode: function, encode: function, root: function}}
*/
module.exports = {
name : 'projectRelative',
decode: decode,
encode: encode,
root : getContextDirectory
};
/**
* Decode the given uri.
* Any path with without leading slash is tested against project directory.
* @this {{options: object}} A loader or compilation
* @param {string} uri A source uri to decode
* @returns {boolean|string} False where unmatched else the decoded path
*/
function decode(uri) {
/* jshint validthis:true */
var base = !uri.startsWith('/') && getContextDirectory.call(this),
absFile = !!base && path.normalize(path.join(base, uri)),
isValid = !!absFile && fs.existsSync(absFile) && fs.statSync(absFile).isFile();
return isValid && absFile;
}
/**
* Encode the given file path.
* @this {{options: object}} A loader or compilation
* @param {string} absolute An absolute file path to encode
* @returns {string} A uri without leading slash
*/
function encode(absolute) {
/* jshint validthis:true */
var base = getContextDirectory.call(this);
if (!base) {
throw new Error('Cannot locate the Webpack project directory');
}
else {
return enhancedRelative(base, absolute);
}
}

View file

@ -0,0 +1,37 @@
'use strict';
var relative = require('./project-relative');
/**
* Codec for relative paths with respect to the project directory.
* @type {{name:string, decode: function, encode: function, root: function}}
*/
module.exports = {
name : 'projectRootRelative',
decode: decode,
encode: encode,
root : relative.root
};
/**
* Decode the given uri.
* Any path with leading slash is tested against project directory.
* @this {{options: object}} A loader or compilation
* @param {string} uri A source uri to decode
* @returns {boolean|string} False where unmatched else the decoded path
*/
function decode(uri) {
/* jshint validthis:true */
return uri.startsWith('/') && relative.decode.call(this, uri.slice(1));
}
/**
* Encode the given file path.
* @this {{options: object}} A loader or compilation
* @param {string} absolute An absolute file path to encode
* @returns {string} A uri with leading slash
*/
function encode(absolute) {
/* jshint validthis:true */
return '/' + relative.encode.call(this, absolute);
}

View file

@ -0,0 +1,51 @@
'use strict';
var path = require('path'),
fs = require('fs');
/**
* Codec for relative paths with respect to the source directory.
* @type {{name:string, decode: function, encode: function, root: function}}
*/
module.exports = {
name : 'sourceRelative',
decode: decode,
encode: encode,
root : root
};
/**
* Decode the given uri.
* Any path without leading slash is tested against source directory.
* @this {{options: object}} A loader or compilation
* @param {string} uri A source uri to decode
* @returns {boolean|string} False where unmatched else the decoded path
*/
function decode(uri) {
/* jshint validthis:true */
var base = !uri.startsWith('/') && this.context,
absFile = !!base && path.normalize(path.join(base, uri)),
isValid = !!absFile && fs.existsSync(absFile) && fs.statSync(absFile).isFile();
return isValid && absFile;
}
/**
* Encode the given file path.
* @this {{options: object}} A loader or compilation
* @param {string} absolute An absolute file path to encode
* @returns {string} A uri without leading slash
*/
function encode(absolute) {
/* jshint validthis:true */
return path.relative(this.context, absolute);
}
/**
* The source-map root where relevant.
* @this {{options: object}} A loader or compilation
* @returns {string|undefined} The source-map root applicable to any encoded uri
*/
function root() {
/* jshint validthis:true */
return this.context;
}

View file

@ -0,0 +1,37 @@
'use strict';
var relative = require('./source-relative');
/**
* Codec for relative paths with respect to the source directory.
* @type {{name:string, decode: function, encode: function, root: function}}
*/
module.exports = {
name : 'sourceRootRelative',
decode: decode,
encode: encode,
root : relative.root
};
/**
* Decode the given uri.
* Any path with leading slash is tested against source directory.
* @this {{options: object}} A loader or compilation
* @param {string} uri A source uri to decode
* @returns {boolean|string} False where unmatched else the decoded path
*/
function decode(uri) {
/* jshint validthis:true */
return uri.startsWith('/') && relative.decode.call(this, uri.slice(1));
}
/**
* Encode the given file path.
* @this {{options: object}} A loader or compilation
* @param {string} absolute An absolute file path to encode
* @returns {string} A uri with leading slash
*/
function encode(absolute) {
/* jshint validthis:true */
return '/' + relative.encode.call(this, absolute);
}

View file

@ -0,0 +1,118 @@
'use strict';
var fs = require('fs'),
path = require('path');
var cache;
/**
* Perform <code>path.relative()</code> but try to detect and correct sym-linked node modules.
* @param {string} from The base path
* @param {string} to The full path
*/
function enhancedRelative(from, to) {
// relative path
var relative = path.relative(from, to);
// trailing is the relative path portion without any '../'
var trailing = relative.replace(/^\.{2}[\\\/]/, ''),
leading = to.replace(trailing, '');
// within project is what we want
var isInProject = (relative === trailing);
if (isInProject) {
return relative;
}
// otherwise look at symbolic linked modules
else {
var splitTrailing = trailing.split(/[\\\/]/);
// ensure failures can retry with fresh cache
for (var i = cache ? 2 : 1, foundPath = false; (i > 0) && !foundPath; i--) {
// ensure cache
cache = cache || indexLinkedModules(from);
// take elements from the trailing path and append them the the leading path in an attempt to find a package.json
for (var j = 0; (j < splitTrailing.length) && !foundPath; j++) {
// find the name of packages in the actual file location
// start at the lowest concrete directory that appears in the relative path
var packagePath = path.join.apply(path, [leading].concat(splitTrailing.slice(0, j + 1))),
packageJsonPath = path.join(packagePath, 'package.json'),
packageName = fs.existsSync(packageJsonPath) && require(packageJsonPath).name;
// lookup any package name in the cache
var linkedPackagePath = !!packageName && cache[packageName];
if (linkedPackagePath) {
// the remaining portion of the trailing path, not including the package path
var remainingPath = path.join.apply(path, splitTrailing.slice(j + 1));
// validate the remaining path in the linked location
// failure implies we will keep trying nested sym-linked packages
var linkedFilePath = path.join(linkedPackagePath, remainingPath),
isValid = !!linkedFilePath && fs.existsSync(linkedFilePath) &&
fs.statSync(linkedFilePath).isFile();
// path is found where valid
foundPath = isValid && linkedFilePath;
}
}
// cache cannot be trusted if a file can't be found
// set the cache to false to trigger its rebuild
cache = !!foundPath && cache;
}
// the relative path should now be within the project
return foundPath ? path.relative(from, foundPath) : relative;
}
}
module.exports = enhancedRelative;
/**
* Make a hash of linked modules within the given directory by breadth-first search.
* @param {string} directory A path to start searching
* @returns {object} A collection of sym-linked paths within the project keyed by their package name
*/
function indexLinkedModules(directory) {
var buffer = listSymLinkedModules(directory),
hash = {};
// while there are items in the buffer
while (buffer.length > 0) {
var modulePath = buffer.shift(),
packageJsonPath = path.join(modulePath, 'package.json'),
packageName = fs.existsSync(packageJsonPath) && require(packageJsonPath).name;
if (packageName) {
// add this path keyed by package name, so long as it doesn't exist at a lower level
hash[packageName] = hash[packageName] || modulePath;
// detect nested module and push to the buffer (breadth-first)
buffer.push.apply(buffer, listSymLinkedModules(modulePath));
}
}
return hash;
function listSymLinkedModules(directory) {
var modulesPath = path.join(directory, 'node_modules'),
hasNodeModules = fs.existsSync(modulesPath) && fs.statSync(modulesPath).isDirectory(),
subdirectories = !!hasNodeModules && fs.readdirSync(modulesPath) || [];
return subdirectories
.map(joinDirectory)
.filter(testIsSymLink);
function joinDirectory(subdirectory) {
return path.join(modulesPath, subdirectory);
}
function testIsSymLink(directory) {
return fs.lstatSync(directory).isSymbolicLink(); // must use lstatSync not statSync
}
}
}

View file

@ -0,0 +1,17 @@
'use strict';
var path = require('path');
/**
* Infer the compilation context directory from options.
* Relative paths are resolved against process.cwd().
* @this {{options: object}} A loader or compilation
* @returns {string} process.cwd() where not defined else the output path string
*/
function getContextDirectory() {
/* jshint validthis:true */
var context = this.options ? this.options.context : null;
return !!context && path.resolve(context) || process.cwd();
}
module.exports = getContextDirectory;

View file

@ -0,0 +1,22 @@
'use strict';
var path = require('path'),
fs = require('fs');
var getContextDirectory = require('./get-context-directory');
/**
* Infer the compilation output directory from options.
* Relative paths are resolved against the compilation context (or process.cwd() where not specified).
* @this {{options: object}} A loader or compilation
* @returns {undefined|string} The output path string, where defined
*/
function getOutputDirectory() {
/* jshint validthis:true */
var base = this.options && this.options.output ? this.options.output.directory : null,
absBase = !!base && path.resolve(getContextDirectory.call(this), base),
isValid = !!absBase && fs.existsSync(absBase) && fs.statSync(absBase).isDirectory();
return isValid ? absBase : undefined;
}
module.exports = getOutputDirectory;

View file

@ -0,0 +1,21 @@
'use strict';
/**
* Codec for webpack generated bootstrap code.
* @type {{name:string, decode:function, abstract:boolean}}
*/
module.exports = {
name : 'webpackBootstrap',
decode : decode,
abstract: true
};
/**
* Validate the given uri (abstract).
* @this {{options: object}} A loader or compilation
* @param {string} uri A source uri to decode
* @returns {boolean|string} False where unmatched else True
*/
function decode(uri) {
return /^webpack\/bootstrap\s+\w{20}$/.test(uri);
}

View file

@ -0,0 +1,45 @@
'use strict';
var projectRelative = require('./project-relative');
/**
* Codec for relative paths with respect to the context directory, preceded by a webpack:// protocol.
* @type {{name:string, decode: function, encode: function, root: function}}
*/
module.exports = {
name : 'webpackProtocol',
decode: decode,
encode: encode,
root : root
};
/**
* Decode the given uri.
* @this {{options: object}} A loader or compilation
* @param {string} uri A source uri to decode
* @returns {boolean|string} False where unmatched else the decoded path
*/
function decode(uri) {
/* jshint validthis:true */
var analysis = /^webpack:\/{2}(.*)$/.exec(uri);
return !!analysis && projectRelative.decode.call(this, analysis[1]);
}
/**
* Encode the given file path.
* @this {{options: object}} A loader or compilation
* @param {string} absolute An absolute file path to encode
* @returns {string} A uri
*/
function encode(absolute) {
/* jshint validthis:true */
return 'webpack://' + projectRelative.encode.call(this, absolute);
}
/**
* The source-map root where relevant.
* @this {{options: object}} A loader or compilation
* @returns {string|undefined} The source-map root applicable to any encoded uri
*/
function root() {
}

10
my-app/node_modules/adjust-sourcemap-loader/index.js generated vendored Executable file
View file

@ -0,0 +1,10 @@
/*
* MIT License http://opensource.org/licenses/MIT
* Author: Ben Holloway @bholloway
*/
'use strict';
module.exports = Object.assign(require('./lib/loader'), {
moduleFilenameTemplate: require('./lib/module-filename-template'),
codec : require('./codec')
});

40
my-app/node_modules/adjust-sourcemap-loader/lib/loader.js generated vendored Executable file
View file

@ -0,0 +1,40 @@
'use strict';
var path = require('path');
var loaderUtils = require('loader-utils');
var process = require('./process');
/**
* Webpack loader that manipulates the source-map of a preceding loader.
* @this {object} The loader context
* @param {string} content The content
* @param {object} sourceMap The source-map
* @returns {string|String}
*/
function loader(content, sourceMap) {
/* jshint validthis:true */
// loader result is cacheable
this.cacheable();
// webpack 1: prefer loader query, else options object
// webpack 2: prefer loader options
// webpack 3: deprecate loader.options object
// webpack 4: loader.options no longer defined
var options = Object.assign(
{},
this.options && this.options.adjustSourcemapLoader,
loaderUtils.getOptions(this),
{sep: path.sep}
);
// process the source-map
var outputMap = process(this, options, sourceMap);
// need to use callback when there are multiple arguments
this.callback(null, content, outputMap);
}
module.exports = loader;

View file

@ -0,0 +1,11 @@
'use strict';
var process = require('./process');
function moduleFilenameTemplate(options) {
return function templateFn(parameters) {
return process(parameters, options, parameters.resourcePath);
};
}
module.exports = moduleFilenameTemplate;

View file

@ -0,0 +1,58 @@
'use strict';
var PACKAGE_NAME = require('../../package.json').name,
PADDING = (new Array(11)).join(' ');
/**
* Format a debug message
* @param {{resourcePath:string, loaders:Array, loaderIndex:number}} context A loader or compilation
* @param {{input:Array.<string>, absolute:Array.<string>, output:Array.<string>, root:string}} info Source-map info
* @returns {string} An encoded debug string
*/
function debugMessage(context, info) {
return [
' ',
PACKAGE_NAME + ':',
' ' + context.resourcePath,
formatField('@', precedingRequest(context)),
formatField('INPUT', info.input || '(source-map absent)'),
formatField('ABSOLUTE', info.absolute),
formatField('OUTPUT', info.output),
formatField('ROOT', info.root)
]
.filter(Boolean)
.join('\n');
}
module.exports = debugMessage;
/**
* Find the request that precedes this loader in the loader chain
* @param {{loaders:Array, loaderIndex:number}} loader The loader context
* @returns {string} The request of the preceding loader
*/
function precedingRequest(loader) {
var isLoader = ('loaderIndex' in loader) && ('loaders' in loader) && Array.isArray(loader.loaders);
if (isLoader) {
var index = loader.loaderIndex + 1;
return (index in loader.loaders) ? loader.loaders[index].request : '(no preceding loader)';
}
}
/**
* Where the data is truthy then format it with a right-aligned title.
* @param {string} title
* @param {*} data The data to display
* @returns {boolean|string} False where data is falsey, else formatted message
*/
function formatField(title, data) {
return !!data && (rightAlign(title) + formatData(data));
function rightAlign(text) {
return (PADDING + text + ' ').slice(-PADDING.length);
}
function formatData(data) {
return Array.isArray(data) ? data.join('\n' + PADDING) : data;
}
}

View file

@ -0,0 +1,78 @@
'use strict';
var getFieldAsFn = require('./get-field-as-fn');
/**
* Create a decoder for input sources using the given codec hash
* @this {object} A loader or compilation
* @param {Array.<object>} codecs A list of codecs, each with a `decode` function
* @param {boolean} mustDecode Return an error for a source that is not decoded
* @returns {function(string):string|Error} A decode function that returns an absolute path or else an Error
*/
function decodeSourcesWith(codecs, mustDecode) {
/* jshint validthis:true */
var context = this;
// get a list of valid decoders
var candidates = [].concat(codecs)
.reduce(reduceValidDecoder.bind(null, codecs), []);
/**
* Attempt to decode the given source path using the previously supplied codecs
* @param {string} inputSource A source path from a source map
* @returns {Error|string|undefined} An absolute path if decoded else an error if encountered else undefined
*/
return function decode(inputSource) {
// attempt all candidates until a match
for (var i = 0, decoded = null; i < candidates.length && !decoded; i++) {
// call the decoder
try {
decoded = candidates[i].decode.call(context, inputSource);
}
catch (exception) {
return getNamedError(exception);
}
// match implies a return value
if (decoded) {
// abstract sources cannot be decoded, only validated
if (candidates[i].abstract) {
return undefined;
}
// non-string implies error
if (typeof decoded !== 'string') {
return getNamedError('Decoder returned a truthy value but it is not a string:\n' + decoded);
}
// otherwise success
else {
return decoded;
}
}
}
// default is undefined or error
return mustDecode ? new Error('No viable decoder for source: ' + inputSource) : undefined;
function getNamedError(details) {
var name = candidates[i].name || '(unnamed)',
message = [
'Decoding with codec: ' + name,
'Incoming source: ' + inputSource,
details && (details.stack ? details.stack : details)
]
.filter(Boolean)
.join('\n');
return new Error(message);
}
};
}
module.exports = decodeSourcesWith;
function reduceValidDecoder(reduced, codec) {
var decoder = getFieldAsFn('decode')(codec);
return decoder ? reduced.concat(codec) : reduced;
}

View file

@ -0,0 +1,48 @@
'use strict';
var getFieldAsFn = require('./get-field-as-fn'),
CustomError = require('./get-error');
/**
* Create an encoder for output sources using the given codec hash
* @throws Error Where the given codec is missing an encode function
* @this {object} A loader or compilation
* @param {{encode:function}} codec A single codec with an `encode` function
* @returns {function(string):string|Error|false} An encode function that takes an absolute path
*/
function encodeSourcesWith(codec) {
/* jshint validthis:true */
var context = this,
encoder = getFieldAsFn('encode')(codec);
if (!encoder) {
return new CustomError('Specified format does not support encoding (it lacks an "encoder" function)');
}
else {
return function encode(absoluteSource) {
// call the encoder
var encoded;
try {
encoded = absoluteSource && encoder.call(context, absoluteSource);
}
catch (exception) {
return getNamedError(exception);
}
return encoded;
function getNamedError(details) {
var name = codec.name || '(unnamed)',
message = [
'Encoding with codec: ' + name,
'Absolute source: ' + absoluteSource,
details && (details.stack ? details.stack : details)
]
.filter(Boolean)
.join('\n');
return new Error(message);
}
};
}
}
module.exports = encodeSourcesWith;

View file

@ -0,0 +1,17 @@
'use strict';
var PACKAGE_NAME = require('../../package.json').name;
/**
* Get an Error instance for the given message
* @param {...*} message Any number of message arguments
* @returns {Error}
*/
function getError() {
var message = (PACKAGE_NAME + ':\n' + Array.prototype.slice.call(arguments).join(' '))
.split(/\s*\n\s*/)
.join('\n ');
return new Error(message);
}
module.exports = getError;

View file

@ -0,0 +1,14 @@
'use strict';
/**
* Create a method that will retrieve the given field from an object where that field has a function value
* @param {string} field The field to consider
* @returns {function(object):function} A method that gets functions from the given field
*/
function getFieldAsFn(field) {
return function getFromValue(value) {
return !!value && (typeof value === 'object') && (typeof value[field] === 'function') && value[field];
};
}
module.exports = getFieldAsFn;

View file

@ -0,0 +1,117 @@
'use strict';
var debugMessage = require('./debug-message'),
toRegExp = require('./to-reg-exp'),
throwErrors = require('./throw-errors'),
decodeSourcesWith = require('./decode-sources-with'),
locateRootWith = require('./locate-root-with'),
encodeSourcesWith = require('./encode-sources-with'),
testCodec = require('./test-codec');
var CODECS = require('../../codec');
/**
* Process the given source-map per the given options.
* @param {{resourcePath:string, context:string, output:{path:string}}} context A loader or compilation
* @param {{debug:boolean, fail:boolean, format:string|boolean, root:string, codecs:object}} opt Options hash
* @param {object|string} sourceMapOrSource An incoming source-map or single source path
* @returns {undefined|object|string} An amended source-map or source path else undefined
*/
function process(context, opt, sourceMapOrSource) {
// default options
var options = Object.assign({
sep : '/',
debug : false,
fail : false,
format: false,
root : false,
codecs: CODECS
}, opt);
// validate codecs
var codecs = options.codecs
.filter(testCodec);
// determine what is present
var inputMap = !!sourceMapOrSource && (typeof sourceMapOrSource === 'object') && sourceMapOrSource,
inputPath = (typeof sourceMapOrSource === 'string') && sourceMapOrSource,
inputSources = inputMap && inputMap.sources || inputPath && [inputPath];
// what we need to produce
var absoluteSources,
outputSources,
outputRoot,
outputMap;
if (inputSources) {
// decode each source with the first valid codec
absoluteSources = inputSources
.map(decodeSourcesWith.call(context, codecs, options.fail));
// check for decode errors
throwErrors(context.resourcePath, absoluteSources);
// output map is a copy unless absent or we are removing
outputMap = (!inputMap || (options.format === 'remove')) ? undefined : Object.assign({}, inputMap);
// some change in format
if (options.format) {
// find the specified codec in the codecs list
var codec = codecs
.filter(testNamedCodec)
.pop();
if (!codec) {
throw new Error('Specified format "' + options.format + '" does not match any available codec.');
}
// use the encoder where specified in 'format'
outputSources = absoluteSources
.map(encodeSourcesWith.call(context, codec))
.map(insertAbstractSources)
.map(convertPathSep);
outputRoot = !!options.root && locateRootWith.call(context, codec)() || undefined;
// check for encode errors
throwErrors(context.resourcePath, outputSources.concat(outputRoot));
// commit the change
if (outputMap) {
outputMap.sources = outputSources;
outputMap.sourceRoot = outputRoot;
}
}
}
// debugging information
var isDebug = toRegExp(options.debug).test(context.resourcePath);
if (isDebug) {
console.log(debugMessage(context, {
input : inputSources,
absolute: absoluteSources,
output : outputSources,
root : outputRoot
}));
}
// complete
return inputMap ? outputMap : outputSources ? outputSources[0] : undefined;
function testNamedCodec(value) {
return (value.name === options.format);
}
function insertAbstractSources(value, i) {
return value || inputSources[i];
}
function convertPathSep(value) {
return (value instanceof Error) ? value : value.replace(/[\\\/]/g, options.sep);
}
}
module.exports = process;

View file

@ -0,0 +1,47 @@
'use strict';
var getFieldAsFn = require('./get-field-as-fn'),
CustomError = require('./get-error');
/**
* Locate the root for input sources using the given codec hash
* @throws Error Where the given codec is missing an encode function
* @this {object} A loader or compilation
* @param {{encode:function}} codec A single codec with an `encode` function
* @returns {function(string):string|Error} An encode function that takes an absolute path
*/
function locateRootWith(codec) {
/* jshint validthis:true */
var context = this,
root = getFieldAsFn('root')(codec);
if (!root) {
return new CustomError('Specified format does not support encoding (it lacks a "root" function)');
}
else {
return function locate() {
// call the root
var located;
try {
located = root.call(context);
}
catch (exception) {
return getNamedError(exception);
}
return located;
function getNamedError(details) {
var name = codec.name || '(unnamed)',
message = [
'Locating root with codec: ' + name,
details && (details.stack ? details.stack : details)
]
.filter(Boolean)
.join('\n');
return new Error(message);
}
};
}
}
module.exports = locateRootWith;

View file

@ -0,0 +1,37 @@
'use strict';
var assert = require('assert');
/**
* Reducer function that converts a codec list to a hash.
* @throws Error on bad codec
* @param {{name:string, decode:function, encode:function, root:function}} candidate A possible codec
* @returns True where an error is not thrown
*/
function testCodec(candidate) {
assert(
!!candidate && (typeof candidate === 'object'),
'Codec must be an object'
);
assert(
(typeof candidate.name === 'string') && /^[\w-]+$/.test(candidate.name),
'Codec.name must be a kebab-case string'
);
assert(
(typeof candidate.decode === 'function') && (candidate.decode.length === 1),
'Codec.decode must be a function that accepts a single source string'
);
assert(
(typeof candidate.encode === 'undefined') ||
((typeof candidate.encode === 'function') && (candidate.encode.length === 1)),
'Codec.encode must be a function that accepts a single absolute path string, or else be omitted'
);
assert(
(typeof candidate.root === 'undefined') ||
(typeof candidate.root === 'function') && (candidate.root.length === 0),
'Codec.root must be a function that accepts no arguments, or else be omitted'
);
return true;
}
module.exports = testCodec;

View file

@ -0,0 +1,30 @@
'use strict';
var getError = require('./get-error');
/**
* Where the given list is non-null and contains error instances then consolidate and throw
* @throws Error
* @param {string} resourcePath The path to the resource being processed
* @param {null|Array} candidates A possible Array with possible error elements
*/
function throwErrors(resourcePath, candidates) {
var errors = !!candidates && candidates
.filter(testIsError)
.map(getMessage);
var hasError = !!errors && errors.length;
if (hasError) {
throw getError(['For resource: ' + resourcePath].concat(errors).join('\n'));
}
function testIsError(candidate) {
return !!candidate && (typeof candidate === 'object') && (candidate instanceof Error);
}
function getMessage(error) {
return error.message;
}
}
module.exports = throwErrors;

View file

@ -0,0 +1,19 @@
'use strict';
var regexParser = require('regex-parser');
var REGEXP = /(\/?)(.+)\1([a-z]*)/i;
/**
* Parse the give value as a regular expression or give a pass-none expression where it is invalid
* @param {RegExp|string|*} value An existing expression, or its string representation, or degenerate value
* @returns {RegExp} The given expression or one matching the RegExp string else a pass-none expression
*/
function toRegExp(value) {
return ((typeof value === 'object') && (typeof value.test === 'function') && value) ||
((typeof value === 'string') && REGEXP.test(value) && regexParser(value)) ||
(/^true$|^$/.test(value) && /.*/) ||
/matchnone^/;
}
module.exports = toRegExp;

View file

@ -0,0 +1,20 @@
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
'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.

View file

@ -0,0 +1,275 @@
# loader-utils
## Methods
### `getOptions`
Recommended way to retrieve the options of a loader invocation:
```javascript
// inside your loader
const options = loaderUtils.getOptions(this);
```
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
const options = Object.assign(
{},
defaultOptions,
loaderUtils.getOptions(this) // it is safe to pass null to Object.assign()
);
// don't forget nested objects or arrays
options.obj = Object.assign({}, options.obj);
options.arr = options.arr.slice();
someLibrary(options);
```
[clone](https://www.npmjs.com/package/clone) is a good library to make a deep copy of the options.
#### Options as query strings
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
const params = loaderUtils.parseQuery(this.resourceQuery); // resource: `file?param1=foo`
if (params.param1 === "foo") {
// do something
}
```
The string is parsed like this:
``` text
-> 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`
Turns a request into a string that can be used inside `require()` or `import` while avoiding absolute paths.
Use it instead of `JSON.stringify(...)` if you're generating code inside a loader.
**Why is this necessary?** Since webpack calculates the hash before module paths are translated into module ids, we must avoid absolute paths to ensure
consistent hashes across different compilations.
This function:
- resolves absolute requests into relative requests if the request and the module are on the same hard drive
- replaces `\` with `/` if the request and the module are on the same hard drive
- won't change the path at all if the request and the module are on different hard drives
- applies `JSON.stringify` to the result
```javascript
loaderUtils.stringifyRequest(this, "./test.js");
// "\"./test.js\""
loaderUtils.stringifyRequest(this, ".\\test.js");
// "\"./test.js\""
loaderUtils.stringifyRequest(this, "test");
// "\"test\""
loaderUtils.stringifyRequest(this, "test/lib/index.js");
// "\"test/lib/index.js\""
loaderUtils.stringifyRequest(this, "otherLoader?andConfig!test?someConfig");
// "\"otherLoader?andConfig!test?someConfig\""
loaderUtils.stringifyRequest(this, require.resolve("test"));
// "\"../node_modules/some-loader/lib/test.js\""
loaderUtils.stringifyRequest(this, "C:\\module\\test.js");
// "\"../../test.js\"" (on Windows, in case the module and the request are on the same drive)
loaderUtils.stringifyRequest(this, "C:\\module\\test.js");
// "\"C:\\module\\test.js\"" (on Windows, in case the module and the request are on different drives)
loaderUtils.stringifyRequest(this, "\\\\network-drive\\test.js");
// "\"\\\\network-drive\\\\test.js\"" (on Windows, in case the module and the request are on different drives)
```
### `urlToRequest`
Converts some resource URL to a webpack module request.
> i Before call `urlToRequest` you need call `isUrlRequest` to ensure it is requestable url
```javascript
const url = "path/to/module.js";
if (loaderUtils.isUrlRequest(url)) {
// Logic for requestable url
const request = loaderUtils.urlToRequest(url);
} else {
// Logic for not requestable url
}
```
Simple example:
```javascript
const url = "path/to/module.js";
const request = loaderUtils.urlToRequest(url); // "./path/to/module.js"
```
#### Module URLs
Any URL containing a `~` will be interpreted as a module request. Anything after the `~` will be considered the request path.
```javascript
const url = "~path/to/module.js";
const request = loaderUtils.urlToRequest(url); // "path/to/module.js"
```
#### Root-relative URLs
URLs that are root-relative (start with `/`) can be resolved relative to some arbitrary path by using the `root` parameter:
```javascript
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
const url = "/path/to/module.js";
const root = "~";
const request = loaderUtils.urlToRequest(url, root); // "path/to/module.js"
```
### `interpolateName`
Interpolates a filename template using multiple placeholders and/or a regular expression.
The template and regular expression are set as query params called `name` and `regExp` on the current loader's context.
```javascript
const interpolatedName = loaderUtils.interpolateName(loaderContext, name, options);
```
The following tokens are replaced in the `name` parameter:
* `[ext]` the extension of the resource
* `[name]` the basename of the resource
* `[path]` the path of the resource relative to the `context` query parameter or option.
* `[folder]` the folder the resource is in
* `[query]` the queryof the resource, i.e. `?foo=bar`
* `[emoji]` a random emoji representation of `options.content`
* `[emoji:<length>]` same as above, but with a customizable number of emojis
* `[contenthash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the md4 hash)
* `[<hashType>:contenthash:<digestType>:<length>]` optionally one can configure
* other `hashType`s, i. e. `sha1`, `md4`, `md5`, `sha256`, `sha512`
* other `digestType`s, i. e. `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
* and `length` the length in chars
* `[hash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the md4 hash)
* `[<hashType>:hash:<digestType>:<length>]` optionally one can configure
* other `hashType`s, i. e. `sha1`, `md4`, `md5`, `sha256`, `sha512`
* other `digestType`s, i. e. `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
* and `length` the length in chars
* `[N]` the N-th match obtained from matching the current file name against `options.regExp`
In loader context `[hash]` and `[contenthash]` are the same, but we recommend using `[contenthash]` for avoid misleading.
Examples
``` javascript
// loaderContext.resourcePath = "/absolute/path/to/app/js/javascript.js"
loaderUtils.interpolateName(loaderContext, "js/[hash].script.[ext]", { content: ... });
// => js/9473fdd0d880a43c21b7778d34872157.script.js
// loaderContext.resourcePath = "/absolute/path/to/app/js/javascript.js"
// loaderContext.resourceQuery = "?foo=bar"
loaderUtils.interpolateName(loaderContext, "js/[hash].script.[ext][query]", { content: ... });
// => js/9473fdd0d880a43c21b7778d34872157.script.js?foo=bar
// loaderContext.resourcePath = "/absolute/path/to/app/js/javascript.js"
loaderUtils.interpolateName(loaderContext, "js/[contenthash].script.[ext]", { content: ... });
// => js/9473fdd0d880a43c21b7778d34872157.script.js
// loaderContext.resourcePath = "/absolute/path/to/app/page.html"
loaderUtils.interpolateName(loaderContext, "html-[hash:6].html", { content: ... });
// => html-9473fd.html
// loaderContext.resourcePath = "/absolute/path/to/app/flash.txt"
loaderUtils.interpolateName(loaderContext, "[hash]", { content: ... });
// => c31e9820c001c9c4a86bce33ce43b679
// loaderContext.resourcePath = "/absolute/path/to/app/img/image.gif"
loaderUtils.interpolateName(loaderContext, "[emoji]", { content: ... });
// => 👍
// loaderContext.resourcePath = "/absolute/path/to/app/img/image.gif"
loaderUtils.interpolateName(loaderContext, "[emoji:4]", { content: ... });
// => 🙍🏢📤🐝
// loaderContext.resourcePath = "/absolute/path/to/app/img/image.png"
loaderUtils.interpolateName(loaderContext, "[sha512:hash:base64:7].[ext]", { content: ... });
// => 2BKDTjl.png
// use sha512 hash instead of md4 and with only 7 chars of base64
// loaderContext.resourcePath = "/absolute/path/to/app/img/myself.png"
// loaderContext.query.name =
loaderUtils.interpolateName(loaderContext, "picture.png");
// => picture.png
// loaderContext.resourcePath = "/absolute/path/to/app/dir/file.png"
loaderUtils.interpolateName(loaderContext, "[path][name].[ext]?[hash]", { content: ... });
// => /app/dir/file.png?9473fdd0d880a43c21b7778d34872157
// loaderContext.resourcePath = "/absolute/path/to/app/js/page-home.js"
loaderUtils.interpolateName(loaderContext, "script-[1].[ext]", { regExp: "page-(.*)\\.js", content: ... });
// => script-home.js
// loaderContext.resourcePath = "/absolute/path/to/app/js/javascript.js"
// loaderContext.resourceQuery = "?foo=bar"
loaderUtils.interpolateName(
loaderContext,
(resourcePath, resourceQuery) => {
// resourcePath - `/app/js/javascript.js`
// resourceQuery - `?foo=bar`
return "js/[hash].script.[ext]";
},
{ content: ... }
);
// => js/9473fdd0d880a43c21b7778d34872157.script.js
```
### `getHashDigest`
``` javascript
const digestString = loaderUtils.getHashDigest(buffer, hashType, digestType, maxLength);
```
* `buffer` the content that should be hashed
* `hashType` one of `sha1`, `md4`, `md5`, `sha256`, `sha512` or any other node.js supported hash type
* `digestType` one of `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
* `maxLength` the maximum length in chars
## License
MIT (http://www.opensource.org/licenses/mit-license.php)

View file

@ -0,0 +1,16 @@
'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;

View file

@ -0,0 +1,91 @@
'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;
}
let createMd4 = undefined;
let BatchedHash = undefined;
function getHashDigest(buffer, hashType, digestType, maxLength) {
hashType = hashType || 'md4';
maxLength = maxLength || 9999;
let hash;
try {
hash = require('crypto').createHash(hashType);
} catch (error) {
if (error.code === 'ERR_OSSL_EVP_UNSUPPORTED' && hashType === 'md4') {
if (createMd4 === undefined) {
createMd4 = require('./hash/md4');
if (BatchedHash === undefined) {
BatchedHash = require('./hash/BatchedHash');
}
}
hash = new BatchedHash(createMd4());
}
if (!hash) {
throw error;
}
}
hash.update(buffer);
if (
digestType === 'base26' ||
digestType === 'base32' ||
digestType === 'base36' ||
digestType === 'base49' ||
digestType === 'base52' ||
digestType === 'base58' ||
digestType === 'base62'
) {
return encodeBufferToBase(hash.digest(), digestType.substr(4)).substr(
0,
maxLength
);
} else {
return hash.digest(digestType || 'hex').substr(0, maxLength);
}
}
module.exports = getHashDigest;

View file

@ -0,0 +1,20 @@
'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 {};
}
return query;
}
module.exports = getOptions;

View file

@ -0,0 +1,16 @@
'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;

View file

@ -0,0 +1,64 @@
const MAX_SHORT_STRING = require('./wasm-hash').MAX_SHORT_STRING;
class BatchedHash {
constructor(hash) {
this.string = undefined;
this.encoding = undefined;
this.hash = hash;
}
/**
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
* @param {string|Buffer} data data
* @param {string=} inputEncoding data encoding
* @returns {this} updated hash
*/
update(data, inputEncoding) {
if (this.string !== undefined) {
if (
typeof data === 'string' &&
inputEncoding === this.encoding &&
this.string.length + data.length < MAX_SHORT_STRING
) {
this.string += data;
return this;
}
this.hash.update(this.string, this.encoding);
this.string = undefined;
}
if (typeof data === 'string') {
if (
data.length < MAX_SHORT_STRING &&
// base64 encoding is not valid since it may contain padding chars
(!inputEncoding || !inputEncoding.startsWith('ba'))
) {
this.string = data;
this.encoding = inputEncoding;
} else {
this.hash.update(data, inputEncoding);
}
} else {
this.hash.update(data);
}
return this;
}
/**
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
* @param {string=} encoding encoding of the return value
* @returns {string|Buffer} digest
*/
digest(encoding) {
if (this.string !== undefined) {
this.hash.update(this.string, this.encoding);
}
return this.hash.digest(encoding);
}
}
module.exports = BatchedHash;

View file

@ -0,0 +1,20 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
'use strict';
const create = require('./wasm-hash');
//#region wasm code: md4 (../../../assembly/hash/md4.asm.ts) --initialMemory 1
const md4 = new WebAssembly.Module(
Buffer.from(
// 2150 bytes
'AGFzbQEAAAABCAJgAX8AYAAAAwUEAQAAAAUDAQABBhoFfwFBAAt/AUEAC38BQQALfwFBAAt/AUEACwciBARpbml0AAAGdXBkYXRlAAIFZmluYWwAAwZtZW1vcnkCAAqFEAQmAEGBxpS6BiQBQYnXtv5+JAJB/rnrxXkkA0H2qMmBASQEQQAkAAvMCgEYfyMBIQojAiEGIwMhByMEIQgDQCAAIAVLBEAgBSgCCCINIAcgBiAFKAIEIgsgCCAHIAUoAgAiDCAKIAggBiAHIAhzcXNqakEDdyIDIAYgB3Nxc2pqQQd3IgEgAyAGc3FzampBC3chAiAFKAIUIg8gASACIAUoAhAiCSADIAEgBSgCDCIOIAYgAyACIAEgA3Nxc2pqQRN3IgQgASACc3FzampBA3ciAyACIARzcXNqakEHdyEBIAUoAiAiEiADIAEgBSgCHCIRIAQgAyAFKAIYIhAgAiAEIAEgAyAEc3FzampBC3ciAiABIANzcXNqakETdyIEIAEgAnNxc2pqQQN3IQMgBSgCLCIVIAQgAyAFKAIoIhQgAiAEIAUoAiQiEyABIAIgAyACIARzcXNqakEHdyIBIAMgBHNxc2pqQQt3IgIgASADc3FzampBE3chBCAPIBAgCSAVIBQgEyAFKAI4IhYgAiAEIAUoAjQiFyABIAIgBSgCMCIYIAMgASAEIAEgAnNxc2pqQQN3IgEgAiAEc3FzampBB3ciAiABIARzcXNqakELdyIDIAkgAiAMIAEgBSgCPCIJIAQgASADIAEgAnNxc2pqQRN3IgEgAiADcnEgAiADcXJqakGZ84nUBWpBA3ciAiABIANycSABIANxcmpqQZnzidQFakEFdyIEIAEgAnJxIAEgAnFyaiASakGZ84nUBWpBCXciAyAPIAQgCyACIBggASADIAIgBHJxIAIgBHFyampBmfOJ1AVqQQ13IgEgAyAEcnEgAyAEcXJqakGZ84nUBWpBA3ciAiABIANycSABIANxcmpqQZnzidQFakEFdyIEIAEgAnJxIAEgAnFyampBmfOJ1AVqQQl3IgMgECAEIAIgFyABIAMgAiAEcnEgAiAEcXJqakGZ84nUBWpBDXciASADIARycSADIARxcmogDWpBmfOJ1AVqQQN3IgIgASADcnEgASADcXJqakGZ84nUBWpBBXciBCABIAJycSABIAJxcmpqQZnzidQFakEJdyIDIBEgBCAOIAIgFiABIAMgAiAEcnEgAiAEcXJqakGZ84nUBWpBDXciASADIARycSADIARxcmpqQZnzidQFakEDdyICIAEgA3JxIAEgA3FyampBmfOJ1AVqQQV3IgQgASACcnEgASACcXJqakGZ84nUBWpBCXciAyAMIAIgAyAJIAEgAyACIARycSACIARxcmpqQZnzidQFakENdyIBcyAEc2pqQaHX5/YGakEDdyICIAQgASACcyADc2ogEmpBodfn9gZqQQl3IgRzIAFzampBodfn9gZqQQt3IgMgAiADIBggASADIARzIAJzampBodfn9gZqQQ93IgFzIARzaiANakGh1+f2BmpBA3ciAiAUIAQgASACcyADc2pqQaHX5/YGakEJdyIEcyABc2pqQaHX5/YGakELdyIDIAsgAiADIBYgASADIARzIAJzampBodfn9gZqQQ93IgFzIARzampBodfn9gZqQQN3IgIgEyAEIAEgAnMgA3NqakGh1+f2BmpBCXciBHMgAXNqakGh1+f2BmpBC3chAyAKIA4gAiADIBcgASADIARzIAJzampBodfn9gZqQQ93IgFzIARzampBodfn9gZqQQN3IgJqIQogBiAJIAEgESADIAIgFSAEIAEgAnMgA3NqakGh1+f2BmpBCXciBHMgAXNqakGh1+f2BmpBC3ciAyAEcyACc2pqQaHX5/YGakEPd2ohBiADIAdqIQcgBCAIaiEIIAVBQGshBQwBCwsgCiQBIAYkAiAHJAMgCCQECw0AIAAQASMAIABqJAAL/wQCA38BfiMAIABqrUIDhiEEIABByABqQUBxIgJBCGshAyAAIgFBAWohACABQYABOgAAA0AgACACSUEAIABBB3EbBEAgAEEAOgAAIABBAWohAAwBCwsDQCAAIAJJBEAgAEIANwMAIABBCGohAAwBCwsgAyAENwMAIAIQAUEAIwGtIgRC//8DgyAEQoCA/P8Pg0IQhoQiBEL/gYCA8B+DIARCgP6DgIDgP4NCCIaEIgRCj4C8gPCBwAeDQgiGIARC8IHAh4CegPgAg0IEiIQiBEKGjJiw4MCBgwZ8QgSIQoGChIiQoMCAAYNCJ34gBEKw4MCBg4aMmDCEfDcDAEEIIwKtIgRC//8DgyAEQoCA/P8Pg0IQhoQiBEL/gYCA8B+DIARCgP6DgIDgP4NCCIaEIgRCj4C8gPCBwAeDQgiGIARC8IHAh4CegPgAg0IEiIQiBEKGjJiw4MCBgwZ8QgSIQoGChIiQoMCAAYNCJ34gBEKw4MCBg4aMmDCEfDcDAEEQIwOtIgRC//8DgyAEQoCA/P8Pg0IQhoQiBEL/gYCA8B+DIARCgP6DgIDgP4NCCIaEIgRCj4C8gPCBwAeDQgiGIARC8IHAh4CegPgAg0IEiIQiBEKGjJiw4MCBgwZ8QgSIQoGChIiQoMCAAYNCJ34gBEKw4MCBg4aMmDCEfDcDAEEYIwStIgRC//8DgyAEQoCA/P8Pg0IQhoQiBEL/gYCA8B+DIARCgP6DgIDgP4NCCIaEIgRCj4C8gPCBwAeDQgiGIARC8IHAh4CegPgAg0IEiIQiBEKGjJiw4MCBgwZ8QgSIQoGChIiQoMCAAYNCJ34gBEKw4MCBg4aMmDCEfDcDAAs=',
'base64'
)
);
//#endregion
module.exports = create.bind(null, md4, [], 64, 32);

View file

@ -0,0 +1,208 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
'use strict';
// 65536 is the size of a wasm memory page
// 64 is the maximum chunk size for every possible wasm hash implementation
// 4 is the maximum number of bytes per char for string encoding (max is utf-8)
// ~3 makes sure that it's always a block of 4 chars, so avoid partially encoded bytes for base64
const MAX_SHORT_STRING = Math.floor((65536 - 64) / 4) & ~3;
class WasmHash {
/**
* @param {WebAssembly.Instance} instance wasm instance
* @param {WebAssembly.Instance[]} instancesPool pool of instances
* @param {number} chunkSize size of data chunks passed to wasm
* @param {number} digestSize size of digest returned by wasm
*/
constructor(instance, instancesPool, chunkSize, digestSize) {
const exports = /** @type {any} */ (instance.exports);
exports.init();
this.exports = exports;
this.mem = Buffer.from(exports.memory.buffer, 0, 65536);
this.buffered = 0;
this.instancesPool = instancesPool;
this.chunkSize = chunkSize;
this.digestSize = digestSize;
}
reset() {
this.buffered = 0;
this.exports.init();
}
/**
* @param {Buffer | string} data data
* @param {BufferEncoding=} encoding encoding
* @returns {this} itself
*/
update(data, encoding) {
if (typeof data === 'string') {
while (data.length > MAX_SHORT_STRING) {
this._updateWithShortString(data.slice(0, MAX_SHORT_STRING), encoding);
data = data.slice(MAX_SHORT_STRING);
}
this._updateWithShortString(data, encoding);
return this;
}
this._updateWithBuffer(data);
return this;
}
/**
* @param {string} data data
* @param {BufferEncoding=} encoding encoding
* @returns {void}
*/
_updateWithShortString(data, encoding) {
const { exports, buffered, mem, chunkSize } = this;
let endPos;
if (data.length < 70) {
if (!encoding || encoding === 'utf-8' || encoding === 'utf8') {
endPos = buffered;
for (let i = 0; i < data.length; i++) {
const cc = data.charCodeAt(i);
if (cc < 0x80) {
mem[endPos++] = cc;
} else if (cc < 0x800) {
mem[endPos] = (cc >> 6) | 0xc0;
mem[endPos + 1] = (cc & 0x3f) | 0x80;
endPos += 2;
} else {
// bail-out for weird chars
endPos += mem.write(data.slice(i), endPos, encoding);
break;
}
}
} else if (encoding === 'latin1') {
endPos = buffered;
for (let i = 0; i < data.length; i++) {
const cc = data.charCodeAt(i);
mem[endPos++] = cc;
}
} else {
endPos = buffered + mem.write(data, buffered, encoding);
}
} else {
endPos = buffered + mem.write(data, buffered, encoding);
}
if (endPos < chunkSize) {
this.buffered = endPos;
} else {
const l = endPos & ~(this.chunkSize - 1);
exports.update(l);
const newBuffered = endPos - l;
this.buffered = newBuffered;
if (newBuffered > 0) {
mem.copyWithin(0, l, endPos);
}
}
}
/**
* @param {Buffer} data data
* @returns {void}
*/
_updateWithBuffer(data) {
const { exports, buffered, mem } = this;
const length = data.length;
if (buffered + length < this.chunkSize) {
data.copy(mem, buffered, 0, length);
this.buffered += length;
} else {
const l = (buffered + length) & ~(this.chunkSize - 1);
if (l > 65536) {
let i = 65536 - buffered;
data.copy(mem, buffered, 0, i);
exports.update(65536);
const stop = l - buffered - 65536;
while (i < stop) {
data.copy(mem, 0, i, i + 65536);
exports.update(65536);
i += 65536;
}
data.copy(mem, 0, i, l - buffered);
exports.update(l - buffered - i);
} else {
data.copy(mem, buffered, 0, l - buffered);
exports.update(l);
}
const newBuffered = length + buffered - l;
this.buffered = newBuffered;
if (newBuffered > 0) {
data.copy(mem, 0, length - newBuffered, length);
}
}
}
digest(type) {
const { exports, buffered, mem, digestSize } = this;
exports.final(buffered);
this.instancesPool.push(this);
const hex = mem.toString('latin1', 0, digestSize);
if (type === 'hex') {
return hex;
}
if (type === 'binary' || !type) {
return Buffer.from(hex, 'hex');
}
return Buffer.from(hex, 'hex').toString(type);
}
}
const create = (wasmModule, instancesPool, chunkSize, digestSize) => {
if (instancesPool.length > 0) {
const old = instancesPool.pop();
old.reset();
return old;
} else {
return new WasmHash(
new WebAssembly.Instance(wasmModule),
instancesPool,
chunkSize,
digestSize
);
}
};
module.exports = create;
module.exports.MAX_SHORT_STRING = MAX_SHORT_STRING;

View file

@ -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;

View file

@ -0,0 +1,151 @@
'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 {
if (!emojiList.length) {
throw new Error('Ran out of emoji');
}
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;
const hasQuery =
loaderContext.resourceQuery && loaderContext.resourceQuery.length > 1;
if (typeof name === 'function') {
filename = name(
loaderContext.resourcePath,
hasQuery ? loaderContext.resourceQuery : undefined
);
} 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 = '';
let query = '';
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);
}
}
if (loaderContext.resourceQuery && loaderContext.resourceQuery.length > 1) {
query = loaderContext.resourceQuery;
const hashIdx = query.indexOf('#');
if (hashIdx >= 0) {
query = query.substr(0, hashIdx);
}
}
let url = filename;
if (content) {
// Match hash template
url = url
// `hash` and `contenthash` are same in `loader-utils` context
// let's keep `hash` for backward compatibility
.replace(
/\[(?:([^[:\]]+):)?(?:hash|contenthash)(?::([a-z]+\d*))?(?::(\d+))?\]/gi,
(all, hashType, digestType, maxLength) =>
getHashDigest(content, hashType, digestType, parseInt(maxLength, 10))
)
.replace(/\[emoji(?::(\d+))?\]/gi, (all, length) =>
encodeStringToEmoji(content, parseInt(length, 10))
);
}
url = url
.replace(/\[ext\]/gi, () => ext)
.replace(/\[name\]/gi, () => basename)
.replace(/\[path\]/gi, () => directory)
.replace(/\[folder\]/gi, () => folder)
.replace(/\[query\]/gi, () => query);
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;

View file

@ -0,0 +1,31 @@
'use strict';
const path = require('path');
function isUrlRequest(url, root) {
// An URL is not an request if
// 1. It's an absolute url and it is not `windows` path like `C:\dir\file`
if (/^[a-z][a-z0-9+.-]*:/i.test(url) && !path.win32.isAbsolute(url)) {
return false;
}
// 2. It's a protocol-relative
if (/^\/\//.test(url)) {
return false;
}
// 3. It's some kind of url for a template
if (/^[{}[\]#*;,'§$%&(=?`´^°<>]/.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;

View file

@ -0,0 +1,69 @@
'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 = Object.create(null);
queryArgs.forEach((arg) => {
const idx = arg.indexOf('=');
if (idx >= 0) {
let name = arg.substr(0, idx);
let value = decodeURIComponent(arg.substr(idx + 1));
// eslint-disable-next-line no-prototype-builtins
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;

View file

@ -0,0 +1,23 @@
'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;

View file

@ -0,0 +1,51 @@
'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(/^(.*?)(\?.*)/);
const query = splittedPart ? splittedPart[2] : '';
let singlePath = splittedPart ? splittedPart[1] : part;
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;

View file

@ -0,0 +1,60 @@
'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) {
// Do not rewrite an empty url
if (url === '') {
return '';
}
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;

View file

@ -0,0 +1,39 @@
{
"name": "loader-utils",
"version": "2.0.4",
"author": "Tobias Koppers @sokra",
"description": "utils for webpack loaders",
"dependencies": {
"big.js": "^5.2.2",
"emojis-list": "^3.0.0",
"json5": "^2.1.2"
},
"scripts": {
"lint": "eslint lib test",
"pretest": "yarn lint",
"test": "jest",
"test:ci": "jest --coverage",
"release": "yarn test && standard-version"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/webpack/loader-utils.git"
},
"engines": {
"node": ">=8.9.0"
},
"devDependencies": {
"coveralls": "^3.0.9",
"eslint": "^6.8.0",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-prettier": "^3.1.2",
"jest": "^25.1.0",
"prettier": "^1.19.1",
"standard-version": "^7.1.0"
},
"main": "lib/index.js",
"files": [
"lib"
]
}

38
my-app/node_modules/adjust-sourcemap-loader/package.json generated vendored Executable file
View file

@ -0,0 +1,38 @@
{
"name": "adjust-sourcemap-loader",
"version": "4.0.0",
"description": "Webpack loader that adjusts source maps",
"main": "index.js",
"engines": {
"node": ">=8.9"
},
"repository": {
"type": "git",
"url": "git+https://github.com/bholloway/adjust-sourcemap-loader.git"
},
"keywords": [
"webpack",
"loader",
"source-map",
"sourcemap",
"sources",
"resolve",
"adjust"
],
"author": "bholloway",
"license": "MIT",
"bugs": {
"url": "https://github.com/bholloway/adjust-sourcemap-loader/issues"
},
"homepage": "https://github.com/bholloway/adjust-sourcemap-loader",
"dependencies": {
"loader-utils": "^2.0.0",
"regex-parser": "^2.2.11"
},
"devDependencies": {
"jshint": "^2.12.0"
},
"scripts": {
"lint": "jshint index.js lib codec"
}
}

143
my-app/node_modules/adjust-sourcemap-loader/readme.md generated vendored Executable file
View file

@ -0,0 +1,143 @@
# Adjust Source-map Loader
[![NPM](https://nodei.co/npm/adjust-sourcemap-loader.png)](http://github.com/bholloway/adjust-sourcemap-loader)
Webpack loader that adjusts source maps.
Use as a **loader** to debug source-maps or to adjust source-maps between other loaders.
Use as a **module filename template** to ensure the final source-map are to your liking.
## Usage : Loader
``` javascript
require('adjust-sourcemap?format=absolute!babel?sourceMap');
```
### Source maps required
Note that **source maps** must be enabled on any preceding loader. In the above example we use `babel?sourceMap`.
### Apply via webpack config
It is preferable to adjust your `webpack.config` so to avoid having to prefix every `require()` statement:
``` javascript
module.exports = {
module: {
loaders: [
{
test : /\.js/,
loaders: ['adjust-sourcemap?format=absolute', 'babel?sourceMap']
}
]
}
};
```
## Usage : Module filename template
Specifying a certain format as the final step in a loader chain will **not** influence the final source format that Webpack will output. Instead the format is determined by the **module filename template**.
There are limitations to the filename templating that Webpack provides. This package may also operate as a custom template function that will convert output source-map sources to the desired `format`.
In the following example we ensure project-relative source-map sources are output.
```javascript
var templateFn = require('adjust-sourcemap-loader')
.moduleFilenameTemplate({
format: 'projectRelative'
});
module.exports = {
output: {
...
devtoolModuleFilenameTemplate : templateFn,
devtoolFallbackModuleFilenameTemplate: templateFn
}
};
```
## Options
As a loader, options may be set using [query parameters](https://webpack.github.io/docs/using-loaders.html#query-parameters) or by using [programmatic parameters](https://webpack.github.io/docs/how-to-write-a-loader.html#programmable-objects-as-query-option). Programmatic means the following in your `webpack.config`.
```javascript
module.exports = {
adjustSourcemapLoader: {
...
}
}
```
Where `...` is a hash of any of the following options.
* **`debug`** : `boolean|RegExp` May be used alone (boolean) or with a `RegExp` to match the resource(s) you are interested in debugging.
* **`fail`** : `boolean` Implies an **Error** if a source-map source cannot be decoded.
* **`format`** : `string` Optional output format for source-map `sources`. Must be the name of one of the available `codecs`. Omitting the format will result in **no change** and the outgoing source-map will match the incomming one.
* **`root`** : `boolean` A boolean flag that indices that a `sourceRoot` path sould be included in the output map. This is contingent on a `format` being specified.
* **`codecs`** : `Array.<{name:string, decode:function, encode:function, root:function}>` Optional Array of codecs. There are a number of built-in codecs available. If you specify you own codecs you will loose those that are built-in. However you can include them from the `codec/` directory.
Note that **query** parameters take precedence over **programmatic** parameters.
### Changing the format
Built-in codecs that may be specified as a `format` include:
* `absolute`
* `outputRelative`
* `projectRelative`
* `webpackProtocol`
* `sourceRelative` (works for loader only, **not** Module filename template)
### Specifying codecs
There are additional built-in codecs that do not support encoding. These are still necessary to decode source-map sources. If you specify your own `options.codecs` then you should **also include the built-in codecs**. Otherwise you will find that some sources cannot be decoded.
The existing codecs may be found in `/codec`, or on the loader itself:
```javascript
var inBuiltCodecs = require('adjust-sourcemap-loader').codecs,
myCodecs = [
{
name : 'foo',
decode: function(uri) {...},
encode: function(absolute) {...},
root : function() {...}
},
...
];
module.exports = {
adjustSourcemapLoader: {
codecs: inBuiltCodecs.concat(myCodecs)
}
}
```
The codec **order is important**. Those that come first have precedence. Any codec that detects a distinct URI should be foremost so that illegal paths are not encountered by successive codecs.
### Abstract codecs
A codec that detects generated code and cannot `decode()` a URI to an absolute file path.
Instead of implementing `encode()` or `root()` it should instead specify `abstract:true`. Its `decode()` function then may return `boolean` where it detects such generated sources.
For example, a built-in abstract codec will match the **Webpack bootstrap** code and ensure that its illegal source uri is not encountered by later coders.
## How it works
The loader will receive a source map as its second parameter, so long as the preceding loader was using source-maps.
The exception is the **css-loader** where the source-map is in the content, which is **not currently supported** .
The source-map `sources` are parsed by applying **codec.decode()** functions until one of them returns an absolute path to a file that exists. The exception is abstract codecs, where the source with remain unchanged.
If a format is specified then the source-map `sources` are recreated by applying the **codec.encode()** function for the stated `format` and (where the `root` option is specified) the **codec.root()** function will set the source-map `sourceRoot`.
If a codec does not specify **codec.encode()** or **codec.root()** then it may **not** be used as the `format`.