@gkalpak/aliases 0.9.4 → 0.10.1

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.
Files changed (162) hide show
  1. package/README.md +4 -4
  2. package/bin/aio/__a-builds-dir.js +5 -7
  3. package/bin/aio/aioall.js +5 -5
  4. package/bin/aio/aioatt.js +5 -5
  5. package/bin/aio/aiobd.js +5 -5
  6. package/bin/aio/aiord.js +5 -5
  7. package/bin/aio/aiorm.js +5 -5
  8. package/bin/config/cfgbash.js +3 -4
  9. package/bin/config/cfgbash.wsl.js +3 -4
  10. package/bin/config/cfggit.js +3 -4
  11. package/bin/config/cfggit.wsl.js +4 -5
  12. package/bin/config/cfgvim.js +5 -3
  13. package/bin/docker/dkrall.js +5 -5
  14. package/bin/docker/dkratt.js +5 -5
  15. package/bin/docker/dkrbd.js +5 -5
  16. package/bin/docker/dkrrd.js +5 -5
  17. package/bin/docker/dkrrm.js +5 -5
  18. package/bin/git/__g-pick-branch.js +5 -7
  19. package/bin/git/__g-pick-commit.js +5 -7
  20. package/bin/git/gaa.js +5 -5
  21. package/bin/git/gb.js +5 -5
  22. package/bin/git/gbc.js +5 -5
  23. package/bin/git/gbcm.js +5 -5
  24. package/bin/git/gbd.js +5 -5
  25. package/bin/git/gcl.js +5 -5
  26. package/bin/git/gcm.js +5 -5
  27. package/bin/git/gcma.js +5 -5
  28. package/bin/git/gcmane.js +5 -5
  29. package/bin/git/gcmf.js +5 -5
  30. package/bin/git/gcmfc.js +5 -5
  31. package/bin/git/gcmfs.js +5 -5
  32. package/bin/git/gcmi.js +5 -5
  33. package/bin/git/gcmia.js +5 -5
  34. package/bin/git/gcmiane.js +5 -5
  35. package/bin/git/gcmif.js +5 -5
  36. package/bin/git/gcmifc.js +5 -5
  37. package/bin/git/gcmifs.js +5 -5
  38. package/bin/git/gco.js +5 -5
  39. package/bin/git/gcoghpr-cleanup.js +5 -5
  40. package/bin/git/gcoghpr.js +5 -7
  41. package/bin/git/gcom.js +5 -5
  42. package/bin/git/gcopr.js +5 -5
  43. package/bin/git/gcp.js +5 -5
  44. package/bin/git/gcpa.js +5 -5
  45. package/bin/git/gcpc.js +5 -5
  46. package/bin/git/gcpx.js +5 -5
  47. package/bin/git/gcpxl.js +5 -5
  48. package/bin/git/gd.js +5 -5
  49. package/bin/git/gd1.js +5 -5
  50. package/bin/git/gdefb.js +5 -5
  51. package/bin/git/gdh.js +5 -5
  52. package/bin/git/gdn.js +5 -5
  53. package/bin/git/gdn1.js +5 -5
  54. package/bin/git/gdnh.js +5 -5
  55. package/bin/git/gl.js +5 -5
  56. package/bin/git/gl1.js +5 -5
  57. package/bin/git/gl1g.js +5 -5
  58. package/bin/git/gmt.js +5 -5
  59. package/bin/git/gngprh.js +5 -5
  60. package/bin/git/gngprm.js +5 -5
  61. package/bin/git/gp.js +5 -5
  62. package/bin/git/gp1.js +5 -5
  63. package/bin/git/gpf.js +5 -5
  64. package/bin/git/gpr.js +5 -5
  65. package/bin/git/gpro.js +5 -5
  66. package/bin/git/gprom.js +5 -5
  67. package/bin/git/gpru.js +5 -5
  68. package/bin/git/gprum.js +5 -5
  69. package/bin/git/grb.js +5 -5
  70. package/bin/git/grba.js +5 -5
  71. package/bin/git/grbc.js +5 -5
  72. package/bin/git/grbi.js +5 -5
  73. package/bin/git/grbia.js +5 -5
  74. package/bin/git/grbin.js +5 -5
  75. package/bin/git/grbm.js +5 -5
  76. package/bin/git/grs.js +5 -5
  77. package/bin/git/grs1.js +5 -5
  78. package/bin/git/gs.js +5 -5
  79. package/bin/git/gsh.js +5 -5
  80. package/bin/git/gshn.js +5 -5
  81. package/bin/git/gst.js +5 -5
  82. package/bin/git/gstk.js +5 -5
  83. package/bin/git/gstl.js +5 -5
  84. package/bin/git/gstp.js +5 -5
  85. package/bin/git/gsync.js +5 -5
  86. package/bin/misc/alv.js +1 -2
  87. package/bin/misc/halp.js +2 -2
  88. package/bin/misc/ll.darwin.js +5 -5
  89. package/bin/misc/ll.js +5 -5
  90. package/bin/misc/lla.darwin.js +5 -5
  91. package/bin/misc/lla.js +5 -5
  92. package/bin/misc/osv.darwin.js +5 -5
  93. package/bin/misc/osv.js +5 -5
  94. package/bin/misc/osv.win32.js +5 -5
  95. package/bin/misc/salfup.js +5 -5
  96. package/bin/node/nad.js +5 -5
  97. package/bin/node/naga.js +5 -5
  98. package/bin/node/nap.js +5 -5
  99. package/bin/node/niin.js +5 -5
  100. package/bin/node/nls.js +5 -5
  101. package/bin/node/nls1.js +5 -5
  102. package/bin/node/nlsg.js +5 -5
  103. package/bin/node/nlsg1.js +5 -5
  104. package/bin/node/nr.js +5 -5
  105. package/bin/node/nrd.js +5 -5
  106. package/bin/node/nrin.js +5 -5
  107. package/bin/node/nrp.js +5 -5
  108. package/bin/node/nrx.js +5 -5
  109. package/bin/node/ns.js +5 -5
  110. package/bin/node/nsin.js +5 -5
  111. package/bin/node/nsx.js +5 -5
  112. package/bin/node/nt.js +5 -5
  113. package/bin/node/ntin.js +5 -5
  114. package/bin/node/ntx.js +5 -5
  115. package/bin/node/nua.js +5 -5
  116. package/bin/node/nud.js +5 -5
  117. package/bin/node/nup.js +5 -5
  118. package/bin/node/nv.js +5 -5
  119. package/bin/node/nvls.js +5 -5
  120. package/bin/node/nvls.win32.js +5 -5
  121. package/bin/node/nvlsa.js +5 -5
  122. package/bin/node/nvlsa.win32.js +5 -5
  123. package/bin/node/nvmup.js +5 -5
  124. package/bin/node/nvmup.win32.js +5 -5
  125. package/bin/node/nvu.js +5 -7
  126. package/bin/node/srv.js +5 -5
  127. package/bin/node/srvw.js +5 -5
  128. package/bin/node/yad.js +5 -5
  129. package/bin/node/yaga.js +5 -5
  130. package/bin/node/yap.js +5 -5
  131. package/bin/node/yiin.js +5 -5
  132. package/bin/node/yls.js +5 -5
  133. package/bin/node/yls1.js +5 -5
  134. package/bin/node/ylsg.js +5 -5
  135. package/bin/node/ylsg1.js +5 -5
  136. package/bin/node/yr.js +5 -5
  137. package/bin/node/yrd.js +5 -5
  138. package/bin/node/yrin.js +5 -5
  139. package/bin/node/yrp.js +5 -5
  140. package/bin/node/yrx.js +5 -5
  141. package/bin/node/ys.js +5 -5
  142. package/bin/node/ysin.js +5 -5
  143. package/bin/node/ysx.js +5 -5
  144. package/bin/node/yt.js +5 -5
  145. package/bin/node/ytin.js +5 -5
  146. package/bin/node/ytx.js +5 -5
  147. package/bin/node/yua.js +5 -5
  148. package/bin/node/yud.js +5 -5
  149. package/bin/node/yup.js +5 -5
  150. package/lib/alias-scripts/a-builds-dir.js +65 -45
  151. package/lib/alias-scripts/g-pick-branch.js +44 -25
  152. package/lib/alias-scripts/g-pick-commit.js +44 -25
  153. package/lib/alias-scripts/gcoghpr.js +182 -195
  154. package/lib/alias-scripts/nvu.js +57 -49
  155. package/lib/alias.js +4 -5
  156. package/lib/constants.js +68 -47
  157. package/lib/helper.js +96 -88
  158. package/lib/utils.js +113 -58
  159. package/package.json +8 -6
  160. package/scripts/build.js +11 -10
  161. package/scripts/platformize-bin.js +7 -7
  162. package/scripts/test-pkg.js +14 -12
package/lib/utils.js CHANGED
@@ -1,45 +1,65 @@
1
- 'use strict';
2
-
3
1
  // Imports
4
- const isWsl = require('is-wsl');
2
+ import {existsSync, readFileSync, realpathSync} from 'node:fs';
3
+ import {createRequire} from 'node:module';
4
+ import {fileURLToPath, pathToFileURL} from 'node:url';
5
+
6
+ import isWsl from 'is-wsl';
7
+
5
8
 
6
9
  // Constants
7
10
  const LINE_LIMIT = 75;
8
11
  const INDENT_PER_LEVEL = 2;
9
-
10
- // Variables
11
- const platform = isWsl ? 'wsl' : process.platform;
12
+ const PLATFORM = isWsl ? 'wsl' : process.platform;
13
+ const internal = {
14
+ _fsExistsSync,
15
+ _fsRealpathSync,
16
+ _getPlatform,
17
+ _import,
18
+ _onError,
19
+ _wrapLine,
20
+ };
12
21
 
13
22
  // Exports
14
- const utils = module.exports = {
15
- capitalize: _capitalize,
16
- finallyAsPromised: _finallyAsPromised,
17
- getPlatform: _getPlatform,
18
- onError: _onError,
19
- padRight: _padRight,
20
- require: _require,
21
- requireWithEnv: _requireWithEnv,
22
- stripIndentation: _stripIndentation,
23
- wrapLine: _wrapLine,
23
+ export {
24
+ capitalize,
25
+ getPlatform,
26
+ hasOwnProperty,
27
+ importWithEnv,
28
+ isMain,
29
+ loadJson,
30
+ onError,
31
+ padRight,
32
+ stripIndentation,
33
+ wrapLine,
34
+
35
+ // Exposed for testing purposes only.
36
+ internal as _testing,
24
37
  };
25
38
 
26
- // Functions - Definitions
27
- function _capitalize(str) {
28
- return `${str[0].toUpperCase()}${str.slice(1)}`;
39
+ // Helpers
40
+ function _fsExistsSync(path) {
41
+ return existsSync(path);
29
42
  }
30
43
 
31
- function _finallyAsPromised(promise, callback) {
32
- return promise.then(
33
- val => Promise.resolve(callback()).then(() => val),
34
- err => Promise.resolve(callback()).then(() => Promise.reject(err)));
44
+ function _fsRealpathSync(path) {
45
+ return realpathSync(path);
35
46
  }
36
47
 
37
48
  function _getPlatform() {
38
- return platform;
49
+ return PLATFORM;
50
+ }
51
+
52
+ function _import(filePath) {
53
+ return import(filePath);
39
54
  }
40
55
 
41
- function _onError(err) {
42
- const chalk = require('chalk');
56
+ async function _onError(err) {
57
+ // NOTE:
58
+ // Avoid eagerly loading `chalk` at the top of the file to allow for it to be imported (directly
59
+ // or transitively) with `importWithEnv()`. This is, for example, useful for being able to force
60
+ // the use of colors.
61
+ const {default: chalk} = await import('chalk');
62
+
43
63
  const isExitCode = err && (typeof err === 'number');
44
64
  const errorMsg = (err instanceof Error) ? err.stack : `${isExitCode ? 'Exit code' : 'Error'}: ${err}`;
45
65
 
@@ -47,41 +67,89 @@ function _onError(err) {
47
67
  process.exit(isExitCode ? err : 1);
48
68
  }
49
69
 
50
- function _padRight(str, len) {
51
- const padLen = Math.max(0, len - str.length);
52
- const pad = ' '.repeat(padLen);
70
+ function _wrapLine(line, indent) {
71
+ if (line.length <= LINE_LIMIT) {
72
+ return line;
73
+ }
53
74
 
54
- return `${str}${pad}`;
75
+ const extraIndent = ' '.repeat(INDENT_PER_LEVEL);
76
+ const sep = Date.now() + Math.random();
77
+ const re = new RegExp(/\s&&/.test(line) ? '(\\s)(&&)' : `(.{${LINE_LIMIT},}?\\s)()`, 'g');
78
+
79
+ let lines = line.replace(re, `$1${sep}$2`).split(sep).filter(l => l.trim());
80
+ if (lines.length > 1) {
81
+ lines = lines.map(l => wrapLine(l, `${indent}${extraIndent}`));
82
+ }
83
+
84
+ return lines.join(`\n${indent}${extraIndent}`);
55
85
  }
56
86
 
57
- function _require(depName) {
58
- return require(depName);
87
+ function capitalize(str) {
88
+ return `${str[0].toUpperCase()}${str.slice(1)}`;
59
89
  }
60
90
 
61
- function _requireWithEnv(depName, env, tempEnvVars) {
62
- if (depName.startsWith('.')) {
63
- throw new Error(utils.stripIndentation(`
64
- Unable to resolve '${depName}'. Relative paths are not supported.
65
- (To load relative files use \`requireWithEnv(require.resolve('${depName}'), ...)\`.)
66
- `));
67
- }
91
+ function getPlatform() {
92
+ return internal._getPlatform();
93
+ }
94
+
95
+ function hasOwnProperty(obj, prop) {
96
+ return Object.prototype.hasOwnProperty.call(obj, prop);
97
+ }
98
+
99
+ async function importWithEnv(targetImportPath, sourceImportMetaUrl, tempEnvVars) {
100
+ const {env} = process;
68
101
 
69
102
  const tempEnvVarNames = Object.keys(tempEnvVars);
70
103
  const originalValues = tempEnvVarNames.
71
- filter(name => env.hasOwnProperty(name)).
104
+ filter(name => hasOwnProperty(env, name)).
72
105
  reduce((aggr, name) => Object.assign(aggr, {[name]: env[name]}), {});
73
106
 
107
+ const req = createRequire(sourceImportMetaUrl);
108
+ const resolvedImportPath = req.resolve(targetImportPath);
109
+ const resolvedImportUrl = ((resolvedImportPath === targetImportPath) && !/[\\/]/.test(resolvedImportPath)) ?
110
+ // It's a built-in module: Do not convert to file URL.
111
+ resolvedImportPath :
112
+ // It's a relative path: Convert to file URL.
113
+ pathToFileURL(resolvedImportPath).href;
114
+
74
115
  try {
75
116
  Object.assign(env, tempEnvVars);
76
- return utils.require(depName);
117
+ return await internal._import(resolvedImportUrl);
77
118
  } finally {
78
- tempEnvVarNames.forEach(name => originalValues.hasOwnProperty(name) ?
119
+ tempEnvVarNames.forEach(name => hasOwnProperty(originalValues, name) ?
79
120
  env[name] = originalValues[name] :
80
121
  delete env[name]);
81
122
  }
82
123
  }
83
124
 
84
- function _stripIndentation(str) {
125
+ function isMain(fileUrl) {
126
+ const mainExt = ['', '.js'].find(ext => internal._fsExistsSync(`${process.argv[1]}${ext}`)) ?? '';
127
+ const mainPath = internal._fsRealpathSync(`${process.argv[1]}${mainExt}`);
128
+ const filePath = fileURLToPath(fileUrl);
129
+
130
+ return filePath === mainPath;
131
+ }
132
+
133
+ function loadJson(filePath) {
134
+ try {
135
+ return JSON.parse(readFileSync(filePath, 'utf8'));
136
+ } catch (err) {
137
+ throw new Error(`Failed to load and parse JSON file '${filePath}': ${err?.message || err}`);
138
+ }
139
+ }
140
+
141
+ function onError(err) {
142
+ return internal._onError(err);
143
+ }
144
+
145
+ function padRight(str, len) {
146
+ const padLen = Math.max(0, len - str.length);
147
+ const pad = ' '.repeat(padLen);
148
+
149
+ return `${str}${pad}`;
150
+ }
151
+
152
+ function stripIndentation(str) {
85
153
  const lines = str.replace(/^ *\n/, '').replace(/\n *$/, '').split('\n');
86
154
  const minIndentation = Math.min(...lines.
87
155
  filter(l => !/^ *$/.test(l)).
@@ -91,19 +159,6 @@ function _stripIndentation(str) {
91
159
  return lines.map(l => l.replace(re, '')).join('\n');
92
160
  }
93
161
 
94
- function _wrapLine(line, indent = '') {
95
- if (line.length <= LINE_LIMIT) {
96
- return line;
97
- }
98
-
99
- const extraIndent = ' '.repeat(INDENT_PER_LEVEL);
100
- const sep = Date.now() + Math.random();
101
- const re = new RegExp(/\s&&/.test(line) ? '(\\s)(&&)' : `(.{${LINE_LIMIT},}?\\s)()`, 'g');
102
-
103
- let lines = line.replace(re, `$1${sep}$2`).split(sep).filter(l => l.trim());
104
- if (lines.length > 1) {
105
- lines = lines.map(l => _wrapLine(l, `${indent}${extraIndent}`));
106
- }
107
-
108
- return lines.join(`\n${indent}${extraIndent}`);
162
+ function wrapLine(line, indent = '') {
163
+ return internal._wrapLine(line, indent);
109
164
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gkalpak/aliases",
3
- "version": "0.9.4",
3
+ "version": "0.10.1",
4
4
  "description": "My global aliases.",
5
5
  "keywords": [
6
6
  "Utility"
@@ -171,6 +171,7 @@
171
171
  "yud": "./bin/node/yud.js",
172
172
  "yup": "./bin/node/yup.js"
173
173
  },
174
+ "type": "module",
174
175
  "license": "Unlicense",
175
176
  "author": "gkalpak <kalpakas.g@gmail.com>",
176
177
  "homepage": "https://github.com/gkalpak/aliases#readme",
@@ -188,17 +189,18 @@
188
189
  },
189
190
  "dependencies": {
190
191
  "@gkalpak/cli-utils": "^0.1.10",
191
- "chalk": "^4.1.2",
192
- "inquirer": "^8.2.4",
192
+ "chalk": "^5.2.0",
193
+ "inquirer": "^9.1.5",
193
194
  "is-wsl": "^2.2.0"
194
195
  },
195
196
  "devDependencies": {
196
- "eslint": "^8.23.0",
197
+ "eslint": "^8.36.0",
197
198
  "eslint-plugin-jasmine": "^4.1.3",
198
- "jasmine": "^4.3.0",
199
+ "eslint-plugin-ordered-imports": "^0.6.0",
200
+ "jasmine": "^4.6.0",
199
201
  "npm-run-all": "^4.1.5",
200
202
  "shelljs": "^0.8.5",
201
- "strip-ansi": "^6.0.1",
203
+ "strip-ansi": "^7.0.1",
202
204
  "watch": "^1.0.2"
203
205
  }
204
206
  }
package/scripts/build.js CHANGED
@@ -1,21 +1,22 @@
1
1
  #!/usr/bin/env/ node
2
- 'use strict';
3
-
4
2
  // Imports
5
- const {mkdirSync, writeFileSync} = require('fs');
6
- const {join} = require('path');
7
- const {rm, set} = require('shelljs');
8
- const {ALIASES, BIN_DIR} = require('../lib/constants');
3
+ import {mkdirSync, writeFileSync} from 'node:fs';
4
+ import {join} from 'node:path';
5
+
6
+ import sh from 'shelljs';
7
+
8
+ import {ALIASES, BIN_DIR} from '../lib/constants.js';
9
+
10
+ sh.set('-e');
11
+
9
12
 
10
13
  // Run
11
14
  _main();
12
15
 
13
- // Function - Definitions
16
+ // Helpers
14
17
  function _main() {
15
- set('-e');
16
-
17
18
  // Clean up `bin/`.
18
- rm('-rf', BIN_DIR);
19
+ sh.rm('-rf', BIN_DIR);
19
20
  mkdirSync(BIN_DIR);
20
21
 
21
22
  // For each alias category...
@@ -1,16 +1,16 @@
1
1
  #!/usr/bin/env/ node
2
- 'use strict';
3
-
4
2
  // Imports
5
- const {chmodSync, copyFileSync, existsSync, readdirSync, renameSync, statSync} = require('fs');
6
- const {join} = require('path');
7
- const {BIN_DIR} = require('../lib/constants');
8
- const {getPlatform} = require('../lib/utils');
3
+ import {chmodSync, copyFileSync, existsSync, readdirSync, renameSync, statSync} from 'node:fs';
4
+ import {join} from 'node:path';
5
+
6
+ import {BIN_DIR} from '../lib/constants.js';
7
+ import {getPlatform} from '../lib/utils.js';
8
+
9
9
 
10
10
  // Run
11
11
  _main();
12
12
 
13
- // Function - Definitions
13
+ // Helpers
14
14
  function _main() {
15
15
  // Nothing to do if `bin/` does not exist (e.g. first local `npm install`).
16
16
  if (!existsSync(BIN_DIR)) return;
@@ -1,21 +1,23 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
3
-
4
2
  // Imports
5
- const {green, red} = require('chalk');
6
- const {existsSync} = require('fs');
7
- const {resolve} = require('path');
8
- const {ALIASES, ROOT_DIR} = require('../lib/constants');
9
- const {bin, main, types, typings} = require('../package.json');
3
+ import {existsSync} from 'node:fs';
4
+ import {resolve as pathResolve} from 'node:path';
5
+
6
+ import chalk from 'chalk';
7
+
8
+ import {ALIASES, ROOT_DIR} from '../lib/constants.js';
9
+ import {loadPackageJson} from '../test/test-utils.js';
10
+
10
11
 
11
12
  // Constants
12
- const CHECK_MARK = green('\u2714');
13
- const X_MARK = red('\u2716');
13
+ const CHECK_MARK = chalk.green('\u2714');
14
+ const X_MARK = chalk.red('\u2716');
15
+ const {bin, main, types, typings} = loadPackageJson();
14
16
 
15
17
  // Run
16
18
  _main();
17
19
 
18
- // Function - Definitions
20
+ // Helpers
19
21
  function _main() {
20
22
  checkBin(bin || {}, ROOT_DIR, ALIASES);
21
23
  checkFile('main', main || '', ROOT_DIR);
@@ -43,7 +45,7 @@ function checkBin(bin, rootDir, aliases) {
43
45
  function checkFile(propName, filePath, rootDir) {
44
46
  if (!filePath) return;
45
47
 
46
- const missingFile = !existsSync(resolve(rootDir, filePath));
48
+ const missingFile = !existsSync(pathResolve(rootDir, filePath));
47
49
 
48
50
  reportResults(
49
51
  `The file mentioned in \`package.json > ${propName}\` exists.`,
@@ -68,7 +70,7 @@ function compareToAliases(bin, aliases) {
68
70
 
69
71
  function compareToBinDir(bin, rootDir) {
70
72
  const missingScripts = Object.keys(bin).
71
- map(key => resolve(rootDir, bin[key])).
73
+ map(key => pathResolve(rootDir, bin[key])).
72
74
  filter(path => !existsSync(path));
73
75
 
74
76
  reportResults(