Skip to content

Commit 42efa14

Browse files
lunnyCL-Jeremy
andauthored
Introduce esbuild on webpack (#14578)
* Vendor node mods as cache; fix esbuild/fomantic offline build * Fix --exclude; use bsdtar for consistent globbing * Fall back to GNU tar; forward-compatible for APT 2.0 * Avoid having extd. attrs with bsdtar * Dependency and misc. optimizations * Remove extra code after esbuild-loader update Co-authored-by: Mike L <[email protected]>
1 parent bc1f211 commit 42efa14

File tree

8 files changed

+157
-930
lines changed

8 files changed

+157
-930
lines changed

.drone.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ steps:
495495
pull: always
496496
image: techknowlogick/xgo:go-1.16.x
497497
commands:
498-
- curl -sL https://deb.nodesource.com/setup_14.x | bash - && apt -y install nodejs
498+
- curl -sL https://deb.nodesource.com/setup_14.x | bash - && apt -y install nodejs bsdtar\|libarchive-tools
499499
- export PATH=$PATH:$GOPATH/bin
500500
- make release
501501
environment:
@@ -591,7 +591,7 @@ steps:
591591
pull: always
592592
image: techknowlogick/xgo:go-1.16.x
593593
commands:
594-
- curl -sL https://deb.nodesource.com/setup_14.x | bash - && apt -y install nodejs
594+
- curl -sL https://deb.nodesource.com/setup_14.x | bash - && apt-get install -y nodejs bsdtar\|libarchive-tools
595595
- export PATH=$PATH:$GOPATH/bin
596596
- make release
597597
environment:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ coverage.all
8080
/public/css
8181
/public/fonts
8282
/public/img/webpack
83+
/web_src/fomantic/node_modules
84+
/web_src/fomantic/semantic.json
8385
/web_src/fomantic/build/*
8486
!/web_src/fomantic/build/semantic.js
8587
!/web_src/fomantic/build/semantic.css
@@ -93,6 +95,7 @@ coverage.all
9395
!/web_src/fomantic/build/themes/default/assets/fonts/outline-icons.woff2
9496
/VERSION
9597
/.air
98+
/.npm-cache
9699

97100
# Snapcraft
98101
snap/.snapcraft/

Makefile

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ else
1414

1515
# This is the "normal" part of the Makefile
1616

17+
TAR := $(shell hash bsdtar > /dev/null 2>&1 && echo "bsdtar --no-xattrs" || echo "tar" )
18+
1719
DIST := dist
1820
DIST_DIRS := $(DIST)/binaries $(DIST)/release
1921
IMPORT := code.gitea.io/gitea
@@ -93,7 +95,7 @@ GO_PACKAGES ?= $(filter-out code.gitea.io/gitea/models/migrations code.gitea.io/
9395

9496
FOMANTIC_CONFIGS := semantic.json web_src/fomantic/theme.config.less web_src/fomantic/_site/globals/site.variables
9597
FOMANTIC_DEST := web_src/fomantic/build/semantic.js web_src/fomantic/build/semantic.css
96-
FOMANTIC_DEST_DIR := web_src/fomantic/build
98+
FOMANTIC_WORK_DIR := web_src/fomantic
9799

98100
WEBPACK_SOURCES := $(shell find web_src/js web_src/less -type f)
99101
WEBPACK_CONFIGS := webpack.config.js
@@ -642,14 +644,16 @@ release-compress: | $(DIST_DIRS)
642644
cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && gxz -k -9 $${file}; done;
643645

644646
.PHONY: release-sources
645-
release-sources: | $(DIST_DIRS) node_modules
647+
release-sources: | $(DIST_DIRS) npm-cache
646648
echo $(VERSION) > $(STORED_VERSION_FILE)
647-
tar --exclude=./$(DIST) --exclude=./.git --exclude=./$(MAKE_EVIDENCE_DIR) --exclude=./node_modules/.cache --exclude=./$(AIR_TMP_DIR) -czf $(DIST)/release/gitea-src-$(VERSION).tar.gz .
649+
$(eval EXCL := --exclude=$(shell [ ! "$(TAR)" = "tar" ] && echo "^" )./)
650+
$(eval EXCL_RECURSIVE := --exclude=)
651+
$(TAR) $(EXCL)$(DIST) $(EXCL).git $(EXCL)$(MAKE_EVIDENCE_DIR) $(EXCL_RECURSIVE)node_modules $(EXCL)$(AIR_TMP_DIR) -czf $(DIST)/release/gitea-src-$(VERSION).tar.gz .
648652
rm -f $(STORED_VERSION_FILE)
649653

650654
.PHONY: release-docs
651655
release-docs: | $(DIST_DIRS) docs
652-
tar -czf $(DIST)/release/gitea-docs-$(VERSION).tar.gz -C ./docs/public .
656+
$(TAR) -czf $(DIST)/release/gitea-docs-$(VERSION).tar.gz -C ./docs/public .
653657

654658
.PHONY: docs
655659
docs:
@@ -662,6 +666,25 @@ node_modules: package-lock.json
662666
npm install --no-save
663667
@touch node_modules
664668

669+
.PHONY: npm-cache
670+
npm-cache: .npm-cache $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui
671+
672+
.npm-cache: package-lock.json
673+
rm -rf .npm-cache
674+
$(eval ESBUILD_VERSION := `node -p "require('./package-lock.json').dependencies.esbuild.version"`)
675+
npm config --userconfig=.npmrc set cache=.npm-cache
676+
rm -rf node_modules && npm install --no-save
677+
npm config --userconfig=$(FOMANTIC_WORK_DIR)/.npmrc set cache=../../.npm-cache
678+
echo esbuild-{darwin-64,linux-{arm,arm64,32,64},windows-{32,64}}@$(ESBUILD_VERSION) | tr " " "\n" | xargs -n 1 -P 4 npm cache add
679+
rm -rf $(FOMANTIC_WORK_DIR)/node_modules
680+
@touch .npm-cache
681+
682+
.PHONY: npm-uncache
683+
npm-uncache:
684+
rm -rf .npm-cache
685+
npm config --userconfig=$(FOMANTIC_WORK_DIR)/.npmrc rm cache
686+
npm config --userconfig=.npmrc rm cache
687+
665688
.PHONY: npm-update
666689
npm-update: node-check | node_modules
667690
npx updates -cu
@@ -672,14 +695,22 @@ npm-update: node-check | node_modules
672695
.PHONY: fomantic
673696
fomantic: $(FOMANTIC_DEST)
674697

675-
$(FOMANTIC_DEST): $(FOMANTIC_CONFIGS) | node_modules
676-
@if [ ! -d node_modules/fomantic-ui ]; then \
677-
npm install --no-save --no-package-lock [email protected]; \
678-
fi
679-
rm -rf $(FOMANTIC_DEST_DIR)
680-
cp -f web_src/fomantic/theme.config.less node_modules/fomantic-ui/src/theme.config
681-
cp -rf web_src/fomantic/_site/* node_modules/fomantic-ui/src/_site/
682-
npx gulp -f node_modules/fomantic-ui/gulpfile.js build
698+
$(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui:
699+
ln -sf ../../semantic.json $(FOMANTIC_WORK_DIR)
700+
cd $(FOMANTIC_WORK_DIR); \
701+
rm -rf node_modules && mkdir node_modules && \
702+
npm install fomantic-ui; \
703+
rm -f semantic.json
704+
@touch $(FOMANTIC_WORK_DIR)/node_modules
705+
706+
$(FOMANTIC_DEST): $(FOMANTIC_CONFIGS) $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui
707+
ln -sf ../../semantic.json $(FOMANTIC_WORK_DIR)
708+
rm -rf $(FOMANTIC_WORK_DIR)/build
709+
cd $(FOMANTIC_WORK_DIR); \
710+
cp -f theme.config.less node_modules/fomantic-ui/src/theme.config; \
711+
cp -rf _site node_modules/fomantic-ui/src/; \
712+
npx gulp -f node_modules/fomantic-ui/gulpfile.js build; \
713+
rm -f semantic.json
683714
@touch $(FOMANTIC_DEST)
684715

685716
.PHONY: webpack

0 commit comments

Comments
 (0)