@medusajs/admin-vite-plugin 2.22.0-snapshot-20261020204851 → 2.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +62 -0
- package/README.md +56 -1
- package/package.json +7 -3
package/AGENTS.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# @medusajs/admin-vite-plugin
|
|
2
|
+
|
|
3
|
+
Vite plugin that scans the `src/admin` directories of a Medusa app and its plugins and turns them into the `virtual:medusa/*` modules that `@medusajs/dashboard` imports (routes, menu items, widgets, layouts, i18n, custom fields, cell renderers, search entities).
|
|
4
|
+
|
|
5
|
+
## Using this package
|
|
6
|
+
|
|
7
|
+
App developers don't configure it: `@medusajs/admin-bundler` adds it with `sources` = every admin source directory. Options (`MedusaVitePluginOptions`):
|
|
8
|
+
|
|
9
|
+
- `sources?: string[]`: absolute paths to `src/admin` directories.
|
|
10
|
+
- `pluginMode?: boolean`: used by `medusa plugin:build`. It writes `src/admin/__admin-extensions__.js` in `buildStart` (re-exporting every generated module as one default `plugin` object) and deletes it in `buildEnd`.
|
|
11
|
+
|
|
12
|
+
What it picks up, relative to each source:
|
|
13
|
+
|
|
14
|
+
| Path | Requirement |
|
|
15
|
+
| --- | --- |
|
|
16
|
+
| `widgets/**` | default export + `export const config = defineWidgetConfig({ zone })` |
|
|
17
|
+
| `routes/**/page.{tsx,jsx,ts,js}` (depth >= 1) | default export; optional `config`, `handle`, `loader` |
|
|
18
|
+
| `layouts/**` | default export + `config` named export |
|
|
19
|
+
| `i18n/index.*` (top level only) | default export; multiple sources are `deepMerge`d |
|
|
20
|
+
| `custom-fields/**` | experimental custom-fields config |
|
|
21
|
+
| `cell-renderers.tsx`, `search-entities.tsx` or `search-entities.ts` | imported for side effects |
|
|
22
|
+
|
|
23
|
+
Route path mapping (`routes/helpers.ts`):
|
|
24
|
+
- `[id]` becomes `:id`, `[[id]]` becomes `:id?`, `(foo)` becomes `foo?`, `[*]` becomes `*`, `[[*]]` becomes `*?`.
|
|
25
|
+
- A folder starting with `@` is a parallel route, added as a child of its parent path with the `@` removed.
|
|
26
|
+
|
|
27
|
+
## Architecture
|
|
28
|
+
|
|
29
|
+
- `src/plugin.ts`:
|
|
30
|
+
- `resolveId` / `load` serve the virtual modules.
|
|
31
|
+
- In dev, a watcher computes a content hash per admin subdirectory and reloads only the virtual modules whose hash changed.
|
|
32
|
+
- `src/<feature>/`: one folder per extension type, each with `generate-*.ts` (code generation) and `generate-*-hash.ts` (change detection).
|
|
33
|
+
- `src/virtual-modules/`: assembles generated code into modules. Each generator takes `pluginMode` and emits `const xModule = ...` instead of `export default` so plugin mode can concatenate them.
|
|
34
|
+
- `src/utils.ts`:
|
|
35
|
+
- `crawl` (fdir) skips directories starting with `_`.
|
|
36
|
+
- `getConfigObjectProperties` handles both unbundled (`ExportNamedDeclaration`) and bundled (`VariableDeclarator`) shapes, because plugin output is re-parsed when the host app builds.
|
|
37
|
+
- `src/vmod.ts`: virtual and resolved (`\0`-prefixed) ids, built from `@medusajs/admin-shared`.
|
|
38
|
+
|
|
39
|
+
## Development
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
yarn build # tsup (cjs + esm)
|
|
43
|
+
yarn watch
|
|
44
|
+
yarn test # vitest --run
|
|
45
|
+
yarn test src/widgets/__tests__/generate-widgets.spec.ts
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Specs live in `src/<feature>/__tests__/`. They mock the filesystem and compare generated code with `normalizeString` (whitespace-insensitive).
|
|
49
|
+
|
|
50
|
+
## Gotchas
|
|
51
|
+
|
|
52
|
+
- All extraction is static (Babel AST). Values computed at runtime (variables, template literals, spreads for `zone`) are ignored with a `logger.warn` and the extension is silently dropped.
|
|
53
|
+
- `getParserOptions` enables the `typescript` Babel plugin only for `.tsx`. A `.ts` widget, route, or layout file containing type syntax fails to parse and is skipped.
|
|
54
|
+
- Widget ids default to `Widget-<4-char md5>` of the path from `widgets/` onward, so they are stable across machines but change when the file moves. Saved user layouts are keyed by this id.
|
|
55
|
+
- Unknown zones pass validation (`isValidInjectionZone` only warns), so custom zones from plugins work without registration here.
|
|
56
|
+
- When adding a new extension type, update all of these:
|
|
57
|
+
- the virtual id in `@medusajs/admin-shared`
|
|
58
|
+
- `vmod.ts`
|
|
59
|
+
- `loadConfigs` and `watcherConfigs` in `plugin.ts`
|
|
60
|
+
- `ADMIN_SUBDIRECTORIES` in `utils.ts`
|
|
61
|
+
- `generatePluginEntryModule`
|
|
62
|
+
- the dashboard's `tsup.config.cjs` externals
|
package/README.md
CHANGED
|
@@ -1 +1,56 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://www.medusajs.com">
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/59018053/229103275-b5e482bb-4601-46e6-8142-244f531cebdb.svg">
|
|
5
|
+
<source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
|
|
6
|
+
<img alt="Medusa logo" src="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
|
|
7
|
+
</picture>
|
|
8
|
+
</a>
|
|
9
|
+
</p>
|
|
10
|
+
<h1 align="center">
|
|
11
|
+
@medusajs/admin-vite-plugin
|
|
12
|
+
</h1>
|
|
13
|
+
|
|
14
|
+
<h4 align="center">
|
|
15
|
+
<a href="https://docs.medusajs.com">Documentation</a> |
|
|
16
|
+
<a href="https://www.medusajs.com">Website</a>
|
|
17
|
+
</h4>
|
|
18
|
+
|
|
19
|
+
<p align="center">
|
|
20
|
+
Building blocks for digital commerce
|
|
21
|
+
</p>
|
|
22
|
+
<p align="center">
|
|
23
|
+
<a href="https://github.com/medusajs/medusa/blob/develop/LICENSE">
|
|
24
|
+
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="Medusa is released under the MIT license." />
|
|
25
|
+
</a>
|
|
26
|
+
<a href="https://github.com/medusajs/medusa/blob/develop/CONTRIBUTING.md">
|
|
27
|
+
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" alt="PRs welcome!" />
|
|
28
|
+
</a>
|
|
29
|
+
<a href="https://discord.gg/xpCwq3Kfn8">
|
|
30
|
+
<img src="https://img.shields.io/badge/chat-on%20discord-7289DA.svg" alt="Discord Chat" />
|
|
31
|
+
</a>
|
|
32
|
+
<a href="https://twitter.com/intent/follow?screen_name=medusajs">
|
|
33
|
+
<img src="https://img.shields.io/twitter/follow/medusajs.svg?label=Follow%20@medusajs" alt="Follow @medusajs" />
|
|
34
|
+
</a>
|
|
35
|
+
</p>
|
|
36
|
+
|
|
37
|
+
Vite plugin for the Medusa Admin dashboard: finds admin extensions (widgets, UI routes, custom fields, layouts, translations, and more) under `src/admin` in a Medusa application or plugin and loads them into the dashboard. It's internal plumbing used by `@medusajs/admin-bundler` and the `@medusajs/dashboard` dev server, so you don't need to install or configure it in a Medusa application.
|
|
38
|
+
|
|
39
|
+
## At a glance
|
|
40
|
+
|
|
41
|
+
| | |
|
|
42
|
+
|---|---|
|
|
43
|
+
| Package | `@medusajs/admin-vite-plugin` |
|
|
44
|
+
| Type | Internal tooling |
|
|
45
|
+
| Import from | `@medusajs/admin-vite-plugin` (default export) |
|
|
46
|
+
|
|
47
|
+
## Configuration
|
|
48
|
+
|
|
49
|
+
| Option | Type | Description | Default |
|
|
50
|
+
|---|---|---|---|
|
|
51
|
+
| `sources` | `string[]` | Paths of the Medusa application or plugin directories to load admin extensions from. | `[]` |
|
|
52
|
+
| `pluginMode` | `boolean` | Build extensions for a Medusa plugin instead of an application. | `false` |
|
|
53
|
+
|
|
54
|
+
## Resources
|
|
55
|
+
|
|
56
|
+
- [Admin Development](https://docs.medusajs.com/learn/fundamentals/admin)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medusajs/admin-vite-plugin",
|
|
3
|
-
"version": "2.22.0
|
|
3
|
+
"version": "2.22.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,8 +21,12 @@
|
|
|
21
21
|
},
|
|
22
22
|
"files": [
|
|
23
23
|
"dist",
|
|
24
|
-
"package.json"
|
|
24
|
+
"package.json",
|
|
25
|
+
"AGENTS.md"
|
|
25
26
|
],
|
|
27
|
+
"llms": "https://docs.medusajs.com/llms.txt",
|
|
28
|
+
"llmsFull": "https://docs.medusajs.com/llms-full.txt",
|
|
29
|
+
"mcpServer": "https://docs.medusajs.com/mcp",
|
|
26
30
|
"scripts": {
|
|
27
31
|
"build": "yarn run -T tsup",
|
|
28
32
|
"watch": "yarn run -T tsup --watch",
|
|
@@ -39,7 +43,7 @@
|
|
|
39
43
|
"@babel/parser": "7.25.6",
|
|
40
44
|
"@babel/traverse": "7.25.6",
|
|
41
45
|
"@babel/types": "7.25.6",
|
|
42
|
-
"@medusajs/admin-shared": "2.22.0
|
|
46
|
+
"@medusajs/admin-shared": "2.22.0",
|
|
43
47
|
"fdir": "6.1.1",
|
|
44
48
|
"magic-string": "0.30.5",
|
|
45
49
|
"outdent": "^0.8.0",
|