normalize-options.js 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.normalizeOptions = void 0;
  4. const os_1 = require("os");
  5. const loader_utils_1 = require("loader-utils");
  6. const validate_options_1 = require("./validate-options");
  7. const normalizePatterns = (patterns) => Array.isArray(patterns) ? patterns : [patterns];
  8. const coerceContentEOL = (content) => (content.endsWith(os_1.EOL) ? content : `${content}${os_1.EOL}`);
  9. const getResourceContent = ({ content }) => coerceContentEOL(content);
  10. const normalizeInjector = (injector) => {
  11. if (typeof injector === 'undefined' || injector === 'prepend') {
  12. return (source, resources) => resources.map(getResourceContent).join('') + source;
  13. }
  14. if (injector === 'append') {
  15. return (source, resources) => source + resources.map(getResourceContent).join('');
  16. }
  17. return injector;
  18. };
  19. const normalizeOptions = (ctx) => {
  20. const options = (0, loader_utils_1.getOptions)(ctx);
  21. (0, validate_options_1.validateOptions)(options);
  22. const { patterns, injector, globOptions = {}, resolveUrl = true } = options;
  23. return {
  24. patterns: normalizePatterns(patterns),
  25. injector: normalizeInjector(injector),
  26. globOptions,
  27. resolveUrl,
  28. };
  29. };
  30. exports.normalizeOptions = normalizeOptions;
  31. //# sourceMappingURL=normalize-options.js.map