@yapyak/vite 0.0.17 → 0.0.19

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 CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Plugin } from "vite";
2
- //#region src/plugin.d.ts
3
2
  /**
4
3
  * Options for {@link yapyak}.
5
4
  */
@@ -48,5 +47,4 @@ type YapyakOptions = {
48
47
  * ```
49
48
  */
50
49
  export declare function yapyak(options?: YapyakOptions): Plugin[];
51
- //#endregion
52
50
  export type { YapyakOptions };
package/dist/index.js CHANGED
@@ -3,19 +3,17 @@ import { CorruptLocaleFileError, YAP_COMPILE, YAP_RUNTIME, autoTranslate, detect
3
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
6
+ // src/plugin/file-id.ts
7
7
  function toFileId(projectRoot, id) {
8
8
  const path = id.split("?")[0] ?? id;
9
9
  return relative(projectRoot, path).replaceAll("\\", "/");
10
10
  }
11
- //#endregion
12
- //#region src/plugin/candidate-id.ts
11
+ // src/plugin/candidate-id.ts
13
12
  function isCandidateId(id, filter, projectRoot) {
14
13
  if (id.startsWith("\0")) return false;
15
14
  return filter(toFileId(projectRoot, id));
16
15
  }
17
- //#endregion
18
- //#region src/plugin/state.ts
16
+ // src/plugin/state.ts
19
17
  function createState(options = {}) {
20
18
  return {
21
19
  command: "serve",
@@ -58,8 +56,7 @@ function createConsoleLogger() {
58
56
  }
59
57
  };
60
58
  }
61
- //#endregion
62
- //#region src/plugin/compiler-runtime.ts
59
+ // src/plugin/compiler-runtime.ts
63
60
  function createCompilerRuntimePlugin(state) {
64
61
  return {
65
62
  enforce: "pre",
@@ -79,8 +76,7 @@ function findCompilerRuntime(processors, source) {
79
76
  if (compilerRuntime?.specifiers.includes(source)) return compilerRuntime;
80
77
  }
81
78
  }
82
- //#endregion
83
- //#region src/locale-resolver.ts
79
+ // src/locale-resolver.ts
84
80
  function createLocaleResolver(config, projectRoot, options) {
85
81
  const fixedLocale = options?.fixedLocale;
86
82
  let discovery;
@@ -136,8 +132,7 @@ function createLocaleResolver(config, projectRoot, options) {
136
132
  }
137
133
  };
138
134
  }
139
- //#endregion
140
- //#region src/virtual-runtime.ts
135
+ // src/virtual-runtime.ts
141
136
  const RUNTIME_ID = "yapyak/runtime";
142
137
  const RUNTIME_CORE_IDS = ["yapyak", "yapyak/internal"];
143
138
  const RUNTIME_RESOLVED = "\0yapyak:runtime";
@@ -145,16 +140,14 @@ const RUNTIME_NO_EXTERNAL = ["yapyak", /^@yapyak\//];
145
140
  function isRuntimeExternal(id) {
146
141
  return RUNTIME_NO_EXTERNAL.some((pattern) => typeof pattern === "string" ? pattern === id : pattern.test(id));
147
142
  }
148
- //#endregion
149
- //#region src/plugin/locale-warning.ts
143
+ // src/plugin/locale-warning.ts
150
144
  function renderLocaleWarning(warning, localesDir) {
151
145
  const reason = warning.issue === "invalid-structure" ? "does not look like a BCP 47 locale tag" : "is not a recognized ISO 639-1 language code";
152
146
  const action = "yapyak will skip syncing stubs and translating for this locale.";
153
147
  const hint = warning.suggestion ? ` Did you mean '${warning.suggestion}'? Rename \`${localesDir}/${warning.code}.json\` to \`${localesDir}/${warning.suggestion}.json\` to enable.` : ` Rename \`${localesDir}/${warning.code}.json\` to a valid locale code, or remove the file.`;
154
148
  return `[yapyak] locale '${warning.code}' ${reason}. ${action}${hint}`;
155
149
  }
156
- //#endregion
157
- //#region src/plugin/config.ts
150
+ // src/plugin/config.ts
158
151
  function createConfigPlugin(state) {
159
152
  const loads = /* @__PURE__ */ new Map();
160
153
  return {
@@ -178,11 +171,14 @@ function createConfigPlugin(state) {
178
171
  state.normalized = result.config;
179
172
  state.configFile = result.configFile;
180
173
  state.filter = createFilter(result.config.include, result.config.exclude);
181
- const ssrExternal = config.ssr?.external;
182
- if (Array.isArray(ssrExternal) && config.ssr) config.ssr.external = ssrExternal.filter((id) => !isRuntimeExternal(id));
183
- else if (ssrExternal === true || typeof ssrExternal === "function") {
184
- const description = typeof ssrExternal === "function" ? "a function" : "`true`";
185
- state.logger.warn(`[yapyak] config.ssr.external is set to ${description}. yapyak's runtime must not be externalized for SSR — translations would not inline. Use an array form for ssr.external, or have your function return false/null for 'yapyak' and 'yapyak/runtime'.`);
174
+ for (const [name, environment] of Object.entries(config.environments)) {
175
+ if (environment.consumer === "client") continue;
176
+ const external = environment.resolve.external;
177
+ if (external === true) {
178
+ state.logger.warn(`[yapyak] resolve.external is \`true\` for the ${name} environment. yapyak's runtime must not be externalized for SSR — translations would not inline. Use an array for ssr.external that leaves out 'yapyak' and '@yapyak/*'.`);
179
+ continue;
180
+ }
181
+ environment.resolve.external = external.filter((id) => !isRuntimeExternal(id));
186
182
  }
187
183
  state.resolver = createLocaleResolver({
188
184
  defaultLocale: result.config.defaultLocale,
@@ -215,8 +211,7 @@ function toRuntimeModules(processors) {
215
211
  }
216
212
  return modules;
217
213
  }
218
- //#endregion
219
- //#region src/plugin/error-diagnostic.ts
214
+ // src/plugin/error-diagnostic.ts
220
215
  function renderErrorDiagnostics(logger, result) {
221
216
  const errors = [];
222
217
  for (const diagnostic of result.diagnostics) {
@@ -233,8 +228,7 @@ function formatDiagnostic(diagnostic) {
233
228
  const location = `${diagnostic.fileId}:${diagnostic.range.start.line}:${diagnostic.range.start.column}`;
234
229
  return `[yapyak] ${diagnostic.code} ${location}: ${diagnostic.message}\nSee ${getDocsUrl(diagnostic.code)}`;
235
230
  }
236
- //#endregion
237
- //#region src/plugin/extraction.ts
231
+ // src/plugin/extraction.ts
238
232
  function resolveExtraction(state, fileId, source) {
239
233
  const { processors } = getNormalized(state);
240
234
  if (!source.includes("yapyak") && !hasAmbientBindings(processors)) {
@@ -263,16 +257,14 @@ function resolveExtraction(state, fileId, source) {
263
257
  function hasAmbientBindings(processors) {
264
258
  return processors.some((processor) => processor.ambientBindings !== void 0 && processor.ambientBindings.length > 0);
265
259
  }
266
- //#endregion
267
- //#region src/plugin/locale-file.ts
260
+ // src/plugin/locale-file.ts
268
261
  function isLocaleFile(state, path) {
269
262
  const directory = join(state.projectRoot, getNormalized(state).localesDir);
270
263
  const relativePath = relative(directory, path);
271
264
  if (relativePath === "" || relativePath.startsWith("..") || relativePath.includes(sep)) return false;
272
265
  return extname(relativePath) === ".json";
273
266
  }
274
- //#endregion
275
- //#region src/plugin/yapyak-command.ts
267
+ // src/plugin/yapyak-command.ts
276
268
  function runYapyakCommand(args) {
277
269
  const userAgent = process.env.npm_config_user_agent ?? "";
278
270
  if (userAgent.startsWith("pnpm/")) return `pnpm yapyak ${args}`;
@@ -280,8 +272,7 @@ function runYapyakCommand(args) {
280
272
  if (userAgent.startsWith("bun/")) return `bunx yapyak ${args}`;
281
273
  return `npx yapyak ${args}`;
282
274
  }
283
- //#endregion
284
- //#region src/plugin/stub.ts
275
+ // src/plugin/stub.ts
285
276
  function fillStubs(state) {
286
277
  state.autoTranslateController?.abort();
287
278
  state.autoTranslateController = void 0;
@@ -397,8 +388,7 @@ function formatElapsed(ms) {
397
388
  if (ms < 1e3) return `${ms}ms`;
398
389
  return `${(ms / 1e3).toFixed(1)}s`;
399
390
  }
400
- //#endregion
401
- //#region src/plugin/sync.ts
391
+ // src/plugin/sync.ts
402
392
  function syncAll(state) {
403
393
  const allMessages = [];
404
394
  for (const list of state.messagesByFile.values()) allMessages.push(...list);
@@ -421,8 +411,7 @@ function emitSyncDiagnostics(state, result) {
421
411
  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.`);
422
412
  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.`);
423
413
  }
424
- //#endregion
425
- //#region src/plugin/dev-server.ts
414
+ // src/plugin/dev-server.ts
426
415
  function createDevServerPlugin(state) {
427
416
  return {
428
417
  buildEnd() {
@@ -694,8 +683,7 @@ function debounce(fn, milliseconds, logger) {
694
683
  };
695
684
  return debounced;
696
685
  }
697
- //#endregion
698
- //#region src/plugin/scan.ts
686
+ // src/plugin/scan.ts
699
687
  function createScanPlugin(state) {
700
688
  return {
701
689
  buildStart() {
@@ -716,8 +704,7 @@ function scanAllSources(state) {
716
704
  }
717
705
  syncAll(state);
718
706
  }
719
- //#endregion
720
- //#region src/plugin/transform.ts
707
+ // src/plugin/transform.ts
721
708
  function createTransformPlugin(state) {
722
709
  return {
723
710
  enforce: "pre",
@@ -813,8 +800,7 @@ function buildTranslations(input) {
813
800
  }
814
801
  return translations;
815
802
  }
816
- //#endregion
817
- //#region src/plugin/virtual-module.ts
803
+ // src/plugin/virtual-module.ts
818
804
  function createVirtualModulePlugin(state) {
819
805
  return {
820
806
  enforce: "pre",
@@ -823,6 +809,7 @@ function createVirtualModulePlugin(state) {
823
809
  const normalized = getNormalized(state);
824
810
  const emitted = getResolver(state).getEmittedLocales();
825
811
  return defineRuntime({
812
+ adoptDocumentLocale: normalized.adoptDocumentLocale,
826
813
  defaultLocale: emitted.defaultLocale,
827
814
  detectUserLocale: normalized.detectUserLocale,
828
815
  locales: emitted.locales,
@@ -839,8 +826,7 @@ function createVirtualModulePlugin(state) {
839
826
  }
840
827
  };
841
828
  }
842
- //#endregion
843
- //#region src/plugin.ts
829
+ // src/plugin.ts
844
830
  /**
845
831
  * Creates the yapyak Vite plugin.
846
832
  *
@@ -883,5 +869,4 @@ function yapyak(options = {}) {
883
869
  createDevServerPlugin(state)
884
870
  ];
885
871
  }
886
- //#endregion
887
872
  export { yapyak };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yapyak/vite",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "description": "Vite plugin for yapyak.",
5
5
  "keywords": [
6
6
  "i18n",
@@ -32,20 +32,20 @@
32
32
  "dist"
33
33
  ],
34
34
  "devDependencies": {
35
- "@types/node": "26.6.2",
36
- "tsdown": "0.23.0",
35
+ "@types/node": "26.6.5",
36
+ "tsdown": "0.23.2",
37
37
  "typescript": "6.0.3",
38
- "vite": "8.3.1",
39
- "vitest": "5.0.1",
38
+ "vite": "8.3.5",
39
+ "vitest": "5.0.5",
40
40
  "@yapyak/tsdown-config": "0.0.0",
41
41
  "@yapyak/typescript-config": "0.0.0"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "vite": ">=8",
45
- "yapyak": "0.0.17"
45
+ "yapyak": "0.0.19"
46
46
  },
47
47
  "engines": {
48
- "node": ">=22.22"
48
+ "node": ">=22.23.4"
49
49
  },
50
50
  "publishConfig": {
51
51
  "access": "public"