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,
|
getJsHelperList,
|
||||||
} = require("../../../../string-templates/src/helpers/list.js")
|
} = require("../../../../string-templates/src/helpers/list.js")
|
||||||
|
|
||||||
export const helpers = {
|
export default {
|
||||||
...getJsHelperList(),
|
...getJsHelperList(),
|
||||||
// pointing stripProtocol to a unexisting function to be able to declare it on isolated-vm
|
// pointing stripProtocol to a unexisting function to be able to declare it on isolated-vm
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|
|
@ -73,6 +73,10 @@ export class IsolatedVM implements VM {
|
||||||
escape: querystring.escape,
|
escape: querystring.escape,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const cryptoModule = this.registerCallbacks({
|
||||||
|
randomUUID: crypto.randomUUID,
|
||||||
|
})
|
||||||
|
|
||||||
this.addToContext({
|
this.addToContext({
|
||||||
helpersStripProtocol: new ivm.Callback((str: string) => {
|
helpersStripProtocol: new ivm.Callback((str: string) => {
|
||||||
var parsed = url.parse(str) as any
|
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) {
|
const injectedRequire = `const require=function req(val) {
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case "url": return ${urlModule};
|
case "url": return ${urlModule};
|
||||||
|
@ -93,7 +93,9 @@ export class IsolatedVM implements VM {
|
||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
const helpersSource = loadBundle(BundleType.HELPERS)
|
const helpersSource = loadBundle(BundleType.HELPERS)
|
||||||
this.moduleHandler.registerModule(`${injectedRequire};${helpersSource}`)
|
this.moduleHandler.registerModule(
|
||||||
|
`${injectedRequire};${helpersSource};helpers=helpers.default`
|
||||||
|
)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue