Skip to content

Modernize to ESM-native + CJS wrapper (like the other CLDMV libs) #2

Description

@Shinrai

polyfillme is currently CommonJS (no "type": "module", CJS source, CJS test/*.test.js). It should move to the CLDMV standard — ESM-native with a thin CJS wrapper — so consumers get native import while require() still works. Non-urgent; tracking follow-up (same modernization as the CJS→ESM issues on gitmulti / wol-proxy / cldmv-node-memcache).

Reference: CLDMV/wisp (the simplest wrapper)

package.json:

{
  "type": "module",
  // no "main"
  "exports": { ".": { "import": "./index.mjs", "require": "./index.cjs" } },
  "files": ["src/", "index.mjs", "index.cjs", "README.md", "LICENSE", "package.json"]
}

ESM source: index.mjs + src/**/*.mjs.

Thin CJS wrapper index.cjs — loads the ESM build via createRequire and re-exports:

"use strict";
const { createRequire } = require("module");
const esm = createRequire(__filename)("./index.mjs");

module.exports = esm.default;
module.exports.default = esm.default;
module.exports.wisp = esm.wisp;       // re-export each named export
module.exports.wispSync = esm.wispSync;

For polyfillme

  • Convert the source to ESM (.js.mjs), add type: "module" + the exports map, and add an index.cjs wrapper re-exporting the public API.
  • Preserve the current public API and any side-effect / global-patch semantics — a polyfill package's consumption pattern (side-effect import vs. explicit apply) must not change behavior across the ESM/CJS split.
  • Keep the test/* suite green against the new entry points (the in-progress v4 onboarding already wires @cldmv/vitest-runner; convert or dual-target the tests as part of this).

This is packaging modernization only — no functional change intended.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions