TomerAberbach/parse-imports

Provide CJS build

brettz9 opened this issue · 10 comments

While it worked for us locally, as we are also using modules, I dumbly forgot to check whether the package supports CJS.

Any chance you'd provide a CJS build?

Looks like my two dependencies both provide CJS builds so should be possible

@brettz9 are you by any chance able to clone the #13 branch, run install, run npm run build, and confirm that using the package locally works for you CJS-wise?

I had problems doing it locally (trying npm link with transitive dependencies), but instead I've made a fork which includes the built files (removing dist from .gitignore). It seems the one thing you will still need to do in your PR is remove "files": ["src"] from package.json (or tweak it to include dist). The package then works as expected in either an ESM or CJS environment.

Unfortunately, in doing testing this way, the race condition occurs and I get the error, "Expected WASM to be loaded before calling parseImportsSync", so it seems we'll be unable to use the package after all. :-( Thanks for your efforts though!

Ah good catch with the "files": ["src"]!

Up to you whether it's worth the trouble, but you could theoretically run this package's async method in a worker to make it synchronous. For example: eslint/eslint#15394 (comment)

If you are interested in that, then I can move forward with this CJS export

One other similar option: https://github.com/sindresorhus/make-synchronous. I think this one uses a child process instead of a worker, so probably not as efficient as the other option I mentioned

Thanks for that!

While make-synchronous gave me an error (Cannot find package 'subsume' imported from /Users/brett/eslint-plugin-jsdoc/[eval1] for posterity), synckit did the trick (at least with the worker having and referenced with an .mjs extension).

So a CJS release would be great.

Nice! Glad that works. Will publish the version with CJS soon

Published as v2.1.0!

Excellent, thanks! Love the turnaround speed too! :-)

Excellent, thanks!

No problem!

Love the turnaround speed too! :-)

Haha, have been avoiding going outside due to the heat here in the Northeast 😅