@decocms/blocks 7.10.0 → 7.11.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.
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "@decocms/blocks",
3
- "version": "7.10.0",
3
+ "version": "7.11.1",
4
4
  "type": "module",
5
+ "engines": {
6
+ "node": ">=24"
7
+ },
5
8
  "description": "Deco framework-agnostic core: CMS block resolution, section registry, matchers, portable SDK utilities",
6
9
  "repository": {
7
10
  "type": "git",
@@ -101,6 +101,24 @@ describe("matchPath", () => {
101
101
  expect(() => matchPath("/[invalid", "/anything")).not.toThrow();
102
102
  expect(matchPath("/[invalid", "/anything")).toBeNull();
103
103
  });
104
+
105
+ // Node <= 22 has no URLPattern global. The malformed-pattern try/catch
106
+ // above must NOT absorb that ReferenceError — a missing API has to fail
107
+ // loudly at first match, not degrade into every CMS page silently
108
+ // returning null (which renders as sitewide 404s).
109
+ it("throws a descriptive error when the runtime lacks URLPattern", () => {
110
+ const g = globalThis as { URLPattern?: unknown };
111
+ const saved = g.URLPattern;
112
+ // biome-ignore lint/performance/noDelete: restoring exact global state
113
+ delete g.URLPattern;
114
+ try {
115
+ expect(() => matchPath("/foo/:slug", "/foo/bar")).toThrow(
116
+ /URLPattern.*Node\.js >= 24/s,
117
+ );
118
+ } finally {
119
+ if (saved !== undefined) g.URLPattern = saved;
120
+ }
121
+ });
104
122
  });
105
123
  });
106
124
 
package/src/cms/loader.ts CHANGED
@@ -223,11 +223,27 @@ declare const URLPattern: {
223
223
  *
224
224
  * Malformed patterns return `null` instead of throwing — bad CMS data must
225
225
  * never take down the worker.
226
+ *
227
+ * A MISSING `URLPattern` API, however, throws loudly and immediately: the
228
+ * try/catch below exists to absorb bad *patterns*, and letting it also
229
+ * swallow a `ReferenceError` from an old runtime turns "wrong Node version"
230
+ * into "every CMS page silently 404s" — the worst possible failure mode.
231
+ * `URLPattern` is native in browsers, workerd, Deno, and Node >= 24 (this
232
+ * package's `engines` floor). Node 22 and older lack it.
226
233
  */
227
234
  export function matchPath(
228
235
  pattern: string,
229
236
  urlPath: string,
230
237
  ): Record<string, string> | null {
238
+ if (typeof URLPattern === "undefined") {
239
+ throw new Error(
240
+ "@decocms/blocks: this runtime has no URLPattern Web API, so CMS page " +
241
+ "paths cannot be matched. URLPattern is native in browsers, " +
242
+ "Cloudflare workerd, Deno, and Node.js >= 24 — you are most likely " +
243
+ "running Node <= 22. Upgrade the runtime to Node 24+ (see this " +
244
+ 'package\'s "engines" field).',
245
+ );
246
+ }
231
247
  let result: MatchPatternResult | null;
232
248
  try {
233
249
  result = new URLPattern({ pathname: pattern }).exec({ pathname: urlPath });