nvm-vanilla 1.0.18 → 1.0.20

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.
@@ -0,0 +1,9 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(npm install:*)",
5
+ "Bash(npx eslint:*)",
6
+ "Bash(npm run lint)"
7
+ ]
8
+ }
9
+ }
package/.eslintrc.js ADDED
@@ -0,0 +1,24 @@
1
+ module.exports = {
2
+ env: {
3
+ node: true,
4
+ es2020: true,
5
+ },
6
+ extends: 'eslint:recommended',
7
+ rules: {
8
+ 'no-unused-vars': 'warn',
9
+ 'no-console': 'off',
10
+ 'semi': ['error', 'always'],
11
+ 'semi-style': ['error', 'last'],
12
+
13
+ 'indent': ['error', 4, {
14
+ 'SwitchCase': 1,
15
+ }],
16
+
17
+ 'comma-dangle': ['error', {
18
+ 'arrays': 'always-multiline',
19
+ 'objects': 'always-multiline',
20
+ }],
21
+
22
+ 'quotes': ['error', 'single'],
23
+ },
24
+ };
package/README.md CHANGED
@@ -1,7 +1,11 @@
1
- # NVM
1
+ # NVM Vanilla
2
2
 
3
3
  ## Usage
4
4
 
5
+ ```
6
+ npm i -g nvm-vanilla
7
+ ```
8
+
5
9
  ```
6
10
  nvm current
7
11
  nvm (which|where) <version>
package/package.json CHANGED
@@ -1,16 +1,20 @@
1
1
  {
2
2
  "name": "nvm-vanilla",
3
- "version": "1.0.18",
4
- "description": "",
3
+ "version": "1.0.20",
4
+ "description": "node version manager written with node itself",
5
5
  "main": "index.js",
6
6
  "bin": {
7
7
  "nvm-vanilla": "src/bin.js"
8
8
  },
9
9
  "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 1",
11
- "postinstall": "node src/init.js"
10
+ "lint": "eslint src/**/*.js",
11
+ "postinstall": "node src/init.js",
12
+ "postpublish": "git push --follow-tags"
12
13
  },
13
14
  "keywords": [],
14
15
  "author": "",
15
- "license": "ISC"
16
+ "license": "ISC",
17
+ "devDependencies": {
18
+ "eslint": "^7.32.0"
19
+ }
16
20
  }
package/src/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-empty */
1
2
  const fs = require('fs');
2
3
  const os = require('os');
3
4
  const path = require('path');
@@ -241,7 +242,7 @@ const getLocalNodeVersion = async (baseDir, name) => {
241
242
  packageFile = getNodePackageFilePath(baseDir, aliasVersion);
242
243
  packageData = await readJsonFile(packageFile).catch(() => { });
243
244
  }
244
-
245
+
245
246
  try {
246
247
  return packageData.version.replace(/^v/, '');
247
248
  } catch (_) {
@@ -317,6 +318,7 @@ const init = async (baseDir, version) => {
317
318
 
318
319
  await mkdirPromise;
319
320
 
321
+ /*
320
322
  const [
321
323
  // nameList,
322
324
  ] = await Promise.all([
@@ -324,6 +326,9 @@ const init = async (baseDir, version) => {
324
326
  install(workDir, nodeVersion, prefixDir),
325
327
  // mkdirPromise,
326
328
  ]);
329
+ */
330
+
331
+ await install(workDir, nodeVersion, prefixDir);
327
332
 
328
333
  const binNameList = await promisify(fs.readdir)(prefixDir);
329
334
  await Promise.all(binNameList.map(async name => {
@@ -382,7 +387,7 @@ const use = async (baseDir, version, evalFlag = true) => {
382
387
  // const workDir = path.join(baseDir, version, 'bin');
383
388
  // const workDir = path.join(baseDir, version, 'node_modules', '.bin');
384
389
 
385
- const prefixDir = path.join(baseDir, version, 'prefix');
390
+ const prefixDir = path.join(baseDir, version, 'prefix');
386
391
  const cacheDir = path.join(baseDir, version, 'cache');
387
392
 
388
393
  const prefixBinDir = getPrefixBinDir(baseDir, version);
package/src/init.js CHANGED
@@ -3,9 +3,15 @@ const fs = require('fs');
3
3
  const path = require('path');
4
4
  const { promisify } = require('util');
5
5
 
6
+ const envCommand = 'nvm-vanilla --eval env';
7
+
6
8
  const pattern = /^.*nvm-vanilla.*$/m;
7
9
 
8
- const insert = async (profilePath, line) => {
10
+ const insert = async (profilePath) => {
11
+ const line = /\.ps1$/.test(profilePath)
12
+ ? `${envCommand} | Out-String | Invoke-Expression`
13
+ : `eval "$(${envCommand})"`;
14
+
9
15
  let content = await promisify(fs.readFile)(profilePath, 'utf-8');
10
16
  if (pattern.test(content)) {
11
17
  content = content.replace(pattern, line);
@@ -16,14 +22,19 @@ const insert = async (profilePath, line) => {
16
22
  };
17
23
 
18
24
  const init = async () => {
19
- if (process.env.PSModulePath) {
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(profilePath, line);
23
- } else {
24
- const profilePath = path.resolve(os.homedir(), '.bashrc');
25
- const line = 'eval "$(nvm-vanilla --eval env)"';
26
- await insert(profilePath, line);
25
+ const profileList = [
26
+ 'Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1',
27
+ '.bashrc',
28
+ '.zshrc',
29
+ // '.profile',
30
+ ];
31
+
32
+ let index = 0;
33
+ while (index < profileList.length) {
34
+ const profileName = profileList[index];
35
+ const profilePath = path.resolve(os.homedir(), profileName);
36
+ await insert(profilePath).catch(() => { });
37
+ index += 1;
27
38
  }
28
39
  };
29
40
 
package/src/nvm-vanilla CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- require('./bin')
3
+ require('./bin');
package/src/.history DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "argv": [
3
- "/usr/local/bin/node",
4
- "/home/nondanee/Playground/nvm2/src/nvm-vanilla",
5
- "init"
6
- ],
7
- "cwd": "/home/nondanee",
8
- "time": 1768744043727,
9
- "pwsh": false
10
- }