diff --git a/.eslintrc b/.eslintrc index 7a9a1db8..69a29ae8 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,11 +1,20 @@ { + "parser": "@babel/eslint-parser", "extends": ["airbnb-base", "prettier"], "plugins": ["prettier"], + "parserOptions": { + "ecmaVersion": 11, + "sourceType": "module", + "requireConfigFile": false + }, "rules": { - "strict": [0, "global"], + "import/prefer-default-export": "off", + "import/extensions": ["error", { + "js": "ignorePackages" + } + ], "class-methods-use-this": [0], "no-underscore-dangle": [0], - "no-restricted-syntax": [0], - "import/extensions": [0] + "no-restricted-syntax": [0] } } diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f043568d..8a1d7ea9 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -14,7 +14,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v2 with: - node-version: 14.x + node-version: 16.x - name: npm install run: | npm install @@ -35,7 +35,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v2 with: - node-version: 14.x + node-version: 16.x - name: npm install run: | npm install diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7a160eff..5d506168 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macOS-latest, windows-latest] - node-version: [12.x, 14.x, 16.x] + node-version: [14.x, 16.x] steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} diff --git a/examples/auth.post.js b/examples/auth.post.js index 1e01d83c..b5d93257 100644 --- a/examples/auth.post.js +++ b/examples/auth.post.js @@ -1,10 +1,8 @@ /* eslint-disable no-console */ /* eslint-disable import/no-extraneous-dependencies */ -'use strict'; - -const FormData = require('form-data'); -const fetch = require('node-fetch'); +import FormData from 'form-data'; +import fetch from 'node-fetch'; const authenticate = async (address) => { const formData = new FormData(); diff --git a/examples/map.alias.delete.js b/examples/map.alias.delete.js index 7dac9d0e..b6ae7675 100644 --- a/examples/map.alias.delete.js +++ b/examples/map.alias.delete.js @@ -1,10 +1,8 @@ /* eslint-disable no-console */ /* eslint-disable import/no-extraneous-dependencies */ -'use strict'; - -const FormData = require('form-data'); -const fetch = require('node-fetch'); +import FormData from 'form-data'; +import fetch from 'node-fetch'; const authenticate = async (address) => { const formData = new FormData(); diff --git a/examples/map.alias.get.js b/examples/map.alias.get.js index 9c284254..f5266d90 100644 --- a/examples/map.alias.get.js +++ b/examples/map.alias.get.js @@ -1,9 +1,7 @@ /* eslint-disable no-console */ /* eslint-disable import/no-extraneous-dependencies */ -'use strict'; - -const fetch = require('node-fetch'); +import fetch from 'node-fetch'; fetch('http://localhost:4001/map/buzz/v4', { method: 'GET', diff --git a/examples/map.alias.post.js b/examples/map.alias.post.js index 00b62933..9ce15355 100644 --- a/examples/map.alias.post.js +++ b/examples/map.alias.post.js @@ -1,10 +1,8 @@ /* eslint-disable no-console */ /* eslint-disable import/no-extraneous-dependencies */ -'use strict'; - -const FormData = require('form-data'); -const fetch = require('node-fetch'); +import FormData from 'form-data'; +import fetch from 'node-fetch'; const authenticate = async (address) => { const formData = new FormData(); diff --git a/examples/map.alias.put.js b/examples/map.alias.put.js index 6215c8c5..0b20b5cc 100644 --- a/examples/map.alias.put.js +++ b/examples/map.alias.put.js @@ -1,10 +1,8 @@ /* eslint-disable no-console */ /* eslint-disable import/no-extraneous-dependencies */ -'use strict'; - -const FormData = require('form-data'); -const fetch = require('node-fetch'); +import FormData from 'form-data'; +import fetch from 'node-fetch'; const authenticate = async (address) => { const formData = new FormData(); diff --git a/examples/map.etag.get.js b/examples/map.etag.get.js index 0c6d29b3..013482ae 100644 --- a/examples/map.etag.get.js +++ b/examples/map.etag.get.js @@ -1,9 +1,7 @@ /* eslint-disable no-console */ /* eslint-disable import/no-extraneous-dependencies */ -'use strict'; - -const fetch = require('node-fetch'); +import fetch from 'node-fetch'; const get = async () => { diff --git a/examples/map.get.js b/examples/map.get.js index 9f802808..471e3803 100644 --- a/examples/map.get.js +++ b/examples/map.get.js @@ -1,9 +1,7 @@ /* eslint-disable no-console */ /* eslint-disable import/no-extraneous-dependencies */ -'use strict'; - -const fetch = require('node-fetch'); +import fetch from 'node-fetch'; fetch('http://localhost:4001/map/buzz/4.2.2', { method: 'GET', diff --git a/examples/map.put.js b/examples/map.put.js index 0c0b34f8..2ad798c1 100644 --- a/examples/map.put.js +++ b/examples/map.put.js @@ -1,11 +1,9 @@ /* eslint-disable no-console */ /* eslint-disable import/no-extraneous-dependencies */ -'use strict'; - -const FormData = require('form-data'); -const fetch = require('node-fetch'); -const fs = require('fs'); +import FormData from 'form-data'; +import fetch from 'node-fetch'; +import fs from 'node:fs'; const authenticate = async (address) => { const formData = new FormData(); diff --git a/examples/npm.alias.delete.js b/examples/npm.alias.delete.js index 0e3d4056..205d1948 100644 --- a/examples/npm.alias.delete.js +++ b/examples/npm.alias.delete.js @@ -1,10 +1,8 @@ /* eslint-disable no-console */ /* eslint-disable import/no-extraneous-dependencies */ -'use strict'; - -const FormData = require('form-data'); -const fetch = require('node-fetch'); +import FormData from 'form-data'; +import fetch from 'node-fetch'; const authenticate = async (address) => { const formData = new FormData(); diff --git a/examples/npm.alias.get.js b/examples/npm.alias.get.js index 2f5acf74..12cd7116 100644 --- a/examples/npm.alias.get.js +++ b/examples/npm.alias.get.js @@ -1,9 +1,7 @@ /* eslint-disable no-console */ /* eslint-disable import/no-extraneous-dependencies */ -'use strict'; - -const fetch = require('node-fetch'); +import fetch from 'node-fetch'; fetch('http://localhost:4001/npm/fuzz/v8/main/index.js', { method: 'GET', diff --git a/examples/npm.alias.post.js b/examples/npm.alias.post.js index 9e1afacc..30fdc298 100644 --- a/examples/npm.alias.post.js +++ b/examples/npm.alias.post.js @@ -1,10 +1,8 @@ /* eslint-disable no-console */ /* eslint-disable import/no-extraneous-dependencies */ -'use strict'; - -const FormData = require('form-data'); -const fetch = require('node-fetch'); +import FormData from 'form-data'; +import fetch from 'node-fetch'; const authenticate = async (address) => { const formData = new FormData(); diff --git a/examples/npm.alias.put.js b/examples/npm.alias.put.js index 5058b2d7..9176f1da 100644 --- a/examples/npm.alias.put.js +++ b/examples/npm.alias.put.js @@ -1,10 +1,8 @@ /* eslint-disable no-console */ /* eslint-disable import/no-extraneous-dependencies */ -'use strict'; - -const FormData = require('form-data'); -const fetch = require('node-fetch'); +import FormData from 'form-data'; +import fetch from 'node-fetch'; const authenticate = async (address) => { const formData = new FormData(); diff --git a/examples/npm.get.js b/examples/npm.get.js index c3f9e7f7..05948075 100644 --- a/examples/npm.get.js +++ b/examples/npm.get.js @@ -1,9 +1,7 @@ /* eslint-disable no-console */ /* eslint-disable import/no-extraneous-dependencies */ -'use strict'; - -const fetch = require('node-fetch'); +import fetch from 'node-fetch'; fetch('http://localhost:4001/npm/fuzz/8.4.1/main/index.js', { method: 'GET', diff --git a/examples/npm.put.js b/examples/npm.put.js index 0f3640c0..b8a0d0fe 100644 --- a/examples/npm.put.js +++ b/examples/npm.put.js @@ -1,11 +1,9 @@ /* eslint-disable no-console */ /* eslint-disable import/no-extraneous-dependencies */ -'use strict'; - -const FormData = require('form-data'); -const fetch = require('node-fetch'); -const fs = require('fs'); +import FormData from 'form-data'; +import fetch from 'node-fetch'; +import fs from 'node:fs'; const authenticate = async (address) => { const formData = new FormData(); diff --git a/examples/pkg.alias.delete.js b/examples/pkg.alias.delete.js index 9ab97eb3..5340bd74 100644 --- a/examples/pkg.alias.delete.js +++ b/examples/pkg.alias.delete.js @@ -1,10 +1,8 @@ /* eslint-disable no-console */ /* eslint-disable import/no-extraneous-dependencies */ -'use strict'; - -const FormData = require('form-data'); -const fetch = require('node-fetch'); +import FormData from 'form-data'; +import fetch from 'node-fetch'; const authenticate = async (address) => { const formData = new FormData(); diff --git a/examples/pkg.alias.get.js b/examples/pkg.alias.get.js index ce5e3f80..988dfd39 100644 --- a/examples/pkg.alias.get.js +++ b/examples/pkg.alias.get.js @@ -1,9 +1,7 @@ /* eslint-disable no-console */ /* eslint-disable import/no-extraneous-dependencies */ -'use strict'; - -const fetch = require('node-fetch'); +import fetch from 'node-fetch'; fetch('http://localhost:4001/pkg/fuzz/v8/main/index.js', { method: 'GET', diff --git a/examples/pkg.alias.post.js b/examples/pkg.alias.post.js index f2035500..b76988e0 100644 --- a/examples/pkg.alias.post.js +++ b/examples/pkg.alias.post.js @@ -1,10 +1,8 @@ /* eslint-disable no-console */ /* eslint-disable import/no-extraneous-dependencies */ -'use strict'; - -const FormData = require('form-data'); -const fetch = require('node-fetch'); +import FormData from 'form-data'; +import fetch from 'node-fetch'; const authenticate = async (address) => { const formData = new FormData(); diff --git a/examples/pkg.alias.put.js b/examples/pkg.alias.put.js index 199831d3..3306c858 100644 --- a/examples/pkg.alias.put.js +++ b/examples/pkg.alias.put.js @@ -1,10 +1,8 @@ /* eslint-disable no-console */ /* eslint-disable import/no-extraneous-dependencies */ -'use strict'; - -const FormData = require('form-data'); -const fetch = require('node-fetch'); +import FormData from 'form-data'; +import fetch from 'node-fetch'; const authenticate = async (address) => { const formData = new FormData(); diff --git a/examples/pkg.etag.get.js b/examples/pkg.etag.get.js index 09754ef9..2b21bdf5 100644 --- a/examples/pkg.etag.get.js +++ b/examples/pkg.etag.get.js @@ -1,9 +1,7 @@ /* eslint-disable no-console */ /* eslint-disable import/no-extraneous-dependencies */ -'use strict'; - -const fetch = require('node-fetch'); +import fetch from 'node-fetch'; const get = async () => { diff --git a/examples/pkg.get.js b/examples/pkg.get.js index 5e26600d..eb7da514 100644 --- a/examples/pkg.get.js +++ b/examples/pkg.get.js @@ -1,9 +1,7 @@ /* eslint-disable no-console */ /* eslint-disable import/no-extraneous-dependencies */ -'use strict'; - -const fetch = require('node-fetch'); +import fetch from 'node-fetch'; fetch('http://localhost:4001/pkg/fuzz/8.4.1/main/index.js', { method: 'GET', diff --git a/examples/pkg.put.js b/examples/pkg.put.js index 9f91db53..2cc0c099 100644 --- a/examples/pkg.put.js +++ b/examples/pkg.put.js @@ -1,11 +1,9 @@ /* eslint-disable no-console */ /* eslint-disable import/no-extraneous-dependencies */ -'use strict'; - -const FormData = require('form-data'); -const fetch = require('node-fetch'); -const fs = require('fs'); +import FormData from 'form-data'; +import fetch from 'node-fetch'; +import fs from 'node:fs'; const authenticate = async (address) => { const formData = new FormData(); diff --git a/lib/classes/alias.js b/lib/classes/alias.js index ce38e0bc..397c1a42 100644 --- a/lib/classes/alias.js +++ b/lib/classes/alias.js @@ -1,5 +1,3 @@ -'use strict'; - const Alias = class Alias { constructor({ name = '', type = '', alias = '', org = '' } = {}) { this._version = ''; @@ -47,4 +45,5 @@ const Alias = class Alias { return 'Alias'; } } -module.exports = Alias; + +export default Alias; \ No newline at end of file diff --git a/lib/classes/asset.js b/lib/classes/asset.js index bd629e6d..4919539a 100644 --- a/lib/classes/asset.js +++ b/lib/classes/asset.js @@ -1,7 +1,5 @@ -'use strict'; - -const mime = require('mime/lite'); -const path = require('path'); +import mime from 'mime'; +import path from 'node:path'; /** * Meta information about an Asset. @@ -95,4 +93,5 @@ const Asset = class Asset { return 'Asset'; } } -module.exports = Asset; + +export default Asset; \ No newline at end of file diff --git a/lib/classes/author.js b/lib/classes/author.js index 715ce8a4..b7a97f27 100644 --- a/lib/classes/author.js +++ b/lib/classes/author.js @@ -1,5 +1,3 @@ -'use strict'; - const Author = class Author { constructor({ name = '', user = '' } = {}) { this._name = name; @@ -25,4 +23,5 @@ const Author = class Author { return 'Author'; } } -module.exports = Author; + +export default Author; diff --git a/lib/classes/http-incoming.js b/lib/classes/http-incoming.js index 1aa8ce72..fe2559cc 100644 --- a/lib/classes/http-incoming.js +++ b/lib/classes/http-incoming.js @@ -1,5 +1,3 @@ -'use strict'; - /** * A bearer object to hold misc data through a http * request / response cyclus. @@ -70,4 +68,5 @@ const HttpIncoming = class HttpIncoming { return 'HttpIncoming'; } }; -module.exports = HttpIncoming; + +export default HttpIncoming; diff --git a/lib/classes/http-outgoing.js b/lib/classes/http-outgoing.js index 89355714..838a23c0 100644 --- a/lib/classes/http-outgoing.js +++ b/lib/classes/http-outgoing.js @@ -1,6 +1,4 @@ -'use strict'; - -const { stream } = require('@eik/common'); +import { stream } from '@eik/common'; const STATUS_CODES = [ 100, 101, 102, 103, @@ -88,4 +86,4 @@ const HttpOutgoing = class HttpOutgoing { return 'HttpOutgoing'; } } -module.exports = HttpOutgoing; +export default HttpOutgoing; diff --git a/lib/classes/meta.js b/lib/classes/meta.js index d651c0b5..a123ea79 100644 --- a/lib/classes/meta.js +++ b/lib/classes/meta.js @@ -1,5 +1,3 @@ -'use strict'; - const Meta = class Meta { constructor({ value = '', @@ -28,4 +26,5 @@ const Meta = class Meta { return 'Meta'; } } -module.exports = Meta; + +export default Meta; diff --git a/lib/classes/package.js b/lib/classes/package.js index 40d76c13..fbfaa19e 100644 --- a/lib/classes/package.js +++ b/lib/classes/package.js @@ -1,8 +1,6 @@ -'use strict'; - -const crypto = require('crypto'); -const Asset = require('./asset'); -const Meta = require('./meta'); +import crypto from 'node:crypto'; +import Asset from './asset.js'; +import Meta from './meta.js'; const Package = class Package { constructor({ version = '', type = '', name = '', org = '', author = {} } = {}) { @@ -85,4 +83,4 @@ const Package = class Package { return 'Package'; } } -module.exports = Package; +export default Package; diff --git a/lib/classes/versions.js b/lib/classes/versions.js index 16199360..0ac5d019 100644 --- a/lib/classes/versions.js +++ b/lib/classes/versions.js @@ -1,6 +1,4 @@ -'use strict'; - -const semver = require('semver'); +import semver from 'semver'; const Versions = class Versions { constructor({ versions = [], type = '', name = '', org = '' } = {}) { @@ -65,4 +63,4 @@ const Versions = class Versions { return 'Versions'; } } -module.exports = Versions; +export default Versions; diff --git a/lib/handlers/alias.delete.js b/lib/handlers/alias.delete.js index 82e033b6..73f08361 100644 --- a/lib/handlers/alias.delete.js +++ b/lib/handlers/alias.delete.js @@ -1,15 +1,13 @@ -'use strict'; +import { validators } from '@eik/common'; +import originalUrl from 'original-url'; +import HttpError from 'http-errors'; +import Metrics from '@metrics/client'; +import abslog from 'abslog'; -const { validators } = require('@eik/common'); -const originalUrl = require('original-url'); -const HttpError = require('http-errors'); -const Metrics = require('@metrics/client'); -const abslog = require('abslog'); - -const { createFilePathToAlias } = require('../utils/path-builders-fs'); -const HttpOutgoing = require('../classes/http-outgoing'); -const config = require('../utils/defaults'); -const utils = require('../utils/utils'); +import { createFilePathToAlias } from '../utils/path-builders-fs.js'; +import { decodeUriComponent } from '../utils/utils.js'; +import HttpOutgoing from '../classes/http-outgoing.js'; +import config from '../utils/defaults.js'; const AliasDel = class AliasDel { constructor({ @@ -61,8 +59,8 @@ const AliasDel = class AliasDel { async handler(req, user, type, name, alias) { const end = this._histogram.timer(); - const pAlias = utils.decodeUriComponent(alias); - const pName = utils.decodeUriComponent(name); + const pAlias = decodeUriComponent(alias); + const pName = decodeUriComponent(name); try { validators.alias(pAlias); @@ -124,4 +122,4 @@ const AliasDel = class AliasDel { return outgoing; } }; -module.exports = AliasDel; +export default AliasDel; diff --git a/lib/handlers/alias.get.js b/lib/handlers/alias.get.js index c311fb15..43c62d51 100644 --- a/lib/handlers/alias.get.js +++ b/lib/handlers/alias.get.js @@ -1,16 +1,14 @@ -'use strict'; +import { validators } from '@eik/common'; +import originalUrl from 'original-url'; +import HttpError from 'http-errors'; +import abslog from 'abslog'; +import Metrics from '@metrics/client'; -const { validators } = require('@eik/common'); -const originalUrl = require('original-url'); -const HttpError = require('http-errors'); -const abslog = require('abslog'); -const Metrics = require('@metrics/client'); - -const { createURIToTargetOfAlias } = require('../utils/path-builders-uri'); -const { createFilePathToAlias } = require('../utils/path-builders-fs'); -const HttpOutgoing = require('../classes/http-outgoing'); -const utils = require('../utils/utils'); -const config = require('../utils/defaults'); +import { decodeUriComponent, readJSON } from '../utils/utils.js'; +import { createURIToTargetOfAlias } from '../utils/path-builders-uri.js'; +import { createFilePathToAlias } from '../utils/path-builders-fs.js'; +import HttpOutgoing from '../classes/http-outgoing.js'; +import config from '../utils/defaults.js'; const AliasGet = class AliasGet { constructor({ @@ -53,9 +51,9 @@ const AliasGet = class AliasGet { async handler(req, type, name, alias, extra) { const end = this._histogram.timer(); - const pAlias = utils.decodeUriComponent(alias); - const pExtra = utils.decodeUriComponent(extra); - const pName = utils.decodeUriComponent(name); + const pAlias = decodeUriComponent(alias); + const pExtra = decodeUriComponent(extra); + const pName = decodeUriComponent(name); try { validators.alias(pAlias); @@ -82,7 +80,7 @@ const AliasGet = class AliasGet { const path = createFilePathToAlias({ org, type, name: pName, alias: pAlias }); try { - const obj = await utils.readJSON(this._sink, path); + const obj = await readJSON(this._sink, path); const location = createURIToTargetOfAlias({ extra: pExtra, ...obj }); const outgoing = new HttpOutgoing(); @@ -103,4 +101,4 @@ const AliasGet = class AliasGet { } } }; -module.exports = AliasGet; +export default AliasGet; diff --git a/lib/handlers/alias.post.js b/lib/handlers/alias.post.js index 3ddbfb01..1f93a75a 100644 --- a/lib/handlers/alias.post.js +++ b/lib/handlers/alias.post.js @@ -1,23 +1,21 @@ -'use strict'; +import { validators } from '@eik/common'; +import originalUrl from 'original-url'; +import HttpError from 'http-errors'; +import abslog from 'abslog'; +import Metrics from '@metrics/client'; -const { validators } = require('@eik/common'); -const originalUrl = require('original-url'); -const HttpError = require('http-errors'); -const abslog = require('abslog'); -const Metrics = require('@metrics/client'); - -const { +import { createFilePathToAlias, createFilePathToAliasOrigin, -} = require('../utils/path-builders-fs'); -const { createURIToAlias } = require('../utils/path-builders-uri'); -const MultipartParser = require('../multipart/parser'); -const HttpIncoming = require('../classes/http-incoming'); -const HttpOutgoing = require('../classes/http-outgoing'); -const Author = require('../classes/author'); -const Alias = require('../classes/alias'); -const config = require('../utils/defaults'); -const utils = require('../utils/utils'); +} from '../utils/path-builders-fs.js'; +import { createURIToAlias } from '../utils/path-builders-uri.js'; +import MultipartParser from '../multipart/parser.js'; +import HttpIncoming from '../classes/http-incoming.js'; +import HttpOutgoing from '../classes/http-outgoing.js'; +import Author from '../classes/author.js'; +import Alias from '../classes/alias.js'; +import config from '../utils/defaults.js'; +import { decodeUriComponent, writeJSON } from '../utils/utils.js'; const AliasPost = class AliasPost { constructor({ @@ -112,7 +110,7 @@ const AliasPost = class AliasPost { ); try { - await utils.writeJSON( + await writeJSON( this._sink, path, alias, @@ -152,8 +150,8 @@ const AliasPost = class AliasPost { async handler(req, user, type, name, alias) { const end = this._histogram.timer(); - const pAlias = utils.decodeUriComponent(alias); - const pName = utils.decodeUriComponent(name); + const pAlias = decodeUriComponent(alias); + const pName = decodeUriComponent(name); try { validators.alias(pAlias); @@ -208,4 +206,4 @@ const AliasPost = class AliasPost { return outgoing; } }; -module.exports = AliasPost; +export default AliasPost; diff --git a/lib/handlers/alias.put.js b/lib/handlers/alias.put.js index 9ea59d59..1d064a31 100644 --- a/lib/handlers/alias.put.js +++ b/lib/handlers/alias.put.js @@ -1,23 +1,21 @@ -'use strict'; +import { validators } from '@eik/common'; +import originalUrl from 'original-url'; +import HttpError from 'http-errors'; +import abslog from 'abslog'; +import Metrics from '@metrics/client'; -const { validators } = require('@eik/common'); -const originalUrl = require('original-url'); -const HttpError = require('http-errors'); -const abslog = require('abslog'); -const Metrics = require('@metrics/client'); - -const { +import { createFilePathToAlias, createFilePathToAliasOrigin -} = require('../utils/path-builders-fs'); -const { createURIToAlias } = require('../utils/path-builders-uri'); -const MultipartParser = require('../multipart/parser'); -const HttpIncoming = require('../classes/http-incoming'); -const HttpOutgoing = require('../classes/http-outgoing'); -const Author = require('../classes/author'); -const Alias = require('../classes/alias'); -const utils = require('../utils/utils'); -const config = require('../utils/defaults'); +} from '../utils/path-builders-fs.js'; +import { decodeUriComponent, writeJSON } from '../utils/utils.js'; +import { createURIToAlias } from '../utils/path-builders-uri.js'; +import MultipartParser from '../multipart/parser.js'; +import HttpIncoming from '../classes/http-incoming.js'; +import HttpOutgoing from '../classes/http-outgoing.js'; +import Author from '../classes/author.js'; +import Alias from '../classes/alias.js'; +import config from '../utils/defaults.js'; const AliasPut = class AliasPut { constructor({ @@ -112,7 +110,7 @@ const AliasPut = class AliasPut { ); try { - await utils.writeJSON( + await writeJSON( this._sink, path, alias, @@ -151,8 +149,8 @@ const AliasPut = class AliasPut { async handler(req, user, type, name, alias) { const end = this._histogram.timer(); - const pAlias = utils.decodeUriComponent(alias); - const pName = utils.decodeUriComponent(name); + const pAlias = decodeUriComponent(alias); + const pName = decodeUriComponent(name); try { validators.alias(pAlias); @@ -207,4 +205,4 @@ const AliasPut = class AliasPut { return outgoing; } }; -module.exports = AliasPut; +export default AliasPut; diff --git a/lib/handlers/auth.post.js b/lib/handlers/auth.post.js index 7853150d..91e09415 100644 --- a/lib/handlers/auth.post.js +++ b/lib/handlers/auth.post.js @@ -1,15 +1,13 @@ -'use strict'; +import originalUrl from 'original-url'; +import HttpError from 'http-errors'; +import Metrics from '@metrics/client'; +import abslog from 'abslog'; -const originalUrl = require('original-url'); -const HttpError = require('http-errors'); -const Metrics = require('@metrics/client'); -const abslog = require('abslog'); - -const MultipartParser = require('../multipart/parser'); -const HttpIncoming = require('../classes/http-incoming'); -const HttpOutgoing = require('../classes/http-outgoing'); -const Author = require('../classes/author'); -const config = require('../utils/defaults'); +import MultipartParser from '../multipart/parser.js'; +import HttpIncoming from '../classes/http-incoming.js'; +import HttpOutgoing from '../classes/http-outgoing.js'; +import Author from '../classes/author.js'; +import config from '../utils/defaults.js'; const AuthPost = class AuthPost { constructor({ @@ -108,4 +106,4 @@ const AuthPost = class AuthPost { return outgoing; } }; -module.exports = AuthPost; +export default AuthPost; diff --git a/lib/handlers/map.get.js b/lib/handlers/map.get.js index b63769b3..52adf27c 100644 --- a/lib/handlers/map.get.js +++ b/lib/handlers/map.get.js @@ -1,15 +1,13 @@ -'use strict'; +import { validators } from '@eik/common'; +import originalUrl from 'original-url'; +import HttpError from 'http-errors'; +import abslog from 'abslog'; +import Metrics from '@metrics/client'; -const { validators } = require('@eik/common'); -const originalUrl = require('original-url'); -const HttpError = require('http-errors'); -const abslog = require('abslog'); -const Metrics = require('@metrics/client'); - -const { createFilePathToImportMap } = require('../utils/path-builders-fs'); -const HttpOutgoing = require('../classes/http-outgoing'); -const config = require('../utils/defaults'); -const utils = require('../utils/utils'); +import { createFilePathToImportMap } from '../utils/path-builders-fs.js'; +import HttpOutgoing from '../classes/http-outgoing.js'; +import config from '../utils/defaults.js'; +import { decodeUriComponent } from '../utils/utils.js'; const MapGet = class MapGet { constructor({ @@ -55,8 +53,8 @@ const MapGet = class MapGet { async handler(req, name, version) { const end = this._histogram.timer(); - const pVersion = utils.decodeUriComponent(version); - const pName = utils.decodeUriComponent(name); + const pVersion = decodeUriComponent(version); + const pName = decodeUriComponent(name); try { validators.version(pVersion); @@ -116,4 +114,4 @@ const MapGet = class MapGet { } } }; -module.exports = MapGet; +export default MapGet; diff --git a/lib/handlers/map.put.js b/lib/handlers/map.put.js index 0b3838a7..cfdb4af9 100644 --- a/lib/handlers/map.put.js +++ b/lib/handlers/map.put.js @@ -1,24 +1,22 @@ -'use strict'; - -const { validators } = require('@eik/common'); -const originalUrl = require('original-url'); -const HttpError = require('http-errors'); -const Busboy = require('busboy'); -const crypto = require('crypto'); -const abslog = require('abslog'); -const Metrics = require('@metrics/client'); - -const { +import { validators } from '@eik/common'; +import originalUrl from 'original-url'; +import HttpError from 'http-errors'; +import Busboy from 'busboy'; +import crypto from 'node:crypto'; +import abslog from 'abslog'; +import Metrics from '@metrics/client'; + +import { createFilePathToImportMap, createFilePathToVersion, -} = require('../utils/path-builders-fs'); -const { createURIPathToImportMap } = require('../utils/path-builders-uri'); -const HttpIncoming = require('../classes/http-incoming'); -const HttpOutgoing = require('../classes/http-outgoing'); -const Versions = require('../classes/versions'); -const Author = require('../classes/author'); -const config = require('../utils/defaults'); -const utils = require('../utils/utils'); +} from '../utils/path-builders-fs.js'; +import { createURIPathToImportMap } from '../utils/path-builders-uri.js'; +import HttpIncoming from '../classes/http-incoming.js'; +import HttpOutgoing from '../classes/http-outgoing.js'; +import Versions from '../classes/versions.js'; +import Author from '../classes/author.js'; +import config from '../utils/defaults.js'; +import { decodeUriComponent, streamCollector, writeJSON, readJSON, } from '../utils/utils.js'; const MapPut = class MapPut { constructor({ @@ -118,7 +116,7 @@ const MapPut = class MapPut { // parse it as JSON or not. let obj = {}; try { - const str = await utils.streamCollector(file); + const str = await streamCollector(file); hasher.update(str); obj = JSON.parse(str); } catch (error) { @@ -130,7 +128,7 @@ const MapPut = class MapPut { // Write file to storage. try { this._log.info(`map:put - Start writing import map to sink - Pathname: ${path}`); - await utils.writeJSON(this._sink, path, obj, 'application/json'); + await writeJSON(this._sink, path, obj, 'application/json'); } catch (error) { this._log.error(`map:put - Failed writing import map to sink - Pathname: ${path}`); this._log.trace(error); @@ -146,7 +144,7 @@ const MapPut = class MapPut { const path = createFilePathToVersion(incoming); let versions; try { - const obj = await utils.readJSON(this._sink, path); + const obj = await readJSON(this._sink, path); versions = new Versions(obj); this._log.info( `map:put - Successfully read version meta file from sink - Pathname: ${path}`, @@ -163,7 +161,7 @@ const MapPut = class MapPut { async _writeVersions(incoming, versions) { const path = createFilePathToVersion(incoming); - await utils.writeJSON(this._sink, path, versions, 'application/json'); + await writeJSON(this._sink, path, versions, 'application/json'); this._log.info( `map:put - Successfully wrote version meta file to sink - Pathname: ${path}`, ); @@ -172,8 +170,8 @@ const MapPut = class MapPut { async handler(req, user, name, version) { const end = this._histogram.timer(); - const pVersion = utils.decodeUriComponent(version); - const pName = utils.decodeUriComponent(name); + const pVersion = decodeUriComponent(version); + const pName = decodeUriComponent(name); try { validators.version(pVersion); @@ -237,4 +235,4 @@ const MapPut = class MapPut { return outgoing; } }; -module.exports = MapPut; +export default MapPut; diff --git a/lib/handlers/pkg.get.js b/lib/handlers/pkg.get.js index b137b1c7..e09337ad 100644 --- a/lib/handlers/pkg.get.js +++ b/lib/handlers/pkg.get.js @@ -1,16 +1,14 @@ -'use strict'; - -const { validators } = require('@eik/common'); -const originalUrl = require('original-url'); -const HttpError = require('http-errors'); -const abslog = require('abslog'); -const Metrics = require('@metrics/client'); - -const { createFilePathToAsset } = require('../utils/path-builders-fs'); -const HttpOutgoing = require('../classes/http-outgoing'); -const Asset = require('../classes/asset'); -const config = require('../utils/defaults'); -const utils = require('../utils/utils'); +import { validators } from '@eik/common'; +import originalUrl from 'original-url'; +import HttpError from 'http-errors'; +import abslog from 'abslog'; +import Metrics from '@metrics/client'; + +import { createFilePathToAsset } from '../utils/path-builders-fs.js'; +import { decodeUriComponent } from '../utils/utils.js'; +import HttpOutgoing from '../classes/http-outgoing.js'; +import Asset from '../classes/asset.js'; +import config from '../utils/defaults.js'; const PkgGet = class PkgGet { constructor({ @@ -56,9 +54,9 @@ const PkgGet = class PkgGet { async handler(req, type, name, version, extra) { const end = this._histogram.timer(); - const pVersion = utils.decodeUriComponent(version); - const pExtra = utils.decodeUriComponent(extra); - const pName = utils.decodeUriComponent(name); + const pVersion = decodeUriComponent(version); + const pExtra = decodeUriComponent(extra); + const pName = decodeUriComponent(name); try { validators.version(pVersion); @@ -126,4 +124,4 @@ const PkgGet = class PkgGet { } } }; -module.exports = PkgGet; +export default PkgGet; diff --git a/lib/handlers/pkg.log.js b/lib/handlers/pkg.log.js index 78179d68..38f85798 100644 --- a/lib/handlers/pkg.log.js +++ b/lib/handlers/pkg.log.js @@ -1,15 +1,13 @@ -'use strict'; +import { validators } from '@eik/common'; +import originalUrl from 'original-url'; +import HttpError from 'http-errors'; +import abslog from 'abslog'; +import Metrics from '@metrics/client'; -const { validators } = require('@eik/common'); -const originalUrl = require('original-url'); -const HttpError = require('http-errors'); -const abslog = require('abslog'); -const Metrics = require('@metrics/client'); - -const { createFilePathToPackage } = require('../utils/path-builders-fs'); -const HttpOutgoing = require('../classes/http-outgoing'); -const config = require('../utils/defaults'); -const utils = require('../utils/utils'); +import { createFilePathToPackage } from '../utils/path-builders-fs.js'; +import { decodeUriComponent } from '../utils/utils.js'; +import HttpOutgoing from '../classes/http-outgoing.js'; +import config from '../utils/defaults.js'; const PkgLog = class PkgLog { constructor({ @@ -54,8 +52,8 @@ const PkgLog = class PkgLog { async handler(req, type, name, version) { const end = this._histogram.timer(); - const pVersion = utils.decodeUriComponent(version); - const pName = utils.decodeUriComponent(name); + const pVersion = decodeUriComponent(version); + const pName = decodeUriComponent(name); try { validators.version(pVersion); @@ -114,4 +112,4 @@ const PkgLog = class PkgLog { } } }; -module.exports = PkgLog; +export default PkgLog; diff --git a/lib/handlers/pkg.put.js b/lib/handlers/pkg.put.js index f087ec4a..4b74ad11 100644 --- a/lib/handlers/pkg.put.js +++ b/lib/handlers/pkg.put.js @@ -1,25 +1,22 @@ -'use strict'; +import { validators } from '@eik/common'; +import originalUrl from 'original-url'; +import HttpError from 'http-errors'; +import Metrics from '@metrics/client'; +import abslog from 'abslog'; -const { validators } = require('@eik/common'); -const originalUrl = require('original-url'); -const HttpError = require('http-errors'); -const Metrics = require('@metrics/client'); -const abslog = require('abslog'); - -const { +import { createFilePathToPackage, createFilePathToVersion, -} = require('../utils/path-builders-fs'); -const { createURIPathToPkgLog } = require('../utils/path-builders-uri'); -const HttpIncoming = require('../classes/http-incoming'); -const HttpOutgoing = require('../classes/http-outgoing'); -const Versions = require('../classes/versions'); -const Package = require('../classes/package'); -const Author = require('../classes/author'); -const utils = require('../utils/utils'); -const config = require('../utils/defaults'); - -const MultipartParser = require('../multipart/parser'); +} from '../utils/path-builders-fs.js'; +import { decodeUriComponent, writeJSON, readJSON } from '../utils/utils.js'; +import { createURIPathToPkgLog } from '../utils/path-builders-uri.js'; +import MultipartParser from '../multipart/parser.js'; +import HttpIncoming from '../classes/http-incoming.js'; +import HttpOutgoing from '../classes/http-outgoing.js'; +import Versions from '../classes/versions.js'; +import Package from '../classes/package.js'; +import Author from '../classes/author.js'; +import config from '../utils/defaults.js'; const PkgPut = class PkgPut { constructor({ @@ -84,7 +81,7 @@ const PkgPut = class PkgPut { return pkg; }).then(async (pkg) => { const path = createFilePathToPackage(pkg); - await utils.writeJSON( + await writeJSON( this._sink, path, pkg, @@ -106,7 +103,7 @@ const PkgPut = class PkgPut { const path = createFilePathToVersion(incoming); let versions; try { - const obj = await utils.readJSON(this._sink, path); + const obj = await readJSON(this._sink, path); versions = new Versions(obj); this._log.info( `pkg:put - Successfully read version meta file from sink - Pathname: ${path}`, @@ -123,7 +120,7 @@ const PkgPut = class PkgPut { async _writeVersions(incoming, versions) { const path = createFilePathToVersion(incoming); - await utils.writeJSON(this._sink, path, versions, 'application/json'); + await writeJSON(this._sink, path, versions, 'application/json'); this._log.info( `pkg:put - Successfully wrote version meta file to sink - Pathname: ${path}`, ); @@ -132,8 +129,8 @@ const PkgPut = class PkgPut { async handler(req, user, type, name, version) { const end = this._histogram.timer(); - const pVersion = utils.decodeUriComponent(version); - const pName = utils.decodeUriComponent(name); + const pVersion = decodeUriComponent(version); + const pName = decodeUriComponent(name); try { validators.version(pVersion); @@ -198,4 +195,4 @@ const PkgPut = class PkgPut { return outgoing; } }; -module.exports = PkgPut; +export default PkgPut; diff --git a/lib/handlers/versions.get.js b/lib/handlers/versions.get.js index 596531f4..1f439917 100644 --- a/lib/handlers/versions.get.js +++ b/lib/handlers/versions.get.js @@ -1,15 +1,13 @@ -'use strict'; +import { validators } from '@eik/common'; +import originalUrl from 'original-url'; +import HttpError from 'http-errors'; +import Metrics from '@metrics/client'; +import abslog from 'abslog'; -const { validators } = require('@eik/common'); -const originalUrl = require('original-url'); -const HttpError = require('http-errors'); -const Metrics = require('@metrics/client'); -const abslog = require('abslog'); - -const { createFilePathToVersion } = require('../utils/path-builders-fs'); -const HttpOutgoing = require('../classes/http-outgoing'); -const config = require('../utils/defaults'); -const utils = require('../utils/utils'); +import { createFilePathToVersion } from '../utils/path-builders-fs.js'; +import { decodeUriComponent } from '../utils/utils.js'; +import HttpOutgoing from '../classes/http-outgoing.js'; +import config from '../utils/defaults.js'; const VersionsGet = class VersionsGet { constructor({ @@ -55,7 +53,7 @@ const VersionsGet = class VersionsGet { async handler(req, type, name) { const end = this._histogram.timer(); - const pName = utils.decodeUriComponent(name); + const pName = decodeUriComponent(name); try { validators.name(pName); @@ -118,4 +116,4 @@ const VersionsGet = class VersionsGet { } } }; -module.exports = VersionsGet; +export default VersionsGet; diff --git a/lib/main.js b/lib/main.js index 80547572..27e0d29f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,26 +1,22 @@ -'use strict'; +import VersionsGet from './handlers/versions.get.js'; +import AliasPost from './handlers/alias.post.js'; +import AliasPut from './handlers/alias.put.js'; +import AliasGet from './handlers/alias.get.js'; +import AliasDel from './handlers/alias.delete.js'; +import AuthPost from './handlers/auth.post.js'; +import PkgLog from './handlers/pkg.log.js'; +import PkgGet from './handlers/pkg.get.js'; +import PkgPut from './handlers/pkg.put.js'; +import MapGet from './handlers/map.get.js'; +import MapPut from './handlers/map.put.js'; -const VersionsGet = require('./handlers/versions.get'); -const AliasPost = require('./handlers/alias.post'); -const AliasPut = require('./handlers/alias.put'); -const AliasGet = require('./handlers/alias.get'); -const AliasDel = require('./handlers/alias.delete'); -const AuthPost = require('./handlers/auth.post'); -const PkgLog = require('./handlers/pkg.log'); -const PkgGet = require('./handlers/pkg.get'); -const PkgPut = require('./handlers/pkg.put'); -const MapGet = require('./handlers/map.get'); -const MapPut = require('./handlers/map.put'); +import MEM from './sinks/mem.js'; +import FS from './sinks/fs.js'; -const MEM = require('./sinks/mem'); -const FS = require('./sinks/fs'); +import HealthCheck from './utils/healthcheck.js'; +import globals from './utils/globals.js'; -const HealthCheck = require('./utils/healthcheck'); -const globals = require('./utils/globals'); - -module.exports.HealthCheck = HealthCheck; - -module.exports.http = { +const http = { VersionsGet, AliasPost, AliasPut, @@ -34,14 +30,21 @@ module.exports.http = { MapPut, }; -module.exports.sink = { +const sink = { MEM, FS, }; -module.exports.prop = { +const prop = { base_auth: globals.BASE_AUTHENTICATION, base_map: globals.BASE_IMPORT_MAPS, base_pkg: globals.BASE_PACKAGES, base_npm: globals.BASE_NPM, }; + +export default { + HealthCheck, + http, + sink, + prop, +} \ No newline at end of file diff --git a/lib/multipart/form-field.js b/lib/multipart/form-field.js index a4f2147d..29838558 100644 --- a/lib/multipart/form-field.js +++ b/lib/multipart/form-field.js @@ -1,5 +1,3 @@ -'use strict'; - const FormField = class FormField { constructor({ value = '', @@ -28,4 +26,4 @@ const FormField = class FormField { return 'FormField'; } } -module.exports = FormField; +export default FormField; diff --git a/lib/multipart/form-file.js b/lib/multipart/form-file.js index 0cf349b1..80f352b7 100644 --- a/lib/multipart/form-file.js +++ b/lib/multipart/form-file.js @@ -1,5 +1,3 @@ -'use strict'; - const FormFile = class FormFile { constructor({ value = [], @@ -29,4 +27,4 @@ const FormFile = class FormFile { return 'FormFile'; } } -module.exports = FormFile; +export default FormFile; diff --git a/lib/multipart/parser.js b/lib/multipart/parser.js index ce054147..ba7efabb 100644 --- a/lib/multipart/parser.js +++ b/lib/multipart/parser.js @@ -1,16 +1,14 @@ -'use strict'; - -const { pipeline } = require('stream'); -const HttpError = require('http-errors'); -const Busboy = require('busboy'); -const abslog = require('abslog'); -const ssri = require('ssri'); -const tar = require('tar'); - -const { createFilePathToAsset } = require('../utils/path-builders-fs'); -const FormField = require('./form-field'); -const FormFile = require('./form-file'); -const Asset = require('../classes/asset'); +import { pipeline } from 'node:stream'; +import HttpError from 'http-errors'; +import Busboy from 'busboy'; +import abslog from 'abslog'; +import ssri from 'ssri'; +import tar from 'tar'; + +import { createFilePathToAsset } from '../utils/path-builders-fs.js'; +import FormField from './form-field.js'; +import FormFile from './form-file.js'; +import Asset from '../classes/asset.js'; const MultipartParser = class MultipartParser { constructor({ @@ -216,4 +214,4 @@ const MultipartParser = class MultipartParser { }); } } -module.exports = MultipartParser; +export default MultipartParser; diff --git a/lib/sinks/fs.js b/lib/sinks/fs.js index 37be1092..77ec972e 100644 --- a/lib/sinks/fs.js +++ b/lib/sinks/fs.js @@ -1,15 +1,13 @@ -'use strict'; +import { ReadFile } from '@eik/common'; +import Metrics from '@metrics/client'; +import rimraf from 'rimraf'; +import Sink from '@eik/sink'; +import mime from 'mime'; +import path from 'node:path'; +import fs from 'node:fs'; -const { ReadFile } = require('@eik/common'); -const Metrics = require('@metrics/client'); -const rimraf = require('rimraf'); -const Sink = require('@eik/sink'); -const mime = require('mime/lite'); -const path = require('path'); -const fs = require('fs'); - -const { etagFromFsStat } = require('../utils/utils'); -const conf = require('../utils/defaults'); +import { etagFromFsStat } from '../utils/utils.js'; +import conf from '../utils/defaults.js'; /** * A sink for persisting files to local file system @@ -263,4 +261,4 @@ const SinkFS = class SinkFS extends Sink { return 'SinkFS'; } } -module.exports = SinkFS; +export default SinkFS; diff --git a/lib/sinks/mem-entry.js b/lib/sinks/mem-entry.js index 51c6dafa..8691bea7 100644 --- a/lib/sinks/mem-entry.js +++ b/lib/sinks/mem-entry.js @@ -1,6 +1,4 @@ -'use strict'; - -const crypto = require('crypto'); +import crypto from 'node:crypto'; const Entry = class Entry { constructor({ @@ -38,4 +36,5 @@ const Entry = class Entry { return 'Entry'; } } -module.exports = Entry; + +export default Entry; diff --git a/lib/sinks/mem.js b/lib/sinks/mem.js index c4de8e52..2b02aa0c 100644 --- a/lib/sinks/mem.js +++ b/lib/sinks/mem.js @@ -1,12 +1,10 @@ -'use strict'; +import { Writable, Readable } from 'node:stream'; +import { ReadFile } from '@eik/common'; +import { join } from 'node:path'; +import Metrics from '@metrics/client'; +import Sink from '@eik/sink'; -const { Writable, Readable } = require('stream'); -const { ReadFile } = require('@eik/common'); -const { join } = require('path'); -const Metrics = require('@metrics/client'); -const Sink = require('@eik/sink'); - -const Entry = require('./mem-entry'); +import Entry from './mem-entry.js'; const DEFAULT_ROOT_PATH = '/eik'; @@ -209,4 +207,4 @@ const SinkMem = class SinkMem extends Sink { return 'SinkMEM'; } } -module.exports = SinkMem; +export default SinkMem; diff --git a/lib/sinks/test.js b/lib/sinks/test.js index 60641c17..a5b9fe8a 100644 --- a/lib/sinks/test.js +++ b/lib/sinks/test.js @@ -1,13 +1,11 @@ -'use strict'; +import { Writable, Readable } from 'node:stream'; +import { ReadFile } from '@eik/common'; +import Metrics from '@metrics/client'; +import Sink from '@eik/sink'; +import mime from 'mime'; +import path from 'node:path'; -const { Writable, Readable } = require('stream'); -const { ReadFile } = require('@eik/common'); -const Metrics = require('@metrics/client'); -const Sink = require('@eik/sink'); -const mime = require('mime/lite'); -const path = require('path'); - -const Entry = require('./mem-entry'); +import Entry from './mem-entry.js'; const DEFAULT_ROOT_PATH = '/eik'; @@ -278,4 +276,5 @@ const SinkTest = class SinkTest extends Sink { return 'SinkTest'; } } -module.exports = SinkTest; + +export default SinkTest; diff --git a/lib/utils/defaults.js b/lib/utils/defaults.js index 44b84ada..8ac26040 100644 --- a/lib/utils/defaults.js +++ b/lib/utils/defaults.js @@ -1,7 +1,5 @@ -'use strict'; - -const path = require('path'); -const os = require('os'); +import path from 'node:path'; +import os from 'node:os'; const config = { authKey: 'change_me', @@ -14,4 +12,5 @@ const config = { ['127.0.0.1', 'local'], ], }; -module.exports = config; + +export default config; diff --git a/lib/utils/globals.js b/lib/utils/globals.js index 2a10fb93..f0af9de3 100644 --- a/lib/utils/globals.js +++ b/lib/utils/globals.js @@ -1,5 +1,3 @@ -'use strict'; - const globals = { BASE_AUTHENTICATION: 'auth', BASE_IMPORT_MAPS: 'map', @@ -7,4 +5,4 @@ const globals = { BASE_NPM: 'npm', ROOT: '/', }; -module.exports = globals; +export default globals; diff --git a/lib/utils/healthcheck.js b/lib/utils/healthcheck.js index 53d3c724..ec7b5d43 100644 --- a/lib/utils/healthcheck.js +++ b/lib/utils/healthcheck.js @@ -1,15 +1,10 @@ -'use strict'; +import { Writable, pipeline } from 'node:stream'; +import { URL } from 'node:url'; +import abslog from 'abslog'; +import slug from 'unique-slug'; +import fs from 'node:fs'; -const { Writable, pipeline } = require('stream'); -const abslog = require('abslog'); -const slug = require('unique-slug'); -const path = require('path'); -const fs = require('fs'); - -const fileReader = (file = '../../README.md') => { - const pathname = path.join(__dirname, file); - return fs.createReadStream(pathname); -}; +const fileReader = (file = '../../README.md') => fs.createReadStream(new URL(file, import.meta.url)); const HealthCheck = class HealthCheck { constructor({ sink, logger } = {}) { @@ -112,4 +107,5 @@ const HealthCheck = class HealthCheck { return 'HealthCheck'; } } -module.exports = HealthCheck; \ No newline at end of file + +export default HealthCheck; \ No newline at end of file diff --git a/lib/utils/path-builders-fs.js b/lib/utils/path-builders-fs.js index de85ade7..cf6347d5 100644 --- a/lib/utils/path-builders-fs.js +++ b/lib/utils/path-builders-fs.js @@ -1,37 +1,30 @@ -'use strict'; - -const path = require('path'); -const { BASE_IMPORT_MAPS, ROOT } = require("./globals"); +import path from 'node:path'; +import globals from './globals.js'; // Build file system path to a package file -const createFilePathToPackage = ({ org = '', type = '', name = '', version = '' } = {}) => path.join(ROOT, org, type, name, `${version}.package.json`) -module.exports.createFilePathToPackage = createFilePathToPackage; +const createFilePathToPackage = ({ org = '', type = '', name = '', version = '' } = {}) => path.join(globals.ROOT, org, type, name, `${version}.package.json`) // Build file system path to an asset in a package // pkgAsset -const createFilePathToAsset = ({ org = '', type = '', name = '', version = '', asset = '' } = {}) => path.join(ROOT, org, type, name, version, asset) -module.exports.createFilePathToAsset = createFilePathToAsset; +const createFilePathToAsset = ({ org = '', type = '', name = '', version = '', asset = '' } = {}) => path.join(globals.ROOT, org, type, name, version, asset) // Build file system path to an import map -const createFilePathToImportMap = ({ org = '', name = '', version = '' } = {}) => path.join(ROOT, org, BASE_IMPORT_MAPS, name, `${version}.import-map.json`) -module.exports.createFilePathToImportMap = createFilePathToImportMap; +const createFilePathToImportMap = ({ org = '', name = '', version = '' } = {}) => path.join(globals.ROOT, org, globals.BASE_IMPORT_MAPS, name, `${version}.import-map.json`) // Build file system path to an alias file -const createFilePathToAlias = ({ org = '', type = '', name = '', alias = '' } = {}) => path.join(ROOT, org, type, name, `${alias}.alias.json`) -module.exports.createFilePathToAlias = createFilePathToAlias; +const createFilePathToAlias = ({ org = '', type = '', name = '', alias = '' } = {}) => path.join(globals.ROOT, org, type, name, `${alias}.alias.json`) // Build file system path to an version file -const createFilePathToVersion = ({ org = '', type = '', name = '' } = {}) => path.join(ROOT, org, type, name, 'versions.json') -module.exports.createFilePathToVersion = createFilePathToVersion; +const createFilePathToVersion = ({ org = '', type = '', name = '' } = {}) => path.join(globals.ROOT, org, type, name, 'versions.json') const createFilePathToAliasOrigin = ({org = '', type = '', name = '', version = '',} = {}) => { if(type === 'map') { @@ -39,4 +32,13 @@ const createFilePathToAliasOrigin = ({org = '', type = '', name = '', version = } return createFilePathToPackage({org, type, name, version}) }; -module.exports.createFilePathToAliasOrigin = createFilePathToAliasOrigin \ No newline at end of file + + +export { + createFilePathToPackage, + createFilePathToAsset, + createFilePathToImportMap, + createFilePathToAlias, + createFilePathToVersion, + createFilePathToAliasOrigin, +} \ No newline at end of file diff --git a/lib/utils/path-builders-uri.js b/lib/utils/path-builders-uri.js index 46ce294f..89e11d74 100644 --- a/lib/utils/path-builders-uri.js +++ b/lib/utils/path-builders-uri.js @@ -1,35 +1,35 @@ -'use strict'; - -const path = require('path'); -const { BASE_IMPORT_MAPS, ROOT } = require("./globals"); +import path from 'node:path'; +import globals from './globals.js'; // Build URL pathname to a package log file -const createURIPathToPkgLog = ({ type = '', name = '', version = '' } = {}) => path.join(ROOT, type, name, version) -module.exports.createURIPathToPkgLog = createURIPathToPkgLog; +const createURIPathToPkgLog = ({ type = '', name = '', version = '' } = {}) => path.join(globals.ROOT, type, name, version) // Build URL pathname to an asset in a package -const createURIPathToAsset = ({ type = '', name = '', version = '', asset = '' } = {}) => path.join(ROOT, type, name, version, asset) -module.exports.createURIPathToAsset = createURIPathToAsset; +const createURIPathToAsset = ({ type = '', name = '', version = '', asset = '' } = {}) => path.join(globals.ROOT, type, name, version, asset) // Build URL pathname to an import map -const createURIPathToImportMap = ({ name = '', version = '' } = {}) => path.join(ROOT, BASE_IMPORT_MAPS, name, version) -module.exports.createURIPathToImportMap = createURIPathToImportMap; +const createURIPathToImportMap = ({ name = '', version = '' } = {}) => path.join(globals.ROOT, globals.BASE_IMPORT_MAPS, name, version) // Build URL pathname to an alias source -const createURIToAlias = ({ type = '', name = '', alias = '' } = {}) => path.join(ROOT, type, name, `v${alias}`) -module.exports.createURIToAlias = createURIToAlias; +const createURIToAlias = ({ type = '', name = '', alias = '' } = {}) => path.join(globals.ROOT, type, name, `v${alias}`) // Build URL pathname to an alias target destination -const createURIToTargetOfAlias = ({ type = '', name = '', version = '', extra = '' } = {}) => path.join(ROOT, type, name, version, extra) -module.exports.createURIToTargetOfAlias = createURIToTargetOfAlias; +const createURIToTargetOfAlias = ({ type = '', name = '', version = '', extra = '' } = {}) => path.join(globals.ROOT, type, name, version, extra) +export { + createURIPathToPkgLog, + createURIPathToAsset, + createURIPathToImportMap, + createURIToAlias, + createURIToTargetOfAlias, +} \ No newline at end of file diff --git a/lib/utils/utils.js b/lib/utils/utils.js index e9e657b1..0e87e390 100644 --- a/lib/utils/utils.js +++ b/lib/utils/utils.js @@ -1,6 +1,4 @@ -'use strict'; - -const { Writable, Readable, pipeline } = require('stream'); +import { Writable, Readable, pipeline } from 'node:stream'; const readJSON = (sink, path) => // eslint-disable-next-line no-async-promise-executor @@ -32,7 +30,6 @@ const readJSON = (sink, path) => } }) ; -module.exports.readJSON = readJSON; const writeJSON = (sink, path, obj, contentType) => // eslint-disable-next-line no-async-promise-executor @@ -59,7 +56,6 @@ const writeJSON = (sink, path, obj, contentType) => } }) ; -module.exports.writeJSON = writeJSON; const streamCollector = (from) => new Promise((resolve, reject) => { const buffer = []; @@ -75,18 +71,22 @@ const streamCollector = (from) => new Promise((resolve, reject) => { return resolve(buffer.join('').toString()); }); }); -module.exports.streamCollector = streamCollector; const etagFromFsStat = (stat) => { const mtime = stat.mtime.getTime().toString(16) const size = stat.size.toString(16) return `W/"${size}-${mtime}"`; }; -module.exports.etagFromFsStat = etagFromFsStat; - const decodeUriComponent = (value) => { if (value === null || value === undefined) return value; return decodeURIComponent(value); } -module.exports.decodeUriComponent = decodeUriComponent; \ No newline at end of file + +export { + readJSON, + writeJSON, + streamCollector, + etagFromFsStat, + decodeUriComponent, +} \ No newline at end of file diff --git a/package.json b/package.json index 6abf7557..d9979173 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.2.29", "description": "Core server package", "main": "lib/main.js", + "type": "module", "files": [ "CHANGELOG.md", "package.json", @@ -33,6 +34,7 @@ "unique-slug": "2.0.2" }, "devDependencies": { + "@babel/eslint-parser": "7.16.5", "@semantic-release/changelog": "6.0.1", "@semantic-release/git": "10.0.1", "eslint": "8.6.0", @@ -42,7 +44,7 @@ "eslint-plugin-prettier": "4.0.0", "form-data": "4.0.0", "mkdirp": "1.0.4", - "node-fetch": "2.6.6", + "node-fetch": "3.1.0", "prettier": "2.5.1", "semantic-release": "18.0.1", "tap": "15.1.6" diff --git a/release.config.js b/release.config.cjs similarity index 100% rename from release.config.js rename to release.config.cjs diff --git a/test/classes/alias.js b/test/classes/alias.js index 688701e2..0257d8d0 100644 --- a/test/classes/alias.js +++ b/test/classes/alias.js @@ -1,15 +1,13 @@ -'use strict'; +import tap from 'tap'; +import Alias from '../../lib/classes/alias.js'; -const { test } = require('tap'); -const Alias = require('../../lib/classes/alias'); - -test('Alias() - Object type', (t) => { +tap.test('Alias() - Object type', (t) => { const obj = new Alias(); t.equal(Object.prototype.toString.call(obj), '[object Alias]', 'should be Alias'); t.end(); }); -test('Alias() - Default property values', (t) => { +tap.test('Alias() - Default property values', (t) => { const obj = new Alias(); t.equal(obj.version, '', '.version should be empty String'); t.equal(obj.alias, '', '.alias should be empty String'); @@ -19,7 +17,7 @@ test('Alias() - Default property values', (t) => { t.end(); }); -test('Alias() - Set values to the arguments on the constructor', (t) => { +tap.test('Alias() - Set values to the arguments on the constructor', (t) => { const obj = new Alias({ version: '1.0.0', alias: 'v1', @@ -35,7 +33,7 @@ test('Alias() - Set values to the arguments on the constructor', (t) => { t.end(); }); -test('Alias() - Set a value on the .version property', (t) => { +tap.test('Alias() - Set a value on the .version property', (t) => { const obj = new Alias({ version: '1.0.0', }); @@ -44,7 +42,7 @@ test('Alias() - Set a value on the .version property', (t) => { t.end(); }); -test('Alias() - Serialize object', (t) => { +tap.test('Alias() - Serialize object', (t) => { const obj = new Alias({ version: '1.0.0', alias: 'v1', diff --git a/test/classes/asset.js b/test/classes/asset.js index 8fc13528..70df9c55 100644 --- a/test/classes/asset.js +++ b/test/classes/asset.js @@ -1,15 +1,13 @@ -'use strict'; +import tap from 'tap'; +import Asset from '../../lib/classes/asset.js'; -const { test } = require('tap'); -const Asset = require('../../lib/classes/asset'); - -test('HttpIncoming() - Object type', (t) => { +tap.test('HttpIncoming() - Object type', (t) => { const obj = new Asset(); t.equal(Object.prototype.toString.call(obj), '[object Asset]', 'should be Asset'); t.end(); }); -test('Asset() - Default property values', (t) => { +tap.test('Asset() - Default property values', (t) => { const obj = new Asset(); t.equal(obj.integrity, '', '.integrity should be empty String'); t.equal(obj.pathname, '/', '.pathname should be "/"'); @@ -23,7 +21,7 @@ test('Asset() - Default property values', (t) => { t.end(); }); -test('Asset() - Set values to the arguments on the constructor', (t) => { +tap.test('Asset() - Set values to the arguments on the constructor', (t) => { const obj = new Asset({ pathname: '/foo/bar.js', version: '4.2.6', @@ -43,7 +41,7 @@ test('Asset() - Set values to the arguments on the constructor', (t) => { t.end(); }); -test('Asset() - Set values to the argument "type" on the constructor in upper case', (t) => { +tap.test('Asset() - Set values to the argument "type" on the constructor in upper case', (t) => { const obj = new Asset({ type: 'PkG', }); @@ -51,35 +49,35 @@ test('Asset() - Set values to the argument "type" on the constructor in upper ca t.end(); }); -test('Asset() - Set .integrity property', (t) => { +tap.test('Asset() - Set .integrity property', (t) => { const obj = new Asset(); obj.integrity = 'foo'; t.equal(obj.integrity, 'foo', '.integrity should contain value set on property'); t.end(); }); -test('Asset() - Set .type property', (t) => { +tap.test('Asset() - Set .type property', (t) => { const obj = new Asset(); obj.type = 'pkg'; t.equal(obj.type, 'pkg', '.type should contain value set on property'); t.end(); }); -test('Asset() - Set .type property with upper case characthers', (t) => { +tap.test('Asset() - Set .type property with upper case characthers', (t) => { const obj = new Asset(); obj.type = 'PkG'; t.equal(obj.type, 'pkg', '.type should contain value set on property in lower case'); t.end(); }); -test('Asset() - Set .size property', (t) => { +tap.test('Asset() - Set .size property', (t) => { const obj = new Asset(); obj.size = 1234; t.equal(obj.size, 1234, '.size should contain value set on property'); t.end(); }); -test('Asset() - Stringify object to JSON', (t) => { +tap.test('Asset() - Stringify object to JSON', (t) => { const obj = new Asset({ pathname: '/foo/bar.js', version: '4.2.6', diff --git a/test/classes/author.js b/test/classes/author.js index f21edd5a..35f24c7f 100644 --- a/test/classes/author.js +++ b/test/classes/author.js @@ -1,29 +1,27 @@ -'use strict'; +import tap from 'tap'; +import Author from '../../lib/classes/author.js'; -const { test } = require('tap'); -const Author = require('../../lib/classes/author'); - -test('Author() - Object type', (t) => { +tap.test('Author() - Object type', (t) => { const obj = new Author(); t.equal(Object.prototype.toString.call(obj), '[object Author]', 'should be Author'); t.end(); }); -test('Author() - Default property values', (t) => { +tap.test('Author() - Default property values', (t) => { const obj = new Author(); t.equal(obj.user, '', '.user should be empty String'); t.equal(obj.name, '', '.name should be empty String'); t.end(); }); -test('Author() - Set arguments on the constructor', (t) => { +tap.test('Author() - Set arguments on the constructor', (t) => { const obj = new Author({ user: 'foo', name: 'bar' }); t.equal(obj.user, 'foo', '.user should be the set value'); t.equal(obj.name, 'bar', '.name should be the set value'); t.end(); }); -test('Author() - Serialize object', (t) => { +tap.test('Author() - Serialize object', (t) => { const obj = new Author({ user: 'foo', name: 'bar' }); const o = JSON.parse(JSON.stringify(obj)); diff --git a/test/classes/http-incoming.js b/test/classes/http-incoming.js index 219c71c5..5e59383d 100644 --- a/test/classes/http-incoming.js +++ b/test/classes/http-incoming.js @@ -1,15 +1,13 @@ -'use strict'; +import tap from 'tap'; +import HttpIncoming from '../../lib/classes/http-incoming.js'; -const { test } = require('tap'); -const HttpIncoming = require('../../lib/classes/http-incoming'); - -test('HttpIncoming() - Object type', (t) => { +tap.test('HttpIncoming() - Object type', (t) => { const obj = new HttpIncoming(); t.equal(Object.prototype.toString.call(obj), '[object HttpIncoming]', 'should be HttpIncoming'); t.end(); }); -test('HttpIncoming() - Default property values', (t) => { +tap.test('HttpIncoming() - Default property values', (t) => { const obj = new HttpIncoming(); t.type(obj.request, 'undefined', '.request should be undefined'); t.same(obj.headers, {}, '.headers should be empty Object'); @@ -22,7 +20,7 @@ test('HttpIncoming() - Default property values', (t) => { t.end(); }); -test('HttpIncoming() - Set values to the arguments on the constructor', (t) => { +tap.test('HttpIncoming() - Set values to the arguments on the constructor', (t) => { const obj = new HttpIncoming({ headers: { foo: 'bar' diff --git a/test/classes/http-outgoing.js b/test/classes/http-outgoing.js index 902668df..36bdcfc6 100644 --- a/test/classes/http-outgoing.js +++ b/test/classes/http-outgoing.js @@ -1,16 +1,14 @@ -'use strict'; +import { Readable } from 'node:stream'; +import tap from 'tap'; +import HttpOutgoing from '../../lib/classes/http-outgoing.js'; -const { Readable } = require('stream'); -const { test } = require('tap'); -const HttpOutgoing = require('../../lib/classes/http-outgoing'); - -test('HttpOutgoing() - Object type', (t) => { +tap.test('HttpOutgoing() - Object type', (t) => { const obj = new HttpOutgoing(); t.equal(Object.prototype.toString.call(obj), '[object HttpOutgoing]', 'should be HttpIncoming'); t.end(); }); -test('HttpOutgoing() - Default property values', (t) => { +tap.test('HttpOutgoing() - Default property values', (t) => { const obj = new HttpOutgoing(); t.equal(obj.statusCode, 200, '.statusCode should be the Number 200'); t.equal(obj.location, '', '.location should be empty String'); @@ -21,14 +19,14 @@ test('HttpOutgoing() - Default property values', (t) => { t.end(); }); -test('HttpOutgoing() - Set .statusCode to legal value', (t) => { +tap.test('HttpOutgoing() - Set .statusCode to legal value', (t) => { const obj = new HttpOutgoing(); obj.statusCode = 404; t.equal(obj.statusCode, 404, '.statusCode should be the set value'); t.end(); }); -test('HttpOutgoing() - Set .statusCode to non numeric value', (t) => { +tap.test('HttpOutgoing() - Set .statusCode to non numeric value', (t) => { t.plan(1); t.throws(() => { const obj = new HttpOutgoing(); @@ -37,7 +35,7 @@ test('HttpOutgoing() - Set .statusCode to non numeric value', (t) => { t.end(); }); -test('HttpOutgoing() - Set .statusCode to a illegal http status code', (t) => { +tap.test('HttpOutgoing() - Set .statusCode to a illegal http status code', (t) => { t.plan(1); t.throws(() => { const obj = new HttpOutgoing(); @@ -46,28 +44,28 @@ test('HttpOutgoing() - Set .statusCode to a illegal http status code', (t) => { t.end(); }); -test('HttpOutgoing() - Set .location to legal value', (t) => { +tap.test('HttpOutgoing() - Set .location to legal value', (t) => { const obj = new HttpOutgoing(); obj.location = '/foo'; t.equal(obj.location, '/foo', '.location should be the set value'); t.end(); }); -test('HttpOutgoing() - Set .mimeType to legal value', (t) => { +tap.test('HttpOutgoing() - Set .mimeType to legal value', (t) => { const obj = new HttpOutgoing(); obj.mimeType = 'application/javascript'; t.equal(obj.mimeType, 'application/javascript', '.location should be the set value'); t.end(); }); -test('HttpOutgoing() - Set .stream to legal value', (t) => { +tap.test('HttpOutgoing() - Set .stream to legal value', (t) => { const obj = new HttpOutgoing(); obj.stream = new Readable(); t.ok(obj.stream instanceof Readable, '.stream should be the set value'); t.end(); }); -test('HttpOutgoing() - Set a non Readable stream as value on the .stream property', (t) => { +tap.test('HttpOutgoing() - Set a non Readable stream as value on the .stream property', (t) => { t.plan(1); t.throws(() => { const obj = new HttpOutgoing(); @@ -76,14 +74,14 @@ test('HttpOutgoing() - Set a non Readable stream as value on the .stream propert t.end(); }); -test('HttpOutgoing() - Set .body to legal value', (t) => { +tap.test('HttpOutgoing() - Set .body to legal value', (t) => { const obj = new HttpOutgoing(); obj.body = 'foo'; t.equal(obj.body, 'foo', '.location should be the set value'); t.end(); }); -test('HttpOutgoing() - Set .etag to legal value', (t) => { +tap.test('HttpOutgoing() - Set .etag to legal value', (t) => { const obj = new HttpOutgoing(); obj.etag = 'foo'; t.equal(obj.etag, 'foo', '.location should be the set value'); diff --git a/test/classes/meta.js b/test/classes/meta.js index 5bcff84a..f31329b7 100644 --- a/test/classes/meta.js +++ b/test/classes/meta.js @@ -1,29 +1,27 @@ -'use strict'; +import tap from 'tap'; +import Meta from '../../lib/classes/meta.js'; -const { test } = require('tap'); -const Meta = require('../../lib/classes/meta'); - -test('Meta() - Object type', (t) => { +tap.test('Meta() - Object type', (t) => { const obj = new Meta(); t.equal(Object.prototype.toString.call(obj), '[object Meta]', 'should be Meta'); t.end(); }); -test('Meta() - Default property values', (t) => { +tap.test('Meta() - Default property values', (t) => { const obj = new Meta(); t.equal(obj.value, '', '.value should be empty String'); t.equal(obj.name, '', '.name should be empty String'); t.end(); }); -test('Meta() - Set arguments on the constructor', (t) => { +tap.test('Meta() - Set arguments on the constructor', (t) => { const obj = new Meta({ value: 'foo', name: 'bar' }); t.equal(obj.value, 'foo', '.value should be the set value'); t.equal(obj.name, 'bar', '.name should be the set value'); t.end(); }); -test('Meta() - Serialize object', (t) => { +tap.test('Meta() - Serialize object', (t) => { const obj = new Meta({ value: 'foo', name: 'bar' }); const o = JSON.parse(JSON.stringify(obj)); diff --git a/test/classes/package.js b/test/classes/package.js index 4d0f54a2..f3f55c0f 100644 --- a/test/classes/package.js +++ b/test/classes/package.js @@ -1,9 +1,7 @@ -'use strict'; +import tap from 'tap'; +import Package from '../../lib/classes/package.js'; -const { test } = require('tap'); -const Package = require('../../lib/classes/package'); - -test('Package() - object type - should be Package', (t) => { +tap.test('Package() - object type - should be Package', (t) => { const pkg = new Package(); t.equal(Object.prototype.toString.call(pkg), '[object Package]'); t.end(); diff --git a/test/classes/versions.js b/test/classes/versions.js index 66649e05..78a240c5 100644 --- a/test/classes/versions.js +++ b/test/classes/versions.js @@ -1,15 +1,13 @@ -'use strict'; +import tap from 'tap'; +import Versions from '../../lib/classes/versions.js'; -const { test } = require('tap'); -const Versions = require('../../lib/classes/versions'); - -test('Versions() - Object type', (t) => { +tap.test('Versions() - Object type', (t) => { const obj = new Versions(); t.equal(Object.prototype.toString.call(obj), '[object Versions]', 'should be Versions'); t.end(); }); -test('Versions() - Default property values', (t) => { +tap.test('Versions() - Default property values', (t) => { const obj = new Versions(); t.strictSame(obj.versions, [], '.version should be empty Array'); t.equal(obj.name, '', '.name should be empty String'); @@ -17,19 +15,19 @@ test('Versions() - Default property values', (t) => { t.end(); }); -test('Versions() - Set a value on the "name" argument on the constructor', (t) => { +tap.test('Versions() - Set a value on the "name" argument on the constructor', (t) => { const obj = new Versions({ name: 'foo' }); t.equal(obj.name, 'foo', '.name should be value set on constructor'); t.end(); }); -test('Versions() - Set a value on the "name" argument on the constructor', (t) => { +tap.test('Versions() - Set a value on the "name" argument on the constructor', (t) => { const obj = new Versions({ org: 'bar' }); t.equal(obj.org, 'bar', '.org should be value set on constructor'); t.end(); }); -test('Versions() - Set the multiple versions in the same major range', (t) => { +tap.test('Versions() - Set the multiple versions in the same major range', (t) => { const obj = new Versions(); obj.setVersion('4.3.2', 'bar'); obj.setVersion('4.6.1', 'foo'); @@ -39,7 +37,7 @@ test('Versions() - Set the multiple versions in the same major range', (t) => { t.end(); }); -test('Versions() - Set multiple versions with different major range', (t) => { +tap.test('Versions() - Set multiple versions with different major range', (t) => { const obj = new Versions(); obj.setVersion('1.7.3', 'rab'); obj.setVersion('3.3.2', 'bar'); @@ -54,7 +52,7 @@ test('Versions() - Set multiple versions with different major range', (t) => { t.end(); }); -test('Version() - Set a version with lower semver version than latest', (t) => { +tap.test('Version() - Set a version with lower semver version than latest', (t) => { t.plan(1); const obj = new Versions(); @@ -67,7 +65,7 @@ test('Version() - Set a version with lower semver version than latest', (t) => { t.end(); }); -test('Versions() - Get a version', (t) => { +tap.test('Versions() - Get a version', (t) => { const obj = new Versions(); obj.setVersion('4.2.4', 'xyz'); obj.setVersion('4.3.2', 'bar'); @@ -82,7 +80,7 @@ test('Versions() - Get a version', (t) => { t.end(); }); -test('Versions() - Set values to the arguments on the constructor', (t) => { +tap.test('Versions() - Set values to the arguments on the constructor', (t) => { const obj = new Versions({ name: 'buzz', org: 'bizz' }); obj.setVersion('1.7.3', 'rab'); obj.setVersion('3.3.2', 'bar'); diff --git a/test/handlers/alias.delete.js b/test/handlers/alias.delete.js index f41d9999..a9ef901a 100644 --- a/test/handlers/alias.delete.js +++ b/test/handlers/alias.delete.js @@ -1,11 +1,9 @@ -'use strict'; +import { PassThrough } from 'node:stream'; +import FormData from 'form-data'; +import tap from 'tap'; -const { PassThrough } = require('stream'); -const FormData = require('form-data'); -const tap = require('tap'); - -const Handler = require('../../lib/handlers/alias.delete.js'); -const Sink = require('../../lib/sinks/test'); +import Handler from '../../lib/handlers/alias.delete.js'; +import Sink from '../../lib/sinks/test.js'; const Request = class Request extends PassThrough { constructor ({ @@ -16,7 +14,6 @@ const Request = class Request extends PassThrough { } } - tap.test('alias.delete() - URL parameters is URL encoded', async (t) => { const sink = new Sink(); sink.set('/local/pkg/@foo/foo-bar/8.alias.json', 'payload'); diff --git a/test/handlers/alias.get.js b/test/handlers/alias.get.js index bc1642cf..94068699 100644 --- a/test/handlers/alias.get.js +++ b/test/handlers/alias.get.js @@ -1,11 +1,9 @@ -'use strict'; +import { PassThrough } from 'node:stream'; +import tap from 'tap'; -const { PassThrough } = require('stream'); -const tap = require('tap'); - -const Handler = require('../../lib/handlers/alias.get.js'); -const Alias = require('../../lib/classes/alias'); -const Sink = require('../../lib/sinks/test'); +import Handler from '../../lib/handlers/alias.get.js'; +import Alias from '../../lib/classes/alias.js'; +import Sink from '../../lib/sinks/test.js'; const Request = class Request extends PassThrough { constructor ({ diff --git a/test/handlers/alias.post.js b/test/handlers/alias.post.js index 9dbd9f99..216e193c 100644 --- a/test/handlers/alias.post.js +++ b/test/handlers/alias.post.js @@ -1,12 +1,10 @@ -'use strict'; +import { PassThrough } from 'node:stream'; +import FormData from 'form-data'; +import tap from 'tap'; +import HttpError from 'http-errors'; -const { PassThrough } = require('stream'); -const FormData = require('form-data'); -const tap = require('tap'); -const HttpError = require('http-errors'); - -const Handler = require('../../lib/handlers/alias.post.js'); -const Sink = require('../../lib/sinks/test'); +import Handler from '../../lib/handlers/alias.post.js'; +import Sink from '../../lib/sinks/test.js'; const Request = class Request extends PassThrough { constructor ({ diff --git a/test/handlers/alias.put.js b/test/handlers/alias.put.js index 7b904167..24d44674 100644 --- a/test/handlers/alias.put.js +++ b/test/handlers/alias.put.js @@ -1,12 +1,10 @@ -'use strict'; +import { PassThrough } from 'node:stream'; +import FormData from 'form-data'; +import tap from 'tap'; +import HttpError from 'http-errors'; -const { PassThrough } = require('stream'); -const FormData = require('form-data'); -const tap = require('tap'); -const HttpError = require('http-errors'); - -const Handler = require('../../lib/handlers/alias.put.js'); -const Sink = require('../../lib/sinks/test'); +import Handler from '../../lib/handlers/alias.put.js'; +import Sink from '../../lib/sinks/test.js'; const Request = class Request extends PassThrough { constructor ({ diff --git a/test/handlers/map.get.js b/test/handlers/map.get.js index 0c4697a8..58009481 100644 --- a/test/handlers/map.get.js +++ b/test/handlers/map.get.js @@ -1,10 +1,8 @@ -'use strict'; +import { Writable, PassThrough, pipeline } from 'node:stream'; +import tap from 'tap'; -const { Writable, PassThrough, pipeline } = require('stream'); -const tap = require('tap'); - -const Handler = require('../../lib/handlers/map.get.js'); -const Sink = require('../../lib/sinks/test'); +import Handler from '../../lib/handlers/map.get.js'; +import Sink from '../../lib/sinks/test.js'; const pipeInto = (...streams) => new Promise((resolve, reject) => { const buffer = []; diff --git a/test/handlers/map.put.js b/test/handlers/map.put.js index c65904aa..86d47664 100644 --- a/test/handlers/map.put.js +++ b/test/handlers/map.put.js @@ -1,15 +1,13 @@ -'use strict'; +import { PassThrough } from 'node:stream'; +import FormData from 'form-data'; +import { URL } from 'node:url'; +import tap from 'tap'; +import fs from 'node:fs'; -const { PassThrough } = require('stream'); -const FormData = require('form-data'); -const path = require('path'); -const tap = require('tap'); -const fs = require('fs'); +import Handler from '../../lib/handlers/map.put.js'; +import Sink from '../../lib/sinks/test.js'; -const Handler = require('../../lib/handlers/map.put.js'); -const Sink = require('../../lib/sinks/test'); - -const FIXTURE_MAP = path.resolve(__dirname, '../../fixtures/import-map.json'); +const FIXTURE_MAP = new URL('../../fixtures/import-map.json', import.meta.url); const Request = class Request extends PassThrough { diff --git a/test/handlers/pkg.get.js b/test/handlers/pkg.get.js index 2df98140..973cb1aa 100644 --- a/test/handlers/pkg.get.js +++ b/test/handlers/pkg.get.js @@ -1,10 +1,8 @@ -'use strict'; +import { Writable, PassThrough, pipeline } from 'node:stream'; +import tap from 'tap'; -const { Writable, PassThrough, pipeline } = require('stream'); -const tap = require('tap'); - -const Handler = require('../../lib/handlers/pkg.get.js'); -const Sink = require('../../lib/sinks/test'); +import Handler from '../../lib/handlers/pkg.get.js'; +import Sink from '../../lib/sinks/test.js'; const pipeInto = (...streams) => new Promise((resolve, reject) => { const buffer = []; diff --git a/test/handlers/pkg.log.js b/test/handlers/pkg.log.js index 40432711..182a8c30 100644 --- a/test/handlers/pkg.log.js +++ b/test/handlers/pkg.log.js @@ -1,10 +1,8 @@ -'use strict'; +import { Writable, PassThrough, pipeline } from 'node:stream'; +import tap from 'tap'; -const { Writable, PassThrough, pipeline } = require('stream'); -const tap = require('tap'); - -const Handler = require('../../lib/handlers/pkg.log.js'); -const Sink = require('../../lib/sinks/test'); +import Handler from '../../lib/handlers/pkg.log.js'; +import Sink from '../../lib/sinks/test.js'; const pipeInto = (...streams) => new Promise((resolve, reject) => { const buffer = []; diff --git a/test/handlers/pkg.put.js b/test/handlers/pkg.put.js index dff9effb..9745df9b 100644 --- a/test/handlers/pkg.put.js +++ b/test/handlers/pkg.put.js @@ -1,22 +1,20 @@ -'use strict'; +import { PassThrough } from 'node:stream'; +import FormData from 'form-data'; +import HttpError from 'http-errors'; +import { URL } from 'node:url'; +import tap from 'tap'; +import fs from 'node:fs'; -const { PassThrough } = require('stream'); -const FormData = require('form-data'); -const HttpError = require('http-errors'); -const path = require('path'); -const tap = require('tap'); -const fs = require('fs'); +import Handler from '../../lib/handlers/pkg.put.js'; +import Sink from '../../lib/sinks/test.js'; -const Handler = require('../../lib/handlers/pkg.put.js'); -const Sink = require('../../lib/sinks/test'); +const FIXTURE_TAR = new URL('../../fixtures/package.tar', import.meta.url); +const FIXTURE_BZ2 = new URL('../../fixtures/package.tar.bz2', import.meta.url); +const FIXTURE_GZ = new URL('../../fixtures/package.tar.gz', import.meta.url); -const FIXTURE_TAR = path.resolve(__dirname, '../../fixtures/package.tar'); -const FIXTURE_BZ2 = path.resolve(__dirname, '../../fixtures/package.tar.bz2'); -const FIXTURE_GZ = path.resolve(__dirname, '../../fixtures/package.tar.gz'); - -const FIXTURE_PKG = path.resolve(__dirname, '../../fixtures/archive.tgz'); -const FIXTURE_MAP = path.resolve(__dirname, '../../fixtures/import-map.json'); +const FIXTURE_PKG = new URL('../../fixtures/archive.tgz', import.meta.url); +const FIXTURE_MAP = new URL('../../fixtures/import-map.json', import.meta.url); const Request = class Request extends PassThrough { diff --git a/test/handlers/versions.get.js b/test/handlers/versions.get.js index 926de518..6527b3b4 100644 --- a/test/handlers/versions.get.js +++ b/test/handlers/versions.get.js @@ -1,10 +1,8 @@ -'use strict'; +import { Writable, PassThrough, pipeline } from 'node:stream'; +import tap from 'tap'; -const { Writable, PassThrough, pipeline } = require('stream'); -const tap = require('tap'); - -const Handler = require('../../lib/handlers/versions.get.js'); -const Sink = require('../../lib/sinks/test'); +import Handler from '../../lib/handlers/versions.get.js'; +import Sink from '../../lib/sinks/test.js'; const pipeInto = (...streams) => new Promise((resolve, reject) => { const buffer = []; diff --git a/test/multipart/form-field.js b/test/multipart/form-field.js index 58117b2e..fae814ae 100644 --- a/test/multipart/form-field.js +++ b/test/multipart/form-field.js @@ -1,7 +1,5 @@ -'use strict'; - -const tap = require('tap'); -const FormField = require('../../lib/multipart/form-field'); +import tap from 'tap'; +import FormField from '../../lib/multipart/form-field.js'; tap.test('FormField() - Object type', (t) => { const obj = new FormField(); diff --git a/test/multipart/form-file.js b/test/multipart/form-file.js index d7e208bc..867570ed 100644 --- a/test/multipart/form-file.js +++ b/test/multipart/form-file.js @@ -1,7 +1,5 @@ -'use strict'; - -const tap = require('tap'); -const FormFile = require('../../lib/multipart/form-file'); +import tap from 'tap'; +import FormFile from '../../lib/multipart/form-file.js'; tap.test('FormFile() - Object type', (t) => { const obj = new FormFile(); diff --git a/test/multipart/parser.js b/test/multipart/parser.js index 41e31289..59a2531d 100644 --- a/test/multipart/parser.js +++ b/test/multipart/parser.js @@ -1,20 +1,18 @@ -'use strict'; - -const { PassThrough } = require('stream'); -const FormData = require('form-data'); -const HttpError = require('http-errors'); -const path = require('path'); -const tap = require('tap'); -const fs = require('fs'); - -const MultipartParser = require('../../lib/multipart/parser'); -const HttpIncoming = require('../../lib/classes/http-incoming'); -const Sink = require('../../lib/sinks/mem'); - -const FIXTURE_TAR = path.resolve(__dirname, '../../fixtures/package.tar'); -const FIXTURE_BZ2 = path.resolve(__dirname, '../../fixtures/package.tar.bz2'); -const FIXTURE_GZ = path.resolve(__dirname, '../../fixtures/package.tar.gz'); -const FIXTURE_PKG = path.resolve(__dirname, '../../fixtures/archive.tgz'); +import { PassThrough } from 'node:stream'; +import FormData from 'form-data'; +import HttpError from 'http-errors'; +import { URL } from 'node:url'; +import tap from 'tap'; +import fs from 'node:fs'; + +import MultipartParser from '../../lib/multipart/parser.js'; +import HttpIncoming from '../../lib/classes/http-incoming.js'; +import Sink from '../../lib/sinks/mem.js'; + +const FIXTURE_TAR = new URL('../../fixtures/package.tar', import.meta.url); +const FIXTURE_BZ2 = new URL('../../fixtures/package.tar.bz2', import.meta.url); +const FIXTURE_GZ = new URL('../../fixtures/package.tar.gz', import.meta.url); +const FIXTURE_PKG = new URL('../../fixtures/archive.tgz', import.meta.url); const Request = class Request extends PassThrough { constructor ({ diff --git a/test/sinks/fs.js b/test/sinks/fs.js index d7a4a484..25713553 100644 --- a/test/sinks/fs.js +++ b/test/sinks/fs.js @@ -1,14 +1,13 @@ -'use strict'; +import { Writable, pipeline } from 'node:stream'; +import { stream } from '@eik/common'; +import { URL } from 'node:url'; +import slug from 'unique-slug'; +import path from 'node:path'; +import tap from 'tap'; +import fs from 'node:fs'; +import os from 'node:os'; -const { Writable, pipeline } = require('stream'); -const { stream } = require('@eik/common'); -const slug = require('unique-slug'); -const path = require('path'); -const tap = require('tap'); -const fs = require('fs'); -const os = require('os'); - -const Sink = require('../../lib/sinks/fs'); +import Sink from '../../lib/sinks/fs.js'; // Ignore the value for "timestamp" field in the snapshots tap.cleanSnapshot = (s) => { @@ -19,7 +18,7 @@ tap.cleanSnapshot = (s) => { const DEFAULT_CONFIG = { sinkFsRootPath: path.join(os.tmpdir(), '/eik-test-files') }; -const FIXTURE = fs.readFileSync(path.join(__dirname, '../../fixtures/import-map.json')).toString(); +const FIXTURE = fs.readFileSync(new URL('../../fixtures/import-map.json', import.meta.url)).toString(); const MetricsInto = class MetricsInto extends Writable { constructor() { @@ -42,10 +41,7 @@ const MetricsInto = class MetricsInto extends Writable { } } -const readFileStream = (file = '../README.md') => { - const pathname = path.join(__dirname, file); - return fs.createReadStream(pathname); -}; +const readFileStream = (file = '../README.md') => fs.createReadStream(new URL(file, import.meta.url)); const pipeInto = (...streams) => new Promise((resolve, reject) => { const buffer = []; diff --git a/test/sinks/mem.js b/test/sinks/mem.js index f6bbd826..5ced75ab 100644 --- a/test/sinks/mem.js +++ b/test/sinks/mem.js @@ -1,13 +1,11 @@ -'use strict'; +import { Writable, pipeline } from 'node:stream'; +import { stream } from '@eik/common'; +import { URL } from 'node:url'; +import slug from 'unique-slug'; +import tap from 'tap'; +import fs from 'node:fs'; -const { Writable, pipeline } = require('stream'); -const { stream } = require('@eik/common'); -const slug = require('unique-slug'); -const path = require('path'); -const tap = require('tap'); -const fs = require('fs'); - -const Sink = require('../../lib/sinks/mem'); +import Sink from '../../lib/sinks/mem.js'; // Ignore the value for "timestamp" field in the snapshots tap.cleanSnapshot = (s) => { @@ -16,7 +14,7 @@ tap.cleanSnapshot = (s) => { }; const DEFAULT_CONFIG = {}; -const FIXTURE = fs.readFileSync(path.join(__dirname, '../../fixtures/import-map.json')).toString(); +const FIXTURE = fs.readFileSync(new URL('../../fixtures/import-map.json', import.meta.url)).toString(); const MetricsInto = class MetricsInto extends Writable { constructor() { @@ -39,10 +37,7 @@ const MetricsInto = class MetricsInto extends Writable { } } -const readFileStream = (file = '../README.md') => { - const pathname = path.join(__dirname, file); - return fs.createReadStream(pathname); -}; +const readFileStream = (file = '../README.md') => fs.createReadStream(new URL(file, import.meta.url)); const pipeInto = (...streams) => new Promise((resolve, reject) => { const buffer = []; diff --git a/test/sinks/test.js b/test/sinks/test.js index 2445e436..36273003 100644 --- a/test/sinks/test.js +++ b/test/sinks/test.js @@ -1,13 +1,11 @@ -'use strict'; +import { Writable, pipeline } from 'node:stream'; +import { stream } from '@eik/common'; +import { URL } from 'node:url'; +import slug from 'unique-slug'; +import tap from 'tap'; +import fs from 'node:fs'; -const { Writable, pipeline } = require('stream'); -const { stream } = require('@eik/common'); -const slug = require('unique-slug'); -const path = require('path'); -const tap = require('tap'); -const fs = require('fs'); - -const Sink = require('../../lib/sinks/test'); +import Sink from '../../lib/sinks/test.js'; // Ignore the value for "timestamp" field in the snapshots tap.cleanSnapshot = (s) => { @@ -16,7 +14,7 @@ tap.cleanSnapshot = (s) => { }; const DEFAULT_CONFIG = {}; -const FIXTURE = fs.readFileSync(path.join(__dirname, '../../fixtures/import-map.json')).toString(); +const FIXTURE = fs.readFileSync(new URL('../../fixtures/import-map.json', import.meta.url)).toString(); const MetricsInto = class MetricsInto extends Writable { constructor() { @@ -39,10 +37,7 @@ const MetricsInto = class MetricsInto extends Writable { } } -const readFileStream = (file = '../README.md') => { - const pathname = path.join(__dirname, file); - return fs.createReadStream(pathname); -}; +const readFileStream = (file = '../README.md') => fs.createReadStream(new URL(file, import.meta.url)); const pipeInto = (...streams) => new Promise((resolve, reject) => { const buffer = []; diff --git a/test/utils/healthchecks.js b/test/utils/healthchecks.js index 5dc9db5f..9cf78f8e 100644 --- a/test/utils/healthchecks.js +++ b/test/utils/healthchecks.js @@ -1,9 +1,6 @@ -'use strict'; - -const tap = require('tap'); - -const HealthCheck = require('../../lib/utils/healthcheck'); -const Sink = require('../../lib/sinks/test'); +import tap from 'tap'; +import HealthCheck from '../../lib/utils/healthcheck.js'; +import Sink from '../../lib/sinks/test.js'; tap.test('HealthCheck() - Object type', (t) => { const health = new HealthCheck(); diff --git a/test/utils/utils.js b/test/utils/utils.js index 245c16ed..1144ef50 100644 --- a/test/utils/utils.js +++ b/test/utils/utils.js @@ -1,12 +1,10 @@ -'use strict'; +import tap from 'tap'; +import { decodeUriComponent } from '../../lib/utils/utils.js'; -const tap = require('tap'); -const utils = require('../../lib/utils/utils'); - -tap.test('utils.decodeUriComponent()', (t) => { - t.equal(utils.decodeUriComponent('%40foo%2Fbar'), '@foo/bar', 'should decode URI encodings'); - t.equal(utils.decodeUriComponent('8%2E1%2E4%2D1'), '8.1.4-1', 'should decode URI encodings'); - t.equal(utils.decodeUriComponent(undefined), undefined, 'should keep a undefined value as undefined'); - t.equal(utils.decodeUriComponent(undefined), undefined, 'should keep a null value as null'); +tap.test('.decodeUriComponent()', (t) => { + t.equal(decodeUriComponent('%40foo%2Fbar'), '@foo/bar', 'should decode URI encodings'); + t.equal(decodeUriComponent('8%2E1%2E4%2D1'), '8.1.4-1', 'should decode URI encodings'); + t.equal(decodeUriComponent(undefined), undefined, 'should keep a undefined value as undefined'); + t.equal(decodeUriComponent(undefined), undefined, 'should keep a null value as null'); t.end(); });