chrome+firefox v0.3.1 Makefile and dist/ build/ folders

This commit is contained in:
2026-08-10 16:14:56 -03:00
parent a7531914f9
commit 5176301116
9 changed files with 100 additions and 49 deletions

View File

@@ -22,16 +22,19 @@
# Makefile for logsdu - build the extension for Firefox and Chrome.
#
# Usage:
# make # typecheck and bundle for Firefox into build/
# make chrome # same, but with Chrome's manifest, into build/
# make # everything: build and package both browsers
# make firefox # build Firefox only -> build/firefox/
# make chrome # build Chrome only -> build/chrome/
# make test # run the unit tests
# make smoke # check the background bundle works as a service worker
# make xpi # package the Firefox build -> dist/logsdu-<version>.xpi
# make crx # package the Chrome build -> dist/logsdu-<version>-chrome.zip
# make packages # both of the above
# make clean # remove build/ and dist/
# make xpi # package Firefox -> dist/logsdu-<version>-firefox.xpi
# make crx # package Chrome -> dist/logsdu-<version>-chrome.zip
# make packages # both of the above (same as plain "make")
# make clean # remove build/, dist/ and stray packages
# make distclean # clean, plus node_modules/
#
# build/ holds the unpacked extension and is regenerated from scratch; dist/
# build/<target>/ holds the unpacked extension for one browser; the two targets
# never share a directory, so neither can be left stale by the other. dist/
# holds the packages meant to be published, and is kept out of build/ so that
# packaging never tries to include its own output.
#
@@ -40,22 +43,33 @@
#
# Load the unpacked build while developing:
# Firefox about:debugging -> This Firefox -> Load Temporary Add-on ->
# build/manifest.json (dropped when Firefox restarts)
# Chrome chrome://extensions -> Developer mode -> Load unpacked -> build/
# build/firefox/manifest.json (dropped when Firefox restarts)
# Chrome chrome://extensions -> Developer mode -> Load unpacked ->
# build/chrome/
#
# Publishing:
# Firefox upload dist/*.xpi at addons.mozilla.org
# Chrome upload dist/*-chrome.zip at chrome.google.com/webstore/devconsole
# Firefox upload dist/*-firefox.xpi at addons.mozilla.org
# Chrome upload dist/*-chrome.zip at chrome.google.com/webstore/devconsole
#
# Every package filename names its browser. The two are not interchangeable --
# they differ in the manifest's background key -- and uploading the wrong one
# fails in ways that are not obvious from the error.
EXT_ID := logsdu
VERSION := $(shell node -p "require('./package.json').version")
FIREFOX_DIR := build/firefox
CHROME_DIR := build/chrome
DIST := dist
XPI := $(DIST)/$(EXT_ID)-$(VERSION).xpi
XPI := $(DIST)/$(EXT_ID)-$(VERSION)-firefox.xpi
CRX := $(DIST)/$(EXT_ID)-$(VERSION)-chrome.zip
.PHONY: all build chrome test smoke xpi crx packages clean check-deps
.PHONY: all firefox chrome typecheck test smoke xpi crx packages clean \
distclean check-deps
all: build
# The default does the lot: build both browsers and package both. Packaging is
# only a zip of a directory that was going to be built anyway, so making it the
# default costs nothing and means dist/ is never quietly out of date with src/.
all: packages
# Unit tests for the pure logic: the input formatters and the decision that
# says whether a page load may press "Entrar". Run straight through Node's
@@ -64,30 +78,40 @@ test:
node --test "src/**/*.test.ts"
# Runs the built background bundle in a service-worker-shaped sandbox, which
# is where a Chrome-only breakage would otherwise hide until runtime.
smoke: build
node tools/sw-smoke.mjs
# is where a Chrome-only breakage would otherwise hide until runtime. The
# bundle is identical for both targets, so checking one covers both.
smoke: chrome
node tools/sw-smoke.mjs $(CHROME_DIR)/background.js
# Call the local toolchain directly, so this works regardless of how pnpm is
# Typecheck once. Both build targets depend on it rather than each running tsc,
# which halves the work when building both.
#
# Calls the local toolchain directly, so this works regardless of how pnpm is
# provided (corepack vs standalone). Run "corepack pnpm install" first.
build: check-deps
typecheck: check-deps
node_modules/.bin/tsc -noEmit -skipLibCheck
firefox: typecheck
node esbuild.config.mjs production
@echo "Firefox build: $(CURDIR)/$(FIREFOX_DIR)"
# The same sources with Chrome's manifest. Firefox and Chrome disagree on the
# background key and on the gecko block, so the manifest is generated per
# target rather than forked.
chrome: check-deps
node_modules/.bin/tsc -noEmit -skipLibCheck
chrome: typecheck
TARGET=chrome node esbuild.config.mjs production
@echo "Chrome build in build/ -- chrome://extensions -> Developer mode -> Load unpacked."
@echo
@echo "Chrome build: $(CURDIR)/$(CHROME_DIR)"
@echo "Load it with chrome://extensions -> Developer mode -> Load unpacked."
@echo "Select the folder itself; Chrome wants the directory holding manifest.json."
@echo
# An .xpi is just a zip of the extension directory, with the manifest at the
# top level rather than inside a wrapper folder.
xpi: build
xpi: firefox
@mkdir -p $(DIST)
rm -f $(XPI)
cd build && zip -qr ../$(XPI) .
cd $(FIREFOX_DIR) && zip -qr $(CURDIR)/$(XPI) .
@echo
@echo "Built: $(CURDIR)/$(XPI)"
@echo
@@ -108,18 +132,30 @@ xpi: build
crx: chrome
@mkdir -p $(DIST)
rm -f $(CRX)
cd build && zip -qr ../$(CRX) .
cd $(CHROME_DIR) && zip -qr $(CURDIR)/$(CRX) .
@echo
@echo "Built: $(CURDIR)/$(CRX)"
@echo "Upload it at chrome.google.com/webstore/devconsole"
@echo
# Both packages. The Firefox build runs last so build/ is left in the state
# the development instructions assume.
packages: crx xpi
# Both packages. Order no longer matters: each target has its own directory.
packages: xpi crx
# Removes everything the build produces, including packages from earlier
# versions, whose filenames carry their own version number and so are never
# overwritten by a later build. dist/ is tracked in git, so a clean shows the
# packages as deleted until the next "make packages" puts them back.
clean:
rm -rf build $(DIST)
rm -f $(EXT_ID)-*.xpi $(EXT_ID)-*.zip
find . -name '*.map' -not -path './node_modules/*' -delete
@echo "Removed build/, $(DIST)/ and any stray packages."
# Everything clean removes, plus the installed dependencies. Recover with
# "corepack pnpm install" -- never with npm, see the note in README.md.
distclean: clean
rm -rf node_modules
@echo "Removed node_modules/. Run: corepack pnpm install"
# Fail with a useful message rather than a confusing "tsc: not found".
check-deps: