Skip to content

Commit 1067aff

Browse files
authored
Fix import path in icon and illustration .d.ts files (#6912)
1 parent faf0e18 commit 1067aff

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ build:
107107
do node scripts/buildEsm.js $$pkg; \
108108
done
109109
node scripts/buildI18n.js
110-
node scripts/copyIconDts.js
110+
node scripts/generateIconDts.js
111111

112112
website:
113113
yarn build:docs --public-url /reactspectrum/$$(git rev-parse HEAD)/docs --dist-dir dist/$$(git rev-parse HEAD)/docs

packages/@react-spectrum/s2/icon.d.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

scripts/copyIconDts.js renamed to scripts/generateIconDts.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@
1212

1313
const glob = require('glob').sync;
1414
const fs = require('fs');
15+
const path = require('path');
1516

16-
// We have to copy icon.d.ts for each icon/illustration so TypeScript's import autocomplete works.
17+
// Generate types for each icon/illustration so TypeScript's import autocomplete works.
1718
for (let file of glob('packages/@react-spectrum/s2/{icons,illustrations/**}/*.mjs')) {
18-
fs.copyFileSync('packages/@react-spectrum/s2/icon.d.ts', file.replace('.mjs', '.d.ts'));
19+
let relative = path.relative(path.dirname(file), 'packages/@react-spectrum/s2/dist/types').replaceAll('\\', '/');
20+
fs.writeFileSync(file.replace('.mjs', '.d.ts'), `import type {IconProps} from '${relative}';
21+
import type {ReactNode} from 'react';
22+
23+
declare function Icon(props: IconProps): ReactNode;
24+
export default Icon;
25+
`);
1926
}

0 commit comments

Comments
 (0)