Registry / web-framework / oc-generic-template-compiler

oc-generic-template-compiler

JSON →
library2.2.0jsnpmunverified

oc-generic-template-compiler is a module for creating a generic compiler that orchestrates view, server, and static compilers in the OpenComponents ecosystem. Version 2.2.0 is current, with stable releases following OpenComponents' cadence. It enables processing of templates across multiple compilers, supporting JavaScript and HTML. Key differentiator: acts as a unified interface for composing compilers, reducing integration complexity in OC-based projects. Supports TypeScript via bundled types.

npm install oc-generic-template-compiler
INSTALL
IMPORT
SIG · OC-GENERIC-TEMPLAT
O
oc-generic-template-compiler
web-frameworkjavascriptv2.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (export default)
✓ import ocGenericTemplateCompiler from 'oc-generic-template-compiler'
✗ const ocGenericTemplateCompiler = require('oc-generic-template-compiler')
Package exports a default function; CommonJS require works but ESM recommended.
GenericCompiler type
✓ import type { GenericCompiler } from 'oc-generic-template-compiler'
Type import for TypeScript users; the package ships types.
CompilerOptions type
✓ import type { CompilerOptions } from 'oc-generic-template-compiler'
✗ import { CompilerOptions } from 'oc-generic-template-compiler' (value import instead of type)
Use 'import type' for type-only imports to avoid runtime issues.

Creates a generic compiler with mock view, server, and statics compilers and compiles a simple template.

import ocGenericTemplateCompiler from 'oc-generic-template-compiler'; const compiler = ocGenericTemplateCompiler({ viewCompiler: { compile: (source) => ({ result: source, dependencies: [] }) }, serverCompiler: { compile: (source) => ({ result: source, dependencies: [] }) }, staticsCompiler: { compile: (source) => ({ result: source, dependencies: [] }) } }); const compiled = compiler.compile({ view: '<div>Hello</div>', server: 'module.exports = () => {}', statics: [] }); console.log(compiled.view.result); // '<div>Hello</div>'
Debug
Known issues
breakingVersion 2.x requires all compilers to return { result, dependencies } objects.
fix
Ensure custom compilers conform to this interface; previously compilers could return strings.
affects: >=2.0.0
deprecatedUsing string-only compilers (without 'dependencies') is deprecated since 2.0.0.
fix
Update custom compilers to return objects with 'result' and 'dependencies'.
affects: >=2.0.0
gotchaEach compiler must be an object with a 'compile' function; passing non-object will throw.
fix
Ensure viewCompiler, serverCompiler, and staticsCompiler are objects implementing compile.
affects: all
Errors
Common errors & fixes
TypeError: Cannot destructure property 'result' of ... as it is undefined
One of the compilers returned undefined instead of an object with result/dependencies.
fix
Ensure all compilers return { result: string, dependencies: any[] }.
Error: Compiler is not a function
The compiler parameter is being passed a non-function value.
fix
Check that each compiler property is an object with a compile method.
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies
@oc/configrequiredCentral configuration for OpenComponents compilers
Agent activity
4 hits · last 30 days
node
4
Resources
oc-generic-template-compiler — npm install oc-generic-template-compiler · libregistry