@inlang/sdk 0.6.0 → 0.8.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.test.js +5 -5
- package/dist/createMessageLintReportsQuery.d.ts.map +1 -1
- package/dist/createMessageLintReportsQuery.js +0 -1
- package/dist/createMessagesQuery.js +1 -1
- package/dist/createMessagesQuery.test.js +9 -0
- package/dist/loadProject.js +3 -2
- package/dist/loadProject.test.js +10 -10
- package/dist/messages/variant.d.ts +4 -4
- package/dist/messages/variant.d.ts.map +1 -1
- package/dist/messages/variant.js +55 -55
- package/dist/messages/variant.test.js +102 -45
- 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/errors.js +1 -1
- package/dist/resolve-modules/plugins/resolvePlugins.d.ts.map +1 -1
- package/dist/resolve-modules/plugins/resolvePlugins.js +1 -11
- package/dist/resolve-modules/plugins/resolvePlugins.test.js +0 -28
- package/dist/resolve-modules/plugins/types.d.ts +0 -4
- package/dist/resolve-modules/plugins/types.d.ts.map +1 -1
- package/dist/test-utilities/createMessage.d.ts +1 -1
- package/dist/test-utilities/createMessage.js +1 -1
- package/dist/test-utilities/createMessage.test.js +4 -4
- package/package.json +1 -1
- package/src/adapter/solidAdapter.test.ts +13 -13
- package/src/adapter/solidAdapter.ts +1 -1
- package/src/api.ts +2 -2
- package/src/createMessageLintReportsQuery.ts +4 -5
- package/src/createMessagesQuery.test.ts +30 -17
- package/src/createMessagesQuery.ts +3 -3
- package/src/lint/message/lintMessages.ts +1 -1
- package/src/lint/message/lintSingleMessage.test.ts +1 -1
- package/src/lint/message/lintSingleMessage.ts +2 -2
- package/src/loadProject.test.ts +14 -14
- package/src/loadProject.ts +15 -15
- package/src/messages/errors.ts +2 -2
- package/src/messages/variant.test.ts +113 -49
- package/src/messages/variant.ts +73 -67
- package/src/parseConfig.ts +2 -2
- package/src/resolve-modules/import.test.ts +2 -2
- package/src/resolve-modules/import.ts +1 -1
- package/src/resolve-modules/message-lint-rules/resolveMessageLintRules.ts +1 -1
- package/src/resolve-modules/plugins/errors.ts +2 -2
- package/src/resolve-modules/plugins/resolvePlugins.test.ts +2 -33
- package/src/resolve-modules/plugins/resolvePlugins.ts +16 -27
- package/src/resolve-modules/plugins/types.ts +0 -4
- package/src/resolve-modules/resolveModules.ts +4 -4
- package/src/test-utilities/createMessage.test.ts +7 -7
- package/src/test-utilities/createMessage.ts +1 -1
|
@@ -12,7 +12,7 @@ describe("$import", async () => {
|
|
|
12
12
|
export function hello() {
|
|
13
13
|
return "hello";
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
`
|
|
16
16
|
)
|
|
17
17
|
|
|
18
18
|
// mock module in a directory
|
|
@@ -23,7 +23,7 @@ describe("$import", async () => {
|
|
|
23
23
|
export function hello() {
|
|
24
24
|
return "world";
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
`
|
|
27
27
|
)
|
|
28
28
|
|
|
29
29
|
const _import = createImport({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Plugin } from "@inlang/plugin"
|
|
2
2
|
|
|
3
3
|
type PluginErrorOptions = {
|
|
4
|
-
plugin: Plugin["id"]
|
|
4
|
+
plugin: Plugin["id"] | undefined
|
|
5
5
|
} & Partial<Error>
|
|
6
6
|
|
|
7
7
|
class PluginError extends Error {
|
|
@@ -10,7 +10,7 @@ class PluginError extends Error {
|
|
|
10
10
|
constructor(message: string, options: PluginErrorOptions) {
|
|
11
11
|
super(message)
|
|
12
12
|
this.name = "PluginError"
|
|
13
|
-
this.plugin = options.plugin
|
|
13
|
+
this.plugin = options.plugin ?? "unknown"
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -91,7 +91,7 @@ describe("loadMessages", () => {
|
|
|
91
91
|
await resolved.data.loadMessages!({
|
|
92
92
|
languageTags: ["en"],
|
|
93
93
|
sourceLanguageTag: "en",
|
|
94
|
-
})
|
|
94
|
+
})
|
|
95
95
|
).toEqual([{ id: "test", expressions: [], selectors: [], variants: [] }])
|
|
96
96
|
})
|
|
97
97
|
|
|
@@ -198,37 +198,6 @@ describe("saveMessages", () => {
|
|
|
198
198
|
})
|
|
199
199
|
})
|
|
200
200
|
|
|
201
|
-
describe("detectedLanguageTags", () => {
|
|
202
|
-
it("should merge language tags from plugins", async () => {
|
|
203
|
-
const mockPlugin: Plugin = {
|
|
204
|
-
id: "plugin.namepsace.detectedLanguageTags",
|
|
205
|
-
description: { en: "My plugin description" },
|
|
206
|
-
displayName: { en: "My plugin" },
|
|
207
|
-
detectedLanguageTags: async () => ["de", "en"],
|
|
208
|
-
addCustomApi: () => {
|
|
209
|
-
return {}
|
|
210
|
-
},
|
|
211
|
-
}
|
|
212
|
-
const mockPlugin2: Plugin = {
|
|
213
|
-
id: "plugin.namepsace.detectedLanguageTags2",
|
|
214
|
-
description: { en: "My plugin description" },
|
|
215
|
-
displayName: { en: "My plugin" },
|
|
216
|
-
addCustomApi: () => {
|
|
217
|
-
return {}
|
|
218
|
-
},
|
|
219
|
-
detectedLanguageTags: async () => ["de", "fr"],
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
const resolved = await resolvePlugins({
|
|
223
|
-
plugins: [mockPlugin, mockPlugin2],
|
|
224
|
-
settings: {},
|
|
225
|
-
nodeishFs: {} as any,
|
|
226
|
-
})
|
|
227
|
-
|
|
228
|
-
expect(resolved.data.detectedLanguageTags).toEqual(["de", "en", "fr"])
|
|
229
|
-
})
|
|
230
|
-
})
|
|
231
|
-
|
|
232
201
|
describe("addCustomApi", () => {
|
|
233
202
|
it("it should resolve app specific api", async () => {
|
|
234
203
|
const mockPlugin: Plugin = {
|
|
@@ -329,7 +298,7 @@ describe("addCustomApi", () => {
|
|
|
329
298
|
|
|
330
299
|
expect(resolved.data.customApi).toHaveProperty("app.inlang.placeholder")
|
|
331
300
|
expect(
|
|
332
|
-
(resolved.data.customApi?.["app.inlang.placeholder"] as any).messageReferenceMatcher()
|
|
301
|
+
(resolved.data.customApi?.["app.inlang.placeholder"] as any).messageReferenceMatcher()
|
|
333
302
|
).toEqual({
|
|
334
303
|
hello: "world",
|
|
335
304
|
})
|
|
@@ -27,7 +27,6 @@ export const resolvePlugins: ResolvePluginsFunction = async (args) => {
|
|
|
27
27
|
data: {
|
|
28
28
|
loadMessages: undefined as any,
|
|
29
29
|
saveMessages: undefined as any,
|
|
30
|
-
detectedLanguageTags: [],
|
|
31
30
|
customApi: {},
|
|
32
31
|
},
|
|
33
32
|
errors: [],
|
|
@@ -46,8 +45,8 @@ export const resolvePlugins: ResolvePluginsFunction = async (args) => {
|
|
|
46
45
|
result.errors.push(
|
|
47
46
|
new PluginHasInvalidIdError(
|
|
48
47
|
`Plugin ${plugin.id} has an invalid id "${plugin.id}". It must be kebap-case and contain a namespace like project.my-plugin.`,
|
|
49
|
-
{ plugin: plugin.id }
|
|
50
|
-
)
|
|
48
|
+
{ plugin: plugin.id }
|
|
49
|
+
)
|
|
51
50
|
)
|
|
52
51
|
}
|
|
53
52
|
|
|
@@ -58,8 +57,8 @@ export const resolvePlugins: ResolvePluginsFunction = async (args) => {
|
|
|
58
57
|
`Plugin ${plugin.id} uses reserved namespace 'inlang'.`,
|
|
59
58
|
{
|
|
60
59
|
plugin: plugin.id,
|
|
61
|
-
}
|
|
62
|
-
)
|
|
60
|
+
}
|
|
61
|
+
)
|
|
63
62
|
)
|
|
64
63
|
}
|
|
65
64
|
|
|
@@ -71,8 +70,8 @@ export const resolvePlugins: ResolvePluginsFunction = async (args) => {
|
|
|
71
70
|
{
|
|
72
71
|
plugin: plugin.id,
|
|
73
72
|
cause: errors,
|
|
74
|
-
}
|
|
75
|
-
)
|
|
73
|
+
}
|
|
74
|
+
)
|
|
76
75
|
)
|
|
77
76
|
}
|
|
78
77
|
|
|
@@ -81,8 +80,8 @@ export const resolvePlugins: ResolvePluginsFunction = async (args) => {
|
|
|
81
80
|
result.errors.push(
|
|
82
81
|
new PluginLoadMessagesFunctionAlreadyDefinedError(
|
|
83
82
|
`Plugin ${plugin.id} defines the loadMessages function, but it was already defined by another plugin.`,
|
|
84
|
-
{ plugin: plugin.id }
|
|
85
|
-
)
|
|
83
|
+
{ plugin: plugin.id }
|
|
84
|
+
)
|
|
86
85
|
)
|
|
87
86
|
}
|
|
88
87
|
|
|
@@ -90,8 +89,8 @@ export const resolvePlugins: ResolvePluginsFunction = async (args) => {
|
|
|
90
89
|
result.errors.push(
|
|
91
90
|
new PluginSaveMessagesFunctionAlreadyDefinedError(
|
|
92
91
|
`Plugin ${plugin.id} defines the saveMessages function, but it was already defined by another plugin.`,
|
|
93
|
-
{ plugin: plugin.id }
|
|
94
|
-
)
|
|
92
|
+
{ plugin: plugin.id }
|
|
93
|
+
)
|
|
95
94
|
)
|
|
96
95
|
}
|
|
97
96
|
|
|
@@ -101,7 +100,7 @@ export const resolvePlugins: ResolvePluginsFunction = async (args) => {
|
|
|
101
100
|
const { data: customApi, error } = tryCatch(() =>
|
|
102
101
|
plugin.addCustomApi!({
|
|
103
102
|
settings: args.settings?.[plugin.id] ?? {},
|
|
104
|
-
})
|
|
103
|
+
})
|
|
105
104
|
)
|
|
106
105
|
if (error) {
|
|
107
106
|
// @ts-ignore
|
|
@@ -112,8 +111,8 @@ export const resolvePlugins: ResolvePluginsFunction = async (args) => {
|
|
|
112
111
|
result.errors.push(
|
|
113
112
|
new PluginReturnedInvalidCustomApiError(
|
|
114
113
|
`Plugin ${plugin.id} defines the addCustomApi function, but it does not return an object.`,
|
|
115
|
-
{ plugin: plugin.id, cause: error }
|
|
116
|
-
)
|
|
114
|
+
{ plugin: plugin.id, cause: error }
|
|
115
|
+
)
|
|
117
116
|
)
|
|
118
117
|
}
|
|
119
118
|
}
|
|
@@ -145,21 +144,11 @@ export const resolvePlugins: ResolvePluginsFunction = async (args) => {
|
|
|
145
144
|
})
|
|
146
145
|
}
|
|
147
146
|
|
|
148
|
-
if (typeof plugin.detectedLanguageTags === "function") {
|
|
149
|
-
const detectedLangugeTags = await plugin.detectedLanguageTags!({
|
|
150
|
-
settings: args.settings?.[plugin.id] ?? {},
|
|
151
|
-
nodeishFs: args.nodeishFs,
|
|
152
|
-
})
|
|
153
|
-
result.data.detectedLanguageTags = [
|
|
154
|
-
...new Set([...result.data.detectedLanguageTags, ...detectedLangugeTags]),
|
|
155
|
-
]
|
|
156
|
-
}
|
|
157
|
-
|
|
158
147
|
if (typeof plugin.addCustomApi === "function") {
|
|
159
148
|
const { data: customApi } = tryCatch(() =>
|
|
160
149
|
plugin.addCustomApi!({
|
|
161
150
|
settings: args.settings?.[plugin.id] ?? {},
|
|
162
|
-
})
|
|
151
|
+
})
|
|
163
152
|
)
|
|
164
153
|
if (customApi) {
|
|
165
154
|
result.data.customApi = deepmerge(result.data.customApi, customApi)
|
|
@@ -175,8 +164,8 @@ export const resolvePlugins: ResolvePluginsFunction = async (args) => {
|
|
|
175
164
|
result.errors.push(
|
|
176
165
|
new PluginsDoNotProvideLoadOrSaveMessagesError(
|
|
177
166
|
"It seems you did not install any plugin that handles messages. Please add one to make inlang work. See https://inlang.com/documentation/plugins/registry.",
|
|
178
|
-
{ plugin:
|
|
179
|
-
)
|
|
167
|
+
{ plugin: undefined }
|
|
168
|
+
)
|
|
180
169
|
)
|
|
181
170
|
}
|
|
182
171
|
|
|
@@ -52,10 +52,6 @@ export type ResolvedPluginApi = {
|
|
|
52
52
|
sourceLanguageTag: LanguageTag
|
|
53
53
|
}) => Promise<Message[]> | Message[]
|
|
54
54
|
saveMessages: (args: { messages: Message[] }) => Promise<void> | void
|
|
55
|
-
/**
|
|
56
|
-
* Detect language tags in the project provided plugins.
|
|
57
|
-
*/
|
|
58
|
-
detectedLanguageTags: LanguageTag[]
|
|
59
55
|
/**
|
|
60
56
|
* App specific APIs.
|
|
61
57
|
*
|
|
@@ -38,7 +38,7 @@ export const resolveModules: ResolveModuleFunction = async (args) => {
|
|
|
38
38
|
new ModuleImportError(`Couldn't import the plugin "${module}"`, {
|
|
39
39
|
module: module,
|
|
40
40
|
cause: importedModule.error as Error,
|
|
41
|
-
})
|
|
41
|
+
})
|
|
42
42
|
)
|
|
43
43
|
continue
|
|
44
44
|
}
|
|
@@ -48,7 +48,7 @@ export const resolveModules: ResolveModuleFunction = async (args) => {
|
|
|
48
48
|
moduleErrors.push(
|
|
49
49
|
new ModuleHasNoExportsError(`Module "${module}" has no exports.`, {
|
|
50
50
|
module: module,
|
|
51
|
-
})
|
|
51
|
+
})
|
|
52
52
|
)
|
|
53
53
|
continue
|
|
54
54
|
}
|
|
@@ -57,12 +57,12 @@ export const resolveModules: ResolveModuleFunction = async (args) => {
|
|
|
57
57
|
|
|
58
58
|
if (isValidModule === false) {
|
|
59
59
|
const errors = [...ModuleCompiler.Errors(importedModule.data)].map(
|
|
60
|
-
(e) => `${e.path} ${e.message}
|
|
60
|
+
(e) => `${e.path} ${e.message}`
|
|
61
61
|
)
|
|
62
62
|
moduleErrors.push(
|
|
63
63
|
new ModuleExportIsInvalidError(`Module "${module}" is invalid: ` + errors.join("\n"), {
|
|
64
64
|
module: module,
|
|
65
|
-
})
|
|
65
|
+
})
|
|
66
66
|
)
|
|
67
67
|
continue
|
|
68
68
|
}
|
|
@@ -5,7 +5,7 @@ test("should create a simple message", () => {
|
|
|
5
5
|
expect(
|
|
6
6
|
createMessage("welcome", {
|
|
7
7
|
de: "Hallo inlang",
|
|
8
|
-
})
|
|
8
|
+
})
|
|
9
9
|
).toMatchInlineSnapshot(`
|
|
10
10
|
{
|
|
11
11
|
"id": "welcome",
|
|
@@ -13,7 +13,7 @@ test("should create a simple message", () => {
|
|
|
13
13
|
"variants": [
|
|
14
14
|
{
|
|
15
15
|
"languageTag": "de",
|
|
16
|
-
"match":
|
|
16
|
+
"match": [],
|
|
17
17
|
"pattern": [
|
|
18
18
|
{
|
|
19
19
|
"type": "Text",
|
|
@@ -34,7 +34,7 @@ test("should create a message with pattern", () => {
|
|
|
34
34
|
{ type: "VariableReference", name: "name" },
|
|
35
35
|
{ type: "Text", value: '"' },
|
|
36
36
|
],
|
|
37
|
-
})
|
|
37
|
+
})
|
|
38
38
|
).toMatchInlineSnapshot(`
|
|
39
39
|
{
|
|
40
40
|
"id": "greeting",
|
|
@@ -42,7 +42,7 @@ test("should create a message with pattern", () => {
|
|
|
42
42
|
"variants": [
|
|
43
43
|
{
|
|
44
44
|
"languageTag": "en",
|
|
45
|
-
"match":
|
|
45
|
+
"match": [],
|
|
46
46
|
"pattern": [
|
|
47
47
|
{
|
|
48
48
|
"type": "Text",
|
|
@@ -68,7 +68,7 @@ test("should create a message with a pattern", () => {
|
|
|
68
68
|
createMessage("welcome", {
|
|
69
69
|
en: "hello inlang",
|
|
70
70
|
de: [{ type: "Text", value: "Hallo inlang" }],
|
|
71
|
-
})
|
|
71
|
+
})
|
|
72
72
|
).toMatchInlineSnapshot(`
|
|
73
73
|
{
|
|
74
74
|
"id": "welcome",
|
|
@@ -76,7 +76,7 @@ test("should create a message with a pattern", () => {
|
|
|
76
76
|
"variants": [
|
|
77
77
|
{
|
|
78
78
|
"languageTag": "en",
|
|
79
|
-
"match":
|
|
79
|
+
"match": [],
|
|
80
80
|
"pattern": [
|
|
81
81
|
{
|
|
82
82
|
"type": "Text",
|
|
@@ -86,7 +86,7 @@ test("should create a message with a pattern", () => {
|
|
|
86
86
|
},
|
|
87
87
|
{
|
|
88
88
|
"languageTag": "de",
|
|
89
|
-
"match":
|
|
89
|
+
"match": [],
|
|
90
90
|
"pattern": [
|
|
91
91
|
{
|
|
92
92
|
"type": "Text",
|