create-eigen-game 0.12.1 → 0.13.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.
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Where the engine range emitted into a scaffolded project comes from.
3
+ *
4
+ * Its own module because the two branches below execute in different worlds,
5
+ * one only inside this repository and the other only inside a published tarball,
6
+ * and a function whose published-only path never runs in CI is a function that
7
+ * is not tested. `src/index.ts` uses it; the package `exports` map does not
8
+ * expose it, so it is internal despite being importable by the tests.
9
+ */
10
+
11
+ /** The dependency whose version the scaffolder emits into the generated server. */
12
+ export const ENGINE_PACKAGE = "@eigeninteractive/server";
13
+
14
+ /**
15
+ * The engine range for a scaffolded project, from this package's own
16
+ * `@eigeninteractive/server` devDependency.
17
+ *
18
+ * That number is not maintained by anyone: it is the version CI compiled the
19
+ * templates against, because `pnpm -r typecheck` runs
20
+ * `tsc -p templates/worker/tsconfig.json` inside this workspace. Emitting
21
+ * anything else would mean shipping templates paired with an engine no build
22
+ * ever saw.
23
+ *
24
+ * It replaced a derivation from this package's OWN version, which was correct
25
+ * only while `create-eigen-game` sat in the `fixed` changesets group, and that
26
+ * membership is what forced an engine-wide release for every scaffolder-only
27
+ * change. Reading the dependency keeps the guarantee and drops the coupling.
28
+ *
29
+ * Two branches, because the same manifest reads differently in the two places
30
+ * this runs:
31
+ *
32
+ * - **Published tarball**: pnpm rewrites `workspace:*` to the exact version
33
+ * while packing, so the manifest already states it (`"0.2.0"`), and no
34
+ * sibling package exists on disk to consult.
35
+ * - **This workspace**: the manifest still says `workspace:*`, which names no
36
+ * version, so the sibling package is read directly.
37
+ *
38
+ * @param declared the raw `@eigeninteractive/server` devDependency value
39
+ * @param readSiblingVersion consulted only for the `workspace:` protocol
40
+ */
41
+ export function engineRange(declared: string | undefined, readSiblingVersion: () => string | undefined): string {
42
+ if (!declared) {
43
+ throw new Error(`create-eigen-game has no ${ENGINE_PACKAGE} devDependency, which is where the engine range it emits comes from`);
44
+ }
45
+
46
+ const version = declared.startsWith("workspace:") ? readSiblingVersion() : declared;
47
+
48
+ if (!version) {
49
+ throw new Error(`create-eigen-game declares ${ENGINE_PACKAGE} as "${declared}" but the workspace package could not be read, so there is no engine version to emit`);
50
+ }
51
+
52
+ // pnpm packs `workspace:*` as a bare version, which is what makes the caret
53
+ // below correct. Asserting it means a change in that behaviour fails here
54
+ // rather than emitting something like `^^0.3.0` into a real project.
55
+ if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(version)) {
56
+ throw new Error(`expected an exact ${ENGINE_PACKAGE} version to build a range from, got "${version}"`);
57
+ }
58
+
59
+ return `^${version}`;
60
+ }