@inlang/sdk 0.24.1 → 0.26.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/adapter/solidAdapter.d.ts +1 -0
- package/dist/adapter/solidAdapter.d.ts.map +1 -1
- package/dist/adapter/solidAdapter.js +1 -0
- package/dist/adapter/solidAdapter.test.js +13 -14
- package/dist/api.d.ts +4 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/loadProject.d.ts +1 -24
- package/dist/loadProject.d.ts.map +1 -1
- package/dist/loadProject.js +19 -11
- package/dist/loadProject.test.js +58 -65
- package/dist/telemetry/groupIdentify.d.ts +13 -0
- package/dist/telemetry/groupIdentify.d.ts.map +1 -0
- package/dist/telemetry/groupIdentify.js +35 -0
- package/package.json +5 -5
- package/src/adapter/solidAdapter.test.ts +13 -14
- package/src/adapter/solidAdapter.ts +2 -0
- package/src/api.ts +5 -0
- package/src/loadProject.test.ts +59 -66
- package/src/loadProject.ts +12 -42
- package/src/telemetry/groupIdentify.ts +41 -0
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"),
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capture an event.
|
|
3
|
+
*
|
|
4
|
+
* - manually calling the PostHog API because the SDKs were not platform angostic (and generally bloated)
|
|
5
|
+
*/
|
|
6
|
+
export declare const identifyProject: (args: {
|
|
7
|
+
projectId: string;
|
|
8
|
+
/**
|
|
9
|
+
* Please use snake_case for property names.
|
|
10
|
+
*/
|
|
11
|
+
properties: Record<string, any>;
|
|
12
|
+
}) => Promise<void>;
|
|
13
|
+
//# sourceMappingURL=groupIdentify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"groupIdentify.d.ts","sourceRoot":"","sources":["../../src/telemetry/groupIdentify.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,eAAe,SAAgB;IAC3C,SAAS,EAAE,MAAM,CAAA;IACjB;;OAEG;IACH,UAAU,EAAE,OAAO,MAAM,EAAE,GAAG,CAAC,CAAA;CAC/B,kBA2BA,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ENV_VARIABLES } from "../env-variables/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Capture an event.
|
|
4
|
+
*
|
|
5
|
+
* - manually calling the PostHog API because the SDKs were not platform angostic (and generally bloated)
|
|
6
|
+
*/
|
|
7
|
+
export const identifyProject = async (args) => {
|
|
8
|
+
// do not send events if the token is not set
|
|
9
|
+
// (assuming this eases testing)
|
|
10
|
+
if (ENV_VARIABLES.PUBLIC_POSTHOG_TOKEN === undefined) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
await fetch("https://eu.posthog.com/capture/", {
|
|
15
|
+
method: "POST",
|
|
16
|
+
body: JSON.stringify({
|
|
17
|
+
api_key: ENV_VARIABLES.PUBLIC_POSTHOG_TOKEN,
|
|
18
|
+
event: "$groupidentify",
|
|
19
|
+
// id is "unknown" because no user information is available
|
|
20
|
+
distinct_id: "unknown",
|
|
21
|
+
properties: {
|
|
22
|
+
$group_type: "project",
|
|
23
|
+
$group_key: args.projectId,
|
|
24
|
+
$group_set: {
|
|
25
|
+
...args.properties,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
// TODO implement sentry logging
|
|
33
|
+
// do not console.log and avoid exposing internal errors to the user
|
|
34
|
+
}
|
|
35
|
+
};
|
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.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"@inlang/language-tag": "1.4.0",
|
|
30
30
|
"@inlang/message-lint-rule": "1.4.1",
|
|
31
31
|
"@inlang/module": "1.2.3",
|
|
32
|
+
"@inlang/message": "2.0.1",
|
|
32
33
|
"@inlang/plugin": "2.4.3",
|
|
33
|
-
"@inlang/result": "1.1.0",
|
|
34
34
|
"@inlang/project-settings": "2.2.1",
|
|
35
|
-
"@inlang/
|
|
35
|
+
"@inlang/result": "1.1.0",
|
|
36
|
+
"@inlang/translatable": "1.2.1",
|
|
36
37
|
"@lix-js/fs": "0.6.0",
|
|
37
|
-
"@lix-js/client": "0.7.0"
|
|
38
|
-
"@inlang/translatable": "1.2.1"
|
|
38
|
+
"@lix-js/client": "0.7.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",
|
|
@@ -13,6 +13,7 @@ export const solidAdapter = (
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
return {
|
|
16
|
+
id: project.id,
|
|
16
17
|
customApi: convert(project.customApi),
|
|
17
18
|
settings: convert(project.settings),
|
|
18
19
|
errors: convert(project.errors),
|
|
@@ -45,6 +46,7 @@ export const solidAdapter = (
|
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
export type InlangProjectWithSolidAdapter = {
|
|
49
|
+
id: InlangProject["id"]
|
|
48
50
|
customApi: () => ReturnType<InlangProject["customApi"]>
|
|
49
51
|
installed: {
|
|
50
52
|
plugins: () => ReturnType<InlangProject["installed"]["plugins"]>
|
package/src/api.ts
CHANGED
|
@@ -34,6 +34,11 @@ export type InstalledMessageLintRule = {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export type InlangProject = {
|
|
37
|
+
/**
|
|
38
|
+
* The project's id.
|
|
39
|
+
*/
|
|
40
|
+
// TODO #2063 make project id non-optional when every project is guaranteed to a project id
|
|
41
|
+
id?: string
|
|
37
42
|
installed: {
|
|
38
43
|
plugins: Subscribable<InstalledPlugin[]>
|
|
39
44
|
messageLintRules: Subscribable<InstalledMessageLintRule[]>
|