Skip to content
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: fix export #225

Merged
merged 1 commit into from
Jun 22, 2022
Merged

fix: fix export #225

merged 1 commit into from
Jun 22, 2022

Conversation

MichaelDeBoey
Copy link
Owner

Closes #221

@codecov
Copy link

codecov bot commented May 10, 2022

Codecov Report

Merging #225 (a92d054) into main (f70a6fb) will not change coverage.
The diff coverage is n/a.

❗ Current head a92d054 differs from pull request most recent head 1f60586. Consider uploading reports for the commit 1f60586 to get more accurate results

@@            Coverage Diff            @@
##              main      #225   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           17        17           
  Lines          300       300           
  Branches        95        95           
=========================================
  Hits           300       300           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f70a6fb...1f60586. Read the comment docs.

@jsg2021
Copy link

jsg2021 commented May 10, 2022

you could do something like this instead:

diff --git a/package.json b/package.json
index 9db7bff..65037ab 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
   "name": "gatsby-remark-embedder",
   "version": "0.0.0-semantically-released",
   "description": "Gatsby Remark plugin to embed well known services by their URL.",
-  "main": "./dist/index.js",
+  "main": "./require.entry.cjs",
   "keywords": [
     "gatsby",
     "gatsby-plugin",
diff --git a/require.entry.cjs b/require.entry.cjs
new file mode 100644
index 0000000..abf91dc
--- /dev/null
+++ b/require.entry.cjs
@@ -0,0 +1,7 @@
+module.exports = async (...args) => {
+  const {
+    // node's own commonjs wrapper adds a second `default` layer
+    default: { default: transform },
+  } = await import('./dist/index.js');
+  return transform(...args);
+};

Your lint rules won't complain about module.exports in the .cjs file, and in the future, if you wish to use native esm, the import() will allow for an easy commonjs bridge.

Repository owner deleted a comment from jsg2021 May 10, 2022
@jsg2021
Copy link

jsg2021 commented May 28, 2022

just fyi... this works locally on node 16...

main...jsg2021:main

the tooling configs and tests may need updating... but as a proof of concept, it's encouraging.

@github-actions
Copy link

🎉 This PR is included in version 6.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The plugin doesn't work for Gatsby 4
2 participants