* initialized next.js project * finished markdown sections * added operation schema component * change page metadata * eslint fixes * fixes related to deployment * added response schema * resolve max stack issue * support for different property types * added support for property types * added loading for components * added more loading * type fixes * added oneOf type * removed console * fix replace with push * refactored everything * use static content for description * fixes and improvements * added code examples section * fix path name * optimizations * fixed tag navigation * add support for admin and store references * general enhancements * optimizations and fixes * fixes and enhancements * added search bar * loading enhancements * added loading * added code blocks * added margin top * add empty response text * fixed oneOf parameters * added path and query parameters * general fixes * added base path env variable * small fix for arrays * enhancements * design enhancements * general enhancements * fix isRequired * added enum values * enhancements * general fixes * general fixes * changed oas generation script * additions to the introduction section * added copy button for code + other enhancements * fix response code block * fix metadata * formatted store introduction * move sidebar logic to Tags component * added test env variables * fix code block bug * added loading animation * added expand param + loading * enhance operation loading * made responsive + improvements * added loading provider * fixed loading * adjustments for small devices * added sidebar label for endpoints * added feedback component * fixed analytics * general fixes * listen to scroll for other headings * added sample env file * update api ref files + support new fields * fix for external docs link * added new sections * fix last item in sidebar not showing * move docs content to www/docs * change redirect url * revert change * resolve build errors * configure rewrites * changed to environment variable url * revert changing environment variable name * add environment variable for API path * fix links * fix tailwind settings * remove vercel file * reconfigured api route * move api page under api * fix page metadata * fix external link in navigation bar * update api spec * updated api specs * fixed google lint error * add max-height on request samples * add padding before loading * fix for one of name * fix undefined types * general fixes * remove response schema example * redesigned navigation bar * redesigned sidebar * fixed up paddings * added feedback component + report issue * fixed up typography, padding, and general styling * redesigned code blocks * optimization * added error timeout * fixes * added indexing with algolia + fixes * fix errors with algolia script * redesign operation sections * fix heading scroll * design fixes * fix padding * fix padding + scroll issues * fix scroll issues * improve scroll performance * fixes for safari * optimization and fixes * fixes to docs + details animation * padding fixes for code block * added tab animation * fixed incorrect link * added selection styling * fix lint errors * redesigned details component * added detailed feedback form * api reference fixes * fix tabs * upgrade + fixes * updated documentation links * optimizations to sidebar items * fix spacing in sidebar item * optimizations and fixes * fix endpoint path styling * remove margin * final fixes * change margin on small devices * generated OAS * fixes for mobile * added feedback modal * optimize dark mode button * fixed color mode useeffect * minimize dom size * use new style system * radius and spacing design system * design fixes * fix eslint errors * added meta files * change cron schedule * fix docusaurus configurations * added operating system to feedback data * change content directory name * fixes to contribution guidelines * revert renaming content * added api-reference to documentation workflow * fixes for search * added dark mode + fixes * oas fixes * handle bugs * added code examples for clients * changed tooltip text * change authentication to card * change page title based on selected section * redesigned mobile navbar * fix icon colors * fix key colors * fix medusa-js installation command * change external regex in algolia * change changeset * fix padding on mobile * fix hydration error * update depedencies
6.9 KiB
description
| description |
|---|
| Learn how to perform local development in the Medusa monorepo. This includes how to use the dev CLI tool and perform unit, integration, and plugin tests. |
Local Development of Medusa Backend and Monorepo
In this document, you’ll learn how to customize Medusa’s core and run tests.
Overview
As an open-source platform, Medusa’s core can be completely customized.
Whether you want to implement something differently, introduce a new feature as part of Medusa’s core or any of the other packages, or contribute to Medusa, this guide helps you learn how to run Medusa’s integration tests, as well as test your own Medusa core in a local backend.
Medusa Repository Overview
Medusa’s repository on GitHub includes all packages related to Medusa under the packages directory. This includes the core Medusa package, the JS Client, the CLI tools, and much more.
All the packages are part of a Yarn workspace. So, when you run a command in the root of the project, such as yarn build, it goes through all registered packages in the workspace under the packages directory and runs the build command in each of those packages.
Prerequisites
Yarn
When using and developing with the Medusa repository, it’s highly recommended that you use Yarn to avoid any errors or issues.
Fork and Clone Medusa’s Repository
To customize Medusa’s core or contribute to it, you must first fork and then clone the GitHub repository.
Install Dependencies and Build Packages
In the directory of the forked GitHub repository, run the following commands to install necessary dependencies then build all packages in the repository:
yarn install
yarn build
Medusa’s Dev CLI tool
Medusa provides a CLI tool to be used for development. This tool facilitates testing your local installment and changes to Medusa’s core without having to publish the changes to NPM.
To install Medusa’s dev CLI tool:
npm install medusa-dev-cli -g
Set the Location of the Medusa Repository
In the directory of your forked GitHub repository, run the following command to specify to the dev CLI tool the location of your Medusa repository:
medusa-dev --set-path-to-repo `pwd`
Run Tests in the Repository
In this section, you’ll learn how to run tests in the Medusa repository. This is helpful after you customize any of Medusa’s packages and want to make sure everything is still working as expected.
Set System Environment Variables
Before you can run the tests, make sure you set the following system environment variables:
DB_HOST=<YOUR_DB_HOST>
DB_USERNAME=<YOUR_DB_USERNAME>
DB_PASSWORD=<YOUR_PASSWORD>
Run Unit Tests
To run unit tests in all packages in the Medusa repository, run the following command in the root directory of the repository:
yarn test
This runs the test script defined in the package.json file of each package under the packages directory.
Alternatively, if you want to run the unit tests in a specific package, you can run the test command in the directory of that package.
For example, to run the unit tests of the Medusa core:
cd packages/medusa
yarn test
Run API Integration Tests
API integration tests are used to test out Medusa’s core endpoints.
To run the API integration tests, run the following command in the root directory of the repository:
yarn test:integration:api
Run Plugin Integration Tests
Plugin integration tests are used to test out Medusa’s official plugins, which are also stored in the packages directory in the repository.
To run the plugin integration tests, run the following command in the root directory of the repository:
yarn test:integration:plugins
Test in a Local Backend
Using Medusa’s dev CLI tool, you can test any changes you make to Medusa’s packages in a local backend installation. This eliminates the need to publish these packages on NPM publicly to be able to use them.
Medusa’s dev CLI tool scans and finds the Medusa packages used in your Medusa backend. Then, it copies the files of these packages from the packages directory in the Medusa repository into the node_modules directory of your Medusa backend.
:::info
Medusa’s Dev CLI tool uses the path you specified earlier to copy the files of the packages.
:::
Copy Files to Local Backend
To test in a local backend:
- Change to the directory of the backend you want to test your changes in:
cd medusa-backend
2. Run the following command to copy the files from the packages directory of your Medusa repository into node_modules:
medusa-dev
By default, Medusa’s dev CLI runs in watch mode. So, it copies the files when you first run it. Then, whenever you make changes in the dist directory of the packages in the Medusa repository, it copies the changed files again.
Watch and Compile Changes
While the above command is running, it's recommended to run the watch command inside the directory of every package you're making changes to.
The combination of these two commands running at the same time will compile the package into the dist directory of the package, then copy the compiled changes into your local backend.
For example, if you're making changes in the medusa package, run the following command inside the directory of the medusa package:
yarn watch
Make sure the medusa-dev command is also running to copy the changes automatically.
Alternatively, you can manually run the build command every time you want to compile the changes:
yarn build
CLI Options
Here are some options you can use to customize how Medusa’s dev CLI tool works:
--scan-onceor-s: Copies files only one time then stops processing. If you make any changes after running the command with this option, you have to run the command again.
medusa-dev -s
--quietor-q: Disables showing any output.
medusa-dev -q
--packages: Only copies specified packages. It accepts at least one package name. Package names are separated by a space.
medusa-dev --packages @medusajs/medusa-cli medusa-file-minio