Skip to content

Commit a5fcaf4

Browse files
tepel-chentchen
andauthored
fix: use vm2 instead of vm (#629)
Co-authored-by: tchen <tchen@tchen>
1 parent c4cfff3 commit a5fcaf4

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"safe-stable-stringify": "^2.2.0",
4949
"ts-node": "^10.9.1",
5050
"typescript": "~5.5.0",
51+
"vm2": "^3.10.0",
5152
"yargs": "^17.1.1"
5253
},
5354
"devDependencies": {

typescript-json-schema.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export { Program, CompilerOptions, Symbol } from "typescript";
99

1010
export { ts };
1111

12-
const vm = require("vm");
12+
const { VM } = require("vm2");
1313

1414
const REGEX_FILE_NAME_OR_SPACE = /(\bimport\(".*?"\)|".*?")\.| /g;
1515
const REGEX_TSCONFIG_NAME = /^.*\.json$/;
@@ -867,10 +867,8 @@ export class JsonSchemaGenerator {
867867
definition.default = initial.getText();
868868
} else {
869869
try {
870-
const sandbox = { sandboxvar: null as any };
871-
vm.runInNewContext("sandboxvar=" + initial.getText(), sandbox);
872-
873-
const val = sandbox.sandboxvar;
870+
const vm = new VM();
871+
const val = vm.run("sandboxvar=" + initial.getText()) as any;
874872
if (
875873
val === null ||
876874
typeof val === "string" ||

yarn.lock

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,18 @@ acorn-walk@^8.1.1:
118118
resolved "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz"
119119
integrity sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==
120120

121+
acorn-walk@^8.3.4:
122+
version "8.3.4"
123+
resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.3.4.tgz#794dd169c3977edf4ba4ea47583587c5866236b7"
124+
integrity sha512-ueEepnujpqee2o5aIYnvHU6C0A42MNdsIDeqy5BydrkuC5R1ZuUFnm27EeFJGoEHJQgn3uleRvmTXaJgfXbt4g==
125+
dependencies:
126+
acorn "^8.11.0"
127+
128+
acorn@^8.11.0, acorn@^8.14.1:
129+
version "8.15.0"
130+
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.15.0.tgz#a360898bc415edaac46c8241f6383975b930b816"
131+
integrity sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==
132+
121133
acorn@^8.4.1:
122134
version "8.5.0"
123135
resolved "https://registry.npmjs.org/acorn/-/acorn-8.5.0.tgz"
@@ -923,6 +935,14 @@ v8-compile-cache-lib@^3.0.1:
923935
resolved "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz"
924936
integrity sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==
925937

938+
vm2@^3.10.0:
939+
version "3.10.0"
940+
resolved "https://registry.yarnpkg.com/vm2/-/vm2-3.10.0.tgz#bd241fbf37fed0b7d0050e40ad08d7be6ba33d57"
941+
integrity sha512-3ggF4Bs0cw4M7Rxn19/Cv3nJi04xrgHwt4uLto+zkcZocaKwP/nKP9wPx6ggN2X0DSXxOOIc63BV1jvES19wXQ==
942+
dependencies:
943+
acorn "^8.14.1"
944+
acorn-walk "^8.3.4"
945+
926946
927947
version "2.0.2"
928948
resolved "https://registry.npmjs.org/which/-/which-2.0.2.tgz"

0 commit comments

Comments
 (0)