@sigil-dev/grimoire 0.9.29 → 0.9.30

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 (105) hide show
  1. package/bin/sigil.ts +4 -0
  2. package/index.ts +16 -10
  3. package/package.json +14 -6
  4. package/server.ts +2 -2
  5. package/src/adapters/bun.ts +17 -17
  6. package/src/adapters/static.ts +41 -41
  7. package/src/adapters/types.ts +36 -36
  8. package/src/base.ts +4 -1
  9. package/src/client/csrf.ts +47 -47
  10. package/src/client/deferred.ts +1 -4
  11. package/src/client/enhance.ts +160 -160
  12. package/src/client/router.ts +927 -926
  13. package/src/config-file.ts +84 -0
  14. package/src/dev/compile-module.ts +199 -193
  15. package/src/dev/hmr-client.ts +229 -229
  16. package/src/dev/hmr-server.ts +274 -266
  17. package/src/dev/loader.ts +144 -144
  18. package/src/dev/runtime-bundle.ts +5 -3
  19. package/src/duration.ts +46 -0
  20. package/src/env/modules.ts +62 -62
  21. package/src/env/required.ts +42 -42
  22. package/src/env/typegen.ts +61 -61
  23. package/src/headers.ts +105 -105
  24. package/src/logger/transports.ts +117 -117
  25. package/src/plugin-order.ts +88 -0
  26. package/src/rendering/head.ts +49 -49
  27. package/src/rendering/hydrate.ts +162 -162
  28. package/src/rendering/images.ts +43 -43
  29. package/src/rendering/preload.ts +22 -8
  30. package/src/rendering/ssrPlugin.ts +107 -107
  31. package/src/rendering/timing.ts +40 -40
  32. package/src/routing/route-ids.ts +65 -0
  33. package/src/routing/route.ts +65 -0
  34. package/src/routing/router.ts +84 -32
  35. package/src/routing/scanner.ts +18 -5
  36. package/src/routing/transform-routes.ts +102 -102
  37. package/src/server/after-response.ts +206 -206
  38. package/src/server/asset-cache.ts +57 -57
  39. package/src/server/build.ts +304 -295
  40. package/src/server/cached.ts +114 -114
  41. package/src/server/client-address.ts +82 -82
  42. package/src/server/client-dir.ts +63 -63
  43. package/src/server/client-entry.ts +44 -44
  44. package/src/server/context.ts +18 -10
  45. package/src/server/cookie-utils.ts +80 -80
  46. package/src/server/coordinator.ts +476 -476
  47. package/src/server/hooks.ts +122 -122
  48. package/src/server/index.ts +8 -0
  49. package/src/server/plugins.ts +172 -172
  50. package/src/server/prerender.ts +473 -473
  51. package/src/server/reserved.ts +17 -17
  52. package/src/server/resolver.ts +149 -123
  53. package/src/server/rewrite.ts +28 -28
  54. package/src/server/warm.ts +9 -3
  55. package/src/server/with-headers.ts +27 -27
  56. package/src/server/worker.ts +2 -6
  57. package/src/server-only.ts +78 -0
  58. package/src/testing/dom.ts +73 -73
  59. package/src/testing/index.ts +169 -169
  60. package/src/testing/server.ts +1 -0
  61. package/src/typegen/index.ts +97 -2
  62. package/src/types.ts +140 -19
  63. package/test/after-response.test.ts +132 -132
  64. package/test/asset-cache-policy.test.ts +6 -2
  65. package/test/base.test.ts +20 -6
  66. package/test/cached.test.ts +126 -126
  67. package/test/client-address.test.ts +78 -78
  68. package/test/client-csrf.test.ts +61 -61
  69. package/test/client-dir.test.ts +101 -101
  70. package/test/client-router.test.ts +37 -5
  71. package/test/config-file.test.ts +84 -0
  72. package/test/coordinator.test.ts +9 -2
  73. package/test/deferred.test.ts +4 -2
  74. package/test/dev-loader.test.ts +30 -30
  75. package/test/env.test.ts +171 -171
  76. package/test/force-production.test.ts +7 -2
  77. package/test/images.test.ts +20 -8
  78. package/test/locals-header.test.ts +61 -61
  79. package/test/middleware.test.ts +243 -243
  80. package/test/parser-plugins.test.ts +98 -92
  81. package/test/plugin-handle.test.ts +62 -62
  82. package/test/plugin-order.test.ts +98 -0
  83. package/test/plugin-routes.test.ts +47 -42
  84. package/test/plugin-services-context.test.ts +7 -2
  85. package/test/preload.test.ts +4 -1
  86. package/test/prerender.test.ts +3 -1
  87. package/test/rendering.test.ts +3 -2
  88. package/test/required-env.test.ts +32 -32
  89. package/test/resolver-windows.test.ts +22 -23
  90. package/test/rewrite-html.test.ts +90 -90
  91. package/test/route-group-layouts.test.ts +38 -36
  92. package/test/route.test.ts +103 -0
  93. package/test/routing.test.ts +225 -197
  94. package/test/scanning.test.ts +53 -33
  95. package/test/server-context.test.ts +22 -0
  96. package/test/server-only.test.ts +110 -0
  97. package/test/server.test.ts +640 -640
  98. package/test/services.test.ts +3 -3
  99. package/test/streaming.test.ts +11 -6
  100. package/test/testing-helpers.test.ts +166 -166
  101. package/test/typegen.test.ts +209 -112
  102. package/test/warm.test.ts +96 -96
  103. package/test/worker-context.test.ts +59 -59
  104. package/test/workspace-files.test.ts +26 -10
  105. package/test/workspace-versions.test.ts +146 -131
@@ -1,57 +1,57 @@
1
- /**
2
- * The cache policy for files served out of public/.
3
- *
4
- * Extracted from the server so the decision can be tested without booting
5
- * one, and so there is exactly one copy of it. A policy test that keeps its
6
- * own duplicate of the logic passes forever regardless of what the server
7
- * does, which is worse than having no test.
8
- */
9
-
10
- /**
11
- * A URL that changes whenever its content changes: a build-stamped hash, or
12
- * a version query the app bumps per deploy.
13
- *
14
- * `?v=` deliberately counts. A file that a caller knows to re-request under
15
- * a new query is content-addressed by that query, and that is the same
16
- * guarantee a hash gives — the URL is the key. Requiring a literal hash in
17
- * the path would send every project that uses the query form back to
18
- * revalidation for no reason.
19
- */
20
- export function isContentAddressed(pathname: string, search: string): boolean {
21
- // /style.a1b2c3d4.css — a hash inserted before the extension.
22
- if (/\.[0-9a-f]{8,}\.[a-z0-9]+$/i.test(pathname)) return true;
23
- // /__grimoire__/chunk-jp4kgm87.js — the name the bundler gives a shared
24
- // chunk: "chunk-" and a hash of the contents. Anchored on the prefix, since
25
- // a bare "8+ letters before the extension" would also match hero-background.png.
26
- if (/(^|\/)chunk-[a-z0-9]{8,}\.[a-z0-9]+$/i.test(pathname)) return true;
27
- // /__grimoire__/hydrate-a1b2c3d4.js — an entry named by its contents
28
- if (/^\/__grimoire__\/[a-z]+-[a-z0-9]{8,}\.js$/i.test(pathname)) return true;
29
- // A non-empty version query, e.g. /style.css?v=3. Deliberately does not
30
- // treat `?` with an empty value as addressed: /style.css? is the same
31
- // URL and would cache forever without ever changing.
32
- return /[?&]v=[^&#]+/.test(search);
33
- }
34
-
35
- /** The `Cache-Control` for a public asset, by its URL. */
36
- export function cacheControlFor(
37
- pathname: string,
38
- search: string,
39
- ): "no-cache" | "immutable" | "revalidate" {
40
- // The document is what references the assets. Caching it hard means
41
- // serving stale references to assets that are long gone.
42
- if (pathname === "/" || pathname.endsWith(".html")) return "no-cache";
43
- if (isContentAddressed(pathname, search)) return "immutable";
44
- // Cached, but revalidated every time. Costs a conditional request and
45
- // guarantees a deploy is visible on the next load — the right trade for a
46
- // file whose URL is not content-addressed.
47
- return "revalidate";
48
- }
49
-
50
- export const CACHE_CONTROL: Record<
51
- ReturnType<typeof cacheControlFor>,
52
- string
53
- > = {
54
- "no-cache": "no-cache",
55
- immutable: "public, max-age=31536000, immutable",
56
- revalidate: "public, max-age=0, must-revalidate",
57
- };
1
+ /**
2
+ * The cache policy for files served out of public/.
3
+ *
4
+ * Extracted from the server so the decision can be tested without booting
5
+ * one, and so there is exactly one copy of it. A policy test that keeps its
6
+ * own duplicate of the logic passes forever regardless of what the server
7
+ * does, which is worse than having no test.
8
+ */
9
+
10
+ /**
11
+ * A URL that changes whenever its content changes: a build-stamped hash, or
12
+ * a version query the app bumps per deploy.
13
+ *
14
+ * `?v=` deliberately counts. A file that a caller knows to re-request under
15
+ * a new query is content-addressed by that query, and that is the same
16
+ * guarantee a hash gives — the URL is the key. Requiring a literal hash in
17
+ * the path would send every project that uses the query form back to
18
+ * revalidation for no reason.
19
+ */
20
+ export function isContentAddressed(pathname: string, search: string): boolean {
21
+ // /style.a1b2c3d4.css — a hash inserted before the extension.
22
+ if (/\.[0-9a-f]{8,}\.[a-z0-9]+$/i.test(pathname)) return true;
23
+ // /__grimoire__/chunk-jp4kgm87.js — the name the bundler gives a shared
24
+ // chunk: "chunk-" and a hash of the contents. Anchored on the prefix, since
25
+ // a bare "8+ letters before the extension" would also match hero-background.png.
26
+ if (/(^|\/)chunk-[a-z0-9]{8,}\.[a-z0-9]+$/i.test(pathname)) return true;
27
+ // /__grimoire__/hydrate-a1b2c3d4.js — an entry named by its contents
28
+ if (/^\/__grimoire__\/[a-z]+-[a-z0-9]{8,}\.js$/i.test(pathname)) return true;
29
+ // A non-empty version query, e.g. /style.css?v=3. Deliberately does not
30
+ // treat `?` with an empty value as addressed: /style.css? is the same
31
+ // URL and would cache forever without ever changing.
32
+ return /[?&]v=[^&#]+/.test(search);
33
+ }
34
+
35
+ /** The `Cache-Control` for a public asset, by its URL. */
36
+ export function cacheControlFor(
37
+ pathname: string,
38
+ search: string,
39
+ ): "no-cache" | "immutable" | "revalidate" {
40
+ // The document is what references the assets. Caching it hard means
41
+ // serving stale references to assets that are long gone.
42
+ if (pathname === "/" || pathname.endsWith(".html")) return "no-cache";
43
+ if (isContentAddressed(pathname, search)) return "immutable";
44
+ // Cached, but revalidated every time. Costs a conditional request and
45
+ // guarantees a deploy is visible on the next load — the right trade for a
46
+ // file whose URL is not content-addressed.
47
+ return "revalidate";
48
+ }
49
+
50
+ export const CACHE_CONTROL: Record<
51
+ ReturnType<typeof cacheControlFor>,
52
+ string
53
+ > = {
54
+ "no-cache": "no-cache",
55
+ immutable: "public, max-age=31536000, immutable",
56
+ revalidate: "public, max-age=0, must-revalidate",
57
+ };