Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
560d111
feat(binding): keep engine state per session and swap it into the glo…
owjs3901 Nov 15, 2026
c5c0cfd
feat(binding): expose createSession, selectSession and dropSession
owjs3901 Nov 15, 2026
7f8b408
test(plugin-utils): count the three session exports in the compiler s…
owjs3901 Nov 15, 2026
0913645
test(binding): report the twenty validated functions in the summary
owjs3901 Nov 15, 2026
ad4c05f
feat(plugin-utils): add openCompilerSession for per-app engine state
owjs3901 Nov 15, 2026
10a91a5
feat(next-plugin): keep one coordinator and engine session per app
owjs3901 Nov 15, 2026
e4bfb3c
Merge main into feat/engine-sessions
owjs3901 Nov 15, 2026
b384718
Merge feat/engine-sessions into feat/engine-session-bindings
owjs3901 Nov 15, 2026
9a7e974
Merge feat/engine-session-bindings into feat/compiler-sessions
owjs3901 Nov 15, 2026
9fd4fed
Merge feat/compiler-sessions into feat/next-coordinator-registry
owjs3901 Nov 15, 2026
33cf39c
Merge main into feat/engine-session-bindings
owjs3901 Nov 17, 2026
c606179
Merge main into feat/compiler-sessions
owjs3901 Nov 17, 2026
ac17b10
Merge feat/engine-session-bindings into feat/compiler-sessions
owjs3901 Nov 17, 2026
4463dc4
Merge main into feat/next-coordinator-registry
owjs3901 Nov 17, 2026
8a50d97
Merge feat/compiler-sessions into feat/next-coordinator-registry
owjs3901 Nov 17, 2026
a090761
Merge main into feat/next-coordinator-registry
owjs3901 Nov 17, 2026
2e4ea8a
Merge main into feat/next-coordinator-registry
owjs3901 Nov 17, 2026
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
7 changes: 7 additions & 0 deletions .changepacks/changepack_log_compiler_sessions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"changes": {
"packages/plugin-utils/package.json": "Patch"
},
"note": "New `openCompilerSession(compiler)`: it opens an engine session of its own on a shared compiler and returns `{ id, compiler, close }`. Every function of the scoped `compiler` selects the session before it runs, so two apps in one process keep their numbering, sheet, theme and settings apart; `close()` drops the session",
"date": "2026-11-15T00:00:00.000Z"
}
8 changes: 8 additions & 0 deletions .changepacks/changepack_log_engine_sessions_bindings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"changes": {
"bindings/devup-ui-wasm/package.json": "Patch",
"bindings/devup-ui-binding/package.json": "Patch"
},
"note": "New `createSession()`, `selectSession(id)` and `dropSession(id)` exports on the WASM and native engines: a session is an engine state of its own (numbering, sheet, theme, settings and module resolver), and every call works on the selected one. Session 0 is selected from the start. `selectSession` and `dropSession` throw a `TypeError` for an id that is not an unsigned 32-bit integer, and an `Error` for an unknown session or for dropping session 0",
"date": "2026-11-15T00:00:00.000Z"
}
7 changes: 7 additions & 0 deletions .changepacks/changepack_log_next_coordinator_registry.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"changes": {
"packages/next-plugin/package.json": "Patch"
},
"note": "Turbopack apps in one process no longer share one coordinator: coordinators are kept per resolved `distDir`, each with its own engine session, extraction tracking and listener. Starting a second app no longer closes the first app's coordinator, and a config re-evaluation replaces only its own app's coordinator; the app's session is dropped when its last coordinator closes",
"date": "2026-11-15T00:00:00.000Z"
}
4 changes: 4 additions & 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,
dropSession: 'id:u',
getCss: 'file_num:n import_main_css:b',
getThemeInterface:
'package_name:s color_interface_name:s typography_interface_name:s length_interface_name:s shadows_interface_name:s theme_interface_name:s',
Expand All @@ -20,6 +21,7 @@ module.exports = function createBoundary() {
reserveClassSlots:
'rows:rows _package:s single_css:b import_main_css_in_code:b _import_main_css_in_css:b import_aliases:aliases',
seedFileMap: 'files:a',
selectSession: 'id:u',
setAtomHoist: 'threshold:n',
setDebug: 'debug:b',
setModuleResolver: 'resolver:f',
Expand All @@ -32,6 +34,7 @@ module.exports = function createBoundary() {
p: 'a string, null or undefined',
f: 'a function, null or undefined',
a: 'an array of strings',
u: 'a session id',
aliases: 'an alias mapping',
canonical: 'a canonical mapping',
class: 'a nested class-index mapping',
Expand All @@ -51,6 +54,7 @@ module.exports = function createBoundary() {
p: (value) => value == null || typeof value === 'string',
f: (value) => value == null || typeof value === 'function',
a: Array.isArray,
u: (value) => Number.isInteger(value) && value >= 0 && value <= 0xffffffff,
}
let frame
const fail = (slot) => {
Expand Down
4 changes: 2 additions & 2 deletions bindings/devup-ui-binding/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Synchronous native build-time compiler for Node.js and Bun. Both
`require('@devup-ui/binding')` and named ESM imports expose exactly the existing
30 compiler names, with identical function/class identities and no default init.
33 compiler names, with identical function/class identities and no default init.
Authored CommonJS/ESM declarations are included; no WASM dependency is required.

The private loader selects one optional platform sibling: Windows MSVC, macOS,
Expand Down Expand Up @@ -96,4 +96,4 @@ The decoder is private and target-bounded: unused Serde hints use trait forwardi

Malformed-enum error paths follow shipped serde-wasm-bindgen 0.6.5: Object.entries result length is read and coerced once for the check, then read and coerced again for the invalid-length diagnostic when the first length is not one, before any index read. The second value supplies the diagnostic; errors thrown by its getter or coercion propagate unchanged. Valid enums retain one length read.

The shared native/WASM boundary validates ordinary calls at 46 argument positions in 19 functions: malformed inputs throw a genuine `TypeError` naming the function, parameter and required type before state mutation. Preflight defaults the entire alias map on schema failure (after diagnostics) or a caught iterator-import failure whose `new Error(String(error))` conversion succeeds. Raw access failures and conversion faults escape unchanged before resolver selection; conversion runs once with the pending failure cleared, so reentry is isolated and resolver changes take effect before the outer core starts. Extraction and reservation remain strict. For example, `setPrefix(false)` throws `setPrefix(): argument prefix must be a string, null or undefined`; string/nullish prefixes remain supported. Extraction wrappers retain the measured metadata, receiver, extra-argument and apply/construct policy; `seedFileMap` validates and copies the caller's array before engine entry without rereading its indices. Same-revision Node/Bun identity, 272-case invalid-input, 73-exception preservation and seed-safety gates cover these contracts, not optimized shipping-native performance or real Node-host Linux Rust/authored-JS 100% coverage, which remain public-delivery gates.
The shared native/WASM boundary validates ordinary calls at 48 argument positions in 21 functions: malformed inputs throw a genuine `TypeError` naming the function, parameter and required type before state mutation. Preflight defaults the entire alias map on schema failure (after diagnostics) or a caught iterator-import failure whose `new Error(String(error))` conversion succeeds. Raw access failures and conversion faults escape unchanged before resolver selection; conversion runs once with the pending failure cleared, so reentry is isolated and resolver changes take effect before the outer core starts. Extraction and reservation remain strict. For example, `setPrefix(false)` throws `setPrefix(): argument prefix must be a string, null or undefined`; string/nullish prefixes remain supported. Extraction wrappers retain the measured metadata, receiver, extra-argument and apply/construct policy; `seedFileMap` validates and copies the caller's array before engine entry without rereading its indices. Same-revision Node/Bun identity, 288-case invalid-input, 73-exception preservation and seed-safety gates cover these contracts, not optimized shipping-native performance or real Node-host Linux Rust/authored-JS 100% coverage, which remain public-delivery gates.
3 changes: 3 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,
createSession: () => raw.createSession(),
dropSession: (id) => raw.dropSession(id),
exportCanonicalMap: raw.exportCanonicalMap,
exportClassMap: raw.exportClassMap,
exportFileMap: raw.exportFileMap,
Expand All @@ -108,6 +110,7 @@ exports.createBinding = function createBinding(raw) {
resetBuildState: () => raw.reset(false),
resetStateForTesting: () => raw.reset(true),
seedFileMap,
selectSession: (id) => raw.selectSession(id),
setAtomHoist: (value) => raw.setAtomHoist(index(value)),
setDebug: (value) => raw.setDebug(value),
setModuleResolver,
Expand Down
8 changes: 7 additions & 1 deletion bindings/devup-ui-binding/index.d.cts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class Output {
readonly updatedBaseStyle: boolean
}

// Positional signatures intentionally match the existing 30-name compiler ABI.
// Positional signatures intentionally match the existing 33-name compiler ABI.
export function codeExtract(
filename: string,
code: string,
Expand All @@ -32,6 +32,10 @@ export function codeExtractWithoutSourceMap(
importMainCssInCss: boolean,
importAliases: unknown,
): 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. */
export function dropSession(id: number): boolean
export function exportCanonicalMap(): string
export function exportClassMap(): string
export function exportFileMap(): string
Expand Down Expand Up @@ -78,6 +82,8 @@ export function reserveClassSlots(
export function resetBuildState(): void
export function resetStateForTesting(): void
export function seedFileMap(files: string[]): void
/** Make a session live: later calls work on its state until another is selected. */
export function selectSession(id: number): void
export function setAtomHoist(threshold?: number | null): void
export function setDebug(debug: boolean): void
export function setModuleResolver(
Expand Down
3 changes: 3 additions & 0 deletions bindings/devup-ui-binding/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export const {
Output,
codeExtract,
codeExtractWithoutSourceMap,
createSession,
dropSession,
exportCanonicalMap,
exportClassMap,
exportFileMap,
Expand All @@ -27,6 +29,7 @@ export const {
resetBuildState,
resetStateForTesting,
seedFileMap,
selectSession,
setAtomHoist,
setDebug,
setModuleResolver,
Expand Down
19 changes: 19 additions & 0 deletions bindings/devup-ui-binding/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,25 @@ pub fn reset(env: Env, full: bool) -> Result<()> {
}
Ok(())
}
/// Create an engine session with a clean state and return its id.
#[napi]
pub fn create_session() -> u32 {
core::create_session()
}
/// Make session `id` live until another is selected.
#[napi]
pub fn select_session(env: Env, id: u32) -> Result<()> {
core::select_session(id)
.map(drop)
.map_err(|error| binding_error(env, error))
}
/// Drop session `id` with its state and this environment's resolver for it.
#[napi]
pub fn drop_session(env: Env, id: u32) -> Result<bool> {
let dropped = core::drop_session(id).map_err(|error| binding_error(env, error))?;
state(&env)?.0.remove(id);
Ok(dropped)
}
fn with_resolver<T>(
env: Env,
diagnostics: core::ResolverState,
Expand Down
5 changes: 4 additions & 1 deletion bindings/devup-ui-binding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ mod host;
mod output;
mod value;

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

use de::Wasm32Index;
Expand Down
10 changes: 10 additions & 0 deletions bindings/devup-ui-wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ unwind. Binding tests compose these with sheet/resolver snapshots. Keep a named
guard on its creating thread and retain `#[serial]`: guards clean up but do not
serialize concurrent tests. Cleanup does not run for panic=abort.

## Sessions

`createSession()` returns the id of a new engine session with a clean state, and
`selectSession(id)` makes it live: every later call reads and changes that
session's state, resolver included, until another is selected. Session 0 is
live from the start, so a single app needs neither. Two apps in one process
each select their own session before each call. `dropSession(id)` forgets a
session (dropping the live one makes session 0 live), and the full test reset
forgets every session but 0.

## Errors

A source the build cannot compile makes `codeExtract` throw an `Error`. Its
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, 30)
assert.equal(new Set(names.map((match) => match[1])).size, 30)
assert.equal([...source.matchAll(/^exports\./gm)].length, 30)
assert.equal(names.length, 33)
assert.equal(new Set(names.map((match) => match[1])).size, 33)
assert.equal([...source.matchAll(/^exports\./gm)].length, 33)
assert.equal(source.includes('module.exports'), false)
for (const name of ['codeExtract', 'codeExtractWithoutSourceMap']) {
const signatures = [
Expand Down
53 changes: 53 additions & 0 deletions bindings/devup-ui-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,40 @@ pub fn seed_file_map(files: Vec<String>) {
binding_core::seed_file_map(&files);
}

/// Create an engine session with a clean state and return its id.
///
/// Two apps in one process each keep their own session: select it before
/// every call so the call reads and changes only that app's state. Session 0
/// is live until another is selected.
#[wasm_bindgen(js_name = "createSession")]
#[must_use]
pub fn create_session() -> u32 {
binding_core::create_session()
}

/// Make session `id` live: every later call works on its state until
/// another session is selected.
#[wasm_bindgen(js_name = "selectSession")]
#[cfg(not(tarpaulin_include))]
pub fn select_session(id: u32) -> Result<(), JsValue> {
binding_core::select_session(id).map(drop).map_err(js_error)
}

/// Drop session `id` with its state and resolver (testable without `JsValue`)
pub fn drop_session_internal(id: u32) -> Result<bool, String> {
let dropped = binding_core::drop_session(id)?;
MODULE_RESOLVER.with_borrow_mut(|resolvers| resolvers.remove(id));
Ok(dropped)
}

/// Drop session `id` with its state and module resolver, returning whether
/// it existed. Dropping the live session makes session 0 live.
#[wasm_bindgen(js_name = "dropSession")]
#[cfg(not(tarpaulin_include))]
pub fn drop_session(id: u32) -> Result<bool, JsValue> {
drop_session_internal(id).map_err(js_error)
}

/// Forget a source file that was deleted or renamed away.
///
/// Its global CSS, its own bucket and the class names handed out in it go,
Expand Down Expand Up @@ -1729,6 +1763,25 @@ mod tests {
assert!(json_str.starts_with('{') || json_str.starts_with("[]"));
}

#[test]
#[serial]
fn sessions_keep_their_own_prefix_until_dropped() {
let _state = TestStateGuard::new();
// Given: a second session with its own prefix
let session = create_session();
assert_eq!(binding_core::select_session(session), Ok(0));
set_prefix(Some("app-".into()));
// When / Then: session 0 keeps its own, and the dropped session goes
assert_eq!(binding_core::select_session(0), Ok(session));
assert_eq!(get_prefix(), None);
assert_eq!(
drop_session_internal(0),
Err("engine session 0 cannot be dropped".to_string())
);
assert_eq!(drop_session_internal(session), Ok(true));
assert_eq!(drop_session_internal(session), Ok(false));
}

#[test]
#[serial]
fn remove_file_reports_whether_the_sheet_changed() {
Expand Down
27 changes: 27 additions & 0 deletions e2e/binding/corpus/state.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,33 @@ add('reservation-malformed-second-row-arity-nonmutation', (h) => {
h.call('reserveClassSlots', value, pkg, false, false, false, {})
h.call('reserveClassSlots', rows, pkg, false, false, false, { bad: 7 })
})
add('sessions-keep-apart-until-dropped', (h) => {
h.call('setPrefix', 'zero-')
h.extract(source)
const session = h.call('createSession').value.value
h.call('selectSession', session)
h.call('registerTheme', theme)
h.extract(box('color="blue"'), { filename: 'src/second.tsx' })
h.call('selectSession', 0)
h.extract(source)
h.call('selectSession', 7)
h.call('dropSession', 0)
h.call('selectSession', session)
h.call('dropSession', session)
h.call('dropSession', session)
})
add('remove-file-stays-in-its-session', (h) => {
h.extract(source, { single: false })
const session = h.call('createSession').value.value
h.call('selectSession', session)
h.extract(box('color="blue"'), { single: false })
h.call('selectSession', 0)
h.call('removeFile', file)
h.call('removeFile', file)
h.call('selectSession', session)
h.call('removeFile', file)
h.call('dropSession', session)
})
add('remove-file-drops-its-own-styles', (h) => {
h.call('importCanonicalMap', { 'src/child.tsx': 'src/root.tsx' })
h.extract(source, { single: false })
Expand Down
6 changes: 3 additions & 3 deletions e2e/binding/host.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ save('provenance.json', {
scenarios: corpus.map((c) => c.name),
})
const names =
'Output codeExtract codeExtractWithoutSourceMap exportCanonicalMap exportClassMap exportFileMap exportSheet getCss getDefaultTheme getPrefix getThemeInterface getUnreservedClassSlotCount hasDevupUI importCanonicalMap importClassMap importFileMap importFileRoutes importSheet isDebug registerShorthands registerTheme removeFile reserveClassSlots resetBuildState resetStateForTesting seedFileMap setAtomHoist setDebug setModuleResolver setPrefix'.split(
'Output codeExtract codeExtractWithoutSourceMap createSession dropSession exportCanonicalMap exportClassMap exportFileMap exportSheet getCss getDefaultTheme getPrefix getThemeInterface getUnreservedClassSlotCount hasDevupUI importCanonicalMap importClassMap importFileMap importFileRoutes importSheet isDebug registerShorthands registerTheme removeFile reserveClassSlots resetBuildState resetStateForTesting seedFileMap selectSession setAtomHoist setDebug setModuleResolver setPrefix'.split(
' ',
)
const abi = {
Expand Down Expand Up @@ -199,8 +199,8 @@ const h = {
)
},
}
assert.equal(corpus.length, 26)
assert.equal(new Set(corpus.map((c) => c.name)).size, 26)
assert.equal(corpus.length, 28)
assert.equal(new Set(corpus.map((c) => c.name)).size, 28)
h.note('public-error-inventory', runDiagnostics(w))
for (const test of corpus) {
scenario = test.name
Expand Down
2 changes: 1 addition & 1 deletion e2e/binding/package/consumer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export async function consume(options) {
]
.map((match) => match[1])
.sort()
assert.equal(names.length, 30)
assert.equal(names.length, 33)
for (const manager of ['npm', 'bun']) {
for (const omit of [false, true]) {
const startRequest = server.requests.length
Expand Down
8 changes: 6 additions & 2 deletions e2e/binding/validation-cases.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const extractSlots =
export const positions = [
['codeExtract', extractSlots, extraction],
['codeExtractWithoutSourceMap', extractSlots, extraction],
['dropSession', 'id:session', () => [1]],
['getCss', 'file_num:n import_main_css:b', () => [null, false]],
[
'getThemeInterface',
Expand All @@ -45,6 +46,7 @@ export const positions = [
() => [[row], pkg, false, false, false, {}],
],
['seedFileMap', 'files:seed', () => [['src/new.tsx']]],
['selectSession', 'id:session', () => [0]],
['setAtomHoist', 'threshold:n', () => [2]],
['setDebug', 'debug:b', () => [true]],
['setModuleResolver', 'resolver:resolver', () => [null]],
Expand All @@ -62,6 +64,7 @@ const labels = {
prefix: 'a string, null or undefined',
resolver: 'a function, null or undefined',
seed: 'an array of strings',
session: 'a session id',
aliases: 'an alias mapping',
canonical: 'a canonical mapping',
class: 'a nested class-index mapping',
Expand All @@ -81,6 +84,7 @@ const invalid = {
b: [7, 'false', null, undefined],
n: ['2', false, 1n, Symbol('number'), {}],
prefix: [false, true, 7, {}],
session: ['1', false, -1, 1.5, 2 ** 32, null, undefined, {}],
resolver: [false, true, 7, 'callback', {}],
seed: [
...roots,
Expand Down Expand Up @@ -154,6 +158,6 @@ export const cases = positions.flatMap((position) =>
.map((good, index) => (index === position.index ? value : good)),
})),
)
assert.equal(positions.length, 46)
assert.equal(new Set(positions.map((p) => p.fn)).size, 19)
assert.equal(positions.length, 48)
assert.equal(new Set(positions.map((p) => p.fn)).size, 21)
assert.equal(new Set(cases.map((c) => c.id)).size, cases.length)
2 changes: 1 addition & 1 deletion e2e/binding/validation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ for (const [engine, entry] of [
const summary = {
cases: cases.length,
positions: positions.length,
functions: 18,
functions: 21,
engines: 2,
runs: runs.length,
failed: runs.filter((run) => run.failed).length,
Expand Down
7 changes: 5 additions & 2 deletions packages/next-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,11 @@ The build-time compiler defaults to `native` for Webpack and Turbopack. Select
WASM explicitly with `DevupUI(nextConfig, { engine: 'wasm' })`. The chosen engine
is retained by configuration, prewarm, extraction, CSS and delayed callbacks.
Turbopack loader options carry only the engine string; the coordinator retains
the selected physical compiler. Independent concurrent builds in one process
are unsupported.
the selected physical compiler. Turbopack apps in one process keep one
coordinator and one engine session per resolved `distDir`, so their numbering,
sheet, theme and settings stay apart; give each app its own `distDir`. A config
re-evaluation of the same app replaces only that app's coordinator. Independent
concurrent Webpack builds in one process are unsupported.

Native load failures identify the required platform package and retain the
original cause. There is no automatic fallback to WASM. Install optional native
Expand Down
Loading
Loading