Externalize xmldom/xpath for ESM/CJS builds#12
Conversation
…mers Replace inline require() calls with top-level imports for @xmldom/xmldom and xpath, and mark them as external in the Rollup module build config. This ensures ESM output uses proper import statements that work in Node.js ESM consumers (e.g. "type": "module" projects). The UMD build continues to bundle these deps inline for browser use. Browser tests stub out these Node-only deps since the browser path uses native DOMParser/XMLSerializer/XPath APIs.
Greptile SummaryThis PR fixes an Key changes:
Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[xmlParser.ts loaded] --> B{Runtime environment?}
B -->|Browser| C[Use window.DOMParser\nand document.evaluate]
B -->|Node.js| D[Use xmldom.DOMParser\nand xpath.select]
subgraph ESM_CJS["ESM / CJS builds"]
E["@xmldom/xmldom — external"]
F["xpath — external"]
G["@peculiar/asn1-* — external"]
end
subgraph UMD["UMD build"]
H["@xmldom/xmldom — bundled inline"]
I["xpath — bundled inline"]
J["@peculiar/asn1-* — bundled inline"]
end
subgraph BrowserTests["Browser tests stub-node-deps plugin"]
K["resolveImport intercepts xmldom and xpath"]
L["serve returns stub with undefined exports"]
K --> L
end
D --> ESM_CJS
D --> UMD
A --> BrowserTests
|
Summary
require()with top-levelimportfor@xmldom/xmldomandxpathin xmlParser.tsimport/requirestatementsisExternalModuleUmdfunction@peculiar/asn1-*packages (were being unnecessarily bundled)Fixes
"XML DOM parser not available"error when ESM consumers (projects with"type": "module") useedockit/trusted-list/buildin Node.js.Test plan
importstatements for xmldom/xpath