@gasket/plugin-fastify 7.5.1 → 7.5.3
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.
- package/cjs/create-servers.cjs +14 -7
- package/cjs/create.cjs +3 -3
- package/lib/create-servers.js +18 -9
- package/lib/create.js +3 -3
- package/package.json +6 -7
package/cjs/create-servers.cjs
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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.
|
|
24
|
-
|
|
25
|
-
|
|
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) {
|
package/cjs/create.cjs
CHANGED
|
@@ -20,8 +20,8 @@ function _interop_require_default(obj) {
|
|
|
20
20
|
default: obj
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
const
|
|
24
|
-
const
|
|
23
|
+
const fileName = (0, _url.fileURLToPath)(require("url").pathToFileURL(__filename).toString());
|
|
24
|
+
const dirName = (0, _path.dirname)(fileName);
|
|
25
25
|
const { name, version, devDependencies } = _packagejson.default;
|
|
26
26
|
const createTestFiles = ({ files, generatorDir, testPlugins, globIgnore })=>{
|
|
27
27
|
if (!testPlugins || testPlugins.length === 0) return;
|
|
@@ -52,7 +52,7 @@ const createTestFiles = ({ files, generatorDir, testPlugins, globIgnore })=>{
|
|
|
52
52
|
};
|
|
53
53
|
async function create(gasket, context) {
|
|
54
54
|
const { files, typescript, apiApp, addApiRoutes = true, testPlugins, pkg, gasketConfig } = context;
|
|
55
|
-
const generatorDir = `${
|
|
55
|
+
const generatorDir = `${dirName}/../generator`;
|
|
56
56
|
gasketConfig.addPlugin('pluginFastify', name);
|
|
57
57
|
pkg.add('dependencies', {
|
|
58
58
|
[name]: `^${version}`,
|
package/lib/create-servers.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
app.use
|
|
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/lib/create.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
5
|
import { dirname } from 'path';
|
|
6
6
|
import packageJson from '../package.json' with { type: 'json' };
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const fileName = fileURLToPath(import.meta.url);
|
|
8
|
+
const dirName = dirname(fileName);
|
|
9
9
|
const { name, version, devDependencies } = packageJson;
|
|
10
10
|
|
|
11
11
|
const createTestFiles = ({ files, generatorDir, testPlugins, globIgnore }) => {
|
|
@@ -42,7 +42,7 @@ export default async function create(gasket, context) {
|
|
|
42
42
|
pkg,
|
|
43
43
|
gasketConfig
|
|
44
44
|
} = context;
|
|
45
|
-
const generatorDir = `${
|
|
45
|
+
const generatorDir = `${dirName}/../generator`;
|
|
46
46
|
|
|
47
47
|
gasketConfig.addPlugin('pluginFastify', name);
|
|
48
48
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gasket/plugin-fastify",
|
|
3
|
-
"version": "7.5.
|
|
3
|
+
"version": "7.5.3",
|
|
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.
|
|
44
|
-
"@gasket/core": "^7.7.
|
|
45
|
-
"@gasket/plugin-https": "^7.4.
|
|
42
|
+
"@gasket/cjs": "^7.1.1",
|
|
43
|
+
"@gasket/core": "^7.7.3",
|
|
44
|
+
"@gasket/plugin-https": "^7.4.1",
|
|
46
45
|
"@gasket/plugin-logger": "^7.4.0",
|
|
47
|
-
"@gasket/plugin-metadata": "^7.5.
|
|
48
|
-
"create-gasket-app": "^7.4.
|
|
46
|
+
"@gasket/plugin-metadata": "^7.5.9",
|
|
47
|
+
"create-gasket-app": "^7.4.19"
|
|
49
48
|
},
|
|
50
49
|
"peerDependencies": {
|
|
51
50
|
"fastify": "^4.29.1"
|