Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fastify/view

Package Overview
Dependencies
Maintainers
17
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/view - npm Package Compare versions

Comparing version 7.4.1 to 8.0.0

32

index.js

@@ -666,5 +666,11 @@ 'use strict'

if (globalOptions.templatesSync) {
engine.templatesSync = globalOptions.templatesSync
}
lru.define = lru.set
engine.configure({
templates: globalOptions.templates ? globalOptions.templates : lru
views: templatesDir || lru,
cache: prod || globalOptions.templatesSync
})

@@ -674,3 +680,3 @@

cache: prod,
views: templatesDir
views: templatesDir || lru
}, globalOptions)

@@ -697,13 +703,19 @@

page = getPage(page, 'eta')
if (opts?.async ?? globalOptions.async) {
engine
.renderFile(page, data, config)
.then(sendContent)
.catch(err => this.send(err))
.renderAsync(page, data, config)
.then((res) => {
sendContent(res)
})
.catch(err => {
this.send(err)
})
} else {
engine.renderFile(page, data, config, (err, html) => {
err
? this.send(err)
: sendContent(html)
})
try {
const html = engine.render(page, data, config)
sendContent(html)
} catch (err) {
this.send(err)
}
}

@@ -710,0 +722,0 @@ }

{
"name": "@fastify/view",
"version": "7.4.1",
"version": "8.0.0",
"description": "Template plugin for Fastify",

@@ -46,3 +46,3 @@ "main": "index.js",

"@fastify/pre-commit": "^2.0.2",
"@types/node": "^18.0.0",
"@types/node": "^20.1.0",
"art-template": "^4.13.2",

@@ -52,3 +52,3 @@ "cross-env": "^7.0.2",

"ejs": "^3.1.8",
"eta": "^1.11.0",
"eta": "^3.0.3",
"express": "^4.17.1",

@@ -68,3 +68,3 @@ "fastify": "^4.0.0-rc.2",

"tap": "^16.0.0",
"tsd": "^0.25.0",
"tsd": "^0.28.0",
"twig": "^1.13.3"

@@ -71,0 +71,0 @@ },

@@ -8,3 +8,2 @@ 'use strict'

const dot = require('dot')
const eta = require('eta')
const handlebars = require('handlebars')

@@ -107,2 +106,5 @@ const { Liquid } = require('liquidjs')

module.exports.etaHtmlMinifierTests = function (t, withMinifierOptions) {
const { Eta } = require('eta')
const eta = new Eta()
const test = t.test

@@ -140,3 +142,3 @@ const options = withMinifierOptions ? minifierOpts : {}

t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
t.equal(minifier.minify(eta.render(fs.readFileSync('./templates/index.eta', 'utf8'), data), options), body.toString())
t.equal(minifier.minify(eta.renderString(fs.readFileSync('./templates/index.eta', 'utf8'), data), options), body.toString())
fastify.close()

@@ -176,3 +178,3 @@ })

t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
t.equal(eta.render(fs.readFileSync('./templates/index.eta', 'utf8'), data), body.toString())
t.equal(eta.renderString(fs.readFileSync('./templates/index.eta', 'utf8'), data), body.toString())
fastify.close()

@@ -179,0 +181,0 @@ })

@@ -11,3 +11,4 @@ 'use strict'

const pointOfView = require('../index')
const eta = require('eta')
const { Eta } = require('eta')
let eta = new Eta()

@@ -17,2 +18,7 @@ require('./helper').etaHtmlMinifierTests(t, true)

t.beforeEach(async t => {
// this is mandatory since some test call eta.configure(customOptions)
eta = new Eta()
})
test('reply.view with eta engine and custom templates folder', t => {

@@ -46,3 +52,3 @@ t.plan(6)

t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
t.equal(eta.render(fs.readFileSync('./templates/index.eta', 'utf8'), data), body.toString())
t.equal(eta.renderString(fs.readFileSync('./templates/index.eta', 'utf8'), data), body.toString())
fastify.close()

@@ -82,3 +88,3 @@ })

t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
t.equal(eta.render(fs.readFileSync('./templates/index.eta', 'utf8'), data), body.toString())
t.equal(eta.renderString(fs.readFileSync('./templates/index.eta', 'utf8'), data), body.toString())
fastify.close()

@@ -117,3 +123,3 @@ })

t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
t.equal(eta.render(fs.readFileSync('./templates/index.eta', 'utf8'), data), body.toString())
t.equal(eta.renderString(fs.readFileSync('./templates/index.eta', 'utf8'), data), body.toString())
fastify.close()

@@ -184,3 +190,3 @@ })

t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
t.equal(eta.render(fs.readFileSync('./templates/index.eta', 'utf8'), data), body.toString())
t.equal(eta.renderString(fs.readFileSync('./templates/index.eta', 'utf8'), data), body.toString())
fastify.close()

@@ -220,3 +226,3 @@ })

t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
t.equal(eta.render(fs.readFileSync('./templates/index.eta', 'utf8'), data), body.toString())
t.equal(eta.renderString(fs.readFileSync('./templates/index.eta', 'utf8'), data), body.toString())
fastify.close()

@@ -256,3 +262,3 @@ })

t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
t.equal(eta.render(fs.readFileSync('./templates/index.eta', 'utf8'), data), body.toString())
t.equal(eta.renderString(fs.readFileSync('./templates/index.eta', 'utf8'), data), body.toString())
fastify.close()

@@ -289,3 +295,3 @@ })

t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
t.equal(eta.render(fs.readFileSync('./templates/index-bare.html', 'utf8')), body.toString())
t.equal(eta.renderString(fs.readFileSync('./templates/index-bare.html', 'utf8')), body.toString())
fastify.close()

@@ -328,3 +334,3 @@ })

t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
t.equal(eta.render(fs.readFileSync('./templates/index-bare.html', 'utf8'), localsData), body.toString())
t.equal(eta.renderString(fs.readFileSync('./templates/index-bare.html', 'utf8'), localsData), body.toString())
fastify.close()

@@ -368,3 +374,3 @@ })

t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
t.equal(eta.render(fs.readFileSync('./templates/index-bare.html', 'utf8'), data), body.toString())
t.equal(eta.renderString(fs.readFileSync('./templates/index-bare.html', 'utf8'), data), body.toString())
fastify.close()

@@ -409,3 +415,3 @@ })

t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
t.equal(eta.render(fs.readFileSync('./templates/index-bare.html', 'utf8'), localsData), body.toString())
t.equal(eta.renderString(fs.readFileSync('./templates/index-bare.html', 'utf8'), localsData), body.toString())
fastify.close()

@@ -451,3 +457,3 @@ })

t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
t.equal(eta.render(fs.readFileSync('./templates/index-bare.html', 'utf8'), data), body.toString())
t.equal(eta.renderString(fs.readFileSync('./templates/index-bare.html', 'utf8'), data), body.toString())
fastify.close()

@@ -486,3 +492,3 @@ })

t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
t.equal(eta.render(fs.readFileSync('./templates/index.eta', 'utf8'), data), body.toString())
t.equal(eta.renderString(fs.readFileSync('./templates/index.eta', 'utf8'), data), body.toString())
fastify.close()

@@ -520,3 +526,3 @@ })

t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
t.equal(eta.render(fs.readFileSync('./templates/index.eta', 'utf8'), data), body.toString())
t.equal(eta.renderString(fs.readFileSync('./templates/index.eta', 'utf8'), data), body.toString())
fastify.close()

@@ -555,3 +561,3 @@ })

t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
t.equal(eta.render(fs.readFileSync('./templates/index.eta', 'utf8'), data), body.toString())
t.equal(eta.renderString(fs.readFileSync('./templates/index.eta', 'utf8'), data), body.toString())
fastify.close()

@@ -590,3 +596,3 @@ })

t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
t.equal(eta.render(fs.readFileSync('./templates/index.eta', 'utf8'), data), body.toString())
t.equal(eta.renderString(fs.readFileSync('./templates/index.eta', 'utf8'), data), body.toString())
fastify.close()

@@ -632,8 +638,5 @@ })

let content = null
eta.renderFile('/index-linking-other-pages.eta', data, options, function (err, str) {
content = str
t.error(err)
t.equal(content.length, body.length)
})
const content = eta.render('/index-linking-other-pages.eta', data, options)
t.equal(content.length, body.length)
t.equal(content, body.toString())

@@ -646,3 +649,3 @@ fastify.close()

test('reply.view with eta engine, templates with folder specified, include files and attributes; home', t => {
t.plan(7)
t.plan(6)
const fastify = Fastify()

@@ -681,13 +684,4 @@

let content = null
eta.renderFile(
'/index.eta',
data,
options,
function (err, str) {
content = str
t.error(err)
t.equal(content.length, body.length)
}
)
const content = eta.render('/index.eta', data, options)
t.equal(content.length, body.length)

@@ -700,3 +694,3 @@ fastify.close()

test('reply.view with eta engine, templates with folder specified, include files and attributes; page with no data', t => {
t.plan(7)
t.plan(6)
const fastify = Fastify()

@@ -734,13 +728,4 @@

let content = null
eta.renderFile(
'/index-with-no-data.eta',
null,
options,
function (err, str) {
content = str
t.error(err)
t.equal(content.length, body.length)
}
)
const content = eta.render('/index-with-no-data.eta', null, options)
t.equal(content.length, body.length)

@@ -753,3 +738,3 @@ fastify.close()

test('reply.view with eta engine, templates with folder specified, include files and attributes; page with includes', t => {
t.plan(7)
t.plan(6)
const fastify = Fastify()

@@ -783,3 +768,3 @@

url: 'http://localhost:' + fastify.server.address().port + '/include-test'
}, (err, response, body) => {
}, async (err, response, body) => {
t.error(err)

@@ -790,13 +775,4 @@ t.equal(response.statusCode, 200)

let content = null
eta.renderFile(
'/index-with-includes.eta',
data,
options,
function (err, str) {
content = str
t.error(err)
t.equal(content.length, body.length)
}
)
const content = await eta.renderAsync('/index-with-includes.eta', data, options)
t.equal(content.length, body.length)

@@ -837,3 +813,3 @@ fastify.close()

url: 'http://localhost:' + fastify.server.address().port + '/include-one-include-missing-test'
}, (err, response, body) => {
}, async (err, response, body) => {
t.error(err)

@@ -845,12 +821,8 @@ t.equal(response.statusCode, 500)

let content = null
eta.renderFile(
'/index-with-includes-one-missing.eta',
data,
options,
function (err, str) {
content = str
t.type(err, Error) // expected Error here ...
t.equal(content, undefined)
}
)
try {
content = await eta.renderAsync('/index-with-includes-one-missing.eta', data, options)
} catch (e) {
t.type(e, Error) // expected Error here ...
t.equal(content, null)
}

@@ -880,3 +852,3 @@ fastify.close()

t.error(err)
t.equal(eta.render(fs.readFileSync('./templates/index.eta', 'utf8'), data), compiled)
t.equal(eta.renderString(fs.readFileSync('./templates/index.eta', 'utf8'), data), compiled)

@@ -888,3 +860,3 @@ fastify.ready(err => {

t.error(err)
t.equal(eta.render(fs.readFileSync('./templates/index.eta', 'utf8'), data), compiled)
t.equal(eta.renderString(fs.readFileSync('./templates/index.eta', 'utf8'), data), compiled)
fastify.close()

@@ -920,3 +892,3 @@ })

options: {
templates: cache
templatesSync: cache
}

@@ -933,3 +905,3 @@ })

test('fastify.view with eta engine and custom cache', t => {
t.plan(9)
t.plan(8)
const fastify = Fastify()

@@ -955,3 +927,4 @@

cache: true,
templates: pseudoCache
templatesSync: pseudoCache,
views: path.join(__dirname, '../templates')
}

@@ -969,3 +942,4 @@

// pre-cache
const tplFn = eta.loadFile(tplAbsPath, { filename: tplAbsPath })
eta.loadTemplate(path.join(__dirname, tplPath), eta.readFile(tplPath))
const tplF = eta.templatesSync.get(path.join(__dirname, tplPath))

@@ -975,5 +949,5 @@ fastify.get('/', (req, reply) => {

const res = reply.view(tplPath, data)
t.equal(eta.config.templates, pseudoCache,
t.equal(eta.templatesSync, pseudoCache,
'Cache instance should be equal to the pre-defined one')
t.not(eta.config.templates.get(tplAbsPath), undefined,
t.not(eta.templatesSync.get(tplAbsPath), undefined,
'Template should be pre-cached')

@@ -994,6 +968,6 @@ return res

t.equal(response.statusCode, 200, 'Response should be 200')
tplFn(data, eta.config, (err, str) => {
t.error(err)
t.equal(str, body.toString(), 'Route should return the same result as cached template function')
})
const str = eta.render(tplF, data)
t.equal(str, body.toString(), 'Route should return the same result as cached template function')
fastify.close()

@@ -1045,3 +1019,3 @@ })

fastify.view('templates/index.eta', data).then((compiled) => {
t.equal(eta.render(fs.readFileSync('./templates/index.eta', 'utf8'), data), compiled)
t.equal(eta.renderString(fs.readFileSync('./templates/index.eta', 'utf8'), data), compiled)
fastify.view('templates/index.eta', null)

@@ -1048,0 +1022,0 @@ .then(() => { t.fail('should not be here') })

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc