@lvce-editor/extension-host-helper-process 0.102.4 → 0.103.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.
package/package.json
CHANGED
|
@@ -1,12 +1,33 @@
|
|
|
1
|
+
import { resolve, sep } from 'node:path'
|
|
1
2
|
import * as Command from '@lvce-editor/command'
|
|
2
3
|
import * as Assert from '../Assert/Assert.js'
|
|
3
4
|
import * as ImportScript from '../ImportScript/ImportScript.js'
|
|
4
5
|
import { VError } from '../VError/VError.js'
|
|
5
6
|
|
|
7
|
+
export const resolveRemoteExtensionPath = (value, extensionsPath = process.env.LVCE_REMOTE_EXTENSIONS_PATH) => {
|
|
8
|
+
if (!extensionsPath) {
|
|
9
|
+
return value
|
|
10
|
+
}
|
|
11
|
+
const normalized = value.replaceAll('\\', '/')
|
|
12
|
+
const marker = '/extensions/'
|
|
13
|
+
const markerIndex = normalized.lastIndexOf(marker)
|
|
14
|
+
if (markerIndex === -1) {
|
|
15
|
+
return value
|
|
16
|
+
}
|
|
17
|
+
const relativePath = normalized.slice(markerIndex + marker.length)
|
|
18
|
+
const root = resolve(extensionsPath)
|
|
19
|
+
const resolved = resolve(root, relativePath)
|
|
20
|
+
if (resolved !== root && !resolved.startsWith(`${root}${sep}`)) {
|
|
21
|
+
throw new Error('Remote extension path escapes the built-in extensions directory')
|
|
22
|
+
}
|
|
23
|
+
return resolved
|
|
24
|
+
}
|
|
25
|
+
|
|
6
26
|
export const loadFile = async (path) => {
|
|
7
27
|
try {
|
|
8
28
|
Assert.string(path)
|
|
9
|
-
const
|
|
29
|
+
const resolvedPath = resolveRemoteExtensionPath(path)
|
|
30
|
+
const module = await ImportScript.importScript(resolvedPath)
|
|
10
31
|
if (module && module.commandMap) {
|
|
11
32
|
const commandMap = module.commandMap
|
|
12
33
|
Command.register(commandMap)
|