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

Commit

Permalink
Use binary-install for npm
Browse files Browse the repository at this point in the history
  • Loading branch information
EverlastingBugstopper committed Nov 11, 2019
1 parent 4a23cab commit b88de95
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 290 deletions.
43 changes: 43 additions & 0 deletions npm/binary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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();
};

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

This file was deleted.

195 changes: 0 additions & 195 deletions npm/npm-shrinkwrap.json

This file was deleted.

9 changes: 2 additions & 7 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.5.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()'"
},
"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 Down
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()

0 comments on commit b88de95

Please sign in to comment.