wuchale 0.18.2 → 0.18.3

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/handler.js CHANGED
@@ -1,4 +1,4 @@
1
- import { basename, dirname, isAbsolute, resolve, normalize, relative, join } from 'node:path';
1
+ import { dirname, isAbsolute, resolve, normalize, relative, join } from 'node:path';
2
2
  import { platform } from 'node:process';
3
3
  import { glob } from "tinyglobby";
4
4
  import { IndexTracker, Message } from "./adapters.js";
@@ -184,14 +184,24 @@ export class AdapterHandler {
184
184
  const ownerKey = this.sharedState.ownerKey;
185
185
  return join(this.#generatedDir, `${ownerKey}.${id ?? ownerKey}.${loc}.compiled.js`);
186
186
  }
187
- #getCompiledImport(loc, id) {
188
- return './' + basename(this.getCompiledFilePath(loc, id));
187
+ #getImportPath(filename, importer) {
188
+ filename = relative(dirname(importer ?? filename), filename);
189
+ if (platform === 'win32') {
190
+ filename = filename.replaceAll('\\', '/');
191
+ }
192
+ if (!filename.startsWith('.')) {
193
+ filename = `./${filename}`;
194
+ }
195
+ return filename;
189
196
  }
190
197
  getLoadIDs(forImport = false) {
191
198
  const loadIDs = [];
192
199
  if (this.#adapter.granularLoad) {
193
- for (const loadID in this.granularStateByID) {
194
- loadIDs.push(loadID);
200
+ for (const state of Object.values(this.granularStateByID)) {
201
+ // only the ones with ready messages
202
+ if (state.compiled[this.#config.sourceLocale].items.length) {
203
+ loadIDs.push(state.id);
204
+ }
195
205
  }
196
206
  }
197
207
  else if (forImport) {
@@ -209,13 +219,14 @@ export class AdapterHandler {
209
219
  for (const [i, id] of loadIDs.entries()) {
210
220
  const importsByLocale = [];
211
221
  for (const loc of this.#locales) {
212
- importsByLocale.push(`${objKeyLocale(loc)}: () => import('${this.#getCompiledImport(loc, loadIDsImport[i])}')`);
222
+ importsByLocale.push(`${objKeyLocale(loc)}: () => import('${this.#getImportPath(this.getCompiledFilePath(loc, loadIDsImport[i]))}')`);
213
223
  }
214
224
  imports.push(`${id}: {${importsByLocale.join(',')}}`);
215
225
  }
216
226
  return `
227
+ /** @type {{[loadID: string]: {[locale: string]: () => Promise<import('wuchale/runtime').CatalogModule>}}} */
217
228
  const catalogs = {${imports.join(',')}}
218
- export const loadCatalog = (loadID, locale) => catalogs[loadID][locale]()
229
+ export const loadCatalog = (/** @type {string} */ loadID, /** @type {string} */ locale) => catalogs[loadID][locale]()
219
230
  export const loadIDs = ['${loadIDs.join("', '")}']
220
231
  `;
221
232
  }
@@ -228,15 +239,16 @@ export class AdapterHandler {
228
239
  const importedByLocale = [];
229
240
  for (const [i, loc] of this.#locales.entries()) {
230
241
  const locKey = `_w_c_${id}_${i}_`;
231
- imports.push(`import * as ${locKey} from '${this.#getCompiledImport(loc, loadIDsImport[il])}'`);
242
+ imports.push(`import * as ${locKey} from '${this.#getImportPath(this.getCompiledFilePath(loc, loadIDsImport[il]))}'`);
232
243
  importedByLocale.push(`${objKeyLocale(loc)}: ${locKey}`);
233
244
  }
234
245
  object.push(`${id}: {${importedByLocale.join(',')}}`);
235
246
  }
236
247
  return `
237
248
  ${imports.join('\n')}
249
+ /** @type {{[loadID: string]: {[locale: string]: import('wuchale/runtime').CatalogModule}}} */
238
250
  const catalogs = {${object.join(',')}}
239
- export const loadCatalog = (loadID, locale) => catalogs[loadID][locale]
251
+ export const loadCatalog = (/** @type {string} */ loadID, /** @type {string} */ locale) => catalogs[loadID][locale]
240
252
  export const loadIDs = ['${loadIDs.join("', '")}']
241
253
  `;
242
254
  }
@@ -472,6 +484,7 @@ export class AdapterHandler {
472
484
  ${module}
473
485
  // only during dev, for HMR
474
486
  let latestVersion = ${hmrVersion}
487
+ // @ts-ignore
475
488
  export function update({ version, data }) {
476
489
  if (latestVersion >= version) {
477
490
  return
@@ -685,17 +698,6 @@ export class AdapterHandler {
685
698
  `;
686
699
  };
687
700
  #prepareHeader = (filename, loadID, hmrData, forServer) => {
688
- let loaderRelTo = filename;
689
- if (this.#adapter.outDir) {
690
- loaderRelTo = resolve(this.#adapter.outDir + '/' + filename);
691
- }
692
- let loaderPath = relative(dirname(loaderRelTo), forServer ? this.loaderPath.server : this.loaderPath.client);
693
- if (platform === 'win32') {
694
- loaderPath = loaderPath.replaceAll('\\', '/');
695
- }
696
- if (!loaderPath.startsWith('.')) {
697
- loaderPath = `./${loaderPath}`;
698
- }
699
701
  let head = [];
700
702
  let getFuncImportPlain = getFuncPlain;
701
703
  let getFuncImportReactive = getFuncReactive;
@@ -705,6 +707,11 @@ export class AdapterHandler {
705
707
  getFuncImportReactive += 'hmr_';
706
708
  head.push(this.#hmrUpdateFunc(getFuncPlain, getFuncImportPlain), this.#hmrUpdateFunc(getFuncReactive, getFuncImportReactive));
707
709
  }
710
+ let loaderRelTo = filename;
711
+ if (this.#adapter.outDir) {
712
+ loaderRelTo = resolve(this.#adapter.outDir + '/' + filename);
713
+ }
714
+ const loaderPath = this.#getImportPath(forServer ? this.loaderPath.server : this.loaderPath.client, loaderRelTo);
708
715
  const importsFuncs = [
709
716
  `${loaderImportGetRuntime} as ${getFuncImportPlain}`,
710
717
  `${loaderImportGetRuntimeRx} as ${getFuncImportReactive}`,
@@ -720,7 +727,7 @@ export class AdapterHandler {
720
727
  const objElms = [];
721
728
  for (const [i, loc] of this.#locales.entries()) {
722
729
  const locKW = `_w_c_${i}_`;
723
- const importFrom = relative(dirname(loaderRelTo), this.#getCompiledImport(loc, loadID));
730
+ const importFrom = this.#getImportPath(this.getCompiledFilePath(loc, loadID), loaderRelTo);
724
731
  imports.push(`import * as ${locKW} from '${importFrom}'`);
725
732
  objElms.push(`${objKeyLocale(loc)}: ${locKW}`);
726
733
  }
package/dist/runtime.d.ts CHANGED
@@ -3,7 +3,7 @@ export declare const catalogVarName: "c";
3
3
  export type CatalogModule = {
4
4
  [catalogVarName]: CompiledElement[];
5
5
  p?: (n: number) => number;
6
- update?: (callback: (newData: CompiledElement[]) => void) => void;
6
+ update?: Function;
7
7
  };
8
8
  declare let onInvalidFunc: (i: number, c: CompiledElement[]) => string;
9
9
  export declare function onInvalid(newOnInvalid: typeof onInvalidFunc): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wuchale",
3
- "version": "0.18.2",
3
+ "version": "0.18.3",
4
4
  "description": "Protobuf-like i18n from plain code",
5
5
  "scripts": {
6
6
  "dev": "tsc --watch",