@lvce-editor/extension-management-worker 1.7.0 → 1.9.0

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.
@@ -14,9 +14,9 @@ const getCombinedMessage = (error, message) => {
14
14
  }
15
15
  return stringifiedError;
16
16
  };
17
- const NewLine$2 = '\n';
17
+ const NewLine$3 = '\n';
18
18
  const getNewLineIndex$1 = (string, startIndex = undefined) => {
19
- return string.indexOf(NewLine$2, startIndex);
19
+ return string.indexOf(NewLine$3, startIndex);
20
20
  };
21
21
  const mergeStacks = (parent, child) => {
22
22
  if (!child) {
@@ -90,6 +90,12 @@ const getType = value => {
90
90
  return Unknown;
91
91
  }
92
92
  };
93
+ const object = value => {
94
+ const type = getType(value);
95
+ if (type !== Object$1) {
96
+ throw new AssertionError('expected value to be of type object');
97
+ }
98
+ };
93
99
  const string = value => {
94
100
  const type = getType(value);
95
101
  if (type !== String) {
@@ -170,9 +176,9 @@ class Ipc extends EventTarget {
170
176
  const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
171
177
  const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
172
178
  const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
173
- const NewLine$1 = '\n';
179
+ const NewLine$2 = '\n';
174
180
  const joinLines$1 = lines => {
175
- return lines.join(NewLine$1);
181
+ return lines.join(NewLine$2);
176
182
  };
177
183
  const RE_AT = /^\s+at/;
178
184
  const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
@@ -199,7 +205,7 @@ const getDetails = lines => {
199
205
  };
200
206
  };
201
207
  const splitLines$1 = lines => {
202
- return lines.split(NewLine$1);
208
+ return lines.split(NewLine$2);
203
209
  };
204
210
  const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
205
211
  const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
@@ -578,10 +584,10 @@ const create$4$1 = (method, params) => {
578
584
  };
579
585
  };
580
586
  const callbacks = Object.create(null);
581
- const set$7 = (id, fn) => {
587
+ const set$8 = (id, fn) => {
582
588
  callbacks[id] = fn;
583
589
  };
584
- const get$3 = id => {
590
+ const get$4 = id => {
585
591
  return callbacks[id];
586
592
  };
587
593
  const remove = id => {
@@ -597,7 +603,7 @@ const registerPromise = () => {
597
603
  resolve,
598
604
  promise
599
605
  } = Promise.withResolvers();
600
- set$7(id, resolve);
606
+ set$8(id, resolve);
601
607
  return {
602
608
  id,
603
609
  promise
@@ -625,7 +631,7 @@ class JsonRpcError extends Error {
625
631
  this.name = 'JsonRpcError';
626
632
  }
627
633
  }
628
- const NewLine = '\n';
634
+ const NewLine$1 = '\n';
629
635
  const DomException = 'DOMException';
630
636
  const ReferenceError$1 = 'ReferenceError';
631
637
  const SyntaxError$1 = 'SyntaxError';
@@ -671,10 +677,10 @@ const constructError = (message, type, name) => {
671
677
  return new ErrorConstructor(message);
672
678
  };
673
679
  const joinLines = lines => {
674
- return lines.join(NewLine);
680
+ return lines.join(NewLine$1);
675
681
  };
676
682
  const splitLines = lines => {
677
- return lines.split(NewLine);
683
+ return lines.split(NewLine$1);
678
684
  };
679
685
  const getCurrentStack = () => {
680
686
  const stackLinesToSkip = 3;
@@ -682,12 +688,12 @@ const getCurrentStack = () => {
682
688
  return currentStack;
683
689
  };
684
690
  const getNewLineIndex = (string, startIndex = undefined) => {
685
- return string.indexOf(NewLine, startIndex);
691
+ return string.indexOf(NewLine$1, startIndex);
686
692
  };
687
693
  const getParentStack = error => {
688
694
  let parentStack = error.stack || error.data || error.message || '';
689
695
  if (parentStack.startsWith(' at')) {
690
- parentStack = error.message + NewLine + parentStack;
696
+ parentStack = error.message + NewLine$1 + parentStack;
691
697
  }
692
698
  return parentStack;
693
699
  };
@@ -697,21 +703,21 @@ const restoreJsonRpcError = error => {
697
703
  const currentStack = getCurrentStack();
698
704
  if (error && error instanceof Error) {
699
705
  if (typeof error.stack === 'string') {
700
- error.stack = error.stack + NewLine + currentStack;
706
+ error.stack = error.stack + NewLine$1 + currentStack;
701
707
  }
702
708
  return error;
703
709
  }
704
710
  if (error && error.code && error.code === MethodNotFound) {
705
711
  const restoredError = new JsonRpcError(error.message);
706
712
  const parentStack = getParentStack(error);
707
- restoredError.stack = parentStack + NewLine + currentStack;
713
+ restoredError.stack = parentStack + NewLine$1 + currentStack;
708
714
  return restoredError;
709
715
  }
710
716
  if (error && error.message) {
711
717
  const restoredError = constructError(error.message, error.type, error.name);
712
718
  if (error.data) {
713
719
  if (error.data.stack && error.data.type && error.message) {
714
- restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
720
+ restoredError.stack = error.data.type + ': ' + error.message + NewLine$1 + error.data.stack + NewLine$1 + currentStack;
715
721
  } else if (error.data.stack) {
716
722
  restoredError.stack = error.data.stack;
717
723
  }
@@ -758,14 +764,14 @@ const unwrapJsonRpcResult = responseMessage => {
758
764
  }
759
765
  throw new JsonRpcError('unexpected response message');
760
766
  };
761
- const warn = (...args) => {
767
+ const warn$1 = (...args) => {
762
768
  console.warn(...args);
763
769
  };
764
770
  const resolve = (id, response) => {
765
- const fn = get$3(id);
771
+ const fn = get$4(id);
766
772
  if (!fn) {
767
773
  console.log(response);
768
- warn(`callback ${id} may already be disposed`);
774
+ warn$1(`callback ${id} may already be disposed`);
769
775
  return;
770
776
  }
771
777
  fn(response);
@@ -1133,45 +1139,45 @@ const RendererWorker = 1;
1133
1139
  const SharedProcess = 1;
1134
1140
 
1135
1141
  const rpcs = Object.create(null);
1136
- const set$6 = (id, rpc) => {
1142
+ const set$7 = (id, rpc) => {
1137
1143
  rpcs[id] = rpc;
1138
1144
  };
1139
- const get$2 = id => {
1145
+ const get$3 = id => {
1140
1146
  return rpcs[id];
1141
1147
  };
1142
1148
 
1143
1149
  const create$1 = rpcId => {
1144
1150
  return {
1145
1151
  async dispose() {
1146
- const rpc = get$2(rpcId);
1152
+ const rpc = get$3(rpcId);
1147
1153
  await rpc.dispose();
1148
1154
  },
1149
1155
  // @ts-ignore
1150
1156
  invoke(method, ...params) {
1151
- const rpc = get$2(rpcId);
1157
+ const rpc = get$3(rpcId);
1152
1158
  // @ts-ignore
1153
1159
  return rpc.invoke(method, ...params);
1154
1160
  },
1155
1161
  // @ts-ignore
1156
1162
  invokeAndTransfer(method, ...params) {
1157
- const rpc = get$2(rpcId);
1163
+ const rpc = get$3(rpcId);
1158
1164
  // @ts-ignore
1159
1165
  return rpc.invokeAndTransfer(method, ...params);
1160
1166
  },
1161
1167
  set(rpc) {
1162
- set$6(rpcId, rpc);
1168
+ set$7(rpcId, rpc);
1163
1169
  }
1164
1170
  };
1165
1171
  };
1166
1172
 
1167
1173
  const {
1168
1174
  invoke: invoke$3,
1169
- set: set$5
1175
+ set: set$6
1170
1176
  } = create$1(ExtensionHostWorker);
1171
1177
 
1172
1178
  const {
1173
1179
  invoke: invoke$2,
1174
- set: set$4
1180
+ set: set$5
1175
1181
  } = create$1(FileSystemWorker);
1176
1182
  const readFile = async uri => {
1177
1183
  return invoke$2('FileSystem.readFile', uri);
@@ -1187,7 +1193,7 @@ const exists = async uri => {
1187
1193
  const {
1188
1194
  invoke: invoke$1,
1189
1195
  invokeAndTransfer,
1190
- set: set$3
1196
+ set: set$4
1191
1197
  } = create$1(RendererWorker);
1192
1198
  const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
1193
1199
  const command = 'FileSystem.handleMessagePort';
@@ -1206,7 +1212,7 @@ const sendMessagePortToSharedProcess = async port => {
1206
1212
 
1207
1213
  const {
1208
1214
  invoke,
1209
- set: set$2
1215
+ set: set$3
1210
1216
  } = create$1(SharedProcess);
1211
1217
 
1212
1218
  const create = () => {
@@ -1252,10 +1258,10 @@ const isImportError = error => {
1252
1258
  };
1253
1259
 
1254
1260
  const states = Object.create(null);
1255
- const set$1 = status => {
1261
+ const set$2 = status => {
1256
1262
  states[status.id] = status;
1257
1263
  };
1258
- const get$1 = extensionId => {
1264
+ const get$2 = extensionId => {
1259
1265
  return states[extensionId];
1260
1266
  };
1261
1267
  const update$1 = (id, update) => {
@@ -1314,6 +1320,9 @@ const activate = async (extensionId, extension) => {
1314
1320
  await invoke$3('ExtensionHost.activateExtension3', extensionId, extension);
1315
1321
  };
1316
1322
  const activateExtension2 = async (extensionId, extension, absolutePath) => {
1323
+ string(extensionId);
1324
+ object(extension);
1325
+ string(absolutePath);
1317
1326
  const token = create();
1318
1327
  try {
1319
1328
  const startTime = performance.now();
@@ -1363,6 +1372,7 @@ const getJson = async url => {
1363
1372
  }
1364
1373
  };
1365
1374
 
1375
+ const NewLine = '\n';
1366
1376
  const Slash = '/';
1367
1377
 
1368
1378
  const interExtensionId = path => {
@@ -1404,7 +1414,7 @@ let state = {
1404
1414
  disabledIds: [],
1405
1415
  platform: 0
1406
1416
  };
1407
- const set = newState => {
1417
+ const set$1 = newState => {
1408
1418
  state = newState;
1409
1419
  };
1410
1420
  const update = newState => {
@@ -1414,19 +1424,19 @@ const update = newState => {
1414
1424
  };
1415
1425
  state = fullNewState;
1416
1426
  };
1417
- const get = () => {
1427
+ const get$1 = () => {
1418
1428
  return state;
1419
1429
  };
1420
1430
 
1421
1431
  const disableExtension = async (id, isTest) => {
1422
- const oldState = get();
1432
+ const oldState = get$1();
1423
1433
  try {
1424
1434
  if (isTest) {
1425
1435
  const newState = {
1426
1436
  ...oldState,
1427
1437
  disabledIds: [...oldState.disabledIds, id]
1428
1438
  };
1429
- set(newState);
1439
+ set$1(newState);
1430
1440
  } else {
1431
1441
  await invoke('ExtensionManagement.disable', id);
1432
1442
  }
@@ -1438,7 +1448,7 @@ const disableExtension = async (id, isTest) => {
1438
1448
  };
1439
1449
 
1440
1450
  const enableExtension = async (id, isTest) => {
1441
- const oldState = get();
1451
+ const oldState = get$1();
1442
1452
  const {
1443
1453
  platform
1444
1454
  } = oldState;
@@ -1463,19 +1473,245 @@ const enableExtension = async (id, isTest) => {
1463
1473
  ...oldState,
1464
1474
  disabledIds: oldState.disabledIds.filter(existing => existing !== id)
1465
1475
  };
1466
- set(newState);
1476
+ set$1(newState);
1467
1477
  }
1468
1478
  return undefined;
1469
1479
  };
1470
1480
 
1481
+ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
1482
+ const warn = (...args) => {
1483
+ console.warn(...args);
1484
+ };
1485
+
1486
+ const transparent = (color, factor) => {
1487
+ return color;
1488
+ };
1489
+ const toColorRule = ([key, value]) => {
1490
+ return ` --${key}: ${value};`;
1491
+ };
1492
+ const toTokenColorRule = tokenColor => {
1493
+ return `.${tokenColor.name} { color: ${tokenColor.foreground} }`;
1494
+ };
1495
+ const addFallbackColors = colors => {
1496
+ const newColors = {
1497
+ ...colors
1498
+ };
1499
+ if (!newColors.ActivityBarInactiveForeground) {
1500
+ // TODO don't assign, avoid mutation
1501
+ newColors.ActivityBarInactiveForeground = transparent(newColors.ActivityBarForeground);
1502
+ }
1503
+ newColors.CssVariableName ||= colors.VariableName;
1504
+ return newColors;
1505
+ };
1506
+ const createColorThemeFromJson = (colorThemeId, colorThemeJson) => {
1507
+ if (!colorThemeJson) {
1508
+ warn(`color theme json for "${colorThemeId}" is empty: "${colorThemeJson}"`);
1509
+ return '';
1510
+ }
1511
+ if (typeof colorThemeJson !== 'object') {
1512
+ warn(`color theme json for "${colorThemeId}" cannot be converted to css: "${colorThemeJson}"`);
1513
+ return '';
1514
+ }
1515
+ if (Array.isArray(colorThemeJson)) {
1516
+ warn(`color theme json for "${colorThemeId}" cannot be converted to css, it must be of type object but was of type array`);
1517
+ return '';
1518
+ }
1519
+ const {
1520
+ colors
1521
+ } = colorThemeJson;
1522
+ if (!colors) {
1523
+ return '';
1524
+ }
1525
+ const newColors = addFallbackColors(colors);
1526
+ const colorRules = Object.entries(newColors).map(toColorRule);
1527
+ const tokenColors = colorThemeJson.tokenColors || [];
1528
+ const tokenColorRules = tokenColors.map(toTokenColorRule);
1529
+ const extraRules = [];
1530
+ if (colors.ContrastBorder) {
1531
+ extraRules.push(`#ActivityBar, #SideBar {
1532
+ border-left: 1px solid var(--ContrastBorder);
1533
+ }`, `#Panel {
1534
+ border-top: 1px solid var(--ContrastBorder);
1535
+ }`, `#StatusBar {
1536
+ border-top: 1px solid var(--ContrastBorder);
1537
+ }`, `.ActivityBarItemBadge {
1538
+ border: 1px solid var(--ContrastBorder);
1539
+ }`, `#QuickPick {
1540
+ border: 1px solid var(--ContrastBorder);
1541
+ }`);
1542
+ }
1543
+ const colorThemeCss = `:root {\n${colorRules.join(NewLine)}\n}\n\n${tokenColorRules.join(NewLine)}\n\n${extraRules.join(NewLine)}`;
1544
+ return colorThemeCss;
1545
+ };
1546
+
1547
+ // for (let i = 0; i < 10000; i++) {
1548
+ // createColorThemeFromJson({
1549
+ // type: 'dark',
1550
+ // colors: {
1551
+ // ActivityBarBackground: 'rgb(40, 46, 47)',
1552
+ // ActivityBarForeground: '#878f8c',
1553
+ // ActivityBarActiveBackground: '#1f2727',
1554
+
1555
+ // EditorBackGround: '#1e2324',
1556
+ // EditorScrollBarBackground: 'rgba(57, 71, 71, 0.6)',
1557
+ // EditorCursorBackground: '#a8df5a',
1558
+
1559
+ // ListActiveSelectionBackground: '#515f59',
1560
+ // ListActiveSelectionForeground: '#ffffff',
1561
+ // ListHoverBackground: '#405c5033',
1562
+ // ListHoverForeground: '#e0e0e0',
1563
+ // ListInactiveSelectionBackground: '#3b474280',
1564
+
1565
+ // MainBackground: '#1e2324',
1566
+
1567
+ // PanelBackground: '#1b2020',
1568
+ // PanelBorderTopColor: 'rgba(128, 128, 128, 0.35)',
1569
+
1570
+ // SideBarBackground: '#1b2020',
1571
+
1572
+ // StatusBarBackground: 'rgb(40, 46, 47)',
1573
+ // StatusBarBorderTopColor: '#222222',
1574
+
1575
+ // TabActiveBackground: '#24292a',
1576
+ // TabInactiveBackground: '#282e2f',
1577
+
1578
+ // TitleBarBackground: 'rgb(40, 46, 47)',
1579
+ // TitleBarBorderBottomColor: '#222',
1580
+ // TitleBarColor: '#cccccc',
1581
+ // TitleBarColorInactive: 'rgba(204, 204, 204, 0.6)',
1582
+ // },
1583
+ // }) //?.
1584
+ // }
1585
+
1586
+ const get = colorThemeId => {
1587
+ return '';
1588
+ };
1589
+ const set = (colorThemeId, data) => {
1590
+ // noop
1591
+ };
1592
+
1593
+ const GetColorThemeCssCachedNoop = {
1594
+ __proto__: null,
1595
+ get,
1596
+ set
1597
+ };
1598
+
1599
+ // TODO make storage configurable via settings as localstorage or indexeddb
1600
+ // also allow disabling caching via settings
1601
+ // then measure which option could be fastest
1602
+
1603
+ const getCacheFn = config => {
1604
+ switch (config) {
1605
+ default:
1606
+ return GetColorThemeCssCachedNoop;
1607
+ }
1608
+ };
1609
+ const getColorThemeCssCached = async (colorThemeId, platform, getData) => {
1610
+ const config = '';
1611
+ const module = getCacheFn(config);
1612
+ const cachedData = module.get(colorThemeId);
1613
+ if (cachedData) {
1614
+ return cachedData;
1615
+ }
1616
+ const newData = await getData(colorThemeId, platform);
1617
+ module.set(colorThemeId, newData);
1618
+ return newData;
1619
+ };
1620
+
1621
+ const readJson = url => {
1622
+ return invoke$1('FileSystem.readJson', url);
1623
+ };
1624
+
1625
+ const join = (pathSeparator, ...parts) => {
1626
+ return parts.join(pathSeparator);
1627
+ };
1628
+
1629
+ const getColorThemeUri = (extensions, colorThemeId) => {
1630
+ for (const extension of extensions) {
1631
+ if (!extension.colorThemes) {
1632
+ continue;
1633
+ }
1634
+ for (const colorTheme of extension.colorThemes) {
1635
+ if (colorTheme.id !== colorThemeId) {
1636
+ continue;
1637
+ }
1638
+ const absolutePath = join('/', extension.uri, colorTheme.path);
1639
+ return absolutePath;
1640
+ }
1641
+ }
1642
+ return '';
1643
+ };
1644
+
1471
1645
  const getAllExtensions = async () => {
1472
- const state = get();
1646
+ const state = get$1();
1473
1647
  if (state.platform === Web) {
1474
1648
  return [];
1475
1649
  }
1476
1650
  return invoke('ExtensionManagement.getAllExtensions');
1477
1651
  };
1478
1652
 
1653
+ const getColorThemeJson$2 = async colorThemeId => {
1654
+ const extensions = await getAllExtensions();
1655
+ const colorThemeUri = getColorThemeUri(extensions, colorThemeId);
1656
+ if (!colorThemeUri) {
1657
+ return {};
1658
+ }
1659
+ const json = await readJson(colorThemeUri);
1660
+ return json;
1661
+ };
1662
+
1663
+ const assetDir = '';
1664
+
1665
+ const getColorThemeUrlWeb = colorThemeId => {
1666
+ return `${assetDir}/extensions/builtin.theme-${colorThemeId}/color-theme.json`;
1667
+ };
1668
+ const getColorThemeJson$1 = colorThemeId => {
1669
+ const url = getColorThemeUrlWeb(colorThemeId);
1670
+ // TODO handle error ?
1671
+ return getJson(url);
1672
+ };
1673
+
1674
+ const getColorThemeJson = (colorThemeId, platform) => {
1675
+ if (platform === Web) {
1676
+ return getColorThemeJson$1(colorThemeId);
1677
+ }
1678
+ return getColorThemeJson$2(colorThemeId);
1679
+ };
1680
+
1681
+ const getColorThemeCssFromJson = async (colorThemeId, colorThemeJson) => {
1682
+ const colorThemeCss = createColorThemeFromJson(/* colorThemeId */colorThemeId, /* colorThemeJson */colorThemeJson);
1683
+ return colorThemeCss;
1684
+ // TODO generate color theme from jsonc
1685
+ };
1686
+ const getColorThemeCssNew = async (colorThemeId, platform) => {
1687
+ const colorThemeJson = await getColorThemeJson(colorThemeId, platform);
1688
+ const colorThemeCss = await getColorThemeCssFromJson(colorThemeId, colorThemeJson);
1689
+ return colorThemeCss;
1690
+ };
1691
+ const getColorThemeCss = (colorThemeId, platform) => {
1692
+ return getColorThemeCssCached(colorThemeId, platform, getColorThemeCssNew);
1693
+ };
1694
+
1695
+ const getExtensionColorThemeNames = extension => {
1696
+ return extension.colorThemes || [];
1697
+ };
1698
+ const getColorThemeId = colorTheme => {
1699
+ return colorTheme.id;
1700
+ };
1701
+
1702
+ // TODO should send names to renderer worker or names with ids?
1703
+ const getColorThemeNamesFromExtensions = async extensions => {
1704
+ const colorThemes = extensions.flatMap(getExtensionColorThemeNames);
1705
+ const colorThemeNames = colorThemes.map(getColorThemeId);
1706
+ return colorThemeNames;
1707
+ };
1708
+
1709
+ const getColorThemeNames = async () => {
1710
+ const extensions = await getAllExtensions();
1711
+ const colorThemeNames = getColorThemeNamesFromExtensions(extensions);
1712
+ return colorThemeNames;
1713
+ };
1714
+
1479
1715
  const getExtension = async id => {
1480
1716
  const allExtensions = await getAllExtensions();
1481
1717
  for (const extension of allExtensions) {
@@ -1498,7 +1734,7 @@ const emptyStatus = {
1498
1734
  status: None
1499
1735
  };
1500
1736
  const getRuntimeStatus = extensionId => {
1501
- return get$1(extensionId) || emptyStatus;
1737
+ return get$2(extensionId) || emptyStatus;
1502
1738
  };
1503
1739
 
1504
1740
  const commandMapRef = {};
@@ -1514,7 +1750,7 @@ const importExtension = async (extensionId, absolutePath, activationEvent) => {
1514
1750
  try {
1515
1751
  string(absolutePath);
1516
1752
  const startTime = performance.now();
1517
- set$1({
1753
+ set$2({
1518
1754
  activationEndTime: 0,
1519
1755
  activationEvent: activationEvent,
1520
1756
  activationStartTime: performance.now(),
@@ -1555,7 +1791,7 @@ const initializeExtensionHostWorker = async () => {
1555
1791
  await sendMessagePortToExtensionHostWorker(port, 0);
1556
1792
  }
1557
1793
  });
1558
- set$5(rpc);
1794
+ set$6(rpc);
1559
1795
  };
1560
1796
 
1561
1797
  const initializeFileSystemWorker = async () => {
@@ -1565,7 +1801,7 @@ const initializeFileSystemWorker = async () => {
1565
1801
  await sendMessagePortToFileSystemWorker(port, 0);
1566
1802
  }
1567
1803
  });
1568
- set$4(rpc);
1804
+ set$5(rpc);
1569
1805
  };
1570
1806
 
1571
1807
  const getRpc = async platform => {
@@ -1591,7 +1827,7 @@ const getRpc = async platform => {
1591
1827
  const initializeSharedProcess = async platform => {
1592
1828
  const rpc = await getRpc(platform);
1593
1829
  if (rpc) {
1594
- set$2(rpc);
1830
+ set$3(rpc);
1595
1831
  }
1596
1832
  };
1597
1833
 
@@ -1606,6 +1842,50 @@ const installExtension = async () => {
1606
1842
  // TODO
1607
1843
  };
1608
1844
 
1845
+ const getLanguagesFromExtension = extension => {
1846
+ // TODO what if extension is null? should not crash process, handle error gracefully
1847
+ // TODO what if extension languages is not of type array?
1848
+ // TODO what if language is null?
1849
+ if (!extension) {
1850
+ return [];
1851
+ }
1852
+ if (!extension.languages) {
1853
+ return [];
1854
+ }
1855
+ const extensionPath = extension.path;
1856
+ const getLanguageFromExtension = language => {
1857
+ if (language.tokenize) {
1858
+ if (typeof language.tokenize !== 'string') {
1859
+ console.warn(`[info] ${language.id}: language.tokenize must be of type string but was of type ${typeof language.tokenize}`);
1860
+ return {
1861
+ ...language,
1862
+ extensionPath,
1863
+ tokenize: ''
1864
+ };
1865
+ }
1866
+ const relativePath = `${extensionPath}/${language.tokenize}`;
1867
+ const absolutePath = relativePath ;
1868
+ return {
1869
+ ...language,
1870
+ extensionPath,
1871
+ tokenize: absolutePath
1872
+ };
1873
+ }
1874
+ return language;
1875
+ };
1876
+ return extension.languages.map(getLanguageFromExtension);
1877
+ };
1878
+
1879
+ const getLanguages = async () => {
1880
+ try {
1881
+ const extensions = await getAllExtensions();
1882
+ const languages = extensions.flatMap(getLanguagesFromExtension);
1883
+ return languages;
1884
+ } catch (error) {
1885
+ throw new VError(error, 'Failed to load languages');
1886
+ }
1887
+ };
1888
+
1609
1889
  const uninstallExtension = async () => {
1610
1890
  // TODO
1611
1891
  };
@@ -1616,12 +1896,17 @@ const commandMap = {
1616
1896
  'Extensions.disable': disableExtension,
1617
1897
  'Extensions.enable': enableExtension,
1618
1898
  'Extensions.getAllExtensions': getAllExtensions,
1899
+ 'Extensions.getColorThemeCssFromJson': getColorThemeCss,
1900
+ 'Extensions.getColorThemeJson': getColorThemeJson,
1901
+ 'Extensions.getColorThemeNames': getColorThemeNames,
1619
1902
  'Extensions.getExtension': getExtension,
1903
+ 'Extensions.getLanguages': getLanguages,
1620
1904
  'Extensions.getRuntimeStatus': getRuntimeStatus,
1621
1905
  'Extensions.handleMessagePort': handleMessagePort,
1622
1906
  'Extensions.importExtension': importExtension,
1623
1907
  'Extensions.initialize': initialize,
1624
1908
  'Extensions.install': installExtension,
1909
+ 'Extensions.invalidateExtensionsCache': invalidateExtensionsCache,
1625
1910
  'Extensions.uninstall': uninstallExtension
1626
1911
  };
1627
1912
 
@@ -1630,7 +1915,7 @@ const listen = async () => {
1630
1915
  const rpc = await WebWorkerRpcClient.create({
1631
1916
  commandMap: commandMap
1632
1917
  });
1633
- set$3(rpc);
1918
+ set$4(rpc);
1634
1919
  };
1635
1920
 
1636
1921
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-management-worker",
3
- "version": "1.7.0",
3
+ "version": "1.9.0",
4
4
  "description": "Webworker for the Extension Management functionality in Lvce Editor.",
5
5
  "keywords": [
6
6
  "web-worker"