[PR #5835] [MERGED] fix(cli): strip module prefix before script execution #5373

Closed
opened 2026-03-17 02:49:36 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/5835
Author: @jamesgeorge007
Created: 2/4/2026
Status: Merged
Merged: 2/5/2026
Merged by: @jamesgeorge007

Base: patchHead: fix/cli-strip-module-prefix


📝 Commits (1)

  • ee3ec78 fix(cli): strip module prefix before script execution

📊 Changes

4 files changed (+72 additions, -49 deletions)

View changed files

📝 packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/scripting-revamp-coll.json (+4 -4)
📝 packages/hoppscotch-cli/src/utils/mutators.ts (+16 -0)
📝 packages/hoppscotch-cli/src/utils/pre-request.ts (+50 -44)
📝 packages/hoppscotch-cli/src/utils/test.ts (+2 -1)

📄 Description

Closes #5834, FE-1127.

Scripts saved from the web app include an export {};\n prefix added by the Monaco editor for TypeScript IntelliSense. The CLI was not stripping this prefix before execution, causing test scripts to fail with SyntaxError: Unexpected token 'export' when running collections from workspaces via PAT. While exporting collections, it was stripped off and hence didn't affect the scenario with supplying the collection file path.

CLI counterpart to #5555.

The fix is applied at the CLI level rather than in js-sandbox since the module prefix is an app-specific concern that the sandbox shouldn't need to be aware of.

What's changed

  • Added stripModulePrefix utility to strip the module prefix before sandbox execution.
  • Applied to both pre-request and test script execution paths for consistency.
  • Added module prefix to existing e2e fixture for implicit coverage.

Notes to reviewers

Try creating a request with a variable in the post-request script under a collection and a sample test case. Run the collection from the pre-existing version of the CLI by supplying the collection ID & PAT, and observe the failure similar to the attached issue. Repeat the same with the CLI changes in scope here and observe a successful run.

This can also be validated with the scripting-revamp-collection from the test fixtures.


Summary by cubic

Fixes CLI script execution by stripping the Monaco-added module prefix (export {};), preventing “Unexpected token 'export'” errors when running collections via PAT. Scripts saved from the app now run correctly in the CLI.

  • Bug Fixes
    • Added stripModulePrefix and applied it to pre-request and test script runners.
    • Updated e2e fixture to include the prefix for coverage.

Written for commit ee3ec78125. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/5835 **Author:** [@jamesgeorge007](https://github.com/jamesgeorge007) **Created:** 2/4/2026 **Status:** ✅ Merged **Merged:** 2/5/2026 **Merged by:** [@jamesgeorge007](https://github.com/jamesgeorge007) **Base:** `patch` ← **Head:** `fix/cli-strip-module-prefix` --- ### 📝 Commits (1) - [`ee3ec78`](https://github.com/hoppscotch/hoppscotch/commit/ee3ec78125a0da98fae2580c10a01e6641b8ab4b) fix(cli): strip module prefix before script execution ### 📊 Changes **4 files changed** (+72 additions, -49 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/scripting-revamp-coll.json` (+4 -4) 📝 `packages/hoppscotch-cli/src/utils/mutators.ts` (+16 -0) 📝 `packages/hoppscotch-cli/src/utils/pre-request.ts` (+50 -44) 📝 `packages/hoppscotch-cli/src/utils/test.ts` (+2 -1) </details> ### 📄 Description Closes #5834, FE-1127. Scripts saved from the web app include an `export {};\n` prefix added by the Monaco editor for TypeScript IntelliSense. The CLI was not stripping this prefix before execution, causing test scripts to fail with `SyntaxError: Unexpected token 'export'` when running collections from workspaces via PAT. While exporting collections, it was stripped off and hence didn't affect the scenario with supplying the collection file path. CLI counterpart to #5555. > The fix is applied at the CLI level rather than in `js-sandbox` since the module prefix is an app-specific concern that the sandbox shouldn't need to be aware of. ### What's changed - Added `stripModulePrefix` utility to strip the module prefix before sandbox execution. - Applied to both pre-request and test script execution paths for consistency. - Added module prefix to existing e2e fixture for implicit coverage. ### Notes to reviewers Try creating a request with a variable in the post-request script under a collection and a sample test case. Run the collection from the pre-existing version of the CLI by supplying the collection ID & PAT, and observe the failure similar to the attached issue. Repeat the same with the CLI changes in scope here and observe a successful run. This can also be validated with the [scripting-revamp-collection](https://github.com/hoppscotch/hoppscotch/pull/5835/files#diff-918d3794b0c7c8c088f3586a83cd32be359403c1d35b02e89ca10599b625eb35) from the test fixtures. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes CLI script execution by stripping the Monaco-added module prefix (export {};), preventing “Unexpected token 'export'” errors when running collections via PAT. Scripts saved from the app now run correctly in the CLI. - **Bug Fixes** - Added stripModulePrefix and applied it to pre-request and test script runners. - Updated e2e fixture to include the prefix for coverage. <sup>Written for commit ee3ec78125a0da98fae2580c10a01e6641b8ab4b. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 02:49:36 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#5373
No description provided.