node-sass icon indicating copy to clipboard operation
node-sass copied to clipboard

Binary CLI arguments not picked up properly during install

Open wittibs opened this issue 9 years ago • 6 comments

According to the docs binary config section, I should be able to pass command-line arguments to the install process, like so:

npm install node-sass --sass-binary-path=./custom-built-binaries/binding.node

However, the sass extensions script isn't coded to pick up CL arguments this way:

function getArgument(name, args) {
  var flags = args || process.argv.slice(2),
    index = flags.lastIndexOf(name);

  if (index === -1 || index + 1 >= flags.length) {
    return null;
  }

  return flags[index + 1];
}

It expects another CL argument after the first flag, something like this:

npm install node-sass --sass-binary-path ./custom-built-binaries/binding.node

However that won't work, as all custom CL arguments must have '--' prefixed.

The getArgument function needs to be modified to properly pick up CL arguments (probably following the --argument=value pattern specified in the docs). This was briefly mentioned once in issue #1955 here by @xzyfer, but I didn't see any other issue / PR mentioning this problem.

OS/platform info below. FWIW - also confirmed on Windows 7 64-bit machine.

  • NPM version (npm -v): 5.3.0
  • Node version (node -v): 8.4.0
  • Node Process (node -p process.versions): { http_parser: '2.7.0', node: '8.4.0', v8: '6.0.286.52', uv: '1.13.1', zlib: '1.2.11', ares: '1.10.1-DEV', modules: '57', nghttp2: '1.22.0', openssl: '1.0.2l', icu: '59.1', unicode: '9.0', cldr: '31.0.1', tz: '2017b' }
  • Node Platform (node -p process.platform): darwin
  • Node architecture (node -p process.arch): x64
  • node-sass version (node -p "require('node-sass').info"): 4.5.3
  • npm node-sass versions (npm ls node-sass): 4.5.3

wittibs avatar Aug 26 '17 14:08 wittibs

The --sass-binary-path shouldn't include the binding.node in it, it's the path to the folder containing the binding. I had to look through the code to figure this one out, so I think the docs need some clarity. The --sass-binary-name is used if you want to override the binding file name.

nschonni avatar Aug 27 '17 17:08 nschonni

@nschonni - from lib/binding.js (which loads the binding):

return require(ext.getBinaryPath());

As it's written today --sass-binary-path will be required, which means it should specify a file.

wittibs avatar Aug 27 '17 23:08 wittibs

This doesn't appear to be an issue (my apologies). As @saper mentioned in PR #2108, omit the standalone -- and use var=val pattern. Example below:

npm install node-sass --sass-binary-path=/path/to/binary/binding.node

wittibs avatar Nov 13 '17 03:11 wittibs

@wittibs does it have to be an absolute path? Would be great if the output said anything like "Can't find binary" rather than me wondering if it picked it up at all or just didn't find it before trying to download it from GitHub

dominictobias avatar Sep 25 '18 13:09 dominictobias

@DominicTobias yes it does have to be an absolute path. The fact that it downloads from github implies that it did not find a valid absolute path to a binary. If this isn't made clear in the docs, you can always submit a bug to update the docs. (I agree, it's not obvious to anyone who hasn't played around with node-sass or looked at the code) See #2081 for more details on why I abandoned an implementation that would allow users to use relative paths.

wittibs avatar Oct 01 '18 16:10 wittibs

Thanks for the reply. I’m just on my phone and didn’t look at PR but in my naive theoretical implementation I thought it’d just be a case of path.resolve with process.cwd on a relative path but I guess there are complications there!

On Mon, 1 Oct 2018 at 18:55, Ryan Wittibschlager [email protected] wrote:

@DominicTobias https://github.com/DominicTobias yes it does have to be an absolute path. The fact that it downloads from github implies that it did not find a valid absolute path to a binary. If this isn't made clear in the docs, you can always submit a bug to update the docs. (I agree, it's not obvious to anyone who hasn't played around with node-sass or looked at the code) See #2081 https://github.com/sass/node-sass/issues/2081 for more details on why I abandoned an implementation that would allow users to use relative paths.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sass/node-sass/issues/2080#issuecomment-425981585, or mute the thread https://github.com/notifications/unsubscribe-auth/AAuZ-vm0vjM1CNg-dqjDZ5aCJvb_x_5rks5ugkj0gaJpZM4PDgrm .

dominictobias avatar Oct 03 '18 19:10 dominictobias