Configuring full externs preservation for default ES6 npm dependencies in :advanced ClojureScript builds
0 reputation · 27 Dec 2022, 01:00 UTC
When building a ClojureScript project with :advanced optimizations and consuming an npm package that exports a default class or function (e.g., lodash-es), the compiler’s :npm-deps externs inference may omit prototype methods, causing property names to be mangled and runtime failures.
The goal is to ensure that all properties of the imported default export are treated as externs without having to enumerate each method manually. Current workarounds require writing externs files, using ^js hints, or lowering the optimization level, each of which adds maintenance overhead or sacrifices whole‑program optimization.
It is unclear whether the compiler can be directed to preserve all exports for a specific namespace, if :foreign‑libs with :provides/:requires can achieve this, or whether Shadow‑cljs offers an equivalent flag.
- Can the compiler be configured with a :preserve-all-exports option for a given :npm-deps namespace?
- Does declaring the default export via :foreign‑libs with :provides/:requires guarantee that all its properties are retained as externs?
- Does Shadow‑cljs provide a build‑time flag that mimics :preserve-all-exports for its :npm-deps handling?