@inlang/sdk 0.10.0 → 0.11.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.
@@ -0,0 +1,30 @@
1
+ import type { NodeishFilesystemSubset } from "@inlang/plugin"
2
+ import { normalizePath } from "@lix-js/fs"
3
+
4
+ export const createNodeishFsWithAbsolutePaths = (args: {
5
+ basePath: string
6
+ nodeishFs: NodeishFilesystemSubset
7
+ }): NodeishFilesystemSubset => {
8
+ const isAbsolutePath = (path: string) => /^[/\\]/.test(path)
9
+
10
+ if (!isAbsolutePath(args.basePath)) {
11
+ throw new Error("The argument `settingsFilePath` of `loadProject()` must be an absolute path.")
12
+ }
13
+
14
+ const intercept = (path: string) => {
15
+ if (isAbsolutePath(path)) {
16
+ return path
17
+ }
18
+
19
+ return normalizePath(args.basePath + "/" + path)
20
+ }
21
+
22
+ return {
23
+ // @ts-expect-error
24
+ readFile: (path: string, options: { encoding: "utf-8" | "binary" }) =>
25
+ args.nodeishFs.readFile(intercept(path), options),
26
+ readdir: (path: string) => args.nodeishFs.readdir(intercept(path)),
27
+ mkdir: (path: string) => args.nodeishFs.mkdir(intercept(path)),
28
+ writeFile: (path: string, data: string) => args.nodeishFs.writeFile(intercept(path), data),
29
+ }
30
+ }
@@ -1,5 +1,4 @@
1
1
  import dedent from "dedent"
2
- import { normalizePath } from "@lix-js/fs"
3
2
  import type { NodeishFilesystemSubset } from "@inlang/plugin"
4
3
  import { ModuleImportError } from "./errors.js"
5
4
 
@@ -42,7 +41,9 @@ async function $import(
42
41
  if (uri.startsWith("http")) {
43
42
  moduleAsText = await (await fetch(uri)).text()
44
43
  } else {
45
- moduleAsText = await options.readFile(normalizePath(uri), { encoding: "utf-8" })
44
+ moduleAsText = await options.readFile(uri, {
45
+ encoding: "utf-8",
46
+ })
46
47
  }
47
48
 
48
49
  const moduleWithMimeType = "data:application/javascript," + encodeURIComponent(moduleAsText)
@@ -1,4 +1,4 @@
1
- import type { NodeishFilesystem as LisaNodeishFilesystem } from "@lix-js/fs"
1
+ import type { NodeishFilesystem } from "@lix-js/fs"
2
2
  import type {
3
3
  PluginReturnedInvalidCustomApiError,
4
4
  PluginLoadMessagesFunctionAlreadyDefinedError,
@@ -18,7 +18,7 @@ import type { ProjectSettings } from "@inlang/project-settings"
18
18
  * - only uses minimally required functions to decrease the API footprint on the ecosystem.
19
19
  */
20
20
  export type NodeishFilesystemSubset = Pick<
21
- LisaNodeishFilesystem,
21
+ NodeishFilesystem,
22
22
  "readFile" | "readdir" | "mkdir" | "writeFile"
23
23
  >
24
24