Skip to content

Commit

Permalink
Work around vitejs/vite#18582
Browse files Browse the repository at this point in the history
After that issue is fixed, this commit should be reverted.
  • Loading branch information
SLaks committed Nov 5, 2024
1 parent 73cebd7 commit 32b5434
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
14 changes: 11 additions & 3 deletions src/location.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference types="vite/client" />
import type { RefWithScroll, ScrollName } from './ref.ts'

type AppleSauce = {
Expand All @@ -8,9 +9,16 @@ type AppleSauce = {
type TOC = Record<string, Record<string, Record<string, AppleSauce>>>

export async function loadScroll(name: ScrollName) {
const toc = await import(`./data/tables-of-contents/${name}.json`, {
with: { type: 'json' },
})
// TODO(https://github.com/vitejs/vite/issues/18582): Delete this workaround.
let toc
if (import.meta.env?.MODE)
// Vite dynamic imports doesn't support the second parameter
toc = await import(`./data/tables-of-contents/${name}.json`)
else
toc = await import(`./data/tables-of-contents/${name}.json`, {
// Node.js requires the second parameter.
with: { type: 'json' },
})
return new ScrollResolver(name, toc.default)
}

Expand Down
15 changes: 11 additions & 4 deletions src/view-model/scroll-view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,24 @@ export abstract class ScrollViewModel {
if (typeof pageNumber === 'object') return pageNumber
if (!pageNumber || pageNumber <= 0) return null

const page: LineType[] = (
await import(

let page: { default: LineType[] }
if (import.meta.env?.MODE)
// Vite dynamic imports doesn't support the second parameter
page = await import(
`../data/pages/${this.relevantRuns[0].scroll}/${pageNumber}.json`
)
else
page = await import(
`../data/pages/${this.relevantRuns[0].scroll}/${pageNumber}.json`,
// Node.js requires the second parameter.
{ with: { type: 'json' } }
)
).default

let run: LeiningRun | undefined
let aliyot: LeiningAliyah[] = []
const labeller = new AliyahLabeller()
const lines: RenderedLineInfo[] = page.map((rawLine) => {
const lines: RenderedLineInfo[] = page.default.map((rawLine) => {
const verses = rawLine.verses.map(toRef)

if (verses.length) [run, aliyot] = this.findContainingAliyot(verses, run)
Expand Down

0 comments on commit 32b5434

Please sign in to comment.