diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f45d26d86..c3688ed46 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,11 +18,11 @@ Within 3 days, any incoming issue should be triaged. Triage involves: ### Labelling -- label all issues coming from non-team members with User Report -- labelling the category of the issue: Feature, External Bug, Bug, Maintenance, Docs -- optionally labelling a secondary category: Webpack, Routes, Workers Runtime, Refactor -- labelling the status of the issue: Need More Info, Needs Repro, Needs Design, PR Welcome -- optionally labelling other calls to action: Help Wanted, Question +- label all issues coming from non-team members with `user report` +- labelling the category of the issue: `feature`, `external bug`, `bug`, `maintenance`, `docs`, `refactor`, `release` +- labelling the status of the issue: `needs design`, `needs docs`, `needs more info`, `needs repro`, `needs template`, `PR attached`, `PR welcome`, `waiting on response` +- optionally labelling a subject: `cargo install`, `kv`, `routes`, `site`, `webpack`, `workers runtime` +- optionally labelling other calls to action: `help wanted`, `question`, `good first issue` ### Assignment @@ -36,7 +36,7 @@ our plans for the milestones and releases. ### Labelling -- labelling the priority of the issue: Critical, Nice to Have, Low Priority +- labelling the priority of the issue: `critical`, `nice to have`, `low priority` - labelling the status of the issue: Needs Design, PR Welcome ### Assignment and Milestones @@ -51,12 +51,12 @@ should be triaged immediately upon open by the PR author. ### Labelling -- All work-in-progress PRs should be labelled Work In Progress and the title should be +- All work-in-progress PRs should be labelled `work in progress` and the title should be annotated [WIP] for easy scanning. No WIP PRs will be reviewed until the annotations are removed. -- All PRs that need to be reviewed should be labelled Needs Review until they have +- All PRs that need to be reviewed should be labelled `needs review` until they have received all required reviews. -- All PRs should be labelled with a changelog label: BREAKING, Feature, Bug, Maintenance, Docs +- All PRs should be labelled with a changelog label: `BREAKING`, `feature`, `fix`, `maintenance`, `docs` ### Merging diff --git a/npm/install-wrangler.js b/npm/install-wrangler.js index e8a7932eb..215a8cc62 100755 --- a/npm/install-wrangler.js +++ b/npm/install-wrangler.js @@ -2,7 +2,6 @@ const axios = require("axios"); const os = require("os"); const { join, resolve } = require("path"); const { mkdirSync, existsSync } = require("fs"); -// while recent versions of Node can do that natively, wait until we can use it. const rimraf = require("rimraf"); const tar = require("tar"); const { get } = axios; diff --git a/src/commands/build/watch/mod.rs b/src/commands/build/watch/mod.rs index 148eb6ba7..c30fe05d0 100644 --- a/src/commands/build/watch/mod.rs +++ b/src/commands/build/watch/mod.rs @@ -20,8 +20,8 @@ const RUST_PATH: &str = "./"; // Paths to ignore live watching in Rust Workers const RUST_IGNORE: &'static [&str] = &["pkg", "target", "worker/generated"]; -/// watch a project for changes and re-build it when necessary, -/// outputting a build event to tx. +// watch a project for changes and re-build it when necessary, +// outputting a build event to tx. pub fn watch_and_build( target: &Target, tx: Option>, diff --git a/src/commands/build/watch/watcher.rs b/src/commands/build/watch/watcher.rs index 49f260df1..01c95122d 100644 --- a/src/commands/build/watch/watcher.rs +++ b/src/commands/build/watch/watcher.rs @@ -8,7 +8,7 @@ use failure::{format_err, Error}; use crate::terminal::message; use log::info; -/// Add cooldown for all types of events to watching logic +// Add cooldown for all types of events to watching logic pub fn wait_for_changes( rx: &Receiver, cooldown: Duration, diff --git a/src/commands/build/wranglerjs/bundle.rs b/src/commands/build/wranglerjs/bundle.rs index 1aeaec7ff..97b7f01ff 100644 --- a/src/commands/build/wranglerjs/bundle.rs +++ b/src/commands/build/wranglerjs/bundle.rs @@ -55,10 +55,6 @@ impl Bundle { self.wasm_path().exists() } - pub fn has_webpack_config(&self, webpack_config_path: &PathBuf) -> bool { - webpack_config_path.exists() - } - pub fn get_wasm_binding(&self) -> String { "wasm".to_string() } diff --git a/src/commands/build/wranglerjs/mod.rs b/src/commands/build/wranglerjs/mod.rs index 229bacc8c..6446ca84d 100644 --- a/src/commands/build/wranglerjs/mod.rs +++ b/src/commands/build/wranglerjs/mod.rs @@ -30,9 +30,9 @@ use std::thread; use std::time::Duration; // Run the underlying {wranglerjs} executable. -// -// In Rust we create a virtual file, pass the pass to {wranglerjs}, run the -// executable and wait for completion. The file will receive the a serialized + +// In Rust we create a virtual file, pass it to {wranglerjs}, run the +// executable and wait for completion. The file will receive a serialized // {WranglerjsOutput} struct. // Note that the ability to pass a fd is platform-specific pub fn run_build(target: &Target) -> Result<(), failure::Error> { @@ -43,8 +43,8 @@ pub fn run_build(target: &Target) -> Result<(), failure::Error> { let status = command.status()?; if status.success() { - let output = fs::read_to_string(temp_file).expect("could not retrieve output"); - + let output = fs::read_to_string(&temp_file).expect("could not retrieve output"); + fs::remove_file(temp_file)?; let wranglerjs_output: WranglerjsOutput = serde_json::from_str(&output).expect("could not parse wranglerjs output"); @@ -62,7 +62,7 @@ pub fn run_build_and_watch(target: &Target, tx: Option>) -> Result<() info!("Running {:?} in watch mode", command); - //Turbofish the result of the closure so we can use ? + // Turbofish the result of the closure so we can use ? thread::spawn::<_, Result<(), failure::Error>>(move || { let _command_guard = util::GuardedCommand::spawn(command); @@ -93,8 +93,8 @@ pub fn run_build_and_watch(target: &Target, tx: Option>) -> Result<() if is_first { is_first = false; message::info("Ignoring stale first change"); - //skip the first change event - //so we don't do a refresh immediately + // skip the first change event + // so we don't do a refresh immediately continue; } @@ -158,7 +158,8 @@ fn setup_build(target: &Target) -> Result<(Command, PathBuf, Bundle), failure::E command.arg(wranglerjs_path); let has_wasm_pack_plugin = true; if has_wasm_pack_plugin { - //put path to our wasm_pack as env variable so wasm-pack-plugin can utilize it + // 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::install(tool_name, author)?.binary(tool_name)?; @@ -179,29 +180,28 @@ fn setup_build(target: &Target) -> Result<(Command, PathBuf, Bundle), failure::E command.arg(format!("--wasm-binding={}", bundle.get_wasm_binding())); - let webpack_config_path = if let Some(webpack_config) = &target.webpack_config { - // require webpack_config in wrangler.toml to use it in sites - Some(PathBuf::from(&webpack_config)) - } else if target.site.is_none() { - let config_path = PathBuf::from("webpack.config.js".to_string()); - // backwards compatibility, deprecated in 1.6.0 - // if webpack.config.js exists and is not specified in wrangler.toml, use it and warn - if bundle.has_webpack_config(&config_path) { - message::warn("In Wrangler v1.6.0, you will need to include a webpack_config field in your wrangler.toml to build with a custom webpack configuration."); - Some(config_path) - } else { - // if webpack.config.js does not exist, don't warn, use our default + let custom_webpack_config_path = match &target.webpack_config { + Some(webpack_config) => match &target.site { + None => Some(PathBuf::from(&webpack_config)), + Some(_) => { + message::warn("Workers Sites does not support custom webpack configuration files"); + None + } + }, + None => { + if target.site.is_none() { + let config_path = PathBuf::from("webpack.config.js".to_string()); + if config_path.exists() { + message::warn("If you would like to use your own custom webpack configuration, you will need to add this to your wrangler.toml:\nwebpack_config = \"webpack.config.js\""); + } + } None } - } else { - // don't use `webpack.config.js` if this project is a site - None }; - // if {webpack.config.js} is not present, we infer the entry based on the - // {package.json} file and pass it to {wranglerjs}. - // https://github.com/cloudflare/wrangler/issues/98 - if let Some(webpack_config_path) = webpack_config_path { + // 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 { build_with_custom_webpack(&mut command, &webpack_config_path); } else { build_with_default_webpack(&mut command, &build_dir)?; @@ -234,7 +234,6 @@ fn build_with_default_webpack( pub fn scaffold_site_worker(target: &Target) -> Result<(), failure::Error> { let build_dir = target.build_dir()?; - // TODO: this is a placeholder template. Replace with The Real Thing on launch. let template = "https://github.com/cloudflare/worker-sites-init"; if !Path::new(&build_dir).exists() { @@ -272,7 +271,7 @@ fn run_npm_install(dir: &PathBuf) -> Result<(), failure::Error> { info!("skipping npm install because node_modules exists"); } - // TODO(sven): figure out why the file doesn't exits in some cases? + // TODO: (sven) figure out why the file doesn't exist in some cases if flock_path.exists() { fs::remove_file(&flock_path)?; } diff --git a/src/commands/build/wranglerjs/output.rs b/src/commands/build/wranglerjs/output.rs index 5cd70de03..87d401a13 100644 --- a/src/commands/build/wranglerjs/output.rs +++ b/src/commands/build/wranglerjs/output.rs @@ -6,8 +6,8 @@ use serde::Deserialize; use std::io::prelude::*; // This structure represents the communication between {wranglerjs} and -// {wrangler}. It is send back after {wranglerjs} completion. -// FIXME(sven): make this private +// {wrangler}. It is sent back after {wranglerjs} completion. +// TODO: (sven) make this private #[derive(Deserialize, Debug)] pub struct WranglerjsOutput { pub wasm: Option, @@ -28,7 +28,7 @@ impl WranglerjsOutput { fn project_size_bytes(&self) -> u64 { let mut e = ZlibEncoder::new(Vec::new(), Compression::default()); - //approximation of how projects are gzipped + // approximation of how projects are gzipped e.write_all(&self.script.as_bytes()) .expect("could not write script buffer"); @@ -42,7 +42,7 @@ impl WranglerjsOutput { fn project_size_message(compressed_size: u64) -> String { const MAX_PROJECT_SIZE: u64 = 1 << 20; // 1 MiB - const WARN_THRESHOLD: u64 = MAX_PROJECT_SIZE - 81_920; //Warn when less than 80 KiB left to grow, ~92% usage + const WARN_THRESHOLD: u64 = MAX_PROJECT_SIZE - 81_920; // Warn when less than 80 KiB left to grow, ~92% usage const MAX_BEFORE_WARN: u64 = WARN_THRESHOLD - 1; let bytes_left = MAX_PROJECT_SIZE.checked_sub(compressed_size); diff --git a/src/commands/config/mod.rs b/src/commands/config/mod.rs index 944685740..e5b75e534 100644 --- a/src/commands/config/mod.rs +++ b/src/commands/config/mod.rs @@ -7,8 +7,7 @@ use std::path::PathBuf; use crate::settings::global_user::{get_global_config_dir, GlobalUser}; -// set the permissions on the dir, we want to avoid that other user reads to -// file +// set the permissions on the dir, we want to avoid other user reads of the file #[cfg(not(target_os = "windows"))] pub fn set_file_mode(file: &PathBuf) { File::open(&file) diff --git a/src/commands/kv/bucket/upload.rs b/src/commands/kv/bucket/upload.rs index b6a5c86e8..ce364b46a 100644 --- a/src/commands/kv/bucket/upload.rs +++ b/src/commands/kv/bucket/upload.rs @@ -172,7 +172,7 @@ mod tests { // Ensure the expected key and value was returned in the filtered pair list // Awkward field-by-field comparison below courtesy of not yet implementing // PartialEq for KeyValuePair in cloudflare-rs :) - // todo(gabbi): Implement PartialEq for KeyValuePair in cloudflare-rs. + // TODO: (gabbi) Implement PartialEq for KeyValuePair in cloudflare-rs. assert!(pair.key == actual[idx].key); assert!(pair.value == actual[idx].value); idx += 1; diff --git a/src/commands/kv/key/get.rs b/src/commands/kv/key/get.rs index 5ab68d363..094dba3e9 100644 --- a/src/commands/kv/key/get.rs +++ b/src/commands/kv/key/get.rs @@ -1,4 +1,4 @@ -// todo(gabbi): This file should use cloudflare-rs instead of our http::auth_client +// TODO:(gabbi) This file should use cloudflare-rs instead of our http::auth_client // when https://github.com/cloudflare/cloudflare-rs/issues/26 is handled (this is // because the GET key operation doesn't return json on success--just the raw // value). diff --git a/src/commands/kv/key/put.rs b/src/commands/kv/key/put.rs index 3502a8966..2c3cf5297 100644 --- a/src/commands/kv/key/put.rs +++ b/src/commands/kv/key/put.rs @@ -1,4 +1,4 @@ -// todo(gabbi): This file should use cloudflare-rs instead of our http::auth_client +// TODO: (gabbi) This file should use cloudflare-rs instead of our http::auth_client // when https://github.com/cloudflare/cloudflare-rs/issues/26 is handled (this is // because the SET key request body is not json--it is the raw value). diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 610bf8027..6acaba4d3 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -22,7 +22,7 @@ pub use subdomain::get_subdomain; pub use subdomain::set_subdomain; pub use whoami::whoami; -/// Run the given command and return its stdout. +// Run the given command and return its stdout. pub fn run(mut command: Command, command_name: &str) -> Result<(), failure::Error> { log::info!("Running {:?}", command); diff --git a/src/commands/preview/fiddle_messenger.rs b/src/commands/preview/fiddle_messenger.rs index c5a9b8e05..3beb1ee31 100644 --- a/src/commands/preview/fiddle_messenger.rs +++ b/src/commands/preview/fiddle_messenger.rs @@ -35,23 +35,23 @@ impl Handler for FiddleMessageServer { const SAFE_ADDRS: &[&str] = &["127.0.0.1", "localhost", "::1"]; - //origin() returns Result> + // origin() returns Result> let origin = handshake .request .origin()? .unwrap_or("unknown") .trim_end_matches(|c: char| c == '/' || c == ':' || c.is_numeric()); - //remote_addr returns Result> + // remote_addr returns Result> let incoming_addr = handshake.remote_addr()?; let incoming_addr = incoming_addr.as_ref().map_or("unknown", String::as_str); - //only allow connections from cloudflareworkers.com + // only allow connections from cloudflareworkers.com let origin_is_safe = SAFE_ORIGINS .iter() .any(|safe_origin| &origin == safe_origin); - //only allow incoming websocket connections from localhost/current machine. + // only allow incoming websocket connections from localhost/current machine. let addr_is_safe = SAFE_ADDRS .iter() .any(|safe_addr| &incoming_addr == safe_addr); diff --git a/src/commands/preview/mod.rs b/src/commands/preview/mod.rs index 74a84f457..7cb6416bd 100644 --- a/src/commands/preview/mod.rs +++ b/src/commands/preview/mod.rs @@ -48,7 +48,8 @@ pub fn preview( let https_str = if https { "https://" } else { "http://" }; if livereload { - let server = WebSocket::new(|out| FiddleMessageServer { out })?.bind("127.0.0.1:0")?; //explicitly use 127.0.0.1, since localhost can resolve to 2 addresses + // explicitly use 127.0.0.1, since localhost can resolve to 2 addresses + let server = WebSocket::new(|out| FiddleMessageServer { out })?.bind("127.0.0.1:0")?; let ws_port = server.local_addr()?.port(); @@ -61,7 +62,7 @@ pub fn preview( ))?; } - //don't do initial GET + POST with livereload as the expected behavior is unclear. + // don't do initial GET + POST with livereload as the expected behavior is unclear. let broadcaster = server.broadcaster(); thread::spawn(move || server.run()); diff --git a/src/commands/publish/upload_form/mod.rs b/src/commands/publish/upload_form/mod.rs index 5faebc0af..e9c7a7b19 100644 --- a/src/commands/publish/upload_form/mod.rs +++ b/src/commands/publish/upload_form/mod.rs @@ -56,8 +56,8 @@ pub fn build( build_form(&assets) } TargetType::Webpack => { - log::info!("Webpack project detected. Publishing..."); - // FIXME(sven): shouldn't new + log::info!("webpack project detected. Publishing..."); + // TODO: https://github.com/cloudflare/wrangler/issues/850 let build_dir = target.build_dir()?; let bundle = wranglerjs::Bundle::new(&build_dir); diff --git a/src/main.rs b/src/main.rs index 3c7abf79c..6b7c593d2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -409,8 +409,9 @@ fn run() -> Result<(), failure::Error> { let default = !matches.is_present("api-key"); let user: GlobalUser = if default { - // Default: use API token. - message::info("Looking to use a Global API Key and email instead? Run \"wrangler config --api-key\". (Not Recommended)"); + // API Tokens are the default + message::info("To find your API token, go to https://dash.cloudflare.com/profile/api-tokens and create it using the \"Edit Cloudflare Workers\" template"); + message::info("If you are trying to use your Global API Key instead of an API Token (Not Recommended), run \"wrangler config --api-key\"."); println!("Enter API token: "); let mut api_token: String = read!("{}\n"); api_token.truncate(api_token.trim_end().len()); @@ -466,7 +467,7 @@ fn run() -> Result<(), failure::Error> { let name = matches.value_of("name"); let site = matches.is_present("site"); let target_type = if site { - // Workers Sites projects are always Webpack for now + // Workers Sites projects are always webpack for now Some(TargetType::Webpack) } else { match matches.value_of("type") { @@ -563,7 +564,7 @@ fn run() -> Result<(), failure::Error> { } None => delete_matches .value_of("namespace-id") - .unwrap() // clap configs ensure that if "binding" isn't present,"namespace-id" must be. + .unwrap() // clap configs ensure that if "binding" isn't present, "namespace-id" must be. .to_string(), }; commands::kv::namespace::delete(&target, &user, &namespace_id)?; diff --git a/src/settings/target/manifest.rs b/src/settings/target/manifest.rs index 676498f60..5e8bf7cbb 100644 --- a/src/settings/target/manifest.rs +++ b/src/settings/target/manifest.rs @@ -122,7 +122,7 @@ impl Manifest { } pub fn get_target(&self, environment_name: Option<&str>) -> Result { - // Site projects are always Webpack for now; don't let toml override this. + // Site projects are always webpack for now; don't let toml override this. let target_type = match self.site { Some(_) => TargetType::Webpack, None => self.target_type.clone(), diff --git a/src/settings/target/site.rs b/src/settings/target/site.rs index 39e0ebefa..46f98a5ce 100644 --- a/src/settings/target/site.rs +++ b/src/settings/target/site.rs @@ -21,6 +21,9 @@ impl Site { site } + // if the user has configured `site.entry-point`, use that + // as the build directory. Otherwise use the default const + // SITE_ENTRY_POINT pub fn build_dir(&self, current_dir: PathBuf) -> Result { Ok(current_dir.join( self.entry_point diff --git a/src/settings/target/target.rs b/src/settings/target/target.rs index 38ae9e6d8..42dc49e64 100644 --- a/src/settings/target/target.rs +++ b/src/settings/target/target.rs @@ -40,9 +40,6 @@ impl Target { let current_dir = env::current_dir()?; // if `site` is configured, we want to isolate worker code // and build artifacts away from static site application code. - // if the user has configured `site.entry-point`, use that - // as the build directory. Otherwise use the default const - // SITE_BUILD_DIR match &self.site { Some(site_config) => site_config.build_dir(current_dir), None => Ok(current_dir), diff --git a/src/util.rs b/src/util.rs index 90a2ce2a6..2c72b40a5 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,9 +1,9 @@ use std::process::{Child, Command}; -/// wrapper around spawning child processes such that they -/// have the same behavior as spawned threads i.e. a spawned -/// child process using GuardedChild has the same lifetime as -/// the main thread. +// wrapper around spawning child processes such that they +// have the same behavior as spawned threads i.e. a spawned +// child process using GuardedChild has the same lifetime as +// the main thread. pub struct GuardedCommand(Child); impl GuardedCommand { diff --git a/tests/build.rs b/tests/build.rs index f43f74554..1a8d10675 100644 --- a/tests/build.rs +++ b/tests/build.rs @@ -39,7 +39,7 @@ fn it_builds_with_webpack_single_js() { let fixture = "webpack_simple_js"; utils::create_temporary_copy(fixture); single_env_settings! {fixture, r#" - type = "Webpack" + type = "webpack" "#}; build(fixture); @@ -53,7 +53,8 @@ fn it_builds_with_webpack_function_config_js() { utils::create_temporary_copy(fixture); single_env_settings! {fixture, r#" - type = "Webpack" + type = "webpack" + webpack_config = "webpack.config.js" "#}; build(fixture); @@ -66,8 +67,17 @@ fn it_builds_with_webpack_promise_config_js() { let fixture = "webpack_promise_config_js"; utils::create_temporary_copy(fixture); + utils::create_fixture_file( + fixture, + "webpack.config.js", + r#" + module.exports = Promise.resolve({ entry: "./index.js" }); + "#, + ); + single_env_settings! {fixture, r#" - type = "Webpack" + type = "webpack" + webpack_config = "webpack.config.js" "#}; build(fixture); @@ -80,8 +90,17 @@ fn it_builds_with_webpack_function_promise_config_js() { let fixture = "webpack_function_promise_config_js"; utils::create_temporary_copy(fixture); + utils::create_fixture_file( + fixture, + "webpack.config.js", + r#" + module.exports = Promise.resolve({ entry: "./index.js" }); + "#, + ); + single_env_settings! {fixture, r#" - type = "Webpack" + type = "webpack" + webpack_config = "webpack.config.js" "#}; build(fixture); @@ -95,7 +114,7 @@ fn it_builds_with_webpack_single_js_use_package_main() { utils::create_temporary_copy(fixture); single_env_settings! {fixture, r#" - type = "Webpack" + type = "webpack" "#}; build(fixture); @@ -108,8 +127,16 @@ fn it_builds_with_webpack_specify_configs() { let fixture = "webpack_specify_config"; utils::create_temporary_copy(fixture); + utils::create_fixture_file( + fixture, + "webpack.worker.js", + r#" + module.exports = { entry: "./index.js" }; + "#, + ); + single_env_settings! {fixture, r#" - type = "Webpack" + type = "webpack" webpack_config = "webpack.worker.js" "#}; @@ -124,7 +151,7 @@ fn it_builds_with_webpack_single_js_missing_package_main() { utils::create_temporary_copy(fixture); single_env_settings! {fixture, r#" - type = "Webpack" + type = "webpack" "#}; build_fails_with( @@ -139,22 +166,20 @@ fn it_fails_with_multiple_webpack_configs() { let fixture = "webpack_multiple_config"; utils::create_temporary_copy(fixture); - single_env_settings! {fixture, r#" - type = "Webpack" - "#}; - - build_fails_with(fixture, "Multiple webpack configurations are not supported. You can specify a different path for your webpack configuration file in wrangler.toml with the `webpack_config` field"); - utils::cleanup(fixture); -} - -#[test] -fn it_fails_with_multiple_specify_webpack_configs() { - let fixture = "webpack_multiple_specify_config"; - utils::create_temporary_copy(fixture); + utils::create_fixture_file( + fixture, + "webpack.config.js", + r#" + module.exports = [ + { entry: "./a.js" }, + { entry: "./b.js" } + ] + "#, + ); single_env_settings! {fixture, r#" - type = "Webpack" - webpack_config = "webpack.worker.js" + type = "webpack" + webpack_config = "webpack.config.js" "#}; build_fails_with(fixture, "Multiple webpack configurations are not supported. You can specify a different path for your webpack configuration file in wrangler.toml with the `webpack_config` field"); @@ -167,7 +192,8 @@ fn it_builds_with_webpack_wast() { utils::create_temporary_copy(fixture); single_env_settings! {fixture, r#" - type = "Webpack" + type = "webpack" + webpack_config = "webpack.config.js" "#}; build(fixture); @@ -184,15 +210,20 @@ fn it_fails_with_webpack_target_node() { let fixture = "webpack_target_node"; utils::create_temporary_copy(fixture); - utils::webpack_config( + utils::create_fixture_file( fixture, - r#"{ - entry: "./index.js", - target: "node", - }"#, + "webpack.config.js", + r#" + module.exports = { + "entry": "./index.js", + "target": "node" + } + "#, ); + single_env_settings! {fixture, r#" type = "webpack" + webpack_config = "webpack.config.js" "#}; build_fails_with( @@ -207,15 +238,20 @@ fn it_fails_with_webpack_target_web() { let fixture = "webpack_target_web"; utils::create_temporary_copy(fixture); - utils::webpack_config( + utils::create_fixture_file( fixture, - r#"{ - entry: "./index.js", - target: "web", - }"#, + "webpack.config.js", + r#" + module.exports = { + "entry": "./index.js", + "target": "web" + } + "#, ); + single_env_settings! {fixture, r#" type = "webpack" + webpack_config = "webpack.config.js" "#}; build_fails_with( @@ -230,15 +266,20 @@ fn it_builds_with_webpack_target_webworker() { let fixture = "webpack_target_webworker"; utils::create_temporary_copy(fixture); - utils::webpack_config( + utils::create_fixture_file( fixture, - r#"{ - entry: "./index.js", - target: "webworker", - }"#, + "webpack.config.js", + r#" + module.exports = { + "entry": "./index.js", + "target": "webworker" + } + "#, ); + single_env_settings! {fixture, r#" type = "webpack" + webpack_config = "webpack.config.js" "#}; build(fixture); diff --git a/tests/fixtures/webpack_function_promise_config_js/package.json b/tests/fixtures/webpack_function_promise_config_js/package.json index 0967ef424..f68471d54 100644 --- a/tests/fixtures/webpack_function_promise_config_js/package.json +++ b/tests/fixtures/webpack_function_promise_config_js/package.json @@ -1 +1,3 @@ -{} +{ + "main": "index.js" +} diff --git a/tests/fixtures/webpack_function_promise_config_js/webpack.config.js b/tests/fixtures/webpack_function_promise_config_js/webpack.config.js deleted file mode 100644 index 545658983..000000000 --- a/tests/fixtures/webpack_function_promise_config_js/webpack.config.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = () => Promise.resolve({ entry: "./index.js" }); diff --git a/tests/fixtures/webpack_multiple_config/package.json b/tests/fixtures/webpack_multiple_config/package.json index 0967ef424..f68471d54 100644 --- a/tests/fixtures/webpack_multiple_config/package.json +++ b/tests/fixtures/webpack_multiple_config/package.json @@ -1 +1,3 @@ -{} +{ + "main": "index.js" +} diff --git a/tests/fixtures/webpack_multiple_config/webpack.config.js b/tests/fixtures/webpack_multiple_config/webpack.config.js deleted file mode 100644 index faf40ebac..000000000 --- a/tests/fixtures/webpack_multiple_config/webpack.config.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = [ - { entry: "./a.js" }, - { entry: "./b.js" } -] diff --git a/tests/fixtures/webpack_multiple_specify_config/index.js b/tests/fixtures/webpack_multiple_specify_config/index.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/fixtures/webpack_multiple_specify_config/package.json b/tests/fixtures/webpack_multiple_specify_config/package.json deleted file mode 100644 index 9e26dfeeb..000000000 --- a/tests/fixtures/webpack_multiple_specify_config/package.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/tests/fixtures/webpack_multiple_specify_config/webpack.worker.js b/tests/fixtures/webpack_multiple_specify_config/webpack.worker.js deleted file mode 100644 index fb177715e..000000000 --- a/tests/fixtures/webpack_multiple_specify_config/webpack.worker.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = [ - { entry: "./a.js" }, - { entry: "./b.js" } - ] \ No newline at end of file diff --git a/tests/fixtures/webpack_simple_js/package.json b/tests/fixtures/webpack_simple_js/package.json index 0967ef424..f68471d54 100644 --- a/tests/fixtures/webpack_simple_js/package.json +++ b/tests/fixtures/webpack_simple_js/package.json @@ -1 +1,3 @@ -{} +{ + "main": "index.js" +} diff --git a/tests/fixtures/webpack_simple_js/webpack.config.js b/tests/fixtures/webpack_simple_js/webpack.config.js deleted file mode 100644 index f07507ec6..000000000 --- a/tests/fixtures/webpack_simple_js/webpack.config.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = { entry: "./index.js" }; diff --git a/tests/fixtures/webpack_specify_config/package.json b/tests/fixtures/webpack_specify_config/package.json index 0967ef424..f68471d54 100644 --- a/tests/fixtures/webpack_specify_config/package.json +++ b/tests/fixtures/webpack_specify_config/package.json @@ -1 +1,3 @@ -{} +{ + "main": "index.js" +} diff --git a/tests/fixtures/webpack_specify_config/webpack.worker.js b/tests/fixtures/webpack_specify_config/webpack.worker.js deleted file mode 100644 index f07507ec6..000000000 --- a/tests/fixtures/webpack_specify_config/webpack.worker.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = { entry: "./index.js" }; diff --git a/tests/fixtures/webpack_target_node/package.json b/tests/fixtures/webpack_target_node/package.json new file mode 100644 index 000000000..f68471d54 --- /dev/null +++ b/tests/fixtures/webpack_target_node/package.json @@ -0,0 +1,3 @@ +{ + "main": "index.js" +} diff --git a/tests/fixtures/webpack_target_web/package.json b/tests/fixtures/webpack_target_web/package.json new file mode 100644 index 000000000..f68471d54 --- /dev/null +++ b/tests/fixtures/webpack_target_web/package.json @@ -0,0 +1,3 @@ +{ + "main": "index.js" +} diff --git a/tests/fixtures/webpack_target_webworker/package.json b/tests/fixtures/webpack_target_webworker/package.json new file mode 100644 index 000000000..f68471d54 --- /dev/null +++ b/tests/fixtures/webpack_target_webworker/package.json @@ -0,0 +1,3 @@ +{ + "main": "index.js" +} diff --git a/tests/preview.rs b/tests/preview.rs index 17bcd4d05..79e0dda57 100644 --- a/tests/preview.rs +++ b/tests/preview.rs @@ -5,6 +5,7 @@ pub mod utils; use assert_cmd::prelude::*; +use std::env; use std::fs::File; use std::io::Write; use std::process::Command; @@ -69,7 +70,7 @@ fn it_can_preview_rust_project() { fn preview(fixture: &str) { // Lock to avoid having concurrent builds let _g = BUILD_LOCK.lock().unwrap(); - + env::remove_var("CF_ACCOUNT_ID"); let mut preview = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap(); preview.current_dir(utils::fixture_path(fixture)); preview.arg("preview").arg("--headless").assert().success(); diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs index 457632885..2a7c1d0b5 100644 --- a/tests/utils/mod.rs +++ b/tests/utils/mod.rs @@ -54,15 +54,10 @@ pub fn create_temporary_copy(fixture: &str) { copy(src, dest, &options).unwrap(); } -// TODO: remove once https://github.com/cloudflare/wrangler/pull/489 is merged -pub fn webpack_config(fixture: &str, config: &str) { - let file_path = fixture_path(fixture).join("webpack.config.js"); +pub fn create_fixture_file(fixture: &str, name: &str, content: &str) { + let file_path = fixture_path(fixture).join(name); + println!("{:?}", file_path); let mut file = File::create(file_path).unwrap(); - let content = format!( - r#" - module.exports = {}; - "#, - config - ); + let content = String::from(content); file.write_all(content.as_bytes()).unwrap(); } diff --git a/wranglerjs/index.js b/wranglerjs/index.js index 2468863d4..2e81bfed2 100644 --- a/wranglerjs/index.js +++ b/wranglerjs/index.js @@ -34,7 +34,7 @@ function filterByExtension(ext) { } // Check if the config is a function and await it either way in - // case the result is a promise + // case the result is a Promise config = await (typeof config === "function" ? config({}) : config); if (Array.isArray(config)) {