schnee effeckt und fehler Korektur
This commit is contained in:
277
node_modules/gulp-sass/index.js
generated
vendored
277
node_modules/gulp-sass/index.js
generated
vendored
@@ -1,159 +1,176 @@
|
||||
const chalk = require('chalk');
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const { Transform } = require('stream');
|
||||
const picocolors = require('picocolors');
|
||||
const PluginError = require('plugin-error');
|
||||
const replaceExtension = require('replace-ext');
|
||||
const stripAnsi = require('strip-ansi');
|
||||
const transfob = require('transfob');
|
||||
const clonedeep = require('lodash/cloneDeep');
|
||||
const path = require('path');
|
||||
const clonedeep = require('lodash.clonedeep');
|
||||
const applySourceMap = require('vinyl-sourcemaps-apply');
|
||||
|
||||
const PLUGIN_NAME = 'gulp-sass';
|
||||
|
||||
/// ///////////////////////////
|
||||
// Main Gulp Sass function
|
||||
/// ///////////////////////////
|
||||
const gulpSass = (options, sync) => transfob((file, enc, cb) => { // eslint-disable-line consistent-return
|
||||
if (file.isNull()) {
|
||||
return cb(null, file);
|
||||
}
|
||||
const MISSING_COMPILER_MESSAGE = `
|
||||
gulp-sass no longer has a default Sass compiler; please set one yourself.
|
||||
Both the "sass" and "node-sass" packages are permitted.
|
||||
For example, in your gulpfile:
|
||||
|
||||
if (file.isStream()) {
|
||||
return cb(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
|
||||
}
|
||||
const sass = require('gulp-sass')(require('sass'));
|
||||
`;
|
||||
|
||||
if (path.basename(file.path).indexOf('_') === 0) {
|
||||
return cb();
|
||||
}
|
||||
const transfob = (transform) => new Transform({ transform, objectMode: true });
|
||||
|
||||
if (!file.contents.length) {
|
||||
file.path = replaceExtension(file.path, '.css'); // eslint-disable-line no-param-reassign
|
||||
return cb(null, file);
|
||||
}
|
||||
/**
|
||||
* Handles returning the file to the stream
|
||||
*/
|
||||
const filePush = (file, sassObject, callback) => {
|
||||
// Build Source Maps!
|
||||
if (sassObject.map) {
|
||||
// Transform map into JSON
|
||||
const sassMap = JSON.parse(sassObject.map.toString());
|
||||
// Grab the stdout and transform it into stdin
|
||||
const sassMapFile = sassMap.file.replace(/^stdout$/, 'stdin');
|
||||
// Grab the base filename that's being worked on
|
||||
const sassFileSrc = file.relative;
|
||||
// Grab the path portion of the file that's being worked on
|
||||
const sassFileSrcPath = path.dirname(sassFileSrc);
|
||||
|
||||
const opts = clonedeep(options || {});
|
||||
opts.data = file.contents.toString();
|
||||
|
||||
// we set the file path here so that libsass can correctly resolve import paths
|
||||
opts.file = file.path;
|
||||
|
||||
// Ensure `indentedSyntax` is true if a `.sass` file
|
||||
if (path.extname(file.path) === '.sass') {
|
||||
opts.indentedSyntax = true;
|
||||
}
|
||||
|
||||
// Ensure file's parent directory in the include path
|
||||
if (opts.includePaths) {
|
||||
if (typeof opts.includePaths === 'string') {
|
||||
opts.includePaths = [opts.includePaths];
|
||||
if (sassFileSrcPath) {
|
||||
const sourceFileIndex = sassMap.sources.indexOf(sassMapFile);
|
||||
// Prepend the path to all files in the sources array except the file that's being worked on
|
||||
sassMap.sources = sassMap.sources.map((source, index) => (
|
||||
index === sourceFileIndex
|
||||
? source
|
||||
: path.join(sassFileSrcPath, source)
|
||||
));
|
||||
}
|
||||
} else {
|
||||
opts.includePaths = [];
|
||||
|
||||
// Remove 'stdin' from souces and replace with filenames!
|
||||
sassMap.sources = sassMap.sources.filter((src) => src !== 'stdin' && src);
|
||||
|
||||
// Replace the map file with the original filename (but new extension)
|
||||
sassMap.file = replaceExtension(sassFileSrc, '.css');
|
||||
// Apply the map
|
||||
applySourceMap(file, sassMap);
|
||||
}
|
||||
|
||||
opts.includePaths.unshift(path.dirname(file.path));
|
||||
file.contents = sassObject.css;
|
||||
file.path = replaceExtension(file.path, '.css');
|
||||
|
||||
// Generate Source Maps if plugin source-map present
|
||||
if (file.sourceMap) {
|
||||
opts.sourceMap = file.path;
|
||||
opts.omitSourceMapUrl = true;
|
||||
opts.sourceMapContents = true;
|
||||
if (file.stat) {
|
||||
file.stat.atime = file.stat.mtime = file.stat.ctime = new Date();
|
||||
}
|
||||
|
||||
/// ///////////////////////////
|
||||
// Handles returning the file to the stream
|
||||
/// ///////////////////////////
|
||||
const filePush = (sassObj) => {
|
||||
let sassMap;
|
||||
let sassMapFile;
|
||||
let sassFileSrc;
|
||||
let sassFileSrcPath;
|
||||
let sourceFileIndex;
|
||||
callback(null, file);
|
||||
};
|
||||
|
||||
// Build Source Maps!
|
||||
if (sassObj.map) {
|
||||
// Transform map into JSON
|
||||
sassMap = JSON.parse(sassObj.map.toString());
|
||||
// Grab the stdout and transform it into stdin
|
||||
sassMapFile = sassMap.file.replace(/^stdout$/, 'stdin');
|
||||
// Grab the base file name that's being worked on
|
||||
sassFileSrc = file.relative;
|
||||
// Grab the path portion of the file that's being worked on
|
||||
sassFileSrcPath = path.dirname(sassFileSrc);
|
||||
if (sassFileSrcPath) {
|
||||
// Prepend the path to all files in the sources array except the file that's being worked on
|
||||
sourceFileIndex = sassMap.sources.indexOf(sassMapFile);
|
||||
sassMap.sources = sassMap.sources.map((source, index) => { // eslint-disable-line arrow-body-style
|
||||
return index === sourceFileIndex ? source : path.join(sassFileSrcPath, source);
|
||||
});
|
||||
/**
|
||||
* Handles error message
|
||||
*/
|
||||
const handleError = (error, file, callback) => {
|
||||
const filePath = (error.file === 'stdin' ? file.path : error.file) || file.path;
|
||||
const relativePath = path.relative(process.cwd(), filePath);
|
||||
const message = `${picocolors.underline(relativePath)}\n${error.formatted}`;
|
||||
|
||||
error.messageFormatted = message;
|
||||
error.messageOriginal = error.message;
|
||||
error.message = stripAnsi(message);
|
||||
error.relativePath = relativePath;
|
||||
|
||||
return callback(new PluginError(PLUGIN_NAME, error));
|
||||
};
|
||||
|
||||
/**
|
||||
* Main Gulp Sass function
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line arrow-body-style
|
||||
const gulpSass = (options, sync) => {
|
||||
return transfob((file, encoding, callback) => {
|
||||
if (file.isNull()) {
|
||||
callback(null, file);
|
||||
return;
|
||||
}
|
||||
|
||||
if (file.isStream()) {
|
||||
callback(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (path.basename(file.path).startsWith('_')) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!file.contents.length) {
|
||||
file.path = replaceExtension(file.path, '.css');
|
||||
callback(null, file);
|
||||
return;
|
||||
}
|
||||
|
||||
const opts = clonedeep(options || {});
|
||||
opts.data = file.contents.toString();
|
||||
|
||||
// We set the file path here so that libsass can correctly resolve import paths
|
||||
opts.file = file.path;
|
||||
|
||||
// Ensure `indentedSyntax` is true if a `.sass` file
|
||||
if (path.extname(file.path) === '.sass') {
|
||||
opts.indentedSyntax = true;
|
||||
}
|
||||
|
||||
// Ensure file's parent directory in the include path
|
||||
if (opts.includePaths) {
|
||||
if (typeof opts.includePaths === 'string') {
|
||||
opts.includePaths = [opts.includePaths];
|
||||
}
|
||||
|
||||
// Remove 'stdin' from souces and replace with filenames!
|
||||
sassMap.sources = sassMap.sources.filter((src) => src !== 'stdin' && src);
|
||||
|
||||
// Replace the map file with the original file name (but new extension)
|
||||
sassMap.file = replaceExtension(sassFileSrc, '.css');
|
||||
// Apply the map
|
||||
applySourceMap(file, sassMap);
|
||||
} else {
|
||||
opts.includePaths = [];
|
||||
}
|
||||
|
||||
file.contents = sassObj.css; // eslint-disable-line no-param-reassign
|
||||
file.path = replaceExtension(file.path, '.css'); // eslint-disable-line no-param-reassign
|
||||
opts.includePaths.unshift(path.dirname(file.path));
|
||||
|
||||
if (file.stat) {
|
||||
file.stat.atime = file.stat.mtime = file.stat.ctime = new Date(); // eslint-disable-line
|
||||
// Generate Source Maps if the source-map plugin is present
|
||||
if (file.sourceMap) {
|
||||
opts.sourceMap = file.path;
|
||||
opts.omitSourceMapUrl = true;
|
||||
opts.sourceMapContents = true;
|
||||
}
|
||||
|
||||
cb(null, file);
|
||||
};
|
||||
if (sync !== true) {
|
||||
/**
|
||||
* Async Sass render
|
||||
*/
|
||||
gulpSass.compiler.render(opts, (error, obj) => {
|
||||
if (error) {
|
||||
handleError(error, file, callback);
|
||||
return;
|
||||
}
|
||||
|
||||
/// ///////////////////////////
|
||||
// Handles error message
|
||||
/// ///////////////////////////
|
||||
const errorM = (error) => {
|
||||
const filePath = (error.file === 'stdin' ? file.path : error.file) || file.path;
|
||||
const relativePath = path.relative(process.cwd(), filePath);
|
||||
const message = [chalk.underline(relativePath), error.formatted].join('\n');
|
||||
|
||||
error.messageFormatted = message; // eslint-disable-line no-param-reassign
|
||||
error.messageOriginal = error.message; // eslint-disable-line no-param-reassign
|
||||
error.message = stripAnsi(message); // eslint-disable-line no-param-reassign
|
||||
error.relativePath = relativePath; // eslint-disable-line no-param-reassign
|
||||
|
||||
return cb(new PluginError(PLUGIN_NAME, error));
|
||||
};
|
||||
|
||||
if (sync !== true) {
|
||||
/// ///////////////////////////
|
||||
// Async Sass render
|
||||
/// ///////////////////////////
|
||||
const callback = (error, obj) => { // eslint-disable-line consistent-return
|
||||
if (error) {
|
||||
return errorM(error);
|
||||
filePush(file, obj, callback);
|
||||
});
|
||||
} else {
|
||||
/**
|
||||
* Sync Sass render
|
||||
*/
|
||||
try {
|
||||
filePush(file, gulpSass.compiler.renderSync(opts), callback);
|
||||
} catch (error) {
|
||||
handleError(error, file, callback);
|
||||
}
|
||||
filePush(obj);
|
||||
};
|
||||
|
||||
gulpSass.compiler.render(opts, callback);
|
||||
} else {
|
||||
/// ///////////////////////////
|
||||
// Sync Sass render
|
||||
/// ///////////////////////////
|
||||
try {
|
||||
filePush(gulpSass.compiler.renderSync(opts));
|
||||
} catch (error) {
|
||||
return errorM(error);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/// ///////////////////////////
|
||||
// Sync Sass render
|
||||
/// ///////////////////////////
|
||||
/**
|
||||
* Sync Sass render
|
||||
*/
|
||||
gulpSass.sync = (options) => gulpSass(options, true);
|
||||
|
||||
/// ///////////////////////////
|
||||
// Log errors nicely
|
||||
/// ///////////////////////////
|
||||
/**
|
||||
* Log errors nicely
|
||||
*/
|
||||
gulpSass.logError = function logError(error) {
|
||||
const message = new PluginError('sass', error.messageFormatted).toString();
|
||||
process.stderr.write(`${message}\n`);
|
||||
@@ -164,17 +181,13 @@ module.exports = (compiler) => {
|
||||
if (!compiler || !compiler.render) {
|
||||
const message = new PluginError(
|
||||
PLUGIN_NAME,
|
||||
'\n'
|
||||
+ 'gulp-sass 5 does not have a default Sass compiler; please set one yourself.\n'
|
||||
+ 'Both the `sass` and `node-sass` packages are permitted.\n'
|
||||
|
||||
+ 'For example, in your gulpfile:\n\n'
|
||||
+ ' var sass = require(\'gulp-sass\')(require(\'sass\'));\n',
|
||||
MISSING_COMPILER_MESSAGE,
|
||||
{ showProperties: false },
|
||||
).toString();
|
||||
process.stderr.write(`${message}\n`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
gulpSass.compiler = compiler;
|
||||
return gulpSass;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user