From 0e43b8436a755021f791ab1fe48f1dad576b05d6 Mon Sep 17 00:00:00 2001 From: Jo Franchetti Date: Mon, 4 Aug 2025 15:10:27 +0100 Subject: [PATCH 1/4] add info about exports --- runtime/fundamentals/configuration.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/runtime/fundamentals/configuration.md b/runtime/fundamentals/configuration.md index 66b0e3302..86d5489cf 100644 --- a/runtime/fundamentals/configuration.md +++ b/runtime/fundamentals/configuration.md @@ -487,6 +487,30 @@ works as well: } ``` +## Exports + +The `exports` field in the `deno.json` file allows you to define which modules +or paths are publicly accessible from your package. This is particularly useful +for controlling the API surface of your package and ensuring that only the +intended parts of your code are exposed to users. + +```json title="deno.json" +{ + "exports": { + "./module1": "./src/module1.ts", + "./module2": "./src/module2.ts", + "./utils/*": "./src/utils/*.ts" + } +} +``` + +This configuration will: + +- expose `module1` and `module2` as entry points for your package, +- allow importing any file from the `utils` directory using a wildcard. This + means users can import these modules using the specified paths, while other + files in your package remain private. + ## An example `deno.json` file ```json From 85347ab16b1db2ba62ebc3e28a866aa3a43f7077 Mon Sep 17 00:00:00 2001 From: Jo Franchetti Date: Mon, 4 Aug 2025 15:25:46 +0100 Subject: [PATCH 2/4] updates as per marvins feedback --- runtime/fundamentals/configuration.md | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/runtime/fundamentals/configuration.md b/runtime/fundamentals/configuration.md index 86d5489cf..170a59388 100644 --- a/runtime/fundamentals/configuration.md +++ b/runtime/fundamentals/configuration.md @@ -489,17 +489,24 @@ works as well: ## Exports -The `exports` field in the `deno.json` file allows you to define which modules -or paths are publicly accessible from your package. This is particularly useful -for controlling the API surface of your package and ensuring that only the -intended parts of your code are exposed to users. +The `exports` field in the `deno.json` file allows you to define which paths of +your package should be publicly accessible. This is particularly useful for +controlling the API surface of your package and ensuring that only the intended +parts of your code are exposed to users. + +```jsonc title="deno.json" +{ + "exports": "./src/mod.ts" // A default entry point +} +``` + +You can also define multiple entry points: ```json title="deno.json" { "exports": { "./module1": "./src/module1.ts", - "./module2": "./src/module2.ts", - "./utils/*": "./src/utils/*.ts" + "./module2": "./src/module2.ts" } } ``` @@ -511,6 +518,13 @@ This configuration will: means users can import these modules using the specified paths, while other files in your package remain private. +To use the exports in your code, you can import them like this: + +```ts title="example.ts" +import * as module_1 from "@example/my-package/module1"; +import * as module_2 from "@example/my-package/module2"; +``` + ## An example `deno.json` file ```json From 1664a75e5da9f92085abc2e279795645c6b40f3b Mon Sep 17 00:00:00 2001 From: Jo Franchetti Date: Wed, 20 Aug 2025 16:16:29 +0100 Subject: [PATCH 3/4] Update runtime/fundamentals/configuration.md --- runtime/fundamentals/configuration.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/fundamentals/configuration.md b/runtime/fundamentals/configuration.md index 343a4c5cb..1e8f1c2f6 100644 --- a/runtime/fundamentals/configuration.md +++ b/runtime/fundamentals/configuration.md @@ -506,7 +506,8 @@ You can also define multiple entry points: { "exports": { "./module1": "./src/module1.ts", - "./module2": "./src/module2.ts" + "./module2": "./src/module2.ts", + ".": "./src/mod.ts" // Default entry point } } ``` From e4fee1d0f77eb16ff71cf815176a128350e239b0 Mon Sep 17 00:00:00 2001 From: Jo Franchetti Date: Wed, 20 Aug 2025 17:50:54 +0100 Subject: [PATCH 4/4] fmt --- runtime/fundamentals/configuration.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/fundamentals/configuration.md b/runtime/fundamentals/configuration.md index 343a4c5cb..1e8f1c2f6 100644 --- a/runtime/fundamentals/configuration.md +++ b/runtime/fundamentals/configuration.md @@ -506,7 +506,8 @@ You can also define multiple entry points: { "exports": { "./module1": "./src/module1.ts", - "./module2": "./src/module2.ts" + "./module2": "./src/module2.ts", + ".": "./src/mod.ts" // Default entry point } } ```