Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

esbuild-plugin-handlebars

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esbuild-plugin-handlebars - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

.prettierrc.json

13

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc