format: prettify entire project
This commit is contained in:
131
node_modules/clean-css/lib/reader/apply-source-maps.js
generated
vendored
131
node_modules/clean-css/lib/reader/apply-source-maps.js
generated
vendored
@ -26,12 +26,12 @@ function applySourceMaps(tokens, context, callback) {
|
||||
processedTokens: [],
|
||||
rebaseTo: context.options.rebaseTo,
|
||||
sourceTokens: tokens,
|
||||
warnings: context.warnings
|
||||
warnings: context.warnings,
|
||||
};
|
||||
|
||||
return context.options.sourceMap && tokens.length > 0 ?
|
||||
doApplySourceMaps(applyContext) :
|
||||
callback(tokens);
|
||||
doApplySourceMaps(applyContext)
|
||||
: callback(tokens);
|
||||
}
|
||||
|
||||
function doApplySourceMaps(applyContext) {
|
||||
@ -41,7 +41,11 @@ function doApplySourceMaps(applyContext) {
|
||||
var token;
|
||||
var l;
|
||||
|
||||
for (l = applyContext.sourceTokens.length; applyContext.index < l; applyContext.index++) {
|
||||
for (
|
||||
l = applyContext.sourceTokens.length;
|
||||
applyContext.index < l;
|
||||
applyContext.index++
|
||||
) {
|
||||
token = applyContext.sourceTokens[applyContext.index];
|
||||
source = findTokenSource(token);
|
||||
|
||||
@ -54,7 +58,12 @@ function doApplySourceMaps(applyContext) {
|
||||
applyContext.processedTokens.push(token);
|
||||
|
||||
if (token[0] == Token.COMMENT && MAP_MARKER_PATTERN.test(token[1])) {
|
||||
return fetchAndApplySourceMap(token[1], source, singleSourceTokens, applyContext);
|
||||
return fetchAndApplySourceMap(
|
||||
token[1],
|
||||
source,
|
||||
singleSourceTokens,
|
||||
applyContext
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,19 +84,35 @@ function findTokenSource(token) {
|
||||
return metadata[2];
|
||||
}
|
||||
|
||||
function fetchAndApplySourceMap(sourceMapComment, source, singleSourceTokens, applyContext) {
|
||||
return extractInputSourceMapFrom(sourceMapComment, applyContext, function (inputSourceMap) {
|
||||
if (inputSourceMap) {
|
||||
applyContext.inputSourceMapTracker.track(source, inputSourceMap);
|
||||
applySourceMapRecursively(singleSourceTokens, applyContext.inputSourceMapTracker);
|
||||
}
|
||||
function fetchAndApplySourceMap(
|
||||
sourceMapComment,
|
||||
source,
|
||||
singleSourceTokens,
|
||||
applyContext
|
||||
) {
|
||||
return extractInputSourceMapFrom(
|
||||
sourceMapComment,
|
||||
applyContext,
|
||||
function (inputSourceMap) {
|
||||
if (inputSourceMap) {
|
||||
applyContext.inputSourceMapTracker.track(source, inputSourceMap);
|
||||
applySourceMapRecursively(
|
||||
singleSourceTokens,
|
||||
applyContext.inputSourceMapTracker
|
||||
);
|
||||
}
|
||||
|
||||
applyContext.index++;
|
||||
return doApplySourceMaps(applyContext);
|
||||
});
|
||||
applyContext.index++;
|
||||
return doApplySourceMaps(applyContext);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function extractInputSourceMapFrom(sourceMapComment, applyContext, whenSourceMapReady) {
|
||||
function extractInputSourceMapFrom(
|
||||
sourceMapComment,
|
||||
applyContext,
|
||||
whenSourceMapReady
|
||||
) {
|
||||
var uri = MAP_MARKER_PATTERN.exec(sourceMapComment)[1];
|
||||
var absoluteUri;
|
||||
var sourceMap;
|
||||
@ -97,17 +122,21 @@ function extractInputSourceMapFrom(sourceMapComment, applyContext, whenSourceMap
|
||||
sourceMap = extractInputSourceMapFromDataUri(uri);
|
||||
return whenSourceMapReady(sourceMap);
|
||||
} else if (isRemoteResource(uri)) {
|
||||
return loadInputSourceMapFromRemoteUri(uri, applyContext, function (sourceMap) {
|
||||
var parsedMap;
|
||||
return loadInputSourceMapFromRemoteUri(
|
||||
uri,
|
||||
applyContext,
|
||||
function (sourceMap) {
|
||||
var parsedMap;
|
||||
|
||||
if (sourceMap) {
|
||||
parsedMap = JSON.parse(sourceMap);
|
||||
rebasedMap = rebaseRemoteMap(parsedMap, uri);
|
||||
whenSourceMapReady(rebasedMap);
|
||||
} else {
|
||||
whenSourceMapReady(null);
|
||||
if (sourceMap) {
|
||||
parsedMap = JSON.parse(sourceMap);
|
||||
rebasedMap = rebaseRemoteMap(parsedMap, uri);
|
||||
whenSourceMapReady(rebasedMap);
|
||||
} else {
|
||||
whenSourceMapReady(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
} else {
|
||||
// at this point `uri` is already rebased, see lib/reader/rebase.js#rebaseSourceMapComment
|
||||
// it is rebased to be consistent with rebasing other URIs
|
||||
@ -116,7 +145,11 @@ function extractInputSourceMapFrom(sourceMapComment, applyContext, whenSourceMap
|
||||
sourceMap = loadInputSourceMapFromLocalUri(absoluteUri, applyContext);
|
||||
|
||||
if (sourceMap) {
|
||||
rebasedMap = rebaseLocalMap(sourceMap, absoluteUri, applyContext.rebaseTo);
|
||||
rebasedMap = rebaseLocalMap(
|
||||
sourceMap,
|
||||
absoluteUri,
|
||||
applyContext.rebaseTo
|
||||
);
|
||||
return whenSourceMapReady(rebasedMap);
|
||||
} else {
|
||||
return whenSourceMapReady(null);
|
||||
@ -128,7 +161,8 @@ function extractInputSourceMapFromDataUri(uri) {
|
||||
var dataUriMatch = matchDataUri(uri);
|
||||
var charset = dataUriMatch[2] ? dataUriMatch[2].split(/[=;]/)[2] : 'us-ascii';
|
||||
var encoding = dataUriMatch[3] ? dataUriMatch[3].split(';')[1] : 'utf8';
|
||||
var data = encoding == 'utf8' ? global.unescape(dataUriMatch[4]) : dataUriMatch[4];
|
||||
var data =
|
||||
encoding == 'utf8' ? global.unescape(dataUriMatch[4]) : dataUriMatch[4];
|
||||
|
||||
var buffer = new Buffer(data, encoding);
|
||||
buffer.charset = charset;
|
||||
@ -141,24 +175,37 @@ function loadInputSourceMapFromRemoteUri(uri, applyContext, whenLoaded) {
|
||||
var isRuntimeResource = !hasProtocol(uri);
|
||||
|
||||
if (applyContext.localOnly) {
|
||||
applyContext.warnings.push('Cannot fetch remote resource from "' + uri + '" as no callback given.');
|
||||
applyContext.warnings.push(
|
||||
'Cannot fetch remote resource from "' + uri + '" as no callback given.'
|
||||
);
|
||||
return whenLoaded(null);
|
||||
} else if (isRuntimeResource) {
|
||||
applyContext.warnings.push('Cannot fetch "' + uri + '" as no protocol given.');
|
||||
applyContext.warnings.push(
|
||||
'Cannot fetch "' + uri + '" as no protocol given.'
|
||||
);
|
||||
return whenLoaded(null);
|
||||
} else if (!isAllowed) {
|
||||
applyContext.warnings.push('Cannot fetch "' + uri + '" as resource is not allowed.');
|
||||
applyContext.warnings.push(
|
||||
'Cannot fetch "' + uri + '" as resource is not allowed.'
|
||||
);
|
||||
return whenLoaded(null);
|
||||
}
|
||||
|
||||
applyContext.fetch(uri, applyContext.inlineRequest, applyContext.inlineTimeout, function (error, body) {
|
||||
if (error) {
|
||||
applyContext.warnings.push('Missing source map at "' + uri + '" - ' + error);
|
||||
return whenLoaded(null);
|
||||
}
|
||||
applyContext.fetch(
|
||||
uri,
|
||||
applyContext.inlineRequest,
|
||||
applyContext.inlineTimeout,
|
||||
function (error, body) {
|
||||
if (error) {
|
||||
applyContext.warnings.push(
|
||||
'Missing source map at "' + uri + '" - ' + error
|
||||
);
|
||||
return whenLoaded(null);
|
||||
}
|
||||
|
||||
whenLoaded(body);
|
||||
});
|
||||
whenLoaded(body);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function loadInputSourceMapFromLocalUri(uri, applyContext) {
|
||||
@ -166,10 +213,14 @@ function loadInputSourceMapFromLocalUri(uri, applyContext) {
|
||||
var sourceMap;
|
||||
|
||||
if (!fs.existsSync(uri) || !fs.statSync(uri).isFile()) {
|
||||
applyContext.warnings.push('Ignoring local source map at "' + uri + '" as resource is missing.');
|
||||
applyContext.warnings.push(
|
||||
'Ignoring local source map at "' + uri + '" as resource is missing.'
|
||||
);
|
||||
return null;
|
||||
} else if (!isAllowed) {
|
||||
applyContext.warnings.push('Cannot fetch "' + uri + '" as resource is not allowed.');
|
||||
applyContext.warnings.push(
|
||||
'Cannot fetch "' + uri + '" as resource is not allowed.'
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -236,7 +287,9 @@ function applySourceMapTo(token, inputSourceMapTracker) {
|
||||
var i, l;
|
||||
|
||||
for (i = 0, l = metadata.length; i < l; i++) {
|
||||
newMetadata.push(inputSourceMapTracker.originalPositionFor(metadata[i], value.length));
|
||||
newMetadata.push(
|
||||
inputSourceMapTracker.originalPositionFor(metadata[i], value.length)
|
||||
);
|
||||
}
|
||||
|
||||
token[2] = newMetadata;
|
||||
|
4
node_modules/clean-css/lib/reader/extract-import-url-and-media.js
generated
vendored
4
node_modules/clean-css/lib/reader/extract-import-url-and-media.js
generated
vendored
@ -24,9 +24,7 @@ function extractImportUrlAndMedia(atRuleValue) {
|
||||
|
||||
parts = split(stripped, ' ');
|
||||
|
||||
uri = parts[0]
|
||||
.replace(BRACE_PREFIX, '')
|
||||
.replace(BRACE_SUFFIX, '');
|
||||
uri = parts[0].replace(BRACE_PREFIX, '').replace(BRACE_SUFFIX, '');
|
||||
mediaQuery = parts.slice(1).join(' ');
|
||||
|
||||
return [uri, mediaQuery];
|
||||
|
15
node_modules/clean-css/lib/reader/input-source-map-tracker.js
generated
vendored
15
node_modules/clean-css/lib/reader/input-source-map-tracker.js
generated
vendored
@ -7,7 +7,7 @@ function inputSourceMapTracker() {
|
||||
all: all.bind(null, maps),
|
||||
isTracking: isTracking.bind(null, maps),
|
||||
originalPositionFor: originalPositionFor.bind(null, maps),
|
||||
track: track.bind(null, maps)
|
||||
track: track.bind(null, maps),
|
||||
};
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ function originalPositionFor(maps, metadata, range, selectorFallbacks) {
|
||||
var source = metadata[2];
|
||||
var position = {
|
||||
line: line,
|
||||
column: column + range
|
||||
column: column + range,
|
||||
};
|
||||
var originalPosition;
|
||||
|
||||
@ -39,12 +39,17 @@ function originalPositionFor(maps, metadata, range, selectorFallbacks) {
|
||||
}
|
||||
|
||||
if (originalPosition.line === null && line > 1 && selectorFallbacks > 0) {
|
||||
return originalPositionFor(maps, [line - 1, column, source], range, selectorFallbacks - 1);
|
||||
return originalPositionFor(
|
||||
maps,
|
||||
[line - 1, column, source],
|
||||
range,
|
||||
selectorFallbacks - 1
|
||||
);
|
||||
}
|
||||
|
||||
return originalPosition.line !== null ?
|
||||
toMetadata(originalPosition) :
|
||||
metadata;
|
||||
toMetadata(originalPosition)
|
||||
: metadata;
|
||||
}
|
||||
|
||||
function toMetadata(asHash) {
|
||||
|
13
node_modules/clean-css/lib/reader/is-allowed-resource.js
generated
vendored
13
node_modules/clean-css/lib/reader/is-allowed-resource.js
generated
vendored
@ -23,13 +23,9 @@ function isAllowedResource(uri, isRemote, rules) {
|
||||
uri = HTTP_PROTOCOL + uri;
|
||||
}
|
||||
|
||||
match = isRemote ?
|
||||
url.parse(uri).host :
|
||||
uri;
|
||||
match = isRemote ? url.parse(uri).host : uri;
|
||||
|
||||
absoluteUri = isRemote ?
|
||||
uri :
|
||||
path.resolve(uri);
|
||||
absoluteUri = isRemote ? uri : path.resolve(uri);
|
||||
|
||||
for (i = 0; i < rules.length; i++) {
|
||||
rule = rules[i];
|
||||
@ -71,7 +67,10 @@ function isAllowedResource(uri, isRemote, rules) {
|
||||
}
|
||||
|
||||
function isRemoteRule(rule) {
|
||||
return isRemoteResource(rule) || url.parse(HTTP_PROTOCOL + '//' + rule).host == rule;
|
||||
return (
|
||||
isRemoteResource(rule) ||
|
||||
url.parse(HTTP_PROTOCOL + '//' + rule).host == rule
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = isAllowedResource;
|
||||
|
61
node_modules/clean-css/lib/reader/load-original-sources.js
generated
vendored
61
node_modules/clean-css/lib/reader/load-original-sources.js
generated
vendored
@ -18,12 +18,12 @@ function loadOriginalSources(context, callback) {
|
||||
rebaseTo: context.options.rebaseTo,
|
||||
sourcesContent: context.sourcesContent,
|
||||
uriToSource: uriToSourceMapping(context.inputSourceMapTracker.all()),
|
||||
warnings: context.warnings
|
||||
warnings: context.warnings,
|
||||
};
|
||||
|
||||
return context.options.sourceMap && context.options.sourceMapInlineSources ?
|
||||
doLoadOriginalSources(loadContext) :
|
||||
callback();
|
||||
doLoadOriginalSources(loadContext)
|
||||
: callback();
|
||||
}
|
||||
|
||||
function uriToSourceMapping(allSourceMapConsumers) {
|
||||
@ -71,11 +71,15 @@ function loadOriginalSource(uri, loadContext) {
|
||||
var content;
|
||||
|
||||
if (isRemoteResource(uri)) {
|
||||
return loadOriginalSourceFromRemoteUri(uri, loadContext, function (content) {
|
||||
loadContext.index++;
|
||||
loadContext.sourcesContent[uri] = content;
|
||||
return doLoadOriginalSources(loadContext);
|
||||
});
|
||||
return loadOriginalSourceFromRemoteUri(
|
||||
uri,
|
||||
loadContext,
|
||||
function (content) {
|
||||
loadContext.index++;
|
||||
loadContext.sourcesContent[uri] = content;
|
||||
return doLoadOriginalSources(loadContext);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
content = loadOriginalSourceFromLocalUri(uri, loadContext);
|
||||
loadContext.index++;
|
||||
@ -89,23 +93,36 @@ function loadOriginalSourceFromRemoteUri(uri, loadContext, whenLoaded) {
|
||||
var isRuntimeResource = !hasProtocol(uri);
|
||||
|
||||
if (loadContext.localOnly) {
|
||||
loadContext.warnings.push('Cannot fetch remote resource from "' + uri + '" as no callback given.');
|
||||
loadContext.warnings.push(
|
||||
'Cannot fetch remote resource from "' + uri + '" as no callback given.'
|
||||
);
|
||||
return whenLoaded(null);
|
||||
} else if (isRuntimeResource) {
|
||||
loadContext.warnings.push('Cannot fetch "' + uri + '" as no protocol given.');
|
||||
loadContext.warnings.push(
|
||||
'Cannot fetch "' + uri + '" as no protocol given.'
|
||||
);
|
||||
return whenLoaded(null);
|
||||
} else if (!isAllowed) {
|
||||
loadContext.warnings.push('Cannot fetch "' + uri + '" as resource is not allowed.');
|
||||
loadContext.warnings.push(
|
||||
'Cannot fetch "' + uri + '" as resource is not allowed.'
|
||||
);
|
||||
return whenLoaded(null);
|
||||
}
|
||||
|
||||
loadContext.fetch(uri, loadContext.inlineRequest, loadContext.inlineTimeout, function (error, content) {
|
||||
if (error) {
|
||||
loadContext.warnings.push('Missing original source at "' + uri + '" - ' + error);
|
||||
}
|
||||
loadContext.fetch(
|
||||
uri,
|
||||
loadContext.inlineRequest,
|
||||
loadContext.inlineTimeout,
|
||||
function (error, content) {
|
||||
if (error) {
|
||||
loadContext.warnings.push(
|
||||
'Missing original source at "' + uri + '" - ' + error
|
||||
);
|
||||
}
|
||||
|
||||
whenLoaded(content);
|
||||
});
|
||||
whenLoaded(content);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function loadOriginalSourceFromLocalUri(relativeUri, loadContext) {
|
||||
@ -113,10 +130,16 @@ function loadOriginalSourceFromLocalUri(relativeUri, loadContext) {
|
||||
var absoluteUri = path.resolve(loadContext.rebaseTo, relativeUri);
|
||||
|
||||
if (!fs.existsSync(absoluteUri) || !fs.statSync(absoluteUri).isFile()) {
|
||||
loadContext.warnings.push('Ignoring local source map at "' + absoluteUri + '" as resource is missing.');
|
||||
loadContext.warnings.push(
|
||||
'Ignoring local source map at "' +
|
||||
absoluteUri +
|
||||
'" as resource is missing.'
|
||||
);
|
||||
return null;
|
||||
} else if (!isAllowed) {
|
||||
loadContext.warnings.push('Cannot fetch "' + absoluteUri + '" as resource is not allowed.');
|
||||
loadContext.warnings.push(
|
||||
'Cannot fetch "' + absoluteUri + '" as resource is not allowed.'
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
49
node_modules/clean-css/lib/reader/load-remote-resource.js
generated
vendored
49
node_modules/clean-css/lib/reader/load-remote-resource.js
generated
vendored
@ -14,10 +14,7 @@ function loadRemoteResource(uri, inlineRequest, inlineTimeout, callback) {
|
||||
var requestOptions;
|
||||
var fetch;
|
||||
|
||||
requestOptions = override(
|
||||
url.parse(uri),
|
||||
inlineRequest || {}
|
||||
);
|
||||
requestOptions = override(url.parse(uri), inlineRequest || {});
|
||||
|
||||
if (inlineRequest.hostname !== undefined) {
|
||||
// overwrite as we always expect a http proxy currently
|
||||
@ -25,9 +22,10 @@ function loadRemoteResource(uri, inlineRequest, inlineTimeout, callback) {
|
||||
requestOptions.path = requestOptions.href;
|
||||
}
|
||||
|
||||
fetch = (proxyProtocol && !isHttpsResource(proxyProtocol)) || isHttpResource(uri) ?
|
||||
http.get :
|
||||
https.get;
|
||||
fetch =
|
||||
(proxyProtocol && !isHttpsResource(proxyProtocol)) || isHttpResource(uri) ?
|
||||
http.get
|
||||
: https.get;
|
||||
|
||||
fetch(requestOptions, function (res) {
|
||||
var chunks = [];
|
||||
@ -41,7 +39,12 @@ function loadRemoteResource(uri, inlineRequest, inlineTimeout, callback) {
|
||||
return callback(res.statusCode, null);
|
||||
} else if (res.statusCode > 299) {
|
||||
movedUri = url.resolve(uri, res.headers.location);
|
||||
return loadRemoteResource(movedUri, inlineRequest, inlineTimeout, callback);
|
||||
return loadRemoteResource(
|
||||
movedUri,
|
||||
inlineRequest,
|
||||
inlineTimeout,
|
||||
callback
|
||||
);
|
||||
}
|
||||
|
||||
res.on('data', function (chunk) {
|
||||
@ -52,23 +55,23 @@ function loadRemoteResource(uri, inlineRequest, inlineTimeout, callback) {
|
||||
callback(null, body);
|
||||
});
|
||||
})
|
||||
.on('error', function (res) {
|
||||
if (errorHandled) {
|
||||
return;
|
||||
}
|
||||
.on('error', function (res) {
|
||||
if (errorHandled) {
|
||||
return;
|
||||
}
|
||||
|
||||
errorHandled = true;
|
||||
callback(res.message, null);
|
||||
})
|
||||
.on('timeout', function () {
|
||||
if (errorHandled) {
|
||||
return;
|
||||
}
|
||||
errorHandled = true;
|
||||
callback(res.message, null);
|
||||
})
|
||||
.on('timeout', function () {
|
||||
if (errorHandled) {
|
||||
return;
|
||||
}
|
||||
|
||||
errorHandled = true;
|
||||
callback('timeout', null);
|
||||
})
|
||||
.setTimeout(inlineTimeout);
|
||||
errorHandled = true;
|
||||
callback('timeout', null);
|
||||
})
|
||||
.setTimeout(inlineTimeout);
|
||||
}
|
||||
|
||||
module.exports = loadRemoteResource;
|
||||
|
217
node_modules/clean-css/lib/reader/read-sources.js
generated
vendored
217
node_modules/clean-css/lib/reader/read-sources.js
generated
vendored
@ -23,7 +23,9 @@ var UNKNOWN_URI = 'uri:unknown';
|
||||
function readSources(input, context, callback) {
|
||||
return doReadSources(input, context, function (tokens) {
|
||||
return applySourceMaps(tokens, context, function () {
|
||||
return loadOriginalSources(context, function () { return callback(tokens); });
|
||||
return loadOriginalSources(context, function () {
|
||||
return callback(tokens);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -45,7 +47,12 @@ function fromString(input, context, callback) {
|
||||
context.sourcesContent[undefined] = input;
|
||||
context.stats.originalSize += input.length;
|
||||
|
||||
return fromStyles(input, context, { inline: context.options.inline }, callback);
|
||||
return fromStyles(
|
||||
input,
|
||||
context,
|
||||
{ inline: context.options.inline },
|
||||
callback
|
||||
);
|
||||
}
|
||||
|
||||
function fromArray(input, context, callback) {
|
||||
@ -55,15 +62,24 @@ function fromArray(input, context, callback) {
|
||||
} else {
|
||||
return addHashSource(uriOrHash, context, accumulator);
|
||||
}
|
||||
|
||||
}, []);
|
||||
|
||||
return fromStyles(inputAsImports.join(''), context, { inline: ['all'] }, callback);
|
||||
return fromStyles(
|
||||
inputAsImports.join(''),
|
||||
context,
|
||||
{ inline: ['all'] },
|
||||
callback
|
||||
);
|
||||
}
|
||||
|
||||
function fromHash(input, context, callback) {
|
||||
var inputAsImports = addHashSource(input, context, []);
|
||||
return fromStyles(inputAsImports.join(''), context, { inline: ['all'] }, callback);
|
||||
return fromStyles(
|
||||
inputAsImports.join(''),
|
||||
context,
|
||||
{ inline: ['all'] },
|
||||
callback
|
||||
);
|
||||
}
|
||||
|
||||
function addStringSource(input, imports) {
|
||||
@ -102,9 +118,7 @@ function normalizeUri(uri) {
|
||||
return uri;
|
||||
}
|
||||
|
||||
absoluteUri = path.isAbsolute(uri) ?
|
||||
uri :
|
||||
path.resolve(uri);
|
||||
absoluteUri = path.isAbsolute(uri) ? uri : path.resolve(uri);
|
||||
relativeToCurrentPath = path.relative(currentPath, absoluteUri);
|
||||
normalizedUri = normalizePath(relativeToCurrentPath);
|
||||
|
||||
@ -112,12 +126,12 @@ function normalizeUri(uri) {
|
||||
}
|
||||
|
||||
function trackSourceMap(sourceMap, uri, context) {
|
||||
var parsedMap = typeof sourceMap == 'string' ?
|
||||
JSON.parse(sourceMap) :
|
||||
sourceMap;
|
||||
var rebasedMap = isRemoteResource(uri) ?
|
||||
rebaseRemoteMap(parsedMap, uri) :
|
||||
rebaseLocalMap(parsedMap, uri || UNKNOWN_URI, context.options.rebaseTo);
|
||||
var parsedMap =
|
||||
typeof sourceMap == 'string' ? JSON.parse(sourceMap) : sourceMap;
|
||||
var rebasedMap =
|
||||
isRemoteResource(uri) ?
|
||||
rebaseRemoteMap(parsedMap, uri)
|
||||
: rebaseLocalMap(parsedMap, uri || UNKNOWN_URI, context.options.rebaseTo);
|
||||
|
||||
context.inputSourceMapTracker.track(uri, rebasedMap);
|
||||
}
|
||||
@ -145,11 +159,16 @@ function fromStyles(styles, context, parentInlinerContext, callback) {
|
||||
}
|
||||
|
||||
tokens = tokenize(styles, context);
|
||||
tokens = rebase(tokens, context.options.rebase, context.validator, rebaseConfig);
|
||||
tokens = rebase(
|
||||
tokens,
|
||||
context.options.rebase,
|
||||
context.validator,
|
||||
rebaseConfig
|
||||
);
|
||||
|
||||
return allowsAnyImports(parentInlinerContext.inline) ?
|
||||
inline(tokens, context, parentInlinerContext, callback) :
|
||||
callback(tokens);
|
||||
inline(tokens, context, parentInlinerContext, callback)
|
||||
: callback(tokens);
|
||||
}
|
||||
|
||||
function allowsAnyImports(inline) {
|
||||
@ -163,7 +182,9 @@ function inline(tokens, externalContext, parentInlinerContext, callback) {
|
||||
errors: externalContext.errors,
|
||||
externalContext: externalContext,
|
||||
fetch: externalContext.options.fetch,
|
||||
inlinedStylesheets: parentInlinerContext.inlinedStylesheets || externalContext.inlinedStylesheets,
|
||||
inlinedStylesheets:
|
||||
parentInlinerContext.inlinedStylesheets ||
|
||||
externalContext.inlinedStylesheets,
|
||||
inline: parentInlinerContext.inline,
|
||||
inlineRequest: externalContext.options.inlineRequest,
|
||||
inlineTimeout: externalContext.options.inlineTimeout,
|
||||
@ -172,7 +193,7 @@ function inline(tokens, externalContext, parentInlinerContext, callback) {
|
||||
outputTokens: [],
|
||||
rebaseTo: externalContext.options.rebaseTo,
|
||||
sourceTokens: tokens,
|
||||
warnings: externalContext.warnings
|
||||
warnings: externalContext.warnings,
|
||||
};
|
||||
|
||||
return doInlineImports(inlinerContext);
|
||||
@ -207,8 +228,8 @@ function inlineStylesheet(token, inlinerContext) {
|
||||
var metadata = token[2];
|
||||
|
||||
return isRemoteResource(uri) ?
|
||||
inlineRemoteStylesheet(uri, mediaQuery, metadata, inlinerContext) :
|
||||
inlineLocalStylesheet(uri, mediaQuery, metadata, inlinerContext);
|
||||
inlineRemoteStylesheet(uri, mediaQuery, metadata, inlinerContext)
|
||||
: inlineLocalStylesheet(uri, mediaQuery, metadata, inlinerContext);
|
||||
}
|
||||
|
||||
function inlineRemoteStylesheet(uri, mediaQuery, metadata, inlinerContext) {
|
||||
@ -218,30 +239,54 @@ function inlineRemoteStylesheet(uri, mediaQuery, metadata, inlinerContext) {
|
||||
var isRuntimeResource = !hasProtocol(uri);
|
||||
|
||||
if (inlinerContext.inlinedStylesheets.indexOf(uri) > -1) {
|
||||
inlinerContext.warnings.push('Ignoring remote @import of "' + uri + '" as it has already been imported.');
|
||||
inlinerContext.warnings.push(
|
||||
'Ignoring remote @import of "' +
|
||||
uri +
|
||||
'" as it has already been imported.'
|
||||
);
|
||||
inlinerContext.sourceTokens = inlinerContext.sourceTokens.slice(1);
|
||||
return doInlineImports(inlinerContext);
|
||||
} else if (inlinerContext.localOnly && inlinerContext.afterContent) {
|
||||
inlinerContext.warnings.push('Ignoring remote @import of "' + uri + '" as no callback given and after other content.');
|
||||
inlinerContext.warnings.push(
|
||||
'Ignoring remote @import of "' +
|
||||
uri +
|
||||
'" as no callback given and after other content.'
|
||||
);
|
||||
inlinerContext.sourceTokens = inlinerContext.sourceTokens.slice(1);
|
||||
return doInlineImports(inlinerContext);
|
||||
} else if (isRuntimeResource) {
|
||||
inlinerContext.warnings.push('Skipping remote @import of "' + uri + '" as no protocol given.');
|
||||
inlinerContext.outputTokens = inlinerContext.outputTokens.concat(inlinerContext.sourceTokens.slice(0, 1));
|
||||
inlinerContext.warnings.push(
|
||||
'Skipping remote @import of "' + uri + '" as no protocol given.'
|
||||
);
|
||||
inlinerContext.outputTokens = inlinerContext.outputTokens.concat(
|
||||
inlinerContext.sourceTokens.slice(0, 1)
|
||||
);
|
||||
inlinerContext.sourceTokens = inlinerContext.sourceTokens.slice(1);
|
||||
return doInlineImports(inlinerContext);
|
||||
} else if (inlinerContext.localOnly && !isLoaded) {
|
||||
inlinerContext.warnings.push('Skipping remote @import of "' + uri + '" as no callback given.');
|
||||
inlinerContext.outputTokens = inlinerContext.outputTokens.concat(inlinerContext.sourceTokens.slice(0, 1));
|
||||
inlinerContext.warnings.push(
|
||||
'Skipping remote @import of "' + uri + '" as no callback given.'
|
||||
);
|
||||
inlinerContext.outputTokens = inlinerContext.outputTokens.concat(
|
||||
inlinerContext.sourceTokens.slice(0, 1)
|
||||
);
|
||||
inlinerContext.sourceTokens = inlinerContext.sourceTokens.slice(1);
|
||||
return doInlineImports(inlinerContext);
|
||||
} else if (!isAllowed && inlinerContext.afterContent) {
|
||||
inlinerContext.warnings.push('Ignoring remote @import of "' + uri + '" as resource is not allowed and after other content.');
|
||||
inlinerContext.warnings.push(
|
||||
'Ignoring remote @import of "' +
|
||||
uri +
|
||||
'" as resource is not allowed and after other content.'
|
||||
);
|
||||
inlinerContext.sourceTokens = inlinerContext.sourceTokens.slice(1);
|
||||
return doInlineImports(inlinerContext);
|
||||
} else if (!isAllowed) {
|
||||
inlinerContext.warnings.push('Skipping remote @import of "' + uri + '" as resource is not allowed.');
|
||||
inlinerContext.outputTokens = inlinerContext.outputTokens.concat(inlinerContext.sourceTokens.slice(0, 1));
|
||||
inlinerContext.warnings.push(
|
||||
'Skipping remote @import of "' + uri + '" as resource is not allowed.'
|
||||
);
|
||||
inlinerContext.outputTokens = inlinerContext.outputTokens.concat(
|
||||
inlinerContext.sourceTokens.slice(0, 1)
|
||||
);
|
||||
inlinerContext.sourceTokens = inlinerContext.sourceTokens.slice(1);
|
||||
return doInlineImports(inlinerContext);
|
||||
}
|
||||
@ -250,10 +295,14 @@ function inlineRemoteStylesheet(uri, mediaQuery, metadata, inlinerContext) {
|
||||
|
||||
function whenLoaded(error, importedStyles) {
|
||||
if (error) {
|
||||
inlinerContext.errors.push('Broken @import declaration of "' + uri + '" - ' + error);
|
||||
inlinerContext.errors.push(
|
||||
'Broken @import declaration of "' + uri + '" - ' + error
|
||||
);
|
||||
|
||||
return process.nextTick(function () {
|
||||
inlinerContext.outputTokens = inlinerContext.outputTokens.concat(inlinerContext.sourceTokens.slice(0, 1));
|
||||
inlinerContext.outputTokens = inlinerContext.outputTokens.concat(
|
||||
inlinerContext.sourceTokens.slice(0, 1)
|
||||
);
|
||||
inlinerContext.sourceTokens = inlinerContext.sourceTokens.slice(1);
|
||||
doInlineImports(inlinerContext);
|
||||
});
|
||||
@ -266,63 +315,101 @@ function inlineRemoteStylesheet(uri, mediaQuery, metadata, inlinerContext) {
|
||||
inlinerContext.externalContext.sourcesContent[uri] = importedStyles;
|
||||
inlinerContext.externalContext.stats.originalSize += importedStyles.length;
|
||||
|
||||
return fromStyles(importedStyles, inlinerContext.externalContext, inlinerContext, function (importedTokens) {
|
||||
importedTokens = wrapInMedia(importedTokens, mediaQuery, metadata);
|
||||
return fromStyles(
|
||||
importedStyles,
|
||||
inlinerContext.externalContext,
|
||||
inlinerContext,
|
||||
function (importedTokens) {
|
||||
importedTokens = wrapInMedia(importedTokens, mediaQuery, metadata);
|
||||
|
||||
inlinerContext.outputTokens = inlinerContext.outputTokens.concat(importedTokens);
|
||||
inlinerContext.sourceTokens = inlinerContext.sourceTokens.slice(1);
|
||||
inlinerContext.outputTokens =
|
||||
inlinerContext.outputTokens.concat(importedTokens);
|
||||
inlinerContext.sourceTokens = inlinerContext.sourceTokens.slice(1);
|
||||
|
||||
return doInlineImports(inlinerContext);
|
||||
});
|
||||
return doInlineImports(inlinerContext);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return isLoaded ?
|
||||
whenLoaded(null, inlinerContext.externalContext.sourcesContent[uri]) :
|
||||
inlinerContext.fetch(uri, inlinerContext.inlineRequest, inlinerContext.inlineTimeout, whenLoaded);
|
||||
whenLoaded(null, inlinerContext.externalContext.sourcesContent[uri])
|
||||
: inlinerContext.fetch(
|
||||
uri,
|
||||
inlinerContext.inlineRequest,
|
||||
inlinerContext.inlineTimeout,
|
||||
whenLoaded
|
||||
);
|
||||
}
|
||||
|
||||
function inlineLocalStylesheet(uri, mediaQuery, metadata, inlinerContext) {
|
||||
var currentPath = path.resolve('');
|
||||
var absoluteUri = path.isAbsolute(uri) ?
|
||||
path.resolve(currentPath, uri[0] == '/' ? uri.substring(1) : uri) :
|
||||
path.resolve(inlinerContext.rebaseTo, uri);
|
||||
var absoluteUri =
|
||||
path.isAbsolute(uri) ?
|
||||
path.resolve(currentPath, uri[0] == '/' ? uri.substring(1) : uri)
|
||||
: path.resolve(inlinerContext.rebaseTo, uri);
|
||||
var relativeToCurrentPath = path.relative(currentPath, absoluteUri);
|
||||
var importedStyles;
|
||||
var isAllowed = isAllowedResource(uri, false, inlinerContext.inline);
|
||||
var normalizedPath = normalizePath(relativeToCurrentPath);
|
||||
var isLoaded = normalizedPath in inlinerContext.externalContext.sourcesContent;
|
||||
var isLoaded =
|
||||
normalizedPath in inlinerContext.externalContext.sourcesContent;
|
||||
|
||||
if (inlinerContext.inlinedStylesheets.indexOf(absoluteUri) > -1) {
|
||||
inlinerContext.warnings.push('Ignoring local @import of "' + uri + '" as it has already been imported.');
|
||||
} else if (!isLoaded && (!fs.existsSync(absoluteUri) || !fs.statSync(absoluteUri).isFile())) {
|
||||
inlinerContext.errors.push('Ignoring local @import of "' + uri + '" as resource is missing.');
|
||||
inlinerContext.warnings.push(
|
||||
'Ignoring local @import of "' + uri + '" as it has already been imported.'
|
||||
);
|
||||
} else if (
|
||||
!isLoaded &&
|
||||
(!fs.existsSync(absoluteUri) || !fs.statSync(absoluteUri).isFile())
|
||||
) {
|
||||
inlinerContext.errors.push(
|
||||
'Ignoring local @import of "' + uri + '" as resource is missing.'
|
||||
);
|
||||
} else if (!isAllowed && inlinerContext.afterContent) {
|
||||
inlinerContext.warnings.push('Ignoring local @import of "' + uri + '" as resource is not allowed and after other content.');
|
||||
inlinerContext.warnings.push(
|
||||
'Ignoring local @import of "' +
|
||||
uri +
|
||||
'" as resource is not allowed and after other content.'
|
||||
);
|
||||
} else if (inlinerContext.afterContent) {
|
||||
inlinerContext.warnings.push('Ignoring local @import of "' + uri + '" as after other content.');
|
||||
inlinerContext.warnings.push(
|
||||
'Ignoring local @import of "' + uri + '" as after other content.'
|
||||
);
|
||||
} else if (!isAllowed) {
|
||||
inlinerContext.warnings.push('Skipping local @import of "' + uri + '" as resource is not allowed.');
|
||||
inlinerContext.outputTokens = inlinerContext.outputTokens.concat(inlinerContext.sourceTokens.slice(0, 1));
|
||||
inlinerContext.warnings.push(
|
||||
'Skipping local @import of "' + uri + '" as resource is not allowed.'
|
||||
);
|
||||
inlinerContext.outputTokens = inlinerContext.outputTokens.concat(
|
||||
inlinerContext.sourceTokens.slice(0, 1)
|
||||
);
|
||||
} else {
|
||||
importedStyles = isLoaded ?
|
||||
inlinerContext.externalContext.sourcesContent[normalizedPath] :
|
||||
fs.readFileSync(absoluteUri, 'utf-8');
|
||||
importedStyles =
|
||||
isLoaded ?
|
||||
inlinerContext.externalContext.sourcesContent[normalizedPath]
|
||||
: fs.readFileSync(absoluteUri, 'utf-8');
|
||||
|
||||
inlinerContext.inlinedStylesheets.push(absoluteUri);
|
||||
inlinerContext.inline = inlinerContext.externalContext.options.inline;
|
||||
|
||||
inlinerContext.externalContext.source = normalizedPath;
|
||||
inlinerContext.externalContext.sourcesContent[normalizedPath] = importedStyles;
|
||||
inlinerContext.externalContext.sourcesContent[normalizedPath] =
|
||||
importedStyles;
|
||||
inlinerContext.externalContext.stats.originalSize += importedStyles.length;
|
||||
|
||||
return fromStyles(importedStyles, inlinerContext.externalContext, inlinerContext, function (importedTokens) {
|
||||
importedTokens = wrapInMedia(importedTokens, mediaQuery, metadata);
|
||||
return fromStyles(
|
||||
importedStyles,
|
||||
inlinerContext.externalContext,
|
||||
inlinerContext,
|
||||
function (importedTokens) {
|
||||
importedTokens = wrapInMedia(importedTokens, mediaQuery, metadata);
|
||||
|
||||
inlinerContext.outputTokens = inlinerContext.outputTokens.concat(importedTokens);
|
||||
inlinerContext.sourceTokens = inlinerContext.sourceTokens.slice(1);
|
||||
inlinerContext.outputTokens =
|
||||
inlinerContext.outputTokens.concat(importedTokens);
|
||||
inlinerContext.sourceTokens = inlinerContext.sourceTokens.slice(1);
|
||||
|
||||
return doInlineImports(inlinerContext);
|
||||
});
|
||||
return doInlineImports(inlinerContext);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
inlinerContext.sourceTokens = inlinerContext.sourceTokens.slice(1);
|
||||
@ -332,7 +419,13 @@ function inlineLocalStylesheet(uri, mediaQuery, metadata, inlinerContext) {
|
||||
|
||||
function wrapInMedia(tokens, mediaQuery, metadata) {
|
||||
if (mediaQuery) {
|
||||
return [[Token.NESTED_BLOCK, [[Token.NESTED_BLOCK_SCOPE, '@media ' + mediaQuery, metadata]], tokens]];
|
||||
return [
|
||||
[
|
||||
Token.NESTED_BLOCK,
|
||||
[[Token.NESTED_BLOCK_SCOPE, '@media ' + mediaQuery, metadata]],
|
||||
tokens,
|
||||
],
|
||||
];
|
||||
} else {
|
||||
return tokens;
|
||||
}
|
||||
|
2
node_modules/clean-css/lib/reader/rebase-local-map.js
generated
vendored
2
node_modules/clean-css/lib/reader/rebase-local-map.js
generated
vendored
@ -5,7 +5,7 @@ function rebaseLocalMap(sourceMap, sourceUri, rebaseTo) {
|
||||
var absoluteUri = path.resolve(currentPath, sourceUri);
|
||||
var absoluteUriDirectory = path.dirname(absoluteUri);
|
||||
|
||||
sourceMap.sources = sourceMap.sources.map(function(source) {
|
||||
sourceMap.sources = sourceMap.sources.map(function (source) {
|
||||
return path.relative(rebaseTo, path.resolve(absoluteUriDirectory, source));
|
||||
});
|
||||
|
||||
|
2
node_modules/clean-css/lib/reader/rebase-remote-map.js
generated
vendored
2
node_modules/clean-css/lib/reader/rebase-remote-map.js
generated
vendored
@ -4,7 +4,7 @@ var url = require('url');
|
||||
function rebaseRemoteMap(sourceMap, sourceUri) {
|
||||
var sourceDirectory = path.dirname(sourceUri);
|
||||
|
||||
sourceMap.sources = sourceMap.sources.map(function(source) {
|
||||
sourceMap.sources = sourceMap.sources.map(function (source) {
|
||||
return url.resolve(sourceDirectory, source);
|
||||
});
|
||||
|
||||
|
15
node_modules/clean-css/lib/reader/rebase.js
generated
vendored
15
node_modules/clean-css/lib/reader/rebase.js
generated
vendored
@ -9,8 +9,8 @@ var SOURCE_MAP_COMMENT_PATTERN = /^\/\*# sourceMappingURL=(\S+) \*\/$/;
|
||||
|
||||
function rebase(tokens, rebaseAll, validator, rebaseConfig) {
|
||||
return rebaseAll ?
|
||||
rebaseEverything(tokens, validator, rebaseConfig) :
|
||||
rebaseAtRules(tokens, validator, rebaseConfig);
|
||||
rebaseEverything(tokens, validator, rebaseConfig)
|
||||
: rebaseAtRules(tokens, validator, rebaseConfig);
|
||||
}
|
||||
|
||||
function rebaseEverything(tokens, validator, rebaseConfig) {
|
||||
@ -75,7 +75,10 @@ function rebaseSourceMapComment(token, rebaseConfig) {
|
||||
var matches = SOURCE_MAP_COMMENT_PATTERN.exec(token[1]);
|
||||
|
||||
if (matches && matches[1].indexOf('data:') === -1) {
|
||||
token[1] = token[1].replace(matches[1], rewriteUrl(matches[1], rebaseConfig, true));
|
||||
token[1] = token[1].replace(
|
||||
matches[1],
|
||||
rewriteUrl(matches[1], rebaseConfig, true)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,7 +91,11 @@ function rebaseProperties(properties, validator, rebaseConfig) {
|
||||
for (i = 0, l = properties.length; i < l; i++) {
|
||||
property = properties[i];
|
||||
|
||||
for (j = 2 /* 0 is Token.PROPERTY, 1 is name */, m = property.length; j < m; j++) {
|
||||
for (
|
||||
j = 2 /* 0 is Token.PROPERTY, 1 is name */, m = property.length;
|
||||
j < m;
|
||||
j++
|
||||
) {
|
||||
value = property[j][1];
|
||||
|
||||
if (validator.isUrl(value)) {
|
||||
|
28
node_modules/clean-css/lib/reader/rewrite-url.js
generated
vendored
28
node_modules/clean-css/lib/reader/rewrite-url.js
generated
vendored
@ -2,7 +2,7 @@ var path = require('path');
|
||||
var url = require('url');
|
||||
|
||||
var DOUBLE_QUOTE = '"';
|
||||
var SINGLE_QUOTE = '\'';
|
||||
var SINGLE_QUOTE = "'";
|
||||
var URL_PREFIX = 'url(';
|
||||
var URL_SUFFIX = ')';
|
||||
|
||||
@ -29,7 +29,7 @@ function rebase(uri, rebaseConfig) {
|
||||
}
|
||||
|
||||
if (isData(uri)) {
|
||||
return '\'' + uri + '\'';
|
||||
return "'" + uri + "'";
|
||||
}
|
||||
|
||||
if (isRemote(rebaseConfig.toBase)) {
|
||||
@ -37,8 +37,8 @@ function rebase(uri, rebaseConfig) {
|
||||
}
|
||||
|
||||
return rebaseConfig.absolute ?
|
||||
normalize(absolute(uri, rebaseConfig)) :
|
||||
normalize(relative(uri, rebaseConfig));
|
||||
normalize(absolute(uri, rebaseConfig))
|
||||
: normalize(relative(uri, rebaseConfig));
|
||||
}
|
||||
|
||||
function isAbsolute(uri) {
|
||||
@ -68,7 +68,10 @@ function absolute(uri, rebaseConfig) {
|
||||
}
|
||||
|
||||
function relative(uri, rebaseConfig) {
|
||||
return path.relative(rebaseConfig.toBase, path.join(rebaseConfig.fromBase || '', uri));
|
||||
return path.relative(
|
||||
rebaseConfig.toBase,
|
||||
path.join(rebaseConfig.fromBase || '', uri)
|
||||
);
|
||||
}
|
||||
|
||||
function normalize(uri) {
|
||||
@ -106,13 +109,18 @@ function rewriteUrl(originalUrl, rebaseConfig, pathOnly) {
|
||||
.replace(QUOTE_SUFFIX_PATTERN, '')
|
||||
.trim();
|
||||
|
||||
var quote = strippedUrl[0] == SINGLE_QUOTE || strippedUrl[0] == DOUBLE_QUOTE ?
|
||||
strippedUrl[0] :
|
||||
quoteFor(unquotedUrl);
|
||||
var quote =
|
||||
strippedUrl[0] == SINGLE_QUOTE || strippedUrl[0] == DOUBLE_QUOTE ?
|
||||
strippedUrl[0]
|
||||
: quoteFor(unquotedUrl);
|
||||
|
||||
return pathOnly ?
|
||||
rebase(unquotedUrl, rebaseConfig) :
|
||||
URL_PREFIX + quote + rebase(unquotedUrl, rebaseConfig) + quote + URL_SUFFIX;
|
||||
rebase(unquotedUrl, rebaseConfig)
|
||||
: URL_PREFIX +
|
||||
quote +
|
||||
rebase(unquotedUrl, rebaseConfig) +
|
||||
quote +
|
||||
URL_SUFFIX;
|
||||
}
|
||||
|
||||
module.exports = rewriteUrl;
|
||||
|
Reference in New Issue
Block a user