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

Commit

Permalink
Merge branch 'master' into malonso/readme-update
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleygwilliams authored Jul 30, 2019
2 parents d2f3396 + d43c54e commit 85a6865
Show file tree
Hide file tree
Showing 37 changed files with 942 additions and 330 deletions.
36 changes: 36 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: 'Bug report'
labels: user report
---

### 🐛 Bug Report

<!-- Please answer these questions before submitting your issue. Thanks! -->

#### What version of Wrangler are you using (`wrangler -V`)?

<pre>
$ wrangler -V

</pre>

#### Does this issue reproduce with the latest release?



#### What environment are you using?
* operating system:
* rustc version:
* node version:

#### What did you do?

<!--
If possible, provide a recipe for reproducing the error.
-->

#### What did you expect to see?



#### What did you see instead?
14 changes: 14 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: 'Feature request'
labels: user report
---

### 💡 Feature request

<!-- Please answer these questions before submitting your issue. Thanks! -->

#### Overview and problem statement
Brief explanation of the requested feature, and a description of the problem it would solve.

#### Basic example
Include a basic code example of this new feature if possible. Omit this section if not applicable.
69 changes: 69 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Contributing

Wrangler is an open source project because we believe that folks should have access, insight,
and the opportunity to contirbute to their developer tools. Wrangler is also a product
delivered by Cloudflare, so it's important to clarify how we think about issue triage and
contributions.

## People

Wrangler is maintained by @ashleygwilliams, and her team, [Workers Developer Experience].

[Workers Developer Experience]: https://github.com/orgs/cloudflare/teams/workers-devexp

## Primary Issue Triage

Within 3 days, any incoming issue should be triaged. Triage involves:

- reading the issue and requesting any further information
- always thank the user for submitting

### 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

### Assignment

- if the issue will require a large amount of back and forth between the reporter and the team
assign a single team member to manage the conversation

## Product Issue Triage

Once a week, the team meets to do Product Triage. This is where we assign work and update
our plans for the milestones and releases.

### Labelling

- 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

- assign all issues for the next two releases a milestone
- assign all issues for the current milestone a person to take point

### Pull Request Triage

Within 3 days, all incoming Community PRs should be triaged. If a team member opens a PR it
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
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
received all required reviews.
- All PRs should be labelled with a changelog label: BREAKING, Feature, Bug, Maintenance, Docs

### Merging

- All PRs should be merged with a Merge Commit. We recommend that folks rebase into a small
number of task driven commits. This is enforced more heavily for team members than
community members. Be reasonable.
- All PRs should be labelled with the current milestone before merging. If a PR for an issue
labelled with a different milestone is to be merged, update the issue milestone as well.
7 changes: 7 additions & 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 @@ -32,6 +32,7 @@ number_prefix = "0.3.0"
flate2 = "1.0.7"
base64 = "0.10.1"
lazy_static = "1.3.0"
text_io = "0.1.7"
exitfailure = "0.5.1"

[dev-dependencies]
Expand Down
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ cargo install wrangler

## 🎙️ Commands

- ### 👯 `generate`
- ### 👯 `generate`
Scaffold a project, including boilerplate for a Rust library and a Cloudflare Worker.
You can pass a name and template to this command optionally.
You can pass a name and template to this command optionally.

```
wrangler generate <name> <template> --type=["webpack", "javascript", "rust"]
Expand Down Expand Up @@ -61,7 +61,7 @@ cargo install wrangler
By default, `publish` will make your worker available at `<project-name>.<subdomain>.workers.dev`.
To disable publishing to your workers.dev subdomain, set `private = true` in your `wrangler.toml`.
This setting prevents the `publish` command from making your worker publicly available. To
explicitly enable deployment to `<project-name>.<subdomain>.workers.dev`, you can set `private = false`.
explicitly enable deployment to `<project-name>.<subdomain>.workers.dev`, you can set `private = false`.

To use this command, you'll need to have the following keys in your `wrangler.toml`:

Expand Down Expand Up @@ -143,6 +143,18 @@ There are two types of configuration that `wrangler` uses: global user and per p
This key is optional if you are using a workers.dev subdomain and is only required for `publish --release`.
- `webpack_config`: This is the path to the webpack configuration file for your worker. This is optional and
defaults to `webpack.config.js`
- `[[kv-namespaces]]`: These specify any [Workers KV](https://workers.cloudflare.com/docs/reference/storage/) namespaces you want to access from
inside your Worker. Each namespace you include should have an entry in your wrangler.toml that includes:

- `binding`: the name you want to bind to in your script
- `id`: the namespace_id assigned to your kv namespace upon creation.
e.g. (per namespace):
``` toml
[[kv-namespaces]]
binding = "FOO"
id = "0f2ac74b498b48028cb68387c421e279"
```
Note: Creating your KV Namespaces should be handled either via the [api](https://workers.cloudflare.com/docs/reference/storage/writing-data/) or via your Cloudflare dashboard.

## ⚓ Installation

Expand Down
75 changes: 0 additions & 75 deletions src/commands/build/wranglerjs/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use std::io::prelude::*;
use std::path::{Path, PathBuf};

use crate::commands::build::wranglerjs::output::WranglerjsOutput;
use crate::settings::binding::Binding;
use crate::settings::metadata;
#[cfg(test)]
use crate::terminal::message;

Expand Down Expand Up @@ -51,21 +49,9 @@ impl Bundle {

script_file.write_all(script.as_bytes())?;

let metadata = create_metadata(self).expect("could not create metadata");
let mut metadata_file = File::create(self.metadata_path())?;
metadata_file.write_all(metadata.as_bytes())?;

Ok(())
}

pub fn metadata_path(&self) -> String {
Path::new(&self.out)
.join("metadata.json".to_string())
.to_str()
.unwrap()
.to_string()
}

pub fn wasm_path(&self) -> String {
Path::new(&self.out)
.join("module.wasm".to_string())
Expand Down Expand Up @@ -104,23 +90,6 @@ pub fn create_prologue() -> String {
.to_string()
}

// This metadata describe the bindings on the Worker.
fn create_metadata(bundle: &Bundle) -> Result<String, serde_json::error::Error> {
let mut bindings = vec![];

if bundle.has_wasm() {
bindings.push(Binding::new_wasm_module(
bundle.get_wasm_binding(),
bundle.get_wasm_binding(),
));
}

serde_json::to_string(&metadata::Metadata {
body_part: "script".to_string(),
bindings,
})
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -136,27 +105,6 @@ mod tests {
dir.to_str().unwrap().to_string()
}

#[test]
fn it_writes_the_bundle_metadata() {
let out = create_temp_dir("it_writes_the_bundle_metadata");
let wranglerjs_output = WranglerjsOutput {
errors: vec![],
script: "".to_string(),

wasm: None,
};
let bundle = Bundle::new_at(out.clone());

bundle.write(&wranglerjs_output).unwrap();
assert!(Path::new(&bundle.metadata_path()).exists());
let contents =
fs::read_to_string(&bundle.metadata_path()).expect("could not read metadata");

assert_eq!(contents, r#"{"body_part":"script","bindings":[]}"#);

cleanup(out);
}

#[test]
fn it_writes_the_bundle_script() {
let out = create_temp_dir("it_writes_the_bundle_script");
Expand Down Expand Up @@ -191,29 +139,6 @@ mod tests {
cleanup(out);
}

#[test]
fn it_writes_the_bundle_wasm_metadata() {
let out = create_temp_dir("it_writes_the_bundle_wasm_metadata");
let wranglerjs_output = WranglerjsOutput {
errors: vec![],
script: "".to_string(),
wasm: Some("abc".to_string()),
};
let bundle = Bundle::new_at(out.clone());

bundle.write(&wranglerjs_output).unwrap();
assert!(Path::new(&bundle.metadata_path()).exists());
let contents =
fs::read_to_string(&bundle.metadata_path()).expect("could not read metadata");

assert_eq!(
contents,
r#"{"body_part":"script","bindings":[{"type":"wasm_module","name":"wasmprogram","part":"wasmprogram"}]}"#
);

cleanup(out);
}

#[test]
fn it_has_errors() {
let wranglerjs_output = WranglerjsOutput {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/build/wranglerjs/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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 MAX_BEFORE_WARN: u64 = WARN_THRESHOLD - 1;

let bytes_left = MAX_PROJECT_SIZE.checked_sub(compressed_size);

Expand All @@ -63,7 +64,7 @@ impl WranglerjsOutput {

match compressed_size {
WARN_THRESHOLD...MAX_PROJECT_SIZE => format!("{}. {2} Your built project is {} away from reaching the 1MiB size limit. {2}", human_size, human_leftover.expect("failed to get leftover bytes"), emoji::WARN),
0...WARN_THRESHOLD => format!("{}.", human_size),
0...MAX_BEFORE_WARN => format!("{}.", human_size),
_ => format!("{}. {1} Your built project has grown past the 1MiB size limit and may fail to deploy. {1}", human_size, emoji::WARN)
}
}
Expand Down
31 changes: 20 additions & 11 deletions src/commands/config.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
use crate::terminal::message;
use std::fs;
use std::path::Path;
use std::fs::File;
#[cfg(not(target_os = "windows"))]
use std::os::unix::fs::PermissionsExt;
use std::path::PathBuf;

use crate::emoji;
use crate::settings::global_user::GlobalUser;
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
#[cfg(not(target_os = "windows"))]
pub fn set_file_mode(file: &PathBuf) {
File::open(&file)
.unwrap()
.set_permissions(PermissionsExt::from_mode(0o600))
.expect("could not set permissions on file");
}

pub fn global_config(email: &str, api_key: &str) -> Result<(), failure::Error> {
let s = GlobalUser {
Expand All @@ -13,19 +25,16 @@ pub fn global_config(email: &str, api_key: &str) -> Result<(), failure::Error> {

let toml = toml::to_string(&s)?;

let config_dir = Path::new(&dirs::home_dir().unwrap_or_else(|| {
panic!(
"{0} could not determine home directory. {0}",
emoji::CONSTRUCTION
)
}))
.join(".wrangler")
.join("config");
let config_dir = get_global_config_dir().expect("could not find global config directory");
fs::create_dir_all(&config_dir)?;

let config_file = config_dir.join("default.toml");
fs::write(&config_file, &toml)?;

// set permissions on the file
#[cfg(not(target_os = "windows"))]
set_file_mode(&config_file);

message::success(&format!(
"Successfully configured. You can find your configuration file at: {}",
&config_file.to_string_lossy()
Expand Down
Loading

0 comments on commit 85a6865

Please sign in to comment.