Correctly transform third-party JSX files (#5437)
This commit is contained in:
parent
a334f1212e
commit
4b188132ef
9 changed files with 65 additions and 0 deletions
5
.changeset/dull-camels-accept.md
Normal file
5
.changeset/dull-camels-accept.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Correctly transform third-party JSX files
|
|
@ -59,3 +59,8 @@ export function removeFileExtension(path: string) {
|
||||||
let idx = path.lastIndexOf('.');
|
let idx = path.lastIndexOf('.');
|
||||||
return idx === -1 ? path : path.slice(0, idx);
|
return idx === -1 ? path : path.slice(0, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function removeQueryString(path: string) {
|
||||||
|
const index = path.lastIndexOf('?');
|
||||||
|
return index > 0 ? path.substring(0, index) : path;
|
||||||
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import esbuild from 'esbuild';
|
||||||
import * as colors from 'kleur/colors';
|
import * as colors from 'kleur/colors';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { error } from '../core/logger/core.js';
|
import { error } from '../core/logger/core.js';
|
||||||
|
import { removeQueryString } from '../core/path.js';
|
||||||
import { parseNpmName } from '../core/util.js';
|
import { parseNpmName } from '../core/util.js';
|
||||||
import tagExportsPlugin from './tag.js';
|
import tagExportsPlugin from './tag.js';
|
||||||
|
|
||||||
|
@ -187,6 +188,7 @@ export default function jsx({ settings, logging }: AstroPluginJSXOptions): Plugi
|
||||||
},
|
},
|
||||||
async transform(code, id, opts) {
|
async transform(code, id, opts) {
|
||||||
const ssr = Boolean(opts?.ssr);
|
const ssr = Boolean(opts?.ssr);
|
||||||
|
id = removeQueryString(id);
|
||||||
if (!JSX_EXTENSIONS.has(path.extname(id))) {
|
if (!JSX_EXTENSIONS.has(path.extname(id))) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
18
packages/astro/test/fixtures/solid-component/deps/solid-jsx-component/Counter.jsx
vendored
Normal file
18
packages/astro/test/fixtures/solid-component/deps/solid-jsx-component/Counter.jsx
vendored
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import { createSignal } from 'solid-js';
|
||||||
|
|
||||||
|
export default function Counter(props) {
|
||||||
|
const [count, setCount] = createSignal(0);
|
||||||
|
const add = () => setCount(count() + 1);
|
||||||
|
const subtract = () => setCount(count() - 1);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div class="counter">
|
||||||
|
<button onClick={subtract}>-</button>
|
||||||
|
<pre>{count()}</pre>
|
||||||
|
<button onClick={add}>+</button>
|
||||||
|
</div>
|
||||||
|
<div class="counter-message">{props.children}</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
1
packages/astro/test/fixtures/solid-component/deps/solid-jsx-component/index.js
vendored
Normal file
1
packages/astro/test/fixtures/solid-component/deps/solid-jsx-component/index.js
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export { default as Counter } from './Counter'
|
15
packages/astro/test/fixtures/solid-component/deps/solid-jsx-component/package.json
vendored
Normal file
15
packages/astro/test/fixtures/solid-component/deps/solid-jsx-component/package.json
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"name": "@test/solid-jsx-component",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"private": true,
|
||||||
|
"type": "module",
|
||||||
|
"exports": {
|
||||||
|
".": {
|
||||||
|
"solid": "./index.js",
|
||||||
|
"default": "./index.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"solid-js": "^1.5.6"
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@astrojs/solid-js": "workspace:*",
|
"@astrojs/solid-js": "workspace:*",
|
||||||
"@solidjs/router": "^0.5.0",
|
"@solidjs/router": "^0.5.0",
|
||||||
|
"@test/solid-jsx-component": "file:./deps/solid-jsx-component",
|
||||||
"astro": "workspace:*",
|
"astro": "workspace:*",
|
||||||
"solid-js": "^1.5.6"
|
"solid-js": "^1.5.6"
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import Hello from '../components/Hello.jsx';
|
||||||
import WithNewlines from '../components/WithNewlines.jsx';
|
import WithNewlines from '../components/WithNewlines.jsx';
|
||||||
import { Router } from "@solidjs/router";
|
import { Router } from "@solidjs/router";
|
||||||
import ProxyComponent from '../components/ProxyComponent.jsx';
|
import ProxyComponent from '../components/ProxyComponent.jsx';
|
||||||
|
import { Counter as DepCounter } from '@test/solid-jsx-component';
|
||||||
---
|
---
|
||||||
<html>
|
<html>
|
||||||
<head><title>Solid</title></head>
|
<head><title>Solid</title></head>
|
||||||
|
@ -12,6 +13,7 @@ import ProxyComponent from '../components/ProxyComponent.jsx';
|
||||||
<WithNewlines client:load />
|
<WithNewlines client:load />
|
||||||
<Router />
|
<Router />
|
||||||
<ProxyComponent client:load />
|
<ProxyComponent client:load />
|
||||||
|
<DepCounter client:load />
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
16
pnpm-lock.yaml
generated
16
pnpm-lock.yaml
generated
|
@ -2178,14 +2178,22 @@ importers:
|
||||||
specifiers:
|
specifiers:
|
||||||
'@astrojs/solid-js': workspace:*
|
'@astrojs/solid-js': workspace:*
|
||||||
'@solidjs/router': ^0.5.0
|
'@solidjs/router': ^0.5.0
|
||||||
|
'@test/solid-jsx-component': file:./deps/solid-jsx-component
|
||||||
astro: workspace:*
|
astro: workspace:*
|
||||||
solid-js: ^1.5.6
|
solid-js: ^1.5.6
|
||||||
dependencies:
|
dependencies:
|
||||||
'@astrojs/solid-js': link:../../../../integrations/solid
|
'@astrojs/solid-js': link:../../../../integrations/solid
|
||||||
'@solidjs/router': 0.5.0_solid-js@1.6.2
|
'@solidjs/router': 0.5.0_solid-js@1.6.2
|
||||||
|
'@test/solid-jsx-component': file:packages/astro/test/fixtures/solid-component/deps/solid-jsx-component
|
||||||
astro: link:../../..
|
astro: link:../../..
|
||||||
solid-js: 1.6.2
|
solid-js: 1.6.2
|
||||||
|
|
||||||
|
packages/astro/test/fixtures/solid-component/deps/solid-jsx-component:
|
||||||
|
specifiers:
|
||||||
|
solid-js: ^1.5.6
|
||||||
|
dependencies:
|
||||||
|
solid-js: 1.6.2
|
||||||
|
|
||||||
packages/astro/test/fixtures/sourcemap:
|
packages/astro/test/fixtures/sourcemap:
|
||||||
specifiers:
|
specifiers:
|
||||||
'@astrojs/react': workspace:*
|
'@astrojs/react': workspace:*
|
||||||
|
@ -18821,3 +18829,11 @@ packages:
|
||||||
name: '@astrojs/renderer-two'
|
name: '@astrojs/renderer-two'
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
file:packages/astro/test/fixtures/solid-component/deps/solid-jsx-component:
|
||||||
|
resolution: {directory: packages/astro/test/fixtures/solid-component/deps/solid-jsx-component, type: directory}
|
||||||
|
name: '@test/solid-jsx-component'
|
||||||
|
version: 0.0.0
|
||||||
|
dependencies:
|
||||||
|
solid-js: 1.6.2
|
||||||
|
dev: false
|
||||||
|
|
Loading…
Add table
Reference in a new issue