runtime-file-policy.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /** Desktop-only omissions from already installed production npm packages. */
  2. /**
  3. * Identify build and diagnostic files omitted from the immutable Desktop runtime.
  4. * Unrecognized assets and target runtime binaries are retained. Paths name the copied
  5. * node_modules tree, including nested package containers.
  6. * @param path - Path relative to the production node_modules directory.
  7. * @param target - Platform and architecture of the bundled Node executable.
  8. * @returns Omission reason, or undefined when the entry must be copied.
  9. */
  10. export function desktopRuntimeFileExclusion(
  11. path: string, target: { platform: NodeJS.Platform; arch: string },
  12. ): string | undefined {
  13. const parts = path.split(/[\\/]/u)
  14. if (parts.some(part => ['.bin', '.pnpm', '.modules.yaml', '.pnpm-workspace-state-v1.json'].includes(part))) {
  15. return 'package-manager metadata'
  16. }
  17. const file = parts.at(-1) ?? ''
  18. if (/\.(?:[cm]?[jt]s|css)\.map$/u.test(file)) return 'source map'
  19. if (/\.d\.[cm]?ts$/u.test(file)) return 'TypeScript declaration'
  20. if (/\.tsbuildinfo$/u.test(file)) return 'TypeScript build cache'
  21. const packageParts = parts.slice(parts.lastIndexOf('node_modules') + 1)
  22. const nameParts = packageParts[0]?.startsWith('@') ? 2 : 1
  23. const name = packageParts.slice(0, nameParts).join('/')
  24. const entry = packageParts.slice(nameParts).join('/')
  25. if (name === 'fs-ext' && /^build\/(?:Release|Debug)\/(?:obj(?:\/|$)|fs_ext\.(?:exp|lib|pdb|iobj|ipdb)$)/u.test(entry)) {
  26. return 'fs-ext compiler output'
  27. }
  28. if (name === 'fs-ext' && /^build\/(?:binding\.sln|config\.gypi|fs_ext\.vcxproj(?:\.filters)?)$/u.test(entry)) {
  29. return 'fs-ext build configuration'
  30. }
  31. if (name === '@mixmark-io/domino' && (entry === 'test' || entry.startsWith('test/'))) return 'Domino test fixtures'
  32. if (name === 'node-pty' && entry.startsWith('prebuilds/')) {
  33. const platform = packageParts[nameParts + 1]
  34. if (platform !== undefined && platform !== `${target.platform}-${target.arch}`) return 'node-pty other platform'
  35. if (file.endsWith('.pdb')) return 'node-pty debug symbols'
  36. }
  37. if (name === '@koromix/koffi-win32-x64' && entry === 'win32_x64/koffi.lib') return 'Koffi import library'
  38. return undefined
  39. }