Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
sassJs.importer(function(request, done) {
// Adapted from
// eslint-disable-next-line max-len
// https://github.com/amiramw/grunt-contrib-sassjs/blob/a65f869df967a4e417c4260fd93239e4f0bc55ee/tasks/sass.js#L11
if (request.path) {
done();
} else if (request.resolved) {
var realPath = request.resolved.replace(/^\/sass\//, ''),
pathVariations = sassJs.getPathVariations(realPath);
q.all(_.map(pathVariations, function(pathVariation) {
return qFs.read(pathVariation)
.then(function(fileContents) {
return {
path: pathVariation,
content: fileContents
};
})
.catch(function(err) {
if (err.code === 'ENOENT') {
return null;
}
throw err;
});
})).then(function(files) {
Sass.importer(function (request, done) {
if (request.path) {
done();
} else if (request.resolved) {
var realPath = request.resolved.replace(/^\/sass\//, "");
done(Sass.getPathVariations(realPath).reduce(function (found, path) {
if (found) {
return found;
}
if (grunt.file.exists(path) && !grunt.file.isDir(path)) {
return {
path: request.resolved.substr(0, request.resolved.lastIndexOf('/') + 1) + PATH.basename(path),
content: grunt.file.read(path)
};
}
return null;
}, null));
} else {
done();
}
});
grunt.registerMultiTask('sass', 'Compile Sass to CSS', function () {
function getPathVariations(filePath, rawPath) {
var pathToUse = rawPath || path,
pathVariations = sassJs.getPathVariations(pathToUse.basename(filePath));
return pathVariations.map(function(pathVariation) {
return pathToUse.join(pathToUse.dirname(filePath), pathVariation);
});
}
sass.importer(async (request, done) => {
const possiblePaths = sass.getPathVariations(request.resolved)
for (let path of possiblePaths) {
const fullpath = origin + path
if (await checkResourceByUrl(fullpath)) {
const content = await fetchContent(fullpath)
done({content})
break
}
}
})