zooid 0.7.3 → 0.8.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/dist/bin.js +214 -109
- package/dist/bin.js.map +1 -1
- package/dist/{chunk-3IKBBKGI.js → chunk-R6EDLH23.js} +283 -11
- package/dist/chunk-R6EDLH23.js.map +1 -0
- package/dist/index.js +1 -1
- package/package.json +12 -8
- package/src/bin.ts +1 -1
- package/src/commands/dev.ts +23 -9
- package/src/daemon/start-daemon.ts +20 -1
- package/src/web/fetch.integration.test.ts +61 -0
- package/src/web/fetch.test.ts +139 -0
- package/src/web/fetch.ts +85 -0
- package/src/web/pin.test.ts +24 -0
- package/src/web/pin.ts +13 -0
- package/src/web/resolve.test.ts +54 -26
- package/src/web/resolve.ts +22 -10
- package/src/web/test-helpers.ts +28 -0
- package/dist/chunk-3IKBBKGI.js.map +0 -1
- package/dist/web/assets/geist-cyrillic-wght-normal-CHSlOQsW.woff2 +0 -0
- package/dist/web/assets/geist-latin-ext-wght-normal-DMtmJ5ZE.woff2 +0 -0
- package/dist/web/assets/geist-latin-wght-normal-Dm3htQBi.woff2 +0 -0
- package/dist/web/assets/index-BqOX0Pv4.js +0 -305
- package/dist/web/assets/index-C-ZtBp7U.css +0 -1
- package/dist/web/assets/index-Dc8BJYf_.js +0 -118066
- package/dist/web/assets/reaction-picker-emoji-xD2HkULN.js +0 -716
- package/dist/web/favicon.svg +0 -1
- package/dist/web/index.html +0 -14
package/src/web/resolve.ts
CHANGED
|
@@ -1,27 +1,39 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs'
|
|
2
2
|
import { dirname, join, resolve } from 'node:path'
|
|
3
|
+
import { fetchWebBundle, type FetchWebBundleOptions } from './fetch.js'
|
|
3
4
|
|
|
4
5
|
const ENV_OVERRIDE = 'ZOOID_DEV_WEB_ROOT_OVERRIDE'
|
|
5
6
|
|
|
6
|
-
export
|
|
7
|
+
export interface EnsureWebRootOptions {
|
|
8
|
+
cliRoot: string
|
|
9
|
+
cacheDir: string
|
|
10
|
+
version: string | undefined
|
|
11
|
+
fetchBundle?: (opts: FetchWebBundleOptions) => Promise<string>
|
|
12
|
+
onProgress?: (msg: string) => void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function ensureWebRoot(opts: EnsureWebRootOptions): Promise<string> {
|
|
7
16
|
const override = process.env[ENV_OVERRIDE]
|
|
8
17
|
if (override && existsSync(join(override, 'index.html'))) return resolve(override)
|
|
9
18
|
|
|
10
|
-
const
|
|
11
|
-
if (existsSync(join(published, 'index.html'))) return published
|
|
12
|
-
|
|
13
|
-
const fromSource = webSourcePackage(cliRoot)
|
|
19
|
+
const fromSource = webSourcePackage(opts.cliRoot)
|
|
14
20
|
if (fromSource && existsSync(join(fromSource, 'dist', 'index.html'))) {
|
|
15
21
|
return join(fromSource, 'dist')
|
|
16
22
|
}
|
|
17
23
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
`
|
|
21
|
-
|
|
24
|
+
if (!opts.version) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`No @zooid/zoon-web version pin (zooid.zoonWebVersion) in the cli package.json ` +
|
|
27
|
+
`and no monorepo sibling build found.\n` +
|
|
28
|
+
`Set ${ENV_OVERRIDE} to a built dist, or run from the monorepo.`,
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
opts.onProgress?.(`Fetching @zooid/zoon-web ${opts.version}…`)
|
|
32
|
+
const fetchBundleFn = opts.fetchBundle ?? fetchWebBundle
|
|
33
|
+
return fetchBundleFn({ version: opts.version, cacheDir: opts.cacheDir })
|
|
22
34
|
}
|
|
23
35
|
|
|
24
|
-
// Returns the path to the in-tree @zoon
|
|
36
|
+
// Returns the path to the in-tree @zooid/zoon-web package (zoon/packages/web) if the
|
|
25
37
|
// CLI is running from the monorepo source. Returns null when running from an
|
|
26
38
|
// installed package (no sibling zoon/ tree).
|
|
27
39
|
export function webSourcePackage(cliRoot: string): string | null {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { tmpdir } from 'node:os'
|
|
3
|
+
import { dirname, join } from 'node:path'
|
|
4
|
+
import { createHash } from 'node:crypto'
|
|
5
|
+
import * as tar from 'tar'
|
|
6
|
+
|
|
7
|
+
export function makeBundleTgz(
|
|
8
|
+
files: Record<string, string> = {
|
|
9
|
+
'package/package.json': '{"name":"@zooid/zoon-web"}',
|
|
10
|
+
'package/dist/index.html': '<html>zoon</html>',
|
|
11
|
+
'package/dist/assets/app.js': '// app',
|
|
12
|
+
},
|
|
13
|
+
): { tgz: Buffer; integrity: string } {
|
|
14
|
+
const dir = mkdtempSync(join(tmpdir(), 'zooid-tgz-'))
|
|
15
|
+
try {
|
|
16
|
+
for (const [path, content] of Object.entries(files)) {
|
|
17
|
+
mkdirSync(join(dir, dirname(path)), { recursive: true })
|
|
18
|
+
writeFileSync(join(dir, path), content)
|
|
19
|
+
}
|
|
20
|
+
const tgz = tar
|
|
21
|
+
.create({ sync: true, gzip: true, cwd: dir, portable: true }, ['package'])
|
|
22
|
+
.read() as Buffer
|
|
23
|
+
const integrity = 'sha512-' + createHash('sha512').update(tgz).digest('base64')
|
|
24
|
+
return { tgz, integrity }
|
|
25
|
+
} finally {
|
|
26
|
+
rmSync(dir, { recursive: true, force: true })
|
|
27
|
+
}
|
|
28
|
+
}
|