Skip to content

Commit 52bc184

Browse files
committed
fix: update to have dependencies for project
1 parent 0eaef8e commit 52bc184

File tree

3 files changed

+205
-710
lines changed

3 files changed

+205
-710
lines changed

README.md

Lines changed: 96 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,83 @@ Core app, HTML pages and static assets for the **WorkAdventure Map Starter Kit**
1616
npm install @workadventure/map-starter-kit-core
1717
```
1818

19-
**Peer / consumer:** The built server expects `express` to be available at runtime. For TypeScript consumers, `@types/express` is used for the exported `Application` type.
19+
**Peer / consumer:** The built server expects `express` to be available at runtime. For TypeScript consumers, install `@types/express` so the exported `Application` type resolves.
20+
21+
---
22+
23+
## Package exports and usage from another package
24+
25+
This package is built and published as a **single server bundle**. Consumers must use the built output, not the source, to avoid module resolution errors.
26+
27+
### How exports are managed
28+
29+
| Field | Role |
30+
|--------|------|
31+
| **`main`** | Entry when a tool doesn’t use `exports`. Should point to `dist/server.js` so the bundle is used, not `src/server.ts`. |
32+
| **`types`** | Tells TypeScript which declaration file to use for the package entry (`dist/server.d.ts`). |
33+
| **`exports`** | Modern entry map: `"."` and `"./dist/server.js"` resolve to `dist/server.js` with types `dist/server.d.ts`. |
34+
| **`files`** | What gets published: `dist`, `public`, `README.md`. Source (`src/`) is not published so consumers never resolve to `.ts` files. |
35+
36+
Recommended in **package.json** for correct consumption:
37+
38+
```json
39+
{
40+
"main": "dist/server.js",
41+
"types": "dist/server.d.ts",
42+
"exports": {
43+
".": {
44+
"types": "./dist/server.d.ts",
45+
"import": "./dist/server.js",
46+
"require": "./dist/server.js"
47+
},
48+
"./dist/server.js": {
49+
"types": "./dist/server.d.ts",
50+
"import": "./dist/server.js",
51+
"require": "./dist/server.js"
52+
}
53+
},
54+
"files": ["dist", "public", "README.md"]
55+
}
56+
```
57+
58+
### Using the package in another project
59+
60+
**1. Install the package**
61+
62+
```bash
63+
npm install @workadventure/map-starter-kit-core
64+
```
65+
66+
**2. Import the Express app (ESM)**
67+
68+
```ts
69+
import core from "@workadventure/map-starter-kit-core";
70+
71+
const app = core.default; // or core.viteNodeApp (same Express Application)
72+
73+
app.listen(3000, () => console.log("Listening on 3000"));
74+
```
75+
76+
**3. Or use the explicit entry (same result)**
77+
78+
```ts
79+
import core from "@workadventure/map-starter-kit-core/dist/server.js";
80+
```
81+
82+
**4. TypeScript**
83+
84+
Types come from `dist/server.d.ts`: the default export is typed as `{ default: Application; viteNodeApp: Application }`. Ensure the consuming project has `express` and `@types/express` so the `Application` type resolves.
85+
86+
**5. CommonJS**
87+
88+
```ts
89+
const core = require("@workadventure/map-starter-kit-core");
90+
const app = core.default;
91+
```
92+
93+
**Important:** Do not import from `@workadventure/map-starter-kit-core/src/server` or rely on `src/` in the package. Only the built `dist/server.js` and its types are the supported contract.
94+
95+
---
2096

2197
## Usage
2298

@@ -25,15 +101,15 @@ npm install @workadventure/map-starter-kit-core
25101
Use the built Express app in your own server:
26102

27103
```ts
28-
import core from "@workadventure/map-starter-kit-core/dist/server.js";
104+
import core from "@workadventure/map-starter-kit-core";
29105

30106
const app = core.default; // or core.viteNodeApp
31107

32108
// Mount or start your server
33109
app.listen(3000, () => console.log("Listening on 3000"));
34110
```
35111

36-
Types are provided: `core` is typed as `{ default: Application; viteNodeApp: Application }` (see `types/server.d.ts`).
112+
Types are provided via `dist/server.d.ts`: `core` is typed as `{ default: Application; viteNodeApp: Application }`.
37113

38114
### Development server (standalone)
39115

@@ -61,23 +137,30 @@ npm run build
61137
map-starter-kit-core/
62138
├── src/
63139
│ ├── server.ts # Express app entry (CORS, static, routes)
64-
│ ├── getCoreRoot.ts # Resolve core package root (cwd vs package dir)
65-
│ ├── controllers/
66-
│ │ ├── FrontController.ts # HTML pages (Mustache): /, step1-git, step2-hosting, step3-*, step4-*
67-
│ │ ├── MapController.ts # /maps/list – list .tmj maps with properties
68-
│ │ └── UploaderController.ts # /uploader/* – configure, status, maps-storage-list, upload
69-
│ └── views/ # Mustache HTML templates
70-
│ ├── index.html
71-
│ ├── step1-git.html … step4-validated-selfhosted.html
72-
├── public/ # Static assets (images, styles, etc.)
140+
│ ├── utils/
141+
│ │ └── getCoreRoot.ts # Resolve core package root (cwd vs package dir)
142+
│ └── controllers/
143+
│ ├── FrontController.ts # HTML pages (Mustache): /, step1-git, step2-hosting, step3-*, step4-*
144+
│ ├── MapController.ts # /maps/list – list .tmj maps with properties
145+
│ └── UploaderController.ts # /uploader/* – configure, status, maps-storage-list, upload
146+
├── public/ # Static assets
147+
│ ├── assets/
148+
│ │ ├── js/ # Client scripts (e.g. index.js – maps list, Mustache)
149+
│ │ └── views/ # HTML views (index.html, step1-git.html, …)
150+
│ ├── images/
151+
│ └── styles/
73152
├── types/
74153
│ └── server.d.ts # Module declaration for dist/server.js (copied to dist on build)
75-
├── dist/ # Build output (server.js, server.d.ts, assets)
154+
├── dist/ # Build output (published)
155+
│ ├── server.js # Bundled server entry
156+
│ └── server.d.ts # Types for consumers
76157
├── vite.config.ts
77158
├── tsconfig.json
78159
└── package.json
79160
```
80161

162+
Only `dist`, `public`, and `README.md` are included in the published package (`files`). Source (`src/`) is not published so consumers always get the built bundle.
163+
81164
## API / Routes
82165

83166
| Method | Path | Description |

0 commit comments

Comments
 (0)