---
title: definePackage
description: Mark luna types as coming from an npm package, and the luna field of package.json that makes a deploy carry the package.
related:
  - /lunas/share-lunas-as-a-package
  - /sdk/define-luna
  - /sdk/define-config
---

`definePackage(name, lunas)` marks luna types as coming from a package, so an app that installs the package runs them and its bill shows their usage on a line of their own.

```ts src/index.ts
import { defineLuna, definePackage, t, table } from "luna";

export const { Session } = definePackage("@acme/luna-sessions", {
  Session: defineLuna({
    name: "Session",
    key: { id: t.string() },
    schema: { values: table({ k: t.string(), v: t.string() }, { primaryKey: ["k"] }) },
    handlers: (h) => ({
      put: h({ args: { k: t.string(), v: t.string() } }, (ctx, { k, v }) => {
        ctx.db.values.upsert({ k, v });
      }),
    }),
  }),
});
```

## Reference

### definePackage(name, lunas)

```ts
import { definePackage } from "luna";
```

| Prop | Type | Default | Description |
| - | - | - | - |
| `name` | `string` | - | The package's name, 1 to 128 letters, digits and the characters @ / . _ -, such as its npm name. |
| `lunas` | `Record<string, Luna>` | - | The package's luna types, by the name it exports them under. |

Returns `lunas` as given, with each luna type and the types it adds marked with `name`. A name that breaks the rule throws.

### The luna field of package.json

| Prop | Type | Default | Description |
| - | - | - | - |
| `luna` | `any JSON value` | - | Marks the package as holding luna types. Its value is not read, so {} is enough. |

```json package.json
{
  "name": "@acme/luna-sessions",
  "version": "1.0.0",
  "type": "module",
  "main": "dist/index.js",
  "luna": {}
}
```

## Good to know

- `luna deploy` carries every installed package whose `package.json` has a `luna` field, with its production dependencies, whether your app imports it or not.
- Only the luna types your app's lunas module exports are deployed. Re-export the package's types there.
- Code from a package runs with your app, as trusted as your own code.
- From `node_modules`, a deploy leaves out `.ts`, `.mts`, `.cts`, `.map` and `.md` files. Publish the package as JavaScript.
- A package with a native `.node` addon fails the deploy, unless it is an optional dependency, which is left out.
- The `luna` package is never deployed from `node_modules`. Luna provides it.
- pnpm's linked layout cannot be deployed. Set `node-linker=hoisted` in `.npmrc` and install again.

## Examples

### Use a package's lunas in your app

After `npm install @acme/luna-sessions`, export its types beside your own.

```ts luna/lunas/index.ts
export { Session } from "@acme/luna-sessions";
export { List } from "./list.ts";
```
