Skip to content

Commit 4337f6e

Browse files
committed
Upgrade dependencies and migrate CJS to ESM
1 parent 6d28344 commit 4337f6e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+14445
-6333
lines changed

.eslintrc.js renamed to .eslintrc.cjs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,17 @@ module.exports = {
2424
// enforce consistent line breaks inside function parentheses
2525
// https://eslint.org/docs/rules/function-paren-newline
2626
'function-paren-newline': ['error', 'multiline'],
27-
'import/no-unresolved': ['error', { commonjs: true }],
27+
// Eslint can't deal with ESM modules currently.
28+
'import/no-unresolved': ['error', { ignore: ['ava', 'got', 'purpleteam-logger'] }],
29+
// Used in order to supress the errors in the use of appending file extensions to the import statement for local modules
30+
// Which is required in order to upgrade from CJS to ESM. At time of upgrade file extensions have to be provided in import statements.
31+
'import/extensions': ['error', { 'js': 'ignorePackages' }],
2832
'no-unused-expressions': ['error', { allowShortCircuit: true, allowTernary: true }],
2933
'object-curly-newline': ['error', { multiline: true }],
3034
'no-multiple-empty-lines': ['error', { max: 2, maxBOF: 0, maxEOF: 1 }],
3135
'newline-per-chained-call': 'off',
3236
'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }]
3337
},
34-
env: { node: true },
35-
parserOptions: { ecmaVersion: 2021 },
36-
parser: 'babel-eslint', // required for private class members as eslint only supports ECMA Stage 4, will be able to remove in the future
37-
settings: {
38-
'import/resolver': {
39-
node: {
40-
paths: [
41-
`${process.cwd()}`
42-
]
43-
}
44-
}
45-
}
38+
env: { node: true, 'es2021': true },
39+
parserOptions: { sourceType: 'module', ecmaVersion: 'latest' }
4640
};

.github/workflows/node.js.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525

2626
strategy:
2727
matrix:
28-
node-version: [14.x, 16.x]
28+
node-version: [17.x]
2929
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
3030

3131
steps:

.husky/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.nycrc

Lines changed: 0 additions & 4 deletions
This file was deleted.

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ RUN echo user is: ${USER}, LOCAL_USER_ID is: ${LOCAL_USER_ID}, group is: ${GROUP
2222
#RUN apk update
2323
#RUN apk add wget
2424

25-
# Remove git once zaproxy from package.json is in NPM
2625
#RUN apk add --no-cache git
2726
# Following taken from: https://github.com/mhart/alpine-node/issues/48#issuecomment-430902787
2827
RUN apk add --no-cache shadow && \

bin/purpleteamParallelCucumber renamed to bin/purpleteamCucumber.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
// Following code taken from https://github.com/cucumber/cucumber-js/blob/cfc9b4a1db5b97d95350ce41144ae69084096adc/bin/cucumber-js
44
// then modified
55

6-
require('app-module-path/cwd');
7-
require('../src/scripts/runCuc').default();
6+
import runCuc from '../src/scripts/runCuc.js';
7+
8+
runCuc();

config/config.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
// the Business Source License, use of this software will be governed
88
// by the Apache License, Version 2.0
99

10-
const convict = require('convict');
11-
const { duration } = require('convict-format-with-moment');
12-
const { url } = require('convict-format-with-validator');
13-
const path = require('path');
10+
import convict from 'convict';
11+
import { duration } from 'convict-format-with-moment';
12+
import { url } from 'convict-format-with-validator';
13+
import { fileURLToPath } from 'url';
14+
import path, { dirname } from 'path';
1415

1516
convict.addFormat(duration);
1617
convict.addFormat(url);
@@ -73,8 +74,7 @@ const schema = {
7374
doc: 'The options used for creating the redis client.',
7475
format: (val) => typeof val === 'object',
7576
default: {
76-
port: 6379,
77-
host: 'redis'
77+
socket: { host: 'redis', port: 6379 }
7878
// "host": "172.17.0.2" // host networking or not running in container
7979
}
8080
}
@@ -211,7 +211,7 @@ const schema = {
211211
doc: 'The location of the Cucumber binary.',
212212
format: String,
213213
// default: `${process.cwd()}/node_modules/.bin/cucumber-js`
214-
default: `${process.cwd()}/bin/purpleteamParallelCucumber`
214+
default: path.join(process.cwd(), '/bin/purpleteamCucumber.js')
215215
},
216216
timeout: {
217217
doc: 'The value used to set the timeout (https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/timeouts.md)',
@@ -255,7 +255,9 @@ const schema = {
255255
};
256256

257257
const config = convict(schema);
258-
config.loadFile(path.join(__dirname, `config.${process.env.NODE_ENV}.json`));
258+
const filename = fileURLToPath(import.meta.url);
259+
const currentDirName = dirname(filename);
260+
config.loadFile(path.join(currentDirName, `config.${process.env.NODE_ENV}.json`));
259261
config.validate();
260262

261-
module.exports = config;
263+
export default config;

healthcheck.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
// the Business Source License, use of this software will be governed
88
// by the Apache License, Version 2.0
99

10-
const http = require('http');
11-
require('convict');
12-
const config = require('./config/config');
10+
import http from 'http';
11+
import 'convict';
12+
import config from './config/config.js';
1313

1414
const options = {
1515
host: config.get('host.host'),

index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
// the Business Source License, use of this software will be governed
88
// by the Apache License, Version 2.0
99

10-
require('app-module-path/register');
11-
const server = require('src/server');
10+
import server from './src/server.js';
1211

1312
const init = async () => {
1413
await server.registerPlugins();

0 commit comments

Comments
 (0)