Fix helpers
This commit is contained in:
parent
fa2fbb4253
commit
0bf94bcd7b
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue