Skip to content

Commit 5a88f8c

Browse files
committed
feat: override local bundle at build time
when building for end-to-end tests, we want to load a local bundle, but the vite preview server isn't up and running to serve static assets yet also, set up lint-staged for faster lint failure feedback
1 parent ec63f53 commit 5a88f8c

File tree

8 files changed

+533
-112
lines changed

8 files changed

+533
-112
lines changed

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx lint-staged

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@
66
"lint": "prettier --write '**/*.{ts,js,svelte,yaml}'",
77
"lint:check": "prettier --check '**/*.{ts,js,svelte,yaml}'",
88
"test": "pnpm run --recursive test",
9-
"test:cov": "pnpm run --recursive test:cov"
9+
"test:cov": "pnpm run --recursive test:cov",
10+
"prepare": "husky"
11+
},
12+
"lint-staged": {
13+
"*.{ts,js,svelte,yaml}": "pnpm lint"
1014
},
1115
"devDependencies": {
1216
"@types/node": "^20.14.0",
1317
"@vitest/coverage-v8": "^1.3.0",
18+
"husky": "^9.1.7",
19+
"lint-staged": "^16.1.0",
1420
"nodemon": "^2.0.22",
1521
"npm-check-updates": "^16.14.12",
1622
"prettier": "^2.8.8",
@@ -20,4 +26,4 @@
2026
"vite": "^5.0.0",
2127
"vitest": "^1.3.0"
2228
}
23-
}
29+
}

packages/core/test/fixtures/bundle.min.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
},
143143
{
144144
"uid": "P000021",
145-
"name": "Weakly Countably Compact",
145+
"name": "Weakly countably compact",
146146
"aliases": ["Limit point compact"],
147147
"refs": [],
148148
"description": "-"

packages/viewer/cypress/fixtures/main.min.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,9 @@
220220
},
221221
{
222222
"uid": "P000021",
223-
"name": "Weakly Countably Compact",
224-
"aliases": [
225-
"Limit point compact"
226-
],
227-
"refs": [
228-
229-
],
223+
"name": "Weakly countably compact",
224+
"aliases": ["Limit point compact"],
225+
"refs": [],
230226
"description": "-"
231227
},
232228
{

packages/viewer/src/gateway.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ export type Result = {
2020

2121
export function sync(
2222
fetch: (input: RequestInfo, init?: RequestInit) => Promise<Response>,
23+
bundle?: pb.Bundle,
2324
): Sync {
2425
return async (host: string, branch: string, etag?: string) => {
2526
trace({ event: 'remote_fetch_started', host, branch })
26-
const result = await pb.bundle.fetch({ host, branch, etag, fetch })
27+
const result = bundle
28+
? { bundle, etag: 'etag' }
29+
: await pb.bundle.fetch({ host, branch, etag, fetch })
2730

2831
if (result) {
2932
trace({ event: 'remote_fetch_complete', result })
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import main from '../../public/refs/heads/main.json'
2+
3+
const bundleHost = import.meta.env.VITE_BUNDLE_HOST
4+
5+
export const load = () => {
6+
if (bundleHost?.includes('localhost')) {
7+
return main
8+
}
9+
}

packages/viewer/src/routes/+layout.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import * as errors from '@/errors'
44
import { sync } from '@/gateway'
55
import type { LayoutLoad } from './$types'
66

7-
export const load: LayoutLoad = async ({ fetch, url: { host } }) => {
7+
const bundleHost = import.meta.env.VITE_BUNDLE_HOST
8+
9+
export const load: LayoutLoad = async ({ data, fetch, url: { host } }) => {
810
const dev = host.match(/(dev(elopment)?[.-]|localhost)/) !== null
911

1012
const errorHandler = dev
@@ -14,7 +16,7 @@ export const load: LayoutLoad = async ({ fetch, url: { host } }) => {
1416
const context = initialize({
1517
showDev: dev,
1618
errorHandler,
17-
gateway: sync(fetch),
19+
gateway: sync(fetch, data ? (data as any) : undefined),
1820
source: {
1921
host: defaultHost,
2022
},

0 commit comments

Comments
 (0)