@inlang/sdk 0.4.0 → 0.5.0
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/adapter/solidAdapter.d.ts +2 -2
- package/dist/adapter/solidAdapter.d.ts.map +1 -1
- package/dist/adapter/solidAdapter.js +2 -2
- package/dist/adapter/solidAdapter.test.js +68 -78
- package/dist/api.d.ts +10 -6
- package/dist/api.d.ts.map +1 -1
- package/dist/api.test-d.d.ts +2 -0
- package/dist/api.test-d.d.ts.map +1 -0
- package/dist/api.test-d.js +4 -0
- package/dist/createMessageLintReportsQuery.d.ts +2 -2
- package/dist/createMessageLintReportsQuery.d.ts.map +1 -1
- package/dist/createMessageLintReportsQuery.js +11 -11
- package/dist/createMessagesQuery.js +1 -1
- package/dist/errors.d.ts +3 -3
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +6 -6
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/lint/message/lintMessages.d.ts +3 -7
- package/dist/lint/message/lintMessages.d.ts.map +1 -1
- package/dist/lint/message/lintMessages.test.js +38 -36
- package/dist/lint/message/lintSingleMessage.d.ts +3 -7
- package/dist/lint/message/lintSingleMessage.d.ts.map +1 -1
- package/dist/lint/message/lintSingleMessage.js +10 -10
- package/dist/lint/message/lintSingleMessage.test.js +71 -65
- package/dist/{openInlangProject.d.ts → loadProject.d.ts} +3 -3
- package/dist/loadProject.d.ts.map +1 -0
- package/dist/{openInlangProject.js → loadProject.js} +70 -66
- package/dist/loadProject.test.d.ts +2 -0
- package/dist/loadProject.test.d.ts.map +1 -0
- package/dist/{openInlangProject.test.js → loadProject.test.js} +160 -176
- package/dist/parseConfig.d.ts +2 -2
- package/dist/parseConfig.d.ts.map +1 -1
- package/dist/parseConfig.js +3 -3
- package/dist/resolve-modules/message-lint-rules/resolveMessageLintRules.js +1 -1
- package/dist/resolve-modules/plugins/errors.d.ts +1 -1
- package/dist/resolve-modules/plugins/errors.d.ts.map +1 -1
- package/dist/resolve-modules/plugins/resolvePlugins.js +15 -15
- package/dist/resolve-modules/plugins/resolvePlugins.test.js +55 -94
- package/dist/resolve-modules/plugins/types.d.ts +1 -1
- package/dist/resolve-modules/plugins/types.d.ts.map +1 -1
- package/dist/resolve-modules/plugins/types.test.js +10 -14
- package/dist/resolve-modules/resolveModules.d.ts.map +1 -1
- package/dist/resolve-modules/resolveModules.js +9 -9
- package/dist/resolve-modules/resolveModules.test.js +28 -42
- package/dist/resolve-modules/types.d.ts +3 -3
- package/dist/resolve-modules/types.d.ts.map +1 -1
- package/dist/versionedInterfaces.d.ts +1 -1
- package/dist/versionedInterfaces.d.ts.map +1 -1
- package/dist/versionedInterfaces.js +1 -1
- package/package.json +2 -2
- package/src/adapter/solidAdapter.test.ts +77 -87
- package/src/adapter/solidAdapter.ts +4 -4
- package/src/api.test-d.ts +8 -0
- package/src/api.ts +10 -6
- package/src/createMessageLintReportsQuery.ts +15 -20
- package/src/createMessagesQuery.ts +1 -1
- package/src/errors.ts +6 -6
- package/src/index.ts +4 -4
- package/src/lint/message/lintMessages.test.ts +38 -36
- package/src/lint/message/lintMessages.ts +3 -11
- package/src/lint/message/lintSingleMessage.test.ts +71 -65
- package/src/lint/message/lintSingleMessage.ts +13 -21
- package/src/{openInlangProject.test.ts → loadProject.test.ts} +165 -181
- package/src/{openInlangProject.ts → loadProject.ts} +81 -82
- package/src/parseConfig.ts +5 -3
- package/src/resolve-modules/message-lint-rules/resolveMessageLintRules.ts +1 -1
- package/src/resolve-modules/plugins/errors.ts +1 -1
- package/src/resolve-modules/plugins/resolvePlugins.test.ts +55 -94
- package/src/resolve-modules/plugins/resolvePlugins.ts +19 -19
- package/src/resolve-modules/plugins/types.test.ts +11 -15
- package/src/resolve-modules/plugins/types.ts +1 -1
- package/src/resolve-modules/resolveModules.test.ts +29 -43
- package/src/resolve-modules/resolveModules.ts +11 -9
- package/src/resolve-modules/types.ts +3 -3
- package/src/versionedInterfaces.ts +1 -1
- package/dist/openInlangProject.d.ts.map +0 -1
- package/dist/openInlangProject.test.d.ts +0 -2
- package/dist/openInlangProject.test.d.ts.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
2
|
import { describe, it, expect, vi } from "vitest";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { loadProject } from "./loadProject.js";
|
|
4
|
+
import { ProjectSettingsFileJSONSyntaxError, ProjectSettingsFileNotFoundError, ProjectSettingsInvalidError, } from "./errors.js";
|
|
5
5
|
import { createNodeishMemoryFs } from "@lix-js/fs";
|
|
6
6
|
// ------------------------------------------------------------------------------------------------
|
|
7
7
|
const getValue = (subscribable) => {
|
|
@@ -9,30 +9,26 @@ const getValue = (subscribable) => {
|
|
|
9
9
|
subscribable.subscribe((v) => void (value = v));
|
|
10
10
|
return value;
|
|
11
11
|
};
|
|
12
|
-
const
|
|
12
|
+
const settings = {
|
|
13
13
|
sourceLanguageTag: "en",
|
|
14
14
|
languageTags: ["en"],
|
|
15
15
|
modules: ["plugin.js", "lintRule.js"],
|
|
16
|
-
|
|
17
|
-
"project.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
variableReferencePattern: ["{", "}"],
|
|
23
|
-
},
|
|
16
|
+
messageLintRuleLevels: {
|
|
17
|
+
"messageLintRule.project.missingTranslation": "error",
|
|
18
|
+
},
|
|
19
|
+
"plugin.project.i18next": {
|
|
20
|
+
pathPattern: "./examples/example01/{languageTag}.json",
|
|
21
|
+
variableReferencePattern: ["{", "}"],
|
|
24
22
|
},
|
|
25
23
|
};
|
|
26
24
|
const mockPlugin = {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
displayName: { en: "Mock Plugin" },
|
|
31
|
-
},
|
|
25
|
+
id: "plugin.project.i18next",
|
|
26
|
+
description: { en: "Mock plugin description" },
|
|
27
|
+
displayName: { en: "Mock Plugin" },
|
|
32
28
|
loadMessages: () => exampleMessages,
|
|
33
29
|
saveMessages: () => undefined,
|
|
34
30
|
addCustomApi: () => ({
|
|
35
|
-
"app.
|
|
31
|
+
"app.project.ideExtension": {
|
|
36
32
|
messageReferenceMatcher: (text) => text,
|
|
37
33
|
},
|
|
38
34
|
}),
|
|
@@ -73,74 +69,72 @@ const exampleMessages = [
|
|
|
73
69
|
},
|
|
74
70
|
];
|
|
75
71
|
const mockMessageLintRule = {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
},
|
|
81
|
-
message: () => undefined,
|
|
72
|
+
id: "messageLintRule.project.mock",
|
|
73
|
+
description: { en: "Mock lint rule description" },
|
|
74
|
+
displayName: { en: "Mock Lint Rule" },
|
|
75
|
+
run: () => undefined,
|
|
82
76
|
};
|
|
83
77
|
const _import = async (name) => ({
|
|
84
78
|
default: name === "plugin.js" ? mockPlugin : mockMessageLintRule,
|
|
85
79
|
});
|
|
86
80
|
// ------------------------------------------------------------------------------------------------
|
|
87
81
|
describe("initialization", () => {
|
|
88
|
-
describe("
|
|
89
|
-
it("should return an error if
|
|
82
|
+
describe("settings", () => {
|
|
83
|
+
it("should return an error if settings file is not found", async () => {
|
|
90
84
|
const fs = createNodeishMemoryFs();
|
|
91
|
-
const
|
|
92
|
-
|
|
85
|
+
const project = await loadProject({
|
|
86
|
+
settingsFilePath: "./test.json",
|
|
93
87
|
nodeishFs: fs,
|
|
94
88
|
_import,
|
|
95
89
|
});
|
|
96
|
-
expect(
|
|
90
|
+
expect(project.errors()[0]).toBeInstanceOf(ProjectSettingsFileNotFoundError);
|
|
97
91
|
});
|
|
98
|
-
it("should return an error if
|
|
92
|
+
it("should return an error if settings file is not a valid JSON", async () => {
|
|
99
93
|
const fs = await createNodeishMemoryFs();
|
|
100
94
|
await fs.writeFile("./project.inlang.json", "invalid json");
|
|
101
|
-
const
|
|
102
|
-
|
|
95
|
+
const project = await loadProject({
|
|
96
|
+
settingsFilePath: "./project.inlang.json",
|
|
103
97
|
nodeishFs: fs,
|
|
104
98
|
_import,
|
|
105
99
|
});
|
|
106
|
-
expect(
|
|
100
|
+
expect(project.errors()[0]).toBeInstanceOf(ProjectSettingsFileJSONSyntaxError);
|
|
107
101
|
});
|
|
108
|
-
it("should return an error if
|
|
102
|
+
it("should return an error if settings file is does not match schema", async () => {
|
|
109
103
|
const fs = await createNodeishMemoryFs();
|
|
110
104
|
await fs.writeFile("./project.inlang.json", JSON.stringify({}));
|
|
111
|
-
const
|
|
112
|
-
|
|
105
|
+
const project = await loadProject({
|
|
106
|
+
settingsFilePath: "./project.inlang.json",
|
|
113
107
|
nodeishFs: fs,
|
|
114
108
|
_import,
|
|
115
109
|
});
|
|
116
|
-
expect(
|
|
110
|
+
expect(project.errors()[0]).toBeInstanceOf(ProjectSettingsInvalidError);
|
|
117
111
|
});
|
|
118
|
-
it("should return the parsed
|
|
112
|
+
it("should return the parsed settings", async () => {
|
|
119
113
|
const fs = await createNodeishMemoryFs();
|
|
120
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
121
|
-
const
|
|
122
|
-
|
|
114
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings));
|
|
115
|
+
const project = await loadProject({
|
|
116
|
+
settingsFilePath: "./project.inlang.json",
|
|
123
117
|
nodeishFs: fs,
|
|
124
118
|
_import,
|
|
125
119
|
});
|
|
126
|
-
expect(
|
|
120
|
+
expect(project.settings()).toStrictEqual(settings);
|
|
127
121
|
});
|
|
128
|
-
it("should not re-write the
|
|
122
|
+
it("should not re-write the settings to disk when initializing", async () => {
|
|
129
123
|
const fs = await createNodeishMemoryFs();
|
|
130
|
-
const
|
|
131
|
-
await fs.writeFile("./project.inlang.json",
|
|
132
|
-
const
|
|
133
|
-
|
|
124
|
+
const settingsWithDeifferentFormatting = JSON.stringify(settings, undefined, 4);
|
|
125
|
+
await fs.writeFile("./project.inlang.json", settingsWithDeifferentFormatting);
|
|
126
|
+
const project = await loadProject({
|
|
127
|
+
settingsFilePath: "./project.inlang.json",
|
|
134
128
|
nodeishFs: fs,
|
|
135
129
|
_import,
|
|
136
130
|
});
|
|
137
|
-
const
|
|
138
|
-
expect(
|
|
139
|
-
|
|
140
|
-
// TODO: how can we await `
|
|
131
|
+
const settingsOnDisk = await fs.readFile("./project.inlang.json", { encoding: "utf-8" });
|
|
132
|
+
expect(settingsOnDisk).toBe(settingsWithDeifferentFormatting);
|
|
133
|
+
project.setSettings(project.settings());
|
|
134
|
+
// TODO: how can we await `setsettings` correctly
|
|
141
135
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
142
|
-
const
|
|
143
|
-
expect(
|
|
136
|
+
const newsettingsOnDisk = await fs.readFile("./project.inlang.json", { encoding: "utf-8" });
|
|
137
|
+
expect(newsettingsOnDisk).not.toBe(settingsWithDeifferentFormatting);
|
|
144
138
|
});
|
|
145
139
|
});
|
|
146
140
|
describe("modules", () => {
|
|
@@ -149,13 +143,13 @@ describe("initialization", () => {
|
|
|
149
143
|
default: {},
|
|
150
144
|
});
|
|
151
145
|
const fs = createNodeishMemoryFs();
|
|
152
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
153
|
-
const
|
|
154
|
-
|
|
146
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings));
|
|
147
|
+
const project = await loadProject({
|
|
148
|
+
settingsFilePath: "./project.inlang.json",
|
|
155
149
|
nodeishFs: fs,
|
|
156
150
|
_import: $badImport,
|
|
157
151
|
});
|
|
158
|
-
expect(
|
|
152
|
+
expect(project.errors()).not.toHaveLength(0);
|
|
159
153
|
});
|
|
160
154
|
// it.todo("should throw if lintRules contain errors ???")
|
|
161
155
|
// it.todo("should return meta data")
|
|
@@ -164,7 +158,7 @@ describe("initialization", () => {
|
|
|
164
158
|
});
|
|
165
159
|
describe("flow", () => {
|
|
166
160
|
it.todo("should not call functions multiple times");
|
|
167
|
-
it.todo("should load modules after
|
|
161
|
+
it.todo("should load modules after settings");
|
|
168
162
|
it.todo("should not load messages");
|
|
169
163
|
it.todo("should not call lint");
|
|
170
164
|
});
|
|
@@ -173,58 +167,61 @@ describe("initialization", () => {
|
|
|
173
167
|
});
|
|
174
168
|
});
|
|
175
169
|
describe("functionality", () => {
|
|
176
|
-
describe("
|
|
177
|
-
it("should return the
|
|
170
|
+
describe("settings", () => {
|
|
171
|
+
it("should return the settings", async () => {
|
|
178
172
|
const fs = await createNodeishMemoryFs();
|
|
179
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
180
|
-
const
|
|
181
|
-
|
|
173
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings));
|
|
174
|
+
const project = await loadProject({
|
|
175
|
+
settingsFilePath: "./project.inlang.json",
|
|
182
176
|
nodeishFs: fs,
|
|
183
177
|
_import,
|
|
184
178
|
});
|
|
185
|
-
expect(getValue(
|
|
179
|
+
expect(getValue(project.settings)).toStrictEqual(settings);
|
|
186
180
|
});
|
|
187
|
-
it("should set a new
|
|
181
|
+
it("should set a new settings", async () => {
|
|
188
182
|
const fs = await createNodeishMemoryFs();
|
|
189
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
190
|
-
const
|
|
191
|
-
|
|
183
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings));
|
|
184
|
+
const project = await loadProject({
|
|
185
|
+
settingsFilePath: "./project.inlang.json",
|
|
192
186
|
nodeishFs: fs,
|
|
193
187
|
_import,
|
|
194
188
|
});
|
|
195
|
-
expect(
|
|
196
|
-
|
|
197
|
-
expect(getValue(
|
|
198
|
-
expect(
|
|
199
|
-
|
|
200
|
-
expect(getValue(
|
|
201
|
-
|
|
189
|
+
expect(project.settings()).toStrictEqual(settings);
|
|
190
|
+
project.setSettings({ ...settings, languageTags: ["en", "de"] });
|
|
191
|
+
expect(getValue(project.settings)).toStrictEqual({ ...settings, languageTags: ["en", "de"] });
|
|
192
|
+
expect(project.settings().languageTags).toStrictEqual(["en", "de"]);
|
|
193
|
+
project.setSettings({ ...settings, languageTags: ["en", "de", "fr"] });
|
|
194
|
+
expect(getValue(project.settings)).toStrictEqual({
|
|
195
|
+
...settings,
|
|
196
|
+
languageTags: ["en", "de", "fr"],
|
|
197
|
+
});
|
|
198
|
+
expect(project.settings().languageTags).toStrictEqual(["en", "de", "fr"]);
|
|
202
199
|
});
|
|
203
200
|
});
|
|
204
|
-
describe("
|
|
205
|
-
it("should fail if
|
|
201
|
+
describe("setSettings", () => {
|
|
202
|
+
it("should fail if settings is not valid", async () => {
|
|
206
203
|
const fs = await createNodeishMemoryFs();
|
|
207
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
208
|
-
const
|
|
209
|
-
|
|
204
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings));
|
|
205
|
+
const project = await loadProject({
|
|
206
|
+
settingsFilePath: "./project.inlang.json",
|
|
210
207
|
nodeishFs: fs,
|
|
211
208
|
_import,
|
|
212
209
|
});
|
|
213
|
-
const result =
|
|
210
|
+
const result = project.setSettings({});
|
|
214
211
|
expect(result.data).toBeUndefined();
|
|
215
|
-
expect(result.error).toBeInstanceOf(
|
|
212
|
+
expect(result.error).toBeInstanceOf(ProjectSettingsInvalidError);
|
|
216
213
|
});
|
|
217
|
-
it("should write
|
|
214
|
+
it("should write settings to disk", async () => {
|
|
218
215
|
const fs = await createNodeishMemoryFs();
|
|
219
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
220
|
-
const
|
|
221
|
-
|
|
216
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings));
|
|
217
|
+
const project = await loadProject({
|
|
218
|
+
settingsFilePath: "./project.inlang.json",
|
|
222
219
|
nodeishFs: fs,
|
|
223
220
|
_import,
|
|
224
221
|
});
|
|
225
222
|
const before = await fs.readFile("./project.inlang.json", { encoding: "utf-8" });
|
|
226
223
|
expect(before).toBeDefined();
|
|
227
|
-
const result =
|
|
224
|
+
const result = project.setSettings({ ...settings, languageTags: [] });
|
|
228
225
|
expect(result.data).toBeUndefined();
|
|
229
226
|
expect(result.error).toBeUndefined();
|
|
230
227
|
// TODO: how to wait for fs.writeFile to finish?
|
|
@@ -237,53 +234,53 @@ describe("functionality", () => {
|
|
|
237
234
|
describe("installed", () => {
|
|
238
235
|
it("should return the installed items", async () => {
|
|
239
236
|
const fs = createNodeishMemoryFs();
|
|
240
|
-
const
|
|
237
|
+
const settings = {
|
|
241
238
|
sourceLanguageTag: "en",
|
|
242
239
|
languageTags: ["en"],
|
|
243
240
|
modules: ["plugin.js", "lintRule.js"],
|
|
244
|
-
settings: {},
|
|
245
241
|
};
|
|
246
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
247
|
-
const
|
|
248
|
-
|
|
242
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings));
|
|
243
|
+
const project = await loadProject({
|
|
244
|
+
settingsFilePath: "./project.inlang.json",
|
|
249
245
|
nodeishFs: fs,
|
|
250
246
|
_import,
|
|
251
247
|
});
|
|
252
|
-
expect(
|
|
253
|
-
|
|
254
|
-
|
|
248
|
+
expect(project.installed.plugins()[0]).toStrictEqual({
|
|
249
|
+
id: mockPlugin.id,
|
|
250
|
+
description: mockPlugin.description,
|
|
251
|
+
displayName: mockPlugin.displayName,
|
|
252
|
+
module: settings.modules[0],
|
|
255
253
|
});
|
|
256
|
-
expect(
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
254
|
+
expect(project.installed.messageLintRules()[0]).toEqual({
|
|
255
|
+
id: mockMessageLintRule.id,
|
|
256
|
+
description: mockMessageLintRule.description,
|
|
257
|
+
displayName: mockMessageLintRule.displayName,
|
|
258
|
+
module: settings.modules[1],
|
|
259
|
+
level: "warning",
|
|
260
260
|
});
|
|
261
261
|
});
|
|
262
|
-
it("should apply 'warning' as default lint level to lint rules that have no lint level defined in the
|
|
262
|
+
it("should apply 'warning' as default lint level to lint rules that have no lint level defined in the settings", async () => {
|
|
263
263
|
const fs = createNodeishMemoryFs();
|
|
264
|
-
const
|
|
264
|
+
const settings = {
|
|
265
265
|
sourceLanguageTag: "en",
|
|
266
266
|
languageTags: ["en"],
|
|
267
267
|
modules: ["plugin.js", "lintRule.js"],
|
|
268
|
-
settings: {},
|
|
269
268
|
};
|
|
270
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
271
|
-
const
|
|
272
|
-
|
|
269
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings));
|
|
270
|
+
const project = await loadProject({
|
|
271
|
+
settingsFilePath: "./project.inlang.json",
|
|
273
272
|
nodeishFs: fs,
|
|
274
273
|
_import,
|
|
275
274
|
});
|
|
276
|
-
expect(
|
|
275
|
+
expect(project.installed.messageLintRules()[0]?.level).toBe("warning");
|
|
277
276
|
});
|
|
278
277
|
// yep, this is a typical "hm, we have a bug here, let's write a test for it" test
|
|
279
278
|
it("should return lint reports if disabled is not set", async () => {
|
|
280
279
|
const _mockLintRule = {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
},
|
|
286
|
-
message: ({ report }) => {
|
|
280
|
+
id: "messageLintRule.namespace.mock",
|
|
281
|
+
description: { en: "Mock lint rule description" },
|
|
282
|
+
displayName: { en: "Mock Lint Rule" },
|
|
283
|
+
run: ({ report }) => {
|
|
287
284
|
report({
|
|
288
285
|
messageId: "some-message-1",
|
|
289
286
|
languageTag: "en",
|
|
@@ -292,11 +289,9 @@ describe("functionality", () => {
|
|
|
292
289
|
},
|
|
293
290
|
};
|
|
294
291
|
const _mockPlugin = {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
displayName: { en: "Mock Plugin" },
|
|
299
|
-
},
|
|
292
|
+
id: "plugin.project.i18next",
|
|
293
|
+
description: { en: "Mock plugin description" },
|
|
294
|
+
displayName: { en: "Mock Plugin" },
|
|
300
295
|
loadMessages: () => [{ id: "some-message", selectors: [], variants: [] }],
|
|
301
296
|
saveMessages: () => undefined,
|
|
302
297
|
};
|
|
@@ -305,31 +300,28 @@ describe("functionality", () => {
|
|
|
305
300
|
sourceLanguageTag: "en",
|
|
306
301
|
languageTags: ["en"],
|
|
307
302
|
modules: ["plugin.js", "lintRule.js"],
|
|
308
|
-
settings: {},
|
|
309
303
|
}));
|
|
310
304
|
const _import = async (name) => {
|
|
311
305
|
return {
|
|
312
306
|
default: name === "plugin.js" ? _mockPlugin : _mockLintRule,
|
|
313
307
|
};
|
|
314
308
|
};
|
|
315
|
-
const
|
|
316
|
-
|
|
309
|
+
const project = await loadProject({
|
|
310
|
+
settingsFilePath: "./project.inlang.json",
|
|
317
311
|
nodeishFs: fs,
|
|
318
312
|
_import,
|
|
319
313
|
});
|
|
320
314
|
await new Promise((resolve) => setTimeout(resolve, 510));
|
|
321
|
-
expect(
|
|
322
|
-
expect(
|
|
323
|
-
expect(
|
|
315
|
+
expect(project.query.messageLintReports.getAll()).toHaveLength(1);
|
|
316
|
+
expect(project.query.messageLintReports.getAll()?.[0]?.ruleId).toBe(_mockLintRule.id);
|
|
317
|
+
expect(project.installed.messageLintRules()).toHaveLength(1);
|
|
324
318
|
});
|
|
325
319
|
it("should return lint reports for a single message", async () => {
|
|
326
320
|
const _mockLintRule = {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
},
|
|
332
|
-
message: ({ report }) => {
|
|
321
|
+
id: "messageLintRule.namepsace.mock",
|
|
322
|
+
description: { en: "Mock lint rule description" },
|
|
323
|
+
displayName: { en: "Mock Lint Rule" },
|
|
324
|
+
run: ({ report }) => {
|
|
333
325
|
report({
|
|
334
326
|
messageId: "some-message",
|
|
335
327
|
languageTag: "en",
|
|
@@ -338,45 +330,42 @@ describe("functionality", () => {
|
|
|
338
330
|
},
|
|
339
331
|
};
|
|
340
332
|
const _mockPlugin = {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
displayName: { en: "Mock Plugin" },
|
|
345
|
-
},
|
|
333
|
+
id: "plugin.project.i18next",
|
|
334
|
+
description: { en: "Mock plugin description" },
|
|
335
|
+
displayName: { en: "Mock Plugin" },
|
|
346
336
|
loadMessages: () => [{ id: "some-message", selectors: [], variants: [] }],
|
|
347
337
|
saveMessages: () => undefined,
|
|
348
338
|
};
|
|
349
339
|
const fs = await createNodeishMemoryFs();
|
|
350
|
-
await fs.writeFile("./
|
|
340
|
+
await fs.writeFile("./project.settings.json", JSON.stringify({
|
|
351
341
|
sourceLanguageTag: "en",
|
|
352
342
|
languageTags: ["en"],
|
|
353
343
|
modules: ["plugin.js", "lintRule.js"],
|
|
354
|
-
settings: {},
|
|
355
344
|
}));
|
|
356
345
|
const _import = async (name) => {
|
|
357
346
|
return {
|
|
358
347
|
default: name === "plugin.js" ? _mockPlugin : _mockLintRule,
|
|
359
348
|
};
|
|
360
349
|
};
|
|
361
|
-
const
|
|
362
|
-
|
|
350
|
+
const project = await loadProject({
|
|
351
|
+
settingsFilePath: "./project.settings.json",
|
|
363
352
|
nodeishFs: fs,
|
|
364
353
|
_import,
|
|
365
354
|
});
|
|
366
355
|
await new Promise((resolve) => setTimeout(resolve, 510));
|
|
367
|
-
expect(
|
|
356
|
+
expect(project.query.messageLintReports.get({ where: { messageId: "some-message" } })).toHaveLength(1);
|
|
368
357
|
});
|
|
369
358
|
});
|
|
370
359
|
describe("errors", () => {
|
|
371
360
|
it("should return the errors", async () => {
|
|
372
361
|
const fs = await createNodeishMemoryFs();
|
|
373
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
374
|
-
const
|
|
375
|
-
|
|
362
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings));
|
|
363
|
+
const project = await loadProject({
|
|
364
|
+
settingsFilePath: "./project.inlang.json",
|
|
376
365
|
nodeishFs: fs,
|
|
377
366
|
_import,
|
|
378
367
|
});
|
|
379
|
-
|
|
368
|
+
project.errors.subscribe((errors) => {
|
|
380
369
|
expect(errors).toStrictEqual([]);
|
|
381
370
|
});
|
|
382
371
|
});
|
|
@@ -384,50 +373,46 @@ describe("functionality", () => {
|
|
|
384
373
|
describe("customApi", () => {
|
|
385
374
|
it("should return the app specific api", async () => {
|
|
386
375
|
const fs = await createNodeishMemoryFs();
|
|
387
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
388
|
-
const
|
|
389
|
-
|
|
376
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings));
|
|
377
|
+
const project = await loadProject({
|
|
378
|
+
settingsFilePath: "./project.inlang.json",
|
|
390
379
|
nodeishFs: fs,
|
|
391
380
|
_import,
|
|
392
381
|
});
|
|
393
|
-
|
|
394
|
-
expect(api["app.
|
|
382
|
+
project.customApi.subscribe((api) => {
|
|
383
|
+
expect(api["app.project.ideExtension"]).toBeDefined();
|
|
395
384
|
});
|
|
396
385
|
});
|
|
397
386
|
});
|
|
398
387
|
describe("messages", () => {
|
|
399
388
|
it("should return the messages", async () => {
|
|
400
389
|
const fs = await createNodeishMemoryFs();
|
|
401
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
402
|
-
const
|
|
403
|
-
|
|
390
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings));
|
|
391
|
+
const project = await loadProject({
|
|
392
|
+
settingsFilePath: "./project.inlang.json",
|
|
404
393
|
nodeishFs: fs,
|
|
405
394
|
_import,
|
|
406
395
|
});
|
|
407
|
-
expect(Object.values(
|
|
396
|
+
expect(Object.values(project.query.messages.getAll())).toEqual(exampleMessages);
|
|
408
397
|
});
|
|
409
398
|
});
|
|
410
399
|
describe("query", () => {
|
|
411
|
-
it("
|
|
412
|
-
const fs =
|
|
400
|
+
it("should call saveMessages() on updates", async () => {
|
|
401
|
+
const fs = createNodeishMemoryFs();
|
|
413
402
|
await fs.writeFile("./project.inlang.json", JSON.stringify({
|
|
414
403
|
sourceLanguageTag: "en",
|
|
415
404
|
languageTags: ["en", "de"],
|
|
416
405
|
modules: ["plugin.js"],
|
|
417
|
-
|
|
418
|
-
"
|
|
419
|
-
pathPattern: "./resources/{languageTag}.json",
|
|
420
|
-
},
|
|
406
|
+
"plugin.project.json": {
|
|
407
|
+
pathPattern: "./resources/{languageTag}.json",
|
|
421
408
|
},
|
|
422
409
|
}));
|
|
423
410
|
await fs.mkdir("./resources");
|
|
424
411
|
const mockSaveFn = vi.fn();
|
|
425
412
|
const _mockPlugin = {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
displayName: { en: "Mock Plugin" },
|
|
430
|
-
},
|
|
413
|
+
id: "plugin.project.json",
|
|
414
|
+
description: { en: "Mock plugin description" },
|
|
415
|
+
displayName: { en: "Mock Plugin" },
|
|
431
416
|
loadMessages: () => exampleMessages,
|
|
432
417
|
saveMessages: mockSaveFn,
|
|
433
418
|
};
|
|
@@ -436,12 +421,12 @@ describe("functionality", () => {
|
|
|
436
421
|
default: _mockPlugin,
|
|
437
422
|
};
|
|
438
423
|
};
|
|
439
|
-
const
|
|
440
|
-
|
|
424
|
+
const project = await loadProject({
|
|
425
|
+
settingsFilePath: "./project.inlang.json",
|
|
441
426
|
nodeishFs: fs,
|
|
442
427
|
_import,
|
|
443
428
|
});
|
|
444
|
-
await
|
|
429
|
+
await project.query.messages.upsert({
|
|
445
430
|
where: { id: "a" },
|
|
446
431
|
data: {
|
|
447
432
|
id: "a",
|
|
@@ -470,7 +455,7 @@ describe("functionality", () => {
|
|
|
470
455
|
],
|
|
471
456
|
},
|
|
472
457
|
});
|
|
473
|
-
await
|
|
458
|
+
await project.query.messages.upsert({
|
|
474
459
|
where: { id: "b" },
|
|
475
460
|
data: {
|
|
476
461
|
id: "b",
|
|
@@ -563,15 +548,15 @@ describe("functionality", () => {
|
|
|
563
548
|
describe("lint", () => {
|
|
564
549
|
it.todo("should throw if lint reports are not initialized yet", async () => {
|
|
565
550
|
const fs = await createNodeishMemoryFs();
|
|
566
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
567
|
-
const
|
|
568
|
-
|
|
551
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings));
|
|
552
|
+
const project = await loadProject({
|
|
553
|
+
settingsFilePath: "./project.inlang.json",
|
|
569
554
|
nodeishFs: fs,
|
|
570
555
|
_import,
|
|
571
556
|
});
|
|
572
557
|
// TODO: test with real lint rules
|
|
573
558
|
try {
|
|
574
|
-
|
|
559
|
+
project.query.messageLintReports.getAll.subscribe((r) => expect(r).toEqual(undefined));
|
|
575
560
|
throw new Error("Should not reach this");
|
|
576
561
|
}
|
|
577
562
|
catch (e) {
|
|
@@ -579,23 +564,22 @@ describe("functionality", () => {
|
|
|
579
564
|
}
|
|
580
565
|
});
|
|
581
566
|
it("should return the message lint reports", async () => {
|
|
582
|
-
const
|
|
567
|
+
const settings = {
|
|
583
568
|
sourceLanguageTag: "en",
|
|
584
569
|
languageTags: ["en"],
|
|
585
570
|
modules: ["lintRule.js"],
|
|
586
|
-
settings: {},
|
|
587
571
|
};
|
|
588
572
|
const fs = createNodeishMemoryFs();
|
|
589
|
-
await fs.writeFile("./project.inlang.json", JSON.stringify(
|
|
590
|
-
const
|
|
591
|
-
|
|
573
|
+
await fs.writeFile("./project.inlang.json", JSON.stringify(settings));
|
|
574
|
+
const project = await loadProject({
|
|
575
|
+
settingsFilePath: "./project.inlang.json",
|
|
592
576
|
nodeishFs: fs,
|
|
593
577
|
_import: async () => ({
|
|
594
578
|
default: mockMessageLintRule,
|
|
595
579
|
}),
|
|
596
580
|
});
|
|
597
581
|
// TODO: test with real lint rules
|
|
598
|
-
|
|
582
|
+
project.query.messageLintReports.getAll.subscribe((r) => expect(r).toEqual([]));
|
|
599
583
|
});
|
|
600
584
|
});
|
|
601
585
|
});
|
package/dist/parseConfig.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProjectSettings } from "./versionedInterfaces.js";
|
|
2
2
|
import type { Result } from "@inlang/result";
|
|
3
3
|
export declare class ParseConfigError extends Error {
|
|
4
4
|
#private;
|
|
5
5
|
constructor(message: string, cause?: string);
|
|
6
6
|
}
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const parseSettings: (config: ProjectSettings) => Result<ProjectSettings, ParseConfigError>;
|
|
8
8
|
//# sourceMappingURL=parseConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseConfig.d.ts","sourceRoot":"","sources":["../src/parseConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"parseConfig.d.ts","sourceRoot":"","sources":["../src/parseConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAG5C,qBAAa,gBAAiB,SAAQ,KAAK;;gBAG9B,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;CAK3C;AAKD,eAAO,MAAM,aAAa,WACjB,eAAe,KACrB,OAAO,eAAe,EAAE,gBAAgB,CAe1C,CAAA"}
|
package/dist/parseConfig.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProjectSettings } from "./versionedInterfaces.js";
|
|
2
2
|
import { TypeCompiler } from "@sinclair/typebox/compiler";
|
|
3
3
|
export class ParseConfigError extends Error {
|
|
4
4
|
#id = "ParseConfigException";
|
|
@@ -9,8 +9,8 @@ export class ParseConfigError extends Error {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
// @ts-ignore - fix after refactor
|
|
12
|
-
const ConfigCompiler = TypeCompiler.Compile(
|
|
13
|
-
export const
|
|
12
|
+
const ConfigCompiler = TypeCompiler.Compile(ProjectSettings);
|
|
13
|
+
export const parseSettings = (config) => {
|
|
14
14
|
if (ConfigCompiler.Check(config)) {
|
|
15
15
|
return {
|
|
16
16
|
data: config,
|