-
-
Notifications
You must be signed in to change notification settings - Fork 362
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
Add support for esm .remarkrc files #654
Comments
I’m willing to fix this by the way 😄 |
Some loose thoughts! plugins && presets are essentially the same thing btw! See also: unifiedjs/unified#121 (comment). Some work would also be in Then there’s work in https://github.com/unifiedjs/unified-engine/blob/53be1502aa05c6b4618402d3d9fa848d594739bf/lib/configuration.js#L19. And indeed, breaking. So we can also drop other features in the engine. |
Some more thoughts on this… Currently undocumented is that If we could drop support for YAML, we could also drop support for string based plugin references, import dictionary from 'dictionary-en';
import remarkFrontmatter from 'remark-frontmatter';
import remarkGfm from 'remark-gfm';
import { remarkMermaid } from 'remark-mermaid';
import remarkPresetWooorm from 'remark-preset-wooorm';
import remarkRetext from 'remark-retext';
import retextSpell from 'retext-spell';
import unified from 'unified';
export const presets = [remarkPresetWooorm];
export const plugins = [
remarkFrontmatter,
remarkGfm,
// Not sure why one would do this, but this is just to show named exports may be used as well.
remarkMermaid,
[remarkRetext, unified().use(retextSpell, { dictionary })],
]; I do realize this is very verbose though. Optionally we could allow an array of promises in the import dictionary from 'dictionary-en';
import retextSpell from 'retext-spell';
import unified from 'unified';
export const presets = [import('remark-preset-wooorm')];
export const plugins = [
import('remark-frontmatter'),
import('remark-gfm'),
[import('remark-retext'), unified().use(retextSpell, { dictionary })],
]; If we do want to keep string based configurations, why not just use Also if we want to keep support for this, I believe there’s value in supporting this for import dictionary from 'dictionary-en';
export const presets = ['remark-preset-wooorm'];
export const plugins = [
'remark-frontmatter',
'remark-gfm',
['remark-retext', [['retext-spell', { dictionary }]]],
]; This also means we need to determine what a string plugin points to for ESM. Probably the default Another though I was having is: What’s the goal of In the beginning this was confusing to me. I just wanted to lint some markdown files, so why can’t I Sorry if I got off topic too much. 😅 But I do think these considerations may affect how this is going to be implemented. |
Tangentially related with new formats being considered, it may be worth revisiting if https://github.com/davidtheclark/cosmiconfig or a similar config manager could be a good fit for the unified ecosystem. |
It’s documented in the engine docs, linked to in the remark-cli and rehype-cli readmes!
There’s still JSON.
ESLint, Babel, xo, postcss, etc, also all allow Having a JS based config file is actually rather bad for caching, because well, it could do
Yeah we can switch to that. It wasn’t around, or at least in those tools, when I made remark-cli and the engine
Because unified is the only project that does both linting and compiling. That doesn’t exist in other languages, which are all fragmented. Rome is one solution that’s trying to fix it. I think unified has already solved all that while being modular instead of monolithic. |
My preference is JavaScript (supports all values and allows comments) > YAML (better caching and allows comments) > JSON (better caching, but not comments) I think this shows users have different preferences for this and we should keep support for JSON, YAML, and JavaScript, meaning we should add support for ESM. I do believe cosmiconfig is the way to go. This means we should wait for cosmiconfig to support ESM, which they want to postpone until NodeJS 10 is EOL (2021-04-30) |
So it’s a two part thing.
|
Second part is now done. Should we wait on cosmic config for the config files or get something in the engine for now (minor?)? That leaves load-plugin as an optional thing, sort of outside the scope of this issue, but nice to have to actually match export maps? |
If this can be done easily, I’d say go for it. |
Note that some people are migrating from
I haven't tried it myself yet, but something to keep in mind. |
@jaydenseric Interesting .Although, that does seem to miss ESM support (cosmiconfig does too, but at least is working on it) |
Thanks @jaydenseric, |
|
This was solved btw, forgot about this issue. And I kept with the existing custom loading—it’s pretty fast and works well and it was relatively fine to add ESM! |
Hi, sorry for posting to an old thread but it's the closest I can find that might add context to my question! |
You can open new questions! That’s a bug in that plugin. Plugins must export the plugin as the default. |
Thanks for getting back to me so quickly :) I posted here as I had an inkling some of the code snippets above were pertinent but I'm not a JS programmer and couldn't tell. In this case I find that version 0.4.0 of remark-code-import works as I need so I'm good, and I've opened an issue in that repository for cli support. |
Subject of the feature
I would like to add support for ESM
.remarkrc
files in remark-cli. 😄Problem
Since @wooorm is eager to ESMify (this is a verb now) a lot of packages, I believe
remark-cli
should support this, so users don’t run into compatibility issues when importing packages in their remark configuration files.I believe this is a breaking change, because users may already have their build these configuration files. I’m not aware of any examples, but there’s probably 1 person on the world for whom this change would be breaking.
Considering this is already a breaking change and ESM files may import CJS files, I believe CJS support may be dropped.
This requires some upstream changes, I believe all of them are within the unified ecosystem.
Expected behavior
Users can create
.remarkrc.mjs
or.remarkrc.js
files using ESM named exports.I.e.:
Alternatives
A default export could be used, but personally I prefer named exports.
The text was updated successfully, but these errors were encountered: