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

sass-module-importer

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sass-module-importer - npm Package Compare versions

Comparing version 1.2.1 to 1.3.1

fixtures/_colors.scss

53

lib/index.js

@@ -22,4 +22,6 @@ 'use strict';

if (this.aliases.has(url)) {
return Promise.resolve(this.aliases.get(url));
var fullPath = prev === 'stdin' ? url : path.resolve(path.dirname(prev), url);
if (this.aliases.has(fullPath)) {
return Promise.resolve(this.aliases.get(fullPath));
}

@@ -32,3 +34,5 @@

.then(function (res) {
this$1.aliases.set(url, res);
if (res) {
this$1.aliases.set(fullPath, res);
}
return res;

@@ -39,4 +43,11 @@ });

ModuleImporter.prototype.filter = function filter(pkg) {
if (!pkg.main || (pkg.main && !pkg.main.match(/\.s?[c|a]ss$/g))) {
pkg.main = pkg.style || pkg['main.scss'] || pkg['main.sass'] || 'index.css';
var regex = /\.s?[c|a]ss$/g;
if (!pkg.main ||
(typeof pkg.main !== 'string') ||
(pkg.main && !pkg.main.match(regex))) {
if (typeof pkg.main === 'object') {
pkg.main = pkg.main.find(function ( elem ) { return elem.match(regex); });
} else {
pkg.main = pkg.style || pkg.sass || pkg['main.scss'] || pkg['main.sass'] || 'index.css';
}
}

@@ -69,16 +80,20 @@ return pkg;

return new Promise(function (resolve, reject) {
if (url.match(/\.css$/g)) {
fs.readFile(url, 'utf8', function (err, contents) {
if (err) {
reject(err);
} else {
resolve({ contents: contents });
if (!resolved) {
resolve();
} else {
if (url.match(/\.css$/g)) {
fs.readFile(url, 'utf8', function (err, contents) {
if (err) {
reject(err);
} else {
resolve({ contents: contents });
}
});
} else {
var resolvedURL = url;
if (!resolved && prev && prev !== 'stdin' && !path.isAbsolute(url)) {
resolvedURL = path.resolve(path.dirname(prev), url);
}
});
} else {
var resolvedURL = url;
if (!resolved && prev && prev !== 'stdin' && !path.isAbsolute(url)) {
resolvedURL = path.resolve(path.dirname(prev), url);
resolve({ file: resolvedURL });
}
resolve({ file: resolvedURL });
}

@@ -107,3 +122,5 @@ });

return function (url, prev, done) {
importer.resolve({ url: url, prev: prev }).then(done);
importer.resolve({ url: url, prev: prev })
.then(done)
.catch(function ( err ) { return setImmediate(function () { throw err; }); });
};

@@ -110,0 +127,0 @@ }

{
"name": "sass-module-importer",
"version": "1.2.1",
"version": "1.3.1",
"main": "lib/index.js",

@@ -44,3 +44,3 @@ "jsnext:main": "src/index.js",

"rollup-plugin-buble": "^0.5.0",
"rollup-plugin-commonjs": "^2.2.1",
"rollup-plugin-commonjs": "^3.1.0",
"rollup-plugin-json": "^2.0.0",

@@ -47,0 +47,0 @@ "rollup-plugin-node-resolve": "^1.5.0"

@@ -44,2 +44,3 @@ [![Build Status](https://travis-ci.org/lucasmotta/sass-module-importer.svg?branch=master)](https://travis-ci.org/lucasmotta/sass-module-importer)

## How-to

@@ -79,2 +80,15 @@

### import partials
If you need to import partials from your external module, just use the path for the partial you want to import. To import the following file:
```
node_modules/module-name/folder/to/_file.scss
```
Import like this anywhere:
```scss
@import "module-name/folder/to/_file.scss"
```
## Options

@@ -81,0 +95,0 @@ You can pass any option supported by [node-resolve](https://github.com/substack/node-resolve#resolveid-opts-cb) directly, like this:

@@ -14,2 +14,3 @@ /* eslint max-len: 0 */

outputStyle: 'compressed',
includePaths: [path.join(__dirname, 'fixtures')],
importer: moduleImporter({

@@ -31,3 +32,3 @@ basedir: path.join(__dirname, 'fixtures'),

it('should import a local file', (done) => {
getCSS(null, '@import "fixtures/dummy";').then((css) => {
getCSS(null, '@import "dummy";').then((css) => {
const expected = 'body{content:"local"}\n';

@@ -97,2 +98,10 @@ expect(css).to.exist.and.equal(expected);

});
it('should import a partial from a npm module', (done) => {
getCSS(null, '@import "test-normalize/normalize/_body.scss";').then((css) => {
const expected = 'html,body{margin:0;padding:0}\n';
expect(css).to.exist.and.equal(expected);
done();
});
});
});

@@ -140,3 +149,29 @@

});
it('should import the first style file from the "main" option if it is an object', (done) => {
getCSS(null, '@import "test-bower-main-array";').then((css) => {
const expected = `.test{content:"CSS from first file in 'main' array"}\n`;
expect(css).to.exist.and.equal(expected);
done();
});
});
});
describe('module vs local file', () => {
it('should import external colors module', (done) => {
getCSS(null, '@import "colors";').then((css) => {
const expected = '.colors{content:"Colors library"}\n';
expect(css).to.exist.and.equal(expected);
done();
});
});
it('should import local colors if using relative path', (done) => {
getCSS(null, '@import "./colors";').then((css) => {
const expected = '.red{color:red}.green{color:green}\n';
expect(css).to.exist.and.equal(expected);
done();
});
});
});
});
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