From c821d3a59141d125c067363049a15b841360fd37 Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Tue, 26 Sep 2017 09:38:18 -0500 Subject: [PATCH] Updates for handling codemods folder (#6279) * add codemod folder to gitignore, update build/test scripts to handle codemods, lerna config --- .gitignore | 2 + Gulpfile.js | 77 +++++++++++-------- Makefile | 55 +++++++++---- .../lib/index.js | 37 --------- .../package.json | 4 +- .../options.json | 3 - .../options.json | 1 + .../try-catch-block-null-binding/options.json | 3 + .../options.json | 3 + .../options.json | 3 + .../options.json | 3 + .../options.json | 3 + .../options.json | 3 + .../try-catch-block-used-binding/options.json | 3 + .../options.json | 3 + .../options.json | 3 + .../options.json | 3 + lerna.json | 9 ++- package.json | 1 + scripts/_get-test-directories.sh | 26 ++++--- yarn.lock | 8 +- 21 files changed, 149 insertions(+), 104 deletions(-) delete mode 100644 codemods/babel-plugin-codemod-optional-catch-binding/lib/index.js delete mode 100644 codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/options.json create mode 100644 codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-null-binding/options.json create mode 100644 codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-unused-array-pattern-binding/options.json create mode 100644 codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-unused-binding/options.json create mode 100644 codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-unused-object-pattern-binding/options.json create mode 100644 codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-used-array-pattern-binding/options.json create mode 100644 codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-used-binding-variable/options.json create mode 100644 codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-used-binding/options.json create mode 100644 codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-used-object-pattern-binding/options.json create mode 100644 codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-finally-unused-binding/options.json create mode 100644 codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-finally-used-binding/options.json diff --git a/.gitignore b/.gitignore index adf691453e..7087f6e030 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,5 @@ package-lock.json /babel.sublime-workspace packages/babel-standalone/babel.js packages/babel-standalone/babel.min.js +/codemods/*/lib +/codemods/*/node_modules diff --git a/Gulpfile.js b/Gulpfile.js index 04535b387b..0048919d8f 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -9,9 +9,9 @@ const watch = require("gulp-watch"); const gutil = require("gulp-util"); const gulp = require("gulp"); const path = require("path"); +const merge = require("merge-stream"); -const base = path.join(__dirname, "packages"); -const scripts = "./packages/*/src/**/*.js"; +const sources = ["codemods", "packages"]; function swapSrcWithLib(srcPath) { const parts = srcPath.split(path.sep); @@ -19,43 +19,54 @@ function swapSrcWithLib(srcPath) { return parts.join(path.sep); } +function getGlobFromSource(source) { + return `./${source}/*/src/**/*.js`; +} + gulp.task("default", ["build"]); gulp.task("build", function() { - return gulp - .src(scripts, { base: base }) - .pipe( - plumber({ - errorHandler: function(err) { - gutil.log(err.stack); - }, - }) - ) - .pipe( - newer({ - dest: base, - map: swapSrcWithLib, - }) - ) - .pipe( - through.obj(function(file, enc, callback) { - gutil.log("Compiling", "'" + chalk.cyan(file.relative) + "'..."); - callback(null, file); - }) - ) - .pipe(babel()) - .pipe( - through.obj(function(file, enc, callback) { - // Passing 'file.relative' because newer() above uses a relative path and this keeps it consistent. - file.path = path.resolve(file.base, swapSrcWithLib(file.relative)); - callback(null, file); - }) - ) - .pipe(gulp.dest(base)); + return merge( + sources.map(source => { + const base = path.join(__dirname, source); + + return gulp + .src(getGlobFromSource(source), { base: base }) + .pipe( + plumber({ + errorHandler: function(err) { + gutil.log(err.stack); + }, + }) + ) + .pipe( + newer({ + dest: base, + map: swapSrcWithLib, + }) + ) + .pipe( + through.obj(function(file, enc, callback) { + gutil.log("Compiling", "'" + chalk.cyan(file.relative) + "'..."); + callback(null, file); + }) + ) + .pipe(babel()) + .pipe( + through.obj(function(file, enc, callback) { + // Passing 'file.relative' because newer() above uses a relative + // path and this keeps it consistent. + file.path = path.resolve(file.base, swapSrcWithLib(file.relative)); + callback(null, file); + }) + ) + .pipe(gulp.dest(base)); + }) + ); }); gulp.task("watch", ["build"], function() { - watch(scripts, { debounceDelay: 200 }, function() { + watch(sources.map(getGlobFromSource), { debounceDelay: 200 }, function() { gulp.start("build"); }); }); diff --git a/Makefile b/Makefile index cb37594bf1..d91ca05ac7 100644 --- a/Makefile +++ b/Makefile @@ -5,10 +5,12 @@ export NODE_ENV = test # Fix color output until TravisCI fixes https://github.com/travis-ci/travis-ci/issues/7967 export FORCE_COLOR = true +SOURCES = packages codemods + .PHONY: build build-dist watch lint fix clean test-clean test-only test test-ci publish bootstrap build: clean - rm -rf packages/*/lib + make clean-lib ./node_modules/.bin/gulp build ifneq ($(BABEL_ENV), "cov") make build-standalone @@ -25,17 +27,17 @@ build-dist: build node scripts/generate-babel-types-docs.js watch: clean - rm -rf packages/*/lib + make clean-lib BABEL_ENV=development ./node_modules/.bin/gulp watch lint: - ./node_modules/.bin/eslint scripts packages *.js --format=codeframe --rulesdir="./eslint_rules" + ./node_modules/.bin/eslint scripts $(SOURCES) *.js --format=codeframe --rulesdir="./eslint_rules" flow: ./node_modules/.bin/flow check --strip-root fix: - ./node_modules/.bin/eslint scripts packages *.js --format=codeframe --fix --rulesdir="./eslint_rules" + ./node_modules/.bin/eslint scripts $(SOURCES) *.js --format=codeframe --fix --rulesdir="./eslint_rules" clean: test-clean rm -rf packages/babel-polyfill/browser* @@ -46,16 +48,8 @@ clean: test-clean rm -rf packages/*/npm-debug* test-clean: - rm -rf packages/*/test/tmp - rm -rf packages/*/test-fixtures.json - -clean-all: - rm -rf packages/*/lib - rm -rf node_modules - rm -rf packages/*/node_modules - rm -rf package-lock.json - rm -rf packages/*/package-lock.json - make clean + $(foreach source, $(SOURCES), \ + $(call clean-source-test, $(source))) test-only: ./scripts/test.sh @@ -75,7 +69,7 @@ test-ci-coverage: publish: git pull --rebase - rm -rf packages/*/lib + make clean-lib BABEL_ENV=production make build-dist make test # not using lerna independent mode atm, so only update packages that have changed since we use ^ @@ -90,3 +84,34 @@ bootstrap: make build cd packages/babel-runtime; \ node scripts/build-dist.js + +clean-lib: + $(foreach source, $(SOURCES), \ + $(call clean-source-lib, $(source))) + +clean-all: + rm -rf node_modules + rm -rf package-lock.json + + $(foreach source, $(SOURCES), \ + $(call clean-source-all, $(source))) + + make clean + +define clean-source-lib + rm -rf $(1)/*/lib + +endef + +define clean-source-test + rm -rf $(1)/*/test/tmp + rm -rf $(1)/*/test-fixtures.json + +endef + +define clean-source-all + rm -rf $(1)/*/lib + rm -rf $(1)/*/node_modules + rm -rf $(1)/*/package-lock.json + +endef diff --git a/codemods/babel-plugin-codemod-optional-catch-binding/lib/index.js b/codemods/babel-plugin-codemod-optional-catch-binding/lib/index.js deleted file mode 100644 index 5b11208e27..0000000000 --- a/codemods/babel-plugin-codemod-optional-catch-binding/lib/index.js +++ /dev/null @@ -1,37 +0,0 @@ -"use strict"; - -exports.__esModule = true; - -exports.default = function (babel) { - const { - types: t - } = babel; - return { - inherits: _babelPluginSyntaxOptionalCatchBinding2.default, - visitor: { - CatchClause(path) { - if (path.node.param === null || !t.isIdentifier(path.node.param)) { - return; - } - - const binding = path.scope.getOwnBinding(path.node.param.name); - - if (binding.constantViolations.length > 0) { - return; - } - - if (!binding.referenced) { - const paramPath = path.get("param"); - paramPath.remove(); - } - } - - } - }; -}; - -var _babelPluginSyntaxOptionalCatchBinding = require("babel-plugin-syntax-optional-catch-binding"); - -var _babelPluginSyntaxOptionalCatchBinding2 = _interopRequireDefault(_babelPluginSyntaxOptionalCatchBinding); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } \ No newline at end of file diff --git a/codemods/babel-plugin-codemod-optional-catch-binding/package.json b/codemods/babel-plugin-codemod-optional-catch-binding/package.json index da1d86c0ba..0e5771dc99 100644 --- a/codemods/babel-plugin-codemod-optional-catch-binding/package.json +++ b/codemods/babel-plugin-codemod-optional-catch-binding/package.json @@ -9,9 +9,9 @@ "babel-plugin" ], "dependencies": { - "babel-plugin-syntax-optional-catch-binding": "7.0.0-beta.0" + "babel-plugin-syntax-optional-catch-binding": "7.0.0-beta.1" }, "devDependencies": { - "babel-helper-plugin-test-runner": "7.0.0-beta.0" + "babel-helper-plugin-test-runner": "7.0.0-beta.1" } } diff --git a/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/options.json b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/options.json deleted file mode 100644 index bfd6f2e628..0000000000 --- a/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["transform-remove-unused-catch-binding"] -} diff --git a/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-duplicate-variable-declaration/options.json b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-duplicate-variable-declaration/options.json index f451b42655..ab01b7471a 100644 --- a/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-duplicate-variable-declaration/options.json +++ b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-duplicate-variable-declaration/options.json @@ -1,3 +1,4 @@ { + "plugins": ["../../../../lib"], "throws": "Duplicate declaration \"e\"" } diff --git a/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-null-binding/options.json b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-null-binding/options.json new file mode 100644 index 0000000000..cbe0e98937 --- /dev/null +++ b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-null-binding/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["../../../../lib"] +} diff --git a/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-unused-array-pattern-binding/options.json b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-unused-array-pattern-binding/options.json new file mode 100644 index 0000000000..cbe0e98937 --- /dev/null +++ b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-unused-array-pattern-binding/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["../../../../lib"] +} diff --git a/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-unused-binding/options.json b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-unused-binding/options.json new file mode 100644 index 0000000000..cbe0e98937 --- /dev/null +++ b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-unused-binding/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["../../../../lib"] +} diff --git a/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-unused-object-pattern-binding/options.json b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-unused-object-pattern-binding/options.json new file mode 100644 index 0000000000..cbe0e98937 --- /dev/null +++ b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-unused-object-pattern-binding/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["../../../../lib"] +} diff --git a/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-used-array-pattern-binding/options.json b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-used-array-pattern-binding/options.json new file mode 100644 index 0000000000..cbe0e98937 --- /dev/null +++ b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-used-array-pattern-binding/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["../../../../lib"] +} diff --git a/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-used-binding-variable/options.json b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-used-binding-variable/options.json new file mode 100644 index 0000000000..cbe0e98937 --- /dev/null +++ b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-used-binding-variable/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["../../../../lib"] +} diff --git a/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-used-binding/options.json b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-used-binding/options.json new file mode 100644 index 0000000000..cbe0e98937 --- /dev/null +++ b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-used-binding/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["../../../../lib"] +} diff --git a/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-used-object-pattern-binding/options.json b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-used-object-pattern-binding/options.json new file mode 100644 index 0000000000..cbe0e98937 --- /dev/null +++ b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-block-used-object-pattern-binding/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["../../../../lib"] +} diff --git a/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-finally-unused-binding/options.json b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-finally-unused-binding/options.json new file mode 100644 index 0000000000..cbe0e98937 --- /dev/null +++ b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-finally-unused-binding/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["../../../../lib"] +} diff --git a/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-finally-used-binding/options.json b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-finally-used-binding/options.json new file mode 100644 index 0000000000..0587911559 --- /dev/null +++ b/codemods/babel-plugin-codemod-optional-catch-binding/test/fixtures/codemod-optional-catch-binding/try-catch-finally-used-binding/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["../../../../lib"] + } diff --git a/lerna.json b/lerna.json index af26dc1cb7..512ab7db58 100644 --- a/lerna.json +++ b/lerna.json @@ -18,8 +18,13 @@ "publish": { "ignore": [ "*.md", - "test/**" + "test/**", + "codemods/**" ] } - } + }, + "packages": [ + "packages/*", + "codemods/*" + ] } diff --git a/package.json b/package.json index d860084b7c..40f35d2fac 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "lerna-changelog": "^0.5.0", "lint-staged": "^4.0.4", "lodash": "^4.2.0", + "merge-stream": "^1.0.1", "mocha": "^3.0.0", "nyc": "^11.0.3", "output-file-sync": "^2.0.0", diff --git a/scripts/_get-test-directories.sh b/scripts/_get-test-directories.sh index 3af84d1594..108f16decf 100755 --- a/scripts/_get-test-directories.sh +++ b/scripts/_get-test-directories.sh @@ -3,18 +3,22 @@ set -e TEST_DIRS="" -for f in packages/*; do - if [ -n "$TEST_ONLY" ] && [[ `basename $f` != *"$TEST_ONLY"* ]]; then - continue - fi - # Exclude babel-standalone from coverage runs - if [ "$TEST_TYPE" = "cov" ] && [ `basename $f` = 'babel-standalone' ]; then - continue - fi +sources=("packages" "codemods") - if [ -d "$f/test" ]; then - TEST_DIRS="$f/test $TEST_DIRS" - fi +for source in "${sources[@]}"; do + for f in $source/*; do + if [ -n "$TEST_ONLY" ] && [[ `basename $f` != *"$TEST_ONLY"* ]]; then + continue + fi + # Exclude babel-standalone from coverage runs + if [ "$TEST_TYPE" = "cov" ] && [ `basename $f` = 'babel-standalone' ]; then + continue + fi + + if [ -d "$f/test" ]; then + TEST_DIRS="$f/test $TEST_DIRS" + fi + done done echo $TEST_DIRS diff --git a/yarn.lock b/yarn.lock index b83e060eb1..1555f0cff2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3952,6 +3952,12 @@ merge-source-map@^1.0.2: dependencies: source-map "^0.5.6" +merge-stream@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-1.0.1.tgz#4041202d508a342ba00174008df0c251b8c135e1" + dependencies: + readable-stream "^2.0.1" + micromatch@^2.1.5, micromatch@^2.3.11, micromatch@^2.3.7: version "2.3.11" resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565" @@ -4707,7 +4713,7 @@ read-pkg@^2.0.0: isarray "0.0.1" string_decoder "~0.10.x" -readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.1.4, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.2.6: +readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.1.4, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.2.6: version "2.3.3" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.3.tgz#368f2512d79f9d46fdfc71349ae7878bbc1eb95c" dependencies: