<commit_before>ESBUILD_VERSION = $(shell cat version.txt)

esbuild: cmd/esbuild/version.go cmd/esbuild/*.go pkg/*/*.go internal/*/*.go go.mod
	go build "-ldflags=-s -w" ./cmd/esbuild

test:
	make -j6 test-common

# These tests are for development
test-common: test-go vet-go no-filepath verify-source-map end-to-end-tests js-api-tests plugin-tests register-test

# These tests are for release (the extra tests are not included in "test" because they are pretty slow)
test-all:
	make -j6 test-common ts-type-tests test-wasm-node test-wasm-browser

# This includes tests of some 3rd-party libraries, which can be very slow
test-prepublish: check-go-version test-all test-preact-splitting test-sucrase bench-rome-esbuild test-esprima test-rollup

check-go-version:
	@go version | grep ' go1\.16 ' || (echo 'Please install Go version 1.16.0' && false)

# This "ESBUILD_RACE" variable exists at the request of a user on GitHub who
# wants to run "make test" on an unsupported version of macOS (version 10.9).
# Go's race detector does not run correctly on that version. With this flag
# you can run "ESBUILD_RACE= make test" to disable the race detector.
ESBUILD_RACE ?= -race

test-go:
	go test $(ESBUILD_RACE) ./internal/...

vet-go:
	go vet ./cmd/... ./internal/... ./pkg/...

fmt-go:
	go fmt ./cmd/... ./internal/... ./pkg/...

no-filepath:
	@! grep --color --include '*.go' -r '"path/filepath"' cmd internal pkg || ( \
		echo 'error: Use of "path/filepath" is disallowed. See http://golang.org/issue/43768.' && false)

test-wasm-node: esbuild
	PATH="$(shell go env GOROOT)/misc/wasm:$$PATH" GOOS=js GOARCH=wasm go test ./internal/...
	node scripts/wasm-tests.js

test-wasm-browser: platform-wasm | scripts/browser/node_modules
	cd scripts/browser && node browser-tests.js

register-test: cmd/esbuild/version.go | scripts/node_modules
	cd npm/esbuild && npm version "$(ESBUILD_VERSION)" --allow-same-version
	node scripts/register-test.js

verify-source-map: cmd/esbuild/version.go | scripts/node_modules
	cd npm/esbuild && npm version "$(ESBUILD_VERSION)" --allow-same-version
	node scripts/verify-source-map.js

end-to-end-tests: cmd/esbuild/version.go | scripts/node_modules
	cd npm/esbuild && npm version "$(ESBUILD_VERSION)" --allow-same-version
	node scripts/end-to-end-tests.js

js-api-tests: cmd/esbuild/version.go | scripts/node_modules
	cd npm/esbuild && npm version "$(ESBUILD_VERSION)" --allow-same-version
	node scripts/js-api-tests.js

plugin-tests: cmd/esbuild/version.go | scripts/node_modules
	node scripts/plugin-tests.js

ts-type-tests: | scripts/node_modules
	node scripts/ts-type-tests.js

lib-typecheck: | lib/node_modules
	cd lib && node_modules/.bin/tsc -noEmit -p .

cmd/esbuild/version.go: version.txt
	# Update this atomically to avoid issues with this being overwritten during use
	node -e 'console.log(`package main\n\nconst esbuildVersion = "$(ESBUILD_VERSION)"`)' > cmd/esbuild/version.go.txt
	mv cmd/esbuild/version.go.txt cmd/esbuild/version.go

wasm-napi-exit0-darwin:
	node -e 'console.log(`#include <unistd.h>\nvoid* napi_register_module_v1(void* a, void* b) { _exit(0); }`)' \
		| clang -x c -dynamiclib -mmacosx-version-min=10.5 -o npm/esbuild-wasm/exit0/darwin-x64-LE.node -
	ls -l npm/esbuild-wasm/exit0/darwin-x64-LE.node

wasm-napi-exit0-linux:
	node -e 'console.log(`#include <unistd.h>\nvoid* napi_register_module_v1(void* a, void* b) { _exit(0); }`)' \
		| gcc -x c -shared -o npm/esbuild-wasm/exit0/linux-x64-LE.node -
	strip npm/esbuild-wasm/exit0/linux-x64-LE.node
	ls -l npm/esbuild-wasm/exit0/linux-x64-LE.node

wasm-napi-exit0-windows:
	# This isn't meant to be run directly but is a rough overview of the instructions<commit_msg>add node unref tests to common tests<commit_after>ESBUILD_VERSION = $(shell cat version.txt)

esbuild: cmd/esbuild/version.go cmd/esbuild/*.go pkg/*/*.go internal/*/*.go go.mod
	go build "-ldflags=-s -w" ./cmd/esbuild

test:
	make -j6 test-common

# These tests are for development
test-common: test-go vet-go no-filepath verify-source-map end-to-end-tests js-api-tests plugin-tests register-test node-unref-tests

# These tests are for release (the extra tests are not included in "test" because they are pretty slow)
test-all:
	make -j6 test-common ts-type-tests test-wasm-node test-wasm-browser

# This includes tests of some 3rd-party libraries, which can be very slow
test-prepublish: check-go-version test-all test-preact-splitting test-sucrase bench-rome-esbuild test-esprima test-rollup

check-go-version:
	@go version | grep ' go1\.16 ' || (echo 'Please install Go version 1.16.0' && false)

# This "ESBUILD_RACE" variable exists at the request of a user on GitHub who
# wants to run "make test" on an unsupported version of macOS (version 10.9).
# Go's race detector does not run correctly on that version. With this flag
# you can run "ESBUILD_RACE= make test" to disable the race detector.
ESBUILD_RACE ?= -race

test-go:
	go test $(ESBUILD_RACE) ./internal/...

vet-go:
	go vet ./cmd/... ./internal/... ./pkg/...

fmt-go:
	go fmt ./cmd/... ./internal/... ./pkg/...

no-filepath:
	@! grep --color --include '*.go' -r '"path/filepath"' cmd internal pkg || ( \
		echo 'error: Use of "path/filepath" is disallowed. See http://golang.org/issue/43768.' && false)

test-wasm-node: esbuild
	PATH="$(shell go env GOROOT)/misc/wasm:$$PATH" GOOS=js GOARCH=wasm go test ./internal/...
	node scripts/wasm-tests.js

test-wasm-browser: platform-wasm | scripts/browser/node_modules
	cd scripts/browser && node browser-tests.js

register-test: cmd/esbuild/version.go | scripts/node_modules
	cd npm/esbuild && npm version "$(ESBUILD_VERSION)" --allow-same-version
	node scripts/register-test.js

verify-source-map: cmd/esbuild/version.go | scripts/node_modules
	cd npm/esbuild && npm version "$(ESBUILD_VERSION)" --allow-same-version
	node scripts/verify-source-map.js

end-to-end-tests: cmd/esbuild/version.go | scripts/node_modules
	cd npm/esbuild && npm version "$(ESBUILD_VERSION)" --allow-same-version
	node scripts/end-to-end-tests.js

js-api-tests: cmd/esbuild/version.go | scripts/node_modules
	cd npm/esbuild && npm version "$(ESBUILD_VERSION)" --allow-same-version
	node scripts/js-api-tests.js

plugin-tests: cmd/esbuild/version.go | scripts/node_modules
	node scripts/plugin-tests.js

ts-type-tests: | scripts/node_modules
	node scripts/ts-type-tests.js

node-unref-tests:
	node scripts/node-unref-tests.js

lib-typecheck: | lib/node_modules
	cd lib && node_modules/.bin/tsc -noEmit -p .

cmd/esbuild/version.go: version.txt
	# Update this atomically to avoid issues with this being overwritten during use
	node -e 'console.log(`package main\n\nconst esbuildVersion = "$(ESBUILD_VERSION)"`)' > cmd/esbuild/version.go.txt
	mv cmd/esbuild/version.go.txt cmd/esbuild/version.go

wasm-napi-exit0-darwin:
	node -e 'console.log(`#include <unistd.h>\nvoid* napi_register_module_v1(void* a, void* b) { _exit(0); }`)' \
		| clang -x c -dynamiclib -mmacosx-version-min=10.5 -o npm/esbuild-wasm/exit0/darwin-x64-LE.node -
	ls -l npm/esbuild-wasm/exit0/darwin-x64-LE.node

wasm-napi-exit0-linux:
	node -e 'console.log(`#include <unistd.h>\nvoid* napi_register_module_v1(void* a, void* b) { _exit(0); }`)' \
		| gcc -x c -shared -o npm/esbuild-wasm/exit0/linux-x64-LE.node -
	strip npm/esbuild-wasm/exit0/linux-x64-LE.node
	ls -l npm/esbuild-wasm/exit0/linux-x64-LE.node

wasm-napi-exit0-windows:
	# This isn't meant to be run directly but is a rough overview of the instructions
{'fraction_non_alphanumeric': 0.14289547833087346, 'fraction_numerical': 0.011538977592915604, 'mean_word_length': 3.7874116891457934, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '149920', 'n_tokens_mistral': 2760, 'n_tokens_neox': 2657, 'n_words': 689}