webpack-like-CSbnjTNU.js 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import { normalizeObjectHook } from "./context-D49cMElb.js";
  2. import { isAbsolute, normalize } from "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 } = 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$1) {
  27. if (isAbsolute(path$1)) return normalize(path$1);
  28. else return path$1;
  29. }
  30. //#endregion
  31. export { normalizeAbsolutePath, transformUse };