[Manual Backport] Use @kbn/handlebars and compileAST over handlebars.compile (#218449) (#218952)

## Summary

Manual backport of https://github.com/elastic/kibana/pull/218449 to move
usage of `handlebars` to `kbn/handlebars`

The changes in the PR to main were on code that doesn't exist in
9.0/8.x/7.17 hence requiring a manual backport to usage of `compileAST`

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Sid 2025-04-23 21:06:37 +02:00 committed by GitHub
parent 171bfdf1d0
commit dbbd9339cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 2 deletions

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import Handlebars from 'handlebars';
import Handlebars from '@kbn/handlebars';
import { safeLoad, safeDump } from 'js-yaml';
import type { Logger } from '@kbn/core/server';
@ -21,7 +21,7 @@ export function compileTemplate(variables: PackagePolicyConfigRecord, templateSt
const { vars, yamlValues } = buildTemplateVariables(logger, variables);
let compiledTemplate: string;
try {
const template = handlebars.compile(templateStr, { noEscape: true });
const template = handlebars.compileAST(templateStr, { noEscape: true });
compiledTemplate = template(vars);
} catch (err) {
throw new PackageInvalidArchiveError(`Error while compiling agent template: ${err.message}`);

View file

@ -119,5 +119,6 @@
"@kbn/field-formats-plugin",
"@kbn/core-security-server",
"@kbn/core-http-server-utils",
"@kbn/handlebars",
]
}