@lvce-editor/extension-host-worker 4.5.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.
@@ -89,7 +89,7 @@ const fn = value => {
89
89
  }
90
90
  };
91
91
 
92
- const state$f = {
92
+ const state$e = {
93
93
  /** @type{any[]} */
94
94
  onDidOpenEditorListeners: [],
95
95
  /** @type{any[]} */
@@ -101,19 +101,19 @@ const state$f = {
101
101
  textDocuments: Object.create(null)
102
102
  };
103
103
  const setDocument = (textDocumentId, textDocument) => {
104
- state$f.textDocuments[textDocumentId] = textDocument;
104
+ state$e.textDocuments[textDocumentId] = textDocument;
105
105
  };
106
106
  const getDidOpenListeners = () => {
107
- return state$f.onDidSaveTextDocumentListeners;
107
+ return state$e.onDidSaveTextDocumentListeners;
108
108
  };
109
109
  const getWillChangeListeners = () => {
110
- return state$f.onWillChangeEditorListeners;
110
+ return state$e.onWillChangeEditorListeners;
111
111
  };
112
112
  const getDidChangeListeners = () => {
113
- return state$f.onDidChangeTextDocumentListeners;
113
+ return state$e.onDidChangeTextDocumentListeners;
114
114
  };
115
115
  const getDocument = textDocumentId => {
116
- return state$f.textDocuments[textDocumentId];
116
+ return state$e.textDocuments[textDocumentId];
117
117
  };
118
118
 
119
119
  const getOffset$1 = (textDocument, position) => {
@@ -303,7 +303,7 @@ const syncIncremental = (textDocumentId, changes) => {
303
303
  textDocument.text = before + syntheticChange.inserted + after;
304
304
  runListenersSafe(getDidChangeListeners(), textDocument, syntheticChanges);
305
305
  };
306
- const get$a = textDocumentId => {
306
+ const get$b = textDocumentId => {
307
307
  const textDocument = getDocument(textDocumentId);
308
308
  return textDocument;
309
309
  };
@@ -535,7 +535,7 @@ const registerMethod = ({
535
535
  }) => {
536
536
  context[`execute${name}Provider`] = async function (textDocumentId, ...params) {
537
537
  try {
538
- const textDocument = get$a(textDocumentId);
538
+ const textDocument = get$b(textDocumentId);
539
539
  if (!textDocument) {
540
540
  throw new Error(`textDocument with id ${textDocumentId} not found`);
541
541
  }
@@ -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
 
@@ -670,12 +670,12 @@ const executeOrganizeImports = async uid => {
670
670
  if (!organizeImportsAction) {
671
671
  return [];
672
672
  }
673
- const textDocument = get$a(uid);
673
+ const textDocument = get$b(uid);
674
674
  const edits = await organizeImportsAction.execute(textDocument);
675
675
  return edits;
676
676
  };
677
677
 
678
- const state$e = {
678
+ const state$d = {
679
679
  commands: Object.create(null)
680
680
  };
681
681
  const getCommandDisplay = command => {
@@ -698,10 +698,10 @@ const registerCommand = command => {
698
698
  if (!command.execute) {
699
699
  throw new Error('command is missing execute function');
700
700
  }
701
- if (command.id in state$e.commands) {
701
+ if (command.id in state$d.commands) {
702
702
  throw new Error(`command cannot be registered multiple times`);
703
703
  }
704
- state$e.commands[command.id] = command;
704
+ state$d.commands[command.id] = command;
705
705
  } catch (error) {
706
706
  const commandDisplayId = getCommandDisplay(command);
707
707
  throw new VError(error, `Failed to register command${commandDisplayId}`);
@@ -709,7 +709,7 @@ const registerCommand = command => {
709
709
  };
710
710
  const executeCommand = async (id, ...args) => {
711
711
  try {
712
- const command = state$e.commands[id];
712
+ const command = state$d.commands[id];
713
713
  if (!command) {
714
714
  throw new Error(`command ${id} not found`);
715
715
  }
@@ -748,34 +748,38 @@ const {
748
748
  }]
749
749
  });
750
750
 
751
- const state$d = {
751
+ const state$c = {
752
752
  configuration: Object.create(null)
753
753
  };
754
754
  const getConfiguration = key => {
755
- return state$d.configuration[key] ?? '';
755
+ return state$c.configuration[key] ?? '';
756
756
  };
757
757
  const setConfigurations = preferences => {
758
- state$d.configuration = preferences;
758
+ state$c.configuration = preferences;
759
759
  };
760
760
 
761
- const state$c = {
762
- rpc: undefined
761
+ const RendererWorker = 1;
762
+
763
+ const rpcs$2 = Object.create(null);
764
+ const set$9 = (id, rpc) => {
765
+ rpcs$2[id] = rpc;
766
+ };
767
+ const get$a = id => {
768
+ return rpcs$2[id];
763
769
  };
770
+
764
771
  const invoke$2 = (method, ...params) => {
765
- const rpc = state$c.rpc;
772
+ const rpc = get$a(RendererWorker);
766
773
  return rpc.invoke(method, ...params);
767
774
  };
768
775
  const send$1 = (method, ...params) => {
769
- const rpc = state$c.rpc;
776
+ const rpc = get$a(RendererWorker);
770
777
  return rpc.send(method, ...params);
771
778
  };
772
779
  const invokeAndTransfer$1 = (method, ...params) => {
773
- const rpc = state$c.rpc;
780
+ const rpc = get$a(RendererWorker);
774
781
  return rpc.invokeAndTransfer(method, ...params);
775
782
  };
776
- const setRpc = rpc => {
777
- state$c.rpc = rpc;
778
- };
779
783
 
780
784
  const state$b = {
781
785
  debugProviderMap: Object.create(null)
@@ -1064,7 +1068,9 @@ const getPosition = (textDocument, offset) => {
1064
1068
  let index = 0;
1065
1069
  let rowIndex = 0;
1066
1070
  let newLineIndex = 0;
1067
- const text = textDocument.text;
1071
+ const {
1072
+ text
1073
+ } = textDocument;
1068
1074
  while (index < offset) {
1069
1075
  newLineIndex = text.indexOf('\n', index);
1070
1076
  if (newLineIndex === -1) {
@@ -2709,7 +2715,7 @@ const {
2709
2715
  }
2710
2716
  });
2711
2717
 
2712
- const RE_PROTOCOL = /^([a-z\-]+):\/\//;
2718
+ const RE_PROTOCOL = /^([a-z-]+):\/\//;
2713
2719
  const getProtocol = uri => {
2714
2720
  const protocolMatch = uri.match(RE_PROTOCOL);
2715
2721
  if (protocolMatch) {
@@ -3069,7 +3075,7 @@ const setup = ({
3069
3075
  setStackTraceLimit(errorConstructor, 20);
3070
3076
  global.onerror ||= handleUnhandledError;
3071
3077
  global.onunhandledrejection ||= handleUnhandledRejection;
3072
- if ('SecurityPolicyViolationEvent' in self) {
3078
+ if ('SecurityPolicyViolationEvent' in globalThis) {
3073
3079
  global.addEventListener('securitypolicyviolation', handleContentSecurityPolicyViolation);
3074
3080
  }
3075
3081
  // @ts-ignore
@@ -3193,7 +3199,9 @@ const createColorThemeFromJson = (colorThemeId, colorThemeJson) => {
3193
3199
  warn(`color theme json for "${colorThemeId}" cannot be converted to css, it must be of type object but was of type array`);
3194
3200
  return '';
3195
3201
  }
3196
- const colors = colorThemeJson.colors;
3202
+ const {
3203
+ colors
3204
+ } = colorThemeJson;
3197
3205
  if (!colors) {
3198
3206
  return '';
3199
3207
  }
@@ -3845,7 +3853,7 @@ const create$1 = () => {
3845
3853
  return ++state$3.id;
3846
3854
  };
3847
3855
 
3848
- const commandMap$1 = {
3856
+ const iframeWorkerCommandMap = {
3849
3857
  'WebView.compatExtensionHostWorkerInvoke': (...args) => invoke$2('WebView.compatExtensionHostWorkerInvoke', ...args),
3850
3858
  'WebView.compatExtensionHostWorkerInvokeAndTransfer': (...args) => invokeAndTransfer$1('WebView.compatExtensionHostWorkerInvokeAndTransfer', ...args),
3851
3859
  'WebView.compatRendererProcessInvoke': (...args) => invoke$2('WebView.compatRendererProcessInvoke', ...args),
@@ -3862,6 +3870,7 @@ const commandMap$1 = {
3862
3870
  'ExtensionHostManagement.activateByEvent': (...args) => invoke$2('ExtensionHostManagement.activateByEvent', ...args),
3863
3871
  'WebView.getRemoteUrl': options => getRemoteUrlForWebView(options.uri, options)
3864
3872
  };
3873
+
3865
3874
  const launchIframeWorker = async () => {
3866
3875
  const configuredWorkerUrl = await getConfiguredIframeWorkerUrl();
3867
3876
  const name = 'Iframe Worker';
@@ -3871,7 +3880,7 @@ const launchIframeWorker = async () => {
3871
3880
  name,
3872
3881
  url: configuredWorkerUrl,
3873
3882
  id,
3874
- commandMap: commandMap$1
3883
+ commandMap: iframeWorkerCommandMap
3875
3884
  });
3876
3885
  return rpc;
3877
3886
  };
@@ -3883,6 +3892,9 @@ const ensureWorker = () => {
3883
3892
  }
3884
3893
  return workerPromise;
3885
3894
  };
3895
+ const isActive = () => {
3896
+ return Boolean(workerPromise);
3897
+ };
3886
3898
  const invoke = async (method, ...params) => {
3887
3899
  const rpc = await ensureWorker();
3888
3900
  return rpc.invoke(method, ...params);
@@ -4030,13 +4042,9 @@ class ContentSecurityPolicyError extends Error {
4030
4042
  constructor(violatedDirective, sourceFile, lineNumber, columnNumber) {
4031
4043
  super(`Content Security Policy Violation: ${violatedDirective}`);
4032
4044
  this.name = 'ContentSecurityPolicyError';
4033
- if (sourceFile) {
4034
- this.stack = `Content Security Policy Violation
4035
- at ${sourceFile}:${lineNumber}:${columnNumber}`;
4036
- } else {
4037
- this.stack = `Content Security Policy Violation
4045
+ this.stack = sourceFile ? `Content Security Policy Violation
4046
+ at ${sourceFile}:${lineNumber}:${columnNumber}` : `Content Security Policy Violation
4038
4047
  at <unknown>`;
4039
- }
4040
4048
  }
4041
4049
  }
4042
4050
 
@@ -4057,15 +4065,17 @@ const isImportError = error => {
4057
4065
  };
4058
4066
 
4059
4067
  const sleep = duration => {
4060
- const promiseCallback = (resolve, reject) => {
4061
- setTimeout(resolve, duration);
4062
- };
4063
- return new Promise(promiseCallback);
4068
+ const {
4069
+ resolve,
4070
+ promise
4071
+ } = Promise.withResolvers();
4072
+ setTimeout(resolve, duration);
4073
+ return promise;
4064
4074
  };
4065
4075
 
4066
4076
  const NotFound = 404;
4067
4077
 
4068
- const RE_LINE_COLUMN = /(.*)(?:\(\d+\:\d+\))/;
4078
+ const RE_LINE_COLUMN = /(.*)(?:\(\d+:\d+\))/;
4069
4079
  const getBabelErrorMessage = message => {
4070
4080
  const match = message.match(RE_LINE_COLUMN);
4071
4081
  if (match) {
@@ -4079,7 +4089,9 @@ class BabelParseError extends SyntaxError {
4079
4089
  super(message);
4080
4090
  this.name = 'BabelParseError';
4081
4091
  // @ts-ignore
4082
- const line = error.loc.line;
4092
+ const {
4093
+ line
4094
+ } = error.loc;
4083
4095
  // @ts-ignore
4084
4096
  const column = error.loc.column + 1;
4085
4097
  this.stack = `${message}
@@ -4197,8 +4209,12 @@ const getBabelAstDependencies = (code, ast) => {
4197
4209
  for (const node of body) {
4198
4210
  if (node.type === ImportDeclaration || node.type === ExportAllDeclaration) {
4199
4211
  const relativePath = node.source.extra.rawValue;
4200
- const start = node.source.start;
4201
- const end = node.source.end;
4212
+ const {
4213
+ start
4214
+ } = node.source;
4215
+ const {
4216
+ end
4217
+ } = node.source;
4202
4218
  // @ts-ignore
4203
4219
  dependencies.push({
4204
4220
  relativePath,
@@ -4208,8 +4224,12 @@ const getBabelAstDependencies = (code, ast) => {
4208
4224
  });
4209
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) {
4210
4226
  const relativePath = node.declarations[0].init.argument.arguments[0].extra.rawValue;
4211
- const start = node.declarations[0].init.argument.arguments[0].start;
4212
- 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];
4213
4233
  // @ts-ignore
4214
4234
  dependencies.push({
4215
4235
  relativePath,
@@ -4222,8 +4242,12 @@ const getBabelAstDependencies = (code, ast) => {
4222
4242
  const visitor = node => {
4223
4243
  if (node && node.type === CallExpression && node.callee && node.callee.type === Import && node.arguments && node.arguments[0] && node.arguments[0].type === StringLiteral) {
4224
4244
  const relativePath = node.arguments[0].extra.rawValue;
4225
- const start = node.arguments[0].start;
4226
- const end = node.arguments[0].end;
4245
+ const {
4246
+ start
4247
+ } = node.arguments[0];
4248
+ const {
4249
+ end
4250
+ } = node.arguments[0];
4227
4251
  // @ts-ignore
4228
4252
  dependencies.push({
4229
4253
  relativePath,
@@ -4297,7 +4321,7 @@ const tryToGetActualErrorMessage = async (error, url, response, seenUrls = []) =
4297
4321
  let text;
4298
4322
  try {
4299
4323
  text = await response.text();
4300
- } catch (error) {
4324
+ } catch {
4301
4325
  return `Failed to import ${url}: Unknown Network Error`;
4302
4326
  }
4303
4327
  let ast;
@@ -4739,6 +4763,16 @@ const getColorThemeNames = async () => {
4739
4763
  return colorThemeNames;
4740
4764
  };
4741
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
+
4742
4776
  const findMatchingIconThemeExtension = (extensions, iconThemeId) => {
4743
4777
  for (const extension of extensions) {
4744
4778
  if (extension && extension.iconThemes) {
@@ -4815,7 +4849,9 @@ const getWebViewsFromExtensions = extensions => {
4815
4849
  for (const extension of extensions) {
4816
4850
  if (extension && extension.webViews) {
4817
4851
  for (const webView of extension.webViews) {
4818
- let path = extension.path;
4852
+ let {
4853
+ path
4854
+ } = extension;
4819
4855
  if (webView && webView.path) {
4820
4856
  path = `${extension.path}/${webView.path}`;
4821
4857
  }
@@ -5065,9 +5101,12 @@ const serializeWebViews = async webViews => {
5065
5101
  }
5066
5102
  return serialized;
5067
5103
  };
5068
- const getAdditional = () => {
5104
+ const getAdditional = async () => {
5105
+ if (!isActive()) {
5106
+ return [];
5107
+ }
5069
5108
  try {
5070
- return invoke('WebView.saveState');
5109
+ return await invoke('WebView.saveState');
5071
5110
  } catch {
5072
5111
  return [];
5073
5112
  }
@@ -5398,6 +5437,7 @@ const commandMap = {
5398
5437
  'ExtensionHostRename.executeprepareRenameProvider': executeprepareRenameProvider,
5399
5438
  'ExtensionHostRename.executeRenameProvider': executeRenameProvider,
5400
5439
  'Extensions.getExtensions': getExtensions,
5440
+ 'Extensions.getExtension': getExtension,
5401
5441
  'Extensions.addWebExtension': addWebExtension,
5402
5442
  'FileSystemFetch.chmod': chmod$1,
5403
5443
  'FileSystemFetch.getBlob': getBlob$1,
@@ -5498,7 +5538,7 @@ const listen = async () => {
5498
5538
  const rpc = await WebWorkerRpcClient.create({
5499
5539
  commandMap: commandMap
5500
5540
  });
5501
- setRpc(rpc);
5541
+ set$9(RendererWorker, rpc);
5502
5542
  };
5503
5543
 
5504
5544
  const main = async () => {
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-host-worker",
3
- "version": "4.5.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
  }