css-modules / css-modules-require-hook

A require hook to compile CSS Modules in runtime

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handle missing extension hook for ignored files

petejodo opened this issue · comments

Currently, if you're trying to require a CSS file that's being ignored by the require-hook and don't have another require.extension to handle that file, an error will be thrown TypeError: existingHook is not a function. The culprit is this bit of code which assumes existingHook is defined.

If throwing an error for these cases is intended then I think it should be a custom error defined by the require hook. This way it can be handled by packages using the require hook i.e. babel-plugin-css-modules-transform and also provides some meaningful feedback to users using it directly.

Another solution is not throwing an error at all i.e.

if (isException(filename)) {
    if (existingHook) {
        existingHook(m, filename);
    }
}

but I'm not sure of the consequences for doing that. Would the resulting value just be undefined?

require('ignored.css'); // equals "undefined"?

edit
so after testing, it looks like it returns an empty object if existingHook doesn't get called