Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface TinypoolChannel {
export interface TinypoolWorker {
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.

argv?: string[]
execArgv?: string[]
resourceLimits?: any
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ interface Options {
maxMemoryLimitBeforeRecycle?: number
argv?: string[]
execArgv?: string[]
env?: Record<string, string>
env?: NodeJS.ProcessEnv
workerData?: any
taskQueue?: TaskQueue
trackUnmanagedFds?: boolean
Expand Down
10 changes: 10 additions & 0 deletions test/simple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ test('passing env to workers works', async () => {
expect(env).toEqual({ A: 'foo' })
})

test('passing process.env to workers works', async () => {
const pool = new Tinypool({
filename: resolve(__dirname, 'fixtures/eval.js'),
env: process.env,
})

const env = await pool.run('({...process.env})')
expect(env).toEqual(process.env)
})

test('passing argv to workers works', async () => {
const pool = new Tinypool({
filename: resolve(__dirname, 'fixtures/eval.js'),
Expand Down