|
6 | 6 | * -> rojo build stamped with `<commit7>[-dirty]` -> hash -> rojo build stamped with the final id |
7 | 7 | * -> payload contents check (only Folders and ModuleScripts) -> .typetorch/payload.rbxm + payload.json. |
8 | 8 | */ |
| 9 | +import { execFileSync } from "node:child_process"; |
9 | 10 | import { createHash } from "node:crypto"; |
| 11 | +import { packProject, type PackResult } from "./pack.ts"; |
10 | 12 | import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; |
11 | 13 | import { dirname, extname, join, relative, resolve } from "node:path"; |
12 | 14 | import type { Project } from "./config.ts"; |
@@ -49,7 +51,7 @@ export const PAYLOAD_FILE = `${OUT_DIR}/payload.rbxm`; |
49 | 51 | export const PAYLOAD_META = `${OUT_DIR}/payload.json`; |
50 | 52 | export { PACKAGES_MANIFEST }; |
51 | 53 | /** Files TypeTorch writes inside the repo; they never make a build "dirty". */ |
52 | | -export const GENERATED_PATHS = [BUILD_FILE, GEN_PROJECT, PROD_TSCONFIG, `${OUT_DIR}/`]; |
| 54 | +export const GENERATED_PATHS = [BUILD_FILE, GEN_PROJECT, PROD_TSCONFIG, `${OUT_DIR}/`, ".typetorch/pack/", ".typetorch/pack-work/"]; |
53 | 55 | /** File types that can end up in a payload (compiled by rbxtsc, or synced by Rojo). */ |
54 | 56 | const PAYLOAD_FILE_TYPES = /\.(ts|tsx|lua|luau|json|toml|ya?ml|txt|csv|rbxm|rbxmx|model\.json|meta\.json)$/i; |
55 | 57 |
|
@@ -243,6 +245,19 @@ export function rojoBinary(): string { |
243 | 245 | return settings().get("TYPETORCH_ROJO")?.value || "rojo"; |
244 | 246 | } |
245 | 247 |
|
| 248 | +export function darkluaBinary(): string { |
| 249 | + return process.env.TYPETORCH_DARKLUA || "darklua"; |
| 250 | +} |
| 251 | + |
| 252 | +/** The installed darklua's version line, or undefined when it can't run. */ |
| 253 | +export function darkluaVersion(): string | undefined { |
| 254 | + try { |
| 255 | + return execFileSync(darkluaBinary(), ["--version"], { encoding: "utf8", timeout: 10_000, stdio: ["ignore", "pipe", "ignore"] }).trim(); |
| 256 | + } catch { |
| 257 | + return undefined; |
| 258 | + } |
| 259 | +} |
| 260 | + |
246 | 261 | export function luneBinary(): string { |
247 | 262 | return settings().get("TYPETORCH_LUNE")?.value || "lune"; |
248 | 263 | } |
@@ -385,6 +400,8 @@ export interface BuildResult { |
385 | 400 | } |
386 | 401 |
|
387 | 402 | export interface BuildOptions { |
| 403 | + /** The production stages (pack.ts); false: --no-minify. */ |
| 404 | + minify?: boolean; |
388 | 405 | branch?: string; |
389 | 406 | channel?: Channel; |
390 | 407 | /** `git clean -fdX` out/ and include/ first (deploy and upload always do; `build --clean`). */ |
@@ -579,10 +596,25 @@ export async function buildPayload(project: Project, options: BuildOptions = {}) |
579 | 596 | Object.assign(stamped, healthAttributes(health)); |
580 | 597 | return stamped; |
581 | 598 | }; |
| 599 | + // The production stages (pack.ts): rojo packs a transformed copy, so the id and the signature cover the final bytes. |
| 600 | + let packed: PackResult | undefined; |
| 601 | + if (options.minify !== false && (project.config as { minify?: boolean }).minify !== false) { |
| 602 | + const version = darkluaVersion(); |
| 603 | + if (!version) { |
| 604 | + warn(`darklua not found: this payload isn't minified. Add it with \`rokit add seaofvoices/darklua\`, or set "minify": false in typetorch.json to silence this`); |
| 605 | + } else { |
| 606 | + await watch.stage("pack", async () => { |
| 607 | + packed = await packProject({ root, project: projectJson, paths: projectPaths(projectJson), darklua: darkluaBinary(), darkluaVersion: version, run }); |
| 608 | + }); |
| 609 | + for (const reason of packed!.skipped) warn(`pack: ${reason}`); |
| 610 | + debug(`pack: ${packed!.modules} modules (${packed!.processed} processed), ${packed!.sourceBytes} -> ${packed!.packedBytes} bytes, ${packed!.dropped.length} dropped`); |
| 611 | + } |
| 612 | + } |
| 613 | + const rojoProject = packed?.project ?? projectJson; |
582 | 614 | const rojoBuild = async (id: string): Promise<Uint8Array> => { |
583 | 615 | debug(`rojo build stamped ArtifactId=${id}`); |
584 | 616 | const children = { [ASSETS_PAYLOAD_FOLDER]: { [ASSETS_PAYLOAD_ATTRIBUTE]: assetsJson } }; |
585 | | - writeFileSync(genPath, JSON.stringify(stampProject(projectJson, attributes(id), children), null, "\t")); |
| 617 | + writeFileSync(genPath, JSON.stringify(stampProject(rojoProject, attributes(id), children), null, "\t")); |
586 | 618 | try { |
587 | 619 | await run([rojoBinary(), "build", GEN_PROJECT, "-o", PAYLOAD_FILE], root); |
588 | 620 | } finally { |
|
0 commit comments