Files
cypress/packages/server/lib/cloud/require_script.ts
Ryan Manuel ffcc6387ef chore: add ability to load types from the studio bundle (#31153)
* chore: set up sharing of react via module federation in studio

* chore: add ability to load types from the studio bundle

* fix build

* fix build

* fix build

* PR comments

* Update guides/studio-development.md

Co-authored-by: Matt Schile <mschile@cypress.io>

* fix test

---------

Co-authored-by: Matt Schile <mschile@cypress.io>
2025-02-28 16:30:45 -06:00

20 lines
468 B
TypeScript

import Module from 'module'
/**
* requireScript, does just that, requires the passed in script as if it was a module.
* @param script - string
* @returns exports
*/
export const requireScript = <T>(script: string): T => {
const mod = new Module('id', module)
mod.filename = ''
// _compile is a private method
// @ts-expect-error
mod._compile(script, mod.filename)
module.children.splice(module.children.indexOf(mod), 1)
return mod.exports as T
}