feat: allow CLI to be ESM
This commit is contained in:
parent
5b20c9af1c
commit
6ce8ad2d7a
|
@ -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: {
|
||||
|
|
|
@ -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]));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue