Skip to content

Commit

Permalink
Fix import path in icon and illustration .d.ts files (adobe#6912)
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Aug 20, 2024
1 parent faf0e18 commit 1067aff
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ build:
do node scripts/buildEsm.js $$pkg; \
done
node scripts/buildI18n.js
node scripts/copyIconDts.js
node scripts/generateIconDts.js

website:
yarn build:docs --public-url /reactspectrum/$$(git rev-parse HEAD)/docs --dist-dir dist/$$(git rev-parse HEAD)/docs
Expand Down
17 changes: 0 additions & 17 deletions packages/@react-spectrum/s2/icon.d.ts

This file was deleted.

11 changes: 9 additions & 2 deletions scripts/copyIconDts.js → scripts/generateIconDts.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@

const glob = require('glob').sync;
const fs = require('fs');
const path = require('path');

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

0 comments on commit 1067aff

Please sign in to comment.