@yapyak/vite 0.0.11 → 0.0.12

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
@@ -11,6 +11,13 @@ type YapyakOptions = {
11
11
  * Must be one of the configured locales. Throws at config resolution if not.
12
12
  */
13
13
  fixedLocale?: string;
14
+ /**
15
+ * The directory `yapyak.config.ts`, the locales directory, and file ids resolve from.
16
+ *
17
+ * @remarks
18
+ * Defaults to Vite's `root`. Set it when the bundler roots Vite somewhere else than the project — a meta-framework pointing Vite at its source directory.
19
+ */
20
+ root?: string;
14
21
  };
15
22
  /**
16
23
  * Creates the yapyak Vite plugin.
package/dist/index.js CHANGED
@@ -75,7 +75,7 @@ function createConfigPlugin(state) {
75
75
  const loads = /* @__PURE__ */ new Map();
76
76
  return {
77
77
  async config(userConfig) {
78
- const result = await loadOnce(loads, resolve(userConfig.root ?? process.cwd()));
78
+ const result = await loadOnce(loads, state.rootOverride ?? resolve(userConfig.root ?? process.cwd()));
79
79
  return {
80
80
  optimizeDeps: { exclude: [
81
81
  RUNTIME_ID,
@@ -86,7 +86,7 @@ function createConfigPlugin(state) {
86
86
  };
87
87
  },
88
88
  async configResolved(config) {
89
- state.projectRoot = config.root;
89
+ state.projectRoot = state.rootOverride ?? config.root;
90
90
  state.yapyakDir = join(state.projectRoot, ".yapyak");
91
91
  state.command = config.command;
92
92
  state.logger = config.logger;
@@ -172,7 +172,8 @@ function createState(options = {}) {
172
172
  ...options.fixedLocale !== void 0 && { fixedLocale: options.fixedLocale },
173
173
  logger: createConsoleLogger(),
174
174
  messagesByFile: /* @__PURE__ */ new Map(),
175
- projectRoot: process.cwd(),
175
+ projectRoot: options.root === void 0 ? process.cwd() : resolve(options.root),
176
+ ...options.root !== void 0 && { rootOverride: resolve(options.root) },
176
177
  teardownCallbacks: [],
177
178
  yapyakDir: ""
178
179
  };
@@ -208,7 +209,8 @@ function createConsoleLogger() {
208
209
  //#endregion
209
210
  //#region src/plugin/extraction.ts
210
211
  function resolveExtraction(state, fileId, source) {
211
- if (!source.includes("yapyak")) return {
212
+ const { processors } = getNormalized(state);
213
+ if (!source.includes("yapyak") && !hasAmbientBindings(processors)) return {
212
214
  callSites: [],
213
215
  diagnostics: [],
214
216
  messages: []
@@ -228,6 +230,9 @@ function resolveExtraction(state, fileId, source) {
228
230
  });
229
231
  return result;
230
232
  }
233
+ function hasAmbientBindings(processors) {
234
+ return processors.some((processor) => processor.ambientBindings !== void 0 && processor.ambientBindings.length > 0);
235
+ }
231
236
  //#endregion
232
237
  //#region src/plugin/locale-file.ts
233
238
  function isLocaleFile(state, path) {
@@ -392,6 +397,7 @@ function createDevServerPlugin(state) {
392
397
  },
393
398
  configureServer(server) {
394
399
  if (state.configFile !== void 0) server.watcher.add(state.configFile);
400
+ server.watcher.add(join(state.projectRoot, getNormalized(state).localesDir));
395
401
  const pendingActionByFileId = /* @__PURE__ */ new Map();
396
402
  const flush = debounce(() => {
397
403
  if (pendingActionByFileId.size === 0) return;
@@ -827,7 +833,10 @@ function createVirtualModulePlugin(state) {
827
833
  * ```
828
834
  */
829
835
  function yapyak(options = {}) {
830
- const state = createState({ fixedLocale: options.fixedLocale });
836
+ const state = createState({
837
+ fixedLocale: options.fixedLocale,
838
+ ...options.root !== void 0 && { root: options.root }
839
+ });
831
840
  return [
832
841
  createConfigPlugin(state),
833
842
  createVirtualModulePlugin(state),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yapyak/vite",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "Vite plugin for yapyak.",
5
5
  "keywords": [
6
6
  "i18n",
@@ -26,6 +26,7 @@
26
26
  "default": "./dist/index.js"
27
27
  }
28
28
  },
29
+ "types": "./dist/index.d.ts",
29
30
  "files": [
30
31
  "dist"
31
32
  ],
@@ -35,12 +36,12 @@
35
36
  "typescript": "6.0.3",
36
37
  "vite": "8.2.0",
37
38
  "vitest": "4.1.10",
38
- "@yapyak/tsdown-config": "0.0.0",
39
- "@yapyak/typescript-config": "0.0.0"
39
+ "@yapyak/typescript-config": "0.0.0",
40
+ "@yapyak/tsdown-config": "0.0.0"
40
41
  },
41
42
  "peerDependencies": {
42
43
  "vite": ">=8",
43
- "yapyak": "0.0.11"
44
+ "yapyak": "0.0.12"
44
45
  },
45
46
  "engines": {
46
47
  "node": ">=22.22"