honox 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -15
- package/dist/server/{components.js → components/has-islands.js} +1 -1
- package/dist/server/components/index.d.ts +4 -0
- package/dist/server/components/index.js +6 -0
- package/dist/server/components/script.d.ts +11 -0
- package/dist/server/components/script.js +31 -0
- package/dist/server/factory/factory.d.ts +19 -0
- package/dist/server/factory/factory.js +11 -0
- package/dist/server/factory/index.d.ts +3 -0
- package/dist/server/factory/index.js +5 -0
- package/dist/server/index.d.ts +3 -1
- package/dist/server/index.js +1 -2
- package/dist/vite/client.d.ts +10 -0
- package/dist/vite/client.js +28 -0
- package/dist/vite/index.d.ts +3 -3
- package/dist/vite/index.js +8 -1
- package/package.json +8 -1
- package/dist/vite/inject-has-islands.d.ts +0 -5
- package/dist/vite/inject-has-islands.js +0 -52
- package/dist/vite/remove-elements.d.ts +0 -8
- package/dist/vite/remove-elements.js +0 -52
- /package/dist/server/{components.d.ts → components/has-islands.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -271,6 +271,27 @@ export default jsxRenderer(({ children }) => {
|
|
|
271
271
|
})
|
|
272
272
|
```
|
|
273
273
|
|
|
274
|
+
If you have a manifest file in `dist/.vite/manifest.json`, you can easily write it using `<Script />`.
|
|
275
|
+
|
|
276
|
+
```tsx
|
|
277
|
+
// app/routes/_renderer.tsx
|
|
278
|
+
import { jsxRenderer } from 'hono/jsx-renderer'
|
|
279
|
+
import { Script } from 'honox/server'
|
|
280
|
+
|
|
281
|
+
export default jsxRenderer(({ children }) => {
|
|
282
|
+
return (
|
|
283
|
+
<html lang='en'>
|
|
284
|
+
<head>
|
|
285
|
+
<meta charset='UTF-8' />
|
|
286
|
+
<meta name='viewport' content='width=device-width, initial-scale=1.0' />
|
|
287
|
+
<Script src='/app/client.ts' />
|
|
288
|
+
</head>
|
|
289
|
+
<body>{children}</body>
|
|
290
|
+
</html>
|
|
291
|
+
)
|
|
292
|
+
})
|
|
293
|
+
```
|
|
294
|
+
|
|
274
295
|
### Client Entry File
|
|
275
296
|
|
|
276
297
|
A client side entry file should be in `app/client.ts`. Simply, write `createClient()`.
|
|
@@ -554,6 +575,7 @@ Since a HonoX instance is essentially a Hono instance, it can be deployed on any
|
|
|
554
575
|
Setup the `vite.config.ts`:
|
|
555
576
|
|
|
556
577
|
```ts
|
|
578
|
+
// vite.config.ts
|
|
557
579
|
import { defineConfig } from 'vite'
|
|
558
580
|
import honox from 'honox/vite'
|
|
559
581
|
import pages from '@hono/vite-cloudflare-pages'
|
|
@@ -567,25 +589,15 @@ If you want to include client side scripts and assets:
|
|
|
567
589
|
|
|
568
590
|
```ts
|
|
569
591
|
// vite.config.ts
|
|
570
|
-
import { defineConfig } from 'vite'
|
|
571
|
-
import honox from 'honox/vite'
|
|
572
592
|
import pages from '@hono/vite-cloudflare-pages'
|
|
593
|
+
import honox from 'honox/vite'
|
|
594
|
+
import client from 'honox/vite/client'
|
|
595
|
+
import { defineConfig } from 'vite'
|
|
573
596
|
|
|
574
597
|
export default defineConfig(({ mode }) => {
|
|
575
598
|
if (mode === 'client') {
|
|
576
599
|
return {
|
|
577
|
-
|
|
578
|
-
rollupOptions: {
|
|
579
|
-
input: ['./app/client.ts'],
|
|
580
|
-
output: {
|
|
581
|
-
entryFileNames: 'static/client.js',
|
|
582
|
-
chunkFileNames: 'static/assets/[name]-[hash].js',
|
|
583
|
-
assetFileNames: 'static/assets/[name].[ext]',
|
|
584
|
-
},
|
|
585
|
-
},
|
|
586
|
-
emptyOutDir: false,
|
|
587
|
-
copyPublicDir: false,
|
|
588
|
-
},
|
|
600
|
+
plugins: [client()],
|
|
589
601
|
}
|
|
590
602
|
} else {
|
|
591
603
|
return {
|
|
@@ -598,7 +610,7 @@ export default defineConfig(({ mode }) => {
|
|
|
598
610
|
Build command (including a client):
|
|
599
611
|
|
|
600
612
|
```txt
|
|
601
|
-
vite build && vite build
|
|
613
|
+
vite build --mode client && vite build
|
|
602
614
|
```
|
|
603
615
|
|
|
604
616
|
Deploy with the following commands after build. Ensure you have [Wrangler](https://developers.cloudflare.com/workers/wrangler/) installed:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fragment, jsx } from "hono/jsx/jsx-runtime";
|
|
2
2
|
import { useRequestContext } from "hono/jsx-renderer";
|
|
3
|
-
import { IMPORTING_ISLANDS_ID } from "
|
|
3
|
+
import { IMPORTING_ISLANDS_ID } from "../../constants.js";
|
|
4
4
|
const HasIslands = ({ children }) => {
|
|
5
5
|
const c = useRequestContext();
|
|
6
6
|
return /* @__PURE__ */ jsx(Fragment, { children: c.get(IMPORTING_ISLANDS_ID) ? children : /* @__PURE__ */ jsx(Fragment, {}) });
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Fragment, jsx } from "hono/jsx/jsx-runtime";
|
|
2
|
+
import { HasIslands } from "./has-islands.js";
|
|
3
|
+
const Script = async (options) => {
|
|
4
|
+
const src = options.src;
|
|
5
|
+
if (options.prod ?? import.meta.env.PROD) {
|
|
6
|
+
let manifest = options.manifest;
|
|
7
|
+
if (!manifest) {
|
|
8
|
+
const MANIFEST = import.meta.glob("/dist/.vite/manifest.json", {
|
|
9
|
+
eager: true
|
|
10
|
+
});
|
|
11
|
+
for (const [, manifestFile] of Object.entries(MANIFEST)) {
|
|
12
|
+
if (manifestFile["default"]) {
|
|
13
|
+
manifest = manifestFile["default"];
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (manifest) {
|
|
19
|
+
const scriptInManifest = manifest[src.replace(/^\//, "")];
|
|
20
|
+
if (scriptInManifest) {
|
|
21
|
+
return /* @__PURE__ */ jsx(HasIslands, { children: /* @__PURE__ */ jsx("script", { type: "module", src: `/${scriptInManifest.file}` }) });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return /* @__PURE__ */ jsx(Fragment, {});
|
|
25
|
+
} else {
|
|
26
|
+
return /* @__PURE__ */ jsx("script", { type: "module", src });
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export {
|
|
30
|
+
Script
|
|
31
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as hono_types from 'hono/types';
|
|
2
|
+
import * as hono from 'hono';
|
|
3
|
+
import { Env, Hono } from 'hono';
|
|
4
|
+
|
|
5
|
+
declare const createRoute: {
|
|
6
|
+
<I extends hono.Input = {}>(handler1: hono_types.H<Env, any, I>): [hono_types.H<Env, any, I>];
|
|
7
|
+
<I_1 extends hono.Input = {}, I2 extends hono.Input = I_1, R extends hono_types.HandlerResponse<any> = any>(handler1: hono_types.H<Env, any, I_1, R>, handler2: hono_types.H<Env, any, I2, R>): [hono_types.H<Env, any, I_1, R>, hono_types.H<Env, any, I2, R>];
|
|
8
|
+
<I_2 extends hono.Input = {}, I2_1 extends hono.Input = I_2, I3 extends hono.Input = I_2 & I2_1, R_1 extends hono_types.HandlerResponse<any> = any>(handler1: hono_types.H<Env, any, I_2, R_1>, handler2: hono_types.H<Env, any, I2_1, R_1>, handler3: hono_types.H<Env, any, I3, R_1>): [hono_types.H<Env, any, I_2, R_1>, hono_types.H<Env, any, I2_1, R_1>, hono_types.H<Env, any, I3, R_1>];
|
|
9
|
+
<I_3 extends hono.Input = {}, I2_2 extends hono.Input = I_3, I3_1 extends hono.Input = I_3 & I2_2, I4 extends hono.Input = I_3 & I2_2 & I3_1, R_2 extends hono_types.HandlerResponse<any> = any>(handler1: hono_types.H<Env, any, I_3, R_2>, handler2: hono_types.H<Env, any, I2_2, R_2>, handler3: hono_types.H<Env, any, I3_1, R_2>, handler4: hono_types.H<Env, any, I4, R_2>): [hono_types.H<Env, any, I_3, R_2>, hono_types.H<Env, any, I2_2, R_2>, hono_types.H<Env, any, I3_1, R_2>, hono_types.H<Env, any, I4, R_2>];
|
|
10
|
+
<I_4 extends hono.Input = {}, I2_3 extends hono.Input = I_4, I3_2 extends hono.Input = I_4 & I2_3, I4_1 extends hono.Input = I_4 & I2_3 & I3_2, I5 extends hono.Input = I_4 & I2_3 & I3_2 & I4_1, R_3 extends hono_types.HandlerResponse<any> = any>(handler1: hono_types.H<Env, any, I_4, R_3>, handler2: hono_types.H<Env, any, I2_3, R_3>, handler3: hono_types.H<Env, any, I3_2, R_3>, handler4: hono_types.H<Env, any, I4_1, R_3>, handler5: hono_types.H<Env, any, I5, R_3>): [hono_types.H<Env, any, I_4, R_3>, hono_types.H<Env, any, I2_3, R_3>, hono_types.H<Env, any, I3_2, R_3>, hono_types.H<Env, any, I4_1, R_3>, hono_types.H<Env, any, I5, R_3>];
|
|
11
|
+
<I_5 extends hono.Input = {}, I2_4 extends hono.Input = I_5, I3_3 extends hono.Input = I_5 & I2_4, I4_2 extends hono.Input = I_5 & I2_4 & I3_3, I5_1 extends hono.Input = I_5 & I2_4 & I3_3 & I4_2, I6 extends hono.Input = I_5 & I2_4 & I3_3 & I4_2 & I5_1, R_4 extends hono_types.HandlerResponse<any> = any>(handler1: hono_types.H<Env, any, I_5, R_4>, handler2: hono_types.H<Env, any, I2_4, R_4>, handler3: hono_types.H<Env, any, I3_3, R_4>, handler4: hono_types.H<Env, any, I4_2, R_4>, handler5: hono_types.H<Env, any, I5_1, R_4>, handler6: hono_types.H<Env, any, I6, R_4>): [hono_types.H<Env, any, I_5, R_4>, hono_types.H<Env, any, I2_4, R_4>, hono_types.H<Env, any, I3_3, R_4>, hono_types.H<Env, any, I4_2, R_4>, hono_types.H<Env, any, I5_1, R_4>, hono_types.H<Env, any, I6, R_4>];
|
|
12
|
+
<I_6 extends hono.Input = {}, I2_5 extends hono.Input = I_6, I3_4 extends hono.Input = I_6 & I2_5, I4_3 extends hono.Input = I_6 & I2_5 & I3_4, I5_2 extends hono.Input = I_6 & I2_5 & I3_4 & I4_3, I6_1 extends hono.Input = I_6 & I2_5 & I3_4 & I4_3 & I5_2, I7 extends hono.Input = I_6 & I2_5 & I3_4 & I4_3 & I5_2 & I6_1, R_5 extends hono_types.HandlerResponse<any> = any>(handler1: hono_types.H<Env, any, I_6, R_5>, handler2: hono_types.H<Env, any, I2_5, R_5>, handler3: hono_types.H<Env, any, I3_4, R_5>, handler4: hono_types.H<Env, any, I4_3, R_5>, handler5: hono_types.H<Env, any, I5_2, R_5>, handler6: hono_types.H<Env, any, I6_1, R_5>, handler7: hono_types.H<Env, any, I7, R_5>): [hono_types.H<Env, any, I_6, R_5>, hono_types.H<Env, any, I2_5, R_5>, hono_types.H<Env, any, I3_4, R_5>, hono_types.H<Env, any, I4_3, R_5>, hono_types.H<Env, any, I5_2, R_5>, hono_types.H<Env, any, I6_1, R_5>, hono_types.H<Env, any, I7, R_5>];
|
|
13
|
+
<I_7 extends hono.Input = {}, I2_6 extends hono.Input = I_7, I3_5 extends hono.Input = I_7 & I2_6, I4_4 extends hono.Input = I_7 & I2_6 & I3_5, I5_3 extends hono.Input = I_7 & I2_6 & I3_5 & I4_4, I6_2 extends hono.Input = I_7 & I2_6 & I3_5 & I4_4 & I5_3, I7_1 extends hono.Input = I_7 & I2_6 & I3_5 & I4_4 & I5_3 & I6_2, I8 extends hono.Input = I_7 & I2_6 & I3_5 & I4_4 & I5_3 & I6_2 & I7_1, R_6 extends hono_types.HandlerResponse<any> = any>(handler1: hono_types.H<Env, any, I_7, R_6>, handler2: hono_types.H<Env, any, I2_6, R_6>, handler3: hono_types.H<Env, any, I3_5, R_6>, handler4: hono_types.H<Env, any, I4_4, R_6>, handler5: hono_types.H<Env, any, I5_3, R_6>, handler6: hono_types.H<Env, any, I6_2, R_6>, handler7: hono_types.H<Env, any, I7_1, R_6>, handler8: hono_types.H<Env, any, I8, R_6>): [hono_types.H<Env, any, I_7, R_6>, hono_types.H<Env, any, I2_6, R_6>, hono_types.H<Env, any, I3_5, R_6>, hono_types.H<Env, any, I4_4, R_6>, hono_types.H<Env, any, I5_3, R_6>, hono_types.H<Env, any, I6_2, R_6>, hono_types.H<Env, any, I7_1, R_6>, hono_types.H<Env, any, I8, R_6>];
|
|
14
|
+
<I_8 extends hono.Input = {}, I2_7 extends hono.Input = I_8, I3_6 extends hono.Input = I_8 & I2_7, I4_5 extends hono.Input = I_8 & I2_7 & I3_6, I5_4 extends hono.Input = I_8 & I2_7 & I3_6 & I4_5, I6_3 extends hono.Input = I_8 & I2_7 & I3_6 & I4_5 & I5_4, I7_2 extends hono.Input = I_8 & I2_7 & I3_6 & I4_5 & I5_4 & I6_3, I8_1 extends hono.Input = I_8 & I2_7 & I3_6 & I4_5 & I5_4 & I6_3 & I7_2, I9 extends hono.Input = I_8 & I2_7 & I3_6 & I4_5 & I5_4 & I6_3 & I7_2 & I8_1, R_7 extends hono_types.HandlerResponse<any> = any>(handler1: hono_types.H<Env, any, I_8, R_7>, handler2: hono_types.H<Env, any, I2_7, R_7>, handler3: hono_types.H<Env, any, I3_6, R_7>, handler4: hono_types.H<Env, any, I4_5, R_7>, handler5: hono_types.H<Env, any, I5_4, R_7>, handler6: hono_types.H<Env, any, I6_3, R_7>, handler7: hono_types.H<Env, any, I7_2, R_7>, handler8: hono_types.H<Env, any, I8_1, R_7>, handler9: hono_types.H<Env, any, I9, R_7>): [hono_types.H<Env, any, I_8, R_7>, hono_types.H<Env, any, I2_7, R_7>, hono_types.H<Env, any, I3_6, R_7>, hono_types.H<Env, any, I4_5, R_7>, hono_types.H<Env, any, I5_4, R_7>, hono_types.H<Env, any, I6_3, R_7>, hono_types.H<Env, any, I7_2, R_7>, hono_types.H<Env, any, I8_1, R_7>, hono_types.H<Env, any, I9, R_7>];
|
|
15
|
+
<I_9 extends hono.Input = {}, I2_8 extends hono.Input = I_9, I3_7 extends hono.Input = I_9 & I2_8, I4_6 extends hono.Input = I_9 & I2_8 & I3_7, I5_5 extends hono.Input = I_9 & I2_8 & I3_7 & I4_6, I6_4 extends hono.Input = I_9 & I2_8 & I3_7 & I4_6 & I5_5, I7_3 extends hono.Input = I_9 & I2_8 & I3_7 & I4_6 & I5_5 & I6_4, I8_2 extends hono.Input = I_9 & I2_8 & I3_7 & I4_6 & I5_5 & I6_4 & I7_3, I9_1 extends hono.Input = I_9 & I2_8 & I3_7 & I4_6 & I5_5 & I6_4 & I7_3 & I8_2, I10 extends hono.Input = I_9 & I2_8 & I3_7 & I4_6 & I5_5 & I6_4 & I7_3 & I8_2 & I9_1, R_8 extends hono_types.HandlerResponse<any> = any>(handler1: hono_types.H<Env, any, I_9, R_8>, handler2: hono_types.H<Env, any, I2_8, R_8>, handler3: hono_types.H<Env, any, I3_7, R_8>, handler4: hono_types.H<Env, any, I4_6, R_8>, handler5: hono_types.H<Env, any, I5_5, R_8>, handler6: hono_types.H<Env, any, I6_4, R_8>, handler7: hono_types.H<Env, any, I7_3, R_8>, handler8: hono_types.H<Env, any, I8_2, R_8>, handler9: hono_types.H<Env, any, I9_1, R_8>, handler10: hono_types.H<Env, any, I10, R_8>): [hono_types.H<Env, any, I_9, R_8>, hono_types.H<Env, any, I2_8, R_8>, hono_types.H<Env, any, I3_7, R_8>, hono_types.H<Env, any, I4_6, R_8>, hono_types.H<Env, any, I5_5, R_8>, hono_types.H<Env, any, I6_4, R_8>, hono_types.H<Env, any, I7_3, R_8>, hono_types.H<Env, any, I8_2, R_8>, hono_types.H<Env, any, I9_1, R_8>, hono_types.H<Env, any, I10, R_8>];
|
|
16
|
+
};
|
|
17
|
+
declare const createHono: () => Hono<Env, hono_types.BlankSchema, "/">;
|
|
18
|
+
|
|
19
|
+
export { createHono, createRoute };
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { ServerOptions, createApp } from './server.js';
|
|
2
|
-
export { HasIslands } from './components.js';
|
|
2
|
+
export { HasIslands } from './components/has-islands.js';
|
|
3
|
+
export { Script } from './components/script.js';
|
|
3
4
|
import 'hono/types';
|
|
4
5
|
import 'hono';
|
|
5
6
|
import '../constants.js';
|
|
6
7
|
import 'hono/jsx';
|
|
8
|
+
import 'vite';
|
package/dist/server/index.js
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const defaultOptions = {
|
|
2
|
+
jsxImportSource: "hono/jsx/dom",
|
|
3
|
+
assetsDir: "static"
|
|
4
|
+
};
|
|
5
|
+
function client(options) {
|
|
6
|
+
return {
|
|
7
|
+
name: "honox-vite-client",
|
|
8
|
+
config: () => {
|
|
9
|
+
return {
|
|
10
|
+
build: {
|
|
11
|
+
rollupOptions: {
|
|
12
|
+
input: ["/app/client.ts"]
|
|
13
|
+
},
|
|
14
|
+
assetsDir: options?.assetsDir ?? defaultOptions.assetsDir,
|
|
15
|
+
manifest: true
|
|
16
|
+
},
|
|
17
|
+
esbuild: {
|
|
18
|
+
jsxImportSource: options?.jsxImportSource ?? defaultOptions.jsxImportSource
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
var client_default = client;
|
|
25
|
+
export {
|
|
26
|
+
client_default as default,
|
|
27
|
+
defaultOptions
|
|
28
|
+
};
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -3,13 +3,13 @@ export { defaultOptions as devServerDefaultOptions } from '@hono/vite-dev-server
|
|
|
3
3
|
import { PluginOption } from 'vite';
|
|
4
4
|
export { islandComponents } from './island-components.js';
|
|
5
5
|
|
|
6
|
-
type
|
|
6
|
+
type Options = {
|
|
7
7
|
islands?: boolean;
|
|
8
8
|
entry?: string;
|
|
9
9
|
devServer?: DevServerOptions;
|
|
10
10
|
external?: string[];
|
|
11
11
|
};
|
|
12
|
-
declare const defaultOptions:
|
|
13
|
-
declare function honox(options?:
|
|
12
|
+
declare const defaultOptions: Options;
|
|
13
|
+
declare function honox(options?: Options): PluginOption[];
|
|
14
14
|
|
|
15
15
|
export { honox as default, defaultOptions };
|
package/dist/vite/index.js
CHANGED
|
@@ -27,7 +27,14 @@ function honox(options) {
|
|
|
27
27
|
plugins.push(injectImportingIslands());
|
|
28
28
|
return [
|
|
29
29
|
{
|
|
30
|
-
name: "honox-vite-config"
|
|
30
|
+
name: "honox-vite-config",
|
|
31
|
+
config: () => {
|
|
32
|
+
return {
|
|
33
|
+
ssr: {
|
|
34
|
+
noExternal: true
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
31
38
|
},
|
|
32
39
|
...plugins
|
|
33
40
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "honox",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -52,6 +52,10 @@
|
|
|
52
52
|
"./vite": {
|
|
53
53
|
"types": "./dist/vite/index.d.ts",
|
|
54
54
|
"import": "./dist/vite/index.js"
|
|
55
|
+
},
|
|
56
|
+
"./vite/client": {
|
|
57
|
+
"types": "./dist/vite/client.d.ts",
|
|
58
|
+
"import": "./dist/vite/client.js"
|
|
55
59
|
}
|
|
56
60
|
},
|
|
57
61
|
"typesVersions": {
|
|
@@ -73,6 +77,9 @@
|
|
|
73
77
|
],
|
|
74
78
|
"vite": [
|
|
75
79
|
"./dist/vite"
|
|
80
|
+
],
|
|
81
|
+
"vite/client": [
|
|
82
|
+
"./dist/vite/client"
|
|
76
83
|
]
|
|
77
84
|
}
|
|
78
85
|
},
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import _generate from "@babel/generator";
|
|
2
|
-
import { parse } from "@babel/parser";
|
|
3
|
-
import _traverse from "@babel/traverse";
|
|
4
|
-
import { HAS_ISLANDS_ID } from "../constants.js";
|
|
5
|
-
const traverse = _traverse.default ?? _traverse;
|
|
6
|
-
const generate = _generate.default ?? _generate;
|
|
7
|
-
function injectHasIslands() {
|
|
8
|
-
return {
|
|
9
|
-
name: "inject-has-islands",
|
|
10
|
-
transform(code, id) {
|
|
11
|
-
if (id.endsWith(".tsx") || id.endsWith(".jsx")) {
|
|
12
|
-
let hasIslandsImport = false;
|
|
13
|
-
const ast = parse(code, {
|
|
14
|
-
sourceType: "module",
|
|
15
|
-
plugins: ["jsx"]
|
|
16
|
-
});
|
|
17
|
-
traverse(ast, {
|
|
18
|
-
ImportDeclaration(path) {
|
|
19
|
-
if (path.node.source.value.includes("islands/")) {
|
|
20
|
-
hasIslandsImport = true;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
if (hasIslandsImport) {
|
|
25
|
-
const hasIslandsNode = {
|
|
26
|
-
type: "ExportNamedDeclaration",
|
|
27
|
-
declaration: {
|
|
28
|
-
type: "VariableDeclaration",
|
|
29
|
-
declarations: [
|
|
30
|
-
{
|
|
31
|
-
type: "VariableDeclarator",
|
|
32
|
-
id: { type: "Identifier", name: HAS_ISLANDS_ID },
|
|
33
|
-
init: { type: "BooleanLiteral", value: true }
|
|
34
|
-
}
|
|
35
|
-
],
|
|
36
|
-
kind: "const"
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
ast.program.body.push(hasIslandsNode);
|
|
40
|
-
}
|
|
41
|
-
const output = generate(ast, {}, code);
|
|
42
|
-
return {
|
|
43
|
-
code: output.code,
|
|
44
|
-
map: output.map
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
export {
|
|
51
|
-
injectHasIslands
|
|
52
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import _generate from "@babel/generator";
|
|
2
|
-
import { parse } from "@babel/parser";
|
|
3
|
-
import _traverse from "@babel/traverse";
|
|
4
|
-
import { HAS_ISLANDS_ID } from "../constants";
|
|
5
|
-
const traverse = _traverse.default ?? _traverse;
|
|
6
|
-
const generate = _generate.default ?? _generate;
|
|
7
|
-
function injectHasIslands() {
|
|
8
|
-
return {
|
|
9
|
-
name: "inject-has-islands",
|
|
10
|
-
transform(code, id) {
|
|
11
|
-
if (id.endsWith(".tsx") || id.endsWith(".jsx")) {
|
|
12
|
-
let hasIslandsImport = false;
|
|
13
|
-
const ast = parse(code, {
|
|
14
|
-
sourceType: "module",
|
|
15
|
-
plugins: ["jsx"]
|
|
16
|
-
});
|
|
17
|
-
traverse(ast, {
|
|
18
|
-
ImportDeclaration(path) {
|
|
19
|
-
if (path.node.source.value.includes("islands/")) {
|
|
20
|
-
hasIslandsImport = true;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
if (hasIslandsImport) {
|
|
25
|
-
const hasIslandsNode = {
|
|
26
|
-
type: "ExportNamedDeclaration",
|
|
27
|
-
declaration: {
|
|
28
|
-
type: "VariableDeclaration",
|
|
29
|
-
declarations: [
|
|
30
|
-
{
|
|
31
|
-
type: "VariableDeclarator",
|
|
32
|
-
id: { type: "Identifier", name: HAS_ISLANDS_ID },
|
|
33
|
-
init: { type: "BooleanLiteral", value: true }
|
|
34
|
-
}
|
|
35
|
-
],
|
|
36
|
-
kind: "const"
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
ast.program.body.push(hasIslandsNode);
|
|
40
|
-
}
|
|
41
|
-
const output = generate(ast, {}, code);
|
|
42
|
-
return {
|
|
43
|
-
code: output.code,
|
|
44
|
-
map: output.map
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
export {
|
|
51
|
-
injectHasIslands
|
|
52
|
-
};
|
|
File without changes
|