prune.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. 'use strict'
  2. const fs = require('fs-extra')
  3. const path = require('path')
  4. const util = require('./_util')
  5. function checkDependency (t, resourcesPath, moduleName, moduleExists) {
  6. const assertion = moduleExists ? 'should' : 'should NOT'
  7. const message = `module dependency '${moduleName}' ${assertion} exist under app/node_modules`
  8. const modulePath = path.join(resourcesPath, 'app', 'node_modules', moduleName)
  9. return fs.pathExists(modulePath)
  10. .then(exists => t.is(moduleExists, exists, message))
  11. .then(() => modulePath)
  12. }
  13. function assertDependencyExists (t, resourcesPath, moduleName) {
  14. return checkDependency(t, resourcesPath, moduleName, true)
  15. .then(modulePath => fs.stat(modulePath))
  16. .then(stats => t.true(stats.isDirectory(), 'module is a directory'))
  17. }
  18. function createPruneOptionTest (t, baseOpts, prune, testMessage) {
  19. const opts = Object.assign({}, baseOpts, {
  20. name: 'pruneTest',
  21. dir: util.fixtureSubdir('basic'),
  22. prune: prune
  23. })
  24. let resourcesPath
  25. return util.packageAndEnsureResourcesPath(t, opts)
  26. .then(generatedResourcesPath => {
  27. resourcesPath = generatedResourcesPath
  28. return assertDependencyExists(t, resourcesPath, 'run-series')
  29. }).then(() => assertDependencyExists(t, resourcesPath, '@types/node'))
  30. .then(() => checkDependency(t, resourcesPath, 'run-waterfall', !prune))
  31. .then(() => checkDependency(t, resourcesPath, 'electron-prebuilt', !prune))
  32. }
  33. util.testSinglePlatform('prune test', (t, baseOpts) => {
  34. return createPruneOptionTest(t, baseOpts, true, 'package.json devDependency should NOT exist under app/node_modules')
  35. })
  36. util.testSinglePlatform('prune electron in dependencies', (t, baseOpts) => {
  37. const opts = Object.assign({}, baseOpts, {
  38. name: 'pruneElectronTest',
  39. dir: util.fixtureSubdir('electron-in-dependencies')
  40. })
  41. return util.packageAndEnsureResourcesPath(t, opts)
  42. .then(resourcesPath => checkDependency(t, resourcesPath, 'electron', false))
  43. })
  44. util.testSinglePlatform('prune: false test', createPruneOptionTest, false,
  45. 'package.json devDependency should exist under app/node_modules')