nvm-vanilla 1.0.4 → 1.0.5

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": "nvm-vanilla",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
package/src/bin.js CHANGED
@@ -17,7 +17,7 @@ const main = async () => {
17
17
 
18
18
  const homeDir = os.homedir();
19
19
 
20
- const baseDir = path.join(homeDir, '.nvm2');
20
+ const baseDir = path.join(homeDir, '.nvm-vanilla');
21
21
 
22
22
  const args = process.argv.slice(2);
23
23
 
package/src/index.js CHANGED
@@ -203,7 +203,7 @@ const getLocalNodeVersion = async (baseDir, name) => {
203
203
  const packageFile = path.join(baseDir, name, 'node_modules', nodePackageName, 'package.json');
204
204
  try {
205
205
  const { version } = await readJsonFile(packageFile);
206
- return version;
206
+ return version.replace(/^v/, '');
207
207
  } catch (_) {
208
208
  throw `no local node version "${name}"`;
209
209
  }
@@ -363,9 +363,10 @@ const use = async (baseDir, version, evalFlag = true) => {
363
363
  ? `export ${key}=${value}`
364
364
  : `export ${key}=\${${key}:-${value}}`;
365
365
 
366
+ // powershell
366
367
  if (process.platform === 'win32') {
367
368
  command = (key === 'PATH' || true)
368
- ? `set ${key}=${value}`
369
+ ? `$env:${key}="${value}"`
369
370
  : `if not defined ${key} set ${key}=${value}`;
370
371
  }
371
372
 
@@ -386,8 +387,7 @@ const list = async (baseDir) => {
386
387
  const nameList = await promisify(fs.readdir)(baseDir);
387
388
 
388
389
  let versionList = await Promise.all(nameList.map(async name => {
389
- const packageFile = path.join(baseDir, name, 'node_modules', nodePackageName, 'package.json');
390
- const { version } = await readJsonFile(packageFile).catch(() => ({}));
390
+ const version = getLocalNodeVersion(baseDir, name).catch(() => {});
391
391
  if (!version) return;
392
392
  return 'node@' + name + ' (' + version + ')';
393
393
  }));
package/src/init.js CHANGED
@@ -3,17 +3,27 @@ const fs = require('fs');
3
3
  const path = require('path');
4
4
  const { promisify } = require('util');
5
5
 
6
+ const pattern = /^.*nvm-vanilla.*$/m;
7
+
8
+ const insert = async (profilePath, line) => {
9
+ let content = await promisify(fs.readFile)(profilePath, 'utf-8');
10
+ if (pattern.test(content)) {
11
+ content = content.replace(pattern, line);
12
+ } else {
13
+ content += '\n' + line;
14
+ }
15
+ await promisify(fs.writeFile)(profilePath, content, 'utf-8');
16
+ };
17
+
6
18
  const init = async () => {
7
19
  if (process.platform === 'win32') {
8
- await promisify(fs.appendFile)(
9
- path.resolve(os.homedir(), 'Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1'),
10
- '\nnvm-vanilla --eval env | Out-String | Invoke-Expression',
11
- )
20
+ const profilePath = path.resolve(os.homedir(), 'Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1');
21
+ const line = 'nvm-vanilla --eval env | Out-String | Invoke-Expression';
22
+ await insert(content, line);
12
23
  } else {
13
- await promisify(fs.appendFile)(
14
- path.resolve(os.homedir(), '.bashrc'),
15
- '\neval "$(nvm-vanilla --eval env)"',
16
- );
24
+ const profilePath = path.resolve(os.homedir(), '.bashrc');
25
+ const line = 'eval "$(nvm-vanilla --eval env)"';
26
+ await insert(content, line);
17
27
  }
18
28
  };
19
29
 
package/src/nvm.ps1 CHANGED
@@ -1,7 +1,7 @@
1
1
  function nvm {
2
2
  $result = nvm-vanilla --eval @args 2>$null
3
3
  if ($result) {
4
- Invoke-Expression $result
4
+ Invoke-Expression ($result -join ";")
5
5
  } else {
6
6
  nvm-vanilla @args
7
7
  }