-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create deno workspace #4
Comments
I agree with that. |
In new version of deno we can create right and more powerful workspace exactly inside Deno supports workspaces, also known as "monorepos", which allow you to manage A "workspace" is a collection of folders containing {
"workspace": ["./add", "./subtract"]
} This configures a workspace with :::info Naming Deno uses ::: ExampleLet's expand on the /
├── deno.json
├── main.ts
├── add/
│ ├── deno.json
│ └── mod.ts
└── subtract/
├── deno.json
└── mod.ts There are two workspace members (add and subtract), each with The top-level {
"workspace": ["./add", "./subtract"],
"imports": {
"chalk": "npm:chalk@5"
}
} The root 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))); In the {
"name": "@scope/add",
"version": "0.1.0",
"exports": "./mod.ts",
"fmt": {
"semiColons": false
}
} export function add(a: number, b: number): number {
return a + b;
} The {
"name": "@scope/subtract",
"version": "0.3.0",
"exports": "./mod.ts"
} import { add } from "@scope/add";
export function subtract(a: number, b: number): number {
return add(a, b * -1);
} Let's run it: > deno run main.ts
1 + 2 = 3
2 - 4 = -2 There's a lot to unpack here, showcasing some of the Deno workspace features:
Deno workspaces are flexible and can work with Node packages. To make migration Migrating from
|
Option | Workspace | Package | Notes |
---|---|---|---|
compilerOptions | ✅ | ❌ | For now we only allow one set of compilerOptions per workspace this because it will require multiple changes to both deno_graph and the TSC integration to allow it. Also we’d have to determine what compilerOptions apply to remote dependencies. We can revisit this in the future. |
importMap | ✅ | ❌ | Exclusive with imports and scopes per config file. It is allowed to have importMap in the workspace config, and imports in the package config. |
imports | ✅ | ✅ | Exclusive with importMap per config file. |
scopes | ✅ | ❌ | Exclusive with importMap per config file. |
exclude | ✅ | ✅ | |
lint.include | ✅ | ✅ | |
lint.exclude | ✅ | ✅ | |
lint.files | ❌ | Deprecated | |
lint.rules.tags | ✅ | ✅ | Tags are merged by appending package to workspace list. Duplicates are ignored. |
lint.rules.include | |||
lint.rules.exclude | ✅ | ✅ | Rules are merged per package, with package taking priority over workspace (package include is stronger than workspace exclude). |
lint.report | ✅ | ❌ | Only one reporter can be active at a time, so allowing different reporters per workspace would not work in the case where you lint files spanning multiple packages. |
fmt.include | ✅ | ✅ | |
fmt.exclude | ✅ | ✅ | |
fmt.files | ❌ | Deprecated | |
fmt.useTabs | ✅ | ✅ | Package takes priority over workspace. |
fmt.indentWidth | ✅ | ✅ | Package takes priority over workspace. |
fmt.singleQuote | ✅ | ✅ | Package takes priority over workspace. |
fmt.proseWrap | ✅ | ✅ | Package takes priority over workspace. |
fmt.semiColons | ✅ | ✅ | Package takes priority over workspace. |
fmt.options.* | ❌ | Deprecated | |
nodeModulesDir | ✅ | ❌ | Resolution behaviour must be the same in the entire workspace. |
vendor | ✅ | ❌ | Resolution behaviour must be the same in the entire workspace. |
tasks | ✅ | ✅ | Package tasks take priority over workspace. cwd used is the cwd of the config file that the task was inside of. |
test.include | ✅ | ✅ | |
test.exclude | ✅ | ✅ | |
test.files | ❌ | Deprecated | |
publish.include | ✅ | ✅ | |
publish.exclude | ✅ | ✅ | |
bench.include | ✅ | ✅ | |
bench.exclude | ✅ | ✅ | |
bench.files | ❌ | Deprecated | |
lock | ✅ | ❌ | Only a single lock file may exist per resolver, and only resolver may exist per workspace, so conditional enablement of the lockfile per package does not make sense. |
unstable | ✅ | ❌ | For simplicities sake, we do not allow unstable flags, because a lot of the CLI assumes that unstable flags are immutable and global to the entire process. Also weird interaction with DENO_UNSTABLE_* flags. |
name | ❌ | ✅ | |
version | ❌ | ✅ | |
exports | ❌ | ✅ | |
workspace | ✅ | ❌ | Nested workspaces are not supported. |
Nice, I try to do this with new docs |
To set up a Deno workspace for your project, you'll want to structure it in a way that allows modularity, ease of development, and scalability. Here's a step-by-step guide to creating a workspace in Deno:
1. Workspace Overview
In Deno, a workspace setup helps you manage multiple projects (or packages/modules) under a single repository. This is ideal for separating concerns such as backend, frontend, shared libraries, and utilities while keeping everything unified.
A basic structure might look like this:
2. Setting Up the Workspace
2.1. Root Directory
Create a root directory for your workspace, which will contain the backend, frontend, and shared code. This directory will also include the configuration files (
deno.json
,deno.lock
).2.2. Create a
deno.json
FileIn the root of your workspace, create a
deno.json
file to manage dependencies, import maps, and compiler options for the entire project. This file allows you to configure how Deno resolves imports across the workspace.2.3. Create an
import_map.json
To avoid relative paths for shared code and dependencies, create an
import_map.json
file to centralize import paths.2.4. Backend Directory
In the
backend/
directory:main.ts
: This file will be the entry point for the backend service. It should start the server and handle routing for APIs.deps.ts
: This file manages the backend dependencies (e.g., third-party modules).Example
main.ts
for a simple server:2.5. Frontend Directory
In the
frontend/
directory:main.ts
: Entry point for the Deno Fresh-based frontend.Example
main.ts
:2.6. Shared Directory
The
shared/
folder is where you place reusable modules, such as utility functions, types, or constants that both the backend and frontend can use.utils.ts
: For shared utility functions.types.ts
: For TypeScript types or interfaces shared across the workspace.2.7. GitHub Actions for CI/CD
Set up GitHub Actions for CI/CD in
.github/workflows/
. You might want to automate tasks such as running tests, building the project, and deploying.Example CI workflow (
ci.yml
):2.8. README.md
Create a
README.md
that documents the structure of your workspace, how to set up the environment, and how to run both the backend and frontend.3. Running and Testing the Workspace
With the workspace set up, you can start different services via the
deno.json
task system:deno task start:backend
deno task start:frontend
deno task test
4. Benefits of Deno Workspace
deno.json
.This setup allows for flexibility and organization, making it easier to manage and contribute to your open-source project.
The text was updated successfully, but these errors were encountered: