@stratal/inertia 0.0.1 → 0.0.19
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/dist/index.d.mts +265 -52
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +551 -177
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +83 -0
- package/dist/react.d.mts.map +1 -0
- package/dist/react.mjs +158 -0
- package/dist/react.mjs.map +1 -0
- package/dist/testing.d.mts +36 -0
- package/dist/testing.d.mts.map +1 -0
- package/dist/testing.mjs +78 -0
- package/dist/testing.mjs.map +1 -0
- package/dist/type-generator-C5JljyzK.mjs +391 -0
- package/dist/type-generator-C5JljyzK.mjs.map +1 -0
- package/dist/vite.d.mts +8 -1
- package/dist/vite.d.mts.map +1 -1
- package/dist/vite.mjs +152 -4
- package/dist/vite.mjs.map +1 -0
- package/package.json +47 -19
- package/dist/inertia-dev-css-plugin-BYromyO_.mjs +0 -70
- package/dist/inertia-dev-css-plugin-BYromyO_.mjs.map +0 -1
- package/dist/inertia-types-plugin-NO_uxhxQ.mjs +0 -39
- package/dist/inertia-types-plugin-NO_uxhxQ.mjs.map +0 -1
- package/dist/rolldown-runtime-wcPFST8Q.mjs +0 -13
- package/dist/type-generator-DlXIc6e2.mjs +0 -193
- package/dist/type-generator-DlXIc6e2.mjs.map +0 -1
package/dist/vite.mjs
CHANGED
|
@@ -1,4 +1,152 @@
|
|
|
1
|
-
import "./type-generator-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { n as runTypeGeneration, t as findPagesDir } from "./type-generator-C5JljyzK.mjs";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { join, relative } from "node:path";
|
|
4
|
+
//#region src/vite/inertia-dev-css-plugin.ts
|
|
5
|
+
const CSS_LANGS_RE = /\.(css|scss|sass|less|styl|stylus|pcss|postcss)(?:$|\?)/;
|
|
6
|
+
const VIRTUAL_MODULE_ID = "virtual:inertia-ssr.css";
|
|
7
|
+
const RESOLVED_VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID;
|
|
8
|
+
function collectStyleUrls(server, entries) {
|
|
9
|
+
const urls = [];
|
|
10
|
+
const visited = /* @__PURE__ */ new Set();
|
|
11
|
+
function traverse(mod) {
|
|
12
|
+
if (visited.has(mod.url)) return;
|
|
13
|
+
visited.add(mod.url);
|
|
14
|
+
if (CSS_LANGS_RE.test(mod.url)) urls.push(mod.url);
|
|
15
|
+
for (const imported of mod.importedModules) traverse(imported);
|
|
16
|
+
}
|
|
17
|
+
for (const entry of entries) {
|
|
18
|
+
const mod = server.moduleGraph.getModulesByFile(entry.startsWith("/") ? entry.slice(1) : entry);
|
|
19
|
+
if (mod) for (const m of mod) traverse(m);
|
|
20
|
+
const urlMod = server.moduleGraph.urlToModuleMap.get(entry);
|
|
21
|
+
if (urlMod) traverse(urlMod);
|
|
22
|
+
}
|
|
23
|
+
return urls;
|
|
24
|
+
}
|
|
25
|
+
async function collectStyle(server, entries) {
|
|
26
|
+
for (const entry of entries) try {
|
|
27
|
+
await server.transformRequest(entry);
|
|
28
|
+
} catch {}
|
|
29
|
+
const urls = collectStyleUrls(server, entries);
|
|
30
|
+
const styles = [];
|
|
31
|
+
for (const url of urls) try {
|
|
32
|
+
const separator = url.includes("?") ? "&" : "?";
|
|
33
|
+
const result = await server.transformRequest(url + separator + "direct");
|
|
34
|
+
if (result?.code) styles.push(result.code);
|
|
35
|
+
} catch {}
|
|
36
|
+
return styles.join("\n");
|
|
37
|
+
}
|
|
38
|
+
function stratalInertiaDevCss(options) {
|
|
39
|
+
let server;
|
|
40
|
+
return {
|
|
41
|
+
name: "stratal:inertia-dev-css",
|
|
42
|
+
apply: "serve",
|
|
43
|
+
resolveId(id) {
|
|
44
|
+
if (id === VIRTUAL_MODULE_ID) return RESOLVED_VIRTUAL_MODULE_ID;
|
|
45
|
+
},
|
|
46
|
+
async load(id) {
|
|
47
|
+
if (id === RESOLVED_VIRTUAL_MODULE_ID) return await collectStyle(server, options.entries);
|
|
48
|
+
},
|
|
49
|
+
configureServer(devServer) {
|
|
50
|
+
server = devServer;
|
|
51
|
+
server.middlewares.use((req, res, next) => {
|
|
52
|
+
if (new URL(req.url ?? "", "http://localhost").pathname !== "/__inertia/ssr-css") {
|
|
53
|
+
next();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
collectStyle(server, options.entries).then((css) => {
|
|
57
|
+
res.setHeader("Content-Type", "text/css");
|
|
58
|
+
res.setHeader("Cache-Control", "no-store");
|
|
59
|
+
res.end(css);
|
|
60
|
+
}).catch(() => {
|
|
61
|
+
res.statusCode = 500;
|
|
62
|
+
res.end("");
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/vite/inertia-types-plugin.ts
|
|
70
|
+
const INERTIA_CALL_PATTERN = /ctx\.inertia\(|\.share\(|ctx\.flash\(|ctx\.defer\(|ctx\.optional\(|ctx\.merge\(|ctx\.once\(|ctx\.always\(/;
|
|
71
|
+
function stratalInertiaTypes() {
|
|
72
|
+
let cwd;
|
|
73
|
+
let pagesDir;
|
|
74
|
+
let srcDir;
|
|
75
|
+
return {
|
|
76
|
+
name: "stratal:inertia-types",
|
|
77
|
+
configResolved(config) {
|
|
78
|
+
cwd = config.root;
|
|
79
|
+
pagesDir = findPagesDir(cwd) + "/";
|
|
80
|
+
srcDir = join(cwd, "src") + "/";
|
|
81
|
+
},
|
|
82
|
+
async buildStart() {
|
|
83
|
+
if (!existsSync(pagesDir)) return;
|
|
84
|
+
try {
|
|
85
|
+
await runTypeGeneration(cwd);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.warn("[stratal:inertia-types] Type generation failed during build:", error);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
async handleHotUpdate({ file }) {
|
|
91
|
+
if (!/\.(tsx|ts)$/.test(file)) return;
|
|
92
|
+
if (!!relative(srcDir, file).startsWith("..")) return;
|
|
93
|
+
if (!!relative(pagesDir, file).startsWith("..")) try {
|
|
94
|
+
const content = readFileSync(file, "utf-8");
|
|
95
|
+
if (!INERTIA_CALL_PATTERN.test(content)) return;
|
|
96
|
+
} catch {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
await runTypeGeneration(cwd);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.warn("[stratal:inertia-types] Type generation failed during HMR:", error);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/vite.ts
|
|
109
|
+
function stratalInertia(options) {
|
|
110
|
+
const entries = options?.entries ?? ["/src/inertia/app.tsx"];
|
|
111
|
+
const optimizeDepsExclude = [
|
|
112
|
+
"@cloudflare/vite-plugin",
|
|
113
|
+
"wrangler",
|
|
114
|
+
"blake3-wasm",
|
|
115
|
+
"@stratal/inertia"
|
|
116
|
+
];
|
|
117
|
+
const optimizeDepsInclude = [
|
|
118
|
+
"buffer",
|
|
119
|
+
"buffer/",
|
|
120
|
+
"base64-js",
|
|
121
|
+
"ieee754"
|
|
122
|
+
];
|
|
123
|
+
const devOnlyExternals = ["ts-morph"];
|
|
124
|
+
return [
|
|
125
|
+
stratalInertiaDevCss({ entries }),
|
|
126
|
+
stratalInertiaTypes(),
|
|
127
|
+
{
|
|
128
|
+
name: "stratal:optimize-deps-fix",
|
|
129
|
+
configEnvironment(_name, env) {
|
|
130
|
+
const existing = env.optimizeDeps?.exclude ?? [];
|
|
131
|
+
const existingInclude = env.optimizeDeps?.include ?? [];
|
|
132
|
+
env.optimizeDeps = {
|
|
133
|
+
...env.optimizeDeps,
|
|
134
|
+
exclude: [...existing, ...optimizeDepsExclude],
|
|
135
|
+
include: [...existingInclude, ...optimizeDepsInclude]
|
|
136
|
+
};
|
|
137
|
+
const existingExternal = env.build?.rolldownOptions?.external ?? [];
|
|
138
|
+
env.build = {
|
|
139
|
+
...env.build,
|
|
140
|
+
rolldownOptions: {
|
|
141
|
+
...env.build?.rolldownOptions,
|
|
142
|
+
external: [...existingExternal, ...devOnlyExternals]
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
];
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
150
|
+
export { stratalInertia, stratalInertiaDevCss, stratalInertiaTypes };
|
|
151
|
+
|
|
152
|
+
//# sourceMappingURL=vite.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.mjs","names":[],"sources":["../src/vite/inertia-dev-css-plugin.ts","../src/vite/inertia-types-plugin.ts","../src/vite.ts"],"sourcesContent":["import type { ModuleNode, Plugin, ViteDevServer } from 'vite'\n\nconst CSS_LANGS_RE = /\\.(css|scss|sass|less|styl|stylus|pcss|postcss)(?:$|\\?)/\nconst VIRTUAL_MODULE_ID = 'virtual:inertia-ssr.css'\nconst RESOLVED_VIRTUAL_MODULE_ID = '\\0' + VIRTUAL_MODULE_ID\n\nexport interface InertiaDevCssOptions {\n entries: string[]\n}\n\nfunction collectStyleUrls(server: ViteDevServer, entries: string[]): string[] {\n const urls: string[] = []\n const visited = new Set<string>()\n\n function traverse(mod: ModuleNode) {\n if (visited.has(mod.url)) return\n visited.add(mod.url)\n\n if (CSS_LANGS_RE.test(mod.url)) {\n urls.push(mod.url)\n }\n\n for (const imported of mod.importedModules) {\n traverse(imported)\n }\n }\n\n for (const entry of entries) {\n const mod = server.moduleGraph.getModulesByFile(\n entry.startsWith('/') ? entry.slice(1) : entry,\n )\n\n if (mod) {\n for (const m of mod) {\n traverse(m)\n }\n }\n\n const urlMod = server.moduleGraph.urlToModuleMap.get(entry)\n if (urlMod) {\n traverse(urlMod)\n }\n }\n\n return urls\n}\n\nasync function collectStyle(server: ViteDevServer, entries: string[]): Promise<string> {\n for (const entry of entries) {\n try {\n await server.transformRequest(entry)\n }\n catch {\n //\n }\n }\n\n const urls = collectStyleUrls(server, entries)\n const styles: string[] = []\n\n for (const url of urls) {\n try {\n const separator = url.includes('?') ? '&' : '?'\n const result = await server.transformRequest(url + separator + 'direct')\n if (result?.code) {\n styles.push(result.code)\n }\n }\n catch {\n //\n }\n }\n\n return styles.join('\\n')\n}\n\nexport function stratalInertiaDevCss(options: InertiaDevCssOptions): Plugin {\n let server: ViteDevServer\n\n return {\n name: 'stratal:inertia-dev-css',\n apply: 'serve',\n\n resolveId(id) {\n if (id === VIRTUAL_MODULE_ID) {\n return RESOLVED_VIRTUAL_MODULE_ID\n }\n },\n\n async load(id) {\n if (id === RESOLVED_VIRTUAL_MODULE_ID) {\n return await collectStyle(server, options.entries)\n }\n },\n\n configureServer(devServer) {\n server = devServer\n\n server.middlewares.use((req, res, next) => {\n const pathname = new URL(req.url ?? '', 'http://localhost').pathname\n if (pathname !== '/__inertia/ssr-css') { next(); return; }\n\n collectStyle(server, options.entries).then((css) => {\n res.setHeader('Content-Type', 'text/css')\n res.setHeader('Cache-Control', 'no-store')\n res.end(css)\n }).catch(() => {\n res.statusCode = 500\n res.end('')\n })\n })\n },\n }\n}\n","import { existsSync, readFileSync } from 'node:fs'\nimport { join, relative } from 'node:path'\nimport type { Plugin } from 'vite'\nimport { findPagesDir, runTypeGeneration } from '../generator/type-generator'\n\nconst INERTIA_CALL_PATTERN = /ctx\\.inertia\\(|\\.share\\(|ctx\\.flash\\(|ctx\\.defer\\(|ctx\\.optional\\(|ctx\\.merge\\(|ctx\\.once\\(|ctx\\.always\\(/\n\nexport function stratalInertiaTypes(): Plugin {\n let cwd: string\n let pagesDir: string\n let srcDir: string\n\n return {\n name: 'stratal:inertia-types',\n\n configResolved(config) {\n cwd = config.root\n pagesDir = findPagesDir(cwd) + '/'\n srcDir = join(cwd, 'src') + '/'\n },\n\n async buildStart() {\n if (!existsSync(pagesDir)) return\n try {\n await runTypeGeneration(cwd)\n } catch (error) {\n console.warn('[stratal:inertia-types] Type generation failed during build:', error)\n }\n },\n\n async handleHotUpdate({ file }) {\n if (!/\\.(tsx|ts)$/.test(file)) return\n\n const relToSrc = relative(srcDir, file)\n const isInSrc = !relToSrc.startsWith('..')\n\n if (!isInSrc) return\n\n // Page files always trigger regeneration\n const relToPages = relative(pagesDir, file)\n const isPageFile = !relToPages.startsWith('..')\n\n if (!isPageFile) {\n // For non-page files, only regenerate if they contain inertia-related calls\n try {\n const content = readFileSync(file, 'utf-8')\n if (!INERTIA_CALL_PATTERN.test(content)) return\n } catch {\n return\n }\n }\n\n try {\n await runTypeGeneration(cwd)\n } catch (error) {\n console.warn('[stratal:inertia-types] Type generation failed during HMR:', error)\n }\n },\n }\n}\n","import type { EnvironmentOptions, Plugin } from 'vite'\nimport { stratalInertiaDevCss } from './vite/inertia-dev-css-plugin'\nimport { stratalInertiaTypes } from './vite/inertia-types-plugin'\n\nexport { stratalInertiaDevCss, stratalInertiaTypes }\n\nexport interface StratalInertiaPluginOptions {\n /** Client entry path(s) for CSS collection (default: ['/src/inertia/app.tsx']) */\n entries?: string[]\n}\n\nexport function stratalInertia(options?: StratalInertiaPluginOptions): Plugin[] {\n const entries = options?.entries ?? ['/src/inertia/app.tsx']\n\n const optimizeDepsExclude = ['@cloudflare/vite-plugin', 'wrangler', 'blake3-wasm', '@stratal/inertia']\n const optimizeDepsInclude = ['buffer', 'buffer/', 'base64-js', 'ieee754']\n const devOnlyExternals = ['ts-morph']\n\n return [\n stratalInertiaDevCss({ entries }),\n stratalInertiaTypes(),\n {\n name: 'stratal:optimize-deps-fix',\n configEnvironment(_name: string, env: EnvironmentOptions) {\n const existing = env.optimizeDeps?.exclude ?? []\n const existingInclude = env.optimizeDeps?.include ?? []\n env.optimizeDeps = {\n ...env.optimizeDeps,\n exclude: [...existing, ...optimizeDepsExclude],\n include: [...existingInclude, ...optimizeDepsInclude],\n }\n\n const existingExternal = (env.build?.rolldownOptions?.external as string[]) ?? []\n env.build = {\n ...env.build,\n rolldownOptions: {\n ...env.build?.rolldownOptions,\n external: [...existingExternal, ...devOnlyExternals],\n },\n }\n },\n },\n ]\n}\n"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stratal/inertia",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"description": "Inertia.js v3 server adapter for Stratal framework — server-driven React SPAs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public",
|
|
31
|
-
"provenance":
|
|
31
|
+
"provenance": true
|
|
32
32
|
},
|
|
33
33
|
"files": [
|
|
34
34
|
"dist",
|
|
@@ -40,6 +40,14 @@
|
|
|
40
40
|
"types": "./dist/index.d.mts",
|
|
41
41
|
"import": "./dist/index.mjs"
|
|
42
42
|
},
|
|
43
|
+
"./react": {
|
|
44
|
+
"types": "./dist/react.d.mts",
|
|
45
|
+
"import": "./dist/react.mjs"
|
|
46
|
+
},
|
|
47
|
+
"./testing": {
|
|
48
|
+
"types": "./dist/testing.d.mts",
|
|
49
|
+
"import": "./dist/testing.mjs"
|
|
50
|
+
},
|
|
43
51
|
"./vite": {
|
|
44
52
|
"types": "./dist/vite.d.mts",
|
|
45
53
|
"import": "./dist/vite.mjs"
|
|
@@ -51,23 +59,31 @@
|
|
|
51
59
|
"typecheck": "tsc --noEmit",
|
|
52
60
|
"test": "vitest run",
|
|
53
61
|
"test:watch": "vitest",
|
|
54
|
-
"lint": "npx
|
|
55
|
-
"lint:fix": "npx
|
|
62
|
+
"lint": "npx oxlint .",
|
|
63
|
+
"lint:fix": "npx oxlint --fix ."
|
|
56
64
|
},
|
|
57
65
|
"dependencies": {
|
|
58
|
-
"ts-morph": "^
|
|
66
|
+
"ts-morph": "^28.0.0"
|
|
59
67
|
},
|
|
60
68
|
"peerDependencies": {
|
|
69
|
+
"@cloudflare/vite-plugin": ">=1.0.0",
|
|
61
70
|
"@inertiajs/core": "^3.0.0-beta.5",
|
|
62
71
|
"@inertiajs/react": "^3.0.0-beta.5",
|
|
63
72
|
"@inertiajs/vite": "^3.0.0-beta.5",
|
|
73
|
+
"@intlify/core-base": ">=11.0.0",
|
|
74
|
+
"@stratal/testing": ">=0.0.19",
|
|
64
75
|
"hono": "^4.12.8",
|
|
65
76
|
"react": "^19.0.0",
|
|
66
77
|
"react-dom": "^19.0.0",
|
|
67
78
|
"reflect-metadata": "^0.2.2",
|
|
68
|
-
"stratal": "^0.0.
|
|
79
|
+
"stratal": "^0.0.19",
|
|
80
|
+
"vite": "^8.0.0",
|
|
81
|
+
"vitest": "^4.1.0"
|
|
69
82
|
},
|
|
70
83
|
"peerDependenciesMeta": {
|
|
84
|
+
"@cloudflare/vite-plugin": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
71
87
|
"@inertiajs/core": {
|
|
72
88
|
"optional": true
|
|
73
89
|
},
|
|
@@ -77,31 +93,43 @@
|
|
|
77
93
|
"@inertiajs/vite": {
|
|
78
94
|
"optional": true
|
|
79
95
|
},
|
|
96
|
+
"@intlify/core-base": {
|
|
97
|
+
"optional": true
|
|
98
|
+
},
|
|
99
|
+
"@stratal/testing": {
|
|
100
|
+
"optional": true
|
|
101
|
+
},
|
|
80
102
|
"react": {
|
|
81
103
|
"optional": true
|
|
82
104
|
},
|
|
83
105
|
"react-dom": {
|
|
84
106
|
"optional": true
|
|
107
|
+
},
|
|
108
|
+
"vitest": {
|
|
109
|
+
"optional": true
|
|
85
110
|
}
|
|
86
111
|
},
|
|
87
112
|
"devDependencies": {
|
|
88
|
-
"@cloudflare/
|
|
89
|
-
"@
|
|
90
|
-
"@inertiajs/
|
|
113
|
+
"@cloudflare/vite-plugin": "^1.33.2",
|
|
114
|
+
"@cloudflare/workers-types": "4.20260426.1",
|
|
115
|
+
"@inertiajs/core": "^3.0.3",
|
|
116
|
+
"@inertiajs/react": "^3.0.3",
|
|
117
|
+
"@inertiajs/vite": "^3.0.3",
|
|
118
|
+
"@intlify/core-base": "^11.4.0",
|
|
91
119
|
"@stratal/testing": "workspace:*",
|
|
92
|
-
"@types/node": "^25.
|
|
120
|
+
"@types/node": "^25.6.0",
|
|
93
121
|
"@types/react": "^19.2.14",
|
|
94
122
|
"@types/react-dom": "^19.2.3",
|
|
95
|
-
"@vitest/runner": "~4.1.
|
|
96
|
-
"@vitest/snapshot": "~4.1.
|
|
97
|
-
"hono": "^4.12.
|
|
98
|
-
"react": "^19.2.
|
|
99
|
-
"react-dom": "^19.2.
|
|
123
|
+
"@vitest/runner": "~4.1.5",
|
|
124
|
+
"@vitest/snapshot": "~4.1.5",
|
|
125
|
+
"hono": "^4.12.15",
|
|
126
|
+
"react": "^19.2.5",
|
|
127
|
+
"react-dom": "^19.2.5",
|
|
100
128
|
"reflect-metadata": "^0.2.2",
|
|
101
129
|
"stratal": "workspace:*",
|
|
102
|
-
"tsdown": "^0.21.
|
|
103
|
-
"typescript": "^
|
|
104
|
-
"vite": "^8.0.
|
|
105
|
-
"vitest": "~4.1.
|
|
130
|
+
"tsdown": "^0.21.10",
|
|
131
|
+
"typescript": "^6.0.3",
|
|
132
|
+
"vite": "^8.0.10",
|
|
133
|
+
"vitest": "~4.1.5"
|
|
106
134
|
}
|
|
107
135
|
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-wcPFST8Q.mjs";
|
|
2
|
-
//#region src/vite/inertia-dev-css-plugin.ts
|
|
3
|
-
var inertia_dev_css_plugin_exports = /* @__PURE__ */ __exportAll({ stratalInertiaDevCss: () => stratalInertiaDevCss });
|
|
4
|
-
const CSS_LANGS_RE = /\.(css|scss|sass|less|styl|stylus|pcss|postcss)(?:$|\?)/;
|
|
5
|
-
const VIRTUAL_MODULE_ID = "virtual:inertia-ssr.css";
|
|
6
|
-
const RESOLVED_VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID;
|
|
7
|
-
function collectStyleUrls(server, entries) {
|
|
8
|
-
const urls = [];
|
|
9
|
-
const visited = /* @__PURE__ */ new Set();
|
|
10
|
-
function traverse(mod) {
|
|
11
|
-
if (visited.has(mod.url)) return;
|
|
12
|
-
visited.add(mod.url);
|
|
13
|
-
if (CSS_LANGS_RE.test(mod.url)) urls.push(mod.url);
|
|
14
|
-
for (const imported of mod.importedModules) traverse(imported);
|
|
15
|
-
}
|
|
16
|
-
for (const entry of entries) {
|
|
17
|
-
const mod = server.moduleGraph.getModulesByFile(entry.startsWith("/") ? entry.slice(1) : entry);
|
|
18
|
-
if (mod) for (const m of mod) traverse(m);
|
|
19
|
-
const urlMod = server.moduleGraph.urlToModuleMap.get(entry);
|
|
20
|
-
if (urlMod) traverse(urlMod);
|
|
21
|
-
}
|
|
22
|
-
return urls;
|
|
23
|
-
}
|
|
24
|
-
async function collectStyle(server, entries) {
|
|
25
|
-
for (const entry of entries) try {
|
|
26
|
-
await server.transformRequest(entry);
|
|
27
|
-
} catch {}
|
|
28
|
-
const urls = collectStyleUrls(server, entries);
|
|
29
|
-
const styles = [];
|
|
30
|
-
for (const url of urls) try {
|
|
31
|
-
const separator = url.includes("?") ? "&" : "?";
|
|
32
|
-
const result = await server.transformRequest(url + separator + "direct");
|
|
33
|
-
if (result?.code) styles.push(result.code);
|
|
34
|
-
} catch {}
|
|
35
|
-
return styles.join("\n");
|
|
36
|
-
}
|
|
37
|
-
function stratalInertiaDevCss(options) {
|
|
38
|
-
let server;
|
|
39
|
-
return {
|
|
40
|
-
name: "stratal:inertia-dev-css",
|
|
41
|
-
apply: "serve",
|
|
42
|
-
resolveId(id) {
|
|
43
|
-
if (id === VIRTUAL_MODULE_ID) return RESOLVED_VIRTUAL_MODULE_ID;
|
|
44
|
-
},
|
|
45
|
-
async load(id) {
|
|
46
|
-
if (id === RESOLVED_VIRTUAL_MODULE_ID) return await collectStyle(server, options.entries);
|
|
47
|
-
},
|
|
48
|
-
configureServer(devServer) {
|
|
49
|
-
server = devServer;
|
|
50
|
-
server.middlewares.use((req, res, next) => {
|
|
51
|
-
if (new URL(req.url ?? "", "http://localhost").pathname !== "/__inertia/ssr-css") {
|
|
52
|
-
next();
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
collectStyle(server, options.entries).then((css) => {
|
|
56
|
-
res.setHeader("Content-Type", "text/css");
|
|
57
|
-
res.setHeader("Cache-Control", "no-store");
|
|
58
|
-
res.end(css);
|
|
59
|
-
}).catch(() => {
|
|
60
|
-
res.statusCode = 500;
|
|
61
|
-
res.end("");
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
//#endregion
|
|
68
|
-
export { stratalInertiaDevCss as n, inertia_dev_css_plugin_exports as t };
|
|
69
|
-
|
|
70
|
-
//# sourceMappingURL=inertia-dev-css-plugin-BYromyO_.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inertia-dev-css-plugin-BYromyO_.mjs","names":[],"sources":["../src/vite/inertia-dev-css-plugin.ts"],"sourcesContent":["import type { ModuleNode, Plugin, ViteDevServer } from 'vite'\n\nconst CSS_LANGS_RE = /\\.(css|scss|sass|less|styl|stylus|pcss|postcss)(?:$|\\?)/\nconst VIRTUAL_MODULE_ID = 'virtual:inertia-ssr.css'\nconst RESOLVED_VIRTUAL_MODULE_ID = '\\0' + VIRTUAL_MODULE_ID\n\nexport interface InertiaDevCssOptions {\n entries: string[]\n}\n\nfunction collectStyleUrls(server: ViteDevServer, entries: string[]): string[] {\n const urls: string[] = []\n const visited = new Set<string>()\n\n function traverse(mod: ModuleNode) {\n if (visited.has(mod.url)) return\n visited.add(mod.url)\n\n if (CSS_LANGS_RE.test(mod.url)) {\n urls.push(mod.url)\n }\n\n for (const imported of mod.importedModules) {\n traverse(imported)\n }\n }\n\n for (const entry of entries) {\n const mod = server.moduleGraph.getModulesByFile(\n entry.startsWith('/') ? entry.slice(1) : entry,\n )\n\n if (mod) {\n for (const m of mod) {\n traverse(m)\n }\n }\n\n const urlMod = server.moduleGraph.urlToModuleMap.get(entry)\n if (urlMod) {\n traverse(urlMod)\n }\n }\n\n return urls\n}\n\nasync function collectStyle(server: ViteDevServer, entries: string[]): Promise<string> {\n for (const entry of entries) {\n try {\n await server.transformRequest(entry)\n }\n catch {\n //\n }\n }\n\n const urls = collectStyleUrls(server, entries)\n const styles: string[] = []\n\n for (const url of urls) {\n try {\n const separator = url.includes('?') ? '&' : '?'\n const result = await server.transformRequest(url + separator + 'direct')\n if (result?.code) {\n styles.push(result.code)\n }\n }\n catch {\n //\n }\n }\n\n return styles.join('\\n')\n}\n\nexport function stratalInertiaDevCss(options: InertiaDevCssOptions): Plugin {\n let server: ViteDevServer\n\n return {\n name: 'stratal:inertia-dev-css',\n apply: 'serve',\n\n resolveId(id) {\n if (id === VIRTUAL_MODULE_ID) {\n return RESOLVED_VIRTUAL_MODULE_ID\n }\n },\n\n async load(id) {\n if (id === RESOLVED_VIRTUAL_MODULE_ID) {\n return await collectStyle(server, options.entries)\n }\n },\n\n configureServer(devServer) {\n server = devServer\n\n server.middlewares.use((req, res, next) => {\n const pathname = new URL(req.url ?? '', 'http://localhost').pathname\n if (pathname !== '/__inertia/ssr-css') { next(); return; }\n\n collectStyle(server, options.entries).then((css) => {\n res.setHeader('Content-Type', 'text/css')\n res.setHeader('Cache-Control', 'no-store')\n res.end(css)\n }).catch(() => {\n res.statusCode = 500\n res.end('')\n })\n })\n },\n }\n}\n"],"mappings":";;;AAEA,MAAM,eAAe;AACrB,MAAM,oBAAoB;AAC1B,MAAM,6BAA6B,OAAO;AAM1C,SAAS,iBAAiB,QAAuB,SAA6B;CAC5E,MAAM,OAAiB,EAAE;CACzB,MAAM,0BAAU,IAAI,KAAa;CAEjC,SAAS,SAAS,KAAiB;AACjC,MAAI,QAAQ,IAAI,IAAI,IAAI,CAAE;AAC1B,UAAQ,IAAI,IAAI,IAAI;AAEpB,MAAI,aAAa,KAAK,IAAI,IAAI,CAC5B,MAAK,KAAK,IAAI,IAAI;AAGpB,OAAK,MAAM,YAAY,IAAI,gBACzB,UAAS,SAAS;;AAItB,MAAK,MAAM,SAAS,SAAS;EAC3B,MAAM,MAAM,OAAO,YAAY,iBAC7B,MAAM,WAAW,IAAI,GAAG,MAAM,MAAM,EAAE,GAAG,MAC1C;AAED,MAAI,IACF,MAAK,MAAM,KAAK,IACd,UAAS,EAAE;EAIf,MAAM,SAAS,OAAO,YAAY,eAAe,IAAI,MAAM;AAC3D,MAAI,OACF,UAAS,OAAO;;AAIpB,QAAO;;AAGT,eAAe,aAAa,QAAuB,SAAoC;AACrF,MAAK,MAAM,SAAS,QAClB,KAAI;AACF,QAAM,OAAO,iBAAiB,MAAM;SAEhC;CAKR,MAAM,OAAO,iBAAiB,QAAQ,QAAQ;CAC9C,MAAM,SAAmB,EAAE;AAE3B,MAAK,MAAM,OAAO,KAChB,KAAI;EACF,MAAM,YAAY,IAAI,SAAS,IAAI,GAAG,MAAM;EAC5C,MAAM,SAAS,MAAM,OAAO,iBAAiB,MAAM,YAAY,SAAS;AACxE,MAAI,QAAQ,KACV,QAAO,KAAK,OAAO,KAAK;SAGtB;AAKR,QAAO,OAAO,KAAK,KAAK;;AAG1B,SAAgB,qBAAqB,SAAuC;CAC1E,IAAI;AAEJ,QAAO;EACL,MAAM;EACN,OAAO;EAEP,UAAU,IAAI;AACZ,OAAI,OAAO,kBACT,QAAO;;EAIX,MAAM,KAAK,IAAI;AACb,OAAI,OAAO,2BACT,QAAO,MAAM,aAAa,QAAQ,QAAQ,QAAQ;;EAItD,gBAAgB,WAAW;AACzB,YAAS;AAET,UAAO,YAAY,KAAK,KAAK,KAAK,SAAS;AAEzC,QADiB,IAAI,IAAI,IAAI,OAAO,IAAI,mBAAmB,CAAC,aAC3C,sBAAsB;AAAE,WAAM;AAAE;;AAEjD,iBAAa,QAAQ,QAAQ,QAAQ,CAAC,MAAM,QAAQ;AAClD,SAAI,UAAU,gBAAgB,WAAW;AACzC,SAAI,UAAU,iBAAiB,WAAW;AAC1C,SAAI,IAAI,IAAI;MACZ,CAAC,YAAY;AACb,SAAI,aAAa;AACjB,SAAI,IAAI,GAAG;MACX;KACF;;EAEL"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-wcPFST8Q.mjs";
|
|
2
|
-
import { n as runTypeGeneration, t as findPagesDir } from "./type-generator-DlXIc6e2.mjs";
|
|
3
|
-
import { existsSync } from "node:fs";
|
|
4
|
-
import { isAbsolute, relative } from "node:path";
|
|
5
|
-
//#region src/vite/inertia-types-plugin.ts
|
|
6
|
-
var inertia_types_plugin_exports = /* @__PURE__ */ __exportAll({ stratalInertiaTypes: () => stratalInertiaTypes });
|
|
7
|
-
function stratalInertiaTypes() {
|
|
8
|
-
let cwd;
|
|
9
|
-
let pagesDir;
|
|
10
|
-
return {
|
|
11
|
-
name: "stratal:inertia-types",
|
|
12
|
-
configResolved(config) {
|
|
13
|
-
cwd = config.root;
|
|
14
|
-
pagesDir = findPagesDir(cwd) + "/";
|
|
15
|
-
},
|
|
16
|
-
async buildStart() {
|
|
17
|
-
if (!existsSync(pagesDir)) return;
|
|
18
|
-
try {
|
|
19
|
-
await runTypeGeneration(cwd);
|
|
20
|
-
} catch (error) {
|
|
21
|
-
console.warn("[stratal:inertia-types] Type generation failed during build:", error);
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
async handleHotUpdate({ file }) {
|
|
25
|
-
const rel = relative(pagesDir, file);
|
|
26
|
-
if (rel.startsWith("..") || isAbsolute(rel)) return;
|
|
27
|
-
if (!/\.(tsx|ts)$/.test(file)) return;
|
|
28
|
-
try {
|
|
29
|
-
await runTypeGeneration(cwd);
|
|
30
|
-
} catch (error) {
|
|
31
|
-
console.warn("[stratal:inertia-types] Type generation failed during HMR:", error);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
//#endregion
|
|
37
|
-
export { stratalInertiaTypes as n, inertia_types_plugin_exports as t };
|
|
38
|
-
|
|
39
|
-
//# sourceMappingURL=inertia-types-plugin-NO_uxhxQ.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inertia-types-plugin-NO_uxhxQ.mjs","names":[],"sources":["../src/vite/inertia-types-plugin.ts"],"sourcesContent":["import { existsSync } from 'node:fs'\nimport { isAbsolute, relative } from 'node:path'\nimport type { Plugin } from 'vite'\nimport { findPagesDir, runTypeGeneration } from '../generator/type-generator'\n\nexport function stratalInertiaTypes(): Plugin {\n let cwd: string\n let pagesDir: string\n\n return {\n name: 'stratal:inertia-types',\n\n configResolved(config) {\n cwd = config.root\n pagesDir = findPagesDir(cwd) + '/'\n },\n\n async buildStart() {\n if (!existsSync(pagesDir)) return\n try {\n await runTypeGeneration(cwd)\n } catch (error) {\n console.warn('[stratal:inertia-types] Type generation failed during build:', error)\n }\n },\n\n async handleHotUpdate({ file }) {\n const rel = relative(pagesDir, file)\n if (rel.startsWith('..') || isAbsolute(rel)) return\n if (!/\\.(tsx|ts)$/.test(file)) return\n\n try {\n await runTypeGeneration(cwd)\n } catch (error) {\n console.warn('[stratal:inertia-types] Type generation failed during HMR:', error)\n }\n },\n }\n}\n"],"mappings":";;;;;;AAKA,SAAgB,sBAA8B;CAC5C,IAAI;CACJ,IAAI;AAEJ,QAAO;EACL,MAAM;EAEN,eAAe,QAAQ;AACrB,SAAM,OAAO;AACb,cAAW,aAAa,IAAI,GAAG;;EAGjC,MAAM,aAAa;AACjB,OAAI,CAAC,WAAW,SAAS,CAAE;AAC3B,OAAI;AACF,UAAM,kBAAkB,IAAI;YACrB,OAAO;AACd,YAAQ,KAAK,gEAAgE,MAAM;;;EAIvF,MAAM,gBAAgB,EAAE,QAAQ;GAC9B,MAAM,MAAM,SAAS,UAAU,KAAK;AACpC,OAAI,IAAI,WAAW,KAAK,IAAI,WAAW,IAAI,CAAE;AAC7C,OAAI,CAAC,cAAc,KAAK,KAAK,CAAE;AAE/B,OAAI;AACF,UAAM,kBAAkB,IAAI;YACrB,OAAO;AACd,YAAQ,KAAK,8DAA8D,MAAM;;;EAGtF"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __exportAll = (all, no_symbols) => {
|
|
4
|
-
let target = {};
|
|
5
|
-
for (var name in all) __defProp(target, name, {
|
|
6
|
-
get: all[name],
|
|
7
|
-
enumerable: true
|
|
8
|
-
});
|
|
9
|
-
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
-
return target;
|
|
11
|
-
};
|
|
12
|
-
//#endregion
|
|
13
|
-
export { __exportAll as t };
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { dirname, join, relative } from "node:path";
|
|
3
|
-
//#region src/generator/type-generator.ts
|
|
4
|
-
async function loadTsMorph() {
|
|
5
|
-
return import("ts-morph");
|
|
6
|
-
}
|
|
7
|
-
async function extractPageTypes(pagesDir, tsConfigPath) {
|
|
8
|
-
if (!existsSync(pagesDir)) return [];
|
|
9
|
-
const { Project, SyntaxKind, ts } = await loadTsMorph();
|
|
10
|
-
const project = new Project({
|
|
11
|
-
tsConfigFilePath: tsConfigPath,
|
|
12
|
-
skipAddingFilesFromTsConfig: true,
|
|
13
|
-
compilerOptions: tsConfigPath ? void 0 : {
|
|
14
|
-
jsx: ts.JsxEmit.ReactJSX,
|
|
15
|
-
esModuleInterop: true,
|
|
16
|
-
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
17
|
-
module: ts.ModuleKind.ESNext,
|
|
18
|
-
target: ts.ScriptTarget.ESNext
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
project.addSourceFilesAtPaths(join(pagesDir, "**/*.{tsx,ts}"));
|
|
22
|
-
const pages = [];
|
|
23
|
-
for (const sourceFile of project.getSourceFiles()) {
|
|
24
|
-
const relPath = relative(pagesDir, sourceFile.getFilePath());
|
|
25
|
-
if (relPath.includes("__tests__") || relPath.includes(".spec.") || relPath.includes(".test.")) continue;
|
|
26
|
-
const fileName = relPath.split("/").pop();
|
|
27
|
-
if (fileName.startsWith("_") || /^Layout\.(tsx|ts)$/.test(fileName)) continue;
|
|
28
|
-
const componentName = relPath.replace(/\.(tsx|ts)$/, "").replace(/\\/g, "/");
|
|
29
|
-
const propsType = extractDefaultExportPropsType(sourceFile, SyntaxKind, ts);
|
|
30
|
-
if (propsType !== null) pages.push({
|
|
31
|
-
componentName,
|
|
32
|
-
propsType
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
return pages.sort((a, b) => a.componentName.localeCompare(b.componentName));
|
|
36
|
-
}
|
|
37
|
-
function extractDefaultExportPropsType(sourceFile, SK, tsObj) {
|
|
38
|
-
const defaultExportSymbol = sourceFile.getDefaultExportSymbol();
|
|
39
|
-
if (!defaultExportSymbol) return null;
|
|
40
|
-
const declarations = defaultExportSymbol.getDeclarations();
|
|
41
|
-
for (const decl of declarations) {
|
|
42
|
-
if (decl.isKind(SK.FunctionDeclaration)) return extractPropsFromFunction(decl, tsObj);
|
|
43
|
-
if (decl.isKind(SK.ExportAssignment)) {
|
|
44
|
-
const expr = decl.getExpression();
|
|
45
|
-
if (!expr) continue;
|
|
46
|
-
if (expr.isKind(SK.FunctionExpression)) return extractPropsFromParams(expr.getParameters(), tsObj);
|
|
47
|
-
if (expr.isKind(SK.Identifier)) return resolveIdentifierPropsType(expr, SK, tsObj);
|
|
48
|
-
if (expr.isKind(SK.ArrowFunction)) return extractPropsFromParams(expr.getParameters(), tsObj);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
function extractPropsFromFunction(fn, tsObj) {
|
|
54
|
-
return extractPropsFromParams(fn.getParameters(), tsObj);
|
|
55
|
-
}
|
|
56
|
-
function extractPropsFromParams(params, tsObj) {
|
|
57
|
-
if (params.length === 0) return "Record<string, never>";
|
|
58
|
-
return typeToString(params[0].getType(), tsObj);
|
|
59
|
-
}
|
|
60
|
-
function resolveIdentifierPropsType(identifier, SK, tsObj) {
|
|
61
|
-
const symbol = identifier.getSymbol();
|
|
62
|
-
if (!symbol) return null;
|
|
63
|
-
for (const decl of symbol.getDeclarations()) {
|
|
64
|
-
if (decl.isKind(SK.FunctionDeclaration)) return extractPropsFromFunction(decl, tsObj);
|
|
65
|
-
if (decl.isKind(SK.VariableDeclaration)) {
|
|
66
|
-
const init = decl.getInitializer();
|
|
67
|
-
if (init?.isKind(SK.ArrowFunction) || init?.isKind(SK.FunctionExpression)) return extractPropsFromParams(init.getParameters(), tsObj);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
function typeToString(type, tsObj) {
|
|
73
|
-
const text = type.getText(void 0, tsObj.TypeFormatFlags.NoTruncation | tsObj.TypeFormatFlags.UseFullyQualifiedType);
|
|
74
|
-
if (text.includes("import(")) return expandTypeToInline(type, tsObj);
|
|
75
|
-
return text;
|
|
76
|
-
}
|
|
77
|
-
function expandTypeToInline(type, tsObj, visited = /* @__PURE__ */ new Set()) {
|
|
78
|
-
if (visited.has(type)) return "Record<string, unknown>";
|
|
79
|
-
visited.add(type);
|
|
80
|
-
if (type.isObject() && !type.isArray()) {
|
|
81
|
-
const properties = type.getProperties();
|
|
82
|
-
if (properties.length === 0) return "Record<string, never>";
|
|
83
|
-
return `{ ${properties.map((prop) => {
|
|
84
|
-
const decl = prop.getDeclarations()[0] ?? prop.getValueDeclaration();
|
|
85
|
-
const isOptional = prop.isOptional();
|
|
86
|
-
if (!decl) return `${prop.getName()}${isOptional ? "?" : ""}: unknown`;
|
|
87
|
-
const propTypeStr = expandTypeToInline(prop.getTypeAtLocation(decl), tsObj, visited);
|
|
88
|
-
return `${prop.getName()}${isOptional ? "?" : ""}: ${propTypeStr}`;
|
|
89
|
-
}).join("; ")} }`;
|
|
90
|
-
}
|
|
91
|
-
if (type.isArray()) {
|
|
92
|
-
const elementType = type.getArrayElementType();
|
|
93
|
-
if (elementType) return `Array<${expandTypeToInline(elementType, tsObj, visited)}>`;
|
|
94
|
-
}
|
|
95
|
-
if (type.isUnion()) return type.getUnionTypes().map((t) => expandTypeToInline(t, tsObj, visited)).join(" | ");
|
|
96
|
-
if (type.isIntersection()) return type.getIntersectionTypes().map((t) => expandTypeToInline(t, tsObj, visited)).join(" & ");
|
|
97
|
-
const text = type.getText(void 0, tsObj.TypeFormatFlags.NoTruncation);
|
|
98
|
-
if (text.includes("import(")) return "Record<string, unknown>";
|
|
99
|
-
return text;
|
|
100
|
-
}
|
|
101
|
-
async function extractSharedDataType(moduleFilePath, tsConfigPath) {
|
|
102
|
-
if (!existsSync(moduleFilePath)) return null;
|
|
103
|
-
const { Project, SyntaxKind, ts } = await loadTsMorph();
|
|
104
|
-
const callExpressions = new Project({
|
|
105
|
-
tsConfigFilePath: tsConfigPath,
|
|
106
|
-
skipAddingFilesFromTsConfig: true,
|
|
107
|
-
compilerOptions: tsConfigPath ? void 0 : {
|
|
108
|
-
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
109
|
-
module: ts.ModuleKind.ESNext,
|
|
110
|
-
target: ts.ScriptTarget.ESNext
|
|
111
|
-
}
|
|
112
|
-
}).addSourceFileAtPath(moduleFilePath).getDescendantsOfKind(SyntaxKind.CallExpression);
|
|
113
|
-
for (const call of callExpressions) {
|
|
114
|
-
const expr = call.getExpression();
|
|
115
|
-
if (!expr.isKind(SyntaxKind.PropertyAccessExpression)) continue;
|
|
116
|
-
const propName = expr.getName();
|
|
117
|
-
if (propName !== "forRoot" && propName !== "forRootAsync") continue;
|
|
118
|
-
const objExpr = expr.getExpression();
|
|
119
|
-
if (!objExpr.isKind(SyntaxKind.Identifier) || objExpr.getText() !== "InertiaModule") continue;
|
|
120
|
-
const args = call.getArguments();
|
|
121
|
-
if (args.length === 0) continue;
|
|
122
|
-
const optionsArg = args[0];
|
|
123
|
-
if (!optionsArg.isKind(SyntaxKind.ObjectLiteralExpression)) continue;
|
|
124
|
-
const sharedDataProp = optionsArg.getProperty("sharedData");
|
|
125
|
-
if (!sharedDataProp) continue;
|
|
126
|
-
if (!sharedDataProp.isKind(SyntaxKind.PropertyAssignment)) continue;
|
|
127
|
-
const initializer = sharedDataProp.getInitializer();
|
|
128
|
-
if (!initializer?.isKind(SyntaxKind.ObjectLiteralExpression)) continue;
|
|
129
|
-
const members = [];
|
|
130
|
-
for (const prop of initializer.getProperties()) {
|
|
131
|
-
if (!prop.isKind(SyntaxKind.PropertyAssignment)) continue;
|
|
132
|
-
const name = prop.getName();
|
|
133
|
-
const value = prop.getInitializer();
|
|
134
|
-
if (!value) continue;
|
|
135
|
-
let valueType;
|
|
136
|
-
if (value.isKind(SyntaxKind.ArrowFunction) || value.isKind(SyntaxKind.FunctionExpression)) valueType = typeToString(value.getReturnType(), ts);
|
|
137
|
-
else valueType = typeToString(value.getType(), ts);
|
|
138
|
-
members.push(`${name}: ${valueType}`);
|
|
139
|
-
}
|
|
140
|
-
if (members.length > 0) return { propsType: `{ ${members.join("; ")} }` };
|
|
141
|
-
}
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
function generateInertiaTypes(pages, sharedData) {
|
|
145
|
-
const lines = ["// Auto-generated by @stratal/inertia. Do not edit.", "declare module '@stratal/inertia' {"];
|
|
146
|
-
lines.push(" interface InertiaPageRegistry {");
|
|
147
|
-
for (const page of pages) lines.push(` '${page.componentName}': ${page.propsType}`);
|
|
148
|
-
lines.push(" }");
|
|
149
|
-
lines.push("}");
|
|
150
|
-
if (sharedData) {
|
|
151
|
-
lines.push("");
|
|
152
|
-
lines.push("declare module '@inertiajs/core' {");
|
|
153
|
-
lines.push(" interface InertiaConfig {");
|
|
154
|
-
lines.push(` sharedPageProps: ${sharedData.propsType}`);
|
|
155
|
-
lines.push(" }");
|
|
156
|
-
lines.push("}");
|
|
157
|
-
}
|
|
158
|
-
lines.push("", "export {}", "");
|
|
159
|
-
return lines.join("\n");
|
|
160
|
-
}
|
|
161
|
-
function writeInertiaTypes(outputPath, content) {
|
|
162
|
-
mkdirSync(dirname(outputPath), { recursive: true });
|
|
163
|
-
writeFileSync(outputPath, content, "utf-8");
|
|
164
|
-
}
|
|
165
|
-
function findAppModulePath(cwd) {
|
|
166
|
-
return [join(cwd, "src", "app.module.ts"), join(cwd, "src", "app.module.tsx")].find(existsSync);
|
|
167
|
-
}
|
|
168
|
-
function findPagesDir(cwd) {
|
|
169
|
-
return join(cwd, "src", "inertia", "pages");
|
|
170
|
-
}
|
|
171
|
-
function findOutputPath(cwd) {
|
|
172
|
-
return join(cwd, "src", "inertia", "inertia.d.ts");
|
|
173
|
-
}
|
|
174
|
-
function findTsConfigPath(cwd) {
|
|
175
|
-
const candidate = join(cwd, "tsconfig.json");
|
|
176
|
-
return existsSync(candidate) ? candidate : void 0;
|
|
177
|
-
}
|
|
178
|
-
async function runTypeGeneration(cwd) {
|
|
179
|
-
const pagesDir = findPagesDir(cwd);
|
|
180
|
-
const outputPath = findOutputPath(cwd);
|
|
181
|
-
const moduleFilePath = findAppModulePath(cwd);
|
|
182
|
-
const tsConfigPath = findTsConfigPath(cwd);
|
|
183
|
-
const pages = await extractPageTypes(pagesDir, tsConfigPath);
|
|
184
|
-
writeInertiaTypes(outputPath, generateInertiaTypes(pages, moduleFilePath ? await extractSharedDataType(moduleFilePath, tsConfigPath) : null));
|
|
185
|
-
return {
|
|
186
|
-
outputPath,
|
|
187
|
-
pageCount: pages.length
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
//#endregion
|
|
191
|
-
export { runTypeGeneration as n, findPagesDir as t };
|
|
192
|
-
|
|
193
|
-
//# sourceMappingURL=type-generator-DlXIc6e2.mjs.map
|