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

Code before:
    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) {
    if (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
      // eslint-disable-next-line no-var
      var files = globSync(input, { dotRelative: true }).sort(
        function alphasort(a, b) {
          return a.localeCompare(b, "en");
        },
      );
    } else {
      files = 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):
```suggestion
    let files = globSync(input, { dotRelative: true });
    if (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
      files.sort(
        function alphasort(a, b) {
          return a.localeCompare(b, "en");
        },
      );
    }
```

Curious if this works (to avoid `var` in the Babel 8 code, minimizing the manual changes when we'll codemod away `process.env.BABEL_8_BREAKING`).

Code after:
    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");
  }

  if (commander.watch) {
    if (!commander.outFile && !commander.outDir) {
      errors.push("--watch requires --out-file or --out-dir");