From 3c546aa1991090f38f9562a7df4cc54e7af61db0 Mon Sep 17 00:00:00 2001 From: Felipe Lalanne <1822826+pipex@users.noreply.github.com> Date: Tue, 5 Mar 2024 15:14:37 -0300 Subject: [PATCH 1/2] Add sync directory to lint sources --- sync/device.ts | 7 +++---- sync/init.ts | 4 ++-- sync/livepush.ts | 13 +++++++------ sync/logs.ts | 7 +++---- sync/sync.ts | 2 +- tsconfig.json | 1 + 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/sync/device.ts b/sync/device.ts index 57216196..3f1f6dee 100644 --- a/sync/device.ts +++ b/sync/device.ts @@ -1,11 +1,10 @@ -import * as Docker from 'dockerode'; -import { Dockerfile } from 'livepush'; -import * as _ from 'lodash'; +import Docker from 'dockerode'; +import type { Dockerfile } from 'livepush'; import { Builder } from 'resin-docker-build'; import { promises as fs } from 'fs'; import * as Path from 'path'; -import { Readable } from 'stream'; +import type { Readable } from 'stream'; import * as tar from 'tar-stream'; import * as readline from 'readline'; diff --git a/sync/init.ts b/sync/init.ts index ec67b9a7..eb44780a 100644 --- a/sync/init.ts +++ b/sync/init.ts @@ -1,5 +1,5 @@ -import * as Docker from 'dockerode'; -import { Dockerfile } from 'livepush'; +import type Docker from 'dockerode'; +import type { Dockerfile } from 'livepush'; import * as device from './device'; import { setTimeout } from 'timers/promises'; diff --git a/sync/livepush.ts b/sync/livepush.ts index 1edad0f6..6b7f6c0f 100644 --- a/sync/livepush.ts +++ b/sync/livepush.ts @@ -1,9 +1,10 @@ import * as chokidar from 'chokidar'; -import * as Docker from 'dockerode'; -import * as _ from 'lodash'; -import * as Path from 'path'; +import type Docker from 'dockerode'; +import _ from 'lodash'; +import Path from 'path'; -import { Dockerfile, Livepush } from 'livepush'; +import type { Dockerfile } from 'livepush'; +import { Livepush } from 'livepush'; // TODO: Pass build args to the livepush process export async function startLivepush(opts: { @@ -37,7 +38,7 @@ export async function startLivepush(opts: { const livepushExecutor = getExecutor(livepush); const watcher = chokidar .watch('.', { - ignored: /((^|[\/\\])\..|(node_modules|sync|test)\/.*)/, + ignored: /((^|[/\\])\..|(node_modules|sync|test)\/.*)/, ignoreInitial: opts.noinit, }) .on('add', (path) => livepushExecutor(path)) @@ -65,6 +66,6 @@ const getExecutor = (livepush: Livepush) => { if (deleted) { deletedFiles.push(deleted); } - actualExecutor(); + return actualExecutor(); }; }; diff --git a/sync/logs.ts b/sync/logs.ts index 33f3d0fd..fddd6cae 100644 --- a/sync/logs.ts +++ b/sync/logs.ts @@ -1,5 +1,4 @@ -import * as Docker from 'dockerode'; -import * as _ from 'lodash'; +import type Docker from 'dockerode'; export async function setupLogs( docker: Docker, @@ -16,7 +15,7 @@ export async function setupLogs( since: lastReadTimestamp, }); - stream.on('data', chunk => { + stream.on('data', (chunk) => { const { message, timestamp } = extractMessage(chunk); // Add one here, other we can end up constantly reading // the same log line @@ -26,7 +25,7 @@ export async function setupLogs( // This happens when a container is restarted stream.on('end', () => { - setupLogs(docker, containerId, lastReadTimestamp); + void setupLogs(docker, containerId, lastReadTimestamp); }); } diff --git a/sync/sync.ts b/sync/sync.ts index e63190a8..077aa375 100644 --- a/sync/sync.ts +++ b/sync/sync.ts @@ -55,7 +55,7 @@ const argv = yargs .scriptName('npm run sync --') .alias('h', 'help').argv; -(async () => { +void (async () => { const address = argv['device-address']!; const dockerfile = new livepush.Dockerfile( await fs.readFile('Dockerfile.template'), diff --git a/tsconfig.json b/tsconfig.json index dd9a8336..3ccf2ef8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -32,6 +32,7 @@ "src/**/*", "test/**/*", "typings/**/*.d.ts", + "sync/**/*", "build-utils/**/*" ] } From 6217546894e25c8216d305f231876fc888a6e407 Mon Sep 17 00:00:00 2001 From: Felipe Lalanne <1822826+pipex@users.noreply.github.com> Date: Tue, 5 Mar 2024 15:15:30 -0300 Subject: [PATCH 2/2] Update typescript to v5 This also updates code to use the default import syntax instead of `import * as` when the imported module exposes a default. This is needed with the latest typescript version. Change-type: patch --- package-lock.json | 72 ++++++++++--------- package.json | 4 +- src/api-binder/index.ts | 6 +- src/api-binder/report.ts | 2 +- src/app.ts | 4 +- src/compose/app.ts | 2 +- src/compose/application-manager.ts | 2 +- src/compose/composition-steps.ts | 2 +- src/compose/images.ts | 4 +- src/compose/network-manager.ts | 2 +- src/compose/network.ts | 4 +- src/compose/ports.ts | 2 +- src/compose/sanitise.ts | 2 +- src/compose/service-manager.ts | 8 +-- src/compose/service.ts | 6 +- src/compose/types/service.ts | 2 +- src/compose/utils.ts | 4 +- src/compose/volume-manager.ts | 4 +- src/compose/volume.ts | 2 +- src/config/backends/config-fs.ts | 4 +- src/config/backends/config-txt.ts | 2 +- src/config/backends/extlinux-file.ts | 2 +- src/config/backends/extlinux.ts | 4 +- src/config/backends/extra-uEnv.ts | 2 +- src/config/backends/odmdata.ts | 2 +- src/config/backends/splash-image.ts | 4 +- src/config/configJson.ts | 4 +- src/config/functions.ts | 4 +- src/config/index.ts | 2 +- src/config/types.ts | 2 +- src/config/utils.ts | 4 +- src/db.ts | 4 +- src/device-api/actions.ts | 2 +- src/device-api/api-keys.ts | 6 +- src/device-api/index.ts | 2 +- src/device-api/middleware/errors.ts | 2 +- src/device-api/middleware/logging.ts | 2 +- src/device-api/v1.ts | 2 +- src/device-api/v2.ts | 4 +- src/device-config.ts | 2 +- src/device-state.ts | 6 +- src/device-state/db-format.ts | 2 +- src/device-state/legacy.ts | 2 +- src/device-state/preload.ts | 2 +- src/device-state/target-state-cache.ts | 2 +- src/device-state/target-state.ts | 4 +- src/event-bus.ts | 2 +- src/host-config.ts | 4 +- src/lib/api-helper.ts | 2 +- src/lib/avahi.ts | 2 +- src/lib/constants.ts | 2 +- src/lib/contracts.ts | 2 +- src/lib/conversions.ts | 2 +- src/lib/docker-utils.ts | 6 +- src/lib/firewall.ts | 2 +- src/lib/fs-utils.ts | 2 +- src/lib/host-utils.ts | 2 +- src/lib/iptables.ts | 2 +- src/lib/lockfile.ts | 2 +- src/lib/mac-address.ts | 4 +- src/lib/migration.ts | 2 +- src/lib/os-release.ts | 2 +- src/lib/request.ts | 6 +- src/lib/supervisor-console.ts | 4 +- src/lib/supervisor-version.ts | 2 +- src/lib/system-info.ts | 6 +- src/lib/update-lock.ts | 6 +- src/lib/validation.ts | 2 +- src/local-mode.ts | 2 +- src/logger.ts | 4 +- src/logging/balena-backend.ts | 10 +-- src/logging/local-backend.ts | 2 +- src/logging/monitor.ts | 2 +- .../20171129064057_multicontainer.js | 4 +- .../20180516164000-endpoint-specific-apps.js | 2 +- ...907164000-endpoint-specific-logschannel.js | 4 +- src/migrations/M00000.js | 2 +- src/migrations/M00001.js | 2 +- src/migrations/M00002.js | 2 +- src/network.ts | 8 +-- .../compose/application-manager.spec.ts | 2 +- test/integration/compose/images.spec.ts | 2 +- test/integration/compose/network.spec.ts | 2 +- .../compose/volume-manager.spec.ts | 2 +- test/integration/compose/volume.spec.ts | 2 +- test/integration/device-api/actions.spec.ts | 4 +- test/integration/device-api/api-keys.spec.ts | 4 +- test/integration/device-api/index.spec.ts | 2 +- .../integration/device-api/middleware.spec.ts | 4 +- test/integration/device-api/v1.spec.ts | 2 +- test/integration/device-api/v2.spec.ts | 2 +- test/integration/device-state.spec.ts | 2 +- test/integration/lib/docker-utils.spec.ts | 2 +- test/integration/lib/firewall.spec.ts | 4 +- test/integration/lib/legacy.spec.ts | 2 +- test/integration/state-engine.spec.ts | 4 +- test/integration/supervisor.spec.ts | 2 +- test/legacy/40-target-state.spec.ts | 6 +- test/legacy/42-device-api-v2.spec.ts | 2 +- test/lib/chai.ts | 10 +-- test/lib/docker-helper.ts | 2 +- test/lib/mocked-balena-api.ts | 4 +- test/lib/mocked-iptables.ts | 4 +- test/lib/mockerode.ts | 4 +- test/unit/device-api/middleware.spec.ts | 4 +- test/unit/lib/journald.spec.ts | 2 +- test/unit/lib/system-info.spec.ts | 2 +- test/unit/network.spec.ts | 2 +- tsconfig.json | 2 +- typings/JSONStream.d.ts | 1 - 110 files changed, 208 insertions(+), 205 deletions(-) delete mode 100644 typings/JSONStream.d.ts diff --git a/package-lock.json b/package-lock.json index 672a0faa..bb5ce7e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,6 +28,7 @@ "@types/event-stream": "^3.3.34", "@types/express": "^4.17.14", "@types/json-mask": "2.0.3", + "@types/JSONStream": "npm:@types/jsonstream@^0.8.33", "@types/lodash": "^4.14.186", "@types/memoizee": "^0.4.8", "@types/mocha": "^8.2.3", @@ -73,6 +74,7 @@ "io-ts": "^2.2.10", "io-ts-reporters": "^1.2.2", "json-mask": "^0.3.9", + "JSONStream": "^1.3.5", "knex": "^2.5.1", "lint-staged": "^13.0.3", "livepush": "^3.5.1", @@ -108,7 +110,7 @@ "ts-node": "^8.10.2", "tsconfig-paths": "^4.1.0", "typed-error": "^3.2.1", - "typescript": "^4.8.4", + "typescript": "^5.3.3", "webpack": "^5.74.0", "webpack-cli": "^4.10.0", "winston": "^3.3.3", @@ -1105,19 +1107,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/@balena/lint/node_modules/typescript": { - "version": "5.3.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", - "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", - "dev": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=14.17" - } - }, "node_modules/@balena/lint/node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", @@ -2079,10 +2068,11 @@ "integrity": "sha512-vuL/tG01yKO//gmCmnV3OZhx2hs538t+7FpQq//sUV1sF6xiKi5V8F60dvAxe/HkC4+QaMCHqrm/akqlppTAkQ==", "dev": true }, - "node_modules/@types/jsonstream": { - "version": "0.8.30", - "resolved": "https://registry.npmjs.org/@types/jsonstream/-/jsonstream-0.8.30.tgz", - "integrity": "sha512-KqHs2eAapKL7ZKUiKI/giUYPVgkoDXkVGFehk3goo+3Q8qwxVVRC3iwg+hK/THORbcri4RRxTtlm3JoSY1KZLQ==", + "node_modules/@types/JSONStream": { + "name": "@types/jsonstream", + "version": "0.8.33", + "resolved": "https://registry.npmjs.org/@types/jsonstream/-/jsonstream-0.8.33.tgz", + "integrity": "sha512-yhg1SNOgJ8y2nOkvAQ1zZ1Z2xibxgFs7984+EeBPuWgo/TbuYo79+rj2wUVch3KF4GhhcwAi/AlJcehmLCXb3g==", "dev": true, "dependencies": { "@types/node": "*" @@ -12785,6 +12775,15 @@ "tar-stream": "^2.1.0" } }, + "node_modules/resin-docker-build/node_modules/@types/jsonstream": { + "version": "0.8.33", + "resolved": "https://registry.npmjs.org/@types/jsonstream/-/jsonstream-0.8.33.tgz", + "integrity": "sha512-yhg1SNOgJ8y2nOkvAQ1zZ1Z2xibxgFs7984+EeBPuWgo/TbuYo79+rj2wUVch3KF4GhhcwAi/AlJcehmLCXb3g==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/resin-docker-build/node_modules/@types/node": { "version": "10.17.28", "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.28.tgz", @@ -15031,16 +15030,16 @@ } }, "node_modules/typescript": { - "version": "4.8.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz", - "integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==", + "version": "5.3.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", + "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" }, "engines": { - "node": ">=4.2.0" + "node": ">=14.17" } }, "node_modules/uglify-js": { @@ -16969,12 +16968,6 @@ "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", "dev": true }, - "typescript": { - "version": "5.3.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", - "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", - "dev": true - }, "y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", @@ -17748,10 +17741,10 @@ "integrity": "sha512-vuL/tG01yKO//gmCmnV3OZhx2hs538t+7FpQq//sUV1sF6xiKi5V8F60dvAxe/HkC4+QaMCHqrm/akqlppTAkQ==", "dev": true }, - "@types/jsonstream": { - "version": "0.8.30", - "resolved": "https://registry.npmjs.org/@types/jsonstream/-/jsonstream-0.8.30.tgz", - "integrity": "sha512-KqHs2eAapKL7ZKUiKI/giUYPVgkoDXkVGFehk3goo+3Q8qwxVVRC3iwg+hK/THORbcri4RRxTtlm3JoSY1KZLQ==", + "@types/JSONStream": { + "version": "npm:@types/jsonstream@0.8.33", + "resolved": "https://registry.npmjs.org/@types/jsonstream/-/jsonstream-0.8.33.tgz", + "integrity": "sha512-yhg1SNOgJ8y2nOkvAQ1zZ1Z2xibxgFs7984+EeBPuWgo/TbuYo79+rj2wUVch3KF4GhhcwAi/AlJcehmLCXb3g==", "dev": true, "requires": { "@types/node": "*" @@ -26014,6 +26007,15 @@ "tar-stream": "^2.1.0" }, "dependencies": { + "@types/jsonstream": { + "version": "0.8.33", + "resolved": "https://registry.npmjs.org/@types/jsonstream/-/jsonstream-0.8.33.tgz", + "integrity": "sha512-yhg1SNOgJ8y2nOkvAQ1zZ1Z2xibxgFs7984+EeBPuWgo/TbuYo79+rj2wUVch3KF4GhhcwAi/AlJcehmLCXb3g==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/node": { "version": "10.17.28", "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.28.tgz", @@ -27734,9 +27736,9 @@ } }, "typescript": { - "version": "4.8.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz", - "integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==", + "version": "5.3.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", + "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", "dev": true }, "uglify-js": { diff --git a/package.json b/package.json index 59e07f73..f97d834f 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "@types/event-stream": "^3.3.34", "@types/express": "^4.17.14", "@types/json-mask": "2.0.3", + "@types/JSONStream": "npm:@types/jsonstream@^0.8.33", "@types/lodash": "^4.14.186", "@types/memoizee": "^0.4.8", "@types/mocha": "^8.2.3", @@ -99,6 +100,7 @@ "io-ts": "^2.2.10", "io-ts-reporters": "^1.2.2", "json-mask": "^0.3.9", + "JSONStream": "^1.3.5", "knex": "^2.5.1", "lint-staged": "^13.0.3", "livepush": "^3.5.1", @@ -134,7 +136,7 @@ "ts-node": "^8.10.2", "tsconfig-paths": "^4.1.0", "typed-error": "^3.2.1", - "typescript": "^4.8.4", + "typescript": "^5.3.3", "webpack": "^5.74.0", "webpack-cli": "^4.10.0", "winston": "^3.3.3", diff --git a/src/api-binder/index.ts b/src/api-binder/index.ts index 5ff5848e..6ede0f6d 100644 --- a/src/api-binder/index.ts +++ b/src/api-binder/index.ts @@ -1,10 +1,10 @@ -import * as Bluebird from 'bluebird'; +import Bluebird from 'bluebird'; import { stripIndent } from 'common-tags'; import { isLeft } from 'fp-ts/lib/Either'; import * as t from 'io-ts'; -import * as _ from 'lodash'; +import _ from 'lodash'; import { PinejsClientRequest } from 'pinejs-client-request'; -import * as url from 'url'; +import url from 'url'; import * as config from '../config'; import * as deviceConfig from '../device-config'; diff --git a/src/api-binder/report.ts b/src/api-binder/report.ts index a6857a44..a67fa87b 100644 --- a/src/api-binder/report.ts +++ b/src/api-binder/report.ts @@ -1,4 +1,4 @@ -import * as url from 'url'; +import url from 'url'; import type { CoreOptions } from 'request'; import { performance } from 'perf_hooks'; import { setTimeout } from 'timers/promises'; diff --git a/src/app.ts b/src/app.ts index 804edb88..f7fcc239 100644 --- a/src/app.ts +++ b/src/app.ts @@ -3,7 +3,7 @@ import { set } from '@balena/es-version'; set('es2019'); import { NOTFOUND } from 'dns'; -import * as mdnsResolver from 'mdns-resolver'; +import mdnsResolver from 'mdns-resolver'; class DnsLookupError extends Error { public constructor(public code: string = NOTFOUND) { @@ -144,7 +144,7 @@ async function mdnsLookup( import '@balena/happy-eyeballs/eye-patch'; import Supervisor from './supervisor'; -import * as process from 'process'; +import process from 'process'; import log from './lib/supervisor-console'; // Register signal handlers before starting the supervisor service diff --git a/src/compose/app.ts b/src/compose/app.ts index 39752d2c..2530d7e7 100644 --- a/src/compose/app.ts +++ b/src/compose/app.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import { promises as fs } from 'fs'; import type { ImageInspectInfo } from 'dockerode'; diff --git a/src/compose/application-manager.ts b/src/compose/application-manager.ts index 5d0c31da..2eb19fdd 100644 --- a/src/compose/application-manager.ts +++ b/src/compose/application-manager.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import { EventEmitter } from 'events'; import type StrictEventEmitter from 'strict-event-emitter-types'; diff --git a/src/compose/composition-steps.ts b/src/compose/composition-steps.ts index 400a847f..787e3ec6 100644 --- a/src/compose/composition-steps.ts +++ b/src/compose/composition-steps.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import * as config from '../config'; diff --git a/src/compose/images.ts b/src/compose/images.ts index 65ce538f..13c52457 100644 --- a/src/compose/images.ts +++ b/src/compose/images.ts @@ -1,6 +1,6 @@ -import type * as Docker from 'dockerode'; +import type Docker from 'dockerode'; import { EventEmitter } from 'events'; -import * as _ from 'lodash'; +import _ from 'lodash'; import type StrictEventEmitter from 'strict-event-emitter-types'; import * as config from '../config'; diff --git a/src/compose/network-manager.ts b/src/compose/network-manager.ts index 33faacfa..e83eae1e 100644 --- a/src/compose/network-manager.ts +++ b/src/compose/network-manager.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import * as constants from '../lib/constants'; import { docker } from '../lib/docker-utils'; diff --git a/src/compose/network.ts b/src/compose/network.ts index 294f16fd..7f7450d2 100644 --- a/src/compose/network.ts +++ b/src/compose/network.ts @@ -1,5 +1,5 @@ -import * as _ from 'lodash'; -import type * as dockerode from 'dockerode'; +import _ from 'lodash'; +import type dockerode from 'dockerode'; import { docker } from '../lib/docker-utils'; import logTypes = require('../lib/log-types'); diff --git a/src/compose/ports.ts b/src/compose/ports.ts index 1530d301..d1c248fd 100644 --- a/src/compose/ports.ts +++ b/src/compose/ports.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import { TypedError } from 'typed-error'; // Adapted from https://github.com/docker/docker-py/blob/master/docker/utils/ports.py#L3 diff --git a/src/compose/sanitise.ts b/src/compose/sanitise.ts index 2567c71b..e86641d8 100644 --- a/src/compose/sanitise.ts +++ b/src/compose/sanitise.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import type { ConfigMap, ServiceComposeConfig } from './types/service'; diff --git a/src/compose/service-manager.ts b/src/compose/service-manager.ts index 71e1e1c1..cb782ecf 100644 --- a/src/compose/service-manager.ts +++ b/src/compose/service-manager.ts @@ -1,8 +1,8 @@ -import type * as Dockerode from 'dockerode'; +import type Dockerode from 'dockerode'; import { EventEmitter } from 'events'; import { isLeft } from 'fp-ts/lib/Either'; -import * as JSONStream from 'JSONStream'; -import * as _ from 'lodash'; +import JSONStream from 'JSONStream'; +import _ from 'lodash'; import { promises as fs } from 'fs'; import type StrictEventEmitter from 'strict-event-emitter-types'; @@ -390,7 +390,7 @@ export function listenToEvents() { stream.on('error', (e) => { log.error(`Error on docker events stream:`, e); }); - const parser = JSONStream.parse(); + const parser = JSONStream.parse(true); parser.on('data', async (data: { status: string; id: string }) => { if (data != null) { const status = data.status; diff --git a/src/compose/service.ts b/src/compose/service.ts index 56910ce5..d4a9a437 100644 --- a/src/compose/service.ts +++ b/src/compose/service.ts @@ -1,8 +1,8 @@ import { detailedDiff as diff } from 'deep-object-diff'; -import type * as Dockerode from 'dockerode'; +import type Dockerode from 'dockerode'; import Duration = require('duration-js'); -import * as _ from 'lodash'; -import * as path from 'path'; +import _ from 'lodash'; +import path from 'path'; import type { DockerPortOptions } from './ports'; import { PortMap } from './ports'; diff --git a/src/compose/types/service.ts b/src/compose/types/service.ts index 3c74d39d..35367290 100644 --- a/src/compose/types/service.ts +++ b/src/compose/types/service.ts @@ -1,5 +1,5 @@ -import type * as Dockerode from 'dockerode'; import * as t from 'io-ts'; +import type Dockerode from 'dockerode'; import { isAbsolute } from 'path'; import type { PortMap } from '../ports'; diff --git a/src/compose/utils.ts b/src/compose/utils.ts index 344648ee..f974ad77 100644 --- a/src/compose/utils.ts +++ b/src/compose/utils.ts @@ -1,6 +1,6 @@ -import type * as Dockerode from 'dockerode'; +import type Dockerode from 'dockerode'; import Duration = require('duration-js'); -import * as _ from 'lodash'; +import _ from 'lodash'; import { parse as parseCommand } from 'shell-quote'; import * as constants from '../lib/constants'; diff --git a/src/compose/volume-manager.ts b/src/compose/volume-manager.ts index fed1c26f..52590844 100644 --- a/src/compose/volume-manager.ts +++ b/src/compose/volume-manager.ts @@ -1,5 +1,5 @@ -import * as _ from 'lodash'; -import * as path from 'path'; +import _ from 'lodash'; +import path from 'path'; import type { VolumeInspectInfo } from 'dockerode'; import { isNotFoundError, InternalInconsistencyError } from '../lib/errors'; diff --git a/src/compose/volume.ts b/src/compose/volume.ts index 4fe3e6ee..0267b90b 100644 --- a/src/compose/volume.ts +++ b/src/compose/volume.ts @@ -1,4 +1,4 @@ -import type * as Docker from 'dockerode'; +import type Docker from 'dockerode'; import isEqual = require('lodash/isEqual'); import omitBy = require('lodash/omitBy'); diff --git a/src/config/backends/config-fs.ts b/src/config/backends/config-fs.ts index 596086e1..e9855ee9 100644 --- a/src/config/backends/config-fs.ts +++ b/src/config/backends/config-fs.ts @@ -1,6 +1,6 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import { promises as fs } from 'fs'; -import * as path from 'path'; +import path from 'path'; import type { ConfigOptions } from './backend'; import { ConfigBackend } from './backend'; diff --git a/src/config/backends/config-txt.ts b/src/config/backends/config-txt.ts index ea9cc833..fee65838 100644 --- a/src/config/backends/config-txt.ts +++ b/src/config/backends/config-txt.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import type { ConfigOptions } from './backend'; import { ConfigBackend } from './backend'; diff --git a/src/config/backends/extlinux-file.ts b/src/config/backends/extlinux-file.ts index 663d12ff..7f941547 100644 --- a/src/config/backends/extlinux-file.ts +++ b/src/config/backends/extlinux-file.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import type { ConfigOptions } from './backend'; import { diff --git a/src/config/backends/extlinux.ts b/src/config/backends/extlinux.ts index 3559eb8b..f3dd5f5b 100644 --- a/src/config/backends/extlinux.ts +++ b/src/config/backends/extlinux.ts @@ -1,5 +1,5 @@ -import * as _ from 'lodash'; -import * as semver from 'semver'; +import _ from 'lodash'; +import semver from 'semver'; import type { ConfigOptions } from './backend'; import { ConfigBackend } from './backend'; diff --git a/src/config/backends/extra-uEnv.ts b/src/config/backends/extra-uEnv.ts index 9406c3df..d5f2a5b4 100644 --- a/src/config/backends/extra-uEnv.ts +++ b/src/config/backends/extra-uEnv.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import type { ConfigOptions } from './backend'; import { ConfigBackend } from './backend'; diff --git a/src/config/backends/odmdata.ts b/src/config/backends/odmdata.ts index ac5f4abd..89993c19 100644 --- a/src/config/backends/odmdata.ts +++ b/src/config/backends/odmdata.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import { promises as fs } from 'fs'; import type { ConfigOptions } from './backend'; diff --git a/src/config/backends/splash-image.ts b/src/config/backends/splash-image.ts index b89cbbbd..a156d8b5 100644 --- a/src/config/backends/splash-image.ts +++ b/src/config/backends/splash-image.ts @@ -1,6 +1,6 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import { promises as fs } from 'fs'; -import * as path from 'path'; +import path from 'path'; import * as constants from '../../lib/constants'; import { exists } from '../../lib/fs-utils'; diff --git a/src/config/configJson.ts b/src/config/configJson.ts index 8e84d5d4..a327640e 100644 --- a/src/config/configJson.ts +++ b/src/config/configJson.ts @@ -1,5 +1,5 @@ -import * as Bluebird from 'bluebird'; -import * as _ from 'lodash'; +import Bluebird from 'bluebird'; +import _ from 'lodash'; import * as constants from '../lib/constants'; import * as hostUtils from '../lib/host-utils'; diff --git a/src/config/functions.ts b/src/config/functions.ts index af3330cf..fa5a6c51 100644 --- a/src/config/functions.ts +++ b/src/config/functions.ts @@ -1,5 +1,5 @@ -import * as _ from 'lodash'; -import * as memoizee from 'memoizee'; +import _ from 'lodash'; +import memoizee from 'memoizee'; import supervisorVersion = require('../lib/supervisor-version'); diff --git a/src/config/index.ts b/src/config/index.ts index db2d8d7d..afb51a2f 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -1,6 +1,6 @@ import { EventEmitter } from 'events'; import type { Knex } from 'knex'; -import * as _ from 'lodash'; +import _ from 'lodash'; import type StrictEventEmitter from 'strict-event-emitter-types'; import { inspect } from 'util'; import { generateUniqueKey } from '../lib/register-device'; diff --git a/src/config/types.ts b/src/config/types.ts index 02047c59..9e2e3abb 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -1,6 +1,6 @@ import { either, isRight } from 'fp-ts/lib/Either'; import * as t from 'io-ts'; -import * as _ from 'lodash'; +import _ from 'lodash'; import { InternalInconsistencyError } from '../lib/errors'; import { checkBooleanish, checkTruthy } from '../lib/validation'; diff --git a/src/config/utils.ts b/src/config/utils.ts index c368e6c4..04ccd1d6 100644 --- a/src/config/utils.ts +++ b/src/config/utils.ts @@ -1,5 +1,5 @@ -import * as _ from 'lodash'; -import * as Bluebird from 'bluebird'; +import _ from 'lodash'; +import Bluebird from 'bluebird'; import * as config from '../config'; import * as constants from '../lib/constants'; diff --git a/src/db.ts b/src/db.ts index 04f728cd..97d01ca0 100644 --- a/src/db.ts +++ b/src/db.ts @@ -1,7 +1,7 @@ import type { Knex } from 'knex'; import { knex } from 'knex'; -import * as path from 'path'; -import * as _ from 'lodash'; +import path from 'path'; +import _ from 'lodash'; import * as constants from './lib/constants'; diff --git a/src/device-api/actions.ts b/src/device-api/actions.ts index 1473a886..8718dbb8 100644 --- a/src/device-api/actions.ts +++ b/src/device-api/actions.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import { getGlobalApiKey, refreshKey } from '.'; import * as messages from './messages'; diff --git a/src/device-api/api-keys.ts b/src/device-api/api-keys.ts index 26e63cac..249c5d41 100644 --- a/src/device-api/api-keys.ts +++ b/src/device-api/api-keys.ts @@ -1,6 +1,6 @@ -import * as _ from 'lodash'; -import type * as express from 'express'; -import * as memoizee from 'memoizee'; +import _ from 'lodash'; +import type express from 'express'; +import memoizee from 'memoizee'; import { TypedError } from 'typed-error'; import * as db from '../db'; diff --git a/src/device-api/index.ts b/src/device-api/index.ts index a93a9f1b..c9e07603 100644 --- a/src/device-api/index.ts +++ b/src/device-api/index.ts @@ -1,4 +1,4 @@ -import * as express from 'express'; +import express from 'express'; import * as middleware from './middleware'; import * as apiKeys from './api-keys'; diff --git a/src/device-api/middleware/errors.ts b/src/device-api/middleware/errors.ts index db68349f..acd88478 100644 --- a/src/device-api/middleware/errors.ts +++ b/src/device-api/middleware/errors.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import { UpdatesLockedError } from '../../lib/errors'; import log from '../../lib/supervisor-console'; diff --git a/src/device-api/middleware/logging.ts b/src/device-api/middleware/logging.ts index c0df8b30..c4224896 100644 --- a/src/device-api/middleware/logging.ts +++ b/src/device-api/middleware/logging.ts @@ -1,4 +1,4 @@ -import * as morgan from 'morgan'; +import morgan from 'morgan'; import type { Request } from 'express'; import log from '../../lib/supervisor-console'; diff --git a/src/device-api/v1.ts b/src/device-api/v1.ts index 2441febd..10ab2cb5 100644 --- a/src/device-api/v1.ts +++ b/src/device-api/v1.ts @@ -1,4 +1,4 @@ -import * as express from 'express'; +import express from 'express'; import type { Response } from 'express'; import * as actions from './actions'; diff --git a/src/device-api/v2.ts b/src/device-api/v2.ts index 0096c035..874f3825 100644 --- a/src/device-api/v2.ts +++ b/src/device-api/v2.ts @@ -1,6 +1,6 @@ -import * as express from 'express'; +import express from 'express'; import type { Response, NextFunction } from 'express'; -import * as _ from 'lodash'; +import _ from 'lodash'; import * as deviceState from '../device-state'; import * as apiBinder from '../api-binder'; diff --git a/src/device-config.ts b/src/device-config.ts index a4b801dc..5e37e033 100644 --- a/src/device-config.ts +++ b/src/device-config.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import { inspect } from 'util'; import { promises as fs } from 'fs'; diff --git a/src/device-state.ts b/src/device-state.ts index 97a99b1f..ff4f7813 100644 --- a/src/device-state.ts +++ b/src/device-state.ts @@ -1,11 +1,11 @@ -import * as Bluebird from 'bluebird'; +import Bluebird from 'bluebird'; import { stripIndent } from 'common-tags'; import { EventEmitter } from 'events'; -import * as _ from 'lodash'; +import _ from 'lodash'; import type StrictEventEmitter from 'strict-event-emitter-types'; import { isRight } from 'fp-ts/lib/Either'; import Reporter from 'io-ts-reporters'; -import prettyMs = require('pretty-ms'); +import prettyMs from 'pretty-ms'; import * as config from './config'; import * as db from './db'; diff --git a/src/device-state/db-format.ts b/src/device-state/db-format.ts index 4276de9d..9c687491 100644 --- a/src/device-state/db-format.ts +++ b/src/device-state/db-format.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import type * as db from '../db'; import * as targetStateCache from './target-state-cache'; diff --git a/src/device-state/legacy.ts b/src/device-state/legacy.ts index a80279ee..9ee99a07 100644 --- a/src/device-state/legacy.ts +++ b/src/device-state/legacy.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import type { TargetAppsV2 } from '../lib/legacy'; import { fromV2TargetApps } from '../lib/legacy'; import type { AppsJsonFormat, TargetApp, TargetRelease } from '../types'; diff --git a/src/device-state/preload.ts b/src/device-state/preload.ts index 21f25aaf..27db9ef2 100644 --- a/src/device-state/preload.ts +++ b/src/device-state/preload.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import { promises as fs } from 'fs'; import type { Image } from '../compose/images'; diff --git a/src/device-state/target-state-cache.ts b/src/device-state/target-state-cache.ts index abbc64d8..50f6b8ca 100644 --- a/src/device-state/target-state-cache.ts +++ b/src/device-state/target-state-cache.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import * as config from '../config'; import * as db from '../db'; diff --git a/src/device-state/target-state.ts b/src/device-state/target-state.ts index 2c0c4860..86179676 100644 --- a/src/device-state/target-state.ts +++ b/src/device-state/target-state.ts @@ -1,7 +1,7 @@ import { EventEmitter } from 'events'; -import * as url from 'url'; +import url from 'url'; import { setTimeout } from 'timers/promises'; -import * as Bluebird from 'bluebird'; +import Bluebird from 'bluebird'; import type StrictEventEmitter from 'strict-event-emitter-types'; import type { TargetState } from '../types/state'; diff --git a/src/event-bus.ts b/src/event-bus.ts index 28cbd6c9..76aa30b8 100644 --- a/src/event-bus.ts +++ b/src/event-bus.ts @@ -1,5 +1,5 @@ import { EventEmitter } from 'events'; -import * as _ from 'lodash'; +import _ from 'lodash'; import type StrictEventEmitter from 'strict-event-emitter-types'; import type { TargetState } from './types/state'; diff --git a/src/host-config.ts b/src/host-config.ts index 84bda23c..a4527199 100644 --- a/src/host-config.ts +++ b/src/host-config.ts @@ -1,7 +1,7 @@ import { stripIndent } from 'common-tags'; -import * as _ from 'lodash'; +import _ from 'lodash'; import { promises as fs } from 'fs'; -import * as path from 'path'; +import path from 'path'; import * as config from './config'; import * as applicationManager from './compose/application-manager'; diff --git a/src/lib/api-helper.ts b/src/lib/api-helper.ts index fb748974..8aa4a074 100644 --- a/src/lib/api-helper.ts +++ b/src/lib/api-helper.ts @@ -1,6 +1,6 @@ import type { PinejsClientRequest } from 'pinejs-client-request'; -import * as Bluebird from 'bluebird'; +import Bluebird from 'bluebird'; import * as config from '../config'; import * as eventTracker from '../event-tracker'; diff --git a/src/lib/avahi.ts b/src/lib/avahi.ts index 801f9c08..6b87b95c 100644 --- a/src/lib/avahi.ts +++ b/src/lib/avahi.ts @@ -1,7 +1,7 @@ import * as config from '../config'; import * as dbus from './dbus'; -import * as _ from 'lodash'; +import _ from 'lodash'; import log from './supervisor-console'; diff --git a/src/lib/constants.ts b/src/lib/constants.ts index f5a34da4..4126cbd9 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -1,4 +1,4 @@ -import * as path from 'path'; +import path from 'path'; import { checkString } from './validation'; const supervisorNetworkInterface = 'supervisor0'; diff --git a/src/lib/contracts.ts b/src/lib/contracts.ts index e9bbb79f..52b7f981 100644 --- a/src/lib/contracts.ts +++ b/src/lib/contracts.ts @@ -1,7 +1,7 @@ import { isLeft } from 'fp-ts/lib/Either'; import * as t from 'io-ts'; import Reporter from 'io-ts-reporters'; -import * as _ from 'lodash'; +import _ from 'lodash'; import { Blueprint, Contract, ContractObject } from '@balena/contrato'; diff --git a/src/lib/conversions.ts b/src/lib/conversions.ts index a0d1c0d6..b9422609 100644 --- a/src/lib/conversions.ts +++ b/src/lib/conversions.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import type { EnvVarObject } from '../types'; diff --git a/src/lib/docker-utils.ts b/src/lib/docker-utils.ts index 72006fee..b7378cf1 100644 --- a/src/lib/docker-utils.ts +++ b/src/lib/docker-utils.ts @@ -1,8 +1,8 @@ import type { ProgressCallback } from 'docker-progress'; import { DockerProgress } from 'docker-progress'; -import * as Dockerode from 'dockerode'; -import * as _ from 'lodash'; -import * as memoizee from 'memoizee'; +import Dockerode from 'dockerode'; +import _ from 'lodash'; +import memoizee from 'memoizee'; import { applyDelta, OutOfSyncError } from 'docker-delta'; import DockerToolbelt = require('docker-toolbelt'); diff --git a/src/lib/firewall.ts b/src/lib/firewall.ts index aecb2919..c1c28f6b 100644 --- a/src/lib/firewall.ts +++ b/src/lib/firewall.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import * as config from '../config/index'; import * as constants from './constants'; diff --git a/src/lib/fs-utils.ts b/src/lib/fs-utils.ts index 101a120b..82a0392d 100644 --- a/src/lib/fs-utils.ts +++ b/src/lib/fs-utils.ts @@ -1,5 +1,5 @@ import { promises as fs } from 'fs'; -import * as path from 'path'; +import path from 'path'; import { exec as execSync } from 'child_process'; import { promisify } from 'util'; import { uptime } from 'os'; diff --git a/src/lib/host-utils.ts b/src/lib/host-utils.ts index 7b7a9652..3be4aa30 100644 --- a/src/lib/host-utils.ts +++ b/src/lib/host-utils.ts @@ -1,5 +1,5 @@ import { spawn } from 'child_process'; -import * as path from 'path'; +import path from 'path'; import * as constants from './constants'; import { exec, exists } from './fs-utils'; diff --git a/src/lib/iptables.ts b/src/lib/iptables.ts index 34e35a6e..a7f061a5 100644 --- a/src/lib/iptables.ts +++ b/src/lib/iptables.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import { spawn } from 'child_process'; import { Readable } from 'stream'; import { TypedError } from 'typed-error'; diff --git a/src/lib/lockfile.ts b/src/lib/lockfile.ts index c80873db..576dab2c 100644 --- a/src/lib/lockfile.ts +++ b/src/lib/lockfile.ts @@ -1,5 +1,5 @@ import { promises as fs, unlinkSync, rmdirSync } from 'fs'; -import * as os from 'os'; +import os from 'os'; import { dirname } from 'path'; import { exec } from './fs-utils'; diff --git a/src/lib/mac-address.ts b/src/lib/mac-address.ts index c53b1b5b..e6c4e667 100644 --- a/src/lib/mac-address.ts +++ b/src/lib/mac-address.ts @@ -1,6 +1,6 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import { promises as fs } from 'fs'; -import * as path from 'path'; +import path from 'path'; import { TypedError } from 'typed-error'; import log from './supervisor-console'; diff --git a/src/lib/migration.ts b/src/lib/migration.ts index 86e7c879..0d17dff0 100644 --- a/src/lib/migration.ts +++ b/src/lib/migration.ts @@ -1,5 +1,5 @@ import { promises as fs } from 'fs'; -import * as path from 'path'; +import path from 'path'; import * as volumeManager from '../compose/volume-manager'; import * as deviceState from '../device-state'; diff --git a/src/lib/os-release.ts b/src/lib/os-release.ts index 14adfa07..40a8e6f4 100644 --- a/src/lib/os-release.ts +++ b/src/lib/os-release.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import { promises as fs } from 'fs'; import { InternalInconsistencyError } from './errors'; diff --git a/src/lib/request.ts b/src/lib/request.ts index cbd7c4fb..76eae460 100644 --- a/src/lib/request.ts +++ b/src/lib/request.ts @@ -1,7 +1,7 @@ -import * as Bluebird from 'bluebird'; +import Bluebird from 'bluebird'; import once = require('lodash/once'); -import * as requestLib from 'request'; -import * as resumableRequestLib from 'resumable-request'; +import requestLib from 'request'; +import resumableRequestLib from 'resumable-request'; import * as constants from './constants'; import * as osRelease from './os-release'; diff --git a/src/lib/supervisor-console.ts b/src/lib/supervisor-console.ts index b5b3e92c..483dabc0 100644 --- a/src/lib/supervisor-console.ts +++ b/src/lib/supervisor-console.ts @@ -1,6 +1,6 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import type { TransformableInfo } from 'logform'; -import * as winston from 'winston'; +import winston from 'winston'; const levels = { error: 0, diff --git a/src/lib/supervisor-version.ts b/src/lib/supervisor-version.ts index 6d95b797..6196af5b 100644 --- a/src/lib/supervisor-version.ts +++ b/src/lib/supervisor-version.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import * as packageJson from '../../package.json'; let version = packageJson.version; diff --git a/src/lib/system-info.ts b/src/lib/system-info.ts index dca0ee5e..11117e6a 100644 --- a/src/lib/system-info.ts +++ b/src/lib/system-info.ts @@ -1,6 +1,6 @@ -import * as systeminformation from 'systeminformation'; -import * as _ from 'lodash'; -import * as memoizee from 'memoizee'; +import systeminformation from 'systeminformation'; +import _ from 'lodash'; +import memoizee from 'memoizee'; import { promises as fs } from 'fs'; import { exec } from './fs-utils'; diff --git a/src/lib/update-lock.ts b/src/lib/update-lock.ts index db118e73..fff60608 100644 --- a/src/lib/update-lock.ts +++ b/src/lib/update-lock.ts @@ -1,7 +1,7 @@ -import * as Bluebird from 'bluebird'; +import Bluebird from 'bluebird'; import { promises as fs } from 'fs'; -import * as path from 'path'; -import * as Lock from 'rwlock'; +import path from 'path'; +import Lock from 'rwlock'; import { isRight } from 'fp-ts/lib/Either'; import { diff --git a/src/lib/validation.ts b/src/lib/validation.ts index 6220216f..891dcb30 100644 --- a/src/lib/validation.ts +++ b/src/lib/validation.ts @@ -1,5 +1,5 @@ import { isRight } from 'fp-ts/lib/Either'; -import * as _ from 'lodash'; +import _ from 'lodash'; import { DeviceName } from '../types'; export interface CheckIntOptions { positive?: boolean; diff --git a/src/local-mode.ts b/src/local-mode.ts index a64cd91a..efb72104 100644 --- a/src/local-mode.ts +++ b/src/local-mode.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import * as config from './config'; import * as db from './db'; diff --git a/src/logger.ts b/src/logger.ts index 4ab1fe2f..5290901e 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -1,5 +1,5 @@ -import * as Bluebird from 'bluebird'; -import * as _ from 'lodash'; +import Bluebird from 'bluebird'; +import _ from 'lodash'; import * as config from './config'; import * as db from './db'; diff --git a/src/logging/balena-backend.ts b/src/logging/balena-backend.ts index 428ce9af..119df6d0 100644 --- a/src/logging/balena-backend.ts +++ b/src/logging/balena-backend.ts @@ -1,9 +1,9 @@ import type { ClientRequest } from 'http'; -import * as https from 'https'; -import * as _ from 'lodash'; -import * as stream from 'stream'; -import * as url from 'url'; -import * as zlib from 'zlib'; +import https from 'https'; +import _ from 'lodash'; +import stream from 'stream'; +import url from 'url'; +import zlib from 'zlib'; import type { LogMessage } from './log-backend'; import { LogBackend } from './log-backend'; diff --git a/src/logging/local-backend.ts b/src/logging/local-backend.ts index fe229a30..51a6ee78 100644 --- a/src/logging/local-backend.ts +++ b/src/logging/local-backend.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import { Readable } from 'stream'; import { checkInt } from '../lib/validation'; diff --git a/src/logging/monitor.ts b/src/logging/monitor.ts index 2ce61b61..97ebad1a 100644 --- a/src/logging/monitor.ts +++ b/src/logging/monitor.ts @@ -1,4 +1,4 @@ -import * as JSONstream from 'JSONStream'; +import JSONstream from 'JSONStream'; import * as db from '../db'; import { spawnJournalctl, toJournalDate } from '../lib/journald'; diff --git a/src/migrations/20171129064057_multicontainer.js b/src/migrations/20171129064057_multicontainer.js index 2b9b15dd..d11a01f8 100644 --- a/src/migrations/20171129064057_multicontainer.js +++ b/src/migrations/20171129064057_multicontainer.js @@ -1,5 +1,5 @@ -import * as Bluebird from 'bluebird'; -import * as _ from 'lodash'; +import Bluebird from 'bluebird'; +import _ from 'lodash'; const tryParse = function (obj) { try { diff --git a/src/migrations/20180516164000-endpoint-specific-apps.js b/src/migrations/20180516164000-endpoint-specific-apps.js index 55246d00..355e7151 100644 --- a/src/migrations/20180516164000-endpoint-specific-apps.js +++ b/src/migrations/20180516164000-endpoint-specific-apps.js @@ -1,4 +1,4 @@ -import * as fs from 'fs'; +import fs from 'fs'; const configJsonPath = process.env.CONFIG_MOUNT_POINT; exports.up = function (knex) { diff --git a/src/migrations/20181907164000-endpoint-specific-logschannel.js b/src/migrations/20181907164000-endpoint-specific-logschannel.js index 9597f7fe..02deca03 100644 --- a/src/migrations/20181907164000-endpoint-specific-logschannel.js +++ b/src/migrations/20181907164000-endpoint-specific-logschannel.js @@ -1,5 +1,5 @@ -import * as Bluebird from 'bluebird'; -import * as fs from 'fs'; +import Bluebird from 'bluebird'; +import fs from 'fs'; const configJsonPath = process.env.CONFIG_MOUNT_POINT; exports.up = function (knex) { diff --git a/src/migrations/M00000.js b/src/migrations/M00000.js index 9a88afeb..adf8c593 100644 --- a/src/migrations/M00000.js +++ b/src/migrations/M00000.js @@ -1,4 +1,4 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; // We take legacy deviceConfig targets and store them without the RESIN_ prefix // (we also strip the BALENA_ prefix for completeness, even though no supervisors diff --git a/src/migrations/M00001.js b/src/migrations/M00001.js index b52400ed..028a19f2 100644 --- a/src/migrations/M00001.js +++ b/src/migrations/M00001.js @@ -1,4 +1,4 @@ -import * as fs from 'fs'; +import fs from 'fs'; const configJsonPath = process.env.CONFIG_MOUNT_POINT; import { checkTruthy } from '../lib/validation'; diff --git a/src/migrations/M00002.js b/src/migrations/M00002.js index 08e4217a..07d6efec 100644 --- a/src/migrations/M00002.js +++ b/src/migrations/M00002.js @@ -1,4 +1,4 @@ -import * as fs from 'fs'; +import fs from 'fs'; const configJsonPath = process.env.CONFIG_MOUNT_POINT; import { checkTruthy } from '../lib/validation'; diff --git a/src/network.ts b/src/network.ts index 1fc79d51..557018d1 100644 --- a/src/network.ts +++ b/src/network.ts @@ -1,8 +1,8 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import { promises as fs, watch } from 'fs'; -import * as networkCheck from 'network-checker'; -import * as os from 'os'; -import * as url from 'url'; +import networkCheck from 'network-checker'; +import os from 'os'; +import url from 'url'; import * as constants from './lib/constants'; import { EEXIST } from './lib/errors'; diff --git a/test/integration/compose/application-manager.spec.ts b/test/integration/compose/application-manager.spec.ts index 1902f45c..a1da6488 100644 --- a/test/integration/compose/application-manager.spec.ts +++ b/test/integration/compose/application-manager.spec.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import * as sinon from 'sinon'; -import * as Docker from 'dockerode'; +import Docker from 'dockerode'; import * as applicationManager from '~/src/compose/application-manager'; import * as imageManager from '~/src/compose/images'; import * as serviceManager from '~/src/compose/service-manager'; diff --git a/test/integration/compose/images.spec.ts b/test/integration/compose/images.spec.ts index 475550fe..73a0a5af 100644 --- a/test/integration/compose/images.spec.ts +++ b/test/integration/compose/images.spec.ts @@ -4,7 +4,7 @@ import * as imageManager from '~/src/compose/images'; import { createImage, withMockerode } from '~/test-lib/mockerode'; import { createDockerImage } from '~/test-lib/docker-helper'; -import * as Docker from 'dockerode'; +import Docker from 'dockerode'; import * as db from '~/src/db'; // TODO: this code is duplicated in multiple tests diff --git a/test/integration/compose/network.spec.ts b/test/integration/compose/network.spec.ts index f022d1eb..21ef7acf 100644 --- a/test/integration/compose/network.spec.ts +++ b/test/integration/compose/network.spec.ts @@ -3,7 +3,7 @@ import { expect } from 'chai'; import { Network } from '~/src/compose/network'; import { createNetwork, withMockerode } from '~/test-lib/mockerode'; -import * as Docker from 'dockerode'; +import Docker from 'dockerode'; describe('compose/network: integration tests', () => { const docker = new Docker(); diff --git a/test/integration/compose/volume-manager.spec.ts b/test/integration/compose/volume-manager.spec.ts index 5ff1e82c..395a7ef9 100644 --- a/test/integration/compose/volume-manager.spec.ts +++ b/test/integration/compose/volume-manager.spec.ts @@ -5,7 +5,7 @@ import * as volumeManager from '~/src/compose/volume-manager'; import Volume from '~/src/compose/volume'; import { createDockerImage } from '~/test-lib/docker-helper'; -import * as Docker from 'dockerode'; +import Docker from 'dockerode'; describe('compose/volume-manager', () => { const docker = new Docker(); diff --git a/test/integration/compose/volume.spec.ts b/test/integration/compose/volume.spec.ts index 87c6cd66..b84d4f9c 100644 --- a/test/integration/compose/volume.spec.ts +++ b/test/integration/compose/volume.spec.ts @@ -5,7 +5,7 @@ import Volume from '~/src/compose/volume'; import * as logTypes from '~/lib/log-types'; import * as logger from '~/src/logger'; -import * as Docker from 'dockerode'; +import Docker from 'dockerode'; import { createVolume, withMockerode } from '~/test-lib/mockerode'; diff --git a/test/integration/device-api/actions.spec.ts b/test/integration/device-api/actions.spec.ts index 3a6a2a59..e987b054 100644 --- a/test/integration/device-api/actions.spec.ts +++ b/test/integration/device-api/actions.spec.ts @@ -1,8 +1,8 @@ import { expect } from 'chai'; import type { SinonStub } from 'sinon'; import { stub } from 'sinon'; -import * as Docker from 'dockerode'; -import * as request from 'supertest'; +import Docker from 'dockerode'; +import request from 'supertest'; import { setTimeout } from 'timers/promises'; import * as deviceState from '~/src/device-state'; diff --git a/test/integration/device-api/api-keys.spec.ts b/test/integration/device-api/api-keys.spec.ts index 0f61310a..c51d4a21 100644 --- a/test/integration/device-api/api-keys.spec.ts +++ b/test/integration/device-api/api-keys.spec.ts @@ -1,5 +1,5 @@ -import * as express from 'express'; -import * as request from 'supertest'; +import express from 'express'; +import request from 'supertest'; import { expect } from 'chai'; import * as config from '~/src/config'; diff --git a/test/integration/device-api/index.spec.ts b/test/integration/device-api/index.spec.ts index a6c02edf..9c75903c 100644 --- a/test/integration/device-api/index.spec.ts +++ b/test/integration/device-api/index.spec.ts @@ -1,5 +1,5 @@ import type * as express from 'express'; -import * as request from 'supertest'; +import request from 'supertest'; import * as deviceApi from '~/src/device-api'; diff --git a/test/integration/device-api/middleware.spec.ts b/test/integration/device-api/middleware.spec.ts index 4c39c401..2afc2fe8 100644 --- a/test/integration/device-api/middleware.spec.ts +++ b/test/integration/device-api/middleware.spec.ts @@ -1,5 +1,5 @@ -import * as express from 'express'; -import * as request from 'supertest'; +import express from 'express'; +import request from 'supertest'; import * as config from '~/src/config'; import * as testDb from '~/src/db'; diff --git a/test/integration/device-api/v1.spec.ts b/test/integration/device-api/v1.spec.ts index dae31feb..bc621347 100644 --- a/test/integration/device-api/v1.spec.ts +++ b/test/integration/device-api/v1.spec.ts @@ -2,7 +2,7 @@ import { expect } from 'chai'; import type * as express from 'express'; import type { SinonStub } from 'sinon'; import { stub } from 'sinon'; -import * as request from 'supertest'; +import request from 'supertest'; import * as config from '~/src/config'; import * as db from '~/src/db'; diff --git a/test/integration/device-api/v2.spec.ts b/test/integration/device-api/v2.spec.ts index 9f5ac8f1..98ba0db9 100644 --- a/test/integration/device-api/v2.spec.ts +++ b/test/integration/device-api/v2.spec.ts @@ -2,7 +2,7 @@ import { expect } from 'chai'; import type * as express from 'express'; import type { SinonStub } from 'sinon'; import { stub } from 'sinon'; -import * as request from 'supertest'; +import request from 'supertest'; import * as config from '~/src/config'; import * as db from '~/src/db'; diff --git a/test/integration/device-state.spec.ts b/test/integration/device-state.spec.ts index b100185a..38853248 100644 --- a/test/integration/device-state.spec.ts +++ b/test/integration/device-state.spec.ts @@ -12,7 +12,7 @@ import { initializeContractRequirements } from '~/lib/contracts'; import { testfs } from 'mocha-pod'; import { createDockerImage } from '~/test-lib/docker-helper'; -import * as Docker from 'dockerode'; +import Docker from 'dockerode'; import { setTimeout } from 'timers/promises'; describe('device-state', () => { diff --git a/test/integration/lib/docker-utils.spec.ts b/test/integration/lib/docker-utils.spec.ts index c2d476b9..0484801c 100644 --- a/test/integration/lib/docker-utils.spec.ts +++ b/test/integration/lib/docker-utils.spec.ts @@ -3,7 +3,7 @@ import { stub } from 'sinon'; import * as dockerUtils from '~/lib/docker-utils'; import { createDockerImage, cleanupDocker } from '~/test-lib/docker-helper'; -import * as Docker from 'dockerode'; +import Docker from 'dockerode'; describe('lib/docker-utils', () => { const docker = new Docker(); diff --git a/test/integration/lib/firewall.spec.ts b/test/integration/lib/firewall.spec.ts index 2f444541..d0373e4b 100644 --- a/test/integration/lib/firewall.spec.ts +++ b/test/integration/lib/firewall.spec.ts @@ -1,6 +1,6 @@ -import * as _ from 'lodash'; +import _ from 'lodash'; import { expect } from 'chai'; -import * as sinon from 'sinon'; +import sinon from 'sinon'; import * as config from '~/src/config'; import * as logger from '~/src/logger'; diff --git a/test/integration/lib/legacy.spec.ts b/test/integration/lib/legacy.spec.ts index 7de2b908..e86bb377 100644 --- a/test/integration/lib/legacy.spec.ts +++ b/test/integration/lib/legacy.spec.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import { isRight } from 'fp-ts/lib/Either'; -import * as nock from 'nock'; +import nock from 'nock'; import { TargetState } from '~/src/types'; import * as legacy from '~/lib/legacy'; diff --git a/test/integration/state-engine.spec.ts b/test/integration/state-engine.spec.ts index a86524d8..a4a795f9 100644 --- a/test/integration/state-engine.spec.ts +++ b/test/integration/state-engine.spec.ts @@ -1,7 +1,7 @@ import { expect } from 'chai'; -import * as Docker from 'dockerode'; +import Docker from 'dockerode'; import type { TargetStateV2 } from '~/lib/legacy'; -import * as request from 'supertest'; +import request from 'supertest'; import { setTimeout as delay } from 'timers/promises'; import { exec } from '~/lib/fs-utils'; diff --git a/test/integration/supervisor.spec.ts b/test/integration/supervisor.spec.ts index d92b1fad..8a9f43a4 100644 --- a/test/integration/supervisor.spec.ts +++ b/test/integration/supervisor.spec.ts @@ -1,4 +1,4 @@ -import * as request from 'supertest'; +import request from 'supertest'; const BALENA_SUPERVISOR_ADDRESS = process.env.BALENA_SUPERVISOR_ADDRESS || 'http://balena-supervisor:48484'; diff --git a/test/legacy/40-target-state.spec.ts b/test/legacy/40-target-state.spec.ts index fa8acfcf..25755076 100644 --- a/test/legacy/40-target-state.spec.ts +++ b/test/legacy/40-target-state.spec.ts @@ -1,8 +1,8 @@ import type { SinonStub, SinonSpy } from 'sinon'; import { stub, spy } from 'sinon'; -import * as Bluebird from 'bluebird'; -import * as _ from 'lodash'; -import rewire = require('rewire'); +import Bluebird from 'bluebird'; +import _ from 'lodash'; +import rewire from 'rewire'; import { expect } from 'chai'; import * as TargetState from '~/src/device-state/target-state'; diff --git a/test/legacy/42-device-api-v2.spec.ts b/test/legacy/42-device-api-v2.spec.ts index 0bb718cf..fa6ba459 100644 --- a/test/legacy/42-device-api-v2.spec.ts +++ b/test/legacy/42-device-api-v2.spec.ts @@ -1,7 +1,7 @@ import { expect } from 'chai'; import type { SinonStub, SinonSpy } from 'sinon'; import { stub, spy } from 'sinon'; -import * as supertest from 'supertest'; +import supertest from 'supertest'; import sampleResponses = require('~/test-data/device-api-responses.json'); import mockedAPI = require('~/test-lib/mocked-device-api'); diff --git a/test/lib/chai.ts b/test/lib/chai.ts index 67774d4d..4bb998eb 100644 --- a/test/lib/chai.ts +++ b/test/lib/chai.ts @@ -1,8 +1,8 @@ -import * as chai from 'chai'; -import * as chaiAsPromised from 'chai-as-promised'; -import * as sinonChai from 'sinon-chai'; -import * as chaiThings from 'chai-things'; -import * as chaiLike from 'chai-like'; +import chai from 'chai'; +import chaiAsPromised from 'chai-as-promised'; +import sinonChai from 'sinon-chai'; +import chaiThings from 'chai-things'; +import chaiLike from 'chai-like'; /** * Mocha runs this EXACTLY ONCE before all tests to set up globals that diff --git a/test/lib/docker-helper.ts b/test/lib/docker-helper.ts index ab8f4c46..9858ee1a 100644 --- a/test/lib/docker-helper.ts +++ b/test/lib/docker-helper.ts @@ -1,4 +1,4 @@ -import * as Docker from 'dockerode'; +import Docker from 'dockerode'; import * as tar from 'tar-stream'; import { strict as assert } from 'assert'; import { setTimeout } from 'timers/promises'; diff --git a/test/lib/mocked-balena-api.ts b/test/lib/mocked-balena-api.ts index b92ee95d..85b1c9e5 100644 --- a/test/lib/mocked-balena-api.ts +++ b/test/lib/mocked-balena-api.ts @@ -1,5 +1,5 @@ -import * as express from 'express'; -import * as _ from 'lodash'; +import express from 'express'; +import _ from 'lodash'; const api: express.Express & { balenaBackend?: { diff --git a/test/lib/mocked-iptables.ts b/test/lib/mocked-iptables.ts index 666687cd..0eae77b0 100644 --- a/test/lib/mocked-iptables.ts +++ b/test/lib/mocked-iptables.ts @@ -1,7 +1,7 @@ -import _ = require('lodash'); +import _ from 'lodash'; import { expect } from 'chai'; import { stub } from 'sinon'; -import * as childProcess from 'child_process'; +import childProcess from 'child_process'; import * as firewall from '~/lib/firewall'; import * as iptables from '~/lib/iptables'; diff --git a/test/lib/mockerode.ts b/test/lib/mockerode.ts index 9c863fb0..79a77ab4 100644 --- a/test/lib/mockerode.ts +++ b/test/lib/mockerode.ts @@ -1,5 +1,5 @@ -import * as dockerode from 'dockerode'; -import * as sinon from 'sinon'; +import dockerode from 'dockerode'; +import sinon from 'sinon'; import { randomUUID as uuidv4 } from 'crypto'; diff --git a/test/unit/device-api/middleware.spec.ts b/test/unit/device-api/middleware.spec.ts index d9a24087..67c1d4c0 100644 --- a/test/unit/device-api/middleware.spec.ts +++ b/test/unit/device-api/middleware.spec.ts @@ -1,5 +1,5 @@ -import * as express from 'express'; -import * as request from 'supertest'; +import express from 'express'; +import request from 'supertest'; import type { SinonStub } from 'sinon'; import { expect } from 'chai'; diff --git a/test/unit/lib/journald.spec.ts b/test/unit/lib/journald.spec.ts index 32719ea7..34c97ea5 100644 --- a/test/unit/lib/journald.spec.ts +++ b/test/unit/lib/journald.spec.ts @@ -1,7 +1,7 @@ import type { SinonStub } from 'sinon'; import { stub } from 'sinon'; import { expect } from 'chai'; -import * as childProcess from 'child_process'; +import childProcess from 'child_process'; import { spawnJournalctl } from '~/lib/journald'; diff --git a/test/unit/lib/system-info.spec.ts b/test/unit/lib/system-info.spec.ts index 70325e44..d1e2713b 100644 --- a/test/unit/lib/system-info.spec.ts +++ b/test/unit/lib/system-info.spec.ts @@ -2,7 +2,7 @@ import { expect } from 'chai'; import type { SinonStub } from 'sinon'; import { stub } from 'sinon'; import { promises as fs } from 'fs'; -import * as systeminformation from 'systeminformation'; +import systeminformation from 'systeminformation'; import * as fsUtils from '~/lib/fs-utils'; import * as sysInfo from '~/lib/system-info'; diff --git a/test/unit/network.spec.ts b/test/unit/network.spec.ts index 3a2a9388..451ff995 100644 --- a/test/unit/network.spec.ts +++ b/test/unit/network.spec.ts @@ -1,4 +1,4 @@ -import * as os from 'os'; +import os from 'os'; import type { SinonStub } from 'sinon'; import { stub } from 'sinon'; diff --git a/tsconfig.json b/tsconfig.json index 3ccf2ef8..f773a87c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "baseUrl": "./", "target": "ES2022", - "module": "commonjs", + "module": "Node16", "moduleResolution": "Node16", "strict": true, "strictFunctionTypes": false, diff --git a/typings/JSONStream.d.ts b/typings/JSONStream.d.ts deleted file mode 100644 index fe8ab5cf..00000000 --- a/typings/JSONStream.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'JSONStream';