Skip to content

Commit

Permalink
Add support for CJS imports in generate (#179)
Browse files Browse the repository at this point in the history
This adds a fallback for importing the modules
as CJS modules if importing the ESM default
export leads to undefined.
  • Loading branch information
blomqma authored Aug 27, 2024
1 parent 8807476 commit 4528c55
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/next-rest-framework/src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const findConfig = async ({ configPath }: { configPath?: string }) => {
const filePathToRoute = join(process.cwd(), path, route);

const url = new URL(`file://${filePathToRoute}`).toString();
const res = await import(url).then((mod) => mod.default);
const res = await import(url).then((mod) => mod.default || mod);

const handlers: any[] = Object.entries(res)
.filter(([key]) => isValidMethod(key))
Expand Down Expand Up @@ -118,7 +118,7 @@ export const findConfig = async ({ configPath }: { configPath?: string }) => {
const filePathToRoute = join(process.cwd(), path, route);

const url = new URL(`file://${filePathToRoute}`).toString();
const res = await import(url).then((mod) => mod.default);
const res = await import(url).then((mod) => mod.default || mod);

const _config = res.default._nextRestFrameworkConfig;

Expand Down Expand Up @@ -310,7 +310,7 @@ export const generatePathsFromBuild = async ({
const filePathToRoute = join(process.cwd(), path, route);

const url = new URL(`file://${filePathToRoute}`).toString();
const res = await import(url).then((mod) => mod.default);
const res = await import(url).then((mod) => mod.default || mod);

const handlers: any[] = Object.entries(res)
.filter(([key]) => isValidMethod(key))
Expand Down Expand Up @@ -359,7 +359,7 @@ export const generatePathsFromBuild = async ({
const filePathToRoute = join(process.cwd(), path, apiRoute);

const url = new URL(`file://${filePathToRoute}`).toString();
const res = await import(url).then((mod) => mod.default);
const res = await import(url).then((mod) => mod.default || mod);

const isDocsHandler = !!res.default._nextRestFrameworkConfig;

Expand Down

0 comments on commit 4528c55

Please sign in to comment.