@swifttui/build 0.1.0 → 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.
|
@@ -19,10 +19,12 @@ async function buildAppWasm(options) {
|
|
|
19
19
|
async function packageBrowserValidatedWasm(options) {
|
|
20
20
|
const sourceBytes = await readFile(options.sourceWasmPath);
|
|
21
21
|
await writeFile(options.outputWasmPath, sourceBytes);
|
|
22
|
+
let lastGood = sourceBytes;
|
|
22
23
|
const optimize = options.optimize ?? optimizePackagedWasm;
|
|
23
24
|
try {
|
|
24
25
|
await optimize(options.outputWasmPath);
|
|
25
26
|
await validateBrowserWasm(options.outputWasmPath, "optimized wasm");
|
|
27
|
+
lastGood = await readFile(options.outputWasmPath);
|
|
26
28
|
} catch (error) {
|
|
27
29
|
await writeFile(options.outputWasmPath, sourceBytes);
|
|
28
30
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -40,7 +42,7 @@ async function packageBrowserValidatedWasm(options) {
|
|
|
40
42
|
await strip(options.outputWasmPath);
|
|
41
43
|
await validateBrowserWasm(options.outputWasmPath, "stripped wasm");
|
|
42
44
|
} catch (error) {
|
|
43
|
-
await writeFile(options.outputWasmPath,
|
|
45
|
+
await writeFile(options.outputWasmPath, lastGood);
|
|
44
46
|
const message = error instanceof Error ? error.message : String(error);
|
|
45
47
|
const warning = [`warning: keeping unstripped wasm at ${options.outputWasmPath}`, `strip step failed browser validation or tooling requirements: ${message}`].join("\n");
|
|
46
48
|
(options.onWarning ?? console.warn)(warning);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildAppWasm.js","names":[],"sources":["../../../src/build/buildAppWasm.ts"],"sourcesContent":["import { mkdir, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { optimizePackagedWasm } from \"./optimizePackagedWasm.ts\";\nimport {\n resolveSwiftArtifacts,\n type ResolveSwiftArtifactsOptions,\n type SwiftArtifactPaths,\n type WasmBuildConfiguration,\n} from \"./resolveSwiftArtifacts.ts\";\nimport { stripPackagedWasm } from \"./stripPackagedWasm.ts\";\nimport { formatWasmTypeDiagnostics } from \"./wasmTypeDiagnostics.ts\";\n\nexport interface BuildAppWasmOptions extends ResolveSwiftArtifactsOptions {\n configuration?: WasmBuildConfiguration;\n packagePath: string;\n outputDirectory: string;\n product: string;\n}\n\nexport async function buildAppWasm(\n options: BuildAppWasmOptions\n): Promise<SwiftArtifactPaths> {\n const artifacts = await resolveSwiftArtifacts(options);\n\n const packagedWasmPath = join(options.outputDirectory, \"assets\", \"app.wasm\");\n await mkdir(join(options.outputDirectory, \"assets\"), { recursive: true });\n await rm(packagedWasmPath, { force: true });\n await packageBrowserValidatedWasm({\n sourceWasmPath: artifacts.wasmPath,\n outputWasmPath: packagedWasmPath,\n });\n return artifacts;\n}\n\ninterface PackageBrowserValidatedWasmOptions {\n optimize?: (wasmPath: string) => Promise<void>;\n sourceWasmPath: string;\n outputWasmPath: string;\n strip?: (wasmPath: string) => Promise<void>;\n onWarning?: (message: string) => void;\n}\n\nexport async function packageBrowserValidatedWasm(\n options: PackageBrowserValidatedWasmOptions\n): Promise<void> {\n const sourceBytes = await readFile(options.sourceWasmPath);\n await writeFile(options.outputWasmPath, sourceBytes);\n\n const optimize = options.optimize ?? optimizePackagedWasm;\n try {\n await optimize(options.outputWasmPath);\n await validateBrowserWasm(options.outputWasmPath, \"optimized wasm\");\n } catch (error) {\n await writeFile(options.outputWasmPath, sourceBytes);\n const message = error instanceof Error ? error.message : String(error);\n\n try {\n await validateBrowserWasm(options.outputWasmPath, \"generated wasm\");\n } catch (rawError) {\n const rawMessage = rawError instanceof Error ? rawError.message : String(rawError);\n throw new Error([\n rawMessage,\n `wasm optimization step failed: ${message}`,\n ].join(\"\\n\"));\n }\n\n const warning = [\n `warning: keeping unoptimized wasm at ${options.outputWasmPath}`,\n `wasm optimization step failed or did not produce browser-parseable output: ${message}`,\n ].join(\"\\n\");\n (options.onWarning ?? console.warn)(warning);\n }\n\n const strip = options.strip ?? stripPackagedWasm;\n\n try {\n await strip(options.outputWasmPath);\n await validateBrowserWasm(options.outputWasmPath, \"stripped wasm\");\n } catch (error) {\n // Stripping is a size optimization only.
|
|
1
|
+
{"version":3,"file":"buildAppWasm.js","names":[],"sources":["../../../src/build/buildAppWasm.ts"],"sourcesContent":["import { mkdir, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { optimizePackagedWasm } from \"./optimizePackagedWasm.ts\";\nimport {\n resolveSwiftArtifacts,\n type ResolveSwiftArtifactsOptions,\n type SwiftArtifactPaths,\n type WasmBuildConfiguration,\n} from \"./resolveSwiftArtifacts.ts\";\nimport { stripPackagedWasm } from \"./stripPackagedWasm.ts\";\nimport { formatWasmTypeDiagnostics } from \"./wasmTypeDiagnostics.ts\";\n\nexport interface BuildAppWasmOptions extends ResolveSwiftArtifactsOptions {\n configuration?: WasmBuildConfiguration;\n packagePath: string;\n outputDirectory: string;\n product: string;\n}\n\nexport async function buildAppWasm(\n options: BuildAppWasmOptions\n): Promise<SwiftArtifactPaths> {\n const artifacts = await resolveSwiftArtifacts(options);\n\n const packagedWasmPath = join(options.outputDirectory, \"assets\", \"app.wasm\");\n await mkdir(join(options.outputDirectory, \"assets\"), { recursive: true });\n await rm(packagedWasmPath, { force: true });\n await packageBrowserValidatedWasm({\n sourceWasmPath: artifacts.wasmPath,\n outputWasmPath: packagedWasmPath,\n });\n return artifacts;\n}\n\ninterface PackageBrowserValidatedWasmOptions {\n optimize?: (wasmPath: string) => Promise<void>;\n sourceWasmPath: string;\n outputWasmPath: string;\n strip?: (wasmPath: string) => Promise<void>;\n onWarning?: (message: string) => void;\n}\n\nexport async function packageBrowserValidatedWasm(\n options: PackageBrowserValidatedWasmOptions\n): Promise<void> {\n const sourceBytes = await readFile(options.sourceWasmPath);\n await writeFile(options.outputWasmPath, sourceBytes);\n\n // Track the last bytes that passed browser validation and are on disk, so a\n // later stage failure restores the best validated output rather than the raw\n // source (discarding an earlier successful optimize pass).\n let lastGood = sourceBytes;\n\n const optimize = options.optimize ?? optimizePackagedWasm;\n try {\n await optimize(options.outputWasmPath);\n await validateBrowserWasm(options.outputWasmPath, \"optimized wasm\");\n lastGood = await readFile(options.outputWasmPath);\n } catch (error) {\n await writeFile(options.outputWasmPath, sourceBytes);\n const message = error instanceof Error ? error.message : String(error);\n\n try {\n await validateBrowserWasm(options.outputWasmPath, \"generated wasm\");\n } catch (rawError) {\n const rawMessage = rawError instanceof Error ? rawError.message : String(rawError);\n throw new Error([\n rawMessage,\n `wasm optimization step failed: ${message}`,\n ].join(\"\\n\"));\n }\n\n const warning = [\n `warning: keeping unoptimized wasm at ${options.outputWasmPath}`,\n `wasm optimization step failed or did not produce browser-parseable output: ${message}`,\n ].join(\"\\n\");\n (options.onWarning ?? console.warn)(warning);\n }\n\n const strip = options.strip ?? stripPackagedWasm;\n\n try {\n await strip(options.outputWasmPath);\n await validateBrowserWasm(options.outputWasmPath, \"stripped wasm\");\n } catch (error) {\n // Stripping is a size optimization only. Restore the last validated wasm\n // (the optimized bytes when optimization succeeded, otherwise the raw\n // source) whenever toolchain-specific objcopy output fails browser\n // validation, rather than discarding a successful optimize pass.\n await writeFile(options.outputWasmPath, lastGood);\n const message = error instanceof Error ? error.message : String(error);\n const warning = [\n `warning: keeping unstripped wasm at ${options.outputWasmPath}`,\n `strip step failed browser validation or tooling requirements: ${message}`,\n ].join(\"\\n\");\n (options.onWarning ?? console.warn)(warning);\n }\n}\n\nasync function validateBrowserWasm(\n wasmPath: string,\n description: string\n): Promise<void> {\n const bytes = await readFile(wasmPath);\n try {\n // Validate against the same JS API the browser uses before we publish it.\n await WebAssembly.compile(bytes);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n throw new Error([\n `${description} does not parse in browser WebAssembly (${wasmPath}): ${message}`,\n formatWasmTypeDiagnostics(bytes),\n ].join(\"\\n\"));\n }\n}\n"],"mappings":";;;;;;;AAmBA,eAAsB,aACpB,SAC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,QAAQ;EAChD,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EACrE,MAAM,UAAU,CACd,uCAAuC,QAAQ,kBAC/C,iEAAiE,SACnE,CAAC,CAAC,KAAK,IAAI;EACX,CAAC,QAAQ,aAAa,QAAQ,KAAA,CAAM,OAAO;CAC7C;AACF;AAEA,eAAe,oBACb,UACA,aACe;CACf,MAAM,QAAQ,MAAM,SAAS,QAAQ;CACrC,IAAI;EAEF,MAAM,YAAY,QAAQ,KAAK;CACjC,SAAS,OAAO;EACd,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EACrE,MAAM,IAAI,MAAM,CACd,GAAG,YAAY,0CAA0C,SAAS,KAAK,WACvE,0BAA0B,KAAK,CACjC,CAAC,CAAC,KAAK,IAAI,CAAC;CACd;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swifttui/build",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@swifttui/web": "0.1.
|
|
37
|
+
"@swifttui/web": "0.1.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/bun": "1.3.13"
|