cli icon indicating copy to clipboard operation
cli copied to clipboard

Fix language validation

Open Integralist opened this issue 3 years ago • 0 comments

Problem: looking up the language manifest file (e.g. Cargo.toml, go.mod, package.json) would cause the CLI to fail if it wasn't in the same directory as the directory the CLI was being run in (which typically is the project directory where the fastly.toml exists).

Solution: We lean into specific language toolchain commands to help identify the language's manifest file, rather than just expecting to find it in the current directory.

Notes: I tested this PR by creating a project for Go, Rust and JavaScript where I run compute init and then manually moved the source code files/fastly.toml into a nested directory to validate I was able to build the projects successfully.

Examples

Rust

.
├── Cargo.lock
├── Cargo.toml
├── README.md
├── nested
│   ├── fastly.toml
│   └── src
│       ├── main.rs
│       └── [email protected]
└── rust-toolchain.toml

NOTE: I needed the following change in the Cargo.toml so Cargo knew which binary crate it needs to reference:

[[bin]]
name = "fastly-compute-project"
path = "nested/src/main.rs"
Screenshot 2022-10-13 at 11 50 48

Go

.
├── README.md
├── go.mod
├── go.sum
└── nested
    ├── fastly.toml
    └── main.go
Screenshot 2022-10-13 at 11 53 25

JavaScript

.
├── README.md
├── nested
│   ├── fastly.toml
│   ├── src
│   │   ├── index.js
│   │   └── [email protected]
│   └── webpack.config.js
├── npm-shrinkwrap.json
└── package.json
Screenshot 2022-10-13 at 12 08 41

Fixes: https://github.com/fastly/cli/issues/598

Integralist avatar Oct 12 '22 19:10 Integralist