@lvce-editor/extension-management-worker 4.40.0 → 4.41.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.
|
@@ -1,58 +1,3 @@
|
|
|
1
|
-
class AssertionError extends Error {
|
|
2
|
-
constructor(message) {
|
|
3
|
-
super(message);
|
|
4
|
-
this.name = 'AssertionError';
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
const Object$1 = 1;
|
|
8
|
-
const Number = 2;
|
|
9
|
-
const Array$1 = 3;
|
|
10
|
-
const String$1 = 4;
|
|
11
|
-
const Boolean$1 = 5;
|
|
12
|
-
const Function = 6;
|
|
13
|
-
const Null = 7;
|
|
14
|
-
const Unknown = 8;
|
|
15
|
-
const getType = value => {
|
|
16
|
-
switch (typeof value) {
|
|
17
|
-
case 'number':
|
|
18
|
-
return Number;
|
|
19
|
-
case 'function':
|
|
20
|
-
return Function;
|
|
21
|
-
case 'string':
|
|
22
|
-
return String$1;
|
|
23
|
-
case 'object':
|
|
24
|
-
if (value === null) {
|
|
25
|
-
return Null;
|
|
26
|
-
}
|
|
27
|
-
if (Array.isArray(value)) {
|
|
28
|
-
return Array$1;
|
|
29
|
-
}
|
|
30
|
-
return Object$1;
|
|
31
|
-
case 'boolean':
|
|
32
|
-
return Boolean$1;
|
|
33
|
-
default:
|
|
34
|
-
return Unknown;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
const object = value => {
|
|
38
|
-
const type = getType(value);
|
|
39
|
-
if (type !== Object$1) {
|
|
40
|
-
throw new AssertionError('expected value to be of type object');
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
const number = value => {
|
|
44
|
-
const type = getType(value);
|
|
45
|
-
if (type !== Number) {
|
|
46
|
-
throw new AssertionError('expected value to be of type number');
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
const string = value => {
|
|
50
|
-
const type = getType(value);
|
|
51
|
-
if (type !== String$1) {
|
|
52
|
-
throw new AssertionError('expected value to be of type string');
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
1
|
const normalizeLine = line => {
|
|
57
2
|
if (line.startsWith('Error: ')) {
|
|
58
3
|
return line.slice('Error: '.length);
|
|
@@ -109,6 +54,61 @@ class VError extends Error {
|
|
|
109
54
|
}
|
|
110
55
|
}
|
|
111
56
|
|
|
57
|
+
class AssertionError extends Error {
|
|
58
|
+
constructor(message) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.name = 'AssertionError';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const Object$1 = 1;
|
|
64
|
+
const Number = 2;
|
|
65
|
+
const Array$1 = 3;
|
|
66
|
+
const String$1 = 4;
|
|
67
|
+
const Boolean$1 = 5;
|
|
68
|
+
const Function = 6;
|
|
69
|
+
const Null = 7;
|
|
70
|
+
const Unknown = 8;
|
|
71
|
+
const getType = value => {
|
|
72
|
+
switch (typeof value) {
|
|
73
|
+
case 'number':
|
|
74
|
+
return Number;
|
|
75
|
+
case 'function':
|
|
76
|
+
return Function;
|
|
77
|
+
case 'string':
|
|
78
|
+
return String$1;
|
|
79
|
+
case 'object':
|
|
80
|
+
if (value === null) {
|
|
81
|
+
return Null;
|
|
82
|
+
}
|
|
83
|
+
if (Array.isArray(value)) {
|
|
84
|
+
return Array$1;
|
|
85
|
+
}
|
|
86
|
+
return Object$1;
|
|
87
|
+
case 'boolean':
|
|
88
|
+
return Boolean$1;
|
|
89
|
+
default:
|
|
90
|
+
return Unknown;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const object = value => {
|
|
94
|
+
const type = getType(value);
|
|
95
|
+
if (type !== Object$1) {
|
|
96
|
+
throw new AssertionError('expected value to be of type object');
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const number = value => {
|
|
100
|
+
const type = getType(value);
|
|
101
|
+
if (type !== Number) {
|
|
102
|
+
throw new AssertionError('expected value to be of type number');
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const string = value => {
|
|
106
|
+
const type = getType(value);
|
|
107
|
+
if (type !== String$1) {
|
|
108
|
+
throw new AssertionError('expected value to be of type string');
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
112
|
const isMessagePort = value => {
|
|
113
113
|
return value && value instanceof MessagePort;
|
|
114
114
|
};
|
|
@@ -1438,6 +1438,7 @@ const Importing = 1;
|
|
|
1438
1438
|
const Activating = 2;
|
|
1439
1439
|
const Activated = 3;
|
|
1440
1440
|
const Error$1 = 4;
|
|
1441
|
+
const Terminated = 5;
|
|
1441
1442
|
|
|
1442
1443
|
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
|
|
1443
1444
|
|
|
@@ -1534,6 +1535,13 @@ const resetExtensionRuntimeState = extensionId => {
|
|
|
1534
1535
|
});
|
|
1535
1536
|
};
|
|
1536
1537
|
|
|
1538
|
+
const getErrorMessage = error => {
|
|
1539
|
+
if (error instanceof Error) {
|
|
1540
|
+
return error.message;
|
|
1541
|
+
}
|
|
1542
|
+
return String(error);
|
|
1543
|
+
};
|
|
1544
|
+
|
|
1537
1545
|
const baseName = path => {
|
|
1538
1546
|
const slashIndex = path.lastIndexOf('/');
|
|
1539
1547
|
return path.slice(slashIndex + 1);
|
|
@@ -1627,16 +1635,21 @@ const activateExtension2 = async (extensionId, extension, absolutePath, extensio
|
|
|
1627
1635
|
});
|
|
1628
1636
|
} catch (error) {
|
|
1629
1637
|
const id = getExtensionId$4(extension);
|
|
1638
|
+
let activationError = error;
|
|
1630
1639
|
if (isImportError(error)) {
|
|
1631
1640
|
const actualErrorMessage = await tryToGetActualImportErrorMessage(absolutePath, error);
|
|
1632
|
-
|
|
1641
|
+
activationError = new Error(`Failed to activate extension ${id}: ${actualErrorMessage}`, {
|
|
1633
1642
|
cause: error
|
|
1634
1643
|
});
|
|
1635
1644
|
}
|
|
1636
1645
|
updateRuntimeStatus(extensionId, {
|
|
1637
|
-
|
|
1646
|
+
error: getErrorMessage(activationError),
|
|
1647
|
+
status: Error$1
|
|
1638
1648
|
});
|
|
1639
|
-
|
|
1649
|
+
if (activationError !== error) {
|
|
1650
|
+
throw activationError;
|
|
1651
|
+
}
|
|
1652
|
+
throw new VError(activationError, `Failed to activate extension ${id}`);
|
|
1640
1653
|
} finally {
|
|
1641
1654
|
cancel(token);
|
|
1642
1655
|
}
|
|
@@ -1821,6 +1834,7 @@ const activateIsolatedExtension = async (extensionId, absolutePath, workerName,
|
|
|
1821
1834
|
});
|
|
1822
1835
|
} catch (error) {
|
|
1823
1836
|
updateRuntimeStatus(extensionId, {
|
|
1837
|
+
error: getErrorMessage(error),
|
|
1824
1838
|
status: Error$1
|
|
1825
1839
|
});
|
|
1826
1840
|
throw error;
|
|
@@ -1915,16 +1929,18 @@ const importExtension = async (extensionId, absolutePath, activationEvent, exten
|
|
|
1915
1929
|
importTime: time
|
|
1916
1930
|
});
|
|
1917
1931
|
} catch (error) {
|
|
1918
|
-
|
|
1919
|
-
status: Error$1 // TODO maybe store error also in runtime status state
|
|
1920
|
-
});
|
|
1932
|
+
let importError = error;
|
|
1921
1933
|
if (isImportError(error)) {
|
|
1922
1934
|
const actualErrorMessage = await tryToGetActualImportErrorMessage(absolutePath, error);
|
|
1923
|
-
|
|
1935
|
+
importError = new Error(actualErrorMessage, {
|
|
1924
1936
|
cause: error
|
|
1925
1937
|
});
|
|
1926
1938
|
}
|
|
1927
|
-
|
|
1939
|
+
updateRuntimeStatus(extensionId, {
|
|
1940
|
+
error: getErrorMessage(importError),
|
|
1941
|
+
status: Error$1
|
|
1942
|
+
});
|
|
1943
|
+
throw importError;
|
|
1928
1944
|
}
|
|
1929
1945
|
} catch (error) {
|
|
1930
1946
|
throw new VError(error, `Failed to import extension ${extensionId}`);
|
|
@@ -2289,6 +2305,7 @@ const doActivateExtension = async (extension, absolutePath, event, platform) =>
|
|
|
2289
2305
|
try {
|
|
2290
2306
|
await activateExtension3(extension, absolutePath, event, platform);
|
|
2291
2307
|
runningExtensions[extensionId] = true;
|
|
2308
|
+
await invoke$2('Layout.handleExtensionsChanged');
|
|
2292
2309
|
} finally {
|
|
2293
2310
|
delete activatingExtensions[extensionId];
|
|
2294
2311
|
}
|
|
@@ -3598,10 +3615,16 @@ const getIcon = (extension, manifestView, assetDir, platform) => {
|
|
|
3598
3615
|
return '';
|
|
3599
3616
|
};
|
|
3600
3617
|
|
|
3618
|
+
const statusNames = {
|
|
3619
|
+
[Activated]: 'running',
|
|
3620
|
+
[Error$1]: 'error',
|
|
3621
|
+
[Terminated]: 'terminated'
|
|
3622
|
+
};
|
|
3601
3623
|
const getRunningExtensionsFromState = (extensions, runtimeStatuses, assetDir, platform) => {
|
|
3602
3624
|
return extensions.flatMap(extension => {
|
|
3603
3625
|
const runtimeStatus = runtimeStatuses[extension.id];
|
|
3604
|
-
|
|
3626
|
+
const status = runtimeStatus && statusNames[runtimeStatus.status];
|
|
3627
|
+
if (!runtimeStatus || !status) {
|
|
3605
3628
|
return [];
|
|
3606
3629
|
}
|
|
3607
3630
|
const manifestIcon = typeof extension.icon === 'string' ? extension.icon.replace(/^\.\//, '') : undefined;
|
|
@@ -3612,19 +3635,51 @@ const getRunningExtensionsFromState = (extensions, runtimeStatuses, assetDir, pl
|
|
|
3612
3635
|
...extension,
|
|
3613
3636
|
activationEvent: runtimeStatus.activationEvent,
|
|
3614
3637
|
activationTime: runtimeStatus.activationTime,
|
|
3638
|
+
error: runtimeStatus.error || '',
|
|
3615
3639
|
...(icon && {
|
|
3616
3640
|
icon
|
|
3617
|
-
})
|
|
3641
|
+
}),
|
|
3642
|
+
status
|
|
3618
3643
|
}];
|
|
3619
3644
|
}).toSorted((a, b) => b.activationTime - a.activationTime);
|
|
3620
3645
|
};
|
|
3621
3646
|
|
|
3647
|
+
const invokePing = async rpc => {
|
|
3648
|
+
try {
|
|
3649
|
+
await rpc.invoke('ExtensionApi.ping');
|
|
3650
|
+
} catch {
|
|
3651
|
+
// Any response proves that the worker is still alive.
|
|
3652
|
+
}
|
|
3653
|
+
return true;
|
|
3654
|
+
};
|
|
3655
|
+
const waitForTimeout = async (timeout, sleep) => {
|
|
3656
|
+
await sleep(timeout);
|
|
3657
|
+
return false;
|
|
3658
|
+
};
|
|
3659
|
+
const isResponsive = async (rpc, timeout, sleep) => {
|
|
3660
|
+
return Promise.race([invokePing(rpc), waitForTimeout(timeout, sleep)]);
|
|
3661
|
+
};
|
|
3662
|
+
const updateTerminatedExtensionStatuses = async (runtimeStatuses, getRpc = get$3, timeout = 250, sleep$1 = sleep) => {
|
|
3663
|
+
const activatedStatuses = Object.values(runtimeStatuses).filter(status => status.status === Activated);
|
|
3664
|
+
await Promise.all(activatedStatuses.map(async status => {
|
|
3665
|
+
const rpc = getRpc(status.id);
|
|
3666
|
+
if (!rpc || (await isResponsive(rpc, timeout, sleep$1))) {
|
|
3667
|
+
return;
|
|
3668
|
+
}
|
|
3669
|
+
updateRuntimeStatus(status.id, {
|
|
3670
|
+
error: 'Extension worker stopped responding',
|
|
3671
|
+
status: Terminated
|
|
3672
|
+
});
|
|
3673
|
+
}));
|
|
3674
|
+
};
|
|
3675
|
+
|
|
3622
3676
|
const getRunningExtensions = async (assetDir, platform) => {
|
|
3623
3677
|
const {
|
|
3624
3678
|
assetDir: resolvedAssetDir,
|
|
3625
3679
|
platform: resolvedPlatform
|
|
3626
3680
|
} = await getRuntimeContext(assetDir, platform);
|
|
3627
3681
|
const extensions = await getAllExtensions(resolvedAssetDir, resolvedPlatform);
|
|
3682
|
+
await updateTerminatedExtensionStatuses(get$5().runtimeStatuses);
|
|
3628
3683
|
const {
|
|
3629
3684
|
runtimeStatuses
|
|
3630
3685
|
} = get$5();
|