Fixes: FRMW-2742
In this PR, we fix the build output of the backend source code, which eliminates a lot of magic between the development and production environments.
Right now, we only compile the source files from the `src` directory and write them within the `dist` directory.
**Here's how the `src` directory with a custom module looks like**
```
src
├── modules
│ └── hello
│ ├── index.ts
```
**Here's the build output**
```
dist
├── modules
│ └── hello
│ ├── index.js
```
Let's imagine a file at the root of your project (maybe the `medusa-config.js` file) that wants to import the `modules/hello/index` file. How can we ensure that the import will work in both the development and production environments?
If we write the import targeting the `src` directory, it will break in production because it should target the `dist` directory.
## Solution
The solution is to compile everything within the project and mimic the file structure in the build output, not just the `src` directory.
**Here's how the fixed output should look like**
```
dist
├── src
│ ├── modules
│ │ └── hello
│ │ ├── index.js
├── medusa-config.js
├── yarn.lock
├── package.json
```
If you notice carefully, we also have `medusa-config.js`, `yarn.lock`, and `package.json` within the `dist` directory. We do so to create a standalone built application, something you can copy/paste to your server and run without relying on the original source code.
- This results in small containers since you are not copying unnecessary files.
- Clear distinction between the development and the production code. If you want to run the production server, then `cd` into the `dist` directory and run it from there.
## Changes in the PR
- Breaking: Remove the `dist` and `build` folders. Instead, write them production artefacts within the `.medusa` directory as `.medusa/admin` and `.medusa/server`.
- Breaking: Change the output of the `.medusa/server` folder to mimic the root project structure.
- Refactor: Remove `Symbol.for("ts-node.register.instance")]` check to find from where to load the source code.
- Refactor: Use `tsc` for creating the production build. This ensures we respect `tsconfig` settings when creating the build and also perform type-checking.
Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
62 lines
1.4 KiB
JSON
62 lines
1.4 KiB
JSON
{
|
|
"name": "@medusajs/modules-sdk",
|
|
"version": "1.12.11",
|
|
"description": "SDK for medusa modules",
|
|
"main": "dist/index.js",
|
|
"export": {
|
|
".": "./dist/index.js"
|
|
},
|
|
"repository": {
|
|
"type": "git",
|
|
"url": "https://github.com/medusajs/medusa",
|
|
"directory": "packages/modules-sdk"
|
|
},
|
|
"engines": {
|
|
"node": ">=20"
|
|
},
|
|
"publishConfig": {
|
|
"access": "public"
|
|
},
|
|
"files": [
|
|
"dist",
|
|
"!dist/**/__tests__",
|
|
"!dist/**/__fixtures__",
|
|
"!dist/**/__mocks__"
|
|
],
|
|
"author": "Medusa",
|
|
"license": "MIT",
|
|
"scripts": {
|
|
"build": "rimraf dist && tsc --build",
|
|
"test": "jest --runInBand --bail --forceExit",
|
|
"watch": "tsc --build --watch"
|
|
},
|
|
"devDependencies": {
|
|
"@mikro-orm/core": "5.9.7",
|
|
"@mikro-orm/knex": "5.9.7",
|
|
"@mikro-orm/migrations": "5.9.7",
|
|
"@mikro-orm/postgresql": "5.9.7",
|
|
"@swc/core": "^1.7.28",
|
|
"@swc/jest": "^0.2.36",
|
|
"awilix": "^8.0.1",
|
|
"cross-env": "^5.2.1",
|
|
"jest": "^29.7.0",
|
|
"pg": "^8.13.0",
|
|
"rimraf": "^5.0.1",
|
|
"typescript": "^5.6.2"
|
|
},
|
|
"dependencies": {
|
|
"@medusajs/orchestration": "^0.5.7",
|
|
"@medusajs/types": "^1.11.16",
|
|
"@medusajs/utils": "^1.11.9"
|
|
},
|
|
"peerDependencies": {
|
|
"@mikro-orm/core": "5.9.7",
|
|
"@mikro-orm/knex": "5.9.7",
|
|
"@mikro-orm/migrations": "5.9.7",
|
|
"@mikro-orm/postgresql": "5.9.7",
|
|
"awilix": "^8.0.1",
|
|
"express": "^4.21.0",
|
|
"pg": "^8.13.0"
|
|
}
|
|
}
|