-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feat/data-table-medusa-ui
- Loading branch information
Showing
13 changed files
with
313 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@medusajs/admin-vite-plugin": patch | ||
"@medusajs/admin-bundler": patch | ||
"@medusajs/medusa": patch | ||
--- | ||
|
||
feat(admin-bundler,admin-vite-plugin): Support loading loading admin extensions from plugins. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { readFileSync } from "fs" | ||
import { glob } from "glob" | ||
import path from "path" | ||
import { UserConfig } from "vite" | ||
|
||
export async function plugin() { | ||
const vite = await import("vite") | ||
const entries = await glob("src/admin/**/*.{ts,tsx,js,jsx}") | ||
|
||
const entryPoints = entries.reduce((acc, entry) => { | ||
// Convert src/admin/routes/brands/page.tsx -> admin/routes/brands/page | ||
const outPath = entry | ||
.replace(/^src\//, "") | ||
.replace(/\.(ts|tsx|js|jsx)$/, "") | ||
|
||
acc[outPath] = path.resolve(process.cwd(), entry) | ||
return acc | ||
}, {} as Record<string, string>) | ||
|
||
const pkg = JSON.parse( | ||
readFileSync(path.resolve(process.cwd(), "package.json"), "utf-8") | ||
) | ||
const external = new Set([ | ||
...Object.keys(pkg.dependencies || {}), | ||
...Object.keys(pkg.peerDependencies || {}), | ||
"react", | ||
"react-dom", | ||
"react/jsx-runtime", | ||
"react-router-dom", | ||
"@medusajs/admin-sdk", | ||
]) | ||
|
||
const pluginConfig: UserConfig = { | ||
build: { | ||
lib: { | ||
entry: entryPoints, | ||
formats: ["es"], | ||
}, | ||
minify: false, | ||
outDir: path.resolve(process.cwd(), "dist"), | ||
rollupOptions: { | ||
external: [...external], | ||
output: { | ||
globals: { | ||
react: "React", | ||
"react-dom": "React-dom", | ||
"react/jsx-runtime": "react/jsx-runtime", | ||
}, | ||
preserveModules: true, | ||
entryFileNames: `[name].js`, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
await vite.build(pluginConfig) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
import { normalizePath } from "../utils" | ||
import { normalizePath, VALID_FILE_EXTENSIONS } from "../utils" | ||
|
||
export function getRoute(file: string): string { | ||
const importPath = normalizePath(file) | ||
return importPath | ||
.replace(/.*\/admin\/(routes)/, "") | ||
.replace(/\[([^\]]+)\]/g, ":$1") | ||
.replace(/\/page\.(tsx|jsx)/, "") | ||
.replace( | ||
new RegExp( | ||
`/page\\.(${VALID_FILE_EXTENSIONS.map((ext) => ext.slice(1)).join( | ||
"|" | ||
)})$` | ||
), | ||
"" | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.