Merge pull request #1302 from TriliumNext/build_webpack-i18n-dayjs-splitjs

build: let webpack handle `dayjs`, `split.js` and `i18next`
This commit is contained in:
Elian Doran
2025-02-28 17:44:33 +02:00
committed by GitHub
12 changed files with 21 additions and 38 deletions

12
package-lock.json generated
View File

@@ -57,7 +57,6 @@
"https-proxy-agent": "7.0.6",
"i18next": "24.2.2",
"i18next-fs-backend": "2.6.0",
"i18next-http-backend": "3.0.2",
"image-type": "5.2.0",
"ini": "5.0.0",
"is-animated": "2.0.2",
@@ -92,7 +91,6 @@
"serve-favicon": "2.5.0",
"session-file-store": "1.5.0",
"source-map-support": "0.5.21",
"split.js": "1.6.5",
"stream-throttle": "0.1.3",
"strip-bom": "5.0.0",
"striptags": "3.2.0",
@@ -168,6 +166,7 @@
"css-loader": "7.1.2",
"electron": "34.3.0",
"esm": "3.2.25",
"i18next-http-backend": "3.0.2",
"jsdoc": "4.0.4",
"lorem-ipsum": "2.0.8",
"mini-css-extract-plugin": "2.9.2",
@@ -178,6 +177,7 @@
"rimraf": "6.0.1",
"sass": "1.85.1",
"sass-loader": "16.0.5",
"split.js": "1.6.5",
"supertest": "7.0.0",
"swagger-jsdoc": "6.2.8",
"tslib": "2.8.1",
@@ -7364,6 +7364,7 @@
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-4.0.0.tgz",
"integrity": "sha512-e4a5N8lVvuLgAWgnCrLr2PP0YyDOTHa9H/Rj54dirp61qXnNq46m82bRhNqIA5VccJtWBvPTFRV3TtvHUKPB1g==",
"dev": true,
"license": "MIT",
"dependencies": {
"node-fetch": "^2.6.12"
@@ -9357,6 +9358,7 @@
"version": "0.1.13",
"resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.13.tgz",
"integrity": "sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==",
"dev": true,
"license": "MIT",
"optional": true,
"dependencies": {
@@ -11410,6 +11412,7 @@
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/i18next-http-backend/-/i18next-http-backend-3.0.2.tgz",
"integrity": "sha512-PdlvPnvIp4E1sYi46Ik4tBYh/v/NbYfFFgTjkwFl0is8A18s7/bx9aXqsrOax9WUbeNS6mD2oix7Z0yGGf6m5g==",
"dev": true,
"license": "MIT",
"dependencies": {
"cross-fetch": "4.0.0"
@@ -13516,6 +13519,7 @@
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",
"integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==",
"dev": true,
"license": "MIT",
"dependencies": {
"whatwg-url": "^5.0.0"
@@ -13536,18 +13540,21 @@
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
"integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==",
"dev": true,
"license": "MIT"
},
"node_modules/node-fetch/node_modules/webidl-conversions": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",
"dev": true,
"license": "BSD-2-Clause"
},
"node_modules/node-fetch/node_modules/whatwg-url": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
"integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
"dev": true,
"license": "MIT",
"dependencies": {
"tr46": "~0.0.3",
@@ -16662,6 +16669,7 @@
"version": "1.6.5",
"resolved": "https://registry.npmjs.org/split.js/-/split.js-1.6.5.tgz",
"integrity": "sha512-mPTnGCiS/RiuTNsVhCm9De9cCAUsrNFFviRbADdKiiV+Kk8HKp/0fWu7Kr8pi3/yBmsqLFHuXGT9UUZ+CNLwFw==",
"dev": true,
"license": "MIT"
},
"node_modules/sprintf-js": {

View File

@@ -110,7 +110,6 @@
"https-proxy-agent": "7.0.6",
"i18next": "24.2.2",
"i18next-fs-backend": "2.6.0",
"i18next-http-backend": "3.0.2",
"image-type": "5.2.0",
"ini": "5.0.0",
"is-animated": "2.0.2",
@@ -145,7 +144,6 @@
"serve-favicon": "2.5.0",
"session-file-store": "1.5.0",
"source-map-support": "0.5.21",
"split.js": "1.6.5",
"stream-throttle": "0.1.3",
"strip-bom": "5.0.0",
"striptags": "3.2.0",
@@ -218,6 +216,7 @@
"css-loader": "7.1.2",
"electron": "34.3.0",
"esm": "3.2.25",
"i18next-http-backend": "3.0.2",
"jsdoc": "4.0.4",
"lorem-ipsum": "2.0.8",
"mini-css-extract-plugin": "2.9.2",
@@ -228,6 +227,7 @@
"rimraf": "6.0.1",
"sass": "1.85.1",
"sass-loader": "16.0.5",
"split.js": "1.6.5",
"supertest": "7.0.0",
"swagger-jsdoc": "6.2.8",
"tslib": "2.8.1",

View File

@@ -17,6 +17,7 @@ import shortcutService from "./shortcuts.js";
import dialogService from "./dialog.js";
import type FNote from "../entities/fnote.js";
import { t } from "./i18n.js";
import dayjs from "dayjs";
import type NoteContext from "../components/note_context.js";
import type NoteDetailWidget from "../widgets/note_detail.js";
import type Component from "../components/component.js";
@@ -84,7 +85,7 @@ interface Api {
* See {@link https://day.js.org} for documentation
* @see https://day.js.org
*/
dayjs: typeof window.dayjs;
dayjs: typeof dayjs;
RightPanelWidget: typeof RightPanelWidget;
NoteContextAwareWidget: typeof NoteContextAwareWidget;

View File

@@ -1,7 +1,6 @@
import library_loader from "./library_loader.js";
import options from "./options.js";
await library_loader.requireLibrary(library_loader.I18NEXT);
import i18next from "i18next";
import i18nextHttpBackend from "i18next-http-backend";
export async function initLocale() {
const locale = (options.get("locale") as string) || "en";
@@ -17,3 +16,4 @@ export async function initLocale() {
}
export const t = i18next.t;
export const getCurrentLanguage = () => i18next.language;

View File

@@ -72,10 +72,6 @@ const MARKJS: Library = {
js: ["node_modules/mark.js/dist/jquery.mark.es6.min.js"]
};
const I18NEXT: Library = {
js: ["node_modules/i18next/i18next.min.js", "node_modules/i18next-http-backend/i18nextHttpBackend.min.js"]
};
const HIGHLIGHT_JS: Library = {
js: () => {
const mimeTypes = mimeTypesService.getMimeTypes();
@@ -194,7 +190,6 @@ export default {
WHEEL_ZOOM,
MERMAID,
MARKJS,
I18NEXT,
HIGHLIGHT_JS,
LEAFLET
};

View File

@@ -1,4 +1,5 @@
import options from "./options.js";
import Split from "split.js"
let leftInstance: ReturnType<typeof Split> | null;
let rightInstance: ReturnType<typeof Split> | null;

View File

@@ -1,7 +1,5 @@
import type FNote from "./entities/fnote";
import type { BackendModule, i18n } from "i18next";
import type { Froca } from "./services/froca-interface";
import type { HttpBackendOptions } from "i18next-http-backend";
import { Suggestion } from "./services/note_autocomplete.ts";
import utils from "./services/utils.ts";
import appContext from "./components/app_context.ts";
@@ -115,22 +113,12 @@ declare global {
// Libraries
// TODO: Replace once library loader is replaced with webpack.
var i18next: i18n;
var i18nextHttpBackend: BackendModule<HttpBackendOptions>;
var hljs: {
highlightAuto(text: string);
highlight(text: string, {
language: string
});
};
var dayjs: {};
var Split: (selectors: string[], config: {
sizes: [ number, number ];
gutterSize: number;
onDragEnd: (sizes: [ number, number ]) => void;
}) => {
destroy();
};
var renderMathInElement: (element: HTMLElement, options: {
trust: boolean;
}) => void;

View File

@@ -2,6 +2,7 @@ import type { EventData } from "../../components/app_context.js";
import type FNote from "../../entities/fnote.js";
import { applySyntaxHighlight } from "../../services/syntax_highlight.js";
import TypeWidget from "./type_widget.js";
import { getCurrentLanguage } from "../../services/i18n.js";
const TPL = `<div class="note-detail-doc note-detail-printable">
<style>
@@ -77,7 +78,7 @@ export default class DocTypeWidget extends TypeWidget {
if (docName) {
// find doc based on language
const url = this.#getUrl(docName, i18next.language);
const url = this.#getUrl(docName, getCurrentLanguage());
this.$content.load(url, (response, status) => {
// fallback to english doc if no translation available
if (status === "error") {

View File

@@ -2,6 +2,7 @@ import { t } from "../services/i18n.js";
import NoteContextAwareWidget from "./note_context_aware_widget.js";
import server from "../services/server.js";
import fileWatcher from "../services/file_watcher.js";
import dayjs from "dayjs";
const TPL = `
<div class="dropdown watched-file-update-status-widget alert alert-warning">

View File

@@ -61,8 +61,6 @@ async function register(app: express.Application) {
app.use(`/node_modules/katex/dist/`, express.static(path.join(srcRoot, "..", "node_modules/katex/dist/")));
app.use(`/${assetPath}/node_modules/katex/dist/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/katex/dist/")));
app.use(`/${assetPath}/node_modules/dayjs/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/dayjs/")));
app.use(`/${assetPath}/node_modules/boxicons/css/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/boxicons/css/")));
app.use(`/${assetPath}/node_modules/boxicons/fonts/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/boxicons/fonts/")));
@@ -72,13 +70,9 @@ async function register(app: express.Application) {
app.use(`/${assetPath}/node_modules/jquery-hotkeys/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/jquery-hotkeys/")));
app.use(`/${assetPath}/node_modules/split.js/dist/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/split.js/dist/")));
app.use(`/${assetPath}/node_modules/panzoom/dist/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/panzoom/dist/")));
// i18n
app.use(`/${assetPath}/node_modules/i18next/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/i18next/")));
app.use(`/${assetPath}/node_modules/i18next-http-backend/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/i18next-http-backend/")));
app.use(`/${assetPath}/translations/`, persistentCacheStatic(path.join(srcRoot, "public", "translations/")));
app.use(`/${assetPath}/node_modules/eslint/bin/`, persistentCacheStatic(path.join(srcRoot, "..", "node_modules/eslint/bin/")));

View File

@@ -45,10 +45,6 @@
<script src="<%= assetPath %>/node_modules/autocomplete.js/dist/autocomplete.jquery.min.js"></script>
<script src="<%= assetPath %>/node_modules/dayjs/dayjs.min.js"></script>
<script src="<%= assetPath %>/node_modules/split.js/dist/split.min.js"></script>
<link href="<%= assetPath %>/stylesheets/ckeditor-theme.css" rel="stylesheet">
<link href="api/fonts" rel="stylesheet">
<link href="<%= assetPath %>/stylesheets/theme-light.css" rel="stylesheet">

View File

@@ -115,8 +115,6 @@
<script src="<%= assetPath %>/node_modules/autocomplete.js/dist/autocomplete.jquery.min.js"></script>
<script src="<%= assetPath %>/node_modules/dayjs/dayjs.min.js"></script>
<link href="<%= assetPath %>/stylesheets/tree.css" rel="stylesheet">
<script src="<%= assetPath %>/node_modules/jquery.fancytree/dist/jquery.fancytree-all-deps.min.js"></script>