Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion scripts/check-setup-needed.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import path from 'path'
import dotenv from 'dotenv'
import { execSync } from 'child_process'
import { L10N_CAGE_DIR, MARKDOWN_L10NS } from '../src/lib/l10n.ts'
import { importRuntimeWithoutVite } from './l10n/utils.ts'

dotenv.config()

const runtimeModule = await import('../src/lib/paraglide/runtime.js')
const runtimeModule = await importRuntimeWithoutVite()
let activeLocales = Array.from(runtimeModule.locales)
let setupNeeded = false
let reason = ''
Expand Down
2 changes: 1 addition & 1 deletion scripts/inlang-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function regenerateSettings(verbose = false): void {
strategy: ['url', 'cookie', 'preferredLanguage', 'baseLocale'],
// Fix for Netlify Edge Functions (Deno runtime)
disableAsyncLocalStorage: true,
isServer: "typeof window === 'undefined' || 'Deno' in globalThis"
isServer: 'import.meta.env.SSR'
}

// Only set urlPatterns for prefix-all-locales strategy
Expand Down
5 changes: 3 additions & 2 deletions scripts/l10n/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
MESSAGE_L10NS,
MESSAGE_SOURCE
} from '../../src/lib/l10n.ts'
import { importRuntimeWithoutVite } from './utils.ts'

// Load environment variables first
dotenv.config()
Expand Down Expand Up @@ -63,12 +64,12 @@ if (unknownArgs.length > 0) {
}

// Ensure inlang settings are current before importing runtime
execSync('tsx scripts/inlang-settings.ts', { stdio: 'ignore' })
execSync('tsx scripts/inlang-settings.ts', { stdio: 'inherit' })

// This let / try / catch lets the ESM scan succeed in the absence of a runtime
let locales: readonly string[]
try {
const runtime = await import('../../src/lib/paraglide/runtime.js')
const runtime = await importRuntimeWithoutVite()
locales = runtime.locales
if (runtime.baseLocale !== 'en')
throw new Error(
Expand Down
16 changes: 15 additions & 1 deletion scripts/l10n/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,20 @@ export function cullCommentary(filePath: string, verbose = false) {

if (verbose) console.log(`✅ Culled LLM commentary in ${filePath}`)
} catch (error) {
console.error(`Error cleaning up file ${filePath}:`, error.message)
console.error(
`Error cleaning up file ${filePath}:`,
error instanceof Error ? error.message : String(error)
)
}
}

export async function importRuntimeWithoutVite(): Promise<
typeof import('../../src/lib/paraglide/runtime.js')
> {
const runtimeString = await fs.readFile('src/lib/paraglide/runtime.js', 'utf-8')
const patchedRuntime = runtimeString.replace('import.meta.env.SSR', 'true')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So let me say this out loud? The scripts that call importRuntimeWithoutVite are clobbered so that if isServer was checked by the runtime in the course of its methods being called, it acts the same as it does when running as a server rather than running as a build.

(Presumably because SSR does not end up in the environment. I get it, and sorry.)

But... shouldn't it really be false? It gets used in a build context.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replied in the main thread

const runtime = await import(
'data:text/javascript;base64,' + Buffer.from(patchedRuntime).toString('base64')
)
return runtime
}
4 changes: 3 additions & 1 deletion scripts/l10ntamer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

import fs from 'fs'
import path from 'path'
import { locales, localizeHref } from '../src/lib/paraglide/runtime.js'
import { importRuntimeWithoutVite } from './l10n/utils.js'

const { locales, localizeHref } = await importRuntimeWithoutVite()

if (localizeHref('/test', { locale: 'en' }) === '/test') {
console.log('⏭️ Skipping l10ntamer - English routes not prefixed')
Expand Down
2 changes: 1 addition & 1 deletion src/routes/api/simple-delay/+server.ts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, we also both fixed this and the other endpoint TS error at the same time. I committed six minutes later, and didn't notice it merged because 585de1d had a tiny Tally warning fix too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the result of the broken Git configuration on one of my machines, I tried to merge from main

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function GET({ url }) {
} catch (error) {
return new Response(
JSON.stringify({
error: error.message,
error: error instanceof Error ? error.message : String(error),
elapsedMs: Date.now() - start
}),
{
Expand Down
2 changes: 1 addition & 1 deletion src/routes/api/test-timeout/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function GET({ url }) {
index: i,
success: false,
elapsed: Date.now() - reqStart,
error: error.message
error: error instanceof Error ? error.message : String(error)
})
break // Stop on first error
}
Expand Down
4 changes: 2 additions & 2 deletions svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import remarkToc from 'remark-toc'
import remarkHeadingId from 'remark-heading-id'
import rehypeSlug from 'rehype-slug'

import { locales } from './src/lib/paraglide/runtime.js'
import settings from './project.inlang/settings.json' with { type: 'json' }

// Export configuration flags for use in build scripts
export const USE_EDGE_FUNCTIONS = true
Expand Down Expand Up @@ -62,7 +62,7 @@ const config = {
prerender: {
// Allows dead links to be rendered
handleHttpError: 'warn',
entries: ['*'].concat(locales.map((locale) => '/' + locale))
entries: ['*'].concat(settings.locales.map((locale) => '/' + locale))
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import path from 'path'
import { defineConfig } from 'vite'
import { isDev } from './src/lib/env'
import { MARKDOWN_L10NS } from './src/lib/l10n'
import { locales as compiledLocales } from './src/lib/paraglide/runtime'
import { importRuntimeWithoutVite } from './scripts/l10n/utils'

const { locales: compiledLocales } = await importRuntimeWithoutVite()

function getLocaleExcludePatterns(): RegExp[] {
const md = path.resolve(MARKDOWN_L10NS)
Expand Down