@quilted/quilt 0.5.158 → 0.6.1

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 (180) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/build/esm/graphql/testing/matchers/operations.mjs +1 -1
  3. package/build/esm/graphql/testing/matchers/utilities.mjs +1 -1
  4. package/build/esm/graphql/testing/matchers.mjs +4 -3
  5. package/build/esm/graphql/testing.mjs +5 -1
  6. package/build/esm/react/testing.mjs +5 -2
  7. package/build/esnext/globals.esnext +1 -1
  8. package/build/esnext/graphql/testing/matchers/operations.esnext +49 -19
  9. package/build/esnext/graphql/testing/matchers/utilities.esnext +18 -15
  10. package/build/esnext/graphql/testing/matchers.esnext +4 -3
  11. package/build/esnext/graphql/testing.esnext +4 -1
  12. package/build/esnext/html/HTML.esnext +6 -9
  13. package/build/esnext/react/testing.esnext +4 -2
  14. package/build/esnext/server/ServerContext.esnext +14 -2
  15. package/build/esnext/server/preload.esnext +9 -10
  16. package/build/esnext/server/request-router.esnext +138 -141
  17. package/build/esnext/utilities/react.esnext +1 -4
  18. package/build/tsconfig.tsbuildinfo +1 -1
  19. package/build/typescript/assets/files.d.ts +97 -0
  20. package/build/typescript/assets/files.d.ts.map +1 -0
  21. package/build/typescript/assets/styles.d.ts +11 -0
  22. package/build/typescript/assets/styles.d.ts.map +1 -0
  23. package/build/typescript/assets.d.ts +2 -0
  24. package/build/typescript/assets.d.ts.map +1 -1
  25. package/build/typescript/globals.d.ts +3 -0
  26. package/build/typescript/globals.d.ts.map +1 -1
  27. package/build/typescript/graphql/testing/matchers/utilities.d.ts +1 -1
  28. package/build/typescript/graphql/testing/matchers/utilities.d.ts.map +1 -1
  29. package/build/typescript/graphql/testing/matchers.d.ts +10 -8
  30. package/build/typescript/graphql/testing/matchers.d.ts.map +1 -1
  31. package/build/typescript/graphql/testing.d.ts +7 -1
  32. package/build/typescript/graphql/testing.d.ts.map +1 -1
  33. package/build/typescript/modules.d.ts +23 -0
  34. package/build/typescript/modules.d.ts.map +1 -0
  35. package/build/typescript/react/testing.d.ts +7 -2
  36. package/build/typescript/react/testing.d.ts.map +1 -1
  37. package/configuration/rollup.config.js +3 -0
  38. package/package.json +66 -197
  39. package/source/assets/files.ts +129 -0
  40. package/source/assets/styles.ts +9 -0
  41. package/source/assets.ts +3 -0
  42. package/source/globals.ts +4 -0
  43. package/source/graphql/testing/matchers/operations.ts +1 -1
  44. package/source/graphql/testing/matchers/utilities.ts +1 -1
  45. package/source/graphql/testing/matchers.ts +15 -22
  46. package/source/graphql/testing.ts +11 -1
  47. package/source/modules.ts +31 -0
  48. package/source/react/testing.ts +10 -3
  49. package/tsconfig.json +2 -4
  50. package/build/cjs/assets.cjs +0 -39
  51. package/build/cjs/async.cjs +0 -32
  52. package/build/cjs/env.cjs +0 -7
  53. package/build/cjs/events.cjs +0 -46
  54. package/build/cjs/globals.cjs +0 -21
  55. package/build/cjs/graphql/server.cjs +0 -14
  56. package/build/cjs/graphql/testing/matchers/operations.cjs +0 -42
  57. package/build/cjs/graphql/testing/matchers/utilities.cjs +0 -43
  58. package/build/cjs/graphql/testing/matchers.cjs +0 -10
  59. package/build/cjs/graphql/testing.cjs +0 -18
  60. package/build/cjs/graphql.cjs +0 -21
  61. package/build/cjs/html/HTML.cjs +0 -21
  62. package/build/cjs/html.cjs +0 -133
  63. package/build/cjs/http.cjs +0 -146
  64. package/build/cjs/index.cjs +0 -2
  65. package/build/cjs/localize.cjs +0 -46
  66. package/build/cjs/magic/app.cjs +0 -2
  67. package/build/cjs/magic/assets.cjs +0 -2
  68. package/build/cjs/magic/request-router.cjs +0 -2
  69. package/build/cjs/navigate/testing.cjs +0 -12
  70. package/build/cjs/navigate.cjs +0 -70
  71. package/build/cjs/performance.cjs +0 -26
  72. package/build/cjs/polyfills/abort-controller.cjs +0 -4
  73. package/build/cjs/polyfills/base.cjs +0 -4
  74. package/build/cjs/polyfills/crypto.cjs +0 -4
  75. package/build/cjs/polyfills/fetch-get-set-cookie.cjs +0 -4
  76. package/build/cjs/polyfills/fetch.cjs +0 -4
  77. package/build/cjs/polyfills/noop.cjs +0 -4
  78. package/build/cjs/react/testing.cjs +0 -30
  79. package/build/cjs/react/tools.cjs +0 -19
  80. package/build/cjs/react.cjs +0 -15
  81. package/build/cjs/request-router/index.cjs +0 -12
  82. package/build/cjs/request-router/node.cjs +0 -12
  83. package/build/cjs/server/ServerContext.cjs +0 -20
  84. package/build/cjs/server/preload.cjs +0 -37
  85. package/build/cjs/server/request-router.cjs +0 -266
  86. package/build/cjs/server.cjs +0 -114
  87. package/build/cjs/signals.cjs +0 -51
  88. package/build/cjs/static/StaticContext.cjs +0 -20
  89. package/build/cjs/static/index.cjs +0 -261
  90. package/build/cjs/static/render.cjs +0 -44
  91. package/build/cjs/testing.cjs +0 -12
  92. package/build/cjs/threads.cjs +0 -117
  93. package/build/cjs/utilities/react.cjs +0 -12
  94. package/build/esm/magic/request-router.mjs +0 -1
  95. package/build/esm/polyfills/abort-controller.mjs +0 -1
  96. package/build/esm/polyfills/base.mjs +0 -1
  97. package/build/esm/polyfills/crypto.mjs +0 -1
  98. package/build/esm/polyfills/fetch-get-set-cookie.mjs +0 -1
  99. package/build/esm/polyfills/fetch.mjs +0 -1
  100. package/build/esm/polyfills/noop.mjs +0 -1
  101. package/build/esm/static/StaticContext.mjs +0 -18
  102. package/build/esm/static/index.mjs +0 -259
  103. package/build/esm/static/render.mjs +0 -42
  104. package/build/esm/testing.mjs +0 -1
  105. package/build/esnext/magic/app.esnext +0 -1
  106. package/build/esnext/magic/assets.esnext +0 -1
  107. package/build/esnext/magic/request-router.esnext +0 -1
  108. package/build/esnext/polyfills/abort-controller.esnext +0 -1
  109. package/build/esnext/polyfills/base.esnext +0 -1
  110. package/build/esnext/polyfills/crypto.esnext +0 -1
  111. package/build/esnext/polyfills/fetch-get-set-cookie.esnext +0 -1
  112. package/build/esnext/polyfills/fetch.esnext +0 -1
  113. package/build/esnext/polyfills/noop.esnext +0 -1
  114. package/build/esnext/static/StaticContext.esnext +0 -18
  115. package/build/esnext/static/index.esnext +0 -259
  116. package/build/esnext/static/render.esnext +0 -42
  117. package/build/esnext/testing.esnext +0 -1
  118. package/build/typescript/App.d.ts +0 -48
  119. package/build/typescript/App.d.ts.map +0 -1
  120. package/build/typescript/TestApp.d.ts +0 -17
  121. package/build/typescript/TestApp.d.ts.map +0 -1
  122. package/build/typescript/global.d.ts +0 -8
  123. package/build/typescript/global.d.ts.map +0 -1
  124. package/build/typescript/magic/app.d.ts +0 -4
  125. package/build/typescript/magic/app.d.ts.map +0 -1
  126. package/build/typescript/magic/assets.d.ts +0 -5
  127. package/build/typescript/magic/assets.d.ts.map +0 -1
  128. package/build/typescript/magic/request-router.d.ts +0 -4
  129. package/build/typescript/magic/request-router.d.ts.map +0 -1
  130. package/build/typescript/matchers/graphql/operations.d.ts +0 -7
  131. package/build/typescript/matchers/graphql/operations.d.ts.map +0 -1
  132. package/build/typescript/matchers/graphql/utilities.d.ts +0 -8
  133. package/build/typescript/matchers/graphql/utilities.d.ts.map +0 -1
  134. package/build/typescript/matchers/graphql.d.ts +0 -9
  135. package/build/typescript/matchers/graphql.d.ts.map +0 -1
  136. package/build/typescript/matchers.d.ts +0 -3
  137. package/build/typescript/matchers.d.ts.map +0 -1
  138. package/build/typescript/polyfills/abort-controller.d.ts +0 -2
  139. package/build/typescript/polyfills/abort-controller.d.ts.map +0 -1
  140. package/build/typescript/polyfills/base.d.ts +0 -2
  141. package/build/typescript/polyfills/base.d.ts.map +0 -1
  142. package/build/typescript/polyfills/crypto.d.ts +0 -2
  143. package/build/typescript/polyfills/crypto.d.ts.map +0 -1
  144. package/build/typescript/polyfills/fetch-get-set-cookie.d.ts +0 -2
  145. package/build/typescript/polyfills/fetch-get-set-cookie.d.ts.map +0 -1
  146. package/build/typescript/polyfills/fetch.d.ts +0 -2
  147. package/build/typescript/polyfills/fetch.d.ts.map +0 -1
  148. package/build/typescript/polyfills/noop.d.ts +0 -2
  149. package/build/typescript/polyfills/noop.d.ts.map +0 -1
  150. package/build/typescript/react/index.d.ts +0 -3
  151. package/build/typescript/react/index.d.ts.map +0 -1
  152. package/build/typescript/react-dom/index.d.ts +0 -3
  153. package/build/typescript/react-dom/index.d.ts.map +0 -1
  154. package/build/typescript/server/index.d.ts +0 -16
  155. package/build/typescript/server/index.d.ts.map +0 -1
  156. package/build/typescript/static/StaticContext.d.ts +0 -13
  157. package/build/typescript/static/StaticContext.d.ts.map +0 -1
  158. package/build/typescript/static/index.d.ts +0 -20
  159. package/build/typescript/static/index.d.ts.map +0 -1
  160. package/build/typescript/static/render.d.ts +0 -19
  161. package/build/typescript/static/render.d.ts.map +0 -1
  162. package/build/typescript/testing.d.ts +0 -2
  163. package/build/typescript/testing.d.ts.map +0 -1
  164. package/quilt.project.ts +0 -5
  165. package/source/magic/app.ts +0 -5
  166. package/source/magic/assets.ts +0 -8
  167. package/source/magic/request-router.ts +0 -5
  168. package/source/polyfills/README.md +0 -3
  169. package/source/polyfills/abort-controller.ts +0 -1
  170. package/source/polyfills/base.ts +0 -1
  171. package/source/polyfills/crypto.ts +0 -1
  172. package/source/polyfills/fetch-get-set-cookie.ts +0 -1
  173. package/source/polyfills/fetch.ts +0 -1
  174. package/source/polyfills/noop.ts +0 -1
  175. package/source/static/StaticContext.tsx +0 -39
  176. package/source/static/index.tsx +0 -315
  177. package/source/static/render.tsx +0 -40
  178. package/source/testing.ts +0 -1
  179. /package/build/esm/{magic/app.mjs → modules.mjs} +0 -0
  180. /package/build/{esm/magic/assets.mjs → esnext/modules.esnext} +0 -0
@@ -1,315 +0,0 @@
1
- import {type ComponentType} from 'react';
2
- import {renderToStaticMarkup} from 'react-dom/server';
3
-
4
- import {type BrowserAssets} from '@quilted/assets';
5
- import {
6
- Head,
7
- Script,
8
- ScriptPreload,
9
- Style,
10
- StylePreload,
11
- } from '@quilted/react-html/server';
12
- import type {RouteDefinition} from '@quilted/react-router';
13
- import {
14
- StaticRenderer,
15
- StaticRendererContext,
16
- } from '@quilted/react-router/static';
17
- import type {HttpState} from '@quilted/react-http/server';
18
-
19
- import {renderApp} from './render.tsx';
20
-
21
- export interface RenderDetails {
22
- readonly route: string;
23
- readonly hasChildren: boolean;
24
- readonly fallback: boolean;
25
- readonly content: string;
26
- readonly http: HttpState;
27
- }
28
-
29
- interface RenderableRoute {
30
- route: string;
31
- fallback: boolean;
32
- }
33
-
34
- export interface Options {
35
- routes: string[];
36
- assets: BrowserAssets<any>;
37
- crawl?: boolean;
38
- baseUrl?: string;
39
- prettify?: boolean;
40
- onRender(details: RenderDetails): void | Promise<void>;
41
- }
42
-
43
- const BASE_URL = 'http://localhost:3000';
44
-
45
- export async function renderStatic(
46
- App: ComponentType<any>,
47
- {
48
- assets,
49
- routes: startingRoutes,
50
- onRender,
51
- crawl = true,
52
- baseUrl = BASE_URL,
53
- prettify = true,
54
- }: Options,
55
- ) {
56
- const routesToHandle = startingRoutes.map<RenderableRoute>((route) => ({
57
- route: removePostfixSlash(new URL(route, baseUrl).pathname),
58
- fallback: false,
59
- }));
60
- const seenRoutes = [...routesToHandle];
61
- const seenRouteIds = new Set<string>(seenRoutes.map(({route}) => route));
62
-
63
- let renderableRoute: RenderableRoute | undefined;
64
-
65
- while ((renderableRoute = routesToHandle.shift())) {
66
- const {route, fallback} = renderableRoute;
67
-
68
- const url = new URL(route, baseUrl);
69
-
70
- const {html, http, routes} = await renderUrl(url, {fallback});
71
-
72
- if (crawl) {
73
- for (const {
74
- routes: routeDefinitions,
75
- fallback = false,
76
- consumedPath,
77
- prefix,
78
- } of routes) {
79
- const basePathname = joinPath(prefix, consumedPath);
80
- const baseId =
81
- basePathname === '/'
82
- ? basePathname
83
- : `__QUILT_BASE_${basePathname}__`;
84
-
85
- for (const routeDefinition of routeDefinitions) {
86
- await recordRouteDefinition(routeDefinition, {
87
- baseId,
88
- basePathname,
89
- addFallbacks: fallback,
90
- });
91
- }
92
-
93
- if (
94
- fallback &&
95
- routeDefinitions[routeDefinitions.length - 1]?.match != null
96
- ) {
97
- await recordRouteDefinition(
98
- {},
99
- {
100
- baseId,
101
- basePathname,
102
- addFallbacks: fallback,
103
- },
104
- );
105
- }
106
- }
107
- }
108
-
109
- await onRender({
110
- route,
111
- content: html,
112
- http,
113
- fallback,
114
- hasChildren:
115
- !fallback &&
116
- seenRoutes.some((otherRoute) =>
117
- otherRoute.route.startsWith(`${route}/`),
118
- ),
119
- });
120
- }
121
-
122
- async function recordRouteDefinition(
123
- {match, children, renderStatic}: RouteDefinition,
124
- {
125
- basePathname,
126
- baseId,
127
- addFallbacks,
128
- }: {basePathname: string; baseId: string; addFallbacks: boolean},
129
- ) {
130
- if (renderStatic === false) return;
131
-
132
- let routeId: string;
133
- const hasChildren = children && children.length > 0;
134
- const hasManualMatches =
135
- typeof renderStatic === 'function' && typeof match !== 'string';
136
-
137
- const matchedRoutes: {id: string; route: string; fallback: boolean}[] = [];
138
-
139
- if (typeof match === 'string') {
140
- routeId = joinPath(baseId, match);
141
- matchedRoutes.push({
142
- id: routeId,
143
- route: joinPath(basePathname, match),
144
- fallback: false,
145
- });
146
- } else if (typeof match === 'function') {
147
- routeId = joinPath(
148
- baseId,
149
- `__QUILT_FUNCTION_ROUTE_${match.toString()}__`,
150
- );
151
- } else if (match instanceof RegExp) {
152
- routeId = joinPath(`__QUILT_REGEX_ROUTE_${match.source}__`);
153
- } else {
154
- routeId = joinPath(baseId, '__QUILT_FALLBACK_ROUTE__');
155
-
156
- if (!hasManualMatches) {
157
- matchedRoutes.push({id: routeId, route: basePathname, fallback: true});
158
- }
159
- }
160
-
161
- if (seenRouteIds.has(routeId)) return;
162
- seenRouteIds.add(routeId);
163
-
164
- if (typeof renderStatic === 'function' && typeof match !== 'string') {
165
- const matchedRouteParts = await renderStatic();
166
-
167
- for (const routePart of matchedRouteParts) {
168
- const id = joinPath(baseId, `__QUILT_MATCH_${routePart}__`);
169
- seenRouteIds.add(id);
170
-
171
- matchedRoutes.push({
172
- id,
173
- route: joinPath(basePathname, routePart),
174
- fallback: false,
175
- });
176
- }
177
- }
178
-
179
- if (hasChildren) {
180
- for (const {id, route} of matchedRoutes) {
181
- for (const child of children!) {
182
- await recordRouteDefinition(child, {
183
- addFallbacks,
184
- basePathname: route,
185
- baseId: id,
186
- });
187
- }
188
-
189
- if (addFallbacks && children![children!.length - 1]?.match != null) {
190
- await recordRouteDefinition(
191
- {},
192
- {
193
- addFallbacks,
194
- basePathname: route,
195
- baseId: id,
196
- },
197
- );
198
- }
199
- }
200
-
201
- return;
202
- }
203
-
204
- for (const {route, fallback} of matchedRoutes) {
205
- const renderableRoute = {route, fallback};
206
- seenRoutes.push(renderableRoute);
207
- routesToHandle.push(renderableRoute);
208
- }
209
- }
210
-
211
- async function renderUrl(url: URL, {fallback = false} = {}) {
212
- const routeRecorder = new StaticRenderer({
213
- forceFallback: fallback ? url.pathname : undefined,
214
- });
215
-
216
- const initialCacheKey = await assets.cacheKey?.(new Request(url));
217
-
218
- const {
219
- http,
220
- html: htmlManager,
221
- assets: assetsManager,
222
- markup,
223
- } = await renderApp(<App />, {
224
- url,
225
- cacheKey: initialCacheKey,
226
- decorate(app) {
227
- return (
228
- <StaticRendererContext.Provider value={routeRecorder}>
229
- {app}
230
- </StaticRendererContext.Provider>
231
- );
232
- },
233
- });
234
-
235
- const cacheKey = assetsManager.cacheKey;
236
-
237
- const [mainAssets, preloadAssets] = await Promise.all([
238
- assets.entry({
239
- modules: assetsManager.usedModules({timing: 'load'}),
240
- cacheKey,
241
- }),
242
- assets.modules(assetsManager.usedModules({timing: 'preload'}), {
243
- cacheKey,
244
- }),
245
- ]);
246
-
247
- const {htmlAttributes, bodyAttributes, ...headProps} = htmlManager.state;
248
- const minifiedHTML =
249
- '<!DOCTYPE html>' +
250
- renderToStaticMarkup(
251
- // eslint-disable-next-line jsx-a11y/html-has-lang
252
- <html {...htmlAttributes}>
253
- <head>
254
- <Head {...headProps} />
255
- {mainAssets?.scripts.map((script) => (
256
- <Script key={script.source} asset={script} baseUrl={url} />
257
- ))}
258
- {mainAssets?.styles.map((style) => (
259
- <Style key={style.source} asset={style} baseUrl={url} />
260
- ))}
261
- {preloadAssets?.styles.map((style) => (
262
- <StylePreload key={style.source} asset={style} baseUrl={url} />
263
- ))}
264
- {preloadAssets?.scripts.map((script) => (
265
- <ScriptPreload key={script.source} asset={script} baseUrl={url} />
266
- ))}
267
- </head>
268
- <body {...bodyAttributes}>
269
- <div
270
- id="app"
271
- dangerouslySetInnerHTML={{__html: markup ?? ''}}
272
- ></div>
273
- </body>
274
- </html>,
275
- );
276
-
277
- const html = prettify ? await prettifyHTML(minifiedHTML) : minifiedHTML;
278
-
279
- return {
280
- html,
281
- http: http.state,
282
- routes: routeRecorder.state,
283
- };
284
- }
285
- }
286
-
287
- async function prettifyHTML(html: string) {
288
- try {
289
- const {default: prettier} = await import('prettier');
290
- return prettier.format(html, {parser: 'html'});
291
- } catch (error) {
292
- return html;
293
- }
294
- }
295
-
296
- function joinPath(...parts: (string | undefined | null | false)[]) {
297
- let path = '/';
298
-
299
- for (const part of parts) {
300
- if (typeof part !== 'string') continue;
301
- const normalizedPart = part.startsWith('/') ? part.slice(1) : part;
302
- if (normalizedPart.length === 0) continue;
303
- if (path !== '/') path += '/';
304
- path += normalizedPart;
305
- path = removePostfixSlash(path);
306
- }
307
-
308
- return path;
309
- }
310
-
311
- function removePostfixSlash(value: string) {
312
- return value.endsWith('/') && value !== '/'
313
- ? value.slice(0, value.length - 1)
314
- : value;
315
- }
@@ -1,40 +0,0 @@
1
- import type {ReactElement} from 'react';
2
-
3
- import {extract} from '@quilted/react-server-render/server';
4
- import type {Options as ExtractOptions} from '@quilted/react-server-render/server';
5
- import {HTMLManager} from '@quilted/react-html/server';
6
- import {HttpManager} from '@quilted/react-http/server';
7
- import {AssetsManager} from '@quilted/react-assets/server';
8
- import type {AssetsCacheKey} from '@quilted/assets';
9
-
10
- import {StaticContext} from './StaticContext.tsx';
11
-
12
- interface Options<CacheKey = AssetsCacheKey> extends ExtractOptions {
13
- url?: string | URL;
14
- cacheKey?: CacheKey;
15
- headers?: NonNullable<
16
- ConstructorParameters<typeof HttpManager>[0]
17
- >['headers'];
18
- }
19
-
20
- export async function renderApp<CacheKey = AssetsCacheKey>(
21
- app: ReactElement<any>,
22
- {decorate, url, headers, cacheKey, ...rest}: Options<CacheKey> = {},
23
- ) {
24
- const html = new HTMLManager();
25
- const http = new HttpManager({headers});
26
- const assets = new AssetsManager<CacheKey>({cacheKey});
27
-
28
- const markup = await extract(app, {
29
- decorate(app) {
30
- return (
31
- <StaticContext html={html} http={http} url={url} assets={assets}>
32
- {decorate?.(app) ?? app}
33
- </StaticContext>
34
- );
35
- },
36
- ...rest,
37
- });
38
-
39
- return {markup, http, html, assets};
40
- }
package/source/testing.ts DELETED
@@ -1 +0,0 @@
1
- export * from '@quilted/testing';
File without changes