@joiner-platform/cli 0.0.0-stage → 0.1.0
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 +148 -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 +196 -0
- package/skills/tile-creator/references/assets.md +124 -0
- package/skills/tile-creator/references/backend-api.md +308 -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,193 @@
|
|
|
1
|
+
// owner: jyoung-q
|
|
2
|
+
import {
|
|
3
|
+
existsSync,
|
|
4
|
+
mkdirSync,
|
|
5
|
+
renameSync,
|
|
6
|
+
rmSync,
|
|
7
|
+
writeFileSync,
|
|
8
|
+
} from "node:fs";
|
|
9
|
+
import { basename, dirname, posix, resolve } from "node:path";
|
|
10
|
+
import type { TarEntry } from "./tar-parse.js";
|
|
11
|
+
|
|
12
|
+
/** What an extracted file may be: plain, or one its owner can run. */
|
|
13
|
+
const EXECUTABLE_FILE_MODE = 0o755;
|
|
14
|
+
|
|
15
|
+
/** Says whether to make a file executable although its header does not. */
|
|
16
|
+
export type ExecutablePathRule = (normalizedPath: string) => boolean;
|
|
17
|
+
|
|
18
|
+
interface TarOutput {
|
|
19
|
+
entry: TarEntry;
|
|
20
|
+
normalizedPath: string;
|
|
21
|
+
executable: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface TarOutputPlan {
|
|
25
|
+
outputs: readonly TarOutput[];
|
|
26
|
+
resolvedTargetDir: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function prepareTarOutputPlan(
|
|
30
|
+
entries: readonly TarEntry[],
|
|
31
|
+
targetDir: string,
|
|
32
|
+
executablePath: ExecutablePathRule = () => false,
|
|
33
|
+
): TarOutputPlan {
|
|
34
|
+
const resolvedTargetDir = resolve(targetDir);
|
|
35
|
+
const outputs = entries.map((entry) =>
|
|
36
|
+
resolveTarOutputPath(entry, executablePath),
|
|
37
|
+
);
|
|
38
|
+
preflightTarOutputs(outputs);
|
|
39
|
+
return { outputs, resolvedTargetDir };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function writeEntriesAtomically(plan: TarOutputPlan): void {
|
|
43
|
+
const parentDir = dirname(plan.resolvedTargetDir);
|
|
44
|
+
const tempDir = resolve(
|
|
45
|
+
parentDir,
|
|
46
|
+
`.${basename(plan.resolvedTargetDir)}.tmp-${process.pid}-${Date.now()}-${Math.random()
|
|
47
|
+
.toString(16)
|
|
48
|
+
.slice(2)}`,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
mkdirSync(parentDir, { recursive: true });
|
|
52
|
+
try {
|
|
53
|
+
mkdirSync(tempDir);
|
|
54
|
+
for (const { entry, normalizedPath, executable } of plan.outputs) {
|
|
55
|
+
const outputPath = resolve(tempDir, normalizedPath);
|
|
56
|
+
if (entry.type === "directory") {
|
|
57
|
+
mkdirSync(outputPath, { recursive: true });
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
mkdirSync(dirname(outputPath), { recursive: true });
|
|
61
|
+
// The umask still applies, as it does to every file written here.
|
|
62
|
+
writeFileSync(
|
|
63
|
+
outputPath,
|
|
64
|
+
entry.data,
|
|
65
|
+
executable ? { mode: EXECUTABLE_FILE_MODE } : undefined,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
if (existsSync(plan.resolvedTargetDir)) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
`Output directory already exists: ${plan.resolvedTargetDir}`,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
renameSync(tempDir, plan.resolvedTargetDir);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function preflightTarOutputs(outputs: readonly TarOutput[]): void {
|
|
81
|
+
const { directoryPaths, filePaths } = collectOutputPaths(outputs);
|
|
82
|
+
ensureNoFileDirectoryConflicts(filePaths, directoryPaths);
|
|
83
|
+
ensureNoFileParentConflicts(filePaths, directoryPaths);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function collectOutputPaths(outputs: readonly TarOutput[]): {
|
|
87
|
+
directoryPaths: Set<string>;
|
|
88
|
+
filePaths: Set<string>;
|
|
89
|
+
} {
|
|
90
|
+
const filePaths = new Set<string>();
|
|
91
|
+
const directoryPaths = new Set<string>();
|
|
92
|
+
|
|
93
|
+
for (const { entry } of outputs) {
|
|
94
|
+
if (entry.type === "directory") {
|
|
95
|
+
directoryPaths.add(entry.path);
|
|
96
|
+
} else {
|
|
97
|
+
addFilePath(filePaths, directoryPaths, entry.path);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return { directoryPaths, filePaths };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function addFilePath(
|
|
105
|
+
filePaths: Set<string>,
|
|
106
|
+
directoryPaths: Set<string>,
|
|
107
|
+
path: string,
|
|
108
|
+
): void {
|
|
109
|
+
if (filePaths.has(path) || directoryPaths.has(path)) {
|
|
110
|
+
throw new Error(`Conflicting tar entries for path: ${path}`);
|
|
111
|
+
}
|
|
112
|
+
filePaths.add(path);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function ensureNoFileDirectoryConflicts(
|
|
116
|
+
filePaths: ReadonlySet<string>,
|
|
117
|
+
directoryPaths: ReadonlySet<string>,
|
|
118
|
+
): void {
|
|
119
|
+
for (const path of directoryPaths) {
|
|
120
|
+
if (filePaths.has(path)) {
|
|
121
|
+
throw new Error(`Conflicting tar entries for path: ${path}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function ensureNoFileParentConflicts(
|
|
127
|
+
filePaths: ReadonlySet<string>,
|
|
128
|
+
directoryPaths: ReadonlySet<string>,
|
|
129
|
+
): void {
|
|
130
|
+
for (const path of [...filePaths, ...directoryPaths]) {
|
|
131
|
+
ensurePathParentsAreDirectories(path, filePaths);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function ensurePathParentsAreDirectories(
|
|
136
|
+
path: string,
|
|
137
|
+
filePaths: ReadonlySet<string>,
|
|
138
|
+
): void {
|
|
139
|
+
for (const parent of parentPaths(path)) {
|
|
140
|
+
if (filePaths.has(parent)) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
`Conflicting tar entries: "${parent}" is both a file and a parent directory`,
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function resolveTarOutputPath(
|
|
149
|
+
entry: TarEntry,
|
|
150
|
+
executablePath: ExecutablePathRule,
|
|
151
|
+
): TarOutput {
|
|
152
|
+
const normalizedPath = normalizeTarPath(entry.path);
|
|
153
|
+
return {
|
|
154
|
+
entry: { ...entry, path: normalizedPath },
|
|
155
|
+
normalizedPath,
|
|
156
|
+
executable:
|
|
157
|
+
entry.type === "file" &&
|
|
158
|
+
(entry.executable || executablePath(normalizedPath)),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function normalizeTarPath(tarPath: string): string {
|
|
163
|
+
const portablePath = tarPath.replace(/\\/g, "/");
|
|
164
|
+
if (portablePath.startsWith("/") || /^[A-Za-z]:/.test(portablePath)) {
|
|
165
|
+
throw new Error(`Refusing unsafe tar path: ${tarPath}`);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const normalizedPath = posix.normalize(portablePath).replace(/\/+$/, "");
|
|
169
|
+
if (isUnsafeNormalizedPath(normalizedPath)) {
|
|
170
|
+
throw new Error(`Refusing unsafe tar path: ${tarPath}`);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return normalizedPath;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function isUnsafeNormalizedPath(path: string): boolean {
|
|
177
|
+
return (
|
|
178
|
+
path === "." ||
|
|
179
|
+
path === ".." ||
|
|
180
|
+
path.startsWith("../") ||
|
|
181
|
+
path.startsWith("/") ||
|
|
182
|
+
/^[A-Za-z]:/.test(path)
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function parentPaths(path: string): string[] {
|
|
187
|
+
const parts = path.split("/");
|
|
188
|
+
const parents: string[] = [];
|
|
189
|
+
for (let i = 1; i < parts.length; i++) {
|
|
190
|
+
parents.push(parts.slice(0, i).join("/"));
|
|
191
|
+
}
|
|
192
|
+
return parents;
|
|
193
|
+
}
|
package/src/tar-parse.ts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// owner: jyoung-q
|
|
2
|
+
/**
|
|
3
|
+
* The tar reader behind the CLI's source bundle extraction.
|
|
4
|
+
*
|
|
5
|
+
* Inlined for the same reason as the builder in `tar.ts`: the CLI installs from
|
|
6
|
+
* a tarball outside the monorepo, where `@lib/tar-parser` does not resolve.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
isTarExtension,
|
|
11
|
+
MAX_TAR_EXTENSION_BYTES,
|
|
12
|
+
maxTarExtensionCount,
|
|
13
|
+
TarExtensions,
|
|
14
|
+
} from "./tar-extensions.js";
|
|
15
|
+
|
|
16
|
+
const BLOCK_SIZE = 512;
|
|
17
|
+
const NAME_LENGTH = 100;
|
|
18
|
+
const PREFIX_LENGTH = 155;
|
|
19
|
+
const HEADER_PREFIX_OFFSET = 345;
|
|
20
|
+
const MODE_OFFSET = 100;
|
|
21
|
+
const MODE_LENGTH = 8;
|
|
22
|
+
const ANY_EXECUTE_BIT = 0o111;
|
|
23
|
+
const SIZE_OFFSET = 124;
|
|
24
|
+
const SIZE_LENGTH = 12;
|
|
25
|
+
const TYPE_FLAG_OFFSET = 156;
|
|
26
|
+
|
|
27
|
+
export type TarEntry =
|
|
28
|
+
| {
|
|
29
|
+
type: "file";
|
|
30
|
+
path: string;
|
|
31
|
+
data: Uint8Array;
|
|
32
|
+
/**
|
|
33
|
+
* Whether the header gives anyone the right to run the file. It is the
|
|
34
|
+
* one fact read from the mode: no other bit reaches the extracted file.
|
|
35
|
+
*/
|
|
36
|
+
executable: boolean;
|
|
37
|
+
}
|
|
38
|
+
| { type: "directory"; path: string };
|
|
39
|
+
|
|
40
|
+
export interface ParsedTar {
|
|
41
|
+
entries: TarEntry[];
|
|
42
|
+
fileCount: number;
|
|
43
|
+
totalBytes: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function parseTar(
|
|
47
|
+
tarData: Uint8Array,
|
|
48
|
+
limits: { maxEntries: number; maxTotalBytes: number },
|
|
49
|
+
): ParsedTar {
|
|
50
|
+
const entries: TarEntry[] = [];
|
|
51
|
+
let offset = 0;
|
|
52
|
+
const state = { entryCount: 0, fileCount: 0, totalBytes: 0 };
|
|
53
|
+
let extensionCount = 0;
|
|
54
|
+
const extensions = new TarExtensions();
|
|
55
|
+
|
|
56
|
+
while (offset + BLOCK_SIZE <= tarData.byteLength) {
|
|
57
|
+
const header = tarData.slice(offset, offset + BLOCK_SIZE);
|
|
58
|
+
if (isZeroBlock(header)) break;
|
|
59
|
+
|
|
60
|
+
if (isTarExtension(header[TYPE_FLAG_OFFSET] ?? 0)) {
|
|
61
|
+
if (++extensionCount > maxTarExtensionCount(limits.maxEntries))
|
|
62
|
+
throw new Error("Too many tar extensions");
|
|
63
|
+
offset = readTarExtension({ tarData, header, offset, extensions });
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const parsed = parseTarEntry(tarData, header, offset, extensions);
|
|
67
|
+
countEntry(parsed.entry, state, limits);
|
|
68
|
+
entries.push(parsed.entry);
|
|
69
|
+
offset = parsed.nextOffset;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
extensions.finish();
|
|
73
|
+
return { entries, fileCount: state.fileCount, totalBytes: state.totalBytes };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function countEntry(
|
|
77
|
+
entry: TarEntry,
|
|
78
|
+
state: { entryCount: number; fileCount: number; totalBytes: number },
|
|
79
|
+
limits: { maxEntries: number; maxTotalBytes: number },
|
|
80
|
+
): void {
|
|
81
|
+
state.entryCount += 1;
|
|
82
|
+
if (state.entryCount > limits.maxEntries) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`Source bundle contains more than ${limits.maxEntries} tar entries`,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
if (entry.type === "file") {
|
|
88
|
+
state.fileCount += 1;
|
|
89
|
+
state.totalBytes += entry.data.byteLength;
|
|
90
|
+
if (state.totalBytes > limits.maxTotalBytes) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`Source bundle would exceed ${limits.maxTotalBytes} bytes after decompression`,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function readTarExtension({
|
|
99
|
+
tarData,
|
|
100
|
+
header,
|
|
101
|
+
offset,
|
|
102
|
+
extensions,
|
|
103
|
+
}: {
|
|
104
|
+
tarData: Uint8Array;
|
|
105
|
+
header: Uint8Array;
|
|
106
|
+
offset: number;
|
|
107
|
+
extensions: TarExtensions;
|
|
108
|
+
}): number {
|
|
109
|
+
const size = readTarOctal(header, SIZE_OFFSET, SIZE_LENGTH);
|
|
110
|
+
if (size > MAX_TAR_EXTENSION_BYTES)
|
|
111
|
+
throw new Error("Tar extension is too large");
|
|
112
|
+
if (offset + BLOCK_SIZE + size > tarData.byteLength)
|
|
113
|
+
throw new Error("Truncated tar extension");
|
|
114
|
+
extensions.consume(
|
|
115
|
+
header[TYPE_FLAG_OFFSET] ?? 0,
|
|
116
|
+
tarData.subarray(offset + BLOCK_SIZE, offset + BLOCK_SIZE + size),
|
|
117
|
+
);
|
|
118
|
+
return offset + BLOCK_SIZE + roundUpToBlock(size);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function parseTarEntry(
|
|
122
|
+
tarData: Uint8Array,
|
|
123
|
+
header: Uint8Array,
|
|
124
|
+
offset: number,
|
|
125
|
+
extensions: TarExtensions,
|
|
126
|
+
): { entry: TarEntry; nextOffset: number } {
|
|
127
|
+
const { path, size } = extensions.resolve(
|
|
128
|
+
readTarPath(header),
|
|
129
|
+
readTarOctal(header, SIZE_OFFSET, SIZE_LENGTH),
|
|
130
|
+
);
|
|
131
|
+
const dataStart = offset + BLOCK_SIZE;
|
|
132
|
+
const dataEnd = dataStart + size;
|
|
133
|
+
if (dataEnd > tarData.byteLength) {
|
|
134
|
+
throw new Error(`Tar entry "${path}" extends past the archive size`);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
entry: buildTarEntry({
|
|
139
|
+
data: tarData.slice(dataStart, dataEnd),
|
|
140
|
+
path,
|
|
141
|
+
typeFlag: header[TYPE_FLAG_OFFSET] ?? 0,
|
|
142
|
+
mode: readTarOctal(header, MODE_OFFSET, MODE_LENGTH),
|
|
143
|
+
}),
|
|
144
|
+
nextOffset: dataStart + roundUpToBlock(size),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function buildTarEntry(options: {
|
|
149
|
+
typeFlag: number;
|
|
150
|
+
path: string;
|
|
151
|
+
data: Uint8Array;
|
|
152
|
+
mode: number;
|
|
153
|
+
}): TarEntry {
|
|
154
|
+
if (options.typeFlag === 0 || options.typeFlag === 0x30) {
|
|
155
|
+
return {
|
|
156
|
+
type: "file",
|
|
157
|
+
path: options.path,
|
|
158
|
+
data: options.data,
|
|
159
|
+
executable: (options.mode & ANY_EXECUTE_BIT) !== 0,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
if (options.typeFlag === 0x35) {
|
|
163
|
+
return { type: "directory", path: options.path };
|
|
164
|
+
}
|
|
165
|
+
const printableType = String.fromCharCode(options.typeFlag);
|
|
166
|
+
throw new Error(
|
|
167
|
+
`Unsupported tar entry type "${printableType}" for "${options.path}"`,
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function readTarPath(header: Uint8Array): string {
|
|
172
|
+
const name = readNullTerminatedString(header, 0, NAME_LENGTH);
|
|
173
|
+
const prefix = readNullTerminatedString(
|
|
174
|
+
header,
|
|
175
|
+
HEADER_PREFIX_OFFSET,
|
|
176
|
+
PREFIX_LENGTH,
|
|
177
|
+
);
|
|
178
|
+
const path = prefix ? `${prefix}/${name}` : name;
|
|
179
|
+
if (!path) {
|
|
180
|
+
throw new Error("Tar entry is missing a path");
|
|
181
|
+
}
|
|
182
|
+
return path;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function readTarOctal(
|
|
186
|
+
header: Uint8Array,
|
|
187
|
+
offset: number,
|
|
188
|
+
length: number,
|
|
189
|
+
): number {
|
|
190
|
+
const raw = readNullTerminatedString(header, offset, length).trim();
|
|
191
|
+
if (!raw) return 0;
|
|
192
|
+
if (!/^[0-7]+$/.test(raw)) {
|
|
193
|
+
throw new Error(`Invalid tar octal value: ${raw}`);
|
|
194
|
+
}
|
|
195
|
+
return Number.parseInt(raw, 8);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function readNullTerminatedString(
|
|
199
|
+
data: Uint8Array,
|
|
200
|
+
offset: number,
|
|
201
|
+
length: number,
|
|
202
|
+
): string {
|
|
203
|
+
let end = offset;
|
|
204
|
+
const limit = offset + length;
|
|
205
|
+
while (end < limit && data[end] !== 0) {
|
|
206
|
+
end += 1;
|
|
207
|
+
}
|
|
208
|
+
// ignoreBOM keeps a leading U+FEFF, a valid filename character, in the path.
|
|
209
|
+
return new TextDecoder("utf-8", { ignoreBOM: true }).decode(
|
|
210
|
+
data.slice(offset, end),
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function roundUpToBlock(size: number): number {
|
|
215
|
+
const remainder = size % BLOCK_SIZE;
|
|
216
|
+
return remainder === 0 ? size : size + (BLOCK_SIZE - remainder);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function isZeroBlock(block: Uint8Array): boolean {
|
|
220
|
+
for (const byte of block) {
|
|
221
|
+
if (byte !== 0) return false;
|
|
222
|
+
}
|
|
223
|
+
return true;
|
|
224
|
+
}
|
package/src/tar.ts
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
// owner: jyoung-q
|
|
2
|
+
/**
|
|
3
|
+
* Minimal tar-gz builder for the publish-app flow.
|
|
4
|
+
*
|
|
5
|
+
* Inlined (not imported from @lib/tar-parser) so the CLI can be packed and
|
|
6
|
+
* installed from a tarball outside the monorepo — workspace:* deps don't
|
|
7
|
+
* resolve for consumers installing via `bun install -g ./poe-tiles-cli.tgz`.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { existsSync } from "node:fs";
|
|
11
|
+
import { Gunzip, gzipSync } from "fflate";
|
|
12
|
+
import {
|
|
13
|
+
maxTarExtensionArchiveBytes,
|
|
14
|
+
type TarHeaderInput,
|
|
15
|
+
tarFileHeaders,
|
|
16
|
+
} from "./tar-extensions.js";
|
|
17
|
+
import {
|
|
18
|
+
type ExecutablePathRule,
|
|
19
|
+
prepareTarOutputPlan,
|
|
20
|
+
writeEntriesAtomically,
|
|
21
|
+
} from "./tar-extract.js";
|
|
22
|
+
import { parseTar } from "./tar-parse.js";
|
|
23
|
+
|
|
24
|
+
const BLOCK_SIZE = 512;
|
|
25
|
+
const END_OF_ARCHIVE_BLOCKS = 2;
|
|
26
|
+
const DEFAULT_MAX_EXTRACTED_BYTES = 100 * 1024 * 1024;
|
|
27
|
+
const DEFAULT_MAX_EXTRACTED_ENTRIES = 50_000;
|
|
28
|
+
const GUNZIP_INPUT_CHUNK_SIZE = 64 * 1024;
|
|
29
|
+
|
|
30
|
+
/** The two modes a bundle records: a plain file, and one its owner can run. */
|
|
31
|
+
const FILE_MODE = 0o644;
|
|
32
|
+
const EXECUTABLE_FILE_MODE = 0o755;
|
|
33
|
+
|
|
34
|
+
export type BuildTarOptions = {
|
|
35
|
+
/**
|
|
36
|
+
* Paths written as 0755. Every other file is 0644, which is also what the
|
|
37
|
+
* server's canonical re-encode writes, so a client bundle names none.
|
|
38
|
+
*/
|
|
39
|
+
executablePaths?: ReadonlySet<string>;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export function buildTarGz(
|
|
43
|
+
files: Map<string, Uint8Array>,
|
|
44
|
+
options: BuildTarOptions = {},
|
|
45
|
+
): Uint8Array {
|
|
46
|
+
return gzipSync(buildTar(files, options), { mtime: 0 });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface ExtractTarGzResult {
|
|
50
|
+
fileCount: number;
|
|
51
|
+
totalBytes: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface ExtractTarGzOptions {
|
|
55
|
+
/** Maximum total bytes across regular file entries after decompression. */
|
|
56
|
+
maxTotalBytes?: number;
|
|
57
|
+
/** Maximum tar entries to parse before extraction. Directory entries count too. */
|
|
58
|
+
maxFiles?: number;
|
|
59
|
+
/**
|
|
60
|
+
* Files to make executable besides those whose header says so, by their
|
|
61
|
+
* normalized path. For bundles that were published without file modes.
|
|
62
|
+
*/
|
|
63
|
+
executablePath?: ExecutablePathRule;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export type { TarEntry } from "./tar-parse.js";
|
|
67
|
+
|
|
68
|
+
export function extractTarGzToDirectory(
|
|
69
|
+
tarGzData: Uint8Array,
|
|
70
|
+
targetDir: string,
|
|
71
|
+
options: ExtractTarGzOptions = {},
|
|
72
|
+
): ExtractTarGzResult {
|
|
73
|
+
if (existsSync(targetDir)) {
|
|
74
|
+
throw new Error(`Output directory already exists: ${targetDir}`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const maxTotalBytes = options.maxTotalBytes ?? DEFAULT_MAX_EXTRACTED_BYTES;
|
|
78
|
+
const maxEntries = options.maxFiles ?? DEFAULT_MAX_EXTRACTED_ENTRIES;
|
|
79
|
+
const tarData = gunzipWithLimit(
|
|
80
|
+
tarGzData,
|
|
81
|
+
maxInflatedTarBytes(maxTotalBytes, maxEntries),
|
|
82
|
+
);
|
|
83
|
+
const parsed = parseTar(tarData, {
|
|
84
|
+
maxEntries,
|
|
85
|
+
maxTotalBytes,
|
|
86
|
+
});
|
|
87
|
+
const outputPlan = prepareTarOutputPlan(
|
|
88
|
+
parsed.entries,
|
|
89
|
+
targetDir,
|
|
90
|
+
options.executablePath,
|
|
91
|
+
);
|
|
92
|
+
writeEntriesAtomically(outputPlan);
|
|
93
|
+
|
|
94
|
+
return { fileCount: parsed.fileCount, totalBytes: parsed.totalBytes };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function gunzipWithLimit(tarGzData: Uint8Array, maxBytes: number): Uint8Array {
|
|
98
|
+
const chunks: Uint8Array[] = [];
|
|
99
|
+
let totalBytes = 0;
|
|
100
|
+
const gunzip = new Gunzip((chunk) => {
|
|
101
|
+
totalBytes += chunk.byteLength;
|
|
102
|
+
if (totalBytes > maxBytes) {
|
|
103
|
+
throw new Error(
|
|
104
|
+
`Source bundle expands past ${maxBytes} bytes before extraction`,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
chunks.push(chunk);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
for (let offset = 0; offset < tarGzData.byteLength; ) {
|
|
111
|
+
const nextOffset = Math.min(
|
|
112
|
+
offset + GUNZIP_INPUT_CHUNK_SIZE,
|
|
113
|
+
tarGzData.byteLength,
|
|
114
|
+
);
|
|
115
|
+
gunzip.push(
|
|
116
|
+
tarGzData.slice(offset, nextOffset),
|
|
117
|
+
nextOffset === tarGzData.byteLength,
|
|
118
|
+
);
|
|
119
|
+
offset = nextOffset;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return concatenateBlocks(chunks);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function maxInflatedTarBytes(
|
|
126
|
+
maxTotalBytes: number,
|
|
127
|
+
maxEntries: number,
|
|
128
|
+
): number {
|
|
129
|
+
return (
|
|
130
|
+
maxTotalBytes +
|
|
131
|
+
maxEntries * BLOCK_SIZE * 2 +
|
|
132
|
+
maxTarExtensionArchiveBytes(maxEntries) +
|
|
133
|
+
END_OF_ARCHIVE_BLOCKS * BLOCK_SIZE
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function buildTar(
|
|
138
|
+
files: Map<string, Uint8Array>,
|
|
139
|
+
options: BuildTarOptions = {},
|
|
140
|
+
): Uint8Array {
|
|
141
|
+
const blocks: Uint8Array[] = [];
|
|
142
|
+
|
|
143
|
+
for (const [path, data] of files) {
|
|
144
|
+
const executable = options.executablePaths?.has(path) === true;
|
|
145
|
+
// A long path's PAX header is not the file: only the file takes the mode.
|
|
146
|
+
const header = (input: TarHeaderInput) =>
|
|
147
|
+
buildHeader(input, executable && input.typeFlag === undefined);
|
|
148
|
+
blocks.push(...tarFileHeaders(path, data.byteLength, header));
|
|
149
|
+
blocks.push(data);
|
|
150
|
+
|
|
151
|
+
const remainder = data.byteLength % BLOCK_SIZE;
|
|
152
|
+
if (remainder > 0) {
|
|
153
|
+
blocks.push(new Uint8Array(BLOCK_SIZE - remainder));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
for (let i = 0; i < END_OF_ARCHIVE_BLOCKS; i++) {
|
|
158
|
+
blocks.push(new Uint8Array(BLOCK_SIZE));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return concatenateBlocks(blocks);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function buildHeader(
|
|
165
|
+
{ path, size, typeFlag = 0x30 }: TarHeaderInput,
|
|
166
|
+
executable: boolean,
|
|
167
|
+
): Uint8Array {
|
|
168
|
+
const header = new Uint8Array(BLOCK_SIZE);
|
|
169
|
+
|
|
170
|
+
const pathBytes = new TextEncoder().encode(path);
|
|
171
|
+
header.set(pathBytes, 0);
|
|
172
|
+
|
|
173
|
+
writeOctal(header, 100, 8, executable ? EXECUTABLE_FILE_MODE : FILE_MODE);
|
|
174
|
+
writeOctal(header, 108, 8, 0);
|
|
175
|
+
writeOctal(header, 116, 8, 0);
|
|
176
|
+
writeOctal(header, 124, 12, size);
|
|
177
|
+
writeOctal(header, 136, 12, 0);
|
|
178
|
+
|
|
179
|
+
header[156] = typeFlag;
|
|
180
|
+
|
|
181
|
+
const magic = new TextEncoder().encode("ustar\0");
|
|
182
|
+
header.set(magic, 257);
|
|
183
|
+
header[263] = 0x30;
|
|
184
|
+
header[264] = 0x30;
|
|
185
|
+
|
|
186
|
+
for (let i = 148; i < 156; i++) {
|
|
187
|
+
header[i] = 0x20;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const checksum = computeChecksum(header);
|
|
191
|
+
writeOctal(header, 148, 7, checksum);
|
|
192
|
+
header[155] = 0x20;
|
|
193
|
+
|
|
194
|
+
return header;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function writeOctal(
|
|
198
|
+
buffer: Uint8Array,
|
|
199
|
+
offset: number,
|
|
200
|
+
length: number,
|
|
201
|
+
value: number,
|
|
202
|
+
): void {
|
|
203
|
+
const octal = value.toString(8).padStart(length - 1, "0");
|
|
204
|
+
const bytes = new TextEncoder().encode(octal);
|
|
205
|
+
buffer.set(bytes, offset);
|
|
206
|
+
buffer[offset + length - 1] = 0;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function computeChecksum(header: Uint8Array): number {
|
|
210
|
+
let sum = 0;
|
|
211
|
+
for (let i = 0; i < BLOCK_SIZE; i++) {
|
|
212
|
+
sum += header[i]!;
|
|
213
|
+
}
|
|
214
|
+
return sum;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function concatenateBlocks(blocks: Uint8Array[]): Uint8Array {
|
|
218
|
+
let totalLength = 0;
|
|
219
|
+
for (const block of blocks) {
|
|
220
|
+
totalLength += block.byteLength;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const result = new Uint8Array(totalLength);
|
|
224
|
+
let offset = 0;
|
|
225
|
+
for (const block of blocks) {
|
|
226
|
+
result.set(block, offset);
|
|
227
|
+
offset += block.byteLength;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// owner: aaronroe
|
|
2
|
+
/**
|
|
3
|
+
* The tile template's check scripts, by their path in a source bundle.
|
|
4
|
+
*
|
|
5
|
+
* The CLI recorded every bundle member as mode 0644 until it began to record
|
|
6
|
+
* file modes, and those bundles keep their bytes. The template runs its setup
|
|
7
|
+
* check as `./scripts/doctor.sh`, so a copy extracted from one of them fails
|
|
8
|
+
* `bun run verify` at its last step unless the extraction sets the bit itself.
|
|
9
|
+
*
|
|
10
|
+
* The rule is the template's own layout and nothing wider: `.sh` files
|
|
11
|
+
* directly inside `scripts/`. `workspace-seed-script-modes.ts` in
|
|
12
|
+
* `projects/creator-v2-sandbox` applies the same rule to a seeded workspace.
|
|
13
|
+
*/
|
|
14
|
+
const TEMPLATE_CHECK_SCRIPT = /^scripts\/[^/]+\.sh$/;
|
|
15
|
+
|
|
16
|
+
export function isTemplateCheckScript(normalizedPath: string): boolean {
|
|
17
|
+
return TEMPLATE_CHECK_SCRIPT.test(normalizedPath);
|
|
18
|
+
}
|