@adonisjs/inertia 1.0.0-1 → 1.0.0-10

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.
Files changed (35) hide show
  1. package/build/app.css.stub +39 -0
  2. package/build/{chunk-TO74VVAR.js → chunk-CXICUKHN.js} +49 -7
  3. package/build/{stubs/config.stub → config.stub} +9 -1
  4. package/build/index.d.ts +2 -2
  5. package/build/index.js +119 -23
  6. package/build/providers/inertia_provider.d.ts +10 -3
  7. package/build/providers/inertia_provider.js +25 -18
  8. package/build/react/app.tsx.stub +25 -0
  9. package/build/react/home.tsx.stub +21 -0
  10. package/build/react/root.edge.stub +22 -0
  11. package/build/react/ssr.tsx.stub +17 -0
  12. package/build/react/tsconfig.json.stub +25 -0
  13. package/build/solid/app.tsx.stub +24 -0
  14. package/build/solid/home.tsx.stub +21 -0
  15. package/build/solid/root.edge.stub +21 -0
  16. package/build/solid/ssr.tsx.stub +19 -0
  17. package/build/solid/tsconfig.json.stub +26 -0
  18. package/build/src/helpers.d.ts +12 -0
  19. package/build/src/helpers.js +14 -0
  20. package/build/src/inertia_middleware.d.ts +13 -4
  21. package/build/src/inertia_middleware.js +1 -1
  22. package/build/src/plugins/edge/plugin.js +85 -0
  23. package/build/src/plugins/{api_client.d.ts → japa/api_client.d.ts} +1 -1
  24. package/build/src/plugins/{api_client.js → japa/api_client.js} +1 -1
  25. package/build/src/plugins/vite.d.ts +26 -0
  26. package/build/src/plugins/vite.js +33 -0
  27. package/build/src/types.d.ts +27 -0
  28. package/build/vue/app.ts.stub +27 -0
  29. package/build/vue/home.vue.stub +21 -0
  30. package/build/vue/root.edge.stub +21 -0
  31. package/build/vue/ssr.ts.stub +22 -0
  32. package/build/vue/tsconfig.json.stub +26 -0
  33. package/package.json +48 -40
  34. package/build/src/plugins/edge.js +0 -41
  35. /package/build/src/plugins/{edge.d.ts → edge/plugin.d.ts} +0 -0
@@ -0,0 +1,39 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/css/app.css') })
3
+ }}}
4
+ @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500&display=swap');
5
+
6
+ * {
7
+ margin: 0;
8
+ padding: 0;
9
+ }
10
+
11
+ html,
12
+ body,
13
+ #app {
14
+ background-color: #F7F8FA;
15
+ font-family: 'Poppins', sans-serif;
16
+ color: #46444c;
17
+ height: 100%;
18
+ width: 100%;
19
+ }
20
+
21
+ .title {
22
+ font-size: 42px;
23
+ font-weight: 500;
24
+ color: #5a45ff;
25
+ }
26
+
27
+ .container {
28
+ display: flex;
29
+ justify-content: center;
30
+ align-items: center;
31
+ flex-direction: column;
32
+ height: 100%;
33
+ width: 100%;
34
+ }
35
+
36
+ a {
37
+ text-decoration: underline;
38
+ color: #5a45ff;
39
+ }
@@ -1,10 +1,13 @@
1
1
  // src/inertia.ts
2
2
  var kLazySymbol = Symbol("lazy");
3
3
  var Inertia = class {
4
- constructor(ctx, config) {
4
+ constructor(ctx, config, viteRuntime) {
5
5
  this.ctx = ctx;
6
6
  this.config = config;
7
+ this.viteRuntime = viteRuntime;
8
+ this.#sharedData = config.sharedData;
7
9
  }
10
+ #sharedData = {};
8
11
  /**
9
12
  * Check if a value is a lazy prop
10
13
  */
@@ -54,19 +57,57 @@ var Inertia = class {
54
57
  return {
55
58
  component,
56
59
  version: this.config.versionCache.getVersion(),
57
- props: await this.#resolvePageProps(component, { ...this.config.sharedData, ...pageProps }),
60
+ props: await this.#resolvePageProps(component, { ...this.#sharedData, ...pageProps }),
58
61
  url: this.ctx.request.url(true)
59
62
  };
60
63
  }
64
+ /**
65
+ * If the page should be rendered on the server
66
+ */
67
+ #shouldRenderOnServer(component) {
68
+ const isSsrEnabled = this.config.ssr.enabled;
69
+ const isSsrEnabledForPage = this.config.ssr.pages ? this.config.ssr.pages.includes(component) : true;
70
+ return isSsrEnabled && isSsrEnabledForPage;
71
+ }
72
+ /**
73
+ * Render the page on the server
74
+ *
75
+ * On development, we use the Vite Runtime API
76
+ * On production, we just import and use the SSR bundle generated by Vite
77
+ */
78
+ async #renderOnServer(pageObject, viewProps) {
79
+ let render;
80
+ if (this.viteRuntime) {
81
+ render = await this.viteRuntime.executeEntrypoint(this.config.ssr.entrypoint);
82
+ } else {
83
+ render = await import(this.config.ssr.bundle);
84
+ }
85
+ const result = await render.default(pageObject);
86
+ return this.ctx.view.render(this.config.rootView, {
87
+ ...viewProps,
88
+ page: { ssrHead: result.head, ssrBody: result.body }
89
+ });
90
+ }
91
+ /**
92
+ * Share data for the current request.
93
+ * This data will override any shared data defined in the config.
94
+ */
95
+ share(data) {
96
+ this.#sharedData = { ...this.#sharedData, ...data };
97
+ }
61
98
  /**
62
99
  * Render a page using Inertia
63
100
  */
64
- async render(component, pageProps) {
101
+ async render(component, pageProps, viewProps) {
65
102
  const pageObject = await this.#buildPageObject(component, pageProps);
66
103
  const isInertiaRequest = !!this.ctx.request.header("x-inertia");
67
104
  if (!isInertiaRequest) {
68
- return this.ctx.view.render(this.config.rootView, { page: pageObject });
105
+ const shouldRenderOnServer = this.#shouldRenderOnServer(component);
106
+ if (shouldRenderOnServer)
107
+ return this.#renderOnServer(pageObject, viewProps);
108
+ return this.ctx.view.render(this.config.rootView, { ...viewProps, page: pageObject });
69
109
  }
110
+ this.ctx.response.header("x-inertia", "true");
70
111
  return pageObject;
71
112
  }
72
113
  /**
@@ -94,18 +135,19 @@ var Inertia = class {
94
135
 
95
136
  // src/inertia_middleware.ts
96
137
  var InertiaMiddleware = class {
97
- constructor(config) {
138
+ constructor(config, vite) {
98
139
  this.config = config;
140
+ this.#runtime = vite?.getRuntime();
99
141
  }
142
+ #runtime;
100
143
  async handle(ctx, next) {
101
144
  const { response, request } = ctx;
102
- ctx.inertia = new Inertia(ctx, this.config);
145
+ ctx.inertia = new Inertia(ctx, this.config, this.#runtime);
103
146
  await next();
104
147
  const isInertiaRequest = !!request.header("x-inertia");
105
148
  if (!isInertiaRequest)
106
149
  return;
107
150
  response.header("Vary", "Accept");
108
- response.header("X-Inertia", "true");
109
151
  const method = request.method();
110
152
  if (response.getStatus() === 302 && ["PUT", "PATCH", "DELETE"].includes(method)) {
111
153
  response.status(303);
@@ -7,7 +7,7 @@ export default defineConfig({
7
7
  /**
8
8
  * Path to the Edge view that will be used as the root view for Inertia responses
9
9
  */
10
- rootView: 'home',
10
+ rootView: 'root',
11
11
 
12
12
  /**
13
13
  * Data that should be shared with all rendered pages
@@ -15,4 +15,12 @@ export default defineConfig({
15
15
  sharedData: {
16
16
  errors: (ctx) => ctx.session.flashMessages.get('errors'),
17
17
  },
18
+
19
+ /**
20
+ * Options for the server-side rendering
21
+ */
22
+ ssr: {
23
+ enabled: {{ ssr }},
24
+ entrypoint: '{{ ssrEntrypoint }}'
25
+ }
18
26
  })
package/build/index.d.ts CHANGED
@@ -8,11 +8,11 @@ import '@adonisjs/core/http';
8
8
  */
9
9
  declare function configure(command: Configure): Promise<void>;
10
10
 
11
- declare const stubsRoot: string;
12
-
13
11
  /**
14
12
  * Define the Inertia configuration
15
13
  */
16
14
  declare function defineConfig(config: InertiaConfig): ConfigProvider<ResolvedConfig>;
17
15
 
16
+ declare const stubsRoot: string;
17
+
18
18
  export { configure, defineConfig, stubsRoot };
package/build/index.js CHANGED
@@ -1,70 +1,160 @@
1
+ // stubs/main.ts
2
+ import { getDirname } from "@poppinss/utils";
3
+ var stubsRoot = getDirname(import.meta.url);
4
+
1
5
  // configure.ts
2
- var ADAPTERS = ["Vue 3", "React", "Svelte"];
6
+ var ADAPTERS = ["Vue 3", "React", "Svelte", "Solid"];
3
7
  var ADAPTERS_INFO = {
4
8
  "Vue 3": {
9
+ stubFolder: "vue",
10
+ appExtension: "ts",
11
+ componentsExtension: "vue",
5
12
  dependencies: [
6
13
  { name: "@inertiajs/vue3", isDevDependency: false },
7
14
  { name: "vue", isDevDependency: false },
8
15
  { name: "@vitejs/plugin-vue", isDevDependency: true }
9
- ]
16
+ ],
17
+ ssrDependencies: [{ name: "@vue/server-renderer", isDevDependency: false }],
18
+ viteRegister: {
19
+ pluginCall: "vue()",
20
+ importDeclarations: [{ isNamed: false, module: "@vitejs/plugin-vue", identifier: "vue" }]
21
+ },
22
+ ssrEntrypoint: "resources/ssr.ts"
10
23
  },
11
24
  "React": {
25
+ stubFolder: "react",
26
+ appExtension: "tsx",
27
+ componentsExtension: "tsx",
12
28
  dependencies: [
13
- { name: "@inertiajs/inertia-react", isDevDependency: false },
29
+ { name: "@inertiajs/react", isDevDependency: false },
14
30
  { name: "react", isDevDependency: false },
15
31
  { name: "react-dom", isDevDependency: false },
16
32
  { name: "@vitejs/plugin-react", isDevDependency: true },
17
33
  { name: "@types/react", isDevDependency: true },
18
34
  { name: "@types/react-dom", isDevDependency: true }
19
- ]
35
+ ],
36
+ viteRegister: {
37
+ pluginCall: "react()",
38
+ importDeclarations: [{ isNamed: false, module: "@vitejs/plugin-react", identifier: "react" }]
39
+ },
40
+ ssrEntrypoint: "resources/ssr.tsx"
20
41
  },
21
42
  "Svelte": {
43
+ stubFolder: "svelte",
44
+ appExtension: "ts",
45
+ componentsExtension: "svelte",
22
46
  dependencies: [
23
- { name: "@inertiajs/inertia-svelte", isDevDependency: false },
47
+ { name: "@inertiajs/svelte", isDevDependency: false },
24
48
  { name: "svelte", isDevDependency: false },
25
49
  { name: "@sveltejs/vite-plugin-svelte", isDevDependency: true }
26
- ]
50
+ ],
51
+ viteRegister: {
52
+ pluginCall: "svelte()",
53
+ importDeclarations: [
54
+ { isNamed: false, module: "@sveltejs/vite-plugin-svelte", identifier: "svelte" }
55
+ ]
56
+ },
57
+ ssrEntrypoint: "resources/ssr.ts"
58
+ },
59
+ "Solid": {
60
+ stubFolder: "solid",
61
+ appExtension: "tsx",
62
+ componentsExtension: "tsx",
63
+ dependencies: [
64
+ { name: "solid-js", isDevDependency: false },
65
+ { name: "inertia-adapter-solid", isDevDependency: false },
66
+ { name: "vite-plugin-solid", isDevDependency: true },
67
+ { name: "@solidjs/meta", isDevDependency: false }
68
+ ],
69
+ viteRegister: {
70
+ pluginCall: "solid()",
71
+ ssrPluginCall: "solid({ ssr: true })",
72
+ importDeclarations: [{ isNamed: false, module: "vite-plugin-solid", identifier: "solid" }]
73
+ },
74
+ ssrEntrypoint: "resources/ssr.tsx"
27
75
  }
28
76
  };
77
+ async function defineExampleRoute(command, codemods) {
78
+ const tsMorph = await codemods.getTsMorphProject();
79
+ const routesFile = tsMorph?.getSourceFile(command.app.makePath("./start/routes.ts"));
80
+ if (!routesFile) {
81
+ return command.logger.warning("Unable to find the routes file");
82
+ }
83
+ const isAlreadyDefined = routesFile.getText().includes("/inertia");
84
+ if (isAlreadyDefined) {
85
+ command.logger.warning("/inertia route is already defined. Skipping");
86
+ return;
87
+ }
88
+ const action = command.logger.action("update start/routes.ts file");
89
+ try {
90
+ routesFile?.addStatements((writer) => {
91
+ writer.writeLine(`router.on('/inertia').renderInertia('home', { version: 6 })`);
92
+ });
93
+ await tsMorph?.save();
94
+ action.succeeded();
95
+ } catch (error) {
96
+ codemods.emit("error", error);
97
+ action.failed(error.message);
98
+ }
99
+ }
29
100
  async function configure(command) {
30
101
  const adapter = await command.prompt.choice(
31
102
  "Select the Inertia adapter you want to use",
32
103
  ADAPTERS,
33
104
  { name: "adapter" }
34
105
  );
35
- const pkgToInstall = ADAPTERS_INFO[adapter].dependencies;
36
- const withSsr = await command.prompt.confirm("Do you want to enable server-side rendering?", {
106
+ const ssr = await command.prompt.confirm("Do you want to use server-side rendering?", {
37
107
  name: "ssr"
38
108
  });
39
- if (withSsr) {
40
- pkgToInstall.push(...ADAPTERS_INFO[adapter].ssrDependencies || []);
41
- }
109
+ const adapterInfo = ADAPTERS_INFO[adapter];
42
110
  const codemods = await command.createCodemods();
43
111
  await codemods.updateRcFile((rcFile) => {
44
112
  rcFile.addProvider("@adonisjs/inertia/inertia_provider");
45
113
  });
46
- codemods.registerMiddleware("router", [
114
+ await codemods.registerMiddleware("router", [
47
115
  { path: "@adonisjs/inertia/inertia_middleware", position: "after" }
48
116
  ]);
49
- await command.publishStub("config.stub");
117
+ const appExt = adapterInfo.appExtension;
118
+ const stubFolder = adapterInfo.stubFolder;
119
+ const compExt = adapterInfo.componentsExtension;
120
+ await codemods.makeUsingStub(stubsRoot, "config.stub", {
121
+ ssr,
122
+ ssrEntrypoint: adapterInfo.ssrEntrypoint
123
+ });
124
+ await codemods.makeUsingStub(stubsRoot, `app.css.stub`, {});
125
+ await codemods.makeUsingStub(stubsRoot, `${stubFolder}/root.edge.stub`, {});
126
+ await codemods.makeUsingStub(stubsRoot, `${stubFolder}/tsconfig.json.stub`, {});
127
+ await codemods.makeUsingStub(stubsRoot, `${stubFolder}/app.${appExt}.stub`, {});
128
+ await codemods.makeUsingStub(stubsRoot, `${stubFolder}/home.${compExt}.stub`, {});
129
+ if (ssr) {
130
+ await codemods.makeUsingStub(stubsRoot, `${stubFolder}/ssr.${appExt}.stub`, {});
131
+ }
132
+ const inertiaPluginCall = ssr ? `inertia({ ssr: { enabled: true, entrypoint: 'resources/ssr.${appExt}' } })` : `inertia({ ssr: { enabled: false } })`;
133
+ await codemods.registerVitePlugin(inertiaPluginCall, [
134
+ { isNamed: false, module: "@adonisjs/inertia/client", identifier: "inertia" }
135
+ ]);
136
+ await codemods.registerVitePlugin(
137
+ ssr && adapterInfo.viteRegister.ssrPluginCall ? adapterInfo.viteRegister.ssrPluginCall : adapterInfo.viteRegister.pluginCall,
138
+ adapterInfo.viteRegister.importDeclarations
139
+ );
140
+ await defineExampleRoute(command, codemods);
141
+ const pkgToInstall = adapterInfo.dependencies;
142
+ if (ssr && adapterInfo.ssrDependencies) {
143
+ pkgToInstall.push(...adapterInfo.ssrDependencies);
144
+ }
50
145
  const shouldInstallPackages = await command.prompt.confirm(
51
146
  `Do you want to install dependencies ${pkgToInstall.map((pkg) => pkg.name).join(", ")}?`,
52
147
  { name: "install" }
53
148
  );
54
149
  if (shouldInstallPackages) {
55
- command.installPackages(pkgToInstall);
150
+ await codemods.installPackages(pkgToInstall);
56
151
  } else {
57
- command.listPackagesToInstall(pkgToInstall);
152
+ await codemods.listPackagesToInstall(pkgToInstall);
58
153
  }
59
- command.logger.success(
60
- "Inertia was configured successfully. Please note that you still need to update your vite config, setup your Edge root view and others things. Read the docs for more info."
61
- );
154
+ const colors = command.colors;
155
+ command.ui.instructions().heading("Inertia was successfully configured !").add(`We have added a dummy ${colors.cyan("/inertia")} route in your project.`).add(`Try visiting it in your browser after starting your server to see Inertia in action`).add("Happy coding !").render();
62
156
  }
63
157
 
64
- // stubs/main.ts
65
- import { getDirname } from "@poppinss/utils";
66
- var stubsRoot = getDirname(import.meta.url);
67
-
68
158
  // src/define_config.ts
69
159
  import { configProvider } from "@adonisjs/core";
70
160
 
@@ -124,7 +214,13 @@ function defineConfig(config) {
124
214
  return {
125
215
  rootView: config.rootView ?? "root",
126
216
  sharedData: config.sharedData || {},
127
- versionCache
217
+ versionCache,
218
+ ssr: {
219
+ enabled: config.ssr?.enabled ?? false,
220
+ pages: config.ssr?.pages,
221
+ entrypoint: config.ssr?.entrypoint ?? app.makePath("resources/ssr.ts"),
222
+ bundle: config.ssr?.bundle ?? app.makePath("ssr/ssr.js")
223
+ }
128
224
  };
129
225
  });
130
226
  }
@@ -1,5 +1,14 @@
1
1
  import { ApplicationService } from '@adonisjs/core/types';
2
2
 
3
+ declare module '@adonisjs/core/http' {
4
+ interface BriskRoute {
5
+ /**
6
+ * Render an inertia page without defining an
7
+ * explicit route handler
8
+ */
9
+ renderInertia(component: string, props?: Record<string, any>, viewProps?: Record<string, any>): void;
10
+ }
11
+ }
3
12
  /**
4
13
  * Inertia provider
5
14
  */
@@ -10,10 +19,8 @@ declare class InertiaProvider {
10
19
  * Registers edge plugin when edge is installed
11
20
  */
12
21
  protected registerEdgePlugin(): Promise<void>;
13
- /**
14
- * Register Inertia bindings
15
- */
16
22
  register(): Promise<void>;
23
+ boot(): Promise<void>;
17
24
  }
18
25
 
19
26
  export { InertiaProvider as default };
@@ -1,10 +1,11 @@
1
1
  import {
2
2
  InertiaMiddleware
3
- } from "../chunk-TO74VVAR.js";
3
+ } from "../chunk-CXICUKHN.js";
4
4
 
5
5
  // providers/inertia_provider.ts
6
6
  import { configProvider } from "@adonisjs/core";
7
7
  import { RuntimeException } from "@poppinss/utils";
8
+ import { BriskRoute } from "@adonisjs/core/http";
8
9
  var InertiaProvider = class {
9
10
  constructor(app) {
10
11
  this.app = app;
@@ -13,26 +14,32 @@ var InertiaProvider = class {
13
14
  * Registers edge plugin when edge is installed
14
15
  */
15
16
  async registerEdgePlugin() {
16
- try {
17
- const edgeExports = await import("edge.js");
18
- const { edgePluginInertia } = await import("../src/plugins/edge.js");
19
- edgeExports.default.use(edgePluginInertia());
20
- } catch {
21
- }
17
+ if (!this.app.usingEdgeJS)
18
+ return;
19
+ const edgeExports = await import("edge.js");
20
+ const { edgePluginInertia } = await import("../src/plugins/edge/plugin.js");
21
+ edgeExports.default.use(edgePluginInertia());
22
22
  }
23
- /**
24
- * Register Inertia bindings
25
- */
26
23
  async register() {
27
- const inertiaConfigProvider = this.app.config.get("inertia");
28
- const config = await configProvider.resolve(this.app, inertiaConfigProvider);
29
- if (!config) {
30
- throw new RuntimeException(
31
- 'Invalid "config/inertia.ts" file. Make sure you are using the "defineConfig" method'
32
- );
33
- }
34
- this.app.container.singleton(InertiaMiddleware, () => new InertiaMiddleware(config));
24
+ this.app.container.singleton(InertiaMiddleware, async () => {
25
+ const inertiaConfigProvider = this.app.config.get("inertia");
26
+ const config = await configProvider.resolve(this.app, inertiaConfigProvider);
27
+ const vite = await this.app.container.make("vite");
28
+ if (!config) {
29
+ throw new RuntimeException(
30
+ 'Invalid "config/inertia.ts" file. Make sure you are using the "defineConfig" method'
31
+ );
32
+ }
33
+ return new InertiaMiddleware(config, vite);
34
+ });
35
+ }
36
+ async boot() {
35
37
  await this.registerEdgePlugin();
38
+ BriskRoute.macro("renderInertia", function(template, props, viewProps) {
39
+ return this.setHandler(({ inertia }) => {
40
+ return inertia.render(template, props, viewProps);
41
+ });
42
+ });
36
43
  }
37
44
  };
38
45
  export {
@@ -0,0 +1,25 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/app.tsx') })
3
+ }}}
4
+ import './css/app.css';
5
+
6
+ import { createRoot } from 'react-dom/client';
7
+ import { createInertiaApp } from '@inertiajs/react';
8
+
9
+ const appName = import.meta.env.VITE_APP_NAME || 'AdonisJS'
10
+
11
+ createInertiaApp({
12
+ progress: { color: '#5468FF' },
13
+
14
+ title: (title) => {{ '`${title} - ${appName}`' }},
15
+
16
+ resolve: (name) => {
17
+ const pages = import.meta.glob('./pages/**/*.tsx', { eager: true })
18
+ {{ 'return pages[`./pages/${name}.tsx`]' }}
19
+ },
20
+
21
+ setup({ el, App, props }) {
22
+ const root = createRoot(el);
23
+ root.render(<App {...props} />);
24
+ },
25
+ });
@@ -0,0 +1,21 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/pages/home.tsx') })
3
+ }}}
4
+ import { Head } from '@inertiajs/react'
5
+
6
+ export default function Home(props: { version: number }) {
7
+ return (
8
+ <>
9
+ <Head title="Homepage" />
10
+
11
+ <div className="container">
12
+ <div className="title">AdonisJS {props.version} x Inertia x React</div>
13
+
14
+ <span>
15
+ Learn more about AdonisJS and Inertia.js by visiting the{' '}
16
+ <a href="https://docs.adonisjs.com/inertia">AdonisJS documentation</a>.
17
+ </span>
18
+ </div>
19
+ </>
20
+ )
21
+ }
@@ -0,0 +1,22 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/views/root.edge') })
3
+ }}}
4
+ <!DOCTYPE html>
5
+ <html>
6
+
7
+ <head>
8
+ <meta charset="utf-8">
9
+ <meta name="viewport" content="width=device-width, initial-scale=1">
10
+
11
+ <title inertia>AdonisJS x Inertia x React</title>
12
+
13
+ @viteReactRefresh()
14
+ @vite(['resources/app.tsx'])
15
+ @inertiaHead()
16
+ </head>
17
+
18
+ <body>
19
+ @inertia()
20
+ </body>
21
+
22
+ </html>
@@ -0,0 +1,17 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/ssr.tsx') })
3
+ }}}
4
+ import ReactDOMServer from 'react-dom/server'
5
+ import { createInertiaApp } from '@inertiajs/react'
6
+
7
+ export default function render(page: any) {
8
+ return createInertiaApp({
9
+ page,
10
+ render: ReactDOMServer.renderToString,
11
+ resolve: (name) => {
12
+ const pages = import.meta.glob('./pages/**/*.tsx', { eager: true })
13
+ {{ 'return pages[`./pages/${name}.tsx`]' }}
14
+ },
15
+ setup: ({ App, props }) => <App {...props} />,
16
+ })
17
+ }
@@ -0,0 +1,25 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/tsconfig.json') })
3
+ }}}
4
+ {
5
+ "compilerOptions": {
6
+ "target": "ESNext",
7
+ "jsx": "react-jsx",
8
+ "lib": ["DOM", "ESNext", "DOM.Iterable", "ES2020"],
9
+ "useDefineForClassFields": true,
10
+ "baseUrl": ".",
11
+ "module": "ESNext",
12
+ "moduleResolution": "Bundler",
13
+ "paths": {
14
+ "@/*": ["./*"],
15
+ "~/*": ["../*"],
16
+ },
17
+ "resolveJsonModule": true,
18
+ "types": ["vite/client"],
19
+ "allowSyntheticDefaultImports": true,
20
+ "esModuleInterop": true,
21
+ "verbatimModuleSyntax": true,
22
+ "skipLibCheck": true,
23
+ },
24
+ "include": ["./**/*.ts", "./**/*.tsx"],
25
+ }
@@ -0,0 +1,24 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/app.tsx') })
3
+ }}}
4
+ import './css/app.css'
5
+
6
+ import { render } from 'solid-js/web'
7
+ import { createInertiaApp } from 'inertia-adapter-solid'
8
+
9
+ const appName = import.meta.env.VITE_APP_NAME || 'AdonisJS'
10
+
11
+ createInertiaApp({
12
+ progress: { color: '#5468FF' },
13
+
14
+ title: (title) => {{ '`${title} - ${appName}`' }},
15
+
16
+ resolve(name) {
17
+ const pages = import.meta.glob('./pages/**/*.tsx', { eager: true })
18
+ {{ 'return pages[`./pages/${name}.tsx`]' }}
19
+ },
20
+
21
+ setup({ el, App, props }) {
22
+ render(() => <App {...props} />, el)
23
+ },
24
+ })
@@ -0,0 +1,21 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/pages/home.tsx') })
3
+ }}}
4
+ import { Title } from '@solidjs/meta'
5
+
6
+ export default function Home(props: { version: number }) {
7
+ return (
8
+ <>
9
+ <Title>Homepage</Title>
10
+
11
+ <div class="container">
12
+ <div class="title">AdonisJS {props.version} x Inertia x Solid.js</div>
13
+
14
+ <span>
15
+ Learn more about AdonisJS and Inertia.js by visiting the{' '}
16
+ <a href="https://docs.adonisjs.com/inertia">AdonisJS documentation</a>.
17
+ </span>
18
+ </div>
19
+ </>
20
+ )
21
+ }
@@ -0,0 +1,21 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/views/root.edge') })
3
+ }}}
4
+ <!DOCTYPE html>
5
+ <html>
6
+
7
+ <head>
8
+ <meta charset="utf-8">
9
+ <meta name="viewport" content="width=device-width, initial-scale=1">
10
+
11
+ <title inertia>AdonisJS x Inertia x SolidJS</title>
12
+
13
+ @vite(['resources/app.tsx'])
14
+ @inertiaHead()
15
+ </head>
16
+
17
+ <body>
18
+ @inertia()
19
+ </body>
20
+
21
+ </html>
@@ -0,0 +1,19 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/ssr.tsx') })
3
+ }}}
4
+
5
+ import { hydrate } from 'solid-js/web'
6
+ import { createInertiaApp } from 'inertia-adapter-solid'
7
+
8
+ export default function render(page: any) {
9
+ return createInertiaApp({
10
+ page,
11
+ resolve: (name) => {
12
+ const pages = import.meta.glob('./pages/**/*.tsx', { eager: true })
13
+ {{ 'return pages[`./pages/${name}.tsx`]' }}
14
+ },
15
+ setup({ el, App, props }) {
16
+ hydrate(() => <App {...props} />, el)
17
+ },
18
+ })
19
+ }
@@ -0,0 +1,26 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/tsconfig.json') })
3
+ }}}
4
+ {
5
+ "compilerOptions": {
6
+ "target": "ESNext",
7
+ "jsx": "preserve",
8
+ "jsxImportSource": "solid-js",
9
+ "lib": ["DOM", "ESNext", "DOM.Iterable", "ES2020"],
10
+ "useDefineForClassFields": true,
11
+ "baseUrl": ".",
12
+ "module": "ESNext",
13
+ "moduleResolution": "Bundler",
14
+ "paths": {
15
+ "@/*": ["./*"],
16
+ "~/*": ["../*"],
17
+ },
18
+ "resolveJsonModule": true,
19
+ "types": ["vite/client"],
20
+ "allowSyntheticDefaultImports": true,
21
+ "esModuleInterop": true,
22
+ "verbatimModuleSyntax": true,
23
+ "skipLibCheck": true,
24
+ },
25
+ "include": ["./**/*.ts", "./**/*.tsx"],
26
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Utility function to resolve a page component
3
+ *
4
+ * @example
5
+ * return resolvePageComponent(
6
+ * `./pages/${name}.vue`,
7
+ * import.meta.glob<DefineComponent>("./pages/**\/*.vue")
8
+ * )
9
+ */
10
+ declare function resolvePageComponent<T>(path: string | string[], pages: Record<string, Promise<T> | (() => Promise<T>)>): Promise<T>;
11
+
12
+ export { resolvePageComponent };
@@ -0,0 +1,14 @@
1
+ // src/helpers.ts
2
+ async function resolvePageComponent(path, pages) {
3
+ for (const p of Array.isArray(path) ? path : [path]) {
4
+ const page = pages[p];
5
+ if (typeof page === "undefined") {
6
+ continue;
7
+ }
8
+ return typeof page === "function" ? page() : page;
9
+ }
10
+ throw new Error(`Page not found: ${path}`);
11
+ }
12
+ export {
13
+ resolvePageComponent
14
+ };
@@ -1,6 +1,8 @@
1
+ import { Vite } from '@adonisjs/vite';
1
2
  import { HttpContext } from '@adonisjs/core/http';
2
3
  import { NextFn } from '@adonisjs/core/types/http';
3
- import { ResolvedConfig, PageProps, MaybePromise } from './types.js';
4
+ import { ViteRuntime } from 'vite/runtime';
5
+ import { ResolvedConfig, Data, PageProps, MaybePromise } from './types.js';
4
6
 
5
7
  /**
6
8
  * Symbol used to identify lazy props
@@ -13,11 +15,17 @@ declare class Inertia {
13
15
  #private;
14
16
  protected ctx: HttpContext;
15
17
  protected config: ResolvedConfig;
16
- constructor(ctx: HttpContext, config: ResolvedConfig);
18
+ protected viteRuntime?: ViteRuntime | undefined;
19
+ constructor(ctx: HttpContext, config: ResolvedConfig, viteRuntime?: ViteRuntime | undefined);
20
+ /**
21
+ * Share data for the current request.
22
+ * This data will override any shared data defined in the config.
23
+ */
24
+ share(data: Record<string, Data>): void;
17
25
  /**
18
26
  * Render a page using Inertia
19
27
  */
20
- render<T extends PageProps>(component: string, pageProps?: T): Promise<string | {
28
+ render<TPageProps extends Record<string, any> = PageProps, TViewProps extends Record<string, any> = PageProps>(component: string, pageProps?: TPageProps, viewProps?: TViewProps): Promise<string | {
21
29
  component: string;
22
30
  version: string | number;
23
31
  props: any;
@@ -56,8 +64,9 @@ declare module '@adonisjs/core/http' {
56
64
  * set appropriate headers/status
57
65
  */
58
66
  declare class InertiaMiddleware {
67
+ #private;
59
68
  protected config: ResolvedConfig;
60
- constructor(config: ResolvedConfig);
69
+ constructor(config: ResolvedConfig, vite?: Vite);
61
70
  handle(ctx: HttpContext, next: NextFn): Promise<void>;
62
71
  }
63
72
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  InertiaMiddleware
3
- } from "../chunk-TO74VVAR.js";
3
+ } from "../chunk-CXICUKHN.js";
4
4
  export {
5
5
  InertiaMiddleware as default
6
6
  };
@@ -0,0 +1,85 @@
1
+ // src/plugins/edge/plugin.ts
2
+ import { encode } from "html-entities";
3
+
4
+ // src/debug.ts
5
+ import { debuglog } from "node:util";
6
+ var debug_default = debuglog("adonisjs:inertia");
7
+
8
+ // src/plugins/edge/tags.ts
9
+ import { EdgeError } from "edge-error";
10
+
11
+ // src/plugins/edge/utils.ts
12
+ function isSubsetOf(expression, expressions, errorCallback) {
13
+ if (!expressions.includes(expression.type)) {
14
+ errorCallback();
15
+ }
16
+ }
17
+
18
+ // src/plugins/edge/tags.ts
19
+ var inertiaTag = {
20
+ block: false,
21
+ tagName: "inertia",
22
+ seekable: true,
23
+ compile(parser, buffer, { filename, loc, properties }) {
24
+ if (properties.jsArg.trim() === "") {
25
+ buffer.writeExpression(`out += state.inertia(state.page)`, filename, loc.start.line);
26
+ return;
27
+ }
28
+ properties.jsArg = `(${properties.jsArg})`;
29
+ const parsed = parser.utils.transformAst(
30
+ parser.utils.generateAST(properties.jsArg, loc, filename),
31
+ filename,
32
+ parser
33
+ );
34
+ isSubsetOf(parsed, ["ObjectExpression"], () => {
35
+ const { line, col } = parser.utils.getExpressionLoc(parsed);
36
+ throw new EdgeError(
37
+ `"${properties.jsArg}" is not a valid argument for @inertia`,
38
+ "E_UNALLOWED_EXPRESSION",
39
+ { line, col, filename }
40
+ );
41
+ });
42
+ const attributes = parser.utils.stringify(parsed);
43
+ buffer.writeExpression(
44
+ `out += state.inertia(state.page, ${attributes})`,
45
+ filename,
46
+ loc.start.line
47
+ );
48
+ }
49
+ };
50
+ var inertiaHeadTag = {
51
+ block: false,
52
+ tagName: "inertiaHead",
53
+ seekable: false,
54
+ compile(_, buffer, { filename, loc }) {
55
+ buffer.writeExpression(`out += state.inertiaHead(state.page)`, filename, loc.start.line);
56
+ }
57
+ };
58
+
59
+ // src/plugins/edge/plugin.ts
60
+ var edgePluginInertia = () => {
61
+ return (edge) => {
62
+ debug_default("sharing globals and inertia tags with edge");
63
+ edge.global(
64
+ "inertia",
65
+ (page = {}, attributes = {}) => {
66
+ if (page.ssrBody)
67
+ return page.ssrBody;
68
+ const className = attributes?.class ? ` class="${attributes.class}"` : "";
69
+ const id = attributes?.id ? ` id="${attributes.id}"` : ' id="app"';
70
+ const tag = attributes?.as || "div";
71
+ const dataPage = encode(JSON.stringify(page));
72
+ return `<${tag}${id}${className} data-page="${dataPage}"></${tag}>`;
73
+ }
74
+ );
75
+ edge.global("inertiaHead", (page) => {
76
+ const { ssrHead = [] } = page || {};
77
+ return ssrHead.join("\n");
78
+ });
79
+ edge.registerTag(inertiaHeadTag);
80
+ edge.registerTag(inertiaTag);
81
+ };
82
+ };
83
+ export {
84
+ edgePluginInertia
85
+ };
@@ -1,6 +1,6 @@
1
1
  import { PluginFn } from '@japa/runner/types';
2
- import { PageProps } from '../types.js';
3
2
  import { ApplicationService } from '@adonisjs/core/types';
3
+ import { PageProps } from '../../types.js';
4
4
  import '@adonisjs/core/http';
5
5
 
6
6
  declare module '@japa/api-client' {
@@ -1,4 +1,4 @@
1
- // src/plugins/api_client.ts
1
+ // src/plugins/japa/api_client.ts
2
2
  import { configProvider } from "@adonisjs/core";
3
3
  import { RuntimeException } from "@poppinss/utils";
4
4
  import { ApiRequest, ApiResponse } from "@japa/api-client";
@@ -0,0 +1,26 @@
1
+ import { PluginOption } from 'vite';
2
+
3
+ type InertiaPluginOptions = {
4
+ ssr?: {
5
+ /**
6
+ * Whether or not to enable server-side rendering
7
+ */
8
+ enabled: true;
9
+ /**
10
+ * The entrypoint for the server-side rendering
11
+ */
12
+ entrypoint: string;
13
+ /**
14
+ * The output directory for the server-side rendering bundle
15
+ */
16
+ output?: string;
17
+ } | {
18
+ enabled: false;
19
+ };
20
+ };
21
+ /**
22
+ * Inertia plugin for Vite that is tailored for AdonisJS
23
+ */
24
+ declare function inertia(options?: InertiaPluginOptions): PluginOption;
25
+
26
+ export { type InertiaPluginOptions, inertia as default };
@@ -0,0 +1,33 @@
1
+ // src/plugins/vite.ts
2
+ function inertia(options) {
3
+ return {
4
+ name: "vite-plugin-inertia",
5
+ config: () => {
6
+ if (!options?.ssr?.enabled)
7
+ return {};
8
+ return {
9
+ buildSteps: [
10
+ {
11
+ name: "build-client",
12
+ description: "build inertia client bundle",
13
+ config: { build: { outDir: "build/public/assets/" } }
14
+ },
15
+ {
16
+ name: "build-ssr",
17
+ description: "build inertia server bundle",
18
+ config: {
19
+ build: {
20
+ ssr: true,
21
+ outDir: options.ssr.output || "build/ssr",
22
+ rollupOptions: { input: options.ssr.entrypoint }
23
+ }
24
+ }
25
+ }
26
+ ]
27
+ };
28
+ }
29
+ };
30
+ }
31
+ export {
32
+ inertia as default
33
+ };
@@ -56,6 +56,27 @@ interface InertiaConfig {
56
56
  * Data that should be shared with all rendered pages
57
57
  */
58
58
  sharedData?: SharedData;
59
+ /**
60
+ * Options to configure SSR
61
+ */
62
+ ssr?: {
63
+ /**
64
+ * Enable or disable SSR
65
+ */
66
+ enabled: boolean;
67
+ /**
68
+ * List of components that should be rendered on the server
69
+ */
70
+ pages?: string[];
71
+ /**
72
+ * Path to the SSR entrypoint file
73
+ */
74
+ entrypoint?: string;
75
+ /**
76
+ * Path to the SSR bundled file that will be used in production
77
+ */
78
+ bundle?: string;
79
+ };
59
80
  }
60
81
  /**
61
82
  * Resolved inertia configuration
@@ -64,6 +85,12 @@ interface ResolvedConfig {
64
85
  rootView: string;
65
86
  versionCache: VersionCache;
66
87
  sharedData: SharedData;
88
+ ssr: {
89
+ enabled: boolean;
90
+ entrypoint: string;
91
+ pages?: string[];
92
+ bundle: string;
93
+ };
67
94
  }
68
95
 
69
96
  export type { AssetsVersion, Data, InertiaConfig, MaybePromise, PageProps, ResolvedConfig, SharedData, SharedDatumFactory };
@@ -0,0 +1,27 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/app.ts') })
3
+ }}}
4
+ import './css/app.css';
5
+
6
+ import { createApp, h } from 'vue'
7
+ import type { DefineComponent } from 'vue'
8
+ import { createInertiaApp } from '@inertiajs/vue3'
9
+
10
+ const appName = import.meta.env.VITE_APP_NAME || 'AdonisJS'
11
+
12
+ createInertiaApp({
13
+ progress: { color: '#5468FF' },
14
+
15
+ title: (title) => {{ '`${title} - ${appName}`' }},
16
+
17
+ resolve: (name) => {
18
+ const pages = import.meta.glob<DefineComponent>('./pages/**/*.vue', { eager: true })
19
+ {{ 'return pages[`./pages/${name}.vue`]' }}
20
+ },
21
+
22
+ setup({ el, App, props, plugin }) {
23
+ createApp({ render: () => h(App, props) })
24
+ .use(plugin)
25
+ .mount(el)
26
+ },
27
+ })
@@ -0,0 +1,21 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/pages/home.vue') })
3
+ }}}
4
+ <script setup lang="ts">
5
+ import { Head } from '@inertiajs/vue3'
6
+
7
+ defineProps<{ version: number }>()
8
+ </script>
9
+
10
+ <template>
11
+ <Head title="Homepage" />
12
+
13
+ <div className="container">
14
+ <div className="title">AdonisJS \{\{ version \}\} x Inertia x Vue.js</div>
15
+
16
+ <span>
17
+ Learn more about AdonisJS and Inertia.js by visiting the
18
+ <a href="https://docs.adonisjs.com/inertia">AdonisJS documentation</a>.
19
+ </span>
20
+ </div>
21
+ </template>
@@ -0,0 +1,21 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/views/root.edge') })
3
+ }}}
4
+ <!DOCTYPE html>
5
+ <html>
6
+
7
+ <head>
8
+ <meta charset="utf-8">
9
+ <meta name="viewport" content="width=device-width, initial-scale=1">
10
+
11
+ <title inertia>AdonisJS x Inertia x VueJS</title>
12
+
13
+ @vite(['resources/app.ts'])
14
+ @inertiaHead()
15
+ </head>
16
+
17
+ <body>
18
+ @inertia()
19
+ </body>
20
+
21
+ </html>
@@ -0,0 +1,22 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/ssr.ts') })
3
+ }}}
4
+
5
+ import { createInertiaApp } from '@inertiajs/vue3'
6
+ import { renderToString } from '@vue/server-renderer'
7
+ import { createSSRApp, h, type DefineComponent } from 'vue'
8
+
9
+ export default function render(page: any) {
10
+ return createInertiaApp({
11
+ page,
12
+ render: renderToString,
13
+ resolve: (name) => {
14
+ const pages = import.meta.glob<DefineComponent>('./pages/**/*.vue', { eager: true })
15
+ {{ 'return pages[`./pages/${name}.vue`]' }}
16
+ },
17
+
18
+ setup({ App, props, plugin }) {
19
+ return createSSRApp({ render: () => h(App, props) }).use(plugin)
20
+ },
21
+ })
22
+ }
@@ -0,0 +1,26 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/tsconfig.json') })
3
+ }}}
4
+ {
5
+ "compilerOptions": {
6
+ "target": "ESNext",
7
+ "jsx": "preserve",
8
+ "jsxImportSource": "vue",
9
+ "lib": ["DOM", "ESNext", "DOM.Iterable", "ES2020"],
10
+ "useDefineForClassFields": true,
11
+ "baseUrl": ".",
12
+ "module": "ESNext",
13
+ "moduleResolution": "Bundler",
14
+ "paths": {
15
+ "@/*": ["./*"],
16
+ "~/*": ["../*"],
17
+ },
18
+ "resolveJsonModule": true,
19
+ "types": ["vite/client"],
20
+ "allowSyntheticDefaultImports": true,
21
+ "esModuleInterop": true,
22
+ "verbatimModuleSyntax": true,
23
+ "skipLibCheck": true,
24
+ },
25
+ "include": ["./**/*.ts", "./**/*.vue"],
26
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adonisjs/inertia",
3
3
  "description": "Official Inertia.js adapter for AdonisJS",
4
- "version": "1.0.0-1",
4
+ "version": "1.0.0-10",
5
5
  "engines": {
6
6
  "node": ">=18.16.0"
7
7
  },
@@ -16,12 +16,14 @@
16
16
  "./services/main": "./build/services/inertia.js",
17
17
  "./inertia_middleware": "./build/src/inertia_middleware.js",
18
18
  "./inertia_provider": "./build/providers/inertia_provider.js",
19
- "./plugins/edge": "./build/src/plugins/edge.js",
20
- "./plugins/api_client": "./build/src/plugins/api_client.js"
19
+ "./plugins/edge": "./build/src/plugins/edge/plugin.js",
20
+ "./plugins/api_client": "./build/src/plugins/japa/api_client.js",
21
+ "./client": "./build/src/plugins/vite.js",
22
+ "./helpers": "./build/src/helpers.js"
21
23
  },
22
24
  "scripts": {
23
25
  "clean": "del-cli build",
24
- "copy:templates": "copyfiles \"stubs/**/*.stub\" build",
26
+ "copy:templates": "copyfiles --up 1 \"stubs/**/*.stub\" build",
25
27
  "typecheck": "tsc --noEmit",
26
28
  "lint": "eslint . --ext=.ts",
27
29
  "format": "prettier --write .",
@@ -36,54 +38,58 @@
36
38
  "prepublishOnly": "npm run build"
37
39
  },
38
40
  "devDependencies": {
39
- "@adonisjs/assembler": "6.1.3-25",
40
- "@adonisjs/core": "6.1.5-31",
41
- "@adonisjs/eslint-config": "^1.1.8",
42
- "@adonisjs/prettier-config": "^1.1.8",
43
- "@adonisjs/session": "7.0.0-13",
44
- "@adonisjs/tsconfig": "^1.1.8",
45
- "@japa/api-client": "^2.0.1",
46
- "@japa/assert": "2.0.1",
47
- "@japa/file-system": "^2.0.1",
48
- "@japa/plugin-adonisjs": "^2.0.1",
49
- "@japa/runner": "3.0.5",
50
- "@swc/core": "^1.3.96",
51
- "@types/node": "^20.9.0",
52
- "@types/qs": "^6.9.10",
53
- "@types/supertest": "^2.0.16",
54
- "c8": "^8.0.1",
41
+ "@adonisjs/assembler": "^7.2.3",
42
+ "@adonisjs/core": "6.3.1",
43
+ "@adonisjs/eslint-config": "^1.2.2",
44
+ "@adonisjs/prettier-config": "^1.2.2",
45
+ "@adonisjs/session": "7.1.1",
46
+ "@adonisjs/tsconfig": "^1.2.2",
47
+ "@adonisjs/vite": "^3.0.0-2",
48
+ "@japa/api-client": "^2.0.2",
49
+ "@japa/assert": "2.1.0",
50
+ "@japa/expect-type": "^2.0.1",
51
+ "@japa/file-system": "^2.2.0",
52
+ "@japa/plugin-adonisjs": "^3.0.0",
53
+ "@japa/runner": "3.1.1",
54
+ "@japa/snapshot": "^2.0.4",
55
+ "@swc/core": "^1.4.2",
56
+ "@types/node": "^20.11.24",
57
+ "@types/qs": "^6.9.12",
58
+ "@types/supertest": "^6.0.2",
59
+ "@vavite/multibuild": "^4.1.1",
60
+ "c8": "^9.1.0",
55
61
  "copyfiles": "^2.4.1",
56
62
  "del-cli": "^5.1.0",
57
- "edge.js": "^6.0.0",
58
- "eslint": "^8.53.0",
63
+ "edge-parser": "^9.0.1",
64
+ "edge.js": "^6.0.1",
65
+ "eslint": "^8.57.0",
59
66
  "get-port": "^7.0.0",
60
- "np": "^8.0.4",
61
- "prettier": "^3.0.3",
62
- "supertest": "^6.3.3",
63
- "tinybench": "^2.5.1",
64
- "ts-node": "^10.9.1",
65
- "tsup": "^7.3.0",
66
- "typescript": "^5.2.2"
67
+ "np": "^10.0.0",
68
+ "prettier": "^3.2.5",
69
+ "supertest": "^6.3.4",
70
+ "tinybench": "^2.6.0",
71
+ "ts-node": "^10.9.2",
72
+ "tsup": "^8.0.2",
73
+ "typescript": "~5.3.3",
74
+ "vite": "^5.1.4"
67
75
  },
68
76
  "dependencies": {
69
- "@poppinss/utils": "^6.5.1",
77
+ "@poppinss/utils": "^6.7.2",
70
78
  "crc-32": "^1.2.2",
79
+ "edge-error": "^4.0.1",
71
80
  "html-entities": "^2.4.0",
72
81
  "qs": "^6.11.2"
73
82
  },
74
83
  "peerDependencies": {
75
- "@adonisjs/assembler": "6.1.3-25",
76
- "@adonisjs/core": "6.1.5-31",
77
- "@adonisjs/session": "7.0.0-13",
78
- "@japa/api-client": "^2.0.1",
84
+ "@adonisjs/core": "^6.2.0",
85
+ "@adonisjs/session": "^7.0.0",
86
+ "@adonisjs/vite": "^3.0.0-2",
87
+ "@japa/api-client": "^2.0.0",
79
88
  "edge.js": "^6.0.0"
80
89
  },
81
90
  "peerDependenciesMeta": {
82
- "@adonisjs/assembler": {
83
- "optional": false
84
- },
85
91
  "@japa/api-client": {
86
- "optional": false
92
+ "optional": true
87
93
  }
88
94
  },
89
95
  "author": "Julien Ripouteau <julien@ripouteau.com>,adonisjs",
@@ -120,11 +126,13 @@
120
126
  "entry": [
121
127
  "./index.ts",
122
128
  "./src/types.ts",
129
+ "./src/helpers.ts",
130
+ "./src/plugins/vite.ts",
123
131
  "./services/inertia.ts",
124
132
  "./src/inertia_middleware.ts",
125
133
  "./providers/inertia_provider.ts",
126
- "./src/plugins/edge.ts",
127
- "./src/plugins/api_client.ts"
134
+ "./src/plugins/edge/plugin.ts",
135
+ "./src/plugins/japa/api_client.ts"
128
136
  ],
129
137
  "outDir": "./build",
130
138
  "clean": true,
@@ -1,41 +0,0 @@
1
- // src/plugins/edge.ts
2
- import { encode } from "html-entities";
3
-
4
- // src/debug.ts
5
- import { debuglog } from "node:util";
6
- var debug_default = debuglog("adonisjs:inertia");
7
-
8
- // src/plugins/edge.ts
9
- var edgePluginInertia = () => {
10
- return (edge) => {
11
- debug_default("sharing globals and inertia tags with edge");
12
- edge.global("inertia", (page = {}) => {
13
- if (page.ssrBody)
14
- return page.ssrBody;
15
- return `<div id="app" data-page="${encode(JSON.stringify(page))}"></div>`;
16
- });
17
- edge.global("inertiaHead", (page) => {
18
- const { ssrHead = [] } = page || {};
19
- return ssrHead.join("\n");
20
- });
21
- edge.registerTag({
22
- block: false,
23
- tagName: "inertia",
24
- seekable: false,
25
- compile(_, buffer, { filename, loc }) {
26
- buffer.writeExpression(`out += state.inertia(state.page)`, filename, loc.start.line);
27
- }
28
- });
29
- edge.registerTag({
30
- block: false,
31
- tagName: "inertiaHead",
32
- seekable: false,
33
- compile(_, buffer, { filename, loc }) {
34
- buffer.writeExpression(`out += state.inertiaHead(state.page)`, filename, loc.start.line);
35
- }
36
- });
37
- };
38
- };
39
- export {
40
- edgePluginInertia
41
- };