diff --git a/Makefile b/Makefile index ebe9f18..1b2192b 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ COMMIT ?= $(shell git rev-parse --short HEAD || echo unknown) BUILDTIME ?= $(shell date +%s) UPDATER ?= off -LDFLAGS := -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.cssVersion=$(CSSVERSION) -X main.buildTimeUnix=$(BUILDTIME) +LDFLAGS := -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.cssVersion=$(CSSVERSION) -X main.buildTimeUnix=$(BUILDTIME) $(if $(BUILTBY),-X 'main.builtBy=$(BUILTBY)',) ifeq ($(UPDATER), on) LDFLAGS := $(LDFLAGS) -X main.updater=binary else ifneq ($(UPDATER), off) @@ -75,14 +75,23 @@ else RACEDETECTOR := endif +ifeq (, $(shell which esbuild)) + ESBUILDINSTALL := go install github.com/evanw/esbuild/cmd/esbuild@latest +else + ESBUILDINSTALL := +endif + +ifeq ($(GOESBUILD), on) + NPMIGNOREOPTIONAL := --no-optional + NPMOPTS := $(NPMIGNOREOPTIONAL); $(ESBUILDINSTALL) +else + NPMOPTS := +endif + + npm: $(info installing npm dependencies) - npm install - @if [ "$(GOESBUILD)" = "off" ]; then\ - npm install esbuild;\ - else\ - go install github.com/evanw/esbuild/cmd/esbuild@latest;\ - fi + npm install $(NPMOPTS) configuration: $(info Fixing config-base) diff --git a/package-lock.json b/package-lock.json index c1cd61f..0d2b0cf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,6 @@ "any-date-parser": "^1.5.4", "browserslist": "^4.21.7", "cheerio": "^1.0.0-rc.12", - "esbuild": "^0.18.6", "fs-cheerio": "^3.0.0", "inline-source": "^8.0.2", "jsdom": "^22.1.0", @@ -32,6 +31,9 @@ }, "devDependencies": { "live-server": "^1.2.2" + }, + "optionalDependencies": { + "esbuild": "^0.18.6" } }, "node_modules/@alloc/quick-lru": { @@ -1651,6 +1653,7 @@ "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.18.6.tgz", "integrity": "sha512-5QgxWaAhU/tPBpvkxUmnFv2YINHuZzjbk0LeUUnC2i3aJHjfi5yR49lgKgF7cb98bclOp/kans8M5TGbGFfJlQ==", "hasInstallScript": true, + "optional": true, "bin": { "esbuild": "bin/esbuild" }, @@ -7899,6 +7902,7 @@ "version": "0.18.6", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.18.6.tgz", "integrity": "sha512-5QgxWaAhU/tPBpvkxUmnFv2YINHuZzjbk0LeUUnC2i3aJHjfi5yR49lgKgF7cb98bclOp/kans8M5TGbGFfJlQ==", + "optional": true, "requires": { "@esbuild/android-arm": "0.18.6", "@esbuild/android-arm64": "0.18.6", diff --git a/package.json b/package.json index e154b97..7b7f95a 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,6 @@ "any-date-parser": "^1.5.4", "browserslist": "^4.21.7", "cheerio": "^1.0.0-rc.12", - "esbuild": "^0.18.6", "fs-cheerio": "^3.0.0", "inline-source": "^8.0.2", "jsdom": "^22.1.0", @@ -40,5 +39,8 @@ }, "devDependencies": { "live-server": "^1.2.2" + }, + "optionalDependencies": { + "esbuild": "^0.18.6" } } diff --git a/scripts/compile_mjml.py b/scripts/compile_mjml.py index f7510bf..8341c5e 100755 --- a/scripts/compile_mjml.py +++ b/scripts/compile_mjml.py @@ -13,8 +13,8 @@ args = parser.parse_args() def runcmd(cmd): if os.name == "nt": return subprocess.check_output(cmd, shell=True) - proc = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) - return proc.communicate() + with subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) as proc: + return proc.communicate() def compile(mjml: Path): fname = mjml.with_suffix(".html")