Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions .changepacks/changepack_log_react_native_core.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"changes": {
"bindings/devup-ui-binding/package.json": "Patch",
"bindings/devup-ui-wasm/package.json": "Patch"
},
"note": "Add `codeExtractNative(filename, code, packageName, platform, runtime)` to both engines (part of #411). It compiles a file for React Native: Devup UI elements imported from `@devup-ui/react` become React Native components (`Box` → `View`, `Text` → `Text`, `Image` → `Image`, `Input` → `TextInput`, `Button` → `Pressable`, `Flex`/`VStack`/`Center` → `View` with their flex styles), and their style props become style objects hoisted into one `StyleSheet.create` per file and passed through `style`. `_ios`, `_android` and `_web` resolve at build time from `platform`. A style React Native cannot take is a build error naming the prop, as are responsive values, themes and `_pressed`, which need a runtime this release does not include. A value read at runtime converts as a literal does, through a function the file declares: numbers take the scale of the property (four pixels a unit for lengths), `px` strings become numbers and `rem`/`em` strings pixels. Web output is unchanged.",
"date": "2026-11-19T00:00:00.000Z"
}
1 change: 1 addition & 0 deletions bindings/argument-validation.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = function createBoundary() {
const descriptors = {
codeExtract: extraction,
codeExtractWithoutSourceMap: extraction,
codeExtractNative: 'filename:s code:s _package:s platform:s runtime:b',
dropSession: 'id:u',
getCss: 'file_num:n import_main_css:b',
getThemeInterface:
Expand Down
2 changes: 2 additions & 0 deletions bindings/devup-ui-binding/adapter.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ exports.createBinding = function createBinding(raw) {
Output: raw.Output,
codeExtract,
codeExtractWithoutSourceMap,
codeExtractNative: (filename, code, pkg, platform, runtime) =>
raw.extractNative(filename, code, pkg, platform, runtime),
createSession: () => raw.createSession(),
dropSession: (id) => raw.dropSession(id),
exportCanonicalMap: raw.exportCanonicalMap,
Expand Down
13 changes: 13 additions & 0 deletions bindings/devup-ui-binding/index.d.cts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ export function codeExtractWithoutSourceMap(
importMainCssInCss: boolean,
importAliases: unknown,
): Output
/**
* Compile a source for React Native on `platform`: Devup UI elements become
* React Native components whose styles are hoisted into one
* `StyleSheet.create`. No CSS is emitted (`css` and `cssFile` are undefined);
* `runtime: false` makes what needs the React Native runtime a build error.
*/
export function codeExtractNative(
filename: string,
code: string,
packageName: string,
platform: 'ios' | 'android' | 'web',
runtime: boolean,
): Output
/** Create an engine session with a clean state; select it before each call. */
export function createSession(): number
/** Drop a session and its state; dropping the live one makes session 0 live. */
Expand Down
1 change: 1 addition & 0 deletions bindings/devup-ui-binding/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const {
Output,
codeExtract,
codeExtractWithoutSourceMap,
codeExtractNative,
createSession,
dropSession,
exportCanonicalMap,
Expand Down
15 changes: 15 additions & 0 deletions bindings/devup-ui-binding/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ pub fn extract<'env>(
single_css: arg(&request, 4)?,
import_main_css: arg(&request, 5)?,
import_aliases: aliases(decode(arg(&request, 7)?, &access, 7)?),
..Default::default()
};
let import_main_css_in_css = arg(&request, 6)?;
let source_map = if arg(&request, 8)? {
Expand Down Expand Up @@ -277,3 +278,17 @@ pub fn reserve<'env>(
))
})
}
/// Compile a source for React Native on a platform: its code and source map, no CSS.
#[napi]
pub fn extract_native(
env: Env,
filename: String,
code: String,
package: String,
platform: String,
runtime: bool,
) -> Result<NativeOutput> {
core::code_extract_native((&filename, &code), &package, &platform, runtime)
.map(|output| NativeOutput(Some(output)))
.map_err(|error| binding_error(env, error))
}
4 changes: 2 additions & 2 deletions bindings/devup-ui-binding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ mod output;
mod value;

pub use host::{
Resolved, create_session, drop_session, extract, has_devup_ui, init, reserve, reset,
select_session, set_resolver,
Resolved, create_session, drop_session, extract, extract_native, has_devup_ui, init, reserve,
reset, select_session, set_resolver,
};
pub use output::NativeOutput;

Expand Down
1 change: 1 addition & 0 deletions bindings/devup-ui-wasm/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Rust → WebAssembly → JavaScript bridge. Exposes extraction engine to build p

### Core Functions
- `codeExtract(filename, code, pkg, cssDir, singleCss, importMainCss, importCssInCss)` → Output
- `codeExtractNative(filename, code, pkg, platform, runtime)` → Output (React Native: `StyleSheet.create` styles, no CSS)
- `hasDevupUI(filename, code, package)` → boolean
- `getCss(fileNum?, importMainCss)` → string

Expand Down
33 changes: 17 additions & 16 deletions bindings/devup-ui-wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,23 @@ repository root fails if one does.

Everything is exported from `pkg/index.js` (types in `pkg/index.d.ts`).

| Function | Does |
| ----------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `codeExtract(filename, code, package, cssDir, singleCss, importMainCssInCode, importMainCssInCss, importAliases)` | Compiles one source file and returns an `Output`: the rewritten `code`, its `css`, `cssFile`, source `map`, the `dependencies` it read and `updatedBaseStyle`. Throws on a build error. |
| `codeExtractWithoutSourceMap(...)` | The same without the source map. |
| `hasDevupUI(filename, code, package)` | Whether the file imports Devup UI, so a plugin can skip the rest. |
| `getCss(fileNum, importMainCss)` | The stylesheet collected so far: the whole sheet for `null`, one file's for its number. |
| `removeFile(filename)` | Forgets a deleted source file: its global CSS, its own stylesheet and the class names handed out in it. Returns whether the sheet changed. |
| `registerTheme(theme)`, `registerShorthands(shorthands)` | Registers the `devup.json` theme and the custom shorthand props before extracting. |
| `getThemeInterface(package, color, typography, length, shadows, theme)` | The `.d.ts` text that types the registered theme. |
| `getDefaultTheme()` | The theme variant that applies without `data-theme`. |
| `setPrefix(prefix)`, `getPrefix()` | Class name prefix. |
| `setDebug(debug)`, `isDebug()` | Readable class names instead of base-37 ones, with repeated declarations kept (the tests run this way). |
| `setLicenseBanner(enabled)`, `isLicenseBanner()` | Whether every stylesheet starts with the `/*! devup-ui v… */` license banner. On by default. A stylesheet without any rule is emitted empty either way. |
| `setModuleResolver(resolver)` | `(specifier, importer) => ({ path, code })`: how imports are resolved, so imported stylesheets are evaluated and imported constants inlined. |
| `setAtomHoist(threshold)`, `importFileRoutes(routes)` | Moves atoms used by `threshold` routes or more into the shared sheet. Call before `codeExtract`. |
| `exportSheet`, `exportClassMap`, `exportFileMap`, `exportCanonicalMap` and the matching `import*` functions | Save the collected state and load it into another process, as a bundler does between its server and client builds. |
| Function | Does |
| ----------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `codeExtract(filename, code, package, cssDir, singleCss, importMainCssInCode, importMainCssInCss, importAliases)` | Compiles one source file and returns an `Output`: the rewritten `code`, its `css`, `cssFile`, source `map`, the `dependencies` it read and `updatedBaseStyle`. Throws on a build error. |
| `codeExtractWithoutSourceMap(...)` | The same without the source map. |
| `codeExtractNative(filename, code, package, platform, runtime)` | Compiles one source file for React Native on `platform` (`ios`, `android` or `web`): Devup UI elements become React Native components, their styles one `StyleSheet.create` passed through `style`. The `Output` has the `code` and its `map`, but no `css`. A style React Native cannot take is a build error; `runtime: false` also makes responsive values, themes and `_pressed` build errors. |
| `hasDevupUI(filename, code, package)` | Whether the file imports Devup UI, so a plugin can skip the rest. |
| `getCss(fileNum, importMainCss)` | The stylesheet collected so far: the whole sheet for `null`, one file's for its number. |
| `removeFile(filename)` | Forgets a deleted source file: its global CSS, its own stylesheet and the class names handed out in it. Returns whether the sheet changed. |
| `registerTheme(theme)`, `registerShorthands(shorthands)` | Registers the `devup.json` theme and the custom shorthand props before extracting. |
| `getThemeInterface(package, color, typography, length, shadows, theme)` | The `.d.ts` text that types the registered theme. |
| `getDefaultTheme()` | The theme variant that applies without `data-theme`. |
| `setPrefix(prefix)`, `getPrefix()` | Class name prefix. |
| `setDebug(debug)`, `isDebug()` | Readable class names instead of base-37 ones, with repeated declarations kept (the tests run this way). |
| `setLicenseBanner(enabled)`, `isLicenseBanner()` | Whether every stylesheet starts with the `/*! devup-ui v… */` license banner. On by default. A stylesheet without any rule is emitted empty either way. |
| `setModuleResolver(resolver)` | `(specifier, importer) => ({ path, code })`: how imports are resolved, so imported stylesheets are evaluated and imported constants inlined. |
| `setAtomHoist(threshold)`, `importFileRoutes(routes)` | Moves atoms used by `threshold` routes or more into the shared sheet. Call before `codeExtract`. |
| `exportSheet`, `exportClassMap`, `exportFileMap`, `exportCanonicalMap` and the matching `import*` functions | Save the collected state and load it into another process, as a bundler does between its server and client builds. |

## State

Expand Down
6 changes: 3 additions & 3 deletions bindings/devup-ui-wasm/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ types = types.replace(hookType, '')
assert.equal(types.includes('install_panic_hook'), false)
writeFileSync('pkg/index.d.ts', types, 'utf8')
const names = [...source.matchAll(/^exports\.(\w+) = \1;/gm)]
assert.equal(names.length, 36)
assert.equal(new Set(names.map((match) => match[1])).size, 36)
assert.equal([...source.matchAll(/^exports\./gm)].length, 36)
assert.equal(names.length, 37)
assert.equal(new Set(names.map((match) => match[1])).size, 37)
assert.equal([...source.matchAll(/^exports\./gm)].length, 37)
assert.equal(source.includes('module.exports'), false)
for (const name of ['codeExtract', 'codeExtractWithoutSourceMap']) {
const signatures = [
Expand Down
Loading
Loading