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

css-modules-require-hook

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-modules-require-hook - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

57

dist/index.js

@@ -40,2 +40,5 @@ 'use strict';

var escapedSeparator = _path.sep.replace(/(.)/g, '\\$1');
var relativePathPattern = new RegExp('^.{1,2}$|^.{1,2}' + escapedSeparator);
var defaultRoot = process.cwd();

@@ -45,4 +48,14 @@ var tokensByFile = {};

var root = defaultRoot;
var importNr = 0;
/**
* @param {string} pathname
* @return {boolean}
*/
function isModule(pathname) {
var parsed = (0, _path.parse)(pathname);
return !parsed.root && !relativePathPattern.test(parsed.dir);
}
/**
* @param {string} sourceString The file content

@@ -60,27 +73,35 @@ * @param {string} sourcePath

(0, _hook2['default'])(function (filename) {
var importNr = 0;
/**
* @param {string} _newPath
* @param {string} _relativeTo
* @param {string} _trace
* @return {object}
*/
function fetch(_newPath, _relativeTo, _trace) {
var newPath = _newPath.replace(/^["']|["']$/g, '');
var trace = _trace || String.fromCharCode(importNr++);
var fetch = function fetch(_newPath, _relativeTo, _trace) {
var newPath = _newPath.replace(/^["']|["']$/g, '');
var trace = _trace || String.fromCharCode(importNr++);
var relativeDir = (0, _path.dirname)(_relativeTo);
var rootRelativePath = (0, _path.resolve)(relativeDir, newPath);
var fileRelativePath = (0, _path.resolve)((0, _path.join)(root, relativeDir), newPath);
var relativeDir = (0, _path.dirname)(_relativeTo);
var rootRelativePath = (0, _path.resolve)(relativeDir, newPath);
var fileRelativePath = (0, _path.resolve)((0, _path.join)(root, relativeDir), newPath);
if (isModule(newPath)) {
fileRelativePath = require.resolve(newPath);
}
var tokens = tokensByFile[fileRelativePath];
if (tokens) {
return tokens;
}
var tokens = tokensByFile[fileRelativePath];
if (tokens) {
return tokens;
}
var source = (0, _fs.readFileSync)(fileRelativePath, 'utf-8');
var exportTokens = load(source, rootRelativePath, trace, fetch);
var source = (0, _fs.readFileSync)(fileRelativePath, 'utf-8');
var exportTokens = load(source, rootRelativePath, trace, fetch);
tokensByFile[fileRelativePath] = exportTokens;
tokensByFile[fileRelativePath] = exportTokens;
return exportTokens;
};
return exportTokens;
}
return fetch((0, _path.relative)(root, filename), '/');
(0, _hook2['default'])(function (filename) {
return fetch('.' + _path.sep + (0, _path.relative)(root, filename), '/');
});

@@ -87,0 +108,0 @@

{
"name": "css-modules-require-hook",
"version": "1.0.2",
"version": "1.0.3",
"description": "A require hook to compile CSS Modules on the fly",
"main": "index.js",
"engines": {
"node": ">0.12"
},
"devDependencies": {

@@ -40,3 +43,3 @@ "babel": "^5.8.20",

"type": "git",
"url": "https://github.com/sullenor/css-modules-require-hook.git"
"url": "https://github.com/css-modules/css-modules-require-hook.git"
},

@@ -54,5 +57,5 @@ "keywords": [

"bugs": {
"url": "https://github.com/sullenor/css-modules-require-hook/issues"
"url": "https://github.com/css-modules/css-modules-require-hook/issues"
},
"homepage": "https://github.com/sullenor/css-modules-require-hook",
"homepage": "https://github.com/css-modules/css-modules-require-hook",
"pre-commit": [

@@ -59,0 +62,0 @@ "test"

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