Skip to content

Commit c772ab9

Browse files
committed
update platform_support file
1 parent cfa67a0 commit c772ab9

File tree

3 files changed

+13
-51
lines changed

3 files changed

+13
-51
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = {
3131
{
3232
'files': ['lib/**/*.ts', 'src/**/*.ts'],
3333
'excludedFiles': [
34+
'**/platform_support.ts',
3435
'**/*.spec.ts',
3536
'**/*.test.ts',
3637
'**/*.tests.ts',

.platform-isolation.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ module.exports = {
1313

1414
// Files and patterns to exclude from validation
1515
exclude: [
16+
// Platform definition file (this file defines Platform type, doesn't need __platforms)
17+
'**/platform_support.ts',
18+
1619
// Test files
1720
'**/*.spec.ts',
1821
'**/*.test.ts',

lib/platform_support.ts

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,17 @@
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[];
341

352
/**
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
414
*
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
439
*
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.
4712
*/
48-
export type RequirePlatformDeclaration<T> = T extends { __platforms: readonly Platform[] }
49-
? T
50-
: never & { error: '__platforms export is required' };
5113

5214
/**
53-
* Utility to check if a file is universal (supports all platforms)
15+
* Valid platform identifiers
5416
*/
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

Comments
 (0)