staytuned_team
staytuned_team2mo ago

does deno_graph natively resolve the path of workspaces?

Hi everyone, I'm working on a project that includes multiple workspace members defined in my deno.json file using the workspaces field. I'm using deno_graph to resolve dependencies, but I noticed that while it allows specifying an import_map, there's no option to include the deno.json file directly. Does deno_graph natively understand and resolve workspaces specified in deno.json? If so, how can I configure it to resolve dependencies across all workspace members? If not, what would be the recommended approach to handle dependencies in a multi-workspace setup using deno_graph? Any guidance would be greatly appreciated! reference: deno_grpah jsr Thank you.
5 Replies
Bhaumin
Bhaumin2mo ago
@bartlomieju @kitsonk @dsherret Any solution? Please help
bartlomieju
bartlomieju2mo ago
deno_graph doesn't understand workspaces. You need to use deno_config to resolve workspace members
Bhaumin
Bhaumin2mo ago
is this correct i asked in ai in deno docs website? To configure a Deno workspace that can be resolved using the Deno graph, you need to set up a deno.json file at the root of your workspace. This file should define the workspace members and any necessary imports. Here’s an example of how your deno.json file might look:
{
"workspace": ["./add", "./subtract"],
"imports": {
"chalk": "npm:chalk@5"
}
}
{
"workspace": ["./add", "./subtract"],
"imports": {
"chalk": "npm:chalk@5"
}
}
In this configuration, the workspace key specifies the directories that contain your workspace members, such as add and subtract. The imports key allows you to define any external dependencies that your workspace will use. Each workspace member can also have its own deno.json file. For example, in the add directory, you might have:
{
"name": "@scope/add",
"version": "0.1.0",
"exports": "./mod.ts"
}
{
"name": "@scope/add",
"version": "0.1.0",
"exports": "./mod.ts"
}
This setup allows you to reference the workspace members using bare specifiers in your code. For instance, in your main.ts file, you can import the functions from the workspace members like this:
import chalk from "chalk";
import { add } from "@scope/add";
import { subtract } from "@scope/subtract";

console.log("1 + 2 =", chalk.green(add(1, 2)));
console.log("2 - 4 =", chalk.red(subtract(2, 4)));
import chalk from "chalk";
import { add } from "@scope/add";
import { subtract } from "@scope/subtract";

console.log("1 + 2 =", chalk.green(add(1, 2)));
console.log("2 - 4 =", chalk.red(subtract(2, 4)));
To visualize the dependencies and how they connect within your workspace, you can use the Deno graph command:
deno graph
deno graph
This command will generate a graph of your module dependencies, showing how everything is interconnected within your workspace. It provides a clear view of the relationships between your modules and their imports.
bartlomieju
bartlomieju2mo ago
It is until the deno graph subcommand. There's no such command
Bhaumin
Bhaumin2mo ago
ok