Skip to content
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

Expose an ESM exclusive binary #6

Closed
wants to merge 1 commit into from

Conversation

dvnrsn
Copy link

@dvnrsn dvnrsn commented Nov 15, 2023

  • create bin.[cjs, mjs]
  • duplicate tests for mjs
  • duplicate *.cjs files used in binode testing examples

- create bin.[cjs, mjs]
- duplicate tests for mjs
- duplicate *.cjs files used in binode testing examples
});
const modPkgDir = path.dirname(modPkgPath);

fs.readFile(modPkgPath, 'utf8')
Copy link
Author

@dvnrsn dvnrsn Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change. Not as easy as a "require" to read JSON in ESM.

@@ -0,0 +1,119 @@
import { spawnSync } from 'child_process';
import path from 'path';
import { fileURLToPath } from 'url';
Copy link
Author

@dvnrsn dvnrsn Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is virtually the same except it runs run-binode*-esm in the package.json which in turn uses the binode-esm binary

@@ -0,0 +1,3 @@
if (!global.globalSetup) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe overkill to duplicate these files but wanted to prove the full ESM format case

},
"keywords": [],
"author": "Kent C. Dodds <me@kentcdodds.com> (https://kentcdodds.com)",
"license": "MIT",
"bin": {
"binode": "bin.js"
"binode": "bin.cjs",
"binode-esm": "bin.mjs"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be clever to simply tease out which module system is being used and proceed from there. Seems like that could be doable I suppose by checking import.meta or __dirname. Haven't investigated

@kentcdodds
Copy link
Owner

Thanks for this. Can you help me understand why this is necessary?

@dvnrsn
Copy link
Author

dvnrsn commented Nov 15, 2023

I wanted to use remix-utils. But remix-utils@7 prefers type: module if I understand correctly.

I authored this proposal under the impression that an ESM exclusive binary was necessary in a type: module context. I came to that impression because of my own inexperience migrating remix indie-stack from CJS to MJS and the comment thread linked in this issue #5.

After noticing that for some reason NODE_OPTIONS=\"--require ./mocks\" remix-serve ./build/index.js is breaking my debugger, I thought my only alternative was binode in ESM.

However, as I noted in the same issue mentioned earlier, I believe using --import is permissible, even though it is experimental. In fact, I'm not sure how to otherwise run binode in an ESM context without using --import. This seems to work for me.

At this point I simply want to do whatever I can to get indie-stack to a better state for newcomers (like me). It might be best to pocket mock service worker as an option for down the road, for example.

Or maybe people should be pointed to templates?

@dvnrsn dvnrsn closed this Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants