@inlang/sdk 0.9.0 → 0.10.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/errors.d.ts +18 -5
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +12 -10
- package/dist/loadProject.d.ts.map +1 -1
- package/dist/loadProject.js +9 -7
- package/dist/resolve-modules/errors.d.ts +6 -5
- package/dist/resolve-modules/errors.d.ts.map +1 -1
- package/dist/resolve-modules/errors.js +10 -8
- package/dist/resolve-modules/import.d.ts.map +1 -1
- package/dist/resolve-modules/import.js +2 -3
- package/dist/resolve-modules/message-lint-rules/errors.d.ts +5 -4
- package/dist/resolve-modules/message-lint-rules/errors.d.ts.map +1 -1
- package/dist/resolve-modules/message-lint-rules/errors.js +2 -4
- package/dist/resolve-modules/message-lint-rules/resolveMessageLintRules.d.ts.map +1 -1
- package/dist/resolve-modules/message-lint-rules/resolveMessageLintRules.js +4 -2
- package/dist/resolve-modules/plugins/errors.d.ts +35 -28
- package/dist/resolve-modules/plugins/errors.d.ts.map +1 -1
- package/dist/resolve-modules/plugins/errors.js +23 -30
- package/dist/resolve-modules/plugins/resolvePlugins.d.ts.map +1 -1
- package/dist/resolve-modules/plugins/resolvePlugins.js +15 -14
- package/dist/resolve-modules/resolveModules.d.ts.map +1 -1
- package/dist/resolve-modules/resolveModules.js +5 -4
- package/dist/resolve-modules/resolveModules.test.js +2 -2
- package/dist/test-utilities/createMessage.d.ts +1 -1
- package/package.json +1 -1
- package/src/errors.ts +19 -10
- package/src/loadProject.ts +13 -14
- package/src/resolve-modules/errors.ts +14 -8
- package/src/resolve-modules/import.ts +2 -3
- package/src/resolve-modules/message-lint-rules/errors.ts +5 -5
- package/src/resolve-modules/message-lint-rules/resolveMessageLintRules.ts +4 -2
- package/src/resolve-modules/plugins/errors.ts +34 -36
- package/src/resolve-modules/plugins/resolvePlugins.ts +17 -46
- package/src/resolve-modules/resolveModules.test.ts +2 -2
- package/src/resolve-modules/resolveModules.ts +5 -6
package/dist/errors.d.ts
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
1
|
+
import type { ValueError } from "@sinclair/typebox/errors";
|
|
1
2
|
export declare class ProjectSettingsInvalidError extends Error {
|
|
2
|
-
constructor(
|
|
3
|
+
constructor(options: {
|
|
4
|
+
errors: ValueError[];
|
|
5
|
+
});
|
|
3
6
|
}
|
|
4
7
|
export declare class ProjectSettingsFileJSONSyntaxError extends Error {
|
|
5
|
-
constructor(
|
|
8
|
+
constructor(options: {
|
|
9
|
+
cause: ErrorOptions["cause"];
|
|
10
|
+
path: string;
|
|
11
|
+
});
|
|
6
12
|
}
|
|
7
13
|
export declare class ProjectSettingsFileNotFoundError extends Error {
|
|
8
|
-
constructor(
|
|
14
|
+
constructor(options: {
|
|
15
|
+
cause?: ErrorOptions["cause"];
|
|
16
|
+
path: string;
|
|
17
|
+
});
|
|
9
18
|
}
|
|
10
19
|
export declare class PluginSaveMessagesError extends Error {
|
|
11
|
-
constructor(
|
|
20
|
+
constructor(options: {
|
|
21
|
+
cause: ErrorOptions["cause"];
|
|
22
|
+
});
|
|
12
23
|
}
|
|
13
24
|
export declare class PluginLoadMessagesError extends Error {
|
|
14
|
-
constructor(
|
|
25
|
+
constructor(options: {
|
|
26
|
+
cause: ErrorOptions["cause"];
|
|
27
|
+
});
|
|
15
28
|
}
|
|
16
29
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,2BAA4B,SAAQ,KAAK;gBACzC,OAAO,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D,qBAAa,2BAA4B,SAAQ,KAAK;gBACzC,OAAO,EAAE;QAAE,MAAM,EAAE,UAAU,EAAE,CAAA;KAAE;CAQ7C;AAED,qBAAa,kCAAmC,SAAQ,KAAK;gBAChD,OAAO,EAAE;QAAE,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;CAOnE;AAED,qBAAa,gCAAiC,SAAQ,KAAK;gBAC9C,OAAO,EAAE;QAAE,KAAK,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;CAIpE;AAED,qBAAa,uBAAwB,SAAQ,KAAK;gBACrC,OAAO,EAAE;QAAE,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,CAAA;KAAE;CAIrD;AAED,qBAAa,uBAAwB,SAAQ,KAAK;gBACrC,OAAO,EAAE;QAAE,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,CAAA;KAAE;CAIrD"}
|
package/dist/errors.js
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
export class ProjectSettingsInvalidError extends Error {
|
|
2
|
-
constructor(
|
|
3
|
-
super(
|
|
2
|
+
constructor(options) {
|
|
3
|
+
super(`The project settings are invalid:\n\n${options.errors
|
|
4
|
+
.map((error) => `The value of "${error.path}" is invalid:\n\n${error.message}`)
|
|
5
|
+
.join("\n")}`);
|
|
4
6
|
this.name = "ProjectSettingsInvalidError";
|
|
5
7
|
}
|
|
6
8
|
}
|
|
7
9
|
export class ProjectSettingsFileJSONSyntaxError extends Error {
|
|
8
|
-
constructor(
|
|
9
|
-
super(
|
|
10
|
+
constructor(options) {
|
|
11
|
+
super(`The settings file at "${options.path}" is not a valid JSON file:\n\n${options.cause}`, options);
|
|
10
12
|
this.name = "ProjectSettingsFileJSONSyntaxError";
|
|
11
13
|
}
|
|
12
14
|
}
|
|
13
15
|
export class ProjectSettingsFileNotFoundError extends Error {
|
|
14
|
-
constructor(
|
|
15
|
-
super(
|
|
16
|
+
constructor(options) {
|
|
17
|
+
super(`The file at "${options.path}" could not be read. Does the file exists?`, options);
|
|
16
18
|
this.name = "ProjectSettingsFileNotFoundError";
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
export class PluginSaveMessagesError extends Error {
|
|
20
|
-
constructor(
|
|
21
|
-
super(
|
|
22
|
+
constructor(options) {
|
|
23
|
+
super(`An error occured in saveMessages() caused by ${options.cause}.`, options);
|
|
22
24
|
this.name = "PluginSaveMessagesError";
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
export class PluginLoadMessagesError extends Error {
|
|
26
|
-
constructor(
|
|
27
|
-
super(
|
|
28
|
+
constructor(options) {
|
|
29
|
+
super(`An error occured in loadMessages() caused by ${options.cause}.`, options);
|
|
28
30
|
this.name = "PluginLoadMessagesError";
|
|
29
31
|
}
|
|
30
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadProject.d.ts","sourceRoot":"","sources":["../src/loadProject.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,aAAa,EAGb,YAAY,EACZ,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,KAAK,cAAc,EAAkB,MAAM,4BAA4B,CAAA;AAahF,OAAO,EAA4B,KAAK,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AAMjG;;;;;;GAMG;AACH,eAAO,MAAM,WAAW;sBACL,MAAM;eACb,uBAAuB;;qBAElB,MAAM,SAAS,OAAO,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI;MAC5D,QAAQ,aAAa,CAqLxB,CAAA;
|
|
1
|
+
{"version":3,"file":"loadProject.d.ts","sourceRoot":"","sources":["../src/loadProject.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,aAAa,EAGb,YAAY,EACZ,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,KAAK,cAAc,EAAkB,MAAM,4BAA4B,CAAA;AAahF,OAAO,EAA4B,KAAK,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AAMjG;;;;;;GAMG;AACH,eAAO,MAAM,WAAW;sBACL,MAAM;eACb,uBAAuB;;qBAElB,MAAM,SAAS,OAAO,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI;MAC5D,QAAQ,aAAa,CAqLxB,CAAA;AAqGD,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAQtE"}
|
package/dist/loadProject.js
CHANGED
|
@@ -46,7 +46,7 @@ export const loadProject = async (args) => {
|
|
|
46
46
|
if (error instanceof ProjectSettingsInvalidError) {
|
|
47
47
|
return { error };
|
|
48
48
|
}
|
|
49
|
-
throw new Error("
|
|
49
|
+
throw new Error("Unhandled error in setSettings. This is an internal bug. Please file an issue.");
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
52
|
// -- resolvedModules -----------------------------------------------------------
|
|
@@ -83,7 +83,7 @@ export const loadProject = async (args) => {
|
|
|
83
83
|
setMessages(messages);
|
|
84
84
|
markInitAsComplete();
|
|
85
85
|
})
|
|
86
|
-
.catch((err) => markInitAsFailed(new PluginLoadMessagesError(
|
|
86
|
+
.catch((err) => markInitAsFailed(new PluginLoadMessagesError({ cause: err })));
|
|
87
87
|
});
|
|
88
88
|
// -- installed items ----------------------------------------------------
|
|
89
89
|
const installedMessageLintRules = () => {
|
|
@@ -122,7 +122,7 @@ export const loadProject = async (args) => {
|
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
124
|
catch (err) {
|
|
125
|
-
throw new PluginSaveMessagesError(
|
|
125
|
+
throw new PluginSaveMessagesError({
|
|
126
126
|
cause: err,
|
|
127
127
|
});
|
|
128
128
|
}
|
|
@@ -160,13 +160,15 @@ export const loadProject = async (args) => {
|
|
|
160
160
|
const loadSettings = async (args) => {
|
|
161
161
|
const { data: settingsFile, error: settingsFileError } = await tryCatch(async () => await args.nodeishFs.readFile(args.settingsFilePath, { encoding: "utf-8" }));
|
|
162
162
|
if (settingsFileError)
|
|
163
|
-
throw new ProjectSettingsFileNotFoundError(
|
|
163
|
+
throw new ProjectSettingsFileNotFoundError({
|
|
164
164
|
cause: settingsFileError,
|
|
165
|
+
path: args.settingsFilePath,
|
|
165
166
|
});
|
|
166
167
|
const json = tryCatch(() => JSON.parse(settingsFile));
|
|
167
168
|
if (json.error) {
|
|
168
|
-
throw new ProjectSettingsFileJSONSyntaxError(
|
|
169
|
+
throw new ProjectSettingsFileJSONSyntaxError({
|
|
169
170
|
cause: json.error,
|
|
171
|
+
path: args.settingsFilePath,
|
|
170
172
|
});
|
|
171
173
|
}
|
|
172
174
|
return parseSettings(json.data);
|
|
@@ -176,8 +178,8 @@ const parseSettings = (settings) => {
|
|
|
176
178
|
if (settingsCompiler.Check(withMigration) === false) {
|
|
177
179
|
const typeErrors = [...settingsCompiler.Errors(settings)];
|
|
178
180
|
if (typeErrors.length > 0) {
|
|
179
|
-
throw new ProjectSettingsInvalidError(
|
|
180
|
-
|
|
181
|
+
throw new ProjectSettingsInvalidError({
|
|
182
|
+
errors: typeErrors,
|
|
181
183
|
});
|
|
182
184
|
}
|
|
183
185
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { ValueError } from "@sinclair/typebox/errors";
|
|
1
2
|
export * from "./plugins/errors.js";
|
|
2
3
|
export * from "./message-lint-rules/errors.js";
|
|
3
4
|
export declare class ModuleError extends Error {
|
|
4
|
-
readonly
|
|
5
|
+
readonly module: string;
|
|
5
6
|
constructor(message: string, options: {
|
|
6
7
|
module: string;
|
|
7
8
|
cause?: Error;
|
|
@@ -11,7 +12,7 @@ export declare class ModuleError extends Error {
|
|
|
11
12
|
* Error when a Module does not export any plugins or lint rules.
|
|
12
13
|
*/
|
|
13
14
|
export declare class ModuleHasNoExportsError extends ModuleError {
|
|
14
|
-
constructor(
|
|
15
|
+
constructor(options: {
|
|
15
16
|
module: string;
|
|
16
17
|
cause?: Error;
|
|
17
18
|
});
|
|
@@ -20,15 +21,15 @@ export declare class ModuleHasNoExportsError extends ModuleError {
|
|
|
20
21
|
* Error when a Module cannot be imported.
|
|
21
22
|
*/
|
|
22
23
|
export declare class ModuleImportError extends ModuleError {
|
|
23
|
-
constructor(
|
|
24
|
+
constructor(options: {
|
|
24
25
|
module: string;
|
|
25
26
|
cause: Error;
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
29
|
export declare class ModuleExportIsInvalidError extends ModuleError {
|
|
29
|
-
constructor(
|
|
30
|
+
constructor(options: {
|
|
30
31
|
module: string;
|
|
31
|
-
|
|
32
|
+
errors: ValueError[];
|
|
32
33
|
});
|
|
33
34
|
}
|
|
34
35
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/resolve-modules/errors.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,gCAAgC,CAAA;AAE9C,qBAAa,WAAY,SAAQ,KAAK;IACrC,SAAgB,MAAM,EAAE,MAAM,CAAA;gBAClB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAMvE;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,WAAW;gBAC3C,OAAO,EAAE
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/resolve-modules/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAC1D,cAAc,qBAAqB,CAAA;AACnC,cAAc,gCAAgC,CAAA;AAE9C,qBAAa,WAAY,SAAQ,KAAK;IACrC,SAAgB,MAAM,EAAE,MAAM,CAAA;gBAClB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAMvE;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,WAAW;gBAC3C,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAItD;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,WAAW;gBACrC,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE;CAIrD;AAED,qBAAa,0BAA2B,SAAQ,WAAW;gBAC9C,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,UAAU,EAAE,CAAA;KAAE;CAS7D"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export * from "./plugins/errors.js";
|
|
2
2
|
export * from "./message-lint-rules/errors.js";
|
|
3
3
|
export class ModuleError extends Error {
|
|
4
|
-
|
|
4
|
+
module;
|
|
5
5
|
constructor(message, options) {
|
|
6
6
|
super(message);
|
|
7
7
|
this.name = "ModuleError";
|
|
8
|
-
this.
|
|
8
|
+
this.module = options.module;
|
|
9
9
|
this.cause = options.cause;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
@@ -13,8 +13,8 @@ export class ModuleError extends Error {
|
|
|
13
13
|
* Error when a Module does not export any plugins or lint rules.
|
|
14
14
|
*/
|
|
15
15
|
export class ModuleHasNoExportsError extends ModuleError {
|
|
16
|
-
constructor(
|
|
17
|
-
super(
|
|
16
|
+
constructor(options) {
|
|
17
|
+
super(`Module "${module}" has no exports. Every module must have an "export default".`, options);
|
|
18
18
|
this.name = "ModuleHasNoExportsError";
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -22,14 +22,16 @@ export class ModuleHasNoExportsError extends ModuleError {
|
|
|
22
22
|
* Error when a Module cannot be imported.
|
|
23
23
|
*/
|
|
24
24
|
export class ModuleImportError extends ModuleError {
|
|
25
|
-
constructor(
|
|
26
|
-
super(
|
|
25
|
+
constructor(options) {
|
|
26
|
+
super(`Couldn't import the plugin "${module}":\n\n${options.cause}`, options);
|
|
27
27
|
this.name = "ModuleImportError";
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
export class ModuleExportIsInvalidError extends ModuleError {
|
|
31
|
-
constructor(
|
|
32
|
-
super(
|
|
31
|
+
constructor(options) {
|
|
32
|
+
super(`The export(s) of "${module}" are invalid:\n\n${options.errors
|
|
33
|
+
.map((error) => `Path "${error.path}" with value "${error.value}": "${error.message}"`)
|
|
34
|
+
.join("\n")}`, options);
|
|
33
35
|
this.name = "ModuleExportIsInvalidError";
|
|
34
36
|
}
|
|
35
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import.d.ts","sourceRoot":"","sources":["../../src/resolve-modules/import.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AAG7D;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;AAE1D;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE;IAClC,6CAA6C;IAC7C,QAAQ,EAAE,uBAAuB,CAAC,UAAU,CAAC,CAAA;CAC7C,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,UAAU,CAAC,OAAO,OAAO,CAAC,CAG9C;AAED,iBAAe,OAAO,CACrB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE;IACR;;OAEG;IACH,QAAQ,EAAE,uBAAuB,CAAC,UAAU,CAAC,CAAA;CAC7C,GACC,OAAO,CAAC,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"import.d.ts","sourceRoot":"","sources":["../../src/resolve-modules/import.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AAG7D;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;AAE1D;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE;IAClC,6CAA6C;IAC7C,QAAQ,EAAE,uBAAuB,CAAC,UAAU,CAAC,CAAA;CAC7C,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,UAAU,CAAC,OAAO,OAAO,CAAC,CAG9C;AAED,iBAAe,OAAO,CACrB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE;IACR;;OAEG;IACH,QAAQ,EAAE,uBAAuB,CAAC,UAAU,CAAC,CAAA;CAC7C,GACC,OAAO,CAAC,GAAG,CAAC,CAuBd"}
|
|
@@ -27,14 +27,13 @@ async function $import(uri, options) {
|
|
|
27
27
|
return await import(/* @vite-ignore */ moduleWithMimeType);
|
|
28
28
|
}
|
|
29
29
|
catch (error) {
|
|
30
|
-
let message = `Error while importing ${uri}: ${error?.message ?? "Unknown error"}`;
|
|
31
30
|
if (error instanceof SyntaxError && uri.includes("jsdelivr")) {
|
|
32
|
-
message += dedent `\n\n
|
|
31
|
+
error.message += dedent `\n\n
|
|
33
32
|
Are you sure that the file exists on JSDelivr?
|
|
34
33
|
|
|
35
34
|
The error indicates that the imported file does not exist on JSDelivr. For non-existent files, JSDelivr returns a 404 text that JS cannot parse as a module and throws a SyntaxError.
|
|
36
35
|
`;
|
|
37
36
|
}
|
|
38
|
-
throw new ModuleImportError(
|
|
37
|
+
throw new ModuleImportError({ module: uri, cause: error });
|
|
39
38
|
}
|
|
40
39
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { MessageLintRule } from "@inlang/message-lint-rule";
|
|
2
|
+
import type { ValueError } from "@sinclair/typebox/errors";
|
|
1
3
|
export declare class MessageLintRuleIsInvalidError extends Error {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
cause?: Error;
|
|
4
|
+
constructor(options: {
|
|
5
|
+
id: MessageLintRule["id"];
|
|
6
|
+
errors: ValueError[];
|
|
6
7
|
});
|
|
7
8
|
}
|
|
8
9
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/resolve-modules/message-lint-rules/errors.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/resolve-modules/message-lint-rules/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D,qBAAa,6BAA8B,SAAQ,KAAK;gBAC3C,OAAO,EAAE;QAAE,EAAE,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;QAAC,MAAM,EAAE,UAAU,EAAE,CAAA;KAAE;CAIxE"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export class MessageLintRuleIsInvalidError extends Error {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
super(message);
|
|
5
|
-
this.module = options.module;
|
|
2
|
+
constructor(options) {
|
|
3
|
+
super(`The message lint rule "${options.id}" is invalid:\n\n${options.errors.join("\n")}`);
|
|
6
4
|
this.name = "MessageLintRuleIsInvalidError";
|
|
7
5
|
}
|
|
8
6
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveMessageLintRules.d.ts","sourceRoot":"","sources":["../../../src/resolve-modules/message-lint-rules/resolveMessageLintRules.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAA;AAE3D,eAAO,MAAM,uBAAuB,SAAU;IAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC,CAAA;CAAE;;;
|
|
1
|
+
{"version":3,"file":"resolveMessageLintRules.d.ts","sourceRoot":"","sources":["../../../src/resolve-modules/message-lint-rules/resolveMessageLintRules.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAA;AAE3D,eAAO,MAAM,uBAAuB,SAAU;IAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC,CAAA;CAAE;;;CAqBzF,CAAA"}
|
|
@@ -8,8 +8,10 @@ export const resolveMessageLintRules = (args) => {
|
|
|
8
8
|
};
|
|
9
9
|
for (const rule of args.messageLintRules) {
|
|
10
10
|
if (Value.Check(MessageLintRule, rule) === false) {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const errors = [...Value.Errors(MessageLintRule, rule)];
|
|
12
|
+
result.errors.push(new MessageLintRuleIsInvalidError({
|
|
13
|
+
id: rule.id,
|
|
14
|
+
errors,
|
|
13
15
|
}));
|
|
14
16
|
continue;
|
|
15
17
|
}
|
|
@@ -1,31 +1,38 @@
|
|
|
1
1
|
import type { Plugin } from "@inlang/plugin";
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import type { ValueError } from "@sinclair/typebox/errors";
|
|
3
|
+
export declare class PluginHasInvalidIdError extends Error {
|
|
4
|
+
constructor(options: {
|
|
5
|
+
id: Plugin["id"];
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
export declare class PluginUsesReservedNamespaceError extends Error {
|
|
9
|
+
constructor(options: {
|
|
10
|
+
id: Plugin["id"];
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export declare class PluginHasInvalidSchemaError extends Error {
|
|
14
|
+
constructor(options: {
|
|
15
|
+
id: Plugin["id"];
|
|
16
|
+
errors: ValueError[];
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export declare class PluginLoadMessagesFunctionAlreadyDefinedError extends Error {
|
|
20
|
+
constructor(options: {
|
|
21
|
+
id: Plugin["id"];
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export declare class PluginSaveMessagesFunctionAlreadyDefinedError extends Error {
|
|
25
|
+
constructor(options: {
|
|
26
|
+
id: Plugin["id"];
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export declare class PluginReturnedInvalidCustomApiError extends Error {
|
|
30
|
+
constructor(options: {
|
|
31
|
+
id: Plugin["id"];
|
|
32
|
+
cause: ErrorOptions["cause"];
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export declare class PluginsDoNotProvideLoadOrSaveMessagesError extends Error {
|
|
36
|
+
constructor();
|
|
8
37
|
}
|
|
9
|
-
export declare class PluginHasInvalidIdError extends PluginError {
|
|
10
|
-
constructor(message: string, options: PluginErrorOptions);
|
|
11
|
-
}
|
|
12
|
-
export declare class PluginUsesReservedNamespaceError extends PluginError {
|
|
13
|
-
constructor(message: string, options: PluginErrorOptions);
|
|
14
|
-
}
|
|
15
|
-
export declare class PluginHasInvalidSchemaError extends PluginError {
|
|
16
|
-
constructor(message: string, options: PluginErrorOptions);
|
|
17
|
-
}
|
|
18
|
-
export declare class PluginLoadMessagesFunctionAlreadyDefinedError extends PluginError {
|
|
19
|
-
constructor(message: string, options: PluginErrorOptions);
|
|
20
|
-
}
|
|
21
|
-
export declare class PluginSaveMessagesFunctionAlreadyDefinedError extends PluginError {
|
|
22
|
-
constructor(message: string, options: PluginErrorOptions);
|
|
23
|
-
}
|
|
24
|
-
export declare class PluginReturnedInvalidCustomApiError extends PluginError {
|
|
25
|
-
constructor(message: string, options: PluginErrorOptions);
|
|
26
|
-
}
|
|
27
|
-
export declare class PluginsDoNotProvideLoadOrSaveMessagesError extends PluginError {
|
|
28
|
-
constructor(message: string, options: PluginErrorOptions);
|
|
29
|
-
}
|
|
30
|
-
export {};
|
|
31
38
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -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;
|
|
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;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D,qBAAa,uBAAwB,SAAQ,KAAK;gBACrC,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;KAAE;CAMzC;AAED,qBAAa,gCAAiC,SAAQ,KAAK;gBAC9C,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;KAAE;CAIzC;AAED,qBAAa,2BAA4B,SAAQ,KAAK;gBACzC,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QAAC,MAAM,EAAE,UAAU,EAAE,CAAA;KAAE;CAQ/D;AAED,qBAAa,6CAA8C,SAAQ,KAAK;gBAC3D,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;KAAE;CAMzC;AAED,qBAAa,6CAA8C,SAAQ,KAAK;gBAC3D,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;KAAE;CAMzC;AAED,qBAAa,mCAAoC,SAAQ,KAAK;gBACjD,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QAAC,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,CAAA;KAAE;CAIvE;AAED,qBAAa,0CAA2C,SAAQ,KAAK;;CAOpE"}
|
|
@@ -1,51 +1,44 @@
|
|
|
1
|
-
class
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
super(message);
|
|
5
|
-
this.name = "PluginError";
|
|
6
|
-
this.plugin = options.plugin ?? "unknown";
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export class PluginHasInvalidIdError extends PluginError {
|
|
10
|
-
constructor(message, options) {
|
|
11
|
-
super(message, options);
|
|
1
|
+
export class PluginHasInvalidIdError extends Error {
|
|
2
|
+
constructor(options) {
|
|
3
|
+
super(`Plugin "${options.id}" has an invalid id. The id must:\n1) Start with "plugin."\n2) camelCase\n3) Contain a namespace.\nAn example would be "plugin.namespace.myPlugin".`);
|
|
12
4
|
this.name = "PluginHasInvalidIdError";
|
|
13
5
|
}
|
|
14
6
|
}
|
|
15
|
-
export class PluginUsesReservedNamespaceError extends
|
|
16
|
-
constructor(
|
|
17
|
-
super(
|
|
7
|
+
export class PluginUsesReservedNamespaceError extends Error {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super(`Plugin ${options.id} uses reserved namespace 'inlang'.`);
|
|
18
10
|
this.name = "PluginUsesReservedNamespaceError";
|
|
19
11
|
}
|
|
20
12
|
}
|
|
21
|
-
export class PluginHasInvalidSchemaError extends
|
|
22
|
-
constructor(
|
|
23
|
-
super(
|
|
13
|
+
export class PluginHasInvalidSchemaError extends Error {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
super(`Plugin "${options.id}" has an invalid schema:\n\n${options.errors
|
|
16
|
+
.map((error) => `Path "${error.path}" with value "${error.value}": "${error.message}"`)
|
|
17
|
+
.join("\n")})}\n\nPlease refer to the documentation for the correct schema.`);
|
|
24
18
|
this.name = "PluginHasInvalidSchemaError";
|
|
25
19
|
}
|
|
26
20
|
}
|
|
27
|
-
export class PluginLoadMessagesFunctionAlreadyDefinedError extends
|
|
28
|
-
constructor(
|
|
29
|
-
super(
|
|
21
|
+
export class PluginLoadMessagesFunctionAlreadyDefinedError extends Error {
|
|
22
|
+
constructor(options) {
|
|
23
|
+
super(`Plugin "${options.id}" defines the \`loadMessages()\` function, but it was already defined by another plugin.\n\nInlang only allows one plugin to define the \`loadMessages()\` function.`);
|
|
30
24
|
this.name = "PluginLoadMessagesFunctionAlreadyDefinedError";
|
|
31
25
|
}
|
|
32
26
|
}
|
|
33
|
-
export class PluginSaveMessagesFunctionAlreadyDefinedError extends
|
|
34
|
-
constructor(
|
|
35
|
-
super(
|
|
27
|
+
export class PluginSaveMessagesFunctionAlreadyDefinedError extends Error {
|
|
28
|
+
constructor(options) {
|
|
29
|
+
super(`Plugin "${options.id}" defines the \`saveMessages()\` function, but it was already defined by another plugin.\n\nInlang only allows one plugin to define the \`saveMessages()\` function.`);
|
|
36
30
|
this.name = "PluginSaveMessagesFunctionAlreadyDefinedError";
|
|
37
31
|
}
|
|
38
32
|
}
|
|
39
|
-
export class PluginReturnedInvalidCustomApiError extends
|
|
40
|
-
constructor(
|
|
41
|
-
super(
|
|
33
|
+
export class PluginReturnedInvalidCustomApiError extends Error {
|
|
34
|
+
constructor(options) {
|
|
35
|
+
super(`Plugin "${options.id}" returned an invalid custom API:\n\n${options.cause}`, options);
|
|
42
36
|
this.name = "PluginReturnedInvalidCustomApiError";
|
|
43
37
|
}
|
|
44
38
|
}
|
|
45
|
-
export class PluginsDoNotProvideLoadOrSaveMessagesError extends
|
|
46
|
-
constructor(
|
|
47
|
-
super(
|
|
39
|
+
export class PluginsDoNotProvideLoadOrSaveMessagesError extends Error {
|
|
40
|
+
constructor() {
|
|
41
|
+
super(`No plugin provides a \`loadMessages()\` or \`saveMessages()\` function\n\nIn case no plugin threw an error, you likely forgot to add a plugin that handles the loading and saving of messages. Refer to the marketplace for available plugins https://inlang.com/marketplace.`);
|
|
48
42
|
this.name = "PluginsDoNotProvideLoadOrSaveMessagesError";
|
|
49
|
-
options.plugin = "plugin.inlang.missing";
|
|
50
43
|
}
|
|
51
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolvePlugins.d.ts","sourceRoot":"","sources":["../../../src/resolve-modules/plugins/resolvePlugins.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAuBxD,eAAO,MAAM,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"resolvePlugins.d.ts","sourceRoot":"","sources":["../../../src/resolve-modules/plugins/resolvePlugins.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAuBxD,eAAO,MAAM,cAAc,EAAE,sBAqH5B,CAAA"}
|
|
@@ -27,27 +27,27 @@ export const resolvePlugins = async (args) => {
|
|
|
27
27
|
// -- INVALID ID in META --
|
|
28
28
|
const hasInvalidId = errors.some((error) => error.path === "/id");
|
|
29
29
|
if (hasInvalidId) {
|
|
30
|
-
result.errors.push(new PluginHasInvalidIdError(
|
|
30
|
+
result.errors.push(new PluginHasInvalidIdError({ id: plugin.id }));
|
|
31
31
|
}
|
|
32
32
|
// -- USES RESERVED NAMESPACE --
|
|
33
33
|
if (plugin.id.includes("inlang") && !whitelistedPlugins.includes(plugin.id)) {
|
|
34
|
-
result.errors.push(new PluginUsesReservedNamespaceError(
|
|
35
|
-
|
|
34
|
+
result.errors.push(new PluginUsesReservedNamespaceError({
|
|
35
|
+
id: plugin.id,
|
|
36
36
|
}));
|
|
37
37
|
}
|
|
38
38
|
// -- USES INVALID SCHEMA --
|
|
39
39
|
if (errors.length > 0) {
|
|
40
|
-
result.errors.push(new PluginHasInvalidSchemaError(
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
result.errors.push(new PluginHasInvalidSchemaError({
|
|
41
|
+
id: plugin.id,
|
|
42
|
+
errors: errors,
|
|
43
43
|
}));
|
|
44
44
|
}
|
|
45
45
|
// -- ALREADY DEFINED LOADMESSAGES / SAVEMESSAGES / DETECTEDLANGUAGETAGS --
|
|
46
46
|
if (typeof plugin.loadMessages === "function" && result.data.loadMessages !== undefined) {
|
|
47
|
-
result.errors.push(new PluginLoadMessagesFunctionAlreadyDefinedError(
|
|
47
|
+
result.errors.push(new PluginLoadMessagesFunctionAlreadyDefinedError({ id: plugin.id }));
|
|
48
48
|
}
|
|
49
49
|
if (typeof plugin.saveMessages === "function" && result.data.saveMessages !== undefined) {
|
|
50
|
-
result.errors.push(new PluginSaveMessagesFunctionAlreadyDefinedError(
|
|
50
|
+
result.errors.push(new PluginSaveMessagesFunctionAlreadyDefinedError({ id: plugin.id }));
|
|
51
51
|
}
|
|
52
52
|
// --- ADD APP SPECIFIC API ---
|
|
53
53
|
if (typeof plugin.addCustomApi === "function") {
|
|
@@ -56,12 +56,13 @@ export const resolvePlugins = async (args) => {
|
|
|
56
56
|
settings: args.settings,
|
|
57
57
|
}));
|
|
58
58
|
if (error) {
|
|
59
|
-
|
|
60
|
-
delete error.stack;
|
|
61
|
-
result.errors.push(error); // TODO: add correct error type
|
|
59
|
+
result.errors.push(new PluginReturnedInvalidCustomApiError({ id: plugin.id, cause: error }));
|
|
62
60
|
}
|
|
63
|
-
if (typeof customApi !== "object") {
|
|
64
|
-
result.errors.push(new PluginReturnedInvalidCustomApiError(
|
|
61
|
+
else if (typeof customApi !== "object") {
|
|
62
|
+
result.errors.push(new PluginReturnedInvalidCustomApiError({
|
|
63
|
+
id: plugin.id,
|
|
64
|
+
cause: new Error(`The return value must be an object. Received "${typeof customApi}".`),
|
|
65
|
+
}));
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
// -- CONTINUE IF ERRORS --
|
|
@@ -95,7 +96,7 @@ export const resolvePlugins = async (args) => {
|
|
|
95
96
|
// --- LOADMESSAGE / SAVEMESSAGE NOT DEFINED ---
|
|
96
97
|
if (typeof result.data.loadMessages !== "function" ||
|
|
97
98
|
typeof result.data.saveMessages !== "function") {
|
|
98
|
-
result.errors.push(new PluginsDoNotProvideLoadOrSaveMessagesError(
|
|
99
|
+
result.errors.push(new PluginsDoNotProvideLoadOrSaveMessagesError());
|
|
99
100
|
}
|
|
100
101
|
return result;
|
|
101
102
|
};
|
|
@@ -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,qBA+E5B,CAAA"}
|
|
@@ -19,7 +19,7 @@ export const resolveModules = async (args) => {
|
|
|
19
19
|
const importedModule = await tryCatch(() => _import(module));
|
|
20
20
|
// -- IMPORT MODULE --
|
|
21
21
|
if (importedModule.error) {
|
|
22
|
-
moduleErrors.push(new ModuleImportError(
|
|
22
|
+
moduleErrors.push(new ModuleImportError({
|
|
23
23
|
module: module,
|
|
24
24
|
cause: importedModule.error,
|
|
25
25
|
}));
|
|
@@ -27,16 +27,17 @@ export const resolveModules = async (args) => {
|
|
|
27
27
|
}
|
|
28
28
|
// -- MODULE DOES NOT EXPORT ANYTHING --
|
|
29
29
|
if (importedModule.data?.default === undefined) {
|
|
30
|
-
moduleErrors.push(new ModuleHasNoExportsError(
|
|
30
|
+
moduleErrors.push(new ModuleHasNoExportsError({
|
|
31
31
|
module: module,
|
|
32
32
|
}));
|
|
33
33
|
continue;
|
|
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(
|
|
37
|
+
const errors = [...ModuleCompiler.Errors(importedModule.data)];
|
|
38
|
+
moduleErrors.push(new ModuleExportIsInvalidError({
|
|
39
39
|
module: module,
|
|
40
|
+
errors,
|
|
40
41
|
}));
|
|
41
42
|
continue;
|
|
42
43
|
}
|
|
@@ -11,7 +11,7 @@ it("should return an error if a plugin cannot be imported", async () => {
|
|
|
11
11
|
settings,
|
|
12
12
|
nodeishFs: {},
|
|
13
13
|
_import: () => {
|
|
14
|
-
throw new ModuleImportError(
|
|
14
|
+
throw new ModuleImportError({
|
|
15
15
|
module: settings.modules[0],
|
|
16
16
|
cause: new Error("Could not import"),
|
|
17
17
|
});
|
|
@@ -74,7 +74,7 @@ it("should return an error if a module cannot be imported", async () => {
|
|
|
74
74
|
modules: ["https://myplugin.com/index.js"],
|
|
75
75
|
};
|
|
76
76
|
const _import = async () => {
|
|
77
|
-
throw new ModuleImportError(
|
|
77
|
+
throw new ModuleImportError({
|
|
78
78
|
module: settings.modules[0],
|
|
79
79
|
cause: new Error(),
|
|
80
80
|
});
|
package/package.json
CHANGED
package/src/errors.ts
CHANGED
|
@@ -1,34 +1,43 @@
|
|
|
1
|
+
import type { ValueError } from "@sinclair/typebox/errors"
|
|
2
|
+
|
|
1
3
|
export class ProjectSettingsInvalidError extends Error {
|
|
2
|
-
constructor(
|
|
3
|
-
super(
|
|
4
|
+
constructor(options: { errors: ValueError[] }) {
|
|
5
|
+
super(
|
|
6
|
+
`The project settings are invalid:\n\n${options.errors
|
|
7
|
+
.map((error) => `The value of "${error.path}" is invalid:\n\n${error.message}`)
|
|
8
|
+
.join("\n")}`
|
|
9
|
+
)
|
|
4
10
|
this.name = "ProjectSettingsInvalidError"
|
|
5
11
|
}
|
|
6
12
|
}
|
|
7
13
|
|
|
8
14
|
export class ProjectSettingsFileJSONSyntaxError extends Error {
|
|
9
|
-
constructor(
|
|
10
|
-
super(
|
|
15
|
+
constructor(options: { cause: ErrorOptions["cause"]; path: string }) {
|
|
16
|
+
super(
|
|
17
|
+
`The settings file at "${options.path}" is not a valid JSON file:\n\n${options.cause}`,
|
|
18
|
+
options
|
|
19
|
+
)
|
|
11
20
|
this.name = "ProjectSettingsFileJSONSyntaxError"
|
|
12
21
|
}
|
|
13
22
|
}
|
|
14
23
|
|
|
15
24
|
export class ProjectSettingsFileNotFoundError extends Error {
|
|
16
|
-
constructor(
|
|
17
|
-
super(
|
|
25
|
+
constructor(options: { cause?: ErrorOptions["cause"]; path: string }) {
|
|
26
|
+
super(`The file at "${options.path}" could not be read. Does the file exists?`, options)
|
|
18
27
|
this.name = "ProjectSettingsFileNotFoundError"
|
|
19
28
|
}
|
|
20
29
|
}
|
|
21
30
|
|
|
22
31
|
export class PluginSaveMessagesError extends Error {
|
|
23
|
-
constructor(
|
|
24
|
-
super(
|
|
32
|
+
constructor(options: { cause: ErrorOptions["cause"] }) {
|
|
33
|
+
super(`An error occured in saveMessages() caused by ${options.cause}.`, options)
|
|
25
34
|
this.name = "PluginSaveMessagesError"
|
|
26
35
|
}
|
|
27
36
|
}
|
|
28
37
|
|
|
29
38
|
export class PluginLoadMessagesError extends Error {
|
|
30
|
-
constructor(
|
|
31
|
-
super(
|
|
39
|
+
constructor(options: { cause: ErrorOptions["cause"] }) {
|
|
40
|
+
super(`An error occured in loadMessages() caused by ${options.cause}.`, options)
|
|
32
41
|
this.name = "PluginLoadMessagesError"
|
|
33
42
|
}
|
|
34
43
|
}
|
package/src/loadProject.ts
CHANGED
|
@@ -73,7 +73,9 @@ export const loadProject = async (args: {
|
|
|
73
73
|
return { error }
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
throw new Error(
|
|
76
|
+
throw new Error(
|
|
77
|
+
"Unhandled error in setSettings. This is an internal bug. Please file an issue."
|
|
78
|
+
)
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
81
|
|
|
@@ -120,9 +122,7 @@ export const loadProject = async (args: {
|
|
|
120
122
|
setMessages(messages)
|
|
121
123
|
markInitAsComplete()
|
|
122
124
|
})
|
|
123
|
-
.catch((err) =>
|
|
124
|
-
markInitAsFailed(new PluginLoadMessagesError("Error in load messages", { cause: err }))
|
|
125
|
-
)
|
|
125
|
+
.catch((err) => markInitAsFailed(new PluginLoadMessagesError({ cause: err })))
|
|
126
126
|
})
|
|
127
127
|
|
|
128
128
|
// -- installed items ----------------------------------------------------
|
|
@@ -178,7 +178,7 @@ export const loadProject = async (args: {
|
|
|
178
178
|
messages: newMessages,
|
|
179
179
|
})
|
|
180
180
|
} catch (err) {
|
|
181
|
-
throw new PluginSaveMessagesError(
|
|
181
|
+
throw new PluginSaveMessagesError({
|
|
182
182
|
cause: err,
|
|
183
183
|
})
|
|
184
184
|
}
|
|
@@ -231,18 +231,17 @@ const loadSettings = async (args: {
|
|
|
231
231
|
async () => await args.nodeishFs.readFile(args.settingsFilePath, { encoding: "utf-8" })
|
|
232
232
|
)
|
|
233
233
|
if (settingsFileError)
|
|
234
|
-
throw new ProjectSettingsFileNotFoundError(
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
)
|
|
234
|
+
throw new ProjectSettingsFileNotFoundError({
|
|
235
|
+
cause: settingsFileError,
|
|
236
|
+
path: args.settingsFilePath,
|
|
237
|
+
})
|
|
240
238
|
|
|
241
239
|
const json = tryCatch(() => JSON.parse(settingsFile!))
|
|
242
240
|
|
|
243
241
|
if (json.error) {
|
|
244
|
-
throw new ProjectSettingsFileJSONSyntaxError(
|
|
242
|
+
throw new ProjectSettingsFileJSONSyntaxError({
|
|
245
243
|
cause: json.error,
|
|
244
|
+
path: args.settingsFilePath,
|
|
246
245
|
})
|
|
247
246
|
}
|
|
248
247
|
return parseSettings(json.data)
|
|
@@ -253,8 +252,8 @@ const parseSettings = (settings: unknown) => {
|
|
|
253
252
|
if (settingsCompiler.Check(withMigration) === false) {
|
|
254
253
|
const typeErrors = [...settingsCompiler.Errors(settings)]
|
|
255
254
|
if (typeErrors.length > 0) {
|
|
256
|
-
throw new ProjectSettingsInvalidError(
|
|
257
|
-
|
|
255
|
+
throw new ProjectSettingsInvalidError({
|
|
256
|
+
errors: typeErrors,
|
|
258
257
|
})
|
|
259
258
|
}
|
|
260
259
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import type { ValueError } from "@sinclair/typebox/errors"
|
|
1
2
|
export * from "./plugins/errors.js"
|
|
2
3
|
export * from "./message-lint-rules/errors.js"
|
|
3
4
|
|
|
4
5
|
export class ModuleError extends Error {
|
|
5
|
-
public readonly
|
|
6
|
+
public readonly module: string
|
|
6
7
|
constructor(message: string, options: { module: string; cause?: Error }) {
|
|
7
8
|
super(message)
|
|
8
9
|
this.name = "ModuleError"
|
|
9
|
-
this.
|
|
10
|
+
this.module = options.module
|
|
10
11
|
this.cause = options.cause
|
|
11
12
|
}
|
|
12
13
|
}
|
|
@@ -15,8 +16,8 @@ export class ModuleError extends Error {
|
|
|
15
16
|
* Error when a Module does not export any plugins or lint rules.
|
|
16
17
|
*/
|
|
17
18
|
export class ModuleHasNoExportsError extends ModuleError {
|
|
18
|
-
constructor(
|
|
19
|
-
super(
|
|
19
|
+
constructor(options: { module: string; cause?: Error }) {
|
|
20
|
+
super(`Module "${module}" has no exports. Every module must have an "export default".`, options)
|
|
20
21
|
this.name = "ModuleHasNoExportsError"
|
|
21
22
|
}
|
|
22
23
|
}
|
|
@@ -25,15 +26,20 @@ export class ModuleHasNoExportsError extends ModuleError {
|
|
|
25
26
|
* Error when a Module cannot be imported.
|
|
26
27
|
*/
|
|
27
28
|
export class ModuleImportError extends ModuleError {
|
|
28
|
-
constructor(
|
|
29
|
-
super(
|
|
29
|
+
constructor(options: { module: string; cause: Error }) {
|
|
30
|
+
super(`Couldn't import the plugin "${module}":\n\n${options.cause}`, options)
|
|
30
31
|
this.name = "ModuleImportError"
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
export class ModuleExportIsInvalidError extends ModuleError {
|
|
35
|
-
constructor(
|
|
36
|
-
super(
|
|
36
|
+
constructor(options: { module: string; errors: ValueError[] }) {
|
|
37
|
+
super(
|
|
38
|
+
`The export(s) of "${module}" are invalid:\n\n${options.errors
|
|
39
|
+
.map((error) => `Path "${error.path}" with value "${error.value}": "${error.message}"`)
|
|
40
|
+
.join("\n")}`,
|
|
41
|
+
options
|
|
42
|
+
)
|
|
37
43
|
this.name = "ModuleExportIsInvalidError"
|
|
38
44
|
}
|
|
39
45
|
}
|
|
@@ -50,14 +50,13 @@ async function $import(
|
|
|
50
50
|
try {
|
|
51
51
|
return await import(/* @vite-ignore */ moduleWithMimeType)
|
|
52
52
|
} catch (error) {
|
|
53
|
-
let message = `Error while importing ${uri}: ${(error as Error)?.message ?? "Unknown error"}`
|
|
54
53
|
if (error instanceof SyntaxError && uri.includes("jsdelivr")) {
|
|
55
|
-
message += dedent`\n\n
|
|
54
|
+
error.message += dedent`\n\n
|
|
56
55
|
Are you sure that the file exists on JSDelivr?
|
|
57
56
|
|
|
58
57
|
The error indicates that the imported file does not exist on JSDelivr. For non-existent files, JSDelivr returns a 404 text that JS cannot parse as a module and throws a SyntaxError.
|
|
59
58
|
`
|
|
60
59
|
}
|
|
61
|
-
throw new ModuleImportError(
|
|
60
|
+
throw new ModuleImportError({ module: uri, cause: error as Error })
|
|
62
61
|
}
|
|
63
62
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { MessageLintRule } from "@inlang/message-lint-rule"
|
|
2
|
+
import type { ValueError } from "@sinclair/typebox/errors"
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export class MessageLintRuleIsInvalidError extends Error {
|
|
5
|
+
constructor(options: { id: MessageLintRule["id"]; errors: ValueError[] }) {
|
|
6
|
+
super(`The message lint rule "${options.id}" is invalid:\n\n${options.errors.join("\n")}`)
|
|
7
7
|
this.name = "MessageLintRuleIsInvalidError"
|
|
8
8
|
}
|
|
9
9
|
}
|
|
@@ -9,9 +9,11 @@ export const resolveMessageLintRules = (args: { messageLintRules: Array<MessageL
|
|
|
9
9
|
}
|
|
10
10
|
for (const rule of args.messageLintRules) {
|
|
11
11
|
if (Value.Check(MessageLintRule, rule) === false) {
|
|
12
|
+
const errors = [...Value.Errors(MessageLintRule, rule)]
|
|
12
13
|
result.errors.push(
|
|
13
|
-
new MessageLintRuleIsInvalidError(
|
|
14
|
-
|
|
14
|
+
new MessageLintRuleIsInvalidError({
|
|
15
|
+
id: rule.id,
|
|
16
|
+
errors,
|
|
15
17
|
})
|
|
16
18
|
)
|
|
17
19
|
continue
|
|
@@ -1,65 +1,63 @@
|
|
|
1
1
|
import type { Plugin } from "@inlang/plugin"
|
|
2
|
+
import type { ValueError } from "@sinclair/typebox/errors"
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
public readonly plugin: string
|
|
9
|
-
|
|
10
|
-
constructor(message: string, options: PluginErrorOptions) {
|
|
11
|
-
super(message)
|
|
12
|
-
this.name = "PluginError"
|
|
13
|
-
this.plugin = options.plugin ?? "unknown"
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class PluginHasInvalidIdError extends PluginError {
|
|
18
|
-
constructor(message: string, options: PluginErrorOptions) {
|
|
19
|
-
super(message, options)
|
|
4
|
+
export class PluginHasInvalidIdError extends Error {
|
|
5
|
+
constructor(options: { id: Plugin["id"] }) {
|
|
6
|
+
super(
|
|
7
|
+
`Plugin "${options.id}" has an invalid id. The id must:\n1) Start with "plugin."\n2) camelCase\n3) Contain a namespace.\nAn example would be "plugin.namespace.myPlugin".`
|
|
8
|
+
)
|
|
20
9
|
this.name = "PluginHasInvalidIdError"
|
|
21
10
|
}
|
|
22
11
|
}
|
|
23
12
|
|
|
24
|
-
export class PluginUsesReservedNamespaceError extends
|
|
25
|
-
constructor(
|
|
26
|
-
super(
|
|
13
|
+
export class PluginUsesReservedNamespaceError extends Error {
|
|
14
|
+
constructor(options: { id: Plugin["id"] }) {
|
|
15
|
+
super(`Plugin ${options.id} uses reserved namespace 'inlang'.`)
|
|
27
16
|
this.name = "PluginUsesReservedNamespaceError"
|
|
28
17
|
}
|
|
29
18
|
}
|
|
30
19
|
|
|
31
|
-
export class PluginHasInvalidSchemaError extends
|
|
32
|
-
constructor(
|
|
33
|
-
super(
|
|
20
|
+
export class PluginHasInvalidSchemaError extends Error {
|
|
21
|
+
constructor(options: { id: Plugin["id"]; errors: ValueError[] }) {
|
|
22
|
+
super(
|
|
23
|
+
`Plugin "${options.id}" has an invalid schema:\n\n${options.errors
|
|
24
|
+
.map((error) => `Path "${error.path}" with value "${error.value}": "${error.message}"`)
|
|
25
|
+
.join("\n")})}\n\nPlease refer to the documentation for the correct schema.`
|
|
26
|
+
)
|
|
34
27
|
this.name = "PluginHasInvalidSchemaError"
|
|
35
28
|
}
|
|
36
29
|
}
|
|
37
30
|
|
|
38
|
-
export class PluginLoadMessagesFunctionAlreadyDefinedError extends
|
|
39
|
-
constructor(
|
|
40
|
-
super(
|
|
31
|
+
export class PluginLoadMessagesFunctionAlreadyDefinedError extends Error {
|
|
32
|
+
constructor(options: { id: Plugin["id"] }) {
|
|
33
|
+
super(
|
|
34
|
+
`Plugin "${options.id}" defines the \`loadMessages()\` function, but it was already defined by another plugin.\n\nInlang only allows one plugin to define the \`loadMessages()\` function.`
|
|
35
|
+
)
|
|
41
36
|
this.name = "PluginLoadMessagesFunctionAlreadyDefinedError"
|
|
42
37
|
}
|
|
43
38
|
}
|
|
44
39
|
|
|
45
|
-
export class PluginSaveMessagesFunctionAlreadyDefinedError extends
|
|
46
|
-
constructor(
|
|
47
|
-
super(
|
|
40
|
+
export class PluginSaveMessagesFunctionAlreadyDefinedError extends Error {
|
|
41
|
+
constructor(options: { id: Plugin["id"] }) {
|
|
42
|
+
super(
|
|
43
|
+
`Plugin "${options.id}" defines the \`saveMessages()\` function, but it was already defined by another plugin.\n\nInlang only allows one plugin to define the \`saveMessages()\` function.`
|
|
44
|
+
)
|
|
48
45
|
this.name = "PluginSaveMessagesFunctionAlreadyDefinedError"
|
|
49
46
|
}
|
|
50
47
|
}
|
|
51
48
|
|
|
52
|
-
export class PluginReturnedInvalidCustomApiError extends
|
|
53
|
-
constructor(
|
|
54
|
-
super(
|
|
49
|
+
export class PluginReturnedInvalidCustomApiError extends Error {
|
|
50
|
+
constructor(options: { id: Plugin["id"]; cause: ErrorOptions["cause"] }) {
|
|
51
|
+
super(`Plugin "${options.id}" returned an invalid custom API:\n\n${options.cause}`, options)
|
|
55
52
|
this.name = "PluginReturnedInvalidCustomApiError"
|
|
56
53
|
}
|
|
57
54
|
}
|
|
58
55
|
|
|
59
|
-
export class PluginsDoNotProvideLoadOrSaveMessagesError extends
|
|
60
|
-
constructor(
|
|
61
|
-
super(
|
|
56
|
+
export class PluginsDoNotProvideLoadOrSaveMessagesError extends Error {
|
|
57
|
+
constructor() {
|
|
58
|
+
super(
|
|
59
|
+
`No plugin provides a \`loadMessages()\` or \`saveMessages()\` function\n\nIn case no plugin threw an error, you likely forgot to add a plugin that handles the loading and saving of messages. Refer to the marketplace for available plugins https://inlang.com/marketplace.`
|
|
60
|
+
)
|
|
62
61
|
this.name = "PluginsDoNotProvideLoadOrSaveMessagesError"
|
|
63
|
-
options.plugin = "plugin.inlang.missing"
|
|
64
62
|
}
|
|
65
63
|
}
|
|
@@ -42,56 +42,35 @@ export const resolvePlugins: ResolvePluginsFunction = async (args) => {
|
|
|
42
42
|
// -- INVALID ID in META --
|
|
43
43
|
const hasInvalidId = errors.some((error) => error.path === "/id")
|
|
44
44
|
if (hasInvalidId) {
|
|
45
|
-
result.errors.push(
|
|
46
|
-
new PluginHasInvalidIdError(
|
|
47
|
-
`Plugin ${plugin.id} has an invalid id "${plugin.id}". It must be camelCase and contain a namespace like plugin.namespace.myPlugin.`,
|
|
48
|
-
{ plugin: plugin.id }
|
|
49
|
-
)
|
|
50
|
-
)
|
|
45
|
+
result.errors.push(new PluginHasInvalidIdError({ id: plugin.id }))
|
|
51
46
|
}
|
|
52
47
|
|
|
53
48
|
// -- USES RESERVED NAMESPACE --
|
|
54
49
|
if (plugin.id.includes("inlang") && !whitelistedPlugins.includes(plugin.id)) {
|
|
55
50
|
result.errors.push(
|
|
56
|
-
new PluginUsesReservedNamespaceError(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
plugin: plugin.id,
|
|
60
|
-
}
|
|
61
|
-
)
|
|
51
|
+
new PluginUsesReservedNamespaceError({
|
|
52
|
+
id: plugin.id,
|
|
53
|
+
})
|
|
62
54
|
)
|
|
63
55
|
}
|
|
64
56
|
|
|
65
57
|
// -- USES INVALID SCHEMA --
|
|
66
58
|
if (errors.length > 0) {
|
|
67
59
|
result.errors.push(
|
|
68
|
-
new PluginHasInvalidSchemaError(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
cause: errors,
|
|
73
|
-
}
|
|
74
|
-
)
|
|
60
|
+
new PluginHasInvalidSchemaError({
|
|
61
|
+
id: plugin.id,
|
|
62
|
+
errors: errors,
|
|
63
|
+
})
|
|
75
64
|
)
|
|
76
65
|
}
|
|
77
66
|
|
|
78
67
|
// -- ALREADY DEFINED LOADMESSAGES / SAVEMESSAGES / DETECTEDLANGUAGETAGS --
|
|
79
68
|
if (typeof plugin.loadMessages === "function" && result.data.loadMessages !== undefined) {
|
|
80
|
-
result.errors.push(
|
|
81
|
-
new PluginLoadMessagesFunctionAlreadyDefinedError(
|
|
82
|
-
`Plugin ${plugin.id} defines the loadMessages function, but it was already defined by another plugin.`,
|
|
83
|
-
{ plugin: plugin.id }
|
|
84
|
-
)
|
|
85
|
-
)
|
|
69
|
+
result.errors.push(new PluginLoadMessagesFunctionAlreadyDefinedError({ id: plugin.id }))
|
|
86
70
|
}
|
|
87
71
|
|
|
88
72
|
if (typeof plugin.saveMessages === "function" && result.data.saveMessages !== undefined) {
|
|
89
|
-
result.errors.push(
|
|
90
|
-
new PluginSaveMessagesFunctionAlreadyDefinedError(
|
|
91
|
-
`Plugin ${plugin.id} defines the saveMessages function, but it was already defined by another plugin.`,
|
|
92
|
-
{ plugin: plugin.id }
|
|
93
|
-
)
|
|
94
|
-
)
|
|
73
|
+
result.errors.push(new PluginSaveMessagesFunctionAlreadyDefinedError({ id: plugin.id }))
|
|
95
74
|
}
|
|
96
75
|
|
|
97
76
|
// --- ADD APP SPECIFIC API ---
|
|
@@ -103,16 +82,13 @@ export const resolvePlugins: ResolvePluginsFunction = async (args) => {
|
|
|
103
82
|
})
|
|
104
83
|
)
|
|
105
84
|
if (error) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
result.errors.push(error as any) // TODO: add correct error type
|
|
109
|
-
}
|
|
110
|
-
if (typeof customApi !== "object") {
|
|
85
|
+
result.errors.push(new PluginReturnedInvalidCustomApiError({ id: plugin.id, cause: error }))
|
|
86
|
+
} else if (typeof customApi !== "object") {
|
|
111
87
|
result.errors.push(
|
|
112
|
-
new PluginReturnedInvalidCustomApiError(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
)
|
|
88
|
+
new PluginReturnedInvalidCustomApiError({
|
|
89
|
+
id: plugin.id,
|
|
90
|
+
cause: new Error(`The return value must be an object. Received "${typeof customApi}".`),
|
|
91
|
+
})
|
|
116
92
|
)
|
|
117
93
|
}
|
|
118
94
|
}
|
|
@@ -159,12 +135,7 @@ export const resolvePlugins: ResolvePluginsFunction = async (args) => {
|
|
|
159
135
|
typeof result.data.loadMessages !== "function" ||
|
|
160
136
|
typeof result.data.saveMessages !== "function"
|
|
161
137
|
) {
|
|
162
|
-
result.errors.push(
|
|
163
|
-
new PluginsDoNotProvideLoadOrSaveMessagesError(
|
|
164
|
-
"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.",
|
|
165
|
-
{ plugin: undefined }
|
|
166
|
-
)
|
|
167
|
-
)
|
|
138
|
+
result.errors.push(new PluginsDoNotProvideLoadOrSaveMessagesError())
|
|
168
139
|
}
|
|
169
140
|
|
|
170
141
|
return result
|
|
@@ -23,7 +23,7 @@ it("should return an error if a plugin cannot be imported", async () => {
|
|
|
23
23
|
settings,
|
|
24
24
|
nodeishFs: {} as any,
|
|
25
25
|
_import: () => {
|
|
26
|
-
throw new ModuleImportError(
|
|
26
|
+
throw new ModuleImportError({
|
|
27
27
|
module: settings.modules[0]!,
|
|
28
28
|
cause: new Error("Could not import"),
|
|
29
29
|
})
|
|
@@ -94,7 +94,7 @@ it("should return an error if a module cannot be imported", async () => {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
const _import = async () => {
|
|
97
|
-
throw new ModuleImportError(
|
|
97
|
+
throw new ModuleImportError({
|
|
98
98
|
module: settings.modules[0]!,
|
|
99
99
|
cause: new Error(),
|
|
100
100
|
})
|
|
@@ -35,7 +35,7 @@ export const resolveModules: ResolveModuleFunction = async (args) => {
|
|
|
35
35
|
// -- IMPORT MODULE --
|
|
36
36
|
if (importedModule.error) {
|
|
37
37
|
moduleErrors.push(
|
|
38
|
-
new ModuleImportError(
|
|
38
|
+
new ModuleImportError({
|
|
39
39
|
module: module,
|
|
40
40
|
cause: importedModule.error as Error,
|
|
41
41
|
})
|
|
@@ -46,7 +46,7 @@ export const resolveModules: ResolveModuleFunction = async (args) => {
|
|
|
46
46
|
// -- MODULE DOES NOT EXPORT ANYTHING --
|
|
47
47
|
if (importedModule.data?.default === undefined) {
|
|
48
48
|
moduleErrors.push(
|
|
49
|
-
new ModuleHasNoExportsError(
|
|
49
|
+
new ModuleHasNoExportsError({
|
|
50
50
|
module: module,
|
|
51
51
|
})
|
|
52
52
|
)
|
|
@@ -56,12 +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)]
|
|
60
|
-
(e) => `${e.path} ${e.message}`
|
|
61
|
-
)
|
|
59
|
+
const errors = [...ModuleCompiler.Errors(importedModule.data)]
|
|
62
60
|
moduleErrors.push(
|
|
63
|
-
new ModuleExportIsInvalidError(
|
|
61
|
+
new ModuleExportIsInvalidError({
|
|
64
62
|
module: module,
|
|
63
|
+
errors,
|
|
65
64
|
})
|
|
66
65
|
)
|
|
67
66
|
continue
|