Git Product home page Git Product logo

Comments (4)

steyep avatar steyep commented on August 26, 2024

You really should debug this within Alfred because it's a different environment from your terminal. One of the main differences being what is available to Alfred on your $PATH at the time of execution. My initial thought is that nvm is the problem.

That said, to better determine what's happening within the Alfred environment, add this to the first line of ./lib/scriptfilter.js:

return console.error(require('./alfred-exec').execSync(`which node; which npm`).toString());

Open Alfred's debugger with the workflow selected and enter the keyword into Alfred. That should tell you:

  • which version of node Alfred is using
  • the path to node Alfred is using
  • the path to npm Alfred is using

Then you can compare that output to the output you get from terminal and nvm and see where the differences are.

While I currently do not, nor do I have future plans to support nvm, I understand that not everyone has node installed at /usr/local/bin/node so I'm wondering if adding a config variable for path/to/node at installation time would be beneficial...

from alfred-jira.

sarumont avatar sarumont commented on August 26, 2024

I started in Alfred's debugger and moved out because it was easier in the terminal. :)

Your comments sent me down a different path than I was going, and I ended up getting it working. For anyone else running into this issue, first update the first step in the workflow to use the full path to your nvm-managed node. Then, apply this patch:

--- a/lib/alfred-exec.js
+++ b/lib/alfred-exec.js
@@ -1,20 +1,21 @@
 const child = require('child_process');
 let shell = process.env.SHELL;
+let home = process.env.HOME;
 let escQuotes = str => str.replace(/"/g,'\\"');
 let escSpace = str => str.replace(/ /g, '\\ ');
-const PATH = `eval $(/usr/libexec/path_helper | awk '{print $1}')`;
+const PATH = `/usr/libexec/path_helper | awk '{print $1}'`;

 module.exports = {
   'exec': (cmd, options, callback) => {
     cmd = escQuotes(cmd);
-    return child.exec(`${shell} -c "${PATH} ${cmd}"`, options, callback);
+    return child.exec(`${shell} -c ". ${home}/.nvm/nvm.sh && ${PATH} && ${cmd}"`, options, callback);
   },
   'execSync': (cmd, options) => {
     cmd = escQuotes(cmd);
-    return child.execSync(`${shell} -c "${PATH} ${cmd}"`, options);
+    return child.execSync(`${shell} -c ". ${home}/.nvm/nvm.sh && ${PATH} && ${cmd}"`, options);
   },
   'spawn': (cmd, args, options) => {
     args = args.map(escSpace)
-    return child.spawn(shell, ['-c', `${PATH} ${cmd} ${args.join(' ')}`], options);
+    return child.spawn(shell, ['-c', `. {home}/.nvm/nvm.sh && ${PATH} && ${cmd} ${args.join(' ')}`], options);
   }
-}

Et voila!

Thanks for the workflow and help, @steyep. Closing this as you (rightly) don't plan to support nvm.

from alfred-jira.

steyep avatar steyep commented on August 26, 2024

Cool, I'm glad you were able to get it working. Don't forget the $ in the spawn command:

return child.spawn(shell, ['-c', `. ${home}/.nvm/nvm.sh && ${PATH} && ${cmd} ${args.join(' ')}`], options);

You might also consider testing for the nvm script before trying to load it – that way the workflow won't break if you uninstall nvm somewhere down the road 😄

const nvm = `test -f ${process.env.HOME}/.nvm/nvm.sh && ${process.env.HOME}/.nvm/nvm.sh`;

module.exports = {
  'exec': (cmd, options, callback) => {
    cmd = escQuotes(cmd);
    return child.exec(`${shell} -c "${nvm}; ${PATH} && ${cmd}"`, options, callback);
  },
  'execSync': (cmd, options) => {
    cmd = escQuotes(cmd);
    return child.execSync(`${shell} -c "${nvm}; ${PATH} && ${cmd}"`, options);
  },
  'spawn': (cmd, args, options) => {
    args = args.map(escSpace)
    return child.spawn(shell, ['-c', `${nvm}; ${PATH} && ${cmd} ${args.join(' ')}`], options);
  }
}

from alfred-jira.

sarumont avatar sarumont commented on August 26, 2024

Thanks for spotting the $!

As to testing for nvm.sh, I like my hacks as hackish as possible. 8)

Cheers!

from alfred-jira.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.