@stacksjs/defaults 0.73.2 → 0.74.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.
|
@@ -149,6 +149,62 @@ Application data belongs in `~/Library/Application Support/<AppName>`, never
|
|
|
149
149
|
inside the bundle — `/Applications` is not writable by the user, and the bundle
|
|
150
150
|
is replaced wholesale on update.
|
|
151
151
|
|
|
152
|
+
## Helper processes: one binary, not three
|
|
153
|
+
|
|
154
|
+
An app that owns its launcher usually needs more than the launcher — an agent
|
|
155
|
+
serving on loopback, a worker doing something slow out of process. Compile each
|
|
156
|
+
as its own binary and the bundle gets very large very quietly.
|
|
157
|
+
|
|
158
|
+
`bun build --compile` embeds the entire Bun runtime in **every** executable it
|
|
159
|
+
writes. `console.log("hi")` measures **60.5 MB**. So three binaries means three
|
|
160
|
+
copies of the same runtime, and nothing says so — the bundle is simply big, and
|
|
161
|
+
a big desktop app looks unremarkable. One real app shipped 230 MB this way, of
|
|
162
|
+
which about 180 MB was the runtime repeated; its own code plus the native Craft
|
|
163
|
+
runtime came to under 40 MB.
|
|
164
|
+
|
|
165
|
+
Compile **one** binary and dispatch on a subcommand. The helpers stay separate
|
|
166
|
+
*processes* — which is what actually matters for isolation and for killing one
|
|
167
|
+
that wedges — they just stop being separate *files*.
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
// app/Desktop/launcher.ts — before anything else at module scope
|
|
171
|
+
const subcommand = process.argv[2]
|
|
172
|
+
|
|
173
|
+
if (subcommand === 'agent' || subcommand === 'scan') {
|
|
174
|
+
if (subcommand === 'agent') {
|
|
175
|
+
const { runAgent } = await import('./server')
|
|
176
|
+
await runAgent()
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
const { runScannerCli } = await import('../Workers/scan')
|
|
180
|
+
await runScannerCli(process.argv[3] ?? '')
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Park. Everything below is the launcher, and a subcommand reaching it would
|
|
184
|
+
// spawn a second agent and open a second window.
|
|
185
|
+
await new Promise(() => {})
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Then spawn `process.execPath` instead of a sibling path:
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
const agent = Bun.spawn([process.execPath, 'agent'], { stdout: 'pipe' })
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Two things that bite, both silently:
|
|
196
|
+
|
|
197
|
+
- **The dispatch must come first.** A launcher's body is top-level code that
|
|
198
|
+
starts a server and opens a window as a side effect of loading.
|
|
199
|
+
- **Do not `process.exit()` after starting a server.** A `runAgent()` that
|
|
200
|
+
returns once `Bun.serve` is listening has not finished — `Bun.serve` is what
|
|
201
|
+
holds the process open. Exiting after it kills the agent one line after it
|
|
202
|
+
printed the port the launcher is still waiting for, and the launcher reports
|
|
203
|
+
a timeout that says nothing about the cause.
|
|
204
|
+
|
|
205
|
+
`buddy build:dmg` warns when a finished bundle contains more than one
|
|
206
|
+
Bun-compiled executable, naming them and what the repetition costs.
|
|
207
|
+
|
|
152
208
|
## CLI Commands
|
|
153
209
|
|
|
154
210
|
```bash
|
|
@@ -2,7 +2,6 @@ import { Action } from '@stacksjs/actions'
|
|
|
2
2
|
import { generateTwoFactorSetup, stashPendingTwoFactorSecret } from '@stacksjs/auth'
|
|
3
3
|
import { config } from '@stacksjs/config'
|
|
4
4
|
import { response } from '@stacksjs/router'
|
|
5
|
-
import { toSvg } from 'ts-qr-codes'
|
|
6
5
|
|
|
7
6
|
export default new Action({
|
|
8
7
|
name: 'GenerateTwoFactorSecretAction',
|
|
@@ -14,7 +13,11 @@ export default new Action({
|
|
|
14
13
|
return response.unauthorized('Unauthorized')
|
|
15
14
|
|
|
16
15
|
const appName = config.app?.name || 'Stacks'
|
|
17
|
-
|
|
16
|
+
|
|
17
|
+
// `qr` is an SVG string of `uri`, rendered by @stacksjs/auth so an app that
|
|
18
|
+
// overrides this action still gets one. Clients that render their own QR
|
|
19
|
+
// code have `uri`; clients that offer manual entry have `secret`.
|
|
20
|
+
const { secret, uri, qr } = generateTwoFactorSetup(user.email ?? '', appName)
|
|
18
21
|
|
|
19
22
|
// Not persisted to users.two_factor_secret until EnableTwoFactorAction
|
|
20
23
|
// verifies a code produced from it — but stashed server-side now so
|
|
@@ -22,15 +25,6 @@ export default new Action({
|
|
|
22
25
|
// two-factor.ts's doc comment for why.
|
|
23
26
|
await stashPendingTwoFactorSecret(user.id as number, secret)
|
|
24
27
|
|
|
25
|
-
// Rendered here rather than left to the client. Every authenticator flow
|
|
26
|
-
// needs the URI as a QR code, and a caller that has to find its own
|
|
27
|
-
// encoder either ships one to the browser or, more often, falls back to
|
|
28
|
-
// asking the user to type a 32-character secret by hand.
|
|
29
|
-
//
|
|
30
|
-
// SVG so it stays sharp at any size and can be inlined into a page or an
|
|
31
|
-
// email; the URI is still returned for clients that render their own.
|
|
32
|
-
const qr = toSvg(uri, { size: 240, title: 'Two-factor authentication setup' })
|
|
33
|
-
|
|
34
28
|
return response.json({ secret, uri, qr })
|
|
35
29
|
},
|
|
36
30
|
})
|
package/ide/vscode/package.json
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/defaults",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.74.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/stacksjs/stacks.git",
|
|
@@ -48,14 +48,14 @@
|
|
|
48
48
|
"default": "./dist/*.js"
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "bun build.ts"
|
|
53
|
+
},
|
|
51
54
|
"dependencies": {
|
|
52
55
|
"@iconify-json/f7": "^1.2.2",
|
|
53
56
|
"@iconify-json/hugeicons": "^1.2.27",
|
|
54
|
-
"@stacksjs/mobile": "^0.
|
|
57
|
+
"@stacksjs/mobile": "^0.74.0",
|
|
55
58
|
"@stacksjs/sanitizer": "^0.2.113",
|
|
56
59
|
"ts-qr-codes": "^0.1.8"
|
|
57
|
-
},
|
|
58
|
-
"scripts": {
|
|
59
|
-
"build": "bun build.ts"
|
|
60
60
|
}
|
|
61
61
|
}
|