@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.
- package/dist/bundler-plugins/unplugin.d.ts.map +1 -1
- package/dist/bundler-plugins/unplugin.js +10 -3
- package/dist/cli/steps/run-compiler.js +1 -1
- package/dist/compiler/compile-bundle.d.ts.map +1 -1
- package/dist/compiler/compile-bundle.js +9 -4
- package/dist/compiler/compile-bundle.test.js +11 -0
- package/dist/compiler/compile-message.d.ts +0 -3
- package/dist/compiler/compile-message.d.ts.map +1 -1
- package/dist/compiler/compile-message.js +14 -9
- package/dist/compiler/compile-message.test.js +25 -3
- package/dist/compiler/compile-project.d.ts.map +1 -1
- package/dist/compiler/compile-project.js +0 -3
- package/dist/compiler/compile-project.test.js +59 -66
- package/dist/compiler/compile.d.ts +41 -2
- package/dist/compiler/compile.d.ts.map +1 -1
- package/dist/compiler/compile.js +12 -4
- package/dist/compiler/compile.test.js +29 -7
- package/dist/compiler/jsdoc-types.d.ts +9 -3
- package/dist/compiler/jsdoc-types.d.ts.map +1 -1
- package/dist/compiler/jsdoc-types.js +15 -11
- package/dist/compiler/output-structure/locale-modules.d.ts.map +1 -1
- package/dist/compiler/output-structure/locale-modules.js +5 -8
- package/dist/compiler/runtime/assert-is-locale.js +1 -1
- package/dist/compiler/runtime/create-runtime.d.ts +3 -4
- package/dist/compiler/runtime/create-runtime.d.ts.map +1 -1
- package/dist/compiler/runtime/create-runtime.js +28 -11
- package/dist/compiler/runtime/de-localize-path.d.ts +2 -2
- package/dist/compiler/runtime/de-localize-path.d.ts.map +1 -1
- package/dist/compiler/runtime/de-localize-path.js +25 -6
- package/dist/compiler/runtime/de-localize-path.test.js +83 -21
- package/dist/compiler/runtime/de-localized-path.d.ts +27 -0
- package/dist/compiler/runtime/de-localized-path.d.ts.map +1 -0
- package/dist/compiler/runtime/de-localized-path.js +32 -0
- package/dist/compiler/runtime/de-localized-path.test.d.ts +2 -0
- package/dist/compiler/runtime/de-localized-path.test.d.ts.map +1 -0
- package/dist/compiler/runtime/de-localized-path.test.js +48 -0
- package/dist/compiler/runtime/detect-locale-from-request.d.ts +22 -0
- package/dist/compiler/runtime/detect-locale-from-request.d.ts.map +1 -0
- package/dist/compiler/runtime/detect-locale-from-request.js +44 -0
- package/dist/compiler/runtime/e2e.test.d.ts +2 -0
- package/dist/compiler/runtime/e2e.test.d.ts.map +1 -0
- package/dist/compiler/runtime/e2e.test.js +33 -0
- package/dist/compiler/runtime/extract-locale-from-cookie.js +1 -1
- package/dist/compiler/runtime/extract-locale-from-pathname.d.ts.map +1 -1
- package/dist/compiler/runtime/extract-locale-from-pathname.js +19 -3
- package/dist/compiler/runtime/extract-locale-from-pathname.test.js +83 -0
- package/dist/compiler/runtime/extract-locale-from-request.d.ts.map +1 -1
- package/dist/compiler/runtime/extract-locale-from-request.js +2 -4
- package/dist/compiler/runtime/extract-locale-from-request.test.js +5 -0
- package/dist/compiler/runtime/get-locale-from-path.d.ts +13 -0
- package/dist/compiler/runtime/get-locale-from-path.d.ts.map +1 -0
- package/dist/compiler/runtime/get-locale-from-path.js +17 -0
- package/dist/compiler/runtime/get-locale-from-path.test.d.ts +2 -0
- package/dist/compiler/runtime/get-locale-from-path.test.d.ts.map +1 -0
- package/dist/compiler/runtime/get-locale-from-path.test.js +22 -0
- package/dist/compiler/runtime/get-locale.d.ts.map +1 -1
- package/dist/compiler/runtime/get-locale.js +7 -5
- package/dist/compiler/runtime/get-locale.test.js +2 -2
- package/dist/compiler/runtime/is-locale.js +1 -1
- package/dist/compiler/runtime/jsdoc-runtime.d.ts +2 -0
- package/dist/compiler/runtime/jsdoc-runtime.d.ts.map +1 -0
- package/dist/compiler/runtime/jsdoc-runtime.js +131 -0
- package/dist/compiler/runtime/locale-in-path.d.ts +13 -0
- package/dist/compiler/runtime/locale-in-path.d.ts.map +1 -0
- package/dist/compiler/runtime/locale-in-path.js +17 -0
- package/dist/compiler/runtime/locale-in-path.test.d.ts +2 -0
- package/dist/compiler/runtime/locale-in-path.test.d.ts.map +1 -0
- package/dist/compiler/runtime/locale-in-path.test.js +22 -0
- package/dist/compiler/runtime/localize-path.d.ts +2 -2
- package/dist/compiler/runtime/localize-path.d.ts.map +1 -1
- package/dist/compiler/runtime/localize-path.js +61 -13
- package/dist/compiler/runtime/localize-path.test.js +192 -20
- package/dist/compiler/runtime/localized-path.d.ts +32 -0
- package/dist/compiler/runtime/localized-path.d.ts.map +1 -0
- package/dist/compiler/runtime/localized-path.js +44 -0
- package/dist/compiler/runtime/localized-path.test.d.ts +2 -0
- package/dist/compiler/runtime/localized-path.test.d.ts.map +1 -0
- package/dist/compiler/runtime/localized-path.test.js +42 -0
- package/dist/compiler/runtime/mock-runtime.d.ts +6 -0
- package/dist/compiler/runtime/mock-runtime.d.ts.map +1 -0
- package/dist/compiler/runtime/mock-runtime.js +31 -0
- package/dist/compiler/runtime/path-to-regexp.d.ts +2 -0
- package/dist/compiler/runtime/path-to-regexp.d.ts.map +1 -0
- package/dist/compiler/runtime/path-to-regexp.js +1 -0
- package/dist/compiler/runtime/pathname-pattern.d.ts +30 -0
- package/dist/compiler/runtime/pathname-pattern.d.ts.map +1 -0
- package/dist/compiler/runtime/pathname-pattern.js +99 -0
- package/dist/compiler/runtime/pathname-pattern.test.d.ts +2 -0
- package/dist/compiler/runtime/pathname-pattern.test.d.ts.map +1 -0
- package/dist/compiler/runtime/pathname-pattern.test.js +103 -0
- package/dist/compiler/runtime/set-locale.d.ts.map +1 -1
- package/dist/compiler/runtime/set-locale.js +5 -5
- package/dist/compiler/runtime/set-locale.test.js +1 -1
- package/dist/compiler/runtime/ts-runtime.d.ts +2 -0
- package/dist/compiler/runtime/ts-runtime.d.ts.map +1 -0
- package/dist/compiler/runtime/ts-runtime.js +119 -0
- package/dist/compiler/runtime/type.d.ts +2 -2
- package/dist/compiler/runtime/type.d.ts.map +1 -1
- package/dist/compiler/runtime/type.test.js +48 -11
- package/dist/compiler/runtime/variables.d.ts +46 -0
- package/dist/compiler/runtime/variables.d.ts.map +1 -0
- package/dist/compiler/runtime/variables.js +45 -0
- package/dist/compiler/strategy.d.ts +13 -0
- package/dist/compiler/strategy.d.ts.map +1 -0
- package/dist/compiler/strategy.js +12 -0
- package/dist/compiler/strategy.test.d.ts +2 -0
- package/dist/compiler/strategy.test.d.ts.map +1 -0
- package/dist/compiler/strategy.test.js +9 -0
- package/dist/path-to-regexp/index.d.ts +12 -0
- package/dist/path-to-regexp/index.d.ts.map +1 -0
- package/dist/path-to-regexp/index.js +11 -0
- package/dist/services/env-variables/index.js +1 -1
- package/dist/services/file-handling/write-output.d.ts +6 -1
- package/dist/services/file-handling/write-output.d.ts.map +1 -1
- package/dist/services/file-handling/write-output.js +33 -19
- package/dist/services/file-handling/write-output.test.js +60 -11
- package/dist/urlpattern-polyfill/index.d.ts +2 -0
- package/dist/urlpattern-polyfill/index.d.ts.map +1 -0
- package/dist/urlpattern-polyfill/index.js +1 -0
- package/package.json +12 -8
|
@@ -1,31 +1,45 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import crypto from "node:crypto";
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
7
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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(
|
|
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
|
-
|
|
21
|
-
|
|
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
|
|
24
|
-
|
|
33
|
+
//Only update the previousOutputHashes if the write was successful
|
|
34
|
+
return currentOutputHashes;
|
|
25
35
|
}
|
|
26
36
|
function hashOutput(output, outputDirectory) {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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(
|
|
38
|
-
|
|
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(
|
|
48
|
-
|
|
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 @@
|
|
|
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.
|
|
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/
|
|
29
|
-
"@inlang/
|
|
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.
|
|
46
|
-
},
|
|
47
|
-
"exports": {
|
|
48
|
-
".": "./dist/index.js"
|
|
52
|
+
"@opral/tsconfig": "1.1.0"
|
|
49
53
|
},
|
|
50
54
|
"keywords": [
|
|
51
55
|
"inlang",
|