Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bring back support for build-time env vars #691

Merged
merged 1 commit into from
Oct 16, 2023

Conversation

JakeChampion
Copy link
Member

@JakeChampion JakeChampion commented Oct 16, 2023

We had these working before we introduced the two experimental flags, when we added those that meant the default env inheritance was overridden and we never added it back

here is it working:

❯ command cat src/index.js
/// <reference types="@fastly/js-compute" />

import { env } from "fastly:env";

const pwd = env("DOG")

addEventListener("fetch", (event) => event.respondWith(handleRequest(event)));

async function handleRequest(event) {
  console.log({buildtime: pwd}, {runtime:env("DOG")});
  return new Response("OK", { status: 200 });
}
❯ export DOG=woof
❯ fastly compute serve --verbose
Fastly API token provided via config file (profile: work)
Fastly API endpoint: https://api.fastly.com

✓ Verifying fastly.toml
✓ Identifying package name
✓ Identifying toolchain

INFO: Creating ./bin directory (for Wasm binary)

Build script to execute:
        sh -c npm run build


INFO: Command output:
--------------------------------------------------------------------------------

> build
> js-compute-runtime ./src/index.js ./bin/main.wasm

--------------------------------------------------------------------------------

✓ Running [scripts.build]

Wasm module 'magic':
        []byte{0x0, 0x61, 0x73, 0x6d}

Wasm module 'version':
        1

✓ Creating package archive

SUCCESS: Built package (pkg/env-meow.tar.gz)


INFO: Viceroy is installed but the CLI config (`fastly config`) shows the TTL, checking for a newer version,
hasn't expired. To force a refresh, re-run the command with the `--viceroy-check` flag.

✓ Running local server

Manifest: /Users/jakechampion/temp/dora-env/fastly.toml
Wasm binary: bin/main.wasm
Viceroy binary: /Users/jakechampion/Library/Application Support/fastly/viceroy
Viceroy version: viceroy 0.9.1

INFO: Command output:
--------------------------------------------------------------------------------
2023-10-16T13:08:41.773188Z  WARN no backend definitions found in /Users/jakechampion/temp/dora-env/fastly.toml
2023-10-16T13:08:41.773307Z  INFO Listening on http://127.0.0.1:7676
2023-10-16T13:08:43.484188Z  INFO request{id=0}: handling request GET http://localhost:7676/
Log: { buildtime: "woof" } { runtime: "" }
2023-10-16T13:08:43.486914Z  INFO request{id=0}: request completed using 7.7 MB of WebAssembly heap
2023-10-16T13:08:43.486921Z  INFO request{id=0}: request completed in 3ms

We had these working before we introduced the two experimental flags, when we added those that meant the default env inheritance was overridden and we never added it back
@@ -101,6 +101,7 @@ export async function compileApplicationToWasm(input, output, wasmEngine, enable
env: {
ENABLE_EXPERIMENTAL_HIGH_RESOLUTION_TIME_METHODS: enableExperimentalHighResolutionTimeMethods ? '1' : '0',
ENABLE_PBL: enablePBL ? '1' : '0',
...process.env
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you ❤️

@JakeChampion JakeChampion enabled auto-merge (squash) October 16, 2023 13:09
@JakeChampion JakeChampion merged commit c044ac4 into main Oct 16, 2023
14 checks passed
@JakeChampion JakeChampion deleted the JakeChampion-patch-1 branch October 16, 2023 13:22
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.

None yet

2 participants