-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3360 from opral/expose-runtime-type
expose runtime type
- Loading branch information
Showing
8 changed files
with
92 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export { addVitePlugin } from "./add-vite-plugin.js"; | ||
export { checkForUncommittedChanges } from "./check-for-uncomitted-changes.js"; | ||
export { detectBundler } from "./detect-bundler.js"; | ||
export { initializeInlangProject } from "./initialize-inlang-project.js"; | ||
export { maybeAddSherlock } from "./maybe-add-sherlock.js"; | ||
export { promptForOutdir } from "./prompt-for-outdir.js"; | ||
export { runCompiler } from "./run-compiler.js"; | ||
export { updatePackageJson } from "./update-package-json.js"; | ||
export { maybeUpdateTsConfig } from "./update-ts-config.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
inlang/packages/paraglide-js/src/compiler/runtime/type.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { expect, test } from "vitest"; | ||
import { createProject as typescriptProject, ts } from "@ts-morph/bootstrap"; | ||
import { createRuntime } from "./create-runtime.js"; | ||
import fs from "node:fs/promises"; | ||
import { dirname, resolve } from "node:path"; | ||
import { fileURLToPath } from "url"; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
|
||
test("runtime type", async () => { | ||
const project = await typescriptProject({ | ||
useInMemoryFileSystem: true, | ||
compilerOptions: { | ||
outDir: "./dist", | ||
declaration: true, | ||
allowJs: true, | ||
checkJs: true, | ||
module: ts.ModuleKind.Node16, | ||
strict: true, | ||
}, | ||
}); | ||
|
||
const jsdocRuntime = createRuntime( | ||
{ baseLocale: "en", locales: ["en"] }, | ||
false | ||
); | ||
|
||
const runtimeType = await fs.readFile( | ||
resolve(__dirname, "./type.ts"), | ||
"utf-8" | ||
); | ||
|
||
project.createSourceFile("./runtime.js", jsdocRuntime); | ||
|
||
project.createSourceFile("./runtime-type.ts", runtimeType); | ||
|
||
project.createSourceFile( | ||
"./test.ts", | ||
` | ||
import * as runtime from "./runtime.js" | ||
import type { Runtime as RuntimeType } from "./runtime-type.js" | ||
const runtimeType: RuntimeType = runtime | ||
` | ||
); | ||
|
||
const program = project.createProgram(); | ||
const diagnostics = ts.getPreEmitDiagnostics(program); | ||
for (const diagnostic of diagnostics) { | ||
console.error(diagnostic.messageText, diagnostic.file?.fileName); | ||
} | ||
expect(diagnostics.length).toEqual(0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* The Paraglide runtime API. | ||
*/ | ||
export type Runtime = { | ||
baseLocale: UnknownLocale; | ||
locales: Readonly<UnknownLocale[]>; | ||
getLocale: () => string; | ||
setLocale: (newLocale: UnknownLocale) => void; | ||
defineGetLocale: (fn: () => UnknownLocale) => void; | ||
defineSetLocale: (fn: (newLocale: UnknownLocale) => void) => void; | ||
isLocale: (locale: UnknownLocale) => locale is UnknownLocale; | ||
}; | ||
|
||
/** | ||
* A locale that is unknown before compilation. | ||
*/ | ||
export type UnknownLocale = any; |