mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-26 01:06:00 +03:00
[PR #3619] [MERGED] refactor(scripting-revamp): migrate js-sandbox to web worker/Node vm based implementation #4452
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#4452
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/hoppscotch/hoppscotch/pull/3619
Author: @jamesgeorge007
Created: 12/3/2023
Status: ✅ Merged
Merged: 12/7/2023
Merged by: @AndrewBastin
Base:
release/2023.12.0← Head:refactor/scripting-revamp-dep-migration📝 Commits (10+)
9a1bfc3refactor: node VM based implementationfd5b196refactor: get started with the web worker based implementationc817394refactor: change in directory hierarchyaac90fechore: conditionally export modules15600a8refactor: web worker based implementation for pre-request scripta6ce496chore: dynamically import environment specific dependencies6d6a2ffchore: inline worker script for pre request script62a393bchore: iterations6f10a89chore: move js-sandbox to a vite based build system9296aabchore: move to multiple entrypoints with subpath exports📊 Changes
43 files changed (+2708 additions, -3188 deletions)
View changed files
📝
packages/hoppscotch-cli/jest.config.ts(+1 -1)📝
packages/hoppscotch-cli/package.json(+2 -1)📝
packages/hoppscotch-cli/src/__tests__/commands/test.spec.ts(+2 -3)📝
packages/hoppscotch-cli/src/__tests__/samples/env-flag-envs.json(+0 -1)📝
packages/hoppscotch-cli/src/__tests__/samples/env-flag-tests.json(+1 -1)📝
packages/hoppscotch-cli/src/utils/pre-request.ts(+10 -9)📝
packages/hoppscotch-cli/src/utils/test.ts(+9 -7)📝
packages/hoppscotch-common/src/helpers/RequestRunner.ts(+21 -23)📝
packages/hoppscotch-common/src/helpers/preRequest.ts(+6 -2)➕
packages/hoppscotch-js-sandbox/index.d.ts(+2 -0)📝
packages/hoppscotch-js-sandbox/jest.config.js(+5 -1)➕
packages/hoppscotch-js-sandbox/node.d.ts(+2 -0)📝
packages/hoppscotch-js-sandbox/package.json(+22 -10)📝
packages/hoppscotch-js-sandbox/src/__tests__/preRequest.spec.ts(+6 -6)📝
packages/hoppscotch-js-sandbox/src/__tests__/testing/envs/get.spec.ts(+4 -3)📝
packages/hoppscotch-js-sandbox/src/__tests__/testing/envs/getResolve.spec.ts(+4 -3)📝
packages/hoppscotch-js-sandbox/src/__tests__/testing/envs/resolve.spec.ts(+5 -3)📝
packages/hoppscotch-js-sandbox/src/__tests__/testing/envs/set.spec.ts(+5 -3)📝
packages/hoppscotch-js-sandbox/src/__tests__/testing/expect/toBe.spec.ts(+5 -3)📝
packages/hoppscotch-js-sandbox/src/__tests__/testing/expect/toBeLevelxxx.spec.ts(+5 -3)...and 23 more files
📄 Description
Description
This PR marks the initial step for the efforts that will be made towards the scripting revamp front. We're moving from quickjs-emscripten to a Web worker/Node VM-based implementation for
js-sandbox.Closes HFE-318.
Changes
Separate implementation based on environments for
js-sandboxwith subpath-based exports. The functions to execute pre-request and test scripts are exposed under subpaths after the respective environment, while types are accessible from the package root.The web worker-based implementation
{pre-request,test-runner}/web-worker/*.tsincludes a script compiling the main thread logic for communicating with the worker thread via the exposed function. The received arguments (script, envs, etc) from the place of invocation are supplied to the worker script residing relative to the main thread source, where the script gets executed via the Function constructor, and the results are sent back to the main thread which in turn is returned to the system.The Node VM-based implementation
{pre-request,test-runner}/node-vm/*.tscreates a new VM context via the createContext method, executes the script in a new context via the runInContext method and returns the relevant results.getPreRequestScriptMethods&getTestRunnerScriptMethodsfunctions underutilscompiles the methods to be exposed under thepwnamespace.Move the
js-sandboxbuild system fromtsuptovite.src/web.tssrc/node.tsThe
marshlObjecToVmfunction underutilshas been made to prevent cyclic objects under the namepreventCyclicObjectssince there isn't a requirement for marshaling.Enable CLI e2e tests on CI.
Checks
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.