-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
fix: remove createRequire for package json #978
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍👍
banner: { | ||
js: `import { createRequire } from 'module'; const require = createRequire(import.meta.url);`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You removed createRequire
, but Is it needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prompts
dynamically requires readline
causing this error when the banner
is omitted:
Error: Dynamic require of "readline" is not supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could look into moving to inquirer.js from prompts:
https://github.com/SBoudrias/Inquirer.js
It seems like it is more actively maintained, so I'd imagine the esm support is more up to date and we could then remove this banner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, I rejected the idea #339 by @himself65 because I thought it was too early.
But now that we have more active contributors, I think the time is right.
I don't think prompts is too bad, but if you guys have a better alternative, and feel like maintaining it, I'm fine of changing the dependency library, or completely re-implementing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried both enquirer and inquirer and each seems to use dynamic requires of their dependencies, so we'd need to keep this banner even if switching.
So, I don't really see a strong motivator for changing off prompts either yet.
This issue: terkelg/prompts#393 if it get's worked on should be enough to solve any of the current concerns we have now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, That's enough since create-waku doesn't have the logic of complex CLI yet.
So I don't have enough motivation on changing other deps.
packages/create-waku/src/index.ts
Outdated
// keep original require to avoid | ||
// bundling the whole package.json by `@vercel/ncc` | ||
const packageJson = createRequire(import.meta.url)('../package.json'); | ||
const packageJson = await import('../package.json'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, is this syntax supported by tsup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep! I think esbuild is technically what supports it under the hood, but still the answer is yes, it's supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I was wrong here ^
This errors because of the json import without the attribute, so I just changed it to use require
which is defined in the banner
the error:
TypeError [ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module "file:///.../waku/packages/create-waku/package.json" needs an import attribute of type "json"
packages/create-waku/src/index.ts
Outdated
// bundling the whole package.json by `@vercel/ncc` | ||
const packageJson = createRequire(import.meta.url)('../package.json'); | ||
// eslint-disable-next-line @typescript-eslint/no-require-imports | ||
const packageJson = require('../package.json'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use JSON.parse(fs.readFileSync(..))
if wanna remove require here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried updating this from my phone. I think it's right but I'll need to correct the prettier issues from my laptop later haha
Thanks for the tip though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought there was a motivation of preferring require
to readFileSync
? @himself65
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, I just think it’s not a familiar way to use require in ESM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks guys!!
Got an error:
I think we need to use |
fix for #978 (comment) Also fixed an issue where the default folder name was not showing on conflict --------- Co-authored-by: Tyler <[email protected]>
follow up to this: #974 (comment)