@replayablejs/export 0.1.0-alpha.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Replayable contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # @replayablejs/export
2
+
3
+ Turn existing playable builds into network-specific delivery artifacts.
4
+
5
+ Part of [Replayable](https://github.com/replayablejs/replayable) **0.1.0-alpha.0**.
6
+ APIs may change during the alpha series.
7
+
8
+ ## Install
9
+
10
+ ```sh
11
+ pnpm add -D @replayablejs/export@0.1.0-alpha.0
12
+ ```
13
+
14
+ ## Public surface
15
+
16
+ `exportProject`, `ExportProjectOptions`, `ExportProjectResult`, `ExportVariantResult`.
17
+
18
+ [Usage and reference](https://github.com/replayablejs/replayable/blob/main/docs/reference/export.md).
19
+ The package manifest defines supported import paths; internal source files are not public APIs.
20
+
21
+ ## Development
22
+
23
+ From the repository root, install with `pnpm install --frozen-lockfile` and build dependencies
24
+ with `pnpm build`. Run `pnpm --filter @replayablejs/export test` for this package's tests.
25
+
26
+ ## License
27
+
28
+ Original code is [MIT licensed](https://github.com/replayablejs/replayable/blob/main/LICENSE). Bundled third-party resources retain
29
+ their accompanying license terms.
@@ -0,0 +1,44 @@
1
+ //#region src/shared/compression-protocol.ts
2
+ /** Identifies the inert script element that stores one Replayable module. */
3
+ const COMPRESSED_ENTRY_ATTRIBUTE = "data-replayable-compressed-entry";
4
+ //#endregion
5
+ //#region src/browser/execute-module.ts
6
+ /**
7
+ * Awaits native module evaluation, including top-level await and its failures.
8
+ *
9
+ * A script-element error event does not report every evaluation failure. Import's
10
+ * promise does, without global error listeners or an appended completion event.
11
+ * Each entry is a self-contained build, so it has no relative imports to resolve.
12
+ */
13
+ async function executeModule(source, role) {
14
+ const url = URL.createObjectURL(new Blob([source], { type: "text/javascript" }));
15
+ try {
16
+ await import(
17
+ /* @vite-ignore */
18
+ url
19
+ );
20
+ } catch (cause) {
21
+ throw new Error(`Failed to execute compressed Replayable ${role} entry.`, { cause });
22
+ } finally {
23
+ URL.revokeObjectURL(url);
24
+ }
25
+ }
26
+ //#endregion
27
+ //#region src/browser/compressed-module-loader.ts
28
+ for (const role of ["assets", "application"]) {
29
+ const payload = document.querySelector(`script[${COMPRESSED_ENTRY_ATTRIBUTE}="${role}"]`);
30
+ if (!(payload instanceof HTMLScriptElement)) throw new Error(`Missing compressed Replayable ${role} entry.`);
31
+ const payloadSource = payload.textContent;
32
+ if (payloadSource === null || payloadSource.trim().length === 0) throw new Error(`Compressed Replayable ${role} entry is empty.`);
33
+ try {
34
+ await executeModule(payload.getAttribute("data-replayable-entry-encoding") === "deflate" ? inflateSource(payloadSource) : payloadSource, role);
35
+ } finally {
36
+ payload.remove();
37
+ }
38
+ }
39
+ /** Restores one Base64-encoded Deflate payload to its original JavaScript. */
40
+ function inflateSource(payload) {
41
+ const bytes = Uint8Array.from(atob(payload.trim()), (character) => character.charCodeAt(0));
42
+ return pako.inflate(bytes, { to: "string" });
43
+ }
44
+ //#endregion
@@ -0,0 +1,38 @@
1
+ import { ReplayableConfigInput } from "@replayablejs/config";
2
+ //#region src/types/export.d.ts
3
+ /** Explicit project and destination choices for one export operation. */
4
+ interface ExportProjectOptions {
5
+ /** Optional output directory, resolved from the project root and defaulting to `exports`. */
6
+ readonly outputDirectory?: string;
7
+ /** Root directory of the authored Replayable project. */
8
+ readonly projectRoot: string;
9
+ }
10
+ /** One upload-ready artifact produced from an existing playable variant build. */
11
+ interface ExportVariantResult {
12
+ /** Absolute path to the exported delivery artifact. */
13
+ readonly file: string;
14
+ /** Final artifact size in bytes. */
15
+ readonly size: number;
16
+ /** ID of the concrete version, network, and language that was exported. */
17
+ readonly variantId: string;
18
+ }
19
+ /** Delivery artifacts produced by one successful project export. */
20
+ interface ExportProjectResult {
21
+ /** Absolute directory containing every configured network's artifacts. */
22
+ readonly outputDirectory: string;
23
+ /** Exported variants in deterministic configuration order. */
24
+ readonly variants: readonly ExportVariantResult[];
25
+ }
26
+ //#endregion
27
+ //#region src/pipeline/export-project.d.ts
28
+ /**
29
+ * Produces every upload-ready artifact from an existing Replayable project build.
30
+ *
31
+ * Resolution verifies the builds and assigns destinations. Preparation creates
32
+ * every artifact in memory. Emission replaces the previous export directory only
33
+ * after all preparation succeeds, preserving the last successful export on error.
34
+ */
35
+ declare function exportProject(config: ReplayableConfigInput, options: ExportProjectOptions): Promise<ExportProjectResult>;
36
+ //#endregion
37
+ export { type ExportProjectOptions, type ExportProjectResult, type ExportVariantResult, exportProject };
38
+ //# sourceMappingURL=index.d.mts.map