Files
xterm.js/src/common/services/ServiceRegistry.ts
T
Daniel ImmsandCursor 17ad33dc3d Remove TypeScript path mappings in favor of relative imports
Fixes https://github.com/xtermjs/xterm.js/issues/5896

TypeScript path mappings for common/*, browser/*, and headless/*
were not rewritten in emitted JavaScript, which forced webpack resolve
aliases and NODE_PATH workarounds so runtime could resolve modules.
That added build complexity and broke tooling such as ESLint import/no-cycle.

Changes:
- Convert ~750 imports across src/, addons/, and test/ to relative paths
- Remove common/browser/headless paths and src catch-all mappings from tsconfigs
  (keep @xterm/addon-* demo and addon typings paths)
- Remove webpack resolve.alias for common, browser, headless, and vs
- Drop NODE_PATH from unit tests, benchmarks, and VS Code launch config
- Fix addon-image IIPImageStorage to import ./Types after removing catch-all *

Verified: npm run build, esbuild, package, package-headless
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-31 09:16:10 -07:00

52 lines
1.7 KiB
TypeScript

/**
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
* @license MIT
*
* This was heavily inspired from microsoft/vscode's dependency injection system (MIT).
*/
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IServiceIdentifier } from './Services';
const enum Constants {
DI_TARGET = 'di$target',
DI_DEPENDENCIES = 'di$dependencies'
}
export const serviceRegistry: Map<string, IServiceIdentifier<any>> = new Map();
export function getServiceDependencies(ctor: any): { id: IServiceIdentifier<any>, index: number, optional: boolean }[] {
return ctor[Constants.DI_DEPENDENCIES] || [];
}
export function createDecorator<T>(id: string): IServiceIdentifier<T> {
if (serviceRegistry.has(id)) {
return serviceRegistry.get(id)!;
}
const decorator: any = function (target: Function, key: string, index: number): any {
if (arguments.length !== 3) {
throw new Error('@IServiceName-decorator can only be used to decorate a parameter');
}
storeServiceDependency(decorator, target, index);
};
decorator._id = id;
serviceRegistry.set(id, decorator);
return decorator;
}
function storeServiceDependency(id: Function, target: Function, index: number): void {
if ((target as any)[Constants.DI_TARGET] === target) {
(target as any)[Constants.DI_DEPENDENCIES].push({ id, index });
} else {
(target as any)[Constants.DI_DEPENDENCIES] = [{ id, index }];
(target as any)[Constants.DI_TARGET] = target;
}
}