Skip to content

feat(core): stronger types, iOS fixes, and opt-in hooks for cli extensions - #11682

Merged
NathanWalker merged 6 commits into
mainfrom
feat/core-stronger-types-and-hooks
Nov 28, 2026
Merged

NathanWalker merged 6 commits into
mainfrom
feat/core-stronger-types-and-hooks

Conversation

@NathanWalker

@NathanWalker NathanWalker commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What is the current behavior?

  1. Two vendored pure-JavaScript files that @nativescript/core imports directly (fetch/index.mjs and js-libs/easysax/easysax.js) only have minimal 4-line and 8-line hand-written .d.mts/.d.ts stubs, so their implementations are unchecked by TypeScript.
  2. Several core APIs declare types narrower or different from what actually runs at runtime (e.g., resolveModuleName returning null, CSS shorthand converters probed with unsetValue, PropertyBag storing converted longhand values, iOS CGPath helpers typed as UIBezierPath, _getFragmentManager walking ViewBase ancestors, NSURLSessionConfiguration created eagerly at module load).
  3. Four deprecated iOS APIs (dispatch_get_current_queue, base64Encoding, presentModalViewControllerAnimated, UITextAttributeTextColor) and four runtime bugs (TouchGestureEventData.getX/getY reading contentOffset on non-UIScrollView, generateShadowLayerPaths missing its box-shadow argument in animation.ios, Background.equals comparing backgrounds instead of gradient images, text-base.ios clearing shadowColor with a UIColor instead of CGColor) remain in core.
  4. ui/builder and ui/core/bindable have no opt-in registry hooks for ahead-of-time compiled XML page factories or binding expressions, and IConfigPlatform is not exported from config.interface.ts / index.d.ts for external CLI plugins to augment NativeScriptConfig cleanly.

What is the new behavior?

  1. refactor(core): convert vendored fetch and easysax to strict TypeScript (6 files, +1,270 −1,331 = net −61 lines, zero behavior change)
    • Replaces fetch/index.mjs (+ .d.mts) with fetch/index.ts and js-libs/easysax/easysax.js (+ .d.ts) with easysax.ts (MIT notices and LICENSE files preserved).
    • Pure strong-typing upgrade with no behavioral change under V8/JSC: verified against the original JS implementations over 216 fetch scenarios (headers, requests/responses of every body type, double-reads, status codes, network errors, aborts) and 49,724 easysax inputs with identical outputs/event logs. The only two micro-differences: fetch's bodyUsed is now an own property per body, and easysax's ParserEvent.prefix/namespace are typed string | undefined, matching what they already hold at runtime.
  2. fix(core): types that say what runs (9 files, +80 −57)
    • Accurate TypeScript types across module-name-resolver, ui/core/properties, ui/styling/style, ui/styling/background.ios, ui/core/view/index.android, utils/native-helper-for-android, xhr, and http/http-request-internal/index.ios (also defers NSURLSessionConfiguration creation to first request instead of module load, saving a few ms at iOS app launch).
  3. fix(core): deprecated iOS APIs and four bugs found by strict typing (8 files, +22 −20)
  4. feat(core): opt-in hooks for compiled XML pages and bindings (6 files, +133 −38)
    • Adds inert opt-in registries registerPageFactory (ui/builder) and registerCompiledBinding (ui/builder/binding-builder, ui/core/bindable). Nothing in core registers anything, so under V8 and JavaScriptCore both registries remain empty and Builder/Binding behave identically to today.
  5. feat(core): export IConfigPlatform for plugin config augmentation (2 files, +2 −2)
    • Exports IConfigPlatform alongside NativeScriptConfig in config/config.interface.ts and index.d.ts so external CLI plugins can cleanly augment NativeScriptConfig and per-platform ios/android config via TypeScript module augmentation without adding plugin-specific options to core. Types only.

Stronger type checking for two vendored JavaScript libraries core already
imports directly (`globals/index.ts` -> `fetch`, `xml/index.ts` -> `easysax`),
with zero behavior change under V8/JSC (net -61 lines).

- fetch/index.ts replaces fetch/index.mjs and its 4-line .d.mts: whatwg-fetch
  as typed classes over core's XMLHttpRequest, Blob, FileReader and FormData
  (MIT notice kept; LICENSE in the folder). Verified against the original over
  216 scenarios (headers, requests and responses of every body type, each body
  read twice, each status, network errors, aborts) with identical results. One
  micro-difference: `bodyUsed` is each body's own property. globals imports it
  without the extension.
- js-libs/easysax/easysax.ts replaces easysax.js and its 8-line .d.ts as a
  typed class with identical parsing, events, entities, namespaces and errors,
  verified against the original over 49,724 inputs and parser setups with
  identical event logs. xml/index.ts imports it without the extension, and
  ParserEvent's prefix and namespace are typed `string | undefined`, matching
  what they already hold at runtime for an element without a prefix.
The compiler type-checks core strictly and spells every type in Swift or
Kotlin, so a declared type must hold every value the code gives it. No
behaviour change, except where noted.

- module-name-resolver: resolveModuleName returns `string | null` (null when
  nothing resolves, which callers already test for).
- properties: shorthand converters take any value (getCssShorthandLonghands
  probes them with unsetValue); the style-symbol map holds CSS animation
  properties as well as CSS properties.
- style: PropertyBag holds converted longhand values as well as strings.
- background.ios: the clip-path helpers return a CGPath (UIBezierPath.CGPath),
  not the UIBezierPath they were declared to.
- view.android: _getFragmentManager walks ViewBase ancestors (a TabViewItem is
  one, and has fragments of its own) and reads _dialogFragment only on a View.
- native-helper-for-android: dismissSoftInput's modal owner is read untyped.
- xhr: XMLHttpRequestResponseType is a plain object (what the namespace
  compiled to); Blob's internal accessor is a named class.
- http-request-internal.ios: sessions are typed NSURLSession; the user agent
  and the session configuration are made on the first request instead of when
  the module loads (creating an NSURLSessionConfiguration costs a few
  milliseconds of every app's launch).
Compiling core to Swift rejects deprecated APIs and calls whose arguments do not
match; each of these is a fix under the JavaScript runtime too.

- image-source.ios: dispatch_get_current_queue (deprecated) gives way to the
  caller's operation queue, else main; base64Encoding to
  base64EncodedStringWithOptions(0).
- dialogs.ios: presentModalViewControllerAnimated to
  presentViewControllerAnimatedCompletion.
- tab-view.ios: UITextAttributeTextColor to NSForegroundColorAttributeName.
- gestures.ios: TouchGestureEventData.getX/getY read contentOffset only from a
  UIScrollView (other views have none).
- animation.ios: generateShadowLayerPaths takes the box shadow its layer draws;
  the animation called it without one (background.d.ts declares the parameter).
- background-common: Background.equals compared the backgrounds, never
  gradients, instead of their images: gradient images now compare by value.
- text-base.ios: clearing a text shadow sets a CGColor, not a UIColor, as the
  layer's shadowColor.
Two registries a compiled build fills; nothing in core registers anything, so
under V8 and JavaScriptCore both stay empty and the Builder behaves as before.

- Builder: registerPageFactory(xmlModule, factory, codeModule?, codeExports?)
  registers a function that builds an XML file's view tree instead of parsing
  it, and optionally the code-behind's exports, which the Builder then takes
  instead of loading the module. The module name resolver still picks the
  file, so qualified variants (.ios.xml, .land.xml) keep their own factories.
- Bindings: registerCompiledBinding(key, binding) registers an expression
  compiled ahead of time for the attribute at `file:line:column:attribute`;
  BindingOptions.compiled carries it, and Binding evaluates its closures in
  place of parsing the expression. The ComponentParser passes each element's
  key down (xmlModule, its start-tag position).
- The component builder holds whatever element it creates (ViewBase: an
  ActionItem, a Span), and a dotted attribute sets a member of any object, as
  the code already did; the types say so now.
- CompiledBinding is exported from ui.
Export `IConfigPlatform` alongside `NativeScriptConfig` from `config.interface.ts`
and `index.d.ts` so external CLI plugins (such as `@nstudio/nativescript-compiler`)
can cleanly augment `NativeScriptConfig` and per-platform `ios`/`android` config
via TypeScript module augmentation without adding plugin-specific options to core.
Types only.
@nx-cloud

nx-cloud Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 6a1f00f

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 2m 44s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

💡 With Ultracache enabled, Nx Cloud learns each task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-11-28 00:46:34 UTC

@pkg-pr-new

pkg-pr-new Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nativescript/core@11682
npm i https://pkg.pr.new/@nativescript/vite@11682
npm i https://pkg.pr.new/@nativescript/webpack@11682

commit: 6a1f00f

@NathanWalker NathanWalker changed the title feat(core): stronger types, iOS fixes, and opt-in hooks for native compilation feat(core): stronger types, iOS fixes, and opt-in hooks for cli extensions Nov 25, 2026
@NathanWalker NathanWalker added this to the 9.2 milestone Nov 25, 2026
@NathanWalker
NathanWalker marked this pull request as ready for review November 25, 2026 22:14
@NathanWalker
NathanWalker merged commit adbe443 into main Nov 28, 2026
13 checks passed
@NathanWalker
NathanWalker deleted the feat/core-stronger-types-and-hooks branch November 28, 2026 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant