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
Feature Request: make Module.prototype._compile() public
#40098
Comments
module._compile() publicModule.prototype._compile() public
|
That sounds like a job for cjs-module-lexer, which is vendored in |
|
I don't think Here's a simple example of more or less what I'm currently having to do: 'use strict';
const Module = require('module');
function load(filename, content) {
const mod = new Module(filename, module);
// This is my "problem". I'd much rather have `mod.compile(content, filename);`
mod._compile(content, filename);
return mod.exports;
}
module.exports = {
foo: load('foo.js', '/* foo.js raw contents here */'),
bar: load('bar.js', '/* bar.js raw contents here */'),
// ...
}; |
|
If we want to expose this publicly, maybe we should design a slightly better API? |
|
Personally I'm perfectly fine with the API as-is, it's flexible enough and isn't complicated. |
|
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
|
Would anyone be opposed to me just renaming |
|
I would be opposed. I'd much prefer a single new function exported from |
|
@targos Suggestions then? |
|
To be improved: const { createCommonJSModule } = require('module');
const myModule = createCommonJSModule({
filename: 'myModule.js',
parent: module,
code: `
exports.value = 42;
`
});
console.log(myModule.exports.value) // 42 |
|
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
|
unstale por favor |
|
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
|
unstale por favor |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Already the
Moduleconstructor is exported fromrequire('module'), which gets userland halfway to being able to compile and evaluate a module from a string. Right now we can callmyModule._compile(...)and then get at the exports, but I would much rather have and use a public (non-underscore-prefixed) version of this method.My particular use case for this is I have many different modules in separate files that all export some data, functions, etc.. As part of a build step to simplify accessing these modules, I combine all of the their sources into a single module, exporting each submodule. In order to achieve this, I need to be able to compile, run, and get at each submodule's exports. As far as I can tell there is no (public) way to do that currently.
The text was updated successfully, but these errors were encountered: