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

fix: enable scoped packages in plugin platform #8492

Merged
merged 1 commit into from
Oct 20, 2021
Merged
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
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(
akshbhu marked this conversation as resolved.
Show resolved Hide resolved
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')) {
Comment on lines +48 to +50
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, this will call addPluginPrefixWithMatchingPattern twice for name-spaced plugins.

Should the first call be in an else block of the if (subDirNames.includes('@aws-amplify')) { statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the first is node_modules path either can be global / local / parent . If this call has @aws-amplify present , then it wont be counted since its not a valid plugin , @aws-amplify/amplify-category-storage is valid plugin which will be present in second call.

Second call is to check if node_modules/@aws-amplify/ is present or not

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this add @aws-amplify/amplify-cli as a plugin?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have noplugin as @aws-amplify/aplify-cli , we have @aws-amplify/cli which is our core.

we get the core plugin using __dirName and we search in 3 folders:

  • local node_modules
  • parent node_modules
  • global node_modules

Packages installed with cli are installed in /usr/local/lib/@aws-amplify/cli/node_modules. Since we are namespacing again , we need to search in the /usr/local/lib/@aws-amplify/cli/node_modules/@aws-amplify as well and look for amplify category plugins

Above solution adds @aws-amplify to the node_modules to see if there are any namespaced packages

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)) {
akshbhu marked this conversation as resolved.
Show resolved Hide resolved
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