qiwi/module-federation-manifest-plugin

View on GitHub
src/main/ts/identifier-parsers/consumed-module.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import { IdentifierParser } from './interface'

export interface ParsedConsumedModule {
  name: string
  version: string
  singleton: boolean
  shareScope: string
  eager: boolean
  strictVersion: boolean
}

class ConsumedModuleParser implements IdentifierParser<ParsedConsumedModule> {
  canActive(identifier: string): boolean {
    return identifier.startsWith('consume-shared-module|')
  }

  parse(identifier: string): ParsedConsumedModule {
    const [, shareScope, shareKey, version, strictVersion, _importResolved, singleton, eager] = identifier.split('|')
    return {
      name: shareKey,
      version: version,
      singleton: singleton === 'true',
      shareScope: shareScope,
      eager: eager === 'true',
      strictVersion: strictVersion === 'true',
    }
  }
}

export const consumedModuleParser = new ConsumedModuleParser()