@joiner-platform/cli 0.0.0-stage → 0.1.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/README.md +30 -2
- package/bundled-resources/poe-tile-templates/base/CLAUDE.md +72 -0
- package/bundled-resources/poe-tile-templates/base/README.md +7 -0
- package/bundled-resources/poe-tile-templates/base/_bunfig.toml +8 -0
- package/bundled-resources/poe-tile-templates/base/_gitignore +18 -0
- package/bundled-resources/poe-tile-templates/base/client.ts +12 -0
- package/bundled-resources/poe-tile-templates/base/package.json +36 -0
- package/bundled-resources/poe-tile-templates/base/playwright.config.ts +38 -0
- package/bundled-resources/poe-tile-templates/base/scripts/check-source.ts +148 -0
- package/bundled-resources/poe-tile-templates/base/scripts/dev.ts +19 -0
- package/bundled-resources/poe-tile-templates/base/scripts/doctor.sh +29 -0
- package/bundled-resources/poe-tile-templates/base/scripts/visual-check.ts +64 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/backend-config.ts +9 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/client-config.ts +8 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/data/items.ts +16 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/index.ts +10 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/remove-todo.ts +5 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/set-todo.ts +20 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/types.ts +5 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators.test.ts +138 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/schema.ts +40 -0
- package/bundled-resources/poe-tile-templates/base/tests/e2e.test.playwright.ts +92 -0
- package/bundled-resources/poe-tile-templates/base/tests/mobile-viewport.test.playwright.ts +111 -0
- package/bundled-resources/poe-tile-templates/base/tests/render-check.test.playwright.ts +128 -0
- package/bundled-resources/poe-tile-templates/base/tests/screenshot.test.playwright.ts +86 -0
- package/bundled-resources/poe-tile-templates/base/tests/setup-dom.ts +70 -0
- package/bundled-resources/poe-tile-templates/base/tile/src/backend.ts +3 -0
- package/bundled-resources/poe-tile-templates/base/tile/styles.css +47 -0
- package/bundled-resources/poe-tile-templates/base/tsconfig.json +13 -0
- package/bundled-resources/poe-tile-templates/coverage.config.json +6 -0
- package/bundled-resources/poe-tile-templates/index.ts +27 -0
- package/bundled-resources/poe-tile-templates/package.json +31 -0
- package/bundled-resources/poe-tile-templates/phaserjs/package.partial.json +6 -0
- package/bundled-resources/poe-tile-templates/phaserjs/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/phaserjs/tile/src/entry.ts +35 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/App.test.happydom.tsx +98 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/App.ts +180 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/phaser-scene.ts +174 -0
- package/bundled-resources/poe-tile-templates/phaserjs/vite.config.ts +28 -0
- package/bundled-resources/poe-tile-templates/preact/package.partial.json +9 -0
- package/bundled-resources/poe-tile-templates/preact/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/preact/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/preact/tile/src/entry.tsx +36 -0
- package/bundled-resources/poe-tile-templates/preact/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/preact/tsconfig.json +15 -0
- package/bundled-resources/poe-tile-templates/preact/ui/App.test.happydom.tsx +69 -0
- package/bundled-resources/poe-tile-templates/preact/ui/App.tsx +116 -0
- package/bundled-resources/poe-tile-templates/preact/vite.config.ts +18 -0
- package/bundled-resources/poe-tile-templates/react/package.partial.json +12 -0
- package/bundled-resources/poe-tile-templates/react/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/react/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/react/tile/src/entry.tsx +38 -0
- package/bundled-resources/poe-tile-templates/react/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/react/tsconfig.json +14 -0
- package/bundled-resources/poe-tile-templates/react/ui/App.test.happydom.tsx +71 -0
- package/bundled-resources/poe-tile-templates/react/ui/App.tsx +110 -0
- package/bundled-resources/poe-tile-templates/react/vite.config.ts +21 -0
- package/bundled-resources/poe-tile-templates/scripts/cleanup.ts +10 -0
- package/bundled-resources/poe-tile-templates/scripts/generate.ts +57 -0
- package/bundled-resources/poe-tile-templates/scripts/install-diagnostics.ts +52 -0
- package/bundled-resources/poe-tile-templates/scripts/paths.ts +7 -0
- package/bundled-resources/poe-tile-templates/scripts/sdk-dependency-key.ts +288 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-all-sdks.ts +132 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-command.ts +30 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-tarball.ts +397 -0
- package/bundled-resources/poe-tile-templates/solidjs/_bunfig.toml +14 -0
- package/bundled-resources/poe-tile-templates/solidjs/package.partial.json +13 -0
- package/bundled-resources/poe-tile-templates/solidjs/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/solidjs/tests/solid-plugin.ts +49 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/src/entry.tsx +36 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/solidjs/tsconfig.json +15 -0
- package/bundled-resources/poe-tile-templates/solidjs/ui/App.test.happydom.tsx +70 -0
- package/bundled-resources/poe-tile-templates/solidjs/ui/App.tsx +129 -0
- package/bundled-resources/poe-tile-templates/solidjs/vite.config.ts +18 -0
- package/bundled-resources/poe-tile-templates/tests/check-source.test.ts +131 -0
- package/bundled-resources/poe-tile-templates/tests/dev-script.test.slow.ts +166 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/customized-manager.ts +67 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/extended-mutators.ts.txt +106 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/multiplayer-verification.test.playwright.ts.txt +103 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/replace-starter-schema.ts +67 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/phaserjs.tsx.txt +85 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/preact.tsx.txt +69 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/react.tsx.txt +73 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/seating.ts.txt +54 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/solidjs.tsx.txt +70 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/vanilla-js.tsx.txt +85 -0
- package/bundled-resources/poe-tile-templates/tests/generated-templates.test.ts +278 -0
- package/bundled-resources/poe-tile-templates/tests/happy-dom-version.test.ts +27 -0
- package/bundled-resources/poe-tile-templates/tests/install-diagnostics.test.ts +99 -0
- package/bundled-resources/poe-tile-templates/tests/native-gesture-defaults.test.ts +23 -0
- package/bundled-resources/poe-tile-templates/tests/playwright-version.test.ts +84 -0
- package/bundled-resources/poe-tile-templates/tests/render-check-scaffold.test.ts +56 -0
- package/bundled-resources/poe-tile-templates/tests/sdk-dependency-key.test.ts +129 -0
- package/bundled-resources/poe-tile-templates/tests/visual-check.test.ts +90 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/package.partial.json +3 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/tile/src/entry.ts +35 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/ui/App.test.happydom.tsx +96 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/ui/App.ts +113 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/vite.config.ts +17 -0
- package/cli.ts +134 -0
- package/index.ts +96 -0
- package/package.json +48 -5
- package/skills/audio-generation/.generated-by-poe-templated-docs +0 -0
- package/skills/audio-generation/SKILL.md +125 -0
- package/skills/finish-prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/finish-prototype/SKILL.md +22 -0
- package/skills/help-me-build/.generated-by-poe-templated-docs +0 -0
- package/skills/help-me-build/SKILL.md +56 -0
- package/skills/image-generation/.generated-by-poe-templated-docs +0 -0
- package/skills/image-generation/SKILL.md +128 -0
- package/skills/one-shot/.generated-by-poe-templated-docs +0 -0
- package/skills/one-shot/SKILL.md +22 -0
- package/skills/platform-prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/platform-prototype/SKILL.md +60 -0
- package/skills/platform-subagent/.generated-by-poe-templated-docs +0 -0
- package/skills/platform-subagent/SKILL.md +16 -0
- package/skills/poe-tiles-cli/.generated-by-poe-templated-docs +0 -0
- package/skills/poe-tiles-cli/SKILL.md +609 -0
- package/skills/poe-tiles-cli/references/device-motion.md +40 -0
- package/skills/poe-tiles-cli/references/player-updates.md +41 -0
- package/skills/prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/prototype/SKILL.md +149 -0
- package/skills/publish/.generated-by-poe-templated-docs +0 -0
- package/skills/publish/SKILL.md +73 -0
- package/skills/synced-store/.generated-by-poe-templated-docs +0 -0
- package/skills/synced-store/SKILL.md +583 -0
- package/skills/synced-store/references/actions.md +85 -0
- package/skills/synced-store/references/api-patterns.md +245 -0
- package/skills/synced-store/references/architecture-scaling-and-performance.md +280 -0
- package/skills/synced-store/references/client-api-reference.md +263 -0
- package/skills/synced-store/references/data-visibility.md +95 -0
- package/skills/synced-store/references/external-stores.md +162 -0
- package/skills/synced-store/references/file-uploads.md +216 -0
- package/skills/synced-store/references/getting-user-info-of-members.md +228 -0
- package/skills/synced-store/references/limitations.md +72 -0
- package/skills/synced-store/references/live-data-limit-hook.md +131 -0
- package/skills/synced-store/references/mutator-rules.md +169 -0
- package/skills/synced-store/references/platform.md +49 -0
- package/skills/synced-store/references/schema-and-bindings.md +85 -0
- package/skills/synced-store/references/schema-libraries.md +57 -0
- package/skills/synced-store/references/schema-migrations.md +119 -0
- package/skills/synced-store/references/searchable-tables.md +27 -0
- package/skills/synced-store/references/server-forking.md +115 -0
- package/skills/synced-store/references/singleton-tables.md +61 -0
- package/skills/synced-store/references/sort-keys.md +253 -0
- package/skills/synced-store/references/ui-patterns.md +95 -0
- package/skills/tile-creator/.generated-by-poe-templated-docs +0 -0
- package/skills/tile-creator/SKILL.md +197 -0
- package/skills/tile-creator/references/assets.md +124 -0
- package/skills/tile-creator/references/backend-api.md +354 -0
- package/skills/tile-creator/references/cli-limitations.md +64 -0
- package/skills/tile-creator/references/cli.md +604 -0
- package/skills/tile-creator/references/client-api.md +2407 -0
- package/skills/tile-creator/references/composing-apps.md +166 -0
- package/skills/tile-creator/references/e2e-tests.md +55 -0
- package/skills/tile-creator/references/game-ux-best-practices.md +57 -0
- package/skills/tile-creator/references/migrating-pre-rename-tiles.md +79 -0
- package/skills/tile-creator/references/multiplayer-api-recipe.md +205 -0
- package/skills/tile-creator/references/native-results.md +100 -0
- package/skills/tile-creator/references/platform-integration.md +201 -0
- package/skills/tile-creator/references/power-report.md +199 -0
- package/skills/tile-creator/references/publish-rollout.md +166 -0
- package/skills/tile-creator/references/publishing.md +33 -0
- package/skills/tile-creator/references/push-notification-guidelines.md +58 -0
- package/skills/tile-creator/references/render-check.md +266 -0
- package/skills/tile-creator/references/running-the-client-api-on-a-server-owned-by-the-user.md +95 -0
- package/skills/tile-creator/references/safe-area-insets.md +79 -0
- package/skills/tile-creator/references/sandbox-limitations.md +32 -0
- package/skills/tile-creator/references/scaffolded-tile-folder-structure.md +48 -0
- package/skills/tile-creator/references/scaffolding-a-new-app.md +202 -0
- package/skills/tile-creator/references/simulations.md +125 -0
- package/skills/tile-creator/references/synced-store-client-reference.md +92 -0
- package/skills/tile-creator/references/troubleshooting.md +22 -0
- package/skills/tile-creator/references/turn-based-mutator.md +43 -0
- package/skills/tile-creator/references/user-erasure.md +14 -0
- package/skills/tile-creator/references/vite-plugin.md +166 -0
- package/skills/tile-creator/references/workspace-retention.md +72 -0
- package/src/admin-conversions-client.ts +28 -0
- package/src/admin-reviews-client.ts +36 -0
- package/src/api.generated.ts +1527 -0
- package/src/auth-token.ts +198 -0
- package/src/bounded-read.ts +35 -0
- package/src/bun-version.ts +33 -0
- package/src/checkout-base.ts +207 -0
- package/src/cli-bun-version.ts +16 -0
- package/src/cli-env.ts +28 -0
- package/src/cli-name.ts +23 -0
- package/src/client.ts +2474 -0
- package/src/collect-files.ts +226 -0
- package/src/commands/accounts.ts +55 -0
- package/src/commands/admin-abandon-conversion.ts +60 -0
- package/src/commands/admin-reviews.ts +66 -0
- package/src/commands/admin.ts +219 -0
- package/src/commands/auth.ts +89 -0
- package/src/commands/checkout-prototype.ts +67 -0
- package/src/commands/creator-source-capability.ts +11 -0
- package/src/commands/doctor-bun.ts +145 -0
- package/src/commands/doctor-command.ts +64 -0
- package/src/commands/doctor-package-json.ts +47 -0
- package/src/commands/doctor-sdk-pin.ts +156 -0
- package/src/commands/doctor-store-keys-lexer.ts +213 -0
- package/src/commands/doctor-store-keys-scan.ts +262 -0
- package/src/commands/doctor-store-keys.ts +196 -0
- package/src/commands/doctor.ts +371 -0
- package/src/commands/init/blank-scaffold-templates.ts +397 -0
- package/src/commands/init/index.ts +170 -0
- package/src/commands/init/internal-toolchain.ts +49 -0
- package/src/commands/init/manager-test-template.ts +107 -0
- package/src/commands/init/multiplayer-test-template.ts +217 -0
- package/src/commands/init/name-input.tsx +167 -0
- package/src/commands/init/no-store-scaffold-templates.ts +281 -0
- package/src/commands/init/no-store-scaffold.ts +134 -0
- package/src/commands/init/package-json-scripts.ts +72 -0
- package/src/commands/init/scaffold.ts +960 -0
- package/src/commands/init/sdk-tarball-url.generated.ts +4 -0
- package/src/commands/init/sdk-tarball-url.ts +31 -0
- package/src/commands/init/template-picker.tsx +147 -0
- package/src/commands/inspect-child-entry.ts +107 -0
- package/src/commands/inspect-contract.ts +87 -0
- package/src/commands/inspect-freshness.ts +217 -0
- package/src/commands/inspect-lock.ts +201 -0
- package/src/commands/inspect-options.ts +360 -0
- package/src/commands/inspect-orchestrate.ts +375 -0
- package/src/commands/inspect-process.ts +172 -0
- package/src/commands/inspect-ready.ts +65 -0
- package/src/commands/inspect-report.ts +235 -0
- package/src/commands/inspect-run-state.ts +296 -0
- package/src/commands/inspect-run.ts +157 -0
- package/src/commands/inspect-watchdog.ts +74 -0
- package/src/commands/install-joiner.ts +208 -0
- package/src/commands/login.ts +308 -0
- package/src/commands/models.ts +40 -0
- package/src/commands/parse-options.ts +36 -0
- package/src/commands/remix-package-json.ts +64 -0
- package/src/commands/remix.ts +379 -0
- package/src/commands/sdk-url.ts +141 -0
- package/src/commands/simulations.ts +133 -0
- package/src/commands/skills.ts +108 -0
- package/src/commands/store-files.ts +92 -0
- package/src/commands/stores.ts +703 -0
- package/src/commands/tiles-channel-commands.ts +115 -0
- package/src/commands/tiles-checkout.ts +351 -0
- package/src/commands/tiles-gallery-command.ts +95 -0
- package/src/commands/tiles-get-helpers.ts +27 -0
- package/src/commands/tiles-inspect.ts +276 -0
- package/src/commands/tiles-power-command.ts +308 -0
- package/src/commands/tiles-power-format.ts +396 -0
- package/src/commands/tiles-power-versions.ts +299 -0
- package/src/commands/tiles-publish-helpers.ts +145 -0
- package/src/commands/tiles-upload-command.ts +277 -0
- package/src/commands/tiles-version-commands.ts +201 -0
- package/src/commands/tiles-visibility-command.ts +103 -0
- package/src/commands/tiles.ts +257 -0
- package/src/commands/upgrade.ts +307 -0
- package/src/commit-in-progress.ts +42 -0
- package/src/creator-source-context.ts +97 -0
- package/src/creator-source-publish.ts +52 -0
- package/src/deferred-assets.ts +125 -0
- package/src/distribution.ts +28 -0
- package/src/errors.ts +61 -0
- package/src/install-command.ts +43 -0
- package/src/output.ts +62 -0
- package/src/poe-tile-config-files.ts +100 -0
- package/src/poe-tile-config-players.ts +168 -0
- package/src/poe-tile-config-remix.ts +166 -0
- package/src/poe-tile-config.ts +831 -0
- package/src/power-report-client.ts +55 -0
- package/src/prototype-startup.ts +21 -0
- package/src/publish-change-summary.ts +55 -0
- package/src/publish-overrides-validation.ts +49 -0
- package/src/publish-pack.ts +167 -0
- package/src/publish-phases.ts +57 -0
- package/src/publish-retry.ts +51 -0
- package/src/publish-tile-from-config.ts +434 -0
- package/src/recorder-stream.ts +169 -0
- package/src/remix-provenance.ts +156 -0
- package/src/resolve-client-credential.ts +71 -0
- package/src/resolve-media-uploads.ts +147 -0
- package/src/sdk-dependency.ts +54 -0
- package/src/sdk-skills.ts +85 -0
- package/src/should-skip-client-setup.ts +20 -0
- package/src/simulation-snapshot.ts +123 -0
- package/src/simulation-types.ts +74 -0
- package/src/simulations-client.ts +112 -0
- package/src/source-bundle.ts +466 -0
- package/src/staged-publish-cleanup.ts +44 -0
- package/src/staged-publish-deferred.ts +160 -0
- package/src/staged-publish.ts +401 -0
- package/src/store-file-upload.ts +268 -0
- package/src/store-request.ts +168 -0
- package/src/tar-canonical.ts +41 -0
- package/src/tar-extensions.ts +159 -0
- package/src/tar-extract.ts +193 -0
- package/src/tar-parse.ts +224 -0
- package/src/tar.ts +231 -0
- package/src/template-check-scripts.ts +18 -0
- package/src/tile-gallery-client.ts +82 -0
- package/src/types.ts +258 -0
- package/src/upload-concurrency.ts +54 -0
- package/src/whole-tile.ts +52 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// owner: aaronroe
|
|
2
|
+
/**
|
|
3
|
+
* A small JavaScript/TypeScript lexer for the `poe-tiles doctor` store-key
|
|
4
|
+
* check. It is not a parser: it finds string and template literals and masks
|
|
5
|
+
* comments, literal text, and regex bodies, so the check can match call
|
|
6
|
+
* shapes with regular expressions over code only.
|
|
7
|
+
*
|
|
8
|
+
* `masked` has the same length and line breaks as the source. Comment text,
|
|
9
|
+
* string contents, template static text, and regex bodies become spaces;
|
|
10
|
+
* quotes, backticks, and the code inside `${...}` stay, so a literal nested
|
|
11
|
+
* inside a template expression is still found with its own context.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export interface LiteralToken {
|
|
15
|
+
/** Index of the opening quote or backtick. */
|
|
16
|
+
start: number;
|
|
17
|
+
/** Literal text outside `${...}`, with escapes kept raw. */
|
|
18
|
+
staticText: string;
|
|
19
|
+
/** Source of each `${...}` expression (template literals only). */
|
|
20
|
+
expressions: string[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface LexedSource {
|
|
24
|
+
masked: string;
|
|
25
|
+
literals: LiteralToken[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type Frame =
|
|
29
|
+
| { kind: "template"; token: LiteralToken }
|
|
30
|
+
| { kind: "expr"; token: LiteralToken; depth: number; exprStart: number };
|
|
31
|
+
|
|
32
|
+
interface LexState {
|
|
33
|
+
src: string;
|
|
34
|
+
out: string[];
|
|
35
|
+
literals: LiteralToken[];
|
|
36
|
+
stack: Frame[];
|
|
37
|
+
i: number;
|
|
38
|
+
/** Index of the last significant code character, or -1. */
|
|
39
|
+
lastCode: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const REGEX_AFTER_PUNCTUATION = /[(,=:[!&|?{;+\-*%<>~^]/;
|
|
43
|
+
const REGEX_AFTER_KEYWORDS = new Set([
|
|
44
|
+
"return",
|
|
45
|
+
"typeof",
|
|
46
|
+
"case",
|
|
47
|
+
"do",
|
|
48
|
+
"else",
|
|
49
|
+
"in",
|
|
50
|
+
"of",
|
|
51
|
+
"void",
|
|
52
|
+
"yield",
|
|
53
|
+
"await",
|
|
54
|
+
"delete",
|
|
55
|
+
"new",
|
|
56
|
+
"throw",
|
|
57
|
+
"instanceof",
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
export function lexSource(src: string): LexedSource {
|
|
61
|
+
const state: LexState = {
|
|
62
|
+
src,
|
|
63
|
+
out: src.split(""),
|
|
64
|
+
literals: [],
|
|
65
|
+
stack: [],
|
|
66
|
+
i: 0,
|
|
67
|
+
lastCode: -1,
|
|
68
|
+
};
|
|
69
|
+
while (state.i < src.length) {
|
|
70
|
+
const top = state.stack.at(-1);
|
|
71
|
+
if (top?.kind === "template") stepTemplate(state, top.token);
|
|
72
|
+
else stepCode(state, top);
|
|
73
|
+
}
|
|
74
|
+
return { masked: state.out.join(""), literals: state.literals };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function stepTemplate(s: LexState, token: LiteralToken): void {
|
|
78
|
+
const c = s.src[s.i];
|
|
79
|
+
if (c === "\\") {
|
|
80
|
+
token.staticText += s.src.slice(s.i, s.i + 2);
|
|
81
|
+
mask(s, s.i, s.i + 2);
|
|
82
|
+
s.i += 2;
|
|
83
|
+
} else if (c === "`") {
|
|
84
|
+
s.stack.pop();
|
|
85
|
+
s.lastCode = s.i;
|
|
86
|
+
s.i++;
|
|
87
|
+
} else if (c === "$" && s.src[s.i + 1] === "{") {
|
|
88
|
+
s.stack.push({ kind: "expr", token, depth: 0, exprStart: s.i + 2 });
|
|
89
|
+
s.lastCode = s.i + 1;
|
|
90
|
+
s.i += 2;
|
|
91
|
+
} else {
|
|
92
|
+
token.staticText += c;
|
|
93
|
+
mask(s, s.i, s.i + 1);
|
|
94
|
+
s.i++;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function stepCode(s: LexState, frame: Frame | undefined): void {
|
|
99
|
+
const c = s.src[s.i]!;
|
|
100
|
+
if (c === "/" && readSlash(s)) return;
|
|
101
|
+
if (c === '"' || c === "'") return readQuoted(s, c);
|
|
102
|
+
if (c === "`") return openTemplate(s);
|
|
103
|
+
if (frame?.kind === "expr" && closesExpression(s, frame, c)) return;
|
|
104
|
+
if (!/\s/.test(c)) s.lastCode = s.i;
|
|
105
|
+
s.i++;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Consumes a comment or regex at `/`; false leaves a division operator. */
|
|
109
|
+
function readSlash(s: LexState): boolean {
|
|
110
|
+
const next = s.src[s.i + 1];
|
|
111
|
+
if (next === "/" || next === "*") {
|
|
112
|
+
skipComment(s, next);
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
return regexAllowed(s) && skipRegex(s);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function skipComment(s: LexState, kind: string | undefined): void {
|
|
119
|
+
const end =
|
|
120
|
+
kind === "/"
|
|
121
|
+
? indexOrEnd(s.src, s.src.indexOf("\n", s.i))
|
|
122
|
+
: indexOrEnd(s.src, s.src.indexOf("*/", s.i + 2), 2);
|
|
123
|
+
mask(s, s.i, end);
|
|
124
|
+
s.i = end;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function indexOrEnd(src: string, index: number, width = 0): number {
|
|
128
|
+
return index < 0 ? src.length : index + width;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function readQuoted(s: LexState, quote: string): void {
|
|
132
|
+
let j = s.i + 1;
|
|
133
|
+
while (j < s.src.length && s.src[j] !== quote && s.src[j] !== "\n") {
|
|
134
|
+
j += s.src[j] === "\\" ? 2 : 1;
|
|
135
|
+
}
|
|
136
|
+
// An unterminated quote ends at the line break, so a stray apostrophe in
|
|
137
|
+
// JSX text cannot swallow the rest of the file.
|
|
138
|
+
s.literals.push({
|
|
139
|
+
start: s.i,
|
|
140
|
+
staticText: s.src.slice(s.i + 1, j),
|
|
141
|
+
expressions: [],
|
|
142
|
+
});
|
|
143
|
+
mask(s, s.i + 1, j);
|
|
144
|
+
const end = s.src[j] === quote ? j + 1 : j;
|
|
145
|
+
s.lastCode = end - 1;
|
|
146
|
+
s.i = end;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function openTemplate(s: LexState): void {
|
|
150
|
+
const token: LiteralToken = { start: s.i, staticText: "", expressions: [] };
|
|
151
|
+
s.literals.push(token);
|
|
152
|
+
s.stack.push({ kind: "template", token });
|
|
153
|
+
s.i++;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function closesExpression(
|
|
157
|
+
s: LexState,
|
|
158
|
+
frame: Extract<Frame, { kind: "expr" }>,
|
|
159
|
+
c: string,
|
|
160
|
+
): boolean {
|
|
161
|
+
if (c === "{") frame.depth++;
|
|
162
|
+
if (c !== "}") return false;
|
|
163
|
+
if (frame.depth > 0) {
|
|
164
|
+
frame.depth--;
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
frame.token.expressions.push(s.src.slice(frame.exprStart, s.i));
|
|
168
|
+
s.stack.pop();
|
|
169
|
+
s.i++;
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function regexAllowed(s: LexState): boolean {
|
|
174
|
+
if (s.lastCode < 0) return true;
|
|
175
|
+
const previous = s.src[s.lastCode]!;
|
|
176
|
+
if (REGEX_AFTER_PUNCTUATION.test(previous)) return true;
|
|
177
|
+
return REGEX_AFTER_KEYWORDS.has(wordEndingAt(s.src, s.lastCode));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function wordEndingAt(src: string, index: number): string {
|
|
181
|
+
let k = index;
|
|
182
|
+
while (k >= 0 && /[\w$]/.test(src[k]!)) k--;
|
|
183
|
+
return src.slice(k + 1, index + 1);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Masks a regex literal; returns false (division) when none closes on the line. */
|
|
187
|
+
function skipRegex(s: LexState): boolean {
|
|
188
|
+
const end = findRegexEnd(s.src, s.i + 1);
|
|
189
|
+
if (end === null) return false;
|
|
190
|
+
let j = end + 1;
|
|
191
|
+
while (/[a-z]/i.test(s.src[j] ?? "")) j++;
|
|
192
|
+
mask(s, s.i + 1, end);
|
|
193
|
+
s.lastCode = j - 1;
|
|
194
|
+
s.i = j;
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function findRegexEnd(src: string, from: number): number | null {
|
|
199
|
+
let inClass = false;
|
|
200
|
+
for (let j = from; j < src.length && src[j] !== "\n"; j++) {
|
|
201
|
+
const ch = src[j];
|
|
202
|
+
if (ch === "\\") j++;
|
|
203
|
+
else if (ch === "/" && !inClass) return j;
|
|
204
|
+
else if (ch === "[" || ch === "]") inClass = ch === "[";
|
|
205
|
+
}
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function mask(s: LexState, from: number, to: number): void {
|
|
210
|
+
for (let k = from; k < Math.min(to, s.out.length); k++) {
|
|
211
|
+
if (s.out[k] !== "\n") s.out[k] = " ";
|
|
212
|
+
}
|
|
213
|
+
}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
// owner: aaronroe
|
|
2
|
+
/**
|
|
3
|
+
* Static scan for synced-store keys that contain ':'.
|
|
4
|
+
*
|
|
5
|
+
* The store rejects ':' in a table name, itemKey, sortKey, or privateOfUser
|
|
6
|
+
* user id, but only when that code path runs, so a rare path (a cooldown
|
|
7
|
+
* row, a per-day save) can ship broken. This scan reads source text with
|
|
8
|
+
* regular expressions over `lexSource`'s masked code; it does not parse.
|
|
9
|
+
*
|
|
10
|
+
* A "colon literal" is a string or template literal with ':' outside
|
|
11
|
+
* `${...}`, or a template whose `${...}` ends in `.toISOString()` and the
|
|
12
|
+
* like. Only a literal can be checked; a computed value is not followed.
|
|
13
|
+
*
|
|
14
|
+
* - `hits` "fail": a colon literal passed straight to the store: the value
|
|
15
|
+
* of an `itemKey:` / `sortKey:` property in a store file, the argument of
|
|
16
|
+
* `.table(` or `.privateOfUser(`, or the key argument of `.get(` /
|
|
17
|
+
* `.has(` / `.delete(` on a `.table(...)` chain or on a variable assigned
|
|
18
|
+
* from one. `itemKey: date.toISOString()` also fails.
|
|
19
|
+
* - `hits` "warn": the same `itemKey:` / `sortKey:` shapes outside a store
|
|
20
|
+
* file, where the object may not reach the store.
|
|
21
|
+
* - `candidates`: a colon literal assigned to `const NAME` or returned from
|
|
22
|
+
* function NAME. `keyNames` lists the names this file passes in a key
|
|
23
|
+
* position. The doctor check fails a candidate whose name this store file
|
|
24
|
+
* itself passes as a key, and warns when the name is passed as a key only
|
|
25
|
+
* in a non-store file or in another file (top-level candidates), so a
|
|
26
|
+
* `const key = ...` used only for a Map stays quiet.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { type LiteralToken, lexSource } from "./doctor-store-keys-lexer.js";
|
|
30
|
+
|
|
31
|
+
export interface StoreKeyHit {
|
|
32
|
+
line: number;
|
|
33
|
+
severity: "fail" | "warn";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface StoreKeyCandidate {
|
|
37
|
+
line: number;
|
|
38
|
+
name: string;
|
|
39
|
+
/** Declared outside every block, so another file may import it. */
|
|
40
|
+
topLevel: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface StoreKeyScan {
|
|
44
|
+
/** Under a store path, or calls `.table(` / `.privateOfUser(` / `.serverOnly(`. */
|
|
45
|
+
storeFile: boolean;
|
|
46
|
+
hits: StoreKeyHit[];
|
|
47
|
+
candidates: StoreKeyCandidate[];
|
|
48
|
+
keyNames: string[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const IDENTIFIER = String.raw`[A-Za-z_$][\w$]*`;
|
|
52
|
+
/** An optional `a + ` prefix, so `itemKey: prefix + ":x"` still matches. */
|
|
53
|
+
const CONCAT = String.raw`(?:[^;,{}()?\n]*\+\s*)?`;
|
|
54
|
+
/** A bare identifier argument: `name` or `name(`, not `obj.name`. */
|
|
55
|
+
const NAME_ARGUMENT = String.raw`(${IDENTIFIER})\b(?!\s*[.[])`;
|
|
56
|
+
const KEY_PROPERTY = String.raw`[{,]\s*(?:itemKey|sortKey)\s*:\s*`;
|
|
57
|
+
const TABLE_KEY_CALL = String.raw`\.table\s*\([^()]*\)\s*\.(?:get|has|delete)\s*\(\s*`;
|
|
58
|
+
const KEY_PROPERTY_LITERAL = new RegExp(`${KEY_PROPERTY}${CONCAT}$`);
|
|
59
|
+
const STORE_CALL_LITERALS = [
|
|
60
|
+
new RegExp(String.raw`\.(?:table|privateOfUser)\s*\(\s*${CONCAT}$`),
|
|
61
|
+
new RegExp(`${TABLE_KEY_CALL}${CONCAT}$`),
|
|
62
|
+
];
|
|
63
|
+
const KEY_NAME_POSITIONS = [
|
|
64
|
+
new RegExp(`${KEY_PROPERTY}(?:await\\s+)?${NAME_ARGUMENT}`, "g"),
|
|
65
|
+
/[{,]\s*(itemKey|sortKey)\s*(?=[,}])/g,
|
|
66
|
+
new RegExp(`${TABLE_KEY_CALL}${NAME_ARGUMENT}`, "g"),
|
|
67
|
+
new RegExp(String.raw`\.privateOfUser\s*\(\s*${NAME_ARGUMENT}`, "g"),
|
|
68
|
+
];
|
|
69
|
+
const TABLE_VARIABLE = new RegExp(
|
|
70
|
+
String.raw`\b(?:const|let|var)\s+(${IDENTIFIER})\s*(?::[^=\n]*)?=\s*[^;=\n]*?\.table\s*\([^()]*\)\s*(?:;|\n)`,
|
|
71
|
+
"g",
|
|
72
|
+
);
|
|
73
|
+
const NAMED_VALUE_CONTEXTS = [
|
|
74
|
+
new RegExp(
|
|
75
|
+
String.raw`\b(?:const|let|var)\s+(${IDENTIFIER})\s*(?::[^=\n]*)?=\s*${CONCAT}$`,
|
|
76
|
+
),
|
|
77
|
+
new RegExp(
|
|
78
|
+
String.raw`\b(?:const|let|var)\s+(${IDENTIFIER})\s*=\s*(?:async\s*)?(?:\([^()]*\)|[\w$]+)\s*(?::[^=\n]*)?=>\s*${CONCAT}$`,
|
|
79
|
+
),
|
|
80
|
+
];
|
|
81
|
+
const RETURN_CONTEXT = new RegExp(String.raw`\breturn\s*${CONCAT}$`);
|
|
82
|
+
const COLON_VALUE_CALL = String.raw`\.(?:toISOString|toTimeString|toLocaleTimeString)\([^()]*\)\s*`;
|
|
83
|
+
const KEY_PROPERTY_COLON_CALL = new RegExp(
|
|
84
|
+
`${KEY_PROPERTY}[^,{}\\n]*?${COLON_VALUE_CALL}(?=[,}\\n])`,
|
|
85
|
+
"g",
|
|
86
|
+
);
|
|
87
|
+
const STORE_CODE = /\.(?:table|privateOfUser|serverOnly)\s*\(/;
|
|
88
|
+
const STORE_PATH = /(?:^|\/)(?:synced-store|shared|mutators)\//;
|
|
89
|
+
const TYPE_NAMES = new Set(["string", "number", "bigint", "boolean", "any"]);
|
|
90
|
+
const CONTROL_KEYWORDS = new Set(["if", "for", "while", "switch", "catch"]);
|
|
91
|
+
const FUNCTION_HEADERS = [
|
|
92
|
+
/\bfunction\s*\*?\s*([\w$]+)\s*\([^()]*\)\s*(?::[^{}()]*)?$/,
|
|
93
|
+
/\b(?:const|let|var)\s+([\w$]+)\s*(?::[^=\n]*)?=\s*(?:async\s*)?(?:\([^()]*\)|[\w$]+)\s*(?::[^{}()=]*)?=>\s*$/,
|
|
94
|
+
/()=>\s*$/,
|
|
95
|
+
/(?:^|[^\w$.])([\w$]+)\s*\([^()]*\)\s*(?::[^{}()]*)?$/,
|
|
96
|
+
];
|
|
97
|
+
const CONTEXT_CHARS = 400;
|
|
98
|
+
const HEADER_CHARS = 200;
|
|
99
|
+
const MAX_ENCLOSING_BLOCKS = 6;
|
|
100
|
+
|
|
101
|
+
/** `path` is project-relative with '/' separators; it marks store files. */
|
|
102
|
+
export function scanStoreKeySource(source: string, path: string): StoreKeyScan {
|
|
103
|
+
const { masked, literals } = lexSource(source);
|
|
104
|
+
const storeFile = STORE_PATH.test(path) || STORE_CODE.test(masked);
|
|
105
|
+
const tableVariables = matchNames(masked, [TABLE_VARIABLE]);
|
|
106
|
+
const tableCall = tableVariableContext(tableVariables, CONCAT + "$");
|
|
107
|
+
const { hits, candidates } = scanLiterals(source, masked, literals, {
|
|
108
|
+
storeFile,
|
|
109
|
+
tableCall,
|
|
110
|
+
});
|
|
111
|
+
for (const match of masked.matchAll(KEY_PROPERTY_COLON_CALL)) {
|
|
112
|
+
hits.push({ index: match.index, severity: storeFile ? "fail" : "warn" });
|
|
113
|
+
}
|
|
114
|
+
const tableArgument = tableVariableContext(tableVariables, NAME_ARGUMENT);
|
|
115
|
+
return {
|
|
116
|
+
storeFile,
|
|
117
|
+
hits: hits
|
|
118
|
+
.sort((a, b) => a.index - b.index)
|
|
119
|
+
.map((hit) => ({
|
|
120
|
+
line: lineAt(source, hit.index),
|
|
121
|
+
severity: hit.severity,
|
|
122
|
+
})),
|
|
123
|
+
candidates,
|
|
124
|
+
keyNames: matchNames(masked, [
|
|
125
|
+
...KEY_NAME_POSITIONS,
|
|
126
|
+
...(tableArgument ? [new RegExp(tableArgument, "g")] : []),
|
|
127
|
+
]),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function scanLiterals(
|
|
132
|
+
source: string,
|
|
133
|
+
masked: string,
|
|
134
|
+
literals: LiteralToken[],
|
|
135
|
+
file: { storeFile: boolean; tableCall: string | null },
|
|
136
|
+
): {
|
|
137
|
+
hits: { index: number; severity: "fail" | "warn" }[];
|
|
138
|
+
candidates: StoreKeyCandidate[];
|
|
139
|
+
} {
|
|
140
|
+
const hits: { index: number; severity: "fail" | "warn" }[] = [];
|
|
141
|
+
const candidates: StoreKeyCandidate[] = [];
|
|
142
|
+
for (const token of literals.filter(literalHasColon)) {
|
|
143
|
+
const before = masked.slice(
|
|
144
|
+
Math.max(0, token.start - CONTEXT_CHARS),
|
|
145
|
+
token.start,
|
|
146
|
+
);
|
|
147
|
+
const severity = directKeySeverity(before, file.storeFile, file.tableCall);
|
|
148
|
+
const named = severity ? null : namedValue(before, masked, token);
|
|
149
|
+
if (severity) hits.push({ index: token.start, severity });
|
|
150
|
+
if (named) candidates.push({ line: lineAt(source, token.start), ...named });
|
|
151
|
+
}
|
|
152
|
+
return { hits, candidates };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function directKeySeverity(
|
|
156
|
+
before: string,
|
|
157
|
+
storeFile: boolean,
|
|
158
|
+
tableCall: string | null,
|
|
159
|
+
): "fail" | "warn" | null {
|
|
160
|
+
if (STORE_CALL_LITERALS.some((context) => context.test(before))) {
|
|
161
|
+
return "fail";
|
|
162
|
+
}
|
|
163
|
+
if (tableCall && new RegExp(tableCall).test(before)) return "fail";
|
|
164
|
+
if (KEY_PROPERTY_LITERAL.test(before)) return storeFile ? "fail" : "warn";
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** The const or function a colon literal names, if any. */
|
|
169
|
+
function namedValue(
|
|
170
|
+
before: string,
|
|
171
|
+
masked: string,
|
|
172
|
+
token: LiteralToken,
|
|
173
|
+
): { name: string; topLevel: boolean } | null {
|
|
174
|
+
if (looksLikeUrl(token.staticText)) return null;
|
|
175
|
+
for (const context of NAMED_VALUE_CONTEXTS) {
|
|
176
|
+
const name = context.exec(before)?.[1];
|
|
177
|
+
if (name) {
|
|
178
|
+
return { name, topLevel: enclosingBrace(masked, token.start) < 0 };
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (!RETURN_CONTEXT.test(before)) return null;
|
|
182
|
+
const fn = enclosingFunction(masked, token.start);
|
|
183
|
+
if (!fn?.name) return null;
|
|
184
|
+
return { name: fn.name, topLevel: enclosingBrace(masked, fn.brace) < 0 };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function literalHasColon(token: LiteralToken): boolean {
|
|
188
|
+
if (isTemplateType(token)) return false;
|
|
189
|
+
const colonCall = new RegExp(`${COLON_VALUE_CALL}$`);
|
|
190
|
+
return (
|
|
191
|
+
token.staticText.includes(":") ||
|
|
192
|
+
token.expressions.some((expression) => colonCall.test(expression))
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** `${string}:${string}` in a type position is not a runtime value. */
|
|
197
|
+
function isTemplateType(token: LiteralToken): boolean {
|
|
198
|
+
return (
|
|
199
|
+
token.expressions.length > 0 &&
|
|
200
|
+
token.expressions.every((expression) => TYPE_NAMES.has(expression.trim()))
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function looksLikeUrl(text: string): boolean {
|
|
205
|
+
return text.includes("://") || /^(?:data|blob|mailto|tel):/i.test(text);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function matchNames(masked: string, patterns: RegExp[]): string[] {
|
|
209
|
+
return patterns.flatMap((pattern) =>
|
|
210
|
+
[...masked.matchAll(pattern)].map((match) => match[1]!),
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Source for `<tableVariable>.get(` + `tail`, or null without table variables. */
|
|
215
|
+
function tableVariableContext(names: string[], tail: string): string | null {
|
|
216
|
+
if (names.length === 0) return null;
|
|
217
|
+
const alternatives = names.map((name) => name.replaceAll("$", "\\$"));
|
|
218
|
+
return String.raw`(?:^|[^\w$.])(?:${alternatives.join("|")})\s*\.(?:get|has|delete)\s*\(\s*${tail}`;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Walks out through enclosing `{` blocks until one opens a function, and
|
|
223
|
+
* returns that function's name ("" for an anonymous one) and its `{`. Control blocks
|
|
224
|
+
* (`if (...) {`) and unrecognized blocks are skipped.
|
|
225
|
+
*/
|
|
226
|
+
function enclosingFunction(
|
|
227
|
+
masked: string,
|
|
228
|
+
index: number,
|
|
229
|
+
): { name: string; brace: number } | null {
|
|
230
|
+
let position = index;
|
|
231
|
+
for (let level = 0; level < MAX_ENCLOSING_BLOCKS; level++) {
|
|
232
|
+
const brace = enclosingBrace(masked, position);
|
|
233
|
+
if (brace < 0) return null;
|
|
234
|
+
const header = masked.slice(Math.max(0, brace - HEADER_CHARS), brace);
|
|
235
|
+
const name = functionHeaderName(header);
|
|
236
|
+
if (name !== null) return { name, brace };
|
|
237
|
+
position = brace;
|
|
238
|
+
}
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function functionHeaderName(header: string): string | null {
|
|
243
|
+
for (const pattern of FUNCTION_HEADERS) {
|
|
244
|
+
const name = pattern.exec(header)?.[1];
|
|
245
|
+
if (name !== undefined) return CONTROL_KEYWORDS.has(name) ? null : name;
|
|
246
|
+
}
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function enclosingBrace(masked: string, index: number): number {
|
|
251
|
+
let depth = 0;
|
|
252
|
+
for (let k = index - 1; k >= 0; k--) {
|
|
253
|
+
const ch = masked[k];
|
|
254
|
+
if (ch === "}") depth++;
|
|
255
|
+
else if (ch === "{" && depth-- === 0) return k;
|
|
256
|
+
}
|
|
257
|
+
return -1;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function lineAt(source: string, index: number): number {
|
|
261
|
+
return source.slice(0, index).split("\n").length;
|
|
262
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// owner: aaronroe
|
|
2
|
+
/**
|
|
3
|
+
* `poe-tiles doctor` check for synced-store keys that contain ':'.
|
|
4
|
+
*
|
|
5
|
+
* The store throws on ':' in a key only when that code path runs, so the
|
|
6
|
+
* tile's tests can pass while a rare path ships broken. This check reads the
|
|
7
|
+
* tile's source files and reports literal keys that would throw. Detection
|
|
8
|
+
* rules live in `doctor-store-keys-scan.ts`.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import type { DoctorCheck, DoctorFileSystem } from "./doctor.js";
|
|
13
|
+
import {
|
|
14
|
+
type StoreKeyHit,
|
|
15
|
+
type StoreKeyScan,
|
|
16
|
+
scanStoreKeySource,
|
|
17
|
+
} from "./doctor-store-keys-scan.js";
|
|
18
|
+
|
|
19
|
+
export const STORE_KEY_SCAN_MAX_FILES = 2000;
|
|
20
|
+
export const STORE_KEY_SCAN_MAX_FILE_BYTES = 1024 * 1024;
|
|
21
|
+
const MAX_LISTED_HITS = 5;
|
|
22
|
+
const SKIPPED_DIRECTORIES = new Set([
|
|
23
|
+
"node_modules",
|
|
24
|
+
"dist",
|
|
25
|
+
"build",
|
|
26
|
+
"out",
|
|
27
|
+
"coverage",
|
|
28
|
+
"public",
|
|
29
|
+
"vendor",
|
|
30
|
+
"tests",
|
|
31
|
+
"test",
|
|
32
|
+
"__tests__",
|
|
33
|
+
"e2e",
|
|
34
|
+
"playwright-report",
|
|
35
|
+
"test-results",
|
|
36
|
+
]);
|
|
37
|
+
const SOURCE_FILE = /\.[cm]?[jt]sx?$/;
|
|
38
|
+
const SKIPPED_FILE = /\.d\.ts$|\.min\.js$|\.(?:test|spec)\./;
|
|
39
|
+
const FIX =
|
|
40
|
+
"Item keys and sort keys cannot contain ':'; join parts with '/' or '-' (e.g. `${a}/${b}`).";
|
|
41
|
+
|
|
42
|
+
interface LocatedHit extends StoreKeyHit {
|
|
43
|
+
path: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function checkStoreKeys(options: {
|
|
47
|
+
cwd: string;
|
|
48
|
+
fileSystem: DoctorFileSystem;
|
|
49
|
+
}): DoctorCheck {
|
|
50
|
+
const files = listSourceFiles(options.cwd, options.fileSystem);
|
|
51
|
+
const hits = locateHits(
|
|
52
|
+
files.map((path) => ({
|
|
53
|
+
path,
|
|
54
|
+
scan: scanFile(options.cwd, path, options.fileSystem),
|
|
55
|
+
})),
|
|
56
|
+
);
|
|
57
|
+
const failures = hits.filter((hit) => hit.severity === "fail");
|
|
58
|
+
if (failures.length > 0) {
|
|
59
|
+
return {
|
|
60
|
+
name: "Store keys",
|
|
61
|
+
status: "fail",
|
|
62
|
+
message: `${countLabel(failures.length, "store key")} ${failures.length === 1 ? "contains" : "contain"} ':', which the store rejects when that code runs: ${listHits(failures)}.`,
|
|
63
|
+
fix: FIX,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (hits.length > 0) {
|
|
67
|
+
return {
|
|
68
|
+
name: "Store keys",
|
|
69
|
+
status: "warn",
|
|
70
|
+
message: `${countLabel(hits.length, "key value")} may contain ':' and may be used as a store key: ${listHits(hits)}.`,
|
|
71
|
+
fix: `${FIX} Ignore this warning for keys that never reach the store, such as Map keys.`,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
name: "Store keys",
|
|
76
|
+
status: "pass",
|
|
77
|
+
message: `No literal store key contains ':' (${countLabel(files.length, "source file")} scanned).`,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Direct hits, plus one for each named colon value passed as a key: a fail
|
|
83
|
+
* when its own store file passes it to the store, else a warn when its own
|
|
84
|
+
* file or, for a top-level name, any scanned file does. One hit per line; a
|
|
85
|
+
* fail outranks a warn.
|
|
86
|
+
*/
|
|
87
|
+
function locateHits(
|
|
88
|
+
scans: { path: string; scan: StoreKeyScan }[],
|
|
89
|
+
): LocatedHit[] {
|
|
90
|
+
const projectKeyNames = new Set(scans.flatMap(({ scan }) => scan.keyNames));
|
|
91
|
+
const byLine = new Map<string, LocatedHit>();
|
|
92
|
+
for (const { path, scan } of scans) {
|
|
93
|
+
const located = [
|
|
94
|
+
...scan.hits.map((hit) => ({ ...hit, path })),
|
|
95
|
+
...keyCandidateHits(path, scan, projectKeyNames),
|
|
96
|
+
];
|
|
97
|
+
for (const hit of located) {
|
|
98
|
+
const id = `${hit.path}:${hit.line}`;
|
|
99
|
+
if (byLine.get(id)?.severity !== "fail") byLine.set(id, hit);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return [...byLine.values()];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function keyCandidateHits(
|
|
106
|
+
path: string,
|
|
107
|
+
scan: StoreKeyScan,
|
|
108
|
+
projectKeyNames: Set<string>,
|
|
109
|
+
): LocatedHit[] {
|
|
110
|
+
const fileKeyNames = new Set(scan.keyNames);
|
|
111
|
+
return scan.candidates
|
|
112
|
+
.filter((candidate) =>
|
|
113
|
+
(candidate.topLevel ? projectKeyNames : fileKeyNames).has(candidate.name),
|
|
114
|
+
)
|
|
115
|
+
.map((candidate) => ({
|
|
116
|
+
path,
|
|
117
|
+
line: candidate.line,
|
|
118
|
+
severity:
|
|
119
|
+
scan.storeFile && fileKeyNames.has(candidate.name) ? "fail" : "warn",
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function countLabel(count: number, noun: string): string {
|
|
124
|
+
return `${count} ${noun}${count === 1 ? "" : "s"}`;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function listHits(hits: LocatedHit[]): string {
|
|
128
|
+
const listed = hits
|
|
129
|
+
.slice(0, MAX_LISTED_HITS)
|
|
130
|
+
.map((hit) => `${hit.path}:${hit.line}`)
|
|
131
|
+
.join(", ");
|
|
132
|
+
const more = hits.length - MAX_LISTED_HITS;
|
|
133
|
+
return more > 0 ? `${listed} (and ${more} more)` : listed;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Project-relative source paths, '/'-separated, sorted, capped. */
|
|
137
|
+
export function listSourceFiles(
|
|
138
|
+
cwd: string,
|
|
139
|
+
fileSystem: DoctorFileSystem,
|
|
140
|
+
): string[] {
|
|
141
|
+
const files: string[] = [];
|
|
142
|
+
const pending = [""];
|
|
143
|
+
while (pending.length > 0 && files.length < STORE_KEY_SCAN_MAX_FILES) {
|
|
144
|
+
const directory = pending.pop()!;
|
|
145
|
+
const entries = readEntries(join(cwd, directory), fileSystem);
|
|
146
|
+
for (const entry of entries) {
|
|
147
|
+
const path = directory ? `${directory}/${entry.name}` : entry.name;
|
|
148
|
+
const list = entryList(entry, { directories: pending, files });
|
|
149
|
+
list?.push(path);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return files.sort().slice(0, STORE_KEY_SCAN_MAX_FILES);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function entryList(
|
|
156
|
+
entry: { name: string; isFile(): boolean; isDirectory(): boolean },
|
|
157
|
+
lists: { directories: string[]; files: string[] },
|
|
158
|
+
): string[] | null {
|
|
159
|
+
if (entry.isDirectory()) {
|
|
160
|
+
return isScannedDirectory(entry.name) ? lists.directories : null;
|
|
161
|
+
}
|
|
162
|
+
return entry.isFile() && isScannedFile(entry.name) ? lists.files : null;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function readEntries(
|
|
166
|
+
directory: string,
|
|
167
|
+
fileSystem: DoctorFileSystem,
|
|
168
|
+
): ReturnType<DoctorFileSystem["readdirEntries"]> {
|
|
169
|
+
try {
|
|
170
|
+
return fileSystem.readdirEntries(directory);
|
|
171
|
+
} catch {
|
|
172
|
+
// An unreadable folder cannot hold keys the build will ship.
|
|
173
|
+
return [];
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function isScannedDirectory(name: string): boolean {
|
|
178
|
+
return !name.startsWith(".") && !SKIPPED_DIRECTORIES.has(name);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function isScannedFile(name: string): boolean {
|
|
182
|
+
return SOURCE_FILE.test(name) && !SKIPPED_FILE.test(name);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function scanFile(
|
|
186
|
+
cwd: string,
|
|
187
|
+
path: string,
|
|
188
|
+
fileSystem: DoctorFileSystem,
|
|
189
|
+
): StoreKeyScan {
|
|
190
|
+
const fullPath = join(cwd, path);
|
|
191
|
+
const stats = fileSystem.statSync(fullPath);
|
|
192
|
+
if ("size" in stats && stats.size > STORE_KEY_SCAN_MAX_FILE_BYTES) {
|
|
193
|
+
return { storeFile: false, hits: [], candidates: [], keyNames: [] };
|
|
194
|
+
}
|
|
195
|
+
return scanStoreKeySource(fileSystem.readFileSync(fullPath, "utf8"), path);
|
|
196
|
+
}
|