1
0
Fork 0
mirror of synced 2024-10-03 19:43:32 +13:00

Fix helpers

This commit is contained in:
Adria Navarro 2024-02-13 17:16:59 +01:00
parent fa2fbb4253
commit 0bf94bcd7b
4 changed files with 16 additions and 7377 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -2,7 +2,7 @@ const {
getJsHelperList,
} = require("../../../../string-templates/src/helpers/list.js")
export const helpers = {
export default {
...getJsHelperList(),
// pointing stripProtocol to a unexisting function to be able to declare it on isolated-vm
// @ts-ignore

View file

@ -73,6 +73,10 @@ export class IsolatedVM implements VM {
escape: querystring.escape,
})
const cryptoModule = this.registerCallbacks({
randomUUID: crypto.randomUUID,
})
this.addToContext({
helpersStripProtocol: new ivm.Callback((str: string) => {
var parsed = url.parse(str) as any
@ -81,10 +85,6 @@ export class IsolatedVM implements VM {
}),
})
const cryptoModule = this.registerCallbacks({
randomUUID: crypto.randomUUID,
})
const injectedRequire = `const require=function req(val) {
switch (val) {
case "url": return ${urlModule};
@ -93,7 +93,9 @@ export class IsolatedVM implements VM {
}
}`
const helpersSource = loadBundle(BundleType.HELPERS)
this.moduleHandler.registerModule(`${injectedRequire};${helpersSource}`)
this.moduleHandler.registerModule(
`${injectedRequire};${helpersSource};helpers=helpers.default`
)
return this
}