@dietechniker/gulp-sass-dependency-tracker
Advanced tools
Comparing version
{ | ||
"name": "@dietechniker/gulp-sass-dependency-tracker", | ||
"version": "1.1.3", | ||
"version": "1.2.0", | ||
"description": "A NodeJS gulp package to optimize sass compilation - only compile what you actually changed.", | ||
"keywords": [ | ||
"gulp", | ||
"gulpplugin", | ||
"sass", | ||
@@ -36,3 +37,3 @@ "dependency", | ||
"path.join": "^1.0.0", | ||
"readable-stream": "^3.0.6", | ||
"readable-stream": "^3.2.0", | ||
"relative": "^3.0.2" | ||
@@ -39,0 +40,0 @@ }, |
@@ -17,3 +17,3 @@ # GulpSassDependencyTracker [](https://badge.fury.io/gh/DieTechniker%2Fgulp-sass-dependency-tracker) [](https://badge.fury.io/js/%40dietechniker%2Fgulp-sass-dependency-tracker) | ||
const fileGlob = 'resources/sass/**/*.scss'; | ||
const fileGlob = 'resources/sass/**/*.s[a|c]ss'; | ||
@@ -93,4 +93,5 @@ gulp.task('sass', function () { | ||
debug: false // Whether or not to provide debug log message (e.g. from the dependency detection) | ||
suppressOutput: false // Whether or not to suppress all console messages | ||
suppressOutput: false // Whether or not to suppress all console messages, | ||
filterNonSass: false // Whether or ot to exclude non-sass files from the stream when running through #filter | ||
} | ||
``` |
@@ -21,3 +21,3 @@ 'use strict'; | ||
const importRegex = /@import ['"]([\w./-]+)['"];/g; | ||
const importRegex = /@import ['"]?([\w./-]+)(?:['"];)?/g; | ||
@@ -42,3 +42,3 @@ /** | ||
*/ | ||
constructor(options = {debug: false, suppressOutput: false}) { | ||
constructor(options = {debug: false, suppressOutput: false, filterNonSass: false}) { | ||
this.sassTree = new SassDependencyTree(options); | ||
@@ -50,2 +50,3 @@ this.options = options; | ||
* Internal method for checking the debug setting. | ||
* @return {boolean} | ||
*/ | ||
@@ -58,2 +59,3 @@ isDebug() { | ||
* Internal function for checking if the output should be suppressed. | ||
* @return {boolean} | ||
*/ | ||
@@ -65,2 +67,10 @@ isOutputSuppressed() { | ||
/** | ||
* Whether or not non-sass files will be removed from the stream by {@link filter} | ||
* @return {boolean} | ||
*/ | ||
isNonSassFiltered() { | ||
return this.option.filterNonSass || false; | ||
} | ||
/** | ||
* Filters the stream to only include files that need to be recompiled. | ||
@@ -72,4 +82,11 @@ * | ||
const me = this; | ||
return gIgnore.include(function (file) { | ||
return !file.path.endsWith('.scss') || !me.getTree().isCompiled(file); | ||
const isSassFile = file => { | ||
return file.path.endsWith('.scss') || file.path.endsWith('.sass') | ||
}; | ||
return gIgnore.exclude(function (file) { | ||
// Exclude the file when: | ||
// * It is a non-sass file and should be excluded | ||
// * OR: It is tracked as compiled | ||
return (!isSassFile(file) && me.isNonSassFiltered()) || me.getTree().isCompiled(file); | ||
}); | ||
@@ -87,3 +104,3 @@ } | ||
return inspectStream(importRegex, function (match, file) { | ||
if (file.path.endsWith('.scss')) { | ||
if (file.path.endsWith('.scss') || file.path.endsWith('.sass')) { | ||
me.reportImport(match, file, sassOptions); | ||
@@ -122,3 +139,3 @@ } | ||
for (let filePath of file.history) { | ||
if (filePath.endsWith('.scss')) { | ||
if (filePath.endsWith('.scss') || filePath.endsWith('.sass')) { | ||
me.getTree().markAsCompiled(filePath); | ||
@@ -152,2 +169,6 @@ } | ||
if (importPath === null || importPath === undefined) { | ||
throw new Error(`No regex group for import match: ${match}`); | ||
} | ||
if (this.isDebug() && !this.isOutputSuppressed()) { | ||
@@ -154,0 +175,0 @@ logging.log.info(logging.colors.debug(`Found import: "${importPath}" in ${filePath}`)); |
@@ -16,4 +16,5 @@ 'use strict'; | ||
function resolveSassImport(importPath, includePath, contextPath) { | ||
if (!importPath.endsWith('.scss')) { | ||
importPath = importPath + '.scss'; | ||
let lookupPath = importPath; | ||
if (!lookupPath.endsWith('.scss') && !lookupPath.endsWith('.sass')) { | ||
lookupPath = lookupPath + '.scss'; | ||
} | ||
@@ -33,5 +34,5 @@ | ||
let containsSep = importPath.includes('/'); | ||
let base = containsSep ? importPath.substr(0, importPath.lastIndexOf('/')) + '/' : ''; | ||
let fileName = containsSep ? importPath.substr(importPath.lastIndexOf('/') + 1) : importPath; | ||
let containsSep = lookupPath.includes('/'); | ||
let base = containsSep ? lookupPath.substr(0, lookupPath.lastIndexOf('/')) + '/' : ''; | ||
let fileName = containsSep ? lookupPath.substr(lookupPath.lastIndexOf('/') + 1) : lookupPath; | ||
@@ -51,4 +52,10 @@ let build = (a,b) => { return path.normalize(path.join(absoluteIncludePath, path.join(a,b)))}; | ||
let relativeContext = path.relative(absoluteIncludePath, contextPath); | ||
let fixedPath = path.normalize(path.join(relativeContext, importPath)); | ||
let fixedPath = path.normalize(path.join(relativeContext, lookupPath)); | ||
return resolveSassImport(fixedPath, includePath, null); | ||
} else if (!importPath.endsWith('.scss') && !importPath.endsWith('.sass') && lookupPath.endsWith('.scss')) { | ||
// When the file type has not been explicitly provided and we only looked for an SCSS file, | ||
// also look for a sassy version ending in ".sass" | ||
let sassyPath = `${importPath}.sass`; | ||
return resolveSassImport(sassyPath, includePath, contextPath); | ||
} | ||
@@ -55,0 +62,0 @@ |
63254
2.37%524
4.8%95
1.06%Updated