Skip to content

Commit 9d3deb5

Browse files
committed
upd
1 parent d319e41 commit 9d3deb5

File tree

4 files changed

+55
-24
lines changed

4 files changed

+55
-24
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"clean:win": "(if exist dist rd /s/q dist)",
5959
"lint": "tsc --noEmit && eslint 'lib/**/*.js' 'lib/**/*.ts'",
6060
"validate-platform-isolation": "./scripts/platform-validator.js --validate",
61-
"fix-platform-isolation": "./scripts/platform-validator.js --fix",
61+
"fix-platform-export": "./scripts/platform-validator.js --fix-export",
6262
"test-isolation-rules": "./scripts/test-validator.js",
6363
"test-vitest": "vitest run",
6464
"test-mocha": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register -r tsconfig-paths/register -r lib/tests/exit_on_unhandled_rejection.js 'lib/**/*.tests.ts' 'lib/**/*.tests.js'",

scripts/README.md

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,28 @@
22

33
This directory contains build and validation scripts for the JavaScript SDK.
44

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+
524
## validate-platform-isolation.js
625

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).
827

928
**Configuration:** File patterns to include/exclude are configured in `.platform-isolation.config.js` at the workspace root.
1029

@@ -38,34 +57,40 @@ The script:
3857
**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.
3958

4059

41-
## add-platform-exports.js
60+
## fix-platform-export.js
4261

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.
4465

4566
### Usage
4667

4768
```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
5074

5175
# Or run directly
52-
node scripts/add-platform-exports.js
76+
./scripts/fix-platform-export.js
5377
```
5478

5579
### How It Works
5680

5781
The script:
5882
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__']`
6387
6. **Moves export to end**: Places `__platforms` export at the end of the file for consistency
6488
7. Preserves existing platform values for files that already have valid `__platforms` exports
6589

6690
### Actions
6791

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
6994
- **Moved**: File had valid `__platforms` export but not at the end - moved to end
7095
- **Skipped**: File already has valid `__platforms` export at the end
7196

scripts/add-platform-exports.js renamed to scripts/fix-platform-export.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,21 @@
1717
*/
1818

1919
/**
20-
* Auto-add __platforms to files
20+
* Fix platform export issues
2121
*
22-
* This script automatically adds __platforms export to files that don't have it.
23-
* Uses TypeScript parser to analyze files and add proper type annotations.
22+
* This script automatically fixes __platforms export issues in files:
23+
* - Adds missing __platforms exports
24+
* - Fixes invalid __platforms declarations
25+
* - Moves __platforms to end of file
26+
* - Ensures correct Platform import
27+
*
28+
* Note: This only fixes __platforms export issues. Import compatibility issues
29+
* must be resolved manually.
2430
*
2531
* Strategy:
2632
* 1. Files with platform-specific naming (.browser.ts, .node.ts, .react_native.ts) get their specific platform(s)
2733
* 2. All other files are assumed to be universal and get ['__universal__']
28-
* 3. Adds Platform type import and type annotation
34+
* 3. Adds Platform import and type annotation
2935
* 4. Inserts __platforms export at the end of the file
3036
*/
3137

scripts/platform-validator.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
* Provides a unified interface for validating and fixing platform isolation issues.
2323
*
2424
* Usage:
25-
* node platform-validator.js --validate # Validate platform isolation (default)
26-
* node platform-validator.js --fix # Fix platform isolation issues
25+
* node platform-validator.js --validate # Validate platform isolation (default)
26+
* node platform-validator.js --fix-export # Fix platform export issues
2727
*/
2828

2929
/* eslint-disable @typescript-eslint/no-var-requires */
@@ -33,21 +33,21 @@ function main() {
3333
const args = process.argv.slice(2);
3434

3535
const hasValidate = args.includes('--validate');
36-
const hasFix = args.includes('--fix');
36+
const hasFixExport = args.includes('--fix-export');
3737

3838
// Check if both options are provided
39-
if (hasValidate && hasFix) {
40-
console.error('❌ Error: Cannot specify both --validate and --fix options');
39+
if (hasValidate && hasFixExport) {
40+
console.error('❌ Error: Cannot specify both --validate and --fix-export options');
4141
process.exit(1);
4242
}
4343

4444
// Determine which script to run (default to validate)
45-
const shouldFix = hasFix;
45+
const shouldFix = hasFixExport;
4646

4747
try {
4848
if (shouldFix) {
49-
console.log('🔧 Running platform isolation fix...\n');
50-
execSync('node scripts/add-platform-exports.js', { stdio: 'inherit' });
49+
console.log('🔧 Fixing platform export issues...\n');
50+
execSync('node scripts/fix-platform-export.js', { stdio: 'inherit' });
5151
} else {
5252
console.log('🔍 Running platform isolation validation...\n');
5353
execSync('node scripts/validate-platform-isolation.js', { stdio: 'inherit' });

0 commit comments

Comments
 (0)