@inlang/paraglide-js 2.6.0 → 2.7.1

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.
@@ -1,2 +1,2 @@
1
- export declare const paraglideWebpackPlugin: (options: import("../index.js").CompilerOptions) => WebpackPluginInstance;
1
+ export declare const paraglideWebpackPlugin: (options: import("../index.js").CompilerOptions) => import("unplugin").WebpackPluginInstance;
2
2
  //# sourceMappingURL=webpack.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"webpack.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/webpack.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,sBAAsB,2EAAuC,CAAC"}
1
+ {"version":3,"file":"webpack.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/webpack.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,sBAAsB,8FAAuC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/compile/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAUpC,eAAO,MAAM,cAAc,SAmDzB,CAAC"}
1
+ {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/compile/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAUpC,eAAO,MAAM,cAAc,SA4DzB,CAAC"}
@@ -16,6 +16,7 @@ export const compileCommand = new Command()
16
16
  "Read more on https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy",
17
17
  ].join("\n"))
18
18
  .requiredOption("--silent", "Only log errors to the console", false)
19
+ .option("--emit-ts-declarations", "Emit .d.ts files for the generated output (requires the typescript package)", defaultCompilerOptions.emitTsDeclarations)
19
20
  .action(async (options) => {
20
21
  const logger = new Logger({ silent: options.silent, prefix: true });
21
22
  const path = resolve(process.cwd(), options.project);
@@ -25,6 +26,8 @@ export const compileCommand = new Command()
25
26
  project: path,
26
27
  outdir: options.outdir,
27
28
  strategy: options.strategy ?? defaultCompilerOptions.strategy,
29
+ emitTsDeclarations: options.emitTsDeclarations ??
30
+ defaultCompilerOptions.emitTsDeclarations,
28
31
  });
29
32
  }
30
33
  catch (e) {
@@ -1 +1 @@
1
- {"version":3,"file":"compile-project.d.ts","sourceRoot":"","sources":["../../src/compiler/compile-project.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAIrE,OAAO,EAEN,KAAK,eAAe,EACpB,MAAM,uBAAuB,CAAC;AAU/B;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,GAAU,MAAM;IAC1C,OAAO,EAAE,aAAa,CAAC;IACvB,eAAe,CAAC,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,GAAG,SAAS,GAAG,QAAQ,CAAC,CAAC;CACrE,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAuEjC,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":"compile-project.d.ts","sourceRoot":"","sources":["../../src/compiler/compile-project.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAIrE,OAAO,EAEN,KAAK,eAAe,EACpB,MAAM,uBAAuB,CAAC;AAW/B;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,GAAU,MAAM;IAC1C,OAAO,EAAE,aAAa,CAAC;IACvB,eAAe,CAAC,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,GAAG,SAAS,GAAG,QAAQ,CAAC,CAAC;CACrE,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA4EjC,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"}
@@ -7,6 +7,7 @@ import { defaultCompilerOptions, } from "./compiler-options.js";
7
7
  import { createRuntimeFile } from "./runtime/create-runtime.js";
8
8
  import { createServerFile } from "./server/create-server-file.js";
9
9
  import { createRegistry } from "./registry.js";
10
+ import { emitTsDeclarations } from "./emit-ts-declarations.js";
10
11
  const outputStructures = {
11
12
  "locale-modules": localeModules,
12
13
  "message-modules": messageModules,
@@ -73,6 +74,10 @@ export const compileProject = async (args) => {
73
74
  }
74
75
  }
75
76
  }
77
+ if (optionsWithDefaults.emitTsDeclarations) {
78
+ const declarations = await emitTsDeclarations(output);
79
+ Object.assign(output, declarations);
80
+ }
76
81
  return output;
77
82
  };
78
83
  export function getFallbackMap(locales, baseLocale) {
@@ -61,6 +61,18 @@ test("emitPrettierIgnore", async () => {
61
61
  expect(_true).toHaveProperty(".prettierignore");
62
62
  expect(_false).not.toHaveProperty(".prettierignore");
63
63
  });
64
+ test("emitTsDeclarations generates declaration files", async () => {
65
+ const output = await compileProject({
66
+ project,
67
+ compilerOptions: {
68
+ emitTsDeclarations: true,
69
+ outputStructure: "locale-modules",
70
+ },
71
+ });
72
+ expect(output).toHaveProperty("messages/_index.d.ts");
73
+ expect(output).toHaveProperty("messages.d.ts");
74
+ expect(output["messages/_index.d.ts"]).toContain("sad_penguin_bundle");
75
+ });
64
76
  test("handles message bundles with a : in the id", async () => {
65
77
  const project = await loadProjectInMemory({
66
78
  blob: await newProject({
@@ -70,7 +82,7 @@ test("handles message bundles with a : in the id", async () => {
70
82
  },
71
83
  }),
72
84
  });
73
- await insertBundleNested(project, createBundleNested({
85
+ await insertBundleNested(project.db, createBundleNested({
74
86
  id: "hello:world",
75
87
  messages: [
76
88
  {
@@ -97,7 +109,7 @@ test("can emit message bundles with more than 255 characters", async () => {
97
109
  },
98
110
  }),
99
111
  });
100
- await insertBundleNested(project, createBundleNested({
112
+ await insertBundleNested(project.db, createBundleNested({
101
113
  // 300 characters long id
102
114
  id: "a".repeat(300),
103
115
  messages: [
@@ -199,7 +211,7 @@ describe.each([
199
211
  settings: { locales: ["en", "de"], baseLocale: "en" },
200
212
  }),
201
213
  });
202
- await insertBundleNested(project, createBundleNested({
214
+ await insertBundleNested(project.db, createBundleNested({
203
215
  id: "plural_test",
204
216
  declarations: [
205
217
  { type: "input-variable", name: "count" },
@@ -333,7 +345,7 @@ describe.each([
333
345
  settings: { locales: ["en", "de", "en-US"], baseLocale: "en" },
334
346
  }),
335
347
  });
336
- await insertBundleNested(project, createBundleNested({
348
+ await insertBundleNested(project.db, createBundleNested({
337
349
  id: "missingInGerman",
338
350
  messages: [
339
351
  {
@@ -363,7 +375,7 @@ describe.each([
363
375
  }),
364
376
  });
365
377
  // Add test messages
366
- await insertBundleNested(project, createBundleNested({
378
+ await insertBundleNested(project.db, createBundleNested({
367
379
  id: "greeting",
368
380
  messages: [
369
381
  {
@@ -380,7 +392,7 @@ describe.each([
380
392
  },
381
393
  ],
382
394
  }));
383
- await insertBundleNested(project, createBundleNested({
395
+ await insertBundleNested(project.db, createBundleNested({
384
396
  id: "farewell",
385
397
  messages: [
386
398
  {
@@ -473,7 +485,7 @@ describe.each([
473
485
  settings: { locales: ["en", "de"], baseLocale: "en" },
474
486
  }),
475
487
  });
476
- await insertBundleNested(project, createBundleNested({
488
+ await insertBundleNested(project.db, createBundleNested({
477
489
  id: "$502.23-hello_world",
478
490
  messages: [
479
491
  {
@@ -499,7 +511,7 @@ describe.each([
499
511
  settings: { locales: ["en", "en-US"], baseLocale: "en" },
500
512
  }),
501
513
  });
502
- await insertBundleNested(project, createBundleNested({
514
+ await insertBundleNested(project.db, createBundleNested({
503
515
  id: "exists_in_both",
504
516
  messages: [
505
517
  {
@@ -523,7 +535,7 @@ describe.each([
523
535
  },
524
536
  ],
525
537
  }));
526
- await insertBundleNested(project, createBundleNested({
538
+ await insertBundleNested(project.db, createBundleNested({
527
539
  id: "missing_in_en_US",
528
540
  messages: [
529
541
  {
@@ -552,7 +564,7 @@ describe.each([
552
564
  settings: { locales: ["en"], baseLocale: "en" },
553
565
  }),
554
566
  });
555
- await insertBundleNested(project, createBundleNested({
567
+ await insertBundleNested(project.db, createBundleNested({
556
568
  id: "happy🍌",
557
569
  messages: [
558
570
  {
@@ -578,7 +590,7 @@ describe.each([
578
590
  }),
579
591
  });
580
592
  // Create two bundles with the same name but different case
581
- await insertBundleNested(project, createBundleNested({
593
+ await insertBundleNested(project.db, createBundleNested({
582
594
  id: "Helloworld",
583
595
  messages: [
584
596
  {
@@ -593,7 +605,7 @@ describe.each([
593
605
  },
594
606
  ],
595
607
  }));
596
- await insertBundleNested(project, createBundleNested({
608
+ await insertBundleNested(project.db, createBundleNested({
597
609
  id: "helloworld",
598
610
  messages: [
599
611
  {
@@ -883,7 +895,7 @@ const mockBundles = [
883
895
  },
884
896
  ];
885
897
  for (const bundle of mockBundles) {
886
- await insertBundleNested(project, bundle);
898
+ await insertBundleNested(project.db, bundle);
887
899
  }
888
900
  function createBundleNested(args) {
889
901
  return {
@@ -4,6 +4,7 @@ export declare const defaultCompilerOptions: {
4
4
  readonly emitGitIgnore: true;
5
5
  readonly includeEslintDisableComment: true;
6
6
  readonly emitPrettierIgnore: true;
7
+ readonly emitTsDeclarations: false;
7
8
  readonly cleanOutdir: true;
8
9
  readonly disableAsyncLocalStorage: false;
9
10
  readonly experimentalMiddlewareLocaleSplitting: false;
@@ -164,6 +165,29 @@ export type CompilerOptions = {
164
165
  * @default true
165
166
  */
166
167
  emitPrettierIgnore?: boolean;
168
+ /**
169
+ * Emit `.d.ts` files for the generated output using the TypeScript compiler.
170
+ *
171
+ * Useful when `allowJs: true` cannot be set in your `tsconfig.json`
172
+ * (e.g., due to project constraints or conflicting compiler options).
173
+ *
174
+ * Requires `typescript` to be resolvable in your toolchain.
175
+ *
176
+ * **Note:** Enabling this option reduces compiler speed because TypeScript
177
+ * needs to generate declaration files for all output modules.
178
+ *
179
+ * @example
180
+ * ```ts
181
+ * await compile({
182
+ * project: "./project.inlang",
183
+ * outdir: "./src/paraglide",
184
+ * emitTsDeclarations: true,
185
+ * });
186
+ * ```
187
+ *
188
+ * @default false
189
+ */
190
+ emitTsDeclarations?: boolean;
167
191
  /**
168
192
  * https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy#url
169
193
  */
@@ -1 +1 @@
1
- {"version":3,"file":"compiler-options.d.ts","sourceRoot":"","sources":["../../src/compiler/compiler-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;CAcU,CAAC;AAE9C,MAAM,MAAM,eAAe,GAAG;IAC7B;;;;;;;;;;OAUG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;;;;;;OAUG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/B;;;;;;;;;;;;;;OAcG;IACH,qCAAqC,CAAC,EAAE,OAAO,CAAC;IAChD;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;;;;;;;;;;;;;;OAkBG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAA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,MAAM,CAAC;IACtB;;;;;;;;;;;;;;;;;;OAkBG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC;;;;;;;;;;;;OAYG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IACrC;;;;OAIG;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC;;;;;;;;;OASG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC;;;;;;;;;;;;OAYG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiDG;IACH,eAAe,CAAC,EAAE,gBAAgB,GAAG,iBAAiB,CAAC;IACvD;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;;OAIG;IACH,EAAE,CAAC,EAAE,GAAG,CAAC;CACT,CAAC"}
@@ -3,6 +3,7 @@ export const defaultCompilerOptions = {
3
3
  emitGitIgnore: true,
4
4
  includeEslintDisableComment: true,
5
5
  emitPrettierIgnore: true,
6
+ emitTsDeclarations: false,
6
7
  cleanOutdir: true,
7
8
  disableAsyncLocalStorage: false,
8
9
  experimentalMiddlewareLocaleSplitting: false,
@@ -1 +1 @@
1
- {"version":3,"file":"emit-ts-declarations.d.ts","sourceRoot":"","sources":["../../src/compiler/emit-ts-declarations.ts"],"names":[],"mappings":"AAIA;;;;;;;;;GASG;AACH,wBAAsB,kBAAkB,CACvC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA6HjC"}
1
+ {"version":3,"file":"emit-ts-declarations.d.ts","sourceRoot":"","sources":["../../src/compiler/emit-ts-declarations.ts"],"names":[],"mappings":"AAIA;;;;;;;;;GASG;AACH,wBAAsB,kBAAkB,CACvC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA8HjC"}
@@ -40,6 +40,7 @@ export async function emitTsDeclarations(output) {
40
40
  checkJs: true,
41
41
  declaration: true,
42
42
  emitDeclarationOnly: true,
43
+ isolatedDeclarations: true,
43
44
  esModuleInterop: true,
44
45
  lib: ["ESNext", "DOM"],
45
46
  module: ts.ModuleKind.ESNext,
@@ -1,5 +1,5 @@
1
1
  export const ENV_VARIABLES = {
2
2
  PARJS_APP_ID: "library.inlang.paraglideJs",
3
3
  PARJS_POSTHOG_TOKEN: undefined,
4
- PARJS_PACKAGE_VERSION: "2.6.0",
4
+ PARJS_PACKAGE_VERSION: "2.7.1",
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.6.0",
4
+ "version": "2.7.1",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -26,13 +26,13 @@
26
26
  "./urlpattern-polyfill": "./dist/urlpattern-polyfill/index.js"
27
27
  },
28
28
  "dependencies": {
29
+ "@inlang/sdk": "2.4.10",
29
30
  "commander": "11.1.0",
30
31
  "consola": "3.4.0",
31
32
  "json5": "2.2.3",
32
33
  "unplugin": "^2.1.2",
33
34
  "urlpattern-polyfill": "^10.0.0",
34
- "@inlang/recommend-sherlock": "0.2.1",
35
- "@inlang/sdk": "2.4.9"
35
+ "@inlang/recommend-sherlock": "0.2.1"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@rollup/plugin-virtual": "3.0.2",