asterobot:runtime lets a script read facts about the packages it's made of: its own package, the packages it depends on, and the built-in asterobot: modules. Nothing in it can change a package.
import { packages } from "asterobot:runtime";
packages is the module's only export. It's a frozen object with one function, info(). There's no flat info export, so it can't be confused with info() from asterobot:console.
packages.info()
packages.info(name) returns a frozen PackageInfo object.
| Parameter | Type | Description |
|---|---|---|
name |
string | A package name, such as "my-first-script" or "@alice:pathfinder", or the name of a built-in module, such as "asterobot:protocol" |
The names it knows are:
- every package in the running script: the bot's package and, all the way down, the packages its dependencies lock;
- the built-in modules
asterobot:protocol,asterobot:bot,asterobot:timers,asterobot:gamedata,asterobot:consoleandasterobot:runtime.
asterobot:parameters isn't one of them: each package has its own copy of that module, and asking for it throws package "asterobot:parameters" is not installed.
An inline script, loaded as code rather than as a library package, is the package api-script with the version local.
packages.info() throws when:
| Error | Type | Cause |
|---|---|---|
packages.info requires a module or package name |
TypeError |
name is missing, empty or not a string. Despite the wording, a module path isn't accepted. |
package "<name>" is not installed |
Error | No package in the running script has that name |
package "<name>" is ambiguous across <count> locked versions |
Error | The script's dependencies lock more than one version of that package, so the name alone doesn't say which |
const self = packages.info("my-first-script");
botInfo(`${self.name} ${self.version}, ${self.provenance}`);
On a local package, this writes my-first-script 1.0.0, local to the bot's console.
packages.info() also answers while Asterobot reads the package's declarations, so a declaration can use it.
PackageInfo
| Property | Type | Value |
|---|---|---|
name |
string | The package's name |
version |
string | The package's version. "embedded" for a built-in module. |
publisher |
string | The part before the colon in @publisher:name: "asterobot" for official packages and built-in modules, "" for a local package |
provenance |
string | "local", "official", "community", or "builtin" for a built-in module |
integrity |
string | The checksum Asterobot recorded when it installed the package from the marketplace, starting with sha256-. "" when there's none, as for a local package, and "embedded" for a built-in module. |
permissions |
array of strings | The permissions listed in the package's asterobot.json. An empty array when it lists none, and always for a built-in module. |
compatibleVersion |
string | The Asterobot versions the package declared it works with, such as ">=1.5.0 <2.0.0", or "" |
The type in the editor also lists "builtin-native" as a possible provenance. Asterobot never returns it.
A package's provenance comes from its name: a name starting with @asterobot: is official, another name starting with @ is community, and a name without @ is local. Names and versions explains the rules, The manifest describes asterobot.json, and Compatibility covers compatibleVersion.
Permissions
permissions only reports what a package declares. Asterobot doesn't check it today: any package can use every function of every built-in module, whatever it lists.
Note
Coming soon. Asterobot will enforce the permissions a package declares. Until then, treat the list as information for the people who install your package. Permissions has the details.
Aucun avis à afficher.