Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function (data, filename) {
var renderer,
result,
imports = [];
renderer = stylus(data, {
paths: [ path.dirname(filename) ],
filename: filename,
_imports: imports,
'include css': true // include CSS on `@import`
});
// monkey-patch lookup with resolver
stylus.utils.find = function (lookupFile, lookupPaths, thisFilename) {
return origFind(resolvePath(lookupFile), lookupPaths, thisFilename);
};
// render stylus file and restore lookup function
result = renderer.render();
stylus.utils.find = origFind;
return {
css: result,
// array of imported file names, including current one
imports: _.map(imports, function (entry) { return entry.path; })
};
};
//
'use strict';
var _ = require('lodash');
var path = require('path');
var stylus = require('stylus');
////////////////////////////////////////////////////////////////////////////////
// keep reference to original lookup function of stylus
var origFind = stylus.utils.find;
// resolves `/path/name` pathnames
function resolvePath(file) {
file = String(file);
if (file[0] !== '.') {
try {
file = require.resolve(file);
} catch (err) {
// do nothing - stylus should report itself
}
}
return file;
}
return Promise.resolve().then(() => {
const stylus = require('stylus');
const origFind = stylus.utils.find;
// monkey-patch lookup with resolver
stylus.utils.find = function (lookupFile, lookupPaths, thisFilename) {
return origFind(resolvePath(lookupFile), lookupPaths, thisFilename);
};
let style = stylus(context.asset.source, {
paths: [ path.dirname(context.asset.logicalPath) ],
filename: context.asset.logicalPath,
_imports: [],
'include css': true,
sourcemap: !context.bundler.sourceMaps ? false : {
comment: false
}
});
context.asset.source = style.render();
// add Stylus `@import`s as dependencies of current asset
_.forEach(style.options._imports, imported => {
return Promise.resolve().then(() => {
const stylus = require('stylus');
const origFind = stylus.utils.find;
// monkey-patch lookup with resolver
stylus.utils.find = function (lookupFile, lookupPaths, thisFilename) {
return origFind(resolvePath(lookupFile), lookupPaths, thisFilename);
};
let style = stylus(context.asset.source, {
paths: [ path.dirname(context.asset.logicalPath) ],
filename: context.asset.logicalPath,
_imports: [],
'include css': true,
sourcemap: !context.bundler.sourceMaps ? false : {
comment: false
}
});
/*!
* nib
* Copyright (c) 2010 TJ Holowaychuk
* MIT Licensed
*/
/**
* Module dependencies.
*/
var stylus = require('stylus')
, path = require('path')
, nodes = stylus.nodes
, utils = stylus.utils
, Canvas
exports = module.exports = plugin;
// conditionally expose canvas-based APIs.
try {
Canvas = require('canvas');
var gradient = require('./nodes/gradient')
, colorImage = require('./nodes/color-image')
} catch (err) {
// ignore
}
/**
/*!
* nib
* Copyright (c) 2010 TJ Holowaychuk
* MIT Licensed
*/
/**
* Module dependencies.
*/
var stylus = require('stylus')
, nodes = stylus.nodes
, utils = stylus.utils
, Canvas
exports = module.exports = plugin;
// conditionally expose canvas-based APIs.
try {
Canvas = require('canvas');
var gradient = require('./nodes/gradient')
, colorImage = require('./nodes/color-image')
} catch (err) {
// ignore
}
/**
/**
* Module dependencies.
*/
var stylus = require('stylus'),
Canvas = require('canvas'),
nodes = stylus.nodes,
utils = stylus.utils;
/**
* Expose `ColorImage`.
*/
exports = module.exports = ColorImage;
/**
* Create a new `ColorImage` node with the given `color`.
*
* @param {Color} color node
* @return {ColorImage}
* @api public
*/
exports.create = function(color){
/**
* Module dependencies.
*/
var stylus = require('stylus')
, Canvas = require('canvas')
, nodes = stylus.nodes
, utils = stylus.utils
/**
* Expose `ColorImage`.
*/
exports = module.exports = ColorImage;
/**
* Create a new `ColorImage` node with the given `color`.
*
* @param {Color} color node
* @return {ColorImage}
* @api public
*/
exports.create = function(color){
/**
* Module dependencies.
*/
var stylus = require('stylus'),
Canvas = require('canvas'),
nodes = stylus.nodes,
utils = stylus.utils;
/**
* Expose `Gradient`.
*/
exports = module.exports = Gradient;
/**
* Create a new `Gradient` node with the given `size`
* and `start` position.
*
* @param {Number} size
* @param {String|Ident|Literal} start
* @return {Gradient}
* @api public
*/
style.define('exists', function(file) {
return !!stylus.utils.lookup(file.string, this.paths);
});