Skip to content

Commit 7f08cd9

Browse files
authored
feat: add min required library versions for generated components (#302) (#303)
1 parent ba6e1a2 commit 7f08cd9

File tree

7 files changed

+310
-10
lines changed

7 files changed

+310
-10
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License").
5+
You may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
import semver from 'semver';
17+
import { ReactRequiredDependencyProvider } from '..';
18+
19+
describe('ReactStudioDependencyProvider', () => {
20+
const requiredDependencies = new ReactRequiredDependencyProvider().getRequiredDependencies();
21+
22+
describe('getRequiredDependencies', () => {
23+
it('has required dependencies', () => {
24+
expect(requiredDependencies.length).toBeGreaterThan(0);
25+
});
26+
27+
it('includes ui-react', () => {
28+
expect(requiredDependencies.filter((dep) => dep.dependencyName === '@aws-amplify/ui-react')).toBeTruthy();
29+
});
30+
31+
it('includes all valid semver values', () => {
32+
requiredDependencies.forEach((dep) => {
33+
expect(semver.valid(dep.supportedSemVerPattern)).toBeDefined();
34+
});
35+
});
36+
37+
it('includes reasons on all dependencies', () => {
38+
requiredDependencies.forEach((dep) => {
39+
expect(dep.reason.length).toBeGreaterThan(0);
40+
});
41+
});
42+
});
43+
});

packages/codegen-ui-react/lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ export * from './react-output-manager';
2424
export * from './amplify-ui-renderers/amplify-renderer';
2525
export * from './primitive';
2626
export * from './react-index-studio-template-renderer';
27+
export * from './react-required-dependency-provider';
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License").
5+
You may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
import { RequiredDependency, RequiredDependencyProvider } from '@aws-amplify/codegen-ui';
17+
18+
type SemVerRequiredDependency = RequiredDependency & {
19+
supportedSemVerPattern: string;
20+
};
21+
22+
export class ReactRequiredDependencyProvider extends RequiredDependencyProvider<SemVerRequiredDependency> {
23+
getRequiredDependencies(): SemVerRequiredDependency[] {
24+
return [
25+
{
26+
dependencyName: '@aws-amplify/ui-react',
27+
supportedSemVerPattern: '^2.1.4',
28+
reason: 'Required to leverage amplify ui primitives, and studio component helper functions.',
29+
},
30+
];
31+
}
32+
}

0 commit comments

Comments
 (0)