index.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. var path = require('path');
  2. var versionArray = process.version
  3. .substr(1)
  4. .replace(/-.*$/, '')
  5. .split('.')
  6. .map(function(item) {
  7. return +item;
  8. });
  9. // TODO: Check if the main node semantic version is within multiple ranges,
  10. // or detect presence of built-in N-API by some other mechanism TBD.
  11. // We know which version of Node.js first shipped the incarnation of the API
  12. // available in *this* package. So, if we find that the Node.js version is below
  13. // that, we indicate that the API is missing from Node.js.
  14. var isNodeApiBuiltin = (
  15. versionArray[0] > 8 ||
  16. (versionArray[0] == 8 && versionArray[1] >= 6) ||
  17. (versionArray[0] == 6 && versionArray[1] >= 15) ||
  18. (versionArray[0] == 6 && versionArray[1] >= 14 && versionArray[2] >= 2));
  19. // The flag is not needed when the Node version is not 8, nor if the API is
  20. // built-in, because we removed the flag at the same time as creating the final
  21. // incarnation of the built-in API.
  22. var needsFlag = (!isNodeApiBuiltin && versionArray[0] == 8);
  23. var include = [__dirname];
  24. var gyp = path.join(__dirname, 'src', 'node_api.gyp');
  25. if (isNodeApiBuiltin) {
  26. gyp += ':nothing';
  27. } else {
  28. gyp += ':node-api';
  29. include.unshift(path.join(__dirname, 'external-napi'));
  30. }
  31. module.exports = {
  32. include: include.map(function(item) {
  33. return '"' + item + '"';
  34. }).join(' '),
  35. gyp: gyp,
  36. isNodeApiBuiltin: isNodeApiBuiltin,
  37. needsFlag: needsFlag
  38. };