Skip to content

Commit 2332702

Browse files
committed
feat: exclude third level dependencies
1 parent ef5b2d1 commit 2332702

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/helper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ export function extractFunctionEntries(
101101
* @param root the root of the dependency tree
102102
* @param rootDeps array of top level root dependencies to whitelist
103103
*/
104-
export const flatDep = (root: DependencyMap, rootDepsFilter: string[]): string[] => {
104+
export const flatDep = (root: DependencyMap, rootDepsFilter: string[], excludes: '*' | string[]): string[] => {
105105
const flattenedDependencies = new Set<string>();
106106

107107
/**
108108
*
109109
* @param deps the current tree
110110
* @param filter the dependencies to get from this tree
111111
*/
112-
const recursiveFind = (deps: DependencyMap | undefined, filter?: string[]) => {
112+
const recursiveFind = (deps: DependencyMap | undefined, filter?: string[], excludes?: '*' | string[]) => {
113113
if (!deps) return;
114114

115115
Object.entries(deps).forEach(([depName, details]) => {
@@ -120,7 +120,7 @@ export const flatDep = (root: DependencyMap, rootDepsFilter: string[]): string[]
120120

121121
if (details.isRootDep || filter) {
122122
// We already have this root dep and it's dependencies - skip this iteration
123-
if (flattenedDependencies.has(depName)) {
123+
if (flattenedDependencies.has(depName) || (excludes && excludes != '*' && excludes.includes(depName))) {
124124
return;
125125
}
126126

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

142-
recursiveFind(root, rootDepsFilter);
142+
recursiveFind(root, rootDepsFilter, excludes);
143143

144144
return Array.from(flattenedDependencies);
145145
};

src/pack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export async function pack(this: EsbuildServerlessPlugin) {
198198
const bundleDeps = getDepsFromBundle(path.join(buildDirPath, bundlePath), isESM(buildOptions));
199199
const bundleExternals = intersection(bundleDeps, externals);
200200

201-
depWhiteList = flatDep(packagerDependenciesList.dependencies, bundleExternals);
201+
depWhiteList = flatDep(packagerDependenciesList.dependencies, bundleExternals, buildOptions.exclude);
202202
}
203203

204204
const zipName = `${functionAlias}.zip`;

0 commit comments

Comments
 (0)