Skip to content

feat: Allow the use of project-level external config file for js-compute-runtime CLI behavior#1405

Open
harmony7 wants to merge 1 commit intomainfrom
kats/config-file
Open

feat: Allow the use of project-level external config file for js-compute-runtime CLI behavior#1405
harmony7 wants to merge 1 commit intomainfrom
kats/config-file

Conversation

@harmony7
Copy link
Copy Markdown
Member

@harmony7 harmony7 commented Apr 1, 2026

Summary

This PR introduces support for external configuration files to manage js-compute-runtime CLI flags. Users can now define their build and runtime configurations in a dedicated file or within their package.json, reducing the need for long, repetitive command-line strings.

The Problem

As the number of available flags in @fastly/js-compute grows (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 a fastlycompute configuration block in package.json.

The following are also searched, though package.json is probably sufficient for most users:

  • .fastlycomputerc (JSON or YAML)
  • .fastlycomputerc.json / .yaml / .js / .mjs
  • fastlycompute.config.js / .mjs

Key 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 in process.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 additiveOptionsMap and strictOptionsMap (in src/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

  • Added cosmiconfig as a dependency.
  • Created src/config.ts to handle file discovery and flag synthesis.
  • Updated src/cli/js-compute-runtime-cli.ts to wrap parseInputs with 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.

@harmony7 harmony7 requested a review from TartanLlama April 1, 2026 08:26
@harmony7 harmony7 marked this pull request as ready for review April 1, 2026 08:54
@harmony7 harmony7 requested review from a team and Pomax and removed request for a team April 1, 2026 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant