Skip to content

Commit

Permalink
Merge pull request #1104 from garden-io/fix-mac-dist-watcher
Browse files Browse the repository at this point in the history
fix(watcher): native fsevents were not used in dist build on macOS
  • Loading branch information
eysi09 authored Aug 16, 2019
2 parents ccca0af + 4eb00a6 commit 9fcdc45
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 81 deletions.
46 changes: 29 additions & 17 deletions garden-service/bin/build-pkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,43 +43,55 @@ rsync -r --exclude=.garden --exclude=.git static tmp/dist
echo "-> Run 'git init' inside static dir"
git init tmp/dist/static

echo "-> Building executables..."
cd dist
pkg --target node10-macos-x64,node10-linux-x64,node10-win-x64,node10-alpine-x64 ../tmp/dist

echo "-> Preparing packages..."
cd dist

echo " -> linux-amd64"
pkg --target node10-linux-x64 ../tmp/dist
rm -rf linux-amd64
mkdir linux-amd64
mv garden-service-linux linux-amd64/garden
mv garden-service linux-amd64/garden
cp -r ../tmp/dist/static linux-amd64
echo " -> tar"
tar -czf garden-${version}-linux-amd64.tar.gz linux-amd64

echo " -> alpine-amd64"
pkg --target node10-alpine-x64 ../tmp/dist
rm -rf alpine-amd64
mkdir alpine-amd64
mv garden-service-alpine alpine-amd64/garden
mv garden-service alpine-amd64/garden
cp -r ../tmp/dist/static alpine-amd64
echo " -> tar"
tar -czf garden-${version}-alpine-amd64.tar.gz alpine-amd64

echo " -> macos-amd64"
rm -rf macos-amd64
mkdir macos-amd64
mv garden-service-macos macos-amd64/garden
cp -r ../tmp/dist/static macos-amd64
# need to include the .node binary for fsevents
cp ../lib/fsevents/node-v64-darwin-x64/fse.node macos-amd64/fse.node
echo " -> tar"
tar -czf garden-${version}-macos-amd64.tar.gz macos-amd64

echo " -> windows-amd64"
pkg --target node10-win-x64 ../tmp/dist
rm -rf windows-amd64
mkdir windows-amd64
# Name should match go release and other standards using full "windows" name
mv garden-service-win.exe windows-amd64/garden.exe
mv garden-service.exe windows-amd64/garden.exe
cp -r ../tmp/dist/static windows-amd64
echo " -> zip"
zip -q -r garden-${version}-windows-amd64.zip windows-amd64

echo " -> macos-amd64"
rm -rf macos-amd64
mkdir macos-amd64

# Need to use a newer version of Pkg for the fsevents module to work properly,
# which unfortunately does NOT work for other platforms :/
echo " -> install pkg@4.4.0"
npm init -y
npm install pkg@4.4.0

echo " -> build binary"
node_modules/.bin/pkg --target node10-macos-x64 ../tmp/dist

mv garden-service macos-amd64/garden
cp -r ../tmp/dist/static macos-amd64

# need to include the .node binary for fsevents
cp ../lib/fsevents/node-v64-darwin-x64/fsevents.node macos-amd64/fsevents.node

echo " -> tar"
tar -czf garden-${version}-macos-amd64.tar.gz macos-amd64
Binary file not shown.
Binary file not shown.
122 changes: 61 additions & 61 deletions garden-service/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions garden-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"certpem": "^1.1.3",
"chalk": "^2.4.2",
"child-process-promise": "^2.2.1",
"chokidar": "^3.0.0",
"chokidar": "^3.0.2",
"ci-info": "^2.0.0",
"circular-json": "^0.5.9",
"cli-cursor": "^3.0.0",
Expand Down Expand Up @@ -174,7 +174,7 @@
"nyc": "^14.1.1",
"p-event": "^4.1.0",
"pegjs": "^0.10.0",
"pkg": "^4.3.8",
"pkg": "4.3.8",
"replace-in-file": "^4.1.0",
"shx": "^0.3.2",
"snyk": "^1.163.3",
Expand All @@ -197,10 +197,11 @@
"check-package-lock": "git diff-index --quiet HEAD -- package-lock.json || (echo 'package-lock.json is dirty!' && exit 1)",
"clean": "shx rm -rf build",
"dev": "npm link && npm run watch",
"dist": "npm run build && ./bin/build-pkg.sh",
"dist": "npm run build && npm run pkg",
"generate-docs": "node ./build/src/bin/generate-docs.js",
"integ": "./test/integ/run",
"e2e-full": "node ./build/test/e2e/e2e-full.js",
"pkg": "./bin/build-pkg.sh",
"prepare": "npm run snyk-protect",
"snyk-protect": "snyk protect",
"test": "node_modules/.bin/mocha",
Expand Down
13 changes: 13 additions & 0 deletions garden-service/src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { registerCleanupFunction, sleep } from "./util/util"
import { some } from "lodash"
import { isConfigFilename, matchPath } from "./util/fs"
import * as Bluebird from "bluebird"
import { InternalError } from "./exceptions"

// How long we wait between processing added files and directories
const DEFAULT_BUFFER_INTERVAL = 500
Expand Down Expand Up @@ -82,6 +83,18 @@ export class Watcher {
this.log.debug(`Watcher: Watching paths ${this.paths.join(", ")}`)

if (watcher === undefined) {
// Make sure that fsevents works when we're on macOS. This has come up before without us noticing, which has
// a dramatic performance impact, so it's best if we simply throw here so that our tests catch such issues.
if (process.platform === "darwin") {
try {
require("fsevents")
} catch (error) {
throw new InternalError(`Unable to load fsevents module: ${error}`, {
error,
})
}
}

watcher = watch(this.paths, {
ignoreInitial: true,
ignorePermissionErrors: true,
Expand Down

0 comments on commit 9fcdc45

Please sign in to comment.