@lvce-editor/extension-management-worker 4.30.3 → 4.31.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.
@@ -604,7 +604,7 @@ const execute = (command, ...args) => {
604
604
 
605
605
  const Two$1 = '2.0';
606
606
  const callbacks = Object.create(null);
607
- const get$6 = id => {
607
+ const get$7 = id => {
608
608
  return callbacks[id];
609
609
  };
610
610
  const remove$2 = id => {
@@ -753,7 +753,7 @@ const warn$1 = (...args) => {
753
753
  console.warn(...args);
754
754
  };
755
755
  const resolve = (id, response) => {
756
- const fn = get$6(id);
756
+ const fn = get$7(id);
757
757
  if (!fn) {
758
758
  console.log(response);
759
759
  warn$1(`callback ${id} may already be disposed`);
@@ -1212,10 +1212,10 @@ const createMockRpc = ({
1212
1212
  };
1213
1213
 
1214
1214
  const rpcs$2 = Object.create(null);
1215
- const set$a = (id, rpc) => {
1215
+ const set$b = (id, rpc) => {
1216
1216
  rpcs$2[id] = rpc;
1217
1217
  };
1218
- const get$5 = id => {
1218
+ const get$6 = id => {
1219
1219
  return rpcs$2[id];
1220
1220
  };
1221
1221
  const remove$1 = id => {
@@ -1226,18 +1226,18 @@ const remove$1 = id => {
1226
1226
  const create$1 = rpcId => {
1227
1227
  return {
1228
1228
  async dispose() {
1229
- const rpc = get$5(rpcId);
1229
+ const rpc = get$6(rpcId);
1230
1230
  await rpc.dispose();
1231
1231
  },
1232
1232
  // @ts-ignore
1233
1233
  invoke(method, ...params) {
1234
- const rpc = get$5(rpcId);
1234
+ const rpc = get$6(rpcId);
1235
1235
  // @ts-ignore
1236
1236
  return rpc.invoke(method, ...params);
1237
1237
  },
1238
1238
  // @ts-ignore
1239
1239
  invokeAndTransfer(method, ...params) {
1240
- const rpc = get$5(rpcId);
1240
+ const rpc = get$6(rpcId);
1241
1241
  // @ts-ignore
1242
1242
  return rpc.invokeAndTransfer(method, ...params);
1243
1243
  },
@@ -1245,7 +1245,7 @@ const create$1 = rpcId => {
1245
1245
  const mockRpc = createMockRpc({
1246
1246
  commandMap
1247
1247
  });
1248
- set$a(rpcId, mockRpc);
1248
+ set$b(rpcId, mockRpc);
1249
1249
  // @ts-ignore
1250
1250
  mockRpc[Symbol.dispose] = () => {
1251
1251
  remove$1(rpcId);
@@ -1254,14 +1254,14 @@ const create$1 = rpcId => {
1254
1254
  return mockRpc;
1255
1255
  },
1256
1256
  set(rpc) {
1257
- set$a(rpcId, rpc);
1257
+ set$b(rpcId, rpc);
1258
1258
  }
1259
1259
  };
1260
1260
  };
1261
1261
 
1262
1262
  const {
1263
1263
  invoke: invoke$6,
1264
- set: set$9
1264
+ set: set$a
1265
1265
  } = create$1(6010);
1266
1266
 
1267
1267
  const Web = 1;
@@ -1277,7 +1277,7 @@ const SharedProcess = 1492;
1277
1277
 
1278
1278
  const {
1279
1279
  invoke: invoke$5,
1280
- set: set$8
1280
+ set: set$9
1281
1281
  } = create$1(ErrorWorker);
1282
1282
 
1283
1283
  const {
@@ -1285,7 +1285,7 @@ const {
1285
1285
  invoke: invoke$4,
1286
1286
  invokeAndTransfer: invokeAndTransfer$2,
1287
1287
  registerMockRpc,
1288
- set: set$7
1288
+ set: set$8
1289
1289
  } = create$1(ExtensionHostWorker);
1290
1290
  const executeReferenceProvider = async (id, offset) => {
1291
1291
  // @ts-ignore
@@ -1314,12 +1314,12 @@ const ExtensionHost = {
1314
1314
  invoke: invoke$4,
1315
1315
  invokeAndTransfer: invokeAndTransfer$2,
1316
1316
  registerMockRpc,
1317
- set: set$7
1317
+ set: set$8
1318
1318
  };
1319
1319
 
1320
1320
  const {
1321
1321
  invoke: invoke$3,
1322
- set: set$6
1322
+ set: set$7
1323
1323
  } = create$1(FileSystemWorker);
1324
1324
  const readFile$1 = async uri => {
1325
1325
  return invoke$3('FileSystem.readFile', uri);
@@ -1337,7 +1337,7 @@ const exists = async uri => {
1337
1337
  const {
1338
1338
  invoke: invoke$2,
1339
1339
  invokeAndTransfer: invokeAndTransfer$1,
1340
- set: set$5
1340
+ set: set$6
1341
1341
  } = create$1(RendererWorker);
1342
1342
  const sendMessagePortToAuthWorker = async (port, rpcId) => {
1343
1343
  const command = 'HandleMessagePort.handleMessagePort';
@@ -1366,7 +1366,7 @@ const sendMessagePortToSharedProcess = async port => {
1366
1366
 
1367
1367
  const {
1368
1368
  invoke: invoke$1,
1369
- set: set$4
1369
+ set: set$5
1370
1370
  } = create$1(SharedProcess);
1371
1371
 
1372
1372
  const create = () => {
@@ -1416,14 +1416,14 @@ const createEmptyRuntimeStatus = id => {
1416
1416
  const state = {
1417
1417
  extensionsState: createInitialState()
1418
1418
  };
1419
- const get$4 = () => {
1419
+ const get$5 = () => {
1420
1420
  return state.extensionsState;
1421
1421
  };
1422
- const set$3 = newState => {
1422
+ const set$4 = newState => {
1423
1423
  state.extensionsState = newState;
1424
1424
  };
1425
1425
  const update = newState => {
1426
- set$3({
1426
+ set$4({
1427
1427
  ...state.extensionsState,
1428
1428
  ...newState
1429
1429
  });
@@ -1578,6 +1578,79 @@ const activateExtension2 = async (extensionId, extension, absolutePath, extensio
1578
1578
 
1579
1579
  const commandMapRef = {};
1580
1580
 
1581
+ const extensions = Object.create(null);
1582
+ const get$4 = extensionId => {
1583
+ return extensions[extensionId];
1584
+ };
1585
+ const set$3 = extension => {
1586
+ extensions[extension.id] = extension;
1587
+ };
1588
+
1589
+ const nodeRpcType = 'node';
1590
+ const joinPath = (base, relativePath) => {
1591
+ let normalizedBase = base.replaceAll('\\', '/');
1592
+ while (normalizedBase.endsWith('/')) {
1593
+ normalizedBase = normalizedBase.slice(0, -1);
1594
+ }
1595
+ const normalizedRelativePath = relativePath.replaceAll('\\', '/').replace(/^\.\//, '');
1596
+ return `${normalizedBase}/${normalizedRelativePath}`;
1597
+ };
1598
+ const toFileSystemPath = path => {
1599
+ if (!path.startsWith('file:')) {
1600
+ return path;
1601
+ }
1602
+ const pathname = decodeURIComponent(new URL(path).pathname);
1603
+ return /^\/[A-Za-z]:\//.test(pathname) ? pathname.slice(1) : pathname;
1604
+ };
1605
+ const getExtensionRoot = async extension => {
1606
+ if (extension.builtin) {
1607
+ const builtinExtensionsPath = await invoke$2('PlatformPaths.getBuiltinExtensionsPath');
1608
+ if (typeof builtinExtensionsPath !== 'string') {
1609
+ throw new TypeError('builtin extensions path must be a string');
1610
+ }
1611
+ return joinPath(builtinExtensionsPath, extension.id);
1612
+ }
1613
+ const extensionPath = extension.uri || extension.path || '';
1614
+ if (!extensionPath) {
1615
+ throw new Error(`Extension ${extension.id} has no path`);
1616
+ }
1617
+ return toFileSystemPath(extensionPath);
1618
+ };
1619
+ const getDeclaredNodeRpc = (extension, rpcId) => {
1620
+ const rpc = extension.rpc.find(candidate => candidate.id === rpcId);
1621
+ if (!rpc) {
1622
+ throw new Error(`Node rpc ${rpcId} is not declared by extension ${extension.id}`);
1623
+ }
1624
+ if (rpc.type !== nodeRpcType) {
1625
+ throw new Error(`Rpc ${rpcId} declared by extension ${extension.id} is not a node rpc`);
1626
+ }
1627
+ if (!rpc.url || rpc.url.startsWith('/') || /^[A-Za-z][A-Za-z\d+.-]*:/.test(rpc.url)) {
1628
+ throw new Error(`Node rpc ${rpcId} declared by extension ${extension.id} must use a relative url`);
1629
+ }
1630
+ return rpc;
1631
+ };
1632
+ const getNodeRpcInfo = async (extensionId, rpcId) => {
1633
+ const extension = get$4(extensionId);
1634
+ if (!extension) {
1635
+ throw new Error(`Extension ${extensionId} has no declared rpcs`);
1636
+ }
1637
+ const rpc = getDeclaredNodeRpc(extension, rpcId);
1638
+ const extensionRoot = await getExtensionRoot(extension);
1639
+ return {
1640
+ name: rpc.name || '',
1641
+ path: joinPath(extensionRoot, rpc.url)
1642
+ };
1643
+ };
1644
+
1645
+ const createExtensionCommandMap = extensionId => {
1646
+ return {
1647
+ ...commandMapRef,
1648
+ 'Extensions.getNodeRpcInfo'(rpcId) {
1649
+ return getNodeRpcInfo(extensionId, rpcId);
1650
+ }
1651
+ };
1652
+ };
1653
+
1581
1654
  const rpcs$1 = Object.create(null);
1582
1655
  const get$3 = extensionId => {
1583
1656
  return rpcs$1[extensionId];
@@ -1597,23 +1670,40 @@ const invokeAndTransfer = (method, ...params) => {
1597
1670
  return invokeAndTransfer$1(method, ...params);
1598
1671
  };
1599
1672
 
1673
+ const pendingRpcs = Object.create(null);
1600
1674
  const createIsolatedExtensionHostWorker = async (extensionId, absolutePath, workerName, createRpc, invokeAndTransfer) => {
1601
1675
  return createRpc({
1602
- commandMap: commandMapRef,
1676
+ commandMap: createExtensionCommandMap(extensionId),
1603
1677
  isMessagePortOpen: true,
1604
1678
  send(port) {
1605
1679
  return invokeAndTransfer('LaunchIsolatedExtensionHostWorker.launchIsolatedExtensionHostWorker', port, extensionId, absolutePath, workerName);
1606
1680
  }
1607
1681
  });
1608
1682
  };
1609
- const getOrCreateIsolatedExtensionHostWorker = async (extensionId, absolutePath, workerName = '') => {
1683
+ const createWorker = (extensionId, absolutePath, workerName) => {
1684
+ return createIsolatedExtensionHostWorker(extensionId, absolutePath, workerName, create$7, invokeAndTransfer);
1685
+ };
1686
+ const createAndStoreRpc = async (extensionId, absolutePath, workerName, create) => {
1687
+ const rpc = await create(extensionId, absolutePath, workerName);
1688
+ set$2(extensionId, rpc);
1689
+ return rpc;
1690
+ };
1691
+ const getOrCreateIsolatedExtensionHostWorker = async (extensionId, absolutePath, workerName = '', create = createWorker) => {
1610
1692
  const existingRpc = get$3(extensionId);
1611
1693
  if (existingRpc) {
1612
1694
  return existingRpc;
1613
1695
  }
1614
- const rpc = await createIsolatedExtensionHostWorker(extensionId, absolutePath, workerName, create$7, invokeAndTransfer);
1615
- set$2(extensionId, rpc);
1616
- return rpc;
1696
+ const pendingRpc = pendingRpcs[extensionId];
1697
+ if (pendingRpc !== undefined) {
1698
+ return pendingRpc;
1699
+ }
1700
+ const newRpc = createAndStoreRpc(extensionId, absolutePath, workerName, create);
1701
+ pendingRpcs[extensionId] = newRpc;
1702
+ try {
1703
+ return await newRpc;
1704
+ } finally {
1705
+ delete pendingRpcs[extensionId];
1706
+ }
1617
1707
  };
1618
1708
 
1619
1709
  const activateIsolatedExtension = async (extensionId, absolutePath, workerName, activationEvent, getOrCreate = getOrCreateIsolatedExtensionHostWorker) => {
@@ -1672,8 +1762,19 @@ const handleRpcInfos = (extension, platform) => {
1672
1762
  if (!Array.isArray(rpcs)) {
1673
1763
  return;
1674
1764
  }
1765
+ if (typeof extension.id === 'string') {
1766
+ set$3({
1767
+ ...extension,
1768
+ rpc: rpcs.map(rpc => ({
1769
+ ...rpc
1770
+ }))
1771
+ });
1772
+ }
1675
1773
  const urlPrefix = getUrlPrefix(platform, extension.path);
1676
1774
  for (const rpc of rpcs) {
1775
+ if (rpc.type === 'node') {
1776
+ continue;
1777
+ }
1677
1778
  rpc.url = `${urlPrefix}/${rpc.url}`;
1678
1779
  add(rpc.id, rpc);
1679
1780
  }
@@ -1969,7 +2070,7 @@ const getAllExtensionsWithState = async (extensionsState, assetDir, platform) =>
1969
2070
  };
1970
2071
 
1971
2072
  const getAllExtensions = async (assetDir, platform) => {
1972
- return getAllExtensionsWithState(get$4(), assetDir, platform);
2073
+ return getAllExtensionsWithState(get$5(), assetDir, platform);
1973
2074
  };
1974
2075
 
1975
2076
  const activatingExtensions = Object.create(null);
@@ -2175,13 +2276,13 @@ const disabledExtensionsCacheKey = '/cache/disabledExtensions.json';
2175
2276
  const disableExtension2$1 = async (id, platform) => {
2176
2277
  const isTest = platform === Test;
2177
2278
  const isWeb = platform === Web;
2178
- const oldState = get$4(); // TODO maybe pass in an application id? Would allow multiple editors with different extensions.
2279
+ const oldState = get$5(); // TODO maybe pass in an application id? Would allow multiple editors with different extensions.
2179
2280
  if (isTest) {
2180
2281
  const newState = {
2181
2282
  ...oldState,
2182
2283
  disabledIds: [...oldState.disabledIds, id]
2183
2284
  };
2184
- set$3(newState);
2285
+ set$4(newState);
2185
2286
  } else if (isWeb) {
2186
2287
  const cached = await getJson(disabledExtensionsCacheKey);
2187
2288
  const oldDisabled = cached?.disabledExtensions || [];
@@ -2197,13 +2298,13 @@ const disableExtension2$1 = async (id, platform) => {
2197
2298
  const enableExtension2$1 = async (id, platform) => {
2198
2299
  const isTest = platform === Test;
2199
2300
  const isWeb = platform === Web;
2200
- const oldState = get$4();
2301
+ const oldState = get$5();
2201
2302
  if (isTest) {
2202
2303
  const newState = {
2203
2304
  ...oldState,
2204
2305
  disabledIds: oldState.disabledIds.filter(existing => existing !== id)
2205
2306
  };
2206
- set$3(newState);
2307
+ set$4(newState);
2207
2308
  } else if (isWeb) {
2208
2309
  const cached = await getJson(disabledExtensionsCacheKey);
2209
2310
  const oldDisabled = cached?.disabledExtensions || [];
@@ -2228,7 +2329,7 @@ const disableExtension2 = async (id, platform) => {
2228
2329
  };
2229
2330
 
2230
2331
  const disableExtension = async (id, isTest) => {
2231
- const oldState = get$4();
2332
+ const oldState = get$5();
2232
2333
  return disableExtension2(id, oldState.platform);
2233
2334
  };
2234
2335
 
@@ -2262,7 +2363,7 @@ const enableExtension2 = async (id, platform) => {
2262
2363
  };
2263
2364
 
2264
2365
  const enableExtension = async (id, isTest) => {
2265
- const oldState = get$4();
2366
+ const oldState = get$5();
2266
2367
  return enableExtension2(id, oldState.platform);
2267
2368
  };
2268
2369
 
@@ -3079,7 +3180,7 @@ const getColorThemeNames = async (assetDir, platform) => {
3079
3180
  };
3080
3181
 
3081
3182
  const getDynamicWebExtensions = () => {
3082
- return get$4().webExtensions;
3183
+ return get$5().webExtensions;
3083
3184
  };
3084
3185
 
3085
3186
  const getExtension = async (id, assetDir, platform) => {
@@ -3216,7 +3317,7 @@ const getRunningExtensions = async (assetDir, platform) => {
3216
3317
  const extensions = await getAllExtensions(assetDir, platform);
3217
3318
  const {
3218
3319
  runtimeStatuses
3219
- } = get$4();
3320
+ } = get$5();
3220
3321
  return getRunningExtensionsFromState(extensions, runtimeStatuses);
3221
3322
  };
3222
3323
 
@@ -3405,7 +3506,7 @@ const getRpc = async platform => {
3405
3506
  const initializeSharedProcess = async platform => {
3406
3507
  const rpc = await getRpc(platform);
3407
3508
  if (rpc) {
3408
- set$4(rpc);
3509
+ set$5(rpc);
3409
3510
  }
3410
3511
  };
3411
3512
 
@@ -3505,7 +3606,7 @@ const uninstallExtension = async () => {
3505
3606
 
3506
3607
  const wrapCommand = command => {
3507
3608
  return (...args) => {
3508
- return command(get$4(), ...args);
3609
+ return command(get$5(), ...args);
3509
3610
  };
3510
3611
  };
3511
3612
  const commandMap = {
@@ -3583,7 +3684,7 @@ const initializeAuthWorker = async () => {
3583
3684
  await sendMessagePortToAuthWorker(port, 0);
3584
3685
  }
3585
3686
  });
3586
- set$9(rpc);
3687
+ set$a(rpc);
3587
3688
  };
3588
3689
 
3589
3690
  const initializeErrorWorker = async () => {
@@ -3593,7 +3694,7 @@ const initializeErrorWorker = async () => {
3593
3694
  await sendMessagePortToErrorWorker(port, 0);
3594
3695
  }
3595
3696
  });
3596
- set$8(rpc);
3697
+ set$9(rpc);
3597
3698
  };
3598
3699
 
3599
3700
  const initializeExtensionHostWorker = async () => {
@@ -3603,7 +3704,7 @@ const initializeExtensionHostWorker = async () => {
3603
3704
  await sendMessagePortToExtensionHostWorker(port, 0);
3604
3705
  }
3605
3706
  });
3606
- set$7(rpc);
3707
+ set$8(rpc);
3607
3708
  };
3608
3709
 
3609
3710
  const initializeFileSystemWorker = async () => {
@@ -3613,7 +3714,7 @@ const initializeFileSystemWorker = async () => {
3613
3714
  await sendMessagePortToFileSystemWorker$1(port, 0);
3614
3715
  }
3615
3716
  });
3616
- set$6(rpc);
3717
+ set$7(rpc);
3617
3718
  };
3618
3719
 
3619
3720
  const initializeIframeWorker = async () => {
@@ -3630,7 +3731,7 @@ const initializeRendererWorker = async () => {
3630
3731
  const rpc = await create$2({
3631
3732
  commandMap: commandMap
3632
3733
  });
3633
- set$5(rpc);
3734
+ set$6(rpc);
3634
3735
  };
3635
3736
 
3636
3737
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-management-worker",
3
- "version": "4.30.3",
3
+ "version": "4.31.0",
4
4
  "description": "Webworker for the Extension Management functionality in Lvce Editor.",
5
5
  "keywords": [
6
6
  "web-worker"