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

Do not install wasm-pack for webpack projects #849

Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c60727f
Empty webpack fixture directories
EverlastingBugstopper Nov 6, 2019
0c1171b
Create Fixture struct to kill fixtures dir
EverlastingBugstopper Nov 6, 2019
fbb344e
Rename utils mod to fixture mod
EverlastingBugstopper Nov 6, 2019
717b7cf
Merge branch 'master' into avery/clean-up-clean-up-everybody-contribu…
EverlastingBugstopper Nov 7, 2019
633b1e5
Merge branch 'master' into avery/clean-up-clean-up-everybody-contribu…
EverlastingBugstopper Nov 7, 2019
90dbec8
Add webpack_wasm_pack fixture
EverlastingBugstopper Nov 5, 2019
b8601c5
Change install::install to install
EverlastingBugstopper Nov 7, 2019
076c6d5
Only install wasm_pack when it's needed
EverlastingBugstopper Nov 7, 2019
55f7c13
Do not install wasm-pack for webpack projects
EverlastingBugstopper Nov 13, 2019
f8bce77
Merge branch 'master' into avery/bob-the-builder-becomes-more-efficie…
EverlastingBugstopper Nov 13, 2019
a2acba9
Merge branch 'master' into avery/bob-the-builder-becomes-more-efficie…
EverlastingBugstopper Dec 6, 2019
d3b79d4
Merge branch 'master' into avery/bob-the-builder-becomes-more-efficie…
EverlastingBugstopper Dec 6, 2019
046f06a
Merge branch 'master' into avery/bob-the-builder-becomes-more-efficie…
EverlastingBugstopper Dec 13, 2019
1052289
Bump wasm-pack version
EverlastingBugstopper Dec 13, 2019
b348fb2
Move parameters to newlines
EverlastingBugstopper Dec 13, 2019
7a4b0c2
WIP: Test broken CI
EverlastingBugstopper Dec 13, 2019
4e2fc39
Export APPDATA and XDG_CONFIG_HOME in Azure
EverlastingBugstopper Dec 13, 2019
e7ff2e1
Export APPDATA and XDG_CONFIG_HOME in Azure
EverlastingBugstopper Dec 13, 2019
063ab9b
Merge branch 'avery/bob-the-builder-becomes-more-efficient-by-laying-…
EverlastingBugstopper Dec 13, 2019
5f38fe8
Remove env var steps from azure
EverlastingBugstopper Dec 13, 2019
66918d9
Merge branch 'master' into avery/bob-the-builder-becomes-more-efficie…
EverlastingBugstopper Jan 10, 2020
c6155c3
Merge branch 'master' into avery/bob-the-builder-becomes-more-efficie…
EverlastingBugstopper Feb 5, 2020
5557134
Merge branch 'master' into avery/bob-the-builder-becomes-more-efficie…
EverlastingBugstopper Feb 14, 2020
f6d6e30
Merge branch 'master' into avery/bob-the-builder-becomes-more-efficie…
EverlastingBugstopper Mar 11, 2020
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
5 changes: 3 additions & 2 deletions src/commands/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ pub mod wranglerjs;
mod watch;
pub use watch::watch_and_build;

use crate::commands;
use crate::install::install;
use crate::settings::target::{Target, TargetType};
use crate::terminal::message;
use crate::{commands, install};

use std::path::PathBuf;
use std::process::Command;
Expand All @@ -18,7 +19,7 @@ pub fn build(target: &Target) -> Result<(), failure::Error> {
}
TargetType::Rust => {
let tool_name = "wasm-pack";
let binary_path = install::install(tool_name, "rustwasm")?.binary(tool_name)?;
let binary_path = install(tool_name, "rustwasm")?.binary(tool_name)?;
let args = ["build", "--target", "no-modules"];

let command = command(&args, &binary_path);
Expand Down
5 changes: 3 additions & 2 deletions src/commands/build/watch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ use ignore::overrides::OverrideBuilder;
use ignore::WalkBuilder;
pub use watcher::wait_for_changes;

use crate::commands;
use crate::commands::build::{command, wranglerjs};
use crate::install::install;
use crate::settings::target::{Target, TargetType};
use crate::terminal::message;
use crate::{commands, install};

use notify::{self, RecursiveMode, Watcher};
use std::sync::mpsc;
Expand Down Expand Up @@ -52,7 +53,7 @@ pub fn watch_and_build(
}
TargetType::Rust => {
let tool_name = "wasm-pack";
let binary_path = install::install(tool_name, "rustwasm")?.binary(tool_name)?;
let binary_path = install(tool_name, "rustwasm")?.binary(tool_name)?;
let args = ["build", "--target", "no-modules"];

thread::spawn(move || {
Expand Down
26 changes: 18 additions & 8 deletions src/commands/build/wranglerjs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::commands::generate::run_generate;

use crate::commands::publish::package::Package;
use crate::install;
use crate::install::{install, install_artifact};
use crate::util;
pub use bundle::Bundle;
use fs2::FileExt;
Expand All @@ -17,6 +18,8 @@ use rand::{thread_rng, Rng};
use std::env;
use std::fs;
use std::fs::File;
use std::io;
use std::io::prelude::*;
use std::iter;
use std::path::{Path, PathBuf};
use std::process::Command;
Expand Down Expand Up @@ -154,14 +157,9 @@ fn setup_build(target: &Target) -> Result<(Command, PathBuf, Bundle), failure::E

let node = which::which("node").unwrap();
let mut command = Command::new(node);
let wranglerjs_path = install().expect("could not install wranglerjs");
let wranglerjs_path = install_wranglerjs().expect("could not install wranglerjs");
command.arg(wranglerjs_path);

// export WASM_PACK_PATH for use by wasm-pack-plugin
// https://github.com/wasm-tool/wasm-pack-plugin/blob/caca20df84782223f002735a8a2e99b2291f957c/plugin.js#L13
let wasm_pack_path = install::install("wasm-pack", "rustwasm")?.binary("wasm-pack")?;
command.env("WASM_PACK_PATH", wasm_pack_path);

// create a temp file for IPC with the wranglerjs process
let mut temp_file = env::temp_dir();
temp_file.push(format!(".wranglerjs_output{}", random_chars(5)));
Expand Down Expand Up @@ -198,6 +196,17 @@ fn setup_build(target: &Target) -> Result<(Command, PathBuf, Bundle), failure::E
// if webpack_config is not configured in the manifest
// we infer the entry based on {package.json} and pass it to {wranglerjs}
if let Some(webpack_config_path) = custom_webpack_config_path {
let mut webpack_file = File::open(&webpack_config_path)?;
let mut webpack_buffer = String::new();
webpack_file.read_to_string(&mut webpack_buffer)?;
if webpack_buffer.contains("wasm-pack-plugin") {
EverlastingBugstopper marked this conversation as resolved.
Show resolved Hide resolved
// export WASM_PACK_PATH for use by wasm-pack-plugin
// https://github.com/wasm-tool/wasm-pack-plugin/blob/caca20df84782223f002735a8a2e99b2291f957c/plugin.js#L13
let tool_name = "wasm-pack";
let author = "rustwasm";
let wasm_pack_path = install(tool_name, author)?.binary(tool_name)?;
command.env("WASM_PACK_PATH", wasm_pack_path);
}
build_with_custom_webpack(&mut command, &webpack_config_path);
} else {
build_with_default_webpack(&mut command, &build_dir)?;
Expand Down Expand Up @@ -310,16 +319,17 @@ fn get_source_dir() -> PathBuf {
}

// Install {wranglerjs} from our GitHub releases
fn install() -> Result<PathBuf, failure::Error> {
fn install_wranglerjs() -> Result<PathBuf, failure::Error> {
let wranglerjs_path = if install::target::DEBUG {
let source_path = get_source_dir();
let wranglerjs_path = source_path.join("wranglerjs");
info!("wranglerjs at: {:?}", wranglerjs_path);
wranglerjs_path
} else {
let tool_name = "wranglerjs";
let author = "cloudflare";
let version = env!("CARGO_PKG_VERSION");
let wranglerjs_path = install::install_artifact(tool_name, "cloudflare", version)?;
let wranglerjs_path = install_artifact(tool_name, author, version)?;
info!("wranglerjs downloaded at: {:?}", wranglerjs_path.path());
wranglerjs_path.path()
};
Expand Down
5 changes: 3 additions & 2 deletions src/commands/generate/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::path::PathBuf;
use std::process::Command;

use crate::commands;
use crate::commands::validate_worker_name;
use crate::install::install;
use crate::settings::target::{Manifest, Site, TargetType};
use crate::{commands, install};

pub fn generate(
name: &str,
Expand All @@ -28,7 +29,7 @@ pub fn generate(

pub fn run_generate(name: &str, template: &str) -> Result<(), failure::Error> {
let tool_name = "cargo-generate";
let binary_path = install::install(tool_name, "ashleygwilliams")?.binary(tool_name)?;
let binary_path = install(tool_name, "ashleygwilliams")?.binary(tool_name)?;

let args = ["generate", "--git", template, "--name", name, "--force"];

Expand Down
Loading