Skip to content

Commit

Permalink
feat: exclude third level dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
deathemperor committed Oct 16, 2023
1 parent ef5b2d1 commit b338366
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
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]) => {

Check warning on line 115 in src/helper.ts

View workflow job for this annotation

GitHub Actions / test (14)

'excludes' is already declared in the upper scope on line 107 column 72

Check warning on line 115 in src/helper.ts

View workflow job for this annotation

GitHub Actions / test (16)

'excludes' is already declared in the upper scope on line 107 column 72

Check warning on line 115 in src/helper.ts

View workflow job for this annotation

GitHub Actions / test (18)

'excludes' is already declared in the upper scope on line 107 column 72
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

0 comments on commit b338366

Please sign in to comment.