Skip to content

Commit 24c8f85

Browse files
committed
fix: avoid copying node_modules folder for increased performance
1 parent 6abf7dd commit 24c8f85

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

packages/amplify-cli/src/extensions/amplify-helpers/update-amplify-meta.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ const moveBackendResourcesToCurrentCloudBackend = (resources: $TSObject[]): void
7777
}
7878

7979
fs.ensureDirSync(targetDir);
80+
const isLambdaOrCustom =
81+
resource?.service === ServiceName.LambdaFunction || (resource?.service && resource?.service.includes('custom'));
8082

8183
// in the case that the resource is being deleted, the sourceDir won't exist
8284
if (fs.pathExistsSync(sourceDir)) {
83-
fs.copySync(sourceDir, targetDir);
84-
if (resource?.service === ServiceName.LambdaFunction || (resource?.service && resource?.service.includes('custom'))) {
85-
removeNodeModulesDir(targetDir);
86-
}
85+
const nodeModulesFilterFn = (src: string): boolean => path.basename(src) !== 'node_modules';
86+
fs.copySync(sourceDir, targetDir, { ...(isLambdaOrCustom ? { filter: nodeModulesFilterFn } : {}) });
8787
}
8888
}
8989

@@ -109,18 +109,6 @@ const moveBackendResourcesToCurrentCloudBackend = (resources: $TSObject[]): void
109109
}
110110
};
111111

112-
const removeNodeModulesDir = (currentCloudBackendDir: string): void => {
113-
const nodeModulesDirs = glob.sync('**/node_modules', {
114-
cwd: currentCloudBackendDir,
115-
absolute: true,
116-
});
117-
for (const nodeModulesPath of nodeModulesDirs) {
118-
if (fs.existsSync(nodeModulesPath)) {
119-
fs.removeSync(nodeModulesPath);
120-
}
121-
}
122-
};
123-
124112
/**
125113
* Update amplify-meta.json and backend-config.json
126114
*/

0 commit comments

Comments
 (0)