@adonisjs/inertia 1.0.0-13 → 1.0.0-15

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.
@@ -1,10 +1,9 @@
1
1
  // src/server_renderer.ts
2
2
  var styleFileRE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\?)/;
3
3
  var ServerRenderer = class {
4
- constructor(config, viteRuntime, viteDevServer) {
4
+ constructor(config, vite) {
5
5
  this.config = config;
6
- this.viteRuntime = viteRuntime;
7
- this.viteDevServer = viteDevServer;
6
+ this.vite = vite;
8
7
  }
9
8
  /**
10
9
  * If the module is a style module
@@ -61,12 +60,14 @@ var ServerRenderer = class {
61
60
  async render(pageObject) {
62
61
  let render;
63
62
  let preloadTags = [];
64
- if (this.viteRuntime && this.viteDevServer) {
65
- render = await this.viteRuntime.executeEntrypoint(this.config.ssr.entrypoint);
66
- const entryMod = this.viteDevServer.moduleGraph.getModuleById(this.config.entrypoint);
63
+ const devServer = this.vite?.getDevServer();
64
+ if (devServer) {
65
+ const runtime = await this.vite.createRuntime();
66
+ render = await runtime.executeEntrypoint(this.config.ssr.entrypoint);
67
+ const entryMod = devServer.moduleGraph.getModuleById(this.config.entrypoint);
67
68
  const pageMod = this.#findPageModule(entryMod, pageObject);
68
69
  if (pageMod)
69
- await this.viteRuntime.executeUrl(pageMod.url);
70
+ await runtime.executeUrl(pageMod.url);
70
71
  const preloadUrls = /* @__PURE__ */ new Set();
71
72
  const visitedModules = /* @__PURE__ */ new Set();
72
73
  if (pageMod)
@@ -86,13 +87,12 @@ var ServerRenderer = class {
86
87
  // src/inertia.ts
87
88
  var kLazySymbol = Symbol("lazy");
88
89
  var Inertia = class {
89
- constructor(ctx, config, viteRuntime, viteDevServer) {
90
+ constructor(ctx, config, vite) {
90
91
  this.ctx = ctx;
91
92
  this.config = config;
92
- this.viteRuntime = viteRuntime;
93
- this.viteDevServer = viteDevServer;
93
+ this.vite = vite;
94
94
  this.#sharedData = config.sharedData;
95
- this.#serverRenderer = new ServerRenderer(config, viteRuntime, viteDevServer);
95
+ this.#serverRenderer = new ServerRenderer(config, vite);
96
96
  }
97
97
  #sharedData = {};
98
98
  #serverRenderer;
@@ -217,14 +217,10 @@ var InertiaMiddleware = class {
217
217
  constructor(config, vite) {
218
218
  this.config = config;
219
219
  this.vite = vite;
220
- this.#runtime = vite?.getRuntime();
221
- this.#viteDevServer = vite?.getDevServer();
222
220
  }
223
- #runtime;
224
- #viteDevServer;
225
221
  async handle(ctx, next) {
226
222
  const { response, request } = ctx;
227
- ctx.inertia = new Inertia(ctx, this.config, this.#runtime, this.#viteDevServer);
223
+ ctx.inertia = new Inertia(ctx, this.config, this.vite);
228
224
  await next();
229
225
  const isInertiaRequest = !!request.header("x-inertia");
230
226
  if (!isInertiaRequest)
package/build/index.js CHANGED
@@ -54,7 +54,7 @@ var ADAPTERS_INFO = {
54
54
  viteRegister: {
55
55
  pluginCall: "svelte()",
56
56
  importDeclarations: [
57
- { isNamed: false, module: "@sveltejs/vite-plugin-svelte", identifier: "svelte" }
57
+ { isNamed: true, module: "@sveltejs/vite-plugin-svelte", identifier: "svelte" }
58
58
  ]
59
59
  },
60
60
  ssrEntrypoint: "resources/ssr.ts"
@@ -156,6 +156,10 @@ async function configure(command) {
156
156
  ssr && adapterInfo.viteRegister.ssrPluginCall ? adapterInfo.viteRegister.ssrPluginCall : adapterInfo.viteRegister.pluginCall,
157
157
  adapterInfo.viteRegister.importDeclarations
158
158
  );
159
+ const adonisjsPluginCall = `adonisjs({ entrypoints: ['resources/app.${appExt}'], reload: ['resources/views/**/*.edge'] })`;
160
+ await codemods.registerVitePlugin(adonisjsPluginCall, [
161
+ { isNamed: false, module: "@adonisjs/vite/client", identifier: "adonisjs" }
162
+ ]);
159
163
  await defineExampleRoute(command, codemods);
160
164
  const pkgToInstall = adapterInfo.dependencies;
161
165
  if (ssr && adapterInfo.ssrDependencies) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  InertiaMiddleware
3
- } from "../chunk-WJOEJN5R.js";
3
+ } from "../chunk-7ZZGYDYU.js";
4
4
 
5
5
  // providers/inertia_provider.ts
6
6
  import { configProvider } from "@adonisjs/core";
@@ -17,7 +17,7 @@ createInertiaApp({
17
17
  resolve: (name) => {
18
18
  return resolvePageComponent(
19
19
  {{ '`./pages/${name}.tsx`' }},
20
- import.meta.glob<DefineComponent>('./pages/**/*.tsx'),
20
+ import.meta.glob('./pages/**/*.tsx'),
21
21
  )
22
22
  },
23
23
 
@@ -13,7 +13,7 @@ export default function Home(props: { version: number }) {
13
13
 
14
14
  <span>
15
15
  Learn more about AdonisJS and Inertia.js by visiting the{' '}
16
- <a href="https://docs.adonisjs.com/inertia">AdonisJS documentation</a>.
16
+ <a href="https://docs.adonisjs.com/guides/inertia">AdonisJS documentation</a>.
17
17
  </span>
18
18
  </div>
19
19
  </>
@@ -11,8 +11,8 @@
11
11
  <title inertia>AdonisJS x Inertia x React</title>
12
12
 
13
13
  @viteReactRefresh()
14
- {{ "@vite(['resources/app.tsx', `resources/pages/${page.component}.tsx`])" }}
15
14
  @inertiaHead()
15
+ {{ "@vite(['resources/app.tsx', `resources/pages/${page.component}.tsx`])" }}
16
16
  </head>
17
17
 
18
18
  <body>
@@ -17,7 +17,7 @@ createInertiaApp({
17
17
  resolve: (name) => {
18
18
  return resolvePageComponent(
19
19
  {{ '`./pages/${name}.tsx`' }},
20
- import.meta.glob<DefineComponent>('./pages/**/*.tsx'),
20
+ import.meta.glob('./pages/**/*.tsx'),
21
21
  )
22
22
  },
23
23
 
@@ -13,7 +13,7 @@ export default function Home(props: { version: number }) {
13
13
 
14
14
  <span>
15
15
  Learn more about AdonisJS and Inertia.js by visiting the{' '}
16
- <a href="https://docs.adonisjs.com/inertia">AdonisJS documentation</a>.
16
+ <a href="https://docs.adonisjs.com/guides/inertia">AdonisJS documentation</a>.
17
17
  </span>
18
18
  </div>
19
19
  </>
@@ -10,8 +10,8 @@
10
10
 
11
11
  <title inertia>AdonisJS x Inertia x SolidJS</title>
12
12
 
13
- {{ "@vite(['resources/app.tsx', `resources/pages/${page.component}.tsx`])" }}
14
13
  @inertiaHead()
14
+ {{ "@vite(['resources/app.tsx', `resources/pages/${page.component}.tsx`])" }}
15
15
  </head>
16
16
 
17
17
  <body>
@@ -1,8 +1,6 @@
1
1
  import { Vite } from '@adonisjs/vite';
2
2
  import { HttpContext } from '@adonisjs/core/http';
3
3
  import { NextFn } from '@adonisjs/core/types/http';
4
- import { ViteDevServer } from 'vite';
5
- import { ViteRuntime } from 'vite/runtime';
6
4
  import { ResolvedConfig, Data, PageProps, PageObject, MaybePromise } from './types.js';
7
5
 
8
6
  /**
@@ -16,9 +14,8 @@ declare class Inertia {
16
14
  #private;
17
15
  protected ctx: HttpContext;
18
16
  protected config: ResolvedConfig;
19
- protected viteRuntime?: ViteRuntime | undefined;
20
- protected viteDevServer?: ViteDevServer | undefined;
21
- constructor(ctx: HttpContext, config: ResolvedConfig, viteRuntime?: ViteRuntime | undefined, viteDevServer?: ViteDevServer | undefined);
17
+ protected vite?: Vite | undefined;
18
+ constructor(ctx: HttpContext, config: ResolvedConfig, vite?: Vite | undefined);
22
19
  /**
23
20
  * Share data for the current request.
24
21
  * This data will override any shared data defined in the config.
@@ -61,7 +58,6 @@ declare module '@adonisjs/core/http' {
61
58
  * set appropriate headers/status
62
59
  */
63
60
  declare class InertiaMiddleware {
64
- #private;
65
61
  protected config: ResolvedConfig;
66
62
  protected vite?: Vite | undefined;
67
63
  constructor(config: ResolvedConfig, vite?: Vite | undefined);
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  InertiaMiddleware
3
- } from "../chunk-WJOEJN5R.js";
3
+ } from "../chunk-7ZZGYDYU.js";
4
4
  export {
5
5
  InertiaMiddleware as default
6
6
  };
@@ -0,0 +1,26 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/app.ts') })
3
+ }}}
4
+ import './css/app.css';
5
+
6
+ import { createInertiaApp } from '@inertiajs/svelte'
7
+ import { resolvePageComponent } from '@adonisjs/inertia/helpers'
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
+ return resolvePageComponent(
18
+ {{ '`./pages/${name}.svelte`' }},
19
+ import.meta.glob('./pages/**/*.svelte'),
20
+ )
21
+ },
22
+
23
+ setup({ el, App, props }) {
24
+ new App({ target: el, props })
25
+ },
26
+ })
@@ -0,0 +1,19 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/pages/home.svelte') })
3
+ }}}
4
+ <script>
5
+ export let version: number
6
+ </script>
7
+
8
+ <svelte:head>
9
+ <title>Homepage</title>
10
+ </svelte:head>
11
+
12
+ <div className="container">
13
+ <div className="title">AdonisJS \{ version \} x Inertia x Svelte</div>
14
+
15
+ <span>
16
+ Learn more about AdonisJS and Inertia.js by visiting the
17
+ <a href="https://docs.adonisjs.com/guides/inertia">AdonisJS documentation</a>.
18
+ </span>
19
+ </div>
@@ -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 Svelte</title>
12
+
13
+ {{ "@vite(['resources/app.ts', `resources/pages/${page.component}.svelte`])" }}
14
+ @inertiaHead()
15
+ </head>
16
+
17
+ <body>
18
+ @inertia()
19
+ </body>
20
+
21
+ </html>
@@ -0,0 +1,15 @@
1
+ {{{
2
+ exports({ to: app.makePath('resources/ssr.ts') })
3
+ }}}
4
+
5
+ import { createInertiaApp } from '@inertiajs/svelte'
6
+
7
+ export default function render(page: any) {
8
+ return createInertiaApp({
9
+ page,
10
+ resolve: (name) => {
11
+ const pages = import.meta.glob('./pages/**/*.svelte', { eager: true })
12
+ {{ 'return pages[`./pages/${name}.svelte`]' }}
13
+ }
14
+ })
15
+ }
@@ -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", "./**/*.svelte"],
26
+ }
@@ -10,12 +10,12 @@ defineProps<{ version: number }>()
10
10
  <template>
11
11
  <Head title="Homepage" />
12
12
 
13
- <div className="container">
14
- <div className="title">AdonisJS \{\{ version \}\} x Inertia x Vue.js</div>
13
+ <div class="container">
14
+ <div class="title">AdonisJS \{\{ version \}\} x Inertia x Vue.js</div>
15
15
 
16
16
  <span>
17
17
  Learn more about AdonisJS and Inertia.js by visiting the
18
- <a href="https://docs.adonisjs.com/inertia">AdonisJS documentation</a>.
18
+ <a href="https://docs.adonisjs.com/guides/inertia">AdonisJS documentation</a>.
19
19
  </span>
20
20
  </div>
21
21
  </template>
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-13",
4
+ "version": "1.0.0-15",
5
5
  "engines": {
6
6
  "node": ">=18.16.0"
7
7
  },
@@ -44,7 +44,7 @@
44
44
  "@adonisjs/prettier-config": "^1.2.2",
45
45
  "@adonisjs/session": "7.1.1",
46
46
  "@adonisjs/tsconfig": "^1.2.2",
47
- "@adonisjs/vite": "^3.0.0-4",
47
+ "@adonisjs/vite": "^3.0.0-6",
48
48
  "@japa/api-client": "^2.0.2",
49
49
  "@japa/assert": "2.1.0",
50
50
  "@japa/expect-type": "^2.0.1",
@@ -84,7 +84,7 @@
84
84
  "peerDependencies": {
85
85
  "@adonisjs/core": "^6.2.0",
86
86
  "@adonisjs/session": "^7.0.0",
87
- "@adonisjs/vite": "^3.0.0-4",
87
+ "@adonisjs/vite": "^3.0.0-6",
88
88
  "@japa/api-client": "^2.0.0",
89
89
  "edge.js": "^6.0.0"
90
90
  },