fix(vite): shim package roots whose export * targets another bundled package - #11426
sitefinitysteve wants to merge 1 commit into
Conversation
|
View your CI Pipeline Execution ↗ for commit c21a9f2
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
|
View your CI Pipeline Execution ↗ for commit c21a9f2
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
commit: |
|
@NathanWalker Looks like we crossed lol NativeScript/NativeScript#11427 happy to close this in favour of it. One thought from this branch in case it's useful... instead of re-resolving the bare target from the importer, I recorded the original -> path edges esbuild already emits in the discovery metafile (import-statement kind only) and followed those, so the shim's names are guaranteed to be the file esbuild bundled even when a scanner and esbuild disagree on an exports condition. Also has a real-esbuild spec for a require-first conditional-exports package. |
PR Checklist
What is the current behavior?
The Vue server strategy pins bare
nativescript-vuein the device import map to/ns/m/node_modules/nativescript-vue, expecting that URL to serve the deps-bundle shim. It doesn't:collectDepsModuleExportInforeturnsnames: nullfor the package root becausenativescript-vue/dist/index.jscontains a bareexport * from '@vue/runtime-core', andgetShimForSpeconly emits a shim when the export surface is enumerable. The real file is served per-module instead, so any node_modules file served per-module that importsnativescript-vuebare (for example@nativescript-community/ui-collectionview/vue3) evaluates the root a second time, and its module-scopeinit()re-registers the core elements:Repro, controls and the
NS_VENDOR_INCLUDEworkaround are in #11421.What is the new behavior?
generateDepsBundlenow records, from esbuild's discovery metafile, how the bundle actually resolved every bare import edge: importer key → bare specifier → target key (bareImportEdges, persisted in the disk cache; schema bumped so existing caches rebuild).collectDepsModuleExportInfotakes an optional resolver for bareexport *targets, and the bundle service backs it with those recorded edges, so the shim enumerates exactly the file esbuild bundled for that importer — no filesystem guessing, no condition lists. If there is no recorded edge, or no resolver, the collector bails tonames: nullas before and per-module serving is unchanged. With this,nativescript-vue's root gets a real shim and the bare specifier lands in the single bundle realm the strategy already assumes.Specs: an end-to-end
createDepsBundleServicecase with a fixture root that doesexport * from 'pkg-i'asserts the served shim re-exports both its own and the target's names through real esbuild; the recorded edges are asserted and round-tripped through the disk cache; collector unit cases cover resolver hit, no edge, and an opaque-CJS target (bails).Residual risks worth knowing, none new to this change: registry keys collapse nested and hoisted copies of a package to one identity (pre-existing model for every shim); an ambiguous name across two
export *targets is unioned and reads asundefinedif absent from the bundled namespace, the same behaviour relative stars already have; and the guard that skips namespaced (:) metafile targets has no dedicated spec.Verified on device with the #11421 repro (blank Vue app importing
@nativescript-community/ui-collectionview/vue3, noNS_VENDOR_INCLUDE): the published 8.0.5 crashes with the error above; this build boots cold and from the rebuilt disk cache, the servednativescript-vueURL is the bundle shim, and live edits hot-reload.Fixes #11421.