{"id":26028,"library":"oc-generic-template-compiler","title":"OC Generic Template Compiler","description":"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.","status":"active","version":"2.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/opencomponents/base-templates","tags":["javascript","oc","opencomponents","typescript"],"install":[{"cmd":"npm install oc-generic-template-compiler","lang":"bash","label":"npm"},{"cmd":"yarn add oc-generic-template-compiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add oc-generic-template-compiler","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Central configuration for OpenComponents compilers","package":"@oc/config","optional":false}],"imports":[{"note":"Package exports a default function; CommonJS require works but ESM recommended.","wrong":"const ocGenericTemplateCompiler = require('oc-generic-template-compiler')","symbol":"default (export default)","correct":"import ocGenericTemplateCompiler from 'oc-generic-template-compiler'"},{"note":"Type import for TypeScript users; the package ships types.","wrong":"","symbol":"GenericCompiler type","correct":"import type { GenericCompiler } from 'oc-generic-template-compiler'"},{"note":"Use 'import type' for type-only imports to avoid runtime issues.","wrong":"import { CompilerOptions } from 'oc-generic-template-compiler' (value import instead of type)","symbol":"CompilerOptions type","correct":"import type { CompilerOptions } from 'oc-generic-template-compiler'"}],"quickstart":{"code":"import ocGenericTemplateCompiler from 'oc-generic-template-compiler';\n\nconst compiler = ocGenericTemplateCompiler({\n  viewCompiler: { compile: (source) => ({ result: source, dependencies: [] }) },\n  serverCompiler: { compile: (source) => ({ result: source, dependencies: [] }) },\n  staticsCompiler: { compile: (source) => ({ result: source, dependencies: [] }) }\n});\n\nconst compiled = compiler.compile({\n  view: '<div>Hello</div>',\n  server: 'module.exports = () => {}',\n  statics: []\n});\n\nconsole.log(compiled.view.result); // '<div>Hello</div>'","lang":"typescript","description":"Creates a generic compiler with mock view, server, and statics compilers and compiles a simple template."},"warnings":[{"fix":"Ensure custom compilers conform to this interface; previously compilers could return strings.","message":"Version 2.x requires all compilers to return { result, dependencies } objects.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Update custom compilers to return objects with 'result' and 'dependencies'.","message":"Using string-only compilers (without 'dependencies') is deprecated since 2.0.0.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Ensure viewCompiler, serverCompiler, and staticsCompiler are objects implementing compile.","message":"Each compiler must be an object with a 'compile' function; passing non-object will throw.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure all compilers return { result: string, dependencies: any[] }.","cause":"One of the compilers returned undefined instead of an object with result/dependencies.","error":"TypeError: Cannot destructure property 'result' of ... as it is undefined"},{"fix":"Check that each compiler property is an object with a compile method.","cause":"The compiler parameter is being passed a non-function value.","error":"Error: Compiler is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}