Using a package in your workflow
This section will cover how to use packages in your project’s workflow.
Prerequisites
Before you can create and upload packages, you’ll need to have the Forest CLI installed.
Installing Packages
For this metaphorical example, we’ll be cooking (coding) spaghetti. To make spaghetti, we need to grab (install) 3 ingredients (packages): pasta, sauce, and meatballs.
Lets say you found 3 packages that provide these ingredients: @forest/pasta, @user1/sauce, and @user1/meatballs.
We’ll cover the install commands in detail later, but for now, use the following to install the packages:
forest i @forest/pasta
forest i @user1/sauce
forest i @user1/meatballsNow that we have our ingredients installed, we can import them into our project and start cooking.
local Pasta = require("pasta")
local Sauce = require("sauce")
local Meatballs = require("meatballs")
-- Do something with our now-imported ingredientsUsing packages this way means every part of your project stays modular. You can update, replace, or share each “ingredient”, allowing you to update or replace packages with ease.
Package Dependencies
When you install a package, Forest PM automatically installs any dependencies it requires.
For example, if @forest/pasta depends on @forest/flour, Forest PM installs both packages when you run:
forest i @forest/pasta
After installation, your project’s file tree will look like this:
- script.lua
- init.lua
- LICENSE
- init.lua
- LICENSE
In the example file tree, the root packages folder contains the three packages we installed. Inside the pasta package, there’s another packages folder with its dependency, flour.
Since we didn’t install flour directly, it doesn’t appear in the root packages folder. That means it isn’t available for you to require() in your project.
This structure keeps dependencies isolated. Each package manages its own requirements without affecting the main project or other packages. If you do want to use flour directly, you can install it yourself with:
forest i @forest/flour