@adonisjs/inertia 1.0.0-22 → 1.0.0-23
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
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
Official [Inertia.js](https://inertiajs.com/) adapter for AdonisJS.
|
|
9
9
|
|
|
10
10
|
## Official Documentation
|
|
11
|
-
The documentation is available on the [AdonisJS website](https://docs.adonisjs.com/guides/inertia/
|
|
11
|
+
The documentation is available on the [AdonisJS website](https://docs.adonisjs.com/guides/inertia/).
|
|
12
12
|
|
|
13
13
|
## Contributing
|
|
14
14
|
One of the primary goals of AdonisJS is to have a vibrant community of users and contributors who believes in the principles of the framework.
|
|
@@ -1,56 +1,9 @@
|
|
|
1
1
|
// src/server_renderer.ts
|
|
2
|
-
var styleFileRE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\?)/;
|
|
3
2
|
var ServerRenderer = class {
|
|
4
3
|
constructor(config, vite) {
|
|
5
4
|
this.config = config;
|
|
6
5
|
this.vite = vite;
|
|
7
6
|
}
|
|
8
|
-
/**
|
|
9
|
-
* If the module is a style module
|
|
10
|
-
*/
|
|
11
|
-
#isStyle(mod) {
|
|
12
|
-
if (styleFileRE.test(mod.url) || mod.id && /\?vue&type=style/.test(mod.id)) {
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Collect CSS files from the module graph recursively
|
|
19
|
-
*/
|
|
20
|
-
#collectCss(mod, styleUrls, visitedModules, importer) {
|
|
21
|
-
if (!mod.url)
|
|
22
|
-
return;
|
|
23
|
-
if (visitedModules.has(mod.url))
|
|
24
|
-
return;
|
|
25
|
-
visitedModules.add(mod.url);
|
|
26
|
-
if (this.#isStyle(mod) && (!importer || !this.#isStyle(importer))) {
|
|
27
|
-
if (mod.url.startsWith("/")) {
|
|
28
|
-
styleUrls.add(mod.url);
|
|
29
|
-
} else if (mod.url.startsWith("\0")) {
|
|
30
|
-
styleUrls.add(`/@id/__x00__${mod.url.substring(1)}`);
|
|
31
|
-
} else {
|
|
32
|
-
styleUrls.add(`/@id/${mod.url}`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
mod.importedModules.forEach((dep) => this.#collectCss(dep, styleUrls, visitedModules, mod));
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Generate the preload tag for a CSS file
|
|
39
|
-
*/
|
|
40
|
-
#getPreloadTag(href) {
|
|
41
|
-
return `<link rel="stylesheet" href="${href}" />`;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Find a page module from the entrypoint module
|
|
45
|
-
*
|
|
46
|
-
* The implementation is dumb, we are just looking for the first module
|
|
47
|
-
* imported by the entrypoint module that matches the regex
|
|
48
|
-
*/
|
|
49
|
-
#findPageModule(entryMod, pageObject) {
|
|
50
|
-
const pattern = `${pageObject.component.replace(/\//g, "\\/")}.(tsx|vue|svelte|jsx|ts|js)$`;
|
|
51
|
-
const regex = new RegExp(pattern);
|
|
52
|
-
return [...entryMod?.ssrImportedModules || []].find((dep) => regex.test(dep.url));
|
|
53
|
-
}
|
|
54
7
|
/**
|
|
55
8
|
* Render the page on the server
|
|
56
9
|
*
|
|
@@ -59,28 +12,15 @@ var ServerRenderer = class {
|
|
|
59
12
|
*/
|
|
60
13
|
async render(pageObject) {
|
|
61
14
|
let render;
|
|
62
|
-
let preloadTags = [];
|
|
63
15
|
const devServer = this.vite?.getDevServer();
|
|
64
16
|
if (devServer) {
|
|
65
17
|
const runtime = await this.vite.createRuntime();
|
|
66
18
|
render = await runtime.executeEntrypoint(this.config.ssr.entrypoint);
|
|
67
|
-
const entryMod = devServer.moduleGraph.getModuleById(this.config.entrypoint);
|
|
68
|
-
const pageMod = this.#findPageModule(entryMod, pageObject);
|
|
69
|
-
if (pageMod)
|
|
70
|
-
await runtime.executeUrl(pageMod.url);
|
|
71
|
-
const preloadUrls = /* @__PURE__ */ new Set();
|
|
72
|
-
const visitedModules = /* @__PURE__ */ new Set();
|
|
73
|
-
if (pageMod)
|
|
74
|
-
this.#collectCss(pageMod, preloadUrls, visitedModules);
|
|
75
|
-
if (entryMod)
|
|
76
|
-
this.#collectCss(entryMod, preloadUrls, visitedModules);
|
|
77
|
-
preloadTags = Array.from(preloadUrls).map(this.#getPreloadTag);
|
|
78
19
|
} else {
|
|
79
20
|
render = await import(this.config.ssr.bundle);
|
|
80
21
|
}
|
|
81
22
|
const result = await render.default(pageObject);
|
|
82
|
-
|
|
83
|
-
return { head, body: result.body };
|
|
23
|
+
return { head: [result.head], body: result.body };
|
|
84
24
|
}
|
|
85
25
|
};
|
|
86
26
|
|
package/build/src/types.d.ts
CHANGED
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-
|
|
4
|
+
"version": "1.0.0-23",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18.16.0"
|
|
7
7
|
},
|
|
@@ -53,7 +53,6 @@
|
|
|
53
53
|
"@japa/runner": "3.1.1",
|
|
54
54
|
"@japa/snapshot": "^2.0.4",
|
|
55
55
|
"@swc/core": "^1.4.8",
|
|
56
|
-
"@tuyau/utils": "^0.0.1",
|
|
57
56
|
"@types/node": "^20.11.30",
|
|
58
57
|
"@types/qs": "^6.9.14",
|
|
59
58
|
"@types/supertest": "^6.0.2",
|
|
@@ -80,6 +79,7 @@
|
|
|
80
79
|
"edge-error": "^4.0.1",
|
|
81
80
|
"html-entities": "^2.5.2",
|
|
82
81
|
"locate-path": "^7.2.0",
|
|
82
|
+
"@tuyau/utils": "^0.0.1",
|
|
83
83
|
"qs": "^6.11.2"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|