Socket
Socket
Sign inDemoInstall

stylus-loader

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stylus-loader - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

42

index.js
var loaderUtils = require('loader-utils');
var stylus = require('stylus');
var nib = require('nib');
var path = require('path');
var fs = require('fs');
module.exports = function(source) {
var self = this;
this.cacheable && this.cacheable();

@@ -12,2 +15,3 @@ var done = this.async();

var styl = stylus(source);
var paths = [path.dirname(options.filename)];

@@ -19,5 +23,7 @@ function needsArray(value) {

if (options.paths && !Array.isArray(options.paths)) {
paths = paths.concat(options.paths);
options.paths = [options.paths];
}
var manualImports = [];
Object.keys(options).forEach(function(key) {

@@ -38,2 +44,3 @@ var value = options[key];

styl.import(stylusModule);
manualImports.push(stylusModule);
});

@@ -45,4 +52,20 @@ } else {

// TODO call this.addDependency for each imported stylus file
// to fix watch mode
extractImports(source).concat(manualImports).map(function(dep) {
var filepath = null;
for (var i = 0; i < paths.length; i++) {
filepath = path.resolve(paths[i], dep);
if (!fs.existsSync(filepath)) {
filepath = path.resolve(paths[i], dep + '.styl');
if (fs.existsSync(filepath)) break;
} else {
break;
}
}
return fs.existsSync(filepath) ? filepath : null;
}).filter(function(dep) {
return !!dep;
}).forEach(function(dep) {
self.addDependency(dep);
});
styl.use(nib());

@@ -54,1 +77,16 @@ styl.render(function(err, css) {

}
// Not the best way but it works for now
function extractImports(source) {
var imports = [];
var regex = /@import *[\'|\"]([^\'|\"]+)*/gi;
var matches = regex.exec(source);
if (matches) {
imports.push(matches[1]);
while (matches != null) {
matches = regex.exec(source);
if (matches) imports.push(matches[1]);
}
}
return imports || [];
}

6

package.json
{
"name": "stylus-loader",
"version": "0.1.1",
"version": "0.2.0",
"description": "Stylus loader for webpack",

@@ -19,4 +19,4 @@ "main": "index.js",

"dependencies": {
"stylus": "~0.39.4",
"nib": "~1.0.1",
"stylus": "~0.42.2",
"nib": "~1.0.2",
"loader-utils": "~0.2.1"

@@ -23,0 +23,0 @@ },

@@ -46,2 +46,3 @@ # stylus-loader

## Release History
* 0.2.0 - Now tracks dependencies for @import statements making cacheable work
* 0.1.0 - Initial release

@@ -48,0 +49,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc