Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate
Node.js
implementation for js-sandbox
to `isolated…
…-vm` (#3973) Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
- Loading branch information
1 parent
a079e0f
commit 22c6eab
Showing
52 changed files
with
1,029 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,31 @@ | ||
#!/usr/bin/env node | ||
// * The entry point of the CLI | ||
// @ts-check | ||
|
||
import { cli } from "../dist/index.js"; | ||
|
||
cli(process.argv); | ||
import { spawnSync } from "child_process"; | ||
import { cloneDeep } from "lodash-es"; | ||
|
||
const nodeVersion = parseInt(process.versions.node.split(".")[0]); | ||
|
||
// As per isolated-vm documentation, we need to supply `--no-node-snapshot` for node >= 20 | ||
// src: https://github.com/laverdet/isolated-vm?tab=readme-ov-file#requirements | ||
if (nodeVersion >= 20 && !process.execArgv.includes("--no-node-snapshot")) { | ||
const argCopy = cloneDeep(process.argv); | ||
|
||
// Replace first argument with --no-node-snapshot | ||
// We can get argv[0] from process.argv0 | ||
argCopy[0] = "--no-node-snapshot"; | ||
|
||
const result = spawnSync( | ||
process.argv0, | ||
argCopy, | ||
{ stdio: "inherit" } | ||
); | ||
|
||
// Exit with the same status code as the spawned process | ||
process.exit(result.status ?? 0); | ||
} else { | ||
cli(process.argv); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 53 additions & 25 deletions
78
packages/hoppscotch-cli/src/__tests__/samples/collections/coll-v1-req-v0.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,55 @@ | ||
{ | ||
"v": 1, | ||
"name": "coll-v1", | ||
"folders": [], | ||
"requests": [ | ||
"v": 1, | ||
"name": "coll-v1", | ||
"folders": [ | ||
{ | ||
"v": 1, | ||
"name": "coll-v1-child", | ||
"folders": [], | ||
"requests": [ | ||
{ | ||
"url": "https://httpbin.org", | ||
"path": "/get", | ||
"headers": [ | ||
{ "key": "Inactive-Header", "value": "Inactive Header", "active": false }, | ||
{ "key": "Authorization", "value": "Bearer token123", "active": true } | ||
], | ||
"params": [ | ||
{ "key": "key", "value": "value", "active": true }, | ||
{ "key": "inactive-key", "value": "inactive-param", "active": false } | ||
], | ||
"name": "req-v0", | ||
"method": "GET", | ||
"preRequestScript": "", | ||
"testScript": "pw.test(\"Asserts request params\", () => {\n pw.expect(pw.response.body.args.key).toBe(\"value\")\n pw.expect(pw.response.body.args[\"inactive-key\"]).toBe(undefined)\n})\n\npw.test(\"Asserts request headers\", () => {\n pw.expect(pw.response.body.headers[\"Authorization\"]).toBe(\"Bearer token123\")\n pw.expect(pw.response.body.headers[\"Inactive-Header\"]).toBe(undefined)\n})", | ||
"contentType": "application/json", | ||
"body": "", | ||
"auth": "Bearer Token", | ||
"bearerToken": "token123" | ||
} | ||
] | ||
} | ||
"url": "https://echo.hoppscotch.io", | ||
"path": "/get", | ||
"headers": [ | ||
{ "key": "Inactive-Header", "value": "Inactive Header", "active": false }, | ||
{ "key": "Authorization", "value": "Bearer token123", "active": true } | ||
], | ||
"params": [ | ||
{ "key": "key", "value": "value", "active": true }, | ||
{ "key": "inactive-key", "value": "inactive-param", "active": false } | ||
], | ||
"name": "req-v0-II", | ||
"method": "GET", | ||
"preRequestScript": "", | ||
"testScript": "pw.test(\"Asserts request params\", () => {\n pw.expect(pw.response.body.args.key).toBe(\"value\")\n pw.expect(pw.response.body.args[\"inactive-key\"]).toBe(undefined)\n})\n\npw.test(\"Asserts request headers\", () => {\n pw.expect(pw.response.body.headers[\"authorization\"]).toBe(\"Bearer token123\")\n pw.expect(pw.response.body.headers[\"inactive-header\"]).toBe(undefined)\n})", | ||
"contentType": "application/json", | ||
"body": "", | ||
"auth": "Bearer Token", | ||
"bearerToken": "token123" | ||
} | ||
] | ||
} | ||
], | ||
"requests": [ | ||
{ | ||
"url": "https://echo.hoppscotch.io", | ||
"path": "/get", | ||
"headers": [ | ||
{ "key": "Inactive-Header", "value": "Inactive Header", "active": false }, | ||
{ "key": "Authorization", "value": "Bearer token123", "active": true } | ||
], | ||
"params": [ | ||
{ "key": "key", "value": "value", "active": true }, | ||
{ "key": "inactive-key", "value": "inactive-param", "active": false } | ||
], | ||
"name": "req-v0", | ||
"method": "GET", | ||
"preRequestScript": "", | ||
"testScript": "pw.test(\"Asserts request params\", () => {\n pw.expect(pw.response.body.args.key).toBe(\"value\")\n pw.expect(pw.response.body.args[\"inactive-key\"]).toBe(undefined)\n})\n\npw.test(\"Asserts request headers\", () => {\n pw.expect(pw.response.body.headers[\"authorization\"]).toBe(\"Bearer token123\")\n pw.expect(pw.response.body.headers[\"inactive-header\"]).toBe(undefined)\n})", | ||
"contentType": "application/json", | ||
"body": "", | ||
"auth": "Bearer Token", | ||
"bearerToken": "token123" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.