Skip to content

Commit

Permalink
feat: add nodeExternals configuration for esbuild-node-external plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nickygb authored and floydspace committed Sep 24, 2022
1 parent 74337b7 commit 935bd6f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export async function bundle(this: EsbuildServerlessPlugin, incremental = false)
delete config['outputFileExtension'];
delete config['outputBuildFolder'];
delete config['outputWorkFolder'];
delete config['nodeExternals'];

/** Build the files */
const bundleMapper = async (entry: string): Promise<FileBuildResult> => {
Expand Down
7 changes: 6 additions & 1 deletion src/pack-externals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,15 @@ export async function packExternalModules(this: EsbuildServerlessPlugin) {
fse.existsSync(path.resolve(__dirname, '../../esbuild-node-externals/dist/utils.js'))
) {
const { findDependencies, findPackagePaths } = require('esbuild-node-externals/dist/utils');

const allowList = this.buildOptions?.nodeExternals?.allowList
? this.buildOptions.nodeExternals.allowList
: [];

this.buildOptions.external = findDependencies({
dependencies: true,
packagePaths: findPackagePaths(),
allowList: [],
allowList,
});
}

Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export interface PackagerOptions {
scripts?: string[] | string;
}

interface NodeExternalsOptions {
allowList?: string[];
}

export type EsbuildOptions = Omit<BuildOptions, 'nativeZip' | 'watch' | 'plugins'>;

export interface Configuration extends EsbuildOptions {
Expand All @@ -32,6 +36,7 @@ export interface Configuration extends EsbuildOptions {
outputWorkFolder?: string;
outputBuildFolder?: string;
outputFileExtension: '.js' | '.cjs' | '.mjs';
nodeExternals?: NodeExternalsOptions;
}

export interface FunctionEntry {
Expand Down

0 comments on commit 935bd6f

Please sign in to comment.