Code coverage report for src/container/InversifyContainerFacade.ts

# All files / src/container InversifyContainerFacade.ts

100% Statements 30/30
100% Branches 0/0
100% Functions 4/4
100% Lines 30/30

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    951x
    1x

    1x
    1x
    1x
    1x

    1x
    1x
    1x
    1x
    1x
    1x
    1x

    1x

    2628x

    2628x

    2626x

    2628x

    2628x

    2628x

    2626x
    2626x

    2628x

    2628x

    2628x

    2628x
    2628x
    2628x
    2628x

    2628x

     import { Container, interfaces } from 'inversify';
    import { ServiceIdentifiers } from './ServiceIdentifiers';

    import { nodeControlFlowTransformersModule } from './modules/node-transformers/NodeControlFlowTransformersModule';
    import { nodeObfuscatorsModule } from './modules/node-transformers/NodeObfuscatorsModule';
    import { nodeTransformersModule } from './modules/node-transformers/NodeTransformersModule';
    import { stackTraceAnalyzerModule } from './modules/stack-trace-analyzer/StackTraceAnalyzerModule';

    import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode';
    import { IInputOptions } from '../interfaces/options/IInputOptions';
    import { IInversifyContainerFacade } from '../interfaces/container/IInversifyContainerFacade';
    import { IJavaScriptObfuscator } from '../interfaces/IJavaScriptObfsucator';
    import { IObfuscationEventEmitter } from '../interfaces/event-emitters/IObfuscationEventEmitter';
    import { IObfuscationResult } from '../interfaces/IObfuscationResult';
    import { IObfuscator } from '../interfaces/IObfuscator';
    import { IOptions } from '../interfaces/options/IOptions';
    import { ISourceMapCorrector } from '../interfaces/ISourceMapCorrector';
    import { IStorage } from '../interfaces/storages/IStorage';

    import { CustomNodesStorage } from '../storages/custom-nodes/CustomNodesStorage';
    import { JavaScriptObfuscatorInternal } from '../JavaScriptObfuscatorInternal';
    import { ObfuscationEventEmitter } from '../event-emitters/ObfuscationEventEmitter';
    import { ObfuscationResult } from '../ObfuscationResult';
    import { Obfuscator } from '../Obfuscator';
    import { Options } from "../options/Options";
    import { SourceMapCorrector } from '../SourceMapCorrector';

    export class InversifyContainerFacade implements IInversifyContainerFacade {
        /**
         * @type {interfaces.Container}
         */
        private readonly container: interfaces.Container;

        /**
         * @param options
         */
        constructor (options: IInputOptions) {
            this.container = new Container();

            this.container
                .bind<IOptions>(ServiceIdentifiers.IOptions)
                .toDynamicValue(() => {
                    return new Options(options);
                })
                .inSingletonScope();

            this.container
                .bind<IJavaScriptObfuscator>(ServiceIdentifiers.IJavaScriptObfuscator)
                .to(JavaScriptObfuscatorInternal)
                .inSingletonScope();

            this.container
                .bind<IObfuscator>(ServiceIdentifiers.IObfuscator)
                .to(Obfuscator)
                .inSingletonScope();

            this.container
                .bind<IObfuscationResult>(ServiceIdentifiers['Factory<IObfuscationResult>'])
                .toFactory<IObfuscationResult>(() => {
                    return (obfuscatedCode: string, sourceMap: string) => {
                        return new ObfuscationResult(obfuscatedCode, sourceMap);
                    };
                });

            this.container
                .bind<ISourceMapCorrector>(ServiceIdentifiers.ISourceMapCorrector)
                .to(SourceMapCorrector)
                .inSingletonScope();

            this.container
                .bind<IObfuscationEventEmitter>(ServiceIdentifiers.IObfuscationEventEmitter)
                .to(ObfuscationEventEmitter)
                .inSingletonScope();

            this.container
                .bind<IStorage<ICustomNode>>(ServiceIdentifiers['IStorage<ICustomNode>'])
                .to(CustomNodesStorage)
                .inSingletonScope();

            // modules
            this.container.load(stackTraceAnalyzerModule);
            this.container.load(nodeTransformersModule);
            this.container.load(nodeControlFlowTransformersModule);
            this.container.load(nodeObfuscatorsModule);
        }

        /**
         * @param serviceIdentifier
         * @returns {T}
         */
        public get <T> (serviceIdentifier: interfaces.ServiceIdentifier<T>): T {
            return this.container.get<T>(serviceIdentifier);
        }
    }