browserify / static-module

convert module usage to inline expressions
MIT License
74 stars 23 forks source link

How about modules which are functions with properties? #13

Open fabiosantoscode opened 9 years ago

fabiosantoscode commented 9 years ago

If I have a module mymodule which exports a function with properties, as follows:

module.exports = function mymodule() { /* ... */ }
module.exports.foo = 1

How am I supposed to "statify" it, without choosing whether to restrict my client code to use either the function or the properties?

// Case 1: statify the function
staticModule({
    mymodule: function () { return '"something"' }
})  // Bad! cannot access require('mymodule').foo

// Case 2: statify the props
staticModule({
    mymodule: {
        foo: function() { return '1' }
    }
})  // Bad! cannot call require('mymodule')()

My use case is my project over at fabiosantoscode/require-emscripten, which is a node module exporting a function which also has properties.

cancerberoSgx commented 6 years ago

same here, I want to use a module that exports just a function : require('my-module')('use', 'no', 'properties', 'exported') - Fortunately the project is mine so I'm also exporting a property - but for users it could be confusing. Thanks