|
1 | | -/** |
2 | | - * Platform Support Type Definitions |
3 | | - * |
4 | | - * Every source file (except tests) must export __platforms to declare |
5 | | - * which platforms it supports. This is enforced at both type-level and runtime. |
6 | | - */ |
7 | | - |
8 | | -/** |
9 | | - * Valid platform identifiers |
10 | | - */ |
11 | | -export type Platform = 'browser' | 'node' | 'react_native' | '__universal__'; |
12 | | - |
13 | | - |
14 | | -/** |
15 | | - * Platform support declaration |
16 | | - * |
17 | | - * Every file must export this to declare which platforms it supports: |
18 | | - * - Specific platforms: export const __platforms = ['browser', 'node']; |
19 | | - * - All platforms (universal): export const __platforms = ['__universal__']; |
20 | | - * |
21 | | - * @example |
22 | | - * // Browser and React Native only |
23 | | - * export const __platforms = ['browser', 'react_native'] satisfies Platform[]; |
24 | | - * |
25 | | - * @example |
26 | | - * // Node.js only |
27 | | - * export const __platforms = ['node'] satisfies Platform[]; |
28 | | - * |
29 | | - * @example |
30 | | - * // Universal (all platforms) |
31 | | - * export const __platforms = ['__universal__'] satisfies Platform[]; |
32 | | - */ |
33 | | -export type SupportedPlatforms = readonly Platform[]; |
34 | 1 |
|
35 | 2 | /** |
36 | | - * Helper type to enforce that a module exports __platforms |
37 | | - * |
38 | | - * Usage in your module: |
39 | | - * ```typescript |
40 | | - * import type { RequirePlatformDeclaration, Platform } from './platform_support'; |
| 3 | + * ⚠️ WARNING: DO NOT MOVE, DELETE, OR RENAME THIS FILE |
41 | 4 | * |
42 | | - * export const __platforms = ['browser'] satisfies Platform[]; |
| 5 | + * This file is used by the build system and validation scripts: |
| 6 | + * - scripts/validate-platform-isolation-ts.js |
| 7 | + * - scripts/platform-utils.js |
| 8 | + * - eslint-local-rules/require-platform-declaration.js |
43 | 9 | * |
44 | | - * // This type check ensures __platforms is exported |
45 | | - * // type _Check = RequirePlatformDeclaration<typeof import('./your-module')>; |
46 | | - * ``` |
| 10 | + * These tools parse this file at build time to extract the Platform type definition. |
| 11 | + * Moving or renaming this file will break the build. |
47 | 12 | */ |
48 | | -export type RequirePlatformDeclaration<T> = T extends { __platforms: readonly Platform[] } |
49 | | - ? T |
50 | | - : never & { error: '__platforms export is required' }; |
51 | 13 |
|
52 | 14 | /** |
53 | | - * Utility to check if a file is universal (supports all platforms) |
| 15 | + * Valid platform identifiers |
54 | 16 | */ |
55 | | -export function isUniversal(platforms: readonly Platform[]): boolean { |
56 | | - return platforms.length === 1 && platforms[0] === '__universal__'; |
57 | | -} |
58 | | - |
59 | | -export const __platforms: Platform[] = ['__universal__']; |
| 17 | +export type Platform = 'browser' | 'node' | 'react_native' | '__universal__'; |
0 commit comments