@yapyak/vite 0.0.14 → 0.0.16
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.d.ts +2 -2
- package/dist/index.js +184 -146
- package/package.json +8 -8
package/dist/index.d.ts
CHANGED
|
@@ -47,6 +47,6 @@ type YapyakOptions = {
|
|
|
47
47
|
* });
|
|
48
48
|
* ```
|
|
49
49
|
*/
|
|
50
|
-
declare function yapyak(options?: YapyakOptions): Plugin[];
|
|
50
|
+
export declare function yapyak(options?: YapyakOptions): Plugin[];
|
|
51
51
|
//#endregion
|
|
52
|
-
export {
|
|
52
|
+
export type { YapyakOptions };
|
package/dist/index.js
CHANGED
|
@@ -1,29 +1,113 @@
|
|
|
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
|
-
import { createFilter, defineRuntime, loadYapyakConfig } from "yapyak/config/internal";
|
|
3
1
|
import { basename, extname, join, relative, resolve, sep } from "node:path";
|
|
2
|
+
import { CorruptLocaleFileError, YAP_COMPILE, YAP_RUNTIME, autoTranslate, detectRenames, discoverLocales, extractFile, findTranslation, getDocsUrl, hasParseFailure, migrateLocales, readLocaleData, readLocaleFile, resolveProcessor, syncLocaleFiles, toMessageKey, toVariants, transformFile, validateLocaleCode, walkSourceFiles, writeRegister } from "yapyak/compiler/internal";
|
|
3
|
+
import { createFilter, defineRuntime, loadYapyakConfig } from "yapyak/config/internal";
|
|
4
4
|
import { buildPatches } from "yapyak/internal";
|
|
5
5
|
import { readFileSync } from "node:fs";
|
|
6
|
+
//#region src/plugin/file-id.ts
|
|
7
|
+
function toFileId(projectRoot, id) {
|
|
8
|
+
const path = id.split("?")[0] ?? id;
|
|
9
|
+
return relative(projectRoot, path).replaceAll("\\", "/");
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/plugin/candidate-id.ts
|
|
13
|
+
function isCandidateId(id, filter, projectRoot) {
|
|
14
|
+
if (id.startsWith("\0")) return false;
|
|
15
|
+
return filter(toFileId(projectRoot, id));
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/plugin/state.ts
|
|
19
|
+
function createState(options = {}) {
|
|
20
|
+
return {
|
|
21
|
+
command: "serve",
|
|
22
|
+
extractionCache: /* @__PURE__ */ new Map(),
|
|
23
|
+
filter: () => false,
|
|
24
|
+
...options.fixedLocale !== void 0 && { fixedLocale: options.fixedLocale },
|
|
25
|
+
logger: createConsoleLogger(),
|
|
26
|
+
messagesByFile: /* @__PURE__ */ new Map(),
|
|
27
|
+
projectRoot: options.root === void 0 ? process.cwd() : resolve(options.root),
|
|
28
|
+
...options.root !== void 0 && { rootOverride: resolve(options.root) },
|
|
29
|
+
teardownCallbacks: [],
|
|
30
|
+
yapyakDir: ""
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function getNormalized(state) {
|
|
34
|
+
if (state.normalized === void 0) throw new Error("[yapyak] plugin used before configResolved — config is not loaded yet.");
|
|
35
|
+
return state.normalized;
|
|
36
|
+
}
|
|
37
|
+
function getResolver(state) {
|
|
38
|
+
if (state.resolver === void 0) throw new Error("[yapyak] plugin used before configResolved — config is not loaded yet.");
|
|
39
|
+
return state.resolver;
|
|
40
|
+
}
|
|
41
|
+
function createConsoleLogger() {
|
|
42
|
+
const noop = () => void 0;
|
|
43
|
+
return {
|
|
44
|
+
clearScreen: noop,
|
|
45
|
+
error: (message) => {
|
|
46
|
+
console.error(message);
|
|
47
|
+
},
|
|
48
|
+
hasErrorLogged: () => false,
|
|
49
|
+
hasWarned: false,
|
|
50
|
+
info: (message) => {
|
|
51
|
+
console.log(message);
|
|
52
|
+
},
|
|
53
|
+
warn: (message) => {
|
|
54
|
+
console.warn(message);
|
|
55
|
+
},
|
|
56
|
+
warnOnce: (message) => {
|
|
57
|
+
console.warn(message);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/plugin/compiler-runtime.ts
|
|
63
|
+
function createCompilerRuntimePlugin(state) {
|
|
64
|
+
return {
|
|
65
|
+
enforce: "pre",
|
|
66
|
+
name: "yapyak:compiler-runtime",
|
|
67
|
+
async resolveId(source, importer) {
|
|
68
|
+
const compilerRuntime = findCompilerRuntime(getNormalized(state).processors, source);
|
|
69
|
+
if (compilerRuntime === void 0 || importer === void 0 || !isCandidateId(importer, state.filter, state.projectRoot)) return null;
|
|
70
|
+
const resolved = await this.resolve(compilerRuntime.module, importer, { skipSelf: true });
|
|
71
|
+
if (resolved === null || resolved.id === importer) return null;
|
|
72
|
+
return resolved.id;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function findCompilerRuntime(processors, source) {
|
|
77
|
+
for (const processor of processors) {
|
|
78
|
+
const compilerRuntime = processor.runtime?.compilerRuntime;
|
|
79
|
+
if (compilerRuntime?.specifiers.includes(source)) return compilerRuntime;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
6
83
|
//#region src/locale-resolver.ts
|
|
7
|
-
function createLocaleResolver(
|
|
84
|
+
function createLocaleResolver(config, projectRoot, options) {
|
|
8
85
|
const fixedLocale = options?.fixedLocale;
|
|
9
86
|
let discovery;
|
|
10
87
|
let emitted;
|
|
11
88
|
let localeData;
|
|
12
89
|
function getDiscovery() {
|
|
13
|
-
if (discovery === void 0) discovery = discoverLocales(
|
|
90
|
+
if (discovery === void 0) discovery = discoverLocales(config.localesDir, projectRoot, {
|
|
91
|
+
defaultLocale: config.defaultLocale,
|
|
92
|
+
sourceLocale: config.sourceLocale
|
|
93
|
+
});
|
|
14
94
|
return discovery;
|
|
15
95
|
}
|
|
16
96
|
function getProjectLocales() {
|
|
17
97
|
const result = getDiscovery();
|
|
18
98
|
return {
|
|
19
99
|
defaultLocale: result.defaultLocale,
|
|
20
|
-
locales: result.locales
|
|
100
|
+
locales: result.locales,
|
|
101
|
+
sourceLocale: result.sourceLocale
|
|
21
102
|
};
|
|
22
103
|
}
|
|
23
104
|
function getEmittedLocales() {
|
|
24
105
|
if (emitted === void 0) {
|
|
25
106
|
const project = getProjectLocales();
|
|
26
|
-
emitted = fixedLocale === void 0 ?
|
|
107
|
+
emitted = fixedLocale === void 0 ? {
|
|
108
|
+
defaultLocale: project.defaultLocale,
|
|
109
|
+
locales: project.locales
|
|
110
|
+
} : {
|
|
27
111
|
defaultLocale: fixedLocale,
|
|
28
112
|
locales: [fixedLocale]
|
|
29
113
|
};
|
|
@@ -33,7 +117,7 @@ function createLocaleResolver(context, projectRoot, options) {
|
|
|
33
117
|
function getLocaleData() {
|
|
34
118
|
if (localeData === void 0) localeData = readLocaleData({
|
|
35
119
|
locales: getEmittedLocales().locales,
|
|
36
|
-
localesDir:
|
|
120
|
+
localesDir: config.localesDir
|
|
37
121
|
}, projectRoot);
|
|
38
122
|
return localeData;
|
|
39
123
|
}
|
|
@@ -102,7 +186,8 @@ function createConfigPlugin(state) {
|
|
|
102
186
|
}
|
|
103
187
|
state.resolver = createLocaleResolver({
|
|
104
188
|
defaultLocale: result.config.defaultLocale,
|
|
105
|
-
localesDir: result.config.localesDir
|
|
189
|
+
localesDir: result.config.localesDir,
|
|
190
|
+
sourceLocale: result.config.sourceLocale
|
|
106
191
|
}, state.projectRoot, { fixedLocale: state.fixedLocale });
|
|
107
192
|
const discovery = state.resolver.getDiscovery();
|
|
108
193
|
for (const warning of discovery.warnings) state.logger.warn(renderLocaleWarning(warning, result.config.localesDir));
|
|
@@ -126,22 +211,11 @@ function toRuntimeModules(processors) {
|
|
|
126
211
|
for (const processor of processors) {
|
|
127
212
|
if (processor.runtime === void 0) continue;
|
|
128
213
|
modules.push(processor.runtime.module);
|
|
214
|
+
if (processor.runtime.compilerRuntime !== void 0) modules.push(processor.runtime.compilerRuntime.module);
|
|
129
215
|
}
|
|
130
216
|
return modules;
|
|
131
217
|
}
|
|
132
218
|
//#endregion
|
|
133
|
-
//#region src/plugin/file-id.ts
|
|
134
|
-
function toFileId(projectRoot, id) {
|
|
135
|
-
const path = id.split("?")[0] ?? id;
|
|
136
|
-
return relative(projectRoot, path).replaceAll("\\", "/");
|
|
137
|
-
}
|
|
138
|
-
//#endregion
|
|
139
|
-
//#region src/plugin/candidate-id.ts
|
|
140
|
-
function isCandidateId(id, filter, projectRoot) {
|
|
141
|
-
if (id.startsWith("\0")) return false;
|
|
142
|
-
return filter(toFileId(projectRoot, id));
|
|
143
|
-
}
|
|
144
|
-
//#endregion
|
|
145
219
|
//#region src/plugin/error-diagnostic.ts
|
|
146
220
|
function renderErrorDiagnostics(logger, result) {
|
|
147
221
|
const errors = [];
|
|
@@ -155,66 +229,22 @@ function renderErrorDiagnostics(logger, result) {
|
|
|
155
229
|
}
|
|
156
230
|
return errors;
|
|
157
231
|
}
|
|
158
|
-
function hasParseFailure(result) {
|
|
159
|
-
return result.diagnostics.some((diagnostic) => diagnostic.code === YAP_COMPILE.PROCESSOR_PARSE_ERROR.code);
|
|
160
|
-
}
|
|
161
232
|
function formatDiagnostic(diagnostic) {
|
|
162
233
|
const location = `${diagnostic.fileId}:${diagnostic.range.start.line}:${diagnostic.range.start.column}`;
|
|
163
234
|
return `[yapyak] ${diagnostic.code} ${location}: ${diagnostic.message}\nSee ${getDocsUrl(diagnostic.code)}`;
|
|
164
235
|
}
|
|
165
236
|
//#endregion
|
|
166
|
-
//#region src/plugin/state.ts
|
|
167
|
-
function createState(options = {}) {
|
|
168
|
-
return {
|
|
169
|
-
command: "serve",
|
|
170
|
-
extractionCache: /* @__PURE__ */ new Map(),
|
|
171
|
-
filter: () => false,
|
|
172
|
-
...options.fixedLocale !== void 0 && { fixedLocale: options.fixedLocale },
|
|
173
|
-
logger: createConsoleLogger(),
|
|
174
|
-
messagesByFile: /* @__PURE__ */ new Map(),
|
|
175
|
-
projectRoot: options.root === void 0 ? process.cwd() : resolve(options.root),
|
|
176
|
-
...options.root !== void 0 && { rootOverride: resolve(options.root) },
|
|
177
|
-
teardownCallbacks: [],
|
|
178
|
-
yapyakDir: ""
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
function getNormalized(state) {
|
|
182
|
-
if (state.normalized === void 0) throw new Error("[yapyak] plugin used before configResolved — config is not loaded yet.");
|
|
183
|
-
return state.normalized;
|
|
184
|
-
}
|
|
185
|
-
function getResolver(state) {
|
|
186
|
-
if (state.resolver === void 0) throw new Error("[yapyak] plugin used before configResolved — config is not loaded yet.");
|
|
187
|
-
return state.resolver;
|
|
188
|
-
}
|
|
189
|
-
function createConsoleLogger() {
|
|
190
|
-
const noop = () => void 0;
|
|
191
|
-
return {
|
|
192
|
-
clearScreen: noop,
|
|
193
|
-
error: (message) => {
|
|
194
|
-
console.error(message);
|
|
195
|
-
},
|
|
196
|
-
hasErrorLogged: () => false,
|
|
197
|
-
hasWarned: false,
|
|
198
|
-
info: (message) => {
|
|
199
|
-
console.log(message);
|
|
200
|
-
},
|
|
201
|
-
warn: (message) => {
|
|
202
|
-
console.warn(message);
|
|
203
|
-
},
|
|
204
|
-
warnOnce: (message) => {
|
|
205
|
-
console.warn(message);
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
//#endregion
|
|
210
237
|
//#region src/plugin/extraction.ts
|
|
211
238
|
function resolveExtraction(state, fileId, source) {
|
|
212
239
|
const { processors } = getNormalized(state);
|
|
213
|
-
if (!source.includes("yapyak") && !hasAmbientBindings(processors))
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
240
|
+
if (!source.includes("yapyak") && !hasAmbientBindings(processors)) {
|
|
241
|
+
state.extractionCache.delete(fileId);
|
|
242
|
+
return {
|
|
243
|
+
callSites: [],
|
|
244
|
+
diagnostics: [],
|
|
245
|
+
messages: []
|
|
246
|
+
};
|
|
247
|
+
}
|
|
218
248
|
const entry = state.extractionCache.get(fileId);
|
|
219
249
|
if (entry && entry.source === source && entry.callSiteCount === 0) return {
|
|
220
250
|
callSites: [],
|
|
@@ -262,25 +292,25 @@ function fillStubs(state) {
|
|
|
262
292
|
const allMessages = [];
|
|
263
293
|
for (const list of state.messagesByFile.values()) allMessages.push(...list);
|
|
264
294
|
if (allMessages.length === 0) return;
|
|
265
|
-
const {
|
|
295
|
+
const { locales, sourceLocale } = getResolver(state).getProjectLocales();
|
|
266
296
|
const translatableLocales = locales.filter((locale) => validateLocaleCode(locale).valid);
|
|
267
|
-
const missing = discoverMissingMessageKeys(allMessages, translatableLocales,
|
|
297
|
+
const missing = discoverMissingMessageKeys(allMessages, translatableLocales, sourceLocale, getResolver(state).getLocaleData());
|
|
268
298
|
if (missing.size === 0) return;
|
|
269
299
|
if (missing.size > config.autoTranslateThreshold) {
|
|
270
300
|
state.logger.info(`[yapyak] ${missing.size} new strings detected. Run \`${runYapyakCommand("translate")}\` to fill.`);
|
|
271
301
|
return;
|
|
272
302
|
}
|
|
273
303
|
const filtered = allMessages.filter((message) => missing.has(toMessageKey(message.source, message.context)));
|
|
274
|
-
const targetLocaleCount = translatableLocales.filter((locale) => locale !==
|
|
304
|
+
const targetLocaleCount = translatableLocales.filter((locale) => locale !== sourceLocale).length;
|
|
275
305
|
const startedAt = Date.now();
|
|
276
306
|
state.logger.info(`[yapyak] translating ${filtered.length} ${pluralize("string", filtered.length)} × ${targetLocaleCount} ${pluralize("locale", targetLocaleCount)} via ${translator.id}…`);
|
|
277
307
|
const controller = new AbortController();
|
|
278
308
|
state.autoTranslateController = controller;
|
|
279
309
|
runAutoTranslate(state, {
|
|
280
|
-
defaultLocale,
|
|
281
310
|
filtered,
|
|
282
311
|
locales,
|
|
283
312
|
signal: controller.signal,
|
|
313
|
+
sourceLocale,
|
|
284
314
|
startedAt,
|
|
285
315
|
translator
|
|
286
316
|
});
|
|
@@ -292,9 +322,9 @@ async function runAutoTranslate(state, input) {
|
|
|
292
322
|
messages: input.filtered,
|
|
293
323
|
translator: input.translator
|
|
294
324
|
}, {
|
|
295
|
-
defaultLocale: input.defaultLocale,
|
|
296
325
|
locales: input.locales,
|
|
297
|
-
localesDir: config.localesDir
|
|
326
|
+
localesDir: config.localesDir,
|
|
327
|
+
sourceLocale: input.sourceLocale
|
|
298
328
|
}, state.projectRoot, {
|
|
299
329
|
signal: input.signal,
|
|
300
330
|
yapyakDir: state.yapyakDir
|
|
@@ -311,14 +341,14 @@ async function runAutoTranslate(state, input) {
|
|
|
311
341
|
state.logger.warn(`[yapyak] auto-translate error · ${elapsed} · ${String(error)}`);
|
|
312
342
|
}
|
|
313
343
|
}
|
|
314
|
-
function discoverMissingMessageKeys(messages, locales,
|
|
344
|
+
function discoverMissingMessageKeys(messages, locales, sourceLocale, localeData) {
|
|
315
345
|
const missing = /* @__PURE__ */ new Set();
|
|
316
346
|
for (const message of messages) {
|
|
317
347
|
const messageKey = toMessageKey(message.source, message.context);
|
|
318
348
|
if (missing.has(messageKey)) continue;
|
|
319
349
|
let isFlagged = false;
|
|
320
350
|
for (const locale of locales) {
|
|
321
|
-
if (locale ===
|
|
351
|
+
if (locale === sourceLocale) continue;
|
|
322
352
|
const localeFile = localeData[locale];
|
|
323
353
|
for (const location of message.locations) {
|
|
324
354
|
const existing = findTranslation(localeFile?.[location.fileId]?.[message.source], message.context);
|
|
@@ -372,17 +402,21 @@ function formatElapsed(ms) {
|
|
|
372
402
|
function syncAll(state) {
|
|
373
403
|
const allMessages = [];
|
|
374
404
|
for (const list of state.messagesByFile.values()) allMessages.push(...list);
|
|
375
|
-
const {
|
|
405
|
+
const { locales, sourceLocale } = getResolver(state).getProjectLocales();
|
|
376
406
|
emitSyncDiagnostics(state, syncLocaleFiles({
|
|
377
|
-
filter: state.filter,
|
|
407
|
+
filter: (fileId) => state.filter(fileId) && isParsed(state, fileId),
|
|
378
408
|
messages: allMessages
|
|
379
409
|
}, {
|
|
380
|
-
defaultLocale,
|
|
381
410
|
locales,
|
|
382
|
-
localesDir: getNormalized(state).localesDir
|
|
411
|
+
localesDir: getNormalized(state).localesDir,
|
|
412
|
+
sourceLocale
|
|
383
413
|
}, state.projectRoot, { yapyakDir: state.yapyakDir }));
|
|
384
414
|
getResolver(state).invalidateData();
|
|
385
415
|
}
|
|
416
|
+
function isParsed(state, fileId) {
|
|
417
|
+
const entry = state.extractionCache.get(fileId);
|
|
418
|
+
return entry === void 0 || !hasParseFailure(entry);
|
|
419
|
+
}
|
|
386
420
|
function emitSyncDiagnostics(state, result) {
|
|
387
421
|
for (const entry of result.orphaned) state.logger.warn(`[yapyak] preserved '${entry.source}' (${entry.locale}) — call site removed from ${entry.fileId}, translation saved in case it returns.`);
|
|
388
422
|
for (const entry of result.restored) state.logger.info(`[yapyak] restored '${entry.source}' (${entry.locale}) in ${entry.fileId} — translation kept from when the call site was removed earlier.`);
|
|
@@ -532,7 +566,7 @@ function createDevServerPlugin(state) {
|
|
|
532
566
|
if (options.type === "create") return;
|
|
533
567
|
const fileId = toFileId(state.projectRoot, options.file);
|
|
534
568
|
const code = await options.read();
|
|
535
|
-
const {
|
|
569
|
+
const { locales, sourceLocale } = getResolver(state).getProjectLocales();
|
|
536
570
|
const result = resolveExtraction(state, fileId, code);
|
|
537
571
|
renderErrorDiagnostics(state.logger, result);
|
|
538
572
|
if (hasParseFailure(result)) return;
|
|
@@ -546,9 +580,9 @@ function createDevServerPlugin(state) {
|
|
|
546
580
|
fileId,
|
|
547
581
|
renames
|
|
548
582
|
}, {
|
|
549
|
-
defaultLocale,
|
|
550
583
|
locales,
|
|
551
|
-
localesDir: getNormalized(state).localesDir
|
|
584
|
+
localesDir: getNormalized(state).localesDir,
|
|
585
|
+
sourceLocale
|
|
552
586
|
}, state.projectRoot, { preserveTranslations: true });
|
|
553
587
|
for (const conflict of migrationResult.conflicts) state.logger.warn(`[yapyak] rename '${conflict.from}' → '${conflict.to}' skipped for '${conflict.locale}' in ${conflict.fileId} — target already has a translation.`);
|
|
554
588
|
getResolver(state).invalidateData();
|
|
@@ -688,67 +722,70 @@ function createTransformPlugin(state) {
|
|
|
688
722
|
return {
|
|
689
723
|
enforce: "pre",
|
|
690
724
|
name: "yapyak:transform",
|
|
691
|
-
transform
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
725
|
+
transform: {
|
|
726
|
+
handler(code, id) {
|
|
727
|
+
if (id.startsWith("\0")) return null;
|
|
728
|
+
if (VITE_NON_CODE_QUERY_RX.test(id)) return null;
|
|
729
|
+
const queryStart = id.indexOf("?");
|
|
730
|
+
const filePath = queryStart === -1 ? id : id.slice(0, queryStart);
|
|
731
|
+
if (!isCandidateId(filePath, state.filter, state.projectRoot)) return null;
|
|
732
|
+
const fileId = toFileId(state.projectRoot, filePath);
|
|
733
|
+
const { locales } = getResolver(state).getEmittedLocales();
|
|
734
|
+
const extracted = resolveExtraction(state, fileId, code);
|
|
735
|
+
const errorDiagnostics = renderErrorDiagnostics(state.logger, extracted);
|
|
736
|
+
const firstError = errorDiagnostics[0];
|
|
737
|
+
if (firstError !== void 0) {
|
|
738
|
+
for (let index = 1; index < errorDiagnostics.length; index += 1) {
|
|
739
|
+
const subsequent = errorDiagnostics[index];
|
|
740
|
+
if (subsequent !== void 0) state.logger.error(formatDiagnostic(subsequent));
|
|
741
|
+
}
|
|
742
|
+
this.error({
|
|
743
|
+
code: firstError.code,
|
|
744
|
+
id: firstError.fileId,
|
|
745
|
+
loc: {
|
|
746
|
+
column: firstError.range.start.column,
|
|
747
|
+
file: firstError.fileId,
|
|
748
|
+
line: firstError.range.start.line
|
|
749
|
+
},
|
|
750
|
+
message: `${firstError.message}\nSee ${getDocsUrl(firstError.code)}`
|
|
751
|
+
});
|
|
706
752
|
}
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
line: firstError.range.start.line
|
|
714
|
-
},
|
|
715
|
-
message: `${firstError.message}\nSee ${getDocsUrl(firstError.code)}`
|
|
753
|
+
if (extracted.callSites.length === 0 && resolveProcessor(fileId, code, getNormalized(state).processors).runtime?.componentHook === void 0) return null;
|
|
754
|
+
const translations = buildTranslations({
|
|
755
|
+
extracted,
|
|
756
|
+
fileId,
|
|
757
|
+
localeData: getResolver(state).getLocaleData(),
|
|
758
|
+
locales
|
|
716
759
|
});
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
for (const locale of getResolver(state).getProjectLocales().locales) this.addWatchFile(join(localesDir, `${locale}.json`));
|
|
747
|
-
}
|
|
748
|
-
return {
|
|
749
|
-
code: result.code,
|
|
750
|
-
map: result.map
|
|
751
|
-
};
|
|
760
|
+
let localeFilePaths;
|
|
761
|
+
if (state.command === "serve" && this.environment.config.consumer === "server") {
|
|
762
|
+
const localesDir = join(state.projectRoot, getNormalized(state).localesDir);
|
|
763
|
+
localeFilePaths = {};
|
|
764
|
+
for (const locale of locales) localeFilePaths[locale] = join(localesDir, `${locale}.json`);
|
|
765
|
+
}
|
|
766
|
+
const result = transformFile({
|
|
767
|
+
dev: state.command === "serve",
|
|
768
|
+
extracted,
|
|
769
|
+
fileId,
|
|
770
|
+
localeFilePaths,
|
|
771
|
+
locales,
|
|
772
|
+
processors: getNormalized(state).processors,
|
|
773
|
+
source: code,
|
|
774
|
+
sourceLocale: getResolver(state).getProjectLocales().sourceLocale,
|
|
775
|
+
sourcePath: filePath,
|
|
776
|
+
translations
|
|
777
|
+
});
|
|
778
|
+
if (result.code === code) return null;
|
|
779
|
+
if (state.command === "build") {
|
|
780
|
+
const localesDir = join(state.projectRoot, getNormalized(state).localesDir);
|
|
781
|
+
for (const locale of getResolver(state).getProjectLocales().locales) this.addWatchFile(join(localesDir, `${locale}.json`));
|
|
782
|
+
}
|
|
783
|
+
return {
|
|
784
|
+
code: result.code,
|
|
785
|
+
map: result.map
|
|
786
|
+
};
|
|
787
|
+
},
|
|
788
|
+
order: "pre"
|
|
752
789
|
},
|
|
753
790
|
watchChange(id, change) {
|
|
754
791
|
if (state.command !== "build") return;
|
|
@@ -842,6 +879,7 @@ function yapyak(options = {}) {
|
|
|
842
879
|
createVirtualModulePlugin(state),
|
|
843
880
|
createScanPlugin(state),
|
|
844
881
|
createTransformPlugin(state),
|
|
882
|
+
createCompilerRuntimePlugin(state),
|
|
845
883
|
createDevServerPlugin(state)
|
|
846
884
|
];
|
|
847
885
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yapyak/vite",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "Vite plugin for yapyak.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -32,17 +32,17 @@
|
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@types/node": "26.
|
|
36
|
-
"tsdown": "0.
|
|
35
|
+
"@types/node": "26.6.2",
|
|
36
|
+
"tsdown": "0.23.0",
|
|
37
37
|
"typescript": "6.0.3",
|
|
38
|
-
"vite": "8.
|
|
39
|
-
"vitest": "
|
|
40
|
-
"@yapyak/
|
|
41
|
-
"@yapyak/
|
|
38
|
+
"vite": "8.3.1",
|
|
39
|
+
"vitest": "5.0.1",
|
|
40
|
+
"@yapyak/tsdown-config": "0.0.0",
|
|
41
|
+
"@yapyak/typescript-config": "0.0.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"vite": ">=8",
|
|
45
|
-
"yapyak": "0.0.
|
|
45
|
+
"yapyak": "0.0.16"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
|
48
48
|
"node": ">=22.22"
|