Repository: babel/babel
File: packages/babel-cli/src/babel/options.ts (TypeScript)

Code before:
    outDir: string;
    relative: boolean;
    copyFiles: boolean;
    copyIgnored: boolean;
    includeDotfiles: boolean;
    verbose: boolean;
    quiet: boolean;
    deleteDirOnStart: boolean;
    sourceMapTarget: string;
  };
};

export default function parseArgv(args: Array<string>): CmdOptions | null {
  //
  commander.parse(args);

  const errors: string[] = [];

  let filenames = commander.args.reduce(function (globbed: string[], input) {
    let files = process.env.BABEL_8_BREAKING
      ? // glob 9+ no longer sorts the result, here we maintain the glob 7 behaviour
        // https://github.com/isaacs/node-glob/blob/c3cd57ae128faa0e9190492acc743bb779ac4054/common.js#L151
        globSync(input, { dotRelative: true }).sort(function alphasort(a, b) {
          return a.localeCompare(b, "en");
        })
      : globSync(input);
    if (!files.length) files = [input];
    globbed.push(...files);
    return globbed;
  }, []);

  filenames = Array.from(new Set(filenames));

  filenames.forEach(function (filename) {
    if (!fs.existsSync(filename)) {
      errors.push(filename + " does not exist");
    }
  });

  if (commander.outDir && !filenames.length) {
    errors.push("--out-dir requires filenames");
  }

  if (commander.outFile && commander.outDir) {
    errors.push("--out-file and --out-dir cannot be used together");
  }

  if (commander.relative && !commander.outDir) {
    errors.push("--relative requires --out-dir usage");
  }


Review comment (suggestion):
Instead of using the plugin, would this work?

```js
import * as glob from "glob";
```
```suggestion
    let files = process.env.BABEL_8_BREAKING
      ? // glob 9+ no longer sorts the result, here we maintain the glob 7 behaviour
        // https://github.com/isaacs/node-glob/blob/c3cd57ae128faa0e9190492acc743bb779ac4054/common.js#L151
        (USE_ESM ? glob.default : glob).sync(input, { dotRelative: true }).sort(function alphasort(a, b) {
          return a.localeCompare(b, "en");
        })
      : glob.sync(input);
```

Code after:
    outDir: string;
    relative: boolean;
    copyFiles: boolean;
    copyIgnored: boolean;
    includeDotfiles: boolean;
    verbose: boolean;
    quiet: boolean;
    deleteDirOnStart: boolean;
    sourceMapTarget: string;
  };
};

export default function parseArgv(args: Array<string>): CmdOptions | null {
  //
  commander.parse(args);

  const errors: string[] = [];

  let filenames = commander.args.reduce(function (globbed: string[], input) {
    let files = process.env.BABEL_8_BREAKING
      ? // glob 9+ no longer sorts the result, here we maintain the glob 7 behaviour
        // https://github.com/isaacs/node-glob/blob/c3cd57ae128faa0e9190492acc743bb779ac4054/common.js#L151
        glob.sync(input, { dotRelative: true }).sort(function alphasort(a, b) {
          return a.localeCompare(b, "en");
        })
      : // @ts-expect-error When USE_ESM is true and BABEL_8_BREAKING is off,
        // the glob package is an ESM wrapper of the CJS glob 7
        (USE_ESM ? glob.default.sync : glob.sync)(input);
    if (!files.length) files = [input];
    globbed.push(...files);
    return globbed;
  }, []);

  filenames = Array.from(new Set(filenames));

  filenames.forEach(function (filename) {
    if (!fs.existsSync(filename)) {
      errors.push(filename + " does not exist");
    }
  });

  if (commander.outDir && !filenames.length) {
    errors.push("--out-dir requires filenames");
  }

  if (commander.outFile && commander.outDir) {
    errors.push("--out-file and --out-dir cannot be used together");
  }

  if (commander.relative && !commander.outDir) {
    errors.push("--relative requires --out-dir usage");