testpackage.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 'use strict';
  2. module.exports = exports = testpackage;
  3. exports.usage = 'Tests that the staged package is valid';
  4. const fs = require('fs');
  5. const path = require('path');
  6. const log = require('npmlog');
  7. const existsAsync = fs.exists || path.exists;
  8. const versioning = require('./util/versioning.js');
  9. const napi = require('./util/napi.js');
  10. const testbinary = require('./testbinary.js');
  11. const tar = require('tar');
  12. const makeDir = require('make-dir');
  13. function testpackage(gyp, argv, callback) {
  14. const package_json = gyp.package_json;
  15. const napi_build_version = napi.get_napi_build_version_from_command_args(argv);
  16. const opts = versioning.evaluate(package_json, gyp.opts, napi_build_version);
  17. const tarball = opts.staged_tarball;
  18. existsAsync(tarball, (found) => {
  19. if (!found) {
  20. return callback(new Error('Cannot test package because ' + tarball + ' missing: run `node-pre-gyp package` first'));
  21. }
  22. const to = opts.module_path;
  23. function filter_func(entry) {
  24. log.info('install', 'unpacking [' + entry.path + ']');
  25. }
  26. makeDir(to).then(() => {
  27. tar.extract({
  28. file: tarball,
  29. cwd: to,
  30. strip: 1,
  31. onentry: filter_func
  32. }).then(after_extract, callback);
  33. }).catch((err) => {
  34. return callback(err);
  35. });
  36. function after_extract() {
  37. testbinary(gyp, argv, (err) => {
  38. if (err) {
  39. return callback(err);
  40. } else {
  41. console.log('[' + package_json.name + '] Package appears valid');
  42. return callback();
  43. }
  44. });
  45. }
  46. });
  47. }