Skip to content

Commit 525ba18

Browse files
committed
change runOn to return undefined instead of null. add @babel/parser as dep instead of dev dep
1 parent 8a9ae11 commit 525ba18

File tree

4 files changed

+34
-46
lines changed

4 files changed

+34
-46
lines changed

packages/springboard/cli/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
"test:watch": "vitest"
3535
},
3636
"dependencies": {
37+
"@babel/generator": "^7.28.5",
38+
"@babel/parser": "^7.28.5",
39+
"@babel/traverse": "^7.28.5",
3740
"commander": "catalog:",
3841
"concurrently": "^9.1.0",
3942
"esbuild": "catalog:",
@@ -50,9 +53,6 @@
5053
"author": "",
5154
"license": "ISC",
5255
"devDependencies": {
53-
"@babel/generator": "^7.28.5",
54-
"@babel/parser": "^7.28.5",
55-
"@babel/traverse": "^7.28.5",
5656
"@babel/types": "^7.28.5",
5757
"@types/babel__generator": "^7.27.0",
5858
"@types/babel__traverse": "^7.28.0"

packages/springboard/cli/src/esbuild_plugins/esbuild_plugin_platform_inject.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {SpringboardPlatform} from 'springboard/engine/register';
1212
*
1313
* **Responsibilities:**
1414
* 1. **Platform directive blocks** - Remove `@platform "..."` blocks for non-matching platforms
15-
* 2. **springboard.runOn()** - Transform to IIFE (if platform matches) or `null` (if doesn't match)
15+
* 2. **springboard.runOn()** - Transform to IIFE (if platform matches) or `undefined` (if doesn't match)
1616
* 3. **Server state removal** - Remove `createServerStates()` variable declarations in client builds
1717
* 4. **Server action stripping** - Strip bodies from `createServerActions()` in client builds
1818
*
@@ -25,7 +25,7 @@ import type {SpringboardPlatform} from 'springboard/engine/register';
2525
* | `cf-workers` | `'cf-workers'`, `'server'` |
2626
* | `web` | `'web'`, `'browser'`, `'client'`, `'user-agent'` |
2727
* | `tauri` | `'tauri'`, `'browser'`, `'client'`, `'user-agent'` |
28-
* | `react-native-web` | `'react-native-web'`, `'browser'`, `'client'` |
28+
* | `react-native-webview` | `'react-native-webview'`, `'browser'`, `'client'` |
2929
* | `react-native` | `'react-native'`, `'user-agent'` |
3030
*
3131
* @see packages/springboard/core/engine/register.ts - TypeScript type definitions
@@ -46,7 +46,7 @@ export const esbuildPluginPlatformInject = (
4646
return false;
4747
case 'web':
4848
case 'tauri':
49-
case 'react-native-web':
49+
case 'react-native-webview':
5050
case 'react-native':
5151
// Client platforms - strip server states/actions
5252
return true;
@@ -64,7 +64,7 @@ export const esbuildPluginPlatformInject = (
6464
let source = await fs.promises.readFile(args.path, 'utf8');
6565

6666
// Early return if file doesn't need any transformations
67-
const hasPlatformAnnotations = /@platform "(node|cf-workers|web|tauri|react-native|react-native-web|server|browser|client|user-agent)"/.test(source);
67+
const hasPlatformAnnotations = /@platform "(node|cf-workers|web|tauri|react-native|react-native-webview|server|browser|client|user-agent)"/.test(source);
6868
// Detect both old and new API patterns for server calls
6969
const hasServerCalls = /createServer(State|States|Action|Actions)/.test(source) ||
7070
/\.server\.createServer(States|Actions)/.test(source);
@@ -95,8 +95,8 @@ export const esbuildPluginPlatformInject = (
9595
targetPlatform === 'browser' ||
9696
targetPlatform === 'client' ||
9797
targetPlatform === 'user-agent';
98-
case 'react-native-web':
99-
return targetPlatform === 'react-native-web' ||
98+
case 'react-native-webview':
99+
return targetPlatform === 'react-native-webview' ||
100100
targetPlatform === 'browser' ||
101101
targetPlatform === 'client';
102102
case 'react-native':
@@ -170,9 +170,9 @@ export const esbuildPluginPlatformInject = (
170170
targetPlatform === 'browser' ||
171171
targetPlatform === 'client' ||
172172
targetPlatform === 'user-agent';
173-
case 'react-native-web':
174-
// react-native-web build accepts: 'react-native-web', 'browser' and context 'client'
175-
return targetPlatform === 'react-native-web' ||
173+
case 'react-native-webview':
174+
// react-native-webview build accepts: 'react-native-webview', 'browser' and context 'client'
175+
return targetPlatform === 'react-native-webview' ||
176176
targetPlatform === 'browser' ||
177177
targetPlatform === 'client';
178178
case 'react-native':
@@ -194,9 +194,10 @@ export const esbuildPluginPlatformInject = (
194194
arguments: [],
195195
} as any);
196196
} else {
197-
// Replace with null
197+
// Replace with undefined
198198
path.replaceWith({
199-
type: 'NullLiteral',
199+
type: 'Identifier',
200+
name: 'undefined',
200201
} as any);
201202
}
202203
}

packages/springboard/core/engine/register.ts

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export type SpringboardRegistry = {
4040
* | `web` | `'web'`, `'browser'`, `'client'`, `'user-agent'` |
4141
* | `tauri` | `'tauri'`, `'browser'`, `'client'`, `'user-agent'` |
4242
* | `browser` | `'browser'`, `'web'`, `'tauri'`, `'client'`, `'user-agent'` (meta-target) |
43-
* | `react-native-web` | `'react-native-web'`, `'browser'`, `'client'` |
43+
* | `react-native-webview` | `'react-native-webview'`, `'browser'`, `'client'` |
4444
* | `react-native` | `'react-native'`, `'user-agent'` |
4545
*
4646
* **Async Support:** Callbacks can be sync or async. Use `await` if the callback returns a Promise:
@@ -87,7 +87,7 @@ export type SpringboardRegistry = {
8787
runOn: <T>(
8888
platform: SpringboardPlatform | SpringboardPlatformContext,
8989
callback: () => T
90-
) => T | null;
90+
) => T | undefined;
9191

9292
/**
9393
* Check if the current runtime matches a platform or context at runtime.
@@ -107,7 +107,7 @@ export type SpringboardRegistry = {
107107
* | `cf-workers` | `'cf-workers'`, `'server'` |
108108
* | `web` | `'web'`, `'browser'`, `'client'`, `'user-agent'` |
109109
* | `tauri` | `'tauri'`, `'browser'`, `'client'`, `'user-agent'` |
110-
* | `react-native-webview` | `'browser'`, `'client'`
110+
* | `react-native-webviewview` | `'browser'`, `'client'`
111111
* | `react-native` | `'react-native'`, `'user-agent'` |
112112
*
113113
* **Implementation:** Transformed by platform macros in build plugin to return
@@ -177,35 +177,22 @@ export const getRegisteredSplashScreen = (): React.ComponentType | null => {
177177
};
178178

179179
/**
180-
* Runtime stub for `springboard.runOn()` - FOR DEVELOPMENT/FALLBACK ONLY.
181-
*
182-
* **Expected Behavior:**
183-
* This function should NEVER be called in production builds. The esbuild plugin
184-
* (`packages/springboard/cli/src/esbuild_plugins/esbuild_plugin_platform_inject.ts`)
185-
* transforms all `runOn` calls at compile time:
180+
* Runtime stub for `springboard.runOn()`
186181
*
187182
* - **Platform matches:** `runOn('node', cb)` → `cb()` (immediate execution)
188-
* - **Platform doesn't match:** `runOn('browser', cb)` → `null` (removed)
189-
*
190-
* **This stub:**
191-
* - Exists for TypeScript type checking and IDE autocomplete
192-
* - Provides fallback behavior in non-transformed environments (development, tests)
193-
* - Simply executes the callback immediately (simulating "platform matches" behavior)
183+
* - **Platform doesn't match:** `runOn('browser', cb)` → `undefined` (removed)
194184
*
195185
* **Platform parameter:**
196186
* Accepts either platform names (`'node'`, `'browser'`, etc.) or contexts (`'server'`, `'client'`, etc.).
197-
* The esbuild plugin (lines 97-118 of esbuild_plugin_platform_inject.ts) handles the platform
187+
* The esbuild plugin (esbuild_plugin_platform_inject.ts) handles the platform
198188
* matching logic based on the build target using a switch statement.
199189
*
200190
* @internal
201191
*/
202192
const runOn = <T>(
203-
platform: SpringboardPlatform | SpringboardPlatformContext,
193+
_platform: SpringboardPlatform | SpringboardPlatformContext,
204194
callback: () => T
205-
): T | null => {
206-
// Development/test fallback: execute callback immediately
207-
// In production, this code is replaced by the esbuild plugin transformation
208-
void platform; // Unused in runtime stub
195+
): T | undefined => {
209196
return callback();
210197
};
211198

@@ -224,7 +211,7 @@ const SPRINGBOARD_PLATFORMS = {
224211
WEB: 'web',
225212
TAURI: 'tauri',
226213
REACT_NATIVE: 'react-native',
227-
REACT_NATIVE_WEBVIEW: 'react-native-web',
214+
REACT_NATIVE_WEBVIEW: 'react-native-webview',
228215
} as const;
229216

230217
export type SpringboardPlatform = typeof SPRINGBOARD_PLATFORMS[keyof typeof SPRINGBOARD_PLATFORMS];
@@ -244,7 +231,7 @@ export type SpringboardPlatform = typeof SPRINGBOARD_PLATFORMS[keyof typeof SPRI
244231
* | `web` | `'web'`, `'browser'`, `'client'`, `'user-agent'` |
245232
* | `tauri` | `'tauri'`, `'browser'`, `'client'`, `'user-agent'` |
246233
* | `browser` | `'browser'`, `'web'`, `'tauri'`, `'client'`, `'user-agent'` (meta-target) |
247-
* | `react-native-web` | `'react-native-web'`, `'browser'`, `'client'` |
234+
* | `react-native-webview` | `'react-native-webview'`, `'browser'`, `'client'` |
248235
* | `react-native` | `'react-native'`, `'user-agent'` |
249236
*/
250237
const isPlatform = (platform: SpringboardPlatform | SpringboardPlatformContext): boolean => {

pnpm-lock.yaml

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)