webpack-like-BAQNtVsj.cjs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const require_context = require('./context-DwbtaXxf.cjs');
  2. const node_path = require_context.__toESM(require("node:path"));
  3. //#region src/utils/webpack-like.ts
  4. function transformUse(data, plugin, transformLoader) {
  5. if (data.resource == null) return [];
  6. const id = normalizeAbsolutePath(data.resource + (data.resourceQuery || ""));
  7. if (plugin.transformInclude && !plugin.transformInclude(id)) return [];
  8. const { filter } = require_context.normalizeObjectHook("load", plugin.transform);
  9. if (!filter(id)) return [];
  10. return [{
  11. loader: transformLoader,
  12. options: { plugin },
  13. ident: plugin.name
  14. }];
  15. }
  16. /**
  17. * Normalizes a given path when it's absolute. Normalizing means returning a new path by converting
  18. * the input path to the native os format. This is useful in cases where we want to normalize
  19. * the `id` argument of a hook. Any absolute ids should be in the default format
  20. * of the operating system. Any relative imports or node_module imports should remain
  21. * untouched.
  22. *
  23. * @param path - Path to normalize.
  24. * @returns a new normalized path.
  25. */
  26. function normalizeAbsolutePath(path) {
  27. if ((0, node_path.isAbsolute)(path)) return (0, node_path.normalize)(path);
  28. else return path;
  29. }
  30. //#endregion
  31. Object.defineProperty(exports, 'normalizeAbsolutePath', {
  32. enumerable: true,
  33. get: function () {
  34. return normalizeAbsolutePath;
  35. }
  36. });
  37. Object.defineProperty(exports, 'transformUse', {
  38. enumerable: true,
  39. get: function () {
  40. return transformUse;
  41. }
  42. });