mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 19:59:55 +08:00
Ship folder-based workspaces and data migration, daily practice, redesigned provider and model settings, and streaming conversation improvements. Synchronize README translations and document the archive/permanent-delete upgrade behavior in assets/releases/ver1-6-9.md. Reduce initial JavaScript by deduplicating English resources and loading animation features after hydration. Keep the existing route size budgets. Update regression fixtures and browser audits for scoped URLs and the new settings and learning interfaces.
31 lines
1.4 KiB
TypeScript
31 lines
1.4 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import path from "node:path";
|
|
import test from "node:test";
|
|
import { runInNewContext } from "node:vm";
|
|
|
|
function compact(source: string): { output: string; resources: unknown } {
|
|
const loaderContext = { module: { exports: undefined as unknown } };
|
|
runInNewContext(
|
|
readFileSync(path.join(process.cwd(), "scripts/compact-locale-loader.cjs"), "utf8"),
|
|
loaderContext,
|
|
);
|
|
const loader = loaderContext.module.exports as (source: string) => string;
|
|
const output = loader.call({}, source);
|
|
const context = { module: { exports: undefined as unknown } };
|
|
runInNewContext(output, context);
|
|
return { output, resources: JSON.parse(JSON.stringify(context.module.exports)) };
|
|
}
|
|
|
|
test("compact English resources preserve every translation and remove duplicate copy", () => {
|
|
const source = readFileSync(path.join(process.cwd(), "locales/en/app.json"), "utf8");
|
|
const result = compact(source);
|
|
assert.deepEqual(result.resources, JSON.parse(source));
|
|
assert.ok(result.output.length < JSON.stringify(JSON.parse(source)).length * 0.65);
|
|
});
|
|
|
|
test("compact resources preserve interpolation, escapes, empty values and special keys", () => {
|
|
const source = '{"Hello {{name}}":"Hello {{name}}","key":"Translated", "quote\\\"":"quote\\\"", "empty":"", "__proto__":"safe", "constructor":"constructor"}';
|
|
assert.deepEqual(compact(source).resources, JSON.parse(source));
|
|
});
|