Skip to content

Commit bb70ea4

Browse files
authored
convert @babel/cli to typescript (#13213)
* babel-cli flowts rename * babel-cli flowts convert * babel-cli * yarn install
1 parent 5def29d commit bb70ea4

File tree

6 files changed

+18
-30
lines changed

6 files changed

+18
-30
lines changed

packages/babel-cli/src/babel-external-helpers.js renamed to packages/babel-cli/src/babel-external-helpers.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @flow
2-
31
import commander from "commander";
42
import { buildExternalHelpers } from "@babel/core";
53

packages/babel-cli/src/babel/dir.js renamed to packages/babel-cli/src/babel/dir.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
// @flow
2-
31
import slash from "slash";
42
import path from "path";
53
import fs from "fs";
64

75
import * as util from "./util";
8-
import { type CmdOptions } from "./options";
6+
import type { CmdOptions } from "./options";
97

108
const FILE_TYPE = Object.freeze({
119
NON_COMPILABLE: "NON_COMPILABLE",
1210
COMPILED: "COMPILED",
1311
IGNORED: "IGNORED",
1412
ERR_COMPILATION: "ERR_COMPILATION",
15-
});
13+
} as const);
1614

1715
function outputFileSync(filePath: string, data: string | Buffer): void {
1816
fs.mkdirSync(path.dirname(filePath), { recursive: true });
@@ -28,7 +26,7 @@ export default async function ({
2826
async function write(
2927
src: string,
3028
base: string,
31-
): Promise<$Keys<typeof FILE_TYPE>> {
29+
): Promise<keyof typeof FILE_TYPE> {
3230
let relative = path.relative(base, src);
3331

3432
if (!util.isCompilableExtension(relative, cliOptions.extensions)) {

packages/babel-cli/src/babel/file.js renamed to packages/babel-cli/src/babel/file.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
// @flow
2-
31
import convertSourceMap from "convert-source-map";
42
import sourceMap from "source-map";
53
import slash from "slash";
64
import path from "path";
75
import fs from "fs";
86

97
import * as util from "./util";
10-
import { type CmdOptions } from "./options";
8+
import type { CmdOptions } from "./options";
119

1210
type CompilationOutput = {
13-
code: string,
14-
map: Object,
11+
code: string;
12+
map: any;
1513
};
1614

1715
export default async function ({
1816
cliOptions,
1917
babelOptions,
2018
}: CmdOptions): Promise<void> {
21-
function buildResult(fileResults: Array<Object>): CompilationOutput {
19+
function buildResult(fileResults: Array<any>): CompilationOutput {
2220
const map = new sourceMap.SourceMapGenerator({
2321
file:
2422
cliOptions.sourceMapTarget ||
@@ -37,7 +35,7 @@ export default async function ({
3735

3836
if (result.map) {
3937
const consumer = new sourceMap.SourceMapConsumer(result.map);
40-
const sources = new Set();
38+
const sources = new Set<string>();
4139

4240
consumer.eachMapping(function (mapping) {
4341
if (mapping.source != null) sources.add(mapping.source);
@@ -104,7 +102,7 @@ export default async function ({
104102
}
105103

106104
function readStdin(): Promise<string> {
107-
return new Promise((resolve: Function, reject: Function): void => {
105+
return new Promise((resolve, reject): void => {
108106
let code = "";
109107

110108
process.stdin.setEncoding("utf8");
@@ -158,7 +156,7 @@ export default async function ({
158156
});
159157

160158
const results = await Promise.all(
161-
_filenames.map(async function (filename: string): Promise<Object> {
159+
_filenames.map(async function (filename: string): Promise<any> {
162160
let sourceFilename = filename;
163161
if (cliOptions.outFile) {
164162
sourceFilename = path.relative(

packages/babel-cli/src/babel/options.js renamed to packages/babel-cli/src/babel/options.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @flow
2-
31
import fs from "fs";
42

53
import commander from "commander";
@@ -170,6 +168,7 @@ commander.option(
170168
"Use a specific extension for the output files",
171169
);
172170

171+
declare const PACKAGE_JSON: { name: string; version: string };
173172
commander.version(PACKAGE_JSON.version + " (@babel/core " + version + ")");
174173
commander.usage("[options] <files ...>");
175174
// register an empty action handler so that commander.js can throw on
@@ -178,8 +177,8 @@ commander.usage("[options] <files ...>");
178177
commander.action(() => {});
179178

180179
export type CmdOptions = {
181-
babelOptions: Object,
182-
cliOptions: Object,
180+
babelOptions: any;
181+
cliOptions: any;
183182
};
184183

185184
export default function parseArgv(args: Array<string>): CmdOptions | null {

packages/babel-cli/src/babel/util.js renamed to packages/babel-cli/src/babel/util.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @flow
2-
31
import readdirRecursive from "fs-readdir-recursive";
42
import * as babel from "@babel/core";
53
import path from "path";
@@ -47,7 +45,7 @@ export function readdirForCompilable(
4745
*/
4846
export function isCompilableExtension(
4947
filename: string,
50-
altExts?: Array<string>,
48+
altExts?: readonly string[],
5149
): boolean {
5250
const exts = altExts || babel.DEFAULT_EXTENSIONS;
5351
const ext = path.extname(filename);
@@ -65,8 +63,8 @@ const CALLER = {
6563
export function transform(
6664
filename: string,
6765
code: string,
68-
opts: Object,
69-
): Promise<Object> {
66+
opts: any,
67+
): Promise<any> {
7068
opts = {
7169
...opts,
7270
caller: CALLER,
@@ -81,10 +79,7 @@ export function transform(
8179
});
8280
}
8381

84-
export function compile(
85-
filename: string,
86-
opts: Object | Function,
87-
): Promise<Object> {
82+
export function compile(filename: string, opts: any | Function): Promise<any> {
8883
opts = {
8984
...opts,
9085
caller: CALLER,
@@ -119,7 +114,7 @@ process.on("uncaughtException", function (err) {
119114
process.exitCode = 1;
120115
});
121116

122-
export function requireChokidar(): Object {
117+
export function requireChokidar(): any {
123118
// $FlowIgnore - https://github.com/facebook/flow/issues/6913#issuecomment-662787504
124119
const require = createRequire(import /*::("")*/.meta.url);
125120

0 commit comments

Comments
 (0)