@lvce-editor/extension-management-worker 4.30.4 → 4.31.1

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];
@@ -1600,7 +1673,7 @@ const invokeAndTransfer = (method, ...params) => {
1600
1673
  const pendingRpcs = Object.create(null);
1601
1674
  const createIsolatedExtensionHostWorker = async (extensionId, absolutePath, workerName, createRpc, invokeAndTransfer) => {
1602
1675
  return createRpc({
1603
- commandMap: commandMapRef,
1676
+ commandMap: createExtensionCommandMap(extensionId),
1604
1677
  isMessagePortOpen: true,
1605
1678
  send(port) {
1606
1679
  return invokeAndTransfer('LaunchIsolatedExtensionHostWorker.launchIsolatedExtensionHostWorker', port, extensionId, absolutePath, workerName);
@@ -1689,8 +1762,19 @@ const handleRpcInfos = (extension, platform) => {
1689
1762
  if (!Array.isArray(rpcs)) {
1690
1763
  return;
1691
1764
  }
1765
+ if (typeof extension.id === 'string') {
1766
+ set$3({
1767
+ ...extension,
1768
+ rpc: rpcs.map(rpc => ({
1769
+ ...rpc
1770
+ }))
1771
+ });
1772
+ }
1692
1773
  const urlPrefix = getUrlPrefix(platform, extension.path);
1693
1774
  for (const rpc of rpcs) {
1775
+ if (rpc.type === 'node') {
1776
+ continue;
1777
+ }
1694
1778
  rpc.url = `${urlPrefix}/${rpc.url}`;
1695
1779
  add(rpc.id, rpc);
1696
1780
  }
@@ -1986,7 +2070,7 @@ const getAllExtensionsWithState = async (extensionsState, assetDir, platform) =>
1986
2070
  };
1987
2071
 
1988
2072
  const getAllExtensions = async (assetDir, platform) => {
1989
- return getAllExtensionsWithState(get$4(), assetDir, platform);
2073
+ return getAllExtensionsWithState(get$5(), assetDir, platform);
1990
2074
  };
1991
2075
 
1992
2076
  const activatingExtensions = Object.create(null);
@@ -2192,13 +2276,13 @@ const disabledExtensionsCacheKey = '/cache/disabledExtensions.json';
2192
2276
  const disableExtension2$1 = async (id, platform) => {
2193
2277
  const isTest = platform === Test;
2194
2278
  const isWeb = platform === Web;
2195
- 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.
2196
2280
  if (isTest) {
2197
2281
  const newState = {
2198
2282
  ...oldState,
2199
2283
  disabledIds: [...oldState.disabledIds, id]
2200
2284
  };
2201
- set$3(newState);
2285
+ set$4(newState);
2202
2286
  } else if (isWeb) {
2203
2287
  const cached = await getJson(disabledExtensionsCacheKey);
2204
2288
  const oldDisabled = cached?.disabledExtensions || [];
@@ -2214,13 +2298,13 @@ const disableExtension2$1 = async (id, platform) => {
2214
2298
  const enableExtension2$1 = async (id, platform) => {
2215
2299
  const isTest = platform === Test;
2216
2300
  const isWeb = platform === Web;
2217
- const oldState = get$4();
2301
+ const oldState = get$5();
2218
2302
  if (isTest) {
2219
2303
  const newState = {
2220
2304
  ...oldState,
2221
2305
  disabledIds: oldState.disabledIds.filter(existing => existing !== id)
2222
2306
  };
2223
- set$3(newState);
2307
+ set$4(newState);
2224
2308
  } else if (isWeb) {
2225
2309
  const cached = await getJson(disabledExtensionsCacheKey);
2226
2310
  const oldDisabled = cached?.disabledExtensions || [];
@@ -2245,7 +2329,7 @@ const disableExtension2 = async (id, platform) => {
2245
2329
  };
2246
2330
 
2247
2331
  const disableExtension = async (id, isTest) => {
2248
- const oldState = get$4();
2332
+ const oldState = get$5();
2249
2333
  return disableExtension2(id, oldState.platform);
2250
2334
  };
2251
2335
 
@@ -2279,7 +2363,7 @@ const enableExtension2 = async (id, platform) => {
2279
2363
  };
2280
2364
 
2281
2365
  const enableExtension = async (id, isTest) => {
2282
- const oldState = get$4();
2366
+ const oldState = get$5();
2283
2367
  return enableExtension2(id, oldState.platform);
2284
2368
  };
2285
2369
 
@@ -2867,8 +2951,8 @@ const saveViewInstanceState = async (viewId, uid, assetDir, platform) => {
2867
2951
  return rpc.invoke('ExtensionApi.saveViewInstanceState', uid);
2868
2952
  };
2869
2953
 
2870
- const getAccessToken = () => {
2871
- return invoke$6('Auth.getAccessToken');
2954
+ const getAccessToken = (options = {}) => {
2955
+ return invoke$6('Auth.getAccessToken', options);
2872
2956
  };
2873
2957
 
2874
2958
  const transparent = (color, factor) => {
@@ -3096,7 +3180,7 @@ const getColorThemeNames = async (assetDir, platform) => {
3096
3180
  };
3097
3181
 
3098
3182
  const getDynamicWebExtensions = () => {
3099
- return get$4().webExtensions;
3183
+ return get$5().webExtensions;
3100
3184
  };
3101
3185
 
3102
3186
  const getExtension = async (id, assetDir, platform) => {
@@ -3233,7 +3317,7 @@ const getRunningExtensions = async (assetDir, platform) => {
3233
3317
  const extensions = await getAllExtensions(assetDir, platform);
3234
3318
  const {
3235
3319
  runtimeStatuses
3236
- } = get$4();
3320
+ } = get$5();
3237
3321
  return getRunningExtensionsFromState(extensions, runtimeStatuses);
3238
3322
  };
3239
3323
 
@@ -3422,7 +3506,7 @@ const getRpc = async platform => {
3422
3506
  const initializeSharedProcess = async platform => {
3423
3507
  const rpc = await getRpc(platform);
3424
3508
  if (rpc) {
3425
- set$4(rpc);
3509
+ set$5(rpc);
3426
3510
  }
3427
3511
  };
3428
3512
 
@@ -3522,7 +3606,7 @@ const uninstallExtension = async () => {
3522
3606
 
3523
3607
  const wrapCommand = command => {
3524
3608
  return (...args) => {
3525
- return command(get$4(), ...args);
3609
+ return command(get$5(), ...args);
3526
3610
  };
3527
3611
  };
3528
3612
  const commandMap = {
@@ -3600,7 +3684,7 @@ const initializeAuthWorker = async () => {
3600
3684
  await sendMessagePortToAuthWorker(port, 0);
3601
3685
  }
3602
3686
  });
3603
- set$9(rpc);
3687
+ set$a(rpc);
3604
3688
  };
3605
3689
 
3606
3690
  const initializeErrorWorker = async () => {
@@ -3610,7 +3694,7 @@ const initializeErrorWorker = async () => {
3610
3694
  await sendMessagePortToErrorWorker(port, 0);
3611
3695
  }
3612
3696
  });
3613
- set$8(rpc);
3697
+ set$9(rpc);
3614
3698
  };
3615
3699
 
3616
3700
  const initializeExtensionHostWorker = async () => {
@@ -3620,7 +3704,7 @@ const initializeExtensionHostWorker = async () => {
3620
3704
  await sendMessagePortToExtensionHostWorker(port, 0);
3621
3705
  }
3622
3706
  });
3623
- set$7(rpc);
3707
+ set$8(rpc);
3624
3708
  };
3625
3709
 
3626
3710
  const initializeFileSystemWorker = async () => {
@@ -3630,7 +3714,7 @@ const initializeFileSystemWorker = async () => {
3630
3714
  await sendMessagePortToFileSystemWorker$1(port, 0);
3631
3715
  }
3632
3716
  });
3633
- set$6(rpc);
3717
+ set$7(rpc);
3634
3718
  };
3635
3719
 
3636
3720
  const initializeIframeWorker = async () => {
@@ -3647,7 +3731,7 @@ const initializeRendererWorker = async () => {
3647
3731
  const rpc = await create$2({
3648
3732
  commandMap: commandMap
3649
3733
  });
3650
- set$5(rpc);
3734
+ set$6(rpc);
3651
3735
  };
3652
3736
 
3653
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.4",
3
+ "version": "4.31.1",
4
4
  "description": "Webworker for the Extension Management functionality in Lvce Editor.",
5
5
  "keywords": [
6
6
  "web-worker"