Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-stylus-compiler

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-stylus-compiler - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

test/module.styl

21

build/index.js

@@ -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 @@ };

2

package.json
{
"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);
});
});
});
});
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