@skathi-native/cli 0.0.0 → 0.1.0-beta.2
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/aot-inputs.ts +294 -0
- package/ascii.ts +397 -0
- package/build.ts +1236 -0
- package/check/builtins.json +1219 -0
- package/check/builtins.ts +112 -0
- package/check/codes.ts +178 -0
- package/check/command.ts +105 -0
- package/check/config.ts +76 -0
- package/check/finding.ts +30 -0
- package/check/graph.ts +69 -0
- package/check/highlight.ts +40 -0
- package/check/index.ts +308 -0
- package/check/packages.ts +54 -0
- package/check/program.ts +209 -0
- package/check/report.ts +219 -0
- package/check/rules.ts +307 -0
- package/check/schema.ts +69 -0
- package/check/typing.ts +703 -0
- package/cli/assets.ts +114 -0
- package/cli/build-app.ts +587 -0
- package/cli/config.ts +646 -0
- package/cli/create.ts +327 -0
- package/cli/dev.ts +92 -0
- package/cli/elf.ts +142 -0
- package/cli/help.ts +160 -0
- package/cli/host-fetch.ts +178 -0
- package/cli/host.ts +378 -0
- package/cli/icon.ts +303 -0
- package/cli/macos-bundle.ts +451 -0
- package/cli/pe.ts +429 -0
- package/cli/platform.ts +74 -0
- package/cli/sk.ts +290 -0
- package/cli/skpk.ts +268 -0
- package/cli/stamp.ts +254 -0
- package/cli/term.ts +176 -0
- package/cli/versioninfo.ts +123 -0
- package/css-prefixes.ts +118 -0
- package/devtools/apps.ts +68 -0
- package/devtools/commands.ts +860 -0
- package/devtools/ctl.ts +166 -0
- package/package.json +52 -3
- package/prod.ts +701 -0
- package/runtime-path.ts +24 -0
- package/tailwind.ts +76 -0
- package/templates/minimal/assets/hello.txt +1 -0
- package/templates/minimal/src/App.vue +142 -0
- package/templates/minimal/src/main.ts +4 -0
- package/templates/showcase/assets/hello.txt +1 -0
- package/templates/showcase/assets/media/aurora.png +0 -0
- package/templates/showcase/assets/media/clip.mp4 +0 -0
- package/templates/showcase/assets/media/sticker.tgs +0 -0
- package/templates/showcase/src/App.vue +128 -0
- package/templates/showcase/src/components/Card.vue +41 -0
- package/templates/showcase/src/components/Icon.vue +29 -0
- package/templates/showcase/src/components/Missing.vue +26 -0
- package/templates/showcase/src/components/Page.vue +41 -0
- package/templates/showcase/src/components/Titlebar.vue +128 -0
- package/templates/showcase/src/engine.ts +33 -0
- package/templates/showcase/src/icons.ts +22 -0
- package/templates/showcase/src/main.ts +7 -0
- package/templates/showcase/src/pages/AudioPage.vue +124 -0
- package/templates/showcase/src/pages/FilesPage.vue +91 -0
- package/templates/showcase/src/pages/FormsPage.vue +139 -0
- package/templates/showcase/src/pages/GraphicsPage.vue +156 -0
- package/templates/showcase/src/pages/HomePage.vue +141 -0
- package/templates/showcase/src/pages/LocalePage.vue +71 -0
- package/templates/showcase/src/pages/MediaPage.vue +85 -0
- package/templates/showcase/src/pages/MotionPage.vue +199 -0
- package/templates/showcase/src/pages/NetworkPage.vue +103 -0
- package/templates/showcase/src/pages/PermissionsPage.vue +80 -0
- package/templates/showcase/src/pages/StoragePage.vue +117 -0
- package/templates/showcase/src/pages/StylesPage.vue +199 -0
- package/templates/showcase/src/pages/SystemPage.vue +89 -0
- package/templates/showcase/src/pages/TrayPage.vue +66 -0
- package/templates/showcase/src/pages/WindowPage.vue +128 -0
- package/templates/showcase/src/product.ts +2 -0
- package/templates/showcase/src/router.ts +149 -0
- package/templates/showcase/src/stores/counter.ts +9 -0
- package/templates/showcase/src/stores/desktop.ts +115 -0
- package/templates/showcase/src/styles.css +140 -0
- package/vitecompat.ts +1151 -0
package/cli/stamp.ts
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
// Stamping: a copy of a host exe becomes ONE app's exe. Copy host -> <out>.partial, strip any
|
|
2
|
+
// certificate table (the author signs the stamped exe later), write icons, VERSIONINFO and the
|
|
3
|
+
// SKPAYLOAD resource (pass 1 with skew 0, pass 2 with the skew that page-aligns the SKPK data
|
|
4
|
+
// region in the mapped image), set the subsystem to GUI unless asked to keep the console, verify
|
|
5
|
+
// by mapping it as an image resource, rename over <out>. The file is freshly written, which is
|
|
6
|
+
// when Windows Defender likes to scan it, so the resource transactions and the rename retry on a
|
|
7
|
+
// sharing violation.
|
|
8
|
+
|
|
9
|
+
import { copyFileSync, existsSync, renameSync, rmSync, statSync, truncateSync } from "node:fs";
|
|
10
|
+
import { groupIcon, type IconImage } from "./icon";
|
|
11
|
+
import {
|
|
12
|
+
ERROR_LOCK_VIOLATION,
|
|
13
|
+
ERROR_SHARING_VIOLATION,
|
|
14
|
+
loadResourceCopy,
|
|
15
|
+
patchFile,
|
|
16
|
+
readFileRange,
|
|
17
|
+
readPe,
|
|
18
|
+
ResourceUpdate,
|
|
19
|
+
RT,
|
|
20
|
+
setSubsystem,
|
|
21
|
+
shellIconCount,
|
|
22
|
+
SUBSYSTEM,
|
|
23
|
+
Win32Error,
|
|
24
|
+
type PeInfo,
|
|
25
|
+
type ResourceEntry,
|
|
26
|
+
} from "./pe";
|
|
27
|
+
import { HEADER_SIZE, PAGE, readHeader, skewFor } from "./skpk";
|
|
28
|
+
|
|
29
|
+
export const PAYLOAD_NAME = "SKPAYLOAD";
|
|
30
|
+
export const RES_LANG = 0x0409;
|
|
31
|
+
export const PAYLOAD_LANG = 0;
|
|
32
|
+
|
|
33
|
+
export interface StampOptions {
|
|
34
|
+
host: string;
|
|
35
|
+
out: string;
|
|
36
|
+
payload: (skew: number) => Uint8Array;
|
|
37
|
+
icons?: IconImage[] | undefined;
|
|
38
|
+
versionInfo?: Uint8Array;
|
|
39
|
+
subsystem?: "gui" | "console" | "keep";
|
|
40
|
+
log?: (line: string) => void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface StampResult {
|
|
44
|
+
out: string;
|
|
45
|
+
bytes: number;
|
|
46
|
+
payloadBytes: number;
|
|
47
|
+
payloadRva: number;
|
|
48
|
+
skew: number;
|
|
49
|
+
dataAligned: boolean;
|
|
50
|
+
passes: number;
|
|
51
|
+
strippedSignature: boolean;
|
|
52
|
+
subsystem: number;
|
|
53
|
+
iconCount: number | null;
|
|
54
|
+
ms: { copy: number; resources: number; verify: number; total: number };
|
|
55
|
+
payload: Uint8Array;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const sleep = (ms: number) => Bun.sleepSync(ms);
|
|
59
|
+
|
|
60
|
+
function isSharing(e: unknown): boolean {
|
|
61
|
+
if (e instanceof Win32Error) return e.code === ERROR_SHARING_VIOLATION || e.code === ERROR_LOCK_VIOLATION;
|
|
62
|
+
const code = (e as NodeJS.ErrnoException)?.code;
|
|
63
|
+
return code === "EBUSY" || code === "EPERM" || code === "EACCES";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function retrying<T>(what: string, f: () => T, log: (l: string) => void, attempts = 8): T {
|
|
67
|
+
let delay = 100;
|
|
68
|
+
for (let i = 1; ; i++) {
|
|
69
|
+
try {
|
|
70
|
+
return f();
|
|
71
|
+
} catch (e) {
|
|
72
|
+
if (!isSharing(e) || i >= attempts) throw e;
|
|
73
|
+
log(`${what}: the file is busy (${(e as Error).message}) — retrying in ${delay} ms`);
|
|
74
|
+
sleep(delay);
|
|
75
|
+
delay = Math.min(delay * 2, 2000);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function payloadEntry(pe: PeInfo): ResourceEntry | undefined {
|
|
81
|
+
return pe.resources.find((r) => r.type === RT.RCDATA && r.name === PAYLOAD_NAME);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Removes an Authenticode certificate table (truncate when it is the file's tail, zero the SECURITY entry either way). Returns whether there was one. */
|
|
85
|
+
export function stripSignature(path: string): boolean {
|
|
86
|
+
const pe = readPe(path);
|
|
87
|
+
if (!pe.security.size) return false;
|
|
88
|
+
const size = statSync(path).size;
|
|
89
|
+
if (pe.security.offset > 0 && pe.security.offset + pe.security.size >= size - 8) {
|
|
90
|
+
truncateSync(path, pe.security.offset);
|
|
91
|
+
}
|
|
92
|
+
patchFile(path, pe.securityEntryOffset, new Uint8Array(8));
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function stamp(options: StampOptions): StampResult {
|
|
97
|
+
const log = options.log ?? (() => {});
|
|
98
|
+
const t0 = performance.now();
|
|
99
|
+
const partial = `${options.out}.partial`;
|
|
100
|
+
rmSync(partial, { force: true });
|
|
101
|
+
retrying("copying the host", () => copyFileSync(options.host, partial), log);
|
|
102
|
+
const tCopy = performance.now();
|
|
103
|
+
|
|
104
|
+
let strippedSignature = false;
|
|
105
|
+
let result: StampResult | null = null;
|
|
106
|
+
try {
|
|
107
|
+
strippedSignature = stripSignature(partial);
|
|
108
|
+
if (strippedSignature) log("removed the host's certificate table — sign the stamped exe instead");
|
|
109
|
+
|
|
110
|
+
const before = readPe(partial);
|
|
111
|
+
let skew = 0;
|
|
112
|
+
let blob = options.payload(skew);
|
|
113
|
+
let passes = 1;
|
|
114
|
+
|
|
115
|
+
retrying(
|
|
116
|
+
"stamping resources",
|
|
117
|
+
() => {
|
|
118
|
+
const u = new ResourceUpdate(partial);
|
|
119
|
+
try {
|
|
120
|
+
for (const r of before.resources) {
|
|
121
|
+
const lang = r.lang;
|
|
122
|
+
if (r.type === RT.RCDATA && r.name === PAYLOAD_NAME) u.remove(r.type, r.name, lang);
|
|
123
|
+
if (options.icons && (r.type === RT.ICON || r.type === RT.GROUP_ICON)) u.remove(r.type, r.name, lang);
|
|
124
|
+
if (options.versionInfo && r.type === RT.VERSION) u.remove(r.type, r.name, lang);
|
|
125
|
+
}
|
|
126
|
+
if (options.icons?.length) {
|
|
127
|
+
const { icons, group } = groupIcon(options.icons, 1);
|
|
128
|
+
for (const icon of icons) u.set(RT.ICON, icon.id, RES_LANG, icon.data);
|
|
129
|
+
u.set(RT.GROUP_ICON, 1, RES_LANG, group);
|
|
130
|
+
}
|
|
131
|
+
if (options.versionInfo) u.set(RT.VERSION, 1, RES_LANG, options.versionInfo);
|
|
132
|
+
u.set(RT.RCDATA, PAYLOAD_NAME, PAYLOAD_LANG, blob);
|
|
133
|
+
u.commit();
|
|
134
|
+
} catch (e) {
|
|
135
|
+
u.discard();
|
|
136
|
+
throw e;
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
log,
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
// Passes 2..3: the skew. The RVA is decided by what sorts ahead of RT_RCDATA (the RT_ICONs).
|
|
143
|
+
let pe = readPe(partial);
|
|
144
|
+
let entry = payloadEntry(pe);
|
|
145
|
+
if (!entry) throw new Error(`${partial}: the payload resource is missing after EndUpdateResourceW`);
|
|
146
|
+
const header0 = readHeader(blob);
|
|
147
|
+
for (;;) {
|
|
148
|
+
const want = skewFor(entry.rva, header0);
|
|
149
|
+
const dataOff = header0.namesOff + header0.namesLen + skew;
|
|
150
|
+
if ((entry.rva + dataOff) % PAGE === 0 || passes >= 3) break;
|
|
151
|
+
skew = want;
|
|
152
|
+
blob = options.payload(skew);
|
|
153
|
+
passes++;
|
|
154
|
+
retrying(
|
|
155
|
+
"re-stamping the payload",
|
|
156
|
+
() => {
|
|
157
|
+
const u = new ResourceUpdate(partial);
|
|
158
|
+
try {
|
|
159
|
+
u.set(RT.RCDATA, PAYLOAD_NAME, PAYLOAD_LANG, blob);
|
|
160
|
+
u.commit();
|
|
161
|
+
} catch (e) {
|
|
162
|
+
u.discard();
|
|
163
|
+
throw e;
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
log,
|
|
167
|
+
);
|
|
168
|
+
pe = readPe(partial);
|
|
169
|
+
entry = payloadEntry(pe);
|
|
170
|
+
if (!entry) throw new Error(`${partial}: the payload resource vanished in pass ${passes}`);
|
|
171
|
+
}
|
|
172
|
+
const header = readHeader(blob);
|
|
173
|
+
const dataAligned = (entry.rva + header.dataOff) % PAGE === 0;
|
|
174
|
+
if (!dataAligned) {
|
|
175
|
+
log(
|
|
176
|
+
`warning: the payload's data region did not land on a page boundary (rva 0x${entry.rva.toString(16)}, ` +
|
|
177
|
+
`data_off ${header.dataOff}) — the app runs exactly the same; only a future bytecode cache cares`,
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (options.subsystem !== "keep") {
|
|
182
|
+
setSubsystem(partial, options.subsystem === "console" ? SUBSYSTEM.CONSOLE : SUBSYSTEM.GUI);
|
|
183
|
+
}
|
|
184
|
+
const tRes = performance.now();
|
|
185
|
+
|
|
186
|
+
// Verify the way the host reads it, so a file Windows will not map fails here, not on a user's machine.
|
|
187
|
+
pe = readPe(partial);
|
|
188
|
+
entry = payloadEntry(pe);
|
|
189
|
+
if (!entry || entry.size !== blob.length) {
|
|
190
|
+
throw new Error(`verify: the stamped payload is ${entry?.size ?? "missing"} bytes, expected ${blob.length}`);
|
|
191
|
+
}
|
|
192
|
+
const mapped = loadResourceCopy(partial, RT.RCDATA, PAYLOAD_NAME, HEADER_SIZE);
|
|
193
|
+
if (!mapped || !bytesEqual(mapped, blob.subarray(0, HEADER_SIZE))) {
|
|
194
|
+
throw new Error("verify: FindResourceW on the stamped image did not return the payload that was written");
|
|
195
|
+
}
|
|
196
|
+
const onDisk = readFileRange(partial, entry.fileOffset, Math.min(blob.length, 4096));
|
|
197
|
+
if (!bytesEqual(onDisk, blob.subarray(0, onDisk.length))) {
|
|
198
|
+
throw new Error("verify: the payload bytes in the file differ from the blob that was written");
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
retrying(
|
|
202
|
+
`replacing ${options.out}`,
|
|
203
|
+
() => {
|
|
204
|
+
if (existsSync(options.out)) {
|
|
205
|
+
try {
|
|
206
|
+
rmSync(options.out);
|
|
207
|
+
} catch (e) {
|
|
208
|
+
const err = new Error(
|
|
209
|
+
`${options.out} cannot be replaced — is it running? Close it and build again. (${(e as Error).message})`,
|
|
210
|
+
);
|
|
211
|
+
(err as { code?: string | undefined }).code = (e as NodeJS.ErrnoException).code;
|
|
212
|
+
throw err;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
renameSync(partial, options.out);
|
|
216
|
+
},
|
|
217
|
+
log,
|
|
218
|
+
6,
|
|
219
|
+
);
|
|
220
|
+
const iconCount = options.icons?.length ? shellIconCount(options.out) : null;
|
|
221
|
+
if (options.icons?.length && !iconCount) {
|
|
222
|
+
throw new Error(`verify: the shell sees no icon in ${options.out} (ExtractIconExW returned 0)`);
|
|
223
|
+
}
|
|
224
|
+
const tVerify = performance.now();
|
|
225
|
+
result = {
|
|
226
|
+
out: options.out,
|
|
227
|
+
bytes: statSync(options.out).size,
|
|
228
|
+
payloadBytes: blob.length,
|
|
229
|
+
payloadRva: entry.rva,
|
|
230
|
+
skew,
|
|
231
|
+
dataAligned,
|
|
232
|
+
passes,
|
|
233
|
+
strippedSignature,
|
|
234
|
+
subsystem: pe.subsystem,
|
|
235
|
+
iconCount,
|
|
236
|
+
ms: {
|
|
237
|
+
copy: Math.round(tCopy - t0),
|
|
238
|
+
resources: Math.round(tRes - tCopy),
|
|
239
|
+
verify: Math.round(tVerify - tRes),
|
|
240
|
+
total: Math.round(tVerify - t0),
|
|
241
|
+
},
|
|
242
|
+
payload: blob,
|
|
243
|
+
};
|
|
244
|
+
return result;
|
|
245
|
+
} finally {
|
|
246
|
+
if (!result) rmSync(partial, { force: true });
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function bytesEqual(a: Uint8Array, b: Uint8Array): boolean {
|
|
251
|
+
if (a.length !== b.length) return false;
|
|
252
|
+
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
253
|
+
return true;
|
|
254
|
+
}
|
package/cli/term.ts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
export interface Paint {
|
|
2
|
+
red: (text: string) => string;
|
|
3
|
+
green: (text: string) => string;
|
|
4
|
+
yellow: (text: string) => string;
|
|
5
|
+
blue: (text: string) => string;
|
|
6
|
+
magenta: (text: string) => string;
|
|
7
|
+
cyan: (text: string) => string;
|
|
8
|
+
bold: (text: string) => string;
|
|
9
|
+
dim: (text: string) => string;
|
|
10
|
+
on: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** FORCE_COLOR and NO_COLOR win over the terminal check; an explicit flag wins over both. */
|
|
14
|
+
export function colorEnabled(stream: { isTTY?: boolean }, flag?: boolean): boolean {
|
|
15
|
+
if (flag !== undefined) return flag;
|
|
16
|
+
const force = process.env.FORCE_COLOR;
|
|
17
|
+
if (force !== undefined) return force !== "0" && force !== "false";
|
|
18
|
+
if (process.env.NO_COLOR) return false;
|
|
19
|
+
return stream.isTTY === true && process.env.TERM !== "dumb";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** `--color` / `--no-color`; undefined when neither is given. */
|
|
23
|
+
export const colorFlag = (flags: { color?: unknown; "no-color"?: unknown }) =>
|
|
24
|
+
flags["no-color"] === true ? false : flags.color === true ? true : undefined;
|
|
25
|
+
|
|
26
|
+
export function paint(on: boolean): Paint {
|
|
27
|
+
const sgr = (open: string) => (text: string) => (on && text ? `\x1b[${open}m${text}\x1b[0m` : text);
|
|
28
|
+
return {
|
|
29
|
+
red: sgr("1;31"),
|
|
30
|
+
green: sgr("32"),
|
|
31
|
+
yellow: sgr("1;33"),
|
|
32
|
+
blue: sgr("1;34"),
|
|
33
|
+
magenta: sgr("35"),
|
|
34
|
+
cyan: sgr("36"),
|
|
35
|
+
bold: sgr("1"),
|
|
36
|
+
dim: sgr("2"),
|
|
37
|
+
on,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const seconds = (ms: number) => (ms < 1000 ? `${Math.round(ms)}ms` : `${(ms / 1000).toFixed(1)}s`);
|
|
42
|
+
|
|
43
|
+
export interface Progress {
|
|
44
|
+
/** Starts a phase (ending the previous one); `total` shows a counter that `tick` advances. */
|
|
45
|
+
step(label: string, total?: number): void;
|
|
46
|
+
tick(): void;
|
|
47
|
+
/** What the finished phase line says after its label. */
|
|
48
|
+
detail(text: string): void;
|
|
49
|
+
/** A line printed above the spinner. */
|
|
50
|
+
info(text: string): void;
|
|
51
|
+
warn(text: string): void;
|
|
52
|
+
end(): void;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const quietProgress: Progress = { step() {}, tick() {}, detail() {}, info() {}, warn() {}, end() {} };
|
|
56
|
+
|
|
57
|
+
/** Progress as plain lines (CI logs, pipes): each finished phase is one line. */
|
|
58
|
+
export function lineProgress(write: (line: string) => void, color: boolean): Progress {
|
|
59
|
+
const p = paint(color);
|
|
60
|
+
let label: string | null = null;
|
|
61
|
+
let note = "";
|
|
62
|
+
let began = 0;
|
|
63
|
+
const finish = () => {
|
|
64
|
+
if (label === null) return;
|
|
65
|
+
write(`${p.green("✓")} ${label}${note ? ` ${p.dim(note)}` : ""} ${p.dim(seconds(performance.now() - began))}`);
|
|
66
|
+
label = null;
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
step(next) {
|
|
70
|
+
finish();
|
|
71
|
+
label = next;
|
|
72
|
+
note = "";
|
|
73
|
+
began = performance.now();
|
|
74
|
+
},
|
|
75
|
+
tick() {},
|
|
76
|
+
detail(text) {
|
|
77
|
+
note = text;
|
|
78
|
+
},
|
|
79
|
+
info(text) {
|
|
80
|
+
write(` ${text}`);
|
|
81
|
+
},
|
|
82
|
+
warn(text) {
|
|
83
|
+
write(`${p.yellow("warning")}: ${text}`);
|
|
84
|
+
},
|
|
85
|
+
end: finish,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The spinner on a terminal, plain lines otherwise. */
|
|
90
|
+
export function progressFor(stream: NodeJS.WriteStream, color = colorEnabled(stream)): Progress {
|
|
91
|
+
return stream.isTTY ? spinner(stream, color) : lineProgress((line) => stream.write(`${line}\n`), color);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** A `log(line)` callback onto a progress: "warning: …" lines become warnings. */
|
|
95
|
+
export function logTo(progress: Progress): (line: string) => void {
|
|
96
|
+
return (line) => {
|
|
97
|
+
const text = line.replace(/^\[sk\] /, "");
|
|
98
|
+
if (text.startsWith("warning: ")) progress.warn(text.slice("warning: ".length));
|
|
99
|
+
else progress.info(text);
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
104
|
+
|
|
105
|
+
/** A one-line spinner on a terminal stream; phases leave a ✓ line with their time. */
|
|
106
|
+
export function spinner(stream: NodeJS.WriteStream, color: boolean): Progress {
|
|
107
|
+
const p = paint(color);
|
|
108
|
+
let label: string | null = null;
|
|
109
|
+
let note = "";
|
|
110
|
+
let total = 0;
|
|
111
|
+
let done = 0;
|
|
112
|
+
let frame = 0;
|
|
113
|
+
let began = 0;
|
|
114
|
+
let drawn = 0;
|
|
115
|
+
const clear = () => stream.write("\r\x1b[2K");
|
|
116
|
+
const draw = () => {
|
|
117
|
+
if (label === null) return;
|
|
118
|
+
drawn = performance.now();
|
|
119
|
+
frame = (frame + 1) % FRAMES.length;
|
|
120
|
+
const count = total ? ` ${done}/${total}` : "";
|
|
121
|
+
clear();
|
|
122
|
+
stream.write(`${p.cyan(FRAMES[frame]!)} ${label}${p.dim(count)} ${p.dim(seconds(drawn - began))}`);
|
|
123
|
+
};
|
|
124
|
+
const finish = () => {
|
|
125
|
+
if (label === null) return;
|
|
126
|
+
clear();
|
|
127
|
+
const what = note ? ` ${p.dim(note)}` : "";
|
|
128
|
+
stream.write(`${p.green("✓")} ${label}${what} ${p.dim(seconds(performance.now() - began))}\n`);
|
|
129
|
+
label = null;
|
|
130
|
+
};
|
|
131
|
+
const restore = () => stream.write("\x1b[?25h");
|
|
132
|
+
const interrupt = () => {
|
|
133
|
+
clear();
|
|
134
|
+
restore();
|
|
135
|
+
process.exit(130);
|
|
136
|
+
};
|
|
137
|
+
stream.write("\x1b[?25l");
|
|
138
|
+
process.once("exit", restore);
|
|
139
|
+
process.once("SIGINT", interrupt);
|
|
140
|
+
const timer = setInterval(draw, 80);
|
|
141
|
+
return {
|
|
142
|
+
step(next, count = 0) {
|
|
143
|
+
finish();
|
|
144
|
+
label = next;
|
|
145
|
+
note = "";
|
|
146
|
+
total = count;
|
|
147
|
+
done = 0;
|
|
148
|
+
began = performance.now();
|
|
149
|
+
draw();
|
|
150
|
+
},
|
|
151
|
+
tick() {
|
|
152
|
+
done++;
|
|
153
|
+
if (performance.now() - drawn > 50) draw();
|
|
154
|
+
},
|
|
155
|
+
detail(text) {
|
|
156
|
+
note = text;
|
|
157
|
+
},
|
|
158
|
+
info(text) {
|
|
159
|
+
clear();
|
|
160
|
+
stream.write(` ${text}\n`);
|
|
161
|
+
draw();
|
|
162
|
+
},
|
|
163
|
+
warn(text) {
|
|
164
|
+
clear();
|
|
165
|
+
stream.write(`${p.yellow("warning")}: ${text}\n`);
|
|
166
|
+
draw();
|
|
167
|
+
},
|
|
168
|
+
end() {
|
|
169
|
+
finish();
|
|
170
|
+
clearInterval(timer);
|
|
171
|
+
restore();
|
|
172
|
+
process.off("exit", restore);
|
|
173
|
+
process.off("SIGINT", interrupt);
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// `VS_VERSIONINFO`: what Explorer's Details tab, Task Manager and SmartScreen read out of an exe.
|
|
2
|
+
// A tree of length-prefixed nodes: WORD wLength; WORD wValueLength; WORD wType; WCHAR szKey[]; pad to 4;
|
|
3
|
+
// Value; pad to 4; Children. `wValueLength` counts BYTES for a binary value, WORDS for a text one.
|
|
4
|
+
|
|
5
|
+
export interface VersionStrings {
|
|
6
|
+
FileDescription: string;
|
|
7
|
+
ProductName: string;
|
|
8
|
+
ProductVersion: string;
|
|
9
|
+
FileVersion: string;
|
|
10
|
+
InternalName: string;
|
|
11
|
+
OriginalFilename: string;
|
|
12
|
+
CompanyName?: string | undefined;
|
|
13
|
+
LegalCopyright?: string | undefined;
|
|
14
|
+
Comments?: string | undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface VersionInfoInput {
|
|
18
|
+
fileVersion: [number, number, number, number];
|
|
19
|
+
productVersion?: [number, number, number, number];
|
|
20
|
+
strings: VersionStrings;
|
|
21
|
+
lang?: number;
|
|
22
|
+
codepage?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const utf16 = (s: string) => new Uint8Array(Buffer.from(s + "\0", "utf16le"));
|
|
26
|
+
|
|
27
|
+
function concat(parts: Uint8Array[]): Uint8Array {
|
|
28
|
+
const n = parts.reduce((a, p) => a + p.length, 0);
|
|
29
|
+
const out = new Uint8Array(n);
|
|
30
|
+
let o = 0;
|
|
31
|
+
for (const p of parts) {
|
|
32
|
+
out.set(p, o);
|
|
33
|
+
o += p.length;
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const pad4 = (b: Uint8Array) => (b.length % 4 ? concat([b, new Uint8Array(4 - (b.length % 4))]) : b);
|
|
39
|
+
|
|
40
|
+
function node(
|
|
41
|
+
key: string,
|
|
42
|
+
type: 0 | 1,
|
|
43
|
+
value: Uint8Array | null,
|
|
44
|
+
valueLen: number,
|
|
45
|
+
children: Uint8Array[],
|
|
46
|
+
): Uint8Array {
|
|
47
|
+
let body = pad4(concat([new Uint8Array(6), utf16(key)]));
|
|
48
|
+
if (value) body = pad4(concat([body, value]));
|
|
49
|
+
for (const c of children) body = pad4(concat([body, c]));
|
|
50
|
+
const dv = new DataView(body.buffer, body.byteOffset, body.byteLength);
|
|
51
|
+
if (body.length > 0xffff) throw new Error(`VERSIONINFO node ${key} is ${body.length} bytes (> 64 KiB)`);
|
|
52
|
+
dv.setUint16(0, body.length, true);
|
|
53
|
+
dv.setUint16(2, value ? valueLen : 0, true);
|
|
54
|
+
dv.setUint16(4, type, true);
|
|
55
|
+
return body;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function numericVersion(v: string): [number, number, number, number] {
|
|
59
|
+
const m = /^\s*v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?(?:[-+].*)?\s*$/.exec(v);
|
|
60
|
+
if (!m) throw new Error(`${JSON.stringify(v)} is not a version (expected a.b.c, semver)`);
|
|
61
|
+
const parts = [m[1], m[2], m[3], m[4]].map((p) => (p === undefined ? 0 : Number(p))) as [
|
|
62
|
+
number,
|
|
63
|
+
number,
|
|
64
|
+
number,
|
|
65
|
+
number,
|
|
66
|
+
];
|
|
67
|
+
for (const p of parts) {
|
|
68
|
+
if (p > 0xffff) throw new Error(`${JSON.stringify(v)}: each version part must be <= 65535 for VERSIONINFO`);
|
|
69
|
+
}
|
|
70
|
+
return parts;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function buildVersionInfo(input: VersionInfoInput): Uint8Array {
|
|
74
|
+
const lang = input.lang ?? 0x0409;
|
|
75
|
+
const codepage = input.codepage ?? 1200;
|
|
76
|
+
const fv = input.fileVersion;
|
|
77
|
+
const pv = input.productVersion ?? fv;
|
|
78
|
+
|
|
79
|
+
const fixed = new Uint8Array(52);
|
|
80
|
+
const dv = new DataView(fixed.buffer);
|
|
81
|
+
const fields = [
|
|
82
|
+
0xfeef04bd, // dwSignature
|
|
83
|
+
0x00010000, // dwStrucVersion
|
|
84
|
+
((fv[0] << 16) | fv[1]) >>> 0,
|
|
85
|
+
((fv[2] << 16) | fv[3]) >>> 0,
|
|
86
|
+
((pv[0] << 16) | pv[1]) >>> 0,
|
|
87
|
+
((pv[2] << 16) | pv[3]) >>> 0,
|
|
88
|
+
0x3f, // dwFileFlagsMask
|
|
89
|
+
0, // dwFileFlags
|
|
90
|
+
0x40004, // dwFileOS = VOS_NT_WINDOWS32
|
|
91
|
+
1, // dwFileType = VFT_APP
|
|
92
|
+
0, // dwFileSubtype
|
|
93
|
+
0, // dwFileDateMS — no timestamps: two builds of one input are byte-identical
|
|
94
|
+
0, // dwFileDateLS
|
|
95
|
+
];
|
|
96
|
+
fields.forEach((x, i) => dv.setUint32(i * 4, x >>> 0, true));
|
|
97
|
+
|
|
98
|
+
const table = `${lang.toString(16).padStart(4, "0")}${codepage.toString(16).padStart(4, "0")}`;
|
|
99
|
+
const order: (keyof VersionStrings)[] = [
|
|
100
|
+
"CompanyName",
|
|
101
|
+
"FileDescription",
|
|
102
|
+
"FileVersion",
|
|
103
|
+
"InternalName",
|
|
104
|
+
"LegalCopyright",
|
|
105
|
+
"OriginalFilename",
|
|
106
|
+
"ProductName",
|
|
107
|
+
"ProductVersion",
|
|
108
|
+
"Comments",
|
|
109
|
+
];
|
|
110
|
+
const strings: Uint8Array[] = [];
|
|
111
|
+
for (const key of order) {
|
|
112
|
+
const value = input.strings[key];
|
|
113
|
+
if (value === undefined || value === "") continue;
|
|
114
|
+
strings.push(node(key, 1, utf16(value), value.length + 1, []));
|
|
115
|
+
}
|
|
116
|
+
const translation = new Uint8Array(4);
|
|
117
|
+
new DataView(translation.buffer).setUint16(0, lang, true);
|
|
118
|
+
new DataView(translation.buffer).setUint16(2, codepage, true);
|
|
119
|
+
|
|
120
|
+
const stringFileInfo = node("StringFileInfo", 1, null, 0, [node(table, 1, null, 0, strings)]);
|
|
121
|
+
const varFileInfo = node("VarFileInfo", 1, null, 0, [node("Translation", 0, translation, 4, [])]);
|
|
122
|
+
return node("VS_VERSION_INFO", 0, fixed, 52, [stringFileInfo, varFileInfo]);
|
|
123
|
+
}
|
package/css-prefixes.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Vendor-prefixed declarations, dropped from the CSS the builders ship. Mirrors
|
|
2
|
+
// crates/sk-css/src/prefix.rs (only the `-webkit-` spellings in `WEBKIT_APPLIED` apply, the rest are
|
|
3
|
+
// dropped); test/css-prefixes.test.ts fails when the lists differ. Declarations only.
|
|
4
|
+
|
|
5
|
+
import postcss, { type Root } from "postcss";
|
|
6
|
+
|
|
7
|
+
export const WEBKIT_APPLIED: readonly string[] = [
|
|
8
|
+
"align-content",
|
|
9
|
+
"align-items",
|
|
10
|
+
"align-self",
|
|
11
|
+
"animation",
|
|
12
|
+
"animation-delay",
|
|
13
|
+
"animation-direction",
|
|
14
|
+
"animation-duration",
|
|
15
|
+
"animation-fill-mode",
|
|
16
|
+
"animation-iteration-count",
|
|
17
|
+
"animation-name",
|
|
18
|
+
"animation-play-state",
|
|
19
|
+
"animation-timing-function",
|
|
20
|
+
"app-region",
|
|
21
|
+
"appearance",
|
|
22
|
+
"backdrop-filter",
|
|
23
|
+
"backface-visibility",
|
|
24
|
+
"background-clip",
|
|
25
|
+
"background-origin",
|
|
26
|
+
"background-size",
|
|
27
|
+
"border-bottom-left-radius",
|
|
28
|
+
"border-bottom-right-radius",
|
|
29
|
+
"border-radius",
|
|
30
|
+
"border-top-left-radius",
|
|
31
|
+
"border-top-right-radius",
|
|
32
|
+
"box-align",
|
|
33
|
+
"box-decoration-break",
|
|
34
|
+
"box-direction",
|
|
35
|
+
"box-flex",
|
|
36
|
+
"box-ordinal-group",
|
|
37
|
+
"box-orient",
|
|
38
|
+
"box-pack",
|
|
39
|
+
"box-reflect",
|
|
40
|
+
"box-shadow",
|
|
41
|
+
"box-sizing",
|
|
42
|
+
"clip-path",
|
|
43
|
+
"column-count",
|
|
44
|
+
"column-gap",
|
|
45
|
+
"column-rule",
|
|
46
|
+
"column-span",
|
|
47
|
+
"column-width",
|
|
48
|
+
"columns",
|
|
49
|
+
"filter",
|
|
50
|
+
"flex",
|
|
51
|
+
"flex-basis",
|
|
52
|
+
"flex-direction",
|
|
53
|
+
"flex-flow",
|
|
54
|
+
"flex-grow",
|
|
55
|
+
"flex-shrink",
|
|
56
|
+
"flex-wrap",
|
|
57
|
+
"font-feature-settings",
|
|
58
|
+
"hyphens",
|
|
59
|
+
"justify-content",
|
|
60
|
+
"line-clamp",
|
|
61
|
+
"mask",
|
|
62
|
+
"mask-clip",
|
|
63
|
+
"mask-composite",
|
|
64
|
+
"mask-image",
|
|
65
|
+
"mask-origin",
|
|
66
|
+
"mask-position",
|
|
67
|
+
"mask-repeat",
|
|
68
|
+
"mask-size",
|
|
69
|
+
"order",
|
|
70
|
+
"perspective",
|
|
71
|
+
"perspective-origin",
|
|
72
|
+
"text-fill-color",
|
|
73
|
+
"text-size-adjust",
|
|
74
|
+
"text-stroke",
|
|
75
|
+
"text-stroke-color",
|
|
76
|
+
"text-stroke-width",
|
|
77
|
+
"transform",
|
|
78
|
+
"transform-origin",
|
|
79
|
+
"transform-style",
|
|
80
|
+
"transition",
|
|
81
|
+
"transition-delay",
|
|
82
|
+
"transition-duration",
|
|
83
|
+
"transition-property",
|
|
84
|
+
"transition-timing-function",
|
|
85
|
+
"user-select",
|
|
86
|
+
"writing-mode",
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
const APPLIED = new Set(WEBKIT_APPLIED);
|
|
90
|
+
const PREFIX = /^-(webkit|moz|ms|o)-/i;
|
|
91
|
+
|
|
92
|
+
export function isDroppedPrefix(prop: string): boolean {
|
|
93
|
+
const m = PREFIX.exec(prop);
|
|
94
|
+
if (!m) return false;
|
|
95
|
+
if (m[1]!.toLowerCase() !== "webkit") return true;
|
|
96
|
+
return !APPLIED.has(prop.slice(m[0].length).toLowerCase());
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const MAYBE = /(^|[;{\s])-(webkit|moz|ms|o)-[a-z-]+\s*:/i;
|
|
100
|
+
|
|
101
|
+
/** `css` without the vendor-prefixed declarations; unchanged when there are none or postcss cannot parse it. */
|
|
102
|
+
export function pruneVendorPrefixes(css: string): string {
|
|
103
|
+
if (!MAYBE.test(css)) return css;
|
|
104
|
+
let root: Root;
|
|
105
|
+
try {
|
|
106
|
+
root = postcss.parse(css);
|
|
107
|
+
} catch {
|
|
108
|
+
return css;
|
|
109
|
+
}
|
|
110
|
+
let removed = 0;
|
|
111
|
+
root.walkDecls((decl) => {
|
|
112
|
+
if (isDroppedPrefix(decl.prop)) {
|
|
113
|
+
decl.remove();
|
|
114
|
+
removed++;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
return removed ? root.toString() : css;
|
|
118
|
+
}
|