-
Notifications
You must be signed in to change notification settings - Fork 79
feat(jsx): base for supporting more runtimes #236
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
13cd709
feat(jsx): base for supporting more runtimes
muningis 961e576
style: remove redundant console.log
muningis 2399081
style: use `jsx*` instead of `Jsx*` naming
muningis 270f533
feat(jsx): getMDXComponent for non-react JSX runtimes
muningis 0558872
docs: update readme
muningis 3dcb9ec
test: add tests for preact and hono
muningis fd5be82
test: add tests for vue
muningis be85bc3
test: typings and eslint ignore for hono tests
muningis 21a58e1
test: fix typing issues in vue and preact tests
muningis 5311d1a
fix(jsx): package json's export declarations
muningis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| module.exports = require('../dist/client') | ||
| module.exports = require('../dist/client/index.js') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| module.exports = require('../dist/client/jsx') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| { | ||
| "type": "commonjs", | ||
| "main": "./index.js", | ||
| "react": "./react.js", | ||
| "jsx": "./jsx.js", | ||
| "types": "./index.d.ts" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| module.exports = require('../dist/client/index.js') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import './setup-tests.js' | ||
| import { Hono } from "hono"; | ||
| /* eslint-disable import/no-unresolved -- | ||
| * imports paths are there in node_modules/hono/package.json | ||
| * but it doesn't get resolved | ||
| */ | ||
| import * as HonoJSX from "hono/jsx"; | ||
| import * as HonoDOM from "hono/jsx/dom"; | ||
| import * as _jsx_runtime from "hono/jsx/jsx-runtime"; | ||
| /* eslint-enable import/no-unresolved */ | ||
| import {suite} from 'uvu' | ||
| import * as assert from 'uvu/assert' | ||
| import {bundleMDX} from '../index.js' | ||
| import {getMDXComponent} from '../client/jsx.js' | ||
|
|
||
| const test = suite("hono"); | ||
|
|
||
| const jsxBundlerConfig = { | ||
| jsxLib: { | ||
| varName: 'HonoJSX', | ||
| package: 'hono/jsx', | ||
| }, | ||
| jsxDom: { | ||
| varName: 'HonoDOM', | ||
| package: 'hono/jsx/dom', | ||
| }, | ||
| jsxRuntime: { | ||
| varName: '_jsx_runtime', | ||
| package: 'hono/jsx/jsx-runtime', | ||
| }, | ||
| } | ||
| const jsxComponentConfig = { HonoJSX, HonoDOM, _jsx_runtime } | ||
|
|
||
| const mdxSource = ` | ||
| --- | ||
| title: Example Post | ||
| published: 2021-02-13 | ||
| description: This is some meta-data | ||
| --- | ||
| import Demo from './demo' | ||
|
|
||
| # This is the title | ||
|
|
||
| Here's a **neat** demo: | ||
| <Demo /> | ||
| `.trim(); | ||
|
|
||
| const demoTsx = ` | ||
| export default function Demo() { | ||
| return <div>mdx-bundler with hono's runtime!</div> | ||
| } | ||
| `.trim(); | ||
|
|
||
|
|
||
| test('smoke test for hono', async () => { | ||
|
|
||
| const result = await bundleMDX({ | ||
| source: mdxSource, | ||
| jsxConfig: jsxBundlerConfig, | ||
| files: { | ||
| './demo.tsx': demoTsx | ||
| } | ||
| }); | ||
|
|
||
| /** @param {HonoJSX.DOMAttributes} props */ | ||
| const SpanBold = ({ children }) => { | ||
| return HonoJSX.createElement('span', { className: "strong" }, children) | ||
| } | ||
|
|
||
| const app = new Hono() | ||
| .get("/", (c) => { | ||
| const Component = getMDXComponent(result.code, jsxComponentConfig); | ||
| return c.html(HonoJSX.jsx(Component, { components: { strong: SpanBold } }).toString()); | ||
| }); | ||
|
|
||
| const req = new Request("http://localhost/"); | ||
| const res = await app.fetch(req); | ||
| assert.equal(await res.text(), `<h1>This is the title</h1> | ||
| <p>Here's a <span class="strong">neat</span> demo:</p> | ||
| <div>mdx-bundler with hono's runtime!</div>`); | ||
| }) | ||
|
|
||
| test.run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import './setup-tests.js' | ||
| import * as Preact from "preact"; | ||
| import * as PreactDOM from "preact/compat"; | ||
| import * as _jsx_runtime from 'preact/jsx-runtime'; | ||
| import {suite} from 'uvu' | ||
| import * as assert from 'uvu/assert' | ||
| import { render } from '@testing-library/preact' | ||
| import {bundleMDX} from '../index.js' | ||
| import {getMDXComponent} from '../client/jsx.js' | ||
|
|
||
| const test = suite("preact"); | ||
|
|
||
| const jsxBundlerConfig = { | ||
| jsxLib: { | ||
| varName: 'Preact', | ||
| package: 'preact', | ||
| }, | ||
| jsxDom: { | ||
| varName: 'PreactDom', | ||
| package: 'preact/compat', | ||
| }, | ||
| jsxRuntime: { | ||
| varName: '_jsx_runtime', | ||
| package: 'preact/jsx-runtime', | ||
| }, | ||
| } | ||
| const jsxComponentConfig = { Preact, PreactDOM, _jsx_runtime } | ||
|
|
||
| const mdxSource = ` | ||
| --- | ||
| title: Example Post | ||
| published: 2021-02-13 | ||
| description: This is some meta-data | ||
| --- | ||
| import Demo from './demo' | ||
|
|
||
| # This is the title | ||
|
|
||
| Here's a **neat** demo: | ||
| <Demo /> | ||
| `.trim(); | ||
|
|
||
| const demoTsx = ` | ||
| export default function Demo() { | ||
| return <div>mdx-bundler with Preact's runtime!</div> | ||
| } | ||
| `.trim(); | ||
|
|
||
|
|
||
| test('smoke test for preact', async () => { | ||
|
|
||
| const result = await bundleMDX({ | ||
| source: mdxSource, | ||
| jsxConfig: jsxBundlerConfig, | ||
| files: { | ||
| './demo.tsx': demoTsx | ||
| } | ||
| }); | ||
|
|
||
| /** | ||
| * @type {import('preact').FunctionComponent<{ components?: Record<string, any> }>} | ||
| */ | ||
| const Component = getMDXComponent(result.code, jsxComponentConfig) | ||
|
|
||
| /** @type {Preact.FunctionComponent<{ children:Preact.ComponentChildren }>} props */ | ||
| const SpanBold = ({children}) => { | ||
| return Preact.createElement('span', { className: "strong" }, children) | ||
| } | ||
|
|
||
| assert.equal(result.frontmatter, { | ||
| title: 'Example Post', | ||
| published: new Date('2021-02-13'), | ||
| description: 'This is some meta-data', | ||
| }) | ||
|
|
||
| const {container} = render( | ||
| Preact.h(Component, {components: {strong: SpanBold}}) | ||
| ) | ||
|
|
||
| assert.equal( | ||
| container.innerHTML, | ||
| `<h1>This is the title</h1> | ||
| <p>Here's a <span class="strong">neat</span> demo:</p> | ||
| <div>mdx-bundler with Preact's runtime!</div>`, | ||
| ) | ||
| }) | ||
|
|
||
| test.run() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What are these? This looks like it actually should be in a export config.
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.
Honestly, I don't know what was there... Fixed it.
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.
As for breaking changes regression check, probably
result.codesnapshot test would be best shot.Create snapshots with separate MR, merge them into
main, and then rebase into this.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 was mostly just thinking about the imports that people have already. I'm pretty sure that you have everything wired up properly, but I just wanted to double check.