Skip to content

Commit

Permalink
Support node v18 and hapi v21, drop node v12 and hapi v19 (#164)
Browse files Browse the repository at this point in the history
* Support node v18 and hapi v21, drop node v12 and hapi v19

* Support ESM imports

* Fix workflow syntax

* Update workflow branch

* Remove unneeded ESM export, remove hapi version requirement exception
  • Loading branch information
devinivy committed Jul 17, 2022
1 parent 68a0a36 commit e11b34d
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 2 additions & 2 deletions lib/directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {});
Expand Down
10 changes: 5 additions & 5 deletions lib/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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));
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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
};

Expand Down
7 changes: 3 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 27 additions & 0 deletions test/esm.js
Original file line number Diff line number Diff line change
@@ -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'
]);
});
});

0 comments on commit e11b34d

Please sign in to comment.