@skedulo/mex-fn-build
v0.0.2
Published
Bundler CLI for Skedulo MEX shared connected functions — bundles the backend entry and emits dist/info.json (libVersion + feature descriptors)
Maintainers
Keywords
Readme
@skedulo/mex-fn-build
Bundler CLI for Skedulo MEX shared connected functions. A shared-function
project depends on this as its single build devDependency and runs it via
yarn bundle (which is just mex-fn-build). The same CLI runs locally and in
the cloud builder, so a local bundle matches the cloud bundle exactly.
Commands
mex-fn-build (default, bundle)
Run from a shared-function project root, in strict order:
- Bundle
src/index.backend.ts→dist/index.backend.jswith esbuild. - Load the
sharedFunctionFactoryexport from the freshly-built bundle. - Read
libVersionfrom the project's installed@skedulo/mex-service-libs. - Derive feature descriptors via the project's
describeSharedResources. Offline the resource thunk throws (no tenant token), so it falls back to an empty resource list + the realchangeSets; the cloud builder re-derives and overwritesfeatures.resources. - Write
dist/info.json = { libVersion, features }.
mex-fn-build serve [--port N]
Boots a local Koa dev server over the function's routes so a developer can
exercise handlers before deploying. It rebuilds a non-minified dev bundle
(dist/index.backend.dev.js, so the shipped dist/index.backend.js stays
untouched), then wraps the bundle's handler dispatcher in Koa. Routes:
POST /resource_fetch, /resource_descriptor, /changeset, /changeset_after.
Auth is per request via Authorization: Bearer <jwt> + Sked-Api-Server: <baseUrl>
headers; for convenience these are injected from SKED_API_TOKEN / SKED_BASE_URL
when a request omits them. Port defaults to 3000 (--port or PORT). koa /
koa-bodyparser resolve from the project's SDK — no dependency is added.
Why it resolves the SDK from the project
The CLI declares no dependency on @skedulo/mex-service-libs. It resolves the
SDK — both the libVersion and the derivation helpers — from the consuming
project's node_modules (require.resolve(id, { paths: [projectRoot] })), the
same discipline the cloud builder uses. If the CLI carried its own SDK copy,
libVersion would reflect the CLI's pin instead of the version the function was
authored against, silently mis-selecting the fetch/save invocation contract.
Usage
In a shared-function project:
// package.json
{
"scripts": {
"bundle": "mex-fn-build",
"start": "mex-fn-build serve"
},
"devDependencies": { "@skedulo/mex-fn-build": "^0.0.1" }
}yarn bundle # -> dist/index.backend.js + dist/info.json
yarn start # local dev server on :3000 (SKED_BASE_URL / SKED_API_TOKEN)Local development of this package
Uses an isolated npm toolchain (independent of the repo's root Yarn project):
cd tools/mex-fn-build
npm install
npm run build # tsc -> dist/cli.js