UNPKG

ayanami

Version:
45 lines (44 loc) 1.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SSRModule = exports.globalKey = exports.moduleNameKey = void 0; var tslib_1 = require("tslib"); var di_1 = require("@asuka/di"); var omit_1 = tslib_1.__importDefault(require("lodash/omit")); var configSets = new Set(); exports.moduleNameKey = Symbol.for('__MODULE__NAME__'); exports.globalKey = Symbol.for('__GLOBAL_MODULE_CACHE__'); // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types var SSRModule = function (config) { var injectableConfig = { providers: [] }; var name; if (typeof config === 'string') { if (configSets.has(config)) { reportDuplicated(config); } name = config; configSets.add(config); } else if (config && typeof config.name === 'string') { if (configSets.has(config.name)) { reportDuplicated(config.name); } configSets.add(config.name); name = config.name; Object.assign(injectableConfig, omit_1.default(config, 'name')); } else { throw new TypeError('config in SSRModule type error, support string or InjectableConfig with name'); } return function (target) { target.prototype[exports.moduleNameKey] = name; return di_1.Injectable(injectableConfig)(target); }; }; exports.SSRModule = SSRModule; function reportDuplicated(moduleName) { if (process.env.NODE_ENV === 'production') { throw new Error("Duplicated Module name: " + moduleName); } // avoid to throw error after HMR console.warn("Duplicated Module name: " + moduleName); }