houdini-react 2.0.0-next.8 → 2.0.0
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/bin/houdini-react +173 -0
- package/package.json +63 -39
- package/postInstall.js +360 -0
- package/runtime/Link.tsx +50 -0
- package/runtime/client.ts +5 -0
- package/runtime/clientPlugin.ts +17 -0
- package/runtime/componentFields.ts +79 -0
- package/runtime/escape.ts +15 -0
- package/runtime/hooks/index.ts +17 -0
- package/runtime/hooks/recycleNodesInto.ts +60 -0
- package/runtime/hooks/useDeepCompareEffect.ts +93 -0
- package/runtime/hooks/useDocumentHandle.ts +243 -0
- package/runtime/hooks/useDocumentStore.ts +112 -0
- package/runtime/hooks/useDocumentSubscription.ts +65 -0
- package/runtime/hooks/useFragment.ts +269 -0
- package/runtime/hooks/useFragmentHandle.ts +274 -0
- package/runtime/hooks/useIsMounted.ts +14 -0
- package/runtime/hooks/useLogoutForm.tsx +60 -0
- package/runtime/hooks/useMutation.ts +80 -0
- package/runtime/hooks/useMutationForm.tsx +163 -0
- package/runtime/hooks/useQuery.ts +12 -0
- package/runtime/hooks/useQueryHandle.ts +194 -0
- package/runtime/hooks/useSubscription.ts +12 -0
- package/runtime/hooks/useSubscriptionHandle.ts +42 -0
- package/runtime/hydration.tsx +186 -0
- package/runtime/index.tsx +77 -0
- package/runtime/login.ts +22 -0
- package/runtime/manifest.ts +6 -0
- package/runtime/mock.ts +9 -0
- package/runtime/package.json +1 -0
- package/runtime/resolve-href.ts +151 -0
- package/runtime/routes.ts +93 -0
- package/runtime/routing/Router.tsx +1101 -0
- package/runtime/routing/cache.ts +57 -0
- package/runtime/routing/errors.tsx +145 -0
- package/runtime/routing/index.ts +17 -0
- package/runtime/testing.tsx +163 -0
- package/runtime/tsconfig.json +39 -0
- package/server/index.d.ts +1 -0
- package/server/index.js +4 -0
- package/server/react-streaming.d.js +0 -0
- package/vite/index.d.ts +3 -0
- package/vite/index.js +397 -0
- package/vite/strip-headers.d.ts +1 -0
- package/vite/strip-headers.js +35 -0
- package/vite/transform.d.ts +13 -0
- package/vite/transform.js +105 -0
- package/README.md +0 -36
- package/build/plugin/codegen/entries/documentWrappers.d.ts +0 -6
- package/build/plugin/codegen/entries/fallbacks.d.ts +0 -5
- package/build/plugin/codegen/entries/index.d.ts +0 -16
- package/build/plugin/codegen/entries/pages.d.ts +0 -2
- package/build/plugin/codegen/index.d.ts +0 -17
- package/build/plugin/codegen/manifest.d.ts +0 -5
- package/build/plugin/codegen/render.d.ts +0 -7
- package/build/plugin/codegen/router.d.ts +0 -7
- package/build/plugin/codegen/typeRoot.d.ts +0 -5
- package/build/plugin/config.d.ts +0 -4
- package/build/plugin/dedent.d.ts +0 -1
- package/build/plugin/extract.d.ts +0 -6
- package/build/plugin/index.d.ts +0 -5
- package/build/plugin/state.d.ts +0 -3
- package/build/plugin/transform.d.ts +0 -6
- package/build/plugin/vite.d.ts +0 -27
- package/build/plugin-cjs/index.js +0 -90125
- package/build/plugin-cjs/package.json +0 -1
- package/build/plugin-esm/index.js +0 -90121
- package/build/runtime/client.d.ts +0 -3
- package/build/runtime/clientPlugin.d.ts +0 -3
- package/build/runtime/componentFields.d.ts +0 -9
- package/build/runtime/hooks/index.d.ts +0 -8
- package/build/runtime/hooks/useDeepCompareEffect.d.ts +0 -35
- package/build/runtime/hooks/useDocumentHandle.d.ts +0 -36
- package/build/runtime/hooks/useDocumentStore.d.ts +0 -11
- package/build/runtime/hooks/useDocumentSubscription.d.ts +0 -11
- package/build/runtime/hooks/useFragment.d.ts +0 -16
- package/build/runtime/hooks/useFragmentHandle.d.ts +0 -8
- package/build/runtime/hooks/useIsMounted.d.ts +0 -3
- package/build/runtime/hooks/useMutation.d.ts +0 -14
- package/build/runtime/hooks/useQuery.d.ts +0 -5
- package/build/runtime/hooks/useQueryHandle.d.ts +0 -10
- package/build/runtime/hooks/useSubscription.d.ts +0 -4
- package/build/runtime/hooks/useSubscriptionHandle.d.ts +0 -25
- package/build/runtime/index.d.ts +0 -14
- package/build/runtime/manifest.d.ts +0 -3
- package/build/runtime/routing/Router.d.ts +0 -62
- package/build/runtime/routing/cache.d.ts +0 -7
- package/build/runtime/routing/hooks.d.ts +0 -40
- package/build/runtime/routing/index.d.ts +0 -3
- package/build/runtime-cjs/client.d.ts +0 -3
- package/build/runtime-cjs/client.js +0 -25
- package/build/runtime-cjs/clientPlugin.d.ts +0 -3
- package/build/runtime-cjs/clientPlugin.js +0 -37
- package/build/runtime-cjs/componentFields.d.ts +0 -9
- package/build/runtime-cjs/componentFields.js +0 -83
- package/build/runtime-cjs/hooks/index.d.ts +0 -8
- package/build/runtime-cjs/hooks/index.js +0 -45
- package/build/runtime-cjs/hooks/useDeepCompareEffect.d.ts +0 -35
- package/build/runtime-cjs/hooks/useDeepCompareEffect.js +0 -76
- package/build/runtime-cjs/hooks/useDocumentHandle.d.ts +0 -36
- package/build/runtime-cjs/hooks/useDocumentHandle.js +0 -177
- package/build/runtime-cjs/hooks/useDocumentStore.d.ts +0 -11
- package/build/runtime-cjs/hooks/useDocumentStore.js +0 -76
- package/build/runtime-cjs/hooks/useDocumentSubscription.d.ts +0 -11
- package/build/runtime-cjs/hooks/useDocumentSubscription.js +0 -76
- package/build/runtime-cjs/hooks/useFragment.d.ts +0 -16
- package/build/runtime-cjs/hooks/useFragment.js +0 -102
- package/build/runtime-cjs/hooks/useFragmentHandle.d.ts +0 -8
- package/build/runtime-cjs/hooks/useFragmentHandle.js +0 -47
- package/build/runtime-cjs/hooks/useIsMounted.d.ts +0 -3
- package/build/runtime-cjs/hooks/useIsMounted.js +0 -38
- package/build/runtime-cjs/hooks/useMutation.d.ts +0 -14
- package/build/runtime-cjs/hooks/useMutation.js +0 -67
- package/build/runtime-cjs/hooks/useQuery.d.ts +0 -5
- package/build/runtime-cjs/hooks/useQuery.js +0 -32
- package/build/runtime-cjs/hooks/useQueryHandle.d.ts +0 -10
- package/build/runtime-cjs/hooks/useQueryHandle.js +0 -131
- package/build/runtime-cjs/hooks/useSubscription.d.ts +0 -4
- package/build/runtime-cjs/hooks/useSubscription.js +0 -32
- package/build/runtime-cjs/hooks/useSubscriptionHandle.d.ts +0 -25
- package/build/runtime-cjs/hooks/useSubscriptionHandle.js +0 -42
- package/build/runtime-cjs/index.d.ts +0 -14
- package/build/runtime-cjs/index.js +0 -88
- package/build/runtime-cjs/manifest.d.ts +0 -3
- package/build/runtime-cjs/manifest.js +0 -25
- package/build/runtime-cjs/package.json +0 -1
- package/build/runtime-cjs/routing/Router.d.ts +0 -62
- package/build/runtime-cjs/routing/Router.js +0 -540
- package/build/runtime-cjs/routing/cache.d.ts +0 -7
- package/build/runtime-cjs/routing/cache.js +0 -61
- package/build/runtime-cjs/routing/hooks.d.ts +0 -40
- package/build/runtime-cjs/routing/hooks.js +0 -93
- package/build/runtime-cjs/routing/index.d.ts +0 -3
- package/build/runtime-cjs/routing/index.js +0 -33
- package/build/runtime-esm/client.d.ts +0 -3
- package/build/runtime-esm/client.js +0 -5
- package/build/runtime-esm/clientPlugin.d.ts +0 -3
- package/build/runtime-esm/clientPlugin.js +0 -17
- package/build/runtime-esm/componentFields.d.ts +0 -9
- package/build/runtime-esm/componentFields.js +0 -59
- package/build/runtime-esm/hooks/index.d.ts +0 -8
- package/build/runtime-esm/hooks/index.js +0 -15
- package/build/runtime-esm/hooks/useDeepCompareEffect.d.ts +0 -35
- package/build/runtime-esm/hooks/useDeepCompareEffect.js +0 -41
- package/build/runtime-esm/hooks/useDocumentHandle.d.ts +0 -36
- package/build/runtime-esm/hooks/useDocumentHandle.js +0 -143
- package/build/runtime-esm/hooks/useDocumentStore.d.ts +0 -11
- package/build/runtime-esm/hooks/useDocumentStore.js +0 -42
- package/build/runtime-esm/hooks/useDocumentSubscription.d.ts +0 -11
- package/build/runtime-esm/hooks/useDocumentSubscription.js +0 -42
- package/build/runtime-esm/hooks/useFragment.d.ts +0 -16
- package/build/runtime-esm/hooks/useFragment.js +0 -67
- package/build/runtime-esm/hooks/useFragmentHandle.d.ts +0 -8
- package/build/runtime-esm/hooks/useFragmentHandle.js +0 -23
- package/build/runtime-esm/hooks/useIsMounted.d.ts +0 -3
- package/build/runtime-esm/hooks/useIsMounted.js +0 -14
- package/build/runtime-esm/hooks/useMutation.d.ts +0 -14
- package/build/runtime-esm/hooks/useMutation.js +0 -42
- package/build/runtime-esm/hooks/useQuery.d.ts +0 -5
- package/build/runtime-esm/hooks/useQuery.js +0 -8
- package/build/runtime-esm/hooks/useQueryHandle.d.ts +0 -10
- package/build/runtime-esm/hooks/useQueryHandle.js +0 -97
- package/build/runtime-esm/hooks/useSubscription.d.ts +0 -4
- package/build/runtime-esm/hooks/useSubscription.js +0 -8
- package/build/runtime-esm/hooks/useSubscriptionHandle.d.ts +0 -25
- package/build/runtime-esm/hooks/useSubscriptionHandle.js +0 -18
- package/build/runtime-esm/index.d.ts +0 -14
- package/build/runtime-esm/index.js +0 -48
- package/build/runtime-esm/manifest.d.ts +0 -3
- package/build/runtime-esm/manifest.js +0 -5
- package/build/runtime-esm/routing/Router.d.ts +0 -62
- package/build/runtime-esm/routing/Router.js +0 -499
- package/build/runtime-esm/routing/cache.d.ts +0 -7
- package/build/runtime-esm/routing/cache.js +0 -36
- package/build/runtime-esm/routing/hooks.d.ts +0 -40
- package/build/runtime-esm/routing/hooks.js +0 -53
- package/build/runtime-esm/routing/index.d.ts +0 -3
- package/build/runtime-esm/routing/index.js +0 -6
- package/build/server/index.d.ts +0 -1
- package/build/server-cjs/index.js +0 -28
- package/build/server-cjs/package.json +0 -1
- package/build/server-esm/index.js +0 -4
- package/build/server-esm/package.json +0 -1
- /package/{build/plugin-esm → server}/package.json +0 -0
- /package/{build/runtime-esm → vite}/package.json +0 -0
package/vite/index.js
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import { fs, path } from "houdini";
|
|
2
|
+
import {
|
|
3
|
+
app_component_path,
|
|
4
|
+
adapter_config_path,
|
|
5
|
+
plugin_dir,
|
|
6
|
+
client_build_directory
|
|
7
|
+
} from "houdini/router/conventions";
|
|
8
|
+
import { load_manifest } from "houdini/router/manifest";
|
|
9
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { createRequire } from "node:module";
|
|
11
|
+
import { build } from "vite";
|
|
12
|
+
import { transform_file } from "./transform.js";
|
|
13
|
+
const REACT_TSCONFIG_STUB = `{
|
|
14
|
+
"compilerOptions": {
|
|
15
|
+
"baseUrl": ".",
|
|
16
|
+
"paths": {
|
|
17
|
+
"$houdini": ["."],
|
|
18
|
+
"$houdini/*": ["./*"],
|
|
19
|
+
"~": ["../src"],
|
|
20
|
+
"~/*": ["../src/*"]
|
|
21
|
+
},
|
|
22
|
+
"rootDirs": ["..", "./types"],
|
|
23
|
+
"target": "ESNext",
|
|
24
|
+
"useDefineForClassFields": true,
|
|
25
|
+
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
|
26
|
+
"allowJs": true,
|
|
27
|
+
"skipLibCheck": true,
|
|
28
|
+
"esModuleInterop": false,
|
|
29
|
+
"allowSyntheticDefaultImports": true,
|
|
30
|
+
"strict": true,
|
|
31
|
+
"forceConsistentCasingInFileNames": true,
|
|
32
|
+
"module": "ESNext",
|
|
33
|
+
"moduleResolution": "Bundler",
|
|
34
|
+
"allowImportingTsExtensions": true,
|
|
35
|
+
"resolveJsonModule": true,
|
|
36
|
+
"isolatedModules": true,
|
|
37
|
+
"noEmit": true,
|
|
38
|
+
"jsx": "react-jsx"
|
|
39
|
+
},
|
|
40
|
+
"include": [
|
|
41
|
+
"ambient.d.ts",
|
|
42
|
+
"./types/**/$types.d.ts",
|
|
43
|
+
"../vite.config.ts",
|
|
44
|
+
"../src/**/*.js",
|
|
45
|
+
"../src/**/*.ts",
|
|
46
|
+
"../src/**/*.jsx",
|
|
47
|
+
"../src/**/*.tsx",
|
|
48
|
+
"../src/+app.d.ts"
|
|
49
|
+
],
|
|
50
|
+
"exclude": ["../node_modules/**", "./[!ambient.d.ts]**"]
|
|
51
|
+
}
|
|
52
|
+
`;
|
|
53
|
+
const _require = createRequire(import.meta.url);
|
|
54
|
+
let reactStreamingServerPath = "";
|
|
55
|
+
try {
|
|
56
|
+
const main = _require.resolve("react-streaming");
|
|
57
|
+
const pkgDir = main.replace(/\/dist\/.*$/, "");
|
|
58
|
+
reactStreamingServerPath = path.join(pkgDir, "dist/server/index.node-and-web.js");
|
|
59
|
+
} catch {
|
|
60
|
+
}
|
|
61
|
+
function index_default(ctx) {
|
|
62
|
+
let manifest;
|
|
63
|
+
let viteEnv;
|
|
64
|
+
let devServer = false;
|
|
65
|
+
let isSSRBuild = false;
|
|
66
|
+
let cfCache = null;
|
|
67
|
+
return {
|
|
68
|
+
name: "houdini-react",
|
|
69
|
+
configResolved(config) {
|
|
70
|
+
isSSRBuild = !!config.build.ssr;
|
|
71
|
+
},
|
|
72
|
+
async config(userConfig, env) {
|
|
73
|
+
viteEnv = env;
|
|
74
|
+
const runtimeDir = path.join(
|
|
75
|
+
ctx.config.root_dir,
|
|
76
|
+
ctx.config.config_file.runtimeDir ?? ".houdini"
|
|
77
|
+
);
|
|
78
|
+
try {
|
|
79
|
+
mkdirSync(runtimeDir, { recursive: true });
|
|
80
|
+
const tsconfigPath = path.join(runtimeDir, "tsconfig.json");
|
|
81
|
+
if (!existsSync(tsconfigPath)) {
|
|
82
|
+
writeFileSync(tsconfigPath, REACT_TSCONFIG_STUB);
|
|
83
|
+
}
|
|
84
|
+
} catch {
|
|
85
|
+
}
|
|
86
|
+
if (userConfig.build?.ssr) {
|
|
87
|
+
return reactStreamingServerPath ? { resolve: { alias: { "react-streaming/server": reactStreamingServerPath } } } : {};
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
manifest = await load_manifest({ config: ctx.config });
|
|
91
|
+
} catch (e) {
|
|
92
|
+
console.log(
|
|
93
|
+
"something went wrong. please try again. \n error: " + e.message
|
|
94
|
+
);
|
|
95
|
+
manifest = {
|
|
96
|
+
pages: {},
|
|
97
|
+
layouts: {},
|
|
98
|
+
page_queries: {},
|
|
99
|
+
layout_queries: {},
|
|
100
|
+
artifacts: [],
|
|
101
|
+
local_schema: false,
|
|
102
|
+
local_yoga: false,
|
|
103
|
+
component_fields: {}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
let conf = {
|
|
107
|
+
build: { rollupOptions: {} }
|
|
108
|
+
};
|
|
109
|
+
if (env.command === "build") {
|
|
110
|
+
conf.base = "/assets";
|
|
111
|
+
}
|
|
112
|
+
const compiledAssetsDir = client_build_directory(ctx.config);
|
|
113
|
+
await fs.mkdirp(compiledAssetsDir);
|
|
114
|
+
conf.build = {
|
|
115
|
+
outDir: compiledAssetsDir,
|
|
116
|
+
rollupOptions: {
|
|
117
|
+
output: {
|
|
118
|
+
assetFileNames: "assets/[name].js",
|
|
119
|
+
entryFileNames: "[name].js"
|
|
120
|
+
},
|
|
121
|
+
// only the client app entry belongs in the client build. The adapter entry
|
|
122
|
+
// imports src/server/+config (session keys, OAuth client secrets) and is built
|
|
123
|
+
// separately into the ssr/ directory by closeBundle below; building it here too
|
|
124
|
+
// would land a server bundle in the client-served assets dir and leak those
|
|
125
|
+
// secrets. Keeping client and server outputs in separate directories lets the
|
|
126
|
+
// adapter serve only the client assets.
|
|
127
|
+
input: {
|
|
128
|
+
"entries/app": app_component_path(ctx.config)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
if (env.command === "build" && ctx.adapter && ctx.adapter.includePaths) {
|
|
133
|
+
const extra = typeof ctx.adapter.includePaths === "function" ? ctx.adapter.includePaths({ config: ctx.config }) : ctx.adapter.includePaths;
|
|
134
|
+
Object.assign(conf.build.rollupOptions.input ?? {}, extra);
|
|
135
|
+
}
|
|
136
|
+
for (const [id, page] of Object.entries(manifest.pages)) {
|
|
137
|
+
;
|
|
138
|
+
conf.build.rollupOptions.input[`pages/${id}`] = `virtual:houdini/pages/${page.id}.jsx`;
|
|
139
|
+
}
|
|
140
|
+
return reactStreamingServerPath ? {
|
|
141
|
+
...conf,
|
|
142
|
+
resolve: { alias: { "react-streaming/server": reactStreamingServerPath } }
|
|
143
|
+
} : conf;
|
|
144
|
+
},
|
|
145
|
+
resolveId(id) {
|
|
146
|
+
if (id.includes("virtual:houdini")) {
|
|
147
|
+
return id.substring(id.indexOf("virtual:houdini"));
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
},
|
|
151
|
+
hotUpdate() {
|
|
152
|
+
cfCache = null;
|
|
153
|
+
},
|
|
154
|
+
async transform(code, filepath, options) {
|
|
155
|
+
filepath = path.posixify(filepath);
|
|
156
|
+
if (filepath.startsWith("/src/")) {
|
|
157
|
+
filepath = path.join(process.cwd(), filepath);
|
|
158
|
+
}
|
|
159
|
+
if (!ctx.config.includeFile(filepath)) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const stripHeaders = !options?.ssr && /(?:^|\/)\+(?:page|layout)\.[jt]sx?$/.test(filepath);
|
|
163
|
+
if (cfCache === null) {
|
|
164
|
+
try {
|
|
165
|
+
cfCache = ctx.db.all(
|
|
166
|
+
"SELECT type, field, fragment FROM component_fields"
|
|
167
|
+
);
|
|
168
|
+
} catch {
|
|
169
|
+
cfCache = [];
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return transform_file(
|
|
173
|
+
{
|
|
174
|
+
config: ctx.config,
|
|
175
|
+
content: code,
|
|
176
|
+
filepath: path.posixify(filepath),
|
|
177
|
+
watch_file: this.addWatchFile.bind(this)
|
|
178
|
+
},
|
|
179
|
+
cfCache,
|
|
180
|
+
{ stripHeaders }
|
|
181
|
+
);
|
|
182
|
+
},
|
|
183
|
+
async closeBundle() {
|
|
184
|
+
if (viteEnv.mode !== "production" || devServer || isSSRBuild) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (!ctx.adapter || ctx.adapter?.disableServer) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const compiledAssetsDir = client_build_directory(ctx.config);
|
|
191
|
+
await build({
|
|
192
|
+
build: {
|
|
193
|
+
ssr: true,
|
|
194
|
+
outDir: path.join(compiledAssetsDir, "ssr"),
|
|
195
|
+
rollupOptions: {
|
|
196
|
+
output: {
|
|
197
|
+
assetFileNames: "assets/[name].js",
|
|
198
|
+
entryFileNames: "[name].js"
|
|
199
|
+
},
|
|
200
|
+
input: {
|
|
201
|
+
"entries/adapter": adapter_config_path(ctx.config)
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
async load(id) {
|
|
208
|
+
if (!id.startsWith("virtual:houdini")) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (!manifest) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
let [, which, arg] = id.split("/");
|
|
215
|
+
const parsedPath = arg ? path.parse(arg) : "";
|
|
216
|
+
const pageName = parsedPath ? parsedPath.name : "";
|
|
217
|
+
if (which === "pages") {
|
|
218
|
+
let page = manifest.pages[pageName];
|
|
219
|
+
if (!page) {
|
|
220
|
+
try {
|
|
221
|
+
manifest = await load_manifest({ config: ctx.config });
|
|
222
|
+
page = manifest.pages[pageName];
|
|
223
|
+
} catch {
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (!page) {
|
|
227
|
+
throw new Error("unknown page" + pageName);
|
|
228
|
+
}
|
|
229
|
+
const pendingQueries = page.queries.filter((query) => {
|
|
230
|
+
const pg = Object.values(manifest.page_queries).find((q) => q.name === query);
|
|
231
|
+
if (pg) {
|
|
232
|
+
return pg.loading;
|
|
233
|
+
}
|
|
234
|
+
const layout = Object.values(manifest.layout_queries).find(
|
|
235
|
+
(q) => q.name === query
|
|
236
|
+
);
|
|
237
|
+
return layout?.loading;
|
|
238
|
+
});
|
|
239
|
+
return `
|
|
240
|
+
import App from '$houdini/plugins/houdini-react/units/render/App'
|
|
241
|
+
import Component from '$houdini/plugins/houdini-react/units/entries/${pageName}.jsx'
|
|
242
|
+
import { hydrate_page } from '$houdini/plugins/houdini-react/runtime/hydration'
|
|
243
|
+
hydrate_page(App, Component, '${pageName}', ${JSON.stringify(pendingQueries)})
|
|
244
|
+
`;
|
|
245
|
+
}
|
|
246
|
+
if (which === "artifacts") {
|
|
247
|
+
return `
|
|
248
|
+
import artifact from '$houdini/artifacts/${pageName}'
|
|
249
|
+
import { register_artifact } from '$houdini/plugins/houdini-react/runtime/hydration'
|
|
250
|
+
register_artifact('${pageName}', artifact)
|
|
251
|
+
`;
|
|
252
|
+
}
|
|
253
|
+
if (which === "static-entry") {
|
|
254
|
+
return `
|
|
255
|
+
import App from '$houdini/plugins/houdini-react/units/render/App'
|
|
256
|
+
import manifest from '$houdini/plugins/houdini-react/runtime/manifest'
|
|
257
|
+
import { mount_static_app } from '$houdini/plugins/houdini-react/runtime/hydration'
|
|
258
|
+
mount_static_app(App, manifest)
|
|
259
|
+
`;
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
async configureServer(server) {
|
|
263
|
+
devServer = true;
|
|
264
|
+
const onUnhandledRejection = (err) => {
|
|
265
|
+
console.error("\n[houdini] dev server error (server still running):\n", err, "\n");
|
|
266
|
+
};
|
|
267
|
+
process.on("unhandledRejection", onUnhandledRejection);
|
|
268
|
+
server.httpServer?.once(
|
|
269
|
+
"close",
|
|
270
|
+
() => process.off("unhandledRejection", onUnhandledRejection)
|
|
271
|
+
);
|
|
272
|
+
server.httpServer?.once("listening", () => {
|
|
273
|
+
const addr = server.httpServer?.address();
|
|
274
|
+
if (addr && typeof addr === "object") {
|
|
275
|
+
process.env.HOUDINI_PORT = String(addr.port);
|
|
276
|
+
}
|
|
277
|
+
const root = ctx.config.root_dir;
|
|
278
|
+
const entry = ["+index.tsx", "+index.jsx"].map((f) => path.join(root, "src", f)).find((f) => existsSync(f));
|
|
279
|
+
if (entry) {
|
|
280
|
+
server.ssrLoadModule(entry).catch(() => {
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
server.middlewares.use(async (req, res, next) => {
|
|
285
|
+
if (!req.url) {
|
|
286
|
+
next();
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
const url = req.url.split("?")[0];
|
|
290
|
+
if (url.startsWith("/@") || url.startsWith("/virtual:") || url.startsWith("/node_modules/") || /\.[a-z]+$/i.test(url)) {
|
|
291
|
+
next();
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
const manifest_module = await server.ssrLoadModule(
|
|
295
|
+
path.join(plugin_dir(ctx.config, "houdini-react"), "runtime", "manifest.ts")
|
|
296
|
+
);
|
|
297
|
+
const router_manifest = manifest_module.default;
|
|
298
|
+
for (const id of Object.keys(manifest_module.route_headers ?? {})) {
|
|
299
|
+
if (router_manifest.pages[id]) {
|
|
300
|
+
router_manifest.pages[id].headers = manifest_module.route_headers[id];
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
const { createServerAdapter } = await server.ssrLoadModule(
|
|
304
|
+
adapter_config_path(ctx.config)
|
|
305
|
+
);
|
|
306
|
+
const requestHeaders = new Headers();
|
|
307
|
+
for (const header of Object.entries(req.headers ?? {})) {
|
|
308
|
+
requestHeaders.set(header[0], header[1]);
|
|
309
|
+
}
|
|
310
|
+
const port = server.config.server.port ?? 5173;
|
|
311
|
+
const request = new Request(
|
|
312
|
+
`http://localhost:${port}` + req.url,
|
|
313
|
+
req.method === "POST" ? {
|
|
314
|
+
method: req.method,
|
|
315
|
+
headers: requestHeaders,
|
|
316
|
+
body: await getBody(req)
|
|
317
|
+
} : void 0
|
|
318
|
+
);
|
|
319
|
+
let documentPremable = `<script type="module" src="/@vite/client" async=""></script>`;
|
|
320
|
+
try {
|
|
321
|
+
const transformed = await server.transformIndexHtml(
|
|
322
|
+
req.url,
|
|
323
|
+
"<!DOCTYPE html><html><head></head><body></body></html>"
|
|
324
|
+
);
|
|
325
|
+
const headMatch = transformed.match(/<head>([\s\S]*?)<\/head>/);
|
|
326
|
+
if (headMatch?.[1]?.trim()) {
|
|
327
|
+
documentPremable = headMatch[1].trim();
|
|
328
|
+
}
|
|
329
|
+
} catch {
|
|
330
|
+
}
|
|
331
|
+
const cssLinkSet = /* @__PURE__ */ new Set();
|
|
332
|
+
for (const [url2] of server.moduleGraph.urlToModuleMap) {
|
|
333
|
+
const cleanUrl = url2.split("?")[0];
|
|
334
|
+
if (!cleanUrl.includes("node_modules") && cleanUrl.endsWith(".css") && !cleanUrl.endsWith(".module.css")) {
|
|
335
|
+
cssLinkSet.add(cleanUrl);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
const cssLinks = [...cssLinkSet];
|
|
339
|
+
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
340
|
+
try {
|
|
341
|
+
const result = await createServerAdapter({
|
|
342
|
+
production: false,
|
|
343
|
+
manifest: router_manifest,
|
|
344
|
+
assetPrefix: "/virtual:houdini",
|
|
345
|
+
pipe: res,
|
|
346
|
+
documentPremable,
|
|
347
|
+
cssLinks
|
|
348
|
+
})(request);
|
|
349
|
+
if (result && result.status === 404) {
|
|
350
|
+
return next();
|
|
351
|
+
}
|
|
352
|
+
if (result && typeof result !== "boolean") {
|
|
353
|
+
if (res.closed) {
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
for (const header of result.headers ?? []) {
|
|
357
|
+
res.setHeader(header[0], header[1]);
|
|
358
|
+
}
|
|
359
|
+
if (result.status >= 300 && result.status < 400) {
|
|
360
|
+
res.writeHead(result.status, {
|
|
361
|
+
Location: result.headers.get("Location") ?? "",
|
|
362
|
+
...[...result.headers].reduce(
|
|
363
|
+
(headers, [key, value]) => ({
|
|
364
|
+
...headers,
|
|
365
|
+
[key]: value
|
|
366
|
+
}),
|
|
367
|
+
{}
|
|
368
|
+
)
|
|
369
|
+
});
|
|
370
|
+
} else {
|
|
371
|
+
res.write(await result.text());
|
|
372
|
+
}
|
|
373
|
+
res.end();
|
|
374
|
+
}
|
|
375
|
+
} catch (e) {
|
|
376
|
+
console.error(e);
|
|
377
|
+
res.end();
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
function getBody(request) {
|
|
384
|
+
return new Promise((resolve) => {
|
|
385
|
+
const bodyParts = [];
|
|
386
|
+
let body;
|
|
387
|
+
request.on("data", (chunk) => {
|
|
388
|
+
bodyParts.push(chunk);
|
|
389
|
+
}).on("end", () => {
|
|
390
|
+
body = Buffer.concat(bodyParts).toString();
|
|
391
|
+
resolve(body);
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
export {
|
|
396
|
+
index_default as default
|
|
397
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function strip_named_export(script: any, name: string): void;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
function strip_named_export(script, name) {
|
|
2
|
+
const body = script.body;
|
|
3
|
+
for (let i = body.length - 1; i >= 0; i--) {
|
|
4
|
+
const node = body[i];
|
|
5
|
+
if (node.type !== "ExportNamedDeclaration") {
|
|
6
|
+
continue;
|
|
7
|
+
}
|
|
8
|
+
if (node.declaration) {
|
|
9
|
+
const decl = node.declaration;
|
|
10
|
+
if (decl.type === "FunctionDeclaration" && decl.id?.name === name) {
|
|
11
|
+
body.splice(i, 1);
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
if (decl.type === "VariableDeclaration") {
|
|
15
|
+
decl.declarations = decl.declarations.filter(
|
|
16
|
+
(d) => !(d.id?.type === "Identifier" && d.id.name === name)
|
|
17
|
+
);
|
|
18
|
+
if (decl.declarations.length === 0) {
|
|
19
|
+
body.splice(i, 1);
|
|
20
|
+
}
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (node.specifiers?.length) {
|
|
26
|
+
node.specifiers = node.specifiers.filter((s) => s.exported?.name !== name);
|
|
27
|
+
if (node.specifiers.length === 0) {
|
|
28
|
+
body.splice(i, 1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
strip_named_export
|
|
35
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TransformPage } from 'houdini';
|
|
2
|
+
import type { SourceMapInput } from 'rollup';
|
|
3
|
+
export type ComponentFieldRow = {
|
|
4
|
+
type: string;
|
|
5
|
+
field: string;
|
|
6
|
+
fragment: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function transform_file(page: TransformPage, cfRows: ComponentFieldRow[], opts?: {
|
|
9
|
+
stripHeaders?: boolean;
|
|
10
|
+
}): Promise<{
|
|
11
|
+
code: string;
|
|
12
|
+
map?: SourceMapInput;
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import * as graphql from "graphql";
|
|
2
|
+
import {
|
|
3
|
+
ArtifactKind,
|
|
4
|
+
artifact_import,
|
|
5
|
+
ensure_imports,
|
|
6
|
+
find_graphql,
|
|
7
|
+
parseJS,
|
|
8
|
+
path,
|
|
9
|
+
printJS
|
|
10
|
+
} from "houdini";
|
|
11
|
+
import { componentField_unit_path, houdini_root } from "houdini/router/conventions";
|
|
12
|
+
import * as recast from "recast";
|
|
13
|
+
import { strip_named_export } from "./strip-headers.js";
|
|
14
|
+
const AST = recast.types.builders;
|
|
15
|
+
async function transform_file(page, cfRows, opts = {}) {
|
|
16
|
+
const isJSX = page.filepath.endsWith(".tsx") || page.filepath.endsWith(".jsx");
|
|
17
|
+
if (!isJSX && !page.filepath.endsWith(".ts") && !page.filepath.endsWith(".js")) {
|
|
18
|
+
return { code: page.content, map: page.map };
|
|
19
|
+
}
|
|
20
|
+
const script = parseJS(page.content, isJSX ? { plugins: ["jsx"] } : {});
|
|
21
|
+
if (opts.stripHeaders) {
|
|
22
|
+
strip_named_export(script, "headers");
|
|
23
|
+
}
|
|
24
|
+
const cfMap = {};
|
|
25
|
+
for (const row of cfRows) {
|
|
26
|
+
if (row.type && row.field && row.fragment) {
|
|
27
|
+
cfMap[row.type] ??= {};
|
|
28
|
+
cfMap[row.type][row.field] = row.fragment;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
await find_graphql(page.config, script, {
|
|
32
|
+
skipGraphqlType: true,
|
|
33
|
+
tag({ node, artifact, parsedDocument }) {
|
|
34
|
+
const { id: artifactRef } = artifact_import({ page, script, artifact });
|
|
35
|
+
const properties = [AST.objectProperty(AST.stringLiteral("artifact"), artifactRef)];
|
|
36
|
+
if (is_paginated(parsedDocument) || is_refetchable(parsedDocument)) {
|
|
37
|
+
if (artifact.kind !== ArtifactKind.Query) {
|
|
38
|
+
const refetchName = artifact.name + (is_paginated(parsedDocument) ? "_Pagination_Query" : "_Refetch_Query");
|
|
39
|
+
const { id: refetchRef } = artifact_import({
|
|
40
|
+
page,
|
|
41
|
+
script,
|
|
42
|
+
artifact: { name: refetchName }
|
|
43
|
+
});
|
|
44
|
+
properties.push(
|
|
45
|
+
AST.objectProperty(AST.stringLiteral("refetchArtifact"), refetchRef)
|
|
46
|
+
);
|
|
47
|
+
} else {
|
|
48
|
+
properties.push(
|
|
49
|
+
AST.objectProperty(AST.stringLiteral("refetchArtifact"), artifactRef)
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (Object.keys(cfMap).length > 0) {
|
|
54
|
+
const typeInfo = new graphql.TypeInfo(page.config.schema);
|
|
55
|
+
graphql.visit(
|
|
56
|
+
parsedDocument,
|
|
57
|
+
graphql.visitWithTypeInfo(typeInfo, {
|
|
58
|
+
Field(fieldNode) {
|
|
59
|
+
const parentType = typeInfo.getParentType();
|
|
60
|
+
const typeName = parentType?.name;
|
|
61
|
+
if (!typeName) return;
|
|
62
|
+
const fragmentName = cfMap[typeName]?.[fieldNode.name.value];
|
|
63
|
+
if (!fragmentName) return;
|
|
64
|
+
const entryPointPath = componentField_unit_path(
|
|
65
|
+
page.config,
|
|
66
|
+
fragmentName
|
|
67
|
+
);
|
|
68
|
+
ensure_imports({
|
|
69
|
+
script,
|
|
70
|
+
sourceModule: "$houdini/" + path.relative(houdini_root(page.config), entryPointPath)
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
node.replaceWith(AST.objectExpression(properties));
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return printJS(script);
|
|
80
|
+
}
|
|
81
|
+
function is_paginated(doc) {
|
|
82
|
+
let paginated = false;
|
|
83
|
+
graphql.visit(doc, {
|
|
84
|
+
Directive(node) {
|
|
85
|
+
if (node.name.value === "paginate") {
|
|
86
|
+
paginated = true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
return paginated;
|
|
91
|
+
}
|
|
92
|
+
function is_refetchable(doc) {
|
|
93
|
+
let refetchable = false;
|
|
94
|
+
graphql.visit(doc, {
|
|
95
|
+
Directive(node) {
|
|
96
|
+
if (node.name.value === "refetchable") {
|
|
97
|
+
refetchable = true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
return refetchable;
|
|
102
|
+
}
|
|
103
|
+
export {
|
|
104
|
+
transform_file
|
|
105
|
+
};
|
package/README.md
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
<picture>
|
|
3
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/HoudiniGraphql/houdini/main/.github/assets/logo_l.svg">
|
|
4
|
-
<img height="140" alt="Houdini's logo (dark or light)" src="https://raw.githubusercontent.com/HoudiniGraphql/houdini/main/.github/assets/logo_d.svg">
|
|
5
|
-
</picture>
|
|
6
|
-
<br />
|
|
7
|
-
<br />
|
|
8
|
-
<strong>
|
|
9
|
-
The disappearing GraphQL clients.
|
|
10
|
-
</strong>
|
|
11
|
-
<br />
|
|
12
|
-
<br />
|
|
13
|
-
<a href="https://npmjs.org/package/houdini">
|
|
14
|
-
<img src="https://img.shields.io/npm/v/houdini.svg" alt="version" />
|
|
15
|
-
</a>
|
|
16
|
-
<a href="https://github.com/HoudiniGraphql/houdini/actions">
|
|
17
|
-
<img src="https://github.com/HoudiniGraphql/houdini/actions/workflows/tests.yml/badge.svg" alt="CI Tests" />
|
|
18
|
-
</a>
|
|
19
|
-
<a href="https://github.com/HoudiniGraphql/houdini">
|
|
20
|
-
<img src="https://img.shields.io/github/stars/HoudiniGraphql/houdini.svg?label=stars" alt="github stars" />
|
|
21
|
-
</a>
|
|
22
|
-
<a href="https://npmjs.org/package/houdini">
|
|
23
|
-
<img src="https://img.shields.io/npm/dm/houdini.svg" alt="downloads" />
|
|
24
|
-
</a>
|
|
25
|
-
<a href="https://github.com/HoudiniGraphql/houdini/blob/main/LICENSE">
|
|
26
|
-
<img src="https://img.shields.io/github/license/HoudiniGraphql/houdini.svg?maxAge=2592000" alt="license" />
|
|
27
|
-
</a>
|
|
28
|
-
</div>
|
|
29
|
-
|
|
30
|
-
----
|
|
31
|
-
|
|
32
|
-
At its core, houdini seeks to enable a high quality developer experience
|
|
33
|
-
without compromising bundle size. Like Svelte, houdini shifts what is
|
|
34
|
-
traditionally handled by a bloated runtime into a compile step that allows
|
|
35
|
-
for the generation of an incredibly lean GraphQL abstraction for your application.
|
|
36
|
-
See more at <a href="https://www.houdinigraphql.com">HoudiniGraphQL.com</a> 🚀
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type Config, type ProjectManifest, type Document } from 'houdini';
|
|
2
|
-
export declare function generate_routing_document_wrappers({ manifest, config, documents, }: {
|
|
3
|
-
manifest: ProjectManifest;
|
|
4
|
-
config: Config;
|
|
5
|
-
documents: Record<string, Document>;
|
|
6
|
-
}): Promise<void[]>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Config, ProjectManifest, PageManifest, Document } from 'houdini';
|
|
2
|
-
import type { ComponentFieldData } from '..';
|
|
3
|
-
export declare function generate_entries({ config, manifest, documents, componentFields, }: {
|
|
4
|
-
config: Config;
|
|
5
|
-
manifest: ProjectManifest;
|
|
6
|
-
documents: Document[];
|
|
7
|
-
componentFields: ComponentFieldData[];
|
|
8
|
-
}): Promise<void>;
|
|
9
|
-
export type PageBundleInput = {
|
|
10
|
-
id: string;
|
|
11
|
-
page: PageManifest;
|
|
12
|
-
project: ProjectManifest;
|
|
13
|
-
config: Config;
|
|
14
|
-
documents: Record<string, Document>;
|
|
15
|
-
componentFields: ComponentFieldData[];
|
|
16
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Config, GenerateHookInput, ProjectManifest } from 'houdini';
|
|
2
|
-
import { processComponentFieldDirective } from 'houdini';
|
|
3
|
-
/**
|
|
4
|
-
* The router is fundamentally a component that knows how to render
|
|
5
|
-
* a particular component tree for a given url. This is driven by something
|
|
6
|
-
* we call the applications "manifest".
|
|
7
|
-
*
|
|
8
|
-
* In react, the tree of route directories maps to a component hierarchy
|
|
9
|
-
* with suspense boundaries sprinkled when there is a loading directive
|
|
10
|
-
* present on a query.
|
|
11
|
-
*/
|
|
12
|
-
export default function routerCodegen({ config, manifest, documents, }: GenerateHookInput & {
|
|
13
|
-
manifest: ProjectManifest;
|
|
14
|
-
}): Promise<void>;
|
|
15
|
-
export type ComponentFieldData = ReturnType<typeof processComponentFieldDirective> & Config['componentFields'][string][string] & {
|
|
16
|
-
type: string;
|
|
17
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type Config, type ProjectManifest } from 'houdini';
|
|
2
|
-
import type { ComponentFieldData } from '.';
|
|
3
|
-
export declare function generate_renders({ componentFields, config, manifest, }: {
|
|
4
|
-
componentFields: ComponentFieldData[];
|
|
5
|
-
config: Config;
|
|
6
|
-
manifest: ProjectManifest;
|
|
7
|
-
}): Promise<void>;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type Config, type ProjectManifest } from 'houdini';
|
|
2
|
-
export declare function format_router_manifest({ config, manifest, exportDefaultStatement, }: {
|
|
3
|
-
config: Config;
|
|
4
|
-
manifest: ProjectManifest;
|
|
5
|
-
exportDefaultStatement: (name: string) => string;
|
|
6
|
-
importStatement: (from: string, as: string) => string;
|
|
7
|
-
}): string;
|
package/build/plugin/config.d.ts
DELETED