css-modules-require-hook
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -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" |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
81212
546
2