mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2025-01-24 19:06:49 +00:00
201e5fcd53
* Use fewer syntax highlighter languages. Reduces client.js size by about 250kB (800kB uncompressed) Common languages: bash, c, cpp, csharp, css, diff, go, graphql, ini, java, javascript, json, kotlin, less, lua, makefile, markdown, objectivec, perl, php-template, php, plaintext, python-repl, python, r, ruby, rust, scss, shell, sql, swift, typescript, vbnet, wasm, xml, yaml Additionally enabled languages: dockerfile, pgsql * Configurable syntax highlighter languages Allows to individually enable languages. * Lazy load syntax highlighter languages Allows to enable additional languages that will not be autodetected. * Include highlight.js in dynamic import check
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import { verifyTranslationImports } from "./services/I18NextService";
|
|
import { verifyDateFnsImports } from "@utils/app/setup-date-fns";
|
|
import { verifyHighlighjsImports } from "./lazy-highlightjs";
|
|
|
|
export class ImportReport {
|
|
error: Array<{ id: string; error: Error | string | undefined }> = [];
|
|
success: string[] = [];
|
|
message?: string;
|
|
}
|
|
|
|
export type ImportReportCollection = {
|
|
translation?: ImportReport;
|
|
"date-fns"?: ImportReport;
|
|
"highlight.js"?: ImportReport;
|
|
};
|
|
|
|
function collect(
|
|
verbose: boolean,
|
|
kind: keyof ImportReportCollection,
|
|
collection: ImportReportCollection,
|
|
report: ImportReport,
|
|
) {
|
|
collection[kind] = report;
|
|
if (verbose) {
|
|
for (const { id, error } of report.error) {
|
|
console.warn(`${kind} "${id}" failed: ${error}`);
|
|
}
|
|
const message = report.message ? ` (${report.message})` : "";
|
|
const good = report.success.length;
|
|
const bad = report.error.length;
|
|
if (bad) {
|
|
console.error(
|
|
`${bad} out of ${bad + good} ${kind} imports failed.` + message,
|
|
);
|
|
} else {
|
|
console.log(`${good} ${kind} imports verified.` + message);
|
|
}
|
|
}
|
|
}
|
|
|
|
// This verifies that the parameters used for parameterized imports are
|
|
// correct, that the respective chunks are reachable or bundled, and that the
|
|
// returned objects match expectations.
|
|
export async function verifyDynamicImports(
|
|
verbose: boolean,
|
|
): Promise<ImportReportCollection> {
|
|
const collection: ImportReportCollection = {};
|
|
await verifyTranslationImports().then(report =>
|
|
collect(verbose, "translation", collection, report),
|
|
);
|
|
await verifyDateFnsImports().then(report =>
|
|
collect(verbose, "date-fns", collection, report),
|
|
);
|
|
await verifyHighlighjsImports().then(report =>
|
|
collect(verbose, "highlight.js", collection, report),
|
|
);
|
|
return collection;
|
|
}
|