feat: allow CLI to be ESM

This commit is contained in:
alexander.akait 2023-04-28 15:49:05 +03:00
parent 5b20c9af1c
commit 6ce8ad2d7a
2 changed files with 20 additions and 2 deletions

View File

@ -77,6 +77,13 @@ module.exports = {
}
},
overrides: [
{
// Allow to use `dynamic` import
files: ["bin/**/*.js"],
parserOptions: {
ecmaVersion: 2020
}
},
{
files: ["lib/**/*.runtime.js", "hot/*.js"],
env: {

View File

@ -78,8 +78,19 @@ const runCli = cli => {
const pkgPath = require.resolve(`${cli.package}/package.json`);
// eslint-disable-next-line node/no-missing-require
const pkg = require(pkgPath);
// eslint-disable-next-line node/no-missing-require
require(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName]));
if (pkg.type === "module" || /\.mjs/i.test(pkg.bin[cli.binName])) {
// eslint-disable-next-line node/no-unsupported-features/es-syntax
import(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName])).catch(
error => {
console.error(error);
process.exitCode = 1;
}
);
} else {
// eslint-disable-next-line node/no-missing-require
require(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName]));
}
};
/**