pi-landstrip 0.1.0 → 0.2.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.
- package/index.ts +29 -1
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -72,6 +72,9 @@ interface LandstripPolicy {
|
|
|
72
72
|
filesystem: SandboxFilesystemConfig;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
const LANDSTRIP_VERSION = [0, 8, 3] as const;
|
|
76
|
+
const SUPPORTED_PLATFORMS = new Set<NodeJS.Platform>(['linux', 'darwin', 'win32']);
|
|
77
|
+
|
|
75
78
|
const DEFAULT_CONFIG: SandboxConfig = {
|
|
76
79
|
enabled: true,
|
|
77
80
|
network: {
|
|
@@ -475,6 +478,24 @@ function landstripVersion(command: string): string | null {
|
|
|
475
478
|
return result.stdout.trim();
|
|
476
479
|
}
|
|
477
480
|
|
|
481
|
+
function parseVersion(version: string): [number, number, number] | null {
|
|
482
|
+
const match = version.match(/\b(\d+)\.(\d+)\.(\d+)\b/);
|
|
483
|
+
if (!match) return null;
|
|
484
|
+
return [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
function hasMinimumVersion(version: string, minimum: readonly [number, number, number]): boolean {
|
|
488
|
+
const parsed = parseVersion(version);
|
|
489
|
+
if (!parsed) return false;
|
|
490
|
+
|
|
491
|
+
for (let i = 0; i < minimum.length; i++) {
|
|
492
|
+
if (parsed[i] > minimum[i]) return true;
|
|
493
|
+
if (parsed[i] < minimum[i]) return false;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
return true;
|
|
497
|
+
}
|
|
498
|
+
|
|
478
499
|
function proxyEnv(env: NodeJS.ProcessEnv | undefined, port: number): NodeJS.ProcessEnv {
|
|
479
500
|
const url = `http://127.0.0.1:${port}`;
|
|
480
501
|
|
|
@@ -928,7 +949,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
928
949
|
function enableSandbox(ctx: ExtensionContext): boolean {
|
|
929
950
|
const config = loadConfig(ctx.cwd);
|
|
930
951
|
|
|
931
|
-
if (process.platform
|
|
952
|
+
if (!SUPPORTED_PLATFORMS.has(process.platform)) {
|
|
932
953
|
sandboxEnabled = false;
|
|
933
954
|
sandboxReady = false;
|
|
934
955
|
ctx.ui.notify(`landstrip sandboxing is not supported on ${process.platform}`, 'warning');
|
|
@@ -943,6 +964,13 @@ export default function (pi: ExtensionAPI) {
|
|
|
943
964
|
return false;
|
|
944
965
|
}
|
|
945
966
|
|
|
967
|
+
if (!hasMinimumVersion(version, LANDSTRIP_VERSION)) {
|
|
968
|
+
sandboxEnabled = false;
|
|
969
|
+
sandboxReady = false;
|
|
970
|
+
ctx.ui.notify(`landstrip 0.8.3 or newer is required; found: ${version}`, 'error');
|
|
971
|
+
return false;
|
|
972
|
+
}
|
|
973
|
+
|
|
946
974
|
sandboxEnabled = true;
|
|
947
975
|
sandboxReady = true;
|
|
948
976
|
warnIfAllDomainsAllowed(ctx, config);
|