runtime-bootstrap.mjs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env node
  2. /** Private entry owned by the Python single-file runtime packaging. */
  3. import { registerHooks } from 'node:module'
  4. import { isSea } from 'node:sea'
  5. import { fileURLToPath, pathToFileURL } from 'node:url'
  6. if (isSea()) {
  7. // Office spawns executable helpers and URL workers; its complete package tree must be real files.
  8. const parentURL = pathToFileURL(`${process.execPath.replace(/\.exe$/i, '')}-office/package.json`).href
  9. registerHooks({
  10. resolve(specifier, context, nextResolve) {
  11. const office = specifier === '@deepseek-ai/libreoffice-kit' || specifier === '@deepseek-ai/libreoffice-kit/package.json'
  12. return nextResolve(specifier, office ? { ...context, parentURL } : context)
  13. },
  14. })
  15. }
  16. const selectorName = 'DSH_SUBPROCESS_RUNNER'
  17. const selection = process.env[selectorName]
  18. const aclRunner = process.platform === 'win32'
  19. ? fileURLToPath(import.meta.resolve('@deepseek-ai/dsh-sandbox-windows-acl/runner'))
  20. : undefined
  21. if (aclRunner !== undefined && process.argv[2] === aclRunner) {
  22. process.argv.splice(1, 1)
  23. await import('@deepseek-ai/dsh-sandbox-windows-acl/runner')
  24. } else if (process.env.DSH_PTC_RUNTIME_NODE === '1') {
  25. Reflect.deleteProperty(process.env, 'DSH_PTC_RUNTIME_NODE')
  26. await import('@deepseek-ai/dsh-ptc-runtime-node/process')
  27. } else if (selection === undefined) {
  28. const { runCli } = await import('@deepseek-ai/dsh/lib/bin.js')
  29. await runCli()
  30. } else {
  31. Reflect.deleteProperty(process.env, selectorName)
  32. const { runSelectedSubprocessRunner } = await import('@deepseek-ai/dsh-subprocess-local/runner')
  33. await runSelectedSubprocessRunner(selection)
  34. }