-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: ability to use underscore file for handler
- Loading branch information
1 parent
56e69b6
commit 55b7f12
Showing
4 changed files
with
63 additions
and
2 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,5 @@ | ||
--- | ||
"@oamerge/generator-routes": patch | ||
--- | ||
|
||
Add ability to use underscore file for handler. |
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
44 changes: 44 additions & 0 deletions
44
packages/generator-routes/tests/handler-in-different-file.md
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,44 @@ | ||
A default export in an underscore file will override the method file handler. | ||
|
||
```js #config | ||
return { | ||
cwd: '/root', | ||
outputDir: './build', | ||
inputs: [ | ||
{ | ||
dir: 'folder1', | ||
ext: '@', | ||
api: '/v1', | ||
files: { | ||
'paths/hello/get.@.js': { | ||
key: [ 'paths', 'hello', 'get' ], | ||
exports: { | ||
default: _ => _, | ||
}, | ||
}, | ||
'paths/hello/get/_.@.js': { | ||
key: [ 'paths', 'hello', 'get', '_' ], | ||
exports: { | ||
default: _ => _, | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
} | ||
``` | ||
|
||
Because the underscore file is more specific, that handler is used instead of the first. | ||
|
||
```js #expected | ||
import handler_0 from "../folder1/paths/hello/get/_.@.js" | ||
|
||
export const routes = [ | ||
{ | ||
path: "/v1/hello", | ||
method: "get", | ||
handler: handler_0, | ||
}, | ||
] | ||
|
||
``` |