Skip to content

Commit dc99ebe

Browse files
authored
feat(packages/sdk): improve deprecation warning for legacy class names (#578)
1 parent 1e81a00 commit dc99ebe

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

.changeset/polite-trees-compete.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

packages/sdk/src/index.ts

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ export class LingoDotDevEngine {
4949
progressCallback?: (
5050
progress: number,
5151
sourceChunk: Record<string, string>,
52-
processedChunk: Record<string, string>
53-
) => void
52+
processedChunk: Record<string, string>,
53+
) => void,
5454
): Promise<Record<string, string>> {
5555
const finalPayload = payloadSchema.parse(payload);
5656
const finalParams = localizationParamsSchema.parse(params);
@@ -68,7 +68,7 @@ export class LingoDotDevEngine {
6868
finalParams.targetLocale,
6969
{ data: chunk, reference: params.reference },
7070
workflowId,
71-
params.fast || false
71+
params.fast || false,
7272
);
7373

7474
if (progressCallback) {
@@ -96,7 +96,7 @@ export class LingoDotDevEngine {
9696
reference?: Z.infer<typeof referenceSchema>;
9797
},
9898
workflowId: string,
99-
fast: boolean
99+
fast: boolean,
100100
): Promise<Record<string, string>> {
101101
const res = await fetch(`${this.config.apiUrl}/i18n`, {
102102
method: "POST",
@@ -115,7 +115,7 @@ export class LingoDotDevEngine {
115115
reference: payload.reference,
116116
},
117117
null,
118-
2
118+
2,
119119
),
120120
});
121121

@@ -202,8 +202,8 @@ export class LingoDotDevEngine {
202202
progressCallback?: (
203203
progress: number,
204204
sourceChunk: Record<string, string>,
205-
processedChunk: Record<string, string>
206-
) => void
205+
processedChunk: Record<string, string>,
206+
) => void,
207207
): Promise<Record<string, any>> {
208208
return this._localizeRaw(obj, params, progressCallback);
209209
}
@@ -221,7 +221,7 @@ export class LingoDotDevEngine {
221221
async localizeText(
222222
text: string,
223223
params: Z.infer<typeof localizationParamsSchema>,
224-
progressCallback?: (progress: number) => void
224+
progressCallback?: (progress: number) => void,
225225
): Promise<string> {
226226
const response = await this._localizeRaw({ text }, params, progressCallback);
227227
return response.text || "";
@@ -242,16 +242,16 @@ export class LingoDotDevEngine {
242242
sourceLocale: LocaleCode;
243243
targetLocales: LocaleCode[];
244244
fast?: boolean;
245-
}
245+
},
246246
) {
247247
const responses = await Promise.all(
248248
params.targetLocales.map((targetLocale) =>
249249
this.localizeText(text, {
250250
sourceLocale: params.sourceLocale,
251251
targetLocale,
252252
fast: params.fast,
253-
})
254-
)
253+
}),
254+
),
255255
);
256256

257257
return responses;
@@ -270,7 +270,7 @@ export class LingoDotDevEngine {
270270
async localizeChat(
271271
chat: Array<{ name: string; text: string }>,
272272
params: Z.infer<typeof localizationParamsSchema>,
273-
progressCallback?: (progress: number) => void
273+
progressCallback?: (progress: number) => void,
274274
): Promise<Array<{ name: string; text: string }>> {
275275
const localized = await this._localizeRaw({ chat }, params, progressCallback);
276276

@@ -294,7 +294,7 @@ export class LingoDotDevEngine {
294294
async localizeHtml(
295295
html: string,
296296
params: Z.infer<typeof localizationParamsSchema>,
297-
progressCallback?: (progress: number) => void
297+
progressCallback?: (progress: number) => void,
298298
): Promise<string> {
299299
const jsdomPackage = await import("jsdom");
300300
const { JSDOM } = jsdomPackage;
@@ -326,7 +326,7 @@ export class LingoDotDevEngine {
326326
}
327327

328328
const siblings = Array.from(parent.childNodes).filter(
329-
(n) => n.nodeType === 1 || (n.nodeType === 3 && n.textContent?.trim())
329+
(n) => n.nodeType === 1 || (n.nodeType === 3 && n.textContent?.trim()),
330330
);
331331
const index = siblings.indexOf(current);
332332
if (index !== -1) {
@@ -392,7 +392,7 @@ export class LingoDotDevEngine {
392392

393393
for (const index of indices) {
394394
const siblings = Array.from(parent.childNodes).filter(
395-
(n) => n.nodeType === 1 || (n.nodeType === 3 && n.textContent?.trim())
395+
(n) => n.nodeType === 1 || (n.nodeType === 3 && n.textContent?.trim()),
396396
);
397397
current = siblings[parseInt(index)] || null;
398398
if (current?.nodeType === 1) {
@@ -440,18 +440,36 @@ export class LingoDotDevEngine {
440440
* @deprecated Use LingoDotDevEngine instead. This class is maintained for backwards compatibility.
441441
*/
442442
export class ReplexicaEngine extends LingoDotDevEngine {
443+
private static hasWarnedDeprecation = false;
444+
443445
constructor(config: Partial<Z.infer<typeof engineParamsSchema>>) {
444446
super(config);
445-
console.warn("ReplexicaEngine is deprecated. Please use LingoDotDevEngine instead.");
447+
if (!ReplexicaEngine.hasWarnedDeprecation) {
448+
console.warn(
449+
"ReplexicaEngine is deprecated and will be removed in a future release. " +
450+
"Please use LingoDotDevEngine instead. " +
451+
"See https://docs.lingo.dev/migration for more information.",
452+
);
453+
ReplexicaEngine.hasWarnedDeprecation = true;
454+
}
446455
}
447456
}
448457

449458
/**
450459
* @deprecated Use LingoDotDevEngine instead. This class is maintained for backwards compatibility.
451460
*/
452461
export class LingoEngine extends LingoDotDevEngine {
462+
private static hasWarnedDeprecation = false;
463+
453464
constructor(config: Partial<Z.infer<typeof engineParamsSchema>>) {
454465
super(config);
455-
console.warn("LingoEngine is deprecated. Please use LingoDotDevEngine instead.");
466+
if (!LingoEngine.hasWarnedDeprecation) {
467+
console.warn(
468+
"LingoEngine is deprecated and will be removed in a future release. " +
469+
"Please use LingoDotDevEngine instead. " +
470+
"See https://docs.lingo.dev/migration for more information.",
471+
);
472+
LingoEngine.hasWarnedDeprecation = true;
473+
}
456474
}
457475
}

0 commit comments

Comments
 (0)