Skip to content

Commit

Permalink
feat: allow CLI to be ESM (#4837)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Apr 29, 2023
1 parent 53bb4d7 commit bb4a5d9
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions bin/webpack-dev-server.js
Expand Up @@ -85,8 +85,18 @@ const runCli = (cli) => {
const pkgPath = require.resolve(`${cli.package}/package.json`);
// eslint-disable-next-line import/no-dynamic-require
const pkg = require(pkgPath);
// eslint-disable-next-line import/no-dynamic-require
require(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName]));

if (pkg.type === "module" || /\.mjs/i.test(pkg.bin[cli.binName])) {
import(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName])).catch(
(error) => {
console.error(error);
process.exitCode = 1;
}
);
} else {
// eslint-disable-next-line import/no-dynamic-require
require(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName]));
}
};

/**
Expand Down

0 comments on commit bb4a5d9

Please sign in to comment.