Skip to content

Commit

Permalink
Prepare repository for gradual flow->ts migration (babel#12317)
Browse files Browse the repository at this point in the history
Co-authored-by: Bogdan Savluk <savluk.bogdan@gmail.com>
  • Loading branch information
nicolo-ribaudo and zxbodya committed Nov 9, 2020
1 parent 3227914 commit fbd3b0e
Show file tree
Hide file tree
Showing 16 changed files with 523 additions and 203 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ packages/babel-runtime-corejs2
packages/babel-runtime-corejs3
packages/*/node_modules
packages/*/lib
packages/*/dts
packages/*/dist
packages/*/test/fixtures
packages/*/test/tmp
Expand Down
25 changes: 19 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,24 @@ module.exports = {
node: true,
},
overrides: [
{
files: ["**/*.ts"],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
rules: {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"no-dupe-class-members": "off",
"@typescript-eslint/no-dupe-class-members": "error",
"no-undef": "off",
"no-redeclare": "off",
},
},
{
files: [
"packages/*/src/**/*.js",
"codemods/*/src/**/*.js",
"eslint/*/src/**/*.js",
"packages/*/src/**/*.{js,ts}",
"codemods/*/src/**/*.{js,ts}",
"eslint/*/src/**/*.{js,ts}",
],
rules: {
"@babel/development/no-undefined-identifier": "error",
Expand All @@ -37,7 +50,7 @@ module.exports = {
"packages/*/test/**/*.js",
"codemods/*/test/**/*.js",
"eslint/*/test/**/*.js",
"packages/babel-helper-transform-fixture-test-runner/src/helpers.js",
"packages/babel-helper-transform-fixture-test-runner/src/helpers.{ts,js}",
"test/**/*.js",
],
env: {
Expand All @@ -53,15 +66,15 @@ module.exports = {
},
},
{
files: ["packages/babel-plugin-*/src/index.js"],
files: ["packages/babel-plugin-*/src/index.{js,ts}"],
excludedFiles: ["packages/babel-plugin-transform-regenerator/**/*.js"],
rules: {
"@babel/development/plugin-name": "error",
eqeqeq: ["error", "always", { null: "ignore" }],
},
},
{
files: ["packages/babel-parser/src/**/*.js"],
files: ["packages/babel-parser/src/**/*.{js,ts}"],
rules: {
"@babel/development-internal/dry-error-messages": [
"error",
Expand Down
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ lib/parser.js
lib/third-party-libs.js.flow
lib/preset-modules.js.flow
packages/babel-types/lib/index.js.flow
lib/babel-packages.js.flow

[options]
include_warnings=true
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,10 @@ packages/babel-standalone/babel.min.js
/eslint/*/LICENSE
!/packages/babel-eslint-plugin/LICENSE
/.vscode

/tsconfig.json
/packages/*/tsconfig.json
/packages/*/tsconfig.tsbuildinfo
/packages/*/dts
/codemods/*/dts
/eslint/*/dts
7 changes: 3 additions & 4 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
"printWidth": 80,
"overrides": [{
"files": [
"**/codemods/*/src/**/*.js",
"**/codemods/*/src/**/*.{js,ts}",
"**/codemods/*/test/**/*.js",
"**/packages/*/src/**/*.js",
"**/packages/*/src/**/*.{js,ts}",
"**/packages/*/test/**/*.js",
"**/eslint/*/src/**/*.js",
"**/eslint/*/src/**/*.{js,ts}",
"**/eslint/*/test/**/*.js"
],
"options": {
"parser": "babel",
"trailingComma": "all"
}
}]
Expand Down
14 changes: 11 additions & 3 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const fancyLog = require("fancy-log");
const filter = require("gulp-filter");
const gulp = require("gulp");
const path = require("path");
const fs = require("fs");
const rollup = require("rollup");
const rollupBabel = require("@rollup/plugin-babel").default;
const rollupBabelSource = require("./scripts/rollup-plugin-babel-source");
Expand All @@ -19,7 +20,7 @@ const rollupNodeResolve = require("@rollup/plugin-node-resolve").default;
const rollupReplace = require("@rollup/plugin-replace");
const { terser: rollupTerser } = require("rollup-plugin-terser");

const defaultSourcesGlob = "./@(codemods|packages|eslint)/*/src/**/*.js";
const defaultSourcesGlob = "./@(codemods|packages|eslint)/*/src/**/*.{js,ts}";

function swapSrcWithLib(srcPath) {
const parts = srcPath.split(path.sep);
Expand All @@ -28,7 +29,12 @@ function swapSrcWithLib(srcPath) {
}

function getIndexFromPackage(name) {
return `${name}/src/index.js`;
try {
fs.statSync(`./${name}/src/index.ts`);
return `${name}/src/index.ts`;
} catch {
return `${name}/src/index.js`;
}
}

function compilationLogger() {
Expand Down Expand Up @@ -121,8 +127,10 @@ function buildRollup(packages) {
babelrc: false,
babelHelpers: "bundled",
extends: "./babel.config.js",
extensions: [".mjs", ".cjs", ".ts", ".js"],
}),
rollupNodeResolve({
extensions: [".mjs", ".cjs", ".ts", ".js", ".json"],
browser: nodeResolveBrowser,
preferBuiltins: true,
//todo: remove when semver and source-map are bumped to latest versions
Expand All @@ -142,7 +150,7 @@ function buildRollup(packages) {
rollupJson(),
rollupNodePolyfills({
sourceMap: sourcemap,
include: "**/*.js",
include: "**/*.{js,ts}",
}),
],
});
Expand Down
25 changes: 20 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ build-bundle: clean clean-lib
build-bundle-ci: bootstrap-only
$(MAKE) build-bundle

generate-tsconfig:
$(NODE) scripts/generators/tsconfig.js

generate-standalone:
$(NODE) packages/babel-standalone/scripts/generate.js

Expand Down Expand Up @@ -85,12 +88,15 @@ watch: build-no-bundle
BABEL_ENV=development $(YARN) gulp watch

code-quality-ci: build-no-bundle-ci
$(MAKE) flowcheck-ci lint-ci
$(MAKE) tscheck flowcheck-ci lint-ci

flowcheck-ci:
$(MAKE) flow

code-quality: flow lint
code-quality: tscheck flow lint

tscheck: generate-tsconfig
$(YARN) tsc -b .

flow:
$(YARN) flow check --strip-root
Expand All @@ -109,15 +115,15 @@ check-compat-data-ci:
lint: lint-js lint-ts

lint-js:
BABEL_ENV=test $(YARN) eslint scripts $(SOURCES) '*.js' --format=codeframe
BABEL_ENV=test $(YARN) eslint scripts $(SOURCES) '*.{js,ts}' --format=codeframe --ext .js,.cjs,.mjs,.ts

lint-ts:
scripts/lint-ts-typings.sh

fix: fix-json fix-js

fix-js:
$(YARN) eslint scripts $(SOURCES) '*.js' --format=codeframe --fix
$(YARN) eslint scripts $(SOURCES) '*.{js,ts}' --format=codeframe --ext .js,.cjs,.mjs,.ts --fix

fix-json:
$(YARN) prettier "{$(COMMA_SEPARATED_SOURCES)}/*/test/fixtures/**/options.json" --write --loglevel warn
Expand All @@ -136,6 +142,10 @@ clean: test-clean
rm -rf packages/*/npm-debug*
rm -rf node_modules/.cache

clean-tsconfig:
rm -f tsconfig.json
rm -f packages/*/tsconfig.json

test-clean:
$(foreach source, $(SOURCES), \
$(call clean-source-test, $(source)))
Expand Down Expand Up @@ -211,12 +221,17 @@ clone-license:
prepublish-build: clean-lib clean-runtime-helpers
NODE_ENV=production BABEL_ENV=production $(MAKE) build-bundle
$(MAKE) prepublish-build-standalone clone-license
# We don't want to publish .d.ts files yet
rm -rf packages/*/dts

prepublish:
$(MAKE) check-yarn-bug-1882
$(MAKE) bootstrap-only
$(MAKE) prepublish-build
IS_PUBLISH=true $(MAKE) test
# We don't want to use modern TS features in published @babel/types typings,
# to avoid breaking backward compatibility.
PRODUCTION_TS_TYPES=true $(MAKE) build-typings

new-version:
git pull --rebase
Expand Down Expand Up @@ -271,7 +286,7 @@ clean-runtime-helpers:
rm -f packages/babel-runtime-corejs3/helpers/**/*.js
rm -rf packages/babel-runtime-corejs2/core-js

clean-all:
clean-all: clean-tsconfig
rm -rf node_modules
rm -rf package-lock.json
rm -rf .changelog
Expand Down
4 changes: 4 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ module.exports = function (api) {
.filter(Boolean)
.map(normalize),
presets: [
[
"@babel/preset-typescript",
{ onlyRemoveTypeImports: true, allowDeclareFields: true },
],
["@babel/env", envOpts],
["@babel/preset-flow", { allowDeclareFields: true }],
],
Expand Down
Empty file added lib/babel-packages.js.flow
Empty file.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@
"@babel/plugin-transform-runtime": "^7.12.0",
"@babel/preset-env": "^7.12.0",
"@babel/preset-flow": "^7.10.4",
"@babel/preset-typescript": "^7.12.1",
"@babel/register": "^7.12.0",
"@babel/runtime": "^7.12.0",
"@rollup/plugin-babel": "^5.2.0",
"@rollup/plugin-commonjs": "^13.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-replace": "^2.3.3",
"@typescript-eslint/eslint-plugin": "^4.6.1",
"@typescript-eslint/parser": "^4.6.1",
"babel-plugin-transform-charcodes": "^0.2.0",
"chalk": "^2.4.2",
"charcodes": "^0.2.0",
Expand Down Expand Up @@ -61,7 +64,7 @@
"rollup-plugin-terser": "^7.0.0",
"test262-stream": "^1.3.0",
"through2": "^2.0.0",
"typescript": "^3.6.3"
"typescript": "^4.0.5"
},
"workspaces": [
"codemods/*",
Expand All @@ -78,7 +81,7 @@
"yarn": ">=1.4.0"
},
"lint-staged": {
"*.js": [
"*.{js,ts}": [
"eslint --format=codeframe"
]
},
Expand Down

0 comments on commit fbd3b0e

Please sign in to comment.