@modernpoacher/halacious 6.2.9 → 6.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ const hapi = require('@hapi/hapi')
2
2
  const vision = require('@hapi/vision')
3
3
  const halacious = require('#halacious')
4
4
 
5
- const { name: PLUGIN } = require('#halacious/package.json')
5
+ const PLUGIN = '@modernpoacher/halacious'
6
6
 
7
7
  async function init () {
8
8
  const server = hapi.server({ port: 8080 })
@@ -4,7 +4,7 @@ const hapi = require('@hapi/hapi')
4
4
  const vision = require('@hapi/vision')
5
5
  const halacious = require('#halacious')
6
6
 
7
- const { name: PLUGIN } = require('#halacious/package.json')
7
+ const PLUGIN = '@modernpoacher/halacious'
8
8
 
9
9
  async function init () {
10
10
  const server = hapi.server({ port: 8080 })
package/index.mjs ADDED
@@ -0,0 +1 @@
1
+ export * as default from './src/index.mjs'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modernpoacher/halacious",
3
- "version": "6.2.9",
3
+ "version": "6.3.0",
4
4
  "description": "A HAL processor for Hapi",
5
5
  "keywords": [
6
6
  "HAL",
@@ -8,7 +8,8 @@
8
8
  "hypermedia",
9
9
  "HATEOAS"
10
10
  ],
11
- "main": "./index.js",
11
+ "type": "module",
12
+ "main": "./src/index.mjs",
12
13
  "author": "Jonathan Perry <modernpoacher@modernpoacher.com> (Modern Poacher Limited)",
13
14
  "contributors": [
14
15
  "Brad Leupen"
@@ -26,7 +27,7 @@
26
27
  "url": "https://github.com/modernpoacher/halacious/issues"
27
28
  },
28
29
  "scripts": {
29
- "lint": "eslint .",
30
+ "lint": "eslint . --ext .mjs --ext .cjs --ext .mts --ext .cts",
30
31
  "lint:fix": "npm run lint -- --fix",
31
32
  "test": "cross-env NODE_ENV=test mocha test",
32
33
  "prepare": "husky install"
@@ -68,12 +69,11 @@
68
69
  "sinon-chai": "^3.7.0"
69
70
  },
70
71
  "imports": {
71
- "#halacious/package.json": "./package.json",
72
- "#halacious/lib/*": "./lib/*.js",
73
- "#halacious": "./lib/index.js"
72
+ "#halacious/*": "./src/*.mjs",
73
+ "#halacious": "./src/index.mjs",
74
+ "#where-am-i": "./where-am-i.mjs"
74
75
  },
75
76
  "exports": {
76
- "./lib": "./lib/*.js",
77
- ".": "./lib/index.js"
77
+ ".": "./src/index.mjs"
78
78
  }
79
79
  }
@@ -1,4 +1,4 @@
1
- declare namespace halacious {
1
+ declare namespace HalaciousTypes {
2
2
  export interface Collection {
3
3
  uid: string
4
4
  }
@@ -27,4 +27,4 @@ declare namespace halacious {
27
27
  }
28
28
  }
29
29
 
30
- export = halacious
30
+ export default HalaciousTypes
package/src/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export * as default from './plugin.mjs'
@@ -1,34 +1,34 @@
1
- const joi = require('@hapi/joi')
2
- const boom = require('@hapi/boom')
3
- const hoek = require('@hapi/hoek')
4
- const _ = require('lodash')
5
- const fs = require('fs')
6
- const path = require('path')
7
- const pug = require('pug')
8
- const util = require('util')
9
- const async = require('async')
10
- const {
1
+ import joi from '@hapi/joi'
2
+ import boom from '@hapi/boom'
3
+ import hoek from '@hapi/hoek'
4
+ import _ from 'lodash'
5
+ import fs from 'node:fs'
6
+ import path from 'node:path'
7
+ import pug from 'pug'
8
+ import util from 'util'
9
+ import async from 'async'
10
+ import {
11
11
  marked
12
- } = require('marked')
13
- const {
12
+ } from 'marked'
13
+ import {
14
14
  mangle
15
- } = require('marked-mangle')
16
- const {
15
+ } from 'marked-mangle'
16
+ import {
17
17
  gfmHeadingId
18
- } = require('marked-gfm-heading-id')
19
- const urlTemplate = require('url-template')
20
- const Negotiator = require('negotiator')
21
- const URITemplate = require('urijs/src/URITemplate')
22
- const url = require('url')
23
- const URI = require('urijs')
24
-
25
- const {
26
- RepresentationFactory
27
- } = require('./representation')
18
+ } from 'marked-gfm-heading-id'
19
+ import urlTemplate from 'url-template'
20
+ import Negotiator from 'negotiator'
21
+ import URITemplate from 'urijs/src/URITemplate.js'
22
+ import url from 'url'
23
+ import URI from 'urijs'
24
+ import IAM from '#where-am-i'
25
+ import RepresentationFactory from './representation.mjs'
28
26
 
29
27
  const HAL_MIME_TYPE = 'application/hal+json'
30
28
 
31
- const re = /{([^{}]+)}|([^{}]+)/g
29
+ const REG = /{([^{}]+)}|([^{}]+)/g
30
+
31
+ const PKG = JSON.parse(fs.readFileSync(path.join(IAM, './package.json')))
32
32
 
33
33
  function reach (object, path) {
34
34
  const parts = path ? path.split('.') : []
@@ -51,7 +51,7 @@ function flattenContext (template, ctx) {
51
51
  let arr
52
52
  const result = {}
53
53
 
54
- while ((arr = re.exec(template)) !== null) {
54
+ while ((arr = REG.exec(template)) !== null) {
55
55
  if (arr[1]) {
56
56
  const value = reach(ctx, arr[1])
57
57
  result[arr[1]] = value && value.toString()
@@ -92,8 +92,8 @@ const optionsSchema = {
92
92
  * @param opts
93
93
  * @param next
94
94
  */
95
- exports.plugin = {
96
- pkg: require('../package'),
95
+ const plugin = {
96
+ pkg: PKG,
97
97
 
98
98
  async register (server, opts) {
99
99
  let settings = opts
@@ -964,7 +964,7 @@ exports.plugin = {
964
964
  engines: {
965
965
  jade: pug
966
966
  },
967
- path: path.join(__dirname, '../views'),
967
+ path: path.join(IAM, './views'),
968
968
  isCached: false
969
969
  })
970
970
  server.route({
@@ -983,3 +983,7 @@ exports.plugin = {
983
983
  server.ext('onPreStart', internals.preStart)
984
984
  }
985
985
  }
986
+
987
+ export {
988
+ plugin
989
+ }
@@ -1,8 +1,8 @@
1
1
 
2
- const _ = require('lodash')
3
- const hoek = require('@hapi/hoek')
2
+ import _ from 'lodash'
3
+ import hoek from '@hapi/hoek'
4
+ import URI from 'urijs'
4
5
 
5
- const URI = require('urijs')
6
6
  const templatedRE = /{*}/
7
7
 
8
8
  /**
@@ -15,7 +15,7 @@ const templatedRE = /{*}/
15
15
  * @param root
16
16
  * @constructor
17
17
  */
18
- class Representation {
18
+ export class Representation {
19
19
  constructor (factory, self, entity, root) {
20
20
  this._halacious = factory._halacious
21
21
  this.factory = factory
@@ -247,7 +247,7 @@ class Representation {
247
247
  * @param request a hapi request object
248
248
  * @constructor
249
249
  */
250
- class RepresentationFactory {
250
+ export class RepresentationFactory {
251
251
  constructor (halacious, request) {
252
252
  this._halacious = halacious
253
253
  this._request = request
@@ -269,4 +269,4 @@ class RepresentationFactory {
269
269
  }
270
270
  }
271
271
 
272
- module.exports.RepresentationFactory = RepresentationFactory
272
+ export default RepresentationFactory
@@ -1,22 +1,24 @@
1
- const path = require('path')
1
+ import path from 'path'
2
2
 
3
- const chai = require('chai')
3
+ import chai from 'chai'
4
+
5
+ import hapi from '@hapi/hapi'
6
+ import vision from '@hapi/vision'
7
+ import sinon from 'sinon'
8
+ import sinonChai from 'sinon-chai'
9
+ import chaiString from 'chai-string'
10
+ import halacious from '#halacious'
11
+ import { plugin } from '#halacious/plugin'
12
+ import _ from 'lodash'
13
+ import url from 'url'
14
+ import IAM from '#where-am-i'
4
15
 
5
16
  const should = chai.should()
6
- const hapi = require('@hapi/hapi')
7
- const vision = require('@hapi/vision')
8
- const sinon = require('sinon')
9
- const sinonChai = require('sinon-chai')
10
- const chaiString = require('chai-string')
11
- const halacious = require('#halacious')
12
- const { plugin } = require('#halacious/lib/plugin')
13
- const _ = require('lodash')
14
- const url = require('url')
15
17
 
16
18
  chai.use(sinonChai)
17
19
  chai.use(chaiString)
18
20
 
19
- const { name: PLUGIN } = require('#halacious/package.json')
21
+ const PLUGIN = '@modernpoacher/halacious'
20
22
 
21
23
  describe('Halacious Plugin', () => {
22
24
  let server
@@ -346,7 +348,7 @@ describe('Halacious Plugin', () => {
346
348
  } = server
347
349
 
348
350
  namespaces.add({
349
- dir: path.resolve(__dirname, 'rels/mycompany'),
351
+ dir: path.join(IAM, './test/rels/mycompany'),
350
352
  prefix: 'mco'
351
353
  })
352
354
  })
@@ -373,7 +375,7 @@ describe('Halacious Plugin', () => {
373
375
  } = server
374
376
 
375
377
  const namespace = plugin.namespaces.add({
376
- dir: path.resolve(__dirname, 'rels/mycompany'),
378
+ dir: path.join(IAM, './test/rels/mycompany'),
377
379
  prefix: 'mco'
378
380
  })
379
381
 
@@ -402,7 +404,7 @@ describe('Halacious Plugin', () => {
402
404
  } = server
403
405
 
404
406
  plugin.namespaces.add({
405
- dir: path.resolve(__dirname, 'rels/mycompany'),
407
+ dir: path.join(IAM, './test/rels/mycompany'),
406
408
  prefix: 'mco'
407
409
  })
408
410
  })
@@ -1,12 +1,11 @@
1
- const chai = require('chai')
1
+ import chai from 'chai'
2
+ import hapi from '@hapi/hapi'
3
+ import halacious from '#halacious'
4
+ import RepresentationFactory from '#halacious/representation'
2
5
 
3
6
  const should = chai.should()
4
- const hapi = require('@hapi/hapi')
5
- const halacious = require('#halacious')
6
7
 
7
- const { RepresentationFactory } = require('#halacious/lib/representation')
8
-
9
- const { name: PLUGIN } = require('#halacious/package.json')
8
+ const PLUGIN = '@modernpoacher/halacious'
10
9
 
11
10
  describe('Representation Factory', () => {
12
11
  let server
package/where-am-i.mjs ADDED
@@ -0,0 +1,9 @@
1
+ import {
2
+ fileURLToPath
3
+ } from 'node:url'
4
+
5
+ import {
6
+ dirname
7
+ } from 'node:path'
8
+
9
+ export default dirname(fileURLToPath(import.meta.url))
package/index.js DELETED
@@ -1,3 +0,0 @@
1
- //
2
-
3
- module.exports = require('./lib')
package/lib/index.js DELETED
@@ -1,2 +0,0 @@
1
-
2
- module.exports = require('./plugin')
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes