Skip to content

Commit

Permalink
Merge pull request #402 from mountaindude/400
Browse files Browse the repository at this point in the history
refactor: Migrate from CJS to ESM
  • Loading branch information
mountaindude authored Feb 19, 2024
2 parents b1a96da + 23deb10 commit d45511e
Show file tree
Hide file tree
Showing 72 changed files with 881 additions and 607 deletions.
32 changes: 32 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
env:
# es6: true
es2023: true
node: true
# commonjs: false
extends:
- airbnb-base
# - eslint:recommended
- prettier
parserOptions:
ecmaVersion: 2023
sourceType: module
requireConfigFile: false
babelOptions:
plugins:
- '@babel/plugin-syntax-import-assertions'
parser: '@babel/eslint-parser'
rules:
prettier/prettier: error
import/no-unresolved: 2
import/no-commonjs: 2
import/extensions: [2, "ignorePackages"]
plugins:
- prettier
- import
globals:
beforeAll: readonly
afterAll: readonly
describe: readonly
expect: readonly
test: readonly
it: readonly
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
367 changes: 332 additions & 35 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,14 @@
"url": "https://github.com/ptarmiganlabs/ctrl-q/issues"
},
"license": "MIT",
"type": "module",
"dependencies": {
"axios": "^1.6.7",
"commander": "^12.0.0",
"csv-parse": "^5.5.3",
"csv-stringify": "^6.4.5",
"enigma.js": "^2.12.0",
"esbuild": "^0.20.1",
"eslint": "^8.56.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"form-data": "^4.0.0",
"fs-extra": "^11.2.0",
"handlebars": "^4.7.8",
Expand All @@ -58,6 +54,13 @@
"yesno": "^0.4.0"
},
"devDependencies": {
"eslint": "^8.56.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"@babel/eslint-parser": "^7.23.10",
"@babel/plugin-syntax-import-assertions": "^7.23.3",
"eslint-plugin-import": "^2.29.1",
"@jest/globals": "^29.7.0",
"jest": "^29.7.0",
"prettier": "^3.2.5",
Expand Down
21 changes: 0 additions & 21 deletions src/.eslintrc.yml

This file was deleted.

14 changes: 7 additions & 7 deletions src/__tests__/app_cert.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');
import { jest, test, expect, describe } from '@jest/globals';

const { getApps, getAppById } = require('../lib/util/app');
import { getApps, getAppById } from '../lib/util/app.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand All @@ -24,11 +24,11 @@ console.log(`Jest timeout: ${defaultTestTimeout}`);
jest.setTimeout(defaultTestTimeout);

// Mock logger
global.console = {
log: jest.fn(),
info: jest.fn(),
error: jest.fn(),
};
// global.console = {
// log: jest.fn(),
// info: jest.fn(),
// error: jest.fn(),
// };

// Define existing and non-existing tasks
const existingAppId1 = 'c840670c-7178-4a5e-8409-ba2da69127e2';
Expand Down
9 changes: 4 additions & 5 deletions src/__tests__/app_export_cert.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');
import { jest, test, expect, describe } from '@jest/globals';

const fs = require('fs');
const path = require('path');

const { exportAppToFile } = require('../lib/cmd/exportapp');
import fs from 'fs';
import path from 'path';
import exportAppToFile from '../lib/cmd/exportapp.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
9 changes: 4 additions & 5 deletions src/__tests__/app_export_jwt.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');
import { jest, test, expect, describe } from '@jest/globals';

const fs = require('fs');
const path = require('path');

const { exportAppToFile } = require('../lib/cmd/exportapp');
import fs from 'fs';
import path from 'path';
import exportAppToFile from '../lib/cmd/exportapp.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/app_import_cert.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');
import { jest, test, expect, describe } from '@jest/globals';

const { importAppFromFile } = require('../lib/cmd/importapp');
const { appExistById, deleteAppById } = require('../lib/util/app');
import importAppFromFile from '../lib/cmd/importapp.js';
import { appExistById, deleteAppById } from '../lib/util/app.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/app_import_jwt.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');
import { jest, test, expect, describe } from '@jest/globals';

const { importAppFromFile } = require('../lib/cmd/importapp');
const { appExistById, deleteAppById } = require('../lib/util/app');
import importAppFromFile from '../lib/cmd/importapp.js';
import { appExistById, deleteAppById } from '../lib/util/app.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/app_jwt.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');
import { jest, test, expect, describe } from '@jest/globals';

const { getApps, getAppById, appExistById, deleteAppById } = require('../lib/util/app');
const { importAppFromFile } = require('../lib/cmd/importapp');
const { sleep } = require('../globals');
import { getApps, getAppById, appExistById, deleteAppById } from '../lib/util/app.js';
import importAppFromFile from '../lib/cmd/importapp.js';
import { sleep } from '../globals.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/bookmark_get_cert.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');
import { jest, test, expect, describe } from '@jest/globals';

const { getBookmark } = require('../lib/cmd/getbookmark');
import getBookmark from '../lib/cmd/getbookmark.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/bookmark_get_jwt.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');
import { jest, test, expect, describe } from '@jest/globals';

const { getBookmark } = require('../lib/cmd/getbookmark');
import getBookmark from '../lib/cmd/getbookmark.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/connection_test_cert.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');
import { jest, test, expect, describe } from '@jest/globals';

const { testConnection } = require('../lib/cmd/testconnection');
import testConnection from '../lib/cmd/testconnection.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/connection_test_jwt.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');
import { jest, test, expect, describe } from '@jest/globals';

const { testConnection } = require('../lib/cmd/testconnection');
import testConnection from '../lib/cmd/testconnection.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/script_get_cert.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');
import { jest, test, expect, describe } from '@jest/globals';

const { getScript } = require('../lib/cmd/getscript');
import getScript from '../lib/cmd/getscript.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/script_get_jwt.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');
import { jest, test, expect, describe } from '@jest/globals';

const { getScript } = require('../lib/cmd/getscript');
import getScript from '../lib/cmd/getscript.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
14 changes: 7 additions & 7 deletions src/__tests__/task_cert.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');
import { jest, test, expect, describe } from '@jest/globals';

const { taskExistById, getTaskByName, getTaskById } = require('../lib/util/task');
import { taskExistById, getTaskByName, getTaskById } from '../lib/util/task.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand All @@ -23,11 +23,11 @@ const defaultTestTimeout = process.env.CTRL_Q_TEST_TIMEOUT || 600000; // 10 minu
jest.setTimeout(defaultTestTimeout);

// Mock logger
global.console = {
log: jest.fn(),
info: jest.fn(),
error: jest.fn(),
};
// global.console = {
// log: jest.fn(),
// info: jest.fn(),
// error: jest.fn(),
// };

// Define existing and non-existing tasks
const existingTaskId = 'e9100e69-4e8e-414b-bf88-10a1110c43a9';
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/task_custom_property_set_cert.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');
import { jest, test, expect, describe } from '@jest/globals';

const { setTaskCustomProperty } = require('../lib/cmd/settaskcp');
const { getTaskById } = require('../lib/util/task');
import setTaskCustomProperty from '../lib/cmd/settaskcp.js';
import { getTaskById } from '../lib/util/task.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/task_custom_property_set_jwt.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');
import { jest, test, expect, describe } from '@jest/globals';

const { setTaskCustomProperty } = require('../lib/cmd/settaskcp');
const { getTaskById } = require('../lib/util/task');
import setTaskCustomProperty from '../lib/cmd/settaskcp.js';
import { getTaskById } from '../lib/util/task.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/task_get_cert.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');
const fs = require('fs');
const path = require('path');
import { jest, test, expect, describe } from '@jest/globals';

const { getTask } = require('../lib/cmd/gettask');
import fs from 'fs';
import path from 'path';
import getTask from '../lib/cmd/gettask.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/task_get_jwt.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');
const fs = require('fs');
const path = require('path');
import { jest, test, expect, describe } from '@jest/globals';

const { getTask } = require('../lib/cmd/gettask');
import fs from 'fs';
import path from 'path';
import getTask from '../lib/cmd/gettask.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/task_import_cert.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');
import { jest, test, expect, describe } from '@jest/globals';

const { importTaskFromFile } = require('../lib/cmd/importtask');
const { getTaskById, deleteExternalProgramTaskById, deleteReloadTaskById } = require('../lib/util/task');
const { mapTaskType } = require('../lib/util/lookups');
import importTaskFromFile from '../lib/cmd/importtask.js';
import { getTaskById, deleteExternalProgramTaskById, deleteReloadTaskById } from '../lib/util/task.js';
import { mapTaskType } from '../lib/util/lookups.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/task_import_jwt.tes.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');
import { jest, test, expect, describe } from '@jest/globals';

const { importTaskFromFile } = require('../lib/cmd/importtask');
const { getTaskById, deleteExternalProgramTaskById, deleteReloadTaskById } = require('../lib/util/task');
const { mapTaskType } = require('../lib/util/lookups');
import importTaskFromFile from '../lib/cmd/importtask.js';
import { getTaskById, deleteExternalProgramTaskById, deleteReloadTaskById } from '../lib/util/task.js';
import { mapTaskType } from '../lib/util/lookups.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
14 changes: 7 additions & 7 deletions src/__tests__/task_jwt.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');
import { jest, test, expect, describe } from '@jest/globals';

const { taskExistById, getTaskByName, getTaskById } = require('../lib/util/task');
import { taskExistById, getTaskByName, getTaskById } from '../lib/util/task.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand All @@ -23,11 +23,11 @@ const defaultTestTimeout = process.env.CTRL_Q_TEST_TIMEOUT || 600000; // 10 minu
jest.setTimeout(defaultTestTimeout);

// Mock logger
global.console = {
log: jest.fn(),
info: jest.fn(),
error: jest.fn(),
};
// global.console = {
// log: jest.fn(),
// info: jest.fn(),
// error: jest.fn(),
// };

// Define existing and non-existing tasks
const existingTaskId = 'e9100e69-4e8e-414b-bf88-10a1110c43a9';
Expand Down
Loading

0 comments on commit d45511e

Please sign in to comment.