@inlang/sdk 0.13.0 → 0.14.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/createNodeishFsWithAbsolutePaths.d.ts +0 -1
- package/dist/createNodeishFsWithAbsolutePaths.d.ts.map +1 -1
- package/dist/createNodeishFsWithAbsolutePaths.js +3 -3
- package/dist/isAbsolutePath.d.ts +2 -0
- package/dist/isAbsolutePath.d.ts.map +1 -0
- package/dist/isAbsolutePath.js +4 -0
- package/dist/isAbsolutePath.test.d.ts +2 -0
- package/dist/isAbsolutePath.test.d.ts.map +1 -0
- package/dist/isAbsolutePath.test.js +20 -0
- package/dist/loadProject.d.ts.map +1 -1
- package/dist/loadProject.js +2 -1
- package/dist/loadProject.test.js +12 -0
- package/package.json +1 -1
- package/src/createNodeishFsWithAbsolutePaths.ts +3 -4
- package/src/isAbsolutePath.test.ts +23 -0
- package/src/isAbsolutePath.ts +5 -0
- package/src/loadProject.test.ts +17 -0
- package/src/loadProject.ts +2 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createNodeishFsWithAbsolutePaths.d.ts","sourceRoot":"","sources":["../src/createNodeishFsWithAbsolutePaths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"createNodeishFsWithAbsolutePaths.d.ts","sourceRoot":"","sources":["../src/createNodeishFsWithAbsolutePaths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AAI7D;;;;;GAKG;AACH,eAAO,MAAM,gCAAgC,SAAU;IACtD,gBAAgB,EAAE,MAAM,CAAA;IACxB,SAAS,EAAE,uBAAuB,CAAA;CAClC,KAAG,uBAyBH,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { normalizePath } from "@lix-js/fs";
|
|
2
|
-
|
|
2
|
+
import { isAbsolutePath } from "./isAbsolutePath.js";
|
|
3
3
|
/**
|
|
4
4
|
* Wraps the nodeish filesystem subset with a function that intercepts paths
|
|
5
5
|
* and prepends the base path.
|
|
@@ -8,11 +8,11 @@ export const isAbsolutePath = (path) => /^[/\\]/.test(path);
|
|
|
8
8
|
*/
|
|
9
9
|
export const createNodeishFsWithAbsolutePaths = (args) => {
|
|
10
10
|
if (!isAbsolutePath(args.settingsFilePath)) {
|
|
11
|
-
throw new Error(
|
|
11
|
+
throw new Error(`Expected an absolute path but received "${args.settingsFilePath}".`);
|
|
12
12
|
}
|
|
13
13
|
// get the base path of the settings file by
|
|
14
14
|
// removing the file name from the path
|
|
15
|
-
const basePath = args.settingsFilePath.split("/").slice(0, -1).join("/");
|
|
15
|
+
const basePath = normalizePath(args.settingsFilePath).split("/").slice(0, -1).join("/");
|
|
16
16
|
const makeAbsolute = (path) => {
|
|
17
17
|
if (isAbsolutePath(path)) {
|
|
18
18
|
return normalizePath(path);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isAbsolutePath.d.ts","sourceRoot":"","sources":["../src/isAbsolutePath.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,SAAU,MAAM,YAI1C,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isAbsolutePath.test.d.ts","sourceRoot":"","sources":["../src/isAbsolutePath.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { assert, describe, it } from "vitest";
|
|
2
|
+
import { isAbsolutePath } from "./isAbsolutePath.js";
|
|
3
|
+
describe("isAbsolutePath", () => {
|
|
4
|
+
it("should correctly identify Unix absolute paths", () => {
|
|
5
|
+
assert.isTrue(isAbsolutePath("/home/user/documents/file.txt"));
|
|
6
|
+
assert.isTrue(isAbsolutePath("/usr/local/bin/script.sh"));
|
|
7
|
+
assert.isFalse(isAbsolutePath("relative/path/to/file.txt"));
|
|
8
|
+
});
|
|
9
|
+
it("should correctly identify Windows absolute paths", () => {
|
|
10
|
+
assert.isTrue(isAbsolutePath("C:\\Users\\User\\Documents\\File.txt"));
|
|
11
|
+
assert.isTrue(isAbsolutePath("C:/Users/user/project/project.inlang.json"));
|
|
12
|
+
assert.isFalse(isAbsolutePath("Projects\\Project1\\source\\file.txt"));
|
|
13
|
+
});
|
|
14
|
+
it("should handle edge cases", () => {
|
|
15
|
+
assert.isFalse(isAbsolutePath("")); // Empty path should return false
|
|
16
|
+
assert.isFalse(isAbsolutePath("relative/path/../file.txt")); // Relative path with ".." should return false
|
|
17
|
+
assert.isFalse(isAbsolutePath("../relative/path/to/file.txt"));
|
|
18
|
+
assert.isFalse(isAbsolutePath("./relative/path/to/file.txt"));
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -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;AAchF,OAAO,EAA4B,KAAK,uBAAuB,EAAE,MAAM,0BAA0B,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;AAchF,OAAO,EAA4B,KAAK,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AASjG;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW;sBACL,MAAM;eACb,uBAAuB;;qBAElB,MAAM,SAAS,OAAO,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI;MAC5D,QAAQ,aAAa,CAuMxB,CAAA;AAuHD,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAQtE"}
|
package/dist/loadProject.js
CHANGED
|
@@ -8,8 +8,9 @@ import { createMessageLintReportsQuery } from "./createMessageLintReportsQuery.j
|
|
|
8
8
|
import { ProjectSettings, Message } from "./versionedInterfaces.js";
|
|
9
9
|
import { tryCatch } from "@inlang/result";
|
|
10
10
|
import { migrateIfOutdated } from "@inlang/project-settings/migration";
|
|
11
|
-
import { createNodeishFsWithAbsolutePaths
|
|
11
|
+
import { createNodeishFsWithAbsolutePaths } from "./createNodeishFsWithAbsolutePaths.js";
|
|
12
12
|
import { normalizePath } from "@lix-js/fs";
|
|
13
|
+
import { isAbsolutePath } from "./isAbsolutePath.js";
|
|
13
14
|
const settingsCompiler = TypeCompiler.Compile(ProjectSettings);
|
|
14
15
|
/**
|
|
15
16
|
* Creates an inlang instance.
|
package/dist/loadProject.test.js
CHANGED
|
@@ -91,6 +91,18 @@ describe("initialization", () => {
|
|
|
91
91
|
expect(result.error).toBeInstanceOf(LoadProjectInvalidArgument);
|
|
92
92
|
expect(result.data).toBeUndefined();
|
|
93
93
|
});
|
|
94
|
+
it("should resolve from a windows path", async () => {
|
|
95
|
+
const fs = createNodeishMemoryFs();
|
|
96
|
+
fs.mkdir("C:\\Users\\user\\project", { recursive: true });
|
|
97
|
+
fs.writeFile("C:\\Users\\user\\project\\project.inlang.json", JSON.stringify(settings));
|
|
98
|
+
const result = await tryCatch(() => loadProject({
|
|
99
|
+
settingsFilePath: "C:\\Users\\user\\project\\project.inlang.json",
|
|
100
|
+
nodeishFs: fs,
|
|
101
|
+
_import,
|
|
102
|
+
}));
|
|
103
|
+
expect(result.error).toBeUndefined();
|
|
104
|
+
expect(result.data).toBeDefined();
|
|
105
|
+
});
|
|
94
106
|
describe("settings", () => {
|
|
95
107
|
it("should return an error if settings file is not found", async () => {
|
|
96
108
|
const fs = createNodeishMemoryFs();
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { NodeishFilesystemSubset } from "@inlang/plugin"
|
|
2
2
|
import { normalizePath } from "@lix-js/fs"
|
|
3
|
-
|
|
4
|
-
export const isAbsolutePath = (path: string) => /^[/\\]/.test(path)
|
|
3
|
+
import { isAbsolutePath } from "./isAbsolutePath.js"
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Wraps the nodeish filesystem subset with a function that intercepts paths
|
|
@@ -14,12 +13,12 @@ export const createNodeishFsWithAbsolutePaths = (args: {
|
|
|
14
13
|
nodeishFs: NodeishFilesystemSubset
|
|
15
14
|
}): NodeishFilesystemSubset => {
|
|
16
15
|
if (!isAbsolutePath(args.settingsFilePath)) {
|
|
17
|
-
throw new Error(
|
|
16
|
+
throw new Error(`Expected an absolute path but received "${args.settingsFilePath}".`)
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
// get the base path of the settings file by
|
|
21
20
|
// removing the file name from the path
|
|
22
|
-
const basePath = args.settingsFilePath.split("/").slice(0, -1).join("/")
|
|
21
|
+
const basePath = normalizePath(args.settingsFilePath).split("/").slice(0, -1).join("/")
|
|
23
22
|
|
|
24
23
|
const makeAbsolute = (path: string) => {
|
|
25
24
|
if (isAbsolutePath(path)) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { assert, describe, it } from "vitest"
|
|
2
|
+
import { isAbsolutePath } from "./isAbsolutePath.js"
|
|
3
|
+
|
|
4
|
+
describe("isAbsolutePath", () => {
|
|
5
|
+
it("should correctly identify Unix absolute paths", () => {
|
|
6
|
+
assert.isTrue(isAbsolutePath("/home/user/documents/file.txt"))
|
|
7
|
+
assert.isTrue(isAbsolutePath("/usr/local/bin/script.sh"))
|
|
8
|
+
assert.isFalse(isAbsolutePath("relative/path/to/file.txt"))
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it("should correctly identify Windows absolute paths", () => {
|
|
12
|
+
assert.isTrue(isAbsolutePath("C:\\Users\\User\\Documents\\File.txt"))
|
|
13
|
+
assert.isTrue(isAbsolutePath("C:/Users/user/project/project.inlang.json"))
|
|
14
|
+
assert.isFalse(isAbsolutePath("Projects\\Project1\\source\\file.txt"))
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it("should handle edge cases", () => {
|
|
18
|
+
assert.isFalse(isAbsolutePath("")) // Empty path should return false
|
|
19
|
+
assert.isFalse(isAbsolutePath("relative/path/../file.txt")) // Relative path with ".." should return false
|
|
20
|
+
assert.isFalse(isAbsolutePath("../relative/path/to/file.txt"))
|
|
21
|
+
assert.isFalse(isAbsolutePath("./relative/path/to/file.txt"))
|
|
22
|
+
})
|
|
23
|
+
})
|
package/src/loadProject.test.ts
CHANGED
|
@@ -113,6 +113,23 @@ describe("initialization", () => {
|
|
|
113
113
|
expect(result.data).toBeUndefined()
|
|
114
114
|
})
|
|
115
115
|
|
|
116
|
+
it("should resolve from a windows path", async () => {
|
|
117
|
+
const fs = createNodeishMemoryFs()
|
|
118
|
+
fs.mkdir("C:\\Users\\user\\project", { recursive: true })
|
|
119
|
+
fs.writeFile("C:\\Users\\user\\project\\project.inlang.json", JSON.stringify(settings))
|
|
120
|
+
|
|
121
|
+
const result = await tryCatch(() =>
|
|
122
|
+
loadProject({
|
|
123
|
+
settingsFilePath: "C:\\Users\\user\\project\\project.inlang.json",
|
|
124
|
+
nodeishFs: fs,
|
|
125
|
+
_import,
|
|
126
|
+
})
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
expect(result.error).toBeUndefined()
|
|
130
|
+
expect(result.data).toBeDefined()
|
|
131
|
+
})
|
|
132
|
+
|
|
116
133
|
describe("settings", () => {
|
|
117
134
|
it("should return an error if settings file is not found", async () => {
|
|
118
135
|
const fs = createNodeishMemoryFs()
|
package/src/loadProject.ts
CHANGED
|
@@ -22,11 +22,9 @@ import { createMessageLintReportsQuery } from "./createMessageLintReportsQuery.j
|
|
|
22
22
|
import { ProjectSettings, Message, type NodeishFilesystemSubset } from "./versionedInterfaces.js"
|
|
23
23
|
import { tryCatch, type Result } from "@inlang/result"
|
|
24
24
|
import { migrateIfOutdated } from "@inlang/project-settings/migration"
|
|
25
|
-
import {
|
|
26
|
-
createNodeishFsWithAbsolutePaths,
|
|
27
|
-
isAbsolutePath,
|
|
28
|
-
} from "./createNodeishFsWithAbsolutePaths.js"
|
|
25
|
+
import { createNodeishFsWithAbsolutePaths } from "./createNodeishFsWithAbsolutePaths.js"
|
|
29
26
|
import { normalizePath } from "@lix-js/fs"
|
|
27
|
+
import { isAbsolutePath } from "./isAbsolutePath.js"
|
|
30
28
|
|
|
31
29
|
const settingsCompiler = TypeCompiler.Compile(ProjectSettings)
|
|
32
30
|
|