Skip to content

Commit ff02463

Browse files
kibertoadjaylinski
authored andcommitted
Make CLI ESM for compatibility with new yargs
1 parent a8a1c9d commit ff02463

5 files changed

Lines changed: 13 additions & 8 deletions

File tree

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#!/usr/bin/env node
22

3-
const yargs = require('yargs')(process.argv.slice(2))
3+
import { createRequire } from 'node:module';
4+
import yargs from 'yargs';
5+
6+
const require = createRequire(import.meta.url);
7+
const Precompiler = require('../dist/cjs/precompiler');
8+
9+
const parser = yargs(process.argv.slice(2))
410
.usage('Precompile handlebar templates.\nUsage: $0 [template|directory]...')
511
.help(false)
612
.version(false)
@@ -107,18 +113,17 @@ const yargs = require('yargs')(process.argv.slice(2))
107113
})
108114
.wrap(120);
109115

110-
const argv = yargs.parseSync();
116+
const argv = parser.parseSync();
111117
argv.files = argv._;
112118
delete argv._;
113119

114-
const Precompiler = require('../dist/cjs/precompiler');
115120
Precompiler.loadTemplates(argv, function (err, opts) {
116121
if (err) {
117122
throw err;
118123
}
119124

120125
if (opts.help || (!opts.templates.length && !opts.version)) {
121-
yargs.showHelp('log');
126+
parser.showHelp('log');
122127
} else {
123128
Precompiler.cli(opts);
124129
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"url": "https://github.com/handlebars-lang/handlebars.js.git"
1717
},
1818
"bin": {
19-
"handlebars": "bin/handlebars.js"
19+
"handlebars": "bin/handlebars.mjs"
2020
},
2121
"files": [
2222
"bin",

spec/expected/help.menu.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Precompile handlebar templates.
2-
Usage: handlebars.js [template|directory]...
2+
Usage: handlebars.mjs [template|directory]...
33

44
Options:
55
-f, --output Output File [string]

tasks/tests/cli.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const fs = require('fs');
22
const { execCommand, FileTestHelper } = require('cli-testlab');
33
const Handlebars = require('../../lib');
44

5-
const cli = 'node ./bin/handlebars.js';
5+
const cli = 'node ./bin/handlebars.mjs';
66

77
expect.extend({
88
toEqualWithRelaxedSpace(received, expected) {

tests/integration/multi-nodejs-test/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ cd "$( dirname "$( readlink -f "$0" )" )" || exit 1
1414
unset npm_config_prefix
1515

1616
echo "Handlebars should be able to run in various versions of NodeJS"
17-
for node_version_to_test in 18 20; do
17+
for node_version_to_test in 20 22; do
1818

1919
rm -rf target node_modules package-lock.json
2020
mkdir target

0 commit comments

Comments
 (0)