Skip to content

Commit 246a9e9

Browse files
committed
update script readme
1 parent 2f93e2d commit 246a9e9

File tree

2 files changed

+47
-12
lines changed

2 files changed

+47
-12
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": "node scripts/validate-platform-isolation.js",
61-
"test-platform-isolation": "node scripts/test-validator.js",
61+
"test-isolation-rules": "node scripts/test-validator.js",
6262
"add-platform-exports": "node scripts/add-platform-exports.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: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
## validate-platform-isolation-ts.js
5+
## validate-platform-isolation.js
66

77
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).
88

@@ -12,7 +12,7 @@ The main platform isolation validator that ensures platform-specific code is pro
1212

1313
```bash
1414
# Run manually
15-
node scripts/validate-platform-isolation-ts.js
15+
node scripts/validate-platform-isolation.js
1616

1717
# Run via npm script
1818
npm run validate-platform-isolation
@@ -24,33 +24,68 @@ npm run build
2424
### How It Works
2525

2626
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
2929
3. **Validates platform values** by reading the Platform type definition from `platform_support.ts`
3030
4. Parses import statements (ES6 imports, require(), dynamic imports) using TypeScript AST
3131
5. **Validates import compatibility**: For each import, ensures the imported file supports ALL platforms that the importing file runs on
3232
6. Fails with exit code 1 if any violations are found, if `__platforms` export is missing, or if invalid platform values are used
3333

3434
**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.
3636
- Example: A browser file can import from universal files or any file that supports browser
3737

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

40-
### Exit Codes
4140

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__']`
4479

4580
## test-validator.js
4681

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

4984
### Usage
5085

5186
```bash
5287
# Run via npm script
53-
npm run test-platform-isolation
88+
npm run test-isolation-rules
5489

5590
# Or run directly
5691
node scripts/test-validator.js

0 commit comments

Comments
 (0)