Skip to content

fix: accept process.env in worker options - #137

Open
cqxswbc2 wants to merge 1 commit into
tinylibs:mainfrom
cqxswbc2:codex/fix-process-env-type
Open

cqxswbc2 wants to merge 1 commit into
tinylibs:mainfrom
cqxswbc2:codex/fix-process-env-type

Conversation

@cqxswbc2

@cqxswbc2 cqxswbc2 commented Sep 4, 2026

Copy link
Copy Markdown

Closes #136

Summary

  • widen the public env option from Record<string, string> to NodeJS.ProcessEnv
  • keep the internal worker interface aligned with the public option type
  • add a regression test that passes process.env directly to a worker

This deliberately does not add SHARE_ENV support because Tinypool also supports the child_process runtime, where that worker-thread-only symbol is not accepted.

Validation

  • pnpm build
  • pnpm typecheck
  • pnpm lint
  • pnpm exec vitest run test/simple.test.ts (26 passed)
  • pnpm exec vitest run test/termination.test.ts (3 passed)

The full test command was also attempted on Windows with Node 24. It reached 87 passing tests before a Vitest child process hit a heap OOM and one termination test timed out; that termination file passed when rerun in isolation.

Comment thread src/common.ts
runtime: string
initialize(options: {
env?: Record<string, string>
env?: NodeJS.ProcessEnv

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this allow passing SHARE_ENV from import { SHARE_ENV } from 'node:worker_threads' too?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

No. This PR deliberately only accepts process.env.

SHARE_ENV is specific to worker_threads, while Tinypool exposes the same env option for child_process. Admitting the symbol in the shared type would also require runtime validation (including the recycleWorkers({ runtime: "child_process" }) path); otherwise the process worker's object spread would turn the symbol into an empty environment.

#138 explores that larger feature and its guards. If you prefer full WorkerOptions["env"] parity, I can expand this PR with the runtime checks and tests. Otherwise, I think keeping #137 scoped to the process.env type mismatch is the safer minimal change.

@cqxswbc2

Copy link
Copy Markdown
Author

Checking in on the scope question above. I can keep this PR limited to process.env, or expand it to support SHARE_ENV with the runtime guards and tests that requires. Please let me know which direction you prefer.

@cqxswbc2

cqxswbc2 commented Oct 7, 2026

Copy link
Copy Markdown
Author

The author of #138 has since closed that alternative in favor of this smaller fix. This PR remains limited to accepting process.env for both worker runtimes; adding SHARE_ENV would require separate runtime guards for child_process and recycleWorkers.

Would appreciate a review of the process.env fix when you have time. Happy to address any further feedback.

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.

Tinypool options.env type doesn't accept process.env or SHARE_ENV

2 participants