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

Commit

Permalink
Merge pull request #185 from cloudflare/fix-npm-install
Browse files Browse the repository at this point in the history
fixes to npm package
  • Loading branch information
xtuc authored Jun 1, 2019
2 parents 0512d85 + d4d3d70 commit af8bb57
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ toml = "0.5.0"
uuid = "0.7"
which = "2.0.1"
rand = "0.6.5"
fs2 = "0.4.3"

[dev-dependencies]
assert_cmd = "0.11.1"
Expand Down
4 changes: 3 additions & 1 deletion npm/install-wrangler.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ function downloadAsset(asset) {
}
mkdirSync(dest);

console.log("Downloading release", asset.browser_download_url);

return axios({
url: asset.browser_download_url,
responseType: "stream"
Expand All @@ -66,7 +68,7 @@ getLatestRelease()
return downloadAsset(compatibleAssets);
})
.then(() => {
console.log("wrangler was installed.");
console.log("Wrangler has been installed!");
})
.catch(err => {
throw err;
Expand Down
4 changes: 2 additions & 2 deletions npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "node ./install-wrangler.js"
"postinstall": "node install-wrangler.js"
},
"bin": {
"wrangler": "./out/wrangler"
"wrangler": "./run-wrangler.js"
},
"repository": {
"type": "git",
Expand Down
14 changes: 14 additions & 0 deletions npm/run-wrangler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env node

const { join, resolve } = require("path");
const { spawnSync } = require("child_process");

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

const opts = {
cwd: process.cwd(),
stdio: "inherit"
};
spawnSync(bin, args, opts);
10 changes: 10 additions & 0 deletions src/wranglerjs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::commands::publish::package::Package;
use crate::install;
use binary_install::Cache;
use fs2::FileExt;
use log::info;
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
Expand Down Expand Up @@ -191,6 +192,11 @@ pub fn run_build(
// Run {npm install} in the specified directory. Skips the install if a
// {node_modules} is found in the directory.
pub fn run_npm_install(dir: PathBuf) -> Result<(), failure::Error> {
let flock_path = dir.join(&".install.lock");
let flock = File::create(&flock_path)?;
// avoid running multiple {npm install} at the same time (eg. in tests)
flock.lock_exclusive()?;

if dir.join("node_modules").exists() {
info!("skipping npm install because node_modules exists");
return Ok(());
Expand All @@ -202,6 +208,10 @@ pub fn run_npm_install(dir: PathBuf) -> Result<(), failure::Error> {
info!("Running {:?} in directory {:?}", command, dir);

let status = command.status()?;

flock.unlock()?;
fs::remove_file(&flock_path)?;

if status.success() {
Ok(())
} else {
Expand Down

0 comments on commit af8bb57

Please sign in to comment.