including-modules
This commit is contained in:
Generated
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Prepend file:// protocol to source path string or source-map sources.
|
||||
*/
|
||||
export declare function prepend(candidate: any): any;
|
||||
/**
|
||||
* Remove file:// protocol from source path string or source-map sources.
|
||||
*/
|
||||
export declare function remove(candidate: any): any;
|
||||
Generated
Vendored
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 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.
|
||||
*/ /**
|
||||
* Prepend file:// protocol to source path string or source-map sources.
|
||||
*/ "use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
0 && (module.exports = {
|
||||
prepend: null,
|
||||
remove: null
|
||||
});
|
||||
function _export(target, all) {
|
||||
for(var name in all)Object.defineProperty(target, name, {
|
||||
enumerable: true,
|
||||
get: all[name]
|
||||
});
|
||||
}
|
||||
_export(exports, {
|
||||
prepend: function() {
|
||||
return prepend;
|
||||
},
|
||||
remove: function() {
|
||||
return remove;
|
||||
}
|
||||
});
|
||||
function prepend(candidate) {
|
||||
if (typeof candidate === 'string') {
|
||||
return 'file://' + candidate;
|
||||
} else if (candidate && typeof candidate === 'object' && Array.isArray(candidate.sources)) {
|
||||
return Object.assign({}, candidate, {
|
||||
sources: candidate.sources.map(prepend)
|
||||
});
|
||||
} else {
|
||||
throw Object.defineProperty(new Error('expected string|object'), "__NEXT_ERROR_CODE", {
|
||||
value: "E489",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
}
|
||||
function remove(candidate) {
|
||||
if (typeof candidate === 'string') {
|
||||
return candidate.replace(/^file:\/{2}/, '');
|
||||
} else if (candidate && typeof candidate === 'object' && Array.isArray(candidate.sources)) {
|
||||
return Object.assign({}, candidate, {
|
||||
sources: candidate.sources.map(remove)
|
||||
});
|
||||
} else {
|
||||
throw Object.defineProperty(new Error('expected string|object'), "__NEXT_ERROR_CODE", {
|
||||
value: "E489",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=file-protocol.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../../../src/build/webpack/loaders/resolve-url-loader/lib/file-protocol.ts"],"sourcesContent":["/*\nThe MIT License (MIT)\n\nCopyright (c) 2016 Ben Holloway\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n*/\n\n/**\n * Prepend file:// protocol to source path string or source-map sources.\n */\nexport function prepend(candidate: any) {\n if (typeof candidate === 'string') {\n return 'file://' + candidate\n } else if (\n candidate &&\n typeof candidate === 'object' &&\n Array.isArray(candidate.sources)\n ) {\n return Object.assign({}, candidate, {\n sources: candidate.sources.map(prepend),\n })\n } else {\n throw new Error('expected string|object')\n }\n}\n\n/**\n * Remove file:// protocol from source path string or source-map sources.\n */\nexport function remove(candidate: any) {\n if (typeof candidate === 'string') {\n return candidate.replace(/^file:\\/{2}/, '')\n } else if (\n candidate &&\n typeof candidate === 'object' &&\n Array.isArray(candidate.sources)\n ) {\n return Object.assign({}, candidate, {\n sources: candidate.sources.map(remove),\n })\n } else {\n throw new Error('expected string|object')\n }\n}\n"],"names":["prepend","remove","candidate","Array","isArray","sources","Object","assign","map","Error","replace"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;AAsBA,GAEA;;CAEC;;;;;;;;;;;;;;;IACeA,OAAO;eAAPA;;IAmBAC,MAAM;eAANA;;;AAnBT,SAASD,QAAQE,SAAc;IACpC,IAAI,OAAOA,cAAc,UAAU;QACjC,OAAO,YAAYA;IACrB,OAAO,IACLA,aACA,OAAOA,cAAc,YACrBC,MAAMC,OAAO,CAACF,UAAUG,OAAO,GAC/B;QACA,OAAOC,OAAOC,MAAM,CAAC,CAAC,GAAGL,WAAW;YAClCG,SAASH,UAAUG,OAAO,CAACG,GAAG,CAACR;QACjC;IACF,OAAO;QACL,MAAM,qBAAmC,CAAnC,IAAIS,MAAM,2BAAV,qBAAA;mBAAA;wBAAA;0BAAA;QAAkC;IAC1C;AACF;AAKO,SAASR,OAAOC,SAAc;IACnC,IAAI,OAAOA,cAAc,UAAU;QACjC,OAAOA,UAAUQ,OAAO,CAAC,eAAe;IAC1C,OAAO,IACLR,aACA,OAAOA,cAAc,YACrBC,MAAMC,OAAO,CAACF,UAAUG,OAAO,GAC/B;QACA,OAAOC,OAAOC,MAAM,CAAC,CAAC,GAAGL,WAAW;YAClCG,SAASH,UAAUG,OAAO,CAACG,GAAG,CAACP;QACjC;IACF,OAAO;QACL,MAAM,qBAAmC,CAAnC,IAAIQ,MAAM,2BAAV,qBAAA;mBAAA;wBAAA;0BAAA;QAAkC;IAC1C;AACF","ignoreList":[0]}
|
||||
Generated
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* The default join function iterates over possible base paths until a suitable join is found.
|
||||
*
|
||||
* The first base path is used as fallback for the case where none of the base paths can locate the actual file.
|
||||
*
|
||||
* @type {function}
|
||||
*/
|
||||
export declare const defaultJoin: ((filename: string, options: {
|
||||
debug?: any | boolean;
|
||||
root: string;
|
||||
}) => (
|
||||
/** A uri path, relative or absolute */
|
||||
uri: string,
|
||||
/** Optional absolute base path or iterator thereof */
|
||||
baseOrIteratorOrAbsent: any) => any) & ("" | {
|
||||
valueOf: () => string;
|
||||
toString: () => string;
|
||||
});
|
||||
Generated
Vendored
+190
@@ -0,0 +1,190 @@
|
||||
// TODO: Remove use of `any` type.
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 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.
|
||||
*/ "use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "defaultJoin", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return defaultJoin;
|
||||
}
|
||||
});
|
||||
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
||||
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
||||
function _interop_require_default(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
const compose = (f, g)=>(...args)=>f(g(...args));
|
||||
const simpleJoin = compose(_path.default.normalize, _path.default.join);
|
||||
const defaultJoin = createJoinForPredicate(function predicate(_, uri, base, i, next) {
|
||||
const absolute = simpleJoin(base, uri);
|
||||
return _fs.default.existsSync(absolute) ? absolute : next(i === 0 ? absolute : null);
|
||||
}, 'defaultJoin');
|
||||
function* createIterator(arr) {
|
||||
for (const i of arr){
|
||||
yield i;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Define a join function by a predicate that tests possible base paths from an iterator.
|
||||
*
|
||||
* The `predicate` is of the form:
|
||||
*
|
||||
* ```
|
||||
* function(filename, uri, base, i, next):string|null
|
||||
* ```
|
||||
*
|
||||
* Given the uri and base it should either return:
|
||||
* - an absolute path success
|
||||
* - a call to `next(null)` as failure
|
||||
* - a call to `next(absolute)` where absolute is placeholder and the iterator continues
|
||||
*
|
||||
* The value given to `next(...)` is only used if success does not eventually occur.
|
||||
*
|
||||
* The `file` value is typically unused but useful if you would like to differentiate behaviour.
|
||||
*
|
||||
* You can write a much simpler function than this if you have specific requirements.
|
||||
*
|
||||
*/ function createJoinForPredicate(/** predicate A function that tests values */ predicate, /** Optional name for the resulting join function */ name) {
|
||||
/**
|
||||
* A factory for a join function with logging.
|
||||
*/ function join(/** The current file being processed */ filename, /** An options hash */ options) {
|
||||
const log = createDebugLogger(options.debug);
|
||||
/**
|
||||
* Join function proper.
|
||||
*
|
||||
* For absolute uri only `uri` will be provided. In this case we substitute any `root` given in options.
|
||||
*
|
||||
* Returns Just the uri where base is empty or the uri appended to the base
|
||||
*/ return function joinProper(/** A uri path, relative or absolute */ uri, /** Optional absolute base path or iterator thereof */ baseOrIteratorOrAbsent) {
|
||||
const iterator = typeof baseOrIteratorOrAbsent === 'undefined' && createIterator([
|
||||
options.root
|
||||
]) || typeof baseOrIteratorOrAbsent === 'string' && createIterator([
|
||||
baseOrIteratorOrAbsent
|
||||
]) || baseOrIteratorOrAbsent;
|
||||
const result = runIterator([]);
|
||||
log(createJoinMsg, [
|
||||
filename,
|
||||
uri,
|
||||
result,
|
||||
result.isFound
|
||||
]);
|
||||
return typeof result.absolute === 'string' ? result.absolute : uri;
|
||||
function runIterator(accumulator) {
|
||||
const nextItem = iterator.next();
|
||||
var base = !nextItem.done && nextItem.value;
|
||||
if (typeof base === 'string') {
|
||||
const element = predicate(filename, uri, base, accumulator.length, next);
|
||||
if (typeof element === 'string' && _path.default.isAbsolute(element)) {
|
||||
return Object.assign(accumulator.concat(base), {
|
||||
isFound: true,
|
||||
absolute: element
|
||||
});
|
||||
} else if (Array.isArray(element)) {
|
||||
return element;
|
||||
} else {
|
||||
throw Object.defineProperty(new Error('predicate must return an absolute path or the result of calling next()'), "__NEXT_ERROR_CODE", {
|
||||
value: "E313",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return accumulator;
|
||||
}
|
||||
function next(fallback) {
|
||||
return runIterator(Object.assign(accumulator.concat(base), typeof fallback === 'string' && {
|
||||
absolute: fallback
|
||||
}));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
function toString() {
|
||||
return '[Function: ' + name + ']';
|
||||
}
|
||||
return Object.assign(join, name && {
|
||||
valueOf: toString,
|
||||
toString: toString
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Format a debug message.
|
||||
* Return Formatted message
|
||||
*/ function createJoinMsg(/** The file being processed by webpack */ file, /** A uri path, relative or absolute */ uri, /** Absolute base paths up to and including the found one */ bases, /** Indicates the last base was correct */ isFound) {
|
||||
return [
|
||||
'resolve-url-loader: ' + pathToString(file) + ': ' + uri,
|
||||
//
|
||||
...bases.map(pathToString).filter(Boolean),
|
||||
...isFound ? [
|
||||
'FOUND'
|
||||
] : [
|
||||
'NOT FOUND'
|
||||
]
|
||||
].join('\n ');
|
||||
/**
|
||||
* If given path is within `process.cwd()` then show relative posix path, otherwise show absolute posix path.
|
||||
*
|
||||
* Returns A relative or absolute path
|
||||
*/ function pathToString(/** An absolute path */ absolute) {
|
||||
if (!absolute) {
|
||||
return null;
|
||||
} else {
|
||||
const relative = _path.default.relative(process.cwd(), absolute).split(_path.default.sep);
|
||||
return (relative[0] === '..' ? absolute.split(_path.default.sep) : [
|
||||
'.'
|
||||
].concat(relative).filter(Boolean)).join('/');
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.createJoinMsg = createJoinMsg;
|
||||
/**
|
||||
* A factory for a log function predicated on the given debug parameter.
|
||||
*
|
||||
* The logging function created accepts a function that formats a message and parameters that the function utilises.
|
||||
* Presuming the message function may be expensive we only call it if logging is enabled.
|
||||
*
|
||||
* The log messages are de-duplicated based on the parameters, so it is assumed they are simple types that stringify
|
||||
* well.
|
||||
*
|
||||
* Returns A logging function possibly degenerate
|
||||
*/ function createDebugLogger(/** A boolean or debug function */ debug) {
|
||||
const log = !!debug && (typeof debug === 'function' ? debug : console.log);
|
||||
const cache = {};
|
||||
return log ? actuallyLog : noop;
|
||||
function noop() {}
|
||||
function actuallyLog(msgFn, params) {
|
||||
const key = JSON.stringify(params);
|
||||
if (!cache[key]) {
|
||||
cache[key] = true;
|
||||
log(msgFn.apply(null, params));
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.createDebugLogger = createDebugLogger;
|
||||
|
||||
//# sourceMappingURL=join-function.js.map
|
||||
Generated
Vendored
+1
File diff suppressed because one or more lines are too long
+1
@@ -0,0 +1 @@
|
||||
export default function process(postcss: any, sourceFile: any, sourceContent: any, params: any): any;
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 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.
|
||||
*/ "use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return process;
|
||||
}
|
||||
});
|
||||
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
||||
const _fileprotocol = require("./file-protocol");
|
||||
function _interop_require_default(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
const ORPHAN_CR_REGEX = /\r(?!\n)(.|\n)?/g;
|
||||
function process(postcss, sourceFile, sourceContent, params) {
|
||||
// #107 libsass emits orphan CR not considered newline, postcss does consider newline (content vs source-map mismatch)
|
||||
postcssPlugin.postcss = true;
|
||||
// prepend file protocol to all sources to avoid problems with source map
|
||||
return postcss([
|
||||
postcssPlugin
|
||||
]).process(sourceContent, {
|
||||
from: (0, _fileprotocol.prepend)(sourceFile),
|
||||
map: params.outputSourceMap && {
|
||||
prev: !!params.inputSourceMap && (0, _fileprotocol.prepend)(params.inputSourceMap),
|
||||
inline: false,
|
||||
annotation: false,
|
||||
sourcesContent: true
|
||||
}
|
||||
}).then((result)=>({
|
||||
content: result.css,
|
||||
map: params.outputSourceMap ? (0, _fileprotocol.remove)(result.map.toJSON()) : null
|
||||
}));
|
||||
/**
|
||||
* Plugin for postcss that follows SASS transpilation.
|
||||
*/ function postcssPlugin() {
|
||||
return {
|
||||
postcssPlugin: 'postcss-resolve-url',
|
||||
Once: function(root) {
|
||||
root.walkDecls(eachDeclaration);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Process a declaration from the syntax tree.
|
||||
* @param declaration
|
||||
*/ function eachDeclaration(declaration) {
|
||||
const isValid = declaration.value && declaration.value.indexOf('url') >= 0;
|
||||
if (isValid) {
|
||||
// reverse the original source-map to find the original source file before transpilation
|
||||
const startPosApparent = declaration.source.start, startPosOriginal = params.sourceMapConsumer && params.sourceMapConsumer.originalPositionFor(startPosApparent);
|
||||
// we require a valid directory for the specified file
|
||||
const directory = startPosOriginal && startPosOriginal.source && (0, _fileprotocol.remove)(_path.default.dirname(startPosOriginal.source));
|
||||
if (directory) {
|
||||
declaration.value = params.transformDeclaration(declaration.value, directory);
|
||||
} else if (params.sourceMapConsumer) {
|
||||
throw Object.defineProperty(new Error('source-map information is not available at url() declaration ' + (ORPHAN_CR_REGEX.test(sourceContent) ? '(found orphan CR, try removeCR option)' : '(no orphan CR found)')), "__NEXT_ERROR_CODE", {
|
||||
value: "E34",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=postcss.js.map
|
||||
Generated
Vendored
+1
File diff suppressed because one or more lines are too long
Generated
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
declare function valueProcessor(filename: any, options: any): (
|
||||
/** A declaration value that may or may not contain a url() statement */
|
||||
value: string,
|
||||
/** An absolute path that may be the correct base or an Iterator thereof */
|
||||
candidate: any) => string;
|
||||
export default valueProcessor;
|
||||
Generated
Vendored
+97
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 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.
|
||||
*/ "use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
const _loaderutils2 = /*#__PURE__*/ _interop_require_default(require("next/dist/compiled/loader-utils2"));
|
||||
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
||||
function _interop_require_default(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
function valueProcessor(filename, options) {
|
||||
const URL_STATEMENT_REGEX = /(url\s*\()\s*(?:(['"])((?:(?!\2).)*)(\2)|([^'"](?:(?!\)).)*[^'"]))\s*(\))/g;
|
||||
const directory = _path.default.dirname(filename);
|
||||
const join = options.join(filename, options);
|
||||
/**
|
||||
* Process the given CSS declaration value.
|
||||
*
|
||||
*/ return function transformValue(/** A declaration value that may or may not contain a url() statement */ value, /** An absolute path that may be the correct base or an Iterator thereof */ candidate) {
|
||||
// allow multiple url() values in the declaration
|
||||
// split by url statements and process the content
|
||||
// additional capture groups are needed to match quotations correctly
|
||||
// escaped quotations are not considered
|
||||
return value.split(URL_STATEMENT_REGEX).map((token, i, arr)=>{
|
||||
// we can get groups as undefined under certain match circumstances
|
||||
const initialised = token || '';
|
||||
// the content of the url() statement is either in group 3 or group 5
|
||||
const mod = i % 7;
|
||||
if (mod === 3 || mod === 5) {
|
||||
// detect quoted url and unescape backslashes
|
||||
const before = arr[i - 1], after = arr[i + 1], isQuoted = before === after && (before === "'" || before === '"'), unescaped = isQuoted ? initialised.replace(/\\{2}/g, '\\') : initialised;
|
||||
// split into uri and query/hash and then find the absolute path to the uri
|
||||
const split = unescaped.split(/([?#])/g), uri = split[0], absolute = testIsRelative(uri) && join(uri, candidate) || testIsAbsolute(uri) && join(uri), query = options.keepQuery ? split.slice(1).join('') : '';
|
||||
// use the absolute path in absolute mode or else relative path (or default to initialised)
|
||||
// #6 - backslashes are not legal in URI
|
||||
if (!absolute) {
|
||||
return initialised;
|
||||
} else if (options.absolute) {
|
||||
return absolute.replace(/\\/g, '/') + query;
|
||||
} else {
|
||||
return _loaderutils2.default.urlToRequest(_path.default.relative(directory, absolute).replace(/\\/g, '/') + query);
|
||||
}
|
||||
} else {
|
||||
return initialised;
|
||||
}
|
||||
}).join('');
|
||||
};
|
||||
/**
|
||||
* The loaderUtils.isUrlRequest() doesn't support windows absolute paths on principle. We do not subscribe to that
|
||||
* dogma so we add path.isAbsolute() check to allow them.
|
||||
*
|
||||
* We also eliminate module relative (~) paths.
|
||||
*
|
||||
* Returns true for relative uri
|
||||
*/ function testIsRelative(/** A uri string possibly empty or undefined */ uri) {
|
||||
return !!uri && _loaderutils2.default.isUrlRequest(uri, false) && !_path.default.isAbsolute(uri) && uri.indexOf('~') !== 0;
|
||||
}
|
||||
/**
|
||||
* The loaderUtils.isUrlRequest() doesn't support windows absolute paths on principle. We do not subscribe to that
|
||||
* dogma so we add path.isAbsolute() check to allow them.
|
||||
*
|
||||
* Returns true for absolute uri
|
||||
*/ function testIsAbsolute(/** A uri string possibly empty or undefined */ uri) {
|
||||
return !!uri && typeof options.root === 'string' && _loaderutils2.default.isUrlRequest(uri, options.root) && (/^\//.test(uri) || _path.default.isAbsolute(uri));
|
||||
}
|
||||
}
|
||||
const _default = valueProcessor;
|
||||
|
||||
//# sourceMappingURL=value-processor.js.map
|
||||
Generated
Vendored
+1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user