|
2 | 2 |
|
3 | 3 | This directory contains build and validation scripts for the JavaScript SDK. |
4 | 4 |
|
| 5 | +## platform-validator.js |
| 6 | + |
| 7 | +Main entry point for platform isolation validation and fixing. Provides a unified CLI interface. |
| 8 | + |
| 9 | +### Usage |
| 10 | + |
| 11 | +```bash |
| 12 | +# Validate platform isolation (default) |
| 13 | +npm run validate-platform-isolation |
| 14 | +./scripts/platform-validator.js --validate |
| 15 | +./scripts/platform-validator.js # --validate is default |
| 16 | + |
| 17 | +# Fix platform export issues |
| 18 | +npm run fix-platform-export |
| 19 | +./scripts/platform-validator.js --fix-export |
| 20 | +``` |
| 21 | + |
| 22 | +**Note:** Cannot specify both `--validate` and `--fix-export` options at the same time. |
| 23 | + |
5 | 24 | ## validate-platform-isolation.js |
6 | 25 |
|
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). |
| 26 | +The 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 | 27 |
|
9 | 28 | **Configuration:** File patterns to include/exclude are configured in `.platform-isolation.config.js` at the workspace root. |
10 | 29 |
|
@@ -38,34 +57,40 @@ The script: |
38 | 57 | **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 | 58 |
|
40 | 59 |
|
41 | | -## add-platform-exports.js |
| 60 | +## fix-platform-export.js |
42 | 61 |
|
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. |
| 62 | +Auto-fix script that adds or updates `__platforms` exports in files. This script helps maintain platform isolation by automatically fixing issues with platform export declarations. |
| 63 | + |
| 64 | +**Important:** This script only fixes `__platforms` export issues. It does not fix import compatibility issues - those must be resolved manually. |
44 | 65 |
|
45 | 66 | ### Usage |
46 | 67 |
|
47 | 68 | ```bash |
48 | | -# Run via npm script |
49 | | -npm run add-platform-exports |
| 69 | +# Run via npm script (recommended) |
| 70 | +npm run fix-platform-export |
| 71 | + |
| 72 | +# Or via platform-validator |
| 73 | +./scripts/platform-validator.js --fix-export |
50 | 74 |
|
51 | 75 | # Or run directly |
52 | | -node scripts/add-platform-exports.js |
| 76 | +./scripts/fix-platform-export.js |
53 | 77 | ``` |
54 | 78 |
|
55 | 79 | ### How It Works |
56 | 80 |
|
57 | 81 | The script: |
58 | 82 | 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 |
| 83 | +2. **Ensures correct Platform import**: Normalizes all Platform imports to use the correct path and format |
| 84 | +3. For each file, checks if it has a valid `__platforms` export |
| 85 | +4. **Determines platform from filename**: Files with platform-specific naming (`.browser.ts`, `.node.ts`, `.react_native.ts`) get their specific platform(s) |
| 86 | +5. **Defaults to universal**: Files without platform-specific naming get `['__universal__']` |
63 | 87 | 6. **Moves export to end**: Places `__platforms` export at the end of the file for consistency |
64 | 88 | 7. Preserves existing platform values for files that already have valid `__platforms` exports |
65 | 89 |
|
66 | 90 | ### Actions |
67 | 91 |
|
68 | | -- **Fixed**: File had missing, invalid, or incorrectly formatted `__platforms` export - now corrected |
| 92 | +- **Added**: File was missing `__platforms` export - now added |
| 93 | +- **Fixed**: File had invalid or incorrectly formatted `__platforms` export - now corrected |
69 | 94 | - **Moved**: File had valid `__platforms` export but not at the end - moved to end |
70 | 95 | - **Skipped**: File already has valid `__platforms` export at the end |
71 | 96 |
|
|
0 commit comments