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
8 changes: 4 additions & 4 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ 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<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]) => {
Expand All @@ -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;
}

Expand All @@ -139,7 +139,7 @@ export const flatDep = (root: DependencyMap, rootDepsFilter: string[]): string[]
});
};

recursiveFind(root, rootDepsFilter);
recursiveFind(root, rootDepsFilter, excludes);

return Array.from(flattenedDependencies);
};
Expand Down
2 changes: 1 addition & 1 deletion src/pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down