@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.
- 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/import.js +1 -1
- 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 +3 -3
- 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/import.ts +1 -1
- 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
|
@@ -41,23 +41,23 @@ export const resolvePlugins: ResolvePluginsFunction = async (args) => {
|
|
|
41
41
|
*/
|
|
42
42
|
|
|
43
43
|
// -- INVALID ID in META --
|
|
44
|
-
const hasInvalidId = errors.some((error) => error.path === "/
|
|
44
|
+
const hasInvalidId = errors.some((error) => error.path === "/id")
|
|
45
45
|
if (hasInvalidId) {
|
|
46
46
|
result.errors.push(
|
|
47
47
|
new PluginHasInvalidIdError(
|
|
48
|
-
`Plugin ${plugin.
|
|
49
|
-
{ plugin: plugin.
|
|
48
|
+
`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
50
|
),
|
|
51
51
|
)
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
// -- USES RESERVED NAMESPACE --
|
|
55
|
-
if (plugin.
|
|
55
|
+
if (plugin.id.includes("inlang") && !whitelistedPlugins.includes(plugin.id)) {
|
|
56
56
|
result.errors.push(
|
|
57
57
|
new PluginUsesReservedNamespaceError(
|
|
58
|
-
`Plugin ${plugin.
|
|
58
|
+
`Plugin ${plugin.id} uses reserved namespace 'inlang'.`,
|
|
59
59
|
{
|
|
60
|
-
plugin: plugin.
|
|
60
|
+
plugin: plugin.id,
|
|
61
61
|
},
|
|
62
62
|
),
|
|
63
63
|
)
|
|
@@ -67,9 +67,9 @@ export const resolvePlugins: ResolvePluginsFunction = async (args) => {
|
|
|
67
67
|
if (errors.length > 0) {
|
|
68
68
|
result.errors.push(
|
|
69
69
|
new PluginHasInvalidSchemaError(
|
|
70
|
-
`Plugin ${plugin.
|
|
70
|
+
`Plugin ${plugin.id} uses an invalid schema. Please check the documentation for the correct Plugin type.`,
|
|
71
71
|
{
|
|
72
|
-
plugin: plugin.
|
|
72
|
+
plugin: plugin.id,
|
|
73
73
|
cause: errors,
|
|
74
74
|
},
|
|
75
75
|
),
|
|
@@ -80,8 +80,8 @@ export const resolvePlugins: ResolvePluginsFunction = async (args) => {
|
|
|
80
80
|
if (typeof plugin.loadMessages === "function" && result.data.loadMessages !== undefined) {
|
|
81
81
|
result.errors.push(
|
|
82
82
|
new PluginLoadMessagesFunctionAlreadyDefinedError(
|
|
83
|
-
`Plugin ${plugin.
|
|
84
|
-
{ plugin: plugin.
|
|
83
|
+
`Plugin ${plugin.id} defines the loadMessages function, but it was already defined by another plugin.`,
|
|
84
|
+
{ plugin: plugin.id },
|
|
85
85
|
),
|
|
86
86
|
)
|
|
87
87
|
}
|
|
@@ -89,8 +89,8 @@ export const resolvePlugins: ResolvePluginsFunction = async (args) => {
|
|
|
89
89
|
if (typeof plugin.saveMessages === "function" && result.data.saveMessages !== undefined) {
|
|
90
90
|
result.errors.push(
|
|
91
91
|
new PluginSaveMessagesFunctionAlreadyDefinedError(
|
|
92
|
-
`Plugin ${plugin.
|
|
93
|
-
{ plugin: plugin.
|
|
92
|
+
`Plugin ${plugin.id} defines the saveMessages function, but it was already defined by another plugin.`,
|
|
93
|
+
{ plugin: plugin.id },
|
|
94
94
|
),
|
|
95
95
|
)
|
|
96
96
|
}
|
|
@@ -100,7 +100,7 @@ export const resolvePlugins: ResolvePluginsFunction = async (args) => {
|
|
|
100
100
|
// TODO: why do we call this function 2 times (here for validation and later for retrieving the actual value)?
|
|
101
101
|
const { data: customApi, error } = tryCatch(() =>
|
|
102
102
|
plugin.addCustomApi!({
|
|
103
|
-
settings: args.settings?.[plugin.
|
|
103
|
+
settings: args.settings?.[plugin.id] ?? {},
|
|
104
104
|
}),
|
|
105
105
|
)
|
|
106
106
|
if (error) {
|
|
@@ -111,8 +111,8 @@ export const resolvePlugins: ResolvePluginsFunction = async (args) => {
|
|
|
111
111
|
if (typeof customApi !== "object") {
|
|
112
112
|
result.errors.push(
|
|
113
113
|
new PluginReturnedInvalidCustomApiError(
|
|
114
|
-
`Plugin ${plugin.
|
|
115
|
-
{ plugin: plugin.
|
|
114
|
+
`Plugin ${plugin.id} defines the addCustomApi function, but it does not return an object.`,
|
|
115
|
+
{ plugin: plugin.id, cause: error },
|
|
116
116
|
),
|
|
117
117
|
)
|
|
118
118
|
}
|
|
@@ -131,7 +131,7 @@ export const resolvePlugins: ResolvePluginsFunction = async (args) => {
|
|
|
131
131
|
result.data.loadMessages = (_args) =>
|
|
132
132
|
plugin.loadMessages!({
|
|
133
133
|
..._args,
|
|
134
|
-
settings: args.settings?.[plugin.
|
|
134
|
+
settings: args.settings?.[plugin.id] ?? {},
|
|
135
135
|
nodeishFs: args.nodeishFs,
|
|
136
136
|
})
|
|
137
137
|
}
|
|
@@ -140,14 +140,14 @@ export const resolvePlugins: ResolvePluginsFunction = async (args) => {
|
|
|
140
140
|
result.data.saveMessages = (_args) =>
|
|
141
141
|
plugin.saveMessages!({
|
|
142
142
|
..._args,
|
|
143
|
-
settings: args.settings?.[plugin.
|
|
143
|
+
settings: args.settings?.[plugin.id] ?? {},
|
|
144
144
|
nodeishFs: args.nodeishFs,
|
|
145
145
|
})
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
if (typeof plugin.detectedLanguageTags === "function") {
|
|
149
149
|
const detectedLangugeTags = await plugin.detectedLanguageTags!({
|
|
150
|
-
settings: args.settings?.[plugin.
|
|
150
|
+
settings: args.settings?.[plugin.id] ?? {},
|
|
151
151
|
nodeishFs: args.nodeishFs,
|
|
152
152
|
})
|
|
153
153
|
result.data.detectedLanguageTags = [
|
|
@@ -158,7 +158,7 @@ export const resolvePlugins: ResolvePluginsFunction = async (args) => {
|
|
|
158
158
|
if (typeof plugin.addCustomApi === "function") {
|
|
159
159
|
const { data: customApi } = tryCatch(() =>
|
|
160
160
|
plugin.addCustomApi!({
|
|
161
|
-
settings: args.settings?.[plugin.
|
|
161
|
+
settings: args.settings?.[plugin.id] ?? {},
|
|
162
162
|
}),
|
|
163
163
|
)
|
|
164
164
|
if (customApi) {
|
|
@@ -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"
|
|
@@ -6,14 +6,12 @@ import { Plugin } from "@inlang/plugin"
|
|
|
6
6
|
|
|
7
7
|
describe("Plugin", () => {
|
|
8
8
|
test("meta.id should enforce plugin.namespace.* patterns", () => {
|
|
9
|
-
expectType<`plugin.${string}.${string}`>("" as Plugin["
|
|
9
|
+
expectType<`plugin.${string}.${string}`>("" as Plugin["id"])
|
|
10
10
|
|
|
11
11
|
const mockPlugin: Plugin = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
description: { en: "" },
|
|
16
|
-
},
|
|
12
|
+
id: "plugin.namespace.placeholder",
|
|
13
|
+
displayName: { en: "" },
|
|
14
|
+
description: { en: "" },
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
const passCases = ["plugin.namespace.helloWorld", "plugin.namespace.i18n"]
|
|
@@ -24,34 +22,32 @@ describe("Plugin", () => {
|
|
|
24
22
|
]
|
|
25
23
|
|
|
26
24
|
for (const pass of passCases) {
|
|
27
|
-
mockPlugin.
|
|
25
|
+
mockPlugin.id = pass as any
|
|
28
26
|
|
|
29
27
|
// @ts-ignore - type mismatch error. fix after refactor
|
|
30
28
|
expect(Value.Check(Plugin, mockPlugin)).toBe(true)
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
for (const fail of failCases) {
|
|
34
|
-
mockPlugin.
|
|
32
|
+
mockPlugin.id = fail as any
|
|
35
33
|
// @ts-ignore - type mismatch error. fix after refactor
|
|
36
34
|
expect(Value.Check(Plugin, mockPlugin)).toBe(false)
|
|
37
35
|
}
|
|
38
36
|
})
|
|
39
37
|
|
|
40
38
|
test("meta.id should be a valid inlang.config.setting key", () => {
|
|
41
|
-
const
|
|
39
|
+
const settings: ProjectSettings = {
|
|
42
40
|
sourceLanguageTag: "en",
|
|
43
41
|
languageTags: ["en", "de"],
|
|
44
42
|
modules: [],
|
|
45
|
-
settings: {},
|
|
46
43
|
}
|
|
47
44
|
const cases = ["plugin.namespace.helloWorld", "plugin.namespace.i18n"]
|
|
48
45
|
|
|
49
46
|
for (const _case of cases) {
|
|
50
|
-
const
|
|
47
|
+
const mergedSettings = { ...settings, [_case]: {} }
|
|
48
|
+
expect(Value.Check(ProjectSettings, mergedSettings)).toBe(true)
|
|
51
49
|
// @ts-ignore - type mismatch error. fix after refactor
|
|
52
|
-
expect(Value.Check(
|
|
53
|
-
// @ts-ignore - type mismatch error. fix after refactor
|
|
54
|
-
expect(Value.Check(Plugin["properties"]["meta"]["properties"]["id"], _case)).toBe(true)
|
|
50
|
+
expect(Value.Check(Plugin["properties"]["id"], _case)).toBe(true)
|
|
55
51
|
}
|
|
56
52
|
})
|
|
57
53
|
})
|
|
@@ -28,7 +28,7 @@ export type NodeishFilesystemSubset = Pick<
|
|
|
28
28
|
*/
|
|
29
29
|
export type ResolvePluginsFunction = (args: {
|
|
30
30
|
plugins: Array<Plugin>
|
|
31
|
-
settings: Record<Plugin["
|
|
31
|
+
settings: Record<Plugin["id"], JSONObject>
|
|
32
32
|
nodeishFs: NodeishFilesystemSubset
|
|
33
33
|
}) => Promise<{
|
|
34
34
|
data: ResolvedPluginApi
|
|
@@ -9,23 +9,22 @@ import {
|
|
|
9
9
|
ModuleImportError,
|
|
10
10
|
} from "./errors.js"
|
|
11
11
|
import { resolveModules } from "./resolveModules.js"
|
|
12
|
-
import type {
|
|
12
|
+
import type { ProjectSettings } from "@inlang/project-settings"
|
|
13
13
|
import type { InlangModule } from "@inlang/module"
|
|
14
14
|
|
|
15
15
|
it("should return an error if a plugin cannot be imported", async () => {
|
|
16
|
-
const
|
|
16
|
+
const settings: ProjectSettings = {
|
|
17
17
|
sourceLanguageTag: "en",
|
|
18
18
|
languageTags: ["de", "en"],
|
|
19
19
|
modules: ["https://myplugin.com/index.js"],
|
|
20
|
-
settings: {},
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
const resolved = await resolveModules({
|
|
24
|
-
|
|
23
|
+
settings,
|
|
25
24
|
nodeishFs: {} as any,
|
|
26
25
|
_import: () => {
|
|
27
26
|
throw new ModuleImportError("Could not import", {
|
|
28
|
-
module:
|
|
27
|
+
module: settings.modules[0]!,
|
|
29
28
|
cause: new Error("Could not import"),
|
|
30
29
|
})
|
|
31
30
|
},
|
|
@@ -37,11 +36,9 @@ it("should return an error if a plugin cannot be imported", async () => {
|
|
|
37
36
|
it("should resolve plugins and message lint rules successfully", async () => {
|
|
38
37
|
// Define mock data
|
|
39
38
|
const mockPlugin: Plugin = {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
displayName: { en: "Mock Plugin" },
|
|
44
|
-
},
|
|
39
|
+
id: "plugin.namespace.mock",
|
|
40
|
+
description: { en: "Mock plugin description" },
|
|
41
|
+
displayName: { en: "Mock Plugin" },
|
|
45
42
|
loadMessages: () => undefined as any,
|
|
46
43
|
saveMessages: () => undefined as any,
|
|
47
44
|
addCustomApi: () => ({
|
|
@@ -52,19 +49,16 @@ it("should resolve plugins and message lint rules successfully", async () => {
|
|
|
52
49
|
}
|
|
53
50
|
|
|
54
51
|
const mockMessageLintRule: MessageLintRule = {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
},
|
|
60
|
-
message: () => undefined,
|
|
52
|
+
id: "messageLintRule.namespace.mock",
|
|
53
|
+
description: { en: "Mock lint rule description" },
|
|
54
|
+
displayName: { en: "Mock Lint Rule" },
|
|
55
|
+
run: () => undefined,
|
|
61
56
|
}
|
|
62
57
|
|
|
63
|
-
const
|
|
58
|
+
const settings: ProjectSettings = {
|
|
64
59
|
sourceLanguageTag: "en",
|
|
65
60
|
languageTags: ["de", "en"],
|
|
66
61
|
modules: ["lint-rule.js", "plugin.js"],
|
|
67
|
-
settings: {},
|
|
68
62
|
}
|
|
69
63
|
|
|
70
64
|
const _import = async (name: string) => {
|
|
@@ -80,88 +74,80 @@ it("should resolve plugins and message lint rules successfully", async () => {
|
|
|
80
74
|
}
|
|
81
75
|
|
|
82
76
|
// Call the function
|
|
83
|
-
const resolved = await resolveModules({
|
|
77
|
+
const resolved = await resolveModules({ settings, _import, nodeishFs: {} as any })
|
|
84
78
|
|
|
85
79
|
// Assert results
|
|
86
80
|
expect(resolved.errors).toHaveLength(0)
|
|
87
81
|
// Check for the meta data of the plugin
|
|
88
|
-
expect(resolved.plugins.some((module) => module.
|
|
82
|
+
expect(resolved.plugins.some((module) => module.id === mockPlugin.id)).toBeDefined()
|
|
89
83
|
// Check for the app specific api
|
|
90
84
|
expect(resolved.resolvedPluginApi["customApi"]?.["app.inlang.ideExtension"]).toBeDefined()
|
|
91
85
|
// Check for the lint rule
|
|
92
|
-
expect(resolved.messageLintRules[0]?.
|
|
86
|
+
expect(resolved.messageLintRules[0]?.id).toBe(mockMessageLintRule.id)
|
|
93
87
|
})
|
|
94
88
|
|
|
95
89
|
it("should return an error if a module cannot be imported", async () => {
|
|
96
|
-
const
|
|
90
|
+
const settings: ProjectSettings = {
|
|
97
91
|
sourceLanguageTag: "en",
|
|
98
92
|
languageTags: ["de", "en"],
|
|
99
93
|
modules: ["https://myplugin.com/index.js"],
|
|
100
|
-
settings: {},
|
|
101
94
|
}
|
|
102
95
|
|
|
103
96
|
const _import = async () => {
|
|
104
97
|
throw new ModuleImportError("Could not import", {
|
|
105
|
-
module:
|
|
98
|
+
module: settings.modules[0]!,
|
|
106
99
|
cause: new Error(),
|
|
107
100
|
})
|
|
108
101
|
}
|
|
109
102
|
|
|
110
103
|
// Call the function
|
|
111
|
-
const resolved = await resolveModules({
|
|
104
|
+
const resolved = await resolveModules({ settings, _import, nodeishFs: {} as any })
|
|
112
105
|
|
|
113
106
|
// Assert results
|
|
114
107
|
expect(resolved.errors[0]).toBeInstanceOf(ModuleImportError)
|
|
115
108
|
})
|
|
116
109
|
|
|
117
|
-
it("should return an error if a module does not export
|
|
118
|
-
const
|
|
110
|
+
it("should return an error if a module does not export anything", async () => {
|
|
111
|
+
const settings: ProjectSettings = {
|
|
119
112
|
sourceLanguageTag: "en",
|
|
120
113
|
languageTags: ["de", "en"],
|
|
121
114
|
modules: ["https://myplugin.com/index.js"],
|
|
122
|
-
settings: {},
|
|
123
115
|
}
|
|
124
116
|
|
|
125
|
-
const _import = async () => ({
|
|
126
|
-
default: {},
|
|
127
|
-
})
|
|
117
|
+
const _import = async () => ({})
|
|
128
118
|
|
|
129
119
|
// Call the function
|
|
130
|
-
const resolved = await resolveModules({
|
|
120
|
+
const resolved = await resolveModules({ settings, _import, nodeishFs: {} as any })
|
|
131
121
|
|
|
132
122
|
// Assert results
|
|
133
123
|
expect(resolved.errors[0]).toBeInstanceOf(ModuleHasNoExportsError)
|
|
134
124
|
})
|
|
135
125
|
|
|
136
126
|
it("should return an error if a module exports an invalid plugin or lint rule", async () => {
|
|
137
|
-
const
|
|
127
|
+
const settings: ProjectSettings = {
|
|
138
128
|
sourceLanguageTag: "en",
|
|
139
129
|
languageTags: ["de", "en"],
|
|
140
130
|
modules: ["https://myplugin.com/index.js"],
|
|
141
|
-
settings: {},
|
|
142
131
|
}
|
|
143
132
|
const _import = async () =>
|
|
144
133
|
({
|
|
134
|
+
// @ts-expect-error - invalid meta of a plugin
|
|
145
135
|
default: {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
id: "plugin.namespace.mock",
|
|
149
|
-
description: { en: "Mock plugin description" },
|
|
150
|
-
},
|
|
136
|
+
id: "plugin.namespace.mock",
|
|
137
|
+
description: { en: "Mock plugin description" },
|
|
151
138
|
},
|
|
152
139
|
} satisfies InlangModule)
|
|
153
140
|
|
|
154
|
-
const resolved = await resolveModules({
|
|
141
|
+
const resolved = await resolveModules({ settings, _import, nodeishFs: {} as any })
|
|
155
142
|
expect(resolved.errors[0]).toBeInstanceOf(ModuleExportIsInvalidError)
|
|
156
143
|
})
|
|
157
144
|
|
|
158
145
|
it("should handle other unhandled errors during plugin resolution", async () => {
|
|
159
146
|
const errorMessage = "Unhandled error during plugin resolution"
|
|
160
|
-
const
|
|
147
|
+
const settings: ProjectSettings = {
|
|
161
148
|
sourceLanguageTag: "en",
|
|
162
149
|
languageTags: ["de", "en"],
|
|
163
150
|
modules: ["https://myplugin.com/index.js"],
|
|
164
|
-
settings: {},
|
|
165
151
|
}
|
|
166
152
|
|
|
167
153
|
const _import = async () => {
|
|
@@ -169,7 +155,7 @@ it("should handle other unhandled errors during plugin resolution", async () =>
|
|
|
169
155
|
}
|
|
170
156
|
|
|
171
157
|
// Call the function
|
|
172
|
-
const resolved = await resolveModules({
|
|
158
|
+
const resolved = await resolveModules({ settings, _import, nodeishFs: {} as any })
|
|
173
159
|
|
|
174
160
|
// Assert results
|
|
175
161
|
expect(resolved.errors[0]).toBeInstanceOf(ModuleError)
|
|
@@ -25,7 +25,7 @@ export const resolveModules: ResolveModuleFunction = async (args) => {
|
|
|
25
25
|
|
|
26
26
|
const meta: Awaited<ReturnType<ResolveModuleFunction>>["meta"] = []
|
|
27
27
|
|
|
28
|
-
for (const module of args.
|
|
28
|
+
for (const module of args.settings.modules) {
|
|
29
29
|
/**
|
|
30
30
|
* -------------- BEGIN SETUP --------------
|
|
31
31
|
*/
|
|
@@ -43,8 +43,8 @@ export const resolveModules: ResolveModuleFunction = async (args) => {
|
|
|
43
43
|
continue
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
// -- MODULE DOES NOT EXPORT
|
|
47
|
-
if (importedModule.data?.default
|
|
46
|
+
// -- MODULE DOES NOT EXPORT ANYTHING --
|
|
47
|
+
if (importedModule.data?.default === undefined) {
|
|
48
48
|
moduleErrors.push(
|
|
49
49
|
new ModuleHasNoExportsError(`Module "${module}" has no exports.`, {
|
|
50
50
|
module: module,
|
|
@@ -56,9 +56,11 @@ export const resolveModules: ResolveModuleFunction = async (args) => {
|
|
|
56
56
|
const isValidModule = ModuleCompiler.Check(importedModule.data)
|
|
57
57
|
|
|
58
58
|
if (isValidModule === false) {
|
|
59
|
-
const errors = [...ModuleCompiler.Errors(importedModule.data)]
|
|
59
|
+
const errors = [...ModuleCompiler.Errors(importedModule.data)].map(
|
|
60
|
+
(e) => `${e.path} ${e.message}`,
|
|
61
|
+
)
|
|
60
62
|
moduleErrors.push(
|
|
61
|
-
new ModuleExportIsInvalidError(`Module "${module}" is invalid: ` + errors, {
|
|
63
|
+
new ModuleExportIsInvalidError(`Module "${module}" is invalid: ` + errors.join("\n"), {
|
|
62
64
|
module: module,
|
|
63
65
|
}),
|
|
64
66
|
)
|
|
@@ -67,12 +69,12 @@ export const resolveModules: ResolveModuleFunction = async (args) => {
|
|
|
67
69
|
|
|
68
70
|
meta.push({
|
|
69
71
|
module: module,
|
|
70
|
-
id: importedModule.data.default.
|
|
72
|
+
id: importedModule.data.default.id,
|
|
71
73
|
})
|
|
72
74
|
|
|
73
|
-
if (importedModule.data.default.
|
|
75
|
+
if (importedModule.data.default.id.startsWith("plugin.")) {
|
|
74
76
|
allPlugins.push(importedModule.data.default as Plugin)
|
|
75
|
-
} else if (importedModule.data.default.
|
|
77
|
+
} else if (importedModule.data.default.id.startsWith("messageLintRule.")) {
|
|
76
78
|
allMessageLintRules.push(importedModule.data.default as MessageLintRule)
|
|
77
79
|
} else {
|
|
78
80
|
throw new Error(`Unimplemented module type. Must start with "plugin." or "messageLintRule.`)
|
|
@@ -81,7 +83,7 @@ export const resolveModules: ResolveModuleFunction = async (args) => {
|
|
|
81
83
|
|
|
82
84
|
const resolvedPlugins = await resolvePlugins({
|
|
83
85
|
plugins: allPlugins,
|
|
84
|
-
settings: args.
|
|
86
|
+
settings: args.settings,
|
|
85
87
|
nodeishFs: args.nodeishFs,
|
|
86
88
|
})
|
|
87
89
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ProjectSettings } from "@inlang/project-settings"
|
|
2
2
|
import type { MessageLintRule } from "@inlang/message-lint-rule"
|
|
3
3
|
import type { Plugin } from "@inlang/plugin"
|
|
4
4
|
import type {
|
|
@@ -16,7 +16,7 @@ import type { resolveMessageLintRules } from "./message-lint-rules/resolveMessag
|
|
|
16
16
|
* Pass a custom `_import` function to override the default import function.
|
|
17
17
|
*/
|
|
18
18
|
export type ResolveModuleFunction = (args: {
|
|
19
|
-
|
|
19
|
+
settings: ProjectSettings
|
|
20
20
|
nodeishFs: NodeishFilesystemSubset
|
|
21
21
|
_import?: ImportFunction
|
|
22
22
|
}) => Promise<{
|
|
@@ -39,7 +39,7 @@ export type ResolveModuleFunction = (args: {
|
|
|
39
39
|
/**
|
|
40
40
|
* The resolved item id of the module.
|
|
41
41
|
*/
|
|
42
|
-
id: Plugin["
|
|
42
|
+
id: Plugin["id"] | MessageLintRule["id"]
|
|
43
43
|
}>
|
|
44
44
|
/**
|
|
45
45
|
* The resolved plugins.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openInlangProject.d.ts","sourceRoot":"","sources":["../src/openInlangProject.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,aAAa,EAGb,YAAY,EACZ,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,KAAK,cAAc,EAAkB,MAAM,4BAA4B,CAAA;AAchF,OAAO,EAA0B,KAAK,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AAK/F;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB;qBACZ,MAAM;eACZ,uBAAuB;;qBAElB,MAAM,SAAS,OAAO,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI;MAC5D,QAAQ,aAAa,CAiLxB,CAAA;AAyGD,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAQtE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openInlangProject.test.d.ts","sourceRoot":"","sources":["../src/openInlangProject.test.ts"],"names":[],"mappings":""}
|