Add `undefined` check
michael-ciniawsky opened this issue · 3 comments
michael-ciniawsky commented
Details
Check forundefined
in the plugin loader (postcss-load-plugins #67)
- if (options === null || Object.keys(options).length === 0)
+ if (options === null || options === undefined || Object.keys(options).length === 0)
Its being tested only if the options {Object}
is null
, if the {Object}
is not null
it tries to
look at the keys of the {Object}
, but I believe that its being forgotten the case when the options {Object}
is undefined
Error (Logs|Stacks)
postcss.config.js
module.exports = ({ file, options, env }) => {
return {
parser: file.extname === '.sss' ? 'sugarss' : false,
plugins: {
'postcss-import': { root: file.dirname },
'postcss-cssnext': options.cssnext ? options.cssnext : false, // <=
'autoprefixer': env == 'production' ? options.autoprefixer : false,
'cssnano': env === 'production' ? options.cssnano : false
}
}
}
Module build failed: TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at load (/home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:42:38)
at /home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:66:18
at Array.forEach (<anonymous>)
at plugins (/home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-plugins/lib/plugins.js:65:8)
at /home/matheus/Repositorios/fidelidade-online/node_modules/postcss-load-config/index.js:64:18
at <anonymous>
Reproduction (Code)
- Not needed
Environment
- Not needed
arthurbuhl commented
I think maybe we can just do:
- if (options === null || options === undefined || Object.keys(options).length === 0)
+ if (!options || Object.keys(options).length === 0)
michael-ciniawsky commented
Would love to but !options
coerces null
, false
, undefined
to false
, while options === false
means don't load this plugin in postcss-load-config
e.g
.postcssrc.js
module.exports = ({ options, env }) => {
plugins: {
// Check for options.plugin === 'undefined',
// but load the plugin with defaults (the current bug)
'postcss-plugin': options.plugin
// if env === 'development' don't load the plugin
'cssnano': env === 'production' ? null : false
}
}
arthurbuhl commented
Ok, that make sense then.