Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: exclude third level dependencies #481

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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,18 +101,18 @@
* @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
// only for root level dependencies
if (filter && !filter.includes(depName)) {
return;
Expand All @@ -120,7 +120,7 @@

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 @@
});
};

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
Loading