feat: Allow the use of project-level external config file for js-compute-runtime CLI behavior#1405
Open
feat: Allow the use of project-level external config file for js-compute-runtime CLI behavior#1405
Conversation
02ae63c to
9eb98ad
Compare
…ute-runtime CLI behavior
9eb98ad to
110853f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces support for external configuration files to manage
js-compute-runtimeCLI flags. Users can now define their build and runtime configurations in a dedicated file or within theirpackage.json, reducing the need for long, repetitive command-line strings.The Problem
As the number of available flags in
@fastly/js-computegrows (AOT settings, HTTP caching, experimental methods, etc.), CI/CD scripts and local development commands are becoming increasingly verbose and difficult to maintain.The Solution
A new configuration discovery layer is added before input parsing. By leveraging
cosmiconfig, it searches for afastlycomputeconfiguration block inpackage.json.The following are also searched, though
package.jsonis probably sufficient for most users:.fastlycomputerc(JSON or YAML).fastlycomputerc.json/.yaml/.js/.mjsfastlycompute.config.js/.mjsKey Features
1. Argument Merging
The implementation uses a two-tier merging strategy to ensure the CLI remains predictable:
Strict Flags: For single-value flags (like
--engine-wasm), the CLI takes absolute precedence. If a flag is detected inprocess.argv, the configuration file value is ignored to prevent "multiple definition" errors.Additive Flags: For
--env, the configuration file and CLI are merged. This allows developers to set baseline environment variables in a config file and override or add specific ones during a specific CLI run.2. Whitelisted Mapping
To prevent configuration pollution, only keys explicitly defined in
additiveOptionsMapandstrictOptionsMap(insrc/config.ts) are processed and injected into the runtime.Example Configuration
Users can now add this to their
package.json:{ "name": "my-fastly-service", "fastlycompute": { "enableAOT": true, "enableStackTraces": true, "env": { "ENVIRONMENT": "staging" } } }Technical Changes
cosmiconfigas a dependency.src/config.tsto handle file discovery and flag synthesis.src/cli/js-compute-runtime-cli.tsto wrapparseInputswith the new config loader.Google Gemini was used in part for generating the code and parts of the README, and thus this PR should receive an additional reviewer.