@quilted/create 0.3.0 → 0.3.2

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.
Files changed (71) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/build/esm/_virtual/index7.mjs +2 -2
  3. package/build/esm/_virtual/index8.mjs +2 -2
  4. package/build/esm/node_modules/.pnpm/@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/index.mjs +1 -1
  5. package/build/esm/node_modules/.pnpm/@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/providers/async.mjs +1 -1
  6. package/build/esm/node_modules/.pnpm/@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/providers/sync.mjs +1 -1
  7. package/build/esm/node_modules/.pnpm/@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/settings.mjs +1 -1
  8. package/build/esm/node_modules/.pnpm/@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/index.mjs +1 -1
  9. package/build/esm/node_modules/.pnpm/@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/providers/async.mjs +1 -1
  10. package/build/esm/node_modules/.pnpm/@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/providers/sync.mjs +1 -1
  11. package/build/esm/node_modules/.pnpm/@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/settings.mjs +1 -1
  12. package/build/esm/node_modules/.pnpm/dir-glob@3.0.1/node_modules/dir-glob/index.mjs +1 -1
  13. package/build/esm/node_modules/.pnpm/fast-glob@3.3.3/node_modules/fast-glob/out/utils/index.mjs +1 -1
  14. package/build/esm/node_modules/.pnpm/prettier@3.5.1/node_modules/prettier/plugins/typescript.mjs +1 -1
  15. package/build/esnext/_virtual/index7.esnext +2 -2
  16. package/build/esnext/_virtual/index8.esnext +2 -2
  17. package/build/esnext/node_modules/.pnpm/@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/index.esnext +1 -1
  18. package/build/esnext/node_modules/.pnpm/@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/index.esnext +1 -1
  19. package/build/esnext/node_modules/.pnpm/dir-glob@3.0.1/node_modules/dir-glob/index.esnext +1 -1
  20. package/build/esnext/node_modules/.pnpm/fast-glob@3.3.3/node_modules/fast-glob/out/readers/stream.esnext +1 -1
  21. package/build/esnext/node_modules/.pnpm/fast-glob@3.3.3/node_modules/fast-glob/out/utils/index.esnext +1 -1
  22. package/build/esnext/node_modules/.pnpm/fast-glob@3.3.3/node_modules/fast-glob/out/utils/stream.esnext +1 -1
  23. package/build/esnext/node_modules/.pnpm/prettier@3.5.1/node_modules/prettier/plugins/typescript.esnext +2 -2
  24. package/package.json +1 -1
  25. package/templates/app-basic/App.tsx +8 -3
  26. package/templates/app-basic/browser.css +10 -0
  27. package/templates/app-basic/browser.tsx +8 -12
  28. package/templates/app-basic/context/browser.ts +10 -0
  29. package/templates/app-basic/context/navigation.ts +17 -0
  30. package/templates/app-basic/{shared/context.ts → context/preact.ts} +1 -1
  31. package/templates/app-basic/context/server.ts +10 -0
  32. package/templates/app-basic/context/types.ts +5 -0
  33. package/templates/app-basic/foundation/frame/Frame.module.css +0 -11
  34. package/templates/app-basic/server.tsx +5 -14
  35. package/templates/app-basic/tests/render/render.tsx +8 -5
  36. package/templates/app-basic/tests/render/types.ts +2 -2
  37. package/templates/app-basic/tsconfig.json +2 -4
  38. package/templates/app-graphql/App.tsx +4 -3
  39. package/templates/app-graphql/browser.css +10 -0
  40. package/templates/app-graphql/browser.tsx +9 -23
  41. package/templates/app-graphql/context/browser.ts +21 -0
  42. package/templates/app-graphql/context/navigation.ts +17 -0
  43. package/templates/{app-trpc/shared/context.ts → app-graphql/context/preact.ts} +1 -1
  44. package/templates/app-graphql/context/server.ts +23 -0
  45. package/templates/app-graphql/context/types.ts +10 -0
  46. package/templates/app-graphql/server.tsx +4 -24
  47. package/templates/app-graphql/tests/render/render.tsx +13 -10
  48. package/templates/app-graphql/tests/render/types.ts +9 -4
  49. package/templates/app-graphql/tsconfig.json +1 -1
  50. package/templates/app-trpc/App.tsx +5 -7
  51. package/templates/app-trpc/browser.css +10 -0
  52. package/templates/app-trpc/browser.tsx +9 -23
  53. package/templates/app-trpc/context/browser.ts +20 -0
  54. package/templates/app-trpc/context/navigation.ts +17 -0
  55. package/templates/{app-graphql/shared/context.ts → app-trpc/context/preact.ts} +1 -1
  56. package/templates/app-trpc/context/server.ts +18 -0
  57. package/templates/app-trpc/context/trpc.ts +6 -0
  58. package/templates/app-trpc/context/types.ts +11 -0
  59. package/templates/app-trpc/features/home/Home.tsx +1 -1
  60. package/templates/app-trpc/server.tsx +4 -19
  61. package/templates/app-trpc/tests/render/render.tsx +11 -6
  62. package/templates/app-trpc/tests/render/types.ts +2 -2
  63. package/templates/app-trpc/tsconfig.json +1 -1
  64. package/templates/github/_github/workflows/actions/prepare/action.yml +6 -3
  65. package/templates/github/_github/workflows/ci.yml +7 -4
  66. package/templates/workspace/package.json +5 -5
  67. package/templates/app-basic/shared/navigation.ts +0 -15
  68. package/templates/app-graphql/shared/graphql.ts +0 -22
  69. package/templates/app-graphql/shared/navigation.ts +0 -15
  70. package/templates/app-trpc/shared/navigation.ts +0 -15
  71. package/templates/app-trpc/shared/trpc.ts +0 -18
@@ -1,3 +1,3 @@
1
- var dirGlob = {exports: {}};
1
+ var utils = {};
2
2
 
3
- export { dirGlob as __module };
3
+ export { utils as __exports };
@@ -1,3 +1,3 @@
1
- var utils = {};
1
+ var dirGlob = {exports: {}};
2
2
 
3
- export { utils as __exports };
3
+ export { dirGlob as __module };
@@ -1,4 +1,4 @@
1
- import { __exports as out } from '../../../../../../../_virtual/index11.esnext';
1
+ import { __exports as out } from '../../../../../../../_virtual/index10.esnext';
2
2
  import { __require as requireAsync } from './providers/async.esnext';
3
3
  import { __require as requireSync } from './providers/sync.esnext';
4
4
  import { __require as requireSettings } from './settings.esnext';
@@ -1,4 +1,4 @@
1
- import { __exports as out } from '../../../../../../../_virtual/index10.esnext';
1
+ import { __exports as out } from '../../../../../../../_virtual/index11.esnext';
2
2
  import { __require as requireAsync } from './providers/async.esnext';
3
3
  import { __require as requireStream } from './providers/stream.esnext';
4
4
  import { __require as requireSync } from './providers/sync.esnext';
@@ -1,4 +1,4 @@
1
- import { __module as dirGlob } from '../../../../../_virtual/index7.esnext';
1
+ import { __module as dirGlob } from '../../../../../_virtual/index8.esnext';
2
2
  import path__default from 'node:path';
3
3
  import { __require as requirePathType } from '../../../path-type@4.0.0/node_modules/path-type/index.esnext';
4
4
 
@@ -1,4 +1,4 @@
1
- import { __exports as stream } from '../../../../../../../_virtual/stream2.esnext';
1
+ import { __exports as stream } from '../../../../../../../_virtual/stream3.esnext';
2
2
  import require$$0 from 'node:stream';
3
3
  import { __require as requireOut } from '../../../../../@nodelib_fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/index.esnext';
4
4
  import { __require as requireOut$1 } from '../../../../../@nodelib_fs.walk@1.2.8/node_modules/@nodelib/fs.walk/out/index.esnext';
@@ -1,4 +1,4 @@
1
- import { __exports as utils } from '../../../../../../../_virtual/index8.esnext';
1
+ import { __exports as utils } from '../../../../../../../_virtual/index7.esnext';
2
2
  import { __require as requireArray } from './array.esnext';
3
3
  import { __require as requireErrno } from './errno.esnext';
4
4
  import { __require as requireFs } from './fs.esnext';
@@ -1,4 +1,4 @@
1
- import { __exports as stream } from '../../../../../../../_virtual/stream3.esnext';
1
+ import { __exports as stream } from '../../../../../../../_virtual/stream2.esnext';
2
2
  import { __require as requireMerge2 } from '../../../../../merge2@1.4.1/node_modules/merge2/index.esnext';
3
3
 
4
4
  var hasRequiredStream;
@@ -3516,10 +3516,10 @@ function z2(e, t) {
3516
3516
  return V2(e) & t;
3517
3517
  }
3518
3518
  function F2(e, t, a) {
3519
- return e.kind >= 0 && e.kind <= 165 ? 0 : (e.modifierFlagsCache & 536870912 || (e.modifierFlagsCache = T1(e) | 536870912), W2(e.modifierFlagsCache));
3519
+ return e.kind >= 0 && e.kind <= 165 ? 0 : (e.modifierFlagsCache & 536870912 || (e.modifierFlagsCache = T1(e) | 536870912), a || t && ea(e) ? (!(e.modifierFlagsCache & 268435456) && e.parent && (e.modifierFlagsCache |= b1(e) | 268435456), v1(e.modifierFlagsCache)) : W2(e.modifierFlagsCache));
3520
3520
  }
3521
3521
  function V2(e) {
3522
- return F2(e);
3522
+ return F2(e, false);
3523
3523
  }
3524
3524
  function b1(e) {
3525
3525
  let t = 0;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@quilted/create",
3
3
  "type": "module",
4
- "version": "0.3.0",
4
+ "version": "0.3.2",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -7,8 +7,9 @@ import {Frame} from './foundation/frame.ts';
7
7
 
8
8
  import {Home} from './features/home.ts';
9
9
 
10
- import {AppContextPreact, type AppContext} from './shared/context.ts';
11
- import {routeWithAppContext} from './shared/navigation.ts';
10
+ import type {AppContext} from './context/types.ts';
11
+ import {AppContextPreact} from './context/preact.ts';
12
+ import {routeWithAppContext} from './context/navigation.ts';
12
13
 
13
14
  export interface AppProps {
14
15
  context: AppContext;
@@ -38,7 +39,11 @@ export function App({context}: AppProps) {
38
39
  <AppContextPreact.Provider value={context}>
39
40
  <Localization>
40
41
  <Head />
41
- <Navigation router={context.router} routes={routes} context={context} />
42
+ <Navigation
43
+ router={context.navigation.router}
44
+ routes={routes}
45
+ context={context}
46
+ />
42
47
  </Localization>
43
48
  </AppContextPreact.Provider>
44
49
  );
@@ -0,0 +1,10 @@
1
+ *,
2
+ *::before,
3
+ *::after {
4
+ box-sizing: border-box;
5
+ }
6
+
7
+ html,
8
+ body {
9
+ margin: 0;
10
+ }
@@ -1,18 +1,11 @@
1
+ import './browser.css';
2
+
1
3
  import type {ComponentChild} from 'preact';
2
4
  import {hydrate} from '@quilted/quilt/browser';
3
- import {Router} from '@quilted/quilt/navigation';
4
5
 
5
- import type {AppContext} from '~/shared/context.ts';
6
+ import {BrowserAppContext} from '~/context/browser.ts';
6
7
  import {App} from './App.tsx';
7
8
 
8
- class BrowserAppContext implements AppContext {
9
- readonly router: Router;
10
-
11
- constructor() {
12
- this.router = new Router();
13
- }
14
- }
15
-
16
9
  class BrowserApp {
17
10
  /**
18
11
  * The app’s globally-available context.
@@ -42,8 +35,11 @@ class BrowserApp {
42
35
  writable: true,
43
36
  });
44
37
  }
38
+
39
+ hydrate() {
40
+ hydrate(this.rendered);
41
+ }
45
42
  }
46
43
 
47
44
  const app = new BrowserApp();
48
-
49
- hydrate(app.rendered);
45
+ app.hydrate();
@@ -0,0 +1,10 @@
1
+ import type {AppContext} from './types.ts';
2
+ import {NavigationForApp} from './navigation.ts';
3
+
4
+ export class BrowserAppContext implements AppContext {
5
+ readonly navigation: NavigationForApp;
6
+
7
+ constructor() {
8
+ this.navigation = new NavigationForApp();
9
+ }
10
+ }
@@ -0,0 +1,17 @@
1
+ import {createContextRouteFunction, Router} from '@quilted/quilt/navigation';
2
+
3
+ import type {AppContext} from './types.ts';
4
+
5
+ export interface Navigation {
6
+ readonly router: Router;
7
+ }
8
+
9
+ export class NavigationForApp implements Navigation {
10
+ readonly router: Router;
11
+
12
+ constructor(url?: string | URL) {
13
+ this.router = new Router(url);
14
+ }
15
+ }
16
+
17
+ export const routeWithAppContext = createContextRouteFunction<AppContext>();
@@ -1,6 +1,6 @@
1
1
  import {createOptionalContext} from '@quilted/quilt/context';
2
2
 
3
- export interface AppContext {}
3
+ import type {AppContext} from './types.ts';
4
4
 
5
5
  export const AppContextPreact = createOptionalContext<AppContext>();
6
6
  export const useAppContext = AppContextPreact.use;
@@ -0,0 +1,10 @@
1
+ import type {AppContext} from './types.ts';
2
+ import {NavigationForApp} from './navigation.ts';
3
+
4
+ export class ServerAppContext implements AppContext {
5
+ readonly navigation: NavigationForApp;
6
+
7
+ constructor(request: Request) {
8
+ this.navigation = new NavigationForApp(request.url);
9
+ }
10
+ }
@@ -0,0 +1,5 @@
1
+ import type {Navigation} from './navigation.ts';
2
+
3
+ export interface AppContext {
4
+ readonly navigation: Navigation;
5
+ }
@@ -1,14 +1,3 @@
1
- *,
2
- *::before,
3
- *::after {
4
- box-sizing: border-box;
5
- }
6
-
7
- html,
8
- body {
9
- margin: 0;
10
- }
11
-
12
1
  .Frame {
13
2
  padding: 1rem;
14
3
  }
@@ -6,30 +6,21 @@ import {
6
6
  PermissionsPolicyHeader,
7
7
  StrictTransportSecurityHeader,
8
8
  } from '@quilted/quilt/server';
9
- import {Router} from '@quilted/quilt/navigation';
10
-
11
9
  import Env from 'quilt:module/env';
12
10
  import {BrowserAssets} from 'quilt:module/assets';
13
11
 
14
- import type {AppContext} from '~/shared/context.ts';
15
-
16
- import {App} from './App.tsx';
17
-
18
12
  const app = new Hono();
19
13
  const assets = new BrowserAssets();
20
14
 
21
- class ServerAppContext implements AppContext {
22
- readonly router: Router;
23
-
24
- constructor(request: Request) {
25
- this.router = new Router(request.url);
26
- }
27
- }
28
-
29
15
  // For all GET requests, render our Preact application.
30
16
  app.get('*', async (c) => {
31
17
  const request = c.req.raw;
32
18
 
19
+ const [{App}, {ServerAppContext}] = await Promise.all([
20
+ import('./App.tsx'),
21
+ import('./context/server.ts'),
22
+ ]);
23
+
33
24
  const context = new ServerAppContext(request);
34
25
 
35
26
  const isHttps = request.url.startsWith('https://');
@@ -6,7 +6,7 @@ import {
6
6
  import {Navigation, TestRouter} from '@quilted/quilt/navigation/testing';
7
7
  import {Localization} from '@quilted/quilt/localize';
8
8
 
9
- import {AppContextReact} from '~/shared/context.ts';
9
+ import {AppContextPreact} from '~/context/preact.ts';
10
10
 
11
11
  import {RenderOptions, RenderContext, RenderActions} from './types.ts';
12
12
 
@@ -24,20 +24,23 @@ export const renderApp = createRender<
24
24
  // authors on the `root.context` property. Context is used to share data between your
25
25
  // React tree and your test code, and is ideal for mocking out global context providers.
26
26
  context({router = new TestRouter(), browser = new BrowserTestMock()}) {
27
- return {router, browser};
27
+ return {navigation: {router}, browser};
28
28
  },
29
29
  // Render all of our app-wide context providers around each component under test.
30
30
  render(element, context, {locale = 'en'}) {
31
- const {router, browser} = context;
31
+ const {
32
+ navigation: {router},
33
+ browser,
34
+ } = context;
32
35
 
33
36
  return (
34
- <AppContextReact.Provider value={context}>
37
+ <AppContextPreact.Provider value={context}>
35
38
  <BrowserDetailsContext.Provider value={browser}>
36
39
  <Localization locale={locale}>
37
40
  <Navigation router={router}>{element}</Navigation>
38
41
  </Localization>
39
42
  </BrowserDetailsContext.Provider>
40
- </AppContextReact.Provider>
43
+ </AppContextPreact.Provider>
41
44
  );
42
45
  },
43
46
  async afterRender() {
@@ -1,7 +1,7 @@
1
1
  import type {TestRouter} from '@quilted/quilt/navigation/testing';
2
2
  import type {BrowserTestMock} from '@quilted/quilt/browser/testing';
3
3
 
4
- import type {AppContext} from '~/shared/context.ts';
4
+ import type {AppContext} from '~/context/types.ts';
5
5
 
6
6
  export interface RenderOptions {
7
7
  /**
@@ -27,7 +27,7 @@ export interface RenderContext extends AppContext {
27
27
  /**
28
28
  * The router used for this component test.
29
29
  */
30
- readonly router: TestRouter;
30
+ readonly navigation: {router: TestRouter};
31
31
 
32
32
  /**
33
33
  * The browser environment for this component test.
@@ -3,10 +3,8 @@
3
3
  "compilerOptions": {
4
4
  "jsxImportSource": "preact",
5
5
  "paths": {
6
- "~/shared/*": ["./shared/*"],
7
- "~/tests/*": ["./tests/*"],
8
- "react": ["./node_modules/preact/compat"],
9
- "react-dom": ["./node_modules/preact/compat"]
6
+ "~/context/*": ["./context/*"],
7
+ "~/tests/*": ["./tests/*"]
10
8
  }
11
9
  },
12
10
  "include": ["**/*"],
@@ -8,8 +8,9 @@ import {Frame} from './foundation/frame.ts';
8
8
 
9
9
  import {Home, homeQuery} from './features/home.ts';
10
10
 
11
- import {AppContextPreact, type AppContext} from './shared/context.ts';
12
- import {routeWithAppContext} from './shared/navigation.ts';
11
+ import type {AppContext} from './context/types.ts';
12
+ import {AppContextPreact} from './context/preact.ts';
13
+ import {routeWithAppContext} from './context/navigation.ts';
13
14
 
14
15
  export interface AppProps {
15
16
  context: AppContext;
@@ -44,7 +45,7 @@ export function App({context}: AppProps) {
44
45
  <Localization>
45
46
  <Head />
46
47
  <Navigation
47
- router={context.router}
48
+ router={context.navigation.router}
48
49
  routes={routes}
49
50
  context={context}
50
51
  />
@@ -0,0 +1,10 @@
1
+ *,
2
+ *::before,
3
+ *::after {
4
+ box-sizing: border-box;
5
+ }
6
+
7
+ html,
8
+ body {
9
+ margin: 0;
10
+ }
@@ -1,29 +1,12 @@
1
+ import './browser.css';
2
+
1
3
  import type {ComponentChild} from 'preact';
2
4
  import {hydrate} from '@quilted/quilt/browser';
3
- import {Router} from '@quilted/quilt/navigation';
4
- import {createGraphQLFetch, GraphQLCache} from '@quilted/quilt/graphql';
5
5
 
6
- import type {AppContext} from '~/shared/context.ts';
6
+ import {BrowserAppContext} from '~/context/browser.ts';
7
7
 
8
8
  import {App} from './App.tsx';
9
9
 
10
- class BrowserAppContext implements AppContext {
11
- readonly router: Router;
12
- readonly graphql: AppContext['graphql'];
13
-
14
- constructor() {
15
- this.router = new Router();
16
-
17
- const graphQLFetch = createGraphQLFetch({url: '/api/graphql'});
18
- const graphQLCache = new GraphQLCache({fetch: graphQLFetch});
19
-
20
- this.graphql = {
21
- fetch: graphQLFetch,
22
- cache: graphQLCache,
23
- };
24
- }
25
- }
26
-
27
10
  class BrowserApp {
28
11
  /**
29
12
  * The app's globally-available context.
@@ -44,7 +27,7 @@ class BrowserApp {
44
27
  // @example
45
28
  // ```js
46
29
  // // Log the current URL
47
- // console.log(globalThis.app.context.router.currentRequest.url);
30
+ // console.log(globalThis.app.context.navigation.router.currentRequest.url);
48
31
  // ```
49
32
  Object.defineProperty(globalThis, 'app', {
50
33
  value: this,
@@ -53,8 +36,11 @@ class BrowserApp {
53
36
  writable: true,
54
37
  });
55
38
  }
39
+
40
+ hydrate() {
41
+ hydrate(this.rendered);
42
+ }
56
43
  }
57
44
 
58
45
  const app = new BrowserApp();
59
-
60
- hydrate(app.rendered);
46
+ app.hydrate();
@@ -0,0 +1,21 @@
1
+ import {createGraphQLFetch, GraphQLCache} from '@quilted/quilt/graphql';
2
+
3
+ import type {AppContext} from './types.ts';
4
+ import {NavigationForApp} from './navigation.ts';
5
+
6
+ export class BrowserAppContext implements AppContext {
7
+ readonly navigation: NavigationForApp;
8
+ readonly graphql: AppContext['graphql'];
9
+
10
+ constructor() {
11
+ this.navigation = new NavigationForApp();
12
+
13
+ const graphQLFetch = createGraphQLFetch({url: '/api/graphql'});
14
+ const graphQLCache = new GraphQLCache({fetch: graphQLFetch});
15
+
16
+ this.graphql = {
17
+ fetch: graphQLFetch,
18
+ cache: graphQLCache,
19
+ };
20
+ }
21
+ }
@@ -0,0 +1,17 @@
1
+ import {createContextRouteFunction, Router} from '@quilted/quilt/navigation';
2
+
3
+ import type {AppContext} from './types.ts';
4
+
5
+ export interface Navigation {
6
+ readonly router: Router;
7
+ }
8
+
9
+ export class NavigationForApp implements Navigation {
10
+ readonly router: Router;
11
+
12
+ constructor(url?: string | URL) {
13
+ this.router = new Router(url);
14
+ }
15
+ }
16
+
17
+ export const routeWithAppContext = createContextRouteFunction<AppContext>();
@@ -1,6 +1,6 @@
1
1
  import {createOptionalContext} from '@quilted/quilt/context';
2
2
 
3
- export interface AppContext {}
3
+ import type {AppContext} from './types.ts';
4
4
 
5
5
  export const AppContextPreact = createOptionalContext<AppContext>();
6
6
  export const useAppContext = AppContextPreact.use;
@@ -0,0 +1,23 @@
1
+ import {GraphQLCache} from '@quilted/quilt/graphql';
2
+
3
+ import type {AppContext} from './types.ts';
4
+ import {NavigationForApp} from './navigation.ts';
5
+
6
+ export class ServerAppContext implements AppContext {
7
+ readonly navigation: NavigationForApp;
8
+ readonly graphql: AppContext['graphql'];
9
+
10
+ constructor(request: Request) {
11
+ this.navigation = new NavigationForApp(request.url);
12
+
13
+ const graphQLFetch: AppContext['graphql']['fetch'] = async (...args) => {
14
+ const {performGraphQLOperation} = await import('../server/graphql.ts');
15
+ return performGraphQLOperation(...args);
16
+ };
17
+
18
+ this.graphql = {
19
+ fetch: graphQLFetch,
20
+ cache: new GraphQLCache({fetch: graphQLFetch}),
21
+ };
22
+ }
23
+ }
@@ -0,0 +1,10 @@
1
+ import type {Navigation} from './navigation.ts';
2
+ import type {GraphQLFetch, GraphQLCache} from '@quilted/quilt/graphql';
3
+
4
+ export interface AppContext {
5
+ readonly navigation: Navigation;
6
+ readonly graphql: {
7
+ readonly fetch: GraphQLFetch;
8
+ readonly cache: GraphQLCache;
9
+ };
10
+ }
@@ -1,5 +1,4 @@
1
1
  import {Hono} from 'hono';
2
- import {Router} from '@quilted/quilt/navigation';
3
2
  import {
4
3
  renderAppToHTMLResponse,
5
4
  CacheControlHeader,
@@ -7,35 +6,13 @@ import {
7
6
  PermissionsPolicyHeader,
8
7
  StrictTransportSecurityHeader,
9
8
  } from '@quilted/quilt/server';
10
- import {GraphQLCache} from '@quilted/quilt/graphql';
11
9
 
12
10
  import Env from 'quilt:module/env';
13
11
  import {BrowserAssets} from 'quilt:module/assets';
14
12
 
15
- import type {AppContext} from '~/shared/context.ts';
16
-
17
13
  const app = new Hono();
18
14
  const assets = new BrowserAssets();
19
15
 
20
- class ServerAppContext implements AppContext {
21
- readonly router: Router;
22
- readonly graphql: AppContext['graphql'];
23
-
24
- constructor(request: Request) {
25
- this.router = new Router(request.url);
26
-
27
- const graphQLFetch: AppContext['graphql']['fetch'] = async (...args) => {
28
- const {performGraphQLOperation} = await import('./server/graphql.ts');
29
- return performGraphQLOperation(...args);
30
- };
31
-
32
- this.graphql = {
33
- fetch: graphQLFetch,
34
- cache: new GraphQLCache({fetch: graphQLFetch}),
35
- };
36
- }
37
- }
38
-
39
16
  // GraphQL API, called from the client
40
17
  app.post('/api/graphql', async (c) => {
41
18
  const request = c.req.raw;
@@ -55,7 +32,10 @@ app.post('/api/graphql', async (c) => {
55
32
  app.get('*', async (c) => {
56
33
  const request = c.req.raw;
57
34
 
58
- const [{App}] = await Promise.all([import('./App.tsx')]);
35
+ const [{App}, {ServerAppContext}] = await Promise.all([
36
+ import('./App.tsx'),
37
+ import('./context/server.ts'),
38
+ ]);
59
39
 
60
40
  const context = new ServerAppContext(request);
61
41
 
@@ -9,7 +9,7 @@ import {Navigation, TestRouter} from '@quilted/quilt/navigation/testing';
9
9
  import {Localization} from '@quilted/quilt/localize';
10
10
  import {GraphQLCache} from '@quilted/quilt/graphql';
11
11
 
12
- import {AppContextReact} from '~/shared/context.ts';
12
+ import {AppContextPreact} from '~/context/preact.ts';
13
13
 
14
14
  import {GraphQLTesting, GraphQLController} from '../graphql.ts';
15
15
 
@@ -32,26 +32,29 @@ export const renderApp = createRender<
32
32
  router = new TestRouter(),
33
33
  browser = new BrowserTestMock(),
34
34
  graphql = new GraphQLController(),
35
- graphQLCache = new GraphQLCache(),
35
+ graphQLCache = new GraphQLCache({fetch: graphql.fetch}),
36
36
  }) {
37
37
  return {
38
- router,
38
+ navigation: {router},
39
39
  browser,
40
- graphql: {fetch: graphql.fetch, cache: graphQLCache},
41
- graphQLController: graphql,
40
+ graphql: {fetch: graphql.fetch, cache: graphQLCache, controller: graphql},
42
41
  };
43
42
  },
44
43
  // Render all of our app-wide context providers around each component under test.
45
44
  render(element, context, {locale = 'en'}) {
46
- const {router, browser, graphql, graphQLController} = context;
45
+ const {
46
+ navigation: {router},
47
+ browser,
48
+ graphql,
49
+ } = context;
47
50
 
48
51
  return (
49
- <AppContextReact.Provider value={context}>
52
+ <AppContextPreact.Provider value={context}>
50
53
  <BrowserDetailsContext.Provider value={browser}>
51
54
  <Localization locale={locale}>
52
55
  <Navigation router={router}>
53
56
  <GraphQLTesting
54
- controller={graphQLController}
57
+ controller={graphql.controller}
55
58
  cache={graphql.cache}
56
59
  >
57
60
  <Suspense fallback={null}>{element}</Suspense>
@@ -59,7 +62,7 @@ export const renderApp = createRender<
59
62
  </Navigation>
60
63
  </Localization>
61
64
  </BrowserDetailsContext.Provider>
62
- </AppContextReact.Provider>
65
+ </AppContextPreact.Provider>
63
66
  );
64
67
  },
65
68
  async afterRender(wrapper) {
@@ -69,7 +72,7 @@ export const renderApp = createRender<
69
72
  // once the data is ready.
70
73
 
71
74
  await wrapper.act(async () => {
72
- await wrapper.context.graphQLController.resolveAll();
75
+ await wrapper.context.graphql.controller.resolveAll();
73
76
  });
74
77
  },
75
78
  });