remove usages of node-abort-controller

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2022-11-28 17:04:49 +01:00
parent e948f5528a
commit de8a975911
26 changed files with 43 additions and 48 deletions
+16
View File
@@ -0,0 +1,16 @@
---
'@backstage/backend-common': minor
'@backstage/backend-tasks': minor
'@backstage/plugin-catalog-backend-module-incremental-ingestion': patch
'@backstage/plugin-search-backend-node': patch
---
Changed to use native `AbortController` and `AbortSignal` from Node.js, instead
of the one from `node-abort-controller`. This is possible now that the minimum
supported Node.js version of the project is 16.
Note that their interfaces are very slightly different, but typically not in a
way that matters to consumers. If you see any typescript errors as a direct
result from this, they are compatible with each other in the ways that we
interact with them, and should be possible to type-cast across without ill
effects.
+5 -7
View File
@@ -6,8 +6,6 @@
/// <reference types="node" />
/// <reference types="webpack-env" />
import { AbortController as AbortController_2 } from 'node-abort-controller';
import { AbortSignal as AbortSignal_2 } from 'node-abort-controller';
import aws from 'aws-sdk';
import { AwsS3Integration } from '@backstage/integration';
import { AzureIntegration } from '@backstage/integration';
@@ -200,7 +198,7 @@ export interface ContainerRunner {
// @alpha
export interface Context {
readonly abortSignal: AbortSignal_2;
readonly abortSignal: AbortSignal;
readonly deadline: Date | undefined;
value<T = unknown>(key: string): T | undefined;
}
@@ -210,7 +208,7 @@ export class Contexts {
static root(): Context;
static withAbort(
parentCtx: Context,
source: AbortController_2 | AbortSignal_2,
source: AbortController | AbortSignal,
): Context;
static withTimeoutDuration(parentCtx: Context, timeout: Duration): Context;
static withTimeoutMillis(parentCtx: Context, timeout: number): Context;
@@ -544,7 +542,7 @@ export type ReadTreeOptions = {
},
): boolean;
etag?: string;
signal?: AbortSignal_2;
signal?: AbortSignal;
};
// @public
@@ -598,7 +596,7 @@ export type ReadTreeResponseFile = {
// @public
export type ReadUrlOptions = {
etag?: string;
signal?: AbortSignal_2;
signal?: AbortSignal;
};
// @public
@@ -657,7 +655,7 @@ export type RunContainerOptions = {
// @public
export type SearchOptions = {
etag?: string;
signal?: AbortSignal_2;
signal?: AbortSignal;
};
// @public
-1
View File
@@ -73,7 +73,6 @@
"minimatch": "^5.0.0",
"minimist": "^1.2.5",
"morgan": "^1.10.0",
"node-abort-controller": "^3.0.1",
"node-fetch": "^2.6.7",
"node-forge": "^1.3.1",
"raw-body": "^2.4.1",
@@ -14,7 +14,6 @@
* limitations under the License.
*/
import { AbortController } from 'node-abort-controller';
import { AbortContext } from './AbortContext';
import { RootContext } from './RootContext';
@@ -14,7 +14,6 @@
* limitations under the License.
*/
import { AbortController, AbortSignal } from 'node-abort-controller';
import { Context } from './types';
/**
@@ -15,7 +15,6 @@
*/
import { Duration } from 'luxon';
import { AbortController } from 'node-abort-controller';
import { Contexts } from './Contexts';
describe('Contexts', () => {
@@ -15,7 +15,6 @@
*/
import { Duration } from 'luxon';
import { AbortController, AbortSignal } from 'node-abort-controller';
import { AbortContext } from './AbortContext';
import { RootContext } from './RootContext';
import { Context } from './types';
@@ -14,29 +14,36 @@
* limitations under the License.
*/
import { AbortSignal } from 'node-abort-controller';
import { Context } from './types';
/**
* Since the root context can never abort, and since nobody is every meant to
* dispatch events through it, we can use a static dummy instance for
* Since the root context can never abort, and since nobody is ever meant to
* dispatch events through it, we can use a static fake instance for
* efficiency.
*/
const dummyAbortSignal: AbortSignal = Object.freeze({
aborted: false,
addEventListener() {},
removeEventListener() {},
dispatchEvent() {
return true;
},
onabort: null,
});
const fakeAbortController = new AbortController();
const fakeAbortSignal: AbortSignal = Object.freeze(
Object.assign(
{
aborted: false,
reason: undefined,
throwIfAborted() {},
onabort() {},
addEventListener() {},
removeEventListener() {},
dispatchEvent() {
return true;
},
},
fakeAbortController.signal,
),
);
/**
* An empty root context.
*/
export class RootContext implements Context {
readonly abortSignal = dummyAbortSignal;
readonly abortSignal = fakeAbortSignal;
readonly deadline = undefined;
value<T = unknown>(_key: string): T | undefined {
@@ -14,7 +14,6 @@
* limitations under the License.
*/
import { AbortSignal } from 'node-abort-controller';
import { Context } from './types';
/**
@@ -14,8 +14,6 @@
* limitations under the License.
*/
import { AbortSignal } from 'node-abort-controller';
/**
* A context that is meant to be passed as a ctx variable down the call chain,
* to pass along scoped information and abort signals.
@@ -17,7 +17,6 @@
import { Readable } from 'stream';
import { Logger } from 'winston';
import { Config } from '@backstage/config';
import { AbortSignal } from 'node-abort-controller';
/**
* A generic interface for fetching plain data from URLs.
+2 -3
View File
@@ -3,7 +3,6 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { AbortSignal as AbortSignal_2 } from 'node-abort-controller';
import { Config } from '@backstage/config';
import { DatabaseManager } from '@backstage/backend-common';
import { Duration } from 'luxon';
@@ -29,14 +28,14 @@ export function readTaskScheduleDefinitionFromConfig(
// @public
export type TaskFunction =
| ((abortSignal: AbortSignal_2) => void | Promise<void>)
| ((abortSignal: AbortSignal) => void | Promise<void>)
| (() => void | Promise<void>);
// @public
export interface TaskInvocationDefinition {
fn: TaskFunction;
id: string;
signal?: AbortSignal_2;
signal?: AbortSignal;
}
// @public
-1
View File
@@ -41,7 +41,6 @@
"knex": "^2.0.0",
"lodash": "^4.17.21",
"luxon": "^3.0.0",
"node-abort-controller": "^3.0.1",
"uuid": "^8.0.0",
"winston": "^3.2.1",
"zod": "^3.9.5"
@@ -15,7 +15,6 @@
*/
import { getVoidLogger } from '@backstage/backend-common';
import { AbortController } from 'node-abort-controller';
import { LocalTaskWorker } from './LocalTaskWorker';
describe('LocalTaskWorker', () => {
@@ -17,7 +17,6 @@
import { ConflictError } from '@backstage/errors';
import { CronTime } from 'cron';
import { DateTime, Duration } from 'luxon';
import { AbortController, AbortSignal } from 'node-abort-controller';
import { Logger } from 'winston';
import { TaskFunction, TaskSettingsV2 } from './types';
import { delegateAbortController, sleep } from './util';
@@ -18,7 +18,6 @@ import { getVoidLogger } from '@backstage/backend-common';
import { TestDatabaseId, TestDatabases } from '@backstage/backend-test-utils';
import { ConflictError, NotFoundError } from '@backstage/errors';
import { Duration } from 'luxon';
import { AbortSignal } from 'node-abort-controller';
import { migrateBackendTasks } from '../database/migrateBackendTasks';
import {
parseDuration,
@@ -16,7 +16,6 @@
import { Knex } from 'knex';
import { Duration } from 'luxon';
import { AbortSignal } from 'node-abort-controller';
import { Logger } from 'winston';
import { DbTasksRow, DB_TASKS_TABLE } from '../database/tables';
import { sleep } from './util';
@@ -17,7 +17,6 @@
import { getVoidLogger } from '@backstage/backend-common';
import { TestDatabases } from '@backstage/backend-test-utils';
import { Duration } from 'luxon';
import { AbortController } from 'node-abort-controller';
import waitForExpect from 'wait-for-expect';
import { migrateBackendTasks } from '../database/migrateBackendTasks';
import { DbTasksRow, DB_TASKS_TABLE } from '../database/tables';
@@ -18,7 +18,6 @@ import { ConflictError, NotFoundError } from '@backstage/errors';
import { CronTime } from 'cron';
import { Knex } from 'knex';
import { DateTime, Duration } from 'luxon';
import { AbortSignal } from 'node-abort-controller';
import { v4 as uuid } from 'uuid';
import { Logger } from 'winston';
import { DbTasksRow, DB_TASKS_TABLE } from '../database/tables';
@@ -17,7 +17,6 @@
import { HumanDuration } from '@backstage/types';
import { CronTime } from 'cron';
import { Duration } from 'luxon';
import { AbortSignal } from 'node-abort-controller';
import { z } from 'zod';
/**
@@ -16,7 +16,6 @@
import knexFactory, { Knex } from 'knex';
import { Duration } from 'luxon';
import { AbortController } from 'node-abort-controller';
import { delegateAbortController, nowPlus, sleep, validateId } from './util';
class KnexBuilder {
-1
View File
@@ -17,7 +17,6 @@
import { InputError } from '@backstage/errors';
import { Knex } from 'knex';
import { DateTime, Duration } from 'luxon';
import { AbortController, AbortSignal } from 'node-abort-controller';
// Keep the IDs compatible with e.g. Prometheus labels
export function validateId(id: string) {
@@ -21,7 +21,6 @@ import {
IterationEngineOptions,
} from '../types';
import { IncrementalIngestionDatabaseManager } from '../database/IncrementalIngestionDatabaseManager';
import type { AbortSignal } from 'node-abort-controller';
import { performance } from 'perf_hooks';
import { Duration, DurationObjectUnits } from 'luxon';
import { v4 } from 'uuid';
-1
View File
@@ -33,7 +33,6 @@
"lodash": "^4.17.21",
"lunr": "^2.3.9",
"ndjson": "^2.0.0",
"node-abort-controller": "^3.0.1",
"uuid": "^8.3.2",
"winston": "^3.2.1"
},
@@ -14,7 +14,6 @@
* limitations under the License.
*/
import { AbortController } from 'node-abort-controller';
import { Logger } from 'winston';
import { TaskFunction, TaskRunner } from '@backstage/backend-tasks';
-3
View File
@@ -3590,7 +3590,6 @@ __metadata:
morgan: ^1.10.0
msw: ^0.49.0
mysql2: ^2.2.5
node-abort-controller: ^3.0.1
node-fetch: ^2.6.7
node-forge: ^1.3.1
raw-body: ^2.4.1
@@ -3654,7 +3653,6 @@ __metadata:
knex: ^2.0.0
lodash: ^4.17.21
luxon: ^3.0.0
node-abort-controller: ^3.0.1
uuid: ^8.0.0
wait-for-expect: ^3.0.2
winston: ^3.2.1
@@ -7676,7 +7674,6 @@ __metadata:
lodash: ^4.17.21
lunr: ^2.3.9
ndjson: ^2.0.0
node-abort-controller: ^3.0.1
uuid: ^8.3.2
winston: ^3.2.1
languageName: unknown