@inlang/paraglide-js 1.10.1 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -4
- package/dist/adapter-utils/index.js +20 -42
- package/dist/cli/index.js +45 -17
- package/dist/cli/utils.d.ts +1 -1
- package/dist/compiler/compilePattern.d.ts +3 -7
- package/dist/{index-f9c48389.js → index-9cf8cd4d.js} +42 -31
- package/dist/index.js +155 -148
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: "Getting Started"
|
|
3
|
-
description: "Learn how to install the ParaglideJS i18n library in your project"
|
|
4
|
-
---
|
|
5
1
|
[](https://inlang.com)
|
|
6
2
|
|
|
7
3
|
# Getting started
|
|
@@ -1,28 +1,24 @@
|
|
|
1
1
|
function negotiateLanguagePreferences(accept, availableLanguageTags) {
|
|
2
|
-
if (availableLanguageTags.length === 0)
|
|
3
|
-
return [];
|
|
4
2
|
accept ||= "*";
|
|
5
3
|
const acceptLanguageSpecs = parseAcceptLanguageHeader(accept);
|
|
6
4
|
const priorities = availableLanguageTags.map(
|
|
7
5
|
(languageTag, index) => getHighestLanguagePriority(languageTag, acceptLanguageSpecs, index)
|
|
8
6
|
);
|
|
9
|
-
return priorities.filter((prio) => prio.quality > 0).sort(
|
|
7
|
+
return priorities.filter((prio) => prio.quality > 0).sort(bySpecificity).sort(byQuality).map((priority) => priority.languageTag);
|
|
10
8
|
}
|
|
11
9
|
function parseAcceptLanguageHeader(acceptLanguage) {
|
|
12
|
-
|
|
13
|
-
const specs = acceptableLanguageDefinitions.map((dfn) => dfn.trim()).map((dfn, index) => parseLanguage(dfn, index)).filter((maybeSpec) => Boolean(maybeSpec));
|
|
14
|
-
return specs;
|
|
10
|
+
return acceptLanguage.split(",").map((dfn) => dfn.trim()).map((dfn, index) => parseLanguage(dfn, index)).filter((maybeSpec) => Boolean(maybeSpec));
|
|
15
11
|
}
|
|
16
|
-
function parseLanguage(
|
|
12
|
+
function parseLanguage(languageTag, index) {
|
|
17
13
|
const LANGUAGE_REGEXP = /^\s*([^\s\-;]+)(?:-([^\s;]+))?\s*(?:;(.*))?$/;
|
|
18
|
-
const match = LANGUAGE_REGEXP.exec(
|
|
14
|
+
const match = LANGUAGE_REGEXP.exec(languageTag);
|
|
19
15
|
if (!match)
|
|
20
16
|
return void 0;
|
|
21
17
|
const [, prefix, suffix, qualityMatch] = match;
|
|
22
18
|
if (!prefix)
|
|
23
|
-
throw new Error(`Invalid language tag: ${
|
|
19
|
+
throw new Error(`Invalid language tag: ${languageTag}`);
|
|
24
20
|
const full = suffix ? `${prefix}-${suffix}` : prefix;
|
|
25
|
-
const quality =
|
|
21
|
+
const quality = parseQuality(qualityMatch ?? "") ?? 1;
|
|
26
22
|
return {
|
|
27
23
|
prefix,
|
|
28
24
|
suffix,
|
|
@@ -32,61 +28,43 @@ function parseLanguage(str, index) {
|
|
|
32
28
|
};
|
|
33
29
|
}
|
|
34
30
|
function parseQuality(qualityMatch) {
|
|
35
|
-
|
|
36
|
-
for (const param of params) {
|
|
37
|
-
const [key, value] = param.split("=");
|
|
38
|
-
if (key === "q" && value)
|
|
39
|
-
return parseFloat(value);
|
|
40
|
-
}
|
|
41
|
-
return void 0;
|
|
31
|
+
return qualityMatch.split(";").map((param) => param.split("=")).filter((p) => p[0] == "q" && !!p[1]).map(([, value]) => parseFloat(value))[0];
|
|
42
32
|
}
|
|
43
|
-
function getHighestLanguagePriority(
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
function getHighestLanguagePriority(languageTag, acceptableLanguages, index) {
|
|
34
|
+
const priorities = acceptableLanguages.map((spec) => calculatePriority(languageTag, spec, index)).filter((prio) => Boolean(prio));
|
|
35
|
+
const highestPriority = priorities.sort(bySpecificity)[0] || {
|
|
36
|
+
languageTag,
|
|
46
37
|
index: 0,
|
|
47
38
|
order: -1,
|
|
48
39
|
quality: 0,
|
|
49
40
|
specificity: 0
|
|
50
41
|
};
|
|
51
|
-
for (const acceptableLanguage of acceptableLanguages) {
|
|
52
|
-
const priority = calculatePriority(availableLanguageTag, acceptableLanguage, index);
|
|
53
|
-
if (!priority)
|
|
54
|
-
continue;
|
|
55
|
-
if (
|
|
56
|
-
//compare the calculated priority to the highest priority ignoring quality.
|
|
57
|
-
(highestPriority.specificity - priority.specificity || highestPriority.quality - priority.quality || highestPriority.order - priority.order) < 0
|
|
58
|
-
) {
|
|
59
|
-
highestPriority = priority;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
42
|
return highestPriority;
|
|
63
43
|
}
|
|
64
|
-
function calculatePriority(
|
|
65
|
-
const parsed = parseLanguage(
|
|
44
|
+
function calculatePriority(languageTag, spec, index) {
|
|
45
|
+
const parsed = parseLanguage(languageTag, 0);
|
|
66
46
|
if (!parsed)
|
|
67
47
|
return void 0;
|
|
68
48
|
let specificity = 0;
|
|
69
49
|
if (spec.full.toLowerCase() === parsed.full.toLowerCase()) {
|
|
70
|
-
specificity
|
|
50
|
+
specificity = 4;
|
|
71
51
|
} else if (spec.prefix.toLowerCase() === parsed.full.toLowerCase()) {
|
|
72
|
-
specificity
|
|
52
|
+
specificity = 2;
|
|
73
53
|
} else if (spec.full.toLowerCase() === parsed.prefix.toLowerCase()) {
|
|
74
|
-
specificity
|
|
54
|
+
specificity = 1;
|
|
75
55
|
}
|
|
76
|
-
if (specificity === 0 && spec.full !== "*")
|
|
56
|
+
if (specificity === 0 && spec.full !== "*")
|
|
77
57
|
return void 0;
|
|
78
|
-
}
|
|
79
58
|
return {
|
|
80
|
-
languageTag
|
|
59
|
+
languageTag,
|
|
81
60
|
index,
|
|
82
61
|
order: spec.index,
|
|
83
62
|
quality: spec.quality,
|
|
84
63
|
specificity
|
|
85
64
|
};
|
|
86
65
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
66
|
+
const byQuality = (a, b) => b.quality - a.quality;
|
|
67
|
+
const bySpecificity = (a, b) => b.specificity - a.specificity || a.order - b.order || a.index - b.index;
|
|
90
68
|
function detectLanguageFromPath({
|
|
91
69
|
path,
|
|
92
70
|
availableLanguageTags,
|
package/dist/cli/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var _a, _b;
|
|
2
2
|
import { Command } from "commander";
|
|
3
|
-
import { p as pattern,
|
|
3
|
+
import { p as pattern, b as assertValidProjectPath, c as getDefaultExportFromCjs, g as getDirname, a as getBasename, d as parseOrigin, t as transformRemote, e as commonjsGlobal, f as getAugmentedNamespace, h as parseLixUri, w as withProxy, compile, writeOutput, Logger, l as loadProject, classifyProjectErrors, i as typebox, n as normalizePath$2, v as value, j as telemetry, k as pathExists$1, m as findPackageJson } from "../index.js";
|
|
4
4
|
import dedent from "dedent";
|
|
5
5
|
import nodeFsPromises from "node:fs/promises";
|
|
6
6
|
import * as nodePath from "node:path";
|
|
@@ -38,7 +38,7 @@ const defaultProjectSettings = {
|
|
|
38
38
|
async function createNewProject(args) {
|
|
39
39
|
assertValidProjectPath(args.projectPath);
|
|
40
40
|
const nodeishFs = args.repo.nodeishFs;
|
|
41
|
-
if (await
|
|
41
|
+
if (await directoryExists(args.projectPath, nodeishFs)) {
|
|
42
42
|
throw new Error(`projectPath already exists, received "${args.projectPath}"`);
|
|
43
43
|
}
|
|
44
44
|
const settingsText = JSON.stringify(args.projectSettings ?? defaultProjectSettings, void 0, 2);
|
|
@@ -49,6 +49,18 @@ async function createNewProject(args) {
|
|
|
49
49
|
nodeishFs.mkdir(`${args.projectPath}/cache/modules`, { recursive: true })
|
|
50
50
|
]);
|
|
51
51
|
}
|
|
52
|
+
async function directoryExists(filePath, nodeishFs) {
|
|
53
|
+
try {
|
|
54
|
+
const stat = await nodeishFs.stat(filePath);
|
|
55
|
+
return stat.isDirectory();
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (error && "code" in error && error.code === "ENOENT") {
|
|
58
|
+
return false;
|
|
59
|
+
} else {
|
|
60
|
+
throw new Error(`Failed to check if path exists: ${error}`, { cause: error });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
52
64
|
var AsyncLock$1 = function(opts) {
|
|
53
65
|
opts = opts || {};
|
|
54
66
|
this.Promise = opts.Promise || Promise;
|
|
@@ -6322,7 +6334,7 @@ function compareRefNames(a, b) {
|
|
|
6322
6334
|
return tmp;
|
|
6323
6335
|
}
|
|
6324
6336
|
const memo = /* @__PURE__ */ new Map();
|
|
6325
|
-
function normalizePath
|
|
6337
|
+
function normalizePath(path) {
|
|
6326
6338
|
let normalizedPath = memo.get(path);
|
|
6327
6339
|
if (!normalizedPath) {
|
|
6328
6340
|
normalizedPath = normalizePathInternal(path);
|
|
@@ -6347,7 +6359,7 @@ function normalizePathInternal(path) {
|
|
|
6347
6359
|
return path;
|
|
6348
6360
|
}
|
|
6349
6361
|
function join$2(...parts) {
|
|
6350
|
-
return normalizePath
|
|
6362
|
+
return normalizePath(parts.map(normalizePath).join("/"));
|
|
6351
6363
|
}
|
|
6352
6364
|
const num = (val) => {
|
|
6353
6365
|
val = val.toLowerCase();
|
|
@@ -6434,7 +6446,7 @@ const lower = (text) => {
|
|
|
6434
6446
|
const getPath = (section, subsection, name) => {
|
|
6435
6447
|
return [lower(section), subsection, lower(name)].filter((a) => a != null).join(".");
|
|
6436
6448
|
};
|
|
6437
|
-
const normalizePath$1
|
|
6449
|
+
const normalizePath$1 = (path) => {
|
|
6438
6450
|
const pathSegments = path.split(".");
|
|
6439
6451
|
const section = pathSegments.shift();
|
|
6440
6452
|
const name = pathSegments.pop();
|
|
@@ -6479,7 +6491,7 @@ class GitConfig {
|
|
|
6479
6491
|
return new GitConfig(text);
|
|
6480
6492
|
}
|
|
6481
6493
|
async get(path, getall = false) {
|
|
6482
|
-
const normalizedPath = normalizePath$1
|
|
6494
|
+
const normalizedPath = normalizePath$1(path).path;
|
|
6483
6495
|
const allValues = this.parsedConfig.filter((config) => config.path === normalizedPath).map(({ section, name, value: value2 }) => {
|
|
6484
6496
|
const fn = schema$1[section] && schema$1[section][name];
|
|
6485
6497
|
return fn ? fn(value2) : value2;
|
|
@@ -6507,7 +6519,7 @@ class GitConfig {
|
|
|
6507
6519
|
name,
|
|
6508
6520
|
path: normalizedPath,
|
|
6509
6521
|
sectionPath
|
|
6510
|
-
} = normalizePath$1
|
|
6522
|
+
} = normalizePath$1(path);
|
|
6511
6523
|
const configIndex = findLastIndex(
|
|
6512
6524
|
this.parsedConfig,
|
|
6513
6525
|
(config) => config.path === normalizedPath
|
|
@@ -15430,7 +15442,7 @@ var index$1 = {
|
|
|
15430
15442
|
_normalizeCommitterObject: normalizeCommitterObject,
|
|
15431
15443
|
_normalizeMode: normalizeMode,
|
|
15432
15444
|
_normalizeNewlines: normalizeNewlines,
|
|
15433
|
-
_normalizePath: normalizePath
|
|
15445
|
+
_normalizePath: normalizePath,
|
|
15434
15446
|
_normalizeStats: normalizeStats,
|
|
15435
15447
|
_outdent: outdent,
|
|
15436
15448
|
_padHex: padHex$1,
|
|
@@ -15636,11 +15648,11 @@ const {
|
|
|
15636
15648
|
STAGE,
|
|
15637
15649
|
isIgnored
|
|
15638
15650
|
} = index$1;
|
|
15639
|
-
function
|
|
15651
|
+
function isoNormalizePath(path) {
|
|
15640
15652
|
return path.replace(/\/\.\//g, "/").replace(/\/{2,}/g, "/").replace(/^\/\.$/, "/").replace(/^\.\/$/, ".").replace(/^\.\//, "").replace(/\/\.$/, "").replace(/(.+)\/$/, "$1").replace(/^$/, ".");
|
|
15641
15653
|
}
|
|
15642
15654
|
function join$1(...parts) {
|
|
15643
|
-
return
|
|
15655
|
+
return isoNormalizePath(parts.map(isoNormalizePath).join("/"));
|
|
15644
15656
|
}
|
|
15645
15657
|
async function statusList(ctx, state, statusArg) {
|
|
15646
15658
|
return await _statusList({
|
|
@@ -23734,7 +23746,7 @@ function makeGithubClient({ gitHubProxyUrl } = {}) {
|
|
|
23734
23746
|
}
|
|
23735
23747
|
async function repoContext(url, args) {
|
|
23736
23748
|
var _a2;
|
|
23737
|
-
const rawFs = args.nodeishFs || (await import("../index-
|
|
23749
|
+
const rawFs = args.nodeishFs || (await import("../index-9cf8cd4d.js")).createNodeishMemoryFs();
|
|
23738
23750
|
const author = args.author;
|
|
23739
23751
|
let debug = args.debug || false;
|
|
23740
23752
|
if (!url || !url.startsWith("file://") && !url.startsWith("https://") && !url.startsWith("http://")) {
|
|
@@ -32314,7 +32326,7 @@ async function isInWorkspaceRecommendation(fs, workingDirectory) {
|
|
|
32314
32326
|
return (extensions == null ? void 0 : extensions.recommendations.includes("inlang.vs-code-extension")) || false;
|
|
32315
32327
|
}
|
|
32316
32328
|
async function isAdopted$1(args) {
|
|
32317
|
-
return isInWorkspaceRecommendation(args.fs, args.workingDirectory);
|
|
32329
|
+
return await isInWorkspaceRecommendation(args.fs, args.workingDirectory);
|
|
32318
32330
|
}
|
|
32319
32331
|
async function add$1(args) {
|
|
32320
32332
|
await addRecommendationToWorkspace(args.fs, args.workingDirectory);
|
|
@@ -32359,7 +32371,7 @@ const maybeChangeTsConfig = async (ctx) => {
|
|
|
32359
32371
|
};
|
|
32360
32372
|
const maybeChangeTsConfigAllowJs = async (ctx) => {
|
|
32361
32373
|
var _a2, _b2;
|
|
32362
|
-
if (await pathExists$
|
|
32374
|
+
if (await pathExists$1("./tsconfig.json", ctx.repo.nodeishFs) === false) {
|
|
32363
32375
|
return ctx;
|
|
32364
32376
|
}
|
|
32365
32377
|
const file = await ctx.repo.nodeishFs.readFile("./tsconfig.json", { encoding: "utf-8" });
|
|
@@ -32407,7 +32419,7 @@ const maybeChangeTsConfigAllowJs = async (ctx) => {
|
|
|
32407
32419
|
};
|
|
32408
32420
|
const maybeChangeTsConfigModuleResolution = async (ctx) => {
|
|
32409
32421
|
var _a2, _b2, _c;
|
|
32410
|
-
if (await pathExists$
|
|
32422
|
+
if (await pathExists$1("./tsconfig.json", ctx.repo.nodeishFs) === false) {
|
|
32411
32423
|
return ctx;
|
|
32412
32424
|
}
|
|
32413
32425
|
const file = await ctx.repo.nodeishFs.readFile("./tsconfig.json", { encoding: "utf-8" });
|
|
@@ -34555,6 +34567,22 @@ const GitHubActionsWorkflow = typebox.Type.Object({
|
|
|
34555
34567
|
jobs: typebox.Type.Record(typebox.Type.String(), GitHubActionJob)
|
|
34556
34568
|
// Use Record to define an object with string keys and GitHubActionJob values
|
|
34557
34569
|
});
|
|
34570
|
+
async function shouldRecommend(args) {
|
|
34571
|
+
try {
|
|
34572
|
+
await args.fs.stat(".git/config");
|
|
34573
|
+
const configData = await args.fs.readFile(".git/config", { encoding: "utf-8" });
|
|
34574
|
+
const match = configData.match(/url = (.+)/);
|
|
34575
|
+
const remoteOriginUrl = match ? match[1] : void 0;
|
|
34576
|
+
const isNinjaAdopted = await isAdopted({ fs: args.fs });
|
|
34577
|
+
if (remoteOriginUrl && remoteOriginUrl.includes("github.com") && !isNinjaAdopted) {
|
|
34578
|
+
return true;
|
|
34579
|
+
} else {
|
|
34580
|
+
return false;
|
|
34581
|
+
}
|
|
34582
|
+
} catch (error) {
|
|
34583
|
+
return false;
|
|
34584
|
+
}
|
|
34585
|
+
}
|
|
34558
34586
|
async function isAdopted(args) {
|
|
34559
34587
|
async function searchWorkflowFiles(directoryPath, depth = 0) {
|
|
34560
34588
|
if (depth > 3) {
|
|
@@ -34647,7 +34675,7 @@ const maybeAddNinja = async (ctx) => {
|
|
|
34647
34675
|
if (response !== true)
|
|
34648
34676
|
return ctx;
|
|
34649
34677
|
try {
|
|
34650
|
-
if (!await
|
|
34678
|
+
if (!await shouldRecommend({ fs: ctx.repo.nodeishFs })) {
|
|
34651
34679
|
await add({ fs: ctx.repo.nodeishFs });
|
|
34652
34680
|
telemetry.capture({ event: "PARAGLIDE JS init added Ninja" });
|
|
34653
34681
|
ctx.logger.success("Added the 🥷 Ninja Github Action for linting translations");
|
|
@@ -34749,7 +34777,7 @@ const addParaglideJsToDevDependencies = async (ctx) => {
|
|
|
34749
34777
|
const ctx1 = await updatePackageJson({
|
|
34750
34778
|
devDependencies: async (devDeps) => ({
|
|
34751
34779
|
...devDeps,
|
|
34752
|
-
"@inlang/paraglide-js": "1.
|
|
34780
|
+
"@inlang/paraglide-js": "1.11.0"
|
|
34753
34781
|
})
|
|
34754
34782
|
})(ctx);
|
|
34755
34783
|
ctx.logger.success("Added @inlang/paraglide-js to the devDependencies in package.json.");
|
|
@@ -34824,7 +34852,7 @@ async function promtStack() {
|
|
|
34824
34852
|
initial: "other"
|
|
34825
34853
|
});
|
|
34826
34854
|
}
|
|
34827
|
-
const cli = new Command().name("paraglide-js").addCommand(compileCommand).addCommand(initCommand).showHelpAfterError().version("1.
|
|
34855
|
+
const cli = new Command().name("paraglide-js").addCommand(compileCommand).addCommand(initCommand).showHelpAfterError().version("1.11.0");
|
|
34828
34856
|
export {
|
|
34829
34857
|
defaults as Defaults,
|
|
34830
34858
|
GitPackIndex as G,
|
package/dist/cli/utils.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export type CliStep<In extends object, Out> = <Ctx extends In>(ctx: Ctx) => Prom
|
|
|
29
29
|
*/
|
|
30
30
|
export declare const prompt: typeof consola.prompt;
|
|
31
31
|
export declare const promptSelection: <T extends string>(message: string, options?: {
|
|
32
|
-
initial?: T
|
|
32
|
+
initial?: T;
|
|
33
33
|
options: {
|
|
34
34
|
label: string;
|
|
35
35
|
value: T;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Pattern } from '@inlang/sdk';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Compiles a pattern into a template literal string.
|
|
3
5
|
*
|
|
@@ -5,13 +7,7 @@
|
|
|
5
7
|
* const { compiled, params } = compilePattern([{ type: "Text", value: "Hello " }, { type: "VariableReference", name: "name" }])
|
|
6
8
|
* >> compiled === "`Hello ${params.name}`"
|
|
7
9
|
*/
|
|
8
|
-
export declare const compilePattern: (pattern:
|
|
9
|
-
type: "Text";
|
|
10
|
-
value: string;
|
|
11
|
-
} | {
|
|
12
|
-
type: "VariableReference";
|
|
13
|
-
name: string;
|
|
14
|
-
})[]) => {
|
|
10
|
+
export declare const compilePattern: (pattern: Pattern) => {
|
|
15
11
|
params: Record<string, "NonNullable<unknown>">;
|
|
16
12
|
compiled: string;
|
|
17
13
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import { b } from "./index.js";
|
|
1
|
+
import { n as normalizePath, g as getDirname, a as getBasename } from "./index.js";
|
|
3
2
|
import "dedent";
|
|
4
3
|
import "tty";
|
|
5
4
|
import "util";
|
|
@@ -62,27 +61,31 @@ function createNodeishMemoryFs() {
|
|
|
62
61
|
});
|
|
63
62
|
const listeners = /* @__PURE__ */ new Set();
|
|
64
63
|
async function stat(path) {
|
|
65
|
-
path =
|
|
64
|
+
path = normalizePath(path, { trailingSlash: "always", leadingSlash: "always" });
|
|
66
65
|
const stats = state.fsStats.get(path);
|
|
67
|
-
if (stats === void 0)
|
|
66
|
+
if (stats === void 0) {
|
|
68
67
|
throw new FilesystemError("ENOENT", path, "stat");
|
|
69
|
-
|
|
68
|
+
}
|
|
69
|
+
if (stats.symlinkTarget) {
|
|
70
70
|
return stat(stats.symlinkTarget);
|
|
71
|
+
}
|
|
71
72
|
return Object.assign({}, stats);
|
|
72
73
|
}
|
|
73
74
|
async function lstat(path) {
|
|
74
|
-
path =
|
|
75
|
+
path = normalizePath(path, { trailingSlash: "always", leadingSlash: "always" });
|
|
75
76
|
const stats = state.fsStats.get(path);
|
|
76
|
-
if (stats === void 0)
|
|
77
|
+
if (stats === void 0) {
|
|
77
78
|
throw new FilesystemError("ENOENT", path, "lstat");
|
|
78
|
-
|
|
79
|
+
}
|
|
80
|
+
if (!stats.symlinkTarget) {
|
|
79
81
|
return stat(path);
|
|
82
|
+
}
|
|
80
83
|
return Object.assign({}, stats);
|
|
81
84
|
}
|
|
82
85
|
return {
|
|
83
86
|
_state: state,
|
|
84
87
|
_createPlaceholder: async function(path, options) {
|
|
85
|
-
path =
|
|
88
|
+
path = normalizePath(path, { trailingSlash: "always", leadingSlash: "always" });
|
|
86
89
|
const dirName = getDirname(path);
|
|
87
90
|
const baseName = getBasename(path);
|
|
88
91
|
let parentDir = state.fsMap.get(dirName);
|
|
@@ -106,7 +109,7 @@ function createNodeishMemoryFs() {
|
|
|
106
109
|
state.fsMap.set(path, { placeholder: true });
|
|
107
110
|
},
|
|
108
111
|
_isPlaceholder: function(path) {
|
|
109
|
-
path =
|
|
112
|
+
path = normalizePath(path, { trailingSlash: "always", leadingSlash: "always" });
|
|
110
113
|
const entry = state.fsMap.get(path);
|
|
111
114
|
if (entry && "placeholder" in entry) {
|
|
112
115
|
return true;
|
|
@@ -114,18 +117,21 @@ function createNodeishMemoryFs() {
|
|
|
114
117
|
return false;
|
|
115
118
|
},
|
|
116
119
|
writeFile: async function(path, data, options) {
|
|
117
|
-
path =
|
|
120
|
+
path = normalizePath(path, { trailingSlash: "always", leadingSlash: "always" });
|
|
118
121
|
const dirName = getDirname(path);
|
|
119
122
|
const baseName = getBasename(path);
|
|
120
123
|
const parentDir = state.fsMap.get(dirName);
|
|
121
124
|
if (!(parentDir instanceof Set))
|
|
122
125
|
throw new FilesystemError("ENOENT", path, "writeFile");
|
|
126
|
+
let inodeData;
|
|
123
127
|
if (typeof data === "string") {
|
|
124
|
-
|
|
128
|
+
inodeData = Buffer.from(new TextEncoder().encode(data));
|
|
125
129
|
} else if (!(data instanceof Uint8Array)) {
|
|
126
130
|
throw new FilesystemError('The "data" argument must be of type string/Uint8Array', data, "readFile");
|
|
127
131
|
} else if (!Buffer.isBuffer(data)) {
|
|
128
|
-
|
|
132
|
+
inodeData = Buffer.from(data);
|
|
133
|
+
} else {
|
|
134
|
+
inodeData = data;
|
|
129
135
|
}
|
|
130
136
|
parentDir.add(baseName);
|
|
131
137
|
newStatEntry({
|
|
@@ -134,7 +140,7 @@ function createNodeishMemoryFs() {
|
|
|
134
140
|
kind: 0,
|
|
135
141
|
modeBits: (options == null ? void 0 : options.mode) ?? 420
|
|
136
142
|
});
|
|
137
|
-
state.fsMap.set(path,
|
|
143
|
+
state.fsMap.set(path, inodeData);
|
|
138
144
|
for (const listener of listeners) {
|
|
139
145
|
listener({ eventType: "rename", filename: dirName + baseName });
|
|
140
146
|
}
|
|
@@ -144,7 +150,7 @@ function createNodeishMemoryFs() {
|
|
|
144
150
|
// a string or a Uint8Array based on the options.
|
|
145
151
|
readFile: async function(path, options) {
|
|
146
152
|
const decoder = new TextDecoder();
|
|
147
|
-
path =
|
|
153
|
+
path = normalizePath(path, { trailingSlash: "always", leadingSlash: "always" });
|
|
148
154
|
const file = state.fsMap.get(path);
|
|
149
155
|
if (file instanceof Set)
|
|
150
156
|
throw new FilesystemError("EISDIR", path, "readFile");
|
|
@@ -157,7 +163,7 @@ function createNodeishMemoryFs() {
|
|
|
157
163
|
return decoder.decode(file);
|
|
158
164
|
},
|
|
159
165
|
readdir: async function(path) {
|
|
160
|
-
path =
|
|
166
|
+
path = normalizePath(path, { trailingSlash: "always", leadingSlash: "always" });
|
|
161
167
|
const dir = state.fsMap.get(path);
|
|
162
168
|
if (dir instanceof Set)
|
|
163
169
|
return [...dir.keys()];
|
|
@@ -166,7 +172,7 @@ function createNodeishMemoryFs() {
|
|
|
166
172
|
throw new FilesystemError("ENOTDIR", path, "readdir");
|
|
167
173
|
},
|
|
168
174
|
mkdir: async function mkdir(path, options) {
|
|
169
|
-
path =
|
|
175
|
+
path = normalizePath(path, { trailingSlash: "always", leadingSlash: "always" });
|
|
170
176
|
const dirName = getDirname(path);
|
|
171
177
|
const baseName = getBasename(path);
|
|
172
178
|
const parentDir = state.fsMap.get(dirName);
|
|
@@ -196,13 +202,14 @@ function createNodeishMemoryFs() {
|
|
|
196
202
|
} else if (options == null ? void 0 : options.recursive) {
|
|
197
203
|
const parent = getDirname(path);
|
|
198
204
|
const parentRes = await mkdir(parent, options);
|
|
199
|
-
await mkdir(path,
|
|
205
|
+
await mkdir(path, { recursive: false }).catch(() => {
|
|
206
|
+
});
|
|
200
207
|
return parentRes;
|
|
201
208
|
}
|
|
202
209
|
throw new FilesystemError("ENOENT", path, "mkdir");
|
|
203
210
|
},
|
|
204
211
|
rm: async function rm(path, options) {
|
|
205
|
-
path =
|
|
212
|
+
path = normalizePath(path, { trailingSlash: "always", leadingSlash: "always" });
|
|
206
213
|
const dirName = getDirname(path);
|
|
207
214
|
const baseName = getBasename(path);
|
|
208
215
|
const target = state.fsMap.get(path);
|
|
@@ -241,7 +248,7 @@ function createNodeishMemoryFs() {
|
|
|
241
248
|
* @throws {"ENOENT" | WatchAbortedError} // TODO: move to lix error classes FileDoesNotExistError
|
|
242
249
|
*/
|
|
243
250
|
watch: function(path, options) {
|
|
244
|
-
path =
|
|
251
|
+
path = normalizePath(path, { trailingSlash: "always", leadingSlash: "always" });
|
|
245
252
|
const watchName = getBasename(path);
|
|
246
253
|
const watchDir = getDirname(path);
|
|
247
254
|
const watchPath = watchName === "/" ? watchDir : watchDir + watchName;
|
|
@@ -308,7 +315,7 @@ function createNodeishMemoryFs() {
|
|
|
308
315
|
return asyncIterator();
|
|
309
316
|
},
|
|
310
317
|
rmdir: async function(path) {
|
|
311
|
-
path =
|
|
318
|
+
path = normalizePath(path, { trailingSlash: "always", leadingSlash: "always" });
|
|
312
319
|
const dirName = getDirname(path);
|
|
313
320
|
const baseName = getBasename(path);
|
|
314
321
|
const target = state.fsMap.get(path);
|
|
@@ -330,9 +337,13 @@ function createNodeishMemoryFs() {
|
|
|
330
337
|
}
|
|
331
338
|
},
|
|
332
339
|
symlink: async function(target, path) {
|
|
333
|
-
path =
|
|
334
|
-
|
|
335
|
-
const
|
|
340
|
+
path = normalizePath(path, { trailingSlash: "always", leadingSlash: "always" });
|
|
341
|
+
const rawTarget = target.startsWith("/") ? target : `${path}/../${target}`;
|
|
342
|
+
const targetWithTrailing = normalizePath(rawTarget, {
|
|
343
|
+
trailingSlash: "always",
|
|
344
|
+
leadingSlash: "always"
|
|
345
|
+
});
|
|
346
|
+
const targetInode = state.fsMap.get(targetWithTrailing);
|
|
336
347
|
const parentDir = state.fsMap.get(getDirname(path));
|
|
337
348
|
if (state.fsMap.get(path)) {
|
|
338
349
|
throw new FilesystemError("EEXIST", path, "symlink", target);
|
|
@@ -352,11 +363,11 @@ function createNodeishMemoryFs() {
|
|
|
352
363
|
stats: state.fsStats,
|
|
353
364
|
kind: 2,
|
|
354
365
|
modeBits: 511,
|
|
355
|
-
target
|
|
366
|
+
target: rawTarget
|
|
356
367
|
});
|
|
357
368
|
},
|
|
358
369
|
unlink: async function(path) {
|
|
359
|
-
path =
|
|
370
|
+
path = normalizePath(path, { trailingSlash: "always", leadingSlash: "always" });
|
|
360
371
|
const targetStats = state.fsStats.get(path);
|
|
361
372
|
const target = state.fsMap.get(path);
|
|
362
373
|
const parentDir = state.fsMap.get(getDirname(path));
|
|
@@ -373,7 +384,7 @@ function createNodeishMemoryFs() {
|
|
|
373
384
|
state.fsMap.delete(path);
|
|
374
385
|
},
|
|
375
386
|
readlink: async function(path) {
|
|
376
|
-
path =
|
|
387
|
+
path = normalizePath(path, { trailingSlash: "always", leadingSlash: "always" });
|
|
377
388
|
const linkStats = await lstat(path);
|
|
378
389
|
if (linkStats === void 0) {
|
|
379
390
|
throw new FilesystemError("ENOENT", path, "readlink");
|
|
@@ -389,9 +400,10 @@ function createNodeishMemoryFs() {
|
|
|
389
400
|
function newStatEntry({ path, stats, kind, modeBits, target, oid, rootHash }) {
|
|
390
401
|
const currentTime = Date.now();
|
|
391
402
|
const _kind = kind;
|
|
392
|
-
const
|
|
403
|
+
const targetPath = normalizePath(path, { trailingSlash: "always", leadingSlash: "always" });
|
|
404
|
+
const oldStats = stats.get(targetPath);
|
|
393
405
|
const mtimeMs = Math.floor(currentTime / 1e3) === ((oldStats == null ? void 0 : oldStats.mtimeMs) && Math.floor((oldStats == null ? void 0 : oldStats.mtimeMs) / 1e3)) ? currentTime + 1e3 : currentTime;
|
|
394
|
-
stats.set(
|
|
406
|
+
stats.set(targetPath, {
|
|
395
407
|
ctimeMs: (oldStats == null ? void 0 : oldStats.ctimeMs) || currentTime,
|
|
396
408
|
mtimeMs,
|
|
397
409
|
dev: 0,
|
|
@@ -415,6 +427,5 @@ export {
|
|
|
415
427
|
createNodeishMemoryFs,
|
|
416
428
|
getBasename,
|
|
417
429
|
getDirname,
|
|
418
|
-
|
|
419
|
-
b as normalizePath
|
|
430
|
+
normalizePath
|
|
420
431
|
};
|
package/dist/index.js
CHANGED
|
@@ -5169,6 +5169,7 @@ const resolveMessageLintRules = (args) => {
|
|
|
5169
5169
|
if (value$1.Value.Check(MessageLintRule, rule) === false) {
|
|
5170
5170
|
const errors2 = [...value$1.Value.Errors(MessageLintRule, rule)];
|
|
5171
5171
|
result.errors.push(new MessageLintRuleIsInvalidError({
|
|
5172
|
+
// @ts-ignore
|
|
5172
5173
|
id: rule.id,
|
|
5173
5174
|
errors: errors2
|
|
5174
5175
|
}));
|
|
@@ -5192,28 +5193,37 @@ async function readModuleFromCache(moduleURI, projectPath, readFile) {
|
|
|
5192
5193
|
async function writeModuleToCache(moduleURI, moduleContent, projectPath, writeFile, mkdir) {
|
|
5193
5194
|
const moduleHash = escape(moduleURI);
|
|
5194
5195
|
const filePath = projectPath + `/cache/modules/${moduleHash}`;
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
5198
|
-
|
|
5199
|
-
|
|
5200
|
-
|
|
5201
|
-
|
|
5196
|
+
const writeFileResult = await tryCatch(() => writeFile(filePath, moduleContent));
|
|
5197
|
+
if (writeFileResult.error) {
|
|
5198
|
+
const dirPath = projectPath + `/cache/modules`;
|
|
5199
|
+
const createDirResult = await tryCatch(() => mkdir(dirPath, { recursive: true }));
|
|
5200
|
+
if (createDirResult.error && createDirResult.error.code !== "EEXIST")
|
|
5201
|
+
throw new Error("[sdk:module-cacke] failed to create cache-directory. Path: " + dirPath, {
|
|
5202
|
+
cause: createDirResult.error
|
|
5203
|
+
});
|
|
5204
|
+
const writeFileResult2 = await tryCatch(() => writeFile(filePath, moduleContent));
|
|
5205
|
+
if (writeFileResult2.error)
|
|
5206
|
+
throw new Error("[sdk:module-cacke] failed to write cache-file. Path: " + filePath, {
|
|
5207
|
+
cause: writeFileResult2.error
|
|
5208
|
+
});
|
|
5202
5209
|
}
|
|
5203
5210
|
}
|
|
5204
5211
|
function withCache(moduleLoader, projectPath, nodeishFs) {
|
|
5205
5212
|
return async (uri) => {
|
|
5206
5213
|
const cachePromise = readModuleFromCache(uri, projectPath, nodeishFs.readFile);
|
|
5207
|
-
const
|
|
5208
|
-
if (
|
|
5214
|
+
const loaderResult = await tryCatch(async () => await moduleLoader(uri));
|
|
5215
|
+
if (loaderResult.error) {
|
|
5209
5216
|
const cacheResult = await cachePromise;
|
|
5210
5217
|
if (!cacheResult.error)
|
|
5211
5218
|
return cacheResult.data;
|
|
5212
5219
|
else
|
|
5213
|
-
throw
|
|
5220
|
+
throw loaderResult.error;
|
|
5214
5221
|
} else {
|
|
5215
|
-
const moduleAsText =
|
|
5216
|
-
|
|
5222
|
+
const moduleAsText = loaderResult.data;
|
|
5223
|
+
try {
|
|
5224
|
+
await writeModuleToCache(uri, moduleAsText, projectPath, nodeishFs.writeFile, nodeishFs.mkdir);
|
|
5225
|
+
} catch (error) {
|
|
5226
|
+
}
|
|
5217
5227
|
return moduleAsText;
|
|
5218
5228
|
}
|
|
5219
5229
|
};
|
|
@@ -6837,7 +6847,7 @@ function requireNode() {
|
|
|
6837
6847
|
return (/* @__PURE__ */ new Date()).toISOString() + " ";
|
|
6838
6848
|
}
|
|
6839
6849
|
function log(...args) {
|
|
6840
|
-
return process.stderr.write(util.
|
|
6850
|
+
return process.stderr.write(util.formatWithOptions(exports.inspectOpts, ...args) + "\n");
|
|
6841
6851
|
}
|
|
6842
6852
|
function save(namespaces) {
|
|
6843
6853
|
if (namespaces) {
|
|
@@ -7042,18 +7052,6 @@ function isInlangProjectPath(path) {
|
|
|
7042
7052
|
function isAbsolutePath(path) {
|
|
7043
7053
|
return /^\/|^[A-Za-z]:[\\/]/.test(path);
|
|
7044
7054
|
}
|
|
7045
|
-
async function pathExists$1(filePath, nodeishFs) {
|
|
7046
|
-
try {
|
|
7047
|
-
await nodeishFs.stat(filePath);
|
|
7048
|
-
return true;
|
|
7049
|
-
} catch (error) {
|
|
7050
|
-
if (error.code === "ENOENT") {
|
|
7051
|
-
return false;
|
|
7052
|
-
} else {
|
|
7053
|
-
throw new Error(`Failed to check if path exists: ${error}`, { cause: error });
|
|
7054
|
-
}
|
|
7055
|
-
}
|
|
7056
|
-
}
|
|
7057
7055
|
class ProjectSettingsInvalidError extends Error {
|
|
7058
7056
|
constructor(options) {
|
|
7059
7057
|
super(`The project settings are invalid:
|
|
@@ -7575,54 +7573,58 @@ var ReactiveMap = class extends Map {
|
|
|
7575
7573
|
}
|
|
7576
7574
|
};
|
|
7577
7575
|
const createNodeishFsWithWatcher = (args) => {
|
|
7578
|
-
const pathList =
|
|
7579
|
-
|
|
7576
|
+
const pathList = /* @__PURE__ */ new Set();
|
|
7577
|
+
const abortControllers = /* @__PURE__ */ new Set();
|
|
7580
7578
|
const stopWatching = () => {
|
|
7581
7579
|
for (const ac of abortControllers) {
|
|
7582
7580
|
ac.abort();
|
|
7581
|
+
abortControllers.delete(ac);
|
|
7583
7582
|
}
|
|
7584
|
-
abortControllers = [];
|
|
7585
7583
|
};
|
|
7586
|
-
const makeWatcher = (path) => {
|
|
7587
|
-
|
|
7588
|
-
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
-
|
|
7594
|
-
|
|
7595
|
-
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
|
-
}
|
|
7584
|
+
const makeWatcher = async (path) => {
|
|
7585
|
+
try {
|
|
7586
|
+
const ac = new AbortController();
|
|
7587
|
+
abortControllers.add(ac);
|
|
7588
|
+
const watcher = args.nodeishFs.watch(path, {
|
|
7589
|
+
signal: ac.signal,
|
|
7590
|
+
recursive: true,
|
|
7591
|
+
persistent: false
|
|
7592
|
+
});
|
|
7593
|
+
if (watcher) {
|
|
7594
|
+
for await (const event of watcher) {
|
|
7595
|
+
args.onChange();
|
|
7599
7596
|
}
|
|
7600
|
-
} catch (err) {
|
|
7601
|
-
if (err.name === "AbortError")
|
|
7602
|
-
return;
|
|
7603
|
-
else if (err.code === "ENOENT")
|
|
7604
|
-
return;
|
|
7605
|
-
throw err;
|
|
7606
7597
|
}
|
|
7607
|
-
}
|
|
7608
|
-
|
|
7609
|
-
|
|
7610
|
-
|
|
7611
|
-
|
|
7612
|
-
|
|
7598
|
+
} catch (err) {
|
|
7599
|
+
if (err.name === "AbortError")
|
|
7600
|
+
return;
|
|
7601
|
+
else if (err.code === "ENOENT")
|
|
7602
|
+
return;
|
|
7603
|
+
throw err;
|
|
7613
7604
|
}
|
|
7614
|
-
|
|
7605
|
+
};
|
|
7606
|
+
const watched = (fn) => {
|
|
7607
|
+
return (path, ...rest) => {
|
|
7608
|
+
if (!pathList.has(path)) {
|
|
7609
|
+
makeWatcher(path);
|
|
7610
|
+
pathList.add(path);
|
|
7611
|
+
}
|
|
7612
|
+
return fn(path, ...rest);
|
|
7613
|
+
};
|
|
7615
7614
|
};
|
|
7616
7615
|
return {
|
|
7616
|
+
...args.nodeishFs,
|
|
7617
|
+
/**
|
|
7618
|
+
* Reads the file and automatically adds it to the list of watched files.
|
|
7619
|
+
* Any changes to the file will trigger a message update.
|
|
7620
|
+
*/
|
|
7617
7621
|
// @ts-expect-error
|
|
7618
|
-
readFile: (
|
|
7619
|
-
|
|
7620
|
-
|
|
7621
|
-
|
|
7622
|
-
|
|
7623
|
-
|
|
7624
|
-
watch: args.nodeishFs.watch,
|
|
7625
|
-
stat: args.nodeishFs.stat,
|
|
7622
|
+
readFile: watched(args.nodeishFs.readFile),
|
|
7623
|
+
/**
|
|
7624
|
+
* Reads the directory and automatically adds it to the list of watched files.
|
|
7625
|
+
* Any changes to the directory will trigger a message update.
|
|
7626
|
+
*/
|
|
7627
|
+
readdir: watched(args.nodeishFs.readdir),
|
|
7626
7628
|
stopWatching
|
|
7627
7629
|
};
|
|
7628
7630
|
};
|
|
@@ -7659,53 +7661,36 @@ function normalizeMessage(message) {
|
|
|
7659
7661
|
function stringifyMessage(message) {
|
|
7660
7662
|
return JSON.stringify(normalizeMessage(message), void 0, 4);
|
|
7661
7663
|
}
|
|
7662
|
-
function normalizePath(path,
|
|
7663
|
-
|
|
7664
|
+
function normalizePath(path, { trailingSlash, leadingSlash } = {}) {
|
|
7665
|
+
path = path.replace(/^\.\//, "/");
|
|
7666
|
+
if (path === "\\" || path === "" || path === "/" || path === "." || path === "//.") {
|
|
7664
7667
|
return "/";
|
|
7665
|
-
|
|
7666
|
-
if (
|
|
7668
|
+
}
|
|
7669
|
+
if (path.length <= 1) {
|
|
7667
7670
|
return path;
|
|
7668
|
-
let prefix = "";
|
|
7669
|
-
if (len > 4 && path[3] === "\\") {
|
|
7670
|
-
const ch = path[2];
|
|
7671
|
-
if ((ch === "?" || ch === ".") && path.slice(0, 2) === "\\\\") {
|
|
7672
|
-
path = path.slice(2);
|
|
7673
|
-
prefix = "//";
|
|
7674
|
-
}
|
|
7675
7671
|
}
|
|
7672
|
+
const hadTrailingSlash = path[path.length - 1] === "/" || path[path.length - 1] === "\\";
|
|
7673
|
+
const addleadingSlash = leadingSlash === "always" || path[0] === "/" || path[0] === "\\";
|
|
7676
7674
|
const segs = path.split(/[/\\]+/);
|
|
7677
7675
|
const stack = [];
|
|
7678
7676
|
for (const seg of segs) {
|
|
7679
7677
|
if (seg === "..") {
|
|
7680
7678
|
stack.pop();
|
|
7681
|
-
} else if (seg !== ".") {
|
|
7679
|
+
} else if (seg && seg !== ".") {
|
|
7682
7680
|
stack.push(seg);
|
|
7683
7681
|
}
|
|
7684
7682
|
}
|
|
7685
|
-
if (
|
|
7686
|
-
stack.
|
|
7683
|
+
if (trailingSlash !== "strip" && (hadTrailingSlash || trailingSlash === "always")) {
|
|
7684
|
+
stack.push("");
|
|
7687
7685
|
}
|
|
7688
|
-
return
|
|
7689
|
-
}
|
|
7690
|
-
const dots = /(\/|^)(\.\/)+/g;
|
|
7691
|
-
const slashes = /\/+/g;
|
|
7692
|
-
const upreference = /(?<!\.\.)[^/]+\/\.\.\//;
|
|
7693
|
-
function normalPath(path) {
|
|
7694
|
-
var _a;
|
|
7695
|
-
path = `/${path}/`;
|
|
7696
|
-
path = path.replace(/^\/\.\./, "");
|
|
7697
|
-
path = path.replace(dots, "/").replace(slashes, "/");
|
|
7698
|
-
let match;
|
|
7699
|
-
while (match = (_a = path.match(upreference)) == null ? void 0 : _a[0]) {
|
|
7700
|
-
path = path.replace(match, "");
|
|
7701
|
-
}
|
|
7702
|
-
return path;
|
|
7686
|
+
return addleadingSlash ? "/" + stack.join("/") : stack.join("/");
|
|
7703
7687
|
}
|
|
7704
7688
|
function getDirname(path) {
|
|
7705
|
-
|
|
7689
|
+
const dirname = path.split("/").filter((x) => x).slice(0, -1).join("/");
|
|
7690
|
+
return normalizePath(dirname, { leadingSlash: "always", trailingSlash: "always" }) ?? path;
|
|
7706
7691
|
}
|
|
7707
7692
|
function getBasename(path) {
|
|
7708
|
-
return path.split("/").filter((x) => x).at(-1) ??
|
|
7693
|
+
return path.split("/").filter((x) => x).at(-1) ?? "";
|
|
7709
7694
|
}
|
|
7710
7695
|
const debug$6 = _debug("sdk:fileLock");
|
|
7711
7696
|
const maxRetries = 10;
|
|
@@ -9235,7 +9220,7 @@ function createMessagesQuery({ projectPath, nodeishFs, settings, resolvedModules
|
|
|
9235
9220
|
nodeishFs,
|
|
9236
9221
|
// this message is called whenever a file changes that was read earlier by this filesystem
|
|
9237
9222
|
// - the plugin loads messages -> reads the file messages.json -> start watching on messages.json -> updateMessages
|
|
9238
|
-
|
|
9223
|
+
onChange: () => {
|
|
9239
9224
|
loadMessagesViaPlugin(
|
|
9240
9225
|
fsWithWatcher,
|
|
9241
9226
|
messageLockDirPath,
|
|
@@ -10015,16 +10000,30 @@ async function maybeAddModuleCache(args) {
|
|
|
10015
10000
|
const gitignoreExists = await fileExists(gitignorePath, args.repo.nodeishFs);
|
|
10016
10001
|
const moduleCacheExists = await directoryExists(moduleCache, args.repo.nodeishFs);
|
|
10017
10002
|
if (gitignoreExists) {
|
|
10018
|
-
|
|
10019
|
-
|
|
10020
|
-
|
|
10021
|
-
|
|
10003
|
+
try {
|
|
10004
|
+
const gitignore = await args.repo.nodeishFs.readFile(gitignorePath, { encoding: "utf-8" });
|
|
10005
|
+
const missingIgnores = EXPECTED_IGNORES.filter((ignore) => !gitignore.includes(ignore));
|
|
10006
|
+
if (missingIgnores.length > 0) {
|
|
10007
|
+
await args.repo.nodeishFs.appendFile(gitignorePath, "\n" + missingIgnores.join("\n"));
|
|
10008
|
+
}
|
|
10009
|
+
} catch (error) {
|
|
10010
|
+
throw new Error("[migrate:module-cache] Failed to update .gitignore", { cause: error });
|
|
10022
10011
|
}
|
|
10023
10012
|
} else {
|
|
10024
|
-
|
|
10013
|
+
try {
|
|
10014
|
+
await args.repo.nodeishFs.writeFile(gitignorePath, EXPECTED_IGNORES.join("\n"));
|
|
10015
|
+
} catch (e) {
|
|
10016
|
+
if (e.code && e.code !== "EISDIR" && e.code !== "EEXIST") {
|
|
10017
|
+
throw new Error("[migrate:module-cache] Failed to create .gitignore", { cause: e });
|
|
10018
|
+
}
|
|
10019
|
+
}
|
|
10025
10020
|
}
|
|
10026
10021
|
if (!moduleCacheExists) {
|
|
10027
|
-
|
|
10022
|
+
try {
|
|
10023
|
+
await args.repo.nodeishFs.mkdir(moduleCache, { recursive: true });
|
|
10024
|
+
} catch (e) {
|
|
10025
|
+
throw new Error("[migrate:module-cache] Failed to create cache directory", { cause: e });
|
|
10026
|
+
}
|
|
10028
10027
|
}
|
|
10029
10028
|
}
|
|
10030
10029
|
async function fileExists(path, nodeishFs) {
|
|
@@ -10347,39 +10346,54 @@ async function loadProject(args) {
|
|
|
10347
10346
|
const { data: projectId } = await tryCatch(() => nodeishFs.readFile(args.projectPath + "/project_id", { encoding: "utf-8" }));
|
|
10348
10347
|
const [initialized, markInitAsComplete, markInitAsFailed] = createAwaitable();
|
|
10349
10348
|
const [loadedSettings, markSettingsAsLoaded, markSettingsAsFailed] = createAwaitable();
|
|
10349
|
+
const [resolvedModules, setResolvedModules] = createSignal();
|
|
10350
10350
|
const [settings, _setSettings] = createSignal();
|
|
10351
10351
|
let v2Persistence = false;
|
|
10352
10352
|
let locales = [];
|
|
10353
|
-
|
|
10354
|
-
loadSettings({ settingsFilePath: projectPath + "/settings.json", nodeishFs }).then((settings2) => {
|
|
10355
|
-
setSettings(settings2);
|
|
10356
|
-
markSettingsAsLoaded();
|
|
10357
|
-
}).catch((err) => {
|
|
10358
|
-
markInitAsFailed(err);
|
|
10359
|
-
markSettingsAsFailed(err);
|
|
10360
|
-
});
|
|
10361
|
-
});
|
|
10362
|
-
const writeSettingsToDisk = skipFirst((settings2) => _writeSettingsToDisk({ nodeishFs, settings: settings2, projectPath }));
|
|
10363
|
-
const setSettings = (settings2) => {
|
|
10353
|
+
const setSettings = (newSettings) => {
|
|
10364
10354
|
var _a;
|
|
10365
10355
|
try {
|
|
10366
|
-
const validatedSettings = parseSettings(
|
|
10356
|
+
const validatedSettings = parseSettings(newSettings);
|
|
10367
10357
|
v2Persistence = !!((_a = validatedSettings.experimental) == null ? void 0 : _a.persistence);
|
|
10368
10358
|
locales = validatedSettings.languageTags;
|
|
10369
10359
|
batch(() => {
|
|
10370
10360
|
setResolvedModules(void 0);
|
|
10371
10361
|
_setSettings(validatedSettings);
|
|
10372
10362
|
});
|
|
10373
|
-
|
|
10374
|
-
return { data: void 0 };
|
|
10363
|
+
return { data: validatedSettings };
|
|
10375
10364
|
} catch (error) {
|
|
10376
10365
|
if (error instanceof ProjectSettingsInvalidError) {
|
|
10377
10366
|
return { error };
|
|
10378
10367
|
}
|
|
10379
|
-
throw new Error("Unhandled error in setSettings. This is an internal bug. Please file an issue.");
|
|
10368
|
+
throw new Error("Unhandled error in setSettings. This is an internal bug. Please file an issue.", { cause: error });
|
|
10380
10369
|
}
|
|
10381
10370
|
};
|
|
10382
|
-
const
|
|
10371
|
+
const nodeishFsWithWatchersForSettings = createNodeishFsWithWatcher({
|
|
10372
|
+
nodeishFs,
|
|
10373
|
+
onChange: async () => {
|
|
10374
|
+
const readSettingsResult = await tryCatch(async () => await loadSettings({
|
|
10375
|
+
settingsFilePath: projectPath + "/settings.json",
|
|
10376
|
+
nodeishFs
|
|
10377
|
+
}));
|
|
10378
|
+
if (readSettingsResult.error)
|
|
10379
|
+
return;
|
|
10380
|
+
const newSettings = readSettingsResult.data;
|
|
10381
|
+
if (JSON.stringify(newSettings) !== JSON.stringify(settings())) {
|
|
10382
|
+
setSettings(newSettings);
|
|
10383
|
+
}
|
|
10384
|
+
}
|
|
10385
|
+
});
|
|
10386
|
+
const settingsResult = await tryCatch(async () => await loadSettings({
|
|
10387
|
+
settingsFilePath: projectPath + "/settings.json",
|
|
10388
|
+
nodeishFs: nodeishFsWithWatchersForSettings
|
|
10389
|
+
}));
|
|
10390
|
+
if (settingsResult.error) {
|
|
10391
|
+
markInitAsFailed(settingsResult.error);
|
|
10392
|
+
markSettingsAsFailed(settingsResult.error);
|
|
10393
|
+
} else {
|
|
10394
|
+
setSettings(settingsResult.data);
|
|
10395
|
+
markSettingsAsLoaded();
|
|
10396
|
+
}
|
|
10383
10397
|
createEffect(() => {
|
|
10384
10398
|
const _settings = settings();
|
|
10385
10399
|
if (!_settings)
|
|
@@ -10504,7 +10518,12 @@ async function loadProject(args) {
|
|
|
10504
10518
|
//...(lintErrors() ?? []),
|
|
10505
10519
|
]),
|
|
10506
10520
|
settings: createSubscribable(() => settings()),
|
|
10507
|
-
setSettings
|
|
10521
|
+
setSettings: (newSettings) => {
|
|
10522
|
+
const result = setSettings(newSettings);
|
|
10523
|
+
if (!result.error)
|
|
10524
|
+
writeSettingsToDisk({ nodeishFs, settings: result.data, projectPath });
|
|
10525
|
+
return result.error ? result : { data: void 0 };
|
|
10526
|
+
},
|
|
10508
10527
|
customApi: createSubscribable(() => {
|
|
10509
10528
|
var _a;
|
|
10510
10529
|
return ((_a = resolvedModules()) == null ? void 0 : _a.resolvedPluginApi.customApi) || {};
|
|
@@ -10559,18 +10578,17 @@ const parseSettings = (settings) => {
|
|
|
10559
10578
|
}
|
|
10560
10579
|
return withMigration;
|
|
10561
10580
|
};
|
|
10562
|
-
const
|
|
10563
|
-
const
|
|
10581
|
+
const writeSettingsToDisk = async (args) => {
|
|
10582
|
+
const serializeResult = tryCatch(() => (
|
|
10564
10583
|
// TODO: this will probably not match the original formatting
|
|
10565
10584
|
JSON.stringify(args.settings, void 0, 2)
|
|
10566
10585
|
));
|
|
10567
|
-
if (
|
|
10568
|
-
throw
|
|
10569
|
-
|
|
10570
|
-
const
|
|
10571
|
-
if (
|
|
10572
|
-
throw
|
|
10573
|
-
}
|
|
10586
|
+
if (serializeResult.error)
|
|
10587
|
+
throw serializeResult.error;
|
|
10588
|
+
const serializedSettings = serializeResult.data;
|
|
10589
|
+
const writeResult = await tryCatch(async () => await args.nodeishFs.writeFile(args.projectPath + "/settings.json", serializedSettings));
|
|
10590
|
+
if (writeResult.error)
|
|
10591
|
+
throw writeResult.error;
|
|
10574
10592
|
};
|
|
10575
10593
|
const createAwaitable = () => {
|
|
10576
10594
|
let resolve;
|
|
@@ -10581,15 +10599,6 @@ const createAwaitable = () => {
|
|
|
10581
10599
|
});
|
|
10582
10600
|
return [promise, resolve, reject];
|
|
10583
10601
|
};
|
|
10584
|
-
function skipFirst(func) {
|
|
10585
|
-
let initial = false;
|
|
10586
|
-
return function(...args) {
|
|
10587
|
-
if (initial) {
|
|
10588
|
-
return func.apply(this, args);
|
|
10589
|
-
}
|
|
10590
|
-
initial = true;
|
|
10591
|
-
};
|
|
10592
|
-
}
|
|
10593
10602
|
function createSubscribable(signal) {
|
|
10594
10603
|
return Object.assign(signal, {
|
|
10595
10604
|
subscribe: (callback) => {
|
|
@@ -11349,24 +11358,22 @@ function split(array, predicate) {
|
|
|
11349
11358
|
export {
|
|
11350
11359
|
Logger,
|
|
11351
11360
|
getBasename as a,
|
|
11352
|
-
|
|
11353
|
-
|
|
11361
|
+
assertValidProjectPath as b,
|
|
11362
|
+
getDefaultExportFromCjs as c,
|
|
11354
11363
|
classifyProjectErrors,
|
|
11355
11364
|
compile,
|
|
11356
|
-
|
|
11357
|
-
|
|
11358
|
-
|
|
11365
|
+
parseOrigin as d,
|
|
11366
|
+
commonjsGlobal as e,
|
|
11367
|
+
getAugmentedNamespace as f,
|
|
11359
11368
|
getDirname as g,
|
|
11360
|
-
|
|
11361
|
-
|
|
11362
|
-
|
|
11363
|
-
|
|
11369
|
+
parseLixUri as h,
|
|
11370
|
+
typebox as i,
|
|
11371
|
+
telemetry as j,
|
|
11372
|
+
pathExists as k,
|
|
11364
11373
|
loadProject as l,
|
|
11365
|
-
|
|
11366
|
-
|
|
11367
|
-
pathExists as o,
|
|
11374
|
+
findPackageJson as m,
|
|
11375
|
+
normalizePath as n,
|
|
11368
11376
|
pattern$1 as p,
|
|
11369
|
-
findPackageJson as q,
|
|
11370
11377
|
transformRemote as t,
|
|
11371
11378
|
value$1 as v,
|
|
11372
11379
|
withProxy as w,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inlang/paraglide-js",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.11.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -57,18 +57,18 @@
|
|
|
57
57
|
"@vitest/coverage-v8": "0.34.3",
|
|
58
58
|
"memfs": "4.6.0",
|
|
59
59
|
"rollup": "3.29.1",
|
|
60
|
-
"typescript": "5.
|
|
60
|
+
"typescript": "^5.5.2",
|
|
61
61
|
"vite": "4.5.2",
|
|
62
62
|
"vite-plugin-dts": "^3.8.1",
|
|
63
63
|
"vite-tsconfig-paths": "^4.3.2",
|
|
64
64
|
"vitest": "0.34.3",
|
|
65
|
-
"@inlang/
|
|
66
|
-
"@inlang/
|
|
67
|
-
"@inlang/language-tag": "1.5.1",
|
|
68
|
-
"@inlang/sdk": "0.36.1",
|
|
69
|
-
"@lix-js/client": "2.2.0",
|
|
65
|
+
"@inlang/recommend-sherlock": "0.1.0",
|
|
66
|
+
"@inlang/recommend-ninja": "0.1.0",
|
|
70
67
|
"@inlang/plugin-message-format": "2.2.0",
|
|
71
|
-
"@
|
|
68
|
+
"@inlang/sdk": "0.36.3",
|
|
69
|
+
"@inlang/language-tag": "1.5.1",
|
|
70
|
+
"@lix-js/client": "2.2.1",
|
|
71
|
+
"@lix-js/fs": "2.2.0"
|
|
72
72
|
},
|
|
73
73
|
"exports": {
|
|
74
74
|
".": {
|