Help with manually setting path for stores
I am using Nx, a monorepo framework. The way it configures it's builds, makes it so that it is not possible to set the
main
entry in package.json
, because Nx also uses that entry to do some preprocessing/validation before running SapphireJS' entry main.js
I tried manually setting the path via container.stores.registerPath('./main.js')
where SapphireJS client logs in, but with no luck. Any advice/direction would be much appreciated.
registerPath()
For the setup, I generated a fresh monorepo in Nx for a Node.js application with PNPM as the package manager. I then added SapphireJS via pnpm and followed the quick start guide for creating a pingpong slash command. The client logs in without issue, but it cannot find any commands to register. I'm assuming the path to stores is incorrect due to Nx.Sapphire Framework
Class: StoreRegistry | Sapphire
A strict-typed store registry. This is available in container.
Solution:Jump to solution
You can also set the root directory so it doesn't rely on the
main
entry in package.json
and is instead a path relative to the main files' directory (import.meta.url
in ESM or __dirname
in CJS).
However, if you want to load the pieces programmatically, you can use this guide: https://sapphirejs.dev/docs/Guide/additional-information/registering-virtual-pieces
If you go for the latter, you can use the Sapphire CLI, you can write sapphire gl
in your terminal and it'll generate all the _load.js
(or _load.ts
depending on your configuration) files ready for usage...Sapphire Framework
Registering and loading virtual pieces | Sapphire
Virtual pieces differ from normal pieces in that they are not loaded from the file system. Instead, they are registered
2 Replies
Solution
You can also set the root directory so it doesn't rely on the
main
entry in package.json
and is instead a path relative to the main files' directory (import.meta.url
in ESM or __dirname
in CJS).
However, if you want to load the pieces programmatically, you can use this guide: https://sapphirejs.dev/docs/Guide/additional-information/registering-virtual-pieces
If you go for the latter, you can use the Sapphire CLI, you can write sapphire gl
in your terminal and it'll generate all the _load.js
(or _load.ts
depending on your configuration) files ready for usageSapphire Framework
Registering and loading virtual pieces | Sapphire
Virtual pieces differ from normal pieces in that they are not loaded from the file system. Instead, they are registered
Thank you, the former worked using
__dirname
.
Virtual pieces look interesting, I'll read more into it!