@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
|
@@ -8,7 +8,7 @@ export const resolveMessageLintRules = (args) => {
|
|
|
8
8
|
};
|
|
9
9
|
for (const rule of args.messageLintRules) {
|
|
10
10
|
if (Value.Check(MessageLintRule, rule) === false) {
|
|
11
|
-
result.errors.push(new MessageLintRuleIsInvalidError(`Couldn't parse lint rule "${rule.
|
|
11
|
+
result.errors.push(new MessageLintRuleIsInvalidError(`Couldn't parse lint rule "${rule.id}"`, {
|
|
12
12
|
module: "not implemented",
|
|
13
13
|
}));
|
|
14
14
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/resolve-modules/plugins/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAE5C,KAAK,kBAAkB,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/resolve-modules/plugins/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAE5C,KAAK,kBAAkB,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;CACpB,GAAG,OAAO,CAAC,KAAK,CAAC,CAAA;AAElB,cAAM,WAAY,SAAQ,KAAK;IAC9B,SAAgB,MAAM,EAAE,MAAM,CAAA;gBAElB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB;CAKxD;AAED,qBAAa,uBAAwB,SAAQ,WAAW;gBAC3C,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB;CAIxD;AAED,qBAAa,gCAAiC,SAAQ,WAAW;gBACpD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB;CAIxD;AAED,qBAAa,2BAA4B,SAAQ,WAAW;gBAC/C,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB;CAIxD;AAED,qBAAa,6CAA8C,SAAQ,WAAW;gBACjE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB;CAIxD;AAED,qBAAa,6CAA8C,SAAQ,WAAW;gBACjE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB;CAIxD;AAED,qBAAa,mCAAoC,SAAQ,WAAW;gBACvD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB;CAIxD;AAED,qBAAa,0CAA2C,SAAQ,WAAW;gBAC9D,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB;CAKxD"}
|
|
@@ -26,35 +26,35 @@ export const resolvePlugins = async (args) => {
|
|
|
26
26
|
* -------------- RESOLVE PLUGIN --------------
|
|
27
27
|
*/
|
|
28
28
|
// -- INVALID ID in META --
|
|
29
|
-
const hasInvalidId = errors.some((error) => error.path === "/
|
|
29
|
+
const hasInvalidId = errors.some((error) => error.path === "/id");
|
|
30
30
|
if (hasInvalidId) {
|
|
31
|
-
result.errors.push(new PluginHasInvalidIdError(`Plugin ${plugin.
|
|
31
|
+
result.errors.push(new PluginHasInvalidIdError(`Plugin ${plugin.id} has an invalid id "${plugin.id}". It must be kebap-case and contain a namespace like project.my-plugin.`, { plugin: plugin.id }));
|
|
32
32
|
}
|
|
33
33
|
// -- USES RESERVED NAMESPACE --
|
|
34
|
-
if (plugin.
|
|
35
|
-
result.errors.push(new PluginUsesReservedNamespaceError(`Plugin ${plugin.
|
|
36
|
-
plugin: plugin.
|
|
34
|
+
if (plugin.id.includes("inlang") && !whitelistedPlugins.includes(plugin.id)) {
|
|
35
|
+
result.errors.push(new PluginUsesReservedNamespaceError(`Plugin ${plugin.id} uses reserved namespace 'inlang'.`, {
|
|
36
|
+
plugin: plugin.id,
|
|
37
37
|
}));
|
|
38
38
|
}
|
|
39
39
|
// -- USES INVALID SCHEMA --
|
|
40
40
|
if (errors.length > 0) {
|
|
41
|
-
result.errors.push(new PluginHasInvalidSchemaError(`Plugin ${plugin.
|
|
42
|
-
plugin: plugin.
|
|
41
|
+
result.errors.push(new PluginHasInvalidSchemaError(`Plugin ${plugin.id} uses an invalid schema. Please check the documentation for the correct Plugin type.`, {
|
|
42
|
+
plugin: plugin.id,
|
|
43
43
|
cause: errors,
|
|
44
44
|
}));
|
|
45
45
|
}
|
|
46
46
|
// -- ALREADY DEFINED LOADMESSAGES / SAVEMESSAGES / DETECTEDLANGUAGETAGS --
|
|
47
47
|
if (typeof plugin.loadMessages === "function" && result.data.loadMessages !== undefined) {
|
|
48
|
-
result.errors.push(new PluginLoadMessagesFunctionAlreadyDefinedError(`Plugin ${plugin.
|
|
48
|
+
result.errors.push(new PluginLoadMessagesFunctionAlreadyDefinedError(`Plugin ${plugin.id} defines the loadMessages function, but it was already defined by another plugin.`, { plugin: plugin.id }));
|
|
49
49
|
}
|
|
50
50
|
if (typeof plugin.saveMessages === "function" && result.data.saveMessages !== undefined) {
|
|
51
|
-
result.errors.push(new PluginSaveMessagesFunctionAlreadyDefinedError(`Plugin ${plugin.
|
|
51
|
+
result.errors.push(new PluginSaveMessagesFunctionAlreadyDefinedError(`Plugin ${plugin.id} defines the saveMessages function, but it was already defined by another plugin.`, { plugin: plugin.id }));
|
|
52
52
|
}
|
|
53
53
|
// --- ADD APP SPECIFIC API ---
|
|
54
54
|
if (typeof plugin.addCustomApi === "function") {
|
|
55
55
|
// TODO: why do we call this function 2 times (here for validation and later for retrieving the actual value)?
|
|
56
56
|
const { data: customApi, error } = tryCatch(() => plugin.addCustomApi({
|
|
57
|
-
settings: args.settings?.[plugin.
|
|
57
|
+
settings: args.settings?.[plugin.id] ?? {},
|
|
58
58
|
}));
|
|
59
59
|
if (error) {
|
|
60
60
|
// @ts-ignore
|
|
@@ -62,7 +62,7 @@ export const resolvePlugins = async (args) => {
|
|
|
62
62
|
result.errors.push(error); // TODO: add correct error type
|
|
63
63
|
}
|
|
64
64
|
if (typeof customApi !== "object") {
|
|
65
|
-
result.errors.push(new PluginReturnedInvalidCustomApiError(`Plugin ${plugin.
|
|
65
|
+
result.errors.push(new PluginReturnedInvalidCustomApiError(`Plugin ${plugin.id} defines the addCustomApi function, but it does not return an object.`, { plugin: plugin.id, cause: error }));
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
// -- CONTINUE IF ERRORS --
|
|
@@ -75,20 +75,20 @@ export const resolvePlugins = async (args) => {
|
|
|
75
75
|
if (typeof plugin.loadMessages === "function") {
|
|
76
76
|
result.data.loadMessages = (_args) => plugin.loadMessages({
|
|
77
77
|
..._args,
|
|
78
|
-
settings: args.settings?.[plugin.
|
|
78
|
+
settings: args.settings?.[plugin.id] ?? {},
|
|
79
79
|
nodeishFs: args.nodeishFs,
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
if (typeof plugin.saveMessages === "function") {
|
|
83
83
|
result.data.saveMessages = (_args) => plugin.saveMessages({
|
|
84
84
|
..._args,
|
|
85
|
-
settings: args.settings?.[plugin.
|
|
85
|
+
settings: args.settings?.[plugin.id] ?? {},
|
|
86
86
|
nodeishFs: args.nodeishFs,
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
89
|
if (typeof plugin.detectedLanguageTags === "function") {
|
|
90
90
|
const detectedLangugeTags = await plugin.detectedLanguageTags({
|
|
91
|
-
settings: args.settings?.[plugin.
|
|
91
|
+
settings: args.settings?.[plugin.id] ?? {},
|
|
92
92
|
nodeishFs: args.nodeishFs,
|
|
93
93
|
});
|
|
94
94
|
result.data.detectedLanguageTags = [
|
|
@@ -97,7 +97,7 @@ export const resolvePlugins = async (args) => {
|
|
|
97
97
|
}
|
|
98
98
|
if (typeof plugin.addCustomApi === "function") {
|
|
99
99
|
const { data: customApi } = tryCatch(() => plugin.addCustomApi({
|
|
100
|
-
settings: args.settings?.[plugin.
|
|
100
|
+
settings: args.settings?.[plugin.id] ?? {},
|
|
101
101
|
}));
|
|
102
102
|
if (customApi) {
|
|
103
103
|
result.data.customApi = deepmerge(result.data.customApi, customApi);
|
|
@@ -5,17 +5,12 @@ import { PluginLoadMessagesFunctionAlreadyDefinedError, PluginSaveMessagesFuncti
|
|
|
5
5
|
describe("generally", () => {
|
|
6
6
|
it("should return an error if a plugin uses an invalid id", async () => {
|
|
7
7
|
const mockPlugin = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
displayName: { en: "My plugin" },
|
|
13
|
-
},
|
|
8
|
+
// @ts-expect-error - invalid id
|
|
9
|
+
id: "no-namespace",
|
|
10
|
+
description: { en: "My plugin description" },
|
|
11
|
+
displayName: { en: "My plugin" },
|
|
14
12
|
loadMessages: () => undefined,
|
|
15
13
|
saveMessages: () => undefined,
|
|
16
|
-
addCustomApi() {
|
|
17
|
-
return {};
|
|
18
|
-
},
|
|
19
14
|
};
|
|
20
15
|
const resolved = await resolvePlugins({
|
|
21
16
|
plugins: [mockPlugin],
|
|
@@ -26,11 +21,9 @@ describe("generally", () => {
|
|
|
26
21
|
});
|
|
27
22
|
it("should return an error if a plugin uses APIs that are not available", async () => {
|
|
28
23
|
const mockPlugin = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
displayName: { en: "My plugin" },
|
|
33
|
-
},
|
|
24
|
+
id: "plugin.namespace.undefinedApi",
|
|
25
|
+
description: { en: "My plugin description" },
|
|
26
|
+
displayName: { en: "My plugin" },
|
|
34
27
|
// @ts-expect-error the key is not available in type
|
|
35
28
|
nonExistentKey: {
|
|
36
29
|
nonexistentOptions: "value",
|
|
@@ -47,11 +40,9 @@ describe("generally", () => {
|
|
|
47
40
|
});
|
|
48
41
|
it("should not initialize a plugin that uses the 'inlang' namespace except for inlang whitelisted plugins", async () => {
|
|
49
42
|
const mockPlugin = {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
displayName: { en: "My plugin" },
|
|
54
|
-
},
|
|
43
|
+
id: "plugin.inlang.notWhitelisted",
|
|
44
|
+
description: { en: "My plugin description" },
|
|
45
|
+
displayName: { en: "My plugin" },
|
|
55
46
|
loadMessages: () => undefined,
|
|
56
47
|
};
|
|
57
48
|
const resolved = await resolvePlugins({
|
|
@@ -65,11 +56,9 @@ describe("generally", () => {
|
|
|
65
56
|
describe("loadMessages", () => {
|
|
66
57
|
it("should load messages from a local source", async () => {
|
|
67
58
|
const mockPlugin = {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
displayName: { en: "My plugin" },
|
|
72
|
-
},
|
|
59
|
+
id: "plugin.namespace.placeholder",
|
|
60
|
+
description: { en: "My plugin description" },
|
|
61
|
+
displayName: { en: "My plugin" },
|
|
73
62
|
loadMessages: async () => [{ id: "test", expressions: [], selectors: [], variants: [] }],
|
|
74
63
|
};
|
|
75
64
|
const resolved = await resolvePlugins({
|
|
@@ -84,19 +73,15 @@ describe("loadMessages", () => {
|
|
|
84
73
|
});
|
|
85
74
|
it("should collect an error if function is defined twice in multiple plugins", async () => {
|
|
86
75
|
const mockPlugin = {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
displayName: { en: "My plugin" },
|
|
91
|
-
},
|
|
76
|
+
id: "plugin.namepsace.loadMessagesFirst",
|
|
77
|
+
description: { en: "My plugin description" },
|
|
78
|
+
displayName: { en: "My plugin" },
|
|
92
79
|
loadMessages: async () => undefined,
|
|
93
80
|
};
|
|
94
81
|
const mockPlugin2 = {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
displayName: { en: "My plugin" },
|
|
99
|
-
},
|
|
82
|
+
id: "plugin.namepsace.loadMessagesSecond",
|
|
83
|
+
description: { en: "My plugin description" },
|
|
84
|
+
displayName: { en: "My plugin" },
|
|
100
85
|
loadMessages: async () => undefined,
|
|
101
86
|
};
|
|
102
87
|
const resolved = await resolvePlugins({
|
|
@@ -108,11 +93,9 @@ describe("loadMessages", () => {
|
|
|
108
93
|
});
|
|
109
94
|
it("should return an error if no plugin defines loadMessages", async () => {
|
|
110
95
|
const mockPlugin = {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
displayName: { en: "My plugin" },
|
|
115
|
-
},
|
|
96
|
+
id: "plugin.namepsace.loadMessagesFirst",
|
|
97
|
+
description: { en: "My plugin description" },
|
|
98
|
+
displayName: { en: "My plugin" },
|
|
116
99
|
saveMessages: async () => undefined,
|
|
117
100
|
};
|
|
118
101
|
const resolved = await resolvePlugins({
|
|
@@ -127,11 +110,9 @@ describe("loadMessages", () => {
|
|
|
127
110
|
describe("saveMessages", () => {
|
|
128
111
|
it("should save messages to a local source", async () => {
|
|
129
112
|
const mockPlugin = {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
displayName: { en: "My plugin" },
|
|
134
|
-
},
|
|
113
|
+
id: "plugin.namespace.placeholder",
|
|
114
|
+
description: { en: "My plugin description" },
|
|
115
|
+
displayName: { en: "My plugin" },
|
|
135
116
|
loadMessages: async () => undefined,
|
|
136
117
|
saveMessages: async () => undefined,
|
|
137
118
|
};
|
|
@@ -144,19 +125,15 @@ describe("saveMessages", () => {
|
|
|
144
125
|
});
|
|
145
126
|
it("should collect an error if function is defined twice in multiple plugins", async () => {
|
|
146
127
|
const mockPlugin = {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
displayName: { en: "My plugin" },
|
|
151
|
-
},
|
|
128
|
+
id: "plugin.namepsace.saveMessages",
|
|
129
|
+
description: { en: "My plugin description" },
|
|
130
|
+
displayName: { en: "My plugin" },
|
|
152
131
|
saveMessages: async () => undefined,
|
|
153
132
|
};
|
|
154
133
|
const mockPlugin2 = {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
displayName: { en: "My plugin" },
|
|
159
|
-
},
|
|
134
|
+
id: "plugin.namepsace.saveMessages2",
|
|
135
|
+
description: { en: "My plugin description" },
|
|
136
|
+
displayName: { en: "My plugin" },
|
|
160
137
|
saveMessages: async () => undefined,
|
|
161
138
|
};
|
|
162
139
|
const resolved = await resolvePlugins({
|
|
@@ -168,11 +145,9 @@ describe("saveMessages", () => {
|
|
|
168
145
|
});
|
|
169
146
|
it("should return an error if no plugin defines saveMessages", async () => {
|
|
170
147
|
const mockPlugin = {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
displayName: { en: "My plugin" },
|
|
175
|
-
},
|
|
148
|
+
id: "plugin.namepsace.loadMessagesFirst",
|
|
149
|
+
description: { en: "My plugin description" },
|
|
150
|
+
displayName: { en: "My plugin" },
|
|
176
151
|
loadMessages: async () => undefined,
|
|
177
152
|
};
|
|
178
153
|
const resolved = await resolvePlugins({
|
|
@@ -187,22 +162,18 @@ describe("saveMessages", () => {
|
|
|
187
162
|
describe("detectedLanguageTags", () => {
|
|
188
163
|
it("should merge language tags from plugins", async () => {
|
|
189
164
|
const mockPlugin = {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
displayName: { en: "My plugin" },
|
|
194
|
-
},
|
|
165
|
+
id: "plugin.namepsace.detectedLanguageTags",
|
|
166
|
+
description: { en: "My plugin description" },
|
|
167
|
+
displayName: { en: "My plugin" },
|
|
195
168
|
detectedLanguageTags: async () => ["de", "en"],
|
|
196
169
|
addCustomApi: () => {
|
|
197
170
|
return {};
|
|
198
171
|
},
|
|
199
172
|
};
|
|
200
173
|
const mockPlugin2 = {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
displayName: { en: "My plugin" },
|
|
205
|
-
},
|
|
174
|
+
id: "plugin.namepsace.detectedLanguageTags2",
|
|
175
|
+
description: { en: "My plugin description" },
|
|
176
|
+
displayName: { en: "My plugin" },
|
|
206
177
|
addCustomApi: () => {
|
|
207
178
|
return {};
|
|
208
179
|
},
|
|
@@ -219,11 +190,9 @@ describe("detectedLanguageTags", () => {
|
|
|
219
190
|
describe("addCustomApi", () => {
|
|
220
191
|
it("it should resolve app specific api", async () => {
|
|
221
192
|
const mockPlugin = {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
displayName: { en: "My plugin" },
|
|
226
|
-
},
|
|
193
|
+
id: "plugin.namespace.placeholder",
|
|
194
|
+
description: { en: "My plugin description" },
|
|
195
|
+
displayName: { en: "My plugin" },
|
|
227
196
|
addCustomApi: () => ({
|
|
228
197
|
"my-app": {
|
|
229
198
|
messageReferenceMatcher: () => undefined,
|
|
@@ -239,11 +208,9 @@ describe("addCustomApi", () => {
|
|
|
239
208
|
});
|
|
240
209
|
it("it should resolve multiple app specific apis", async () => {
|
|
241
210
|
const mockPlugin = {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
displayName: { en: "My plugin" },
|
|
246
|
-
},
|
|
211
|
+
id: "plugin.namespace.placeholder",
|
|
212
|
+
description: { en: "My plugin description" },
|
|
213
|
+
displayName: { en: "My plugin" },
|
|
247
214
|
addCustomApi: () => ({
|
|
248
215
|
"my-app-1": {
|
|
249
216
|
functionOfMyApp1: () => undefined,
|
|
@@ -254,11 +221,9 @@ describe("addCustomApi", () => {
|
|
|
254
221
|
}),
|
|
255
222
|
};
|
|
256
223
|
const mockPlugin2 = {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
displayName: { en: "My plugin" },
|
|
261
|
-
},
|
|
224
|
+
id: "plugin.namespace.placeholder2",
|
|
225
|
+
description: { en: "My plugin description" },
|
|
226
|
+
displayName: { en: "My plugin" },
|
|
262
227
|
addCustomApi: () => ({
|
|
263
228
|
"my-app-3": {
|
|
264
229
|
functionOfMyApp3: () => undefined,
|
|
@@ -276,11 +241,9 @@ describe("addCustomApi", () => {
|
|
|
276
241
|
});
|
|
277
242
|
it("it should throw an error if return value is not an object", async () => {
|
|
278
243
|
const mockPlugin = {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
displayName: { en: "My plugin" },
|
|
283
|
-
},
|
|
244
|
+
id: "plugin.namespace.placeholder",
|
|
245
|
+
description: { en: "My plugin description" },
|
|
246
|
+
displayName: { en: "My plugin" },
|
|
284
247
|
// @ts-expect-error - invalid return type
|
|
285
248
|
addCustomApi: () => undefined,
|
|
286
249
|
};
|
|
@@ -293,11 +256,9 @@ describe("addCustomApi", () => {
|
|
|
293
256
|
});
|
|
294
257
|
it("it should throw an error if the passed options are not defined inside customApi", async () => {
|
|
295
258
|
const mockPlugin = {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
displayName: { en: "My plugin" },
|
|
300
|
-
},
|
|
259
|
+
id: "plugin.namepsace.placeholder",
|
|
260
|
+
description: { en: "My plugin description" },
|
|
261
|
+
displayName: { en: "My plugin" },
|
|
301
262
|
addCustomApi: () => ({
|
|
302
263
|
"app.inlang.placeholder": {
|
|
303
264
|
messageReferenceMatcher: () => {
|
|
@@ -15,7 +15,7 @@ export type NodeishFilesystemSubset = Pick<LisaNodeishFilesystem, "readFile" | "
|
|
|
15
15
|
*/
|
|
16
16
|
export type ResolvePluginsFunction = (args: {
|
|
17
17
|
plugins: Array<Plugin>;
|
|
18
|
-
settings: Record<Plugin["
|
|
18
|
+
settings: Record<Plugin["id"], JSONObject>;
|
|
19
19
|
nodeishFs: NodeishFilesystemSubset;
|
|
20
20
|
}) => Promise<{
|
|
21
21
|
data: ResolvedPluginApi;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/resolve-modules/plugins/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,iBAAiB,IAAI,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAC5E,OAAO,KAAK,EACX,mCAAmC,EACnC,6CAA6C,EAC7C,6CAA6C,EAC7C,uBAAuB,EACvB,2BAA2B,EAC3B,gCAAgC,EAChC,0CAA0C,EAC1C,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEzE;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GAAG,IAAI,CACzC,qBAAqB,EACrB,UAAU,GAAG,SAAS,GAAG,OAAO,GAAG,WAAW,CAC9C,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,IAAI,EAAE;IAC3C,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/resolve-modules/plugins/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,iBAAiB,IAAI,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAC5E,OAAO,KAAK,EACX,mCAAmC,EACnC,6CAA6C,EAC7C,6CAA6C,EAC7C,uBAAuB,EACvB,2BAA2B,EAC3B,gCAAgC,EAChC,0CAA0C,EAC1C,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEzE;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GAAG,IAAI,CACzC,qBAAqB,EACrB,UAAU,GAAG,SAAS,GAAG,OAAO,GAAG,WAAW,CAC9C,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,IAAI,EAAE;IAC3C,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,CAAA;IAC1C,SAAS,EAAE,uBAAuB,CAAA;CAClC,KAAK,OAAO,CAAC;IACb,IAAI,EAAE,iBAAiB,CAAA;IACvB,MAAM,EAAE,KAAK,CACV,mCAAmC,GACnC,6CAA6C,GAC7C,6CAA6C,GAC7C,uBAAuB,GACvB,2BAA2B,GAC3B,gCAAgC,GAChC,0CAA0C,CAC5C,CAAA;CACD,CAAC,CAAA;AAEF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC/B,YAAY,EAAE,CAAC,IAAI,EAAE;QACpB,YAAY,EAAE,WAAW,EAAE,CAAA;QAC3B,iBAAiB,EAAE,WAAW,CAAA;KAC9B,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,CAAA;IACpC,YAAY,EAAE,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,OAAO,EAAE,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;IACrE;;OAEG;IACH,oBAAoB,EAAE,WAAW,EAAE,CAAA;IACnC;;;;;;;;;;;;;;;;OAgBG;IACH,SAAS,EAAE,MAAM,CAAC,OAAO,MAAM,IAAI,MAAM,EAAE,GAAG,WAAW,MAAM,IAAI,MAAM,EAAE,EAAE,OAAO,CAAC,GAAG;QACvF,yBAAyB,CAAC,EAAE,2BAA2B,CAAA;KACvD,CAAA;CACD,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProjectSettings } from "@inlang/project-settings";
|
|
2
2
|
import { Value } from "@sinclair/typebox/value";
|
|
3
3
|
import { describe, test, expect } from "vitest";
|
|
4
4
|
import { expectType } from "tsd";
|
|
@@ -7,11 +7,9 @@ describe("Plugin", () => {
|
|
|
7
7
|
test("meta.id should enforce plugin.namespace.* patterns", () => {
|
|
8
8
|
expectType("");
|
|
9
9
|
const mockPlugin = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
description: { en: "" },
|
|
14
|
-
},
|
|
10
|
+
id: "plugin.namespace.placeholder",
|
|
11
|
+
displayName: { en: "" },
|
|
12
|
+
description: { en: "" },
|
|
15
13
|
};
|
|
16
14
|
const passCases = ["plugin.namespace.helloWorld", "plugin.namespace.i18n"];
|
|
17
15
|
const failCases = [
|
|
@@ -20,30 +18,28 @@ describe("Plugin", () => {
|
|
|
20
18
|
"lintRule.namespace.coolPlugin",
|
|
21
19
|
];
|
|
22
20
|
for (const pass of passCases) {
|
|
23
|
-
mockPlugin.
|
|
21
|
+
mockPlugin.id = pass;
|
|
24
22
|
// @ts-ignore - type mismatch error. fix after refactor
|
|
25
23
|
expect(Value.Check(Plugin, mockPlugin)).toBe(true);
|
|
26
24
|
}
|
|
27
25
|
for (const fail of failCases) {
|
|
28
|
-
mockPlugin.
|
|
26
|
+
mockPlugin.id = fail;
|
|
29
27
|
// @ts-ignore - type mismatch error. fix after refactor
|
|
30
28
|
expect(Value.Check(Plugin, mockPlugin)).toBe(false);
|
|
31
29
|
}
|
|
32
30
|
});
|
|
33
31
|
test("meta.id should be a valid inlang.config.setting key", () => {
|
|
34
|
-
const
|
|
32
|
+
const settings = {
|
|
35
33
|
sourceLanguageTag: "en",
|
|
36
34
|
languageTags: ["en", "de"],
|
|
37
35
|
modules: [],
|
|
38
|
-
settings: {},
|
|
39
36
|
};
|
|
40
37
|
const cases = ["plugin.namespace.helloWorld", "plugin.namespace.i18n"];
|
|
41
38
|
for (const _case of cases) {
|
|
42
|
-
const
|
|
39
|
+
const mergedSettings = { ...settings, [_case]: {} };
|
|
40
|
+
expect(Value.Check(ProjectSettings, mergedSettings)).toBe(true);
|
|
43
41
|
// @ts-ignore - type mismatch error. fix after refactor
|
|
44
|
-
expect(Value.Check(
|
|
45
|
-
// @ts-ignore - type mismatch error. fix after refactor
|
|
46
|
-
expect(Value.Check(Plugin["properties"]["meta"]["properties"]["id"], _case)).toBe(true);
|
|
42
|
+
expect(Value.Check(Plugin["properties"]["id"], _case)).toBe(true);
|
|
47
43
|
}
|
|
48
44
|
});
|
|
49
45
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveModules.d.ts","sourceRoot":"","sources":["../../src/resolve-modules/resolveModules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAkBvD,eAAO,MAAM,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"resolveModules.d.ts","sourceRoot":"","sources":["../../src/resolve-modules/resolveModules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAkBvD,eAAO,MAAM,cAAc,EAAE,qBAgF5B,CAAA"}
|
|
@@ -12,7 +12,7 @@ export const resolveModules = async (args) => {
|
|
|
12
12
|
const allPlugins = [];
|
|
13
13
|
const allMessageLintRules = [];
|
|
14
14
|
const meta = [];
|
|
15
|
-
for (const module of args.
|
|
15
|
+
for (const module of args.settings.modules) {
|
|
16
16
|
/**
|
|
17
17
|
* -------------- BEGIN SETUP --------------
|
|
18
18
|
*/
|
|
@@ -25,8 +25,8 @@ export const resolveModules = async (args) => {
|
|
|
25
25
|
}));
|
|
26
26
|
continue;
|
|
27
27
|
}
|
|
28
|
-
// -- MODULE DOES NOT EXPORT
|
|
29
|
-
if (importedModule.data?.default
|
|
28
|
+
// -- MODULE DOES NOT EXPORT ANYTHING --
|
|
29
|
+
if (importedModule.data?.default === undefined) {
|
|
30
30
|
moduleErrors.push(new ModuleHasNoExportsError(`Module "${module}" has no exports.`, {
|
|
31
31
|
module: module,
|
|
32
32
|
}));
|
|
@@ -34,20 +34,20 @@ export const resolveModules = async (args) => {
|
|
|
34
34
|
}
|
|
35
35
|
const isValidModule = ModuleCompiler.Check(importedModule.data);
|
|
36
36
|
if (isValidModule === false) {
|
|
37
|
-
const errors = [...ModuleCompiler.Errors(importedModule.data)];
|
|
38
|
-
moduleErrors.push(new ModuleExportIsInvalidError(`Module "${module}" is invalid: ` + errors, {
|
|
37
|
+
const errors = [...ModuleCompiler.Errors(importedModule.data)].map((e) => `${e.path} ${e.message}`);
|
|
38
|
+
moduleErrors.push(new ModuleExportIsInvalidError(`Module "${module}" is invalid: ` + errors.join("\n"), {
|
|
39
39
|
module: module,
|
|
40
40
|
}));
|
|
41
41
|
continue;
|
|
42
42
|
}
|
|
43
43
|
meta.push({
|
|
44
44
|
module: module,
|
|
45
|
-
id: importedModule.data.default.
|
|
45
|
+
id: importedModule.data.default.id,
|
|
46
46
|
});
|
|
47
|
-
if (importedModule.data.default.
|
|
47
|
+
if (importedModule.data.default.id.startsWith("plugin.")) {
|
|
48
48
|
allPlugins.push(importedModule.data.default);
|
|
49
49
|
}
|
|
50
|
-
else if (importedModule.data.default.
|
|
50
|
+
else if (importedModule.data.default.id.startsWith("messageLintRule.")) {
|
|
51
51
|
allMessageLintRules.push(importedModule.data.default);
|
|
52
52
|
}
|
|
53
53
|
else {
|
|
@@ -56,7 +56,7 @@ export const resolveModules = async (args) => {
|
|
|
56
56
|
}
|
|
57
57
|
const resolvedPlugins = await resolvePlugins({
|
|
58
58
|
plugins: allPlugins,
|
|
59
|
-
settings: args.
|
|
59
|
+
settings: args.settings,
|
|
60
60
|
nodeishFs: args.nodeishFs,
|
|
61
61
|
});
|
|
62
62
|
const resolvedLintRules = resolveMessageLintRules({ messageLintRules: allMessageLintRules });
|