Skip to content

Commit e71934a

Browse files
committed
debugability
1 parent 5fe77aa commit e71934a

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ Short alias for the [postcss-modules-local-by-default](https://github.com/css-mo
216216

217217
[debug](https://www.npmjs.com/package/debug) package is used for debugging. So to turn it on simply specify the **DEBUG** environment variable:
218218
- `DEBUG=css-modules:fetch` — to see resolved paths to the files.
219+
- `DEBUG=css-modules:preset` — to see whether config was found or not.
219220
- `DEBUG=css-modules:setup` — to see the new options list.
220221
- `DEBUG=css-modules:*` — to see everything.
221222

lib/index.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,8 @@ const ExtractImports = require('postcss-modules-extract-imports');
1717
const Scope = require('postcss-modules-scope');
1818
const Parser = require('postcss-modules-parser');
1919

20-
/**
21-
* @param {function|regex|string} ignore glob, regex or function
22-
* @return {function}
23-
*/
24-
function buildExceptionChecker(ignore) {
25-
if (ignore instanceof RegExp) {
26-
return filepath => ignore.test(filepath);
27-
}
28-
29-
if (typeof ignore === 'string') {
30-
return filepath => globToRegex(ignore).test(filepath);
31-
}
32-
33-
return ignore || negate(identity);
34-
}
20+
const debugFetch = require('debug')('css-modules:fetch');
21+
const debugSetup = require('debug')('css-modules:setup');
3522

3623
module.exports = function setupHook({
3724
extensions = '.css',
@@ -47,6 +34,7 @@ module.exports = function setupHook({
4734
use,
4835
rootDir: context = process.cwd(),
4936
}) {
37+
debugSetup(arguments[0]);
5038
validate(arguments[0]);
5139

5240
const tokensByFile = {};
@@ -93,9 +81,12 @@ module.exports = function setupHook({
9381
? require.resolve(_to)
9482
: resolve(dirname(from), _to);
9583

84+
9685
// checking cache
9786
let tokens = tokensByFile[filename];
9887
if (tokens) {
88+
debugFetch(`${filename} → cache`);
89+
debugFetch(tokens);
9990
return tokens;
10091
}
10192

@@ -120,10 +111,29 @@ module.exports = function setupHook({
120111
processCss(lazyResult.css, filename);
121112
}
122113

114+
debugFetch(`${filename} → fs`);
115+
debugFetch(tokens);
116+
123117
return tokens;
124118
};
125119

126120
const isException = buildExceptionChecker(ignore);
127121

128122
attachHook(filename => fetch(filename, filename), '.css', isException);
129123
};
124+
125+
/**
126+
* @param {function|regex|string} ignore glob, regex or function
127+
* @return {function}
128+
*/
129+
function buildExceptionChecker(ignore) {
130+
if (ignore instanceof RegExp) {
131+
return filepath => ignore.test(filepath);
132+
}
133+
134+
if (typeof ignore === 'string') {
135+
return filepath => globToRegex(ignore).test(filepath);
136+
}
137+
138+
return ignore || negate(identity);
139+
}

preset.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
const debug = require('debug')('css-modules:preset');
12
const dirname = require('path').dirname;
23
const hook = require('.');
34
const seekout = require('seekout');
45

6+
debug('→ cmrh.conf.js');
57
const preset = seekout('cmrh.conf.js', dirname(module.parent.filename));
8+
69
if (!preset) {
7-
throw new Error('Unable to find cmrh.conf.js');
10+
debug('failure');
11+
return void hook({});
812
}
913

14+
debug('success');
1015
hook(require(preset));

0 commit comments

Comments
 (0)