-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplaceNlsMessages.ts
More file actions
25 lines (19 loc) · 1011 Bytes
/
replaceNlsMessages.ts
File metadata and controls
25 lines (19 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import type { PitchLoaderDefinitionFunction } from "webpack";
import { MonacoEditorI18nPlugin } from "..";
const fs = require("fs");
const nlsMessages = require.resolve("../nls.messages");
// replace monaco-editor/esm/vs/nls.messages.js
const replaceNlsMessages: PitchLoaderDefinitionFunction<MonacoEditorI18nPlugin.IMonacoEditorI18nPluginOpts> = function (
content: string
) {
const pathRegExp = /monaco-editor[\\\/]esm[\\\/]vs[\\\/]nls\.message\.js$/;
if (!pathRegExp.test(this.resourcePath)) return content;
let _content = fs.readFileSync(nlsMessages, { encoding: "utf8" });
if (_content.includes("windowKey") && _content.includes("localStorageKey")) {
const { windowKey, localStorageKey } = this.getOptions() || {};
_content = _content.replace(/const windowKey = \("[^"]*"\);/g, `${windowKey};`);
_content = _content.replace(/const localStorageKey = \("[^"]*"\);/g, `${localStorageKey};`);
}
return _content;
};
module.exports = replaceNlsMessages;