From ff3f2f59c28a2d2786091675a697a83e71ffe76e Mon Sep 17 00:00:00 2001 From: Jon Edvald Date: Fri, 28 May 2021 14:27:10 +0000 Subject: [PATCH] fix(workflows): error when running `garden` in a workflow script step This works around https://github.com/vercel/pkg/issues/897 by patching the `pkg` `prelude/bootstrap.js` script. Fixes #2032 --- cli/package.json | 10 ++++++- cli/patches/pkg+4.4.9.patch | 13 +++++++++ cli/src/build-pkg.ts | 2 +- core/src/util/util.ts | 5 ++++ support/alpine-builder.Dockerfile | 2 +- yarn.lock | 47 +++++++++++++++++++++++++++++-- 6 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 cli/patches/pkg+4.4.9.patch diff --git a/cli/package.json b/cli/package.json index a14853c2221..b3a4e8e051a 100644 --- a/cli/package.json +++ b/cli/package.json @@ -38,7 +38,9 @@ "minimist": "^1.2.5", "mocha": "^8.1.1", "mocha-logger": "^1.0.6", + "patch-package": "^6.4.7", "pkg": "4.4.9", + "postinstall-postinstall": "^2.1.0", "prettier": "^2.1.0", "split2": "^3.2.2", "tslint": "^6.1.3", @@ -58,6 +60,7 @@ "fix-format": "prettier --write \"{src,test}/**/*.ts\"", "generate-docs": "node ./build/src/generate-docs.js", "lint": "tslint -p .", + "postinstall": "patch-package", "test": "mocha" }, "pkg": { @@ -67,5 +70,10 @@ "node_modules/@garden-io/**/*.js", "node_modules/es-get-iterator/**/*.js" ] + }, + "workspaces": { + "nohoist": [ + "pkg" + ] } -} \ No newline at end of file +} diff --git a/cli/patches/pkg+4.4.9.patch b/cli/patches/pkg+4.4.9.patch new file mode 100644 index 00000000000..1e6caf8d3ea --- /dev/null +++ b/cli/patches/pkg+4.4.9.patch @@ -0,0 +1,13 @@ +diff --git a/node_modules/pkg/prelude/bootstrap.js b/node_modules/pkg/prelude/bootstrap.js +index 0d19f1d..f7f5415 100644 +--- a/node_modules/pkg/prelude/bootstrap.js ++++ b/node_modules/pkg/prelude/bootstrap.js +@@ -1400,7 +1400,7 @@ function payloadFileSync (pointer) { + } + var opts = args[pos]; + if (!opts.env) opts.env = require('util')._extend({}, process.env); +- if (opts.env.PKG_EXECPATH === 'PKG_INVOKE_NODEJS') return; ++ if (opts.env.PKG_EXECPATH !== undefined) return; + opts.env.PKG_EXECPATH = EXECPATH; + } + diff --git a/cli/src/build-pkg.ts b/cli/src/build-pkg.ts index 5a96182f4b6..1019ef33d40 100644 --- a/cli/src/build-pkg.ts +++ b/cli/src/build-pkg.ts @@ -21,7 +21,7 @@ require("source-map-support").install() const repoRoot = resolve(GARDEN_CLI_ROOT, "..") const tmpDir = resolve(repoRoot, "tmp", "pkg") const tmpStaticDir = resolve(tmpDir, "static") -const pkgPath = resolve(repoRoot, "node_modules", ".bin", "pkg") +const pkgPath = resolve(repoRoot, "cli", "node_modules", ".bin", "pkg") const pkgFetchPath = resolve(repoRoot, "node_modules", ".bin", "pkg-fetch") const distPath = resolve(repoRoot, "dist") const sqliteBinFilename = "better_sqlite3.node" diff --git a/core/src/util/util.ts b/core/src/util/util.ts index 510c39215cf..871d638060f 100644 --- a/core/src/util/util.ts +++ b/core/src/util/util.ts @@ -650,6 +650,11 @@ export async function runScript({ script: string envVars?: PrimitiveMap }) { + envVars = envVars || {} + + // Workaround for https://github.com/vercel/pkg/issues/897 + envVars.PKG_EXECPATH = "" + // Run the script, capturing any errors const proc = execa("bash", ["-s"], { all: true, diff --git a/support/alpine-builder.Dockerfile b/support/alpine-builder.Dockerfile index c59ada350fb..16814c18883 100644 --- a/support/alpine-builder.Dockerfile +++ b/support/alpine-builder.Dockerfile @@ -36,6 +36,6 @@ ADD static /garden/static # Create the binary RUN mkdir -p /garden \ - && ../pkg/node_modules/.bin/pkg --target node12-alpine-x64 . --output /garden/garden \ + && node_modules/.bin/pkg --target node12-alpine-x64 . --output /garden/garden \ && cp node_modules/better-sqlite3/build/Release/better_sqlite3.node /garden \ && /garden/garden version diff --git a/yarn.lock b/yarn.lock index 0ce22f5aba6..afa93696dbe 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3200,6 +3200,11 @@ "@types/emscripten" "^1.38.0" tslib "^1.13.0" +"@yarnpkg/lockfile@^1.1.0": + version "1.1.0" + resolved "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz#e77a97fbd345b76d83245edcd17d393b1b41fb31" + integrity sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ== + "@yarnpkg/parsers@^2.3.0": version "2.3.0" resolved "https://registry.yarnpkg.com/@yarnpkg/parsers/-/parsers-2.3.0.tgz#7b9564c6df02f4921d5cfe8287c4b648e93ea84b" @@ -7956,6 +7961,13 @@ find-versions@^4.0.0: dependencies: semver-regex "^3.1.2" +find-yarn-workspace-root@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/find-yarn-workspace-root/-/find-yarn-workspace-root-2.0.0.tgz#f47fb8d239c900eb78179aa81b66673eac88f7bd" + integrity sha512-1IMnbjt4KzsQfnhnzNd8wUEgXZ44IzZaZmnLYx7D5FZlaHt2gW20Cri8Q+E/t5tIj4+epTBub+2Zxu/vNILzqQ== + dependencies: + micromatch "^4.0.2" + findup-sync@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/findup-sync/-/findup-sync-2.0.0.tgz#9326b1488c22d1a6088650a86901b2d9a90a2cbc" @@ -8216,7 +8228,7 @@ fs-extra@^4.0.2: jsonfile "^4.0.0" universalify "^0.1.0" -fs-extra@^7.0.0: +fs-extra@^7.0.0, fs-extra@^7.0.1: version "7.0.1" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9" integrity sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw== @@ -11145,6 +11157,13 @@ kind-of@^6.0.0, kind-of@^6.0.2, kind-of@^6.0.3: resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd" integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw== +klaw-sync@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/klaw-sync/-/klaw-sync-6.0.0.tgz#1fd2cfd56ebb6250181114f0a581167099c2b28c" + integrity sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ== + dependencies: + graceful-fs "^4.1.11" + klaw@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/klaw/-/klaw-3.0.0.tgz#b11bec9cf2492f06756d6e809ab73a2910259146" @@ -13226,7 +13245,7 @@ only@~0.0.2: resolved "https://registry.yarnpkg.com/only/-/only-0.0.2.tgz#2afde84d03e50b9a8edc444e30610a70295edfb4" integrity sha1-Kv3oTQPlC5qO3EROMGEKcCle37Q= -open@^7.0.2, open@^7.0.4: +open@^7.0.2, open@^7.0.4, open@^7.4.2: version "7.4.2" resolved "https://registry.yarnpkg.com/open/-/open-7.4.2.tgz#b8147e26dcf3e426316c730089fd71edd29c2321" integrity sha512-MVHddDVweXZF3awtlAS+6pgKLlm/JgxZ90+/NBurBoQctVOOB/zDdVjcyPzQ+0laDGbsWgrRkflI65sQeOgT9Q== @@ -13652,6 +13671,25 @@ pascalcase@^0.1.1: resolved "https://registry.yarnpkg.com/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14" integrity sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ= +patch-package@^6.4.7: + version "6.4.7" + resolved "https://registry.yarnpkg.com/patch-package/-/patch-package-6.4.7.tgz#2282d53c397909a0d9ef92dae3fdeb558382b148" + integrity sha512-S0vh/ZEafZ17hbhgqdnpunKDfzHQibQizx9g8yEf5dcVk3KOflOfdufRXQX8CSEkyOQwuM/bNz1GwKvFj54kaQ== + dependencies: + "@yarnpkg/lockfile" "^1.1.0" + chalk "^2.4.2" + cross-spawn "^6.0.5" + find-yarn-workspace-root "^2.0.0" + fs-extra "^7.0.1" + is-ci "^2.0.0" + klaw-sync "^6.0.0" + minimist "^1.2.0" + open "^7.4.2" + rimraf "^2.6.3" + semver "^5.6.0" + slash "^2.0.0" + tmp "^0.0.33" + path-browserify@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-0.0.1.tgz#e6c4ddd7ed3aa27c68a20cc4e50e1a4ee83bbc4a" @@ -14646,6 +14684,11 @@ postcss@^7, postcss@^7.0.0, postcss@^7.0.1, postcss@^7.0.14, postcss@^7.0.17, po source-map "^0.6.1" supports-color "^6.1.0" +postinstall-postinstall@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/postinstall-postinstall/-/postinstall-postinstall-2.1.0.tgz#4f7f77441ef539d1512c40bd04c71b06a4704ca3" + integrity sha512-7hQX6ZlZXIoRiWNrbMQaLzUUfH+sSx39u8EJ9HYuDc1kLo9IXKWjM5RSquZN1ad5GnH8CGFM78fsAAQi3OKEEQ== + prebuild-install@^5.3.3: version "5.3.6" resolved "https://registry.yarnpkg.com/prebuild-install/-/prebuild-install-5.3.6.tgz#7c225568d864c71d89d07f8796042733a3f54291"