From c29b8f4284660af5016811a256bd0e0123a62861 Mon Sep 17 00:00:00 2001 From: Aaron Boodman Date: Fri, 2 Oct 2020 09:26:10 -1000 Subject: [PATCH] Revert "Remove diff-server from the JS SDK (#120)" This reverts commit 409d4ee69228078c463a9ed5edac1dee69211c28. --- .github/workflows/perf.js.yml | 1 + HACKING.md | 2 +- bin/diff-server | 3 +++ package.json | 6 +++++- tool/get-deps.sh | 8 +++++++- tool/validate-binaries-for-publish.js | 27 +++++++++++++++++++++++++++ 6 files changed, 44 insertions(+), 3 deletions(-) create mode 100755 bin/diff-server create mode 100755 tool/validate-binaries-for-publish.js diff --git a/.github/workflows/perf.js.yml b/.github/workflows/perf.js.yml index ab573b30..05211e93 100644 --- a/.github/workflows/perf.js.yml +++ b/.github/workflows/perf.js.yml @@ -17,6 +17,7 @@ jobs: - run: npm ci - run: npm run build --if-present + - run: git restore --quiet bin/diff-server # Run benchmark and stores the output to a file - name: Run benchmark diff --git a/HACKING.md b/HACKING.md index e0272106..b51a6651 100644 --- a/HACKING.md +++ b/HACKING.md @@ -1,6 +1,6 @@ # Getting binary dependencies -`npm install` automatically downloads the correct version of the wasm bundle. +`npm install` automatically downloads the correct version of the wasm bundle and `diff-server`. # Building against a dev version of repc diff --git a/bin/diff-server b/bin/diff-server new file mode 100755 index 00000000..8faeb95a --- /dev/null +++ b/bin/diff-server @@ -0,0 +1,3 @@ +#!/usr/bin/env node +console.error('diff-server: Failed to install correctly'); +process.exit(1); diff --git a/package.json b/package.json index cbdcaf9f..82330cf5 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,14 @@ "build": "tsc && rm -rf out/wasm && mkdir out/wasm && cp -R src/wasm/* out/wasm", "build:watch": "tsc --watch", "build:cjs": "tsc --outDir out.cjs --module CommonJS && rm -rf out.cjs/wasm && mkdir out.cjs/wasm && cp -R src/wasm/* out.cjs/wasm", + "start:diff-server": "bin/diff-server --db=/tmp/diffs serve", "postinstall": "rm -f node_modules/fetch-mock/esm/client.d.ts && tool/get-deps.sh", - "prepublishOnly": "npm run lint && npm run test && rm -rf out && npm run build && rm -rf out.cjs && npm run build:cjs", + "prepublishOnly": "tool/validate-binaries-for-publish.js && npm run lint && npm run test && rm -rf out && npm run build && rm -rf out.cjs && npm run build:cjs", "perf": "node perf/runner.mjs" }, + "bin": { + "diff-server": "bin/diff-server" + }, "devDependencies": { "@esm-bundle/chai": "^4.1.5", "@types/mocha": "^8.0.3", diff --git a/tool/get-deps.sh b/tool/get-deps.sh index 4de183b1..79f66176 100755 --- a/tool/get-deps.sh +++ b/tool/get-deps.sh @@ -17,8 +17,14 @@ REPC_VERSION='v0.9.0' exit fi + # Diff server is a public interface. We *do* maintain backward compat. + # We download the latest release. + echo "Fetching diff-server..." + URL="https://github.com/rocicorp/diff-server/releases/latest/download/diffs-$PLATFORM" + curl -L -f $URL > bin/diff-server + chmod u+x bin/diff-server + echo "Fetching repc..." - mkdir -p bin URL="https://github.com/rocicorp/repc/releases/download/$REPC_VERSION/repc.zip" curl -L -f $URL > bin/repc.zip cd bin diff --git a/tool/validate-binaries-for-publish.js b/tool/validate-binaries-for-publish.js new file mode 100755 index 00000000..74c9abd7 --- /dev/null +++ b/tool/validate-binaries-for-publish.js @@ -0,0 +1,27 @@ +#!/usr/bin/env node +'use strict'; + +// This file is used to ensure that we are not trying to publish the downloaded +// binaries. + +const {existsSync, statSync} = require('fs'); +const {join} = require('path'); + +function validateFile(name) { + const p = join(__dirname, '..', 'bin', name); + if (!existsSync(p)) { + console.error(`${name} does not exist`); + process.exit(1); + } + + // If it exists, make sure that this is not the compiled binary. + const stat = statSync(p); + if (stat.size > 10000) { + console.error( + `${name} looks too large. Has it been replaced by the binary?`, + ); + process.exit(1); + } +} + +validateFile('diff-server');