Skip to content

Commit

Permalink
deps: remove node-fetch and update module imports (#140)
Browse files Browse the repository at this point in the history
* deps: bump node fetch

* deps: bump dependencies and use usage

* fix: remove leak

* remove config.kjs

* fix: config import
  • Loading branch information
JonasBa authored Jan 2, 2024
1 parent ef5d5ad commit c1436de
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 92 deletions.
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,20 @@
"dependencies": {
"@sentry/node": "7.49.0",
"@sentry/profiling-node": "1.0.0-alpha.5",
"@types/express": "4.17.13",
"@types/yargs": "^16.0.0",
"abort-controller": "^3.0.0",
"canvas": "^2.11.2",
"dotenv": "^8.2.0",
"echarts": "5.4.0",
"express": "4.18.1",
"joi": "17.6.0",
"node-fetch": "v3.0.0-beta.9",
"winston": "3.7.2",
"yargs": "^16.2.0"
},
"devDependencies": {
"@types/express": "^4.17.21",
"@types/jest-image-snapshot": "4.3.1",
"@types/node": "^20.10.6",
"@types/supertest": "^2.0.10",
"@types/yargs": "^17.0.32",
"eslint": "^8.56.0",
"eslint-config-sentry-app": "^1.129.0",
"jest": "^29.7.0",
Expand Down
16 changes: 8 additions & 8 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import path from 'path';
import * as vm from 'vm';

import AbortController from 'abort-controller';
import * as echarts from 'echarts';
import fetch from 'node-fetch';
import path from 'node:path';
import vm from 'node:vm';

import ConfigPoller from './configPolling';
import {logger} from './logging';
Expand Down Expand Up @@ -37,7 +34,7 @@ async function loadViaHttp(url: string, ac?: AbortController) {
/**
* Service to manage resolving the external chart configuration module.
*/
export default class ConfigService {
export class ConfigService {
/**
* The path / uri to load the render configuration from
*/
Expand Down Expand Up @@ -80,8 +77,11 @@ export default class ConfigService {
const ac = new AbortController();
const deadlineTimeout = setTimeout(() => ac.abort(), deadline);

config = await loadViaHttp(this.#uri, ac);
clearTimeout(deadlineTimeout);
try {
config = await loadViaHttp(this.#uri, ac);
} finally {
clearTimeout(deadlineTimeout);
}

return config;
}
Expand Down
5 changes: 2 additions & 3 deletions src/configPolling.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as Sentry from '@sentry/node';
import fetch from 'node-fetch';

import ConfigService from './config';
import {ConfigService} from './config';
import {logger} from './logging';
import {PollingConfig} from './types';
import {validateConfig} from './validate';
Expand Down Expand Up @@ -69,7 +68,7 @@ export default class ConfigPoller {
try {
config = await this.#config.fetchConfig(loadDeadline);
} catch (error) {
const didAbort = error instanceof fetch.AbortError;
const didAbort = error instanceof Error && error.name === 'AbortError';

if (didAbort) {
logger.debug('Config resolution aborted for next polling tick');
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as Sentry from '@sentry/node';
import dotenv from 'dotenv';
import yargs from 'yargs';

import ConfigService from './config';
import {ConfigService} from './config';
import * as logging from './logging';
import {renderServer} from './renderServer';
import {renderStream} from './renderStream';
Expand Down
4 changes: 2 additions & 2 deletions src/renderServer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// eslint-disable-next-line simple-import-sort/imports
import {performance} from 'perf_hooks';
import {performance} from 'node:perf_hooks';

import * as Sentry from '@sentry/node';
import {ProfilingIntegration} from '@sentry/profiling-node';
import express from 'express';

import ConfigService from './config';
import {ConfigService} from './config';
import {logger} from './logging';
import {renderSync} from './render';
import {validateRenderData} from './validate';
Expand Down
6 changes: 3 additions & 3 deletions src/renderStream.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from 'fs';
import * as util from 'util';
import fs from 'node:fs';
import util from 'node:util';

import ConfigService from './config';
import {ConfigService} from './config';
import {renderSync} from './render';
import {validateRenderData} from './validate';

Expand Down
3 changes: 1 addition & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as path from 'path';

import {registerFont} from 'canvas';
import type {EChartsOption} from 'echarts';
import path from 'node:path';

function fontFile(name: string) {
return path.join(__dirname, '/../fonts/', name);
Expand Down
2 changes: 1 addition & 1 deletion src/validate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Joi from 'joi';

import ConfigService from './config';
import {ConfigService} from './config';
import {ChartcuterieConfig, RenderData} from './types';

const renderType = Joi.object({
Expand Down
2 changes: 1 addition & 1 deletion tests/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fetchMock from 'jest-fetch-mock';

fetchMock.enableMocks();

import ConfigService from 'app/config';
import {ConfigService} from 'app/config';

describe('config', () => {
beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion tests/renderServer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import supertest from 'supertest';

import ConfigService from 'app/config';
import {ConfigService} from 'app/config';
import {renderServer} from 'app/renderServer';
import {RenderData} from 'app/types';

Expand Down
7 changes: 3 additions & 4 deletions tests/renderStream.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import * as fs from 'fs';

import type {EChartsOption} from 'echarts';
import fs from 'node:fs';

import ConfigService from 'app/config';
import {ConfigService} from 'app/config';
import {renderStream} from 'app/renderStream';
import {RenderData} from 'app/types';

jest.mock('fs');
jest.mock('node:fs');

describe('renderStream', () => {
it('can render graphs given a valid config and render data', async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/validate.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ValidationError} from 'joi';

import ConfigService from 'app/config';
import {ConfigService} from 'app/config';
import {RenderDescriptor} from 'app/types';
import {validateConfig, validateRenderData} from 'app/validate';

Expand Down
Loading

0 comments on commit c1436de

Please sign in to comment.