tui-package-privacy.mjs 901 B

1234567891011121314151617181920212223242526
  1. import path from "node:path";
  2. const TEST_DIRECTORY_NAMES = new Set(["test", "tests", "__tests__"]);
  3. export function isTuiNonRuntimeResourcePath(sourcePath) {
  4. const normalized = String(sourcePath).replaceAll(
  5. path.win32.sep,
  6. path.posix.sep,
  7. );
  8. const segments = normalized.split("/").filter(Boolean);
  9. const baseName = (segments.at(-1) ?? "").toLowerCase();
  10. if (baseName === "__pycache__" || baseName.endsWith(".pyc")) return true;
  11. if (baseName.endsWith(".map") || baseName.endsWith(".snap")) return true;
  12. if (
  13. segments.some((segment) => TEST_DIRECTORY_NAMES.has(segment.toLowerCase()))
  14. )
  15. return true;
  16. return (
  17. /\.(?:test|spec)\.[^.]+$/u.test(baseName) ||
  18. /^test(?:[_-].+)?\.[^.]+$/u.test(baseName) ||
  19. /[_-]test\.[^.]+$/u.test(baseName)
  20. );
  21. }
  22. export function shouldCopyTuiRuntimeResource(sourcePath) {
  23. return !isTuiNonRuntimeResourcePath(sourcePath);
  24. }