Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}
function fromFileURL(url) {
const address = decodeURIComponent(url.replace(/^file:(\/+)?/i, ''));
return path.sep === '/' ? `/${address}` : address.replace(/\//g, '\\');
}
// intercept file loading requests (@import directive) from libsass
sass.importer(async (request, done) => {
// Currently only supporting scss imports due to
// https://github.com/sass/libsass/issues/1695
let content;
let resolved;
let readImportPath;
let readPartialPath;
try {
resolved = await resolvePath(request);
const partialUrl = resolved.replace(/\/([^/]*)$/, '/_$1');
readImportPath = fromFileURL(resolved);
readPartialPath = fromFileURL(partialUrl);
content = await loadFile(readPartialPath);
} catch (e) {
try {
content = await loadFile(readImportPath);
} catch (er) {
DataPacksBuilder.prototype.compile = function (lang, source, options, cb) {
// This function contains the core code to execute compilation of source data
// add addtional languages here to support more compilation types
switch (lang) {
case 'scss':
// intercept file loading requests from libsass
sass.importer((request, done) => {
// (object) request
// (string) request.current path libsass wants to load (content of »@import "
module.exports = function(content) {
var callback = this.async();
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
};
var sassJs = require('sass.js'),
path = require('path');
sassJs.importer(function(request, done) {
console.log(request);
done();
});
sassJs.compile(
'@import "posix"',
{
inputPath: path.posix.join('nested', 'directory', 'file.scss')
}, function() {});
sassJs.compile(
'@import "win32"',
{
inputPath: path.win32.join('nested', 'directory', 'file.scss')
}, function() {});
private static _initSassJsImporter(shouldLogStatus: boolean) {
sassJs.importer(function(request, done) {
let basePath = path.join(__dirname, "../../");
if (request.current.indexOf("~igniteui-angular") !== -1) {
let fullImportPath = request.current.replace("~", "node_modules/");
let importFilePath = path.join(basePath, fullImportPath);
importFilePath = SassCompiler._convertSassImportToFilePath(importFilePath);
let importFileContent = fs.readFileSync(importFilePath, "utf8");
if (shouldLogStatus) {
console.log("Compiling " + importFilePath);
}
done({
content: importFileContent,
path: importFilePath
});
} else if (request.previous) {
let importFilePath = SassCompiler._getFilePathFromImport(request.current, request.previous);
module.exports = function (grunt) {
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));
const compileSass = (key, source, indentedSyntax = false) => {
const parsedKey = urlParse(key)
const {origin, pathname} = parsedKey
const options = {}
options.indentedSyntax = indentedSyntax
options.inputPath = pathname
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
}
}
})
return new Promise(resolve => {
sass.compile(source, options, result => {
resolve(result)
})
})