Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodenext compatibility #355

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,3 +761,5 @@ module.exports = fp(fastifyView, {
fastify: '4.x',
name: '@fastify/view'
})
module.exports.default = fastifyView
module.exports.fastifyView = fastifyView
6 changes: 3 additions & 3 deletions types/index-global-layout.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fastify from "fastify";
import pointOfView, { PointOfViewOptions } from "..";
import fastifyView, { FastifyViewOptions } from "..";
import { expectAssignable } from "tsd";
import * as path from "path";

Expand All @@ -14,7 +14,7 @@ declare module "fastify" {
}
const app = fastify();

app.register(pointOfView, {
app.register(fastifyView, {
engine: {
ejs: require("ejs"),
},
Expand Down Expand Up @@ -61,4 +61,4 @@ app.listen({port: 3000}, (err, address) => {
console.log(`server listening on ${address} ...`)
})

expectAssignable<PointOfViewOptions>({ engine: { twig: require('twig') }, propertyName: 'mobile' })
expectAssignable<FastifyViewOptions>({ engine: { twig: require('twig') }, propertyName: 'mobile' })
64 changes: 38 additions & 26 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,43 @@ declare module "fastify" {
}
}

export interface PointOfViewOptions {
engine: {
ejs?: any;
eta?: any;
nunjucks?: any;
pug?: any;
handlebars?: any;
mustache?: any;
'art-template'?: any;
twig?: any;
liquid?: any;
dot?: any;
};
templates?: string;
includeViewExtension?: boolean;
options?: object;
charset?: string;
maxCache?: number;
production?: boolean;
defaultContext?: object;
layout?: string;
root?: string;
viewExt?: string;
propertyName?: string;
type FastifyView = FastifyPluginCallback<fastifyView.FastifyViewOptions>

declare namespace fastifyView {
export interface FastifyViewOptions {
engine: {
ejs?: any;
eta?: any;
nunjucks?: any;
pug?: any;
handlebars?: any;
mustache?: any;
'art-template'?: any;
twig?: any;
liquid?: any;
dot?: any;
};
templates?: string;
includeViewExtension?: boolean;
options?: object;
charset?: string;
maxCache?: number;
production?: boolean;
defaultContext?: object;
layout?: string;
root?: string;
viewExt?: string;
propertyName?: string;
}

/**
* @deprecated Use FastifyViewOptions
*/
export type PointOfViewOptions = FastifyViewOptions

export const fastifyView: FastifyView
export { fastifyView as default }
}

declare const pointOfView: FastifyPluginCallback<PointOfViewOptions>;
export default pointOfView;
declare function fastifyView(...params: Parameters<FastifyView>): ReturnType<FastifyView>
export = fastifyView
10 changes: 6 additions & 4 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fastify from "fastify";
import pointOfView, { PointOfViewOptions } from "..";
import { expectAssignable, expectType } from "tsd";
import fastifyView, { PointOfViewOptions, FastifyViewOptions } from "..";
import { expectAssignable, expectDeprecated, expectType } from "tsd";
import * as path from "path";

interface Locals {
Expand All @@ -14,7 +14,7 @@ declare module "fastify" {
}
const app = fastify();

app.register(pointOfView, {
app.register(fastifyView, {
engine: {
ejs: require("ejs"),
},
Expand Down Expand Up @@ -66,4 +66,6 @@ app.listen({port: 3000}, (err, address) => {

expectType<Promise<string>>(app.view("/index", {}, { layout: "/layout-ts"}))

expectAssignable<PointOfViewOptions>({ engine: { twig: require('twig') }, propertyName: 'mobile' })
expectAssignable<FastifyViewOptions>({ engine: { twig: require('twig') }, propertyName: 'mobile' })

expectDeprecated({} as PointOfViewOptions)