@yapyak/vite 0.0.5 → 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.
Files changed (2) hide show
  1. package/dist/index.js +10 -91
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
- import { CorruptLocaleFileError, YAP_RUNTIME, autoTranslate, detectRenames, discoverLocales, extractFile, findTranslation, getDocsUrl, migrateLocales, parseTemplate, readLocaleData, readLocaleFile, syncLocaleFiles, toMessageKey, toVariants, transformFile, validateLocaleCode, walkSourceFiles, writeRegister } from "yapyak/compiler/internal";
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
- import { isRunnableDevEnvironment } from "vite";
5
4
  import { readFileSync } from "node:fs";
6
5
  //#region src/locale-resolver.ts
7
6
  function createLocaleResolver(context, projectRoot, options) {
@@ -444,7 +443,7 @@ function createDevServerPlugin(state) {
444
443
  pendingLocalePaths.clear();
445
444
  if (allPatches.length === 0 && filesToReload.size === 0) return;
446
445
  getResolver(state).invalidateData();
447
- reloadServerEnvironments(server, patchedFiles);
446
+ invalidateEnvironments(server, patchedFiles);
448
447
  for (const file of filesToReload) server.ws.send({
449
448
  path: file,
450
449
  type: "full-reload"
@@ -548,20 +547,11 @@ function createDevServerPlugin(state) {
548
547
  name: "yapyak:dev-server"
549
548
  };
550
549
  }
551
- function reloadServerEnvironments(server, files) {
550
+ function invalidateEnvironments(server, files) {
552
551
  for (const environment of Object.values(server.environments)) {
553
- if (environment.name === "client") continue;
554
552
  const affected = /* @__PURE__ */ new Set();
555
553
  for (const file of files) for (const module of environment.moduleGraph.getModulesByFile(file) ?? []) collectWithImporters(module, affected);
556
- if (affected.size === 0) continue;
557
554
  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
555
  }
566
556
  }
567
557
  function collectWithImporters(module, seen) {
@@ -607,84 +597,6 @@ function isTranslated(localeFile) {
607
597
  }
608
598
  return hasTranslations;
609
599
  }
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
600
  function toCallSitePositions(message) {
689
601
  return message.locations.map((location) => ({
690
602
  column: location.range.start.column,
@@ -796,11 +708,18 @@ function createTransformPlugin(state) {
796
708
  localeData: getResolver(state).getLocaleData(),
797
709
  locales
798
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
+ }
799
717
  const result = transformFile({
800
718
  defaultLocale: getResolver(state).getProjectLocales().defaultLocale,
801
719
  dev: state.command === "serve",
802
720
  extracted,
803
721
  fileId,
722
+ localeFilePaths,
804
723
  locales,
805
724
  processors: getNormalized(state).processors,
806
725
  source: code,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yapyak/vite",
3
- "version": "0.0.5",
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.5"
43
+ "yapyak": "0.0.6"
44
44
  },
45
45
  "engines": {
46
46
  "node": ">=22.22"