babel-plugin-stylus-compiler
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -23,4 +23,19 @@ 'use strict'; | ||
/* | ||
MODULE REGEX WILL RETURN STYLUS NODE_MODULE IMPORT | ||
WILL RETURN TRUE FOR | ||
* @import '~module' | ||
* @require '~another-module' | ||
WILL RETURN FALSE FOR | ||
* @require 'module.styl' | ||
* @require 'module' | ||
* div ~ input | ||
*/ | ||
/* global process */ | ||
var MODULE_REGEX = /(~*@).*/; | ||
var fileExists = function fileExists(filename) { | ||
@@ -53,2 +68,8 @@ try { | ||
var stylusContent = _fs2.default.readFileSync(path, 'utf8'); | ||
if (stylusContent.match(MODULE_REGEX) !== null) { | ||
var match = stylusContent.match(MODULE_REGEX); | ||
stylusContent = stylusContent.replace(MODULE_REGEX, match[0].replace('~', '')); | ||
} | ||
return (0, _stylus2.default)(stylusContent).include((0, _path.dirname)(path)).include((0, _path.resolve)('./node_modules')).use((0, _autoprefixerStylus2.default)()).render().replace(/\n/g, ' '); | ||
@@ -55,0 +76,0 @@ }; |
{ | ||
"name": "babel-plugin-stylus-compiler", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "A Babel 6 plugin for compiling stylus files into css", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -8,2 +8,17 @@ /* global process */ | ||
/* | ||
MODULE REGEX WILL RETURN STYLUS NODE_MODULE IMPORT | ||
WILL RETURN TRUE FOR | ||
* @import '~module' | ||
* @require '~another-module' | ||
WILL RETURN FALSE FOR | ||
* @require 'module.styl' | ||
* @require 'module' | ||
* div ~ input | ||
*/ | ||
const MODULE_REGEX = /(~*@).*/; | ||
const fileExists = filename => { | ||
@@ -35,3 +50,9 @@ try { | ||
const stylusContent = fs.readFileSync(path, 'utf8'); | ||
let stylusContent = fs.readFileSync(path, 'utf8'); | ||
if (stylusContent.match(MODULE_REGEX) !== null) { | ||
const match = stylusContent.match(MODULE_REGEX); | ||
stylusContent = stylusContent.replace(MODULE_REGEX, match[0].replace('~', '')); | ||
} | ||
return stylus(stylusContent) | ||
@@ -38,0 +59,0 @@ .include(dirname(path)) |
@@ -0,10 +1,40 @@ | ||
/* globals it describe require __dirname process */ | ||
require('mocha'); | ||
var babel = require("babel-core"); | ||
var babel = require('babel-core'); | ||
var fs = require('fs'); | ||
var exec = require('child_process').exec; | ||
var path = require('path'); | ||
var should = require('chai').should(); | ||
var babelOptions = { | ||
'babelrc': false, | ||
'plugins': [__dirname + '/../'], | ||
'babelrc': false, | ||
}; | ||
var createTestNodeModule = function(json, css, test) { | ||
fs.mkdirSync(path.resolve('./node_modules/') + '/' + json.name); | ||
fs.writeFileSync( | ||
path.resolve('./node_modules/') + '/' + json.name + '/package.json', JSON.stringify(json) | ||
); | ||
fs.writeFileSync( | ||
path.resolve('./node_modules/') + '/' + json.name + '/' + json.main, css | ||
); | ||
test(); | ||
}; | ||
var cleanupNodeModuleTest = function(json) { | ||
var command = /^win/.test(process.platform) | ||
? 'RMDIR /S' | ||
: 'rm -r '; | ||
exec(command + path.resolve('./node_modules/') + '/' + json.name, function(err) { | ||
if (err) { | ||
throw Error('An error occurred cleaning up test for ' + json.name); | ||
} | ||
}); | ||
}; | ||
describe('babel-plugin-stylus-compiler', function() { | ||
@@ -15,3 +45,3 @@ it('should compile stylus to css and assign to a variable if specifier in import', function(done) { | ||
should.exist(result); | ||
result.code.should.equal("var css = 'div { border: 1px solid #000; display: -webkit-box; display: -ms-flexbox; display: flex; } ';"); | ||
result.code.should.equal('var css = \'div { border: 1px solid #000; display: -webkit-box; display: -ms-flexbox; display: flex; } \';'); | ||
done(); | ||
@@ -25,6 +55,31 @@ }); | ||
should.exist(result); | ||
result.code.should.equal('var _css = document.createElement(\'style\');\n\n_css.innerHTML = \'div { border: 1px solid #000; display: -webkit-box; display: -ms-flexbox; display: flex; } \'\ndocument.head.appendChild(_css)') | ||
result.code.should.equal('var _css = document.createElement(\'style\');\n\n_css.innerHTML = \'div { border: 1px solid #000; display: -webkit-box; display: -ms-flexbox; display: flex; } \'\ndocument.head.appendChild(_css)'); | ||
done(); | ||
}); | ||
}); | ||
it('should compile stylus to css from node_module and assign to a variable if specifier in import', function(done) { | ||
var json = { | ||
main: 'main.styl', | ||
name: 'node-module-for-import', | ||
}; | ||
var css = '$font-size = 13px'; | ||
createTestNodeModule(json, css, function() { | ||
babel.transformFile(__dirname + '/node-module-for-import.js', babelOptions, function (err, result) { | ||
should.not.exist(err); | ||
should.exist(result); | ||
result.code.should.equal('var css = \'div { font-size: 13px; } \';'); | ||
done(); | ||
cleanupNodeModuleTest(json); | ||
}); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14428
15
278
7
1