@yapyak/vite 0.0.4 → 0.0.6
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 +27 -81
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CorruptLocaleFileError, YAP_RUNTIME, autoTranslate, detectRenames, discoverLocales, extractFile, findTranslation, getDocsUrl, migrateLocales,
|
|
1
|
+
import { CorruptLocaleFileError, YAP_RUNTIME, autoTranslate, buildPatches, 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
4
|
import { readFileSync } from "node:fs";
|
|
@@ -425,6 +425,7 @@ function createDevServerPlugin(state) {
|
|
|
425
425
|
if (pendingLocalePaths.size === 0) return;
|
|
426
426
|
const allPatches = [];
|
|
427
427
|
const filesToReload = /* @__PURE__ */ new Set();
|
|
428
|
+
const patchedFiles = /* @__PURE__ */ new Set();
|
|
428
429
|
const skipHmrExtensions = getNormalized(state).processors.filter((processor) => processor.skipHmrCallback === true).flatMap((processor) => processor.extensions);
|
|
429
430
|
for (const localePath of pendingLocalePaths) {
|
|
430
431
|
const locale = localeFromPath(localePath);
|
|
@@ -433,12 +434,16 @@ function createDevServerPlugin(state) {
|
|
|
433
434
|
if (after === void 0) continue;
|
|
434
435
|
previousLocaleData.set(locale, after);
|
|
435
436
|
const localePatches = buildPatches(before, after, locale);
|
|
436
|
-
for (const patch of localePatches)
|
|
437
|
-
|
|
437
|
+
for (const patch of localePatches) {
|
|
438
|
+
patchedFiles.add(join(state.projectRoot, patch.fileId));
|
|
439
|
+
if (skipHmrExtensions.some((extension) => patch.fileId.endsWith(extension))) filesToReload.add(join(state.projectRoot, patch.fileId));
|
|
440
|
+
else allPatches.push(patch);
|
|
441
|
+
}
|
|
438
442
|
}
|
|
439
443
|
pendingLocalePaths.clear();
|
|
440
444
|
if (allPatches.length === 0 && filesToReload.size === 0) return;
|
|
441
445
|
getResolver(state).invalidateData();
|
|
446
|
+
invalidateEnvironments(server, patchedFiles);
|
|
442
447
|
for (const file of filesToReload) server.ws.send({
|
|
443
448
|
path: file,
|
|
444
449
|
type: "full-reload"
|
|
@@ -542,6 +547,18 @@ function createDevServerPlugin(state) {
|
|
|
542
547
|
name: "yapyak:dev-server"
|
|
543
548
|
};
|
|
544
549
|
}
|
|
550
|
+
function invalidateEnvironments(server, files) {
|
|
551
|
+
for (const environment of Object.values(server.environments)) {
|
|
552
|
+
const affected = /* @__PURE__ */ new Set();
|
|
553
|
+
for (const file of files) for (const module of environment.moduleGraph.getModulesByFile(file) ?? []) collectWithImporters(module, affected);
|
|
554
|
+
for (const module of affected) environment.moduleGraph.invalidateModule(module);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
function collectWithImporters(module, seen) {
|
|
558
|
+
if (seen.has(module)) return;
|
|
559
|
+
seen.add(module);
|
|
560
|
+
for (const importer of module.importers) collectWithImporters(importer, seen);
|
|
561
|
+
}
|
|
545
562
|
function reloadAllModules(server) {
|
|
546
563
|
server.moduleGraph.invalidateAll();
|
|
547
564
|
server.ws.send({ type: "full-reload" });
|
|
@@ -580,84 +597,6 @@ function isTranslated(localeFile) {
|
|
|
580
597
|
}
|
|
581
598
|
return hasTranslations;
|
|
582
599
|
}
|
|
583
|
-
function buildPatches(before, after, locale) {
|
|
584
|
-
const patches = [];
|
|
585
|
-
const fileIds = /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)]);
|
|
586
|
-
for (const fileId of fileIds) {
|
|
587
|
-
const beforeEntries = before[fileId] ?? {};
|
|
588
|
-
const afterEntries = after[fileId] ?? {};
|
|
589
|
-
const sources = /* @__PURE__ */ new Set([...Object.keys(beforeEntries), ...Object.keys(afterEntries)]);
|
|
590
|
-
for (const source of sources) {
|
|
591
|
-
const beforeEntry = beforeEntries[source];
|
|
592
|
-
const afterEntry = afterEntries[source];
|
|
593
|
-
walkEntry(patches, fileId, source, locale, beforeEntry, afterEntry);
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
return patches;
|
|
597
|
-
}
|
|
598
|
-
function walkEntry(patches, fileId, source, locale, beforeEntry, afterEntry) {
|
|
599
|
-
if (typeof afterEntry === "string") {
|
|
600
|
-
if (beforeEntry && typeof beforeEntry === "object") for (const context of Object.keys(beforeEntry)) patches.push({
|
|
601
|
-
fileId,
|
|
602
|
-
id: toMessageKey(source, context),
|
|
603
|
-
locale,
|
|
604
|
-
value: ""
|
|
605
|
-
});
|
|
606
|
-
if (typeof beforeEntry !== "string" || beforeEntry !== afterEntry) patches.push({
|
|
607
|
-
fileId,
|
|
608
|
-
id: toMessageKey(source),
|
|
609
|
-
locale,
|
|
610
|
-
value: parseLocaleValue(afterEntry)
|
|
611
|
-
});
|
|
612
|
-
return;
|
|
613
|
-
}
|
|
614
|
-
if (afterEntry && typeof afterEntry === "object") {
|
|
615
|
-
if (typeof beforeEntry === "string") patches.push({
|
|
616
|
-
fileId,
|
|
617
|
-
id: toMessageKey(source),
|
|
618
|
-
locale,
|
|
619
|
-
value: ""
|
|
620
|
-
});
|
|
621
|
-
const beforeMap = beforeEntry && typeof beforeEntry === "object" ? beforeEntry : {};
|
|
622
|
-
const contexts = /* @__PURE__ */ new Set([...Object.keys(beforeMap), ...Object.keys(afterEntry)]);
|
|
623
|
-
for (const context of contexts) {
|
|
624
|
-
const beforeValue = beforeMap[context];
|
|
625
|
-
const afterValue = afterEntry[context];
|
|
626
|
-
if (typeof afterValue === "string") {
|
|
627
|
-
if (beforeValue !== afterValue) patches.push({
|
|
628
|
-
fileId,
|
|
629
|
-
id: toMessageKey(source, context),
|
|
630
|
-
locale,
|
|
631
|
-
value: parseLocaleValue(afterValue)
|
|
632
|
-
});
|
|
633
|
-
} else if (afterValue === void 0 && typeof beforeValue === "string") patches.push({
|
|
634
|
-
fileId,
|
|
635
|
-
id: toMessageKey(source, context),
|
|
636
|
-
locale,
|
|
637
|
-
value: ""
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
return;
|
|
641
|
-
}
|
|
642
|
-
if (typeof beforeEntry === "string") patches.push({
|
|
643
|
-
fileId,
|
|
644
|
-
id: toMessageKey(source),
|
|
645
|
-
locale,
|
|
646
|
-
value: ""
|
|
647
|
-
});
|
|
648
|
-
if (beforeEntry && typeof beforeEntry === "object") for (const context of Object.keys(beforeEntry)) patches.push({
|
|
649
|
-
fileId,
|
|
650
|
-
id: toMessageKey(source, context),
|
|
651
|
-
locale,
|
|
652
|
-
value: ""
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
function parseLocaleValue(raw) {
|
|
656
|
-
const { template } = parseTemplate(raw);
|
|
657
|
-
if (template.length === 0) return "";
|
|
658
|
-
if (template.length === 1 && template[0]?.kind === "literal") return template[0].value;
|
|
659
|
-
return template;
|
|
660
|
-
}
|
|
661
600
|
function toCallSitePositions(message) {
|
|
662
601
|
return message.locations.map((location) => ({
|
|
663
602
|
column: location.range.start.column,
|
|
@@ -769,11 +708,18 @@ function createTransformPlugin(state) {
|
|
|
769
708
|
localeData: getResolver(state).getLocaleData(),
|
|
770
709
|
locales
|
|
771
710
|
});
|
|
711
|
+
let localeFilePaths;
|
|
712
|
+
if (state.command === "serve" && this.environment.config.consumer === "server") {
|
|
713
|
+
const localesDir = join(state.projectRoot, getNormalized(state).localesDir);
|
|
714
|
+
localeFilePaths = {};
|
|
715
|
+
for (const locale of locales) localeFilePaths[locale] = join(localesDir, `${locale}.json`);
|
|
716
|
+
}
|
|
772
717
|
const result = transformFile({
|
|
773
718
|
defaultLocale: getResolver(state).getProjectLocales().defaultLocale,
|
|
774
719
|
dev: state.command === "serve",
|
|
775
720
|
extracted,
|
|
776
721
|
fileId,
|
|
722
|
+
localeFilePaths,
|
|
777
723
|
locales,
|
|
778
724
|
processors: getNormalized(state).processors,
|
|
779
725
|
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.6",
|
|
4
4
|
"description": "Vite plugin for yapyak.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"vite": ">=8",
|
|
43
|
-
"yapyak": "0.0.
|
|
43
|
+
"yapyak": "0.0.6"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=22.22"
|