diff --git a/.github/workflows/ci-plugin.yml b/.github/workflows/ci-plugin.yml index 8c667d5..aa80048 100644 --- a/.github/workflows/ci-plugin.yml +++ b/.github/workflows/ci-plugin.yml @@ -10,3 +10,6 @@ on: jobs: test: uses: hapijs/.github/.github/workflows/ci-plugin.yml@master + with: + min-node-version: 14 + min-hapi-version: 20 diff --git a/LICENSE.md b/LICENSE.md index 226d3eb..5178760 100755 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,7 @@ -Copyright (c) 2012-2020, Sideway Inc, and project contributors -Copyright (c) 2014-2019, Gil Pedersen -Copyright (c) 2012-2014, Walmart. +Copyright (c) 2012-2022, Project contributors +Copyright (c) 2012-2020, Sideway Inc +Copyright (c) 2014-2019, Gil Pedersen +Copyright (c) 2012-2014, Walmart. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/lib/directory.js b/lib/directory.js index 9a2a602..7e1dc3d 100755 --- a/lib/directory.js +++ b/lib/directory.js @@ -60,11 +60,11 @@ exports.handler = function (route, options) { const handler = async (request, reply) => { - const paths = normalized || internals.resolvePathOption(settings.path.call(null, request)); + const paths = normalized ?? internals.resolvePathOption(settings.path.call(null, request)); // Append parameter - const selection = request.params[paramName] || ''; + const selection = request.params[paramName] ?? ''; if (Path.isAbsolute(selection)) { throw Boom.notFound(null, {}); diff --git a/lib/file.js b/lib/file.js index 5d2e19b..68eed92 100755 --- a/lib/file.js +++ b/lib/file.js @@ -106,7 +106,7 @@ internals.prepare = async function (response) { try { const stat = await file.openStat('r'); - const start = settings.start || 0; + const start = settings.start ?? 0; if (settings.end !== undefined) { response.bytes(settings.end - start + 1); } @@ -115,13 +115,13 @@ internals.prepare = async function (response) { } if (!response.headers['content-type']) { - response.type(request.server.mime.path(path).type || 'application/octet-stream'); + response.type(request.server.mime.path(path).type ?? 'application/octet-stream'); } response.header('last-modified', stat.mtime.toUTCString()); if (settings.mode) { - const fileName = settings.filename || Path.basename(path); + const fileName = settings.filename ?? Path.basename(path); response.header('content-disposition', settings.mode + '; filename=' + encodeURIComponent(fileName)); } @@ -146,7 +146,7 @@ internals.marshal = async function (response) { settings.end === undefined && request.server.settings.compression !== false) { - const lookupMap = settings.lookupMap || internals.defaultMap; + const lookupMap = settings.lookupMap ?? internals.defaultMap; const encoding = request.info.acceptEncoding; const extension = lookupMap.hasOwnProperty(encoding) ? lookupMap[encoding] : null; if (extension) { @@ -232,7 +232,7 @@ internals.createStream = function (response) { const range = internals.addContentRange(response); const options = { - start: settings.start || 0, + start: settings.start ?? 0, end: settings.end }; diff --git a/lib/index.js b/lib/index.js index eb00cbd..a78d67e 100755 --- a/lib/index.js +++ b/lib/index.js @@ -33,15 +33,14 @@ exports.plugin = { pkg: require('../package.json'), once: true, requirements: { - hapi: '>=19.0.0' + hapi: '>=20.0.0' }, - register(server, options) { Hoek.assert(Object.keys(options).length === 0, 'Inert does not support registration options'); - const settings = Validate.attempt(Hoek.reach(server.settings.plugins, ['inert']) || {}, internals.schema, 'Invalid "inert" server options'); + const settings = Validate.attempt(server.settings.plugins?.inert ?? {}, internals.schema, 'Invalid "inert" server options'); - server.expose('_etags', settings.etagsCacheMaxSize > 0 ? new Etag.Cache(settings.etagsCacheMaxSize) : null); + server.expose('_etags', settings.etagsCacheMaxSize > 0 ? new Etag.Cache({ max: settings.etagsCacheMaxSize }) : null); server.decorate('handler', 'file', File.handler); server.decorate('handler', 'directory', Directory.handler); diff --git a/package.json b/package.json index b34105e..16edf5b 100644 --- a/package.json +++ b/package.json @@ -20,19 +20,19 @@ ] }, "dependencies": { - "@hapi/ammo": "5.x.x", - "@hapi/boom": "9.x.x", - "@hapi/bounce": "2.x.x", - "@hapi/hoek": "9.x.x", - "@hapi/validate": "1.x.x", - "lru-cache": "^6.0.0" + "@hapi/ammo": "^6.0.0", + "@hapi/boom": "^10.0.0", + "@hapi/bounce": "^3.0.0", + "@hapi/hoek": "^10.0.0", + "@hapi/validate": "^2.0.0", + "lru-cache": "^7.10.2" }, "devDependencies": { - "@hapi/code": "8.x.x", - "@hapi/eslint-plugin": "*", - "@hapi/file": "2.x.x", - "@hapi/hapi": "20.x.x", - "@hapi/lab": "24.x.x" + "@hapi/code": "^9.0.0", + "@hapi/eslint-plugin": "^6.0.0", + "@hapi/file": "^3.0.0", + "@hapi/hapi": "21.0.0-beta.1", + "@hapi/lab": "^25.0.1" }, "scripts": { "test": "lab -f -a @hapi/code -t 100 -L", diff --git a/test/esm.js b/test/esm.js new file mode 100644 index 0000000..5c8bc8f --- /dev/null +++ b/test/esm.js @@ -0,0 +1,27 @@ +'use strict'; + +const Code = require('@hapi/code'); +const Lab = require('@hapi/lab'); + + +const { before, describe, it } = exports.lab = Lab.script(); +const expect = Code.expect; + + +describe('import()', () => { + + let Inert; + + before(async () => { + + Inert = await import('../lib/index.js'); + }); + + it('exposes all methods and classes as named imports', () => { + + expect(Object.keys(Inert)).to.equal([ + 'default', + 'plugin' + ]); + }); +});