@lvce-editor/extension-host-worker 4.6.0 → 4.7.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.
@@ -614,7 +614,7 @@ const create$a = ({
614
614
  };
615
615
 
616
616
  const Array$1 = 'array';
617
- const Boolean = 'boolean';
617
+ const Boolean$1 = 'boolean';
618
618
  const Number = 'number';
619
619
  const Object$1 = 'object';
620
620
  const String$1 = 'string';
@@ -626,7 +626,7 @@ const {
626
626
  } = create$a({
627
627
  name: 'BraceCompletion',
628
628
  resultShape: {
629
- type: Boolean
629
+ type: Boolean$1
630
630
  }
631
631
  });
632
632
 
@@ -1068,7 +1068,9 @@ const getPosition = (textDocument, offset) => {
1068
1068
  let index = 0;
1069
1069
  let rowIndex = 0;
1070
1070
  let newLineIndex = 0;
1071
- const text = textDocument.text;
1071
+ const {
1072
+ text
1073
+ } = textDocument;
1072
1074
  while (index < offset) {
1073
1075
  newLineIndex = text.indexOf('\n', index);
1074
1076
  if (newLineIndex === -1) {
@@ -2713,7 +2715,7 @@ const {
2713
2715
  }
2714
2716
  });
2715
2717
 
2716
- const RE_PROTOCOL = /^([a-z\-]+):\/\//;
2718
+ const RE_PROTOCOL = /^([a-z-]+):\/\//;
2717
2719
  const getProtocol = uri => {
2718
2720
  const protocolMatch = uri.match(RE_PROTOCOL);
2719
2721
  if (protocolMatch) {
@@ -3073,7 +3075,7 @@ const setup = ({
3073
3075
  setStackTraceLimit(errorConstructor, 20);
3074
3076
  global.onerror ||= handleUnhandledError;
3075
3077
  global.onunhandledrejection ||= handleUnhandledRejection;
3076
- if ('SecurityPolicyViolationEvent' in self) {
3078
+ if ('SecurityPolicyViolationEvent' in globalThis) {
3077
3079
  global.addEventListener('securitypolicyviolation', handleContentSecurityPolicyViolation);
3078
3080
  }
3079
3081
  // @ts-ignore
@@ -3197,7 +3199,9 @@ const createColorThemeFromJson = (colorThemeId, colorThemeJson) => {
3197
3199
  warn(`color theme json for "${colorThemeId}" cannot be converted to css, it must be of type object but was of type array`);
3198
3200
  return '';
3199
3201
  }
3200
- const colors = colorThemeJson.colors;
3202
+ const {
3203
+ colors
3204
+ } = colorThemeJson;
3201
3205
  if (!colors) {
3202
3206
  return '';
3203
3207
  }
@@ -3849,7 +3853,7 @@ const create$1 = () => {
3849
3853
  return ++state$3.id;
3850
3854
  };
3851
3855
 
3852
- const commandMap$1 = {
3856
+ const iframeWorkerCommandMap = {
3853
3857
  'WebView.compatExtensionHostWorkerInvoke': (...args) => invoke$2('WebView.compatExtensionHostWorkerInvoke', ...args),
3854
3858
  'WebView.compatExtensionHostWorkerInvokeAndTransfer': (...args) => invokeAndTransfer$1('WebView.compatExtensionHostWorkerInvokeAndTransfer', ...args),
3855
3859
  'WebView.compatRendererProcessInvoke': (...args) => invoke$2('WebView.compatRendererProcessInvoke', ...args),
@@ -3866,6 +3870,7 @@ const commandMap$1 = {
3866
3870
  'ExtensionHostManagement.activateByEvent': (...args) => invoke$2('ExtensionHostManagement.activateByEvent', ...args),
3867
3871
  'WebView.getRemoteUrl': options => getRemoteUrlForWebView(options.uri, options)
3868
3872
  };
3873
+
3869
3874
  const launchIframeWorker = async () => {
3870
3875
  const configuredWorkerUrl = await getConfiguredIframeWorkerUrl();
3871
3876
  const name = 'Iframe Worker';
@@ -3875,7 +3880,7 @@ const launchIframeWorker = async () => {
3875
3880
  name,
3876
3881
  url: configuredWorkerUrl,
3877
3882
  id,
3878
- commandMap: commandMap$1
3883
+ commandMap: iframeWorkerCommandMap
3879
3884
  });
3880
3885
  return rpc;
3881
3886
  };
@@ -3887,6 +3892,9 @@ const ensureWorker = () => {
3887
3892
  }
3888
3893
  return workerPromise;
3889
3894
  };
3895
+ const isActive = () => {
3896
+ return Boolean(workerPromise);
3897
+ };
3890
3898
  const invoke = async (method, ...params) => {
3891
3899
  const rpc = await ensureWorker();
3892
3900
  return rpc.invoke(method, ...params);
@@ -4034,13 +4042,9 @@ class ContentSecurityPolicyError extends Error {
4034
4042
  constructor(violatedDirective, sourceFile, lineNumber, columnNumber) {
4035
4043
  super(`Content Security Policy Violation: ${violatedDirective}`);
4036
4044
  this.name = 'ContentSecurityPolicyError';
4037
- if (sourceFile) {
4038
- this.stack = `Content Security Policy Violation
4039
- at ${sourceFile}:${lineNumber}:${columnNumber}`;
4040
- } else {
4041
- this.stack = `Content Security Policy Violation
4045
+ this.stack = sourceFile ? `Content Security Policy Violation
4046
+ at ${sourceFile}:${lineNumber}:${columnNumber}` : `Content Security Policy Violation
4042
4047
  at <unknown>`;
4043
- }
4044
4048
  }
4045
4049
  }
4046
4050
 
@@ -4061,15 +4065,17 @@ const isImportError = error => {
4061
4065
  };
4062
4066
 
4063
4067
  const sleep = duration => {
4064
- const promiseCallback = (resolve, reject) => {
4065
- setTimeout(resolve, duration);
4066
- };
4067
- return new Promise(promiseCallback);
4068
+ const {
4069
+ resolve,
4070
+ promise
4071
+ } = Promise.withResolvers();
4072
+ setTimeout(resolve, duration);
4073
+ return promise;
4068
4074
  };
4069
4075
 
4070
4076
  const NotFound = 404;
4071
4077
 
4072
- const RE_LINE_COLUMN = /(.*)(?:\(\d+\:\d+\))/;
4078
+ const RE_LINE_COLUMN = /(.*)(?:\(\d+:\d+\))/;
4073
4079
  const getBabelErrorMessage = message => {
4074
4080
  const match = message.match(RE_LINE_COLUMN);
4075
4081
  if (match) {
@@ -4083,7 +4089,9 @@ class BabelParseError extends SyntaxError {
4083
4089
  super(message);
4084
4090
  this.name = 'BabelParseError';
4085
4091
  // @ts-ignore
4086
- const line = error.loc.line;
4092
+ const {
4093
+ line
4094
+ } = error.loc;
4087
4095
  // @ts-ignore
4088
4096
  const column = error.loc.column + 1;
4089
4097
  this.stack = `${message}
@@ -4201,8 +4209,12 @@ const getBabelAstDependencies = (code, ast) => {
4201
4209
  for (const node of body) {
4202
4210
  if (node.type === ImportDeclaration || node.type === ExportAllDeclaration) {
4203
4211
  const relativePath = node.source.extra.rawValue;
4204
- const start = node.source.start;
4205
- const end = node.source.end;
4212
+ const {
4213
+ start
4214
+ } = node.source;
4215
+ const {
4216
+ end
4217
+ } = node.source;
4206
4218
  // @ts-ignore
4207
4219
  dependencies.push({
4208
4220
  relativePath,
@@ -4212,8 +4224,12 @@ const getBabelAstDependencies = (code, ast) => {
4212
4224
  });
4213
4225
  } else if (node.type === VariableDeclaration && node.declarations && node.declarations[0] && node.declarations[0].type === VariableDeclarator && node.declarations[0].init && node.declarations[0].init.type === AwaitExpression && node.declarations[0].init.argument && node.declarations[0].init.argument.type === CallExpression && node.declarations[0].init.argument.callee && node.declarations[0].init.argument.callee.type === Import && node.declarations[0].init.argument.arguments && node.declarations[0].init.argument.arguments[0] && node.declarations[0].init.argument.arguments[0].type === StringLiteral) {
4214
4226
  const relativePath = node.declarations[0].init.argument.arguments[0].extra.rawValue;
4215
- const start = node.declarations[0].init.argument.arguments[0].start;
4216
- const end = node.declarations[0].init.argument.arguments[0].end;
4227
+ const {
4228
+ start
4229
+ } = node.declarations[0].init.argument.arguments[0];
4230
+ const {
4231
+ end
4232
+ } = node.declarations[0].init.argument.arguments[0];
4217
4233
  // @ts-ignore
4218
4234
  dependencies.push({
4219
4235
  relativePath,
@@ -4226,8 +4242,12 @@ const getBabelAstDependencies = (code, ast) => {
4226
4242
  const visitor = node => {
4227
4243
  if (node && node.type === CallExpression && node.callee && node.callee.type === Import && node.arguments && node.arguments[0] && node.arguments[0].type === StringLiteral) {
4228
4244
  const relativePath = node.arguments[0].extra.rawValue;
4229
- const start = node.arguments[0].start;
4230
- const end = node.arguments[0].end;
4245
+ const {
4246
+ start
4247
+ } = node.arguments[0];
4248
+ const {
4249
+ end
4250
+ } = node.arguments[0];
4231
4251
  // @ts-ignore
4232
4252
  dependencies.push({
4233
4253
  relativePath,
@@ -4301,7 +4321,7 @@ const tryToGetActualErrorMessage = async (error, url, response, seenUrls = []) =
4301
4321
  let text;
4302
4322
  try {
4303
4323
  text = await response.text();
4304
- } catch (error) {
4324
+ } catch {
4305
4325
  return `Failed to import ${url}: Unknown Network Error`;
4306
4326
  }
4307
4327
  let ast;
@@ -4743,6 +4763,16 @@ const getColorThemeNames = async () => {
4743
4763
  return colorThemeNames;
4744
4764
  };
4745
4765
 
4766
+ const getExtension = async id => {
4767
+ const allExtensions = await getExtensions();
4768
+ for (const extension of allExtensions) {
4769
+ if (extension.id === id) {
4770
+ return extension;
4771
+ }
4772
+ }
4773
+ return undefined;
4774
+ };
4775
+
4746
4776
  const findMatchingIconThemeExtension = (extensions, iconThemeId) => {
4747
4777
  for (const extension of extensions) {
4748
4778
  if (extension && extension.iconThemes) {
@@ -4819,7 +4849,9 @@ const getWebViewsFromExtensions = extensions => {
4819
4849
  for (const extension of extensions) {
4820
4850
  if (extension && extension.webViews) {
4821
4851
  for (const webView of extension.webViews) {
4822
- let path = extension.path;
4852
+ let {
4853
+ path
4854
+ } = extension;
4823
4855
  if (webView && webView.path) {
4824
4856
  path = `${extension.path}/${webView.path}`;
4825
4857
  }
@@ -5069,9 +5101,12 @@ const serializeWebViews = async webViews => {
5069
5101
  }
5070
5102
  return serialized;
5071
5103
  };
5072
- const getAdditional = () => {
5104
+ const getAdditional = async () => {
5105
+ if (!isActive()) {
5106
+ return [];
5107
+ }
5073
5108
  try {
5074
- return invoke('WebView.saveState');
5109
+ return await invoke('WebView.saveState');
5075
5110
  } catch {
5076
5111
  return [];
5077
5112
  }
@@ -5402,6 +5437,7 @@ const commandMap = {
5402
5437
  'ExtensionHostRename.executeprepareRenameProvider': executeprepareRenameProvider,
5403
5438
  'ExtensionHostRename.executeRenameProvider': executeRenameProvider,
5404
5439
  'Extensions.getExtensions': getExtensions,
5440
+ 'Extensions.getExtension': getExtension,
5405
5441
  'Extensions.addWebExtension': addWebExtension,
5406
5442
  'FileSystemFetch.chmod': chmod$1,
5407
5443
  'FileSystemFetch.getBlob': getBlob$1,
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-host-worker",
3
- "version": "4.6.0",
3
+ "version": "4.7.0",
4
4
  "description": "Webworker for the extension host functionality in Lvce Editor.",
5
- "main": "dist/extensionHostWorkerMain.js",
6
- "type": "module",
7
5
  "keywords": [
8
6
  "web-worker"
9
7
  ],
8
+ "license": "MIT",
10
9
  "author": "Lvce Editor",
11
- "license": "MIT"
10
+ "type": "module",
11
+ "main": "dist/extensionHostWorkerMain.js"
12
12
  }