diff --git a/src/helper.ts b/src/helper.ts index 21315220..20ac886b 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -101,7 +101,7 @@ export function extractFunctionEntries( * @param root the root of the dependency tree * @param rootDeps array of top level root dependencies to whitelist */ -export const flatDep = (root: DependencyMap, rootDepsFilter: string[]): string[] => { +export const flatDep = (root: DependencyMap, rootDepsFilter: string[], excludes: '*' | string[]): string[] => { const flattenedDependencies = new Set(); /** @@ -109,7 +109,7 @@ export const flatDep = (root: DependencyMap, rootDepsFilter: string[]): string[] * @param deps the current tree * @param filter the dependencies to get from this tree */ - const recursiveFind = (deps: DependencyMap | undefined, filter?: string[]) => { + const recursiveFind = (deps: DependencyMap | undefined, filter?: string[], excludes?: '*' | string[]) => { if (!deps) return; Object.entries(deps).forEach(([depName, details]) => { @@ -120,7 +120,7 @@ export const flatDep = (root: DependencyMap, rootDepsFilter: string[]): string[] if (details.isRootDep || filter) { // We already have this root dep and it's dependencies - skip this iteration - if (flattenedDependencies.has(depName)) { + if (flattenedDependencies.has(depName) || (excludes && excludes !== '*' && excludes.includes(depName))) { return; } @@ -139,7 +139,7 @@ export const flatDep = (root: DependencyMap, rootDepsFilter: string[]): string[] }); }; - recursiveFind(root, rootDepsFilter); + recursiveFind(root, rootDepsFilter, excludes); return Array.from(flattenedDependencies); }; diff --git a/src/pack.ts b/src/pack.ts index 6d9af2c1..4443e142 100644 --- a/src/pack.ts +++ b/src/pack.ts @@ -198,7 +198,7 @@ export async function pack(this: EsbuildServerlessPlugin) { const bundleDeps = getDepsFromBundle(path.join(buildDirPath, bundlePath), isESM(buildOptions)); const bundleExternals = intersection(bundleDeps, externals); - depWhiteList = flatDep(packagerDependenciesList.dependencies, bundleExternals); + depWhiteList = flatDep(packagerDependenciesList.dependencies, bundleExternals, buildOptions.exclude); } const zipName = `${functionAlias}.zip`;