mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 13:23:04 +00:00
fix(plugin-sdk): make require('trek-plugin-sdk') actually resolve everywhere
A freshly scaffolded plugin could not load anywhere: the npm package is
ESM-only (no require condition in its exports map), so the scaffold's
require('trek-plugin-sdk') threw ERR_PACKAGE_PATH_NOT_EXPORTED under
`trek-plugin dev` - and the runtime injection the wiki promised for the
plugin child never existed, so a packed plugin (node_modules stripped)
crashed with MODULE_NOT_FOUND after a real install.
- plugin child: inject a frozen {definePlugin, PLUGIN_API_VERSION} shim
for require('trek-plugin-sdk'); subpaths fail with a pointed error
- trek-plugin dev: inject the exact same shim, so a fresh scaffold runs
with zero npm install and dev parity with production holds
- npm package: ship a real CommonJS build (dist/cjs + require export
conditions) so the installed package also requires cleanly on Node 18+
- create: scaffold a package.json (type commonjs, SDK as devDependency,
npx scripts); print resolvable `npx trek-plugin-sdk ...` hints
- wiki: package.json in the scaffold tree + publishing checklist, and
document the zero-install dev flow
This commit is contained in:
@@ -22,6 +22,7 @@ This emits:
|
||||
```
|
||||
my-plugin/
|
||||
trek-plugin.json # manifest
|
||||
package.json # CommonJS marker + the SDK as a devDependency
|
||||
server/index.js # your plugin code (built, plain JS)
|
||||
client/index.html # page/widget iframe (page/widget only)
|
||||
README.md # fill this in — the registry requires a screenshot
|
||||
@@ -33,8 +34,11 @@ my-plugin/
|
||||
npx trek-plugin-sdk dev # http://localhost:4317
|
||||
```
|
||||
|
||||
`dev` loads your `server/index.js` through the same `definePlugin` contract the
|
||||
host uses and gives you a **real request loop without a full TREK**: a dashboard
|
||||
`dev` works straight after `create` — no `npm install` needed, because it
|
||||
injects `require('trek-plugin-sdk')` from the CLI itself, exactly like TREK
|
||||
injects it in production. It loads your `server/index.js` through the same
|
||||
`definePlugin` contract the host uses and gives you a **real request loop
|
||||
without a full TREK**: a dashboard
|
||||
listing your routes, the routes served under `/api/<path>`, your page/widget UI
|
||||
at `/ui`, and a reload on every save. The injected `ctx` **enforces exactly the
|
||||
permissions your manifest grants** — an ungranted call throws `PERMISSION_DENIED`,
|
||||
|
||||
Reference in New Issue
Block a user