docs: `dev --env-file` help/docs say it does not reach tasks, but it does

Đang mở
#4,425 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

  • #4473 của @RealBhupesh — đã đóng, không merge
  • #4478 của @BILLKISHORE — đã đóng, không merge

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
typescript
Lĩnh vực
cli, documentation

Hướng nghiên cứu

Start by reading dev/devSupervisor.ts and the resolveLocalEnvVars → resolveDotEnvVars path mentioned in the issue, then compare it with the dev/deploy/preview CLI help and the three named docs pages. Reproduce with a task reading process.env.PROBE and trigger dev --env-file custom.env; done means the documented contract and actual behavior agree. Two pull requests have already been linked, so check their discussions before starting.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Provide environment information

trigger.dev 4.5.0 (also verified 4.5.9)

Describe the bug

The --env-file option is documented — in the CLI --help for dev/deploy/preview and in the docs pages (cli-dev-commands, cli-deploy-commands, cli-preview-archive) — as:

Load environment variables from a file. This will only hydrate the process.env of the CLI process, not the tasks.

But in dev, the file is passed through to the tasks. DevSupervisor.#getEnvVars() (dev/devSupervisor.ts) builds the run environment from resolveLocalEnvVars(this.options.args.envFile, …):

async #getEnvVars() {
    const environmentVariablesResponse = await this.options.client.getEnvironmentVariables(...);
    return {
        ...resolveLocalEnvVars(this.options.args.envFile, environmentVariablesResponse.success ? ... : {}),
        NODE_ENV: "development",
        ...
    };
}

and resolveLocalEnvVars(envFile, …) → resolveDotEnvVars(undefined, envFile) reads exactly that file and includes it in what the task receives via process.env.

To reproduce
  1. echo "PROBE=from-file" > custom.env
  2. trigger dev --env-file custom.env
  3. In a task: process.env.PROBE
  4. It is from-file — the task does see the --env-file value.

Expected per the docs: the task should NOT see it (docs say the flag only affects the CLI process).

Which is correct?

The behavior (file reaches tasks) is arguably the more useful one — passing --env-file /path/to/empty is a clean way to make the CLI read no ambient .env* files and rely solely on the injected process.env. But the docs and --help text state the opposite, so please either:

  • fix the docs/--help to say --env-file values are included in the task environment, or
  • if the documented behavior is the intended contract, fix dev to not pass envFile into resolveLocalEnvVars.

Either way the code and the docs currently disagree, which makes --env-file hard to reason about.

Additional information

Related: #2999 (the .env vs .env.local precedence bug in the same resolveDotEnvVars path).

Ngôn ngữ chính
TypeScript
Star
16.5k
Fork
1.5k
Merge trung bình
1 ngày 15 giờ
Pull request đã merge (30 ngày)
17

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của triggerdotdev/trigger.dev

Tất cả issue của triggerdotdev/trigger.dev

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.