@yapyak/vite 0.0.5 → 0.0.7
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/index.js +21 -93
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CorruptLocaleFileError, YAP_RUNTIME, autoTranslate, detectRenames, discoverLocales, extractFile, findTranslation, getDocsUrl, migrateLocales,
|
|
1
|
+
import { CorruptLocaleFileError, YAP_COMPILE, YAP_RUNTIME, autoTranslate, detectRenames, discoverLocales, extractFile, findTranslation, getDocsUrl, migrateLocales, readLocaleData, readLocaleFile, syncLocaleFiles, toMessageKey, toVariants, transformFile, validateLocaleCode, walkSourceFiles, writeRegister } from "yapyak/compiler/internal";
|
|
2
2
|
import { createFilter, defineRuntime, loadYapyakConfig } from "yapyak/config/internal";
|
|
3
3
|
import { basename, extname, join, relative, resolve, sep } from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { buildPatches } from "yapyak/internal";
|
|
5
5
|
import { readFileSync } from "node:fs";
|
|
6
6
|
//#region src/locale-resolver.ts
|
|
7
7
|
function createLocaleResolver(context, projectRoot, options) {
|
|
@@ -132,7 +132,8 @@ function toRuntimeModules(processors) {
|
|
|
132
132
|
//#endregion
|
|
133
133
|
//#region src/plugin/file-id.ts
|
|
134
134
|
function toFileId(projectRoot, id) {
|
|
135
|
-
|
|
135
|
+
const path = id.split("?")[0] ?? id;
|
|
136
|
+
return relative(projectRoot, path).replaceAll("\\", "/");
|
|
136
137
|
}
|
|
137
138
|
//#endregion
|
|
138
139
|
//#region src/plugin/candidate-id.ts
|
|
@@ -145,6 +146,7 @@ function isCandidateId(id, filter, projectRoot) {
|
|
|
145
146
|
function renderErrorDiagnostics(logger, result) {
|
|
146
147
|
const errors = [];
|
|
147
148
|
for (const diagnostic of result.diagnostics) {
|
|
149
|
+
if (diagnostic.code === YAP_COMPILE.PROCESSOR_PARSE_ERROR.code) continue;
|
|
148
150
|
if (diagnostic.severity === "error") {
|
|
149
151
|
errors.push(diagnostic);
|
|
150
152
|
continue;
|
|
@@ -153,6 +155,9 @@ function renderErrorDiagnostics(logger, result) {
|
|
|
153
155
|
}
|
|
154
156
|
return errors;
|
|
155
157
|
}
|
|
158
|
+
function hasParseFailure(result) {
|
|
159
|
+
return result.diagnostics.some((diagnostic) => diagnostic.code === YAP_COMPILE.PROCESSOR_PARSE_ERROR.code);
|
|
160
|
+
}
|
|
156
161
|
function formatDiagnostic(diagnostic) {
|
|
157
162
|
const location = `${diagnostic.fileId}:${diagnostic.range.start.line}:${diagnostic.range.start.column}`;
|
|
158
163
|
return `[yapyak] ${diagnostic.code} ${location}: ${diagnostic.message}\nSee ${getDocsUrl(diagnostic.code)}`;
|
|
@@ -226,7 +231,8 @@ function resolveExtraction(state, fileId, source) {
|
|
|
226
231
|
//#endregion
|
|
227
232
|
//#region src/plugin/locale-file.ts
|
|
228
233
|
function isLocaleFile(state, path) {
|
|
229
|
-
const
|
|
234
|
+
const directory = join(state.projectRoot, getNormalized(state).localesDir);
|
|
235
|
+
const relativePath = relative(directory, path);
|
|
230
236
|
if (relativePath === "" || relativePath.startsWith("..") || relativePath.includes(sep)) return false;
|
|
231
237
|
return extname(relativePath) === ".json";
|
|
232
238
|
}
|
|
@@ -406,6 +412,7 @@ function createDevServerPlugin(state) {
|
|
|
406
412
|
}
|
|
407
413
|
const result = resolveExtraction(state, fileId, code);
|
|
408
414
|
renderErrorDiagnostics(state.logger, result);
|
|
415
|
+
if (hasParseFailure(result)) continue;
|
|
409
416
|
if (result.messages.length > 0) state.messagesByFile.set(fileId, result.messages);
|
|
410
417
|
else state.messagesByFile.delete(fileId);
|
|
411
418
|
}
|
|
@@ -444,7 +451,7 @@ function createDevServerPlugin(state) {
|
|
|
444
451
|
pendingLocalePaths.clear();
|
|
445
452
|
if (allPatches.length === 0 && filesToReload.size === 0) return;
|
|
446
453
|
getResolver(state).invalidateData();
|
|
447
|
-
|
|
454
|
+
invalidateEnvironments(server, patchedFiles);
|
|
448
455
|
for (const file of filesToReload) server.ws.send({
|
|
449
456
|
path: file,
|
|
450
457
|
type: "full-reload"
|
|
@@ -523,6 +530,7 @@ function createDevServerPlugin(state) {
|
|
|
523
530
|
const { defaultLocale, locales } = getResolver(state).getProjectLocales();
|
|
524
531
|
const result = resolveExtraction(state, fileId, code);
|
|
525
532
|
renderErrorDiagnostics(state.logger, result);
|
|
533
|
+
if (hasParseFailure(result)) return;
|
|
526
534
|
const before = state.messagesByFile.get(fileId) ?? [];
|
|
527
535
|
const after = result.messages;
|
|
528
536
|
if (areMessagesEqual(before, after)) return;
|
|
@@ -548,20 +556,11 @@ function createDevServerPlugin(state) {
|
|
|
548
556
|
name: "yapyak:dev-server"
|
|
549
557
|
};
|
|
550
558
|
}
|
|
551
|
-
function
|
|
559
|
+
function invalidateEnvironments(server, files) {
|
|
552
560
|
for (const environment of Object.values(server.environments)) {
|
|
553
|
-
if (environment.name === "client") continue;
|
|
554
561
|
const affected = /* @__PURE__ */ new Set();
|
|
555
562
|
for (const file of files) for (const module of environment.moduleGraph.getModulesByFile(file) ?? []) collectWithImporters(module, affected);
|
|
556
|
-
if (affected.size === 0) continue;
|
|
557
563
|
for (const module of affected) environment.moduleGraph.invalidateModule(module);
|
|
558
|
-
environment.hot.send({ type: "full-reload" });
|
|
559
|
-
if (!isRunnableDevEnvironment(environment)) continue;
|
|
560
|
-
for (const module of affected) {
|
|
561
|
-
if (module.file === null) continue;
|
|
562
|
-
const evaluated = environment.runner.evaluatedModules.getModulesByFile(module.file);
|
|
563
|
-
for (const node of evaluated ?? []) environment.runner.evaluatedModules.invalidateModule(node);
|
|
564
|
-
}
|
|
565
564
|
}
|
|
566
565
|
}
|
|
567
566
|
function collectWithImporters(module, seen) {
|
|
@@ -607,84 +606,6 @@ function isTranslated(localeFile) {
|
|
|
607
606
|
}
|
|
608
607
|
return hasTranslations;
|
|
609
608
|
}
|
|
610
|
-
function buildPatches(before, after, locale) {
|
|
611
|
-
const patches = [];
|
|
612
|
-
const fileIds = /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)]);
|
|
613
|
-
for (const fileId of fileIds) {
|
|
614
|
-
const beforeEntries = before[fileId] ?? {};
|
|
615
|
-
const afterEntries = after[fileId] ?? {};
|
|
616
|
-
const sources = /* @__PURE__ */ new Set([...Object.keys(beforeEntries), ...Object.keys(afterEntries)]);
|
|
617
|
-
for (const source of sources) {
|
|
618
|
-
const beforeEntry = beforeEntries[source];
|
|
619
|
-
const afterEntry = afterEntries[source];
|
|
620
|
-
walkEntry(patches, fileId, source, locale, beforeEntry, afterEntry);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
return patches;
|
|
624
|
-
}
|
|
625
|
-
function walkEntry(patches, fileId, source, locale, beforeEntry, afterEntry) {
|
|
626
|
-
if (typeof afterEntry === "string") {
|
|
627
|
-
if (beforeEntry && typeof beforeEntry === "object") for (const context of Object.keys(beforeEntry)) patches.push({
|
|
628
|
-
fileId,
|
|
629
|
-
id: toMessageKey(source, context),
|
|
630
|
-
locale,
|
|
631
|
-
value: ""
|
|
632
|
-
});
|
|
633
|
-
if (typeof beforeEntry !== "string" || beforeEntry !== afterEntry) patches.push({
|
|
634
|
-
fileId,
|
|
635
|
-
id: toMessageKey(source),
|
|
636
|
-
locale,
|
|
637
|
-
value: parseLocaleValue(afterEntry)
|
|
638
|
-
});
|
|
639
|
-
return;
|
|
640
|
-
}
|
|
641
|
-
if (afterEntry && typeof afterEntry === "object") {
|
|
642
|
-
if (typeof beforeEntry === "string") patches.push({
|
|
643
|
-
fileId,
|
|
644
|
-
id: toMessageKey(source),
|
|
645
|
-
locale,
|
|
646
|
-
value: ""
|
|
647
|
-
});
|
|
648
|
-
const beforeMap = beforeEntry && typeof beforeEntry === "object" ? beforeEntry : {};
|
|
649
|
-
const contexts = /* @__PURE__ */ new Set([...Object.keys(beforeMap), ...Object.keys(afterEntry)]);
|
|
650
|
-
for (const context of contexts) {
|
|
651
|
-
const beforeValue = beforeMap[context];
|
|
652
|
-
const afterValue = afterEntry[context];
|
|
653
|
-
if (typeof afterValue === "string") {
|
|
654
|
-
if (beforeValue !== afterValue) patches.push({
|
|
655
|
-
fileId,
|
|
656
|
-
id: toMessageKey(source, context),
|
|
657
|
-
locale,
|
|
658
|
-
value: parseLocaleValue(afterValue)
|
|
659
|
-
});
|
|
660
|
-
} else if (afterValue === void 0 && typeof beforeValue === "string") patches.push({
|
|
661
|
-
fileId,
|
|
662
|
-
id: toMessageKey(source, context),
|
|
663
|
-
locale,
|
|
664
|
-
value: ""
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
return;
|
|
668
|
-
}
|
|
669
|
-
if (typeof beforeEntry === "string") patches.push({
|
|
670
|
-
fileId,
|
|
671
|
-
id: toMessageKey(source),
|
|
672
|
-
locale,
|
|
673
|
-
value: ""
|
|
674
|
-
});
|
|
675
|
-
if (beforeEntry && typeof beforeEntry === "object") for (const context of Object.keys(beforeEntry)) patches.push({
|
|
676
|
-
fileId,
|
|
677
|
-
id: toMessageKey(source, context),
|
|
678
|
-
locale,
|
|
679
|
-
value: ""
|
|
680
|
-
});
|
|
681
|
-
}
|
|
682
|
-
function parseLocaleValue(raw) {
|
|
683
|
-
const { template } = parseTemplate(raw);
|
|
684
|
-
if (template.length === 0) return "";
|
|
685
|
-
if (template.length === 1 && template[0]?.kind === "literal") return template[0].value;
|
|
686
|
-
return template;
|
|
687
|
-
}
|
|
688
609
|
function toCallSitePositions(message) {
|
|
689
610
|
return message.locations.map((location) => ({
|
|
690
611
|
column: location.range.start.column,
|
|
@@ -796,11 +717,18 @@ function createTransformPlugin(state) {
|
|
|
796
717
|
localeData: getResolver(state).getLocaleData(),
|
|
797
718
|
locales
|
|
798
719
|
});
|
|
720
|
+
let localeFilePaths;
|
|
721
|
+
if (state.command === "serve" && this.environment.config.consumer === "server") {
|
|
722
|
+
const localesDir = join(state.projectRoot, getNormalized(state).localesDir);
|
|
723
|
+
localeFilePaths = {};
|
|
724
|
+
for (const locale of locales) localeFilePaths[locale] = join(localesDir, `${locale}.json`);
|
|
725
|
+
}
|
|
799
726
|
const result = transformFile({
|
|
800
727
|
defaultLocale: getResolver(state).getProjectLocales().defaultLocale,
|
|
801
728
|
dev: state.command === "serve",
|
|
802
729
|
extracted,
|
|
803
730
|
fileId,
|
|
731
|
+
localeFilePaths,
|
|
804
732
|
locales,
|
|
805
733
|
processors: getNormalized(state).processors,
|
|
806
734
|
source: code,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yapyak/vite",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Vite plugin for yapyak.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -30,17 +30,17 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@types/node": "26.1.
|
|
34
|
-
"tsdown": "0.22.
|
|
33
|
+
"@types/node": "26.1.2",
|
|
34
|
+
"tsdown": "0.22.14",
|
|
35
35
|
"typescript": "6.0.3",
|
|
36
|
-
"vite": "8.
|
|
36
|
+
"vite": "8.2.0",
|
|
37
37
|
"vitest": "4.1.10",
|
|
38
38
|
"@yapyak/tsdown-config": "0.0.0",
|
|
39
39
|
"@yapyak/typescript-config": "0.0.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"vite": ">=8",
|
|
43
|
-
"yapyak": "0.0.
|
|
43
|
+
"yapyak": "0.0.7"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=22.22"
|