Skip to content

Commit

Permalink
fix(@whook/whook): fix definition autoload ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Mar 26, 2020
1 parent 9b9eccc commit 55f2e0a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/whook-cli/src/commands/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export const definition: WhookCommandDefinition = {
},
};

export default extra(definition, autoService(initConfigCommand));
export default extra(definition, autoService(initInspectCommand));

async function initConfigCommand({
async function initInspectCommand({
$injector,
promptArgs,
log = noop,
Expand Down
2 changes: 1 addition & 1 deletion packages/whook-example/src/__snapshots__/cli.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Object {
- create: A command helping to create new Whook files easily
- env: A command printing env values
- handler: Runs the given server handler for testing purpose
- config: A simple program that returns the result of the injected service
- inspect: A simple program that returns the result of the injected service
- ls: Print available commands
Expand Down
10 changes: 8 additions & 2 deletions packages/whook-example/src/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ Object {
"💿 - Loading getOpenAPIWrapped initializer from /home/whoiam/projects/whook/packages/whook-example/src/handlers/getOpenAPI.ts.",
],
Array [
"💿 - Loading getPingWrapped initializer from /home/whoiam/projects/whook/packages/whook-example/src/handlers/getPing.ts.",
"💿 - Loading getPingWrapped initializer from /home/whoiam/projects/whook/dist/handlers/getPing.js.",
],
Array [
"💿 - Loading getTimeWrapped initializer from /home/whoiam/projects/whook/packages/whook-example/src/handlers/getTime.ts.",
Expand Down Expand Up @@ -241,7 +241,7 @@ Object {
"💿 - Service \\"getOpenAPIWrapped\\" found in: /home/whoiam/projects/whook/packages/whook-example/src/handlers/getOpenAPI.ts",
],
Array [
"💿 - Service \\"getPingWrapped\\" found in: /home/whoiam/projects/whook/packages/whook-example/src/handlers/getPing.ts",
"💿 - Service \\"getPingWrapped\\" found in: /home/whoiam/projects/whook/dist/handlers/getPing.js",
],
Array [
"💿 - Service \\"getTimeWrapped\\" found in: /home/whoiam/projects/whook/packages/whook-example/src/handlers/getTime.ts",
Expand Down Expand Up @@ -501,6 +501,12 @@ Object {
Array [
"🚫 - Service \\"TIMEOUT\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/TIMEOUT",
],
Array [
"🚫 - Service \\"getPingWrapped\\" not found in: /home/whoiam/projects/whook/packages/whook-cli/dist/handlers/getPing",
],
Array [
"🚫 - Service \\"getPingWrapped\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/handlers/getPing",
],
Array [
"🚫 - Service \\"readDir\\" not found in: /home/whoiam/projects/whook/dist/services/readDir",
],
Expand Down
5 changes: 3 additions & 2 deletions packages/whook-example/src/handlers/getOpenAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import {
getOpenAPIDefinition as baseGetOpenAPIDefinition,
} from '@whook/swagger-ui';

// TODO: Use WHOOK_PLUGINS to get handlers from plugins
// instead of proxying here
// We could use WHOOK_PLUGINS to get handlers from plugins
// instead of proxying here, but we want to ensure the
// endpoint is reachable with a token too

export const definition = {
...baseGetOpenAPIDefinition,
Expand Down
4 changes: 0 additions & 4 deletions packages/whook-example/src/handlers/getPing.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/whook-example/src/services/API.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('API', () => {
beforeAll(async () => {
API_DEFINITIONS = await initAPIDefinitions({
PROJECT_SRC: path.join(__dirname, '..'),
WHOOK_PLUGINS_PATHS: [path.dirname(require.resolve('@whook/whook/dist'))],
});
});

Expand Down
7 changes: 5 additions & 2 deletions packages/whook/src/services/API_DEFINITIONS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ async function initAPIDefinitions({
PROJECT_SRC,
...WHOOK_PLUGINS_PATHS,
].reduce(async (accHandlersModulesPromise, currentPath) => {
// We need to await previous modules here to ensure the
// `seenFiles` variable is completed in order
const accHandlersModules = await accHandlersModulesPromise;
let files;

try {
Expand All @@ -113,7 +116,7 @@ async function initAPIDefinitions({
// throw only if the root plugin dir doesn't exists
if (err.code === 'E_BAD_DIR') {
try {
await readDir(path.join(currentPath));
await readDir(currentPath);
} catch (err) {
throw new YError('E_BAD_PLUGIN_DIR');
}
Expand Down Expand Up @@ -143,7 +146,7 @@ async function initAPIDefinitions({
.map(file => path.join(currentPath, 'handlers', file))
.map(file => (require(file) as unknown) as WhookAPIHandlerModule);

return [...(await accHandlersModulesPromise), ...currentHandlersModules];
return [...accHandlersModules, ...currentHandlersModules];
}, Promise.resolve([]));

const API_DEFINITIONS = {
Expand Down

0 comments on commit 55f2e0a

Please sign in to comment.