@inlang/sdk 0.25.0 → 0.26.1
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/adapter/solidAdapter.test.js +13 -14
- package/dist/loadProject.d.ts +1 -24
- package/dist/loadProject.d.ts.map +1 -1
- package/dist/loadProject.js +9 -11
- package/dist/loadProject.test.js +58 -65
- package/package.json +5 -5
- package/src/adapter/solidAdapter.test.ts +13 -14
- package/src/loadProject.test.ts +59 -66
- package/src/loadProject.ts +2 -42
|
@@ -3,8 +3,7 @@ import { describe, it, expect } from "vitest";
|
|
|
3
3
|
import { createEffect, from, createRoot } from "../reactivity/solid.js";
|
|
4
4
|
import { solidAdapter } from "./solidAdapter.js";
|
|
5
5
|
import { loadProject } from "../loadProject.js";
|
|
6
|
-
import {
|
|
7
|
-
import { openRepository } from "@lix-js/client";
|
|
6
|
+
import { mockRepo } from "@lix-js/client";
|
|
8
7
|
// ------------------------------------------------------------------------------------------------
|
|
9
8
|
const config = {
|
|
10
9
|
sourceLanguageTag: "en",
|
|
@@ -72,10 +71,10 @@ const $import = async (name) => ({
|
|
|
72
71
|
// ------------------------------------------------------------------------------------------------
|
|
73
72
|
describe("config", () => {
|
|
74
73
|
it("should react to changes in config", async () => {
|
|
75
|
-
const
|
|
74
|
+
const repo = await mockRepo();
|
|
75
|
+
const fs = repo.nodeishFs;
|
|
76
76
|
await fs.mkdir("/user/project.inlang", { recursive: true });
|
|
77
77
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(config));
|
|
78
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
79
78
|
const project = solidAdapter(await loadProject({
|
|
80
79
|
projectPath: "/user/project.inlang",
|
|
81
80
|
repo,
|
|
@@ -97,10 +96,10 @@ describe("config", () => {
|
|
|
97
96
|
});
|
|
98
97
|
describe("installed", () => {
|
|
99
98
|
it("react to changes that are unrelated to installed items", async () => {
|
|
100
|
-
const
|
|
99
|
+
const repo = await mockRepo();
|
|
100
|
+
const fs = repo.nodeishFs;
|
|
101
101
|
await fs.mkdir("/user/project.inlang", { recursive: true });
|
|
102
102
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(config));
|
|
103
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
104
103
|
const project = solidAdapter(await loadProject({
|
|
105
104
|
projectPath: "/user/project.inlang",
|
|
106
105
|
repo,
|
|
@@ -125,7 +124,8 @@ describe("installed", () => {
|
|
|
125
124
|
});
|
|
126
125
|
describe("messages", () => {
|
|
127
126
|
it("should react to changes in config", async () => {
|
|
128
|
-
const
|
|
127
|
+
const repo = await mockRepo();
|
|
128
|
+
const fs = repo.nodeishFs;
|
|
129
129
|
const mockConfig = {
|
|
130
130
|
sourceLanguageTag: "en",
|
|
131
131
|
languageTags: ["en", "de"],
|
|
@@ -154,7 +154,6 @@ describe("messages", () => {
|
|
|
154
154
|
const mockImport = async () => ({ default: mockPlugin });
|
|
155
155
|
await fs.mkdir("/user/project.inlang.inlang", { recursive: true });
|
|
156
156
|
await fs.writeFile("/user/project.inlang.inlang/settings.json", JSON.stringify(mockConfig));
|
|
157
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
158
157
|
const project = solidAdapter(await loadProject({
|
|
159
158
|
projectPath: "/user/project.inlang.inlang",
|
|
160
159
|
repo,
|
|
@@ -173,10 +172,10 @@ describe("messages", () => {
|
|
|
173
172
|
expect(Object.values(project.query.messages.getAll()).length).toBe(2);
|
|
174
173
|
});
|
|
175
174
|
it("should react to changes in messages", async () => {
|
|
176
|
-
const
|
|
175
|
+
const repo = await mockRepo();
|
|
176
|
+
const fs = repo.nodeishFs;
|
|
177
177
|
await fs.mkdir("/user/project.inlang.inlang", { recursive: true });
|
|
178
178
|
await fs.writeFile("/user/project.inlang.inlang/settings.json", JSON.stringify(config));
|
|
179
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
180
179
|
const project = solidAdapter(await loadProject({
|
|
181
180
|
projectPath: "/user/project.inlang.inlang",
|
|
182
181
|
repo,
|
|
@@ -220,10 +219,10 @@ describe("messages", () => {
|
|
|
220
219
|
describe("lint", () => {
|
|
221
220
|
it.todo("should react to changes in config", async () => {
|
|
222
221
|
await createRoot(async () => {
|
|
223
|
-
const
|
|
222
|
+
const repo = await mockRepo();
|
|
223
|
+
const fs = repo.nodeishFs;
|
|
224
224
|
await fs.mkdir("./project.inlang", { recursive: true });
|
|
225
225
|
await fs.writeFile("./project.inlang/settings.json", JSON.stringify(config));
|
|
226
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
227
226
|
const project = solidAdapter(await loadProject({
|
|
228
227
|
projectPath: "./project.inlang",
|
|
229
228
|
repo,
|
|
@@ -249,9 +248,9 @@ describe("lint", () => {
|
|
|
249
248
|
it.todo("should react to changes to modules");
|
|
250
249
|
it.todo("should react to changes to messages", async () => {
|
|
251
250
|
await createRoot(async () => {
|
|
252
|
-
const
|
|
251
|
+
const repo = await mockRepo();
|
|
252
|
+
const fs = repo.nodeishFs;
|
|
253
253
|
await fs.writeFile("./project.config.json", JSON.stringify(config));
|
|
254
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
255
254
|
const project = solidAdapter(await loadProject({
|
|
256
255
|
projectPath: "./project.config.json",
|
|
257
256
|
repo,
|
package/dist/loadProject.d.ts
CHANGED
|
@@ -1,35 +1,12 @@
|
|
|
1
1
|
import type { InlangProject, Subscribable } from "./api.js";
|
|
2
2
|
import { type ImportFunction } from "./resolve-modules/index.js";
|
|
3
3
|
import type { Repository } from "@lix-js/client";
|
|
4
|
-
/**
|
|
5
|
-
* Creates an inlang instance.
|
|
6
|
-
*
|
|
7
|
-
* @param projectPath - Absolute path to the inlang settings file.
|
|
8
|
-
* @param @deprecated nodeishFs - Filesystem that implements the NodeishFilesystemSubset interface.
|
|
9
|
-
* @param _import - Use `_import` to pass a custom import function for testing,
|
|
10
|
-
* and supporting legacy resolvedModules such as CJS.
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
export declare function loadProject(args: {
|
|
14
|
-
projectPath: string;
|
|
15
|
-
nodeishFs: Repository["nodeishFs"];
|
|
16
|
-
/**
|
|
17
|
-
* The app id is used to identify the app that is using the SDK.
|
|
18
|
-
*
|
|
19
|
-
* We use the app id to group events in telemetry to answer questions
|
|
20
|
-
* like "Which apps causes these errors?" or "Which apps are used more than others?".
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* appId: "app.inlang.badge"
|
|
24
|
-
*/
|
|
25
|
-
appId?: string;
|
|
26
|
-
_import?: ImportFunction;
|
|
27
|
-
}): Promise<InlangProject>;
|
|
28
4
|
/**
|
|
29
5
|
* @param projectPath - Absolute path to the inlang settings file.
|
|
30
6
|
* @param repo - An instance of a lix repo as returned by `openRepository`.
|
|
31
7
|
* @param _import - Use `_import` to pass a custom import function for testing,
|
|
32
8
|
* and supporting legacy resolvedModules such as CJS.
|
|
9
|
+
* @param appId - The app id to use for telemetry e.g "app.inlang.badge"
|
|
33
10
|
*
|
|
34
11
|
*/
|
|
35
12
|
export declare function loadProject(args: {
|
|
@@ -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;AAuBhF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAMhD
|
|
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;AAuBhF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAMhD;;;;;;;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,CAgRzB;AAwHD,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAQtE"}
|
package/dist/loadProject.js
CHANGED
|
@@ -17,6 +17,14 @@ import { maybeCreateFirstProjectId } from "./migrations/maybeCreateFirstProjectI
|
|
|
17
17
|
import { capture } from "./telemetry/capture.js";
|
|
18
18
|
import { identifyProject } from "./telemetry/groupIdentify.js";
|
|
19
19
|
const settingsCompiler = TypeCompiler.Compile(ProjectSettings);
|
|
20
|
+
/**
|
|
21
|
+
* @param projectPath - Absolute path to the inlang settings file.
|
|
22
|
+
* @param repo - An instance of a lix repo as returned by `openRepository`.
|
|
23
|
+
* @param _import - Use `_import` to pass a custom import function for testing,
|
|
24
|
+
* and supporting legacy resolvedModules such as CJS.
|
|
25
|
+
* @param appId - The app id to use for telemetry e.g "app.inlang.badge"
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
20
28
|
export async function loadProject(args) {
|
|
21
29
|
const projectPath = normalizePath(args.projectPath);
|
|
22
30
|
// -- validation --------------------------------------------------------
|
|
@@ -29,17 +37,7 @@ export async function loadProject(args) {
|
|
|
29
37
|
else if (/[^\\/]+\.inlang$/.test(projectPath) === false) {
|
|
30
38
|
throw new LoadProjectInvalidArgument(`Expected a path ending in "{name}.inlang" but received "${projectPath}".\n\nValid examples: \n- "/path/to/micky-mouse.inlang"\n- "/path/to/green-elephant.inlang\n`, { argument: "projectPath" });
|
|
31
39
|
}
|
|
32
|
-
|
|
33
|
-
if (args.nodeishFs) {
|
|
34
|
-
// TODO: deprecate
|
|
35
|
-
fs = args.nodeishFs;
|
|
36
|
-
}
|
|
37
|
-
else if (args.repo) {
|
|
38
|
-
fs = args.repo.nodeishFs;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
throw new LoadProjectInvalidArgument(`Repo missing from arguments.`, { argument: "repo" });
|
|
42
|
-
}
|
|
40
|
+
const fs = args.repo.nodeishFs;
|
|
43
41
|
const nodeishFs = createNodeishFsWithAbsolutePaths({
|
|
44
42
|
projectPath,
|
|
45
43
|
nodeishFs: fs,
|
package/dist/loadProject.test.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import { describe, it, expect, vi } from "vitest";
|
|
3
3
|
import { loadProject } from "./loadProject.js";
|
|
4
4
|
import { LoadProjectInvalidArgument, ProjectSettingsFileJSONSyntaxError, ProjectSettingsFileNotFoundError, ProjectSettingsInvalidError, } from "./errors.js";
|
|
5
|
-
import {
|
|
5
|
+
import { normalizePath } from "@lix-js/fs";
|
|
6
6
|
import { createMessage } from "./test-utilities/createMessage.js";
|
|
7
7
|
import { tryCatch } from "@inlang/result";
|
|
8
|
-
import { mockRepo
|
|
8
|
+
import { mockRepo } from "@lix-js/client";
|
|
9
9
|
import {} from "@lix-js/fs";
|
|
10
10
|
// eslint-disable-next-line no-restricted-imports -- test
|
|
11
11
|
import { readFileSync } from "node:fs";
|
|
@@ -85,13 +85,9 @@ const mockMessageLintRule = {
|
|
|
85
85
|
const _import = async (name) => ({
|
|
86
86
|
default: name === "plugin.js" ? mockPlugin : mockMessageLintRule,
|
|
87
87
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
encoding: "utf-8",
|
|
92
|
-
})),
|
|
93
|
-
});
|
|
94
|
-
}
|
|
88
|
+
const ciTestRepoSnapshot = JSON.parse(readFileSync(resolve(__dirname, "../mocks/ci-test-repo-no-shallow.json"), {
|
|
89
|
+
encoding: "utf-8",
|
|
90
|
+
}));
|
|
95
91
|
// ------------------------------------------------------------------------------------------------
|
|
96
92
|
/**
|
|
97
93
|
* Dear Developers,
|
|
@@ -100,8 +96,7 @@ async function openCiTestRepo() {
|
|
|
100
96
|
* like files: they can be renamed and moved around.
|
|
101
97
|
*/
|
|
102
98
|
it("should throw if a project (path) does not have a name", async () => {
|
|
103
|
-
const
|
|
104
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
99
|
+
const repo = await mockRepo();
|
|
105
100
|
const project = await tryCatch(() => loadProject({
|
|
106
101
|
projectPath: "/source-code/.inlang",
|
|
107
102
|
repo,
|
|
@@ -110,8 +105,7 @@ it("should throw if a project (path) does not have a name", async () => {
|
|
|
110
105
|
expect(project.error).toBeInstanceOf(LoadProjectInvalidArgument);
|
|
111
106
|
});
|
|
112
107
|
it("should throw if a project path does not end with .inlang", async () => {
|
|
113
|
-
const
|
|
114
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
108
|
+
const repo = await mockRepo();
|
|
115
109
|
const invalidPaths = [
|
|
116
110
|
"/source-code/frontend.inlang/settings",
|
|
117
111
|
"/source-code/frontend.inlang/settings.json",
|
|
@@ -128,8 +122,7 @@ it("should throw if a project path does not end with .inlang", async () => {
|
|
|
128
122
|
});
|
|
129
123
|
describe("initialization", () => {
|
|
130
124
|
it("should throw if projectPath is not an absolute path", async () => {
|
|
131
|
-
const
|
|
132
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
125
|
+
const repo = await mockRepo();
|
|
133
126
|
const result = await tryCatch(() => loadProject({
|
|
134
127
|
projectPath: "relative/path",
|
|
135
128
|
repo,
|
|
@@ -139,7 +132,7 @@ describe("initialization", () => {
|
|
|
139
132
|
expect(result.data).toBeUndefined();
|
|
140
133
|
});
|
|
141
134
|
it("should generate projectId on missing projectid", async () => {
|
|
142
|
-
const repo = await
|
|
135
|
+
const repo = await mockRepo({ fromSnapshot: ciTestRepoSnapshot });
|
|
143
136
|
const existing = await repo.nodeishFs
|
|
144
137
|
.readFile("/project.inlang/project_id", {
|
|
145
138
|
encoding: "utf-8",
|
|
@@ -166,7 +159,7 @@ describe("initialization", () => {
|
|
|
166
159
|
expect(result.data).toBeDefined();
|
|
167
160
|
});
|
|
168
161
|
it("should reuse projectId on existing projectid", async () => {
|
|
169
|
-
const repo = await
|
|
162
|
+
const repo = await mockRepo({ fromSnapshot: ciTestRepoSnapshot });
|
|
170
163
|
repo.nodeishFs.writeFile("/project.inlang/project_id", "testId");
|
|
171
164
|
const result = await tryCatch(() => loadProject({
|
|
172
165
|
projectPath: "/project.inlang",
|
|
@@ -185,10 +178,10 @@ describe("initialization", () => {
|
|
|
185
178
|
expect(result.data).toBeDefined();
|
|
186
179
|
});
|
|
187
180
|
it("should resolve from a windows path", async () => {
|
|
188
|
-
const
|
|
181
|
+
const repo = await mockRepo();
|
|
182
|
+
const fs = repo.nodeishFs;
|
|
189
183
|
fs.mkdir("C:\\Users\\user\\project.inlang", { recursive: true });
|
|
190
184
|
fs.writeFile("C:\\Users\\user\\project.inlang\\settings.json", JSON.stringify(settings));
|
|
191
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
192
185
|
const result = await tryCatch(() => loadProject({
|
|
193
186
|
projectPath: "C:\\Users\\user\\project.inlang",
|
|
194
187
|
repo,
|
|
@@ -199,9 +192,9 @@ describe("initialization", () => {
|
|
|
199
192
|
});
|
|
200
193
|
describe("settings", () => {
|
|
201
194
|
it("should return an error if settings file is not found", async () => {
|
|
202
|
-
const
|
|
195
|
+
const repo = await mockRepo();
|
|
196
|
+
const fs = repo.nodeishFs;
|
|
203
197
|
fs.mkdir("/user/project", { recursive: true });
|
|
204
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
205
198
|
const project = await loadProject({
|
|
206
199
|
projectPath: "/user/non-existend-project.inlang",
|
|
207
200
|
repo,
|
|
@@ -210,10 +203,10 @@ describe("initialization", () => {
|
|
|
210
203
|
expect(project.errors()[0]).toBeInstanceOf(ProjectSettingsFileNotFoundError);
|
|
211
204
|
});
|
|
212
205
|
it("should return an error if settings file is not a valid JSON", async () => {
|
|
213
|
-
const
|
|
206
|
+
const repo = await mockRepo();
|
|
207
|
+
const fs = repo.nodeishFs;
|
|
214
208
|
await fs.mkdir("/user/project.inlang", { recursive: true });
|
|
215
209
|
await fs.writeFile("/user/project.inlang/settings.json", "invalid json");
|
|
216
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
217
210
|
const project = await loadProject({
|
|
218
211
|
projectPath: "/user/project.inlang",
|
|
219
212
|
repo,
|
|
@@ -222,10 +215,10 @@ describe("initialization", () => {
|
|
|
222
215
|
expect(project.errors()[0]).toBeInstanceOf(ProjectSettingsFileJSONSyntaxError);
|
|
223
216
|
});
|
|
224
217
|
it("should return an error if settings file is does not match schema", async () => {
|
|
225
|
-
const
|
|
218
|
+
const repo = await mockRepo();
|
|
219
|
+
const fs = repo.nodeishFs;
|
|
226
220
|
await fs.mkdir("/user/project.inlang", { recursive: true });
|
|
227
221
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify({}));
|
|
228
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
229
222
|
const project = await loadProject({
|
|
230
223
|
projectPath: "/user/project.inlang",
|
|
231
224
|
repo,
|
|
@@ -234,10 +227,10 @@ describe("initialization", () => {
|
|
|
234
227
|
expect(project.errors()[0]).toBeInstanceOf(ProjectSettingsInvalidError);
|
|
235
228
|
});
|
|
236
229
|
it("should return the parsed settings", async () => {
|
|
237
|
-
const
|
|
230
|
+
const repo = await mockRepo();
|
|
231
|
+
const fs = repo.nodeishFs;
|
|
238
232
|
await fs.mkdir("/user/project.inlang", { recursive: true });
|
|
239
233
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings));
|
|
240
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
241
234
|
const project = await loadProject({
|
|
242
235
|
projectPath: "/user/project.inlang",
|
|
243
236
|
repo,
|
|
@@ -246,11 +239,11 @@ describe("initialization", () => {
|
|
|
246
239
|
expect(project.settings()).toStrictEqual(settings);
|
|
247
240
|
});
|
|
248
241
|
it("should not re-write the settings to disk when initializing", async () => {
|
|
249
|
-
const
|
|
242
|
+
const repo = await mockRepo();
|
|
243
|
+
const fs = repo.nodeishFs;
|
|
250
244
|
const settingsWithDeifferentFormatting = JSON.stringify(settings, undefined, 4);
|
|
251
245
|
await fs.mkdir("/user/project.inlang", { recursive: true });
|
|
252
246
|
await fs.writeFile("/user/project.inlang/settings.json", settingsWithDeifferentFormatting);
|
|
253
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
254
247
|
const project = await loadProject({
|
|
255
248
|
projectPath: "/user/project.inlang",
|
|
256
249
|
repo,
|
|
@@ -274,10 +267,10 @@ describe("initialization", () => {
|
|
|
274
267
|
const $badImport = async () => ({
|
|
275
268
|
default: {},
|
|
276
269
|
});
|
|
277
|
-
const
|
|
270
|
+
const repo = await mockRepo();
|
|
271
|
+
const fs = repo.nodeishFs;
|
|
278
272
|
await fs.mkdir("/user/project.inlang", { recursive: true });
|
|
279
273
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings));
|
|
280
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
281
274
|
const project = await loadProject({
|
|
282
275
|
projectPath: "/user/project.inlang",
|
|
283
276
|
repo,
|
|
@@ -303,10 +296,10 @@ describe("initialization", () => {
|
|
|
303
296
|
describe("functionality", () => {
|
|
304
297
|
describe("settings", () => {
|
|
305
298
|
it("should return the settings", async () => {
|
|
306
|
-
const
|
|
299
|
+
const repo = await mockRepo();
|
|
300
|
+
const fs = repo.nodeishFs;
|
|
307
301
|
await fs.mkdir("/user/project.inlang", { recursive: true });
|
|
308
302
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings));
|
|
309
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
310
303
|
const project = await loadProject({
|
|
311
304
|
projectPath: "/user/project.inlang",
|
|
312
305
|
repo,
|
|
@@ -315,10 +308,10 @@ describe("functionality", () => {
|
|
|
315
308
|
expect(getValue(project.settings)).toStrictEqual(settings);
|
|
316
309
|
});
|
|
317
310
|
it("should set a new settings", async () => {
|
|
318
|
-
const
|
|
311
|
+
const repo = await mockRepo();
|
|
312
|
+
const fs = repo.nodeishFs;
|
|
319
313
|
await fs.mkdir("/user/project.inlang", { recursive: true });
|
|
320
314
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings));
|
|
321
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
322
315
|
const project = await loadProject({
|
|
323
316
|
projectPath: "/user/project.inlang",
|
|
324
317
|
repo,
|
|
@@ -338,10 +331,10 @@ describe("functionality", () => {
|
|
|
338
331
|
});
|
|
339
332
|
describe("setSettings", () => {
|
|
340
333
|
it("should fail if settings are not valid", async () => {
|
|
341
|
-
const
|
|
334
|
+
const repo = await mockRepo();
|
|
335
|
+
const fs = repo.nodeishFs;
|
|
342
336
|
await fs.mkdir("/user/project.inlang", { recursive: true });
|
|
343
337
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings));
|
|
344
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
345
338
|
const project = await loadProject({
|
|
346
339
|
projectPath: "/user/project.inlang",
|
|
347
340
|
repo,
|
|
@@ -352,7 +345,8 @@ describe("functionality", () => {
|
|
|
352
345
|
expect(result.error).toBeInstanceOf(ProjectSettingsInvalidError);
|
|
353
346
|
});
|
|
354
347
|
it("should throw an error if sourceLanguageTag is not in languageTags", async () => {
|
|
355
|
-
const
|
|
348
|
+
const repo = await mockRepo();
|
|
349
|
+
const fs = repo.nodeishFs;
|
|
356
350
|
await fs.mkdir("/user/project.inlang", { recursive: true });
|
|
357
351
|
const settings = {
|
|
358
352
|
sourceLanguageTag: "en",
|
|
@@ -360,7 +354,6 @@ describe("functionality", () => {
|
|
|
360
354
|
modules: [],
|
|
361
355
|
};
|
|
362
356
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings));
|
|
363
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
364
357
|
const project = await loadProject({
|
|
365
358
|
projectPath: "/user/project.inlang",
|
|
366
359
|
repo,
|
|
@@ -370,10 +363,10 @@ describe("functionality", () => {
|
|
|
370
363
|
expect(project.errors()[0]).toBeInstanceOf(ProjectSettingsInvalidError);
|
|
371
364
|
});
|
|
372
365
|
it("should write settings to disk", async () => {
|
|
373
|
-
const
|
|
366
|
+
const repo = await mockRepo();
|
|
367
|
+
const fs = repo.nodeishFs;
|
|
374
368
|
await fs.mkdir("/user/project.inlang", { recursive: true });
|
|
375
369
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings));
|
|
376
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
377
370
|
const project = await loadProject({
|
|
378
371
|
projectPath: "/user/project.inlang",
|
|
379
372
|
repo,
|
|
@@ -393,7 +386,8 @@ describe("functionality", () => {
|
|
|
393
386
|
});
|
|
394
387
|
describe("installed", () => {
|
|
395
388
|
it("should return the installed items", async () => {
|
|
396
|
-
const
|
|
389
|
+
const repo = await mockRepo();
|
|
390
|
+
const fs = repo.nodeishFs;
|
|
397
391
|
const settings = {
|
|
398
392
|
sourceLanguageTag: "en",
|
|
399
393
|
languageTags: ["en"],
|
|
@@ -401,7 +395,6 @@ describe("functionality", () => {
|
|
|
401
395
|
};
|
|
402
396
|
await fs.mkdir("/user/project.inlang", { recursive: true });
|
|
403
397
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings));
|
|
404
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
405
398
|
const project = await loadProject({
|
|
406
399
|
projectPath: "/user/project.inlang",
|
|
407
400
|
repo,
|
|
@@ -422,7 +415,8 @@ describe("functionality", () => {
|
|
|
422
415
|
});
|
|
423
416
|
});
|
|
424
417
|
it("should apply 'warning' as default lint level to lint rules that have no lint level defined in the settings", async () => {
|
|
425
|
-
const
|
|
418
|
+
const repo = await mockRepo();
|
|
419
|
+
const fs = repo.nodeishFs;
|
|
426
420
|
const settings = {
|
|
427
421
|
sourceLanguageTag: "en",
|
|
428
422
|
languageTags: ["en"],
|
|
@@ -430,7 +424,6 @@ describe("functionality", () => {
|
|
|
430
424
|
};
|
|
431
425
|
await fs.mkdir("/user/project.inlang", { recursive: true });
|
|
432
426
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings));
|
|
433
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
434
427
|
const project = await loadProject({
|
|
435
428
|
projectPath: "/user/project.inlang",
|
|
436
429
|
repo,
|
|
@@ -459,14 +452,14 @@ describe("functionality", () => {
|
|
|
459
452
|
loadMessages: () => [{ id: "some-message", selectors: [], variants: [] }],
|
|
460
453
|
saveMessages: () => undefined,
|
|
461
454
|
};
|
|
462
|
-
const
|
|
455
|
+
const repo = await mockRepo();
|
|
456
|
+
const fs = repo.nodeishFs;
|
|
463
457
|
await fs.mkdir("/user/project.inlang", { recursive: true });
|
|
464
458
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify({
|
|
465
459
|
sourceLanguageTag: "en",
|
|
466
460
|
languageTags: ["en"],
|
|
467
461
|
modules: ["plugin.js", "lintRule.js"],
|
|
468
462
|
}));
|
|
469
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
470
463
|
const _import = async (name) => {
|
|
471
464
|
return {
|
|
472
465
|
default: name === "plugin.js" ? _mockPlugin : _mockLintRule,
|
|
@@ -502,14 +495,14 @@ describe("functionality", () => {
|
|
|
502
495
|
loadMessages: () => [{ id: "some-message", selectors: [], variants: [] }],
|
|
503
496
|
saveMessages: () => undefined,
|
|
504
497
|
};
|
|
505
|
-
const
|
|
498
|
+
const repo = await mockRepo();
|
|
499
|
+
const fs = repo.nodeishFs;
|
|
506
500
|
await fs.mkdir("/user/project.inlang", { recursive: true });
|
|
507
501
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify({
|
|
508
502
|
sourceLanguageTag: "en",
|
|
509
503
|
languageTags: ["en"],
|
|
510
504
|
modules: ["plugin.js", "lintRule.js"],
|
|
511
505
|
}));
|
|
512
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
513
506
|
const _import = async (name) => {
|
|
514
507
|
return {
|
|
515
508
|
default: name === "plugin.js" ? _mockPlugin : _mockLintRule,
|
|
@@ -526,10 +519,10 @@ describe("functionality", () => {
|
|
|
526
519
|
});
|
|
527
520
|
describe("errors", () => {
|
|
528
521
|
it("should return the errors", async () => {
|
|
529
|
-
const
|
|
522
|
+
const repo = await mockRepo();
|
|
523
|
+
const fs = repo.nodeishFs;
|
|
530
524
|
await fs.mkdir("/user/project.inlang", { recursive: true });
|
|
531
525
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings));
|
|
532
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
533
526
|
const project = await loadProject({
|
|
534
527
|
projectPath: "/user/project.inlang",
|
|
535
528
|
repo,
|
|
@@ -542,10 +535,10 @@ describe("functionality", () => {
|
|
|
542
535
|
});
|
|
543
536
|
describe("customApi", () => {
|
|
544
537
|
it("should return the app specific api", async () => {
|
|
545
|
-
const
|
|
538
|
+
const repo = await mockRepo();
|
|
539
|
+
const fs = repo.nodeishFs;
|
|
546
540
|
await fs.mkdir("/user/project.inlang", { recursive: true });
|
|
547
541
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings));
|
|
548
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
549
542
|
const project = await loadProject({
|
|
550
543
|
projectPath: "/user/project.inlang",
|
|
551
544
|
repo,
|
|
@@ -558,10 +551,10 @@ describe("functionality", () => {
|
|
|
558
551
|
});
|
|
559
552
|
describe("messages", () => {
|
|
560
553
|
it("should return the messages", async () => {
|
|
561
|
-
const
|
|
554
|
+
const repo = await mockRepo();
|
|
555
|
+
const fs = repo.nodeishFs;
|
|
562
556
|
await fs.mkdir("/user/project.inlang", { recursive: true });
|
|
563
557
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings));
|
|
564
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
565
558
|
const project = await loadProject({
|
|
566
559
|
projectPath: "/user/project.inlang",
|
|
567
560
|
repo,
|
|
@@ -572,7 +565,8 @@ describe("functionality", () => {
|
|
|
572
565
|
});
|
|
573
566
|
describe("query", () => {
|
|
574
567
|
it("should call saveMessages() on updates", async () => {
|
|
575
|
-
const
|
|
568
|
+
const repo = await mockRepo();
|
|
569
|
+
const fs = repo.nodeishFs;
|
|
576
570
|
const settings = {
|
|
577
571
|
sourceLanguageTag: "en",
|
|
578
572
|
languageTags: ["en", "de"],
|
|
@@ -584,7 +578,6 @@ describe("functionality", () => {
|
|
|
584
578
|
await fs.mkdir("/user/project.inlang", { recursive: true });
|
|
585
579
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings));
|
|
586
580
|
await fs.mkdir("./resources");
|
|
587
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
588
581
|
const mockSaveFn = vi.fn();
|
|
589
582
|
const _mockPlugin = {
|
|
590
583
|
id: "plugin.project.json",
|
|
@@ -735,7 +728,8 @@ describe("functionality", () => {
|
|
|
735
728
|
* - Might be slow for a large number of messages. The requirement hasn't popped up yet though.
|
|
736
729
|
*/
|
|
737
730
|
it("should pass all messages, regardless of which message changed, to saveMessages()", async () => {
|
|
738
|
-
const
|
|
731
|
+
const repo = await mockRepo();
|
|
732
|
+
const fs = repo.nodeishFs;
|
|
739
733
|
const settings = {
|
|
740
734
|
sourceLanguageTag: "en",
|
|
741
735
|
languageTags: ["en", "de"],
|
|
@@ -746,7 +740,6 @@ describe("functionality", () => {
|
|
|
746
740
|
};
|
|
747
741
|
await fs.mkdir("./project.inlang", { recursive: true });
|
|
748
742
|
await fs.writeFile("./project.inlang/settings.json", JSON.stringify(settings));
|
|
749
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
750
743
|
const mockSaveFn = vi.fn();
|
|
751
744
|
const _mockPlugin = {
|
|
752
745
|
id: "plugin.placeholder.name",
|
|
@@ -777,10 +770,10 @@ describe("functionality", () => {
|
|
|
777
770
|
});
|
|
778
771
|
describe("lint", () => {
|
|
779
772
|
it.todo("should throw if lint reports are not initialized yet", async () => {
|
|
780
|
-
const
|
|
773
|
+
const repo = await mockRepo();
|
|
774
|
+
const fs = repo.nodeishFs;
|
|
781
775
|
await fs.mkdir("/user/project", { recursive: true });
|
|
782
776
|
await fs.writeFile("/user/project/project.inlang.json", JSON.stringify(settings));
|
|
783
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
784
777
|
const project = await loadProject({
|
|
785
778
|
projectPath: "/user/project/project.inlang.json",
|
|
786
779
|
repo,
|
|
@@ -801,10 +794,10 @@ describe("functionality", () => {
|
|
|
801
794
|
languageTags: ["en"],
|
|
802
795
|
modules: ["lintRule.js"],
|
|
803
796
|
};
|
|
804
|
-
const
|
|
797
|
+
const repo = await mockRepo();
|
|
798
|
+
const fs = repo.nodeishFs;
|
|
805
799
|
await fs.mkdir("/user/project.inlang", { recursive: true });
|
|
806
800
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings));
|
|
807
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
808
801
|
const project = await loadProject({
|
|
809
802
|
projectPath: "/user/project.inlang",
|
|
810
803
|
repo,
|
|
@@ -818,7 +811,8 @@ describe("functionality", () => {
|
|
|
818
811
|
});
|
|
819
812
|
describe("watcher", () => {
|
|
820
813
|
it("changing files in resources should trigger callback of message query", async () => {
|
|
821
|
-
const
|
|
814
|
+
const repo = await mockRepo();
|
|
815
|
+
const fs = repo.nodeishFs;
|
|
822
816
|
const messages = {
|
|
823
817
|
$schema: "https://inlang.com/schema/inlang-message-format",
|
|
824
818
|
data: [
|
|
@@ -862,7 +856,6 @@ describe("functionality", () => {
|
|
|
862
856
|
};
|
|
863
857
|
await fs.mkdir("./project.inlang", { recursive: true });
|
|
864
858
|
await fs.writeFile("./project.inlang/settings.json", JSON.stringify(settings));
|
|
865
|
-
const repo = await openRepository("file://", { nodeishFs: fs });
|
|
866
859
|
// establish watcher
|
|
867
860
|
const project = await loadProject({
|
|
868
861
|
projectPath: normalizePath("/project.inlang"),
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inlang/sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.26.1",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -26,16 +26,16 @@
|
|
|
26
26
|
"solid-js": "1.6.12",
|
|
27
27
|
"throttle-debounce": "^5.0.0",
|
|
28
28
|
"@inlang/language-tag": "1.4.0",
|
|
29
|
-
"@inlang/message": "2.0.1",
|
|
30
29
|
"@inlang/json-types": "1.1.0",
|
|
30
|
+
"@inlang/message": "2.0.1",
|
|
31
31
|
"@inlang/module": "1.2.3",
|
|
32
32
|
"@inlang/message-lint-rule": "1.4.1",
|
|
33
|
-
"@inlang/plugin": "2.4.3",
|
|
34
33
|
"@inlang/project-settings": "2.2.1",
|
|
35
|
-
"@inlang/
|
|
34
|
+
"@inlang/plugin": "2.4.3",
|
|
36
35
|
"@inlang/translatable": "1.2.1",
|
|
36
|
+
"@inlang/result": "1.1.0",
|
|
37
37
|
"@lix-js/fs": "0.6.0",
|
|
38
|
-
"@lix-js/client": "0.
|
|
38
|
+
"@lix-js/client": "0.8.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/throttle-debounce": "5.0.0",
|
|
@@ -4,8 +4,7 @@ import type { ImportFunction } from "../resolve-modules/index.js"
|
|
|
4
4
|
import { createEffect, from, createRoot } from "../reactivity/solid.js"
|
|
5
5
|
import { solidAdapter } from "./solidAdapter.js"
|
|
6
6
|
import { loadProject } from "../loadProject.js"
|
|
7
|
-
import {
|
|
8
|
-
import { openRepository } from "@lix-js/client"
|
|
7
|
+
import { mockRepo } from "@lix-js/client"
|
|
9
8
|
import type {
|
|
10
9
|
Message,
|
|
11
10
|
ProjectSettings,
|
|
@@ -90,10 +89,10 @@ const $import: ImportFunction = async (name) => ({
|
|
|
90
89
|
|
|
91
90
|
describe("config", () => {
|
|
92
91
|
it("should react to changes in config", async () => {
|
|
93
|
-
const
|
|
92
|
+
const repo = await mockRepo()
|
|
93
|
+
const fs = repo.nodeishFs
|
|
94
94
|
await fs.mkdir("/user/project.inlang", { recursive: true })
|
|
95
95
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(config))
|
|
96
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
97
96
|
const project = solidAdapter(
|
|
98
97
|
await loadProject({
|
|
99
98
|
projectPath: "/user/project.inlang",
|
|
@@ -124,10 +123,10 @@ describe("config", () => {
|
|
|
124
123
|
|
|
125
124
|
describe("installed", () => {
|
|
126
125
|
it("react to changes that are unrelated to installed items", async () => {
|
|
127
|
-
const
|
|
126
|
+
const repo = await mockRepo()
|
|
127
|
+
const fs = repo.nodeishFs
|
|
128
128
|
await fs.mkdir("/user/project.inlang", { recursive: true })
|
|
129
129
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(config))
|
|
130
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
131
130
|
const project = solidAdapter(
|
|
132
131
|
await loadProject({
|
|
133
132
|
projectPath: "/user/project.inlang",
|
|
@@ -161,7 +160,8 @@ describe("installed", () => {
|
|
|
161
160
|
|
|
162
161
|
describe("messages", () => {
|
|
163
162
|
it("should react to changes in config", async () => {
|
|
164
|
-
const
|
|
163
|
+
const repo = await mockRepo()
|
|
164
|
+
const fs = repo.nodeishFs
|
|
165
165
|
const mockConfig: ProjectSettings = {
|
|
166
166
|
sourceLanguageTag: "en",
|
|
167
167
|
languageTags: ["en", "de"],
|
|
@@ -193,7 +193,6 @@ describe("messages", () => {
|
|
|
193
193
|
|
|
194
194
|
await fs.mkdir("/user/project.inlang.inlang", { recursive: true })
|
|
195
195
|
await fs.writeFile("/user/project.inlang.inlang/settings.json", JSON.stringify(mockConfig))
|
|
196
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
197
196
|
const project = solidAdapter(
|
|
198
197
|
await loadProject({
|
|
199
198
|
projectPath: "/user/project.inlang.inlang",
|
|
@@ -221,10 +220,10 @@ describe("messages", () => {
|
|
|
221
220
|
})
|
|
222
221
|
|
|
223
222
|
it("should react to changes in messages", async () => {
|
|
224
|
-
const
|
|
223
|
+
const repo = await mockRepo()
|
|
224
|
+
const fs = repo.nodeishFs
|
|
225
225
|
await fs.mkdir("/user/project.inlang.inlang", { recursive: true })
|
|
226
226
|
await fs.writeFile("/user/project.inlang.inlang/settings.json", JSON.stringify(config))
|
|
227
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
228
227
|
const project = solidAdapter(
|
|
229
228
|
await loadProject({
|
|
230
229
|
projectPath: "/user/project.inlang.inlang",
|
|
@@ -284,10 +283,10 @@ describe("messages", () => {
|
|
|
284
283
|
describe("lint", () => {
|
|
285
284
|
it.todo("should react to changes in config", async () => {
|
|
286
285
|
await createRoot(async () => {
|
|
287
|
-
const
|
|
286
|
+
const repo = await mockRepo()
|
|
287
|
+
const fs = repo.nodeishFs
|
|
288
288
|
await fs.mkdir("./project.inlang", { recursive: true })
|
|
289
289
|
await fs.writeFile("./project.inlang/settings.json", JSON.stringify(config))
|
|
290
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
291
290
|
const project = solidAdapter(
|
|
292
291
|
await loadProject({
|
|
293
292
|
projectPath: "./project.inlang",
|
|
@@ -324,9 +323,9 @@ describe("lint", () => {
|
|
|
324
323
|
|
|
325
324
|
it.todo("should react to changes to messages", async () => {
|
|
326
325
|
await createRoot(async () => {
|
|
327
|
-
const
|
|
326
|
+
const repo = await mockRepo()
|
|
327
|
+
const fs = repo.nodeishFs
|
|
328
328
|
await fs.writeFile("./project.config.json", JSON.stringify(config))
|
|
329
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
330
329
|
const project = solidAdapter(
|
|
331
330
|
await loadProject({
|
|
332
331
|
projectPath: "./project.config.json",
|
package/src/loadProject.test.ts
CHANGED
|
@@ -16,10 +16,10 @@ import {
|
|
|
16
16
|
ProjectSettingsFileNotFoundError,
|
|
17
17
|
ProjectSettingsInvalidError,
|
|
18
18
|
} from "./errors.js"
|
|
19
|
-
import {
|
|
19
|
+
import { normalizePath } from "@lix-js/fs"
|
|
20
20
|
import { createMessage } from "./test-utilities/createMessage.js"
|
|
21
21
|
import { tryCatch } from "@inlang/result"
|
|
22
|
-
import { mockRepo
|
|
22
|
+
import { mockRepo } from "@lix-js/client"
|
|
23
23
|
import { type Snapshot } from "@lix-js/fs"
|
|
24
24
|
// eslint-disable-next-line no-restricted-imports -- test
|
|
25
25
|
import { readFileSync } from "node:fs"
|
|
@@ -109,15 +109,11 @@ const _import: ImportFunction = async (name) =>
|
|
|
109
109
|
default: name === "plugin.js" ? mockPlugin : mockMessageLintRule,
|
|
110
110
|
} satisfies InlangModule)
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
readFileSync(resolve(__dirname, "../mocks/ci-test-repo-no-shallow.json"), {
|
|
116
|
-
encoding: "utf-8",
|
|
117
|
-
})
|
|
118
|
-
) as Snapshot,
|
|
112
|
+
const ciTestRepoSnapshot = JSON.parse(
|
|
113
|
+
readFileSync(resolve(__dirname, "../mocks/ci-test-repo-no-shallow.json"), {
|
|
114
|
+
encoding: "utf-8",
|
|
119
115
|
})
|
|
120
|
-
|
|
116
|
+
) as Snapshot
|
|
121
117
|
|
|
122
118
|
// ------------------------------------------------------------------------------------------------
|
|
123
119
|
|
|
@@ -128,8 +124,7 @@ async function openCiTestRepo() {
|
|
|
128
124
|
* like files: they can be renamed and moved around.
|
|
129
125
|
*/
|
|
130
126
|
it("should throw if a project (path) does not have a name", async () => {
|
|
131
|
-
const
|
|
132
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
127
|
+
const repo = await mockRepo()
|
|
133
128
|
const project = await tryCatch(() =>
|
|
134
129
|
loadProject({
|
|
135
130
|
projectPath: "/source-code/.inlang",
|
|
@@ -141,8 +136,7 @@ it("should throw if a project (path) does not have a name", async () => {
|
|
|
141
136
|
})
|
|
142
137
|
|
|
143
138
|
it("should throw if a project path does not end with .inlang", async () => {
|
|
144
|
-
const
|
|
145
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
139
|
+
const repo = await mockRepo()
|
|
146
140
|
|
|
147
141
|
const invalidPaths = [
|
|
148
142
|
"/source-code/frontend.inlang/settings",
|
|
@@ -164,8 +158,7 @@ it("should throw if a project path does not end with .inlang", async () => {
|
|
|
164
158
|
|
|
165
159
|
describe("initialization", () => {
|
|
166
160
|
it("should throw if projectPath is not an absolute path", async () => {
|
|
167
|
-
const
|
|
168
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
161
|
+
const repo = await mockRepo()
|
|
169
162
|
|
|
170
163
|
const result = await tryCatch(() =>
|
|
171
164
|
loadProject({
|
|
@@ -179,7 +172,7 @@ describe("initialization", () => {
|
|
|
179
172
|
})
|
|
180
173
|
|
|
181
174
|
it("should generate projectId on missing projectid", async () => {
|
|
182
|
-
const repo = await
|
|
175
|
+
const repo = await mockRepo({ fromSnapshot: ciTestRepoSnapshot })
|
|
183
176
|
|
|
184
177
|
const existing = await repo.nodeishFs
|
|
185
178
|
.readFile("/project.inlang/project_id", {
|
|
@@ -215,7 +208,7 @@ describe("initialization", () => {
|
|
|
215
208
|
})
|
|
216
209
|
|
|
217
210
|
it("should reuse projectId on existing projectid", async () => {
|
|
218
|
-
const repo = await
|
|
211
|
+
const repo = await mockRepo({ fromSnapshot: ciTestRepoSnapshot })
|
|
219
212
|
|
|
220
213
|
repo.nodeishFs.writeFile("/project.inlang/project_id", "testId")
|
|
221
214
|
|
|
@@ -242,10 +235,10 @@ describe("initialization", () => {
|
|
|
242
235
|
})
|
|
243
236
|
|
|
244
237
|
it("should resolve from a windows path", async () => {
|
|
245
|
-
const
|
|
238
|
+
const repo = await mockRepo()
|
|
239
|
+
const fs = repo.nodeishFs
|
|
246
240
|
fs.mkdir("C:\\Users\\user\\project.inlang", { recursive: true })
|
|
247
241
|
fs.writeFile("C:\\Users\\user\\project.inlang\\settings.json", JSON.stringify(settings))
|
|
248
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
249
242
|
|
|
250
243
|
const result = await tryCatch(() =>
|
|
251
244
|
loadProject({
|
|
@@ -261,9 +254,9 @@ describe("initialization", () => {
|
|
|
261
254
|
|
|
262
255
|
describe("settings", () => {
|
|
263
256
|
it("should return an error if settings file is not found", async () => {
|
|
264
|
-
const
|
|
257
|
+
const repo = await mockRepo()
|
|
258
|
+
const fs = repo.nodeishFs
|
|
265
259
|
fs.mkdir("/user/project", { recursive: true })
|
|
266
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
267
260
|
|
|
268
261
|
const project = await loadProject({
|
|
269
262
|
projectPath: "/user/non-existend-project.inlang",
|
|
@@ -275,10 +268,10 @@ describe("initialization", () => {
|
|
|
275
268
|
})
|
|
276
269
|
|
|
277
270
|
it("should return an error if settings file is not a valid JSON", async () => {
|
|
278
|
-
const
|
|
271
|
+
const repo = await mockRepo()
|
|
272
|
+
const fs = repo.nodeishFs
|
|
279
273
|
await fs.mkdir("/user/project.inlang", { recursive: true })
|
|
280
274
|
await fs.writeFile("/user/project.inlang/settings.json", "invalid json")
|
|
281
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
282
275
|
|
|
283
276
|
const project = await loadProject({
|
|
284
277
|
projectPath: "/user/project.inlang",
|
|
@@ -290,10 +283,10 @@ describe("initialization", () => {
|
|
|
290
283
|
})
|
|
291
284
|
|
|
292
285
|
it("should return an error if settings file is does not match schema", async () => {
|
|
293
|
-
const
|
|
286
|
+
const repo = await mockRepo()
|
|
287
|
+
const fs = repo.nodeishFs
|
|
294
288
|
await fs.mkdir("/user/project.inlang", { recursive: true })
|
|
295
289
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify({}))
|
|
296
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
297
290
|
|
|
298
291
|
const project = await loadProject({
|
|
299
292
|
projectPath: "/user/project.inlang",
|
|
@@ -305,10 +298,10 @@ describe("initialization", () => {
|
|
|
305
298
|
})
|
|
306
299
|
|
|
307
300
|
it("should return the parsed settings", async () => {
|
|
308
|
-
const
|
|
301
|
+
const repo = await mockRepo()
|
|
302
|
+
const fs = repo.nodeishFs
|
|
309
303
|
await fs.mkdir("/user/project.inlang", { recursive: true })
|
|
310
304
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings))
|
|
311
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
312
305
|
const project = await loadProject({
|
|
313
306
|
projectPath: "/user/project.inlang",
|
|
314
307
|
repo,
|
|
@@ -319,11 +312,11 @@ describe("initialization", () => {
|
|
|
319
312
|
})
|
|
320
313
|
|
|
321
314
|
it("should not re-write the settings to disk when initializing", async () => {
|
|
322
|
-
const
|
|
315
|
+
const repo = await mockRepo()
|
|
316
|
+
const fs = repo.nodeishFs
|
|
323
317
|
const settingsWithDeifferentFormatting = JSON.stringify(settings, undefined, 4)
|
|
324
318
|
await fs.mkdir("/user/project.inlang", { recursive: true })
|
|
325
319
|
await fs.writeFile("/user/project.inlang/settings.json", settingsWithDeifferentFormatting)
|
|
326
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
327
320
|
|
|
328
321
|
const project = await loadProject({
|
|
329
322
|
projectPath: "/user/project.inlang",
|
|
@@ -354,10 +347,10 @@ describe("initialization", () => {
|
|
|
354
347
|
default: {} as Plugin,
|
|
355
348
|
} satisfies InlangModule)
|
|
356
349
|
|
|
357
|
-
const
|
|
350
|
+
const repo = await mockRepo()
|
|
351
|
+
const fs = repo.nodeishFs
|
|
358
352
|
await fs.mkdir("/user/project.inlang", { recursive: true })
|
|
359
353
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings))
|
|
360
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
361
354
|
|
|
362
355
|
const project = await loadProject({
|
|
363
356
|
projectPath: "/user/project.inlang",
|
|
@@ -388,10 +381,10 @@ describe("initialization", () => {
|
|
|
388
381
|
describe("functionality", () => {
|
|
389
382
|
describe("settings", () => {
|
|
390
383
|
it("should return the settings", async () => {
|
|
391
|
-
const
|
|
384
|
+
const repo = await mockRepo()
|
|
385
|
+
const fs = repo.nodeishFs
|
|
392
386
|
await fs.mkdir("/user/project.inlang", { recursive: true })
|
|
393
387
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings))
|
|
394
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
395
388
|
const project = await loadProject({
|
|
396
389
|
projectPath: "/user/project.inlang",
|
|
397
390
|
repo,
|
|
@@ -402,10 +395,10 @@ describe("functionality", () => {
|
|
|
402
395
|
})
|
|
403
396
|
|
|
404
397
|
it("should set a new settings", async () => {
|
|
405
|
-
const
|
|
398
|
+
const repo = await mockRepo()
|
|
399
|
+
const fs = repo.nodeishFs
|
|
406
400
|
await fs.mkdir("/user/project.inlang", { recursive: true })
|
|
407
401
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings))
|
|
408
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
409
402
|
const project = await loadProject({
|
|
410
403
|
projectPath: "/user/project.inlang",
|
|
411
404
|
repo,
|
|
@@ -429,10 +422,10 @@ describe("functionality", () => {
|
|
|
429
422
|
|
|
430
423
|
describe("setSettings", () => {
|
|
431
424
|
it("should fail if settings are not valid", async () => {
|
|
432
|
-
const
|
|
425
|
+
const repo = await mockRepo()
|
|
426
|
+
const fs = repo.nodeishFs
|
|
433
427
|
await fs.mkdir("/user/project.inlang", { recursive: true })
|
|
434
428
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings))
|
|
435
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
436
429
|
const project = await loadProject({
|
|
437
430
|
projectPath: "/user/project.inlang",
|
|
438
431
|
repo,
|
|
@@ -445,7 +438,8 @@ describe("functionality", () => {
|
|
|
445
438
|
})
|
|
446
439
|
|
|
447
440
|
it("should throw an error if sourceLanguageTag is not in languageTags", async () => {
|
|
448
|
-
const
|
|
441
|
+
const repo = await mockRepo()
|
|
442
|
+
const fs = repo.nodeishFs
|
|
449
443
|
await fs.mkdir("/user/project.inlang", { recursive: true })
|
|
450
444
|
|
|
451
445
|
const settings: ProjectSettings = {
|
|
@@ -455,7 +449,6 @@ describe("functionality", () => {
|
|
|
455
449
|
}
|
|
456
450
|
|
|
457
451
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings))
|
|
458
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
459
452
|
|
|
460
453
|
const project = await loadProject({
|
|
461
454
|
projectPath: "/user/project.inlang",
|
|
@@ -468,10 +461,10 @@ describe("functionality", () => {
|
|
|
468
461
|
})
|
|
469
462
|
|
|
470
463
|
it("should write settings to disk", async () => {
|
|
471
|
-
const
|
|
464
|
+
const repo = await mockRepo()
|
|
465
|
+
const fs = repo.nodeishFs
|
|
472
466
|
await fs.mkdir("/user/project.inlang", { recursive: true })
|
|
473
467
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings))
|
|
474
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
475
468
|
const project = await loadProject({
|
|
476
469
|
projectPath: "/user/project.inlang",
|
|
477
470
|
repo,
|
|
@@ -496,7 +489,8 @@ describe("functionality", () => {
|
|
|
496
489
|
|
|
497
490
|
describe("installed", () => {
|
|
498
491
|
it("should return the installed items", async () => {
|
|
499
|
-
const
|
|
492
|
+
const repo = await mockRepo()
|
|
493
|
+
const fs = repo.nodeishFs
|
|
500
494
|
const settings: ProjectSettings = {
|
|
501
495
|
sourceLanguageTag: "en",
|
|
502
496
|
languageTags: ["en"],
|
|
@@ -504,7 +498,6 @@ describe("functionality", () => {
|
|
|
504
498
|
}
|
|
505
499
|
await fs.mkdir("/user/project.inlang", { recursive: true })
|
|
506
500
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings))
|
|
507
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
508
501
|
const project = await loadProject({
|
|
509
502
|
projectPath: "/user/project.inlang",
|
|
510
503
|
repo,
|
|
@@ -528,7 +521,8 @@ describe("functionality", () => {
|
|
|
528
521
|
})
|
|
529
522
|
|
|
530
523
|
it("should apply 'warning' as default lint level to lint rules that have no lint level defined in the settings", async () => {
|
|
531
|
-
const
|
|
524
|
+
const repo = await mockRepo()
|
|
525
|
+
const fs = repo.nodeishFs
|
|
532
526
|
|
|
533
527
|
const settings: ProjectSettings = {
|
|
534
528
|
sourceLanguageTag: "en",
|
|
@@ -538,7 +532,6 @@ describe("functionality", () => {
|
|
|
538
532
|
|
|
539
533
|
await fs.mkdir("/user/project.inlang", { recursive: true })
|
|
540
534
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings))
|
|
541
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
542
535
|
|
|
543
536
|
const project = await loadProject({
|
|
544
537
|
projectPath: "/user/project.inlang",
|
|
@@ -571,7 +564,8 @@ describe("functionality", () => {
|
|
|
571
564
|
loadMessages: () => [{ id: "some-message", selectors: [], variants: [] }],
|
|
572
565
|
saveMessages: () => undefined,
|
|
573
566
|
}
|
|
574
|
-
const
|
|
567
|
+
const repo = await mockRepo()
|
|
568
|
+
const fs = repo.nodeishFs
|
|
575
569
|
await fs.mkdir("/user/project.inlang", { recursive: true })
|
|
576
570
|
await fs.writeFile(
|
|
577
571
|
"/user/project.inlang/settings.json",
|
|
@@ -581,7 +575,6 @@ describe("functionality", () => {
|
|
|
581
575
|
modules: ["plugin.js", "lintRule.js"],
|
|
582
576
|
} satisfies ProjectSettings)
|
|
583
577
|
)
|
|
584
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
585
578
|
|
|
586
579
|
const _import: ImportFunction = async (name) => {
|
|
587
580
|
return {
|
|
@@ -623,7 +616,8 @@ describe("functionality", () => {
|
|
|
623
616
|
loadMessages: () => [{ id: "some-message", selectors: [], variants: [] }],
|
|
624
617
|
saveMessages: () => undefined,
|
|
625
618
|
}
|
|
626
|
-
const
|
|
619
|
+
const repo = await mockRepo()
|
|
620
|
+
const fs = repo.nodeishFs
|
|
627
621
|
await fs.mkdir("/user/project.inlang", { recursive: true })
|
|
628
622
|
await fs.writeFile(
|
|
629
623
|
"/user/project.inlang/settings.json",
|
|
@@ -633,7 +627,6 @@ describe("functionality", () => {
|
|
|
633
627
|
modules: ["plugin.js", "lintRule.js"],
|
|
634
628
|
} satisfies ProjectSettings)
|
|
635
629
|
)
|
|
636
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
637
630
|
const _import: ImportFunction = async (name) => {
|
|
638
631
|
return {
|
|
639
632
|
default: name === "plugin.js" ? _mockPlugin : _mockLintRule,
|
|
@@ -656,10 +649,10 @@ describe("functionality", () => {
|
|
|
656
649
|
|
|
657
650
|
describe("errors", () => {
|
|
658
651
|
it("should return the errors", async () => {
|
|
659
|
-
const
|
|
652
|
+
const repo = await mockRepo()
|
|
653
|
+
const fs = repo.nodeishFs
|
|
660
654
|
await fs.mkdir("/user/project.inlang", { recursive: true })
|
|
661
655
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings))
|
|
662
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
663
656
|
const project = await loadProject({
|
|
664
657
|
projectPath: "/user/project.inlang",
|
|
665
658
|
repo,
|
|
@@ -673,10 +666,10 @@ describe("functionality", () => {
|
|
|
673
666
|
|
|
674
667
|
describe("customApi", () => {
|
|
675
668
|
it("should return the app specific api", async () => {
|
|
676
|
-
const
|
|
669
|
+
const repo = await mockRepo()
|
|
670
|
+
const fs = repo.nodeishFs
|
|
677
671
|
await fs.mkdir("/user/project.inlang", { recursive: true })
|
|
678
672
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings))
|
|
679
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
680
673
|
const project = await loadProject({
|
|
681
674
|
projectPath: "/user/project.inlang",
|
|
682
675
|
repo,
|
|
@@ -691,10 +684,10 @@ describe("functionality", () => {
|
|
|
691
684
|
|
|
692
685
|
describe("messages", () => {
|
|
693
686
|
it("should return the messages", async () => {
|
|
694
|
-
const
|
|
687
|
+
const repo = await mockRepo()
|
|
688
|
+
const fs = repo.nodeishFs
|
|
695
689
|
await fs.mkdir("/user/project.inlang", { recursive: true })
|
|
696
690
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings))
|
|
697
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
698
691
|
const project = await loadProject({
|
|
699
692
|
projectPath: "/user/project.inlang",
|
|
700
693
|
repo,
|
|
@@ -707,7 +700,8 @@ describe("functionality", () => {
|
|
|
707
700
|
|
|
708
701
|
describe("query", () => {
|
|
709
702
|
it("should call saveMessages() on updates", async () => {
|
|
710
|
-
const
|
|
703
|
+
const repo = await mockRepo()
|
|
704
|
+
const fs = repo.nodeishFs
|
|
711
705
|
|
|
712
706
|
const settings: ProjectSettings = {
|
|
713
707
|
sourceLanguageTag: "en",
|
|
@@ -722,7 +716,6 @@ describe("functionality", () => {
|
|
|
722
716
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings))
|
|
723
717
|
|
|
724
718
|
await fs.mkdir("./resources")
|
|
725
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
726
719
|
|
|
727
720
|
const mockSaveFn = vi.fn()
|
|
728
721
|
|
|
@@ -885,7 +878,8 @@ describe("functionality", () => {
|
|
|
885
878
|
* - Might be slow for a large number of messages. The requirement hasn't popped up yet though.
|
|
886
879
|
*/
|
|
887
880
|
it("should pass all messages, regardless of which message changed, to saveMessages()", async () => {
|
|
888
|
-
const
|
|
881
|
+
const repo = await mockRepo()
|
|
882
|
+
const fs = repo.nodeishFs
|
|
889
883
|
|
|
890
884
|
const settings: ProjectSettings = {
|
|
891
885
|
sourceLanguageTag: "en",
|
|
@@ -898,7 +892,6 @@ describe("functionality", () => {
|
|
|
898
892
|
|
|
899
893
|
await fs.mkdir("./project.inlang", { recursive: true })
|
|
900
894
|
await fs.writeFile("./project.inlang/settings.json", JSON.stringify(settings))
|
|
901
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
902
895
|
|
|
903
896
|
const mockSaveFn = vi.fn()
|
|
904
897
|
|
|
@@ -938,10 +931,10 @@ describe("functionality", () => {
|
|
|
938
931
|
|
|
939
932
|
describe("lint", () => {
|
|
940
933
|
it.todo("should throw if lint reports are not initialized yet", async () => {
|
|
941
|
-
const
|
|
934
|
+
const repo = await mockRepo()
|
|
935
|
+
const fs = repo.nodeishFs
|
|
942
936
|
await fs.mkdir("/user/project", { recursive: true })
|
|
943
937
|
await fs.writeFile("/user/project/project.inlang.json", JSON.stringify(settings))
|
|
944
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
945
938
|
const project = await loadProject({
|
|
946
939
|
projectPath: "/user/project/project.inlang.json",
|
|
947
940
|
repo,
|
|
@@ -961,10 +954,10 @@ describe("functionality", () => {
|
|
|
961
954
|
languageTags: ["en"],
|
|
962
955
|
modules: ["lintRule.js"],
|
|
963
956
|
}
|
|
964
|
-
const
|
|
957
|
+
const repo = await mockRepo()
|
|
958
|
+
const fs = repo.nodeishFs
|
|
965
959
|
await fs.mkdir("/user/project.inlang", { recursive: true })
|
|
966
960
|
await fs.writeFile("/user/project.inlang/settings.json", JSON.stringify(settings))
|
|
967
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
968
961
|
const project = await loadProject({
|
|
969
962
|
projectPath: "/user/project.inlang",
|
|
970
963
|
repo,
|
|
@@ -979,7 +972,8 @@ describe("functionality", () => {
|
|
|
979
972
|
|
|
980
973
|
describe("watcher", () => {
|
|
981
974
|
it("changing files in resources should trigger callback of message query", async () => {
|
|
982
|
-
const
|
|
975
|
+
const repo = await mockRepo()
|
|
976
|
+
const fs = repo.nodeishFs
|
|
983
977
|
|
|
984
978
|
const messages = {
|
|
985
979
|
$schema: "https://inlang.com/schema/inlang-message-format",
|
|
@@ -1030,7 +1024,6 @@ describe("functionality", () => {
|
|
|
1030
1024
|
|
|
1031
1025
|
await fs.mkdir("./project.inlang", { recursive: true })
|
|
1032
1026
|
await fs.writeFile("./project.inlang/settings.json", JSON.stringify(settings))
|
|
1033
|
-
const repo = await openRepository("file://", { nodeishFs: fs })
|
|
1034
1027
|
|
|
1035
1028
|
// establish watcher
|
|
1036
1029
|
const project = await loadProject({
|
package/src/loadProject.ts
CHANGED
|
@@ -34,36 +34,12 @@ import { identifyProject } from "./telemetry/groupIdentify.js"
|
|
|
34
34
|
|
|
35
35
|
const settingsCompiler = TypeCompiler.Compile(ProjectSettings)
|
|
36
36
|
|
|
37
|
-
/**
|
|
38
|
-
* Creates an inlang instance.
|
|
39
|
-
*
|
|
40
|
-
* @param projectPath - Absolute path to the inlang settings file.
|
|
41
|
-
* @param @deprecated nodeishFs - Filesystem that implements the NodeishFilesystemSubset interface.
|
|
42
|
-
* @param _import - Use `_import` to pass a custom import function for testing,
|
|
43
|
-
* and supporting legacy resolvedModules such as CJS.
|
|
44
|
-
*
|
|
45
|
-
*/
|
|
46
|
-
export async function loadProject(args: {
|
|
47
|
-
projectPath: string
|
|
48
|
-
nodeishFs: Repository["nodeishFs"]
|
|
49
|
-
/**
|
|
50
|
-
* The app id is used to identify the app that is using the SDK.
|
|
51
|
-
*
|
|
52
|
-
* We use the app id to group events in telemetry to answer questions
|
|
53
|
-
* like "Which apps causes these errors?" or "Which apps are used more than others?".
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* appId: "app.inlang.badge"
|
|
57
|
-
*/
|
|
58
|
-
appId?: string
|
|
59
|
-
_import?: ImportFunction
|
|
60
|
-
}): Promise<InlangProject>
|
|
61
|
-
|
|
62
37
|
/**
|
|
63
38
|
* @param projectPath - Absolute path to the inlang settings file.
|
|
64
39
|
* @param repo - An instance of a lix repo as returned by `openRepository`.
|
|
65
40
|
* @param _import - Use `_import` to pass a custom import function for testing,
|
|
66
41
|
* and supporting legacy resolvedModules such as CJS.
|
|
42
|
+
* @param appId - The app id to use for telemetry e.g "app.inlang.badge"
|
|
67
43
|
*
|
|
68
44
|
*/
|
|
69
45
|
export async function loadProject(args: {
|
|
@@ -71,14 +47,6 @@ export async function loadProject(args: {
|
|
|
71
47
|
repo: Repository
|
|
72
48
|
appId?: string
|
|
73
49
|
_import?: ImportFunction
|
|
74
|
-
}): Promise<InlangProject>
|
|
75
|
-
|
|
76
|
-
export async function loadProject(args: {
|
|
77
|
-
projectPath: string
|
|
78
|
-
repo?: Repository
|
|
79
|
-
appId?: string
|
|
80
|
-
_import?: ImportFunction
|
|
81
|
-
nodeishFs?: Repository["nodeishFs"]
|
|
82
50
|
}): Promise<InlangProject> {
|
|
83
51
|
const projectPath = normalizePath(args.projectPath)
|
|
84
52
|
|
|
@@ -99,15 +67,7 @@ export async function loadProject(args: {
|
|
|
99
67
|
)
|
|
100
68
|
}
|
|
101
69
|
|
|
102
|
-
|
|
103
|
-
if (args.nodeishFs) {
|
|
104
|
-
// TODO: deprecate
|
|
105
|
-
fs = args.nodeishFs
|
|
106
|
-
} else if (args.repo) {
|
|
107
|
-
fs = args.repo.nodeishFs
|
|
108
|
-
} else {
|
|
109
|
-
throw new LoadProjectInvalidArgument(`Repo missing from arguments.`, { argument: "repo" })
|
|
110
|
-
}
|
|
70
|
+
const fs = args.repo.nodeishFs
|
|
111
71
|
|
|
112
72
|
const nodeishFs = createNodeishFsWithAbsolutePaths({
|
|
113
73
|
projectPath,
|