Make CLI ESM for compatibility with new yargs

This commit is contained in:
Igor Savin
2026-03-19 00:40:09 +02:00
committed by Jay Linski
parent a8a1c9dd4f
commit ff02463429
5 changed files with 13 additions and 8 deletions
+9 -4
View File
@@ -1,6 +1,12 @@
#!/usr/bin/env node
const yargs = require('yargs')(process.argv.slice(2))
import { createRequire } from 'node:module';
import yargs from 'yargs';
const require = createRequire(import.meta.url);
const Precompiler = require('../dist/cjs/precompiler');
const parser = yargs(process.argv.slice(2))
.usage('Precompile handlebar templates.\nUsage: $0 [template|directory]...')
.help(false)
.version(false)
@@ -107,18 +113,17 @@ const yargs = require('yargs')(process.argv.slice(2))
})
.wrap(120);
const argv = yargs.parseSync();
const argv = parser.parseSync();
argv.files = argv._;
delete argv._;
const Precompiler = require('../dist/cjs/precompiler');
Precompiler.loadTemplates(argv, function (err, opts) {
if (err) {
throw err;
}
if (opts.help || (!opts.templates.length && !opts.version)) {
yargs.showHelp('log');
parser.showHelp('log');
} else {
Precompiler.cli(opts);
}
+1 -1
View File
@@ -16,7 +16,7 @@
"url": "https://github.com/handlebars-lang/handlebars.js.git"
},
"bin": {
"handlebars": "bin/handlebars.js"
"handlebars": "bin/handlebars.mjs"
},
"files": [
"bin",
+1 -1
View File
@@ -1,5 +1,5 @@
Precompile handlebar templates.
Usage: handlebars.js [template|directory]...
Usage: handlebars.mjs [template|directory]...
Options:
-f, --output Output File [string]
+1 -1
View File
@@ -2,7 +2,7 @@ const fs = require('fs');
const { execCommand, FileTestHelper } = require('cli-testlab');
const Handlebars = require('../../lib');
const cli = 'node ./bin/handlebars.js';
const cli = 'node ./bin/handlebars.mjs';
expect.extend({
toEqualWithRelaxedSpace(received, expected) {
+1 -1
View File
@@ -14,7 +14,7 @@ cd "$( dirname "$( readlink -f "$0" )" )" || exit 1
unset npm_config_prefix
echo "Handlebars should be able to run in various versions of NodeJS"
for node_version_to_test in 18 20; do
for node_version_to_test in 20 22; do
rm -rf target node_modules package-lock.json
mkdir target