Repository: cloudflare/wrangler (rust)

Issue:
wrangler init --type="javascript" doesn’t work as expected
### 🐛 Bug report

<!-- 
  Did you remember to update wrangler?
  https://developers.cloudflare.com/workers/cli-wrangler/install-update#update

  Did you search for related issues?
  https://github.com/cloudflare/wrangler/issues
-->

#### Describe the bug

`wrangler init` doesn’t work as expected when `--type="javascript"`.

Running `wrangler init --type="javascript"` outputs a `wrangler.toml` file where, unexpectedly, `type = 'webpack'` and `target_type = "js"`.

It is accompanied by a warning in the console:

```text
⚠️  The template recommends the "webpack" type. Using type "js" may cause errors, we recommend changing the type field in wrangler.toml to "webpack"
```

#### Reproduce the bug

Run `wrangler init --type="javascript"`

#### Expected behavior

Running `wrangler init --type="javascript"` should produce a `wrangler.toml` similar to the following:

```toml
# ... truncated
type = "javascript"
build.command = "npm install && npm run build"
```

#### Environment and versions

Fill out the following information about your environment.

* operating system: MacOS 10.15.7 
* output of `wrangler -V`: wrangler 1.17.0
* output of `node -v`: v14.16.1
* content of `wrangler.toml`: N/A


Pull request description:
Made config add target_type to type instead of "target_type"
Fixes #1960

We used serde to rename the `target_type` field to `type` but when making the toml ourselves we still used `target_type`

Patch:
diff --git a/src/settings/toml/manifest.rs b/src/settings/toml/manifest.rs
index 55efbbde..ec88dfb3 100644
--- a/src/settings/toml/manifest.rs
+++ b/src/settings/toml/manifest.rs
@@ -140,7 +140,7 @@ impl Manifest {
             config_template_doc["workers_dev"] = toml_edit::value(default_workers_dev);
         }
         if let Some(target_type) = &target_type {
-            config_template_doc["target_type"] = toml_edit::value(target_type.to_string());
+            config_template_doc["type"] = toml_edit::value(target_type.to_string());
         }
         if let Some(site) = site {
             if config_template.site.is_none() {
@@ -685,3 +685,29 @@ fn get_namespaces(
         Ok(Vec::new())
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    #[test]
+    fn generate() -> Result<()> {
+        let toml_path = Path::new(".");
+
+        let toml = Manifest::generate(
+            "test".to_string(),
+            Some(TargetType::JavaScript),
+            toml_path,
+            None,
+        )?;
+        assert_eq!(toml.name.to_string(), "test".to_string());
+        assert_eq!(toml.target_type.to_string(), "javascript".to_string());
+        fs::remove_file(toml_path.with_file_name("wrangler.toml"))?;
+
+        let toml = Manifest::generate("test".to_string(), None, toml_path, None)?;
+        assert_eq!(toml.target_type.to_string(), "webpack".to_string());
+        fs::remove_file(toml_path.with_file_name("wrangler.toml"))?;
+
+        Ok(())
+    }
+}
diff --git a/src/settings/toml/target_type.rs b/src/settings/toml/target_type.rs
index aeeb6c98..0ed34b9c 100644
--- a/src/settings/toml/target_type.rs
+++ b/src/settings/toml/target_type.rs
@@ -21,7 +21,7 @@ impl Default for TargetType {
 impl fmt::Display for TargetType {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         let printable = match *self {
-            TargetType::JavaScript => "js",
+            TargetType::JavaScript => "javascript",
             TargetType::Rust => "rust",
             TargetType::Webpack => "webpack",
         };


Test patch:
diff --git a/tests/build.rs b/tests/build.rs
index 9ec7b840..88f3fadb 100644
--- a/tests/build.rs
+++ b/tests/build.rs
@@ -359,7 +359,8 @@ fn it_builds_with_webpack_name_output_warn() {
 
     assert!(
         stderr.contains("webpack's output filename is being renamed"),
-        format!("given: {}", stderr)
+        "given: {}",
+        stderr
     );
 }
 
@@ -415,11 +416,9 @@ fn build_fails_with(fixture: &Fixture, expected_message: &str) {
         str::from_utf8(&output.stderr)
             .unwrap()
             .contains(expected_message),
-        format!(
-            "expected {:?} not found, given: {:?}",
-            expected_message,
-            str::from_utf8(&output.stderr)
-        )
+        "expected {:?} not found, given: {:?}",
+        expected_message,
+        str::from_utf8(&output.stderr)
     );
 }