@inlang/sdk 0.3.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.
Files changed (82) 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/import.js +1 -1
  37. package/dist/resolve-modules/message-lint-rules/resolveMessageLintRules.js +1 -1
  38. package/dist/resolve-modules/plugins/errors.d.ts +1 -1
  39. package/dist/resolve-modules/plugins/errors.d.ts.map +1 -1
  40. package/dist/resolve-modules/plugins/resolvePlugins.js +15 -15
  41. package/dist/resolve-modules/plugins/resolvePlugins.test.js +55 -94
  42. package/dist/resolve-modules/plugins/types.d.ts +1 -1
  43. package/dist/resolve-modules/plugins/types.d.ts.map +1 -1
  44. package/dist/resolve-modules/plugins/types.test.js +10 -14
  45. package/dist/resolve-modules/resolveModules.d.ts.map +1 -1
  46. package/dist/resolve-modules/resolveModules.js +9 -9
  47. package/dist/resolve-modules/resolveModules.test.js +28 -42
  48. package/dist/resolve-modules/types.d.ts +3 -3
  49. package/dist/resolve-modules/types.d.ts.map +1 -1
  50. package/dist/versionedInterfaces.d.ts +1 -1
  51. package/dist/versionedInterfaces.d.ts.map +1 -1
  52. package/dist/versionedInterfaces.js +1 -1
  53. package/package.json +3 -3
  54. package/src/adapter/solidAdapter.test.ts +77 -87
  55. package/src/adapter/solidAdapter.ts +4 -4
  56. package/src/api.test-d.ts +8 -0
  57. package/src/api.ts +10 -6
  58. package/src/createMessageLintReportsQuery.ts +15 -20
  59. package/src/createMessagesQuery.ts +1 -1
  60. package/src/errors.ts +6 -6
  61. package/src/index.ts +4 -4
  62. package/src/lint/message/lintMessages.test.ts +38 -36
  63. package/src/lint/message/lintMessages.ts +3 -11
  64. package/src/lint/message/lintSingleMessage.test.ts +71 -65
  65. package/src/lint/message/lintSingleMessage.ts +13 -21
  66. package/src/{openInlangProject.test.ts → loadProject.test.ts} +165 -181
  67. package/src/{openInlangProject.ts → loadProject.ts} +81 -82
  68. package/src/parseConfig.ts +5 -3
  69. package/src/resolve-modules/import.ts +1 -1
  70. package/src/resolve-modules/message-lint-rules/resolveMessageLintRules.ts +1 -1
  71. package/src/resolve-modules/plugins/errors.ts +1 -1
  72. package/src/resolve-modules/plugins/resolvePlugins.test.ts +55 -94
  73. package/src/resolve-modules/plugins/resolvePlugins.ts +19 -19
  74. package/src/resolve-modules/plugins/types.test.ts +11 -15
  75. package/src/resolve-modules/plugins/types.ts +1 -1
  76. package/src/resolve-modules/resolveModules.test.ts +29 -43
  77. package/src/resolve-modules/resolveModules.ts +11 -9
  78. package/src/resolve-modules/types.ts +3 -3
  79. package/src/versionedInterfaces.ts +1 -1
  80. package/dist/openInlangProject.d.ts.map +0 -1
  81. package/dist/openInlangProject.test.d.ts +0 -2
  82. package/dist/openInlangProject.test.d.ts.map +0 -1
@@ -1,13 +1,13 @@
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 type { ProjectConfig, Plugin, MessageLintRule, Message } from "./versionedInterfaces.js"
3
+ import { loadProject } from "./loadProject.js"
4
+ import type { ProjectSettings, Plugin, MessageLintRule, Message } from "./versionedInterfaces.js"
5
5
  import type { ImportFunction } from "./resolve-modules/index.js"
6
6
  import type { InlangModule } from "@inlang/module"
7
7
  import {
8
- ProjectFilePathNotFoundError,
9
- ProjectFileJSONSyntaxError,
10
- InvalidConfigError,
8
+ ProjectSettingsFileJSONSyntaxError,
9
+ ProjectSettingsFileNotFoundError,
10
+ ProjectSettingsInvalidError,
11
11
  } from "./errors.js"
12
12
  import { createNodeishMemoryFs } from "@lix-js/fs"
13
13
 
@@ -19,31 +19,27 @@ const getValue = <T>(subscribable: { subscribe: (subscriber: (value: T) => void)
19
19
  return value!
20
20
  }
21
21
 
22
- const config: ProjectConfig = {
22
+ const settings: ProjectSettings = {
23
23
  sourceLanguageTag: "en",
24
24
  languageTags: ["en"],
25
25
  modules: ["plugin.js", "lintRule.js"],
26
- settings: {
27
- "project.messageLintRuleLevels": {
28
- "messageLintRule.inlang.missingTranslation": "error",
29
- },
30
- "plugin.inlang.i18next": {
31
- pathPattern: "./examples/example01/{languageTag}.json",
32
- variableReferencePattern: ["{", "}"],
33
- },
26
+ messageLintRuleLevels: {
27
+ "messageLintRule.project.missingTranslation": "error",
28
+ },
29
+ "plugin.project.i18next": {
30
+ pathPattern: "./examples/example01/{languageTag}.json",
31
+ variableReferencePattern: ["{", "}"],
34
32
  },
35
33
  }
36
34
 
37
35
  const mockPlugin: Plugin = {
38
- meta: {
39
- id: "plugin.inlang.i18next",
40
- description: { en: "Mock plugin description" },
41
- displayName: { en: "Mock Plugin" },
42
- },
36
+ id: "plugin.project.i18next",
37
+ description: { en: "Mock plugin description" },
38
+ displayName: { en: "Mock Plugin" },
43
39
  loadMessages: () => exampleMessages,
44
40
  saveMessages: () => undefined as any,
45
41
  addCustomApi: () => ({
46
- "app.inlang.ideExtension": {
42
+ "app.project.ideExtension": {
47
43
  messageReferenceMatcher: (text: string) => text as any,
48
44
  },
49
45
  }),
@@ -86,12 +82,10 @@ const exampleMessages: Message[] = [
86
82
  ]
87
83
 
88
84
  const mockMessageLintRule: MessageLintRule = {
89
- meta: {
90
- id: "messageLintRule.inlang.mock",
91
- description: { en: "Mock lint rule description" },
92
- displayName: { en: "Mock Lint Rule" },
93
- },
94
- message: () => undefined,
85
+ id: "messageLintRule.project.mock",
86
+ description: { en: "Mock lint rule description" },
87
+ displayName: { en: "Mock Lint Rule" },
88
+ run: () => undefined,
95
89
  }
96
90
 
97
91
  const _import: ImportFunction = async (name) =>
@@ -102,77 +96,77 @@ const _import: ImportFunction = async (name) =>
102
96
  // ------------------------------------------------------------------------------------------------
103
97
 
104
98
  describe("initialization", () => {
105
- describe("config", () => {
106
- it("should return an error if config file is not found", async () => {
99
+ describe("settings", () => {
100
+ it("should return an error if settings file is not found", async () => {
107
101
  const fs = createNodeishMemoryFs()
108
102
 
109
- const inlang = await openInlangProject({
110
- projectFilePath: "./test.json",
103
+ const project = await loadProject({
104
+ settingsFilePath: "./test.json",
111
105
  nodeishFs: fs,
112
106
  _import,
113
107
  })
114
108
 
115
- expect(inlang.errors()![0]).toBeInstanceOf(ProjectFilePathNotFoundError)
109
+ expect(project.errors()![0]).toBeInstanceOf(ProjectSettingsFileNotFoundError)
116
110
  })
117
111
 
118
- it("should return an error if config file is not a valid JSON", async () => {
112
+ it("should return an error if settings file is not a valid JSON", async () => {
119
113
  const fs = await createNodeishMemoryFs()
120
114
  await fs.writeFile("./project.inlang.json", "invalid json")
121
115
 
122
- const inlang = await openInlangProject({
123
- projectFilePath: "./project.inlang.json",
116
+ const project = await loadProject({
117
+ settingsFilePath: "./project.inlang.json",
124
118
  nodeishFs: fs,
125
119
  _import,
126
120
  })
127
121
 
128
- expect(inlang.errors()![0]).toBeInstanceOf(ProjectFileJSONSyntaxError)
122
+ expect(project.errors()![0]).toBeInstanceOf(ProjectSettingsFileJSONSyntaxError)
129
123
  })
130
124
 
131
- it("should return an error if config file is does not match schema", async () => {
125
+ it("should return an error if settings file is does not match schema", async () => {
132
126
  const fs = await createNodeishMemoryFs()
133
127
  await fs.writeFile("./project.inlang.json", JSON.stringify({}))
134
128
 
135
- const inlang = await openInlangProject({
136
- projectFilePath: "./project.inlang.json",
129
+ const project = await loadProject({
130
+ settingsFilePath: "./project.inlang.json",
137
131
  nodeishFs: fs,
138
132
  _import,
139
133
  })
140
134
 
141
- expect(inlang.errors()![0]).toBeInstanceOf(InvalidConfigError)
135
+ expect(project.errors()![0]).toBeInstanceOf(ProjectSettingsInvalidError)
142
136
  })
143
137
 
144
- it("should return the parsed config", async () => {
138
+ it("should return the parsed settings", async () => {
145
139
  const fs = await createNodeishMemoryFs()
146
- await fs.writeFile("./project.inlang.json", JSON.stringify(config))
147
- const inlang = await openInlangProject({
148
- projectFilePath: "./project.inlang.json",
140
+ await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
141
+ const project = await loadProject({
142
+ settingsFilePath: "./project.inlang.json",
149
143
  nodeishFs: fs,
150
144
  _import,
151
145
  })
152
146
 
153
- expect(inlang.config()).toStrictEqual(config)
147
+ expect(project.settings()).toStrictEqual(settings)
154
148
  })
155
149
 
156
- it("should not re-write the config to disk when initializing", async () => {
150
+ it("should not re-write the settings to disk when initializing", async () => {
157
151
  const fs = await createNodeishMemoryFs()
158
- const configWithDeifferentFormatting = JSON.stringify(config, undefined, 4)
159
- await fs.writeFile("./project.inlang.json", configWithDeifferentFormatting)
152
+ const settingsWithDeifferentFormatting = JSON.stringify(settings, undefined, 4)
153
+ await fs.writeFile("./project.inlang.json", settingsWithDeifferentFormatting)
160
154
 
161
- const inlang = await openInlangProject({
162
- projectFilePath: "./project.inlang.json",
155
+ const project = await loadProject({
156
+ settingsFilePath: "./project.inlang.json",
163
157
  nodeishFs: fs,
164
158
  _import,
165
159
  })
166
160
 
167
- const configOnDisk = await fs.readFile("./project.inlang.json", { encoding: "utf-8" })
168
- expect(configOnDisk).toBe(configWithDeifferentFormatting)
161
+ const settingsOnDisk = await fs.readFile("./project.inlang.json", { encoding: "utf-8" })
162
+ expect(settingsOnDisk).toBe(settingsWithDeifferentFormatting)
169
163
 
170
- inlang.setConfig(inlang.config()!)
171
- // TODO: how can we await `setConfig` correctly
164
+ project.setSettings(project.settings())
165
+ // TODO: how can we await `setsettings` correctly
172
166
  await new Promise((resolve) => setTimeout(resolve, 0))
173
167
 
174
- const newConfigOnDisk = await fs.readFile("./project.inlang.json", { encoding: "utf-8" })
175
- expect(newConfigOnDisk).not.toBe(configWithDeifferentFormatting)
168
+ const newsettingsOnDisk = await fs.readFile("./project.inlang.json", { encoding: "utf-8" })
169
+ expect(newsettingsOnDisk).not.toBe(settingsWithDeifferentFormatting)
176
170
  })
177
171
  })
178
172
 
@@ -184,15 +178,15 @@ describe("initialization", () => {
184
178
  } satisfies InlangModule)
185
179
 
186
180
  const fs = createNodeishMemoryFs()
187
- await fs.writeFile("./project.inlang.json", JSON.stringify(config))
181
+ await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
188
182
 
189
- const inlang = await openInlangProject({
190
- projectFilePath: "./project.inlang.json",
183
+ const project = await loadProject({
184
+ settingsFilePath: "./project.inlang.json",
191
185
  nodeishFs: fs,
192
186
  _import: $badImport,
193
187
  })
194
188
 
195
- expect(inlang.errors()).not.toHaveLength(0)
189
+ expect(project.errors()).not.toHaveLength(0)
196
190
  })
197
191
  // it.todo("should throw if lintRules contain errors ???")
198
192
  // it.todo("should return meta data")
@@ -202,7 +196,7 @@ describe("initialization", () => {
202
196
 
203
197
  describe("flow", () => {
204
198
  it.todo("should not call functions multiple times")
205
- it.todo("should load modules after config")
199
+ it.todo("should load modules after settings")
206
200
  it.todo("should not load messages")
207
201
  it.todo("should not call lint")
208
202
  })
@@ -213,60 +207,63 @@ describe("initialization", () => {
213
207
  })
214
208
 
215
209
  describe("functionality", () => {
216
- describe("config", () => {
217
- it("should return the config", async () => {
210
+ describe("settings", () => {
211
+ it("should return the settings", async () => {
218
212
  const fs = await createNodeishMemoryFs()
219
- await fs.writeFile("./project.inlang.json", JSON.stringify(config))
220
- const inlang = await openInlangProject({
221
- projectFilePath: "./project.inlang.json",
213
+ await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
214
+ const project = await loadProject({
215
+ settingsFilePath: "./project.inlang.json",
222
216
  nodeishFs: fs,
223
217
  _import,
224
218
  })
225
219
 
226
- expect(getValue(inlang.config)).toStrictEqual(config)
220
+ expect(getValue(project.settings)).toStrictEqual(settings)
227
221
  })
228
222
 
229
- it("should set a new config", async () => {
223
+ it("should set a new settings", async () => {
230
224
  const fs = await createNodeishMemoryFs()
231
- await fs.writeFile("./project.inlang.json", JSON.stringify(config))
232
- const inlang = await openInlangProject({
233
- projectFilePath: "./project.inlang.json",
225
+ await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
226
+ const project = await loadProject({
227
+ settingsFilePath: "./project.inlang.json",
234
228
  nodeishFs: fs,
235
229
  _import,
236
230
  })
237
231
 
238
- expect(inlang.config()).toStrictEqual(config)
232
+ expect(project.settings()).toStrictEqual(settings)
239
233
 
240
- inlang.setConfig({ ...config, languageTags: ["en", "de"] })
241
- expect(getValue(inlang.config)).toStrictEqual({ ...config, languageTags: ["en", "de"] })
242
- expect(inlang.config()!.languageTags).toStrictEqual(["en", "de"])
234
+ project.setSettings({ ...settings, languageTags: ["en", "de"] })
235
+ expect(getValue(project.settings)).toStrictEqual({ ...settings, languageTags: ["en", "de"] })
236
+ expect(project.settings()!.languageTags).toStrictEqual(["en", "de"])
243
237
 
244
- inlang.setConfig({ ...config, languageTags: ["en", "de", "fr"] })
245
- expect(getValue(inlang.config)).toStrictEqual({ ...config, languageTags: ["en", "de", "fr"] })
246
- expect(inlang.config()!.languageTags).toStrictEqual(["en", "de", "fr"])
238
+ project.setSettings({ ...settings, languageTags: ["en", "de", "fr"] })
239
+ expect(getValue(project.settings)).toStrictEqual({
240
+ ...settings,
241
+ languageTags: ["en", "de", "fr"],
242
+ })
243
+ expect(project.settings()!.languageTags).toStrictEqual(["en", "de", "fr"])
247
244
  })
248
245
  })
249
246
 
250
- describe("setConfig", () => {
251
- it("should fail if config is not valid", async () => {
247
+ describe("setSettings", () => {
248
+ it("should fail if settings is not valid", async () => {
252
249
  const fs = await createNodeishMemoryFs()
253
- await fs.writeFile("./project.inlang.json", JSON.stringify(config))
254
- const inlang = await openInlangProject({
255
- projectFilePath: "./project.inlang.json",
250
+ await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
251
+ const project = await loadProject({
252
+ settingsFilePath: "./project.inlang.json",
256
253
  nodeishFs: fs,
257
254
  _import,
258
255
  })
259
256
 
260
- const result = inlang.setConfig({} as ProjectConfig)
257
+ const result = project.setSettings({} as ProjectSettings)
261
258
  expect(result.data).toBeUndefined()
262
- expect(result.error).toBeInstanceOf(InvalidConfigError)
259
+ expect(result.error).toBeInstanceOf(ProjectSettingsInvalidError)
263
260
  })
264
261
 
265
- it("should write config to disk", async () => {
262
+ it("should write settings to disk", async () => {
266
263
  const fs = await createNodeishMemoryFs()
267
- await fs.writeFile("./project.inlang.json", JSON.stringify(config))
268
- const inlang = await openInlangProject({
269
- projectFilePath: "./project.inlang.json",
264
+ await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
265
+ const project = await loadProject({
266
+ settingsFilePath: "./project.inlang.json",
270
267
  nodeishFs: fs,
271
268
  _import,
272
269
  })
@@ -274,7 +271,7 @@ describe("functionality", () => {
274
271
  const before = await fs.readFile("./project.inlang.json", { encoding: "utf-8" })
275
272
  expect(before).toBeDefined()
276
273
 
277
- const result = inlang.setConfig({ ...config, languageTags: [] })
274
+ const result = project.setSettings({ ...settings, languageTags: [] })
278
275
  expect(result.data).toBeUndefined()
279
276
  expect(result.error).toBeUndefined()
280
277
 
@@ -290,61 +287,61 @@ describe("functionality", () => {
290
287
  describe("installed", () => {
291
288
  it("should return the installed items", async () => {
292
289
  const fs = createNodeishMemoryFs()
293
- const config: ProjectConfig = {
290
+ const settings: ProjectSettings = {
294
291
  sourceLanguageTag: "en",
295
292
  languageTags: ["en"],
296
293
  modules: ["plugin.js", "lintRule.js"],
297
- settings: {},
298
294
  }
299
- await fs.writeFile("./project.inlang.json", JSON.stringify(config))
300
- const inlang = await openInlangProject({
301
- projectFilePath: "./project.inlang.json",
295
+ await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
296
+ const project = await loadProject({
297
+ settingsFilePath: "./project.inlang.json",
302
298
  nodeishFs: fs,
303
299
  _import,
304
300
  })
305
301
 
306
- expect(inlang.installed.plugins()[0]).toStrictEqual({
307
- meta: mockPlugin.meta,
308
- module: config.modules[0],
302
+ expect(project.installed.plugins()[0]).toStrictEqual({
303
+ id: mockPlugin.id,
304
+ description: mockPlugin.description,
305
+ displayName: mockPlugin.displayName,
306
+ module: settings.modules[0],
309
307
  })
310
308
 
311
- expect(inlang.installed.messageLintRules()[0]).toEqual({
312
- meta: mockMessageLintRule.meta,
313
- module: config.modules[1],
314
- lintLevel: "warning",
309
+ expect(project.installed.messageLintRules()[0]).toEqual({
310
+ id: mockMessageLintRule.id,
311
+ description: mockMessageLintRule.description,
312
+ displayName: mockMessageLintRule.displayName,
313
+ module: settings.modules[1],
314
+ level: "warning",
315
315
  })
316
316
  })
317
317
 
318
- it("should apply 'warning' as default lint level to lint rules that have no lint level defined in the config", async () => {
318
+ it("should apply 'warning' as default lint level to lint rules that have no lint level defined in the settings", async () => {
319
319
  const fs = createNodeishMemoryFs()
320
320
 
321
- const config: ProjectConfig = {
321
+ const settings: ProjectSettings = {
322
322
  sourceLanguageTag: "en",
323
323
  languageTags: ["en"],
324
324
  modules: ["plugin.js", "lintRule.js"],
325
- settings: {},
326
325
  }
327
326
 
328
- await fs.writeFile("./project.inlang.json", JSON.stringify(config))
327
+ await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
329
328
 
330
- const inlang = await openInlangProject({
331
- projectFilePath: "./project.inlang.json",
329
+ const project = await loadProject({
330
+ settingsFilePath: "./project.inlang.json",
332
331
  nodeishFs: fs,
333
332
  _import,
334
333
  })
335
334
 
336
- expect(inlang.installed.messageLintRules()[0]?.lintLevel).toBe("warning")
335
+ expect(project.installed.messageLintRules()[0]?.level).toBe("warning")
337
336
  })
338
337
 
339
338
  // yep, this is a typical "hm, we have a bug here, let's write a test for it" test
340
339
  it("should return lint reports if disabled is not set", async () => {
341
340
  const _mockLintRule: MessageLintRule = {
342
- meta: {
343
- id: "messageLintRule.namespace.mock",
344
- description: { en: "Mock lint rule description" },
345
- displayName: { en: "Mock Lint Rule" },
346
- },
347
- message: ({ report }) => {
341
+ id: "messageLintRule.namespace.mock",
342
+ description: { en: "Mock lint rule description" },
343
+ displayName: { en: "Mock Lint Rule" },
344
+ run: ({ report }) => {
348
345
  report({
349
346
  messageId: "some-message-1",
350
347
  languageTag: "en",
@@ -353,11 +350,9 @@ describe("functionality", () => {
353
350
  },
354
351
  }
355
352
  const _mockPlugin: Plugin = {
356
- meta: {
357
- id: "plugin.inlang.i18next",
358
- description: { en: "Mock plugin description" },
359
- displayName: { en: "Mock Plugin" },
360
- },
353
+ id: "plugin.project.i18next",
354
+ description: { en: "Mock plugin description" },
355
+ displayName: { en: "Mock Plugin" },
361
356
  loadMessages: () => [{ id: "some-message", selectors: [], variants: [] }],
362
357
  saveMessages: () => undefined,
363
358
  }
@@ -368,8 +363,7 @@ describe("functionality", () => {
368
363
  sourceLanguageTag: "en",
369
364
  languageTags: ["en"],
370
365
  modules: ["plugin.js", "lintRule.js"],
371
- settings: {},
372
- } satisfies ProjectConfig),
366
+ } satisfies ProjectSettings),
373
367
  )
374
368
 
375
369
  const _import: ImportFunction = async (name) => {
@@ -377,27 +371,25 @@ describe("functionality", () => {
377
371
  default: name === "plugin.js" ? _mockPlugin : _mockLintRule,
378
372
  } satisfies InlangModule
379
373
  }
380
- const inlang = await openInlangProject({
381
- projectFilePath: "./project.inlang.json",
374
+ const project = await loadProject({
375
+ settingsFilePath: "./project.inlang.json",
382
376
  nodeishFs: fs,
383
377
  _import,
384
378
  })
385
379
 
386
380
  await new Promise((resolve) => setTimeout(resolve, 510))
387
381
 
388
- expect(inlang.query.messageLintReports.getAll()).toHaveLength(1)
389
- expect(inlang.query.messageLintReports.getAll()?.[0]?.ruleId).toBe(_mockLintRule.meta.id)
390
- expect(inlang.installed.messageLintRules()).toHaveLength(1)
382
+ expect(project.query.messageLintReports.getAll()).toHaveLength(1)
383
+ expect(project.query.messageLintReports.getAll()?.[0]?.ruleId).toBe(_mockLintRule.id)
384
+ expect(project.installed.messageLintRules()).toHaveLength(1)
391
385
  })
392
386
 
393
387
  it("should return lint reports for a single message", async () => {
394
388
  const _mockLintRule: MessageLintRule = {
395
- meta: {
396
- id: "messageLintRule.namepsace.mock",
397
- description: { en: "Mock lint rule description" },
398
- displayName: { en: "Mock Lint Rule" },
399
- },
400
- message: ({ report }) => {
389
+ id: "messageLintRule.namepsace.mock",
390
+ description: { en: "Mock lint rule description" },
391
+ displayName: { en: "Mock Lint Rule" },
392
+ run: ({ report }) => {
401
393
  report({
402
394
  messageId: "some-message",
403
395
  languageTag: "en",
@@ -406,23 +398,20 @@ describe("functionality", () => {
406
398
  },
407
399
  }
408
400
  const _mockPlugin: Plugin = {
409
- meta: {
410
- id: "plugin.inlang.i18next",
411
- description: { en: "Mock plugin description" },
412
- displayName: { en: "Mock Plugin" },
413
- },
401
+ id: "plugin.project.i18next",
402
+ description: { en: "Mock plugin description" },
403
+ displayName: { en: "Mock Plugin" },
414
404
  loadMessages: () => [{ id: "some-message", selectors: [], variants: [] }],
415
405
  saveMessages: () => undefined,
416
406
  }
417
407
  const fs = await createNodeishMemoryFs()
418
408
  await fs.writeFile(
419
- "./inlang.config.json",
409
+ "./project.settings.json",
420
410
  JSON.stringify({
421
411
  sourceLanguageTag: "en",
422
412
  languageTags: ["en"],
423
413
  modules: ["plugin.js", "lintRule.js"],
424
- settings: {},
425
- } satisfies ProjectConfig),
414
+ } satisfies ProjectSettings),
426
415
  )
427
416
  const _import: ImportFunction = async (name) => {
428
417
  return {
@@ -430,8 +419,8 @@ describe("functionality", () => {
430
419
  } satisfies InlangModule
431
420
  }
432
421
 
433
- const inlang = await openInlangProject({
434
- projectFilePath: "./inlang.config.json",
422
+ const project = await loadProject({
423
+ settingsFilePath: "./project.settings.json",
435
424
  nodeishFs: fs,
436
425
  _import,
437
426
  })
@@ -439,7 +428,7 @@ describe("functionality", () => {
439
428
  await new Promise((resolve) => setTimeout(resolve, 510))
440
429
 
441
430
  expect(
442
- inlang.query.messageLintReports.get({ where: { messageId: "some-message" } }),
431
+ project.query.messageLintReports.get({ where: { messageId: "some-message" } }),
443
432
  ).toHaveLength(1)
444
433
  })
445
434
  })
@@ -447,13 +436,13 @@ describe("functionality", () => {
447
436
  describe("errors", () => {
448
437
  it("should return the errors", async () => {
449
438
  const fs = await createNodeishMemoryFs()
450
- await fs.writeFile("./project.inlang.json", JSON.stringify(config))
451
- const inlang = await openInlangProject({
452
- projectFilePath: "./project.inlang.json",
439
+ await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
440
+ const project = await loadProject({
441
+ settingsFilePath: "./project.inlang.json",
453
442
  nodeishFs: fs,
454
443
  _import,
455
444
  })
456
- inlang.errors.subscribe((errors) => {
445
+ project.errors.subscribe((errors) => {
457
446
  expect(errors).toStrictEqual([])
458
447
  })
459
448
  })
@@ -462,15 +451,15 @@ describe("functionality", () => {
462
451
  describe("customApi", () => {
463
452
  it("should return the app specific api", async () => {
464
453
  const fs = await createNodeishMemoryFs()
465
- await fs.writeFile("./project.inlang.json", JSON.stringify(config))
466
- const inlang = await openInlangProject({
467
- projectFilePath: "./project.inlang.json",
454
+ await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
455
+ const project = await loadProject({
456
+ settingsFilePath: "./project.inlang.json",
468
457
  nodeishFs: fs,
469
458
  _import,
470
459
  })
471
460
 
472
- inlang.customApi.subscribe((api) => {
473
- expect(api["app.inlang.ideExtension"]).toBeDefined()
461
+ project.customApi.subscribe((api) => {
462
+ expect(api["app.project.ideExtension"]).toBeDefined()
474
463
  })
475
464
  })
476
465
  })
@@ -478,20 +467,20 @@ describe("functionality", () => {
478
467
  describe("messages", () => {
479
468
  it("should return the messages", async () => {
480
469
  const fs = await createNodeishMemoryFs()
481
- await fs.writeFile("./project.inlang.json", JSON.stringify(config))
482
- const inlang = await openInlangProject({
483
- projectFilePath: "./project.inlang.json",
470
+ await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
471
+ const project = await loadProject({
472
+ settingsFilePath: "./project.inlang.json",
484
473
  nodeishFs: fs,
485
474
  _import,
486
475
  })
487
476
 
488
- expect(Object.values(inlang.query.messages.getAll())).toEqual(exampleMessages)
477
+ expect(Object.values(project.query.messages.getAll())).toEqual(exampleMessages)
489
478
  })
490
479
  })
491
480
 
492
481
  describe("query", () => {
493
- it("updates should trigger the plugin persistence", async () => {
494
- const fs = await createNodeishMemoryFs()
482
+ it("should call saveMessages() on updates", async () => {
483
+ const fs = createNodeishMemoryFs()
495
484
 
496
485
  await fs.writeFile(
497
486
  "./project.inlang.json",
@@ -499,10 +488,8 @@ describe("functionality", () => {
499
488
  sourceLanguageTag: "en",
500
489
  languageTags: ["en", "de"],
501
490
  modules: ["plugin.js"],
502
- settings: {
503
- "plugin.inlang.json": {
504
- pathPattern: "./resources/{languageTag}.json",
505
- },
491
+ "plugin.project.json": {
492
+ pathPattern: "./resources/{languageTag}.json",
506
493
  },
507
494
  }),
508
495
  )
@@ -512,11 +499,9 @@ describe("functionality", () => {
512
499
  const mockSaveFn = vi.fn()
513
500
 
514
501
  const _mockPlugin: Plugin = {
515
- meta: {
516
- id: "plugin.inlang.json",
517
- description: { en: "Mock plugin description" },
518
- displayName: { en: "Mock Plugin" },
519
- },
502
+ id: "plugin.project.json",
503
+ description: { en: "Mock plugin description" },
504
+ displayName: { en: "Mock Plugin" },
520
505
  loadMessages: () => exampleMessages,
521
506
  saveMessages: mockSaveFn,
522
507
  }
@@ -527,13 +512,13 @@ describe("functionality", () => {
527
512
  } satisfies InlangModule
528
513
  }
529
514
 
530
- const inlang = await openInlangProject({
531
- projectFilePath: "./project.inlang.json",
515
+ const project = await loadProject({
516
+ settingsFilePath: "./project.inlang.json",
532
517
  nodeishFs: fs,
533
518
  _import,
534
519
  })
535
520
 
536
- await inlang.query.messages.upsert({
521
+ await project.query.messages.upsert({
537
522
  where: { id: "a" },
538
523
  data: {
539
524
  id: "a",
@@ -563,7 +548,7 @@ describe("functionality", () => {
563
548
  },
564
549
  })
565
550
 
566
- await inlang.query.messages.upsert({
551
+ await project.query.messages.upsert({
567
552
  where: { id: "b" },
568
553
  data: {
569
554
  id: "b",
@@ -662,38 +647,37 @@ describe("functionality", () => {
662
647
  describe("lint", () => {
663
648
  it.todo("should throw if lint reports are not initialized yet", async () => {
664
649
  const fs = await createNodeishMemoryFs()
665
- await fs.writeFile("./project.inlang.json", JSON.stringify(config))
666
- const inlang = await openInlangProject({
667
- projectFilePath: "./project.inlang.json",
650
+ await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
651
+ const project = await loadProject({
652
+ settingsFilePath: "./project.inlang.json",
668
653
  nodeishFs: fs,
669
654
  _import,
670
655
  })
671
656
  // TODO: test with real lint rules
672
657
  try {
673
- inlang.query.messageLintReports.getAll.subscribe((r) => expect(r).toEqual(undefined))
658
+ project.query.messageLintReports.getAll.subscribe((r) => expect(r).toEqual(undefined))
674
659
  throw new Error("Should not reach this")
675
660
  } catch (e) {
676
661
  expect((e as Error).message).toBe("lint not initialized yet")
677
662
  }
678
663
  })
679
664
  it("should return the message lint reports", async () => {
680
- const config: ProjectConfig = {
665
+ const settings: ProjectSettings = {
681
666
  sourceLanguageTag: "en",
682
667
  languageTags: ["en"],
683
668
  modules: ["lintRule.js"],
684
- settings: {},
685
669
  }
686
670
  const fs = createNodeishMemoryFs()
687
- await fs.writeFile("./project.inlang.json", JSON.stringify(config))
688
- const inlang = await openInlangProject({
689
- projectFilePath: "./project.inlang.json",
671
+ await fs.writeFile("./project.inlang.json", JSON.stringify(settings))
672
+ const project = await loadProject({
673
+ settingsFilePath: "./project.inlang.json",
690
674
  nodeishFs: fs,
691
675
  _import: async () => ({
692
676
  default: mockMessageLintRule,
693
677
  }),
694
678
  })
695
679
  // TODO: test with real lint rules
696
- inlang.query.messageLintReports.getAll.subscribe((r) => expect(r).toEqual([]))
680
+ project.query.messageLintReports.getAll.subscribe((r) => expect(r).toEqual([]))
697
681
  })
698
682
  })
699
683
  })