Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

node.js 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. 'use strict';
  2. const path = require('path')
  3. const {debug} = require("../debug")
  4. const {getExeBasename} = require("../exe-type")
  5. const whichOrUndefined = require("../which-or-undefined")
  6. /**
  7. * Intercepts Node spawned processes.
  8. *
  9. * @param workingDir {string} Absolute system-dependent path to the directory containing the shim files.
  10. * @param options {import("../munge").InternalSpawnOptions} Original internal spawn options.
  11. * @return {import("../munge").InternalSpawnOptions} Updated internal spawn options.
  12. */
  13. function mungeNode(workingDir, options) {
  14. // Remember the original Node command to use it in the shim
  15. const originalNode = options.file
  16. const command = getExeBasename(options.file)
  17. // make sure it has a main script.
  18. // otherwise, just let it through.
  19. let a = 0
  20. let hasMain = false
  21. let mainIndex = 1
  22. for (a = 1; !hasMain && a < options.args.length; a++) {
  23. switch (options.args[a]) {
  24. case '-p':
  25. case '-i':
  26. case '--interactive':
  27. case '--eval':
  28. case '-e':
  29. case '-pe':
  30. hasMain = false
  31. a = options.args.length
  32. continue
  33. case '-r':
  34. case '--require':
  35. a += 1
  36. continue
  37. default:
  38. // TODO: Double-check this part
  39. if (options.args[a].startsWith('-')) {
  40. continue
  41. } else {
  42. hasMain = true
  43. mainIndex = a
  44. a = options.args.length
  45. break
  46. }
  47. }
  48. }
  49. const newArgs = [...options.args];
  50. let newFile = options.file;
  51. if (hasMain) {
  52. const replace = path.join(workingDir, command)
  53. newArgs.splice(mainIndex, 0, replace)
  54. }
  55. // If the file is just something like 'node' then that'll
  56. // resolve to our shim, and so to prevent double-shimming, we need
  57. // to resolve that here first.
  58. // This also handles the case where there's not a main file, like
  59. // `node -e 'program'`, where we want to avoid the shim entirely.
  60. if (options.file === command) {
  61. const realNode = whichOrUndefined(options.file) || process.execPath
  62. newArgs[0] = realNode
  63. newFile = realNode
  64. }
  65. debug('mungeNode after', options.file, options.args)
  66. return {...options, file: newFile, args: newArgs, originalNode};
  67. }
  68. module.exports = mungeNode