diff --git a/packages/whook-aws-lambda/README.md b/packages/whook-aws-lambda/README.md index 14da3f6f..92cdbc6a 100644 --- a/packages/whook-aws-lambda/README.md +++ b/packages/whook-aws-lambda/README.md @@ -29,7 +29,7 @@ npm i --save-dev @whook/http-transaction babel-loader babel-plugin-knifecycle we ``` Add this module to your Whook plugins and tweak the 2 build functions in your -`index.ts` main file: +`build.ts` main file: ```diff +import { @@ -84,7 +84,7 @@ export async function prepareBuildEnvironment( - // Usually, here you call the installed build env - // $ = await prepareBaseBuildEnvironment($); -+ // Calling the AWS specific build ++ // Calling the AWS specific build env + $ = await prepareBaseBuildEnvironment($); @@ -93,8 +93,7 @@ export async function prepareBuildEnvironment( // remove the need to create an injector $.register( constant('INITIALIZER_PATH_MAP', { - ENV: '@whook/whook/dist/services/ProxyedENV', - apm: '@whook/http-transaction/dist/services/apm', + // (...) obfuscator: '@whook/http-transaction/dist/services/obfuscator', - log: 'common-services/dist/log', + log: '@whook/aws-lambda/dist/services/log', diff --git a/packages/whook-example/bin/build.js b/packages/whook-example/bin/build.js index 8723f087..071a902f 100644 --- a/packages/whook-example/bin/build.js +++ b/packages/whook-example/bin/build.js @@ -1,5 +1,5 @@ #! /usr/bin/env node -const { runBuild } = require('../dist/index'); +const { runBuild } = require('../dist/build'); runBuild(); diff --git a/packages/whook-example/src/build.ts b/packages/whook-example/src/build.ts new file mode 100644 index 00000000..ed59e248 --- /dev/null +++ b/packages/whook-example/src/build.ts @@ -0,0 +1,51 @@ +import Knifecycle, { constant, alsoInject } from 'knifecycle'; +import { initBuildConstants } from '@whook/whook'; +import { prepareEnvironment } from '.'; +import YError from 'yerror'; +import type { Dependencies } from 'knifecycle'; + +// Per convention a Whook server build file must export +// the following 2 functions to be composable: + +// The `runBuild` function is intended to build the +// project +export async function runBuild( + innerPrepareEnvironment = prepareBuildEnvironment, +): Promise { + throw new YError('E_NO_BUILD_IMPLEMENTED'); + + // Usually, here you call the installed build + // return runBaseBuild(innerPrepareEnvironment); +} + +// The `prepareBuildEnvironment` create the build +// environment +export async function prepareBuildEnvironment< + T extends Knifecycle +>($: T = new Knifecycle() as T): Promise { + $ = await prepareEnvironment($); + + // Usually, here you call the installed build env + // $ = await prepareBaseBuildEnvironment($); + + // The build often need to know were initializer + // can be found to create a static build and + // remove the need to create an injector + $.register( + constant('INITIALIZER_PATH_MAP', { + ENV: '@whook/whook/dist/services/ProxyedENV', + apm: '@whook/http-transaction/dist/services/apm', + obfuscator: '@whook/http-transaction/dist/services/obfuscator', + errorHandler: '@whook/http-router/dist/services/errorHandler', + log: 'common-services/dist/log', + time: 'common-services/dist/time', + delay: 'common-services/dist/delay', + }), + ); + + // Finally, some constants can be serialized instead of being + // initialized in the target build saving some time at boot + $.register(alsoInject(['API_DEFINITIONS'], initBuildConstants)); + + return $; +} diff --git a/packages/whook-example/src/index.ts b/packages/whook-example/src/index.ts index cb7a06e3..0d4e6152 100644 --- a/packages/whook-example/src/index.ts +++ b/packages/whook-example/src/index.ts @@ -1,15 +1,13 @@ -import Knifecycle, { constant, alsoInject } from 'knifecycle'; +import Knifecycle, { constant } from 'knifecycle'; import { runServer as runBaseServer, prepareServer as prepareBaseServer, prepareEnvironment as prepareBaseEnvironment, initAutoload, initAPIDefinitions, - initBuildConstants, } from '@whook/whook'; import initHTTPRouter from '@whook/http-router'; import wrapHTTPRouterWithSwaggerUI from '@whook/swagger-ui'; -import YError from 'yerror'; import type { DependencyDeclaration, Dependencies } from 'knifecycle'; // Per convention a Whook server main file must export @@ -85,49 +83,3 @@ export async function prepareEnvironment>( return $; } - -// Additionnally, 2 others functions can be exported -// for building purpose - -// The `runBuild` function is intended to build the -// project -export async function runBuild( - innerPrepareEnvironment = prepareBuildEnvironment, -): Promise { - throw new YError('E_NO_BUILD_IMPLEMENTED'); - - // Usually, here you call the installed build - // return runBaseBuild(innerPrepareEnvironment); -} - -// The `prepareBuildEnvironment` create the build -// environment -export async function prepareBuildEnvironment< - T extends Knifecycle ->($: T = new Knifecycle() as T): Promise { - $ = await prepareEnvironment($); - - // Usually, here you call the installed build env - // $ = await prepareBaseBuildEnvironment($); - - // The build often need to know were initializer - // can be found to create a static build and - // remove the need to create an injector - $.register( - constant('INITIALIZER_PATH_MAP', { - ENV: '@whook/whook/dist/services/ProxyedENV', - apm: '@whook/http-transaction/dist/services/apm', - obfuscator: '@whook/http-transaction/dist/services/obfuscator', - errorHandler: '@whook/http-router/dist/services/errorHandler', - log: 'common-services/dist/log', - time: 'common-services/dist/time', - delay: 'common-services/dist/delay', - }), - ); - - // Finally, some constants can be serialized instead of being - // initialized in the target build saving some time at boot - $.register(alsoInject(['API_DEFINITIONS'], initBuildConstants)); - - return $; -} diff --git a/packages/whook-gcp-functions/README.md b/packages/whook-gcp-functions/README.md index 5dc6b9cf..9128b272 100644 --- a/packages/whook-gcp-functions/README.md +++ b/packages/whook-gcp-functions/README.md @@ -30,7 +30,7 @@ npm i --save-dev @whook/http-transaction babel-loader babel-plugin-knifecycle we ``` Add this module to your Whook plugins and tweak the 2 build functions in your -`index.ts` main file: +`build.ts` main file: ```diff +import { @@ -85,7 +85,7 @@ export async function prepareBuildEnvironment( - // Usually, here you call the installed build env - // $ = await prepareBaseBuildEnvironment($); -+ // Calling the GCP specific build ++ // Calling the GCP specific build env + $ = await prepareBaseBuildEnvironment($); @@ -94,8 +94,7 @@ export async function prepareBuildEnvironment( // remove the need to create an injector $.register( constant('INITIALIZER_PATH_MAP', { - ENV: '@whook/whook/dist/services/ProxyedENV', - apm: '@whook/http-transaction/dist/services/apm', + // (...) obfuscator: '@whook/http-transaction/dist/services/obfuscator', - log: 'common-services/dist/log', + log: '@whook/gcp-functions/dist/services/log', @@ -130,7 +129,7 @@ const CONFIG: AppConfigs = { + ignoredModules: [], + extensions: ['.ts', '.js', '.json'], + mainFields: ['browser', 'main'], -+ target: '12.13', ++ target: '12', + }, }; diff --git a/packages/whook-swagger-ui/src/__snapshots__/index.test.ts.snap b/packages/whook-swagger-ui/src/__snapshots__/index.test.ts.snap index 9837d595..c6757b96 100644 --- a/packages/whook-swagger-ui/src/__snapshots__/index.test.ts.snap +++ b/packages/whook-swagger-ui/src/__snapshots__/index.test.ts.snap @@ -197,7 +197,7 @@ Object { Swagger UI - +