Skip to content

Commit d3b950c

Browse files
committed
Upgrade dependencies and migrate CJS to ESM
1 parent 68e288e commit d3b950c

File tree

30 files changed

+7615
-11466
lines changed

30 files changed

+7615
-11466
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', '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:

Dockerfile

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

10-
FROM node:16-alpine
10+
FROM node:17-alpine
1111

1212
ARG LOCAL_USER_ID
1313
ARG LOCAL_GROUP_ID

bin/purpleteamCucumber 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: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
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 path = require('path');
10+
import convict from 'convict';
11+
import { duration } from 'convict-format-with-moment';
12+
import { fileURLToPath } from 'url';
13+
import path, { dirname } from 'path';
1314

1415
convict.addFormat(duration);
1516

@@ -69,8 +70,7 @@ const schema = {
6970
doc: 'The options used for creating the redis client.',
7071
format: (val) => typeof val === 'object',
7172
default: {
72-
port: 6379,
73-
host: 'redis'
73+
socket: { host: 'redis', port: 6379 }
7474
// "host": "172.17.0.2" // host networking or not running in container
7575
}
7676
}
@@ -121,7 +121,7 @@ const schema = {
121121
doc: 'The location of the Cucumber binary.',
122122
format: String,
123123
// default: `${process.cwd()}/node_modules/.bin/cucumber-js`
124-
default: `${process.cwd()}/bin/purpleteamCucumber`
124+
default: path.join(process.cwd(), '/bin/purpleteamCucumber.js')
125125
},
126126
timeout: {
127127
doc: 'The value used to set the timeout (https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/timeouts.md)',
@@ -139,7 +139,9 @@ const schema = {
139139
};
140140

141141
const config = convict(schema);
142-
config.loadFile(path.join(__dirname, `config.${process.env.NODE_ENV}.json`));
142+
const filename = fileURLToPath(import.meta.url);
143+
const currentDirName = dirname(filename);
144+
config.loadFile(path.join(currentDirName, `config.${process.env.NODE_ENV}.json`));
143145
config.validate();
144146

145-
module.exports = config;
147+
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)