diff --git a/Makefile b/Makefile index f8b0c006f2a..c8a0d468ed9 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/packages/@react-spectrum/s2/icon.d.ts b/packages/@react-spectrum/s2/icon.d.ts deleted file mode 100644 index 768a2827aff..00000000000 --- a/packages/@react-spectrum/s2/icon.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2024 Adobe. All rights reserved. - * This file is licensed to you under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. You may obtain a copy - * of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - * OF ANY KIND, either express or implied. See the License for the specific language - * governing permissions and limitations under the License. - */ - -import type {IconProps} from './dist/types'; -import type {ReactNode} from 'react'; - -declare function Icon(props: IconProps): ReactNode; -export default Icon; diff --git a/scripts/copyIconDts.js b/scripts/generateIconDts.js similarity index 63% rename from scripts/copyIconDts.js rename to scripts/generateIconDts.js index c1f6ad6e9e8..f6409fd2c9c 100644 --- a/scripts/copyIconDts.js +++ b/scripts/generateIconDts.js @@ -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; +`); }