@ansstory/hias 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ansstory/hias",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "private": false,
5
5
  "description": "个人自用脚手架内置个人常用功能",
6
6
  "author": "AnsStory story <story0809@163.com>",
@@ -3,6 +3,10 @@ const os = require('os')
3
3
  const path = require('path')
4
4
  const { spawnSync } = require('child_process')
5
5
 
6
+ function getNpmCommand(platform = process.platform) {
7
+ return platform === 'win32' ? 'npm.cmd' : 'npm'
8
+ }
9
+
6
10
  function getConfigDirectory(homeDir = os.homedir()) {
7
11
  return path.join(homeDir, '.hias-cli')
8
12
  }
@@ -28,9 +32,16 @@ function clearConfigDirectory({ homeDir = os.homedir(), logger = console, dryRun
28
32
  function uninstallPackage({ homeDir = os.homedir(), logger = console, runCommand = spawnSync } = {}) {
29
33
  clearConfigDirectory({ homeDir, logger })
30
34
 
31
- const result = runCommand('npm', ['uninstall', '@ansstory/hias', '-g'], {
35
+ const command = getNpmCommand()
36
+ const args = ['uninstall', '@ansstory/hias', '-g']
37
+
38
+ if (logger) {
39
+ logger.log(`Running: npm ${args.join(' ')}`)
40
+ }
41
+
42
+ const result = runCommand(command, args, {
32
43
  stdio: 'inherit',
33
- shell: true,
44
+ shell: false,
34
45
  })
35
46
 
36
47
  if (typeof result.status === 'number' && result.status !== 0) {
@@ -64,6 +75,7 @@ if (require.main === module) {
64
75
 
65
76
  module.exports = {
66
77
  clearConfigDirectory,
78
+ getNpmCommand,
67
79
  getConfigDirectory,
68
80
  uninstallPackage,
69
81
  printUsage,
@@ -4,7 +4,7 @@ const fs = require('fs')
4
4
  const os = require('os')
5
5
  const path = require('path')
6
6
 
7
- const { clearConfigDirectory, getConfigDirectory, uninstallPackage } = require('../scripts/cleanup-config')
7
+ const { clearConfigDirectory, getConfigDirectory, getNpmCommand, uninstallPackage } = require('../scripts/cleanup-config')
8
8
 
9
9
  test('clearConfigDirectory removes the hias cli config directory', () => {
10
10
  const tempHome = fs.mkdtempSync(path.join(os.tmpdir(), 'hias-clear-'))
@@ -56,6 +56,7 @@ test('uninstallPackage clears config before uninstalling the global package', ()
56
56
  homeDir: tempHome,
57
57
  logger: null,
58
58
  runCommand: (command, args, options) => {
59
+ assert.equal(fs.existsSync(configDir), false)
59
60
  calls.push({ command, args, options })
60
61
  return { status: 0 }
61
62
  },
@@ -64,9 +65,9 @@ test('uninstallPackage clears config before uninstalling the global package', ()
64
65
  assert.equal(fs.existsSync(configDir), false)
65
66
  assert.deepEqual(calls, [
66
67
  {
67
- command: 'npm',
68
+ command: getNpmCommand(),
68
69
  args: ['uninstall', '@ansstory/hias', '-g'],
69
- options: { stdio: 'inherit', shell: true },
70
+ options: { stdio: 'inherit', shell: false },
70
71
  },
71
72
  ])
72
73
  })