@swifttui/build 0.0.14 → 0.0.15
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 +23 -4
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +77 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/src/build/buildAppWasm.d.ts +21 -0
- package/dist/src/build/buildAppWasm.js +61 -0
- package/dist/src/build/buildAppWasm.js.map +1 -0
- package/dist/src/build/buildSwiftTUIWebApp.d.ts +10 -0
- package/dist/src/build/buildSwiftTUIWebApp.js +23 -0
- package/dist/src/build/buildSwiftTUIWebApp.js.map +1 -0
- package/dist/src/build/generateSceneManifest.d.ts +13 -0
- package/dist/src/build/generateSceneManifest.js +28 -0
- package/dist/src/build/generateSceneManifest.js.map +1 -0
- package/dist/src/build/optimizePackagedWasm.js +17 -0
- package/dist/src/build/optimizePackagedWasm.js.map +1 -0
- package/dist/src/build/resolveSwiftArtifacts.d.ts +39 -0
- package/dist/src/build/resolveSwiftArtifacts.js +161 -0
- package/dist/src/build/resolveSwiftArtifacts.js.map +1 -0
- package/dist/src/build/runCommand.js +55 -0
- package/dist/src/build/runCommand.js.map +1 -0
- package/dist/src/build/stripPackagedWasm.js +16 -0
- package/dist/src/build/stripPackagedWasm.js.map +1 -0
- package/dist/src/build/swiftCommandPrefix.js +14 -0
- package/dist/src/build/swiftCommandPrefix.js.map +1 -0
- package/dist/src/build/wasmTypeDiagnostics.js +204 -0
- package/dist/src/build/wasmTypeDiagnostics.js.map +1 -0
- package/package.json +25 -11
- package/AGENTS.md +0 -44
- package/cli.ts +0 -98
- package/index.ts +0 -4
- package/src/build/buildAppWasm.test.ts +0 -178
- package/src/build/buildAppWasm.ts +0 -107
- package/src/build/buildSwiftTUIWebApp.ts +0 -22
- package/src/build/generateSceneManifest.ts +0 -46
- package/src/build/optimizePackagedWasm.ts +0 -20
- package/src/build/resolveSwiftArtifacts.test.ts +0 -90
- package/src/build/resolveSwiftArtifacts.ts +0 -253
- package/src/build/runCommand.ts +0 -81
- package/src/build/stripPackagedWasm.ts +0 -19
- package/src/build/swiftCommandPrefix.ts +0 -9
- package/src/build/wasmTypeDiagnostics.ts +0 -313
- package/tsconfig.json +0 -21
|
@@ -1,313 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
|
|
3
|
-
const wasmMagic = [0x00, 0x61, 0x73, 0x6d] as const;
|
|
4
|
-
const wasmVersion = [0x01, 0x00, 0x00, 0x00] as const;
|
|
5
|
-
const typeSectionID = 1;
|
|
6
|
-
const functionTypeTag = 0x60;
|
|
7
|
-
const browserMaxTypeParameterCount = 1000;
|
|
8
|
-
|
|
9
|
-
interface SectionHeader {
|
|
10
|
-
id: number;
|
|
11
|
-
size: number;
|
|
12
|
-
startOffset: number;
|
|
13
|
-
nextOffset: number;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface ReadUnsignedLEB128Result {
|
|
17
|
-
nextOffset: number;
|
|
18
|
-
value: number;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
interface WasmTypeSummary {
|
|
22
|
-
maxTypeParameterCount?: number;
|
|
23
|
-
maxTypeParameterTypeIndex?: number;
|
|
24
|
-
note?: string;
|
|
25
|
-
overBrowserLimitTypes: number[];
|
|
26
|
-
topParameterCounts: Array<{
|
|
27
|
-
parameterCount: number;
|
|
28
|
-
typeIndex: number;
|
|
29
|
-
}>;
|
|
30
|
-
typeCount?: number;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function formatWasmTypeDiagnostics(
|
|
34
|
-
bytes: Uint8Array
|
|
35
|
-
): string {
|
|
36
|
-
const summary = summarizeWasmTypes(bytes);
|
|
37
|
-
const components = [
|
|
38
|
-
`size=${bytes.byteLength} bytes`,
|
|
39
|
-
`sha256=${createHash("sha256").update(bytes).digest("hex")}`,
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
if (summary.typeCount !== undefined) {
|
|
43
|
-
components.push(`typeCount=${summary.typeCount}`);
|
|
44
|
-
}
|
|
45
|
-
if (summary.maxTypeParameterCount !== undefined) {
|
|
46
|
-
components.push(`maxTypeParameterCount=${summary.maxTypeParameterCount}`);
|
|
47
|
-
}
|
|
48
|
-
if (summary.maxTypeParameterTypeIndex !== undefined) {
|
|
49
|
-
components.push(`maxTypeParameterTypeIndex=${summary.maxTypeParameterTypeIndex}`);
|
|
50
|
-
}
|
|
51
|
-
if (summary.overBrowserLimitTypes.length > 0) {
|
|
52
|
-
components.push(`overBrowserLimitTypes=${summary.overBrowserLimitTypes.join(",")}`);
|
|
53
|
-
}
|
|
54
|
-
if (summary.topParameterCounts.length > 0) {
|
|
55
|
-
components.push(
|
|
56
|
-
`largestTypes=${summary.topParameterCounts.map(formatLargestTypeSummary).join(";")}`
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
if (summary.note) {
|
|
60
|
-
components.push(`note=${summary.note}`);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return `wasm diagnostics: ${components.join(", ")}`;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function formatLargestTypeSummary(
|
|
67
|
-
summary: { parameterCount: number; typeIndex: number }
|
|
68
|
-
): string {
|
|
69
|
-
return `${summary.typeIndex}:${summary.parameterCount}`;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function summarizeWasmTypes(
|
|
73
|
-
bytes: Uint8Array
|
|
74
|
-
): WasmTypeSummary {
|
|
75
|
-
if (!hasExpectedPrefix(bytes, 0, wasmMagic)) {
|
|
76
|
-
return {
|
|
77
|
-
note: "missing wasm magic header",
|
|
78
|
-
overBrowserLimitTypes: [],
|
|
79
|
-
topParameterCounts: [],
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
if (!hasExpectedPrefix(bytes, wasmMagic.length, wasmVersion)) {
|
|
83
|
-
return {
|
|
84
|
-
note: "missing wasm version header",
|
|
85
|
-
overBrowserLimitTypes: [],
|
|
86
|
-
topParameterCounts: [],
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
let offset = 8;
|
|
91
|
-
while (offset < bytes.length) {
|
|
92
|
-
let sectionHeader: SectionHeader;
|
|
93
|
-
try {
|
|
94
|
-
sectionHeader = readSectionHeader(bytes, offset);
|
|
95
|
-
} catch (error) {
|
|
96
|
-
return {
|
|
97
|
-
note: `failed to read section header at byte ${offset}: ${describeError(error)}`,
|
|
98
|
-
overBrowserLimitTypes: [],
|
|
99
|
-
topParameterCounts: [],
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (sectionHeader.id === typeSectionID) {
|
|
104
|
-
return summarizeTypeSection(bytes, sectionHeader.startOffset, sectionHeader.nextOffset);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
offset = sectionHeader.nextOffset;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return {
|
|
111
|
-
note: "module has no type section",
|
|
112
|
-
overBrowserLimitTypes: [],
|
|
113
|
-
topParameterCounts: [],
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function summarizeTypeSection(
|
|
118
|
-
bytes: Uint8Array,
|
|
119
|
-
startOffset: number,
|
|
120
|
-
endOffset: number
|
|
121
|
-
): WasmTypeSummary {
|
|
122
|
-
let offset = startOffset;
|
|
123
|
-
let typeCount: number;
|
|
124
|
-
|
|
125
|
-
try {
|
|
126
|
-
const result = readUnsignedLEB128(bytes, offset);
|
|
127
|
-
typeCount = result.value;
|
|
128
|
-
offset = result.nextOffset;
|
|
129
|
-
} catch (error) {
|
|
130
|
-
return {
|
|
131
|
-
note: `failed to read type vector length: ${describeError(error)}`,
|
|
132
|
-
overBrowserLimitTypes: [],
|
|
133
|
-
topParameterCounts: [],
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
let maxTypeParameterCount = -1;
|
|
138
|
-
let maxTypeParameterTypeIndex = -1;
|
|
139
|
-
const overBrowserLimitTypes: number[] = [];
|
|
140
|
-
const topParameterCounts: Array<{ parameterCount: number; typeIndex: number }> = [];
|
|
141
|
-
|
|
142
|
-
for (let typeIndex = 0; typeIndex < typeCount; typeIndex += 1) {
|
|
143
|
-
if (offset >= endOffset) {
|
|
144
|
-
return {
|
|
145
|
-
note: `type section ended early while reading type ${typeIndex}`,
|
|
146
|
-
overBrowserLimitTypes,
|
|
147
|
-
topParameterCounts,
|
|
148
|
-
typeCount,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const typeTag = bytes[offset];
|
|
153
|
-
offset += 1;
|
|
154
|
-
if (typeTag !== functionTypeTag) {
|
|
155
|
-
return {
|
|
156
|
-
note: `unexpected type tag 0x${typeTag.toString(16)} at type ${typeIndex}`,
|
|
157
|
-
overBrowserLimitTypes,
|
|
158
|
-
topParameterCounts,
|
|
159
|
-
typeCount,
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
let parameterCount: number;
|
|
164
|
-
try {
|
|
165
|
-
const result = readUnsignedLEB128(bytes, offset);
|
|
166
|
-
parameterCount = result.value;
|
|
167
|
-
offset = result.nextOffset;
|
|
168
|
-
} catch (error) {
|
|
169
|
-
return {
|
|
170
|
-
note: `failed to read parameter count for type ${typeIndex}: ${describeError(error)}`,
|
|
171
|
-
overBrowserLimitTypes,
|
|
172
|
-
topParameterCounts,
|
|
173
|
-
typeCount,
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (parameterCount > maxTypeParameterCount) {
|
|
178
|
-
maxTypeParameterCount = parameterCount;
|
|
179
|
-
maxTypeParameterTypeIndex = typeIndex;
|
|
180
|
-
}
|
|
181
|
-
if (parameterCount > browserMaxTypeParameterCount) {
|
|
182
|
-
overBrowserLimitTypes.push(typeIndex);
|
|
183
|
-
}
|
|
184
|
-
updateLargestTypeSummaries(topParameterCounts, typeIndex, parameterCount);
|
|
185
|
-
|
|
186
|
-
offset += parameterCount;
|
|
187
|
-
if (offset > endOffset) {
|
|
188
|
-
return {
|
|
189
|
-
note: `parameter vector for type ${typeIndex} overruns type section`,
|
|
190
|
-
overBrowserLimitTypes,
|
|
191
|
-
topParameterCounts,
|
|
192
|
-
typeCount,
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
let resultCount: number;
|
|
197
|
-
try {
|
|
198
|
-
const result = readUnsignedLEB128(bytes, offset);
|
|
199
|
-
resultCount = result.value;
|
|
200
|
-
offset = result.nextOffset;
|
|
201
|
-
} catch (error) {
|
|
202
|
-
return {
|
|
203
|
-
note: `failed to read result count for type ${typeIndex}: ${describeError(error)}`,
|
|
204
|
-
overBrowserLimitTypes,
|
|
205
|
-
topParameterCounts,
|
|
206
|
-
typeCount,
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
offset += resultCount;
|
|
211
|
-
if (offset > endOffset) {
|
|
212
|
-
return {
|
|
213
|
-
note: `result vector for type ${typeIndex} overruns type section`,
|
|
214
|
-
overBrowserLimitTypes,
|
|
215
|
-
topParameterCounts,
|
|
216
|
-
typeCount,
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
return {
|
|
222
|
-
maxTypeParameterCount: maxTypeParameterCount >= 0 ? maxTypeParameterCount : undefined,
|
|
223
|
-
maxTypeParameterTypeIndex: maxTypeParameterTypeIndex >= 0 ? maxTypeParameterTypeIndex : undefined,
|
|
224
|
-
overBrowserLimitTypes,
|
|
225
|
-
topParameterCounts,
|
|
226
|
-
typeCount,
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
function updateLargestTypeSummaries(
|
|
231
|
-
summaries: Array<{ parameterCount: number; typeIndex: number }>,
|
|
232
|
-
typeIndex: number,
|
|
233
|
-
parameterCount: number
|
|
234
|
-
): void {
|
|
235
|
-
summaries.push({ parameterCount, typeIndex });
|
|
236
|
-
summaries.sort((left, right) => {
|
|
237
|
-
if (right.parameterCount === left.parameterCount) {
|
|
238
|
-
return left.typeIndex - right.typeIndex;
|
|
239
|
-
}
|
|
240
|
-
return right.parameterCount - left.parameterCount;
|
|
241
|
-
});
|
|
242
|
-
summaries.splice(5);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
function readSectionHeader(
|
|
246
|
-
bytes: Uint8Array,
|
|
247
|
-
offset: number
|
|
248
|
-
): SectionHeader {
|
|
249
|
-
if (offset >= bytes.length) {
|
|
250
|
-
throw new Error("unexpected end of file");
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const id = bytes[offset];
|
|
254
|
-
const size = readUnsignedLEB128(bytes, offset + 1);
|
|
255
|
-
const startOffset = size.nextOffset;
|
|
256
|
-
const nextOffset = startOffset + size.value;
|
|
257
|
-
if (nextOffset > bytes.length) {
|
|
258
|
-
throw new Error(`section ${id} overruns file bounds`);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
return {
|
|
262
|
-
id,
|
|
263
|
-
size: size.value,
|
|
264
|
-
startOffset,
|
|
265
|
-
nextOffset,
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
function readUnsignedLEB128(
|
|
270
|
-
bytes: Uint8Array,
|
|
271
|
-
offset: number
|
|
272
|
-
): ReadUnsignedLEB128Result {
|
|
273
|
-
let shift = 0;
|
|
274
|
-
let value = 0;
|
|
275
|
-
let nextOffset = offset;
|
|
276
|
-
|
|
277
|
-
while (nextOffset < bytes.length) {
|
|
278
|
-
const byte = bytes[nextOffset];
|
|
279
|
-
nextOffset += 1;
|
|
280
|
-
value |= (byte & 0x7f) << shift;
|
|
281
|
-
if ((byte & 0x80) === 0) {
|
|
282
|
-
return {
|
|
283
|
-
nextOffset,
|
|
284
|
-
value,
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
shift += 7;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
throw new Error("unterminated LEB128 value");
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
function hasExpectedPrefix(
|
|
294
|
-
bytes: Uint8Array,
|
|
295
|
-
startOffset: number,
|
|
296
|
-
expected: readonly number[]
|
|
297
|
-
): boolean {
|
|
298
|
-
if (startOffset + expected.length > bytes.length) {
|
|
299
|
-
return false;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
for (let index = 0; index < expected.length; index += 1) {
|
|
303
|
-
if (bytes[startOffset + index] !== expected[index]) {
|
|
304
|
-
return false;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
return true;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
function describeError(error: unknown): string {
|
|
312
|
-
return error instanceof Error ? error.message : String(error);
|
|
313
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"lib": ["ESNext"],
|
|
4
|
-
"target": "ESNext",
|
|
5
|
-
"module": "Preserve",
|
|
6
|
-
"moduleDetection": "force",
|
|
7
|
-
"allowJs": true,
|
|
8
|
-
"moduleResolution": "bundler",
|
|
9
|
-
"allowImportingTsExtensions": true,
|
|
10
|
-
"verbatimModuleSyntax": true,
|
|
11
|
-
"noEmit": true,
|
|
12
|
-
"strict": true,
|
|
13
|
-
"skipLibCheck": true,
|
|
14
|
-
"noFallthroughCasesInSwitch": true,
|
|
15
|
-
"noUncheckedIndexedAccess": true,
|
|
16
|
-
"noImplicitOverride": true,
|
|
17
|
-
"noUnusedLocals": false,
|
|
18
|
-
"noUnusedParameters": false,
|
|
19
|
-
"noPropertyAccessFromIndexSignature": false
|
|
20
|
-
}
|
|
21
|
-
}
|