@inlang/sdk 0.36.1 → 0.36.2

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 (51) hide show
  1. package/dist/adapter/solidAdapter.d.ts.map +1 -1
  2. package/dist/createMessagesQuery.js +1 -1
  3. package/dist/createNewProject.d.ts.map +1 -1
  4. package/dist/createNewProject.js +19 -2
  5. package/dist/createNodeishFsWithWatcher.d.ts +1 -1
  6. package/dist/createNodeishFsWithWatcher.d.ts.map +1 -1
  7. package/dist/createNodeishFsWithWatcher.js +54 -45
  8. package/dist/createNodeishFsWithWatcher.test.js +1 -1
  9. package/dist/lint/message/lintMessages.d.ts.map +1 -1
  10. package/dist/lint/message/lintSingleMessage.d.ts.map +1 -1
  11. package/dist/listProjects.d.ts.map +1 -1
  12. package/dist/loadProject.d.ts.map +1 -1
  13. package/dist/loadProject.js +56 -50
  14. package/dist/loadProject.test.js +8 -13
  15. package/dist/migrations/maybeAddModuleCache.d.ts.map +1 -1
  16. package/dist/migrations/maybeAddModuleCache.js +24 -6
  17. package/dist/parseConfig.d.ts.map +1 -1
  18. package/dist/reactivity/map.d.ts +1 -0
  19. package/dist/reactivity/map.d.ts.map +1 -1
  20. package/dist/reactivity/solid.d.ts +11 -11
  21. package/dist/reactivity/solid.d.ts.map +1 -1
  22. package/dist/resolve-modules/cache.d.ts.map +1 -1
  23. package/dist/resolve-modules/cache.js +24 -16
  24. package/dist/resolve-modules/message-lint-rules/resolveMessageLintRules.d.ts +1 -1
  25. package/dist/resolve-modules/message-lint-rules/resolveMessageLintRules.d.ts.map +1 -1
  26. package/dist/resolve-modules/message-lint-rules/resolveMessageLintRules.js +1 -0
  27. package/dist/storage/helper.d.ts +1 -19
  28. package/dist/storage/helper.d.ts.map +1 -1
  29. package/dist/telemetry/capture.d.ts.map +1 -1
  30. package/dist/telemetry/groupIdentify.d.ts.map +1 -1
  31. package/dist/test-utilities/createMessage.d.ts.map +1 -1
  32. package/dist/v2/helper.d.ts +1 -89
  33. package/dist/v2/helper.d.ts.map +1 -1
  34. package/dist/validateProjectPath.d.ts +2 -8
  35. package/dist/validateProjectPath.d.ts.map +1 -1
  36. package/dist/validateProjectPath.js +0 -21
  37. package/dist/validateProjectPath.test.js +2 -18
  38. package/package.json +6 -6
  39. package/src/createMessagesQuery.ts +1 -1
  40. package/src/createNewProject.ts +19 -2
  41. package/src/createNodeishFsWithWatcher.test.ts +1 -1
  42. package/src/createNodeishFsWithWatcher.ts +53 -42
  43. package/src/loadProject.test.ts +11 -18
  44. package/src/loadProject.ts +69 -58
  45. package/src/migrations/maybeAddModuleCache.ts +21 -6
  46. package/src/persistence/filelock/acquireFileLock.ts +2 -2
  47. package/src/persistence/filelock/releaseLock.ts +1 -1
  48. package/src/resolve-modules/cache.ts +30 -14
  49. package/src/resolve-modules/message-lint-rules/resolveMessageLintRules.ts +1 -0
  50. package/src/validateProjectPath.test.ts +1 -19
  51. package/src/validateProjectPath.ts +4 -24
@@ -1 +1 @@
1
- {"version":3,"file":"solidAdapter.d.ts","sourceRoot":"","sources":["../../src/adapter/solidAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAA;AAC1E,OAAO,EAAc,KAAK,IAAI,IAAI,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,eAAO,MAAM,YAAY,YACf,aAAa,OACjB;IACJ,IAAI,EAAE,gBAAgB,CAAA;CACtB,KACC,6BAoCF,CAAA;AAED,MAAM,MAAM,6BAA6B,GAAG;IAC3C,EAAE,EAAE,aAAa,CAAC,IAAI,CAAC,CAAA;IACvB,SAAS,EAAE,MAAM,UAAU,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,CAAA;IACvD,SAAS,EAAE;QACV,OAAO,EAAE,MAAM,UAAU,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,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,CAAC,CAAC,CAAA;SAC9D,CAAA;KACD,CAAA;CACD,CAAA"}
@@ -58,7 +58,7 @@ export function createMessagesQuery({ projectPath, nodeishFs, settings, resolved
58
58
  nodeishFs: nodeishFs,
59
59
  // this message is called whenever a file changes that was read earlier by this filesystem
60
60
  // - the plugin loads messages -> reads the file messages.json -> start watching on messages.json -> updateMessages
61
- updateMessages: () => {
61
+ onChange: () => {
62
62
  // reload
63
63
  loadMessagesViaPlugin(fsWithWatcher, messageLockDirPath, messageStates, index, defaultAliasIndex, delegate, _settings, // NOTE we bang here - we don't expect the settings to become null during the livetime of a project
64
64
  resolvedPluginApi)
@@ -1 +1 @@
1
- {"version":3,"file":"createNewProject.d.ts","sourceRoot":"","sources":["../src/createNewProject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAI1D;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE;IAC5C,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,UAAU,CAAA;IAChB,eAAe,EAAE,eAAe,CAAA;CAChC,GAAG,OAAO,CAAC,IAAI,CAAC,CAehB"}
1
+ {"version":3,"file":"createNewProject.d.ts","sourceRoot":"","sources":["../src/createNewProject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAI1D;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE;IAC5C,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,UAAU,CAAA;IAChB,eAAe,EAAE,eAAe,CAAA;CAChC,GAAG,OAAO,CAAC,IAAI,CAAC,CAehB"}
@@ -1,5 +1,5 @@
1
1
  import { ProjectSettings } from "@inlang/project-settings";
2
- import { assertValidProjectPath, pathExists } from "./validateProjectPath.js";
2
+ import { assertValidProjectPath } from "./validateProjectPath.js";
3
3
  import { defaultProjectSettings } from "./defaultProjectSettings.js";
4
4
  /**
5
5
  * Creates a new project in the given directory.
@@ -8,7 +8,7 @@ import { defaultProjectSettings } from "./defaultProjectSettings.js";
8
8
  export async function createNewProject(args) {
9
9
  assertValidProjectPath(args.projectPath);
10
10
  const nodeishFs = args.repo.nodeishFs;
11
- if (await pathExists(args.projectPath, nodeishFs)) {
11
+ if (await directoryExists(args.projectPath, nodeishFs)) {
12
12
  throw new Error(`projectPath already exists, received "${args.projectPath}"`);
13
13
  }
14
14
  const settingsText = JSON.stringify(args.projectSettings ?? defaultProjectSettings, undefined, 2);
@@ -19,3 +19,20 @@ export async function createNewProject(args) {
19
19
  nodeishFs.mkdir(`${args.projectPath}/cache/modules`, { recursive: true }),
20
20
  ]);
21
21
  }
22
+ /**
23
+ * Returns true if the path exists (file or directory), false otherwise.
24
+ */
25
+ async function directoryExists(filePath, nodeishFs) {
26
+ try {
27
+ const stat = await nodeishFs.stat(filePath);
28
+ return stat.isDirectory();
29
+ }
30
+ catch (error) {
31
+ if (error && "code" in error && error.code === "ENOENT") {
32
+ return false;
33
+ }
34
+ else {
35
+ throw new Error(`Failed to check if path exists: ${error}`, { cause: error });
36
+ }
37
+ }
38
+ }
@@ -7,7 +7,7 @@ import type { NodeishFilesystem } from "@lix-js/fs";
7
7
  */
8
8
  export declare const createNodeishFsWithWatcher: (args: {
9
9
  nodeishFs: NodeishFilesystem;
10
- updateMessages: () => void;
10
+ onChange: () => void;
11
11
  }) => NodeishFilesystem & {
12
12
  stopWatching: () => void;
13
13
  };
@@ -1 +1 @@
1
- {"version":3,"file":"createNodeishFsWithWatcher.d.ts","sourceRoot":"","sources":["../src/createNodeishFsWithWatcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnD;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,SAAU;IAChD,SAAS,EAAE,iBAAiB,CAAA;IAC5B,cAAc,EAAE,MAAM,IAAI,CAAA;CAC1B;kBACc,MAAM,IAAI;CA6DxB,CAAA"}
1
+ {"version":3,"file":"createNodeishFsWithWatcher.d.ts","sourceRoot":"","sources":["../src/createNodeishFsWithWatcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnD;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,SAAU;IAChD,SAAS,EAAE,iBAAiB,CAAA;IAC5B,QAAQ,EAAE,MAAM,IAAI,CAAA;CACpB,KAAG,iBAAiB,GAAG;IACvB,YAAY,EAAE,MAAM,IAAI,CAAA;CAwExB,CAAA"}
@@ -5,62 +5,71 @@
5
5
  * The paths are resolved from the `projectPath` argument.
6
6
  */
7
7
  export const createNodeishFsWithWatcher = (args) => {
8
- const pathList = [];
9
- let abortControllers = [];
8
+ const pathList = new Set();
9
+ const abortControllers = new Set();
10
10
  const stopWatching = () => {
11
11
  for (const ac of abortControllers) {
12
12
  ac.abort();
13
+ abortControllers.delete(ac); // release reference
13
14
  }
14
- // release references
15
- abortControllers = [];
16
15
  };
17
- const makeWatcher = (path) => {
18
- ;
19
- (async () => {
20
- try {
21
- const ac = new AbortController();
22
- abortControllers.push(ac);
23
- const watcher = args.nodeishFs.watch(path, {
24
- signal: ac.signal,
25
- persistent: false,
26
- });
27
- if (watcher) {
28
- //eslint-disable-next-line @typescript-eslint/no-unused-vars
29
- for await (const event of watcher) {
30
- args.updateMessages();
31
- }
16
+ const makeWatcher = async (path) => {
17
+ try {
18
+ const ac = new AbortController();
19
+ abortControllers.add(ac);
20
+ const watcher = args.nodeishFs.watch(path, {
21
+ signal: ac.signal,
22
+ recursive: true,
23
+ persistent: false,
24
+ });
25
+ if (watcher) {
26
+ //eslint-disable-next-line @typescript-eslint/no-unused-vars
27
+ for await (const event of watcher) {
28
+ // whenever the watcher changes we need to update the messages
29
+ args.onChange();
32
30
  }
33
31
  }
34
- catch (err) {
35
- if (err.name === "AbortError")
36
- return;
37
- // https://github.com/opral/monorepo/issues/1647
38
- // the file does not exist (yet)
39
- // this is not testable beacause the fs.watch api differs
40
- // from node and lix. lenghty
41
- else if (err.code === "ENOENT")
42
- return;
43
- throw err;
44
- }
45
- })();
46
- };
47
- const readFileAndExtractPath = (path, options) => {
48
- if (!pathList.includes(path)) {
49
- makeWatcher(path);
50
- pathList.push(path);
51
32
  }
52
- return args.nodeishFs.readFile(path, options);
33
+ catch (err) {
34
+ if (err.name === "AbortError")
35
+ return;
36
+ // https://github.com/opral/monorepo/issues/1647
37
+ // the file does not exist (yet)
38
+ // this is not testable beacause the fs.watch api differs
39
+ // from node and lix. lenghty
40
+ else if (err.code === "ENOENT")
41
+ return;
42
+ throw err;
43
+ }
44
+ };
45
+ /**
46
+ * Creates watchers on-the-fly for any file or directory that is not yet watched.
47
+ *
48
+ * We do this instead of recursively watching the entire project because fs.watch does not support
49
+ * recursive watching on linux in node 18. Once node 18 support is dropped this can be drastically simplified.
50
+ */
51
+ const watched = (fn) => {
52
+ return (path, ...rest) => {
53
+ if (!pathList.has(path)) {
54
+ makeWatcher(path);
55
+ pathList.add(path);
56
+ }
57
+ return fn(path, ...rest);
58
+ };
53
59
  };
54
60
  return {
61
+ ...args.nodeishFs,
62
+ /**
63
+ * Reads the file and automatically adds it to the list of watched files.
64
+ * Any changes to the file will trigger a message update.
65
+ */
55
66
  // @ts-expect-error
56
- readFile: (path, options) => readFileAndExtractPath(path, options),
57
- rm: args.nodeishFs.rm,
58
- readdir: args.nodeishFs.readdir,
59
- mkdir: args.nodeishFs.mkdir,
60
- rmdir: args.nodeishFs.rmdir,
61
- writeFile: args.nodeishFs.writeFile,
62
- watch: args.nodeishFs.watch,
63
- stat: args.nodeishFs.stat,
67
+ readFile: watched(args.nodeishFs.readFile),
68
+ /**
69
+ * Reads the directory and automatically adds it to the list of watched files.
70
+ * Any changes to the directory will trigger a message update.
71
+ */
72
+ readdir: watched(args.nodeishFs.readdir),
64
73
  stopWatching,
65
74
  };
66
75
  };
@@ -6,7 +6,7 @@ describe("watcher", () => {
6
6
  let counter = 0;
7
7
  const fs = createNodeishFsWithWatcher({
8
8
  nodeishFs: createNodeishMemoryFs(),
9
- updateMessages: () => {
9
+ onChange: () => {
10
10
  counter++;
11
11
  },
12
12
  });
@@ -1 +1 @@
1
- {"version":3,"file":"lintMessages.d.ts","sourceRoot":"","sources":["../../../src/lint/message/lintMessages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAE9C,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AACnF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE/D,eAAO,MAAM,YAAY,SAAgB;IACxC,QAAQ,EAAE,eAAe,GAAG,SAAS,KAAK,eAAe,EAAE,uBAAuB,CAAC,CAAC,CAAA;IACpF,KAAK,EAAE,eAAe,EAAE,CAAA;IACxB,QAAQ,EAAE,OAAO,EAAE,CAAA;CACnB,KAAG,QAAQ;IAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC;IAAC,MAAM,EAAE,4BAA4B,EAAE,CAAA;CAAE,CAchF,CAAA"}
1
+ {"version":3,"file":"lintMessages.d.ts","sourceRoot":"","sources":["../../../src/lint/message/lintMessages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAE9C,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AACnF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE/D,eAAO,MAAM,YAAY,SAAgB;IACxC,QAAQ,EAAE,eAAe,GAAG,QAAQ,CAAC,IAAI,CAAC,eAAe,EAAE,uBAAuB,CAAC,CAAC,CAAA;IACpF,KAAK,EAAE,eAAe,EAAE,CAAA;IACxB,QAAQ,EAAE,OAAO,EAAE,CAAA;CACnB,KAAG,OAAO,CAAC;IAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC;IAAC,MAAM,EAAE,4BAA4B,EAAE,CAAA;CAAE,CAchF,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"lintSingleMessage.d.ts","sourceRoot":"","sources":["../../../src/lint/message/lintSingleMessage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AACnF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE/D;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,SAAgB;IAC7C,QAAQ,EAAE,eAAe,GAAG,SAAS,KAAK,eAAe,EAAE,uBAAuB,CAAC,CAAC,CAAA;IACpF,KAAK,EAAE,eAAe,EAAE,CAAA;IACxB,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,OAAO,EAAE,OAAO,CAAA;CAChB;UAAmB,iBAAiB,EAAE;YAAU,4BAA4B,EAAE;EAyC9E,CAAA"}
1
+ {"version":3,"file":"lintSingleMessage.d.ts","sourceRoot":"","sources":["../../../src/lint/message/lintSingleMessage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AACnF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE/D;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,SAAgB;IAC7C,QAAQ,EAAE,eAAe,GAAG,QAAQ,CAAC,IAAI,CAAC,eAAe,EAAE,uBAAuB,CAAC,CAAC,CAAA;IACpF,KAAK,EAAE,eAAe,EAAE,CAAA;IACxB,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,OAAO,EAAE,OAAO,CAAA;CAChB,KAAG,OAAO,CAAC;IAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC;IAAC,MAAM,EAAE,4BAA4B,EAAE,CAAA;CAAE,CAyChF,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"listProjects.d.ts","sourceRoot":"","sources":["../src/listProjects.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAInD,eAAO,MAAM,YAAY,cACb,iBAAiB,QACtB,MAAM,KACV,QAAQ,MAAM;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC,CAwCxC,CAAA"}
1
+ {"version":3,"file":"listProjects.d.ts","sourceRoot":"","sources":["../src/listProjects.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAInD,eAAO,MAAM,YAAY,cACb,iBAAiB,QACtB,MAAM,KACV,OAAO,CAAC,KAAK,CAAC;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC,CAwCxC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"loadProject.d.ts","sourceRoot":"","sources":["../src/loadProject.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,aAAa,EAGb,YAAY,EAGZ,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,KAAK,cAAc,EAAkB,MAAM,4BAA4B,CAAA;AAsBhF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAchD;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE;IACvC,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,UAAU,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,cAAc,CAAA;CACxB,GAAG,OAAO,CAAC,aAAa,CAAC,CA+QzB;AA+GD,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,EAGZ,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,KAAK,cAAc,EAAkB,MAAM,4BAA4B,CAAA;AAuBhF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAchD;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE;IACvC,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,UAAU,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,cAAc,CAAA;CACxB,GAAG,OAAO,CAAC,aAAa,CAAC,CAoSzB;AAoGD,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAQtE"}
@@ -8,6 +8,7 @@ import { ProjectSettings } from "./versionedInterfaces.js";
8
8
  import { tryCatch } from "@inlang/result";
9
9
  import { migrateIfOutdated } from "@inlang/project-settings/migration";
10
10
  import { createNodeishFsWithAbsolutePaths } from "./createNodeishFsWithAbsolutePaths.js";
11
+ import { createNodeishFsWithWatcher } from "./createNodeishFsWithWatcher.js";
11
12
  import { normalizePath } from "@lix-js/fs";
12
13
  import { assertValidProjectPath } from "./validateProjectPath.js";
13
14
  // Migrations
@@ -53,36 +54,20 @@ export async function loadProject(args) {
53
54
  const { data: projectId } = await tryCatch(() => nodeishFs.readFile(args.projectPath + "/project_id", { encoding: "utf-8" }));
54
55
  const [initialized, markInitAsComplete, markInitAsFailed] = createAwaitable();
55
56
  const [loadedSettings, markSettingsAsLoaded, markSettingsAsFailed] = createAwaitable();
57
+ const [resolvedModules, setResolvedModules] = createSignal();
56
58
  // -- settings ------------------------------------------------------------
57
59
  const [settings, _setSettings] = createSignal();
58
60
  let v2Persistence = false;
59
61
  let locales = [];
60
- // This effect currently has no signals
61
- // TODO: replace createEffect with await loadSettings
62
- // https://github.com/opral/inlang-message-sdk/issues/77
63
- createEffect(() => {
64
- // TODO:
65
- // if (projectId) {
66
- // telemetryBrowser.group("project", projectId, {
67
- // name: projectId,
68
- // })
69
- // }
70
- loadSettings({ settingsFilePath: projectPath + "/settings.json", nodeishFs })
71
- .then((settings) => {
72
- setSettings(settings);
73
- markSettingsAsLoaded();
74
- })
75
- .catch((err) => {
76
- markInitAsFailed(err);
77
- markSettingsAsFailed(err);
78
- });
79
- });
80
- // TODO: create FS watcher and update settings on change
81
- // https://github.com/opral/inlang-message-sdk/issues/35
82
- const writeSettingsToDisk = skipFirst((settings) => _writeSettingsToDisk({ nodeishFs, settings, projectPath }));
83
- const setSettings = (settings) => {
62
+ // TODO:
63
+ // if (projectId) {
64
+ // telemetryBrowser.group("project", projectId, {
65
+ // name: projectId,
66
+ // })
67
+ // }
68
+ const setSettings = (newSettings) => {
84
69
  try {
85
- const validatedSettings = parseSettings(settings);
70
+ const validatedSettings = parseSettings(newSettings);
86
71
  v2Persistence = !!validatedSettings.experimental?.persistence;
87
72
  locales = validatedSettings.languageTags;
88
73
  batch(() => {
@@ -90,18 +75,43 @@ export async function loadProject(args) {
90
75
  setResolvedModules(undefined);
91
76
  _setSettings(validatedSettings);
92
77
  });
93
- writeSettingsToDisk(validatedSettings);
94
- return { data: undefined };
78
+ return { data: validatedSettings };
95
79
  }
96
80
  catch (error) {
97
81
  if (error instanceof ProjectSettingsInvalidError) {
98
82
  return { error };
99
83
  }
100
- throw new Error("Unhandled error in setSettings. This is an internal bug. Please file an issue.");
84
+ throw new Error("Unhandled error in setSettings. This is an internal bug. Please file an issue.", { cause: error });
101
85
  }
102
86
  };
87
+ const nodeishFsWithWatchersForSettings = createNodeishFsWithWatcher({
88
+ nodeishFs: nodeishFs,
89
+ onChange: async () => {
90
+ const readSettingsResult = await tryCatch(async () => await loadSettings({
91
+ settingsFilePath: projectPath + "/settings.json",
92
+ nodeishFs: nodeishFs,
93
+ }));
94
+ if (readSettingsResult.error)
95
+ return;
96
+ const newSettings = readSettingsResult.data;
97
+ if (JSON.stringify(newSettings) !== JSON.stringify(settings())) {
98
+ setSettings(newSettings);
99
+ }
100
+ },
101
+ });
102
+ const settingsResult = await tryCatch(async () => await loadSettings({
103
+ settingsFilePath: projectPath + "/settings.json",
104
+ nodeishFs: nodeishFsWithWatchersForSettings,
105
+ }));
106
+ if (settingsResult.error) {
107
+ markInitAsFailed(settingsResult.error);
108
+ markSettingsAsFailed(settingsResult.error);
109
+ }
110
+ else {
111
+ setSettings(settingsResult.data);
112
+ markSettingsAsLoaded();
113
+ }
103
114
  // -- resolvedModules -----------------------------------------------------------
104
- const [resolvedModules, setResolvedModules] = createSignal();
105
115
  createEffect(() => {
106
116
  const _settings = settings();
107
117
  if (!_settings)
@@ -240,7 +250,12 @@ export async function loadProject(args) {
240
250
  //...(lintErrors() ?? []),
241
251
  ]),
242
252
  settings: createSubscribable(() => settings()),
243
- setSettings,
253
+ setSettings: (newSettings) => {
254
+ const result = setSettings(newSettings);
255
+ if (!result.error)
256
+ writeSettingsToDisk({ nodeishFs, settings: result.data, projectPath });
257
+ return result.error ? result : { data: undefined };
258
+ },
244
259
  customApi: createSubscribable(() => resolvedModules()?.resolvedPluginApi.customApi || {}),
245
260
  query: {
246
261
  messages: messagesQuery,
@@ -267,6 +282,9 @@ const loadSettings = async (args) => {
267
282
  }
268
283
  return parseSettings(json.data);
269
284
  };
285
+ /**
286
+ * @throws If the settings are not valid
287
+ */
270
288
  const parseSettings = (settings) => {
271
289
  const withMigration = migrateIfOutdated(settings);
272
290
  if (settingsCompiler.Check(withMigration) === false) {
@@ -293,17 +311,16 @@ const parseSettings = (settings) => {
293
311
  }
294
312
  return withMigration;
295
313
  };
296
- const _writeSettingsToDisk = async (args) => {
297
- const { data: serializedSettings, error: serializeSettingsError } = tryCatch(() =>
314
+ const writeSettingsToDisk = async (args) => {
315
+ const serializeResult = tryCatch(() =>
298
316
  // TODO: this will probably not match the original formatting
299
317
  JSON.stringify(args.settings, undefined, 2));
300
- if (serializeSettingsError) {
301
- throw serializeSettingsError;
302
- }
303
- const { error: writeSettingsError } = await tryCatch(async () => args.nodeishFs.writeFile(args.projectPath + "/settings.json", serializedSettings));
304
- if (writeSettingsError) {
305
- throw writeSettingsError;
306
- }
318
+ if (serializeResult.error)
319
+ throw serializeResult.error;
320
+ const serializedSettings = serializeResult.data;
321
+ const writeResult = await tryCatch(async () => await args.nodeishFs.writeFile(args.projectPath + "/settings.json", serializedSettings));
322
+ if (writeResult.error)
323
+ throw writeResult.error;
307
324
  };
308
325
  // ------------------------------------------------------------------------------------------------
309
326
  const createAwaitable = () => {
@@ -315,17 +332,6 @@ const createAwaitable = () => {
315
332
  });
316
333
  return [promise, resolve, reject];
317
334
  };
318
- // Skip initial call, eg. to skip setup of a createEffect
319
- function skipFirst(func) {
320
- let initial = false;
321
- return function (...args) {
322
- if (initial) {
323
- // @ts-ignore
324
- return func.apply(this, args);
325
- }
326
- initial = true;
327
- };
328
- }
329
335
  export function createSubscribable(signal) {
330
336
  return Object.assign(signal, {
331
337
  subscribe: (callback) => {
@@ -219,22 +219,17 @@ describe("initialization", () => {
219
219
  expect(result.error).toBeUndefined();
220
220
  expect(result.data).toBeDefined();
221
221
  });
222
- // TODO: fix this test
223
- // https://github.com/opral/inlang-message-sdk/issues/76
224
- // it doesn't work because failure to open the settings file doesn't throw
225
- // errors are returned in project.errors()
226
- it("should resolve from a windows path", async () => {
222
+ it.skipIf(() => process.platform !== "win32")("should resolve from a windows path", async () => {
227
223
  const repo = await mockRepo();
228
224
  const fs = repo.nodeishFs;
229
225
  await fs.mkdir("C:\\Users\\user\\project.inlang", { recursive: true });
230
226
  await fs.writeFile("C:\\Users\\user\\project.inlang\\settings.json", JSON.stringify(settings));
231
- const result = await tryCatch(() => loadProject({
227
+ const project = await loadProject({
232
228
  projectPath: "C:\\Users\\user\\project.inlang",
233
229
  repo,
234
230
  _import,
235
- }));
236
- expect(result.error).toBeUndefined();
237
- expect(result.data).toBeDefined();
231
+ });
232
+ expect(project.errors()).toEqual([]);
238
233
  });
239
234
  describe("settings", () => {
240
235
  it("should return an error if settings file is not found", async () => {
@@ -287,9 +282,9 @@ describe("initialization", () => {
287
282
  it("should not re-write the settings to disk when initializing", async () => {
288
283
  const repo = await mockRepo();
289
284
  const fs = repo.nodeishFs;
290
- const settingsWithDeifferentFormatting = JSON.stringify(settings, undefined, 4);
285
+ const settingsWithDifferentFormatting = JSON.stringify(settings, undefined, 4);
291
286
  await fs.mkdir("/user/project.inlang", { recursive: true });
292
- await fs.writeFile("/user/project.inlang/settings.json", settingsWithDeifferentFormatting);
287
+ await fs.writeFile("/user/project.inlang/settings.json", settingsWithDifferentFormatting);
293
288
  const project = await loadProject({
294
289
  projectPath: "/user/project.inlang",
295
290
  repo,
@@ -298,14 +293,14 @@ describe("initialization", () => {
298
293
  const settingsOnDisk = await fs.readFile("/user/project.inlang/settings.json", {
299
294
  encoding: "utf-8",
300
295
  });
301
- expect(settingsOnDisk).toBe(settingsWithDeifferentFormatting);
296
+ expect(settingsOnDisk).toBe(settingsWithDifferentFormatting);
302
297
  project.setSettings(project.settings());
303
298
  // TODO: how can we await `setsettings` correctly
304
299
  await new Promise((resolve) => setTimeout(resolve, 0));
305
300
  const newsettingsOnDisk = await fs.readFile("/user/project.inlang/settings.json", {
306
301
  encoding: "utf-8",
307
302
  });
308
- expect(newsettingsOnDisk).not.toBe(settingsWithDeifferentFormatting);
303
+ expect(newsettingsOnDisk).not.toBe(settingsWithDifferentFormatting);
309
304
  });
310
305
  });
311
306
  describe("modules", () => {
@@ -1 +1 @@
1
- {"version":3,"file":"maybeAddModuleCache.d.ts","sourceRoot":"","sources":["../../src/migrations/maybeAddModuleCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAKhD,wBAAsB,mBAAmB,CAAC,IAAI,EAAE;IAC/C,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,CAAC,EAAE,UAAU,CAAA;CACjB,GAAG,OAAO,CAAC,IAAI,CAAC,CA0BhB"}
1
+ {"version":3,"file":"maybeAddModuleCache.d.ts","sourceRoot":"","sources":["../../src/migrations/maybeAddModuleCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAKhD,wBAAsB,mBAAmB,CAAC,IAAI,EAAE;IAC/C,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,CAAC,EAAE,UAAU,CAAA;CACjB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyChB"}
@@ -11,17 +11,35 @@ export async function maybeAddModuleCache(args) {
11
11
  const moduleCacheExists = await directoryExists(moduleCache, args.repo.nodeishFs);
12
12
  if (gitignoreExists) {
13
13
  // non-destructively add any missing ignores
14
- const gitignore = await args.repo.nodeishFs.readFile(gitignorePath, { encoding: "utf-8" });
15
- const missingIgnores = EXPECTED_IGNORES.filter((ignore) => !gitignore.includes(ignore));
16
- if (missingIgnores.length > 0) {
17
- await args.repo.nodeishFs.appendFile(gitignorePath, "\n" + missingIgnores.join("\n"));
14
+ try {
15
+ const gitignore = await args.repo.nodeishFs.readFile(gitignorePath, { encoding: "utf-8" });
16
+ const missingIgnores = EXPECTED_IGNORES.filter((ignore) => !gitignore.includes(ignore));
17
+ if (missingIgnores.length > 0) {
18
+ await args.repo.nodeishFs.appendFile(gitignorePath, "\n" + missingIgnores.join("\n"));
19
+ }
20
+ }
21
+ catch (error) {
22
+ throw new Error("[migrate:module-cache] Failed to update .gitignore", { cause: error });
18
23
  }
19
24
  }
20
25
  else {
21
- await args.repo.nodeishFs.writeFile(gitignorePath, EXPECTED_IGNORES.join("\n"));
26
+ try {
27
+ await args.repo.nodeishFs.writeFile(gitignorePath, EXPECTED_IGNORES.join("\n"));
28
+ }
29
+ catch (e) {
30
+ // @ts-ignore
31
+ if (e.code && e.code !== "EISDIR" && e.code !== "EEXIST") {
32
+ throw new Error("[migrate:module-cache] Failed to create .gitignore", { cause: e });
33
+ }
34
+ }
22
35
  }
23
36
  if (!moduleCacheExists) {
24
- await args.repo.nodeishFs.mkdir(moduleCache, { recursive: true });
37
+ try {
38
+ await args.repo.nodeishFs.mkdir(moduleCache, { recursive: true });
39
+ }
40
+ catch (e) {
41
+ throw new Error("[migrate:module-cache] Failed to create cache directory", { cause: e });
42
+ }
25
43
  }
26
44
  }
27
45
  async function fileExists(path, nodeishFs) {
@@ -1 +1 @@
1
- {"version":3,"file":"parseConfig.d.ts","sourceRoot":"","sources":["../src/parseConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAG5C,qBAAa,gBAAiB,SAAQ,KAAK;;gBAG9B,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;CAK3C;AAKD,eAAO,MAAM,aAAa,WACjB,eAAe,KACrB,OAAO,eAAe,EAAE,gBAAgB,CAe1C,CAAA"}
1
+ {"version":3,"file":"parseConfig.d.ts","sourceRoot":"","sources":["../src/parseConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAG5C,qBAAa,gBAAiB,SAAQ,KAAK;;gBAG9B,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;CAK3C;AAKD,eAAO,MAAM,aAAa,WACjB,eAAe,KACrB,MAAM,CAAC,eAAe,EAAE,gBAAgB,CAe1C,CAAA"}
@@ -23,6 +23,7 @@ declare var ReactiveMap: {
23
23
  [Symbol.iterator](): IterableIterator<[any, any]>;
24
24
  readonly [Symbol.toStringTag]: string;
25
25
  };
26
+ groupBy<K, T>(items: Iterable<T>, keySelector: (item: T, index: number) => K): Map<K, T[]>;
26
27
  readonly [Symbol.species]: MapConstructor;
27
28
  };
28
29
  declare var ReactiveWeakMap: {
@@ -1 +1 @@
1
- {"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/reactivity/map.ts"],"names":[],"mappings":"AAQA,QAAA,IAAI,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;CA+Ed,CAAA;AACD,QAAA,IAAI,eAAe;;;;;;;;;;;;;;;;;;CAmClB,CAAA;AACD,iBAAS,SAAS,CAAC,OAAO,KAAA,sBAKzB;AACD,iBAAS,aAAa,CAAC,OAAO,KAAA;;;;;;;;;;;;;;;;EAE7B;AAED,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,SAAS,EAAE,aAAa,EAAE,CAAA"}
1
+ {"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/reactivity/map.ts"],"names":[],"mappings":"AAQA,QAAA,IAAI,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+Ed,CAAA;AACD,QAAA,IAAI,eAAe;;;;;;;;;;;;;;;;;;CAmClB,CAAA;AACD,iBAAS,SAAS,CAAC,OAAO,KAAA,sBAKzB;AACD,iBAAS,aAAa,CAAC,OAAO,KAAA;;;;;;;;;;;;;;;;EAE7B;AAED,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,SAAS,EAAE,aAAa,EAAE,CAAA"}
@@ -1,14 +1,14 @@
1
1
  import { DEV } from "solid-js/dist/solid.js";
2
- declare const createSignal: typeof import("solid-js").createSignal;
3
- declare const createMemo: typeof import("solid-js").createMemo;
4
- declare const createRoot: typeof import("solid-js").createRoot;
5
- declare const createEffect: typeof import("solid-js").createEffect;
6
- declare const createResource: typeof import("solid-js").createResource;
7
- declare const observable: typeof import("solid-js").observable;
8
- declare const from: typeof import("solid-js").from;
9
- declare const batch: typeof import("solid-js").batch;
10
- declare const getListener: typeof import("solid-js").getListener;
11
- declare const onCleanup: typeof import("solid-js").onCleanup;
12
- declare const untrack: typeof import("solid-js").untrack;
2
+ declare const createSignal: typeof import("solid-js")["createSignal"];
3
+ declare const createMemo: typeof import("solid-js")["createMemo"];
4
+ declare const createRoot: typeof import("solid-js")["createRoot"];
5
+ declare const createEffect: typeof import("solid-js")["createEffect"];
6
+ declare const createResource: typeof import("solid-js")["createResource"];
7
+ declare const observable: typeof import("solid-js")["observable"];
8
+ declare const from: typeof import("solid-js")["from"];
9
+ declare const batch: typeof import("solid-js")["batch"];
10
+ declare const getListener: typeof import("solid-js")["getListener"];
11
+ declare const onCleanup: typeof import("solid-js")["onCleanup"];
12
+ declare const untrack: typeof import("solid-js")["untrack"];
13
13
  export { createSignal, createMemo, createRoot, createEffect, createResource, observable, from, batch, getListener, onCleanup, untrack, DEV, };
14
14
  //# sourceMappingURL=solid.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"solid.d.ts","sourceRoot":"","sources":["../../src/reactivity/solid.ts"],"names":[],"mappings":"AAAA,OAAO,EAYN,GAAG,EAEH,MAAM,wBAAwB,CAAA;AAE/B,QAAA,MAAM,YAAY,wCAA6D,CAAA;AAC/E,QAAA,MAAM,UAAU,sCAAyD,CAAA;AACzE,QAAA,MAAM,UAAU,sCAAyD,CAAA;AACzE,QAAA,MAAM,YAAY,wCAA6D,CAAA;AAC/E,QAAA,MAAM,cAAc,0CAAiE,CAAA;AACrF,QAAA,MAAM,UAAU,sCAAyD,CAAA;AACzE,QAAA,MAAM,IAAI,gCAA6C,CAAA;AACvD,QAAA,MAAM,KAAK,iCAA+C,CAAA;AAC1D,QAAA,MAAM,WAA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,UAAU,EACV,YAAY,EACZ,cAAc,EACd,UAAU,EACV,IAAI,EACJ,KAAK,EACL,WAAW,EACX,SAAS,EACT,OAAO,EACP,GAAG,GACH,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/resolve-modules/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AAkD7D;;GAEG;AACH,wBAAgB,SAAS,CACxB,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,EAC9C,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,IAAI,CAAC,uBAAuB,EAAE,UAAU,GAAG,WAAW,GAAG,OAAO,CAAC,GAC1E,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAelC"}
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/resolve-modules/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AAwD7D;;GAEG;AACH,wBAAgB,SAAS,CACxB,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,EAC9C,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,IAAI,CAAC,uBAAuB,EAAE,UAAU,GAAG,WAAW,GAAG,OAAO,CAAC,GAC1E,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAyBlC"}
@@ -1,6 +1,5 @@
1
1
  import { tryCatch } from "@inlang/result";
2
2
  function escape(url) {
3
- // collect the bytes of the UTF-8 representation
4
3
  const bytes = new TextEncoder().encode(url);
5
4
  // 64-bit FNV1a hash to make the file-names shorter
6
5
  // https://en.wikipedia.org/wiki/FNV-1a
@@ -15,16 +14,20 @@ async function readModuleFromCache(moduleURI, projectPath, readFile) {
15
14
  async function writeModuleToCache(moduleURI, moduleContent, projectPath, writeFile, mkdir) {
16
15
  const moduleHash = escape(moduleURI);
17
16
  const filePath = projectPath + `/cache/modules/${moduleHash}`;
18
- try {
19
- await writeFile(filePath, moduleContent);
20
- }
21
- catch (e) {
22
- // if ENONET -> likely means the parent directory does not exist yet
23
- if (!(e instanceof Error) || !e.message.includes("ENONET"))
24
- return;
25
- // create the parent directory & retry
26
- await mkdir(projectPath + `/cache/modules`, { recursive: true });
27
- await writeFile(filePath, moduleContent);
17
+ const writeFileResult = await tryCatch(() => writeFile(filePath, moduleContent));
18
+ if (writeFileResult.error) {
19
+ const dirPath = projectPath + `/cache/modules`;
20
+ const createDirResult = await tryCatch(() => mkdir(dirPath, { recursive: true }));
21
+ // @ts-ignore - If the directory exists we can ignore this error
22
+ if (createDirResult.error && createDirResult.error.code !== "EEXIST")
23
+ throw new Error("[sdk:module-cacke] failed to create cache-directory. Path: " + dirPath, {
24
+ cause: createDirResult.error,
25
+ });
26
+ const writeFileResult = await tryCatch(() => writeFile(filePath, moduleContent));
27
+ if (writeFileResult.error)
28
+ throw new Error("[sdk:module-cacke] failed to write cache-file. Path: " + filePath, {
29
+ cause: writeFileResult.error,
30
+ });
28
31
  }
29
32
  }
30
33
  /**
@@ -33,17 +36,22 @@ async function writeModuleToCache(moduleURI, moduleContent, projectPath, writeFi
33
36
  export function withCache(moduleLoader, projectPath, nodeishFs) {
34
37
  return async (uri) => {
35
38
  const cachePromise = readModuleFromCache(uri, projectPath, nodeishFs.readFile);
36
- const networkResult = await tryCatch(async () => await moduleLoader(uri));
37
- if (networkResult.error) {
39
+ const loaderResult = await tryCatch(async () => await moduleLoader(uri));
40
+ if (loaderResult.error) {
38
41
  const cacheResult = await cachePromise;
39
42
  if (!cacheResult.error)
40
43
  return cacheResult.data;
41
44
  else
42
- throw networkResult.error;
45
+ throw loaderResult.error;
43
46
  }
44
47
  else {
45
- const moduleAsText = networkResult.data;
46
- await writeModuleToCache(uri, moduleAsText, projectPath, nodeishFs.writeFile, nodeishFs.mkdir);
48
+ const moduleAsText = loaderResult.data;
49
+ try {
50
+ await writeModuleToCache(uri, moduleAsText, projectPath, nodeishFs.writeFile, nodeishFs.mkdir);
51
+ }
52
+ catch (error) {
53
+ // TODO trigger a warning
54
+ }
47
55
  return moduleAsText;
48
56
  }
49
57
  };