folke / esbuild-runner

⚡️ Super-fast on-the-fly transpilation of modern JS, TypeScript and JSX using esbuild
https://www.npmjs.com/package/esbuild-runner
Apache License 2.0
712 stars 24 forks source link

feat: ✨ add `cwd` option #47

Open jfirebaugh opened 2 years ago

jfirebaugh commented 2 years ago

I want to use esbuild-runner in contexts where the current directory is not the directory containing the package.json whose dependencies should be used to chose externals. This makes the location for package.json configurable. It's roughly equivalent to the cwd option from ts-node: https://github.com/TypeStrong/ts-node/blob/abc616ece2a8cdb066439a4e5c6fc7d493aa4612/src/index.ts#L191-L196.

romanlamsal commented 1 year ago

Why not just make use of process.chdir?

jfirebaugh commented 1 year ago

It would change the execution environment of the code that the runner is running, which may be expecting the current directory to be the one where the command was executed.

romanlamsal commented 1 year ago

Yes, but is that not the intention of a --cwd flag? For example, running ts-node --cwd /some/where your-script.ts will try to execute /some/where/your-script.ts. I'm just saying, cwd as flag is confusing if the actual goal is to just tell esbuild-runner to read from another package.json.