diff --git a/packages/react/components/data-view/__tests__/data-view.test.tsx b/packages/react/components/data-view/__tests__/data-view.test.tsx index b7778cdd0..99a3474bb 100644 --- a/packages/react/components/data-view/__tests__/data-view.test.tsx +++ b/packages/react/components/data-view/__tests__/data-view.test.tsx @@ -371,7 +371,7 @@ describe('DataView', () => { label: 'Status', filterable: true, filterType: 'select', - filterOptions: [{ label: 'Active', value: 'string' }] + filterOptions: [{ label: 'Active', value: 'active' }] }, { accessorKey: 'email', diff --git a/packages/react/components/filter-chip/__tests__/data-slots.test.tsx b/packages/react/components/filter-chip/__tests__/data-slots.test.tsx index 2701d0352..c9e65fef5 100644 --- a/packages/react/components/filter-chip/__tests__/data-slots.test.tsx +++ b/packages/react/components/filter-chip/__tests__/data-slots.test.tsx @@ -36,7 +36,7 @@ describe('FilterChip data-slot contract', () => { ); expect( diff --git a/packages/react/package.json b/packages/react/package.json index b459c5b5d..04c4de209 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -116,6 +116,7 @@ "rollup-plugin-preserve-directives": "^0.4.0", "rollup-plugin-tsconfig-paths": "^1.5.2", "semver": "^7.6.0", + "tsc-alias": "1.9.10", "typescript": "~5.4.3", "vitest": "^3.2.4" }, diff --git a/packages/react/rollup.config.mjs b/packages/react/rollup.config.mjs index 61db2daf6..93e043d93 100644 --- a/packages/react/rollup.config.mjs +++ b/packages/react/rollup.config.mjs @@ -1,3 +1,5 @@ +import { readdirSync, readFileSync } from 'node:fs'; +import { join } from 'node:path'; import commonjs from '@rollup/plugin-commonjs'; import { nodeResolve } from '@rollup/plugin-node-resolve'; import typescript from '@rollup/plugin-typescript'; @@ -7,6 +9,7 @@ import nodeExternals from 'rollup-plugin-node-externals'; import postcss from 'rollup-plugin-postcss'; import preserveDirectives from 'rollup-plugin-preserve-directives'; import tsconfigPaths from 'rollup-plugin-tsconfig-paths'; +import { replaceTscAliasPaths } from 'tsc-alias'; /** Matches `@import url("https://fonts.googleapis.com/…");` in any quoting. */ const FONT_IMPORT = @@ -42,6 +45,44 @@ const emitFontFreeCss = ({ from, to }) => { }; }; +/** Matches a quoted `~/` module specifier. */ +const ALIAS_SPECIFIER = /(['"])~\/[^'"]+\1/g; + +/** + * Rewrites `~/` specifiers in emitted declarations to relative paths, because + * TypeScript keeps `paths` aliases as written and apps cannot resolve them. + * `tsconfig.alias.json` leaves out the `react` entry of `tsconfig.json`, which + * tsc-alias would otherwise rewrite to `node_modules/@types/react`. Fails the + * build if a specifier is left. Must be ordered after `typescript()`. + */ +const resolveDeclarationAliases = () => ({ + name: 'apsara-declaration-aliases', + async closeBundle() { + await replaceTscAliasPaths({ + configFile: 'tsconfig.alias.json', + outDir: 'dist' + }); + const leaks = []; + const declarations = readdirSync('dist', { recursive: true }).filter( + fileName => fileName.endsWith('.d.ts') + ); + for (const fileName of declarations) { + readFileSync(join('dist', fileName), 'utf8') + .split('\n') + .forEach((line, index) => { + for (const [specifier] of line.matchAll(ALIAS_SPECIFIER)) { + leaks.push(`dist/${fileName}:${index + 1} ${specifier}`); + } + }); + } + if (leaks.length > 0) { + this.error( + `Declarations still import through the ~/ alias:\n${leaks.join('\n')}` + ); + } + } +}); + const createPlugins = ({ rootDir, declarationDir }) => [ // Externalize all dependencies and peer dependencies // This must be placed before nodeResolve() to work correctly @@ -79,6 +120,7 @@ const createPlugins = ({ rootDir, declarationDir }) => [ rootDir: rootDir, declarationDir: declarationDir }), + resolveDeclarationAliases(), preserveDirectives() //preserve `use client` directive ]; diff --git a/packages/react/tsconfig.alias.json b/packages/react/tsconfig.alias.json new file mode 100644 index 000000000..94495433c --- /dev/null +++ b/packages/react/tsconfig.alias.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "paths": { + "~/*": ["./*"] + } + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 79ce2397c..aa638d62c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -326,6 +326,9 @@ importers: semver: specifier: ^7.6.0 version: 7.6.0 + tsc-alias: + specifier: 1.9.10 + version: 1.9.10 typescript: specifier: ~5.4.3 version: 5.4.3 @@ -3150,6 +3153,10 @@ packages: any-promise@1.3.0: resolution: {integrity: sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A==} + anymatch@3.1.3: + resolution: {integrity: sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==} + engines: {node: '>= 8'} + arg@4.1.3: resolution: {integrity: sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==} @@ -3224,6 +3231,10 @@ packages: engines: {node: '>=6.0.0'} hasBin: true + binary-extensions@2.3.0: + resolution: {integrity: sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==} + engines: {node: '>=8'} + binaryextensions@6.11.0: resolution: {integrity: sha512-sXnYK/Ij80TO3lcqZVV2YgfKN5QjUWIRk/XSm2J/4bd/lPko3lvk0O4ZppH6m+6hB2/GTu+ptNwVFe1xh+QLQw==} engines: {node: '>=4'} @@ -3365,6 +3376,10 @@ packages: resolution: {integrity: sha512-+0hMx9eYhJvWbgpKV9hN7jg0JcwydpopZE4hgi+KvQtByZXPp04NiCWU0LzcAbP63abZckIHkTQaXVF52mX3xQ==} engines: {node: '>=18.17'} + chokidar@3.6.0: + resolution: {integrity: sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==} + engines: {node: '>= 8.10.0'} + chokidar@6.0.0: resolution: {integrity: sha512-Ec2Z7wpcKBiMpR7DxteoqS/sq5G5d2A4fpxzPv6+fD7xNNdrTghn7L11YwV5EN1B3i72Erc3XVT5FkWIDx90+A==} engines: {node: '>= 22.22'} @@ -3493,6 +3508,10 @@ packages: resolution: {integrity: sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==} engines: {node: '>= 10'} + commander@9.5.0: + resolution: {integrity: sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==} + engines: {node: ^12.20.0 || >=14} + commondir@1.0.1: resolution: {integrity: sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==} @@ -4163,6 +4182,9 @@ packages: resolution: {integrity: sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==} engines: {node: '>= 0.4'} + get-tsconfig@4.14.3: + resolution: {integrity: sha512-++QEw4DIY7WGoukz+/+A/8dGYPT9l9yIadnmSgZ8Rjr3YVSVDipQSO9CdnJo9ePqFqUUqh+wk9uIaoiAwsiPkA==} + github-from-package@0.0.0: resolution: {integrity: sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw==} @@ -4203,6 +4225,10 @@ packages: resolution: {integrity: sha512-7dUi7RvCoT/xast/o/dLN53oqND4yk0nsHkhRgn9w65C4PofCLOoJ39iSOg+qVDdWQPIEj+eszMHQ+aLVwwQSg==} engines: {node: '>=8'} + globby@11.1.0: + resolution: {integrity: sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==} + engines: {node: '>=10'} + globby@14.1.0: resolution: {integrity: sha512-0Ia46fDOaT7k4og1PDW4YbodWWr3scS2vAr2lTbsplOt2WkKp0vQbkI9wKis/T5LV/dqPjO3bpS/z6GTJB82LA==} engines: {node: '>=18'} @@ -4405,6 +4431,10 @@ packages: is-bigint@1.0.4: resolution: {integrity: sha512-zB9CruMamjym81i2JZ3UMn54PKGsQzsJeo6xvN3HJJ4CAsQNB6iRutp2To77OfCNuoxspsIhzaPoO1zyCEhFOg==} + is-binary-path@2.1.0: + resolution: {integrity: sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==} + engines: {node: '>=8'} + is-boolean-object@1.1.2: resolution: {integrity: sha512-gDYaKHJmnj4aWxyj6YHyXVpdQawtVLHU5cb+eztPGczf6cjuTdwve5ZIEfgXqH4e57An1D1AKf8CZ3kYrQRqYA==} engines: {node: '>= 0.4'} @@ -5163,6 +5193,10 @@ packages: mute-stream@0.0.8: resolution: {integrity: sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==} + mylas@2.1.14: + resolution: {integrity: sha512-BzQguy9W9NJgoVn2mRWzbFrFWWztGCcng2QI9+41frfk+Athwgx3qhqhvStz7ExeUUu7Kzw427sNzHpEZNINog==} + engines: {node: '>=16.0.0'} + mz@2.7.0: resolution: {integrity: sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==} @@ -5243,6 +5277,10 @@ packages: resolution: {integrity: sha512-V6gygoYb/5EmNI+MEGrWkC+e6+Rr7mTmfHrxDbLzxQogBkgzo76rkok0Am6thgSF7Mv2nLOajAJj5vDJZEFn7g==} engines: {node: ^16.14.0 || >=18.0.0} + normalize-path@3.0.0: + resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==} + engines: {node: '>=0.10.0'} + normalize-url@6.1.0: resolution: {integrity: sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A==} engines: {node: '>=10'} @@ -5449,6 +5487,10 @@ packages: resolution: {integrity: sha512-BwPsw/e1Be7F0SfpxhNc2VSxX7uHgCy46Ck+2Z/vqCwXoePhUBrX/VbcawpAlZgMvQe2iwGbZIQ6HSj9bmCk8A==} hasBin: true + plimit-lit@1.6.1: + resolution: {integrity: sha512-B7+VDyb8Tl6oMJT9oSO2CW8XC/T4UcJGrwOVoNGwOQsQYhlpfajmrMj5xeejqaASq3V/EqThyOeATEOMuSEXiA==} + engines: {node: '>=12'} + pluralize@2.0.0: resolution: {integrity: sha512-TqNZzQCD4S42De9IfnnBvILN7HAW7riLqsCyp8lgjXeysyPlX5HhqKAcJHHHb9XskE4/a+7VGC9zzx8Ls0jOAw==} @@ -5781,6 +5823,10 @@ packages: querystringify@2.2.0: resolution: {integrity: sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==} + queue-lit@1.5.2: + resolution: {integrity: sha512-tLc36IOPeMAubu8BkW8YDBV+WyIgKlYU7zUNs0J5Vk9skSZ4JfGlPOqplP0aHdfv7HL0B2Pg6nwiq60Qc6M2Hw==} + engines: {node: '>=12'} + queue-microtask@1.2.3: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} @@ -5910,6 +5956,10 @@ packages: resolution: {integrity: sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==} engines: {node: '>= 6'} + readdirp@3.6.0: + resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==} + engines: {node: '>=8.10.0'} + readdirp@5.1.1: resolution: {integrity: sha512-Kko+Y5XQ6fM+Ce3dq3m9YGxnacYZYl9cA1wZjaF3Vbry2L3i1qVg8+CAgNPsXRArPMUMCaOR7oa9Nqntc43JKA==} engines: {node: '>= 20.19.0'} @@ -5998,6 +6048,9 @@ packages: resolution: {integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==} engines: {node: '>=8'} + resolve-pkg-maps@1.0.0: + resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==} + resolve@1.22.8: resolution: {integrity: sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==} hasBin: true @@ -6532,6 +6585,11 @@ packages: '@swc/wasm': optional: true + tsc-alias@1.9.10: + resolution: {integrity: sha512-dsZvDB/wgAtRPFDHPYy7X7uqKFR4jJ7VB/2ndPGZQkIMQREz8q74fFsMZL4UmCbUztXhxoA1brKfqW7XzQeMqA==} + engines: {node: '>=16.20.2'} + hasBin: true + tslib@1.14.1: resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==} @@ -9729,6 +9787,11 @@ snapshots: any-promise@1.3.0: {} + anymatch@3.1.3: + dependencies: + normalize-path: 3.0.0 + picomatch: 2.3.1 + arg@4.1.3: {} argparse@1.0.10: @@ -9792,6 +9855,8 @@ snapshots: baseline-browser-mapping@2.11.24: {} + binary-extensions@2.3.0: {} + binaryextensions@6.11.0: dependencies: editions: 6.21.0 @@ -9987,6 +10052,18 @@ snapshots: undici: 7.10.0 whatwg-mimetype: 4.0.0 + chokidar@3.6.0: + dependencies: + anymatch: 3.1.3 + braces: 3.0.3 + glob-parent: 5.1.2 + is-binary-path: 2.1.0 + is-glob: 4.0.3 + normalize-path: 3.0.0 + readdirp: 3.6.0 + optionalDependencies: + fsevents: 2.3.3 + chokidar@6.0.0: dependencies: readdirp: 5.1.1 @@ -10090,6 +10167,8 @@ snapshots: commander@7.2.0: {} + commander@9.5.0: {} + commondir@1.0.1: {} compare-versions@6.1.1: {} @@ -10840,6 +10919,10 @@ snapshots: dunder-proto: 1.0.1 es-object-atoms: 1.1.1 + get-tsconfig@4.14.3: + dependencies: + resolve-pkg-maps: 1.0.0 + github-from-package@0.0.0: optional: true @@ -10904,6 +10987,15 @@ snapshots: merge2: 1.4.1 slash: 3.0.0 + globby@11.1.0: + dependencies: + array-union: 2.1.0 + dir-glob: 3.0.1 + fast-glob: 3.3.3 + ignore: 5.3.1 + merge2: 1.4.1 + slash: 3.0.0 + globby@14.1.0: dependencies: '@sindresorhus/merge-streams': 2.3.0 @@ -11193,6 +11285,10 @@ snapshots: dependencies: has-bigints: 1.0.2 + is-binary-path@2.1.0: + dependencies: + binary-extensions: 2.3.0 + is-boolean-object@1.1.2: dependencies: call-bind: 1.0.7 @@ -12186,6 +12282,8 @@ snapshots: mute-stream@0.0.8: {} + mylas@2.1.14: {} + mz@2.7.0: dependencies: any-promise: 1.3.0 @@ -12274,6 +12372,8 @@ snapshots: semver: 7.7.3 validate-npm-package-license: 3.0.4 + normalize-path@3.0.0: {} + normalize-url@6.1.0: {} npm-to-yarn@3.2.0: {} @@ -12471,6 +12571,10 @@ snapshots: pkg-pr-new@0.0.86: {} + plimit-lit@1.6.1: + dependencies: + queue-lit: 1.5.2 + pluralize@2.0.0: {} pluralize@8.0.0: {} @@ -12833,6 +12937,8 @@ snapshots: querystringify@2.2.0: {} + queue-lit@1.5.2: {} + queue-microtask@1.2.3: {} radix-ui@1.4.3(@types/react-dom@19.2.2(@types/react@19.2.2))(@types/react@19.2.2)(react-dom@19.2.1(react@19.2.1))(react@19.2.1): @@ -13020,6 +13126,10 @@ snapshots: string_decoder: 1.3.0 util-deprecate: 1.0.2 + readdirp@3.6.0: + dependencies: + picomatch: 2.3.1 + readdirp@5.1.1: {} recma-build-jsx@1.0.0: @@ -13162,6 +13272,8 @@ snapshots: resolve-from@5.0.0: {} + resolve-pkg-maps@1.0.0: {} + resolve@1.22.8: dependencies: is-core-module: 2.14.0 @@ -13803,6 +13915,16 @@ snapshots: '@swc/core': 1.11.21 optional: true + tsc-alias@1.9.10: + dependencies: + chokidar: 3.6.0 + commander: 9.5.0 + get-tsconfig: 4.14.3 + globby: 11.1.0 + mylas: 2.1.14 + normalize-path: 3.0.0 + plimit-lit: 1.6.1 + tslib@1.14.1: {} tslib@2.6.3: {}