Skip to content

Commit

Permalink
fix(admin-vite-plugin): ensure forward slashes are used for paths (#8023
Browse files Browse the repository at this point in the history
)
  • Loading branch information
kasperkristensen authored Jul 9, 2024
1 parent 273529f commit d46f9fd
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions packages/admin-next/admin-vite-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@ import {

const VALID_FILE_EXTENSIONS = [".tsx", ".jsx"]

function convertToImportPath(file: string) {
return path.normalize(file).split(path.sep).join("/")
}

/**
* Returns the module type of a given file.
*/
function getModuleType(file: string) {
const normalizedPath = path.normalize(file)
const normalizedPath = convertToImportPath(file)

if (normalizedPath.includes(path.normalize("/admin/widgets/"))) {
if (normalizedPath.includes("/admin/widgets/")) {
return "widget"
} else if (normalizedPath.includes(path.normalize("/admin/routes/"))) {
} else if (normalizedPath.includes("/admin/routes/")) {
return "route"
} else {
return "none"
Expand Down Expand Up @@ -331,7 +335,10 @@ async function generateWidgetEntrypoint(
}

const importString = validatedWidgets
.map((path, index) => `import WidgetExt${index} from "${path}";`)
.map(
(path, index) =>
`import WidgetExt${index} from "${convertToImportPath(path)}";`
)
.join("\n")

const exportString = `export default {
Expand Down Expand Up @@ -416,7 +423,9 @@ async function validateRoute(file: string, resolveMenuItem = false) {
}

function createRoutePath(file: string) {
return file
const importPath = convertToImportPath(file)

return importPath
.replace(/.*\/admin\/(routes|settings)/, "")
.replace(/\[([^\]]+)\]/g, ":$1")
.replace(/\/page\.(tsx|jsx)/, "")
Expand Down Expand Up @@ -454,8 +463,10 @@ async function generateRouteEntrypoint(
const importString = validatedRoutes
.map((path, index) => {
return type === "page"
? `import RouteExt${index} from "${path}";`
: `import { config as routeConfig${index} } from "${path}";`
? `import RouteExt${index} from "${convertToImportPath(path)}";`
: `import { config as routeConfig${index} } from "${convertToImportPath(
path
)}";`
})
.join("\n")

Expand Down

0 comments on commit d46f9fd

Please sign in to comment.