-
Notifications
You must be signed in to change notification settings - Fork 4
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: add back CommonJS output #11
Conversation
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 had a feeling that going all-in on ESM might cause some trouble downstream. I think at some point it'd become reasonable to drop formal support for CommonJS, though if Gutenberg still relies on it and it's one of the project's biggest consumers, it probably makes sense to keep supporting for now.
Co-authored-by: Andrew Duthie <andrew@andrewduthie.com>
@aduth, sad news it doesn't work with your suggestion, Also, there was one test in the Gutenberg suite that relied on |
Hm, that's strange. I was able to reproduce the original issue with a simple CommonJS project ("Error [ERR_REQUIRE_ESM]: require() of ES Module not supported."), but the error went away with the introduction of Worst case, I think we could invert the default by reverting back to CommonJS with dropping {
"main": "dist/index.js",
"exports": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
}
}
That function was never meant to be part of a public API, so I don't feel too bad about that breaking. Could that function call or test be removed? I don't even like that it's relied on in Memize's own tests 😅 and was contemplating removing it altogether. |
I can look into this.
The error I was getting was from Jest, it pointed to either transpiling with babel, or enabling support for es modules in Jest https://jestjs.io/docs/ecmascript-modules, it looks like it might load it appropriately if it has a Edit: @aduth the solution above does work
|
I was able to confirm the issues you're seeing in Gutenberg when testing on your branch at WordPress/gutenberg#48604 . It's still strange that the The fact that it works with the I'd be alright with moving forward with that solution if it's working in Gutenberg. |
It builds and the full test suite passes. I think there is work to switch Gutenberg to a new version of node., it might be jumping to v18. When that happens, we can experiment with dropping the |
Curious how you were testing, because one thing I noticed in looking closer at the test failures in Gutenberg was that failures were coming from Eventually I ran |
4a4dea2
to
41c3cff
Compare
@aduth I will try this, I didn't consider lerna. That worked, I left the
As soon as I realized there was a problem I fell back to a clean fork of trunk. I have a branch prepared to update |
Is this the affected code? https://github.com/WordPress/gutenberg/blob/488295de/packages/edit-site/src/store/test/utils.js#L147-L150 I really think it'd be best to propose to drop that, or refactor it so that it checks that the original function being memoized isn't called again on subsequent calls (e.g. Partly my concern is the inconsistency between ESM and CJS versions. I'm guessing previously it was not auto-replacing the ENV value except in the prebuilt browser version, so we probably could drop the replace altogether to restore that behavior, but it does seem like that requires that downstream projects replace NODE_ENV if they use memize in the browser, which is an unfortunate requirement to impose. |
Yes, that’s the issue. They have a complex roadmap to get there that has some dependency on changes in Node.js itself and they collaborate between projects. It's fine to leave ESM in the package configured without workarounds, if possible. We can list https://github.com/WordPress/gutenberg/blob/trunk/test/unit/scripts/resolver.js You can compare how https://unpkg.com/browse/react-colorful@5.6.1/package.json or https://unpkg.com/browse/uuid@9.0.0/package.json it looks pretty complex! |
@aduth yes that is the offending code. I added back the replacement of @gziolo thank you for chiming in, I looked at {
"name": "memize",
"version": "2.0.0",
"description": "Unabashedly-barebones memoization library with an aim toward speed",
"type": "module",
"main": "dist/index.js", // Since the type is module the main property is pointing to the ESM version.
"exports": {
"import": "./dist/index.js",
"require": "./dist/index.cjs" // Jest is able to find this version
},
"types": "dist/index.d.ts",
// ....
} Edit: I tested with Gutenberg, test pass (with that one commented out) and it builds successfully. |
I think the current setup makes sense, because when you define the type as |
@gziolo as I am testing this with Gutenberg (aside: boy, my poor computer is getting hot), I have some tests that seem to randomly timeout and fail, is that normal? This is the common offender:
|
There is a nearly 600 test files so it might happen. It takes less than a minute to run them all on Mac with M1 😅 |
@gziolo I think I need to upgrade then 😂 |
Edit: Don't bother with this comment - I was chasing issues in the @aduth in WordPress/gutenberg#50172 with the current version EDIT: ^^ that wasn't right, the There is a new problem related to the ES Module import in the lint CI workflow, I'm investigating it now. https://github.com/WordPress/gutenberg/actions/runs/4831032473/jobs/8607946542?pr=50172#step:5:543 Something in the ESLint config must not like importing ES Modules, the rule Edit: I am getting very different results between CI and local... I think its issues with using |
Hey @gziolo 😄 Thanks for jumping in and pointing to that It sounds like maybe we don't need to change anything in Memize then? But I'll wait to hear how the upgrade shakes out. |
@aduth from what I understood, there still needs to be a CommonJS export, is that correct @gziolo? With the current additions of this PR, Gutenberg tests pass and it builds. All the JavaScript test workflows are currently failing WordPress/gutenberg#50172 But I'm not very knowledgeable about the possibilities of fixing the problem from the Jest configuration side. It looks like it should be able to load ES Modules https://jestjs.io/docs/ecmascript-modules |
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.
Looks great 👍 I'll publish this shortly.
Published as v2.1.0. Thanks again @johnhooks ! |
@aduth Gutenberg built beautifully and works with this module as an ES Module, though with the current Jest config it can't load ES Modules. I'm sorry I should have run the tests before we finished the #10.