From 69a4c083403f7d90cf68224b83ffbcf6e1c694cf Mon Sep 17 00:00:00 2001 From: Greg Brimble Date: Fri, 2 Apr 2021 21:05:54 +0100 Subject: [PATCH 1/3] Allow non-Webpack Workers Sites --- src/settings/toml/manifest.rs | 8 +------- src/upload/form/mod.rs | 18 +++++++++--------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/settings/toml/manifest.rs b/src/settings/toml/manifest.rs index dc97582a5..2e2db5be8 100644 --- a/src/settings/toml/manifest.rs +++ b/src/settings/toml/manifest.rs @@ -312,12 +312,6 @@ impl Manifest { environment_name: Option<&str>, preview: bool, ) -> Result { - // 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(), - }; - /* From https://developers.cloudflare.com/workers/cli-wrangler/configuration#keys Top level: required to be configured at the top level of your wrangler.toml only; multiple environments on the same project must share this property @@ -327,7 +321,7 @@ impl Manifest { Not inherited: Must be defined for every environment individually. */ let mut target = Target { - target_type, // Top level + target_type: self.target_type.clone(), // Top level account_id: self.account_id.clone(), // Inherited webpack_config: self.webpack_config.clone(), // Inherited build: self.build.clone(), // Inherited diff --git a/src/upload/form/mod.rs b/src/upload/form/mod.rs index c71dd8137..f4958bc7a 100644 --- a/src/upload/form/mod.rs +++ b/src/upload/form/mod.rs @@ -58,6 +58,14 @@ pub fn build( } } + if let Some(asset_manifest) = asset_manifest { + log::info!("adding __STATIC_CONTENT_MANIFEST"); + let binding = "__STATIC_CONTENT_MANIFEST".to_string(); + let asset_manifest_blob = get_asset_manifest_blob(asset_manifest)?; + let text_blob = TextBlob::new(asset_manifest_blob, binding)?; + text_blobs.push(text_blob); + } + match target_type { TargetType::Rust => { log::info!("Rust project detected. Publishing..."); @@ -89,7 +97,7 @@ pub fn build( log::info!("Plain JavaScript project detected. Publishing..."); let package_dir = target.package_dir()?; let package = Package::new(&package_dir)?; - let script_path = package.main(&package_dir)?; + let script_path = package_dir.join(package.main(&package_dir)?); let assets = ServiceWorkerAssets::new( script_path, @@ -185,14 +193,6 @@ pub fn build( wasm_modules.push(wasm_module); } - if let Some(asset_manifest) = asset_manifest { - log::info!("adding __STATIC_CONTENT_MANIFEST"); - let binding = "__STATIC_CONTENT_MANIFEST".to_string(); - let asset_manifest_blob = get_asset_manifest_blob(asset_manifest)?; - let text_blob = TextBlob::new(asset_manifest_blob, binding)?; - text_blobs.push(text_blob); - } - let assets = ServiceWorkerAssets::new( script_path, wasm_modules, From 589a69f904de3075ecaa86cc846219407336dd4c Mon Sep 17 00:00:00 2001 From: Greg Brimble Date: Fri, 2 Apr 2021 21:44:19 +0100 Subject: [PATCH 2/3] Throw errors on Rust types and when missing build commands on JS types --- src/settings/toml/builder.rs | 2 +- src/settings/toml/manifest.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/settings/toml/builder.rs b/src/settings/toml/builder.rs index 2094e0b10..0d6ec89cb 100644 --- a/src/settings/toml/builder.rs +++ b/src/settings/toml/builder.rs @@ -12,7 +12,7 @@ const WATCH_DIR: &str = "src"; #[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] #[serde(deny_unknown_fields)] pub struct Builder { - command: Option, + pub command: Option, #[serde(default = "project_root")] pub cwd: PathBuf, #[serde(default = "upload_dir")] diff --git a/src/settings/toml/manifest.rs b/src/settings/toml/manifest.rs index 2e2db5be8..1d2955156 100644 --- a/src/settings/toml/manifest.rs +++ b/src/settings/toml/manifest.rs @@ -312,6 +312,33 @@ impl Manifest { environment_name: Option<&str>, preview: bool, ) -> Result { + if self.site.is_some() { + match self.target_type { + TargetType::Rust => { + failure::bail!(format!( + "{} Workers Sites does not support Rust type projects.", + emoji::WARN + )) + } + TargetType::JavaScript => { + if let Some(build) = &self.build { + if build.command.is_none() { + failure::bail!(format!( + "{} Workers Sites requires using a bundler, and your configuration indicates that you aren't using one. You can fix this by:\n* setting your project type to \"webpack\" to use our automatically configured webpack bundler.\n* setting your project type to \"javascript\", and configuring a build command in the `[build]` section if you wish to use your choice of bundler.", + emoji::WARN + )) + } + } else { + failure::bail!(format!( + "{} Workers Sites requires using a bundler, and your configuration indicates that you aren't using one. You can fix this by:\n* setting your project type to \"webpack\" to use our automatically configured webpack bundler.\n* setting your project type to \"javascript\", and configuring a build command in the `[build]` section if you wish to use your choice of bundler.", + emoji::WARN + )) + } + } + _ => {} + } + } + /* From https://developers.cloudflare.com/workers/cli-wrangler/configuration#keys Top level: required to be configured at the top level of your wrangler.toml only; multiple environments on the same project must share this property From 8e78fb8a5cea12b6cd977b794718299bec92fdd2 Mon Sep 17 00:00:00 2001 From: Greg Brimble Date: Tue, 6 Apr 2021 23:35:10 +0100 Subject: [PATCH 3/3] Extract out error message --- src/settings/toml/manifest.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/settings/toml/manifest.rs b/src/settings/toml/manifest.rs index 1d2955156..332184260 100644 --- a/src/settings/toml/manifest.rs +++ b/src/settings/toml/manifest.rs @@ -321,18 +321,16 @@ impl Manifest { )) } TargetType::JavaScript => { + let error_message = format!( + "{} Workers Sites requires using a bundler, and your configuration indicates that you aren't using one. You can fix this by:\n* setting your project type to \"webpack\" to use our automatically configured webpack bundler.\n* setting your project type to \"javascript\", and configuring a build command in the `[build]` section if you wish to use your choice of bundler.", + emoji::WARN + ); if let Some(build) = &self.build { if build.command.is_none() { - failure::bail!(format!( - "{} Workers Sites requires using a bundler, and your configuration indicates that you aren't using one. You can fix this by:\n* setting your project type to \"webpack\" to use our automatically configured webpack bundler.\n* setting your project type to \"javascript\", and configuring a build command in the `[build]` section if you wish to use your choice of bundler.", - emoji::WARN - )) + failure::bail!(error_message) } } else { - failure::bail!(format!( - "{} Workers Sites requires using a bundler, and your configuration indicates that you aren't using one. You can fix this by:\n* setting your project type to \"webpack\" to use our automatically configured webpack bundler.\n* setting your project type to \"javascript\", and configuring a build command in the `[build]` section if you wish to use your choice of bundler.", - emoji::WARN - )) + failure::bail!(error_message) } } _ => {}