Skip to content

Commit a4e33c7

Browse files
committed
CJS interop
1 parent 7e22795 commit a4e33c7

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

lib/handlebars.runtime.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,15 @@ noConflict(inst);
3737

3838
inst['default'] = inst;
3939

40+
// Named re-exports for CJS interop.
41+
// See the comment in lib/index.js for the full explanation. In short:
42+
// require('handlebars/runtime').COMPILER_REVISION must be directly accessible
43+
// for tools like handlebars-loader that compare compiler and runtime revisions.
44+
export {
45+
VERSION,
46+
COMPILER_REVISION,
47+
LAST_COMPATIBLE_COMPILER_REVISION,
48+
REVISION_CHANGES,
49+
} from './handlebars/base.js';
50+
4051
export default inst;

lib/index.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,43 @@ import { PrintVisitor, print } from '@handlebars/parser';
44
handlebars.PrintVisitor = PrintVisitor;
55
handlebars.print = print;
66

7+
// Named exports for CJS interop.
8+
//
9+
// When Node.js (v22+) runs require() on an ESM module, it returns the module
10+
// namespace object — only named exports become direct properties. Without these,
11+
// require('handlebars') would return { default: inst } and calls like
12+
// Handlebars.precompile() or Handlebars.COMPILER_REVISION would be undefined.
13+
//
14+
// Tools like handlebars-loader rely on these being directly accessible via
15+
// require('handlebars').create(), require('handlebars').COMPILER_REVISION, etc.
16+
export const {
17+
create,
18+
compile,
19+
precompile,
20+
parse,
21+
parseWithoutProcessing,
22+
COMPILER_REVISION,
23+
LAST_COMPATIBLE_COMPILER_REVISION,
24+
REVISION_CHANGES,
25+
VERSION,
26+
AST,
27+
Compiler,
28+
JavaScriptCompiler,
29+
Parser,
30+
Visitor,
31+
SafeString,
32+
Exception,
33+
Utils,
34+
escapeExpression,
35+
VM,
36+
template,
37+
log,
38+
registerHelper,
39+
unregisterHelper,
40+
registerPartial,
41+
unregisterPartial,
42+
registerDecorator,
43+
unregisterDecorator,
44+
} = handlebars;
45+
export { PrintVisitor, print };
746
export default handlebars;

0 commit comments

Comments
 (0)