npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@singleton-sd/post-kit-compiler

v0.4.0

Published

Template compiler for PostKit — validates and compiles EmailBuilder.js source files into deployable HTML artifacts

Readme

@singleton-sd/post-kit-compiler

Template compiler for PostKit. Reads Git-backed email template source files (template.json, metadata.json, preview.json), validates them, and produces a compiled CompiledTemplate artifact for use by post-kit-publisher and apps/api.

HTML renderer and variable engine

HTML is produced by @usewaypoint/email-builder renderToStaticMarkup (EmailBuilder.js JSON → email HTML).

Subject lines and {{variable}} substitution in that HTML use Handlebars ^4.7.8 (the version declared in this package). Handlebars is not the HTML renderer.

Until send-time substitution, compiled templateHtml keeps Handlebars placeholders. compile() still renders preview.json through Handlebars to fail fast on invalid templates.

Installation

pnpm add @singleton-sd/post-kit-compiler

API

import { compile, compileFromDirectory, renderPreview, validateSource, CompilerError } from '@singleton-sd/post-kit-compiler';

compile(source, options?)

Validates and compiles a TemplateSource object into a CompiledTemplate.

const result = await compile({
  templateJson: { document: { type: 'EmailLayout', data: {} } },
  metadata: {
    key: 'marketing.contact-us',
    name: 'Contact Us',
    subject: 'New message from {{name}}',
    variables: ['name', 'email', 'message'],
    schemaVersion: '1',
  },
  previewData: { name: 'Jane Doe', email: '[email protected]', message: 'Hello!' },
});

console.log(result.manifest.contentHash); // SHA-256 hex

compileFromDirectory(dir, options?)

Reads template.json, metadata.json, and preview.json from dir and delegates to compile().

const result = await compileFromDirectory('./content/email-templates/marketing.contact-us');

renderPreview(source)

Same validation and EmailBuilder render path as compile(), but returns the Handlebars-substituted HTML string (preview values applied). Intended for the admin editor preview pane. Does not hash content and does not use node:crypto or the filesystem.

Browser bundles must import from @singleton-sd/post-kit-compiler/preview (not the package root). The root entry still re-exports renderPreview for Node tooling, but also pulls in compile / filesystem helpers.

import { renderPreview } from '@singleton-sd/post-kit-compiler/preview';

const html = await renderPreview(source);

validateSource(source)

Dry-run validation — returns { ok: true } or { ok: false; errors: string[] }. Does not throw.

const validation = validateSource(source);
if (!validation.ok) {
  console.error(validation.errors);
}

CompilerError

Thrown by compile() and compileFromDirectory() on validation or render failures. Has a code property:

| Code | Meaning | |---|---| | INVALID_TEMPLATE_JSON | template.json is missing or not valid JSON | | INVALID_METADATA | metadata.json or preview.json is missing, not valid JSON, or fails schema validation | | MISSING_PREVIEW_VARIABLE | A variable declared in metadata.variables is absent from previewData | | RENDER_FAILURE | HTML or subject template rendering failed |

Development

pnpm test   # type-check + run tests
pnpm build  # emit CommonJS to dist/
pnpm lint   # covered by root eslint