Skip to content

Commit

Permalink
fix: enable scoped packages in plugin platform (#8492)
Browse files Browse the repository at this point in the history
  • Loading branch information
akshbhu committed Oct 28, 2021
1 parent d5ae466 commit 25bd7ef
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
1 change: 1 addition & 0 deletions packages/amplify-category-auth/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
**/tests/**
src
tsconfig.json
!resources/overrides-resource/tsconfig.json
tsconfig.tsbuildinfo
38 changes: 24 additions & 14 deletions packages/amplify-cli/src/plugin-helpers/scan-plugin-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { twoPluginsAreTheSame } from './compare-plugins';
import { checkPlatformHealth } from './platform-health-check';
import isChildPath from '../utils/is-child-path';
import { JSONUtilities, $TSAny, isPackaged } from 'amplify-cli-core';
import sequential from 'promise-sequential';

export async function scanPluginPlatform(pluginPlatform?: PluginPlatform): Promise<PluginPlatform> {
pluginPlatform = pluginPlatform || readPluginsJsonFile() || new PluginPlatform();
Expand All @@ -20,17 +21,15 @@ export async function scanPluginPlatform(pluginPlatform?: PluginPlatform): Promi

await addCore(pluginPlatform!);

const sequential = require('promise-sequential');

if (pluginPlatform!.userAddedLocations && pluginPlatform!.userAddedLocations.length > 0) {
// clean up the userAddedLocation first
pluginPlatform!.userAddedLocations = pluginPlatform!.userAddedLocations.filter(pluginDirPath => {
const result = fs.existsSync(pluginDirPath);
return result;
});

const scanUserLocationTasks = pluginPlatform!.userAddedLocations.map(pluginDirPath => async () =>
await verifyAndAdd(pluginPlatform!, pluginDirPath),
const scanUserLocationTasks = pluginPlatform!.userAddedLocations.map(
pluginDirPath => async () => await verifyAndAdd(pluginPlatform!, pluginDirPath),
);
await sequential(scanUserLocationTasks);
}
Expand All @@ -44,17 +43,14 @@ export async function scanPluginPlatform(pluginPlatform?: PluginPlatform): Promi
directory = normalizePluginDirectory(directory);
const exists = await fs.pathExists(directory);
if (exists) {
//adding subDir based on amplify-
const subDirNames = await fs.readdir(directory);
if (subDirNames.length > 0) {
const scanSubDirTasks = subDirNames.map(subDirName => {
return async () => {
if (isMatchingNamePattern(pluginPlatform!.pluginPrefixes, subDirName)) {
const pluginDirPath = path.join(directory, subDirName);
await verifyAndAdd(pluginPlatform!, pluginDirPath);
}
};
});
await sequential(scanSubDirTasks);
await addPluginPrefixWithMatchingPattern(subDirNames, directory, pluginPlatform!);
//ading plugin based on @aws-amplify/amplify-
if (subDirNames.includes('@aws-amplify')) {
const nameSpacedDir = path.join(directory, '@aws-amplify');
const nameSpacedPackages = await fs.readdir(nameSpacedDir);
await addPluginPrefixWithMatchingPattern(nameSpacedPackages, nameSpacedDir, pluginPlatform!);
}
}
});
Expand Down Expand Up @@ -161,3 +157,17 @@ export function isUnderScanCoverageSync(pluginPlatform: PluginPlatform, pluginDi

return result;
}

const addPluginPrefixWithMatchingPattern = async (subDirNames: string[], directory: string, pluginPlatform: PluginPlatform) => {
if (subDirNames.length > 0) {
const scanSubDirTasks = subDirNames.map(subDirName => {
return async () => {
if (isMatchingNamePattern(pluginPlatform.pluginPrefixes, subDirName)) {
const pluginDirPath = path.join(directory, subDirName);
await verifyAndAdd(pluginPlatform, pluginDirPath);
}
};
});
await sequential(scanSubDirTasks);
}
};
1 change: 1 addition & 0 deletions packages/amplify-provider-awscloudformation/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
**/__tests__/**
src
tsconfig.json
!resources/overrides-resource/tsconfig.json
tsconfig.tsbuildinfo

0 comments on commit 25bd7ef

Please sign in to comment.