Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try {
new vm.Script(script).runInNewContext(context)
if (typeof context.result !== 'undefined') {
this.emit('filter-valid', {
result: context.result,
type: 'js'
})
} else {
this.emit('filter-invalid')
}
} catch (e) {
fs.writeFileSync(this.tmp, JSON.stringify(this.data))
// If JavaScript filter fails, run through jq
jq.run(filter, this.tmp, {
input: 'file',
output: 'json'
}).then((result) => {
if (result === null) {
// jq returns null for incorrect keys, but we will count them as
// invalid
this.emit('filter-invalid')
} else {
// The jq filter worked
this.emit('filter-valid', {
type: 'jq',
result
})
}
() => jq.run('.', descriptorFile, { sort: true }).then(out => fs.writeFileSync(descriptorFile, out + '\n'))
)
() => jq.run('.', DEPLOYMENT_JSON, { sort: true }).then(out => fs.writeFileSync(DEPLOYMENT_JSON, out + '\n'))
)