UNPKG

@fesjs/preset-built-in

Version:
38 lines (37 loc) 2.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = generateExports; var _utils = require("@fesjs/utils"); var _assert = _interopRequireDefault(require("assert")); var _path = _interopRequireDefault(require("path")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const reserveLibrarys = ['fes']; // reserve library // todo 插件导出内容冲突问题待解决 const reserveExportsNames = ['Link', 'NavLink', 'Redirect', 'dynamic', 'withRouter', 'Route']; function generateExports(basePath, { item, fesExportsHook }) { (0, _assert.default)(item.source, 'source should be supplied.'); const source = _path.default.relative(_path.default.basename(basePath), item.source); (0, _assert.default)(item.exportAll || item.specifiers, 'exportAll or specifiers should be supplied.'); (0, _assert.default)(!reserveLibrarys.includes(source), `${source} is reserve library, Please don't use it.`); if (item.exportAll) { return `export * from '${(0, _utils.winPath)(source)}';`; } (0, _assert.default)(Array.isArray(item.specifiers), `specifiers should be Array, but got ${item.specifiers.toString()}.`); const specifiersStrArr = item.specifiers.map(specifier => { if (typeof specifier === 'string') { (0, _assert.default)(!reserveExportsNames.includes(specifier), `${specifier} is reserve name, you can use 'exported' to set alias.`); (0, _assert.default)(!fesExportsHook[specifier], `${specifier} is Defined, you can use 'exported' to set alias.`); fesExportsHook[specifier] = true; return specifier; } (0, _assert.default)(_utils.lodash.isPlainObject(specifier), `Configure item context should be Plain Object, but got ${specifier}.`); (0, _assert.default)(specifier.local && specifier.exported, 'local and exported should be supplied.'); return `${specifier.local} as ${specifier.exported}`; }); return `export { ${specifiersStrArr.join(', ')} } from '${(0, _utils.winPath)(source)}';`; }