Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add undefined check #154

Closed
michael-ciniawsky opened this issue Jul 13, 2018 · 3 comments · Fixed by #177
Closed

Add undefined check #154

michael-ciniawsky opened this issue Jul 13, 2018 · 3 comments · Fixed by #177

Comments

@michael-ciniawsky
Copy link
Collaborator

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
Copy link

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
Copy link
Collaborator Author

michael-ciniawsky commented Jul 14, 2018

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
Copy link

Ok, that make sense then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants