|
| 1 | +import os from 'node:os'; |
1 | 2 | import fsRoutes from 'fs-routes';
|
2 | 3 | import OpenAPIDefaultSetter from 'openapi-default-setter';
|
3 | 4 | import OpenAPIRequestCoercer from 'openapi-request-coercer';
|
@@ -230,12 +231,20 @@ export default class OpenAPIFramework implements IOpenAPIFramework {
|
230 | 231 | })
|
231 | 232 | .map(async (fsRoutesItem) => {
|
232 | 233 | routesCheckMap[fsRoutesItem.route] = true;
|
233 |
| - // There are two cases to distinguish: |
234 |
| - // - file is a CommonJS script, and `module.export` appears |
235 |
| - // as `default` property |
236 |
| - // - file is a ECMAScript module, and `export default` appears |
237 |
| - // at top-level |
238 |
| - const imported = await import(`file://${fsRoutesItem.path}`); |
| 234 | + /** |
| 235 | + * There are a few cases to distinguish: |
| 236 | + * - file is a CommonJS script, and `module.export` appears |
| 237 | + * as `default` property. |
| 238 | + * - file is a ECMAScript module, and `export default` appears |
| 239 | + * at top-level. |
| 240 | + * - OS is Windows needs absolute path while others support |
| 241 | + * relative paths. |
| 242 | + */ |
| 243 | + let importPath = fsRoutesItem.path; |
| 244 | + if (os.type().includes('Windows')) { |
| 245 | + importPath = `file://${importPath}`; |
| 246 | + } |
| 247 | + const imported = await import(importPath); |
239 | 248 | return {
|
240 | 249 | path: fsRoutesItem.route,
|
241 | 250 | module: imported.default ?? imported,
|
|
0 commit comments