hapipal / confidence

Dynamic, declarative configurations
Other
263 stars 43 forks source link

"Invalid node object type" with Regexp #22

Closed SimonDegraeve closed 9 years ago

SimonDegraeve commented 10 years ago

Hi,

I use Confidence to build my webpack configuration. So I need to use a Regexp in the "loaders" part of webpack configuration but this is throwing an error.

Any suggestion how I can use Regexp? And why they are forbidden in Confidence?

Thanks

SimonDegraeve commented 10 years ago

This is a quick workaround for anybody having the same issue:

var regexp = function(pattern) {
  pattern = new RegExp(pattern);
  this.test = function(str) {
    return pattern.test(str);
  };
};

new regexp('\.scss$') // will not throw an error
kpdecker commented 10 years ago

An example of the error would be helpful here. Even better would be example code that is failing.

SimonDegraeve commented 10 years ago

Any value that is a RegExp in the Confidence object will throw the error because of this line. So it is not really a bug but I am wondering why RegExp are not allowed.

kpdecker commented 10 years ago

I suspect that it's due to JSON not supporting regexs. @hueniverse is this the case?

I agree that this is detrimental for users who are using JS literals or ALCE to parse the confidence file as both of those situations supoprt RegEx literals

hueniverse commented 10 years ago

I need to see an actual config where you want to use Regex. The referenced line is there to prevent invalid nodes.

patrickkettner commented 9 years ago

ping @SimonDegraeve

SimonDegraeve commented 9 years ago

Hi sorry for the delay. I am not using confidence anymore. Feel free to close the issue. I will be back with a full example when I have a chance to use this library again.

taddei commented 9 years ago

ho about something like this?

var store = new Confidence.Store({
    webpack: {
        $filter: 'env',
        production: {
            entry: constants.src.js,
            output:  {
                path:     constants.dest.js.prod,
                filename: '[name].js' // Template based on keys in entry above
            },
            module: {
                loaders: [{
                    test: /\.jsx$/,
                    loader: 'jsx-loader'
                }]
            }
        },
        $default: {
            watch:   true,
            entry:   constants.src.js,
            output:  {
                path:     constants.dest.js.dev,
                filename: '[name].js' // Template based on keys in entry above
            },
            module:  {
                loaders: [{
                    test:   /\.jsx$/,
                    loader: 'jsx-loader'
                },
                {
                    test:   /\.css/,
                    loader: 'css-loader'
                }]
            }
        }
    }
});
prashaantt commented 8 years ago

I'm also trying to create a Webpack plugin, and need to pass a Webpack config object to it that uses the test RegExp property:


// webpack.config.js

module.exports = {
    module: {
      loaders: [{
        test: /\.jsx?/,
        loaders: ['babel'],
        presets: ['react', 'es2015']
      }]
    }
};
// manifest.js
// using the latest Glue syntax

const manifest = {
    registrations: [
        {
            plugin: {
                register: './my-plugin',
                options: {
                    config: require('./webpack.config.js')
                }
            }
        }
    ]
};

Confidence 1.4.2 throws me this error:

Error: Invalid node object type
    at error (/Users/user/project/node_modules/confidence/lib/store.js:211:22)
danielbayerlein commented 8 years ago

@patrickkettner I have the same problem as @prashaantt. Any idea?

patrickkettner commented 8 years ago

@danielbayerlein have you tried the above workaround?

danielbayerlein commented 8 years ago

@patrickkettner The workaround does not work well with webpack v2.1.0-beta because the webpack default configuration used RegEx. See https://github.com/webpack/webpack/blob/6b0c20a53ad7b04d4282a8a5c334ea0982fd364c/lib/WebpackOptionsDefaulter.js#L25

danielbayerlein commented 8 years ago

@patrickkettner Can we add a support for RegEx?

patrickkettner commented 7 years ago

@hueniverse do you recall the original reason for marking regexp as an invalid type?

hueniverse commented 7 years ago

No idea.

damusix commented 6 years ago

Any fix for this? still getting it

orditeck commented 5 years ago

I have the same issue.

{
    plugin: 'hapi-pagination',
    options: {
        meta: {
            location: 'body'
        },
        reply: {
            paginate: 'hapiPaginate'
        },
        routes: {
            exclude: [
                new RegExp('/documentation*'), // or /\/documentation*/,
                new RegExp('/swaggerui*') // or /\/swaggerui*/,
            ]
        }
    }
}