(config: string | (InjectableConfig & { name: string }))
| 8 | |
| 9 | // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types |
| 10 | export const SSRModule = (config: string | (InjectableConfig & { name: string })) => { |
| 11 | const injectableConfig: InjectableConfig = { providers: [] } |
| 12 | let name: string |
| 13 | if (typeof config === 'string') { |
| 14 | if (configSets.has(config)) { |
| 15 | reportDuplicated(config) |
| 16 | } |
| 17 | name = config |
| 18 | configSets.add(config) |
| 19 | } else if (config && typeof config.name === 'string') { |
| 20 | if (configSets.has(config.name)) { |
| 21 | reportDuplicated(config.name) |
| 22 | } |
| 23 | configSets.add(config.name) |
| 24 | name = config.name |
| 25 | Object.assign(injectableConfig, omit(config, 'name')) |
| 26 | } else { |
| 27 | throw new TypeError( |
| 28 | 'config in SSRModule type error, support string or InjectableConfig with name', |
| 29 | ) |
| 30 | } |
| 31 | |
| 32 | return (target: any) => { |
| 33 | target.prototype[moduleNameKey] = name |
| 34 | return Injectable(injectableConfig)(target) |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | function reportDuplicated(moduleName: string) { |
| 39 | if (process.env.NODE_ENV === 'production') { |
no test coverage detected