-
Notifications
You must be signed in to change notification settings - Fork 27
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
Extending exports object detections #58
Comments
If this gets implemented, we must not forget to also consider template literals in depth tracking: module.exports = {
prop1: `${1,notExported}`,
}; |
Right, it would effectively be a wrapped and nested implementation of the entire main parser. |
Would it be unreasonable to support this (even if it uses Here is my use case: I am trying to monkey patch nw.js with node builtins (issue: nwjs/nw.js#7639). However, since they are defined as |
@CxRes can you share more details on the exact source patterns you need supported? It would be first worth assessing if this feature would really solve the problem. I am hesitant to add new features at this late stage to this project though as well, since having highly variable compatibility for older versions of Node.js will be quite confusing... |
I am looking to add support for esm version of node built-ins (which are not available on the client/browser side of nwjs). For a pattern example, see the The alternative is to transpile code to commonjs. |
So this issue wouldn't solve that. That's actually multiple separate issues to get to work:
None of the above are at all related to this issue.... It would have been possible to really dive into these when we were first fleshing this out, but at this late stage in the day I think this is out of scope unfortunately. You're likely better off just wrapping them in an ESM wrapper. |
I understand! However, given the maintenance burden of wrapping the entire node API (and it is unlikely that nwjs developers are themselves interested in fixing this), it looks like I would have to take the evil route and keep transpiling all my code to cjs (and maintain two versions of the same code). I find it evil because by sticking to the legacy format, there is less incentive for others, like nwjs authors, to move ahead with esm. We are left in this mess for even longer, despite the herculean effort of good people like you in this space! |
Yes CommonJS will be around for another 10 years at least! For what it is worth, an ESM wrapper is not that hard to do / not that much maintenance, see eg - https://github.com/jspm/jspm-core/blob/main/src-browser/fs.js. |
OMG!!! Maybe not for you, but for lesser mortals that is a bit too much. Not the process of creating such a library (which is straight forward), but the fact that you have to then keep on top of node API and that too different versions of it in perpetuity is borderline madness!!! |
Perhaps you could write a script that does |
Thanks!!!! After agonizing over it over the weekend, that is what I ended up implementing! I was hoping to do this with a virtual file system at application but the I realized to map the paths I would need to start a server in the background, so gave up on that! Extra 25kB it is! |
I can say that this specific issue would be wonderful to resolve. The current problem is with this itself. The reason for it is that Unfortunately, when I was attempting to test code that imports (intentionally without mocking) the The code it's trying to parse looks like this: module.exports = {
decode: require('./decode'),
verify: require('./verify'),
sign: require('./sign'),
JsonWebTokenError: require('./lib/JsonWebTokenError'),
NotBeforeError: require('./lib/NotBeforeError'),
TokenExpiredError: require('./lib/TokenExpiredError'),
}; Looking at the code and why it's not catching the I can see one other possible limitation to that approach, and that's mostly because of |
I failed to mention that the only thing it's catching as an |
I think a similar problem was also happening to the |
While I appreciate the complexity of supporting arbitrary expressions, it would be nice if it at least supported |
I found this is not supported: const result = require('cjs-module-lexer').parse(`
module.exports = {
a: utils.a,
b: utils.b,
c: utils.c,
}
`) This code is used by https://www.jsdelivr.com/package/npm/web3-utils, cjs-module-lexer can only detected export |
This underlying issue is the blocker for upgrading to ESM. Is there any discussion or progress moving forward in this direction @cwadrupldijjit have you find anything (even a hack) to solve this problem so that |
I ended up moving most all of what I was working on to
I also dabbled in more recent projects using the built-in Node test runner, which though it may not be considered stable, it definitely includes most of what I need in a test runner. It is not without its issues, but I got it working to a good enough extent for my setup in my side projects. That was written in TS and it seems like some reporting and coverage parts that I attempted to use didn't really work. |
@cwadrupldijjit Thanks for your input, unfortunately, our app is a web app. So it is going to be a long journey toward ESM conversion. |
I'm sorry if it sounded like I had to use vite for a Node app--vite is supposed to be used to bundle a web application. vitest doesn't have to be tied to a web app and that's what I was talking about. With me, I configured vitest to run as if it was running like jest does and it was a direct replacement. It doesn't have the same dependencies as jest does, which means that the bug preventing jest from reading ESM/TS like it should. However, I can think of a few alternatives in the case that you can't jump off of jest:
In my case, I couldn't find a great way to work around this issue with jest and just gave up on it when I found out that vitest was a much better setup experience. If you would like me to, I could post an example of a decent working example of vitest replacing the jest setup. |
Object expressons like:
would still be beneficial to fully support reading their properties.
The challenge is doing this without a full parser that can't handle eg object expression / brace ambiguity details.
One idea is that it could be possible to use a
,
parser with no knowledge of object assign / expression ambiguity but purely based on matching the first,
that happens at the same depth of brace tracking (including all brace types) which might be a way to dodge the harder parsing issues while supporting arbitrary expressions.Will leave this open as a tracking issue for that kind of support.
The text was updated successfully, but these errors were encountered: