@xmachines/shared 1.0.0-beta.7 → 1.0.0-beta.9

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/README.md CHANGED
@@ -139,8 +139,6 @@ What the shared Vitest layer provides automatically:
139
139
  - Node setup injection (`config/vitest.node.setup.ts`) for non-browser projects
140
140
  - Runtime preflight:
141
141
  - Node.js runtime/version check (`>=22`) in node setup
142
- - `urlpattern-polyfill` load in shared setup
143
- - `URLPattern` availability assertion in shared setup
144
142
  - DOM matcher extension via `@testing-library/jest-dom/vitest`
145
143
 
146
144
  ### Vitest Setup Injection Rules
@@ -162,9 +160,12 @@ This gives a safe default for Node package tests while keeping browser projects
162
160
  - `@xmachines/shared/vitest` → `config/vitest.ts`
163
161
  - `@xmachines/shared/vitest-setup` → `config/vitest.setup.ts`
164
162
  - `@xmachines/shared/vitest-node-setup` → `config/vitest.node.setup.ts`
163
+ - `@xmachines/shared/vitest-urlpattern-setup` → `config/vitest.urlpattern.setup.ts`
165
164
 
166
165
  Use `@xmachines/shared/vitest` for package config files; direct setup exports are for advanced customization only.
167
166
 
167
+ `vitest-urlpattern-setup` must be added explicitly to `setupFiles` in packages that exercise URLPattern-based route matching (e.g. `play-router` and its adapter packages). It mirrors what consumers must do in production on Node < 24 or older browsers.
168
+
168
169
  ## Configuration Details
169
170
 
170
171
  ### TypeScript (`config/tsconfig.json`)
@@ -198,14 +199,16 @@ import { foo } from "./bar"; // ❌ Wrong
198
199
  - **Style:** Double quotes, semicolons, trailing commas
199
200
  - **Final Newline:** Always insert
200
201
 
201
- ### Vitest (`config/vitest.ts`, `config/vitest.setup.ts`, `config/vitest.node.setup.ts`)
202
+ ### Vitest (`config/vitest.ts`, `config/vitest.setup.ts`, `config/vitest.node.setup.ts`, `config/vitest.urlpattern.setup.ts`)
202
203
 
203
204
  - **Helper API:** `defineXmVitestConfig(importMetaUrl, overrides)` merges shared defaults with package-specific Vitest config
204
205
  - **Auto-aliasing:** `resolve.alias` is wired to `xmAliases(importMetaUrl)` so workspace packages resolve to source
205
206
  - **Cross-runtime setup (`config/vitest.setup.ts`):**
206
- - loads `urlpattern-polyfill`
207
207
  - extends `expect` with `@testing-library/jest-dom/vitest`
208
- - asserts `URLPattern` availability
208
+ - **URLPattern setup (`config/vitest.urlpattern.setup.ts`):**
209
+ - loads `urlpattern-polyfill` — opt-in per package via `setupFiles: ["@xmachines/shared/vitest-urlpattern-setup"]`
210
+ - required for packages exercising URLPattern-based route matching (play-router and adapters)
211
+ - mirrors what consumers must do in production on Node < 24 or older browsers
209
212
  - **Node-only setup (`config/vitest.node.setup.ts`):**
210
213
  - asserts Node runtime (`process.release.name === "node"`)
211
214
  - enforces Node version `>=22`
@@ -11,7 +11,7 @@
11
11
  "rules": {
12
12
  "unicorn/filename-case": "off",
13
13
  "import/no-cycle": "error",
14
- "typescript/no-explicit-any": "warn",
14
+ "typescript/no-explicit-any": "error",
15
15
  "typescript/no-unused-vars": [
16
16
  "error",
17
17
  {
@@ -4,10 +4,4 @@
4
4
  * @internal
5
5
  */
6
6
  // eslint-disable-next-line import/no-unassigned-import
7
- import "urlpattern-polyfill";
8
- // eslint-disable-next-line import/no-unassigned-import
9
7
  import "@testing-library/jest-dom/vitest";
10
-
11
- if (typeof (globalThis as { URLPattern?: unknown }).URLPattern !== "function") {
12
- throw new Error("URLPattern is unavailable after setup");
13
- }
package/config/vitest.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { fileURLToPath } from "node:url";
2
2
  import { dirname, resolve } from "node:path";
3
3
  import { defineConfig, mergeConfig } from "vitest/config";
4
- import { xmAliases } from "./vite-aliases.js";
4
+ import { xmAliases } from "@xmachines/shared/vite-aliases";
5
5
 
6
6
  const configDir = dirname(fileURLToPath(import.meta.url));
7
7
  const nodeSetupFile = resolve(configDir, "vitest.node.setup.ts");
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Optional Vitest setup file for packages that use URLPattern (via @xmachines/play-router).
3
+ *
4
+ * Include this in `setupFiles` for packages that exercise route matching in tests:
5
+ *
6
+ * ```ts
7
+ * // vitest.config.ts
8
+ * import { defineXmVitestConfig } from "@xmachines/shared/vitest";
9
+ * export default defineXmVitestConfig(import.meta.url, {
10
+ * test: {
11
+ * setupFiles: ["@xmachines/shared/vitest-urlpattern-setup"],
12
+ * },
13
+ * });
14
+ * ```
15
+ *
16
+ * This mirrors what consumers must do in production on Node < 24 or older browsers:
17
+ * load a URLPattern polyfill before importing @xmachines/play-router.
18
+ *
19
+ * @internal — test infrastructure only, not part of the public API
20
+ */
21
+ // eslint-disable-next-line import/no-unassigned-import
22
+ import "urlpattern-polyfill";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmachines/shared",
3
- "version": "1.0.0-beta.7",
3
+ "version": "1.0.0-beta.9",
4
4
  "description": "Shared configurations for XMachines packages",
5
5
  "keywords": [
6
6
  "config",
@@ -28,24 +28,31 @@
28
28
  "./vitest": "./config/vitest.ts",
29
29
  "./vitest-node-setup": "./config/vitest.node.setup.ts",
30
30
  "./vitest-setup": "./config/vitest.setup.ts",
31
+ "./vitest-urlpattern-setup": "./config/vitest.urlpattern.setup.ts",
31
32
  "./config/tsconfig.json": "./config/tsconfig.json",
32
33
  "./config/oxlint.json": "./config/oxlint.json",
33
34
  "./config/oxfmt.json": "./config/oxfmt.json",
34
35
  "./config/vitest.ts": "./config/vitest.ts",
35
36
  "./config/vitest.node.setup.ts": "./config/vitest.node.setup.ts",
36
- "./config/vitest.setup.ts": "./config/vitest.setup.ts"
37
+ "./config/vitest.setup.ts": "./config/vitest.setup.ts",
38
+ "./config/vitest.urlpattern.setup.ts": "./config/vitest.urlpattern.setup.ts"
37
39
  },
38
40
  "publishConfig": {
39
41
  "access": "public"
40
42
  },
41
43
  "scripts": {
44
+ "clean": "rm -rf dist coverage *.tsbuildinfo node_modules/.vite node_modules/.vite-temp",
42
45
  "lint": "oxlint .",
43
46
  "lint:fix": "oxlint --fix .",
44
47
  "format": "oxfmt .",
45
48
  "format:check": "oxfmt --check .",
46
- "test": "echo \"Error: no test specified\" && exit 1"
49
+ "test": "vitest"
47
50
  },
48
51
  "dependencies": {
49
- "@testing-library/jest-dom": "^6.9.1"
52
+ "@testing-library/jest-dom": "^6.9.1",
53
+ "urlpattern-polyfill": "^10.1.0"
54
+ },
55
+ "devDependencies": {
56
+ "vitest": "^4.1.0"
50
57
  }
51
58
  }