-
Notifications
You must be signed in to change notification settings - Fork 912
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
feat!: move from CommonJS to ESM #3705
Comments
@escapedcat is this still something that you'd like assistance with, and if so, would you prefer everything be converted to ESM all in one PR, or is conversion in piecemeal per module okay for more complicated conversions (e.g. a PR just for @commitlint/resolve-extends)? |
Yes, happy for any help. I'm not sure if commitlint can be run with some packages in CommonJS and some in ESM. If so, this might be preferred, right? wdyt? |
Yeah I believe it's considered a breaking change from moving to CJS -> ESM because a project can't require ESM modules and any commitlint project could technically be published on its own. So if you wanted to do incremental changes, you'd want to bump the major version for the affected packages at minimum, and I think the rest of the packages using it could still be on CJS as long as they change their require references to import, which is not a breaking change for consumers. But that depends on how easy it is to bump individual packages differently.
If the versioning seems like it'll be tricky to adjust, the separate long-standing feature branch makes sense, just might have the pain of merge conflicts when it's ready to be merged in. But I think in either approach, making a PR for each module conversion to ESM separately would be easier to digest since it will probably involve a lot of files. |
I am quickly mentioning I developed that package while working on ESM presets support for Please note that it only supports default exports for now (which for CJS is the whole module), but if supporting ESM named exports is needed, please open an issue on the repo and we can work on designing that feature! Also, if ESM presets are needed to check they're working with |
@sheerlox I'm not too well-versed in how this package is being used, but is there still a gap that exists that import-from address which can't be filled with node:path and await import(...)? As I understand it, import-from uses a given directory to call the import from, but I'm unclear on how that's different from passing path.resolve/relative or something similar to await import. Could you provide some additional context in case I'm missing something? |
The main benefit of using (fromDirectory, moduleId) => createRequire(path.resolve(fromDirectory, 'noop.js'))(moduleId); In the case of
As you can see, there is quite a bit of complexity that is abstracted behind As a proponent of ESM, I have put a lot of thought into poly-filling |
Thanks for the explanation! It sounds like the behavior difference is mostly in the extension handling rather than resolving file paths. Is it correct to say that require needs extra support to handle resolving other packages installed in a parent package, but import can handle that on its own with import.meta.resolve? |
Both need extra support: Here's the relevant (and simplified) part of the code from import { resolve } from 'node:path';
import { pathToFileURL } from 'node:url';
import { moduleResolve } from 'import-meta-resolve';
const parentModulePath = pathToFileURL(resolve(fromDirectory, 'noop.js'));
try {
const resolvedModule = moduleResolve(moduleId, parentModulePath, new Set(['node', 'import']));
const loadedModule = await import(resolvedModule);
} catch (error) {
debug(`Failed to resolve '${moduleId}' from '${baseURL.href}': ${String(error)}`);
} Support for loading JSON modules also needs explicit handling in ESM (preferably by falling back to |
Just a short note: |
Linking #3850 here |
Expected Behavior
Should update all the code, like it was done here: https://github.com/conventional-changelog/conventional-changelog/pull/1144/files
The text was updated successfully, but these errors were encountered: