@gtkx/cli 2.0.0-beta.2 → 2.0.0-beta.4
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/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +12 -2
- package/dist/cli.js.map +1 -1
- package/dist/codegen/config-dependencies.d.ts +3 -0
- package/dist/codegen/config-dependencies.d.ts.map +1 -0
- package/dist/codegen/config-dependencies.js +355 -0
- package/dist/codegen/config-dependencies.js.map +1 -0
- package/dist/codegen/reference.d.ts.map +1 -1
- package/dist/codegen/reference.js +1 -0
- package/dist/codegen/reference.js.map +1 -1
- package/dist/codegen/run-codegen.d.ts +3 -2
- package/dist/codegen/run-codegen.d.ts.map +1 -1
- package/dist/codegen/run-codegen.js +33 -14
- package/dist/codegen/run-codegen.js.map +1 -1
- package/dist/codegen/store-resolver.d.ts +2 -0
- package/dist/codegen/store-resolver.d.ts.map +1 -1
- package/dist/codegen/store-resolver.js +6 -3
- package/dist/codegen/store-resolver.js.map +1 -1
- package/dist/commands/cleanup.d.ts +9 -0
- package/dist/commands/cleanup.d.ts.map +1 -0
- package/dist/commands/cleanup.js +31 -0
- package/dist/commands/cleanup.js.map +1 -0
- package/dist/commands/dev.d.ts +1 -0
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +13 -4
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/docs.d.ts.map +1 -1
- package/dist/commands/docs.js +1 -0
- package/dist/commands/docs.js.map +1 -1
- package/dist/deploy/freedesktop/validate.d.ts.map +1 -1
- package/dist/deploy/freedesktop/validate.js +11 -4
- package/dist/deploy/freedesktop/validate.js.map +1 -1
- package/dist/deploy/nfpm/config.d.ts +3 -2
- package/dist/deploy/nfpm/config.d.ts.map +1 -1
- package/dist/deploy/nfpm/config.js +3 -3
- package/dist/deploy/nfpm/config.js.map +1 -1
- package/dist/deploy/node-runtime/index.d.ts.map +1 -1
- package/dist/deploy/node-runtime/index.js +2 -1
- package/dist/deploy/node-runtime/index.js.map +1 -1
- package/dist/deploy/payload/stage.d.ts.map +1 -1
- package/dist/deploy/payload/stage.js +24 -3
- package/dist/deploy/payload/stage.js.map +1 -1
- package/dist/deploy/settings/extra-files.d.ts.map +1 -1
- package/dist/deploy/settings/extra-files.js +4 -3
- package/dist/deploy/settings/extra-files.js.map +1 -1
- package/dist/deploy/targets/nfpm-target.d.ts.map +1 -1
- package/dist/deploy/targets/nfpm-target.js +12 -7
- package/dist/deploy/targets/nfpm-target.js.map +1 -1
- package/dist/dev/entry-env.d.ts +2 -1
- package/dist/dev/entry-env.d.ts.map +1 -1
- package/dist/dev/entry-env.js +2 -1
- package/dist/dev/entry-env.js.map +1 -1
- package/dist/dev/runner-deps.d.ts +1 -1
- package/dist/dev/runner-deps.d.ts.map +1 -1
- package/dist/dev/runner-deps.js +3 -3
- package/dist/dev/runner-deps.js.map +1 -1
- package/dist/dev/runner-main.d.ts.map +1 -1
- package/dist/dev/runner-main.js +8 -3
- package/dist/dev/runner-main.js.map +1 -1
- package/dist/dev/supervisor.d.ts +3 -1
- package/dist/dev/supervisor.d.ts.map +1 -1
- package/dist/dev/supervisor.js +124 -27
- package/dist/dev/supervisor.js.map +1 -1
- package/dist/i18n/catalogs.d.ts.map +1 -1
- package/dist/i18n/catalogs.js +1 -0
- package/dist/i18n/catalogs.js.map +1 -1
- package/dist/i18n/source-messages.d.ts +3 -1
- package/dist/i18n/source-messages.d.ts.map +1 -1
- package/dist/i18n/source-messages.js +167 -37
- package/dist/i18n/source-messages.js.map +1 -1
- package/dist/internal/build-output.d.ts.map +1 -1
- package/dist/internal/build-output.js +53 -6
- package/dist/internal/build-output.js.map +1 -1
- package/dist/internal/docs-elements.d.ts +1 -0
- package/dist/internal/docs-elements.d.ts.map +1 -1
- package/dist/internal/docs-elements.js +5 -4
- package/dist/internal/docs-elements.js.map +1 -1
- package/dist/internal/errors.d.ts +2 -1
- package/dist/internal/errors.d.ts.map +1 -1
- package/dist/internal/errors.js +1 -1
- package/dist/internal/errors.js.map +1 -1
- package/dist/internal/parent-process.d.ts +12 -0
- package/dist/internal/parent-process.d.ts.map +1 -0
- package/dist/internal/parent-process.js +74 -0
- package/dist/internal/parent-process.js.map +1 -0
- package/dist/internal/prepare-project.d.ts +1 -0
- package/dist/internal/prepare-project.d.ts.map +1 -1
- package/dist/internal/prepare-project.js +8 -2
- package/dist/internal/prepare-project.js.map +1 -1
- package/dist/vite-plugins/ensure-store.d.ts +1 -1
- package/dist/vite-plugins/ensure-store.d.ts.map +1 -1
- package/dist/vite-plugins/ensure-store.js +2 -2
- package/dist/vite-plugins/ensure-store.js.map +1 -1
- package/dist/vite-plugins/i18n.d.ts +1 -1
- package/dist/vite-plugins/i18n.d.ts.map +1 -1
- package/dist/vite-plugins/i18n.js +24 -11
- package/dist/vite-plugins/i18n.js.map +1 -1
- package/dist/vite-plugins/index.d.ts.map +1 -1
- package/dist/vite-plugins/index.js +3 -1
- package/dist/vite-plugins/index.js.map +1 -1
- package/dist/vite-plugins/native.d.ts.map +1 -1
- package/dist/vite-plugins/native.js +0 -4
- package/dist/vite-plugins/native.js.map +1 -1
- package/dist/vite-plugins/settings-worker-env.d.ts +1 -1
- package/dist/vite-plugins/settings-worker-env.d.ts.map +1 -1
- package/dist/vite-plugins/settings-worker-env.js +2 -2
- package/dist/vite-plugins/settings-worker-env.js.map +1 -1
- package/dist/vitest-plugin.d.ts +2 -1
- package/dist/vitest-plugin.d.ts.map +1 -1
- package/dist/vitest-plugin.js +6 -6
- package/dist/vitest-plugin.js.map +1 -1
- package/package.json +12 -9
- package/src/cli.ts +12 -2
- package/src/codegen/config-dependencies.ts +470 -0
- package/src/codegen/reference.ts +1 -0
- package/src/codegen/run-codegen.ts +39 -17
- package/src/codegen/store-resolver.ts +8 -3
- package/src/commands/cleanup.ts +36 -0
- package/src/commands/dev.ts +26 -4
- package/src/commands/docs.ts +1 -0
- package/src/deploy/freedesktop/validate.ts +13 -4
- package/src/deploy/nfpm/config.ts +9 -3
- package/src/deploy/node-runtime/index.ts +2 -1
- package/src/deploy/payload/stage.ts +42 -3
- package/src/deploy/settings/extra-files.ts +5 -3
- package/src/deploy/targets/nfpm-target.ts +13 -6
- package/src/dev/entry-env.ts +2 -1
- package/src/dev/runner-deps.ts +3 -3
- package/src/dev/runner-main.ts +10 -3
- package/src/dev/supervisor.ts +164 -30
- package/src/i18n/catalogs.ts +1 -0
- package/src/i18n/source-messages.ts +240 -41
- package/src/internal/build-output.ts +79 -7
- package/src/internal/docs-elements.ts +10 -4
- package/src/internal/errors.ts +1 -1
- package/src/internal/parent-process.ts +110 -0
- package/src/internal/prepare-project.ts +9 -3
- package/src/vite-plugins/ensure-store.ts +2 -2
- package/src/vite-plugins/i18n.ts +30 -14
- package/src/vite-plugins/index.ts +8 -1
- package/src/vite-plugins/native.ts +0 -5
- package/src/vite-plugins/settings-worker-env.ts +2 -2
- package/src/vitest-plugin.ts +6 -6
|
@@ -33,6 +33,74 @@ const STATIC_KEY_WRAPPER_TYPES = new Set([
|
|
|
33
33
|
"TSTypeAssertion",
|
|
34
34
|
"TSNonNullExpression",
|
|
35
35
|
]);
|
|
36
|
+
class SourceExtractionError extends Error {
|
|
37
|
+
}
|
|
38
|
+
const sourceErrorMessage = (error) => {
|
|
39
|
+
if (!(error instanceof Error)) {
|
|
40
|
+
return String(error);
|
|
41
|
+
}
|
|
42
|
+
if ("code" in error &&
|
|
43
|
+
error.code === "BABEL_PARSE_ERROR") {
|
|
44
|
+
const separator = error.message.indexOf(": ");
|
|
45
|
+
if (separator !== -1) {
|
|
46
|
+
return error.message.slice(separator + 2);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return error.message;
|
|
50
|
+
};
|
|
51
|
+
const projectSourcePath = (root, path) => {
|
|
52
|
+
const absolute = isAbsolute(path) ? resolve(path) : resolve(root, path);
|
|
53
|
+
return toPosixPath(isPathInside(root, absolute) ? relative(root, absolute) : path);
|
|
54
|
+
};
|
|
55
|
+
const sourceExtractionError = (root, path, point, error) => {
|
|
56
|
+
if (error instanceof SourceExtractionError) {
|
|
57
|
+
return error;
|
|
58
|
+
}
|
|
59
|
+
const file = projectSourcePath(root, path);
|
|
60
|
+
const location = point === null
|
|
61
|
+
? file
|
|
62
|
+
: `${file}:${String(point.line)}:${String(point.column + 1)}`;
|
|
63
|
+
return new SourceExtractionError(`${location}: ${sourceErrorMessage(error)}`, { cause: error });
|
|
64
|
+
};
|
|
65
|
+
const locatablePoint = (node) => {
|
|
66
|
+
const location = node.loc?.start;
|
|
67
|
+
return location === undefined ? null : { column: location.column, line: location.line };
|
|
68
|
+
};
|
|
69
|
+
const isSourcePoint = (value) => typeof value === "object" &&
|
|
70
|
+
value !== null &&
|
|
71
|
+
"column" in value &&
|
|
72
|
+
typeof value.column === "number" &&
|
|
73
|
+
"line" in value &&
|
|
74
|
+
typeof value.line === "number";
|
|
75
|
+
const errorSourcePoint = (error) => {
|
|
76
|
+
if (typeof error !== "object" || error === null) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
if ("loc" in error && isSourcePoint(error.loc)) {
|
|
80
|
+
return error.loc;
|
|
81
|
+
}
|
|
82
|
+
return "location" in error && isSourcePoint(error.location) ? error.location : null;
|
|
83
|
+
};
|
|
84
|
+
const atSourceNode = (root, path, node, operation) => {
|
|
85
|
+
try {
|
|
86
|
+
return operation();
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
throw sourceExtractionError(root, path, locatablePoint(node), error);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const atExtractedLocation = (root, locations, operation) => {
|
|
93
|
+
const location = locations.find((candidate) => candidate.line !== undefined && candidate.column !== undefined);
|
|
94
|
+
if (location?.line === undefined || location.column === undefined) {
|
|
95
|
+
return operation();
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
return operation();
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
throw sourceExtractionError(root, location.file, { column: location.column, line: location.line }, error);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
36
104
|
const quietLogger = () => {
|
|
37
105
|
const reports = [];
|
|
38
106
|
return {
|
|
@@ -121,10 +189,10 @@ const expandedPlural = (entry) => {
|
|
|
121
189
|
},
|
|
122
190
|
};
|
|
123
191
|
};
|
|
124
|
-
const groupedPlurals = (entries) => {
|
|
192
|
+
const groupedPlurals = (root, entries) => {
|
|
125
193
|
const groups = new Map();
|
|
126
194
|
for (const entry of entries) {
|
|
127
|
-
const { baseKey, variant } = expandedPlural(entry);
|
|
195
|
+
const { baseKey, variant } = atExtractedLocation(root, entry.locations ?? [], () => expandedPlural(entry));
|
|
128
196
|
const namespace = namespaceFor(entry);
|
|
129
197
|
const key = `${namespace}\0${baseKey}`;
|
|
130
198
|
const group = groups.get(key) ?? { baseKey, namespace, variants: [] };
|
|
@@ -163,17 +231,19 @@ const pluralMessage = ({ baseKey, namespace, variants }) => {
|
|
|
163
231
|
sourceKey: msgid,
|
|
164
232
|
};
|
|
165
233
|
};
|
|
166
|
-
const pluralMessages = (entries) => groupedPlurals(entries).map((group) => pluralMessage(group));
|
|
234
|
+
const pluralMessages = (root, entries) => groupedPlurals(root, entries).map((group) => atExtractedLocation(root, group.variants.flatMap((variant) => variant.locations), () => pluralMessage(group)));
|
|
167
235
|
const assertCardinal = (entry) => {
|
|
168
236
|
if (entry.isOrdinal === true) {
|
|
169
237
|
throw new Error("GNU gettext catalogs do not support i18next ordinal plurals");
|
|
170
238
|
}
|
|
171
239
|
};
|
|
172
|
-
const sourceMessages = (entries) => {
|
|
240
|
+
const sourceMessages = (root, entries) => {
|
|
173
241
|
const points = [];
|
|
174
242
|
const plurals = [];
|
|
175
243
|
for (const entry of entries) {
|
|
176
|
-
|
|
244
|
+
atExtractedLocation(root, entry.locations ?? [], () => {
|
|
245
|
+
assertCardinal(entry);
|
|
246
|
+
});
|
|
177
247
|
if (entry.isExpandedPlural === true) {
|
|
178
248
|
plurals.push(entry);
|
|
179
249
|
continue;
|
|
@@ -183,7 +253,10 @@ const sourceMessages = (entries) => {
|
|
|
183
253
|
}
|
|
184
254
|
points.push(entry);
|
|
185
255
|
}
|
|
186
|
-
return [
|
|
256
|
+
return [
|
|
257
|
+
...points.map((entry) => atExtractedLocation(root, entry.locations ?? [], () => pointMessage(entry))),
|
|
258
|
+
...pluralMessages(root, plurals),
|
|
259
|
+
];
|
|
187
260
|
};
|
|
188
261
|
const compareMessages = (left, right) => left.namespace.localeCompare(right.namespace) ||
|
|
189
262
|
(left.context ?? "").localeCompare(right.context ?? "") ||
|
|
@@ -497,13 +570,12 @@ const registerSourceMask = (node, references) => {
|
|
|
497
570
|
};
|
|
498
571
|
const sourceLocationKey = (line, column) => `${String(line)}:${String(column)}`;
|
|
499
572
|
const sourcePoint = (node) => {
|
|
500
|
-
|
|
501
|
-
return location === undefined ? null : { column: location.column, line: location.line };
|
|
573
|
+
return locatablePoint(node);
|
|
502
574
|
};
|
|
503
575
|
const registerSourceLocation = (node, references) => {
|
|
504
576
|
const point = sourcePoint(node);
|
|
505
577
|
if (point !== null) {
|
|
506
|
-
references.locations.
|
|
578
|
+
references.locations.set(sourceLocationKey(point.line, point.column), point);
|
|
507
579
|
}
|
|
508
580
|
return point;
|
|
509
581
|
};
|
|
@@ -603,6 +675,9 @@ const registerCallReference = (callPath, references, keyPrefix) => {
|
|
|
603
675
|
references.calls.add(nodeStart(callPath));
|
|
604
676
|
const firstArgument = callPath.node.arguments[0];
|
|
605
677
|
const point = registerSourceLocation(firstArgument ?? callPath.node, references);
|
|
678
|
+
if (point !== null) {
|
|
679
|
+
references.sourcePoints.set(nodeStart(callPath), point);
|
|
680
|
+
}
|
|
606
681
|
registerEntryLocation(extractedEntryKey(callPath.node, keyPrefix), point, references);
|
|
607
682
|
};
|
|
608
683
|
const parserPlugins = (lang) => [
|
|
@@ -610,6 +685,21 @@ const parserPlugins = (lang) => [
|
|
|
610
685
|
...(lang === "ts" || lang === "tsx" ? ["typescript"] : []),
|
|
611
686
|
...(lang === "jsx" || lang === "tsx" ? ["jsx"] : []),
|
|
612
687
|
];
|
|
688
|
+
const parseTranslationReferences = (root, path, source, lang) => {
|
|
689
|
+
try {
|
|
690
|
+
return parseBabelSync(source, {
|
|
691
|
+
ast: true,
|
|
692
|
+
babelrc: false,
|
|
693
|
+
configFile: false,
|
|
694
|
+
filename: projectSourcePath(root, path),
|
|
695
|
+
parserOpts: { createParenthesizedExpressions: true, plugins: parserPlugins(lang) },
|
|
696
|
+
sourceType: "module",
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
catch (error) {
|
|
700
|
+
throw sourceExtractionError(root, path, errorSourcePoint(error), error);
|
|
701
|
+
}
|
|
702
|
+
};
|
|
613
703
|
const registerIdentifierTranslationCall = (callPath, callee, references) => {
|
|
614
704
|
if (!callee.isIdentifier()) {
|
|
615
705
|
return;
|
|
@@ -680,6 +770,14 @@ const registerUnrecognizedElementMasks = (elementPath, name, references) => {
|
|
|
680
770
|
registerSourceMask(closingName, references);
|
|
681
771
|
}
|
|
682
772
|
};
|
|
773
|
+
const registerElementReference = (elementPath, references) => {
|
|
774
|
+
const start = nodeStart(elementPath);
|
|
775
|
+
const point = registerSourceLocation(elementPath.node, references);
|
|
776
|
+
references.elements.add(start);
|
|
777
|
+
if (point !== null) {
|
|
778
|
+
references.sourcePoints.set(start, point);
|
|
779
|
+
}
|
|
780
|
+
};
|
|
683
781
|
const registerTranslationElement = (elementPath, references) => {
|
|
684
782
|
const name = elementPath.get("name");
|
|
685
783
|
if (!name.isJSXIdentifier()) {
|
|
@@ -690,8 +788,7 @@ const registerTranslationElement = (elementPath, references) => {
|
|
|
690
788
|
throw new Error("Translation components must use their imported names");
|
|
691
789
|
}
|
|
692
790
|
if (kind === "canonical") {
|
|
693
|
-
|
|
694
|
-
registerSourceLocation(elementPath.node, references);
|
|
791
|
+
registerElementReference(elementPath, references);
|
|
695
792
|
}
|
|
696
793
|
else if (TRANS_ELEMENTS.has(name.node.name)) {
|
|
697
794
|
registerUnrecognizedElementMasks(elementPath, name, references);
|
|
@@ -705,15 +802,8 @@ const maskUnrecognizedTranslations = (source, references) => {
|
|
|
705
802
|
}
|
|
706
803
|
return masked;
|
|
707
804
|
};
|
|
708
|
-
const translationReferences = (path, source, lang) => {
|
|
709
|
-
const parsed =
|
|
710
|
-
ast: true,
|
|
711
|
-
babelrc: false,
|
|
712
|
-
configFile: false,
|
|
713
|
-
filename: path,
|
|
714
|
-
parserOpts: { createParenthesizedExpressions: true, plugins: parserPlugins(lang) },
|
|
715
|
-
sourceType: "module",
|
|
716
|
-
});
|
|
805
|
+
const translationReferences = (root, path, source, lang) => {
|
|
806
|
+
const parsed = parseTranslationReferences(root, path, source, lang);
|
|
717
807
|
if (parsed === null) {
|
|
718
808
|
throw new Error(`Translation extraction could not parse ${path}`);
|
|
719
809
|
}
|
|
@@ -721,21 +811,30 @@ const translationReferences = (path, source, lang) => {
|
|
|
721
811
|
calls: new Set(),
|
|
722
812
|
elements: new Set(),
|
|
723
813
|
entryLocations: new Map(),
|
|
724
|
-
locations: new
|
|
814
|
+
locations: new Map(),
|
|
725
815
|
masks: [],
|
|
816
|
+
sourcePoints: new Map(),
|
|
726
817
|
};
|
|
727
818
|
traverse(parsed, {
|
|
728
819
|
CallExpression(callPath) {
|
|
729
|
-
|
|
820
|
+
atSourceNode(root, path, callPath.node, () => {
|
|
821
|
+
registerTranslationCall(callPath, references);
|
|
822
|
+
});
|
|
730
823
|
},
|
|
731
824
|
JSXOpeningElement(elementPath) {
|
|
732
|
-
|
|
825
|
+
atSourceNode(root, path, elementPath.node, () => {
|
|
826
|
+
registerTranslationElement(elementPath, references);
|
|
827
|
+
});
|
|
733
828
|
},
|
|
734
829
|
OptionalCallExpression(callPath) {
|
|
735
|
-
|
|
830
|
+
atSourceNode(root, path, callPath.node, () => {
|
|
831
|
+
assertSupportedOptionalCall(callPath);
|
|
832
|
+
});
|
|
736
833
|
},
|
|
737
834
|
TaggedTemplateExpression(tagPath) {
|
|
738
|
-
|
|
835
|
+
atSourceNode(root, path, tagPath.node, () => {
|
|
836
|
+
assertUnsupportedTranslationTag(tagPath);
|
|
837
|
+
});
|
|
739
838
|
},
|
|
740
839
|
});
|
|
741
840
|
return references;
|
|
@@ -799,19 +898,42 @@ const assertSupportedTransElement = (node, references) => {
|
|
|
799
898
|
assertSupportedTransAttribute(attribute);
|
|
800
899
|
}
|
|
801
900
|
};
|
|
802
|
-
const assertSupportedTranslationSyntax = (path, source) => {
|
|
901
|
+
const assertSupportedTranslationSyntax = (root, path, source) => {
|
|
803
902
|
const lang = sourceLanguage(path);
|
|
804
903
|
if (lang === undefined) {
|
|
805
|
-
return {
|
|
904
|
+
return {
|
|
905
|
+
calls: new Set(),
|
|
906
|
+
elements: new Set(),
|
|
907
|
+
entryLocations: new Map(),
|
|
908
|
+
locations: new Map(),
|
|
909
|
+
masks: [],
|
|
910
|
+
sourcePoints: new Map(),
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
let parsed;
|
|
914
|
+
try {
|
|
915
|
+
parsed = parseSync(projectSourcePath(root, path), source, { lang });
|
|
806
916
|
}
|
|
807
|
-
|
|
808
|
-
|
|
917
|
+
catch (error) {
|
|
918
|
+
throw sourceExtractionError(root, path, errorSourcePoint(error), error);
|
|
919
|
+
}
|
|
920
|
+
const references = translationReferences(root, path, source, lang);
|
|
809
921
|
new Visitor({
|
|
810
922
|
CallExpression(node) {
|
|
811
|
-
|
|
923
|
+
try {
|
|
924
|
+
assertSupportedTranslationCall(node, references);
|
|
925
|
+
}
|
|
926
|
+
catch (error) {
|
|
927
|
+
throw sourceExtractionError(root, path, references.sourcePoints.get(node.start) ?? null, error);
|
|
928
|
+
}
|
|
812
929
|
},
|
|
813
930
|
JSXOpeningElement(node) {
|
|
814
|
-
|
|
931
|
+
try {
|
|
932
|
+
assertSupportedTransElement(node, references);
|
|
933
|
+
}
|
|
934
|
+
catch (error) {
|
|
935
|
+
throw sourceExtractionError(root, path, references.sourcePoints.get(node.start) ?? null, error);
|
|
936
|
+
}
|
|
815
937
|
},
|
|
816
938
|
}).visit(parsed.program);
|
|
817
939
|
return references;
|
|
@@ -997,12 +1119,20 @@ const extractedSourcePoints = (root, entries) => {
|
|
|
997
1119
|
}
|
|
998
1120
|
return points;
|
|
999
1121
|
};
|
|
1000
|
-
const
|
|
1122
|
+
const missingSourcePoint = (file, references, extracted) => {
|
|
1123
|
+
for (const [location, point] of references.locations) {
|
|
1124
|
+
if (!extracted.has(`${file}\0${location}`)) {
|
|
1125
|
+
return point;
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
return null;
|
|
1129
|
+
};
|
|
1001
1130
|
const assertAllReferencesExtracted = (root, references, entries) => {
|
|
1002
1131
|
const extracted = extractedSourcePoints(root, entries);
|
|
1003
1132
|
for (const [file, sourceReferences] of references) {
|
|
1004
|
-
|
|
1005
|
-
|
|
1133
|
+
const point = missingSourcePoint(file, sourceReferences, extracted);
|
|
1134
|
+
if (point !== null) {
|
|
1135
|
+
throw sourceExtractionError(root, file, point, new Error("A translation expression could not be extracted safely"));
|
|
1006
1136
|
}
|
|
1007
1137
|
}
|
|
1008
1138
|
};
|
|
@@ -1014,7 +1144,7 @@ const findSourceMessages = async (root, sourceFiles) => {
|
|
|
1014
1144
|
const sources = new Map(sourceFiles.map((file) => [file, readFileSync(file, "utf8")]));
|
|
1015
1145
|
const references = new Map();
|
|
1016
1146
|
for (const [file, source] of sources) {
|
|
1017
|
-
references.set(file, assertSupportedTranslationSyntax(file, source));
|
|
1147
|
+
references.set(file, assertSupportedTranslationSyntax(root, file, source));
|
|
1018
1148
|
}
|
|
1019
1149
|
let extracted;
|
|
1020
1150
|
const { logger, reports } = quietLogger();
|
|
@@ -1042,7 +1172,7 @@ const findSourceMessages = async (root, sourceFiles) => {
|
|
|
1042
1172
|
if (extracted === undefined || reports.length > 0 || result.hasErrors) {
|
|
1043
1173
|
throw new Error(reports.join("\n") || "i18next extraction failed");
|
|
1044
1174
|
}
|
|
1045
|
-
return sourceMessages(extracted.values().toArray())
|
|
1175
|
+
return sourceMessages(root, extracted.values().toArray())
|
|
1046
1176
|
.map((message) => inferLocations(message, sources))
|
|
1047
1177
|
.toSorted(compareMessages);
|
|
1048
1178
|
};
|
|
@@ -1214,5 +1344,5 @@ const extractSourceCatalog = async (project, paths, shouldPreserveMetadataMessag
|
|
|
1214
1344
|
writePotfiles(project, sourceFiles);
|
|
1215
1345
|
extractCatalogTemplate({ project, messages, shouldPreserveMetadataMessages });
|
|
1216
1346
|
};
|
|
1217
|
-
export { extractSourceCatalog, extractSourceCatalogTo };
|
|
1347
|
+
export { extractSourceCatalog, extractSourceCatalogTo, SourceExtractionError };
|
|
1218
1348
|
//# sourceMappingURL=source-messages.js.map
|