Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make most make commands cross-platform #14671

Merged
merged 12 commits into from Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -114,9 +114,12 @@ jobs:
env:
BABEL_8_BREAKING: false
STRIP_BABEL_8_FLAG: true
- name: Build Makefile.js
run: |
node ./scripts/pack-script.js
- name: Ensure cwd does not contain uncommitted changes
run: |
./scripts/assert-dir-git-clean.sh
node ./scripts/assert-dir-git-clean.js
- uses: actions/upload-artifact@v3
with:
name: babel-artifact
Expand Down Expand Up @@ -149,9 +152,8 @@ jobs:
BABEL_8_BREAKING: false
STRIP_BABEL_8_FLAG: true
- name: Ensure cwd does not contain uncommitted changes
shell: bash
run: |
./scripts/assert-dir-git-clean.sh
node ./scripts/assert-dir-git-clean.js

lint:
name: Lint
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Expand Up @@ -43,8 +43,8 @@ _Yarn_: Make sure that Yarn 1 is [installed](https://classic.yarnpkg.com/en/docs

_Make_: If you are running Windows 10, you'll need to do one of the following:

- Clone the repository and run the commands inside [WSL 2](https://docs.microsoft.com/en-us/windows/wsl/install-win10).
- Install [Make for Windows](http://gnuwin32.sourceforge.net/packages/make.htm).
- Run the commands inside [WSL 2](https://docs.microsoft.com/en-us/windows/wsl/install-win10).
- Using make normally (`make` or `./make`), it will automatically call the cross-platform `Makefile.mjs`. (There may be a small part of the function not implemented.)

### Setup

Expand Down
35 changes: 17 additions & 18 deletions Gulpfile.mjs
Expand Up @@ -673,24 +673,23 @@ gulp.task(
)
);

gulp.task(
"watch",
gulp.series("build-dev", function watch() {
gulp.watch(defaultSourcesGlob, gulp.task("build-no-bundle-watch"));
gulp.watch(
babelStandalonePluginConfigGlob,
gulp.task("generate-standalone")
);
gulp.watch(buildTypingsWatchGlob, gulp.task("generate-type-helpers"));
function watch() {
gulp.watch(defaultSourcesGlob, gulp.task("build-no-bundle-watch"));
gulp.watch(babelStandalonePluginConfigGlob, gulp.task("generate-standalone"));
gulp.watch(buildTypingsWatchGlob, gulp.task("generate-type-helpers"));
gulp.watch(
"./packages/babel-helpers/src/helpers/*.js",
gulp.task("generate-runtime-helpers")
);
if (USE_ESM) {
gulp.watch(
"./packages/babel-helpers/src/helpers/*.js",
gulp.task("generate-runtime-helpers")
cjsBundles.map(({ src }) => `./${src}/lib/**.js`),
gulp.task("build-cjs-bundles")
);
if (USE_ESM) {
gulp.watch(
cjsBundles.map(({ src }) => `./${src}/lib/**.js`),
gulp.task("build-cjs-bundles")
);
}
})
}
}

gulp.task(
"watch",
process.env.WATCH_SKIP_BUILD ? watch : gulp.series("build-dev", watch)
);
206 changes: 72 additions & 134 deletions Makefile
Expand Up @@ -14,110 +14,127 @@ COMMA_SEPARATED_SOURCES = $(subst $(SPACE),$(COMMA),$(SOURCES))

YARN := yarn
NODE := $(YARN) node
MAKEJS := node Makefile.js


.PHONY: build build-dist watch lint fix clean test-clean test-only test test-ci publish bootstrap use-esm use-cjs

build: build-no-bundle
ifneq ("$(BABEL_COVERAGE)", "true")
$(MAKE) build-standalone
endif
build:
$(MAKEJS) build

build-bundle: clean clean-lib
node ./scripts/set-module-type.js
$(YARN) gulp build
$(MAKE) build-flow-typings
$(MAKE) build-dist
build-bundle:
$(MAKEJS) build-bundle

build-no-bundle-ci: bootstrap-only
$(YARN) gulp build-dev
$(MAKE) build-flow-typings
$(MAKE) build-dist

build-no-bundle: clean clean-lib
node ./scripts/set-module-type.js
BABEL_ENV=development $(YARN) gulp build-dev
$(MAKE) build-flow-typings
$(MAKE) build-dist
build-no-bundle:
$(MAKEJS) build-no-bundle

generate-tsconfig:
$(NODE) scripts/generators/tsconfig.js
$(NODE) scripts/generators/archived-libs-typings.js
$(MAKEJS) generate-tsconfig

generate-type-helpers:
$(YARN) gulp generate-type-helpers
$(MAKEJS) generate-type-helpers

build-flow-typings:
$(NODE) packages/babel-types/scripts/generators/flow.js > packages/babel-types/lib/index.js.flow
$(MAKEJS) build-flow-typings

# For TypeScript older than 3.7
build-typescript-legacy-typings:
$(NODE) packages/babel-types/scripts/generators/typescript-legacy.js > packages/babel-types/lib/index-legacy.d.ts
$(MAKEJS) build-typescript-legacy-typings

build-standalone: build-babel-standalone
build-standalone:
$(MAKEJS) build-standalone

build-standalone-ci: build-no-bundle-ci
$(MAKE) build-standalone

build-babel-standalone:
$(YARN) gulp build-babel-standalone
$(MAKEJS) build-standalone

prepublish-build-standalone:
BABEL_ENV=production IS_PUBLISH=true $(YARN) gulp build-babel-standalone
$(MAKEJS) prepublish-build-standalone

build-dist: build-plugin-transform-runtime-dist

build-plugin-transform-runtime-dist:
cd packages/babel-plugin-transform-runtime; \
$(NODE) scripts/build-dist.js
$(MAKEJS) build-plugin-transform-runtime-dist

watch: build-no-bundle
BABEL_ENV=development $(YARN) gulp watch
watch:
$(MAKEJS) watch

code-quality: tscheck lint

tscheck: generate-tsconfig
rm -rf dts
$(YARN) tsc -b .
tscheck:
$(MAKEJS) tscheck

lint-ci: lint check-compat-data-ci

check-compat-data-ci:
$(MAKE) check-compat-data
check-compat-data-ci: check-compat-data

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

fix: fix-json fix-js

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

fix-json:
$(YARN) prettier "{$(COMMA_SEPARATED_SOURCES)}/*/test/fixtures/**/options.json" --write --loglevel warn
$(MAKEJS) fix-json

check-compat-data:
cd packages/babel-compat-data; CHECK_COMPAT_DATA=true $(YARN) run build-data
clean:
$(MAKEJS) clean

build-compat-data:
cd packages/babel-compat-data; $(YARN) run build-data
test: lint test-only

clone-license:
$(MAKEJS) clone-license

prepublish-build:
$(MAKEJS) prepublish-build

prepublish:
$(MAKEJS) prepublish

clean: test-clean
rm -f .npmrc
rm -rf coverage
rm -rf packages/*/npm-debug*
rm -rf node_modules/.cache
bootstrap-only:
$(MAKEJS) bootstrap-only

test-clean:
$(foreach source, $(SOURCES), \
$(call clean-source-test, $(source)))
bootstrap:
$(MAKEJS) bootstrap

use-cjs:
$(MAKEJS) use-cjs

use-esm:
$(MAKEJS) use-esm

clean-lib:
$(MAKEJS) clean-lib

clean-runtime-helpers:
$(MAKEJS) clean-runtime-helpers

clean-all:
$(MAKEJS) clean-all


build-no-bundle-ci: bootstrap-only
$(YARN) gulp build-dev
$(MAKE) build-flow-typings
$(MAKE) build-dist

# Does not work on Windows; use "$(YARN) jest" instead
test-only:
BABEL_ENV=test ./scripts/test.sh
$(MAKE) test-clean

test: lint test-only
check-compat-data:
cd packages/babel-compat-data; CHECK_COMPAT_DATA=true $(YARN) run build-data

build-compat-data:
cd packages/babel-compat-data; $(YARN) run build-data

update-env-corejs-fixture:
rm -rf packages/babel-preset-env/node_modules/core-js-compat
$(YARN)
$(MAKE) build-bundle
OVERWRITE=true $(YARN) jest packages/babel-preset-env

test-ci: build-standalone-ci
BABEL_ENV=test $(YARN) jest --maxWorkers=4 --ci
Expand Down Expand Up @@ -165,24 +182,6 @@ test-test262:
test-test262-update-allowlist:
$(NODE) scripts/parser-tests/test262 --update-allowlist

# Does not work on Windows
clone-license:
./scripts/clone-license.sh

prepublish-build: clean-lib clean-runtime-helpers
NODE_ENV=production BABEL_ENV=production STRIP_BABEL_8_FLAG=true $(MAKE) build-bundle
STRIP_BABEL_8_FLAG=true $(MAKE) prepublish-build-standalone clone-license prepublish-prepare-dts

prepublish-prepare-dts:
$(MAKE) tscheck
$(YARN) gulp bundle-dts
$(MAKE) build-typescript-legacy-typings

prepublish:
$(MAKE) bootstrap-only
$(MAKE) prepublish-build
IS_PUBLISH=true $(MAKE) test
node ./scripts/set-module-type.js clean

new-version-checklist:
# @echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Expand Down Expand Up @@ -221,64 +220,3 @@ endif
node ./scripts/set-module-type.js clean
YARN_NPM_PUBLISH_REGISTRY=http://localhost:4873 $(YARN) release-tool publish --yes --tag-version-prefix="version-e2e-test-"
$(MAKE) clean

bootstrap-only: clean-all
$(YARN) install

bootstrap: bootstrap-only
$(MAKE) generate-tsconfig build

use-cjs:
node ./scripts/set-module-type.js script
$(MAKE) bootstrap

use-esm:
node ./scripts/set-module-type.js module
$(MAKE) bootstrap

clean-lib:
$(foreach source, $(SOURCES), \
$(call clean-source-lib, $(source)))

clean-runtime-helpers:
rm -f packages/babel-runtime/helpers/**/*.js
rm -f packages/babel-runtime-corejs2/helpers/**/*.js
rm -f packages/babel-runtime-corejs3/helpers/**/*.js
rm -f packages/babel-runtime/helpers/**/*.mjs
rm -f packages/babel-runtime-corejs2/helpers/**/*.mjs
rm -f packages/babel-runtime-corejs3/helpers/**/*.mjs
rm -rf packages/babel-runtime-corejs2/core-js

clean-all:
rm -rf node_modules
rm -rf package-lock.json
rm -rf .changelog

$(foreach source, $(SOURCES), \
$(call clean-source-all, $(source)))

$(MAKE) clean

update-env-corejs-fixture:
rm -rf packages/babel-preset-env/node_modules/core-js-compat
$(YARN)
$(MAKE) build-bundle
OVERWRITE=true $(YARN) jest packages/babel-preset-env

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
$(call clean-source-lib, $1)
rm -rf $(1)/*/node_modules
rm -rf $(1)/*/package-lock.json

endef
3 changes: 3 additions & 0 deletions Makefile.js

Large diffs are not rendered by default.