runtime-file-policy.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 Electron Node runtime.
  8. * @param officeEngine - Engine selected from the installed kit manifest.
  9. * @returns Omission reason, or undefined when the entry must be copied.
  10. */
  11. export function desktopRuntimeFileExclusion(
  12. path: string, target: { platform: NodeJS.Platform; arch: string }, officeEngine: string,
  13. ): string | undefined {
  14. const parts = path.split(/[\\/]/u)
  15. if (parts.some(part => ['.bin', '.pnpm', '.modules.yaml', '.pnpm-workspace-state-v1.json'].includes(part))) {
  16. return 'package-manager metadata'
  17. }
  18. const file = parts.at(-1) ?? ''
  19. if (/\.(?:[cm]?[jt]s|css)\.map$/u.test(file)) return 'source map'
  20. if (/\.d\.[cm]?ts$/u.test(file)) return 'TypeScript declaration'
  21. if (/\.tsbuildinfo$/u.test(file)) return 'TypeScript build cache'
  22. const packageParts = parts.slice(parts.lastIndexOf('node_modules') + 1)
  23. const nameParts = packageParts[0]?.startsWith('@') ? 2 : 1
  24. const name = packageParts.slice(0, nameParts).join('/')
  25. const entry = packageParts.slice(nameParts).join('/')
  26. if (name.startsWith('@deepseek-ai/libreoffice-kit-')) {
  27. if (name !== `@deepseek-ai/libreoffice-kit-${officeEngine}`) return 'LibreOffice other platform'
  28. }
  29. if (name === 'fs-ext' && /^build\/(?:Release|Debug)\/(?:obj(?:\/|$)|fs_ext\.(?:exp|lib|pdb|iobj|ipdb)$)/u.test(entry)) {
  30. return 'fs-ext compiler output'
  31. }
  32. if (name === 'fs-ext' && /^build\/(?:binding\.sln|config\.gypi|fs_ext\.vcxproj(?:\.filters)?)$/u.test(entry)) {
  33. return 'fs-ext build configuration'
  34. }
  35. if (name === '@mixmark-io/domino' && (entry === 'test' || entry.startsWith('test/'))) return 'Domino test fixtures'
  36. if (name === 'node-pty' && entry.startsWith('prebuilds/')) {
  37. const platform = packageParts[nameParts + 1]
  38. if (platform !== undefined && platform !== `${target.platform}-${target.arch}`) return 'node-pty other platform'
  39. if (file.endsWith('.pdb')) return 'node-pty debug symbols'
  40. }
  41. if (name === '@koromix/koffi-win32-x64' && entry === 'win32_x64/koffi.lib') return 'Koffi import library'
  42. return undefined
  43. }