@inlang/sdk 0.8.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.
Files changed (44) hide show
  1. package/dist/adapter/solidAdapter.test.js +1 -1
  2. package/dist/errors.d.ts +18 -5
  3. package/dist/errors.d.ts.map +1 -1
  4. package/dist/errors.js +12 -10
  5. package/dist/loadProject.d.ts.map +1 -1
  6. package/dist/loadProject.js +14 -10
  7. package/dist/loadProject.test.js +4 -5
  8. package/dist/resolve-modules/errors.d.ts +6 -5
  9. package/dist/resolve-modules/errors.d.ts.map +1 -1
  10. package/dist/resolve-modules/errors.js +10 -8
  11. package/dist/resolve-modules/import.d.ts.map +1 -1
  12. package/dist/resolve-modules/import.js +2 -3
  13. package/dist/resolve-modules/message-lint-rules/errors.d.ts +5 -4
  14. package/dist/resolve-modules/message-lint-rules/errors.d.ts.map +1 -1
  15. package/dist/resolve-modules/message-lint-rules/errors.js +2 -4
  16. package/dist/resolve-modules/message-lint-rules/resolveMessageLintRules.d.ts.map +1 -1
  17. package/dist/resolve-modules/message-lint-rules/resolveMessageLintRules.js +4 -2
  18. package/dist/resolve-modules/plugins/errors.d.ts +35 -28
  19. package/dist/resolve-modules/plugins/errors.d.ts.map +1 -1
  20. package/dist/resolve-modules/plugins/errors.js +23 -30
  21. package/dist/resolve-modules/plugins/resolvePlugins.d.ts.map +1 -1
  22. package/dist/resolve-modules/plugins/resolvePlugins.js +17 -18
  23. package/dist/resolve-modules/plugins/resolvePlugins.test.js +79 -49
  24. package/dist/resolve-modules/plugins/types.d.ts +4 -5
  25. package/dist/resolve-modules/plugins/types.d.ts.map +1 -1
  26. package/dist/resolve-modules/resolveModules.d.ts.map +1 -1
  27. package/dist/resolve-modules/resolveModules.js +5 -4
  28. package/dist/resolve-modules/resolveModules.test.js +2 -2
  29. package/dist/test-utilities/createMessage.d.ts +1 -1
  30. package/package.json +1 -1
  31. package/src/adapter/solidAdapter.test.ts +1 -1
  32. package/src/errors.ts +19 -10
  33. package/src/loadProject.test.ts +11 -14
  34. package/src/loadProject.ts +18 -17
  35. package/src/resolve-modules/errors.ts +14 -8
  36. package/src/resolve-modules/import.ts +2 -3
  37. package/src/resolve-modules/message-lint-rules/errors.ts +5 -5
  38. package/src/resolve-modules/message-lint-rules/resolveMessageLintRules.ts +4 -2
  39. package/src/resolve-modules/plugins/errors.ts +34 -36
  40. package/src/resolve-modules/plugins/resolvePlugins.test.ts +94 -62
  41. package/src/resolve-modules/plugins/resolvePlugins.ts +19 -50
  42. package/src/resolve-modules/plugins/types.ts +4 -8
  43. package/src/resolve-modules/resolveModules.test.ts +2 -2
  44. package/src/resolve-modules/resolveModules.ts +5 -6
@@ -143,7 +143,7 @@ describe("messages", () => {
143
143
  description: {
144
144
  en: "wo",
145
145
  },
146
- loadMessages: ({ languageTags }) => (languageTags.length ? exampleMessages : []),
146
+ loadMessages: ({ settings }) => (settings.languageTags.length ? exampleMessages : []),
147
147
  saveMessages: () => undefined,
148
148
  };
149
149
  const mockImport = async () => ({ default: mockPlugin });
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(message: string, options: ErrorOptions);
3
+ constructor(options: {
4
+ errors: ValueError[];
5
+ });
3
6
  }
4
7
  export declare class ProjectSettingsFileJSONSyntaxError extends Error {
5
- constructor(message: string, options: ErrorOptions);
8
+ constructor(options: {
9
+ cause: ErrorOptions["cause"];
10
+ path: string;
11
+ });
6
12
  }
7
13
  export declare class ProjectSettingsFileNotFoundError extends Error {
8
- constructor(message: string, options: ErrorOptions);
14
+ constructor(options: {
15
+ cause?: ErrorOptions["cause"];
16
+ path: string;
17
+ });
9
18
  }
10
19
  export declare class PluginSaveMessagesError extends Error {
11
- constructor(message: string, options: ErrorOptions);
20
+ constructor(options: {
21
+ cause: ErrorOptions["cause"];
22
+ });
12
23
  }
13
24
  export declare class PluginLoadMessagesError extends Error {
14
- constructor(message: string, options: ErrorOptions);
25
+ constructor(options: {
26
+ cause: ErrorOptions["cause"];
27
+ });
15
28
  }
16
29
  //# sourceMappingURL=errors.d.ts.map
@@ -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,OAAO,EAAE,YAAY;CAIlD;AAED,qBAAa,kCAAmC,SAAQ,KAAK;gBAChD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY;CAIlD;AAED,qBAAa,gCAAiC,SAAQ,KAAK;gBAC9C,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY;CAIlD;AAED,qBAAa,uBAAwB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY;CAIlD;AAED,qBAAa,uBAAwB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY;CAIlD"}
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(message, options) {
3
- super(message, options);
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(message, options) {
9
- super(message, options);
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(message, options) {
15
- super(message, options);
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(message, options) {
21
- super(message, options);
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(message, options) {
27
- super(message, options);
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,CAmLxB,CAAA;AAsGD,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAQtE"}
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"}
@@ -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("unhandled");
49
+ throw new Error("Unhandled error in setSettings. This is an internal bug. Please file an issue.");
50
50
  }
51
51
  };
52
52
  // -- resolvedModules -----------------------------------------------------------
@@ -77,14 +77,13 @@ export const loadProject = async (args) => {
77
77
  return;
78
78
  }
79
79
  makeTrulyAsync(_resolvedModules.resolvedPluginApi.loadMessages({
80
- languageTags: settingsValue.languageTags,
81
- sourceLanguageTag: settingsValue.sourceLanguageTag,
80
+ settings: settingsValue,
82
81
  }))
83
82
  .then((messages) => {
84
83
  setMessages(messages);
85
84
  markInitAsComplete();
86
85
  })
87
- .catch((err) => markInitAsFailed(new PluginLoadMessagesError("Error in load messages", { cause: err })));
86
+ .catch((err) => markInitAsFailed(new PluginLoadMessagesError({ cause: err })));
88
87
  });
89
88
  // -- installed items ----------------------------------------------------
90
89
  const installedMessageLintRules = () => {
@@ -117,10 +116,13 @@ export const loadProject = async (args) => {
117
116
  const lintReportsQuery = createMessageLintReportsQuery(messages, settings, installedMessageLintRules, resolvedModules);
118
117
  const debouncedSave = skipFirst(debounce(500, async (newMessages) => {
119
118
  try {
120
- await resolvedModules()?.resolvedPluginApi.saveMessages({ messages: newMessages });
119
+ await resolvedModules()?.resolvedPluginApi.saveMessages({
120
+ settings: settingsValue,
121
+ messages: newMessages,
122
+ });
121
123
  }
122
124
  catch (err) {
123
- throw new PluginSaveMessagesError("Error in saving messages", {
125
+ throw new PluginSaveMessagesError({
124
126
  cause: err,
125
127
  });
126
128
  }
@@ -158,13 +160,15 @@ export const loadProject = async (args) => {
158
160
  const loadSettings = async (args) => {
159
161
  const { data: settingsFile, error: settingsFileError } = await tryCatch(async () => await args.nodeishFs.readFile(args.settingsFilePath, { encoding: "utf-8" }));
160
162
  if (settingsFileError)
161
- throw new ProjectSettingsFileNotFoundError(`Could not locate settings file in (${args.settingsFilePath}).`, {
163
+ throw new ProjectSettingsFileNotFoundError({
162
164
  cause: settingsFileError,
165
+ path: args.settingsFilePath,
163
166
  });
164
167
  const json = tryCatch(() => JSON.parse(settingsFile));
165
168
  if (json.error) {
166
- throw new ProjectSettingsFileJSONSyntaxError(`The settings is not a valid JSON file.`, {
169
+ throw new ProjectSettingsFileJSONSyntaxError({
167
170
  cause: json.error,
171
+ path: args.settingsFilePath,
168
172
  });
169
173
  }
170
174
  return parseSettings(json.data);
@@ -174,8 +178,8 @@ const parseSettings = (settings) => {
174
178
  if (settingsCompiler.Check(withMigration) === false) {
175
179
  const typeErrors = [...settingsCompiler.Errors(settings)];
176
180
  if (typeErrors.length > 0) {
177
- throw new ProjectSettingsInvalidError(`The settings is invalid according to the schema.`, {
178
- cause: typeErrors,
181
+ throw new ProjectSettingsInvalidError({
182
+ errors: typeErrors,
179
183
  });
180
184
  }
181
185
  }
@@ -399,14 +399,15 @@ describe("functionality", () => {
399
399
  describe("query", () => {
400
400
  it("should call saveMessages() on updates", async () => {
401
401
  const fs = createNodeishMemoryFs();
402
- await fs.writeFile("./project.inlang.json", JSON.stringify({
402
+ const settings = {
403
403
  sourceLanguageTag: "en",
404
404
  languageTags: ["en", "de"],
405
405
  modules: ["plugin.js"],
406
406
  "plugin.project.json": {
407
407
  pathPattern: "./resources/{languageTag}.json",
408
408
  },
409
- }));
409
+ };
410
+ await fs.writeFile("./project.inlang.json", JSON.stringify(settings));
410
411
  await fs.mkdir("./resources");
411
412
  const mockSaveFn = vi.fn();
412
413
  const _mockPlugin = {
@@ -486,9 +487,7 @@ describe("functionality", () => {
486
487
  });
487
488
  await new Promise((resolve) => setTimeout(resolve, 510));
488
489
  expect(mockSaveFn.mock.calls.length).toBe(1);
489
- expect(mockSaveFn.mock.calls[0][0].settings).toStrictEqual({
490
- pathPattern: "./resources/{languageTag}.json",
491
- });
490
+ expect(mockSaveFn.mock.calls[0][0].settings).toStrictEqual(settings);
492
491
  expect(Object.values(mockSaveFn.mock.calls[0][0].messages)).toStrictEqual([
493
492
  {
494
493
  id: "a",
@@ -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 Module: string;
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(message: string, options: {
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(message: string, options: {
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(message: string, options: {
30
+ constructor(options: {
30
31
  module: string;
31
- cause?: Error;
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,MAAM,EAAE,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAIvE;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,WAAW;gBACrC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE;CAItE;AAED,qBAAa,0BAA2B,SAAQ,WAAW;gBAC9C,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAIvE"}
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
- Module;
4
+ module;
5
5
  constructor(message, options) {
6
6
  super(message);
7
7
  this.name = "ModuleError";
8
- this.Module = options.module;
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(message, options) {
17
- super(message, options);
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(message, options) {
26
- super(message, options);
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(message, options) {
32
- super(message, options);
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,CAwBd"}
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(message, { module: uri, cause: error });
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
- readonly module: string;
3
- constructor(message: string, options: {
4
- module: string;
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,qBAAa,6BAA8B,SAAQ,KAAK;IACvD,SAAgB,MAAM,EAAE,MAAM,CAAA;gBAElB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAKvE"}
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
- module;
3
- constructor(message, options) {
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;;;CAmBzF,CAAA"}
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
- result.errors.push(new MessageLintRuleIsInvalidError(`Couldn't parse lint rule "${rule.id}"`, {
12
- module: "not implemented",
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 PluginErrorOptions = {
3
- plugin: Plugin["id"] | undefined;
4
- } & Partial<Error>;
5
- declare class PluginError extends Error {
6
- readonly plugin: string;
7
- constructor(message: string, options: PluginErrorOptions);
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;AAE5C,KAAK,kBAAkB,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,SAAS,CAAA;CAChC,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"}
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 PluginError extends Error {
2
- plugin;
3
- constructor(message, options) {
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 PluginError {
16
- constructor(message, options) {
17
- super(message, options);
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 PluginError {
22
- constructor(message, options) {
23
- super(message, options);
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 PluginError {
28
- constructor(message, options) {
29
- super(message, options);
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 PluginError {
34
- constructor(message, options) {
35
- super(message, options);
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 PluginError {
40
- constructor(message, options) {
41
- super(message, options);
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 PluginError {
46
- constructor(message, options) {
47
- super(message, options);
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,sBAoJ5B,CAAA"}
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,41 +27,42 @@ 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(`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 }));
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(`Plugin ${plugin.id} uses reserved namespace 'inlang'.`, {
35
- plugin: plugin.id,
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(`Plugin ${plugin.id} uses an invalid schema. Please check the documentation for the correct Plugin type.`, {
41
- plugin: plugin.id,
42
- cause: errors,
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(`Plugin ${plugin.id} defines the loadMessages function, but it was already defined by another plugin.`, { plugin: plugin.id }));
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(`Plugin ${plugin.id} defines the saveMessages function, but it was already defined by another plugin.`, { plugin: plugin.id }));
50
+ result.errors.push(new PluginSaveMessagesFunctionAlreadyDefinedError({ id: plugin.id }));
51
51
  }
52
52
  // --- ADD APP SPECIFIC API ---
53
53
  if (typeof plugin.addCustomApi === "function") {
54
54
  // TODO: why do we call this function 2 times (here for validation and later for retrieving the actual value)?
55
55
  const { data: customApi, error } = tryCatch(() => plugin.addCustomApi({
56
- settings: args.settings?.[plugin.id] ?? {},
56
+ settings: args.settings,
57
57
  }));
58
58
  if (error) {
59
- // @ts-ignore
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(`Plugin ${plugin.id} defines the addCustomApi function, but it does not return an object.`, { plugin: plugin.id, cause: error }));
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 --
@@ -74,20 +75,18 @@ export const resolvePlugins = async (args) => {
74
75
  if (typeof plugin.loadMessages === "function") {
75
76
  result.data.loadMessages = (_args) => plugin.loadMessages({
76
77
  ..._args,
77
- settings: args.settings?.[plugin.id] ?? {},
78
78
  nodeishFs: args.nodeishFs,
79
79
  });
80
80
  }
81
81
  if (typeof plugin.saveMessages === "function") {
82
82
  result.data.saveMessages = (_args) => plugin.saveMessages({
83
83
  ..._args,
84
- settings: args.settings?.[plugin.id] ?? {},
85
84
  nodeishFs: args.nodeishFs,
86
85
  });
87
86
  }
88
87
  if (typeof plugin.addCustomApi === "function") {
89
88
  const { data: customApi } = tryCatch(() => plugin.addCustomApi({
90
- settings: args.settings?.[plugin.id] ?? {},
89
+ settings: args.settings,
91
90
  }));
92
91
  if (customApi) {
93
92
  result.data.customApi = deepmerge(result.data.customApi, customApi);
@@ -97,7 +96,7 @@ export const resolvePlugins = async (args) => {
97
96
  // --- LOADMESSAGE / SAVEMESSAGE NOT DEFINED ---
98
97
  if (typeof result.data.loadMessages !== "function" ||
99
98
  typeof result.data.saveMessages !== "function") {
100
- result.errors.push(new PluginsDoNotProvideLoadOrSaveMessagesError("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.", { plugin: undefined }));
99
+ result.errors.push(new PluginsDoNotProvideLoadOrSaveMessagesError());
101
100
  }
102
101
  return result;
103
102
  };