diff --git a/bin/handlebars.js b/bin/handlebars.mjs old mode 100755 new mode 100644 similarity index 92% rename from bin/handlebars.js rename to bin/handlebars.mjs index 08f5e2fc..24ff8fd7 --- a/bin/handlebars.js +++ b/bin/handlebars.mjs @@ -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); } diff --git a/package.json b/package.json index e3851062..856466cb 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "url": "https://github.com/handlebars-lang/handlebars.js.git" }, "bin": { - "handlebars": "bin/handlebars.js" + "handlebars": "bin/handlebars.mjs" }, "files": [ "bin", diff --git a/spec/expected/help.menu.txt b/spec/expected/help.menu.txt index 44fcca84..82427835 100644 --- a/spec/expected/help.menu.txt +++ b/spec/expected/help.menu.txt @@ -1,5 +1,5 @@ Precompile handlebar templates. -Usage: handlebars.js [template|directory]... +Usage: handlebars.mjs [template|directory]... Options: -f, --output Output File [string] diff --git a/tasks/tests/cli.test.js b/tasks/tests/cli.test.js index 28934d4f..9547a016 100644 --- a/tasks/tests/cli.test.js +++ b/tasks/tests/cli.test.js @@ -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) { diff --git a/tests/integration/multi-nodejs-test/test.sh b/tests/integration/multi-nodejs-test/test.sh index 5dce414e..a0c43d54 100755 --- a/tests/integration/multi-nodejs-test/test.sh +++ b/tests/integration/multi-nodejs-test/test.sh @@ -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