Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Use binary-install for npm #862

Merged
merged 4 commits into from
Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions npm/binary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const { Binary } = require("binary-install");
const os = require("os");
const { join } = require("path");

const getPlatform = () => {
const type = os.type();
const arch = os.arch();

if (type === "Windows_NT" && arch === "x64") {
return "x86_64-pc-windows-msvc";
}
if (type === "Linux" && arch === "x64") {
return "x86_64-unknown-linux-musl";
}
if (type === "Darwin" && arch === "x64") {
return "x86_64-apple-darwin";
}

throw new Error(`Unsupported platform: ${type} ${arch}`);
};

const getBinary = () => {
const platform = getPlatform();
const version = require("./package.json").version;
const url = `https://workers.cloudflare.com/get-npm-wrangler-binary/${version}/${platform}`;
const installDirectory = join(os.homedir(), ".wrangler");
return new Binary(url, { name: "wrangler", installDirectory });
};

const run = () => {
const binary = getBinary();
binary.run();
};

const install = () => {
const binary = getBinary();
binary.install();
};

const uninstall = () => {
const binary = getBinary();
binary.uninstall();
}

module.exports = {
install,
run,
uninstall
};
67 changes: 0 additions & 67 deletions npm/install-wrangler.js

This file was deleted.

192 changes: 1 addition & 191 deletions npm/npm-shrinkwrap.json

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

16 changes: 7 additions & 9 deletions npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "@cloudflare/wrangler",
"version": "1.6.0",
"description": "Wrangle your Cloudflare Workers",
"main": "index.js",
"main": "binary.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "node install-wrangler.js"
"postinstall": "node -e 'require(\"./binary.js\").install()'",
"preuninstall": "node -e 'require(\"./binary.js\").uninstall()'"
},
"bin": {
"wrangler": "./run-wrangler.js"
Expand All @@ -20,11 +20,6 @@
"url": "https://github.com/cloudflare/wrangler/issues"
},
"homepage": "https://github.com/cloudflare/wrangler#readme",
"dependencies": {
"axios": "0.18.1",
"rimraf": "2.7.1",
"tar": "4.4.10"
},
"keywords": [
"wrangler",
"cloudflare",
Expand All @@ -46,5 +41,8 @@
"router",
"http",
"cli"
]
],
"dependencies": {
"binary-install": "0.0.0"
}
}
23 changes: 2 additions & 21 deletions npm/run-wrangler.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
#!/usr/bin/env node

const { join } = require("path");
const { spawnSync } = require("child_process");
const { homedir } = require("os");

const cwd = join(homedir(), ".wrangler");
const bin = join(cwd, "out", "wrangler");
const [, , ...args] = process.argv;

const opts = {
cwd: process.cwd(),
stdio: "inherit"
};

const result = spawnSync(bin, args, opts);

if (result.error) {
console.error(result.error);
process.exit(1);
}

process.exit(result.status);
const { run } = require("./binary");
run()