UNPKG

@modern-js/module-tools-v2

Version:

The meta-framework suite designed from scratch for frontend-focused modern web development.

50 lines (49 loc) 4.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.resolveGlobalVars = exports.resolveEnvVars = exports.resolveAlias = exports.getSourceConfig = void 0; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } const resolveAlias = async (context, userAlias) => { const { applyOptionsChain } = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/utils'))); const defaultAlias = context.isTsProject ? {} : { '@': 'src' }; if (!userAlias) { return defaultAlias; } return applyOptionsChain(defaultAlias, userAlias); }; exports.resolveAlias = resolveAlias; const resolveEnvVars = userEnvVars => { const defaultEnvVars = []; return [...defaultEnvVars, ...(userEnvVars !== null && userEnvVars !== void 0 ? userEnvVars : [])]; }; exports.resolveEnvVars = resolveEnvVars; const resolveGlobalVars = userGlobalVars => { const defaultGlobalVars = {}; return _objectSpread(_objectSpread({}, defaultGlobalVars), userGlobalVars !== null && userGlobalVars !== void 0 ? userGlobalVars : {}); }; exports.resolveGlobalVars = resolveGlobalVars; const getSourceConfig = async (api, context) => { var _config$source, _config$source2, _config$source3; const config = api.useResolvedConfigContext(); const alias = await resolveAlias(context, (_config$source = config.source) === null || _config$source === void 0 ? void 0 : _config$source.alias); const envVars = resolveEnvVars((_config$source2 = config.source) === null || _config$source2 === void 0 ? void 0 : _config$source2.envVars); const globalVars = resolveGlobalVars((_config$source3 = config.source) === null || _config$source3 === void 0 ? void 0 : _config$source3.globalVars); const designSystem = {}; return { alias, envVars, globalVars, designSystem }; }; exports.getSourceConfig = getSourceConfig; //# sourceMappingURL=source.js.map