Infinite loop when having `fastly compute build` defined in npm run build command
Version
Fastly CLI version v3.1.1 (59efd38) Built with go version go1.18.3 linux/amd64 Viceroy version: viceroy 0.2.14
What happened
I created a new empty js compute project:
fastly compute init --language javascript --from https://github.com/fastly/compute-starter-kit-javascript-empty
I then changed the npm build run-script to "fastly compute build":
npm set-script build "fastly compute build"
I then ran npm run build:
npm run build
At this point it gets into an infinite loop.
The log gets this far and doesn't make it look like an infinite loop, which could confuse people:
> [email protected] prebuild
> webpack
asset index.js 219 bytes [emitted] [minimized] (name: main)
./src/index.js 212 bytes [built] [code generated]
WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value.
Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/
webpack 5.73.0 compiled with 1 warning in 110 ms
> [email protected] build
> fastly compute build
✓ Initializing...
✓ Verifying package manifest...
✓ Verifying local javascript toolchain...
/ Building package using javascript toolchain...
I think we should possibly add a flag to fastly compute build which enables it to not run npm run build within itself, something like fastly compute build --ignore-npm-build - that way javascript projects can keep the convention of having their build script be fully defined by npm run build and not get into this infinite loop
I propose the CLI no longer runs the package.json file's build step, basically in the CLI instead of calling npm run build we'll call js-compute-runtime bin/index.js bin/main.wasm.
We don't do it for the deploy step (e.g. in all the starter kits they are set to npm run build && fastly compute deploy and the CLI's internal deploy logic doesn't rely on any package.json configuration).
I'll open a PR to fix this. Then I'll open a follow-up PR to update each JS starter kit so that its build step is just fastly compute build, then that way user's can modify it however they see fit.