@joiner-platform/cli 0.1.17 → 0.1.19

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 (38) hide show
  1. package/package.json +2 -2
  2. package/skills/tile-creator/references/cli.md +1 -1
  3. package/skills/tile-creator/references/client-api.md +16 -6
  4. package/src/commands/init/scaffold.ts +2 -9
  5. package/src/commands/init/sdk-tarball-url.generated.ts +2 -2
  6. package/src/commands/init/template-names.ts +18 -0
  7. package/bundled-resources/poe-tile-templates/coverage.config.json +0 -6
  8. package/bundled-resources/poe-tile-templates/index.ts +0 -27
  9. package/bundled-resources/poe-tile-templates/package.json +0 -31
  10. package/bundled-resources/poe-tile-templates/scripts/cleanup.ts +0 -10
  11. package/bundled-resources/poe-tile-templates/scripts/generate.ts +0 -57
  12. package/bundled-resources/poe-tile-templates/scripts/install-diagnostics.ts +0 -52
  13. package/bundled-resources/poe-tile-templates/scripts/paths.ts +0 -7
  14. package/bundled-resources/poe-tile-templates/scripts/sdk-dependency-key.ts +0 -288
  15. package/bundled-resources/poe-tile-templates/scripts/verify-all-sdks.ts +0 -132
  16. package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-command.ts +0 -30
  17. package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-tarball.ts +0 -397
  18. package/bundled-resources/poe-tile-templates/tests/check-source.test.ts +0 -131
  19. package/bundled-resources/poe-tile-templates/tests/dev-script.test.slow.ts +0 -166
  20. package/bundled-resources/poe-tile-templates/tests/doctor-launcher.test.ts +0 -48
  21. package/bundled-resources/poe-tile-templates/tests/fixtures/customized-manager.ts +0 -67
  22. package/bundled-resources/poe-tile-templates/tests/fixtures/extended-mutators.ts.txt +0 -106
  23. package/bundled-resources/poe-tile-templates/tests/fixtures/multiplayer-verification.test.playwright.ts.txt +0 -103
  24. package/bundled-resources/poe-tile-templates/tests/fixtures/replace-starter-schema.ts +0 -67
  25. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/phaserjs.tsx.txt +0 -85
  26. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/preact.tsx.txt +0 -69
  27. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/react.tsx.txt +0 -73
  28. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/seating.ts.txt +0 -54
  29. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/solidjs.tsx.txt +0 -70
  30. package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/vanilla-js.tsx.txt +0 -85
  31. package/bundled-resources/poe-tile-templates/tests/generated-templates.test.ts +0 -278
  32. package/bundled-resources/poe-tile-templates/tests/happy-dom-version.test.ts +0 -27
  33. package/bundled-resources/poe-tile-templates/tests/install-diagnostics.test.ts +0 -99
  34. package/bundled-resources/poe-tile-templates/tests/native-gesture-defaults.test.ts +0 -23
  35. package/bundled-resources/poe-tile-templates/tests/playwright-version.test.ts +0 -84
  36. package/bundled-resources/poe-tile-templates/tests/render-check-scaffold.test.ts +0 -56
  37. package/bundled-resources/poe-tile-templates/tests/sdk-dependency-key.test.ts +0 -129
  38. package/bundled-resources/poe-tile-templates/tests/visual-check.test.ts +0 -90
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@joiner-platform/cli",
3
- "version": "0.1.17",
4
- "gitHead": "960c0d76e00310125672a371eae2d31766a1af8a",
3
+ "version": "0.1.19",
4
+ "gitHead": "95979a27890c7a1d4f5fdde8e7b293eb9a4c5aa2",
5
5
  "description": "The Joiner CLI: create, test, and publish Joiner tiles, with agent skills for coding agents.",
6
6
  "keywords": [
7
7
  "joiner",
@@ -61,7 +61,7 @@ an older pin, so prefer the live result when upgrading:
61
61
 
62
62
  <!-- begin: sdk-tarball-snippet (auto-generated by packages/poe-tiles-sdk/scripts/publish-tar.ts — do not edit by hand) -->
63
63
  ```json
64
- "joiner-sdk": "https://misc-dev-uploads.quora-913.workers.dev/2ccea219f2bab1a49cd7f7f8bace347f4b248f916bc6db118833ae4ca0096c21"
64
+ "joiner-sdk": "https://misc-dev-uploads.quora-913.workers.dev/ca6d9024d5d9881a193a9ea2d0e58b333d9e6e024e472ca2bb3b3e272ef73bb4"
65
65
  ```
66
66
  <!-- end: sdk-tarball-snippet -->
67
67
 
@@ -59,7 +59,7 @@ below for custom behavior.
59
59
  - [`Poe.consumeEntryContext()`](#poe-consumeentrycontext) — Deprecated for notifications: use `watchEntryContext()`
60
60
  - [`Poe.parent`](#poe-parent) — Parent store identity (for child apps)
61
61
  - [`Poe.topOrigin`](#poe-toporigin) — Origin of the top (host) document, for building absolute URLs from sandboxed iframes
62
- - [`Poe.interfaceLanguages`](#poe-interfacelanguages) — The host's interface languages, preferred over `navigator.languages` when localizing a tile
62
+ - [`Poe.languages`](#poe-languages) — The viewer's preferred languages, to pick which of your translations to show
63
63
  - [`Poe.haptics`](#poe-haptics) — Trigger cross-platform haptic feedback
64
64
  - [`Poe.motion.claim()`](#device-motion) — Tell the host this tile uses device motion as input, so shake-to-report stands down
65
65
  - [`resumeAudioContext()`](#resumeaudiocontext) — Recover Web Audio after browser or iOS system-audio interruptions
@@ -1220,17 +1220,27 @@ await navigator.clipboard.writeText(shareUrl);
1220
1220
 
1221
1221
  For top-document apps (trusted apps not running in an iframe) that construct a `PostMessageEnvironment` manually, pass `topOrigin: window.location.origin` in the constructor options.
1222
1222
 
1223
- ### `Poe.interfaceLanguages`
1223
+ ### `Poe.languages`
1224
1224
 
1225
- The host's interface language preferences, as BCP 47 tags with the most preferred first (e.g. `["fr"]`). Apps that localize their own UI should prefer this over `navigator.languages`.
1225
+ The viewer's preferred languages, as BCP 47 tags with the most preferred first (e.g. `["fr"]` or `["pt-BR", "pt", "en"]`). Never empty. Use it, not `navigator.languages`, to choose which of your translations to show: walk the list and take the first language you have, else your default.
1226
1226
 
1227
1227
  ```typescript
1228
- const languages = Poe.interfaceLanguages ?? navigator.languages;
1228
+ const supported = ["en", "fr", "ja"];
1229
+ // Hosts before kernel v71 have no `Poe.languages`; their deprecated
1230
+ // `interfaceLanguages` still carries the saved choice.
1231
+ const languages = Poe.has("languages")
1232
+ ? Poe.languages
1233
+ : (Poe.interfaceLanguages ?? navigator.languages);
1234
+ const locale =
1235
+ languages
1236
+ .map((tag) => supported.find((s) => s === tag || tag.startsWith(`${s}-`)))
1237
+ .find((match) => match !== undefined) ?? "en";
1238
+ document.documentElement.lang = locale;
1229
1239
  ```
1230
1240
 
1231
- A host can let the viewer pick an interface language (Poe's Language setting) and keep that choice where a sandboxed tile cannot read it, so `navigator.languages` inside the iframe would still report the browser's own languages. The platform injects the host's list into the iframe via `<div id="poe-config" data-interface-languages="...">` when the tile mounts. A change takes effect on the next mount; the host reloads after the viewer changes it.
1241
+ When the viewer picked a language in the host's Language setting, the list is that one language. The choice lives where a sandboxed tile cannot read it, so `navigator.languages` inside the iframe would still report the browser's own languages; the platform stamps the choice into the iframe when the tile mounts. With no saved choice the list is the browser's languages, and `["en"]` when there are none. The value is fixed for the life of the mount; the host reloads after the viewer changes it.
1232
1242
 
1233
- Returns `undefined` when the host supplies no list (no choice made, or an older host); fall back to `navigator.languages`, as above.
1243
+ `Poe.languages` needs kernel v71. Guard it with `Poe.has("languages")` as above, or set `poeTile({ minSdkVersion: 71 })` to require it. `Poe.interfaceLanguages` is deprecated: it holds only the saved choice and is `undefined` without one. Read it only as the fallback on older hosts, as above, so the saved choice still applies there.
1234
1244
 
1235
1245
  ### `Poe.capabilities`
1236
1246
 
@@ -35,15 +35,7 @@ import {
35
35
  applyInternalMonoRepoTypeCheckScripts,
36
36
  } from "./package-json-scripts.js";
37
37
  import { readSdkTarballUrl } from "./sdk-tarball-url.js";
38
-
39
- export const TEMPLATES = [
40
- "react",
41
- "vanilla-js",
42
- "solidjs",
43
- "preact",
44
- "phaserjs",
45
- ] as const;
46
- export type TemplateName = (typeof TEMPLATES)[number];
38
+ import { TEMPLATES, type TemplateName } from "./template-names.js";
47
39
 
48
40
  /**
49
41
  * Allowed app-name shape and length cap. Re-exported from
@@ -56,6 +48,7 @@ export {
56
48
  TILE_HANDLE_MAX_LENGTH as VALID_NAME_MAX_LENGTH,
57
49
  TILE_HANDLE_REGEX as VALID_NAME_RE,
58
50
  } from "../../poe-tile-config.js";
51
+ export { TEMPLATES, type TemplateName };
59
52
  export const INVALID_NAME_HINT =
60
53
  "Use lowercase letters, numbers, and hyphens only. Must start and end with a letter or number; 1-100 characters.";
61
54
 
@@ -1,4 +1,4 @@
1
1
  // Auto-generated by poe-tiles-sdk/scripts/publish-tar.ts — do not edit
2
- // publishedAt: 2026-11-30T16:31:28.359Z
2
+ // publishedAt: 2026-11-30T17:07:09.403Z
3
3
  export const SDK_TARBALL_URL =
4
- "https://misc-dev-uploads.quora-913.workers.dev/2ccea219f2bab1a49cd7f7f8bace347f4b248f916bc6db118833ae4ca0096c21";
4
+ "https://misc-dev-uploads.quora-913.workers.dev/ca6d9024d5d9881a193a9ea2d0e58b333d9e6e024e472ca2bb3b3e272ef73bb4";
@@ -0,0 +1,18 @@
1
+ // owner: jyoung-q
2
+ // Kept import-free: scripts/pack-tarball.ts reads it to choose which template
3
+ // directories ship, and runs before the CLI's dependencies are installed.
4
+ export const TEMPLATES = [
5
+ "react",
6
+ "vanilla-js",
7
+ "solidjs",
8
+ "preact",
9
+ "phaserjs",
10
+ ] as const;
11
+ export type TemplateName = (typeof TEMPLATES)[number];
12
+
13
+ /**
14
+ * The top-level directories of packages/poe-tile-templates the published CLI
15
+ * ships and scaffolds from. The package's own tests, scripts and manifest stay
16
+ * out, and edits to them do not trigger a CLI release.
17
+ */
18
+ export const BUNDLED_TEMPLATE_DIRS = ["base", ...TEMPLATES] as const;
@@ -1,6 +0,0 @@
1
- {
2
- "lines": 0,
3
- "functions": 0,
4
- "lcovInfoPath": "$none",
5
- "note": "Static template files for scaffolding, tested via poe-tiles-cli scaffold tests"
6
- }
@@ -1,27 +0,0 @@
1
- // owner: jyoung-q
2
- /**
3
- * Poe app templates for scaffolding new apps.
4
- *
5
- * Exports template names and a function to resolve template directories.
6
- */
7
-
8
- import { resolve } from "node:path";
9
-
10
- export const TEMPLATES = [
11
- "react",
12
- "vanilla-js",
13
- "solidjs",
14
- "preact",
15
- "phaserjs",
16
- ] as const;
17
- export type TemplateName = (typeof TEMPLATES)[number];
18
-
19
- /** Resolve the base template directory. */
20
- export function baseTemplateDir(): string {
21
- return resolve(import.meta.dir, "base");
22
- }
23
-
24
- /** Resolve a framework-specific template directory. */
25
- export function frameworkTemplateDir(template: TemplateName): string {
26
- return resolve(import.meta.dir, template);
27
- }
@@ -1,31 +0,0 @@
1
- {
2
- "name": "@poe-tile/templates",
3
- "version": "0.0.1",
4
- "type": "module",
5
- "main": "index.ts",
6
- "types": "index.ts",
7
- "exports": {
8
- ".": {
9
- "types": "./index.ts",
10
- "default": "./index.ts"
11
- },
12
- "./test-utils/customized-manager": "./tests/fixtures/customized-manager.ts"
13
- },
14
- "scripts": {
15
- "generate-test-apps": "bun scripts/generate.ts && bun install --ignore-scripts --no-save",
16
- "generate:cleanup": "bun scripts/cleanup.ts",
17
- "test": "bun test tests/check-source.test.ts tests/playwright-version.test.ts tests/happy-dom-version.test.ts tests/native-gesture-defaults.test.ts tests/visual-check.test.ts tests/install-diagnostics.test.ts tests/render-check-scaffold.test.ts tests/sdk-dependency-key.test.ts tests/doctor-launcher.test.ts",
18
- "test:generated": "bun test tests/generated-templates.test.ts",
19
- "test:generated:packaged-sdk": "bun scripts/verify-local-sdk-tarball.ts",
20
- "test:slow": "bun run generate-test-apps && bun test ./tests/*.test.slow.ts --reporter=junit --reporter-outfile=junit-slow.xml",
21
- "verify:all-sdks": "bun scripts/verify-all-sdks.ts",
22
- "lint": "biome lint --error-on-warnings .",
23
- "format:check": "biome format ."
24
- },
25
- "devDependencies": {
26
- "@types/bun": "^1"
27
- },
28
- "peerDependencies": {
29
- "typescript": "^6 || ^7"
30
- }
31
- }
@@ -1,10 +0,0 @@
1
- // owner: jyoung-q
2
- /**
3
- * Removes generated template dirs.
4
- */
5
-
6
- import { rmSync } from "node:fs";
7
- import { GENERATED_APPS_DIR } from "./paths.ts";
8
-
9
- rmSync(GENERATED_APPS_DIR, { recursive: true, force: true });
10
- console.log(" Removed: generated-apps/");
@@ -1,57 +0,0 @@
1
- // owner: jyoung-q
2
- /**
3
- * Scaffolds all templates into generated-apps/template-<name>/.
4
- * Run this before testing to create workspace-resolvable template instances.
5
- */
6
-
7
- import { mkdirSync, rmSync } from "node:fs";
8
- import { join } from "node:path";
9
- import { scaffoldApp } from "../../../projects/poe-tiles-cli/src/commands/init/scaffold.ts";
10
- import { TEMPLATES } from "..";
11
- import { GENERATED_APPS_DIR } from "./paths.ts";
12
-
13
- mkdirSync(GENERATED_APPS_DIR, { recursive: true });
14
-
15
- for (const template of TEMPLATES) {
16
- const dir = join(GENERATED_APPS_DIR, `template-${template}`);
17
- rmSync(dir, { recursive: true, force: true });
18
- scaffoldApp({
19
- appName: `template-${template}`,
20
- template,
21
- outputDir: dir,
22
- // Generated apps live inside the monorepo workspace, so resolve
23
- // `joiner-sdk` to `workspace:*` rather than the published tarball.
24
- // Without this, the base template's mutator tests fail with
25
- // "Export named 'waitForKeyExists' not found" because the tarball
26
- // SDK lags the workspace SDK. The tarball path is exercised
27
- // separately by `bun run test:generated-apps:all-sdks` /
28
- // `verify-all-sdks.ts`.
29
- internalMonoRepo: true,
30
- // Mirror `poe-tiles tiles init` CLI defaults so the generated-apps
31
- // suite verifies the actual getting-started experience — a user
32
- // running the CLI with no flags gets `--blank` + `--skills`, and any
33
- // regression that breaks build/test/e2e for that exact shape (or
34
- // drops the bundled SDK skills) must fail this suite.
35
- includeSkill: true,
36
- blank: true,
37
- });
38
- console.log(` Generated: ${template}`);
39
- }
40
-
41
- // The store-less variant behind `poe-tiles tiles init --no-store`. Generated
42
- // beside the default so the suite proves each template still installs,
43
- // type-checks, tests, and builds with synced-store removed.
44
- for (const template of TEMPLATES) {
45
- const dir = join(GENERATED_APPS_DIR, `template-${template}-no-store`);
46
- rmSync(dir, { recursive: true, force: true });
47
- scaffoldApp({
48
- appName: `template-${template}-no-store`,
49
- template,
50
- outputDir: dir,
51
- internalMonoRepo: true,
52
- includeSkill: true,
53
- blank: true,
54
- noStore: true,
55
- });
56
- console.log(` Generated (no-store): ${template}`);
57
- }
@@ -1,52 +0,0 @@
1
- import { copyFileSync, existsSync, mkdirSync, writeFileSync } from "node:fs";
2
- import { createRequire } from "node:module";
3
- import { join } from "node:path";
4
-
5
- /** Preserve only install evidence, never the scaffold's environment or credentials. */
6
- export function saveInstallDiagnostics(
7
- appDir: string,
8
- outputDir: string,
9
- ): void {
10
- mkdirSync(outputDir, { recursive: true });
11
- for (const name of ["package.json", "bun.lock"]) {
12
- const path = join(appDir, name);
13
- if (existsSync(path)) copyFileSync(path, join(outputDir, name));
14
- }
15
-
16
- const appRequire = createRequire(join(appDir, "package.json"));
17
- const resolutions: Record<string, string> = {};
18
- try {
19
- const vitePath = appRequire.resolve("vite/package.json");
20
- resolutions["vite"] = vitePath;
21
- copyFileSync(vitePath, join(outputDir, "vite-package.json"));
22
- // Follow Vite's dependency graph, including a nested Rollup installation.
23
- const rollupPath = createRequire(vitePath).resolve("rollup/package.json");
24
- resolutions["rollup"] = rollupPath;
25
- copyFileSync(rollupPath, join(outputDir, "rollup-package.json"));
26
- const rollupRequire = createRequire(rollupPath);
27
- const rollup: { optionalDependencies?: Record<string, string> } =
28
- rollupRequire(rollupPath);
29
- for (const name of Object.keys(rollup.optionalDependencies ?? {})) {
30
- try {
31
- resolutions[name] = rollupRequire.resolve(name);
32
- } catch (error) {
33
- resolutions[name] = String(error);
34
- }
35
- }
36
- } catch (error) {
37
- resolutions["error"] = String(error);
38
- }
39
- writeFileSync(
40
- join(outputDir, "resolution.json"),
41
- JSON.stringify(
42
- {
43
- platform: process.platform,
44
- arch: process.arch,
45
- bun: Bun.version,
46
- resolutions,
47
- },
48
- null,
49
- 2,
50
- ),
51
- );
52
- }
@@ -1,7 +0,0 @@
1
- // owner: jyoung-q
2
- /** Shared path constants for template generation scripts and tests. */
3
-
4
- import { join, resolve } from "node:path";
5
-
6
- export const MONOREPO_ROOT = resolve(import.meta.dir, "../../..");
7
- export const GENERATED_APPS_DIR = join(MONOREPO_ROOT, "generated-apps");
@@ -1,288 +0,0 @@
1
- // owner: jyoung-q
2
- /**
3
- * Lets the packed-SDK verification run a scaffold under either SDK dependency
4
- * key (`joiner-sdk` or the legacy `poe-tiles-sdk`), and repack the tarball
5
- * under either package name. Every tarball the release bot publishes must
6
- * install and build under both keys, because old projects keep the legacy
7
- * key with no end date:
8
- *
9
- * bun scripts/verify-local-sdk-tarball.ts \
10
- * [--dependency-key joiner-sdk|poe-tiles-sdk] \
11
- * [--tarball-name joiner-sdk|poe-tiles-sdk]
12
- *
13
- * `--dependency-key` (default `joiner-sdk`, what the CLI scaffold writes) is
14
- * the key the scaffolded projects install the SDK under and the name their
15
- * source imports. `--tarball-name` repacks the tarball under that package
16
- * name first (default: the name in the source package.json, `joiner-sdk`).
17
- */
18
-
19
- import assert from "node:assert/strict";
20
- import { execFileSync } from "node:child_process";
21
- import {
22
- copyFileSync,
23
- existsSync,
24
- mkdtempSync,
25
- readdirSync,
26
- readFileSync,
27
- rmSync,
28
- writeFileSync,
29
- } from "node:fs";
30
- import { tmpdir } from "node:os";
31
- import { extname, join } from "node:path";
32
- import { runVerificationCommand } from "./verify-local-sdk-command";
33
-
34
- export const SDK_DEPENDENCY_KEYS = ["poe-tiles-sdk", "joiner-sdk"] as const;
35
- export type SdkDependencyKey = (typeof SDK_DEPENDENCY_KEYS)[number];
36
-
37
- /** The key the CLI scaffold writes, and the packed tarball's `name`. */
38
- const SCAFFOLD_KEY: SdkDependencyKey = "joiner-sdk";
39
-
40
- export interface VerifyOptions {
41
- /** The key the scaffolded project installs the SDK under. */
42
- dependencyKey: SdkDependencyKey;
43
- /** Repack the tarball under this `name`; undefined keeps the packed name. */
44
- tarballName: SdkDependencyKey | undefined;
45
- }
46
-
47
- function parseKey(flag: string, value: string | undefined): SdkDependencyKey {
48
- const key = SDK_DEPENDENCY_KEYS.find((candidate) => candidate === value);
49
- if (!key) {
50
- throw new Error(
51
- `${flag} must be one of ${SDK_DEPENDENCY_KEYS.join(", ")}; got ${value ?? "nothing"}`,
52
- );
53
- }
54
- return key;
55
- }
56
-
57
- /** `--dependency-key <key>` and `--tarball-name <key>`; both optional. */
58
- export function parseVerifyOptions(argv: readonly string[]): VerifyOptions {
59
- const options: VerifyOptions = {
60
- dependencyKey: SCAFFOLD_KEY,
61
- tarballName: undefined,
62
- };
63
- for (let index = 0; index < argv.length; index += 1) {
64
- const flag = argv[index];
65
- const value = argv[index + 1];
66
- if (flag === "--dependency-key") {
67
- options.dependencyKey = parseKey(flag, value);
68
- } else if (flag === "--tarball-name") {
69
- options.tarballName = parseKey(flag, value);
70
- } else {
71
- throw new Error(`Unknown option: ${flag}`);
72
- }
73
- index += 1;
74
- }
75
- return options;
76
- }
77
-
78
- const QUOTED_SDK_SPECIFIER = /(["'`])joiner-sdk(?=["'`/])/g;
79
- const INSTALLED_SDK_PATH = /node_modules\/joiner-sdk(?=\/)/g;
80
-
81
- /** Rewrites quoted `joiner-sdk` specifiers and installed paths to `key`. */
82
- export function rewriteSdkSpecifiers(
83
- text: string,
84
- key: SdkDependencyKey,
85
- ): string {
86
- if (key === SCAFFOLD_KEY) return text;
87
- return text
88
- .replace(QUOTED_SDK_SPECIFIER, `$1${key}`)
89
- .replace(INSTALLED_SDK_PATH, `node_modules/${key}`);
90
- }
91
-
92
- const PROJECT_SOURCE_EXTENSIONS = new Set([
93
- ".ts",
94
- ".tsx",
95
- ".mts",
96
- ".cts",
97
- ".js",
98
- ".jsx",
99
- ".mjs",
100
- ".cjs",
101
- ".json",
102
- ".html",
103
- ]);
104
- const SKIPPED_DIRECTORIES = new Set(["node_modules", ".git", "dist"]);
105
-
106
- function* projectSourceFiles(dir: string): Generator<string> {
107
- for (const entry of readdirSync(dir, { withFileTypes: true })) {
108
- const path = join(dir, entry.name);
109
- if (entry.isDirectory()) {
110
- if (!SKIPPED_DIRECTORIES.has(entry.name)) yield* projectSourceFiles(path);
111
- } else if (
112
- entry.isFile() &&
113
- PROJECT_SOURCE_EXTENSIONS.has(extname(entry.name))
114
- ) {
115
- yield path;
116
- }
117
- }
118
- }
119
-
120
- type PackageJson = Record<string, unknown> & {
121
- dependencies?: Record<string, string>;
122
- devDependencies?: Record<string, string>;
123
- };
124
-
125
- /**
126
- * Moves a scaffolded project from the `joiner-sdk` key to `key`: the
127
- * dependency entry (renamed in place, so the manifest changes only by name)
128
- * and every import and installed path in its source.
129
- */
130
- export function useSdkDependencyKey(
131
- appDir: string,
132
- key: SdkDependencyKey,
133
- ): void {
134
- if (key === SCAFFOLD_KEY) return;
135
- for (const path of projectSourceFiles(appDir)) {
136
- const text = readFileSync(path, "utf8");
137
- const rewritten = rewriteSdkSpecifiers(text, key);
138
- if (rewritten !== text) writeFileSync(path, rewritten);
139
- }
140
- const manifestPath = join(appDir, "package.json");
141
- const manifest = JSON.parse(
142
- readFileSync(manifestPath, "utf8"),
143
- ) as PackageJson;
144
- const declared = [manifest.dependencies, manifest.devDependencies].some(
145
- (deps) => deps !== undefined && key in deps && !(SCAFFOLD_KEY in deps),
146
- );
147
- if (!declared) {
148
- throw new Error(`${manifestPath} must depend on ${key} only`);
149
- }
150
- }
151
-
152
- /**
153
- * The SDK's imports of its own entries, which the packer keeps external: the
154
- * `joiner-sdk/...` entries of `EXTERNAL` in
155
- * `packages/poe-tiles-sdk/scripts/publish-constants.ts`. A self-import missing
156
- * here keeps its old name in the repacked tarball and fails to resolve there,
157
- * so the verification fails loudly rather than passing on a stale list.
158
- */
159
- const SDK_SELF_IMPORTS = [
160
- "joiner-sdk/v1/test-utils/harness.js",
161
- "joiner-sdk/v1/test-utils/headless-element.js",
162
- "joiner-sdk/v1/test-utils.js",
163
- "joiner-sdk/v1/test-utils/playwright.js",
164
- ];
165
-
166
- /**
167
- * Rewrites the SDK's self-imports in one packed file to `name`. Only the
168
- * self-imports change: the wire specifiers the SDK emits into built tiles
169
- * (`poe-tiles-sdk/v1/client.js`) stay as they are.
170
- */
171
- export function renameSdkSelfImports(text: string, name: string): string {
172
- let result = text;
173
- for (const specifier of SDK_SELF_IMPORTS) {
174
- const renamed = `${name}${specifier.slice(SCAFFOLD_KEY.length)}`;
175
- for (const quote of ['"', "'"]) {
176
- result = result.replaceAll(
177
- `${quote}${specifier}${quote}`,
178
- `${quote}${renamed}${quote}`,
179
- );
180
- }
181
- }
182
- return result;
183
- }
184
-
185
- function* packedCodeFiles(dir: string): Generator<string> {
186
- for (const entry of readdirSync(dir, { withFileTypes: true })) {
187
- const path = join(dir, entry.name);
188
- if (entry.isDirectory()) yield* packedCodeFiles(path);
189
- else if (entry.name.endsWith(".js") || entry.name.endsWith(".d.ts"))
190
- yield path;
191
- }
192
- }
193
-
194
- /**
195
- * Repacks `sourceTarball` as `targetTarball` with package `name`, and its
196
- * self-imports under that name. This builds the tarball the workspace rename
197
- * will publish, from today's source, so both keys can be tested against it.
198
- */
199
- export function repackSdkTarballAs(
200
- sourceTarball: string,
201
- targetTarball: string,
202
- name: SdkDependencyKey,
203
- ): void {
204
- const workDir = mkdtempSync(join(tmpdir(), "sdk-tarball-repack-"));
205
- try {
206
- execFileSync("tar", ["xzf", sourceTarball, "-C", workDir]);
207
- const packageDir = join(workDir, "package");
208
- const manifestPath = join(packageDir, "package.json");
209
- const manifest = JSON.parse(readFileSync(manifestPath, "utf8")) as {
210
- name: string;
211
- };
212
- manifest.name = name;
213
- writeFileSync(manifestPath, `${JSON.stringify(manifest, null, "\t")}\n`);
214
- let rewrittenFiles = 0;
215
- for (const path of packedCodeFiles(packageDir)) {
216
- const text = readFileSync(path, "utf8");
217
- const rewritten = renameSdkSelfImports(text, name);
218
- if (rewritten === text) continue;
219
- writeFileSync(path, rewritten);
220
- rewrittenFiles += 1;
221
- }
222
- if (name !== SCAFFOLD_KEY && rewrittenFiles === 0) {
223
- throw new Error(
224
- "Repacked SDK tarball has no self-imports to rename; update SDK_SELF_IMPORTS",
225
- );
226
- }
227
- execFileSync("tar", [
228
- "czf",
229
- targetTarball,
230
- "--no-xattrs",
231
- "-C",
232
- workDir,
233
- "package",
234
- ]);
235
- } finally {
236
- rmSync(workDir, { recursive: true, force: true });
237
- }
238
- }
239
-
240
- /** The SDK is installed under the key only, from the tarball, by its packed name. */
241
- export function assertInstalledSdk(
242
- appDir: string,
243
- { dependencyKey, tarballName }: VerifyOptions,
244
- ): void {
245
- const manifestPath = join(
246
- appDir,
247
- "node_modules",
248
- dependencyKey,
249
- "package.json",
250
- );
251
- const manifest = JSON.parse(readFileSync(manifestPath, "utf8")) as {
252
- name: string;
253
- };
254
- const expected = tarballName ?? SCAFFOLD_KEY;
255
- assert.equal(
256
- manifest.name,
257
- expected,
258
- `${manifestPath} must name ${expected}`,
259
- );
260
- for (const other of SDK_DEPENDENCY_KEYS) {
261
- if (other === dependencyKey) continue;
262
- assert(
263
- !existsSync(join(appDir, "node_modules", other)),
264
- `the SDK must be installed under ${dependencyKey} only, not ${other}`,
265
- );
266
- }
267
- }
268
-
269
- /** Copies the packed tarball to `target`, repacked as `tarballName` if set. */
270
- export function stageSdkTarball(
271
- source: string,
272
- target: string,
273
- tarballName: SdkDependencyKey | undefined,
274
- ): void {
275
- if (tarballName === undefined) copyFileSync(source, target);
276
- else repackSdkTarballAs(source, target, tarballName);
277
- }
278
-
279
- /** Moves a scaffold to the key, installs it, and checks what got installed. */
280
- export function installWithSdkKey(
281
- appDir: string,
282
- options: VerifyOptions,
283
- label: string,
284
- ): void {
285
- useSdkDependencyKey(appDir, options.dependencyKey);
286
- runVerificationCommand(["bun", "install", "--ignore-scripts"], appDir, label);
287
- assertInstalledSdk(appDir, options);
288
- }