From d0f0770fef6bc0c447de8c82c435e46638e948d1 Mon Sep 17 00:00:00 2001 From: Vladimir Kalmykov Date: Mon, 20 Nov 2017 23:28:23 +0300 Subject: [PATCH 1/2] support disableCache option --- src/index.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index b015092..644a3e2 100644 --- a/src/index.js +++ b/src/index.js @@ -23,6 +23,7 @@ const debugSetup = require('debug')('css-modules:setup'); module.exports = function setupHook({ camelCase, devMode, + disableCache, extensions = '.css', ignore, preprocessCss = identity, @@ -87,11 +88,14 @@ module.exports = function setupHook({ : resolve(dirname(from), _to); // checking cache - let tokens = tokensByFile[filename]; - if (tokens) { - debugFetch(`${filename} → cache`); - debugFetch(tokens); - return tokens; + let tokens + if (!disableCache) { + tokens = tokensByFile[filename]; + if (tokens) { + debugFetch(`${filename} → cache`); + debugFetch(tokens); + return tokens; + } } const source = preprocessCss(readFileSync(filename, 'utf8'), filename); @@ -103,11 +107,11 @@ module.exports = function setupHook({ tokens = lazyResult.root.exports || {}; - if (!debugMode) + if (!debugMode && !disableCache) // updating cache tokensByFile[filename] = tokens; else - // clearing cache in development mode + // clearing cache in development mode or with disableCache option delete require.cache[filename]; if (processCss) From b53a940f87f3b405131915d2ccfdb6f14a49b77c Mon Sep 17 00:00:00 2001 From: Vladimir Kalmykov Date: Tue, 21 Nov 2017 04:18:22 +0300 Subject: [PATCH 2/2] noCache --- README.md | 4 ++++ src/index.js | 11 ++++++----- src/validate.js | 1 + 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 505ec8e..3096578 100644 --- a/README.md +++ b/README.md @@ -268,6 +268,10 @@ Short alias for the [postcss-modules-local-by-default](https://github.com/css-mo Provides absolute path to the project directory. Providing this will result in better generated class names. It can be obligatory, if you run require hook and build tools (like [css-modulesify](https://github.com/css-modules/css-modulesify)) from different working directories. +### `noCache` boolean + +Do not cache module. You may need this option if you want to watch files. But expect the performance degradation when you call require for same file multiple times. + ## Debugging diff --git a/src/index.js b/src/index.js index 644a3e2..aab15c6 100644 --- a/src/index.js +++ b/src/index.js @@ -23,7 +23,7 @@ const debugSetup = require('debug')('css-modules:setup'); module.exports = function setupHook({ camelCase, devMode, - disableCache, + noCache, extensions = '.css', ignore, preprocessCss = identity, @@ -38,6 +38,7 @@ module.exports = function setupHook({ use, rootDir: context = process.cwd(), }) { + console.log('noCache', noCache); debugSetup(arguments[0]); validate(arguments[0]); @@ -88,8 +89,8 @@ module.exports = function setupHook({ : resolve(dirname(from), _to); // checking cache - let tokens - if (!disableCache) { + let tokens; + if (!noCache) { tokens = tokensByFile[filename]; if (tokens) { debugFetch(`${filename} → cache`); @@ -107,11 +108,11 @@ module.exports = function setupHook({ tokens = lazyResult.root.exports || {}; - if (!debugMode && !disableCache) + if (!debugMode && !noCache) // updating cache tokensByFile[filename] = tokens; else - // clearing cache in development mode or with disableCache option + // clearing cache in development mode or with noCache option delete require.cache[filename]; if (processCss) diff --git a/src/validate.js b/src/validate.js index 7b76c95..08706bf 100644 --- a/src/validate.js +++ b/src/validate.js @@ -30,6 +30,7 @@ const rules = { hashPrefix: 'string', mode: 'string', rootDir: 'string', + noCache: 'boolean', }; const tests = {