Update documentation on custom CJS/ESM plugins#2876
Update documentation on custom CJS/ESM plugins#2876Harjun751 wants to merge 1 commit intoMarkBind:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2876 +/- ##
=======================================
Coverage 71.04% 71.04%
=======================================
Files 131 131
Lines 7117 7117
Branches 1586 1621 +35
=======================================
Hits 5056 5056
- Misses 1961 2055 +94
+ Partials 100 6 -94 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
gerteck
left a comment
There was a problem hiding this comment.
LGTM! thanks for the PR, just some notes or possible nits
|
|
||
| Generally, if your plugin has `require(...)` and `module.exports`, it is **CJS**. | ||
|
|
||
| Alternatively, if your plugin has `import { ... }` and `export { ... }` it is **ESM**. |
There was a problem hiding this comment.
just wondering, is it possible to mix and match? Or to mix and match, i need to be explicit and use .cjs and .mjs?
There was a problem hiding this comment.
There's 2 cases:
1. No package.json or package.json without "type": "module" set
In this case, CJS/ESM is inferred on a per-file basis, see the third rule of loading ESM with require.
2. package.json with "type":"module"
In this case all code is simply inferred to be ESM. Using CJS with this is invalid, and the import process will skip over CJS plugins.
Using the .cjs extension will not help either, as we currently hardcode to use .js:
markbind/packages/core/src/plugins/PluginManager.ts
Lines 123 to 124 in b641bc9
Do you think it's worth noting?
There was a problem hiding this comment.
hmm, should we remove the hardcode to make it such that .cjs and .mjs filenames work as expected? I think it's worth nothing it, if it is not too much work i suppose
What is the purpose of this pull request?
Resolves #2867
Overview of changes:
Adds documentation on how to manage the different module systems with plugins. Check out the deploy preview's "Writing Plugins" page for the changes
Details
Anything you'd like to highlight/discuss:
Testing instructions:
Proposed commit message: (wrap lines at 72 characters)
Update documentation on custom CJS/ESM plugins
Checklist: ☑️
Reviewer checklist:
Indicate the SEMVER impact of the PR:
At the end of the review, please label the PR with the appropriate label:
r.Major,r.Minor,r.Patch.Breaking change release note preparation (if applicable):