@inlang/sdk 0.4.0 → 0.6.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.
Files changed (80) hide show
  1. package/dist/adapter/solidAdapter.d.ts +2 -2
  2. package/dist/adapter/solidAdapter.d.ts.map +1 -1
  3. package/dist/adapter/solidAdapter.js +2 -2
  4. package/dist/adapter/solidAdapter.test.js +68 -78
  5. package/dist/api.d.ts +10 -6
  6. package/dist/api.d.ts.map +1 -1
  7. package/dist/api.test-d.d.ts +2 -0
  8. package/dist/api.test-d.d.ts.map +1 -0
  9. package/dist/api.test-d.js +4 -0
  10. package/dist/createMessageLintReportsQuery.d.ts +2 -2
  11. package/dist/createMessageLintReportsQuery.d.ts.map +1 -1
  12. package/dist/createMessageLintReportsQuery.js +11 -11
  13. package/dist/createMessagesQuery.js +1 -1
  14. package/dist/errors.d.ts +3 -3
  15. package/dist/errors.d.ts.map +1 -1
  16. package/dist/errors.js +6 -6
  17. package/dist/index.d.ts +2 -2
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +2 -2
  20. package/dist/lint/message/lintMessages.d.ts +3 -7
  21. package/dist/lint/message/lintMessages.d.ts.map +1 -1
  22. package/dist/lint/message/lintMessages.test.js +38 -36
  23. package/dist/lint/message/lintSingleMessage.d.ts +3 -7
  24. package/dist/lint/message/lintSingleMessage.d.ts.map +1 -1
  25. package/dist/lint/message/lintSingleMessage.js +10 -10
  26. package/dist/lint/message/lintSingleMessage.test.js +71 -65
  27. package/dist/{openInlangProject.d.ts → loadProject.d.ts} +3 -3
  28. package/dist/loadProject.d.ts.map +1 -0
  29. package/dist/{openInlangProject.js → loadProject.js} +70 -66
  30. package/dist/loadProject.test.d.ts +2 -0
  31. package/dist/loadProject.test.d.ts.map +1 -0
  32. package/dist/{openInlangProject.test.js → loadProject.test.js} +160 -176
  33. package/dist/parseConfig.d.ts +2 -2
  34. package/dist/parseConfig.d.ts.map +1 -1
  35. package/dist/parseConfig.js +3 -3
  36. package/dist/resolve-modules/message-lint-rules/resolveMessageLintRules.js +1 -1
  37. package/dist/resolve-modules/plugins/errors.d.ts +1 -1
  38. package/dist/resolve-modules/plugins/errors.d.ts.map +1 -1
  39. package/dist/resolve-modules/plugins/resolvePlugins.js +15 -15
  40. package/dist/resolve-modules/plugins/resolvePlugins.test.js +55 -94
  41. package/dist/resolve-modules/plugins/types.d.ts +1 -1
  42. package/dist/resolve-modules/plugins/types.d.ts.map +1 -1
  43. package/dist/resolve-modules/plugins/types.test.js +10 -14
  44. package/dist/resolve-modules/resolveModules.d.ts.map +1 -1
  45. package/dist/resolve-modules/resolveModules.js +9 -9
  46. package/dist/resolve-modules/resolveModules.test.js +28 -42
  47. package/dist/resolve-modules/types.d.ts +3 -3
  48. package/dist/resolve-modules/types.d.ts.map +1 -1
  49. package/dist/versionedInterfaces.d.ts +1 -1
  50. package/dist/versionedInterfaces.d.ts.map +1 -1
  51. package/dist/versionedInterfaces.js +1 -1
  52. package/package.json +2 -2
  53. package/src/adapter/solidAdapter.test.ts +77 -87
  54. package/src/adapter/solidAdapter.ts +4 -4
  55. package/src/api.test-d.ts +8 -0
  56. package/src/api.ts +10 -6
  57. package/src/createMessageLintReportsQuery.ts +15 -20
  58. package/src/createMessagesQuery.ts +1 -1
  59. package/src/errors.ts +6 -6
  60. package/src/index.ts +4 -4
  61. package/src/lint/message/lintMessages.test.ts +38 -36
  62. package/src/lint/message/lintMessages.ts +3 -11
  63. package/src/lint/message/lintSingleMessage.test.ts +71 -65
  64. package/src/lint/message/lintSingleMessage.ts +13 -21
  65. package/src/{openInlangProject.test.ts → loadProject.test.ts} +165 -181
  66. package/src/{openInlangProject.ts → loadProject.ts} +81 -82
  67. package/src/parseConfig.ts +5 -3
  68. package/src/resolve-modules/message-lint-rules/resolveMessageLintRules.ts +1 -1
  69. package/src/resolve-modules/plugins/errors.ts +1 -1
  70. package/src/resolve-modules/plugins/resolvePlugins.test.ts +55 -94
  71. package/src/resolve-modules/plugins/resolvePlugins.ts +19 -19
  72. package/src/resolve-modules/plugins/types.test.ts +11 -15
  73. package/src/resolve-modules/plugins/types.ts +1 -1
  74. package/src/resolve-modules/resolveModules.test.ts +29 -43
  75. package/src/resolve-modules/resolveModules.ts +11 -9
  76. package/src/resolve-modules/types.ts +3 -3
  77. package/src/versionedInterfaces.ts +1 -1
  78. package/dist/openInlangProject.d.ts.map +0 -1
  79. package/dist/openInlangProject.test.d.ts +0 -2
  80. 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 { openInlangProject } from "./openInlangProject.js";
4
- import { ProjectFilePathNotFoundError, ProjectFileJSONSyntaxError, InvalidConfigError, } from "./errors.js";
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 config = {
12
+ const settings = {
13
13
  sourceLanguageTag: "en",
14
14
  languageTags: ["en"],
15
15
  modules: ["plugin.js", "lintRule.js"],
16
- settings: {
17
- "project.messageLintRuleLevels": {
18
- "messageLintRule.inlang.missingTranslation": "error",
19
- },
20
- "plugin.inlang.i18next": {
21
- pathPattern: "./examples/example01/{languageTag}.json",
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
- meta: {
28
- id: "plugin.inlang.i18next",
29
- description: { en: "Mock plugin description" },
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.inlang.ideExtension": {
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
- meta: {
77
- id: "messageLintRule.inlang.mock",
78
- description: { en: "Mock lint rule description" },
79
- displayName: { en: "Mock Lint Rule" },
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("config", () => {
89
- it("should return an error if config file is not found", async () => {
82
+ describe("settings", () => {
83
+ it("should return an error if settings file is not found", async () => {
90
84
  const fs = createNodeishMemoryFs();
91
- const inlang = await openInlangProject({
92
- projectFilePath: "./test.json",
85
+ const project = await loadProject({
86
+ settingsFilePath: "./test.json",
93
87
  nodeishFs: fs,
94
88
  _import,
95
89
  });
96
- expect(inlang.errors()[0]).toBeInstanceOf(ProjectFilePathNotFoundError);
90
+ expect(project.errors()[0]).toBeInstanceOf(ProjectSettingsFileNotFoundError);
97
91
  });
98
- it("should return an error if config file is not a valid JSON", async () => {
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 inlang = await openInlangProject({
102
- projectFilePath: "./project.inlang.json",
95
+ const project = await loadProject({
96
+ settingsFilePath: "./project.inlang.json",
103
97
  nodeishFs: fs,
104
98
  _import,
105
99
  });
106
- expect(inlang.errors()[0]).toBeInstanceOf(ProjectFileJSONSyntaxError);
100
+ expect(project.errors()[0]).toBeInstanceOf(ProjectSettingsFileJSONSyntaxError);
107
101
  });
108
- it("should return an error if config file is does not match schema", async () => {
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 inlang = await openInlangProject({
112
- projectFilePath: "./project.inlang.json",
105
+ const project = await loadProject({
106
+ settingsFilePath: "./project.inlang.json",
113
107
  nodeishFs: fs,
114
108
  _import,
115
109
  });
116
- expect(inlang.errors()[0]).toBeInstanceOf(InvalidConfigError);
110
+ expect(project.errors()[0]).toBeInstanceOf(ProjectSettingsInvalidError);
117
111
  });
118
- it("should return the parsed config", async () => {
112
+ it("should return the parsed settings", async () => {
119
113
  const fs = await createNodeishMemoryFs();
120
- await fs.writeFile("./project.inlang.json", JSON.stringify(config));
121
- const inlang = await openInlangProject({
122
- projectFilePath: "./project.inlang.json",
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(inlang.config()).toStrictEqual(config);
120
+ expect(project.settings()).toStrictEqual(settings);
127
121
  });
128
- it("should not re-write the config to disk when initializing", async () => {
122
+ it("should not re-write the settings to disk when initializing", async () => {
129
123
  const fs = await createNodeishMemoryFs();
130
- const configWithDeifferentFormatting = JSON.stringify(config, undefined, 4);
131
- await fs.writeFile("./project.inlang.json", configWithDeifferentFormatting);
132
- const inlang = await openInlangProject({
133
- projectFilePath: "./project.inlang.json",
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 configOnDisk = await fs.readFile("./project.inlang.json", { encoding: "utf-8" });
138
- expect(configOnDisk).toBe(configWithDeifferentFormatting);
139
- inlang.setConfig(inlang.config());
140
- // TODO: how can we await `setConfig` correctly
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 newConfigOnDisk = await fs.readFile("./project.inlang.json", { encoding: "utf-8" });
143
- expect(newConfigOnDisk).not.toBe(configWithDeifferentFormatting);
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(config));
153
- const inlang = await openInlangProject({
154
- projectFilePath: "./project.inlang.json",
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(inlang.errors()).not.toHaveLength(0);
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 config");
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("config", () => {
177
- it("should return the config", async () => {
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(config));
180
- const inlang = await openInlangProject({
181
- projectFilePath: "./project.inlang.json",
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(inlang.config)).toStrictEqual(config);
179
+ expect(getValue(project.settings)).toStrictEqual(settings);
186
180
  });
187
- it("should set a new config", async () => {
181
+ it("should set a new settings", async () => {
188
182
  const fs = await createNodeishMemoryFs();
189
- await fs.writeFile("./project.inlang.json", JSON.stringify(config));
190
- const inlang = await openInlangProject({
191
- projectFilePath: "./project.inlang.json",
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(inlang.config()).toStrictEqual(config);
196
- inlang.setConfig({ ...config, languageTags: ["en", "de"] });
197
- expect(getValue(inlang.config)).toStrictEqual({ ...config, languageTags: ["en", "de"] });
198
- expect(inlang.config().languageTags).toStrictEqual(["en", "de"]);
199
- inlang.setConfig({ ...config, languageTags: ["en", "de", "fr"] });
200
- expect(getValue(inlang.config)).toStrictEqual({ ...config, languageTags: ["en", "de", "fr"] });
201
- expect(inlang.config().languageTags).toStrictEqual(["en", "de", "fr"]);
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("setConfig", () => {
205
- it("should fail if config is not valid", async () => {
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(config));
208
- const inlang = await openInlangProject({
209
- projectFilePath: "./project.inlang.json",
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 = inlang.setConfig({});
210
+ const result = project.setSettings({});
214
211
  expect(result.data).toBeUndefined();
215
- expect(result.error).toBeInstanceOf(InvalidConfigError);
212
+ expect(result.error).toBeInstanceOf(ProjectSettingsInvalidError);
216
213
  });
217
- it("should write config to disk", async () => {
214
+ it("should write settings to disk", async () => {
218
215
  const fs = await createNodeishMemoryFs();
219
- await fs.writeFile("./project.inlang.json", JSON.stringify(config));
220
- const inlang = await openInlangProject({
221
- projectFilePath: "./project.inlang.json",
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 = inlang.setConfig({ ...config, languageTags: [] });
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 config = {
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(config));
247
- const inlang = await openInlangProject({
248
- projectFilePath: "./project.inlang.json",
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(inlang.installed.plugins()[0]).toStrictEqual({
253
- meta: mockPlugin.meta,
254
- module: config.modules[0],
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(inlang.installed.messageLintRules()[0]).toEqual({
257
- meta: mockMessageLintRule.meta,
258
- module: config.modules[1],
259
- lintLevel: "warning",
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 config", async () => {
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 config = {
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(config));
271
- const inlang = await openInlangProject({
272
- projectFilePath: "./project.inlang.json",
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(inlang.installed.messageLintRules()[0]?.lintLevel).toBe("warning");
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
- meta: {
282
- id: "messageLintRule.namespace.mock",
283
- description: { en: "Mock lint rule description" },
284
- displayName: { en: "Mock Lint Rule" },
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
- meta: {
296
- id: "plugin.inlang.i18next",
297
- description: { en: "Mock plugin description" },
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 inlang = await openInlangProject({
316
- projectFilePath: "./project.inlang.json",
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(inlang.query.messageLintReports.getAll()).toHaveLength(1);
322
- expect(inlang.query.messageLintReports.getAll()?.[0]?.ruleId).toBe(_mockLintRule.meta.id);
323
- expect(inlang.installed.messageLintRules()).toHaveLength(1);
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
- meta: {
328
- id: "messageLintRule.namepsace.mock",
329
- description: { en: "Mock lint rule description" },
330
- displayName: { en: "Mock Lint Rule" },
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
- meta: {
342
- id: "plugin.inlang.i18next",
343
- description: { en: "Mock plugin description" },
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("./inlang.config.json", JSON.stringify({
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 inlang = await openInlangProject({
362
- projectFilePath: "./inlang.config.json",
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(inlang.query.messageLintReports.get({ where: { messageId: "some-message" } })).toHaveLength(1);
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(config));
374
- const inlang = await openInlangProject({
375
- projectFilePath: "./project.inlang.json",
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
- inlang.errors.subscribe((errors) => {
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(config));
388
- const inlang = await openInlangProject({
389
- projectFilePath: "./project.inlang.json",
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
- inlang.customApi.subscribe((api) => {
394
- expect(api["app.inlang.ideExtension"]).toBeDefined();
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(config));
402
- const inlang = await openInlangProject({
403
- projectFilePath: "./project.inlang.json",
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(inlang.query.messages.getAll())).toEqual(exampleMessages);
396
+ expect(Object.values(project.query.messages.getAll())).toEqual(exampleMessages);
408
397
  });
409
398
  });
410
399
  describe("query", () => {
411
- it("updates should trigger the plugin persistence", async () => {
412
- const fs = await createNodeishMemoryFs();
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
- settings: {
418
- "plugin.inlang.json": {
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
- meta: {
427
- id: "plugin.inlang.json",
428
- description: { en: "Mock plugin description" },
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 inlang = await openInlangProject({
440
- projectFilePath: "./project.inlang.json",
424
+ const project = await loadProject({
425
+ settingsFilePath: "./project.inlang.json",
441
426
  nodeishFs: fs,
442
427
  _import,
443
428
  });
444
- await inlang.query.messages.upsert({
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 inlang.query.messages.upsert({
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(config));
567
- const inlang = await openInlangProject({
568
- projectFilePath: "./project.inlang.json",
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
- inlang.query.messageLintReports.getAll.subscribe((r) => expect(r).toEqual(undefined));
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 config = {
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(config));
590
- const inlang = await openInlangProject({
591
- projectFilePath: "./project.inlang.json",
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
- inlang.query.messageLintReports.getAll.subscribe((r) => expect(r).toEqual([]));
582
+ project.query.messageLintReports.getAll.subscribe((r) => expect(r).toEqual([]));
599
583
  });
600
584
  });
601
585
  });
@@ -1,8 +1,8 @@
1
- import { ProjectConfig } from "./versionedInterfaces.js";
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 parseConfig: (config: ProjectConfig) => Result<ProjectConfig, ParseConfigError>;
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,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACxD,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,WAAW,WAAY,aAAa,KAAG,OAAO,aAAa,EAAE,gBAAgB,CAezF,CAAA"}
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"}
@@ -1,4 +1,4 @@
1
- import { ProjectConfig } from "./versionedInterfaces.js";
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(ProjectConfig);
13
- export const parseConfig = (config) => {
12
+ const ConfigCompiler = TypeCompiler.Compile(ProjectSettings);
13
+ export const parseSettings = (config) => {
14
14
  if (ConfigCompiler.Check(config)) {
15
15
  return {
16
16
  data: config,