@aws-amplify/amplify-util-uibuilder 1.2.13 → 1.2.15-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,10 +2,24 @@ import { pathManager, JSONUtilities, $TSContext, $TSAny } from 'amplify-cli-core
2
2
  import { printer } from 'amplify-prompts';
3
3
  import fs from 'fs-extra';
4
4
  import path from 'path';
5
+ import rangeSubset from 'semver/ranges/subset';
5
6
  import { extractArgs } from './extractArgs';
6
- const REQUIRED_PACKAGES: { [key: string]: string } = { '@aws-amplify/ui-react': '*', 'aws-amplify': '*' };
7
+ import { ReactRequiredDependencyProvider } from '@aws-amplify/codegen-ui-react-old';
8
+ import { ReactRequiredDependencyProvider as ReactRequiredDependencyProviderNew } from '@aws-amplify/codegen-ui-react-new';
9
+ import { StudioComponent } from '@aws-amplify/codegen-ui-new';
7
10
 
8
- export const notifyMissingPackages = (context: $TSContext) => {
11
+ const isUpdatedSchema = (schemas: StudioComponent[]) => {
12
+ return schemas.some(schema => schema.schemaVersion && schema.schemaVersion === '1.0');
13
+ };
14
+
15
+ const getRequiredDependencies = (schemas: StudioComponent[]) => {
16
+ if (isUpdatedSchema(schemas)) {
17
+ return new ReactRequiredDependencyProviderNew().getRequiredDependencies();
18
+ }
19
+ return new ReactRequiredDependencyProvider().getRequiredDependencies();
20
+ };
21
+
22
+ export const notifyMissingPackages = (context: $TSContext, schemas: StudioComponent[]) => {
9
23
  const args = extractArgs(context);
10
24
  const localEnvFilePath = args.localEnvFilePath ?? pathManager.getLocalEnvFilePath();
11
25
  if (!fs.existsSync(localEnvFilePath)) {
@@ -19,22 +33,20 @@ export const notifyMissingPackages = (context: $TSContext) => {
19
33
  return;
20
34
  }
21
35
  const packageJson = JSONUtilities.readJson(packageJsonPath) as { dependencies: { [key: string]: string } };
22
- Object.keys(REQUIRED_PACKAGES).forEach(packageName => {
23
- const packageIsInstalled = Object.keys(packageJson.dependencies).includes(packageName);
36
+ getRequiredDependencies(schemas).forEach((dependency: $TSAny) => {
37
+ const packageIsInstalled = Object.keys(packageJson.dependencies).includes(dependency.dependencyName);
24
38
  if (!packageIsInstalled) {
25
- printer.warn(`UIBuilder components required "${packageName}" that is not in your package.json. Run \`npm install ${packageName}\``);
26
- } else if (!packageVersionMatches(REQUIRED_PACKAGES[packageName], packageJson.dependencies[packageName])) {
27
39
  printer.warn(
28
- `UIBuilder components requires version "${REQUIRED_PACKAGES[packageName]}" of "${packageName}". You currently are on version "${packageJson.dependencies[packageName]}".`,
40
+ `UIBuilder components required "${dependency.dependencyName}" that is not in your package.json. Run \`npm install "${dependency.dependencyName}@${dependency.supportedSemVerPattern}"\`. ${dependency.reason}`,
41
+ );
42
+ } else if (!rangeSubset(packageJson.dependencies[dependency.dependencyName], dependency.supportedSemVerPattern)) {
43
+ printer.warn(
44
+ `UIBuilder components requires version "${dependency.supportedSemVerPattern}" of "${
45
+ dependency.dependencyName
46
+ }". You currently are on version "${packageJson.dependencies[dependency.dependencyName]}". Run \`npm install "${
47
+ dependency.dependencyName
48
+ }@${dependency.supportedSemVerPattern}"\`. ${dependency.reason}`,
29
49
  );
30
50
  }
31
51
  });
32
52
  };
33
-
34
- const packageVersionMatches = (requiredVersion: string, existingVersion: string) => {
35
- if (requiredVersion === '*') {
36
- return true;
37
- }
38
-
39
- return requiredVersion === existingVersion;
40
- };