@swiftbrowser/cli 0.1.0 → 0.2.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 +330 -64
- package/dist/assetSymbols.d.ts +25 -0
- package/dist/assetSymbols.js +218 -0
- package/dist/assetSymbols.js.map +1 -0
- package/dist/build.d.ts +17 -2
- package/dist/build.js +40 -13
- package/dist/build.js.map +1 -1
- package/dist/buildSettings.d.ts +15 -0
- package/dist/buildSettings.js +74 -0
- package/dist/buildSettings.js.map +1 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +60 -11
- package/dist/cli.js.map +1 -1
- package/dist/commands/build.js +6 -5
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/check.js +2 -2
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/dev.d.ts +5 -2
- package/dist/commands/dev.js +19 -13
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/init.d.ts +18 -0
- package/dist/commands/init.js +57 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/kit.d.ts +3 -0
- package/dist/commands/kit.js +21 -0
- package/dist/commands/kit.js.map +1 -0
- package/dist/commands/shared.d.ts +25 -4
- package/dist/commands/shared.js +104 -10
- package/dist/commands/shared.js.map +1 -1
- package/dist/compat.d.ts +44 -6
- package/dist/compat.js +64 -36
- package/dist/compat.js.map +1 -1
- package/dist/config.d.ts +48 -10
- package/dist/config.js +64 -8
- package/dist/config.js.map +1 -1
- package/dist/coreml.d.ts +194 -0
- package/dist/coreml.js +626 -0
- package/dist/coreml.js.map +1 -0
- package/dist/icu.d.ts +17 -4
- package/dist/icu.js +32 -18
- package/dist/icu.js.map +1 -1
- package/dist/kit.d.ts +133 -0
- package/dist/kit.js +403 -0
- package/dist/kit.js.map +1 -0
- package/dist/objc.d.ts +31 -0
- package/dist/objc.js +319 -0
- package/dist/objc.js.map +1 -0
- package/dist/packagePatches.d.ts +24 -0
- package/dist/packagePatches.js +107 -0
- package/dist/packagePatches.js.map +1 -0
- package/dist/packages.d.ts +59 -0
- package/dist/packages.js +149 -0
- package/dist/packages.js.map +1 -0
- package/dist/project.d.ts +45 -4
- package/dist/project.js +91 -18
- package/dist/project.js.map +1 -1
- package/dist/protobuf.d.ts +62 -0
- package/dist/protobuf.js +233 -0
- package/dist/protobuf.js.map +1 -0
- package/dist/stage.d.ts +155 -27
- package/dist/stage.js +483 -79
- package/dist/stage.js.map +1 -1
- package/dist/strings.d.ts +44 -0
- package/dist/strings.js +386 -0
- package/dist/strings.js.map +1 -0
- package/dist/template.d.ts +29 -0
- package/dist/template.js +438 -0
- package/dist/template.js.map +1 -0
- package/dist/threadStacks.d.ts +14 -0
- package/dist/threadStacks.js +78 -0
- package/dist/threadStacks.js.map +1 -0
- package/dist/toolchain.d.ts +7 -1
- package/dist/toolchain.js +8 -2
- package/dist/toolchain.js.map +1 -1
- package/dist/urlSchemes.d.ts +11 -0
- package/dist/urlSchemes.js +58 -0
- package/dist/urlSchemes.js.map +1 -0
- package/dist/vendor.d.ts +109 -0
- package/dist/vendor.js +440 -0
- package/dist/vendor.js.map +1 -0
- package/dist/wasm.d.ts +28 -0
- package/dist/wasm.js +84 -0
- package/dist/wasm.js.map +1 -0
- package/package.json +7 -6
package/dist/protobuf.js
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
// A reader for the protocol buffers wire format, as much of it as Core ML's
|
|
2
|
+
// model files need (coreml.ts): a message decodes into its fields by number,
|
|
3
|
+
// and the typed accessors apply proto3's rules (a missing scalar is its zero
|
|
4
|
+
// value, the last occurrence of a scalar wins, repeated numbers may be packed
|
|
5
|
+
// or not). No schema, no code generation, no dependency.
|
|
6
|
+
/** Wire types (the low three bits of a field's key). Groups (3, 4) are long deprecated and rejected. */
|
|
7
|
+
export const WIRE_VARINT = 0;
|
|
8
|
+
export const WIRE_FIXED64 = 1;
|
|
9
|
+
export const WIRE_BYTES = 2;
|
|
10
|
+
export const WIRE_FIXED32 = 5;
|
|
11
|
+
/** A malformed message: truncated, a bad varint, an unknown wire type. */
|
|
12
|
+
export class ProtobufError extends Error {
|
|
13
|
+
offset;
|
|
14
|
+
constructor(message, offset) {
|
|
15
|
+
super(offset === undefined ? message : `${message} at byte ${offset}`);
|
|
16
|
+
this.offset = offset;
|
|
17
|
+
this.name = 'ProtobufError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** Reads a base-128 varint at `offset`; returns the value (unsigned, at most 64 bits) and the offset after it. */
|
|
21
|
+
export function readVarint(buffer, offset) {
|
|
22
|
+
let result = 0n;
|
|
23
|
+
let shift = 0n;
|
|
24
|
+
let position = offset;
|
|
25
|
+
for (;;) {
|
|
26
|
+
if (position >= buffer.length)
|
|
27
|
+
throw new ProtobufError('truncated varint', offset);
|
|
28
|
+
const byte = buffer[position];
|
|
29
|
+
position += 1;
|
|
30
|
+
result |= BigInt(byte & 0x7f) << shift;
|
|
31
|
+
if ((byte & 0x80) === 0)
|
|
32
|
+
break;
|
|
33
|
+
shift += 7n;
|
|
34
|
+
if (shift >= 70n)
|
|
35
|
+
throw new ProtobufError('varint longer than 10 bytes', offset);
|
|
36
|
+
}
|
|
37
|
+
return [BigInt.asUintN(64, result), position];
|
|
38
|
+
}
|
|
39
|
+
/** A decoded message: its fields by number, in the order they appeared. */
|
|
40
|
+
export class ProtoMessage {
|
|
41
|
+
buffer;
|
|
42
|
+
fields = new Map();
|
|
43
|
+
constructor(buffer) {
|
|
44
|
+
this.buffer = buffer;
|
|
45
|
+
let offset = 0;
|
|
46
|
+
while (offset < buffer.length) {
|
|
47
|
+
const start = offset;
|
|
48
|
+
const [key, afterKey] = readVarint(buffer, offset);
|
|
49
|
+
offset = afterKey;
|
|
50
|
+
const number = Number(key >> 3n);
|
|
51
|
+
const wireType = Number(key & 7n);
|
|
52
|
+
if (number === 0)
|
|
53
|
+
throw new ProtobufError('field number 0', start);
|
|
54
|
+
let field;
|
|
55
|
+
switch (wireType) {
|
|
56
|
+
case WIRE_VARINT: {
|
|
57
|
+
const [value, next] = readVarint(buffer, offset);
|
|
58
|
+
offset = next;
|
|
59
|
+
field = { wireType, varint: value };
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
case WIRE_FIXED64:
|
|
63
|
+
case WIRE_FIXED32: {
|
|
64
|
+
const size = wireType === WIRE_FIXED64 ? 8 : 4;
|
|
65
|
+
if (offset + size > buffer.length)
|
|
66
|
+
throw new ProtobufError('truncated fixed-width field', start);
|
|
67
|
+
field = { wireType, bytes: buffer.subarray(offset, offset + size) };
|
|
68
|
+
offset += size;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
case WIRE_BYTES: {
|
|
72
|
+
const [length, next] = readVarint(buffer, offset);
|
|
73
|
+
const end = next + Number(length);
|
|
74
|
+
if (length > BigInt(buffer.length) || end > buffer.length)
|
|
75
|
+
throw new ProtobufError('truncated length-delimited field', start);
|
|
76
|
+
field = { wireType, bytes: buffer.subarray(next, end) };
|
|
77
|
+
offset = end;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
default:
|
|
81
|
+
throw new ProtobufError(`unsupported wire type ${wireType} (field ${number})`, start);
|
|
82
|
+
}
|
|
83
|
+
let list = this.fields.get(number);
|
|
84
|
+
if (!list) {
|
|
85
|
+
list = [];
|
|
86
|
+
this.fields.set(number, list);
|
|
87
|
+
}
|
|
88
|
+
list.push(field);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
has(number) {
|
|
92
|
+
return this.fields.has(number);
|
|
93
|
+
}
|
|
94
|
+
/** The field numbers present, ascending. */
|
|
95
|
+
numbers() {
|
|
96
|
+
return [...this.fields.keys()].sort((a, b) => a - b);
|
|
97
|
+
}
|
|
98
|
+
last(number) {
|
|
99
|
+
const list = this.fields.get(number);
|
|
100
|
+
return list?.[list.length - 1];
|
|
101
|
+
}
|
|
102
|
+
/** An embedded message (the last occurrence), or undefined when absent. */
|
|
103
|
+
message(number) {
|
|
104
|
+
const field = this.last(number);
|
|
105
|
+
if (!field)
|
|
106
|
+
return undefined;
|
|
107
|
+
return new ProtoMessage(expectBytes(field, number));
|
|
108
|
+
}
|
|
109
|
+
/** Every occurrence of a repeated message field. */
|
|
110
|
+
messages(number) {
|
|
111
|
+
return (this.fields.get(number) ?? []).map((field) => new ProtoMessage(expectBytes(field, number)));
|
|
112
|
+
}
|
|
113
|
+
/** A `bytes` field ('' → empty). */
|
|
114
|
+
bytes(number) {
|
|
115
|
+
const field = this.last(number);
|
|
116
|
+
return field ? expectBytes(field, number) : new Uint8Array();
|
|
117
|
+
}
|
|
118
|
+
/** A `string` field (UTF-8; '' when absent). */
|
|
119
|
+
string(number) {
|
|
120
|
+
return DECODER.decode(this.bytes(number));
|
|
121
|
+
}
|
|
122
|
+
/** A `repeated string` field. */
|
|
123
|
+
strings(number) {
|
|
124
|
+
return (this.fields.get(number) ?? []).map((field) => DECODER.decode(expectBytes(field, number)));
|
|
125
|
+
}
|
|
126
|
+
/** An unsigned varint field (`uint32`, `uint64`, `bool`, enums): 0n when absent. */
|
|
127
|
+
uint64(number) {
|
|
128
|
+
const field = this.last(number);
|
|
129
|
+
if (!field)
|
|
130
|
+
return 0n;
|
|
131
|
+
if (field.wireType !== WIRE_VARINT)
|
|
132
|
+
throw new ProtobufError(`field ${number} is not a varint`);
|
|
133
|
+
return field.varint;
|
|
134
|
+
}
|
|
135
|
+
/** A signed `int32` / `int64` field (two's complement, not zigzag). */
|
|
136
|
+
int64(number) {
|
|
137
|
+
return BigInt.asIntN(64, this.uint64(number));
|
|
138
|
+
}
|
|
139
|
+
/** A varint field as a JavaScript number; throws when it does not fit exactly. */
|
|
140
|
+
int(number) {
|
|
141
|
+
return safeNumber(this.int64(number), number);
|
|
142
|
+
}
|
|
143
|
+
bool(number) {
|
|
144
|
+
return this.uint64(number) !== 0n;
|
|
145
|
+
}
|
|
146
|
+
/** A `double` field: 0 when absent. */
|
|
147
|
+
double(number) {
|
|
148
|
+
const field = this.last(number);
|
|
149
|
+
if (!field)
|
|
150
|
+
return 0;
|
|
151
|
+
if (field.wireType !== WIRE_FIXED64)
|
|
152
|
+
throw new ProtobufError(`field ${number} is not a double`);
|
|
153
|
+
return view(field.bytes).getFloat64(0, true);
|
|
154
|
+
}
|
|
155
|
+
/** A `float` field: 0 when absent. */
|
|
156
|
+
float(number) {
|
|
157
|
+
const field = this.last(number);
|
|
158
|
+
if (!field)
|
|
159
|
+
return 0;
|
|
160
|
+
if (field.wireType !== WIRE_FIXED32)
|
|
161
|
+
throw new ProtobufError(`field ${number} is not a float`);
|
|
162
|
+
return view(field.bytes).getFloat32(0, true);
|
|
163
|
+
}
|
|
164
|
+
/** A `repeated double` field, packed or not. */
|
|
165
|
+
doubles(number) {
|
|
166
|
+
return this.fixedList(number, 8, (v, at) => v.getFloat64(at, true));
|
|
167
|
+
}
|
|
168
|
+
/** A `repeated float` field, packed or not. */
|
|
169
|
+
floats(number) {
|
|
170
|
+
return this.fixedList(number, 4, (v, at) => v.getFloat32(at, true));
|
|
171
|
+
}
|
|
172
|
+
/** A `repeated int64` / `uint64` / enum field, packed or not, signed. */
|
|
173
|
+
int64s(number) {
|
|
174
|
+
const out = [];
|
|
175
|
+
for (const field of this.fields.get(number) ?? []) {
|
|
176
|
+
if (field.wireType === WIRE_VARINT) {
|
|
177
|
+
out.push(BigInt.asIntN(64, field.varint));
|
|
178
|
+
}
|
|
179
|
+
else if (field.wireType === WIRE_BYTES) {
|
|
180
|
+
const bytes = field.bytes;
|
|
181
|
+
let offset = 0;
|
|
182
|
+
while (offset < bytes.length) {
|
|
183
|
+
const [value, next] = readVarint(bytes, offset);
|
|
184
|
+
out.push(BigInt.asIntN(64, value));
|
|
185
|
+
offset = next;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
throw new ProtobufError(`field ${number} is not a varint list`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return out;
|
|
193
|
+
}
|
|
194
|
+
/** `int64s` as JavaScript numbers; throws when one does not fit exactly. */
|
|
195
|
+
ints(number) {
|
|
196
|
+
return this.int64s(number).map((value) => safeNumber(value, number));
|
|
197
|
+
}
|
|
198
|
+
fixedList(number, size, read) {
|
|
199
|
+
const out = [];
|
|
200
|
+
const wire = size === 8 ? WIRE_FIXED64 : WIRE_FIXED32;
|
|
201
|
+
for (const field of this.fields.get(number) ?? []) {
|
|
202
|
+
const bytes = field.bytes;
|
|
203
|
+
if ((field.wireType !== wire && field.wireType !== WIRE_BYTES) || !bytes)
|
|
204
|
+
throw new ProtobufError(`field ${number} is not a list of ${size === 8 ? 'doubles' : 'floats'}`);
|
|
205
|
+
if (bytes.length % size !== 0)
|
|
206
|
+
throw new ProtobufError(`packed field ${number} is not a whole number of values`);
|
|
207
|
+
const v = view(bytes);
|
|
208
|
+
for (let at = 0; at < bytes.length; at += size)
|
|
209
|
+
out.push(read(v, at));
|
|
210
|
+
}
|
|
211
|
+
return out;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const DECODER = new TextDecoder('utf-8');
|
|
215
|
+
function view(bytes) {
|
|
216
|
+
return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
217
|
+
}
|
|
218
|
+
function expectBytes(field, number) {
|
|
219
|
+
if (field.wireType !== WIRE_BYTES)
|
|
220
|
+
throw new ProtobufError(`field ${number} is not length-delimited`);
|
|
221
|
+
return field.bytes;
|
|
222
|
+
}
|
|
223
|
+
function safeNumber(value, number) {
|
|
224
|
+
if (value > BigInt(Number.MAX_SAFE_INTEGER) || value < BigInt(Number.MIN_SAFE_INTEGER)) {
|
|
225
|
+
throw new ProtobufError(`field ${number} holds ${value}, too large for this reader`);
|
|
226
|
+
}
|
|
227
|
+
return Number(value);
|
|
228
|
+
}
|
|
229
|
+
/** Decodes a message from `bytes`. */
|
|
230
|
+
export function decodeMessage(bytes) {
|
|
231
|
+
return new ProtoMessage(bytes);
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=protobuf.js.map
|
|
@@ -0,0 +1 @@
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CAAC,EAAE,CAAC;QACvF,MAAM,IAAI,aAAa,CAAC,SAAS,MAAM,UAAU,KAAK,6BAA6B,CAAC,CAAC;IACvF,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED,sCAAsC;AACtC,MAAM,UAAU,aAAa,CAAC,KAAiB;IAC7C,OAAO,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;AACjC,CAAC"}
|
package/dist/stage.d.ts
CHANGED
|
@@ -1,15 +1,36 @@
|
|
|
1
|
+
import { type CompiledModel } from './coreml.js';
|
|
1
2
|
import { type ICUData } from './icu.js';
|
|
2
3
|
import type { ResolvedApp } from './project.js';
|
|
4
|
+
import type { Vendored } from './vendor.js';
|
|
3
5
|
export interface StagedApp {
|
|
4
6
|
/** The staging package directory (holds Package.swift, Sources/, .build/). */
|
|
5
7
|
dir: string;
|
|
6
|
-
/** Staged file → original
|
|
8
|
+
/** Staged file (or copied local package folder, with a trailing separator) → the original, for mapping compiler diagnostics back. */
|
|
7
9
|
originals: Map<string, string>;
|
|
8
10
|
/** `#Preview` blocks removed, in total. */
|
|
9
11
|
previewsStripped: number;
|
|
12
|
+
/**
|
|
13
|
+
* The `<language>.lproj` folders of string tables compiled from the app's
|
|
14
|
+
* catalogs and `.strings` files (strings.ts), published with its bundle.
|
|
15
|
+
*/
|
|
16
|
+
localizations: string[];
|
|
17
|
+
/** What compiling the string tables reported. */
|
|
18
|
+
localizationWarnings: string[];
|
|
10
19
|
}
|
|
11
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* `$SWIFTBROWSER_BUILD_ROOT`, resolved; unset by default. With it, every app is
|
|
22
|
+
* staged at `<root>/<App>/` and built with one SwiftPM scratch path,
|
|
23
|
+
* `<root>/.build`, so a run that compiles several apps compiles the
|
|
24
|
+
* SwiftBrowser package once. SwiftPM recompiles a dependency whenever the
|
|
25
|
+
* root package's parent directory changes, so apps staged in their own
|
|
26
|
+
* projects cannot share it even with a common scratch path. One build at a
|
|
27
|
+
* time per root: SwiftPM locks the scratch path.
|
|
28
|
+
*/
|
|
29
|
+
export declare function buildRoot(): string | undefined;
|
|
30
|
+
/** Where an app's staging package lives: `<project>/.swiftbrowser/<App>/`, or under the build root. */
|
|
12
31
|
export declare function stagingDir(app: ResolvedApp): string;
|
|
32
|
+
/** The `swift build` arguments that select the shared scratch path under the build root, if any. */
|
|
33
|
+
export declare function scratchPathArgs(): string[];
|
|
13
34
|
/** The built module, optimized or not. */
|
|
14
35
|
export declare function wasmOutput(app: ResolvedApp): string;
|
|
15
36
|
export interface TransformResult {
|
|
@@ -21,52 +42,155 @@ export interface TransformResult {
|
|
|
21
42
|
/**
|
|
22
43
|
* Adjusts one source for the shim without moving any line, so compiler
|
|
23
44
|
* diagnostics keep their line numbers:
|
|
24
|
-
* - `import SwiftUI` also imports
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* -
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
45
|
+
* - `import SwiftUI` also imports Foundation, FoundationBridge and Observation,
|
|
46
|
+
* as Apple's SwiftUI re-exports Foundation (and Foundation re-exports
|
|
47
|
+
* Observation, so `@Observable` works in a file that imports either alone);
|
|
48
|
+
* - `import Foundation` also imports Observation, for the same reason, and
|
|
49
|
+
* (`bridged`: in a module built against the bridge) FoundationBridge, whose
|
|
50
|
+
* `URLSession`, `UserDefaults`… the alias file names: a public default
|
|
51
|
+
* argument (`session: URLSession = .shared`) may only use a member of a
|
|
52
|
+
* module its own file imports;
|
|
53
|
+
* - `import CoreImage.CIFilterBuiltins` → `import CoreImage`, and likewise
|
|
54
|
+
* `import UIKit.UIImage`, `import os.log`, `import CoreGraphics.CGImage`:
|
|
55
|
+
* on Apple platforms those are Clang submodules; the shim's frameworks are
|
|
56
|
+
* Swift modules, which have no submodules to import;
|
|
57
|
+
* - `delegate?.urlSession?(…)` → `delegate?.urlSession(…)`: the delegate
|
|
58
|
+
* methods are `@objc optional` on Apple platforms, plain requirements with
|
|
59
|
+
* default implementations in FoundationBridge;
|
|
60
|
+
* - `ProcessInfo.processInfo.physicalMemory` → `_swiftBrowserPhysicalMemory` (the alias file's):
|
|
61
|
+
* swift-foundation answers 0 on WASI, and limits sized from it refuse everything;
|
|
62
|
+
* - `import Dispatch` → `import FoundationBridge`: the SDK has no Dispatch on
|
|
63
|
+
* WASI, and the bridge's queues run on the main actor (a package that
|
|
64
|
+
* imports it is built from a copy, vendor.ts);
|
|
65
|
+
* - `import ObjectiveC` → `import FoundationBridge`, which has the associated
|
|
66
|
+
* objects (CoreFoundation.swift), and `unsafeBitCast(Selector(…), to:
|
|
67
|
+
* UnsafeRawPointer.self)` → `Selector(…)._uniquePointer`: on Apple platforms
|
|
68
|
+
* a selector is a uniqued pointer, the usual key of an associated object;
|
|
69
|
+
* here it is a struct, which the bit cast would trap on (`selectorPointers`;
|
|
70
|
+
* a package that imports ObjectiveC is built from a copy, vendor.ts);
|
|
71
|
+
* - `import FoundationLite` → `import FoundationBridge`: FoundationLite was the
|
|
72
|
+
* lean mode's formatting layer (Phase 14 folded it into Foundation); a file
|
|
73
|
+
* that still names it gets the bridge, which holds what remains;
|
|
74
|
+
* - `configuration.delegateClass = SceneDelegate.self` records how to make
|
|
75
|
+
* the scene delegate (`sceneDelegateClasses`);
|
|
76
|
+
* - `x as? AnyObject` → `x as? _AnyObjectValue` in a file that reads a number
|
|
77
|
+
* off it (`.doubleValue`, `.intValue`…): Objective-C finds those members on
|
|
78
|
+
* any object at run time, which the browser's Swift cannot (`numberCasts`);
|
|
79
|
+
* - `@objc` protocols become class-bound, with their `optional` requirements
|
|
80
|
+
* as plain ones that have default implementations, and calls of those
|
|
81
|
+
* requirements (`delegate?.method?(…)`, in any of the module's files:
|
|
82
|
+
* `optionalRequirements`) plain calls; an `override` in an extension is
|
|
83
|
+
* blanked; `#keyPath(Type.property)` becomes `"property"` (objc.ts);
|
|
84
|
+
* - `ProcessInfo()` → `ProcessInfo.processInfo`;
|
|
33
85
|
* - `#Preview { … }` blocks (and `#Preview("name", traits: …) { … }`) become
|
|
34
86
|
* blank lines: the shim has no preview macro and previews are not part of
|
|
35
|
-
* the app.
|
|
87
|
+
* the app. So do the older `struct …: PreviewProvider { … }` declarations,
|
|
88
|
+
* which packages still carry (with preview-only modifiers inside).
|
|
36
89
|
*/
|
|
37
|
-
export declare function transformSource(text: string, options
|
|
38
|
-
|
|
90
|
+
export declare function transformSource(text: string, options?: {
|
|
91
|
+
bridged?: boolean;
|
|
92
|
+
optionalRequirements?: ReadonlySet<string>;
|
|
39
93
|
}): TransformResult;
|
|
40
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
* `configuration.delegateClass = SceneDelegate.self` →
|
|
96
|
+
* `configuration._setDelegateClass(SceneDelegate.self) { SceneDelegate() }`:
|
|
97
|
+
* UIKit makes the scene delegate through the Objective-C runtime, and Swift
|
|
98
|
+
* without it can only make an instance from a metatype through a `required`
|
|
99
|
+
* initializer (UIKit/SceneDelegates.swift). Same line, so diagnostics keep
|
|
100
|
+
* their places.
|
|
101
|
+
*/
|
|
102
|
+
export declare function sceneDelegateClasses(text: string): string;
|
|
103
|
+
/**
|
|
104
|
+
* `as? AnyObject` → `as? _AnyObjectValue` where the file reads a number from
|
|
105
|
+
* the result: `(dict[key] as? AnyObject)?.doubleValue` looks the member up on
|
|
106
|
+
* any object through Objective-C (nil where there is none); FoundationBridge's
|
|
107
|
+
* `_AnyObjectValue` (Selector.swift) has those members, optional likewise, on
|
|
108
|
+
* the numbers, booleans and strings a dictionary of `Any` holds.
|
|
109
|
+
*/
|
|
110
|
+
export declare function numberCasts(text: string): string;
|
|
111
|
+
/** Whether a source uses the Objective-C runtime's selectors or attributes. */
|
|
112
|
+
export declare function usesObjC(text: string): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Whether a source calls POSIX mutex functions. WASI's libc module leaves
|
|
115
|
+
* `pthread.h` out, so a package that does is built from a copy: there
|
|
116
|
+
* `#if os(iOS)` holds (Darwin's `os_unfair_lock` branch) and FoundationBridge
|
|
117
|
+
* declares the mutex functions for the page's single thread (Locks.swift).
|
|
118
|
+
*/
|
|
119
|
+
/**
|
|
120
|
+
* `unsafeBitCast(Selector(#function), to: UnsafeRawPointer.self)` →
|
|
121
|
+
* `Selector(#function)._uniquePointer`: the address that stands for the
|
|
122
|
+
* selector's name (FoundationBridge/Selector.swift), which on Apple
|
|
123
|
+
* platforms the bit cast gives, the selector being a uniqued pointer.
|
|
124
|
+
*/
|
|
125
|
+
export declare function selectorPointers(text: string): string;
|
|
126
|
+
/** Whether a source imports ObjectiveC, which the SDK does not have on WASI (transformSource). */
|
|
127
|
+
export declare function importsObjectiveC(text: string): boolean;
|
|
128
|
+
/** Whether a source imports Dispatch, which the SDK does not have on WASI (transformSource). */
|
|
129
|
+
export declare function importsDispatch(text: string): boolean;
|
|
130
|
+
export declare function usesPosixMutex(text: string): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Objective-C without its runtime (FoundationBridge/Selector.swift). The
|
|
133
|
+
* browser's Swift has no Objective-C interop, so `@objc` (and the Interface
|
|
134
|
+
* Builder attributes that imply it) is dropped, and `#selector(handle(_:))`
|
|
135
|
+
* becomes `Selector(Self.handle(_:), name: "handle(_:)")`: the method itself,
|
|
136
|
+
* which the target/selector APIs call on their target. A qualified method
|
|
137
|
+
* (`Type.method`) is used as it is; one of another object
|
|
138
|
+
* (`#selector(model.refresh)`) is called bound; `getter:`/`setter:`
|
|
139
|
+
* selectors only have a name. A method the file declares `@MainActor` is
|
|
140
|
+
* bound to its target in a closure instead,
|
|
141
|
+
* `Selector(name: "tick", isolated: { (target: Self) in target.tick })`:
|
|
142
|
+
* Swift 6 rejects naming a main-actor method of a class that is not
|
|
143
|
+
* `Sendable` unapplied (Gifu's display link proxy).
|
|
144
|
+
*/
|
|
145
|
+
export declare function rewriteObjC(text: string): string;
|
|
146
|
+
/** Replaces every `#Preview …{ … }` block and `PreviewProvider` struct with blank lines of the same count. */
|
|
41
147
|
export declare function stripPreviews(text: string): {
|
|
42
148
|
text: string;
|
|
43
149
|
count: number;
|
|
44
150
|
};
|
|
45
151
|
/** Index of the `}` closing the `{` at `open`, skipping strings and comments; -1 when unbalanced. */
|
|
46
152
|
export declare function matchingBrace(text: string, open: number): number;
|
|
153
|
+
/** What the app's sources use beyond the shim, which decides what the staging links. */
|
|
154
|
+
export interface StageFeatures {
|
|
155
|
+
/**
|
|
156
|
+
* Some file imports SwiftData: the app links the SwiftData product (and so
|
|
157
|
+
* builds its macros, against swift-syntax), and the generated file routes
|
|
158
|
+
* `#Predicate` to SwiftData's copy of the macro.
|
|
159
|
+
*/
|
|
160
|
+
swiftData: boolean;
|
|
161
|
+
/** The stand-in frameworks (StoreKit, CoreLocation, LocalAuthentication, CoreML, PhotosUI, CoreImage, UserNotifications, …) some file imports; each is linked. */
|
|
162
|
+
frameworks: readonly string[];
|
|
163
|
+
}
|
|
164
|
+
/** The features `sources` (their text) call for. */
|
|
165
|
+
export declare function featuresOf(sources: readonly string[]): StageFeatures;
|
|
47
166
|
/** The Package.swift of the staging package. */
|
|
48
|
-
export declare function packageManifest(app: ResolvedApp, swiftPackagePath: string): string;
|
|
167
|
+
export declare function packageManifest(app: ResolvedApp, swiftPackagePath: string, features?: StageFeatures, vendored?: Vendored): string;
|
|
168
|
+
/** Where the compiled string tables go in the staging directory (`<language>.lproj` folders). */
|
|
169
|
+
export declare const LOCALIZATION_DIR = "Localization";
|
|
49
170
|
/** The staged file that settles names declared by both the shim and Foundation. */
|
|
50
171
|
export declare const FULL_FOUNDATION_FILE = "_SwiftBrowserFoundation.swift";
|
|
51
172
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* its `Timer` needs CFRunLoop and does not link).
|
|
173
|
+
* The app imports both the shim and Foundation, and both declare a few names
|
|
174
|
+
* (a module does not shadow another's declarations, only the current module's
|
|
175
|
+
* do). A typealias in the app module does: these point the shared names at
|
|
176
|
+
* the shim's types (what its `frame(width:)` and friends take) and at
|
|
177
|
+
* FoundationBridge's `Timer` and `RunLoop`, which Foundation lacks on WASI
|
|
178
|
+
* (`RunLoop` is marked unavailable, its `Timer` needs CFRunLoop and does not
|
|
179
|
+
* link).
|
|
60
180
|
*/
|
|
61
|
-
export declare function fullFoundationSource(): string;
|
|
181
|
+
export declare function fullFoundationSource(features?: StageFeatures, declared?: ReadonlySet<string>): string;
|
|
182
|
+
/** The type names a module's sources declare at the top level (lines that start with the declaration). */
|
|
183
|
+
export declare function declaredTypeNames(sources: readonly string[]): Set<string>;
|
|
62
184
|
/** The directory the staged sources keep their layout relative to. */
|
|
63
185
|
export declare function commonSourceBase(app: ResolvedApp): string;
|
|
64
186
|
export interface StageOptions {
|
|
65
187
|
/**
|
|
66
|
-
* The trimmed ICU data for a
|
|
67
|
-
*
|
|
188
|
+
* The trimmed ICU data for a wasm build (`prepareICUData`); without it the
|
|
189
|
+
* staging builds on the host only.
|
|
68
190
|
*/
|
|
69
191
|
icu?: ICUData | null;
|
|
192
|
+
/** The packages copied and adjusted for the shim (`vendorPackages`), by identity. */
|
|
193
|
+
vendored?: Vendored;
|
|
70
194
|
}
|
|
71
195
|
/**
|
|
72
196
|
* Writes (or refreshes) the staging package. Files are written only when
|
|
@@ -74,5 +198,9 @@ export interface StageOptions {
|
|
|
74
198
|
* staged files whose source is gone are removed.
|
|
75
199
|
*/
|
|
76
200
|
export declare function stage(app: ResolvedApp, swiftPackagePath: string, options?: StageOptions): StagedApp;
|
|
201
|
+
/** The staged file of a model's generated class: `<Class>.mlmodel.swift`, a name no app source has. */
|
|
202
|
+
export declare function modelSourceName(model: CompiledModel): string;
|
|
203
|
+
/** Compiles each Core ML model of the app (coreml.ts); two models may not make the same class. */
|
|
204
|
+
export declare function compileModels(files: readonly string[]): CompiledModel[];
|
|
77
205
|
/** Rewrites staged paths in compiler output back to the user's files. */
|
|
78
206
|
export declare function remapDiagnostics(output: string, staged: StagedApp): string;
|