Skip to content

Commit

Permalink
Merge pull request #13821 from ErlendHer/platform-push/move-resources…
Browse files Browse the repository at this point in the history
…-performance-improvement

feat: improve performance in storing current cloud backend
  • Loading branch information
Amplifiyer authored Sep 23, 2024
2 parents 7ab8fae + eb2ada8 commit cff2863
Showing 1 changed file with 4 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { buildTypeKeyMap, ServiceName } from '@aws-amplify/amplify-category-func
import { $TSAny, $TSMeta, $TSObject, JSONUtilities, pathManager, ResourceTuple, stateManager } from '@aws-amplify/amplify-cli-core';
import { BuildType } from '@aws-amplify/amplify-function-plugin-interface';
import * as fs from 'fs-extra';
import glob from 'glob';
import _ from 'lodash';
import * as path from 'path';
import { ensureAmplifyMetaFrontendConfig } from './on-category-outputs-change';
Expand Down Expand Up @@ -77,13 +76,13 @@ const moveBackendResourcesToCurrentCloudBackend = (resources: $TSObject[]): void
}

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

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

Expand All @@ -109,18 +108,6 @@ const moveBackendResourcesToCurrentCloudBackend = (resources: $TSObject[]): void
}
};

const removeNodeModulesDir = (currentCloudBackendDir: string): void => {
const nodeModulesDirs = glob.sync('**/node_modules', {
cwd: currentCloudBackendDir,
absolute: true,
});
for (const nodeModulesPath of nodeModulesDirs) {
if (fs.existsSync(nodeModulesPath)) {
fs.removeSync(nodeModulesPath);
}
}
};

/**
* Update amplify-meta.json and backend-config.json
*/
Expand Down

0 comments on commit cff2863

Please sign in to comment.