@yapyak/vite 0.0.4 → 0.0.5
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 +29 -2
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
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";
|
|
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";
|
|
4
5
|
import { readFileSync } from "node:fs";
|
|
5
6
|
//#region src/locale-resolver.ts
|
|
6
7
|
function createLocaleResolver(context, projectRoot, options) {
|
|
@@ -425,6 +426,7 @@ function createDevServerPlugin(state) {
|
|
|
425
426
|
if (pendingLocalePaths.size === 0) return;
|
|
426
427
|
const allPatches = [];
|
|
427
428
|
const filesToReload = /* @__PURE__ */ new Set();
|
|
429
|
+
const patchedFiles = /* @__PURE__ */ new Set();
|
|
428
430
|
const skipHmrExtensions = getNormalized(state).processors.filter((processor) => processor.skipHmrCallback === true).flatMap((processor) => processor.extensions);
|
|
429
431
|
for (const localePath of pendingLocalePaths) {
|
|
430
432
|
const locale = localeFromPath(localePath);
|
|
@@ -433,12 +435,16 @@ function createDevServerPlugin(state) {
|
|
|
433
435
|
if (after === void 0) continue;
|
|
434
436
|
previousLocaleData.set(locale, after);
|
|
435
437
|
const localePatches = buildPatches(before, after, locale);
|
|
436
|
-
for (const patch of localePatches)
|
|
437
|
-
|
|
438
|
+
for (const patch of localePatches) {
|
|
439
|
+
patchedFiles.add(join(state.projectRoot, patch.fileId));
|
|
440
|
+
if (skipHmrExtensions.some((extension) => patch.fileId.endsWith(extension))) filesToReload.add(join(state.projectRoot, patch.fileId));
|
|
441
|
+
else allPatches.push(patch);
|
|
442
|
+
}
|
|
438
443
|
}
|
|
439
444
|
pendingLocalePaths.clear();
|
|
440
445
|
if (allPatches.length === 0 && filesToReload.size === 0) return;
|
|
441
446
|
getResolver(state).invalidateData();
|
|
447
|
+
reloadServerEnvironments(server, patchedFiles);
|
|
442
448
|
for (const file of filesToReload) server.ws.send({
|
|
443
449
|
path: file,
|
|
444
450
|
type: "full-reload"
|
|
@@ -542,6 +548,27 @@ function createDevServerPlugin(state) {
|
|
|
542
548
|
name: "yapyak:dev-server"
|
|
543
549
|
};
|
|
544
550
|
}
|
|
551
|
+
function reloadServerEnvironments(server, files) {
|
|
552
|
+
for (const environment of Object.values(server.environments)) {
|
|
553
|
+
if (environment.name === "client") continue;
|
|
554
|
+
const affected = /* @__PURE__ */ new Set();
|
|
555
|
+
for (const file of files) for (const module of environment.moduleGraph.getModulesByFile(file) ?? []) collectWithImporters(module, affected);
|
|
556
|
+
if (affected.size === 0) continue;
|
|
557
|
+
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
|
+
}
|
|
566
|
+
}
|
|
567
|
+
function collectWithImporters(module, seen) {
|
|
568
|
+
if (seen.has(module)) return;
|
|
569
|
+
seen.add(module);
|
|
570
|
+
for (const importer of module.importers) collectWithImporters(importer, seen);
|
|
571
|
+
}
|
|
545
572
|
function reloadAllModules(server) {
|
|
546
573
|
server.moduleGraph.invalidateAll();
|
|
547
574
|
server.ws.send({ type: "full-reload" });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yapyak/vite",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
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.5"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=22.22"
|