@salesforcedevs/dx-components 1.31.9-alpha5 → 1.31.9-alpha7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/logs.txt +49007 -0
- package/package.json +1 -1
- package/src/modules/dxUtils/shiki/__mocks__/shiki.ts +5 -0
- package/src/modules/dxUtils/shiki/shiki.ts +11 -5
- package/src/modules/dxUtils/shikiCore/shikiCore.ts +53 -9
- package/src/modules/dxUtils/shikiGrammars/shikiGrammars.ts +6 -6
- package/src/modules/dxUtils/shikiStatic/shikiStatic.ts +2 -2
package/package.json
CHANGED
|
@@ -107,5 +107,10 @@ export const createOnigurumaEngine = jest.fn().mockImplementation(() => {
|
|
|
107
107
|
return Promise.resolve({});
|
|
108
108
|
});
|
|
109
109
|
|
|
110
|
+
// Mock for shiki/engine/javascript
|
|
111
|
+
export const createJavaScriptRegexEngine = jest.fn().mockImplementation(() => {
|
|
112
|
+
return {};
|
|
113
|
+
});
|
|
114
|
+
|
|
110
115
|
// Mock for shiki/wasm - just return a promise that resolves to a buffer
|
|
111
116
|
export default Promise.resolve(new ArrayBuffer(0));
|
|
@@ -10,16 +10,22 @@ import {
|
|
|
10
10
|
/**
|
|
11
11
|
* Dynamic loading version of Shiki.
|
|
12
12
|
* Uses dynamic import() for code splitting - shiki is lazy loaded on first use.
|
|
13
|
-
*
|
|
13
|
+
* Uses createJavaScriptRegexEngine (no WASM) so it works in LWR at runtime.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
let shikiModulePromise: Promise<
|
|
16
|
+
let shikiModulePromise: Promise<{
|
|
17
|
+
createHighlighterCore: any;
|
|
18
|
+
createJavaScriptRegexEngine: any;
|
|
19
|
+
}> | null = null;
|
|
17
20
|
let bracketsModulePromise: Promise<
|
|
18
21
|
typeof import("@shikijs/colorized-brackets")
|
|
19
22
|
> | null = null;
|
|
20
23
|
|
|
21
24
|
async function getShiki() {
|
|
22
|
-
return (shikiModulePromise ??= import("shiki"))
|
|
25
|
+
return (shikiModulePromise ??= import("shiki").then((m) => ({
|
|
26
|
+
createHighlighterCore: m.createHighlighterCore,
|
|
27
|
+
createJavaScriptRegexEngine: m.createJavaScriptRegexEngine
|
|
28
|
+
})));
|
|
23
29
|
}
|
|
24
30
|
|
|
25
31
|
async function getBrackets() {
|
|
@@ -29,8 +35,8 @@ async function getBrackets() {
|
|
|
29
35
|
const shikiState: ShikiState = createShikiState();
|
|
30
36
|
|
|
31
37
|
async function initializeShiki(): Promise<HighlighterCore> {
|
|
32
|
-
const
|
|
33
|
-
return initializeHighlighter(shikiState,
|
|
38
|
+
const { createHighlighterCore, createJavaScriptRegexEngine } = await getShiki();
|
|
39
|
+
return initializeHighlighter(shikiState, { createHighlighterCore }, createJavaScriptRegexEngine());
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
export async function highlightCode(
|
|
@@ -2,9 +2,10 @@ import type { BundledLanguage, BundledTheme, HighlighterCore } from "shiki";
|
|
|
2
2
|
import { getCustomLanguageGrammars } from "dxUtils/shikiGrammars";
|
|
3
3
|
|
|
4
4
|
export interface ShikiModule {
|
|
5
|
-
|
|
6
|
-
themes:
|
|
7
|
-
langs:
|
|
5
|
+
createHighlighterCore: (options: {
|
|
6
|
+
themes: any[];
|
|
7
|
+
langs: any[];
|
|
8
|
+
engine: any;
|
|
8
9
|
}) => Promise<HighlighterCore>;
|
|
9
10
|
}
|
|
10
11
|
|
|
@@ -94,6 +95,41 @@ const languageLoadPromises = new WeakMap<
|
|
|
94
95
|
Map<string, Promise<void>>
|
|
95
96
|
>();
|
|
96
97
|
|
|
98
|
+
const themeLoadPromises = new WeakMap<
|
|
99
|
+
HighlighterCore,
|
|
100
|
+
Map<string, Promise<void>>
|
|
101
|
+
>();
|
|
102
|
+
|
|
103
|
+
async function loadThemeIfNeeded(
|
|
104
|
+
highlighter: HighlighterCore,
|
|
105
|
+
themeName: BundledTheme
|
|
106
|
+
): Promise<void> {
|
|
107
|
+
if ((highlighter.getLoadedThemes() as string[]).includes(themeName)) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (!themeLoadPromises.has(highlighter)) {
|
|
112
|
+
themeLoadPromises.set(highlighter, new Map());
|
|
113
|
+
}
|
|
114
|
+
const promiseMap = themeLoadPromises.get(highlighter)!;
|
|
115
|
+
|
|
116
|
+
if (promiseMap.has(themeName)) {
|
|
117
|
+
return promiseMap.get(themeName);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const loadPromise = (async () => {
|
|
121
|
+
try {
|
|
122
|
+
await highlighter.loadTheme(themeName);
|
|
123
|
+
} catch (error) {
|
|
124
|
+
promiseMap.delete(themeName);
|
|
125
|
+
console.warn(`Failed to load theme ${themeName}:`, error);
|
|
126
|
+
}
|
|
127
|
+
})();
|
|
128
|
+
|
|
129
|
+
promiseMap.set(themeName, loadPromise);
|
|
130
|
+
return loadPromise;
|
|
131
|
+
}
|
|
132
|
+
|
|
97
133
|
export async function loadLanguageIfNeeded(
|
|
98
134
|
highlighter: HighlighterCore,
|
|
99
135
|
language: string
|
|
@@ -160,7 +196,8 @@ export function createShikiState(): ShikiState {
|
|
|
160
196
|
|
|
161
197
|
export async function initializeHighlighter(
|
|
162
198
|
shikiState: ShikiState,
|
|
163
|
-
shikiModule: ShikiModule
|
|
199
|
+
shikiModule: ShikiModule,
|
|
200
|
+
engine: any
|
|
164
201
|
): Promise<HighlighterCore> {
|
|
165
202
|
if (shikiState.highlighter) {
|
|
166
203
|
return shikiState.highlighter;
|
|
@@ -171,9 +208,12 @@ export async function initializeHighlighter(
|
|
|
171
208
|
}
|
|
172
209
|
|
|
173
210
|
shikiState.initPromise = (async () => {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
211
|
+
// Only load the default light theme upfront; dark theme is lazy-loaded
|
|
212
|
+
// on first dark-mode request via loadThemeIfNeeded().
|
|
213
|
+
const highlighter = await shikiModule.createHighlighterCore({
|
|
214
|
+
themes: [THEME_MAP.light],
|
|
215
|
+
langs: CORE_LANGUAGES,
|
|
216
|
+
engine
|
|
177
217
|
});
|
|
178
218
|
shikiState.highlighter = highlighter;
|
|
179
219
|
shikiState.initialized = true;
|
|
@@ -198,7 +238,11 @@ export async function highlightCodeWithShiki(
|
|
|
198
238
|
): Promise<string> {
|
|
199
239
|
let mappedLanguage = getMappedLanguage(language);
|
|
200
240
|
|
|
201
|
-
|
|
241
|
+
const themeName = THEME_MAP[theme];
|
|
242
|
+
await Promise.all([
|
|
243
|
+
loadLanguageIfNeeded(highlighter, mappedLanguage),
|
|
244
|
+
loadThemeIfNeeded(highlighter, themeName)
|
|
245
|
+
]);
|
|
202
246
|
|
|
203
247
|
const loadedLanguages = highlighter.getLoadedLanguages();
|
|
204
248
|
if (!loadedLanguages.includes(mappedLanguage)) {
|
|
@@ -207,7 +251,7 @@ export async function highlightCodeWithShiki(
|
|
|
207
251
|
|
|
208
252
|
return highlighter.codeToHtml(code, {
|
|
209
253
|
lang: mappedLanguage,
|
|
210
|
-
theme:
|
|
254
|
+
theme: themeName,
|
|
211
255
|
transformers: [transformerColorizedBrackets()],
|
|
212
256
|
colorReplacements: THEME_MAP_COLOR_REPLACEMENTS[theme].colorReplacements
|
|
213
257
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
function createDataweaveGrammar() { return {
|
|
2
2
|
name: "dataweave",
|
|
3
3
|
scopeName: "source.data-weave",
|
|
4
4
|
fileTypes: ["dwl"],
|
|
@@ -1121,7 +1121,7 @@ const dataweaveGrammar = {
|
|
|
1121
1121
|
]
|
|
1122
1122
|
}
|
|
1123
1123
|
}
|
|
1124
|
-
};
|
|
1124
|
+
}; }
|
|
1125
1125
|
|
|
1126
1126
|
const ampscriptGrammar = {
|
|
1127
1127
|
version: "2.0",
|
|
@@ -1300,7 +1300,7 @@ const ampscriptGrammar = {
|
|
|
1300
1300
|
}
|
|
1301
1301
|
};
|
|
1302
1302
|
|
|
1303
|
-
|
|
1303
|
+
function createAgentscriptGrammar() { return {
|
|
1304
1304
|
name: "agentscript",
|
|
1305
1305
|
scopeName: "source.agentscript",
|
|
1306
1306
|
fileTypes: ["agent"],
|
|
@@ -2479,12 +2479,12 @@ const agentscriptGrammar = {
|
|
|
2479
2479
|
]
|
|
2480
2480
|
}
|
|
2481
2481
|
}
|
|
2482
|
-
};
|
|
2482
|
+
}; }
|
|
2483
2483
|
|
|
2484
2484
|
export function getCustomLanguageGrammars() {
|
|
2485
2485
|
return {
|
|
2486
|
-
dataweave:
|
|
2486
|
+
dataweave: createDataweaveGrammar,
|
|
2487
2487
|
ampscript: ampscriptGrammar,
|
|
2488
|
-
agentscript:
|
|
2488
|
+
agentscript: createAgentscriptGrammar
|
|
2489
2489
|
};
|
|
2490
2490
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HighlighterCore } from "shiki";
|
|
2
|
-
import
|
|
2
|
+
import { createHighlighterCore, createJavaScriptRegexEngine } from "shiki";
|
|
3
3
|
import { transformerColorizedBrackets } from "@shikijs/colorized-brackets";
|
|
4
4
|
import {
|
|
5
5
|
createShikiState,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
const shikiState: ShikiState = createShikiState();
|
|
19
19
|
|
|
20
20
|
async function initializeShiki(): Promise<HighlighterCore> {
|
|
21
|
-
return initializeHighlighter(shikiState,
|
|
21
|
+
return initializeHighlighter(shikiState, { createHighlighterCore }, createJavaScriptRegexEngine());
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|