SreedharAvvari commented on issue #4000:
URL: 
https://github.com/apache/incubator-kie-tools/issues/4000#issuecomment-5857321691

   Thanks for looking at this. The motivation is running the same DMN code in 
the browser and in Node, and shipping it as a small, pure-JS bundle.
   
   We publish a package built on `@kie-tools/dmn-marshaller` that runs in two 
places: our web modeler, and command-line tooling that validates and packages 
`.dmn` files. We need both to accept and reject exactly the same documents, so 
we parse with one DOM implementation in both environments. `@xmldom/xmldom` is 
pure JS and small, and behaves the same in the browser and in Node. With jsdom 
that isn't possible, because jsdom doesn't run in the browser, so the two 
environments would parse through different implementations.
   
   jsdom also breaks how the CLI is distributed:
   
   - It is heavy for this use, since the marshaller only needs `DOMParser` and 
basic node traversal.
   - Its optional native `canvas` binding stops esbuild when it is present: `No 
loader is configured for ".node" files: .../canvas/build/Release/canvas.node`.
   - Its `require.resolve("./xhr-sync-worker.js")` doesn't survive bundling 
into a single file, which is how our CLI is shipped (esbuild, then `pkg`).
   
   `domParser.getDomDocument` already makes the DOM pluggable, and xmldom works 
well through it. Our marshaller tests, and a round trip of every document we 
ship, pass on it. The only blocker is that the default Node entry hard-requires 
jsdom. Either option in the issue would fix that: jsdom as an optional, lazily 
loaded peer, or the environment-agnostic build as the default with jsdom behind 
a `/node` subpath.
   
   A related blocker for Node consumers, which I can file separately if you 
prefer: `@kie-tools/dmn-marshaller`'s `dist` uses ESM syntax without `"type": 
"module"`, and imports `@kie-tools/xml-parser-ts/dist/ns` without a file 
extension. Plain Node ESM can't load it, even with a DOM provided:
   
   ```
   Error [ERR_MODULE_NOT_FOUND]: Cannot find module 
'.../@kie-tools/xml-parser-ts/dist/ns' imported from 
.../@kie-tools/dmn-marshaller/dist/index.js
   ```
   
   Today we work around both by inlining the marshaller into our bundle, 
resolving `@kie-tools/xml-parser-ts` to `dist/index.js`, and setting 
`domParser.getDomDocument` to xmldom. We'd like to drop that once the packages 
load in Node as published.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to