@adonisjs/inertia 4.0.0-next.0 → 4.0.0-next.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.
- package/README.md +8 -5
- package/build/bin/test.d.ts +1 -0
- package/build/chunk-4EZ2J6OA.js +7 -0
- package/build/chunk-5QRJHXXQ.js +91 -0
- package/build/chunk-DISC5OYC.js +46 -0
- package/build/chunk-MLKGABMK.js +9 -0
- package/build/chunk-YQ72YL64.js +813 -0
- package/build/factories/inertia_factory.d.ts +137 -0
- package/build/factories/main.d.ts +1 -0
- package/build/factories/main.js +175 -0
- package/build/index.d.ts +7 -19
- package/build/index.js +21 -307
- package/build/providers/inertia_provider.d.ts +86 -13
- package/build/providers/inertia_provider.js +48 -18
- package/build/src/client/helpers.d.ts +27 -0
- package/build/src/client/helpers.js +30 -0
- package/build/src/client/react/context.d.ts +24 -0
- package/build/src/client/react/index.d.ts +3 -0
- package/build/src/client/react/index.js +72 -0
- package/build/src/client/react/link.d.ts +64 -0
- package/build/src/client/react/router.d.ts +33 -0
- package/build/src/client/vite.d.ts +65 -0
- package/build/src/{plugins → client}/vite.js +6 -2
- package/build/src/debug.d.ts +22 -0
- package/build/src/define_config.d.ts +30 -0
- package/build/src/headers.d.ts +61 -0
- package/build/src/index_pages.d.ts +32 -0
- package/build/src/inertia.d.ts +261 -0
- package/build/src/inertia_manager.d.ts +47 -0
- package/build/src/inertia_middleware.d.ts +76 -86
- package/build/src/inertia_middleware.js +110 -3
- package/build/src/plugins/edge/plugin.d.ts +30 -6
- package/build/src/plugins/edge/plugin.js +13 -9
- package/build/src/plugins/edge/tags.d.ts +47 -0
- package/build/src/plugins/edge/utils.d.ts +26 -0
- package/build/src/plugins/japa/api_client.d.ts +136 -22
- package/build/src/plugins/japa/api_client.js +36 -48
- package/build/src/props.d.ts +276 -0
- package/build/src/server_renderer.d.ts +54 -0
- package/build/src/symbols.d.ts +25 -0
- package/build/src/types.d.ts +400 -4
- package/build/tests/helpers.d.ts +35 -0
- package/build/tests/index_pages.spec.d.ts +1 -0
- package/build/tests/inertia.spec.d.ts +1 -0
- package/build/tests/inertia_page.spec.d.ts +1 -0
- package/build/tests/middleware.spec.d.ts +1 -0
- package/build/tests/plugins/api_client.spec.d.ts +1 -0
- package/build/tests/plugins/edge.plugin.spec.d.ts +1 -0
- package/build/tests/provider.spec.d.ts +1 -0
- package/build/tests/types/react.spec.d.ts +65 -0
- package/build/tests/types/shared_props.spec.d.ts +1 -0
- package/build/tests/types/to_component_props.spec.d.ts +1 -0
- package/build/tests/types/to_page_props.spec.d.ts +1 -0
- package/package.json +99 -71
- package/build/app.css.stub +0 -13
- package/build/chunk-AWCR2NAY.js +0 -412
- package/build/config.stub +0 -33
- package/build/react/app.tsx.stub +0 -38
- package/build/react/errors/not_found.tsx.stub +0 -14
- package/build/react/errors/server_error.tsx.stub +0 -14
- package/build/react/home.tsx.stub +0 -349
- package/build/react/root.edge.stub +0 -76
- package/build/react/ssr.tsx.stub +0 -17
- package/build/react/tsconfig.json.stub +0 -15
- package/build/solid/app.tsx.stub +0 -38
- package/build/solid/errors/not_found.tsx.stub +0 -14
- package/build/solid/errors/server_error.tsx.stub +0 -14
- package/build/solid/home.tsx.stub +0 -358
- package/build/solid/root.edge.stub +0 -73
- package/build/solid/ssr.tsx.stub +0 -19
- package/build/solid/tsconfig.json.stub +0 -16
- package/build/src/helpers.d.ts +0 -12
- package/build/src/helpers.js +0 -14
- package/build/src/plugins/vite.d.ts +0 -26
- package/build/svelte/app.ts.stub +0 -32
- package/build/svelte/errors/not_found.svelte.stub +0 -10
- package/build/svelte/errors/server_error.svelte.stub +0 -14
- package/build/svelte/home.svelte.stub +0 -339
- package/build/svelte/root.edge.stub +0 -75
- package/build/svelte/ssr.ts.stub +0 -19
- package/build/svelte/tsconfig.json.stub +0 -14
- package/build/types-DVqEHBD1.d.ts +0 -240
- package/build/vue/app.ts.stub +0 -41
- package/build/vue/errors/not_found.vue.stub +0 -10
- package/build/vue/errors/server_error.vue.stub +0 -14
- package/build/vue/home.vue.stub +0 -343
- package/build/vue/root.edge.stub +0 -75
- package/build/vue/ssr.ts.stub +0 -22
- package/build/vue/tsconfig.json.stub +0 -16
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { type Vite } from '@adonisjs/vite';
|
|
2
|
+
import { type HttpContext } from '@adonisjs/core/http';
|
|
3
|
+
import { Inertia } from '../src/inertia.js';
|
|
4
|
+
import { type AssetsVersion, type InertiaConfig, type ComponentProps, type InertiaConfigInput } from '../src/types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Parameters for configuring the Inertia factory
|
|
7
|
+
*/
|
|
8
|
+
type FactoryParameters = {
|
|
9
|
+
/** HTTP context for the request */
|
|
10
|
+
ctx: HttpContext;
|
|
11
|
+
/** Inertia configuration object */
|
|
12
|
+
config: InertiaConfig;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Inertia factory to quickly create a new instance of Inertia
|
|
16
|
+
* for testing purposes
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const factory = new InertiaFactory()
|
|
21
|
+
* const inertia = factory
|
|
22
|
+
* .merge({ config: { ssr: { enabled: true } } })
|
|
23
|
+
* .withVersion('1.0.0')
|
|
24
|
+
* .create()
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare class InertiaFactory<Pages extends Record<string, ComponentProps>> {
|
|
28
|
+
#private;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new InertiaFactory instance with default Inertia headers
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const factory = new InertiaFactory()
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
constructor();
|
|
38
|
+
/**
|
|
39
|
+
* Merges additional parameters into the factory configuration
|
|
40
|
+
*
|
|
41
|
+
* @param parameters - Partial factory parameters to merge
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* factory.merge({
|
|
46
|
+
* config: { ssr: { enabled: true } },
|
|
47
|
+
* ctx: customContext
|
|
48
|
+
* })
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
merge(parameters: Omit<Partial<FactoryParameters>, 'config'> & {
|
|
52
|
+
config?: InertiaConfigInput;
|
|
53
|
+
}): this;
|
|
54
|
+
/**
|
|
55
|
+
* Removes the X-Inertia header from the request headers
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const inertia = factory.withoutInertia().create()
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
withoutInertia(): this;
|
|
63
|
+
/**
|
|
64
|
+
* Configures the factory for partial reloads of a specific component
|
|
65
|
+
*
|
|
66
|
+
* @param component - Name of the component to partially reload
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const inertia = factory
|
|
71
|
+
* .partialReload('UserProfile')
|
|
72
|
+
* .only(['name', 'email'])
|
|
73
|
+
* .create()
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
partialReload<Page extends keyof Pages & string>(component: Page): {
|
|
77
|
+
/**
|
|
78
|
+
* Specifies which props to include in the partial reload
|
|
79
|
+
*
|
|
80
|
+
* @param props - Array of property names to include
|
|
81
|
+
*/
|
|
82
|
+
only(props: string[]): /*elided*/ any;
|
|
83
|
+
/**
|
|
84
|
+
* Specifies which props to exclude from the partial reload
|
|
85
|
+
*
|
|
86
|
+
* @param props - Array of property names to exclude
|
|
87
|
+
*/
|
|
88
|
+
except(props: string[]): /*elided*/ any;
|
|
89
|
+
/**
|
|
90
|
+
* Specifies which props should be reset during the partial reload
|
|
91
|
+
*
|
|
92
|
+
* @param props - Array of property names to reset
|
|
93
|
+
*/
|
|
94
|
+
reset(props: string[]): /*elided*/ any;
|
|
95
|
+
/**
|
|
96
|
+
* Creates the Inertia instance with partial reload configuration
|
|
97
|
+
*/
|
|
98
|
+
create(): Inertia<Pages>;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Sets the assets version for cache busting
|
|
102
|
+
*
|
|
103
|
+
* @param version - Version string or function for asset versioning
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* factory.withVersion('1.0.0')
|
|
108
|
+
* // or
|
|
109
|
+
* factory.withVersion(() => Date.now().toString())
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
withVersion(version: AssetsVersion): this;
|
|
113
|
+
/**
|
|
114
|
+
* Sets the Vite instance for asset handling
|
|
115
|
+
*
|
|
116
|
+
* @param options - Vite configuration object
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* factory.withVite(viteInstance)
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
withVite(options: Vite): this;
|
|
124
|
+
/**
|
|
125
|
+
* Creates a new Inertia instance with the configured parameters
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* const inertia = factory
|
|
130
|
+
* .merge({ config: customConfig })
|
|
131
|
+
* .withVersion('1.0.0')
|
|
132
|
+
* .create()
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
create(): Inertia<Pages>;
|
|
136
|
+
}
|
|
137
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { InertiaFactory } from './inertia_factory.ts';
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineConfig
|
|
3
|
+
} from "../chunk-5QRJHXXQ.js";
|
|
4
|
+
import {
|
|
5
|
+
Inertia,
|
|
6
|
+
ServerRenderer
|
|
7
|
+
} from "../chunk-YQ72YL64.js";
|
|
8
|
+
import "../chunk-4EZ2J6OA.js";
|
|
9
|
+
import {
|
|
10
|
+
InertiaHeaders
|
|
11
|
+
} from "../chunk-DISC5OYC.js";
|
|
12
|
+
import "../chunk-MLKGABMK.js";
|
|
13
|
+
|
|
14
|
+
// factories/inertia_factory.ts
|
|
15
|
+
import { HttpContextFactory } from "@adonisjs/core/factories/http";
|
|
16
|
+
var InertiaFactory = class {
|
|
17
|
+
/** Optional Vite instance for asset handling */
|
|
18
|
+
#vite;
|
|
19
|
+
/** Internal parameters for factory configuration */
|
|
20
|
+
#parameters = {
|
|
21
|
+
ctx: new HttpContextFactory().create(),
|
|
22
|
+
config: defineConfig({})
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new InertiaFactory instance with default Inertia headers
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const factory = new InertiaFactory()
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
constructor() {
|
|
33
|
+
this.#parameters.ctx.request.request.headers[InertiaHeaders.Inertia] = "true";
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Merges additional parameters into the factory configuration
|
|
37
|
+
*
|
|
38
|
+
* @param parameters - Partial factory parameters to merge
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* factory.merge({
|
|
43
|
+
* config: { ssr: { enabled: true } },
|
|
44
|
+
* ctx: customContext
|
|
45
|
+
* })
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
merge(parameters) {
|
|
49
|
+
if (parameters.ctx) {
|
|
50
|
+
this.#parameters.ctx = parameters.ctx;
|
|
51
|
+
}
|
|
52
|
+
if (parameters.config) {
|
|
53
|
+
this.#parameters.config = defineConfig(parameters.config);
|
|
54
|
+
}
|
|
55
|
+
this.#parameters.ctx.request.request.headers[InertiaHeaders.Inertia] = "true";
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Removes the X-Inertia header from the request headers
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const inertia = factory.withoutInertia().create()
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
withoutInertia() {
|
|
67
|
+
delete this.#parameters.ctx.request.request.headers[InertiaHeaders.Inertia];
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Configures the factory for partial reloads of a specific component
|
|
72
|
+
*
|
|
73
|
+
* @param component - Name of the component to partially reload
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const inertia = factory
|
|
78
|
+
* .partialReload('UserProfile')
|
|
79
|
+
* .only(['name', 'email'])
|
|
80
|
+
* .create()
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
partialReload(component) {
|
|
84
|
+
const self = this;
|
|
85
|
+
const request = this.#parameters.ctx.request;
|
|
86
|
+
request.request.headers[InertiaHeaders.PartialComponent] = component;
|
|
87
|
+
return {
|
|
88
|
+
/**
|
|
89
|
+
* Specifies which props to include in the partial reload
|
|
90
|
+
*
|
|
91
|
+
* @param props - Array of property names to include
|
|
92
|
+
*/
|
|
93
|
+
only(props) {
|
|
94
|
+
request.request.headers[InertiaHeaders.PartialOnly] = props.join(",");
|
|
95
|
+
return this;
|
|
96
|
+
},
|
|
97
|
+
/**
|
|
98
|
+
* Specifies which props to exclude from the partial reload
|
|
99
|
+
*
|
|
100
|
+
* @param props - Array of property names to exclude
|
|
101
|
+
*/
|
|
102
|
+
except(props) {
|
|
103
|
+
request.request.headers[InertiaHeaders.PartialExcept] = props.join(",");
|
|
104
|
+
return this;
|
|
105
|
+
},
|
|
106
|
+
/**
|
|
107
|
+
* Specifies which props should be reset during the partial reload
|
|
108
|
+
*
|
|
109
|
+
* @param props - Array of property names to reset
|
|
110
|
+
*/
|
|
111
|
+
reset(props) {
|
|
112
|
+
request.request.headers[InertiaHeaders.Reset] = props.join(",");
|
|
113
|
+
return this;
|
|
114
|
+
},
|
|
115
|
+
/**
|
|
116
|
+
* Creates the Inertia instance with partial reload configuration
|
|
117
|
+
*/
|
|
118
|
+
create() {
|
|
119
|
+
return self.create();
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Sets the assets version for cache busting
|
|
125
|
+
*
|
|
126
|
+
* @param version - Version string or function for asset versioning
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* factory.withVersion('1.0.0')
|
|
131
|
+
* // or
|
|
132
|
+
* factory.withVersion(() => Date.now().toString())
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
withVersion(version) {
|
|
136
|
+
this.#parameters.config = { ...this.#parameters.config, assetsVersion: version };
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Sets the Vite instance for asset handling
|
|
141
|
+
*
|
|
142
|
+
* @param options - Vite configuration object
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* factory.withVite(viteInstance)
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
withVite(options) {
|
|
150
|
+
this.#vite = options;
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Creates a new Inertia instance with the configured parameters
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* const inertia = factory
|
|
159
|
+
* .merge({ config: customConfig })
|
|
160
|
+
* .withVersion('1.0.0')
|
|
161
|
+
* .create()
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
create() {
|
|
165
|
+
return new Inertia(
|
|
166
|
+
this.#parameters.ctx,
|
|
167
|
+
this.#parameters.config,
|
|
168
|
+
this.#vite,
|
|
169
|
+
this.#vite ? new ServerRenderer(this.#parameters.config, this.#vite) : void 0
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
export {
|
|
174
|
+
InertiaFactory
|
|
175
|
+
};
|
package/build/index.d.ts
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* Configures the package
|
|
9
|
-
*/
|
|
10
|
-
declare function configure(command: Configure): Promise<void>;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Define the Inertia configuration
|
|
14
|
-
*/
|
|
15
|
-
declare function defineConfig<T extends SharedData>(config: InertiaConfig<T>): ConfigProvider<ResolvedConfig<T>>;
|
|
16
|
-
|
|
17
|
-
declare const stubsRoot: string;
|
|
18
|
-
|
|
19
|
-
export { configure, defineConfig, stubsRoot };
|
|
1
|
+
export { Inertia } from './src/inertia.ts';
|
|
2
|
+
export * as symbols from './src/symbols.ts';
|
|
3
|
+
export { InertiaHeaders } from './src/headers.ts';
|
|
4
|
+
export { indexPages } from './src/index_pages.ts';
|
|
5
|
+
export { defineConfig } from './src/define_config.js';
|
|
6
|
+
export { InertiaManager } from './src/inertia_manager.ts';
|
|
7
|
+
export { ServerRenderer } from './src/server_renderer.ts';
|
package/build/index.js
CHANGED
|
@@ -1,310 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
{ name: "@inertiajs/vue3", isDevDependency: false },
|
|
17
|
-
{ name: "vue", isDevDependency: false },
|
|
18
|
-
{ name: "@vitejs/plugin-vue", isDevDependency: true }
|
|
19
|
-
],
|
|
20
|
-
ssrDependencies: [{ name: "@vue/server-renderer", isDevDependency: false }],
|
|
21
|
-
viteRegister: {
|
|
22
|
-
pluginCall: "vue()",
|
|
23
|
-
importDeclarations: [{ isNamed: false, module: "@vitejs/plugin-vue", identifier: "vue" }]
|
|
24
|
-
},
|
|
25
|
-
ssrEntrypoint: "inertia/app/ssr.ts"
|
|
26
|
-
},
|
|
27
|
-
react: {
|
|
28
|
-
stubFolder: "react",
|
|
29
|
-
appExtension: "tsx",
|
|
30
|
-
componentsExtension: "tsx",
|
|
31
|
-
dependencies: [
|
|
32
|
-
{ name: "@inertiajs/react", isDevDependency: false },
|
|
33
|
-
{ name: "react", isDevDependency: false },
|
|
34
|
-
{ name: "react-dom", isDevDependency: false },
|
|
35
|
-
{ name: "@vitejs/plugin-react", isDevDependency: true },
|
|
36
|
-
{ name: "@types/react", isDevDependency: true },
|
|
37
|
-
{ name: "@types/react-dom", isDevDependency: true }
|
|
38
|
-
],
|
|
39
|
-
viteRegister: {
|
|
40
|
-
pluginCall: "react()",
|
|
41
|
-
importDeclarations: [{ isNamed: false, module: "@vitejs/plugin-react", identifier: "react" }]
|
|
42
|
-
},
|
|
43
|
-
ssrEntrypoint: "inertia/app/ssr.tsx"
|
|
44
|
-
},
|
|
45
|
-
svelte: {
|
|
46
|
-
stubFolder: "svelte",
|
|
47
|
-
appExtension: "ts",
|
|
48
|
-
componentsExtension: "svelte",
|
|
49
|
-
dependencies: [
|
|
50
|
-
{ name: "@inertiajs/svelte", isDevDependency: false },
|
|
51
|
-
{ name: "svelte", isDevDependency: false },
|
|
52
|
-
{ name: "@sveltejs/vite-plugin-svelte", isDevDependency: true }
|
|
53
|
-
],
|
|
54
|
-
viteRegister: {
|
|
55
|
-
pluginCall: "svelte()",
|
|
56
|
-
ssrPluginCall: "svelte({ compilerOptions: { hydratable: true } })",
|
|
57
|
-
importDeclarations: [
|
|
58
|
-
{ isNamed: true, module: "@sveltejs/vite-plugin-svelte", identifier: "svelte" }
|
|
59
|
-
]
|
|
60
|
-
},
|
|
61
|
-
ssrEntrypoint: "inertia/app/ssr.ts"
|
|
62
|
-
},
|
|
63
|
-
solid: {
|
|
64
|
-
stubFolder: "solid",
|
|
65
|
-
appExtension: "tsx",
|
|
66
|
-
componentsExtension: "tsx",
|
|
67
|
-
dependencies: [
|
|
68
|
-
{ name: "solid-js", isDevDependency: false },
|
|
69
|
-
{ name: "inertia-adapter-solid", isDevDependency: false },
|
|
70
|
-
{ name: "vite-plugin-solid", isDevDependency: true },
|
|
71
|
-
{ name: "@solidjs/meta", isDevDependency: false }
|
|
72
|
-
],
|
|
73
|
-
viteRegister: {
|
|
74
|
-
pluginCall: "solid()",
|
|
75
|
-
ssrPluginCall: "solid({ ssr: true })",
|
|
76
|
-
importDeclarations: [{ isNamed: false, module: "vite-plugin-solid", identifier: "solid" }]
|
|
77
|
-
},
|
|
78
|
-
ssrEntrypoint: "inertia/app/ssr.tsx"
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
async function defineExampleRoute(command, codemods) {
|
|
82
|
-
const tsMorph = await codemods.getTsMorphProject();
|
|
83
|
-
const routesFile = tsMorph?.getSourceFile(command.app.makePath("./start/routes.ts"));
|
|
84
|
-
if (!routesFile) {
|
|
85
|
-
return command.logger.warning("Unable to find the routes file");
|
|
86
|
-
}
|
|
87
|
-
const action = command.logger.action("update start/routes.ts file");
|
|
88
|
-
try {
|
|
89
|
-
routesFile?.addStatements((writer) => {
|
|
90
|
-
writer.writeLine(`router.on('/').renderInertia('home')`);
|
|
91
|
-
});
|
|
92
|
-
await tsMorph?.save();
|
|
93
|
-
action.succeeded();
|
|
94
|
-
} catch (error) {
|
|
95
|
-
codemods.emit("error", error);
|
|
96
|
-
action.failed(error.message);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
async function configure(command) {
|
|
100
|
-
let adapter = command.parsedFlags.adapter;
|
|
101
|
-
let ssr = command.parsedFlags.ssr;
|
|
102
|
-
let shouldInstallPackages = command.parsedFlags.install;
|
|
103
|
-
let shouldSkipExampleRoute = command.parsedFlags["skip-example-route"];
|
|
104
|
-
if (adapter === void 0) {
|
|
105
|
-
adapter = await command.prompt.choice(
|
|
106
|
-
"Select the Inertia adapter you want to use",
|
|
107
|
-
ADAPTERS.map((adapterName) => string.capitalCase(adapterName)),
|
|
108
|
-
{ name: "adapter", result: (value) => value.toLowerCase() }
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
if (ssr === void 0) {
|
|
112
|
-
ssr = await command.prompt.confirm("Do you want to use server-side rendering?", {
|
|
113
|
-
name: "ssr"
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
if (adapter in ADAPTERS_INFO === false) {
|
|
117
|
-
command.logger.error(
|
|
118
|
-
`The selected adapter "${adapter}" is invalid. Select one from: ${string.sentence(
|
|
119
|
-
Object.keys(ADAPTERS_INFO)
|
|
120
|
-
)}`
|
|
121
|
-
);
|
|
122
|
-
command.exitCode = 1;
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const adapterInfo = ADAPTERS_INFO[adapter];
|
|
126
|
-
const codemods = await command.createCodemods();
|
|
127
|
-
await codemods.updateRcFile((rcFile) => {
|
|
128
|
-
rcFile.addProvider("@adonisjs/inertia/inertia_provider");
|
|
129
|
-
});
|
|
130
|
-
await codemods.registerMiddleware("server", [
|
|
131
|
-
{ path: "@adonisjs/inertia/inertia_middleware", position: "after" }
|
|
132
|
-
]);
|
|
133
|
-
const appExt = adapterInfo.appExtension;
|
|
134
|
-
const stubFolder = adapterInfo.stubFolder;
|
|
135
|
-
const compExt = adapterInfo.componentsExtension;
|
|
136
|
-
await codemods.makeUsingStub(stubsRoot, "config.stub", {
|
|
137
|
-
ssr,
|
|
138
|
-
ssrEntrypoint: adapterInfo.ssrEntrypoint
|
|
139
|
-
});
|
|
140
|
-
await codemods.makeUsingStub(stubsRoot, `app.css.stub`, {});
|
|
141
|
-
await codemods.makeUsingStub(stubsRoot, `${stubFolder}/root.edge.stub`, {});
|
|
142
|
-
await codemods.makeUsingStub(stubsRoot, `${stubFolder}/tsconfig.json.stub`, {});
|
|
143
|
-
await codemods.makeUsingStub(stubsRoot, `${stubFolder}/app.${appExt}.stub`, { ssr });
|
|
144
|
-
await codemods.makeUsingStub(stubsRoot, `${stubFolder}/home.${compExt}.stub`, {});
|
|
145
|
-
await codemods.makeUsingStub(stubsRoot, `${stubFolder}/errors/not_found.${compExt}.stub`, {});
|
|
146
|
-
await codemods.makeUsingStub(stubsRoot, `${stubFolder}/errors/server_error.${compExt}.stub`, {});
|
|
147
|
-
if (ssr) {
|
|
148
|
-
await codemods.makeUsingStub(stubsRoot, `${stubFolder}/ssr.${appExt}.stub`, {});
|
|
149
|
-
}
|
|
150
|
-
const inertiaPluginCall = ssr ? `inertia({ ssr: { enabled: true, entrypoint: 'inertia/app/ssr.${appExt}' } })` : `inertia({ ssr: { enabled: false } })`;
|
|
151
|
-
await codemods.registerVitePlugin(inertiaPluginCall, [
|
|
152
|
-
{ isNamed: false, module: "@adonisjs/inertia/client", identifier: "inertia" }
|
|
153
|
-
]);
|
|
154
|
-
await codemods.registerVitePlugin(
|
|
155
|
-
ssr && adapterInfo.viteRegister.ssrPluginCall ? adapterInfo.viteRegister.ssrPluginCall : adapterInfo.viteRegister.pluginCall,
|
|
156
|
-
adapterInfo.viteRegister.importDeclarations
|
|
157
|
-
);
|
|
158
|
-
const adonisjsPluginCall = `adonisjs({ entrypoints: ['inertia/app/app.${appExt}'], reload: ['resources/views/**/*.edge'] })`;
|
|
159
|
-
await codemods.registerVitePlugin(adonisjsPluginCall, [
|
|
160
|
-
{ isNamed: false, module: "@adonisjs/vite/client", identifier: "adonisjs" }
|
|
161
|
-
]);
|
|
162
|
-
if (shouldSkipExampleRoute !== true) {
|
|
163
|
-
await defineExampleRoute(command, codemods);
|
|
164
|
-
}
|
|
165
|
-
const pkgToInstall = adapterInfo.dependencies;
|
|
166
|
-
if (ssr && adapterInfo.ssrDependencies) {
|
|
167
|
-
pkgToInstall.push(...adapterInfo.ssrDependencies);
|
|
168
|
-
}
|
|
169
|
-
if (shouldInstallPackages === void 0) {
|
|
170
|
-
shouldInstallPackages = await command.prompt.confirm(
|
|
171
|
-
`Do you want to install dependencies ${pkgToInstall.map((pkg) => pkg.name).join(", ")}?`,
|
|
172
|
-
{ name: "install" }
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
if (shouldInstallPackages) {
|
|
176
|
-
await codemods.installPackages(pkgToInstall);
|
|
177
|
-
} else {
|
|
178
|
-
await codemods.listPackagesToInstall(pkgToInstall);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// src/define_config.ts
|
|
183
|
-
import { slash } from "@poppinss/utils";
|
|
184
|
-
import { configProvider } from "@adonisjs/core";
|
|
185
|
-
|
|
186
|
-
// src/version_cache.ts
|
|
187
|
-
import { createHash } from "crypto";
|
|
188
|
-
import { readFile } from "fs/promises";
|
|
189
|
-
var VersionCache = class {
|
|
190
|
-
constructor(appRoot, assetsVersion) {
|
|
191
|
-
this.appRoot = appRoot;
|
|
192
|
-
this.assetsVersion = assetsVersion;
|
|
193
|
-
this.#cachedVersion = assetsVersion;
|
|
194
|
-
}
|
|
195
|
-
#cachedVersion;
|
|
196
|
-
/**
|
|
197
|
-
* Compute the hash of the manifest file and cache it
|
|
198
|
-
*/
|
|
199
|
-
async #getManifestHash() {
|
|
200
|
-
try {
|
|
201
|
-
const manifestPath = new URL("public/assets/.vite/manifest.json", this.appRoot);
|
|
202
|
-
const manifestFile = await readFile(manifestPath, "utf-8");
|
|
203
|
-
this.#cachedVersion = createHash("md5").update(manifestFile).digest("hex");
|
|
204
|
-
return this.#cachedVersion;
|
|
205
|
-
} catch {
|
|
206
|
-
this.#cachedVersion = "1";
|
|
207
|
-
return this.#cachedVersion;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Pre-compute the version
|
|
212
|
-
*/
|
|
213
|
-
async computeVersion() {
|
|
214
|
-
if (!this.assetsVersion) await this.#getManifestHash();
|
|
215
|
-
return this;
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Returns the current assets version
|
|
219
|
-
*/
|
|
220
|
-
getVersion() {
|
|
221
|
-
if (!this.#cachedVersion) throw new Error("Version has not been computed yet");
|
|
222
|
-
return this.#cachedVersion;
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Set the assets version
|
|
226
|
-
*/
|
|
227
|
-
async setVersion(version) {
|
|
228
|
-
this.#cachedVersion = version;
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
// src/files_detector.ts
|
|
233
|
-
import { locatePath } from "locate-path";
|
|
234
|
-
var FilesDetector = class {
|
|
235
|
-
constructor(app) {
|
|
236
|
-
this.app = app;
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Try to locate the entrypoint file based
|
|
240
|
-
* on the conventional locations
|
|
241
|
-
*/
|
|
242
|
-
async detectEntrypoint(defaultPath) {
|
|
243
|
-
const possiblesLocations = [
|
|
244
|
-
"./inertia/app/app.ts",
|
|
245
|
-
"./inertia/app/app.tsx",
|
|
246
|
-
"./resources/app.ts",
|
|
247
|
-
"./resources/app.tsx",
|
|
248
|
-
"./resources/app.jsx",
|
|
249
|
-
"./resources/app.js",
|
|
250
|
-
"./inertia/app/app.jsx"
|
|
251
|
-
];
|
|
252
|
-
const path = await locatePath(possiblesLocations, { cwd: this.app.appRoot });
|
|
253
|
-
return this.app.makePath(path || defaultPath);
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Try to locate the SSR entrypoint file based
|
|
257
|
-
* on the conventional locations
|
|
258
|
-
*/
|
|
259
|
-
async detectSsrEntrypoint(defaultPath) {
|
|
260
|
-
const possiblesLocations = [
|
|
261
|
-
"./inertia/app/ssr.ts",
|
|
262
|
-
"./inertia/app/ssr.tsx",
|
|
263
|
-
"./resources/ssr.ts",
|
|
264
|
-
"./resources/ssr.tsx",
|
|
265
|
-
"./resources/ssr.jsx",
|
|
266
|
-
"./resources/ssr.js",
|
|
267
|
-
"./inertia/app/ssr.jsx"
|
|
268
|
-
];
|
|
269
|
-
const path = await locatePath(possiblesLocations, { cwd: this.app.appRoot });
|
|
270
|
-
return this.app.makePath(path || defaultPath);
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Try to locate the SSR bundle file based
|
|
274
|
-
* on the conventional locations
|
|
275
|
-
*/
|
|
276
|
-
async detectSsrBundle(defaultPath) {
|
|
277
|
-
const possiblesLocations = ["./ssr/ssr.js", "./ssr/ssr.mjs"];
|
|
278
|
-
const path = await locatePath(possiblesLocations, { cwd: this.app.appRoot });
|
|
279
|
-
return this.app.makePath(path || defaultPath);
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
// src/define_config.ts
|
|
284
|
-
function defineConfig(config) {
|
|
285
|
-
return configProvider.create(async (app) => {
|
|
286
|
-
const detector = new FilesDetector(app);
|
|
287
|
-
const versionCache = new VersionCache(app.appRoot, config.assetsVersion);
|
|
288
|
-
await versionCache.computeVersion();
|
|
289
|
-
return {
|
|
290
|
-
versionCache,
|
|
291
|
-
rootView: config.rootView ?? "inertia_layout",
|
|
292
|
-
sharedData: config.sharedData || {},
|
|
293
|
-
history: { encrypt: config.history?.encrypt ?? false },
|
|
294
|
-
entrypoint: slash(
|
|
295
|
-
config.entrypoint ?? await detector.detectEntrypoint("inertia/app/app.ts")
|
|
296
|
-
),
|
|
297
|
-
ssr: {
|
|
298
|
-
enabled: config.ssr?.enabled ?? false,
|
|
299
|
-
pages: config.ssr?.pages,
|
|
300
|
-
entrypoint: config.ssr?.entrypoint ?? await detector.detectSsrEntrypoint("inertia/app/ssr.ts"),
|
|
301
|
-
bundle: config.ssr?.bundle ?? await detector.detectSsrBundle("ssr/ssr.js")
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
});
|
|
305
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
defineConfig,
|
|
3
|
+
indexPages
|
|
4
|
+
} from "./chunk-5QRJHXXQ.js";
|
|
5
|
+
import {
|
|
6
|
+
Inertia,
|
|
7
|
+
InertiaManager,
|
|
8
|
+
ServerRenderer,
|
|
9
|
+
symbols_exports
|
|
10
|
+
} from "./chunk-YQ72YL64.js";
|
|
11
|
+
import "./chunk-4EZ2J6OA.js";
|
|
12
|
+
import {
|
|
13
|
+
InertiaHeaders
|
|
14
|
+
} from "./chunk-DISC5OYC.js";
|
|
15
|
+
import "./chunk-MLKGABMK.js";
|
|
306
16
|
export {
|
|
307
|
-
|
|
17
|
+
Inertia,
|
|
18
|
+
InertiaHeaders,
|
|
19
|
+
InertiaManager,
|
|
20
|
+
ServerRenderer,
|
|
308
21
|
defineConfig,
|
|
309
|
-
|
|
22
|
+
indexPages,
|
|
23
|
+
symbols_exports as symbols
|
|
310
24
|
};
|