Skip to content

Commit

Permalink
persist data source branch in localStorage (#89)
Browse files Browse the repository at this point in the history
* persist data source branch in localStorage

* fix compile build failure

which appears to have been introduced through random dependency
drift, not any changes here :/

* cache cypress binary in CI

to fix https://github.com/pi-base/web/actions/runs/7149095438/job/19470902100?pr=89
  • Loading branch information
jamesdabbs authored Dec 9, 2023
1 parent ab6e45f commit 57d30ee
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 50 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,17 @@ jobs:
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-v1-${{ hashFiles('**/pnpm-lock.yaml') }}
key: ${{ runner.os }}-pnpm-store-v2-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-v1-
${{ runner.os }}-pnpm-store-v2-
- uses: actions/cache@v3
name: Setup Cypress cache
with:
path: /github/home/.cache/Cypress
key: ${{ runner.os }}-cypress-v1-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-cypress-v1-
- name: Install dependencies
run: pnpm install
Expand Down
7 changes: 4 additions & 3 deletions packages/compile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"scripts": {
"build": "tsc",
"dev": "nodemon",
"start": "ts-node --esm src/watch.ts",
"start": "tsx src/watch.ts",
"test": "vitest run",
"test:cov": "vitest run --coverage",
"test:watch": "vitest"
Expand All @@ -47,6 +47,7 @@
"@types/yaml-front-matter": "^4.1.0",
"cors": "^2.8.5",
"express": "^4.18.2",
"tsheredoc": "^1.0.1"
"tsheredoc": "^1.0.1",
"tsx": "^4.6.2"
}
}
}
20 changes: 8 additions & 12 deletions packages/compile/src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@ const repo = join(__dirname, '..', 'test', 'repo')
const out = join(repo, 'out.json')

async function run(dir: string) {
const { stdout, stderr, error, status } = spawnSync(
'pnpm',
['exec', 'ts-node', '--esm', main],
{
env: {
GITHUB_REF: 'refs/heads/test',
GITHUB_SHA: 'c74d99cf46f6ed23e742f2617e9908294b4a608b',
GITHUB_WORKSPACE: join(repo, dir),
INPUT_OUT: out,
PATH: process.env.PATH,
},
const { stdout, stderr, error, status } = spawnSync('tsx', [main], {
env: {
GITHUB_REF: 'refs/heads/test',
GITHUB_SHA: 'c74d99cf46f6ed23e742f2617e9908294b4a608b',
GITHUB_WORKSPACE: join(repo, dir),
INPUT_OUT: out,
PATH: process.env.PATH,
},
)
})

if (error) {
throw error
Expand Down
40 changes: 25 additions & 15 deletions packages/viewer/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
export type { Context } from './context/types'

import { getContext, setContext } from 'svelte'
import { type Readable, derived } from 'svelte/store'
import { formula as F } from '@pi-base/core'

import type { Context } from './context/types'
import { trace } from './debug'
import * as Errors from './errors'
import type * as Gateway from './gateway'
import { Id } from './models'
import { renderer } from './parser'
import { type Local, local } from './repositories'
import { type Prestore, type Store, create } from './stores'
import { subscribeUntil } from './util'
import { getContext, setContext } from 'svelte'
import { derived, get, type Readable } from 'svelte/store'

import type { Context } from '@/context/types'
import { trace } from '@/debug'
import * as Errors from '@/errors'
import type * as Gateway from '@/gateway'
import { Id } from '@/models'
import { renderer } from '@/parser'
import { local, type Local } from '@/repositories'
import { create, type Prestore, type Store } from '@/stores'
import { type Source } from '@/types'
import { subscribeUntil } from '@/util'

export type Config = {
showDevLink: boolean
Expand All @@ -39,20 +40,29 @@ function project(store: Store) {
export function initialize({
db = local(),
errorHandler = Errors.log(),
host,
source = {},
gateway,
showDev = false,
typesetter = renderer,
}: {
db?: Local<Prestore>
errorHandler?: Errors.Handler
host?: string
source?: Partial<Source>
gateway: Gateway.Sync
showDev?: boolean
typesetter?: typeof renderer
}): Context {
const pre = db.load()
const store = create(pre, gateway, { host })
const store = create(
{
...pre,
source: {
host: source.host || pre.source.host,
branch: source.branch || pre.source.branch,
},
},
gateway,
)

db.subscribe(project(store))

Expand Down
4 changes: 3 additions & 1 deletion packages/viewer/src/routes/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export const load: LayoutLoad = async ({ fetch, url: { host } }) => {
showDev: dev,
errorHandler,
gateway: sync(fetch),
host: bundleHost,
source: {
host: bundleHost,
},
})

await context.loaded()
Expand Down
17 changes: 2 additions & 15 deletions packages/viewer/src/stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,12 @@ export type Store = {
deduction: Deduction.Store
}

export function create(
pre: Prestore,
gateway: Gateway.Sync,
{
host = defaultHost,
branch = mainBranch,
}: {
host?: string
branch?: string
} = {},
): Store {
export function create(pre: Prestore, gateway: Gateway.Sync): Store {
const spaces = writable(Collection.empty<Space>())
const properties = writable(Collection.empty<Property>())
const theorems = writable(new Theorems())
const traits = writable(new Traits())
const source = Source.create({
host,
branch,
})
const source = Source.create(pre.source)
const sync = Sync.create(refresh, pre.sync)

const deduction = Deduction.create(
Expand Down
36 changes: 34 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 57d30ee

Please sign in to comment.