-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Support third party type imports (#43)
- Loading branch information
Showing
9 changed files
with
135 additions
and
5 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
fixtures/components/third-party-import-types/button/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import * as React from 'react'; | ||
|
||
import { ButtonProps } from './interfaces'; | ||
|
||
export { ButtonProps }; | ||
|
||
/** | ||
* Component-level description | ||
*/ | ||
export default function Button({ iconName }: ButtonProps) { | ||
return <div className={iconName}>{iconName}</div>; | ||
} |
10 changes: 10 additions & 0 deletions
10
fixtures/components/third-party-import-types/button/interfaces.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { IconProps } from '../node_modules_mock/icon'; | ||
|
||
export interface ButtonProps { | ||
/** | ||
* This is icon name | ||
*/ | ||
iconName: IconProps.Name; | ||
} |
4 changes: 4 additions & 0 deletions
4
fixtures/components/third-party-import-types/node_modules_mock/icon/index.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { IconProps } from './interfaces'; | ||
export { IconProps }; |
11 changes: 11 additions & 0 deletions
11
fixtures/components/third-party-import-types/node_modules_mock/icon/interfaces.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
export interface IconProps { | ||
/** | ||
* Specifies the icon to be displayed. | ||
*/ | ||
name?: IconProps.Name; | ||
} | ||
export declare namespace IconProps { | ||
type Name = 'icon1' | 'icon2' | 'icon3'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "button" | ||
}, | ||
"include": ["button"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { buildProject } from './test-helpers'; | ||
import { ComponentDefinition } from '../../src'; | ||
import * as bootstrap from '../../src/bootstrap'; | ||
import process from 'node:process'; | ||
const cwd = process.cwd(); | ||
const nodeModulesPath = `${cwd}/fixtures/components/third-party-import-types/node_modules_mock/icon/interfaces.d.ts`; | ||
|
||
test('should resolve object type to string', () => { | ||
const resultBefore = buildProject('third-party-import-types'); | ||
const buttonBefore: ComponentDefinition | undefined = resultBefore.find(component => component.name === 'Button'); | ||
|
||
expect(buttonBefore?.properties).toEqual([ | ||
{ | ||
name: 'iconName', | ||
type: 'IconProps.Name', | ||
inlineType: undefined, | ||
optional: false, | ||
description: 'This is icon name', | ||
defaultValue: undefined, | ||
visualRefreshTag: undefined, | ||
deprecatedTag: undefined, | ||
i18nTag: undefined, | ||
analyticsTag: undefined, | ||
}, | ||
]); | ||
|
||
const resultAfter = buildProject('third-party-import-types', [nodeModulesPath]); | ||
const buttonAfter: ComponentDefinition | undefined = resultAfter.find(component => component.name === 'Button'); | ||
|
||
expect(buttonAfter?.properties).toEqual([ | ||
{ | ||
name: 'iconName', | ||
type: 'string', | ||
inlineType: { name: 'IconProps.Name', type: 'union', values: ['icon1', 'icon2', 'icon3'] }, | ||
optional: false, | ||
description: 'This is icon name', | ||
defaultValue: undefined, | ||
visualRefreshTag: undefined, | ||
deprecatedTag: undefined, | ||
i18nTag: undefined, | ||
analyticsTag: undefined, | ||
}, | ||
]); | ||
}); | ||
|
||
test('passing nodeModulesDependencyFilePaths should enable includeDeclarations and excludeExternals', () => { | ||
const bootstrapProjectSpy = jest.spyOn(bootstrap, 'bootstrapProject'); | ||
buildProject('third-party-import-types', [nodeModulesPath]); | ||
|
||
expect(bootstrapProjectSpy.mock.calls[0][0].includeDeclarations).toBe(true); | ||
expect(bootstrapProjectSpy.mock.calls[0][0].excludeExternals).toBe(true); | ||
|
||
jest.restoreAllMocks(); | ||
}); |