@@ -20,3 +20,63 @@ reference (filename for require() plus function name)
2020?
2121
2222=== ...
23+
24+ == Importing from `ep_etherpad-lite`
25+
26+ Etherpad ships dual entry points so plugins authored in either CommonJS
27+ or ECMAScript Modules can consume core APIs.
28+
29+ === CJS plugins (default — most existing plugins)
30+
31+ Use `require()` against extensionless or `.js` subpaths:
32+
33+ [source,js]
34+ ----
35+ const eejs = require('ep_etherpad-lite/node/eejs');
36+ const PadManager = require('ep_etherpad-lite/node/db/PadManager');
37+ const API = require('ep_etherpad-lite/node/db/API.js');
38+ const padUtils = require('ep_etherpad-lite/static/js/pad_utils');
39+ ----
40+
41+ These resolve through the package's `exports` map under the `require`
42+ condition and load CJS twins from `dist-cjs/`.
43+
44+ NOTE: `require('ep_etherpad-lite/node/eejs/')` with a trailing slash is
45+ **not** supported. Drop the slash: `require('ep_etherpad-lite/node/eejs')`.
46+
47+ NOTE: Some core modules (database modules under `node/db/*`) transitively
48+ depend on `ueberdb2` which is ESM-only. They can be resolved by
49+ `require.resolve` but cannot be synchronously loaded from CJS contexts.
50+ Plugins that actually use these modules at runtime must migrate to ESM
51+ (see below) or stop depending on them.
52+
53+ === ESM plugins (opt-in)
54+
55+ Set `"type": "module"` in your plugin's `package.json`. Use `import` with
56+ explicit `.js` extensions:
57+
58+ [source,js]
59+ ----
60+ import * as eejs from 'ep_etherpad-lite/node/eejs/index.js';
61+ import { getPad } from 'ep_etherpad-lite/node/db/PadManager.js';
62+ import { randomString } from 'ep_etherpad-lite/static/js/pad_utils.js';
63+ ----
64+
65+ These resolve through the `import` condition and load ESM modules from
66+ `dist/`.
67+
68+ === Supported subpaths
69+
70+ * `ep_etherpad-lite/node/*` — server-side modules
71+ * `ep_etherpad-lite/node/eejs` — template engine (no trailing slash)
72+ * `ep_etherpad-lite/static/js/*` — code shared with the browser
73+ * `ep_etherpad-lite/tests/backend/*` — test helpers (only useful in plugin
74+ tests; ESM only)
75+
76+ === What is NOT supported
77+
78+ * Reaching into `src/...` or `dist/...` paths directly — only the subpaths
79+ above are stable API.
80+ * Mixing `require()` and `import` inside the same plugin file. Pick one.
81+ * `require('ep_etherpad-lite/node/eejs/')` with trailing slash.
82+ * `require()` of database modules from CJS (use ESM imports instead).
0 commit comments