@lvce-editor/extension-management-worker 1.9.0 → 1.11.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.
@@ -1353,6 +1353,50 @@ const activateExtension2 = async (extensionId, extension, absolutePath) => {
1353
1353
  }
1354
1354
  };
1355
1355
 
1356
+ const importExtension = async (extensionId, absolutePath, activationEvent) => {
1357
+ try {
1358
+ string(absolutePath);
1359
+ const startTime = performance.now();
1360
+ set$2({
1361
+ activationEndTime: 0,
1362
+ activationEvent: activationEvent,
1363
+ activationStartTime: performance.now(),
1364
+ activationTime: 0,
1365
+ id: extensionId,
1366
+ importEndTime: 0,
1367
+ importStartTime: startTime,
1368
+ importTime: 0,
1369
+ status: Importing
1370
+ });
1371
+ try {
1372
+ await invoke$3('ExtensionHost.importExtension2', extensionId, absolutePath);
1373
+ const endTime = performance.now();
1374
+ const time = endTime - startTime;
1375
+ update$1(extensionId, {
1376
+ importEndTime: endTime,
1377
+ importTime: time
1378
+ });
1379
+ } catch (error) {
1380
+ update$1(extensionId, {
1381
+ status: Error$1 // TODO maybe store error also in runtime status state
1382
+ });
1383
+ if (isImportError(error)) {
1384
+ const actualErrorMessage = await tryToGetActualImportErrorMessage(absolutePath, error);
1385
+ throw new Error(actualErrorMessage);
1386
+ }
1387
+ throw error;
1388
+ }
1389
+ } catch (error) {
1390
+ throw new VError(error, `Failed to import extension ${extensionId}`);
1391
+ }
1392
+ };
1393
+
1394
+ const activateExtension3 = async (extension, absolutePath, activationEvent) => {
1395
+ const extensionId = extension.id;
1396
+ await importExtension(extensionId, absolutePath, activationEvent);
1397
+ await activateExtension2(extensionId, extension, absolutePath);
1398
+ };
1399
+
1356
1400
  const cache = Object.create(null);
1357
1401
  const id = 1;
1358
1402
  const clear = () => {
@@ -1660,20 +1704,18 @@ const getColorThemeJson$2 = async colorThemeId => {
1660
1704
  return json;
1661
1705
  };
1662
1706
 
1663
- const assetDir = '';
1664
-
1665
- const getColorThemeUrlWeb = colorThemeId => {
1707
+ const getColorThemeUrlWeb = (assetDir, colorThemeId) => {
1666
1708
  return `${assetDir}/extensions/builtin.theme-${colorThemeId}/color-theme.json`;
1667
1709
  };
1668
- const getColorThemeJson$1 = colorThemeId => {
1669
- const url = getColorThemeUrlWeb(colorThemeId);
1710
+ const getColorThemeJson$1 = (colorThemeId, assetDir) => {
1711
+ const url = getColorThemeUrlWeb(assetDir, colorThemeId);
1670
1712
  // TODO handle error ?
1671
1713
  return getJson(url);
1672
1714
  };
1673
1715
 
1674
- const getColorThemeJson = (colorThemeId, platform) => {
1716
+ const getColorThemeJson = (colorThemeId, platform, assetDir) => {
1675
1717
  if (platform === Web) {
1676
- return getColorThemeJson$1(colorThemeId);
1718
+ return getColorThemeJson$1(colorThemeId, assetDir);
1677
1719
  }
1678
1720
  return getColorThemeJson$2(colorThemeId);
1679
1721
  };
@@ -1683,8 +1725,8 @@ const getColorThemeCssFromJson = async (colorThemeId, colorThemeJson) => {
1683
1725
  return colorThemeCss;
1684
1726
  // TODO generate color theme from jsonc
1685
1727
  };
1686
- const getColorThemeCssNew = async (colorThemeId, platform) => {
1687
- const colorThemeJson = await getColorThemeJson(colorThemeId, platform);
1728
+ const getColorThemeCssNew = async (colorThemeId, platform, assetDir) => {
1729
+ const colorThemeJson = await getColorThemeJson(colorThemeId, platform, assetDir);
1688
1730
  const colorThemeCss = await getColorThemeCssFromJson(colorThemeId, colorThemeJson);
1689
1731
  return colorThemeCss;
1690
1732
  };
@@ -1746,44 +1788,6 @@ const handleMessagePort = async port => {
1746
1788
  });
1747
1789
  };
1748
1790
 
1749
- const importExtension = async (extensionId, absolutePath, activationEvent) => {
1750
- try {
1751
- string(absolutePath);
1752
- const startTime = performance.now();
1753
- set$2({
1754
- activationEndTime: 0,
1755
- activationEvent: activationEvent,
1756
- activationStartTime: performance.now(),
1757
- activationTime: 0,
1758
- id: extensionId,
1759
- importEndTime: 0,
1760
- importStartTime: startTime,
1761
- importTime: 0,
1762
- status: Importing
1763
- });
1764
- try {
1765
- await invoke$3('ExtneionHost.importExtension2', extensionId, absolutePath);
1766
- const endTime = performance.now();
1767
- const time = endTime - startTime;
1768
- update$1(extensionId, {
1769
- importEndTime: endTime,
1770
- importTime: time
1771
- });
1772
- } catch (error) {
1773
- update$1(extensionId, {
1774
- status: Error$1 // TODO maybe store error also in runtime status state
1775
- });
1776
- if (isImportError(error)) {
1777
- const actualErrorMessage = await tryToGetActualImportErrorMessage(absolutePath, error);
1778
- throw new Error(actualErrorMessage);
1779
- }
1780
- throw error;
1781
- }
1782
- } catch (error) {
1783
- throw new VError(error, `Failed to import extension ${extensionId}`);
1784
- }
1785
- };
1786
-
1787
1791
  const initializeExtensionHostWorker = async () => {
1788
1792
  const rpc = await TransferMessagePortRpcParent.create({
1789
1793
  commandMap: commandMapRef,
@@ -1842,7 +1846,14 @@ const installExtension = async () => {
1842
1846
  // TODO
1843
1847
  };
1844
1848
 
1845
- const getLanguagesFromExtension = extension => {
1849
+ const getRemoteUrl = uri => {
1850
+ if (uri.startsWith('/')) {
1851
+ return `/remote${uri}`;
1852
+ }
1853
+ return `/remote/${uri}`;
1854
+ };
1855
+
1856
+ const getLanguagesFromExtension = (extension, platform) => {
1846
1857
  // TODO what if extension is null? should not crash process, handle error gracefully
1847
1858
  // TODO what if extension languages is not of type array?
1848
1859
  // TODO what if language is null?
@@ -1864,7 +1875,7 @@ const getLanguagesFromExtension = extension => {
1864
1875
  };
1865
1876
  }
1866
1877
  const relativePath = `${extensionPath}/${language.tokenize}`;
1867
- const absolutePath = relativePath ;
1878
+ const absolutePath = platform === Web ? relativePath : getRemoteUrl(relativePath);
1868
1879
  return {
1869
1880
  ...language,
1870
1881
  extensionPath,
@@ -1876,10 +1887,10 @@ const getLanguagesFromExtension = extension => {
1876
1887
  return extension.languages.map(getLanguageFromExtension);
1877
1888
  };
1878
1889
 
1879
- const getLanguages = async () => {
1890
+ const getLanguages = async platform => {
1880
1891
  try {
1881
1892
  const extensions = await getAllExtensions();
1882
- const languages = extensions.flatMap(getLanguagesFromExtension);
1893
+ const languages = extensions.flatMap(extension => getLanguagesFromExtension(extension, platform));
1883
1894
  return languages;
1884
1895
  } catch (error) {
1885
1896
  throw new VError(error, 'Failed to load languages');
@@ -1892,6 +1903,7 @@ const uninstallExtension = async () => {
1892
1903
 
1893
1904
  const commandMap = {
1894
1905
  'Extensions.activate2': activateExtension2,
1906
+ 'Extensions.activate3': activateExtension3,
1895
1907
  'Extensions.addWebExtension': addWebExtension,
1896
1908
  'Extensions.disable': disableExtension,
1897
1909
  'Extensions.enable': enableExtension,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-management-worker",
3
- "version": "1.9.0",
3
+ "version": "1.11.0",
4
4
  "description": "Webworker for the Extension Management functionality in Lvce Editor.",
5
5
  "keywords": [
6
6
  "web-worker"