diff --git a/API.md b/API.md index 6ccb63de..efb8dc88 100644 --- a/API.md +++ b/API.md @@ -82,6 +82,20 @@ Instead use only relative paths and avoid `..`. --- +##### `esbuildBinaryPath`Optional + +```typescript +public readonly esbuildBinaryPath: string; +``` + +- *Type:* `string` + +Path to the binary used by esbuild. + +This is the same as setting the ESBUILD_BINARY_PATH environment variable. + +--- + ##### `entryPoints`Required ```typescript @@ -885,6 +899,20 @@ Instead use only relative paths and avoid `..`. --- +##### `esbuildBinaryPath`Optional + +```typescript +public readonly esbuildBinaryPath: string; +``` + +- *Type:* `string` + +Path to the binary used by esbuild. + +This is the same as setting the ESBUILD_BINARY_PATH environment variable. + +--- + ### CodeConfig #### Initializer @@ -986,6 +1014,20 @@ Instead use only relative paths and avoid `..`. --- +##### `esbuildBinaryPath`Optional + +```typescript +public readonly esbuildBinaryPath: string; +``` + +- *Type:* `string` + +Path to the binary used by esbuild. + +This is the same as setting the ESBUILD_BINARY_PATH environment variable. + +--- + ##### `assetHash`Optional ```typescript @@ -1081,6 +1123,20 @@ Instead use only relative paths and avoid `..`. --- +##### `esbuildBinaryPath`Optional + +```typescript +public readonly esbuildBinaryPath: string; +``` + +- *Type:* `string` + +Path to the binary used by esbuild. + +This is the same as setting the ESBUILD_BINARY_PATH environment variable. + +--- + ##### `assetHash`Optional ```typescript @@ -1638,6 +1694,20 @@ Instead use only relative paths and avoid `..`. --- +##### `esbuildBinaryPath`Optional + +```typescript +public readonly esbuildBinaryPath: string; +``` + +- *Type:* `string` + +Path to the binary used by esbuild. + +This is the same as setting the ESBUILD_BINARY_PATH environment variable. + +--- + ##### `assetHash`Optional ```typescript @@ -1733,6 +1803,20 @@ Instead use only relative paths and avoid `..`. --- +##### `esbuildBinaryPath`Optional + +```typescript +public readonly esbuildBinaryPath: string; +``` + +- *Type:* `string` + +Path to the binary used by esbuild. + +This is the same as setting the ESBUILD_BINARY_PATH environment variable. + +--- + ##### `assetHash`Optional ```typescript diff --git a/README.md b/README.md index 8d442ba4..ff98be7c 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,16 @@ It's possible that you want to use an implementation of esbuild that's different For these situations, this package offers an escape hatch to bypass regular the implementation and provide a custom build and transform function. +#### Esbuild binary path + +It is possible to override the binary used by esbuild. The usual way to do this is to set the `ESBUILD_BINARY_PATH` environment variable. For convenience this package allows to set the binary path as a prop: + +```ts +new TypeScriptCode("fixtures/handlers/ts-handler.ts", { + esbuildBinaryPath: "path/to/esbuild/binary" +}); +``` + #### Custom build function > 💡 See [Using esbuild with plugins](examples/esbuild-with-plugins) for a complete working example of a custom build function using this escape hatch. diff --git a/src/bundler.ts b/src/bundler.ts index 7b81562c..128505d3 100644 --- a/src/bundler.ts +++ b/src/bundler.ts @@ -77,6 +77,15 @@ export interface BundlerProps { * @default esbuild.buildSync */ readonly buildFn?: any; + + /** + * Path to the binary used by esbuild. + * + * This is the same as setting the ESBUILD_BINARY_PATH environment variable. + * + * @stability experimental + */ + readonly esbuildBinaryPath?: string; } /** @@ -148,6 +157,11 @@ export class EsbuildBundler { }); } + const originalEsbuildBinaryPath = process.env.ESBUILD_BINARY_PATH; + if (this.props.esbuildBinaryPath) { + process.env.ESBUILD_BINARY_PATH = this.props.esbuildBinaryPath; + } + try { const buildResult: BuildResult = buildFn({ entryPoints, @@ -160,6 +174,8 @@ export class EsbuildBundler { printBuildMessages(error as BuildFailure, { prefix: 'Build ' }); } + process.env.ESBUILD_BINARY_PATH = originalEsbuildBinaryPath; + return true; }, };