@inlang/sdk 0.18.0 → 0.19.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 (31) hide show
  1. package/dist/adapter/solidAdapter.test.js +16 -15
  2. package/dist/createNodeishFsWithAbsolutePaths.d.ts +2 -2
  3. package/dist/createNodeishFsWithAbsolutePaths.d.ts.map +1 -1
  4. package/dist/createNodeishFsWithAbsolutePaths.js +4 -4
  5. package/dist/createNodeishFsWithAbsolutePaths.test.js +4 -4
  6. package/dist/createNodeishFsWithWatcher.d.ts +1 -1
  7. package/dist/createNodeishFsWithWatcher.d.ts.map +1 -1
  8. package/dist/createNodeishFsWithWatcher.js +6 -4
  9. package/dist/isAbsolutePath.test.js +1 -1
  10. package/dist/loadProject.d.ts +4 -4
  11. package/dist/loadProject.d.ts.map +1 -1
  12. package/dist/loadProject.js +23 -17
  13. package/dist/loadProject.test.js +108 -75
  14. package/dist/migrations/migrateToDirectory.d.ts +10 -0
  15. package/dist/migrations/migrateToDirectory.d.ts.map +1 -0
  16. package/dist/migrations/migrateToDirectory.js +46 -0
  17. package/dist/migrations/migrateToDirectory.test.d.ts +2 -0
  18. package/dist/migrations/migrateToDirectory.test.d.ts.map +1 -0
  19. package/dist/migrations/migrateToDirectory.test.js +48 -0
  20. package/dist/resolve-modules/validateModuleSettings.test.js +1 -1
  21. package/package.json +56 -56
  22. package/src/adapter/solidAdapter.test.ts +16 -15
  23. package/src/createNodeishFsWithAbsolutePaths.test.ts +4 -4
  24. package/src/createNodeishFsWithAbsolutePaths.ts +5 -5
  25. package/src/createNodeishFsWithWatcher.ts +6 -4
  26. package/src/isAbsolutePath.test.ts +1 -1
  27. package/src/loadProject.test.ts +116 -75
  28. package/src/loadProject.ts +36 -22
  29. package/src/migrations/migrateToDirectory.test.ts +54 -0
  30. package/src/migrations/migrateToDirectory.ts +59 -0
  31. package/src/resolve-modules/validateModuleSettings.test.ts +1 -1
package/package.json CHANGED
@@ -1,57 +1,57 @@
1
1
  {
2
- "name": "@inlang/sdk",
3
- "type": "module",
4
- "version": "0.18.0",
5
- "license": "Apache-2.0",
6
- "publishConfig": {
7
- "access": "public"
8
- },
9
- "exports": {
10
- ".": "./dist/index.js",
11
- "./test-utilities": "./dist/test-utilities/index.js",
12
- "./lint": "./dist/lint/index.js",
13
- "./messages": "./dist/messages/index.js"
14
- },
15
- "files": [
16
- "./dist",
17
- "./src"
18
- ],
19
- "scripts": {
20
- "build": "tsc --build",
21
- "dev": "tsc --watch",
22
- "test": "tsc --noEmit && vitest run --passWithNoTests --coverage",
23
- "lint": "eslint ./src --fix",
24
- "format": "prettier ./src --write",
25
- "clean": "rm -rf ./dist ./node_modules"
26
- },
27
- "engines": {
28
- "node": ">=18.0.0"
29
- },
30
- "dependencies": {
31
- "@inlang/json-types": "*",
32
- "@inlang/translatable": "*",
33
- "@inlang/message-lint-rule": "*",
34
- "@inlang/module": "*",
35
- "@inlang/language-tag": "*",
36
- "@inlang/message": "*",
37
- "@inlang/plugin": "*",
38
- "@inlang/project-settings": "*",
39
- "@inlang/result": "*",
40
- "@lix-js/fs": "*",
41
- "@sinclair/typebox": "^0.31.17",
42
- "deepmerge-ts": "^5.1.0",
43
- "solid-js": "1.6.12",
44
- "throttle-debounce": "5.0.0",
45
- "dedent": "1.5.1"
46
- },
47
- "devDependencies": {
48
- "@lix-js/fs": "*",
49
- "@types/throttle-debounce": "5.0.0",
50
- "@vitest/coverage-v8": "^0.33.0",
51
- "jsdom": "22.1.0",
52
- "patch-package": "6.5.1",
53
- "tsd": "^0.25.0",
54
- "typescript": "5.2.2",
55
- "vitest": "^0.33.0"
56
- }
57
- }
2
+ "name": "@inlang/sdk",
3
+ "type": "module",
4
+ "version": "0.19.0",
5
+ "license": "Apache-2.0",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "exports": {
10
+ ".": "./dist/index.js",
11
+ "./test-utilities": "./dist/test-utilities/index.js",
12
+ "./lint": "./dist/lint/index.js",
13
+ "./messages": "./dist/messages/index.js"
14
+ },
15
+ "files": [
16
+ "./dist",
17
+ "./src"
18
+ ],
19
+ "engines": {
20
+ "node": ">=18.0.0"
21
+ },
22
+ "dependencies": {
23
+ "@sinclair/typebox": "^0.31.17",
24
+ "deepmerge-ts": "^5.1.0",
25
+ "solid-js": "1.6.12",
26
+ "throttle-debounce": "5.0.0",
27
+ "dedent": "1.5.1",
28
+ "@inlang/json-types": "1.1.0",
29
+ "@inlang/message-lint-rule": "1.4.0",
30
+ "@inlang/translatable": "1.2.0",
31
+ "@inlang/module": "1.2.0",
32
+ "@inlang/language-tag": "1.2.0",
33
+ "@inlang/message": "2.0.0",
34
+ "@inlang/plugin": "2.4.0",
35
+ "@inlang/result": "1.1.0",
36
+ "@inlang/project-settings": "2.2.0",
37
+ "@lix-js/fs": "0.4.0"
38
+ },
39
+ "devDependencies": {
40
+ "@types/throttle-debounce": "5.0.0",
41
+ "@vitest/coverage-v8": "^0.33.0",
42
+ "jsdom": "22.1.0",
43
+ "patch-package": "6.5.1",
44
+ "tsd": "^0.25.0",
45
+ "typescript": "5.2.2",
46
+ "vitest": "^0.33.0",
47
+ "@lix-js/fs": "0.4.0"
48
+ },
49
+ "scripts": {
50
+ "build": "tsc --build",
51
+ "dev": "tsc --watch",
52
+ "test": "tsc --noEmit && vitest run --passWithNoTests --coverage",
53
+ "lint": "eslint ./src --fix",
54
+ "format": "prettier ./src --write",
55
+ "clean": "rm -rf ./dist ./node_modules"
56
+ }
57
+ }
@@ -90,11 +90,11 @@ const $import: ImportFunction = async (name) => ({
90
90
  describe("config", () => {
91
91
  it("should react to changes in config", async () => {
92
92
  const fs = createNodeishMemoryFs()
93
- await fs.mkdir("/user/project", { recursive: true })
94
- await fs.writeFile("/user/project/project.inlang.json", JSON.stringify(config))
93
+ await fs.mkdir("/user/project.inlang", { recursive: true })
94
+ await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(config))
95
95
  const project = solidAdapter(
96
96
  await loadProject({
97
- settingsFilePath: "/user/project/project.inlang.json",
97
+ projectPath: "/user/project.inlang",
98
98
  nodeishFs: fs,
99
99
  _import: $import,
100
100
  }),
@@ -123,11 +123,11 @@ describe("config", () => {
123
123
  describe("installed", () => {
124
124
  it("react to changes that are unrelated to installed items", async () => {
125
125
  const fs = createNodeishMemoryFs()
126
- await fs.mkdir("/user/project", { recursive: true })
127
- await fs.writeFile("/user/project/project.inlang.json", JSON.stringify(config))
126
+ await fs.mkdir("/user/project.inlang", { recursive: true })
127
+ await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(config))
128
128
  const project = solidAdapter(
129
129
  await loadProject({
130
- settingsFilePath: "/user/project/project.inlang.json",
130
+ projectPath: "/user/project.inlang",
131
131
  nodeishFs: fs,
132
132
  _import: $import,
133
133
  }),
@@ -188,11 +188,11 @@ describe("messages", () => {
188
188
 
189
189
  const mockImport: ImportFunction = async () => ({ default: mockPlugin })
190
190
 
191
- await fs.mkdir("/user/project", { recursive: true })
192
- await fs.writeFile("/user/project/project.inlang.json", JSON.stringify(mockConfig))
191
+ await fs.mkdir("/user/project.inlang.inlang", { recursive: true })
192
+ await fs.writeFile("/user/project.inlang.inlang/settings.json", JSON.stringify(mockConfig))
193
193
  const project = solidAdapter(
194
194
  await loadProject({
195
- settingsFilePath: "/user/project/project.inlang.json",
195
+ projectPath: "/user/project.inlang.inlang",
196
196
  nodeishFs: fs,
197
197
  _import: mockImport,
198
198
  }),
@@ -218,11 +218,11 @@ describe("messages", () => {
218
218
 
219
219
  it("should react to changes in messages", async () => {
220
220
  const fs = createNodeishMemoryFs()
221
- await fs.mkdir("/user/project", { recursive: true })
222
- await fs.writeFile("/user/project/project.inlang.json", JSON.stringify(config))
221
+ await fs.mkdir("/user/project.inlang.inlang", { recursive: true })
222
+ await fs.writeFile("/user/project.inlang.inlang/settings.json", JSON.stringify(config))
223
223
  const project = solidAdapter(
224
224
  await loadProject({
225
- settingsFilePath: "/user/project/project.inlang.json",
225
+ projectPath: "/user/project.inlang.inlang",
226
226
  nodeishFs: fs,
227
227
  _import: $import,
228
228
  }),
@@ -280,10 +280,11 @@ describe("lint", () => {
280
280
  it.todo("should react to changes in config", async () => {
281
281
  await createRoot(async () => {
282
282
  const fs = createNodeishMemoryFs()
283
- await fs.writeFile("./project.config.json", JSON.stringify(config))
283
+ await fs.mkdir("./project.inlang", { recursive: true })
284
+ await fs.writeFile("./project.inlang/settings.json", JSON.stringify(config))
284
285
  const project = solidAdapter(
285
286
  await loadProject({
286
- settingsFilePath: "./project.config.json",
287
+ projectPath: "./project.inlang",
287
288
  nodeishFs: fs,
288
289
  _import: $import,
289
290
  }),
@@ -321,7 +322,7 @@ describe("lint", () => {
321
322
  await fs.writeFile("./project.config.json", JSON.stringify(config))
322
323
  const project = solidAdapter(
323
324
  await loadProject({
324
- settingsFilePath: "./project.config.json",
325
+ projectPath: "./project.config.json",
325
326
  nodeishFs: fs,
326
327
  _import: $import,
327
328
  }),
@@ -2,16 +2,16 @@ import { it, expect, vi } from "vitest"
2
2
  import { createNodeishFsWithAbsolutePaths } from "./createNodeishFsWithAbsolutePaths.js"
3
3
  import type { NodeishFilesystemSubset } from "./versionedInterfaces.js"
4
4
 
5
- it("throws an error if settingsFilePath is not an absolute path", () => {
5
+ it("throws an error if projectPath is not an absolute path", () => {
6
6
  const relativePath = "relative/path"
7
7
 
8
8
  expect(() =>
9
- createNodeishFsWithAbsolutePaths({ settingsFilePath: relativePath, nodeishFs: {} as any })
9
+ createNodeishFsWithAbsolutePaths({ projectPath: relativePath, nodeishFs: {} as any })
10
10
  ).toThrow()
11
11
  })
12
12
 
13
13
  it("intercepts paths correctly for readFile", async () => {
14
- const settingsFilePath = `/Users/samuel/Documents/paraglide/example/project.inlang.json`
14
+ const projectPath = `/Users/samuel/Documents/paraglide/example/project.inlang`
15
15
 
16
16
  const filePaths = [
17
17
  ["file.txt", `/Users/samuel/Documents/paraglide/example/file.txt`],
@@ -32,7 +32,7 @@ it("intercepts paths correctly for readFile", async () => {
32
32
  } satisfies Record<keyof NodeishFilesystemSubset, any>
33
33
 
34
34
  const interceptedFs = createNodeishFsWithAbsolutePaths({
35
- settingsFilePath,
35
+ projectPath,
36
36
  nodeishFs: mockNodeishFs,
37
37
  })
38
38
 
@@ -6,19 +6,19 @@ import { isAbsolutePath } from "./isAbsolutePath.js"
6
6
  * Wraps the nodeish filesystem subset with a function that intercepts paths
7
7
  * and prepends the base path.
8
8
  *
9
- * The paths are resolved from the `settingsFilePath` argument.
9
+ * The paths are resolved from the `projectPath` argument.
10
10
  */
11
11
  export const createNodeishFsWithAbsolutePaths = (args: {
12
- settingsFilePath: string
12
+ projectPath: string
13
13
  nodeishFs: NodeishFilesystemSubset
14
14
  }): NodeishFilesystemSubset => {
15
- if (!isAbsolutePath(args.settingsFilePath)) {
16
- throw new Error(`Expected an absolute path but received "${args.settingsFilePath}".`)
15
+ if (!isAbsolutePath(args.projectPath)) {
16
+ throw new Error(`Expected an absolute path but received "${args.projectPath}".`)
17
17
  }
18
18
 
19
19
  // get the base path of the settings file by
20
20
  // removing the file name from the path
21
- const basePath = normalizePath(args.settingsFilePath).split("/").slice(0, -1).join("/")
21
+ const basePath = normalizePath(args.projectPath).split("/").slice(0, -1).join("/")
22
22
 
23
23
  const makeAbsolute = (path: string) => {
24
24
  if (isAbsolutePath(path)) {
@@ -4,7 +4,7 @@ import type { NodeishFilesystemSubset } from "@inlang/plugin"
4
4
  * Wraps the nodeish filesystem subset with a function that intercepts paths
5
5
  * and prepends the base path.
6
6
  *
7
- * The paths are resolved from the `settingsFilePath` argument.
7
+ * The paths are resolved from the `projectPath` argument.
8
8
  */
9
9
  export const createNodeishFsWithWatcher = (args: {
10
10
  nodeishFs: NodeishFilesystemSubset
@@ -20,9 +20,11 @@ export const createNodeishFsWithWatcher = (args: {
20
20
  signal: abortController.signal,
21
21
  persistent: false,
22
22
  })
23
- //eslint-disable-next-line @typescript-eslint/no-unused-vars
24
- for await (const event of watcher) {
25
- args.updateMessages()
23
+ if (watcher) {
24
+ //eslint-disable-next-line @typescript-eslint/no-unused-vars
25
+ for await (const event of watcher) {
26
+ args.updateMessages()
27
+ }
26
28
  }
27
29
  } catch (err: any) {
28
30
  if (err.name === "AbortError") return
@@ -10,7 +10,7 @@ describe("isAbsolutePath", () => {
10
10
 
11
11
  it("should correctly identify Windows absolute paths", () => {
12
12
  assert.isTrue(isAbsolutePath("C:\\Users\\User\\Documents\\File.txt"))
13
- assert.isTrue(isAbsolutePath("C:/Users/user/project/project.inlang.json"))
13
+ assert.isTrue(isAbsolutePath("C:/Users/user/project.inlang/settings.json"))
14
14
  assert.isFalse(isAbsolutePath("Projects\\Project1\\source\\file.txt"))
15
15
  })
16
16