Skip to content

Dependencies ​

A template can use npm packages, such as a map or chart library (included in the contract-1 baseline):

  1. Add the package to dependencies in template/package.json (create it if needed). Do not run npm install in template/.
  2. Import the package as usual: import maplibregl from 'maplibre-gl', and its CSS with import 'maplibre-gl/dist/maplibre-gl.css'.
  3. Rebuild: an agent calls the rebuild_dependencies tool; in the app, choose Templates → Rebuild Template Dependencies; in an ImageFlow source checkout, run node scripts/rebuild-template-dependencies.mjs /path/to/template. ImageFlow installs the packages with the npm on your Mac (install Node.js if you have none) into its own cache outside the book, keyed by package.json and package-lock.json so an unchanged set is reused at once, and writes npm's updated package-lock.json back. Install scripts do not run, and file: dependencies, such as a package in template/packages/, install from the same folders. Since no build step runs, such a package can point main and types at its TypeScript source ("main": "src/index.ts", "types": "src/index.ts"): the rebuild compiles it while bundling and saves the source as its declarations. A package that names a built entry, such as dist/index.js, must keep that output in the template; when an entry is missing, the rebuild stops and says which. It then bundles every package the template imports into template/vendor/: modules/ (ES modules, shared code split into chunks, CSS beside them), types/ (the declarations those packages reach, in types/packages/ by package name, so .gitignore rules for node_modules keep them), LICENSES/ and manifest.json (packages and versions, the lockfile's hash, and which import maps to which module).

A book never contains installed packages, so it stays small: a template/node_modules folder from before is not used, and the Book check says so; Rebuild Template Dependencies offers to move it to the Trash. Books never read node_modules: book revisions, the folder watcher and Save a Copy skip it. Opening, previews, the Book check and export resolve package imports only through vendor/manifest.json, so a book renders the same code on every Mac, and the template hash, which covers vendor/ but not node_modules/, identifies that code. A package import missing from the manifest is a compile error pointing at the rebuild, and so is a relative import into node_modules/ (or a dot folder), which the template hash and copies leave out. When package-lock.json changes after a rebuild, the Book check warns (template-dependencies) and the book keeps the saved bundle until you rebuild. Exported templates and the library include vendor/ and leave out node_modules/.

  • React is the app's: packages that import react get the host's React and its hooks. React components from packages, including memo and forwardRef components such as react-map-gl's <Map>, are valid JSX in templates and type-check with their props. Bundling react, react-dom or imageflow is refused.
  • Types: the rebuild resolves each import as written, subpaths included, through the package's exports (types conditions), types and typesVersions, then its @types package, and copies the declarations it reaches into vendor/types, including those of linked file: dependencies. The type check resolves bare imports among those copies as it would in node_modules, so check_book with typescript: true works without node_modules and without hand-written forwarding declarations; problems inside third-party declarations are not reported. manifest.json records each typed import's declaration entry under types. An import without declarations is typed as any, with a template-dependencies warning. The rebuild also maps each import, and every subpath a vendored package exports with declarations (so imports used only for types, or by other packages' declarations, resolve too), to its entry in paths of template/tsconfig.json (with a vendor/types fallback) and excludes vendor/ there, so code editors and a standalone tsc see the same declarations as the book's check. When tsconfig.json extends the generated .imageflow-sdk/tsconfig.json, the rebuild carries that file's paths and files over, since TypeScript would otherwise drop them, and the app's rebuild first refreshes .imageflow-sdk/ from the installed app.
  • Purity still applies: a library may run freely in an element editor. In a layout, asynchronous or GPU work such as drawing a map runs inside a <RenderedImage>; render itself stays synchronous (Render function).
  • Stylesheets: a package's CSS is bundled with the template's own, and inline data: images in it stay inline.
  • Licences: vendor/LICENSES/ holds each bundled package's licence file. Keep it when you share the template.

Rebuilding explicitly in the app or through MCP also refreshes the book's generated .imageflow-sdk/ and .claude/skills/imageflow-templates/ from the installed app, including removal of obsolete generated references. These folders are generated tooling; keep personal instructions elsewhere. Opening a book does not rewrite them. After updating ImageFlow, rebuild once to update local editor types and agent guidance; MCP reference topics always come from the installed app.