You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: scripts/README.md
+46-11Lines changed: 46 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
This directory contains build and validation scripts for the JavaScript SDK.
4
4
5
-
## validate-platform-isolation-ts.js
5
+
## validate-platform-isolation.js
6
6
7
7
The main platform isolation validator that ensures platform-specific code is properly isolated to prevent runtime errors when building for different platforms (Browser, Node.js, React Native).
8
8
@@ -12,7 +12,7 @@ The main platform isolation validator that ensures platform-specific code is pro
12
12
13
13
```bash
14
14
# Run manually
15
-
node scripts/validate-platform-isolation-ts.js
15
+
node scripts/validate-platform-isolation.js
16
16
17
17
# Run via npm script
18
18
npm run validate-platform-isolation
@@ -24,33 +24,68 @@ npm run build
24
24
### How It Works
25
25
26
26
The script:
27
-
1. Scans all TypeScript/JavaScript files in the `lib/` directory
28
-
2.**Requires every non-test file to export `__platforms` array** declaring supported platforms
27
+
1. Scans all TypeScript/JavaScript files configured in the in the `.platform-isolation.config.js` config file.
28
+
2.**Requires every file to export `__platforms` array** declaring supported platforms
29
29
3.**Validates platform values** by reading the Platform type definition from `platform_support.ts`
5.**Validates import compatibility**: For each import, ensures the imported file supports ALL platforms that the importing file runs on
32
32
6. Fails with exit code 1 if any violations are found, if `__platforms` export is missing, or if invalid platform values are used
33
33
34
34
**Import Rule**: When file A imports file B, file B must support ALL platforms that file A runs on.
35
-
- Example: A universal file can only import from universal files (or files supporting all platforms)
35
+
- Example: A universal file can only import from universal files.
36
36
- Example: A browser file can import from universal files or any file that supports browser
37
37
38
-
**Note:** The validator can theoretically support file naming conventions (`.browser.ts`, etc.) in addition to `__platforms` exports, but currently enforces only the `__platforms` export. File naming is not validated and is considered redundant.
38
+
**Note:** The validator can be updated to support file naming conventions (`.browser.ts`, etc.) in addition to `__platforms` exports, but currently enforces only the `__platforms` export. File naming is not validated and is used for convenience.
39
39
40
-
### Exit Codes
41
40
42
-
-`0`: All platform-specific files are properly isolated
43
-
-`1`: Violations found or script error
41
+
## add-platform-exports.js
42
+
43
+
Auto-fix script that adds or updates `__platforms` exports in files. This script helps maintain platform isolation by automatically adding the required `__platforms` export to files that are missing it or have invalid exports.
44
+
45
+
### Usage
46
+
47
+
```bash
48
+
# Run via npm script
49
+
npm run add-platform-exports
50
+
51
+
# Or run directly
52
+
node scripts/add-platform-exports.js
53
+
```
54
+
55
+
### How It Works
56
+
57
+
The script:
58
+
1. Scans all TypeScript/JavaScript files configured in `.platform-isolation.config.js`
59
+
2. For each file, checks if it has a valid `__platforms` export
60
+
3.**Determines platform from filename**: Files with platform-specific naming (`.browser.ts`, `.node.ts`, `.react_native.ts`) get their specific platform(s)
61
+
4.**Defaults to universal**: Files without platform-specific naming get `['__universal__']`
62
+
5.**Adds Platform type import**: Calculates correct relative path and ensures `import type { Platform } from '../path/to/platform_support'` exists
63
+
6.**Moves export to end**: Places `__platforms` export at the end of the file for consistency
64
+
7. Preserves existing platform values for files that already have valid `__platforms` exports
65
+
66
+
### Actions
67
+
68
+
-**Fixed**: File had missing, invalid, or incorrectly formatted `__platforms` export - now corrected
69
+
-**Moved**: File had valid `__platforms` export but not at the end - moved to end
70
+
-**Skipped**: File already has valid `__platforms` export at the end
71
+
72
+
### Platform Detection
73
+
74
+
-`file.browser.ts` → `['browser']`
75
+
-`file.node.ts` → `['node']`
76
+
-`file.react_native.ts` → `['react_native']`
77
+
-`file.browser.node.ts` → `['browser', 'node']`
78
+
-`file.ts` → `['__universal__']`
44
79
45
80
## test-validator.js
46
81
47
-
Comprehensive test suite for the platform isolation validator. Documents and validates all compatibility rules.
82
+
Comprehensive test suite for the platform isolation rules. Documents and validates all compatibility rules.
0 commit comments