Skip to content

Commit d9ef0a1

Browse files
JakeChampionJake Champion
andauthored
remove packing ability and requirement for fastly.toml file to exist when using the js-compute-runtime cli (#108)
Co-authored-by: Jake Champion <[email protected]>
1 parent ade5133 commit d9ef0a1

File tree

6 files changed

+10
-95
lines changed

6 files changed

+10
-95
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## unreleased
2+
3+
### Enhancements
4+
5+
- Removed the requirement for a fastly.toml file to be present when using js-compute-runtimes CLI to compile a WASM file
6+
7+
- **Breaking change:** Removed --skip-pkg argument from js-compute-runtime's CLI
8+
[#108](https://github.com/fastly/js-compute-runtime/pull/108)
9+
110
## 0.2.5 (2022-04-12)
211

312
### Fixes

Cargo.lock

Lines changed: 0 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ edition = "2018"
88
anyhow = "1.0.34"
99
env_logger = "0.8.2"
1010
log = "0.4.11"
11-
sanitize-filename = "0.3.0"
1211
structopt = "0.3.20"
1312
tempfile = "3.1.0"
14-
toml = "0.5.0"
1513
wizer = "1.4.0"

README.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,6 @@ As an example, to turn a file `test.js` with this source code:
9696
addEventListener('fetch', e => {
9797
console.log("Hello World!");
9898
});
99-
```
100-
Create a fastly.toml file which is required for the application to run:
101-
```toml
102-
# This file describes a Fastly Compute@Edge package. To learn more visit:
103-
# https://developer.fastly.com/reference/fastly-toml/
104-
105-
authors = ["[email protected]"]
106-
description = "test service"
107-
language = "javascript"
108-
manifest_version = 2
109-
name = "test"
110-
service_id = ""
111-
11299
```
113100

114101
into a C@E service with your build of the CLI tool, run the following command:

integration-tests/js-compute/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"scripts": {
33
"install:ci": "npm ci",
4-
"build:test": "base=$npm_config_test; webpack \"./fixtures/$base/$base.ts\" --output-path \"./fixtures/$base\" --output-filename \"$base.js\"; ../../target/release/js-compute-runtime --skip-pkg \"./fixtures/$base/$base.js\" \"./fixtures/$base/$base.wasm\"",
4+
"build:test": "base=$npm_config_test; webpack \"./fixtures/$base/$base.ts\" --output-path \"./fixtures/$base\" --output-filename \"$base.js\"; ../../target/release/js-compute-runtime \"./fixtures/$base/$base.js\" \"./fixtures/$base/$base.wasm\"",
55
"lint": "npx prettier --write ./fixtures/**/*.ts"
66
},
77
"devDependencies": {

src/main.rs

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use anyhow::Context;
22
use std::fs;
3-
use std::mem::ManuallyDrop;
43
use std::path::{Path, PathBuf};
54
use std::process::Command;
65
use structopt::StructOpt;
7-
use toml::Value;
86
use wizer::Wizer;
97

108
#[derive(StructOpt)]
@@ -21,10 +19,6 @@ pub struct Options {
2119
#[structopt(long, parse(from_os_str))]
2220
engine_wasm: Option<PathBuf>,
2321

24-
/// Skip creation of deployable bundle.
25-
#[structopt(long)]
26-
skip_pkg: bool,
27-
2822
#[structopt(long = "internal-wizening-mode")]
2923
wizen: bool,
3024
}
@@ -33,12 +27,6 @@ fn main() -> anyhow::Result<()> {
3327
env_logger::init();
3428
let options = Options::from_args();
3529

36-
if !(options.wizen || options.skip_pkg) && !Path::exists(Path::new("fastly.toml")) {
37-
eprintln!("Error: fastly.toml not found.\n");
38-
Options::clap().print_help()?;
39-
std::process::exit(-1);
40-
}
41-
4230
if options.wizen {
4331
log::debug!("Wizerize subprocess start");
4432
wizen(&options.engine_wasm, &options.output)?;
@@ -47,9 +35,6 @@ fn main() -> anyhow::Result<()> {
4735
}
4836

4937
initialize_js(&options.input, &options.output, options.engine_wasm)?;
50-
if !options.skip_pkg {
51-
create_bundle(&options.input, &options.output)?;
52-
}
5338

5439
Ok(())
5540
}
@@ -87,58 +72,6 @@ fn initialize_js(input_path: &PathBuf,
8772
Ok(())
8873
}
8974

90-
fn create_bundle(_input_path: &PathBuf, wasm_path: &PathBuf) -> anyhow::Result<()> {
91-
log::debug!("Creating bundle for Fastly deploy");
92-
let fastly_toml = fs::read_to_string("fastly.toml")?.parse::<Value>()?;
93-
let name = fastly_toml["name"].as_str().unwrap();
94-
let name = sanitize_filename::sanitize(&name).replace(" ", "-");
95-
log::debug!("sanitized project name: {}", name);
96-
97-
let tmpdir = ManuallyDrop::new(tempfile::tempdir()?);
98-
log::debug!("Bundling in temp directory: {}", tmpdir.path().display());
99-
let build_dir = tmpdir.path().join(&name);
100-
log::debug!("Build dir: {}", build_dir.display());
101-
fs::create_dir(&build_dir)?;
102-
let bin_dir = build_dir.join("bin");
103-
fs::create_dir(&bin_dir)?;
104-
105-
fs::copy(wasm_path, bin_dir.join("main.wasm"))?;
106-
fs::copy("fastly.toml", &build_dir.join("fastly.toml"))?;
107-
108-
let pkgdir = Path::new(".").canonicalize()?.join("pkg");
109-
if !Path::exists(&pkgdir) {
110-
fs::create_dir(&pkgdir)?;
111-
}
112-
113-
let pkgpath = pkgdir.join(format!("{}.tar.gz", name));
114-
log::debug!("Creating tarball: {}", pkgpath.display());
115-
116-
let status = Command::new("tar")
117-
.current_dir(tmpdir.path())
118-
.arg("-czf")
119-
.arg(pkgpath)
120-
.arg(name)
121-
.status()
122-
.expect("Failed to invoke tar");
123-
124-
if !status.success() {
125-
eprintln!("Tar failed with status: {}", status);
126-
std::process::exit(-1);
127-
}
128-
129-
if std::env::var("FASTLY_JS_DEBUG_TEMP_DIR").is_ok() {
130-
log::debug!(
131-
"FASTLY_JS_DEBUG_TEMP_DIR is set; will not clean up {}",
132-
tmpdir.path().display()
133-
);
134-
} else {
135-
log::debug!("Cleaning up {}", tmpdir.path().display());
136-
drop(ManuallyDrop::into_inner(tmpdir));
137-
}
138-
139-
Ok(())
140-
}
141-
14275
fn wizen(engine_path: &Option<PathBuf>, output_path: &Path) -> anyhow::Result<()> {
14376
let engine_wasm_bytes = match engine_path {
14477
None => {

0 commit comments

Comments
 (0)