diff --git a/lib/index.js b/lib/index.js index 714a8fe..0b524ce 100755 --- a/lib/index.js +++ b/lib/index.js @@ -1,14 +1,16 @@ -'use strict'; +import { readFileSync } from 'node:fs'; -const Boom = require('@hapi/boom'); -const Hoek = require('@hapi/hoek'); +import * as Boom from '@hapi/boom'; +import * as Hoek from '@hapi/hoek'; const internals = {}; +const Package = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')); -exports.plugin = { - pkg: require('../package.json'), + +const plugin = { + pkg: Package, requirements: { hapi: '>=20.0.0' }, @@ -83,3 +85,6 @@ internals.implementation = function (server, options) { return scheme; }; + + +export { plugin }; diff --git a/package.json b/package.json index d915fac..d018a88 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,10 @@ { "name": "@hapi/basic", "description": "Basic authentication plugin", - "version": "7.0.2", + "version": "8.0.0", + "type": "module", "repository": "git://github.com/hapijs/basic", - "main": "lib/index.js", + "exports": "./lib/index.js", "types": "lib/index.d.ts", "files": [ "lib" @@ -33,7 +34,7 @@ "typescript": "^5.1.3" }, "scripts": { - "test": "lab -a @hapi/code -t 100 -L -Y", + "test": "lab -a @hapi/code -Y", "test-cov-html": "lab -a @hapi/code -r html -o coverage.html" }, "license": "BSD-3-Clause" diff --git a/test/esm.js b/test/esm.js index 78fc6de..a410a35 100644 --- a/test/esm.js +++ b/test/esm.js @@ -1,11 +1,11 @@ -'use strict'; +import * as Code from '@hapi/code'; +import * as Lab from '@hapi/lab'; -const Code = require('@hapi/code'); -const Lab = require('@hapi/lab'); - -const { before, describe, it } = exports.lab = Lab.script(); +const lab = Lab.script(); +const { before, describe, it } = lab; const expect = Code.expect; +export { lab }; describe('import()', () => { @@ -20,7 +20,6 @@ describe('import()', () => { it('exposes all methods and classes as named imports', () => { expect(Object.keys(Basic)).to.equal([ - 'default', 'plugin' ]); }); diff --git a/test/index.js b/test/index.js index 040a2d1..286bad8 100755 --- a/test/index.js +++ b/test/index.js @@ -1,17 +1,17 @@ -'use strict'; - -const Basic = require('..'); -const Boom = require('@hapi/boom'); -const Code = require('@hapi/code'); -const Hapi = require('@hapi/hapi'); -const Lab = require('@hapi/lab'); +import * as Basic from '../lib/index.js'; +import * as Boom from '@hapi/boom'; +import * as Code from '@hapi/code'; +import * as Hapi from '@hapi/hapi'; +import * as Lab from '@hapi/lab'; const internals = {}; -const { it, describe } = exports.lab = Lab.script(); +const lab = Lab.script(); +const { it, describe } = lab; const expect = Code.expect; +export { lab }; describe('Basic authentication', () => { diff --git a/test/index.ts b/test/index.ts index 0a25759..329405f 100644 --- a/test/index.ts +++ b/test/index.ts @@ -1,6 +1,6 @@ // from https://github.com/hapijs/hapi-auth-basic#hapi-auth-basic -import * as Basic from '..'; +import * as Basic from '../lib/index.js'; import { Server } from '@hapi/hapi'; import { types } from '@hapi/lab';