houdini-adapter-static 1.2.51

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Alec Aivazis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ import { type Adapter } from 'houdini';
2
+ declare const adapter: Adapter;
3
+ export default adapter;
package/build/index.js ADDED
@@ -0,0 +1,65 @@
1
+ // @ts-nocheck
2
+ import { fs } from 'houdini';
3
+ import path from 'node:path';
4
+ import React from 'react';
5
+ import ReactDOM from 'react-dom/server';
6
+ // in order to prepare the app as a single-page app, we have 2 create 2 additional files:
7
+ // - 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
8
+ // - an index.html containing the static shell that wraps the application.
9
+ const adapter = async ({ outDir }) => {
10
+ // the first thing we need to do is pull out the rendered html file into the root of the outDir
11
+ await fs.copyFile(path.join(outDir, 'assets', '$houdini', 'temp', 'spa-shell', 'index.html'), path.join(outDir, 'index.html'));
12
+ try {
13
+ await fs.rmdir(path.join(outDir, 'assets', '$houdini'));
14
+ }
15
+ catch { }
16
+ };
17
+ // make sure we include the app entry point in the bundle
18
+ adapter.includePaths = {
19
+ shell: '$houdini/temp/spa-shell/index.html',
20
+ };
21
+ // we dont want any server artifacts to be generated
22
+ adapter.disableServer = true;
23
+ adapter.pre = async ({ config, outDir, conventions }) => {
24
+ // before we do anything, we need to ensure the user isn't using a local API
25
+ if (config.localSchema) {
26
+ throw new Error("Houdini's SPA adapter cannot be used if your project relies on a local schema");
27
+ }
28
+ process.env.HOUDINI_SECONDARY_BUILD = 'true';
29
+ const { build } = await import('vite');
30
+ const shellDir = conventions.temp_dir(config, 'spa-shell');
31
+ // before we can import and render the user's index file, we need to compile it with vite
32
+ await build({
33
+ build: {
34
+ emptyOutDir: false,
35
+ ssr: true,
36
+ rollupOptions: {
37
+ output: {
38
+ dir: shellDir,
39
+ entryFileNames: '[name].js',
40
+ },
41
+ },
42
+ lib: {
43
+ entry: {
44
+ shell: conventions.router_index_path(config),
45
+ },
46
+ formats: ['es'],
47
+ },
48
+ },
49
+ });
50
+ process.env.HOUDINI_SECONDARY_BUILD = 'false';
51
+ // now we can import the bundled shell
52
+ const { default: App } = await import(path.join(shellDir, 'shell.js'));
53
+ // render the index.jsx file to generate the static html that
54
+ // we can use to wrap the ajvascript application
55
+ let shellContents = ReactDOM.renderToStaticMarkup(React.createElement(App, {
56
+ children: [
57
+ React.createElement('div', {
58
+ id: 'app',
59
+ }),
60
+ ],
61
+ })).replace('</head>', "<script type='module' src='virtual:houdini/static-entry'></script></head>");
62
+ // write the shell to the outDir
63
+ await fs.writeFile(path.join(shellDir, 'index.html'), shellContents);
64
+ };
65
+ export default adapter;
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "houdini-adapter-static",
3
+ "version": "1.2.51",
4
+ "description": "The adapter for deploying your Houdini application as a single-page application without a server component",
5
+ "keywords": [
6
+ "houdini",
7
+ "adpter",
8
+ "node"
9
+ ],
10
+ "homepage": "https://github.com/HoudiniGraphql/houdini",
11
+ "funding": "https://github.com/sponsors/HoudiniGraphql",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/HoudiniGraphql/houdini.git"
15
+ },
16
+ "license": "MIT",
17
+ "type": "module",
18
+ "devDependencies": {
19
+ "@types/react-dom": "^18.3.0",
20
+ "@types/node": "^18.7.23",
21
+ "csstype": "^3.1.3",
22
+ "tsup": "^7.2.0",
23
+ "typescript": "^5.5.4",
24
+ "scripts": "^1.0.0"
25
+ },
26
+ "dependencies": {
27
+ "react": "19.0.0-rc-eb259b5d3b-20240605",
28
+ "react-dom": "19.0.0-rc-eb259b5d3b-20240605",
29
+ "vite": "^4.1.4",
30
+ "houdini": "^1.2.51"
31
+ },
32
+ "files": [
33
+ "build"
34
+ ],
35
+ "exports": {
36
+ "./package.json": "./package.json",
37
+ ".": {
38
+ "import": "./build/index.js",
39
+ "require": "./build/index.cjs"
40
+ }
41
+ },
42
+ "types": "./build/index.d.ts",
43
+ "typesVersions": {
44
+ "*": {
45
+ "app": [
46
+ "build/app.d.ts"
47
+ ]
48
+ }
49
+ },
50
+ "scripts": {
51
+ "build": "npx tsc src/* --allowJs --outDir build --module esnext --target esnext --allowSyntheticDefaultImports --declaration || exit 0 ",
52
+ "build:": "cd ../../ && ((run build && cd -) || (cd - && exit 1))",
53
+ "build:build": "pnpm build: && pnpm build"
54
+ }
55
+ }