esbuild-plugin-handlebars
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "esbuild-plugin-handlebars", | ||
"description": "an esbuild plugin to handle ... handlebars!", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"main": "dist/index.js", | ||
@@ -14,3 +14,3 @@ "author": "Inqnuam", | ||
"dependencies": { | ||
"handlebars": "^4.7.7" | ||
"handlebars": "^4.7.8" | ||
}, | ||
@@ -22,4 +22,9 @@ "devDependencies": { | ||
"scripts": { | ||
"build": "node build.js" | ||
} | ||
"build": "node build.js", | ||
"test": "node test/test.js" | ||
}, | ||
"keywords": [ | ||
"handlebars", | ||
"esbuild" | ||
] | ||
} |
@@ -34,6 +34,8 @@ # esbuild-plugin-handlebars | ||
const hbsOptions = { | ||
additionalHelpers: {}, | ||
additionalPartials: {}, | ||
precompileOptions: {} | ||
} | ||
additionalHelpers: {}, | ||
additionalPartials: { | ||
childTemplate: "./child.hbs", | ||
}, | ||
precompileOptions: {}, | ||
}; | ||
@@ -40,0 +42,0 @@ // usual esbuild config |
@@ -7,5 +7,9 @@ import handlebars from "handlebars"; | ||
const fileCache = new Map(); | ||
// @ts-ignore | ||
class ESBuildHandlebarsJSCompiler extends handlebars.JavaScriptCompiler { | ||
// @ts-ignore | ||
constructor() { | ||
super(...arguments); | ||
} | ||
public compiler: typeof ESBuildHandlebarsJSCompiler = ESBuildHandlebarsJSCompiler; | ||
nameLookup(parent, name: string, type) { | ||
@@ -18,7 +22,8 @@ if (type === "helper" && !foundHelpers.includes(name)) { | ||
} | ||
const onloadOpt: OnLoadOptions = { | ||
filter: /\.(hbs|handlebars)$/i, | ||
}; | ||
function hbs(options: { additionalHelpers: any; additionalPartials: any; precompileOptions: any } = { additionalHelpers: {}, additionalPartials: {}, precompileOptions: {} }) { | ||
const onloadOpt: OnLoadOptions = { | ||
filter: /\.(hbs|handlebars)$/i, | ||
}; | ||
const { additionalHelpers = {}, additionalPartials = {}, precompileOptions = {} } = options; | ||
@@ -53,2 +58,3 @@ return { | ||
} | ||
const source = await readFile(filename, "utf-8"); | ||
@@ -59,2 +65,3 @@ const knownHelpers = Object.keys(additionalHelpers).reduce((prev: any, helper: string) => { | ||
}, {}); | ||
// Compile options | ||
@@ -66,2 +73,3 @@ const compileOptions = { | ||
}; | ||
try { | ||
@@ -71,3 +79,10 @@ foundHelpers = []; | ||
const foundAndMatchedHelpers = foundHelpers.filter((helper) => additionalHelpers[helper] !== undefined); | ||
const contents = ["import * as Handlebars from 'handlebars/runtime';", ...foundAndMatchedHelpers.map((helper) => `import ${helper} from '${additionalHelpers[helper]}';`), ...Object.entries(additionalPartials).map(([name, path]) => `import ${name} from '${path}';`), `Handlebars.registerHelper({${foundAndMatchedHelpers.join()}});`, `Handlebars.registerPartial({${Object.keys(additionalPartials).join()}});`, `export default Handlebars.template(${template});`].join("\n"); | ||
const contents = [ | ||
"import * as Handlebars from 'handlebars/runtime';", | ||
...foundAndMatchedHelpers.map((helper) => `import ${helper} from '${additionalHelpers[helper]}';`), | ||
...Object.entries(additionalPartials).map(([name, path]) => `import ${name} from '${path}';`), | ||
`Handlebars.registerHelper({${foundAndMatchedHelpers.join()}});`, | ||
`Handlebars.registerPartial({${Object.keys(additionalPartials).join()}});`, | ||
`export default Handlebars.template(${template});`, | ||
].join("\n"); | ||
return { contents }; | ||
@@ -74,0 +89,0 @@ } catch (err: any) { |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
114911
6
546
49
Updatedhandlebars@^4.7.8