Skip to content

Commit

Permalink
fix: unique imports in #nitro-internal-virtual/server-handlers-meta
Browse files Browse the repository at this point in the history
  • Loading branch information
ZerxZ committed Dec 17, 2024
1 parent f982f99 commit f707298
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions src/rollup/plugins/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,49 +65,52 @@ export function handlers(nitro: Nitro) {

const code = /* js */ `
${imports
.map((handler) => `import ${getImportId(handler)} from '${handler}';`)
.join("\n")}
.map((handler) => `import ${getImportId(handler)} from '${handler}';`)
.join("\n")}
${lazyImports
.map(
(handler) =>
`const ${getImportId(handler, true)} = () => import('${handler}');`
)
.join("\n")}
.map(
(handler) =>
`const ${getImportId(handler, true)} = () => import('${handler}');`
)
.join("\n")}
export const handlers = [
${handlers
.map(
(h) =>
` { route: '${h.route || ""}', handler: ${getImportId(
h.handler,
h.lazy
)}, lazy: ${!!h.lazy}, middleware: ${!!h.middleware}, method: ${JSON.stringify(
h.method?.toLowerCase()
)} }`
)
.join(",\n")}
.map(
(h) =>
` { route: '${h.route || ""}', handler: ${getImportId(
h.handler,
h.lazy
)}, lazy: ${!!h.lazy}, middleware: ${!!h.middleware}, method: ${JSON.stringify(
h.method?.toLowerCase()
)} }`
)
.join(",\n")}
];
`.trim();
return code;
},
"#nitro-internal-virtual/server-handlers-meta": () => {
const handlers = getHandlers();
const imports = unique(
handlers.map((h) => h.handler)
);
return /* js */ `
${handlers
.map(
(h) => `import ${getImportId(h.handler)}Meta from "${h.handler}?meta";`
)
.join("\n")}
${imports
.map(
(handler) => `import ${getImportId(handler)}Meta from "${handler}?meta";`
)
.join("\n")}
export const handlersMeta = [
${handlers
.map(
(h) =>
.map(
(h) =>
/* js */ `{ route: ${JSON.stringify(h.route)}, method: ${JSON.stringify(
h.method?.toLowerCase()
)}, meta: ${getImportId(h.handler)}Meta }`
)
.join(",\n")}
h.method?.toLowerCase()
)}, meta: ${getImportId(h.handler)}Meta }`
)
.join(",\n")}
];
`;
},
Expand Down

0 comments on commit f707298

Please sign in to comment.