Skip to content
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
bfcb365
init
raju-opti Nov 24, 2025
96e1b80
multi platform
raju-opti Nov 24, 2025
3759938
mandatory export
raju-opti Nov 24, 2025
965b073
use ts parser
raju-opti Nov 24, 2025
87fcd5d
add eslint rule for platform export
raju-opti Nov 24, 2025
7729865
eslint rule update
raju-opti Nov 24, 2025
4bc72f7
use __platform
raju-opti Nov 25, 2025
a12858d
doc updates
raju-opti Nov 25, 2025
cc266fe
update validation
raju-opti Nov 25, 2025
ff034eb
declraration
raju-opti Nov 25, 2025
dc0927f
const check
raju-opti Nov 25, 2025
fed9c58
readme
raju-opti Nov 25, 2025
ea9e33b
dry up
raju-opti Nov 25, 2025
954980d
eslint config
raju-opti Nov 25, 2025
7dd1406
update add export script
raju-opti Nov 25, 2025
2a3342f
fix failed validations
raju-opti Nov 25, 2025
37b368e
update file matching
raju-opti Nov 25, 2025
2faebf6
update
raju-opti Nov 25, 2025
cfa67a0
update
raju-opti Nov 25, 2025
c772ab9
update platform_support file
raju-opti Nov 25, 2025
fde779c
updates
raju-opti Nov 25, 2025
bdb7f25
fix add platform script
raju-opti Nov 26, 2025
65f1607
remove const declaration requirement
raju-opti Nov 26, 2025
1a9203f
updates in platform-utils
raju-opti Nov 26, 2025
70aa9a7
refactor validator
raju-opti Nov 27, 2025
17ffe48
update module resolution
raju-opti Nov 27, 2025
a6617e8
dry
raju-opti Nov 27, 2025
901cc4a
update platform extraction from file name
raju-opti Nov 27, 2025
2f93e2d
finalize scripts
raju-opti Nov 28, 2025
246a9e9
update script readme
raju-opti Nov 28, 2025
99f710b
lint doc updates
raju-opti Nov 28, 2025
c4ffd43
refactor eslint rule
raju-opti Nov 28, 2025
94cbeec
update doc
raju-opti Nov 28, 2025
823e2c1
copilot review updates
raju-opti Dec 1, 2025
a6b69fd
update add script
raju-opti Dec 1, 2025
c7be4d4
rm
raju-opti Dec 1, 2025
b62aad8
fix imports
raju-opti Dec 2, 2025
81527c7
updates
raju-opti Dec 2, 2025
d319e41
update scripts
raju-opti Dec 2, 2025
9d3deb5
upd
raju-opti Dec 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module.exports = {
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'local-rules'],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
Expand All @@ -25,6 +27,23 @@ module.exports = {
'rules': {
'@typescript-eslint/explicit-module-boundary-types': ['error']
}
},
{
'files': ['lib/**/*.ts', 'src/**/*.ts'],
'excludedFiles': [
'**/platform_support.ts',
'**/*.spec.ts',
'**/*.test.ts',
'**/*.tests.ts',
'**/*.test-d.ts',
'**/*.gen.ts',
'**/*.d.ts',
'**/__mocks__/**',
'**/tests/**'
],
'rules': {
'local-rules/require-platform-declaration': 'error',
}
}
],
rules: {
Expand Down
39 changes: 39 additions & 0 deletions .platform-isolation.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Platform Isolation Configuration
*
* Configures which files should be validated by the platform isolation validator.
*/

module.exports = {
// Base directories to scan for source files
include: [
'lib/**/*.ts',
'lib/**/*.js'
],

// Files and patterns to exclude from validation
exclude: [
// Platform definition file (this file defines Platform type, doesn't need __platforms)
'**/platform_support.ts',

// Test files
'**/*.spec.ts',
'**/*.test.ts',
'**/*.tests.ts',
'**/*.test.js',
'**/*.spec.js',
'**/*.tests.js',
'**/*.umdtests.js',
'**/*.test-d.ts',

// Generated files
'**/*.gen.ts',

// Type declaration files
'**/*.d.ts',

// Test directories and mocks
'**/__mocks__/**',
'**/tests/**'
]
};
84 changes: 84 additions & 0 deletions ESLINT_TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# ESLint Rule Troubleshooting

## The Rule is Working!

The `require-platform-declaration` rule **is** working correctly from the command line:

```bash
$ npx eslint lib/core/custom_attribute_condition_evaluator/index.ts

lib/core/custom_attribute_condition_evaluator/index.ts
16:1 error File must export __platforms to declare which platforms
it supports. Example: export const __platforms = ['__universal__'] as const;
```

## VSCode Not Showing Errors?

If VSCode isn't showing the ESLint errors, try these steps:

### 1. Restart ESLint Server
- Open Command Palette: `Cmd+Shift+P` (Mac) or `Ctrl+Shift+P` (Windows/Linux)
- Type: `ESLint: Restart ESLint Server`
- Press Enter

### 2. Check ESLint Extension is Installed
- Open Extensions panel: `Cmd+Shift+X` (Mac) or `Ctrl+Shift+X` (Windows/Linux)
- Search for "ESLint" by Microsoft
- Make sure it's installed and enabled

### 3. Check ESLint Output
- Open Output panel: `Cmd+Shift+U` (Mac) or `Ctrl+Shift+U` (Windows/Linux)
- Select "ESLint" from the dropdown
- Look for any error messages

### 4. Reload VSCode Window
- Open Command Palette: `Cmd+Shift+P` (Mac) or `Ctrl+Shift+P` (Windows/Linux)
- Type: `Developer: Reload Window`
- Press Enter

### 5. Check File is Being Linted
The rule only applies to:
- ✅ Files in `lib/` or `src/` directory
- ✅ TypeScript files (`.ts`)
- ❌ Test files (`.spec.ts`, `.test.ts`, etc.)
- ❌ Declaration files (`.d.ts`)

### 6. Verify ESLint Configuration
Check that `.eslintrc.js` has the parser set:
```javascript
parser: '@typescript-eslint/parser',
```

And that the rule is in the overrides:
```javascript
overrides: [{
files: ['*.ts', '!*.spec.ts', '!*.test.ts', '!*.tests.ts', '!*.test-d.ts'],
rules: {
'local-rules/require-platform-declaration': 'error',
}
}]
```

## Manual Verification

You can always verify the rule works by running:

```bash
# Check a specific file
npx eslint lib/service.ts

# Check all lib files (shows only errors)
npx eslint lib/**/*.ts --quiet
```

## Adding __platforms

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

```typescript
// Universal file (all platforms)
export const __platforms = ['__universal__'] as const;

// OR platform-specific file
export const __platforms = ['browser', 'node'] as const;
```
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@ If you're updating your SDK version, please check the appropriate migration guid

## SDK Development

### Platform Isolation

The SDK supports multiple JavaScript platforms (Browser, Node.js, React Native) with a unified codebase. To prevent runtime errors from platform-specific code being bundled incorrectly, we enforce **platform isolation** constraints:

- Every source file must declare which platforms it supports using `export const __platforms: Platform[] = [...]`
- Files can only import from other files that support all their declared platforms
- Universal files (`__platforms = ['__universal__']`) work everywhere but can only import from other universal files

This system is enforced at build time through ESLint rules and validation scripts, ensuring platform-specific code (like browser DOM APIs or Node.js `fs` module) never leaks into incompatible builds.

**For detailed documentation**, see [docs/PLATFORM_ISOLATION.md](docs/PLATFORM_ISOLATION.md).

### Unit Tests

There is a mix of testing paradigms used within the JavaScript SDK which include Mocha, Chai, Karma, and Vitest, indicated by their respective `*.tests.js` and `*.spec.ts` filenames.
Expand Down
Loading
Loading