@inlang/paraglide-js 2.0.0-beta.8 → 2.0.0-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/adapter-utils/routing/resolveUserPathDefinition.test.js +6 -6
  2. package/dist/adapter-utils/routing/resolveUserPathDefinitions.d.ts +4 -4
  3. package/dist/adapter-utils/routing/resolveUserPathDefinitions.d.ts.map +1 -1
  4. package/dist/adapter-utils/routing/resolveUserPathDefinitions.js +4 -7
  5. package/dist/bundler-plugins/rollup.d.ts +1 -5
  6. package/dist/bundler-plugins/rollup.d.ts.map +1 -1
  7. package/dist/bundler-plugins/unplugin.d.ts +2 -16
  8. package/dist/bundler-plugins/unplugin.d.ts.map +1 -1
  9. package/dist/bundler-plugins/vite.d.ts +1 -5
  10. package/dist/bundler-plugins/vite.d.ts.map +1 -1
  11. package/dist/compiler/compile.d.ts +28 -7
  12. package/dist/compiler/compile.d.ts.map +1 -1
  13. package/dist/compiler/compile.js +1 -1
  14. package/dist/compiler/compileBundle.js +3 -3
  15. package/dist/compiler/compileBundle.test.js +2 -2
  16. package/dist/compiler/compileProject.d.ts +2 -2
  17. package/dist/compiler/compileProject.d.ts.map +1 -1
  18. package/dist/compiler/compileProject.test.js +10 -66
  19. package/dist/compiler/emit-dts.d.ts +7 -0
  20. package/dist/compiler/emit-dts.d.ts.map +1 -0
  21. package/dist/compiler/emit-dts.js +56 -0
  22. package/dist/compiler/index.d.ts +2 -0
  23. package/dist/compiler/index.d.ts.map +1 -1
  24. package/dist/compiler/jsDocComment.d.ts +9 -0
  25. package/dist/compiler/jsDocComment.d.ts.map +1 -0
  26. package/dist/compiler/jsDocComment.js +30 -0
  27. package/dist/compiler/jsdoc-types.js +1 -1
  28. package/dist/compiler/runtime.js +0 -49
  29. package/dist/compiler/types.d.ts +17 -0
  30. package/dist/compiler/types.d.ts.map +1 -1
  31. package/dist/index.d.ts +2 -6
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +2 -2
  34. package/dist/services/env-variables/index.js +1 -1
  35. package/package.json +1 -1
@@ -8,14 +8,14 @@ describe("resolvePathTranslations", () => {
8
8
  de: "/ueber-uns",
9
9
  },
10
10
  };
11
- const availableLanguageTags = ["en", "de"];
12
- const result = resolveUserPathDefinitions(userTranslations, availableLanguageTags);
11
+ const availableLocales = ["en", "de"];
12
+ const result = resolveUserPathDefinitions(userTranslations, availableLocales);
13
13
  expect(result).toEqual(userTranslations);
14
14
  });
15
15
  it("resolves message translations", () => {
16
16
  const userTranslations = {
17
- "/about": (_, { languageTag }) => {
18
- switch (languageTag) {
17
+ "/about": (_, { locale }) => {
18
+ switch (locale) {
19
19
  case "en":
20
20
  return "/about";
21
21
  case "de":
@@ -23,8 +23,8 @@ describe("resolvePathTranslations", () => {
23
23
  }
24
24
  },
25
25
  };
26
- const availableLanguageTags = ["en", "de"];
27
- const result = resolveUserPathDefinitions(userTranslations, availableLanguageTags);
26
+ const availableLocales = ["en", "de"];
27
+ const result = resolveUserPathDefinitions(userTranslations, availableLocales);
28
28
  expect(result).toEqual({
29
29
  "/about": {
30
30
  en: "/about",
@@ -1,4 +1,4 @@
1
- import type { MessageIndexFunction } from "../../index.js";
1
+ import type { MessageBundleFunction } from "../../compiler/types.js";
2
2
  import type { PathDefinitionTranslations } from "./routeDefinitions.js";
3
3
  /**
4
4
  * Maps canonical paths to translations for each language.
@@ -22,7 +22,7 @@ import type { PathDefinitionTranslations } from "./routeDefinitions.js";
22
22
  * ```
23
23
  */
24
24
  export type UserPathDefinitionTranslations<T extends string = string> = {
25
- [canonicalPath: `/${string}`]: Record<T, `/${string}`> | MessageIndexFunction<T>;
25
+ [canonicalPath: `/${string}`]: Record<T, `/${string}`> | MessageBundleFunction<T>;
26
26
  };
27
27
  /**
28
28
  * For UX purpouses we let users pass messages as pathnames.
@@ -33,8 +33,8 @@ export type UserPathDefinitionTranslations<T extends string = string> = {
33
33
  * Does NOT perform any validation on if the user-provided path translation configuration is valid.
34
34
  *
35
35
  * @param userTranslations The user-provided path translation configuration.
36
- * @param availableLanguageTags The available language tags.
36
+ * @param availableLocales The available language tags.
37
37
  * @returns The resolved path translations.
38
38
  */
39
- export declare const resolveUserPathDefinitions: <T extends string>(userTranslations: UserPathDefinitionTranslations<T>, availableLanguageTags: readonly T[]) => PathDefinitionTranslations<T>;
39
+ export declare const resolveUserPathDefinitions: <T extends string>(userTranslations: UserPathDefinitionTranslations<T>, availableLocales: readonly T[]) => PathDefinitionTranslations<T>;
40
40
  //# sourceMappingURL=resolveUserPathDefinitions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolveUserPathDefinitions.d.ts","sourceRoot":"","sources":["../../../src/adapter-utils/routing/resolveUserPathDefinitions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,8BAA8B,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI;IACvE,CAAC,aAAa,EAAE,IAAI,MAAM,EAAE,GACzB,MAAM,CAAC,CAAC,EAAE,IAAI,MAAM,EAAE,CAAC,GACvB,oBAAoB,CAAC,CAAC,CAAC,CAAC;CAC3B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,0BAA0B,GAAI,CAAC,SAAS,MAAM,oBACxC,8BAA8B,CAAC,CAAC,CAAC,yBAC5B,SAAS,CAAC,EAAE,KACjC,0BAA0B,CAAC,CAAC,CAQ7B,CAAC"}
1
+ {"version":3,"file":"resolveUserPathDefinitions.d.ts","sourceRoot":"","sources":["../../../src/adapter-utils/routing/resolveUserPathDefinitions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,8BAA8B,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI;IACvE,CAAC,aAAa,EAAE,IAAI,MAAM,EAAE,GACzB,MAAM,CAAC,CAAC,EAAE,IAAI,MAAM,EAAE,CAAC,GACvB,qBAAqB,CAAC,CAAC,CAAC,CAAC;CAC5B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,0BAA0B,GAAI,CAAC,SAAS,MAAM,oBACxC,8BAA8B,CAAC,CAAC,CAAC,oBACjC,SAAS,CAAC,EAAE,KAC5B,0BAA0B,CAAC,CAAC,CAQ7B,CAAC"}
@@ -7,16 +7,13 @@
7
7
  * Does NOT perform any validation on if the user-provided path translation configuration is valid.
8
8
  *
9
9
  * @param userTranslations The user-provided path translation configuration.
10
- * @param availableLanguageTags The available language tags.
10
+ * @param availableLocales The available language tags.
11
11
  * @returns The resolved path translations.
12
12
  */
13
- export const resolveUserPathDefinitions = (userTranslations, availableLanguageTags) => Object.fromEntries(Object.entries(userTranslations).map(([path, translation]) => [
13
+ export const resolveUserPathDefinitions = (userTranslations, availableLocales) => Object.fromEntries(Object.entries(userTranslations).map(([path, translation]) => [
14
14
  path,
15
15
  typeof translation === "object"
16
16
  ? translation
17
- : fromMessage(translation, availableLanguageTags),
18
- ]));
19
- const fromMessage = (message, availableLanguageTags) => Object.fromEntries(availableLanguageTags.map((languageTag) => [
20
- languageTag,
21
- message({}, { languageTag }),
17
+ : fromMessage(translation, availableLocales),
22
18
  ]));
19
+ const fromMessage = (message, availableLocales) => Object.fromEntries(availableLocales.map((locale) => [locale, message({}, { locale })]));
@@ -1,6 +1,2 @@
1
- export declare const paraglideRollupPlugin: (options: {
2
- project: string;
3
- outdir: string;
4
- compilerOptions?: import("../compiler/compileProject.js").ParaglideCompilerOptions;
5
- }) => import("unplugin").RollupPlugin<any> | import("unplugin").RollupPlugin<any>[];
1
+ export declare const paraglideRollupPlugin: (options: import("../index.js").CompilerArgs) => import("unplugin").RollupPlugin<any> | import("unplugin").RollupPlugin<any>[];
6
2
  //# sourceMappingURL=rollup.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rollup.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/rollup.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB;;;;mFAAsC,CAAC"}
1
+ {"version":3,"file":"rollup.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/rollup.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB,gIAAsC,CAAC"}
@@ -1,18 +1,4 @@
1
1
  import type { UnpluginFactory } from "unplugin";
2
- import type { ParaglideCompilerOptions } from "../compiler/compileProject.js";
3
- export declare const unpluginFactory: UnpluginFactory<{
4
- /**
5
- * The path to the inlang project.
6
- *
7
- * @example "./project.inlang"
8
- */
9
- project: string;
10
- /**
11
- * The path to the output directory.
12
- *
13
- * @example "./src/paraglide"
14
- */
15
- outdir: string;
16
- compilerOptions?: ParaglideCompilerOptions;
17
- }>;
2
+ import { type CompilerArgs } from "../compiler/compile.js";
3
+ export declare const unpluginFactory: UnpluginFactory<CompilerArgs>;
18
4
  //# sourceMappingURL=unplugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"unplugin.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/unplugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAO9E,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC;IAC7C;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,wBAAwB,CAAC;CAC3C,CAwCC,CAAC"}
1
+ {"version":3,"file":"unplugin.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/unplugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAMpE,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,YAAY,CAwCxD,CAAC"}
@@ -1,6 +1,2 @@
1
- export declare const paraglideVitePlugin: (options: {
2
- project: string;
3
- outdir: string;
4
- compilerOptions?: import("../compiler/compileProject.js").ParaglideCompilerOptions;
5
- }) => import("vite").Plugin<any> | import("vite").Plugin<any>[];
1
+ export declare const paraglideVitePlugin: (options: import("../index.js").CompilerArgs) => import("vite").Plugin<any> | import("vite").Plugin<any>[];
6
2
  //# sourceMappingURL=vite.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/vite.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB;;;;+DAAoC,CAAC"}
1
+ {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/vite.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB,4GAAoC,CAAC"}
@@ -1,4 +1,30 @@
1
- import { type ParaglideCompilerOptions } from "./compileProject.js";
1
+ import { type CompilerOptions } from "./compileProject.js";
2
+ export type CompilerArgs = {
3
+ /**
4
+ * The path to the project to compile.
5
+ *
6
+ * @example
7
+ * './project.inlang'
8
+ */
9
+ project: string;
10
+ /**
11
+ * The path to the directory to write the output to.
12
+ *
13
+ * @example
14
+ * './src/paraglide'
15
+ */
16
+ outdir: string;
17
+ /**
18
+ * Additional compiler options.
19
+ */
20
+ compilerOptions?: CompilerOptions;
21
+ /**
22
+ * The file system to use. Defaults to `await import('node:fs')`.
23
+ *
24
+ * Useful for testing the paraglide compiler by mocking the fs.
25
+ */
26
+ fs?: typeof import("node:fs");
27
+ };
2
28
  /**
3
29
  * Loads, compiles, and writes the output to disk.
4
30
  *
@@ -12,10 +38,5 @@ import { type ParaglideCompilerOptions } from "./compileProject.js";
12
38
  * outdir: 'path/to/output',
13
39
  * })
14
40
  */
15
- export declare function compile(args: {
16
- project: string;
17
- outdir: string;
18
- fs?: typeof import("node:fs");
19
- compilerOptions?: ParaglideCompilerOptions;
20
- }): Promise<void>;
41
+ export declare function compile(args: CompilerArgs): Promise<void>;
21
42
  //# sourceMappingURL=compile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/compiler/compile.ts"],"names":[],"mappings":"AAGA,OAAO,EAEN,KAAK,wBAAwB,EAC7B,MAAM,qBAAqB,CAAC;AAO7B;;;;;;;;;;;;GAYG;AACH,wBAAsB,OAAO,CAAC,IAAI,EAAE;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,cAAc,SAAS,CAAC,CAAC;IAC9B,eAAe,CAAC,EAAE,wBAAwB,CAAC;CAC3C,GAAG,OAAO,CAAC,IAAI,CAAC,CA8BhB"}
1
+ {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/compiler/compile.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAO3E,MAAM,MAAM,YAAY,GAAG;IAC1B;;;;;OAKG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC;;;;OAIG;IACH,EAAE,CAAC,EAAE,cAAc,SAAS,CAAC,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAsB,OAAO,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CA8B/D"}
@@ -1,7 +1,7 @@
1
1
  import { loadProjectFromDirectory } from "@inlang/sdk";
2
2
  import path from "node:path";
3
3
  import { ENV_VARIABLES } from "../services/env-variables/index.js";
4
- import { compileProject, } from "./compileProject.js";
4
+ import { compileProject } from "./compileProject.js";
5
5
  import { writeOutput } from "../services/file-handling/write-output.js";
6
6
  import { getLocalAccount, saveLocalAccount, } from "../services/account/index.js";
7
7
  /**
@@ -10,7 +10,7 @@ export const compileBundle = (args) => {
10
10
  const compiledMessages = {};
11
11
  for (const message of args.bundle.messages) {
12
12
  if (compiledMessages[message.locale]) {
13
- throw new Error(`Duplicate language tag: ${message.locale}`);
13
+ throw new Error(`Duplicate locale: ${message.locale}`);
14
14
  }
15
15
  const compiledMessage = compileMessage(args.bundle.declarations, message, message.variants, args.registry);
16
16
  // add types to the compiled message function
@@ -48,7 +48,7 @@ const compileBundleFunction = (args) => {
48
48
  */
49
49
  /* @__NO_SIDE_EFFECTS__ */
50
50
  const ${jsIdentifier(args.bundle.id)} = (inputs${emitTs ? tsInputType(inputs) : ""} ${hasInputs ? "" : "= {}"}, options${emitTs ? tsOptionsType(args.availableLocales) : ""} = {}) ${emitTs ? ": string" : ""} => {
51
- const locale = options.locale ?? options.languageTag ?? getLocale()
51
+ const locale = options.locale ?? getLocale()
52
52
  ${args.availableLocales
53
53
  .map((locale, index) => `${index > 0 ? " " : ""}if (locale === "${locale}") return ${jsIdentifier(locale)}.${args.bundle.id}(inputs)`)
54
54
  .join("\n")}
@@ -69,7 +69,7 @@ const ${jsIdentifier(args.bundle.id)} = (inputs${emitTs ? tsInputType(inputs) :
69
69
  };
70
70
  function tsOptionsType(locales) {
71
71
  const localesUnion = locales.map((locale) => `"${locale}"`).join(" | ");
72
- return `: { locale?: ${localesUnion},/** @deprecated use \`locale\` instead */languageTag?: ${localesUnion} }`;
72
+ return `: { locale?: ${localesUnion} }`;
73
73
  }
74
74
  function tsInputType(inputs) {
75
75
  const inputParams = inputs
@@ -20,8 +20,8 @@ test("compiles as ts", async () => {
20
20
  *
21
21
  */
22
22
  /* @__NO_SIDE_EFFECTS__ */
23
- const blue_moon_bottle = (inputs: { age: NonNullable<unknown> } , options: { locale?: "en" | "en-US",/** @deprecated use \`locale\` instead */languageTag?: "en" | "en-US" } = {}) : string => {
24
- const locale = options.locale ?? options.languageTag ?? getLocale()
23
+ const blue_moon_bottle = (inputs: { age: NonNullable<unknown> } , options: { locale?: "en" | "en-US" } = {}) : string => {
24
+ const locale = options.locale ?? getLocale()
25
25
  if (locale === "en") return en.blue_moon_bottle(inputs)
26
26
  if (locale === "en-US") return en_US.blue_moon_bottle(inputs)
27
27
  return "blue_moon_bottle"
@@ -1,5 +1,5 @@
1
1
  import { type InlangProject } from "@inlang/sdk";
2
- export type ParaglideCompilerOptions = {
2
+ export type CompilerOptions = {
3
3
  /**
4
4
  * Whether to emit TypeScript files instead of JSDoc annotated JavaScript.
5
5
  *
@@ -55,7 +55,7 @@ export type ParaglideCompilerOptions = {
55
55
  */
56
56
  export declare const compileProject: (args: {
57
57
  project: InlangProject;
58
- compilerOptions?: ParaglideCompilerOptions;
58
+ compilerOptions?: CompilerOptions;
59
59
  }) => Promise<Record<string, string>>;
60
60
  export declare function getFallbackMap<T extends string>(locales: T[], baseLocale: NoInfer<T>): Record<T, T | undefined>;
61
61
  //# sourceMappingURL=compileProject.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compileProject.d.ts","sourceRoot":"","sources":["../../src/compiler/compileProject.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAKrE,MAAM,MAAM,wBAAwB,GAAG;IACtC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;;;;;;;;;;;;;;OAgBG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;OAIG;IACH,eAAe,CAAC,EAAE,gBAAgB,GAAG,iBAAiB,CAAC;CACvD,CAAC;AAUF;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,SAAgB;IAC1C,OAAO,EAAE,aAAa,CAAC;IACvB,eAAe,CAAC,EAAE,wBAAwB,CAAC;CAC3C,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA4DjC,CAAC;AAEF,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAC9C,OAAO,EAAE,CAAC,EAAE,EACZ,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,GACpB,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAY1B"}
1
+ {"version":3,"file":"compileProject.d.ts","sourceRoot":"","sources":["../../src/compiler/compileProject.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAKrE,MAAM,MAAM,eAAe,GAAG;IAC7B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;;;;;;;;;;;;;;OAgBG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;OAIG;IACH,eAAe,CAAC,EAAE,gBAAgB,GAAG,iBAAiB,CAAC;CACvD,CAAC;AAUF;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,SAAgB;IAC1C,OAAO,EAAE,aAAa,CAAC;IACvB,eAAe,CAAC,EAAE,eAAe,CAAC;CAClC,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA4DjC,CAAC;AAEF,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAC9C,OAAO,EAAE,CAAC,EAAE,EACZ,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,GACpB,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAY1B"}
@@ -1,7 +1,7 @@
1
1
  import { expect, test, describe, vi, beforeEach } from "vitest";
2
2
  import { createProject as typescriptProject, ts } from "@ts-morph/bootstrap";
3
3
  import { Declaration, insertBundleNested, loadProjectInMemory, newProject, Pattern, VariableReference, } from "@inlang/sdk";
4
- import { compileProject, } from "./compileProject.js";
4
+ import { compileProject } from "./compileProject.js";
5
5
  import virtual from "@rollup/plugin-virtual";
6
6
  import { rolldown } from "rolldown";
7
7
  beforeEach(() => {
@@ -183,16 +183,16 @@ describe.each([
183
183
  expect(cb2).toHaveBeenCalledTimes(1);
184
184
  expect(cb1).toHaveBeenCalledTimes(1);
185
185
  });
186
- test("should return the correct message if a languageTag is set in the message options", async () => {
186
+ test("should return the correct message if a locale is set in the message options", async () => {
187
187
  const { m, runtime } = await importCode(code);
188
188
  // set the language tag to de to make sure that the message options override the runtime language tag
189
- runtime.setLanguageTag("de");
189
+ runtime.setLocale("de");
190
190
  expect(m.sad_penguin_bundle()).toBe("Eine einfache Nachricht.");
191
- expect(m.sad_penguin_bundle(undefined, { languageTag: "en" })).toBe("A simple message.");
191
+ expect(m.sad_penguin_bundle(undefined, { locale: "en" })).toBe("A simple message.");
192
192
  });
193
193
  test("runtime.isAvailableLocale should only return `true` if a locale is passed to it", async () => {
194
194
  const { runtime } = await importCode(code);
195
- for (const tag of runtime.availableLanguageTags) {
195
+ for (const tag of runtime.availableLocales) {
196
196
  expect(runtime.isAvailableLocale(tag)).toBe(true);
197
197
  }
198
198
  expect(runtime.isAvailableLocale("")).toBe(false);
@@ -334,62 +334,6 @@ describe.each([
334
334
  }
335
335
  expect(diagnostics.length).toEqual(0);
336
336
  });
337
- // remove with v3 of paraglide js
338
- test("./runtime.js (legacy) types", async () => {
339
- const project = await typescriptProject({
340
- useInMemoryFileSystem: true,
341
- compilerOptions: {
342
- outDir: "dist",
343
- declaration: true,
344
- allowJs: true,
345
- checkJs: true,
346
- module: ts.ModuleKind.Node16,
347
- strict: true,
348
- },
349
- });
350
- for (const [fileName, code] of Object.entries(output)) {
351
- if (fileName.endsWith(".js") || fileName.endsWith(".ts")) {
352
- project.createSourceFile(fileName, code);
353
- }
354
- }
355
- project.createSourceFile("test.ts", `
356
- import * as runtime from "./runtime.js"
357
-
358
- // --------- RUNTIME ---------
359
-
360
- // sourceLanguageTag should have a narrow type, not a generic string
361
-
362
- runtime.sourceLanguageTag satisfies "en"
363
-
364
- // availableLanguageTags should have a narrow type, not a generic string
365
- runtime.availableLanguageTags satisfies Readonly<Array<"de" | "en" | "en-US">>
366
-
367
- // setLanguageTag() should fail if the given language tag is not included in availableLanguageTags
368
- // @ts-expect-error
369
- runtime.setLanguageTag("fr")
370
-
371
- // setLanguageTag() should not fail if the given language tag is included in availableLanguageTags
372
- runtime.setLanguageTag("de")
373
-
374
- // languageTag should return type should be a union of language tags, not a generic string
375
- runtime.languageTag() satisfies "de" | "en" | "en-US"
376
-
377
- // isAvailableLocale should narrow the type of it's argument
378
- const thing = 5;
379
- if(runtime.isAvailableLocale(thing)) {
380
- const a : "de" | "en" | "en-US" = thing
381
- } else {
382
- // @ts-expect-error - thing is not a language tag
383
- const a : "de" | "en" | "en-US" = thing
384
- }
385
- `);
386
- const program = project.createProgram();
387
- const diagnostics = ts.getPreEmitDiagnostics(program);
388
- for (const diagnostic of diagnostics) {
389
- console.error(diagnostic.messageText, diagnostic.file?.fileName);
390
- }
391
- expect(diagnostics.length).toEqual(0);
392
- });
393
337
  test("./messages.js types", async () => {
394
338
  const project = await typescriptProject({
395
339
  useInMemoryFileSystem: true,
@@ -425,15 +369,15 @@ describe.each([
425
369
  m.sad_penguin_bundle() satisfies string
426
370
 
427
371
  // --------- MESSAGE OPTIONS ---------
428
- // the languageTag option should be optional
372
+ // the locale option should be optional
429
373
  m.sad_penguin_bundle({}, {}) satisfies string
430
374
 
431
- // the languageTag option should be allowed
432
- m.sad_penguin_bundle({}, { languageTag: "en" }) satisfies string
375
+ // the locale option should be allowed
376
+ m.sad_penguin_bundle({}, { locale: "en" }) satisfies string
433
377
 
434
- // the languageTag option must be a valid language tag
378
+ // the locale option must be a valid language tag
435
379
  // @ts-expect-error - invalid language tag
436
- m.sad_penguin_bundle({}, { languageTag: "---" })
380
+ m.sad_penguin_bundle({}, { locale: "---" })
437
381
  `);
438
382
  const program = project.createProgram();
439
383
  const diagnostics = ts.getPreEmitDiagnostics(program);
@@ -0,0 +1,7 @@
1
+ import type { CompiledBundleWithMessages } from "./compileBundle.js";
2
+ /**
3
+ * @param inputFiles The files in the `outdir`
4
+ * @returns .d.ts files for each file in the `outdir`
5
+ */
6
+ export declare function emitDts(compiledBundles: CompiledBundleWithMessages[], compiledRuntime: string, compiledRegistry: string): Record<string, string>;
7
+ //# sourceMappingURL=emit-dts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emit-dts.d.ts","sourceRoot":"","sources":["../../src/compiler/emit-dts.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAErE;;;GAGG;AACH,wBAAgB,OAAO,CACtB,eAAe,EAAE,0BAA0B,EAAE,EAC7C,eAAe,EAAE,MAAM,EACvB,gBAAgB,EAAE,MAAM,GACtB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAyCxB"}
@@ -0,0 +1,56 @@
1
+ import { createProgram, createCompilerHost, } from "typescript";
2
+ /**
3
+ * @param inputFiles The files in the `outdir`
4
+ * @returns .d.ts files for each file in the `outdir`
5
+ */
6
+ export function emitDts(compiledBundles, compiledRuntime, compiledRegistry) {
7
+ /**
8
+ * Stores files that were emitted as `.d.ts` files during the output.
9
+ * @example
10
+ * ```js
11
+ * {
12
+ * "paraglide/runtime.d.ts": "export type AvailableLanguageTag = ...",
13
+ * "paragildes/messages.d.ts": "...",
14
+ * }
15
+ * ```
16
+ */
17
+ const outputFiles = {};
18
+ const host = createCompilerHost(compilerOptions);
19
+ const inputFiles = {
20
+ "messages.js": compiledBundles
21
+ .map((compiled) => compiled.bundle.code)
22
+ .join("\n"),
23
+ "registry.js": compiledRegistry,
24
+ "runtime.js": compiledRuntime,
25
+ };
26
+ // A list of input paths for the compiler
27
+ const inputs = Object.keys(inputFiles);
28
+ // intercept read/write methods of the compiler
29
+ host.writeFile = (path, contents) => (outputFiles[path] = contents);
30
+ host.readFile = (path) => inputFiles[path];
31
+ // run the TS compiler
32
+ // this will cause `host.writeFile` to be called
33
+ // our output files are in `outputFiles` after this
34
+ const program = createProgram(inputs, compilerOptions, host);
35
+ program.emit();
36
+ const output = {};
37
+ for (const [path, content] of Object.entries(outputFiles)) {
38
+ output[path] = `/* eslint-disable */\n` + content;
39
+ }
40
+ return output;
41
+ }
42
+ /**
43
+ * TypeScript compiler options
44
+ */
45
+ const compilerOptions = {
46
+ allowJs: true,
47
+ checkJs: true,
48
+ declaration: true,
49
+ declarationDir: undefined,
50
+ declarationMap: false,
51
+ emitDeclarationOnly: true,
52
+ lib: undefined,
53
+ noEmit: false,
54
+ noEmitOnError: false,
55
+ skipLibCheck: true,
56
+ };
@@ -1,3 +1,5 @@
1
+ export type { CompilerArgs } from "./compile.js";
2
+ export type { CompilerOptions } from "./compileProject.js";
1
3
  export { compile } from "./compile.js";
2
4
  export { compileProject } from "./compileProject.js";
3
5
  export { compileBundle } from "./compileBundle.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compiler/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compiler/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { InputVariable } from "@inlang/sdk";
2
+ export declare function jsDocBundleComment(args: {
3
+ inputs: InputVariable[];
4
+ locales: string[];
5
+ }): string;
6
+ export declare function jsDocMessageComment(args: {
7
+ inputs: InputVariable[];
8
+ }): string;
9
+ //# sourceMappingURL=jsDocComment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsDocComment.d.ts","sourceRoot":"","sources":["../../src/compiler/jsDocComment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IACxC,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,OAAO,EAAE,MAAM,EAAE,CAAC;CAClB,GAAG,MAAM,CAqBT;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE;IAAE,MAAM,EAAE,aAAa,EAAE,CAAA;CAAE,GAAG,MAAM,CAU7E"}
@@ -0,0 +1,30 @@
1
+ export function jsDocBundleComment(args) {
2
+ const inputParams = args.inputs
3
+ .map((input) => {
4
+ return `${input.name}: NonNullable<unknown>`;
5
+ })
6
+ .join(", ");
7
+ const localesUnion = args.locales.map((locale) => `"${locale}"`).join(" | ");
8
+ return `/**
9
+ * This function has been compiled by [Paraglide JS](https://inlang.com/m/gerre34r).
10
+ *
11
+ * - Changing this function will be over-written by the next build.
12
+ *
13
+ * - If you want to change the translations, you can either edit the source files e.g. \`en.json\`, or
14
+ * use another inlang app like [Fink](https://inlang.com/m/tdozzpar) or the [VSCode extension Sherlock](https://inlang.com/m/r7kp499g).
15
+ *
16
+ * @param {{ ${inputParams} }} inputs
17
+ * @param {{ locale?: ${localesUnion}, languageTag?: ${localesUnion} }} options
18
+ * @returns {string}
19
+ */`;
20
+ }
21
+ export function jsDocMessageComment(args) {
22
+ const inputParams = args.inputs
23
+ .map((input) => {
24
+ return `${input.name}: NonNullable<unknown>`;
25
+ })
26
+ .join(", ");
27
+ return `/**
28
+ * @param {{ ${inputParams} }} i
29
+ */`;
30
+ }
@@ -7,7 +7,7 @@ export function jsDocBundleFunctionTypes(args) {
7
7
  const localesUnion = args.locales.map((locale) => `"${locale}"`).join(" | ");
8
8
  return `
9
9
  * @param {{ ${inputParams} }} inputs
10
- * @param {{ locale?: ${localesUnion}, languageTag?: ${localesUnion} }} options
10
+ * @param {{ locale?: ${localesUnion} }} options
11
11
  * @returns {string}
12
12
  `;
13
13
  }
@@ -136,31 +136,6 @@ export function isAvailableLocale(locale) {
136
136
  *
137
137
  * @typedef {(typeof availableLocales)[number]} AvailableLocale
138
138
  */
139
-
140
- // ------ LEGACY RUNTIME (will be removed in the next major version) ------
141
-
142
- /** @deprecated Use \`baseLocale\` instead */
143
- export const sourceLanguageTag = baseLocale;
144
-
145
- /** @deprecated Use \`availableLocales\` instead */
146
- export const availableLanguageTags = availableLocales;
147
-
148
- /** @deprecated Use \`getLocale()\` instead */
149
- export let languageTag = getLocale;
150
-
151
- /** @deprecated Use \`setLocale()\` instead */
152
- export const setLanguageTag = setLocale;
153
-
154
- /**
155
- * @deprecated Use \`isAvailableLocale()\` instead
156
- * @returns {thing is AvailableLanguageTag}
157
- */
158
- export const isAvailableLanguageTag = isAvailableLocale;
159
-
160
- /**
161
- * @deprecated Use \`AvailableLocale\` instead
162
- * @typedef {(typeof availableLocales)[number]} AvailableLanguageTag
163
- */
164
139
  `;
165
140
  const tsRuntime = (settings) => `
166
141
  /* eslint-disable */
@@ -279,28 +254,4 @@ export function isAvailableLocale(locale: any): locale is AvailableLocale {
279
254
  *
280
255
  */
281
256
  export type AvailableLocale = (typeof availableLocales)[number];
282
-
283
- // ------ LEGACY RUNTIME (will be removed in the next major version) ------
284
-
285
- /** @deprecated Use \`baseLocale\` instead */
286
- export const sourceLanguageTag = baseLocale;
287
-
288
- /** @deprecated Use \`availableLocales\` instead */
289
- export const availableLanguageTags = availableLocales;
290
-
291
- /** @deprecated Use \`getLocale()\` instead */
292
- export let languageTag = getLocale;
293
-
294
- /** @deprecated Use \`setLocale()\` instead */
295
- export const setLanguageTag = setLocale;
296
-
297
- /**
298
- * @deprecated Use \`isAvailableLocale()\` instead
299
- */
300
- export const isAvailableLanguageTag = isAvailableLocale;
301
-
302
- /**
303
- * @deprecated Use \`AvailableLocale\` instead
304
- */
305
- export type AvailableLanguageTag = AvailableLocale;
306
257
  `;
@@ -4,6 +4,23 @@ export type Compiled<Node> = {
4
4
  /** The code generated to implement the AST node */
5
5
  code: string;
6
6
  };
7
+ /**
8
+ * A message function that takes inputs and returns a message.
9
+ *
10
+ * @example
11
+ * import
12
+ */
13
+ export type MessageFunction = (inputs?: Record<string, never>) => string;
14
+ /**
15
+ * A message bundle function.
16
+ *
17
+ * @example
18
+ * import * as m from './messages.js'
19
+ * m.hello({ name: 'world', { locale: "en" } })
20
+ */
21
+ export type MessageBundleFunction<T extends string> = (params: Record<string, never>, options: {
22
+ locale: T;
23
+ }) => string;
7
24
  /**
8
25
  * Attempts to merge type restrictions from two variants.
9
26
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/compiler/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,CAAC,IAAI,IAAI;IAC5B,4BAA4B;IAC5B,IAAI,EAAE,IAAI,CAAC;IACX,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;GAEG;AACH,wBAAgB,qBAAqB,CACpC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACzB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACvB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAmBxB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/compiler/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,CAAC,IAAI,IAAI;IAC5B,4BAA4B;IAC5B,IAAI,EAAE,IAAI,CAAC;IACX,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,MAAM,CAAC;AAEzE;;;;;;GAMG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,MAAM,IAAI,CACrD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAC7B,OAAO,EAAE;IAAE,MAAM,EAAE,CAAC,CAAA;CAAE,KAClB,MAAM,CAAC;AAEZ;;GAEG;AACH,wBAAgB,qBAAqB,CACpC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACzB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACvB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAmBxB"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,3 @@
1
- export type MessageIndexFunction<T extends string> = (params: Record<string, never>, options: {
2
- languageTag: T;
3
- }) => string;
4
- export type MessageFunction = (params?: Record<string, never>) => string;
5
- export { paraglideVitePlugin } from "./bundler-plugins/vite.js";
6
- export { paraglideRollupPlugin } from "./bundler-plugins/rollup.js";
1
+ export * from "./bundler-plugins/index.js";
2
+ export * from "./compiler/index.js";
7
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,MAAM,IAAI,CACpD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAC7B,OAAO,EAAE;IAAE,WAAW,EAAE,CAAC,CAAA;CAAE,KACvB,MAAM,CAAC;AAEZ,MAAM,MAAM,eAAe,GAAG,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,MAAM,CAAC;AAEzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { paraglideVitePlugin } from "./bundler-plugins/vite.js";
2
- export { paraglideRollupPlugin } from "./bundler-plugins/rollup.js";
1
+ export * from "./bundler-plugins/index.js";
2
+ export * from "./compiler/index.js";
@@ -1,5 +1,5 @@
1
1
  export const ENV_VARIABLES = {
2
2
  PARJS_APP_ID: "library.inlang.paraglideJs",
3
3
  PARJS_POSTHOG_TOKEN: "phc_m5yJZCxjOGxF8CJvP5sQ3H0d76xpnLrsmiZHduT4jDz",
4
- PARJS_PACKAGE_VERSION: "2.0.0-beta.8",
4
+ PARJS_PACKAGE_VERSION: "2.0.0-beta.9",
5
5
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@inlang/paraglide-js",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.8",
4
+ "version": "2.0.0-beta.9",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public",