super-productivity/packages/sync-providers/package.json
Johannes Millan a11f27cf43 refactor(sync-providers): @xmldom/xmldom to devDeps + global DOMParser
Multi-review (W3) flagged that `@xmldom/xmldom` was a runtime
dependency only because the package's vitest env (Node) lacks the
DOM `DOMParser`. Browsers, Electron, and Capacitor WebViews all
provide their own `DOMParser` — so the dep was shipping into the
host's transitive bundle just to support the package's unit tests.

Move it to `devDependencies` and:

- Use `globalThis.DOMParser` at runtime in `webdav-xml-parser.ts`.
  Added a minimal `declare const DOMParser: { new(): {
  parseFromString(text, mimeType): XmlNodeLike } }` so the package's
  strict TS still type-checks without DOM lib pulling in via
  xmldom's `/// <reference lib="dom" />`.
- Polyfill `globalThis.DOMParser` from `@xmldom/xmldom` in a new
  `tests/setup-dom-parser.ts` vitest setup file. Vitest config adds
  it to `setupFiles`.
- Drop the explicit `import { DOMParser } from '@xmldom/xmldom'` from
  the parser source.

Side effect: the package's `tsconfig.json` now sets `lib: ["ES2022",
"DOM"]`. Previously the `/// <reference lib="dom" />` directive
inside `@xmldom/xmldom`'s shipped `index.d.ts` was transparently
pulling DOM lib in for our TS DTS compilation (covering `Response`,
`RequestInit`, `URL`, `URLSearchParams`, `btoa`, etc.). Removing the
xmldom import broke that chain — the package code uses those DOM
globals throughout, so adding `DOM` to `lib` is the explicit fix.

Bundle impact
- Package's own ESM bundle: 73.23 KB (was 70.93 KB; +2.3 KB from
  PR 6b's test-connection helper, not xmldom — xmldom was already
  marked external by tsup since it was a dep, so the package bundle
  never carried it).
- Host bundle savings: `@xmldom/xmldom` no longer transitively
  installed for consumers — roughly 50 KB pre-gzip / ~15 KB gzip
  recovered from app bundles.

Verification
- npm run sync-providers:test: 164/164 (setup file polyfills
  DOMParser correctly; vitest reports 274 ms setup time).
- npm run sync-providers:build: ESM 73.23 KB / CJS 75.77 KB / DTS
  37.13 KB. Confirmed `grep -c xmldom dist/index.mjs == 0`.
- All modified files pass `npm run checkFile`.
2026-05-12 22:22:42 +02:00

37 lines
832 B
JSON

{
"name": "@sp/sync-providers",
"version": "1.0.0",
"description": "Framework-agnostic sync provider contracts for Super Productivity sync",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"sideEffects": false,
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
},
"dependencies": {
"@sp/sync-core": "*",
"hash-wasm": "^4.12.0"
},
"scripts": {
"build": "tsup",
"build:tsc": "tsc",
"test": "vitest run",
"test:watch": "vitest"
},
"devDependencies": {
"@xmldom/xmldom": "^0.8.12",
"tsup": "^8.0.0",
"typescript": "^5.0.0",
"vitest": "^3.2.4"
}
}