-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e57e9f6
commit 9090197
Showing
34 changed files
with
17,519 additions
and
12,367 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'houdini': patch | ||
--- | ||
|
||
Add necessary infrastructure to support spa adapter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'houdini-adapter-static': patch | ||
--- | ||
|
||
initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# houdini-adapter-static |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"name": "houdini-adapter-static", | ||
"version": "1.2.49", | ||
"description": "The adapter for deploying your Houdini application as a single-page application without a server component", | ||
"keywords": [ | ||
"houdini", | ||
"adpter", | ||
"node" | ||
], | ||
"homepage": "https://github.com/HoudiniGraphql/houdini", | ||
"funding": "https://github.com/sponsors/HoudiniGraphql", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/HoudiniGraphql/houdini.git" | ||
}, | ||
"license": "MIT", | ||
"type": "module", | ||
"scripts": { | ||
"build": "npx tsc src/* --allowJs --outDir build --module esnext --target esnext --allowSyntheticDefaultImports --declaration || exit 0 ", | ||
"build:": "cd ../../ && ((run build && cd -) || (cd - && exit 1))", | ||
"build:build": "pnpm build: && pnpm build" | ||
}, | ||
"devDependencies": { | ||
"@types/react-dom": "^18.3.0", | ||
"@types/node": "^18.7.23", | ||
"csstype": "^3.1.3", | ||
"scripts": "workspace:^", | ||
"tsup": "^7.2.0", | ||
"typescript": "^5.5.4" | ||
}, | ||
"dependencies": { | ||
"houdini": "workspace:^", | ||
"react": "19.0.0-rc-eb259b5d3b-20240605", | ||
"react-dom": "19.0.0-rc-eb259b5d3b-20240605", | ||
"vite": "^4.1.4" | ||
}, | ||
"files": [ | ||
"build" | ||
], | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": { | ||
"import": "./build/index.js", | ||
"require": "./build/index.cjs" | ||
} | ||
}, | ||
"types": "./build/index.d.ts", | ||
"typesVersions": { | ||
"*": { | ||
"app": [ | ||
"build/app.d.ts" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// @ts-nocheck | ||
import { fs, type Adapter } from 'houdini' | ||
import path from 'node:path' | ||
import React from 'react' | ||
import ReactDOM from 'react-dom/server' | ||
|
||
// in order to prepare the app as a single-page app, we have 2 create 2 additional files: | ||
// - an index.js that imports the application and calls React.render. This file needs to be built by vite so it's passed with the includePaths option for an adapter | ||
// - an index.html containing the static shell that wraps the application. | ||
const adapter: Adapter = async ({ outDir }) => { | ||
// the first thing we need to do is pull out the rendered html file into the root of the outDir | ||
await fs.copyFile( | ||
path.join(outDir, 'assets', '$houdini', 'temp', 'spa-shell', 'index.html'), | ||
path.join(outDir, 'index.html') | ||
) | ||
|
||
try { | ||
await fs.rmdir(path.join(outDir, 'assets', '$houdini')) | ||
} catch {} | ||
} | ||
|
||
// make sure we include the app entry point in the bundle | ||
adapter.includePaths = { | ||
shell: '$houdini/temp/spa-shell/index.html', | ||
} | ||
|
||
// we dont want any server artifacts to be generated | ||
adapter.disableServer = true | ||
|
||
adapter.pre = async ({ config, outDir, conventions }) => { | ||
// before we do anything, we need to ensure the user isn't using a local API | ||
if (config.localSchema) { | ||
throw new Error( | ||
"Houdini's SPA adapter cannot be used if your project relies on a local schema" | ||
) | ||
} | ||
|
||
process.env.HOUDINI_SECONDARY_BUILD = 'true' | ||
|
||
const { build } = await import('vite') | ||
|
||
const shellDir = conventions.temp_dir(config, 'spa-shell') | ||
|
||
// before we can import and render the user's index file, we need to compile it with vite | ||
await build({ | ||
build: { | ||
emptyOutDir: false, | ||
ssr: true, | ||
rollupOptions: { | ||
output: { | ||
dir: shellDir, | ||
entryFileNames: '[name].js', | ||
}, | ||
}, | ||
lib: { | ||
entry: { | ||
shell: conventions.router_index_path(config), | ||
}, | ||
formats: ['es'], | ||
}, | ||
}, | ||
}) | ||
|
||
process.env.HOUDINI_SECONDARY_BUILD = 'false' | ||
|
||
// now we can import the bundled shell | ||
const { default: App } = await import(path.join(shellDir, 'shell.js')) | ||
|
||
// render the index.jsx file to generate the static html that | ||
// we can use to wrap the ajvascript application | ||
let shellContents = ReactDOM.renderToStaticMarkup( | ||
React.createElement(App, { | ||
children: [ | ||
React.createElement('div', { | ||
id: 'app', | ||
}), | ||
], | ||
}) | ||
).replace( | ||
'</head>', | ||
"<script type='module' src='virtual:houdini/static-entry'></script></head>" | ||
) | ||
|
||
// write the shell to the outDir | ||
await fs.writeFile(path.join(shellDir, 'index.html'), shellContents) | ||
} | ||
|
||
export default adapter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.