Skip to content

Commit 4bc72f7

Browse files
committed
use __platform
1 parent 7729865 commit 4bc72f7

File tree

132 files changed

+242
-242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+242
-242
lines changed

ESLINT_TROUBLESHOOTING.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ The `require-platform-declaration` rule **is** working correctly from the comman
88
$ npx eslint lib/core/custom_attribute_condition_evaluator/index.ts
99

1010
lib/core/custom_attribute_condition_evaluator/index.ts
11-
16:1 error File must export __supportedPlatforms to declare which platforms
12-
it supports. Example: export const __supportedPlatforms = ['__universal__'] as const;
11+
16:1 error File must export __platforms to declare which platforms
12+
it supports. Example: export const __platforms = ['__universal__'] as const;
1313
```
1414

1515
## VSCode Not Showing Errors?
@@ -71,14 +71,14 @@ npx eslint lib/service.ts
7171
npx eslint lib/**/*.ts --quiet
7272
```
7373

74-
## Adding __supportedPlatforms
74+
## Adding __platforms
7575

7676
To fix the error, add this export to your file (after imports):
7777

7878
```typescript
7979
// Universal file (all platforms)
80-
export const __supportedPlatforms = ['__universal__'] as const;
80+
export const __platforms = ['__universal__'] as const;
8181

8282
// OR platform-specific file
83-
export const __supportedPlatforms = ['browser', 'node'] as const;
83+
export const __platforms = ['browser', 'node'] as const;
8484
```

docs/PLATFORM_ISOLATION.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ For files specific to a single platform, use a suffix pattern:
1818

1919
### 2. Export Declaration (Multiple Platforms)
2020

21-
For files that support multiple platforms but not all (e.g., Browser + React Native, but not Node.js), export a `__supportedPlatforms` array:
21+
For files that support multiple platforms but not all (e.g., Browser + React Native, but not Node.js), export a `__platforms` array:
2222

2323
```typescript
2424
// lib/utils/web-features.ts
25-
export const __supportedPlatforms = ['browser', 'react_native'];
25+
export const __platforms = ['browser', 'react_native'];
2626

2727
// Your code that works on both browser and react_native
2828
export function getWindowSize() {
@@ -34,7 +34,7 @@ Valid platform identifiers: `'browser'`, `'node'`, `'react_native'`
3434

3535
### Priority
3636

37-
If a file has both a platform suffix in its name AND a `__supportedPlatforms` export, the `__supportedPlatforms` export **takes priority**. This allows you to keep the `.browser.ts` naming convention while expanding support to additional platforms like React Native.
37+
If a file has both a platform suffix in its name AND a `__platforms` export, the `__platforms` export **takes priority**. This allows you to keep the `.browser.ts` naming convention while expanding support to additional platforms like React Native.
3838

3939
## Import Rules
4040

@@ -51,11 +51,11 @@ A file is compatible if:
5151

5252
### Compatibility Examples
5353

54-
**Single Platform File (`.browser.ts` or `__supportedPlatforms = ['browser']`)**
54+
**Single Platform File (`.browser.ts` or `__platforms = ['browser']`)**
5555
- ✅ Can import from: universal files, `.browser.ts` files, files with `['browser']` or `['browser', 'react_native']`
5656
- ❌ Cannot import from: `.node.ts` files, files with `['node']` or `['react_native']` only
5757

58-
**Multi-Platform File (`__supportedPlatforms = ['browser', 'react_native']`)**
58+
**Multi-Platform File (`__platforms = ['browser', 'react_native']`)**
5959
- ✅ Can import from: universal files, files with exactly `['browser', 'react_native']`
6060
- ❌ Cannot import from: `.browser.ts` (browser only), `.react_native.ts` (react_native only), `.node.ts`
6161
- **Why?** A file supporting both platforms needs imports that work in BOTH environments
@@ -81,17 +81,17 @@ import { NodeRequestHandler } from './utils/http_request_handler/request_handler
8181
// In lib/index.react_native.ts (React Native platform only)
8282
import { Config } from './shared_types'; // ✅ Universal file
8383

84-
// If web-features.ts has: __supportedPlatforms = ['browser', 'react_native']
84+
// If web-features.ts has: __platforms = ['browser', 'react_native']
8585
import { getWindowSize } from './utils/web-features'; // ✅ Compatible (supports react_native)
8686
```
8787

8888
```typescript
8989
// In lib/utils/web-api.ts
90-
// export const __supportedPlatforms = ['browser', 'react_native'];
90+
// export const __platforms = ['browser', 'react_native'];
9191

9292
import { Config } from './shared_types'; // ✅ Universal file
9393

94-
// If dom-helpers.ts has: __supportedPlatforms = ['browser', 'react_native']
94+
// If dom-helpers.ts has: __platforms = ['browser', 'react_native']
9595
import { helpers } from './dom-helpers'; // ✅ Compatible (supports BOTH browser and react_native)
9696
```
9797

@@ -104,15 +104,15 @@ import { NodeRequestHandler } from './utils/http_request_handler/request_handler
104104

105105
```typescript
106106
// In lib/index.node.ts (Node platform only)
107-
// If web-features.ts has: __supportedPlatforms = ['browser', 'react_native']
107+
// If web-features.ts has: __platforms = ['browser', 'react_native']
108108
import { getWindowSize } from './utils/web-features'; // ❌ Not compatible with Node
109109
```
110110

111111
```typescript
112112
// In lib/utils/web-api.ts
113-
// export const __supportedPlatforms = ['browser', 'react_native'];
113+
// export const __platforms = ['browser', 'react_native'];
114114

115-
// If helper.browser.ts is browser-only (no __supportedPlatforms export)
115+
// If helper.browser.ts is browser-only (no __platforms export)
116116
import { helper } from './helper.browser'; // ❌ Browser-only, doesn't support react_native
117117

118118
// This file needs imports that work in BOTH browser AND react_native
@@ -203,13 +203,13 @@ export const createMyFeature = () => new NodeMyFeature();
203203

204204
### Multiple Platforms (But Not All)
205205

206-
For code that works on multiple platforms but not all, use the `__supportedPlatforms` export:
206+
For code that works on multiple platforms but not all, use the `__platforms` export:
207207

208208
**Example: Browser + React Native only**
209209

210210
```typescript
211211
// lib/utils/dom-helpers.ts
212-
export const __supportedPlatforms = ['browser', 'react_native'];
212+
export const __platforms = ['browser', 'react_native'];
213213

214214
// This code works on both browser and react_native, but not node
215215
export function getElementById(id: string): Element | null {
@@ -225,7 +225,7 @@ export function getElementById(id: string): Element | null {
225225

226226
```typescript
227227
// lib/utils/native-crypto.ts
228-
export const __supportedPlatforms = ['node', 'react_native'];
228+
export const __platforms = ['node', 'react_native'];
229229

230230
import crypto from 'crypto'; // Available in both Node and React Native
231231

eslint-local-rules/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This directory contains custom ESLint rules specific to this project.
66

77
### `require-platform-declaration`
88

9-
**Purpose:** Ensures all source files (except tests) export `__supportedPlatforms` to declare which platforms they support.
9+
**Purpose:** Ensures all source files (except tests) export `__platforms` to declare which platforms they support.
1010

1111
**Why:** This enforces platform isolation at the linting level, catching missing declarations before build time.
1212

@@ -19,20 +19,20 @@ This directory contains custom ESLint rules specific to this project.
1919

2020
```typescript
2121
// Universal file (all platforms)
22-
export const __supportedPlatforms = ['__universal__'] as const;
22+
export const __platforms = ['__universal__'] as const;
2323

2424
// Platform-specific file
25-
export const __supportedPlatforms = ['browser', 'node'] as const;
25+
export const __platforms = ['browser', 'node'] as const;
2626

2727
// With type annotation
28-
export const __supportedPlatforms: Platform[] = ['react_native'] as const;
28+
export const __platforms: Platform[] = ['react_native'] as const;
2929
```
3030

3131
**Invalid:**
3232

3333
```typescript
34-
// Missing __supportedPlatforms export
35-
// ESLint Error: File must export __supportedPlatforms to declare which platforms it supports
34+
// Missing __platforms export
35+
// ESLint Error: File must export __platforms to declare which platforms it supports
3636
```
3737

3838
## Configuration

eslint-local-rules/require-platform-declaration.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/**
22
* ESLint Rule: require-platform-declaration
33
*
4-
* Ensures that all non-test source files export __supportedPlatforms with valid platform values
4+
* Ensures that all non-test source files export __platforms with valid platform values
55
*
66
* Valid:
7-
* export const __supportedPlatforms = ['browser'];
8-
* export const __supportedPlatforms = ['__universal__'];
9-
* export const __supportedPlatforms = ['browser', 'node'];
7+
* export const __platforms = ['browser'];
8+
* export const __platforms = ['__universal__'];
9+
* export const __platforms = ['browser', 'node'];
1010
*
1111
* Invalid:
12-
* // Missing __supportedPlatforms export
12+
* // Missing __platforms export
1313
* // Invalid platform values (must match Platform type definition in platform_support.ts)
1414
* // Not exported as const array
1515
*/
@@ -83,15 +83,15 @@ module.exports = {
8383
meta: {
8484
type: 'problem',
8585
docs: {
86-
description: 'Require __supportedPlatforms export with valid platform values in all source files',
86+
description: 'Require __platforms export with valid platform values in all source files',
8787
category: 'Best Practices',
8888
recommended: true,
8989
},
9090
messages: {
91-
missingPlatformDeclaration: 'File must export __supportedPlatforms to declare which platforms it supports. Example: export const __supportedPlatforms = [\'__universal__\'];',
92-
invalidPlatformDeclaration: '__supportedPlatforms must be exported as a const array. Example: export const __supportedPlatforms = [\'browser\', \'node\'];',
93-
invalidPlatformValue: '__supportedPlatforms contains invalid platform value "{{value}}". Valid platforms are: {{validPlatforms}}',
94-
emptyPlatformArray: '__supportedPlatforms array cannot be empty. Specify at least one platform or use [\'__universal__\']',
91+
missingPlatformDeclaration: 'File must export __platforms to declare which platforms it supports. Example: export const __platforms = [\'__universal__\'];',
92+
invalidPlatformDeclaration: '__platforms must be exported as a const array. Example: export const __platforms = [\'browser\', \'node\'];',
93+
invalidPlatformValue: '__platforms contains invalid platform value "{{value}}". Valid platforms are: {{validPlatforms}}',
94+
emptyPlatformArray: '__platforms array cannot be empty. Specify at least one platform or use [\'__universal__\']',
9595
},
9696
schema: [],
9797
},
@@ -123,13 +123,13 @@ module.exports = {
123123

124124
return {
125125
ExportNamedDeclaration(node) {
126-
// Check for: export const __supportedPlatforms = [...]
126+
// Check for: export const __platforms = [...]
127127
if (node.declaration &&
128128
node.declaration.type === 'VariableDeclaration') {
129129

130130
for (const declarator of node.declaration.declarations) {
131131
if (declarator.id.type === 'Identifier' &&
132-
declarator.id.name === '__supportedPlatforms') {
132+
declarator.id.name === '__platforms') {
133133

134134
hasPlatformExport = true;
135135

@@ -199,7 +199,7 @@ module.exports = {
199199
},
200200

201201
'Program:exit'(node) {
202-
// At the end of the file, check if __supportedPlatforms was exported
202+
// At the end of the file, check if __platforms was exported
203203
if (!hasPlatformExport) {
204204
context.report({
205205
node,

lib/client_factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { InMemoryLruCache } from "./utils/cache/in_memory_lru_cache";
2929
import { transformCache, CacheWithRemove } from "./utils/cache/cache";
3030
import { ConstantBackoff } from "./utils/repeater/repeater";
3131

32-
export const __supportedPlatforms = ['__universal__'];
32+
export const __platforms = ['__universal__'];
3333

3434
export type OptimizelyFactoryConfig = Config & {
3535
requestHandler: RequestHandler;

lib/common_exports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
export const __supportedPlatforms = ['__universal__'];
17+
export const __platforms = ['__universal__'];
1818

1919
export { createStaticProjectConfigManager } from './project_config/config_manager_factory';
2020

lib/core/audience_evaluator/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { CONDITION_EVALUATOR_ERROR, UNKNOWN_CONDITION_TYPE } from 'error_message
2121
import { AUDIENCE_EVALUATION_RESULT, EVALUATING_AUDIENCE} from 'log_message';
2222
import { LoggerFacade } from '../../logging/logger';
2323

24-
export const __supportedPlatforms = ['__universal__'];
24+
export const __platforms = ['__universal__'];
2525

2626
export class AudienceEvaluator {
2727
private logger?: LoggerFacade;

lib/core/audience_evaluator/odp_segment_condition_evaluator/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { UNKNOWN_MATCH_TYPE } from 'error_message';
1717
import { LoggerFacade } from '../../../logging/logger';
1818
import { Condition, OptimizelyUserContext } from '../../../shared_types';
1919

20-
export const __supportedPlatforms = ['__universal__'];
20+
export const __platforms = ['__universal__'];
2121

2222
const QUALIFIED_MATCH_TYPE = 'qualified';
2323

lib/core/bucketer/bucket_value_generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import murmurhash from 'murmurhash';
1717
import { INVALID_BUCKETING_ID } from 'error_message';
1818
import { OptimizelyError } from '../../error/optimizly_error';
1919

20-
export const __supportedPlatforms = ['__universal__'];
20+
export const __platforms = ['__universal__'];
2121

2222
const HASH_SEED = 1;
2323
const MAX_HASH_VALUE = Math.pow(2, 32);

lib/core/bucketer/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { OptimizelyError } from '../../error/optimizly_error';
2929
import { generateBucketValue } from './bucket_value_generator';
3030
import { DecisionReason } from '../decision_service';
3131

32-
export const __supportedPlatforms = ['__universal__'];
32+
export const __platforms = ['__universal__'];
3333

3434
export const USER_NOT_IN_ANY_EXPERIMENT = 'User %s is not in any experiment of group %s.';
3535
export const USER_NOT_BUCKETED_INTO_EXPERIMENT_IN_GROUP = 'User %s is not in experiment %s of group %s.';

0 commit comments

Comments
 (0)