Skip to content

Libraries from other plugins - #72

Merged
jeany55 merged 1 commit into
mainfrom
libraries
Oct 26, 2026
Merged

jeany55 merged 1 commit into
mainfrom
libraries

Conversation

@jeany55

@jeany55 jeany55 commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Lets another plugin give TrigScript scripts a library to import, the way the standard library is imported.

For map makers. import { spawnWave } from "waves" imports a library a plugin provides ("waves/spawn" for one module, "waves" for its index). Applying the script copies each imported library into the map (trigscript\@libraries\<id>\), and the map builds with that copy from then on: it still builds where the plugin is not installed, or where a different version is. When the installed plugin has a different version, the editor offers Update / Keep the map's copy. It never updates by itself.

For plugin authors. trigscript.build is now service version 2, with provideLibrary({ id, label, version, modules }), documented in contract.d.ts and the README (Providing a library). examples/library is a complete library plugin to copy, installable as github:scm-js/plugin-trigscript/examples/library.

How

  • Compiler (compiler/libraries.ts): CompileOptions.libraries. Only modules something imports join the files (__libraries__/<id>/…), so a program() in a library module runs only where that module is imported. TypeScript paths and the linker resolve bare ids. A missing library or module gets a message saying where libraries come from.
  • Map copy (script.ts): readLibraries / withLibraries; pathOf keeps the copy out of the script's own files. The manifest hash covers the copies via hashSources; with no libraries it equals hashFiles, so existing maps still read as built.
  • Service: a compile takes the map's copy first, then what a plugin provides. Apply writes exactly the libraries the compile used. New commands trigscript.libraries and trigscript.updateLibraries; state() lists the copies.
  • Editor: library modules become Monaco extra libs (completion, hovers), refreshed when a provider comes or goes.

Tested

  • New tests/libraries.test.ts (compiler, map copy, the example library) and service tests (copy on apply, building without the plugin, update, dropping an unused library, contributions, refusals). There is also a test that the compile worker's own source forwards libraries. Full suite: 1398 passed; tsc clean.
  • Played in the editor: a dev server with this branch as the built-in TrigScript and the compiler bundle served locally. Import → 0 problems and the library's hover; Apply; Save As → the archive holds trigscript\@libraries\waves\…. Reopened with the example at 1.1.0 → the notice, then Update → "Changes not applied". Reopened with the example not installed → 0 problems, still built.

Left open (in docs/v4-plan.md, Libraries from other plugins): a Libraries view, cost per library, media in libraries, a template repository and a way to test a library in its own repo, libraries without a plugin, and the scm-js guide pages once a release pins this.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WdKDdRDTseBGCMyjhrAiNG

…mported by id, kept in the map

A plugin provides a library through trigscript.build (service version 2): provideLibrary({ id, label,
version, modules }). A script imports "<id>/<module>" or "<id>" (index), as it imports the standard
library; only the modules something imports join the build, at __libraries__/<id>/.

When the script is applied, each library it imports is copied into the map under
trigscript\@libraries\<id>\ with a library.json, and the map builds with that copy from then on, with
or without the plugin. A newer provided version is offered in the editor (Keep / Update), never taken
by itself. The manifest's source hash covers the copies; with none it is the old hash, so existing
maps still read as built.

Also: Monaco gets each library's modules (completion, hovers), commands trigscript.libraries and
trigscript.updateLibraries, state() lists the copies, contract.d.ts documents provideLibrary, and
examples/library is a complete library plugin to copy. Played in the editor end to end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WdKDdRDTseBGCMyjhrAiNG
@jeany55
jeany55 merged commit 90c26b6 into main Oct 26, 2026
1 check passed
@jeany55 jeany55 mentioned this pull request Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant