@gasket/plugin-fastify 7.5.1 → 7.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,8 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  Object.defineProperty(exports, /**
7
7
  * Create the Fastify instance and setup the lifecycle hooks.
8
- * Fastify is compatible with express middleware out of the box, so we can
9
- * use the same middleware lifecycles.
8
+ * Fastify is compatible with express middleware when @fastify/express is installed.
10
9
  * @type {import('@gasket/core').HookHandler<'createServers'>}
11
10
  */ "default", {
12
11
  enumerable: true,
@@ -16,14 +15,22 @@ Object.defineProperty(exports, /**
16
15
  });
17
16
  const _utils = require("./utils.cjs");
18
17
  async function createServers(gasket, serverOpts) {
19
- /** Cast to Fastify + Express hybrid because Gasket adds `.use()` via @fastify/express plugin */ const app = /** @type {import('fastify').FastifyInstance & { use: Function }} */ (0, _utils.getAppInstance)(gasket);
18
+ const app = (0, _utils.getAppInstance)(gasket);
20
19
  // allow consuming apps to directly append options to their server
21
20
  await gasket.exec('fastify', app);
22
21
  const postRenderingStacks = (await gasket.exec('errorMiddleware')).filter(Boolean);
23
- postRenderingStacks.forEach((stack)=>{
24
- /** @type {import('connect').NextHandleFunction} */ const middleware = stack;
25
- app.use(middleware);
26
- });
22
+ if (postRenderingStacks.length > 0) {
23
+ // app.use() is added by @fastify/express when registered via @gasket/plugin-middleware
24
+ // @ts-expect-error
25
+ if (typeof app.use !== 'function') {
26
+ throw new Error('errorMiddleware requires @fastify/express to be installed and registered. ' + 'Install @fastify/express and ensure @gasket/plugin-middleware is configured.');
27
+ }
28
+ postRenderingStacks.forEach((stack)=>{
29
+ /** @type {import('connect').NextHandleFunction} */ const middleware = stack;
30
+ // @ts-expect-error
31
+ app.use(middleware);
32
+ });
33
+ }
27
34
  return {
28
35
  ...serverOpts,
29
36
  handler: async function handler(...args) {
@@ -5,23 +5,32 @@ import { getAppInstance } from './utils.js';
5
5
 
6
6
  /**
7
7
  * Create the Fastify instance and setup the lifecycle hooks.
8
- * Fastify is compatible with express middleware out of the box, so we can
9
- * use the same middleware lifecycles.
8
+ * Fastify is compatible with express middleware when @fastify/express is installed.
10
9
  * @type {import('@gasket/core').HookHandler<'createServers'>}
11
10
  */
12
11
  export default async function createServers(gasket, serverOpts) {
13
- /** Cast to Fastify + Express hybrid because Gasket adds `.use()` via @fastify/express plugin */
14
- const app = /** @type {import('fastify').FastifyInstance & { use: Function }} */ (getAppInstance(gasket));
12
+ const app = getAppInstance(gasket);
15
13
 
16
14
  // allow consuming apps to directly append options to their server
17
15
  await gasket.exec('fastify', app);
18
16
 
19
17
  const postRenderingStacks = (await gasket.exec('errorMiddleware')).filter(Boolean);
20
- postRenderingStacks.forEach((stack) => {
21
- /** @type {import('connect').NextHandleFunction} */
22
- const middleware = stack;
23
- app.use(middleware);
24
- });
18
+ if (postRenderingStacks.length > 0) {
19
+ // app.use() is added by @fastify/express when registered via @gasket/plugin-middleware
20
+ // @ts-expect-error
21
+ if (typeof app.use !== 'function') {
22
+ throw new Error(
23
+ 'errorMiddleware requires @fastify/express to be installed and registered. ' +
24
+ 'Install @fastify/express and ensure @gasket/plugin-middleware is configured.'
25
+ );
26
+ }
27
+ postRenderingStacks.forEach((stack) => {
28
+ /** @type {import('connect').NextHandleFunction} */
29
+ const middleware = stack;
30
+ // @ts-expect-error
31
+ app.use(middleware);
32
+ });
33
+ }
25
34
 
26
35
  return {
27
36
  ...serverOpts,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gasket/plugin-fastify",
3
- "version": "7.5.1",
3
+ "version": "7.5.2",
4
4
  "description": "Adds fastify support to your application",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -33,19 +33,18 @@
33
33
  "bugs": "https://github.com/godaddy/gasket/issues",
34
34
  "homepage": "https://github.com/godaddy/gasket/tree/main/packages/gasket-plugin-fastify",
35
35
  "dependencies": {
36
- "@fastify/express": "^3.0.0",
37
36
  "fastify": "^4.29.1"
38
37
  },
39
38
  "devDependencies": {
40
39
  "@types/connect": "^3.4.38",
41
40
  "fastify": "^4.29.1",
42
41
  "vitest": "^3.2.0",
43
- "@gasket/cjs": "^7.1.0",
44
- "@gasket/core": "^7.7.1",
42
+ "@gasket/core": "^7.7.2",
45
43
  "@gasket/plugin-https": "^7.4.0",
46
44
  "@gasket/plugin-logger": "^7.4.0",
47
- "@gasket/plugin-metadata": "^7.5.7",
48
- "create-gasket-app": "^7.4.17"
45
+ "@gasket/plugin-metadata": "^7.5.8",
46
+ "create-gasket-app": "^7.4.18",
47
+ "@gasket/cjs": "^7.1.1"
49
48
  },
50
49
  "peerDependencies": {
51
50
  "fastify": "^4.29.1"