@inlang/paraglide-js 2.0.0-beta.15 → 2.0.0-beta.17

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 (120) hide show
  1. package/dist/bundler-plugins/unplugin.d.ts.map +1 -1
  2. package/dist/bundler-plugins/unplugin.js +10 -3
  3. package/dist/cli/steps/run-compiler.js +1 -1
  4. package/dist/compiler/compile-bundle.d.ts.map +1 -1
  5. package/dist/compiler/compile-bundle.js +9 -4
  6. package/dist/compiler/compile-bundle.test.js +11 -0
  7. package/dist/compiler/compile-message.d.ts +0 -3
  8. package/dist/compiler/compile-message.d.ts.map +1 -1
  9. package/dist/compiler/compile-message.js +14 -9
  10. package/dist/compiler/compile-message.test.js +25 -3
  11. package/dist/compiler/compile-project.d.ts.map +1 -1
  12. package/dist/compiler/compile-project.js +0 -3
  13. package/dist/compiler/compile-project.test.js +59 -66
  14. package/dist/compiler/compile.d.ts +41 -2
  15. package/dist/compiler/compile.d.ts.map +1 -1
  16. package/dist/compiler/compile.js +12 -4
  17. package/dist/compiler/compile.test.js +29 -7
  18. package/dist/compiler/jsdoc-types.d.ts +9 -3
  19. package/dist/compiler/jsdoc-types.d.ts.map +1 -1
  20. package/dist/compiler/jsdoc-types.js +15 -11
  21. package/dist/compiler/output-structure/locale-modules.d.ts.map +1 -1
  22. package/dist/compiler/output-structure/locale-modules.js +5 -8
  23. package/dist/compiler/runtime/assert-is-locale.js +1 -1
  24. package/dist/compiler/runtime/create-runtime.d.ts +3 -4
  25. package/dist/compiler/runtime/create-runtime.d.ts.map +1 -1
  26. package/dist/compiler/runtime/create-runtime.js +28 -11
  27. package/dist/compiler/runtime/de-localize-path.d.ts +2 -2
  28. package/dist/compiler/runtime/de-localize-path.d.ts.map +1 -1
  29. package/dist/compiler/runtime/de-localize-path.js +25 -6
  30. package/dist/compiler/runtime/de-localize-path.test.js +83 -21
  31. package/dist/compiler/runtime/de-localized-path.d.ts +27 -0
  32. package/dist/compiler/runtime/de-localized-path.d.ts.map +1 -0
  33. package/dist/compiler/runtime/de-localized-path.js +32 -0
  34. package/dist/compiler/runtime/de-localized-path.test.d.ts +2 -0
  35. package/dist/compiler/runtime/de-localized-path.test.d.ts.map +1 -0
  36. package/dist/compiler/runtime/de-localized-path.test.js +48 -0
  37. package/dist/compiler/runtime/detect-locale-from-request.d.ts +22 -0
  38. package/dist/compiler/runtime/detect-locale-from-request.d.ts.map +1 -0
  39. package/dist/compiler/runtime/detect-locale-from-request.js +44 -0
  40. package/dist/compiler/runtime/e2e.test.d.ts +2 -0
  41. package/dist/compiler/runtime/e2e.test.d.ts.map +1 -0
  42. package/dist/compiler/runtime/e2e.test.js +33 -0
  43. package/dist/compiler/runtime/extract-locale-from-cookie.js +1 -1
  44. package/dist/compiler/runtime/extract-locale-from-pathname.d.ts.map +1 -1
  45. package/dist/compiler/runtime/extract-locale-from-pathname.js +19 -3
  46. package/dist/compiler/runtime/extract-locale-from-pathname.test.js +83 -0
  47. package/dist/compiler/runtime/extract-locale-from-request.d.ts.map +1 -1
  48. package/dist/compiler/runtime/extract-locale-from-request.js +2 -4
  49. package/dist/compiler/runtime/extract-locale-from-request.test.js +5 -0
  50. package/dist/compiler/runtime/get-locale-from-path.d.ts +13 -0
  51. package/dist/compiler/runtime/get-locale-from-path.d.ts.map +1 -0
  52. package/dist/compiler/runtime/get-locale-from-path.js +17 -0
  53. package/dist/compiler/runtime/get-locale-from-path.test.d.ts +2 -0
  54. package/dist/compiler/runtime/get-locale-from-path.test.d.ts.map +1 -0
  55. package/dist/compiler/runtime/get-locale-from-path.test.js +22 -0
  56. package/dist/compiler/runtime/get-locale.d.ts.map +1 -1
  57. package/dist/compiler/runtime/get-locale.js +7 -5
  58. package/dist/compiler/runtime/get-locale.test.js +2 -2
  59. package/dist/compiler/runtime/is-locale.js +1 -1
  60. package/dist/compiler/runtime/jsdoc-runtime.d.ts +2 -0
  61. package/dist/compiler/runtime/jsdoc-runtime.d.ts.map +1 -0
  62. package/dist/compiler/runtime/jsdoc-runtime.js +131 -0
  63. package/dist/compiler/runtime/locale-in-path.d.ts +13 -0
  64. package/dist/compiler/runtime/locale-in-path.d.ts.map +1 -0
  65. package/dist/compiler/runtime/locale-in-path.js +17 -0
  66. package/dist/compiler/runtime/locale-in-path.test.d.ts +2 -0
  67. package/dist/compiler/runtime/locale-in-path.test.d.ts.map +1 -0
  68. package/dist/compiler/runtime/locale-in-path.test.js +22 -0
  69. package/dist/compiler/runtime/localize-path.d.ts +2 -2
  70. package/dist/compiler/runtime/localize-path.d.ts.map +1 -1
  71. package/dist/compiler/runtime/localize-path.js +61 -13
  72. package/dist/compiler/runtime/localize-path.test.js +192 -20
  73. package/dist/compiler/runtime/localized-path.d.ts +32 -0
  74. package/dist/compiler/runtime/localized-path.d.ts.map +1 -0
  75. package/dist/compiler/runtime/localized-path.js +44 -0
  76. package/dist/compiler/runtime/localized-path.test.d.ts +2 -0
  77. package/dist/compiler/runtime/localized-path.test.d.ts.map +1 -0
  78. package/dist/compiler/runtime/localized-path.test.js +42 -0
  79. package/dist/compiler/runtime/mock-runtime.d.ts +6 -0
  80. package/dist/compiler/runtime/mock-runtime.d.ts.map +1 -0
  81. package/dist/compiler/runtime/mock-runtime.js +31 -0
  82. package/dist/compiler/runtime/path-to-regexp.d.ts +2 -0
  83. package/dist/compiler/runtime/path-to-regexp.d.ts.map +1 -0
  84. package/dist/compiler/runtime/path-to-regexp.js +1 -0
  85. package/dist/compiler/runtime/pathname-pattern.d.ts +30 -0
  86. package/dist/compiler/runtime/pathname-pattern.d.ts.map +1 -0
  87. package/dist/compiler/runtime/pathname-pattern.js +99 -0
  88. package/dist/compiler/runtime/pathname-pattern.test.d.ts +2 -0
  89. package/dist/compiler/runtime/pathname-pattern.test.d.ts.map +1 -0
  90. package/dist/compiler/runtime/pathname-pattern.test.js +103 -0
  91. package/dist/compiler/runtime/set-locale.d.ts.map +1 -1
  92. package/dist/compiler/runtime/set-locale.js +5 -5
  93. package/dist/compiler/runtime/set-locale.test.js +1 -1
  94. package/dist/compiler/runtime/ts-runtime.d.ts +2 -0
  95. package/dist/compiler/runtime/ts-runtime.d.ts.map +1 -0
  96. package/dist/compiler/runtime/ts-runtime.js +119 -0
  97. package/dist/compiler/runtime/type.d.ts +2 -2
  98. package/dist/compiler/runtime/type.d.ts.map +1 -1
  99. package/dist/compiler/runtime/type.test.js +48 -11
  100. package/dist/compiler/runtime/variables.d.ts +46 -0
  101. package/dist/compiler/runtime/variables.d.ts.map +1 -0
  102. package/dist/compiler/runtime/variables.js +45 -0
  103. package/dist/compiler/strategy.d.ts +13 -0
  104. package/dist/compiler/strategy.d.ts.map +1 -0
  105. package/dist/compiler/strategy.js +12 -0
  106. package/dist/compiler/strategy.test.d.ts +2 -0
  107. package/dist/compiler/strategy.test.d.ts.map +1 -0
  108. package/dist/compiler/strategy.test.js +9 -0
  109. package/dist/path-to-regexp/index.d.ts +12 -0
  110. package/dist/path-to-regexp/index.d.ts.map +1 -0
  111. package/dist/path-to-regexp/index.js +11 -0
  112. package/dist/services/env-variables/index.js +1 -1
  113. package/dist/services/file-handling/write-output.d.ts +6 -1
  114. package/dist/services/file-handling/write-output.d.ts.map +1 -1
  115. package/dist/services/file-handling/write-output.js +33 -19
  116. package/dist/services/file-handling/write-output.test.js +60 -11
  117. package/dist/urlpattern-polyfill/index.d.ts +2 -0
  118. package/dist/urlpattern-polyfill/index.d.ts.map +1 -0
  119. package/dist/urlpattern-polyfill/index.js +1 -0
  120. package/package.json +12 -8
@@ -1,31 +1,45 @@
1
1
  import path from "node:path";
2
2
  import crypto from "node:crypto";
3
- let previousOutputHash;
4
- export async function writeOutput(outputDirectory, output, fs) {
3
+ export async function writeOutput(args) {
4
+ const currentOutputHashes = hashOutput(args.output, args.directory);
5
5
  // if the output hasn't changed, don't write it
6
- const currentOutputHash = hashOutput(output, outputDirectory);
7
- if (currentOutputHash === previousOutputHash)
6
+ const changedFiles = new Set();
7
+ for (const [filePath, hash] of Object.entries(currentOutputHashes)) {
8
+ if (args.previousOutputHashes?.[filePath] !== hash) {
9
+ changedFiles.add(filePath);
10
+ }
11
+ }
12
+ if (changedFiles.size === 0) {
8
13
  return;
9
- // clear the output directory
10
- await fs.rm(outputDirectory, { recursive: true, force: true });
11
- await fs.mkdir(outputDirectory, { recursive: true });
14
+ }
15
+ // disabled because of https://github.com/opral/inlang-paraglide-js/issues/350
16
+ // // clear the output directory
17
+ // await args.fs.rm(args.outputDirectory, { recursive: true, force: true });
18
+ await args.fs.mkdir(args.directory, { recursive: true });
12
19
  //Create missing directories inside the output directory
13
- await Promise.allSettled(Object.keys(output).map(async (filePath) => {
14
- const fullPath = path.resolve(outputDirectory, filePath);
20
+ await Promise.allSettled(Object.keys(args.output).map(async (filePath) => {
21
+ const fullPath = path.resolve(args.directory, filePath);
15
22
  const directory = path.dirname(fullPath);
16
- await fs.mkdir(directory, { recursive: true });
23
+ await args.fs.mkdir(directory, { recursive: true });
17
24
  }));
18
25
  //Write files
19
- await Promise.allSettled(Object.entries(output).map(async ([filePath, fileContent]) => {
20
- const fullPath = path.resolve(outputDirectory, filePath);
21
- await fs.writeFile(fullPath, fileContent);
26
+ await Promise.allSettled(Object.entries(args.output).map(async ([filePath, fileContent]) => {
27
+ if (!changedFiles.has(filePath)) {
28
+ return;
29
+ }
30
+ const fullPath = path.resolve(args.directory, filePath);
31
+ await args.fs.writeFile(fullPath, fileContent);
22
32
  }));
23
- //Only update the previousOutputHash if the write was successful
24
- previousOutputHash = currentOutputHash;
33
+ //Only update the previousOutputHashes if the write was successful
34
+ return currentOutputHashes;
25
35
  }
26
36
  function hashOutput(output, outputDirectory) {
27
- const hash = crypto.createHash("sha256");
28
- hash.update(JSON.stringify(output));
29
- hash.update(outputDirectory);
30
- return hash.digest("hex");
37
+ const hashes = {};
38
+ for (const [filePath, fileContent] of Object.entries(output)) {
39
+ const hash = crypto.createHash("sha256");
40
+ hash.update(fileContent);
41
+ hash.update(path.resolve(outputDirectory, filePath));
42
+ hashes[filePath] = hash.digest("hex");
43
+ }
44
+ return hashes;
31
45
  }
@@ -6,26 +6,38 @@ beforeEach(() => {
6
6
  it("should write the output to a non-existing directory", async () => {
7
7
  const { writeOutput } = await import("./write-output.js");
8
8
  const fs = mockFs({});
9
- await writeOutput("/output", { "test.txt": "test" }, fs);
9
+ await writeOutput({
10
+ directory: "/output",
11
+ output: { "test.txt": "test" },
12
+ fs,
13
+ });
10
14
  expect(await fs.readFile("/output/test.txt", { encoding: "utf-8" })).toBe("test");
11
15
  });
12
- it("should clear & overwrite output that's already there", async () => {
16
+ it.skip("should clear & overwrite output that's already there", async () => {
13
17
  const { writeOutput } = await import("./write-output.js");
14
18
  const fs = mockFs({
15
19
  "/output/test.txt": "old",
16
20
  "/output/other.txt": "other",
17
21
  });
18
- await writeOutput("/output", { "test.txt": "new" }, fs);
22
+ await writeOutput({
23
+ directory: "/output",
24
+ output: { "test.txt": "new" },
25
+ fs,
26
+ });
19
27
  expect(await fs.readFile("/output/test.txt", { encoding: "utf-8" })).toBe("new");
20
28
  await expect(async () => await fs.readFile("/output/other.txt", { encoding: "utf-8" })).rejects.toBeDefined();
21
29
  });
22
30
  it("should create any missing directories", async () => {
23
31
  const { writeOutput } = await import("./write-output.js");
24
32
  const fs = mockFs({});
25
- await writeOutput("/output/messages", {
26
- "de/test.txt": "de",
27
- "en/test.txt": "en",
28
- }, fs);
33
+ await writeOutput({
34
+ directory: "/output/messages",
35
+ output: {
36
+ "de/test.txt": "de",
37
+ "en/test.txt": "en",
38
+ },
39
+ fs,
40
+ });
29
41
  expect(await fs.readFile("/output/messages/de/test.txt", { encoding: "utf-8" })).toBe("de");
30
42
  expect(await fs.readFile("/output/messages/en/test.txt", { encoding: "utf-8" })).toBe("en");
31
43
  });
@@ -34,8 +46,17 @@ it("should only write once if the output hasn't changed", async () => {
34
46
  const fs = mockFs({});
35
47
  // @ts-expect-error - spy
36
48
  fs.writeFile = vi.spyOn(fs, "writeFile");
37
- await writeOutput("/output", { "test.txt": "test" }, fs);
38
- await writeOutput("/output", { "test.txt": "test" }, fs);
49
+ const hashes = await writeOutput({
50
+ directory: "/output",
51
+ output: { "test.txt": "test" },
52
+ fs,
53
+ });
54
+ await writeOutput({
55
+ directory: "/output",
56
+ output: { "test.txt": "test" },
57
+ fs,
58
+ previousOutputHashes: hashes,
59
+ });
39
60
  expect(await fs.readFile("/output/test.txt", { encoding: "utf-8" })).toBe("test");
40
61
  expect(fs.writeFile).toHaveBeenCalledTimes(1);
41
62
  });
@@ -44,11 +65,39 @@ it("should write again if the output has changed", async () => {
44
65
  const fs = mockFs({});
45
66
  // @ts-expect-error - spy
46
67
  fs.writeFile = vi.spyOn(fs, "writeFile");
47
- await writeOutput("/output", { "test.txt": "test" }, fs);
48
- await writeOutput("/output", { "test.txt": "test2" }, fs);
68
+ const hashes = await writeOutput({
69
+ directory: "/output",
70
+ output: { "test.txt": "test" },
71
+ fs,
72
+ });
73
+ await writeOutput({
74
+ directory: "/output",
75
+ output: { "test.txt": "test2" },
76
+ fs,
77
+ previousOutputHashes: hashes,
78
+ });
49
79
  expect(await fs.readFile("/output/test.txt", { encoding: "utf-8" })).toBe("test2");
50
80
  expect(fs.writeFile).toHaveBeenCalledTimes(2);
51
81
  });
82
+ it("should write files if output has partially changed", async () => {
83
+ const { writeOutput } = await import("./write-output.js");
84
+ const fs = mockFs({});
85
+ // @ts-expect-error - spy
86
+ fs.writeFile = vi.spyOn(fs, "writeFile");
87
+ const hashes = await writeOutput({
88
+ directory: "/output",
89
+ output: { "file1.txt": "test", "file2.txt": "test" },
90
+ fs,
91
+ });
92
+ await writeOutput({
93
+ directory: "/output",
94
+ output: { "file1.txt": "test", "file2.txt": "test2" },
95
+ fs,
96
+ previousOutputHashes: hashes,
97
+ });
98
+ expect(fs.writeFile).toHaveBeenCalledWith("/output/file2.txt", "test2");
99
+ expect(fs.writeFile).toHaveBeenCalledTimes(3);
100
+ });
52
101
  const mockFs = (files) => {
53
102
  const _memfs = memfs.createFsFromVolume(memfs.Volume.fromJSON(files));
54
103
  return _memfs.promises;
@@ -0,0 +1,2 @@
1
+ export * from "urlpattern-polyfill";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/urlpattern-polyfill/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1 @@
1
+ export * from "urlpattern-polyfill";
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.15",
4
+ "version": "2.0.0-beta.17",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -20,13 +20,20 @@
20
20
  "./dist",
21
21
  "./bin"
22
22
  ],
23
+ "exports": {
24
+ ".": "./dist/index.js",
25
+ "./path-to-regexp": "./dist/path-to-regexp/index.js"
26
+ },
27
+ "_comment": "Required for tree-shaking https://webpack.js.org/guides/tree-shaking/#mark-the-file-as-side-effect-free",
28
+ "sideEffects": false,
23
29
  "dependencies": {
24
30
  "commander": "11.1.0",
25
31
  "consola": "3.4.0",
26
32
  "json5": "2.2.3",
33
+ "path-to-regexp": "^8.2.0",
27
34
  "unplugin": "^2.1.2",
28
- "@inlang/sdk": "2.1.2",
29
- "@inlang/recommend-sherlock": "0.2.1"
35
+ "@inlang/recommend-sherlock": "0.2.1",
36
+ "@inlang/sdk": "2.2.0"
30
37
  },
31
38
  "devDependencies": {
32
39
  "@eslint/js": "^9.18.0",
@@ -38,14 +45,11 @@
38
45
  "memfs": "4.17.0",
39
46
  "prettier": "^3.4.2",
40
47
  "rolldown": "1.0.0-beta.1",
41
- "typescript-eslint": "^8.20.0",
42
48
  "typescript": "^5.7.3",
49
+ "typescript-eslint": "^8.20.0",
43
50
  "vitest": "2.1.8",
44
51
  "@inlang/plugin-message-format": "3.1.1",
45
- "@opral/tsconfig": "1.0.0"
46
- },
47
- "exports": {
48
- ".": "./dist/index.js"
52
+ "@opral/tsconfig": "1.1.0"
49
53
  },
50
54
  "keywords": [
51
55
  "inlang",