@gkalpak/aliases 0.10.0 → 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.
@@ -2,7 +2,7 @@
2
2
  import {stripIndentation} from '../../lib/utils.js';
3
3
  /* eslint-disable max-len */
4
4
  console.log(stripIndentation(`
5
- ### [Generated by: @gkalpak/aliases v0.10.0]
5
+ ### [Generated by: @gkalpak/aliases v0.10.1]
6
6
  ### Copy the following into '~/.bashrc':
7
7
 
8
8
  # Set up prompt.
@@ -2,7 +2,7 @@
2
2
  import {stripIndentation} from '../../lib/utils.js';
3
3
  /* eslint-disable max-len */
4
4
  console.log(stripIndentation(`
5
- ### [Generated by: @gkalpak/aliases v0.10.0]
5
+ ### [Generated by: @gkalpak/aliases v0.10.1]
6
6
  ### Copy the following into '~/.bashrc':
7
7
 
8
8
  # Set up prompt.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {stripIndentation} from '../../lib/utils.js';
3
3
  console.log(stripIndentation(`
4
- ### [Generated by: @gkalpak/aliases v0.10.0]
4
+ ### [Generated by: @gkalpak/aliases v0.10.1]
5
5
  ### Run the following commands:
6
6
 
7
7
  git config --global commit.gpgSign true
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {stripIndentation} from '../../lib/utils.js';
3
3
  console.log(stripIndentation(`
4
- ### [Generated by: @gkalpak/aliases v0.10.0]
4
+ ### [Generated by: @gkalpak/aliases v0.10.1]
5
5
  ### Run the following commands:
6
6
 
7
7
  git config --global commit.gpgSign true
@@ -2,6 +2,6 @@
2
2
  import {readFileSync} from 'node:fs';
3
3
  import {fileURLToPath} from 'node:url';
4
4
  const __dirname = fileURLToPath(new URL('.', import.meta.url));
5
- console.log('""" [Generated by: @gkalpak/aliases v0.10.0]');
5
+ console.log('""" [Generated by: @gkalpak/aliases v0.10.1]');
6
6
  console.log('""" Copy the following into \'~/.vimrc\':\n');
7
7
  console.log(readFileSync(`${__dirname}/../../lib/assets/vimrc.txt`, 'utf8').trim() + '\n');
package/bin/misc/alv.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- console.log('@gkalpak/aliases v0.10.0');
2
+ console.log('@gkalpak/aliases v0.10.1');
package/lib/utils.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // Imports
2
- import {readFileSync} from 'node:fs';
2
+ import {existsSync, readFileSync, realpathSync} from 'node:fs';
3
3
  import {createRequire} from 'node:module';
4
4
  import {fileURLToPath, pathToFileURL} from 'node:url';
5
5
 
@@ -11,6 +11,8 @@ const LINE_LIMIT = 75;
11
11
  const INDENT_PER_LEVEL = 2;
12
12
  const PLATFORM = isWsl ? 'wsl' : process.platform;
13
13
  const internal = {
14
+ _fsExistsSync,
15
+ _fsRealpathSync,
14
16
  _getPlatform,
15
17
  _import,
16
18
  _onError,
@@ -35,6 +37,14 @@ export {
35
37
  };
36
38
 
37
39
  // Helpers
40
+ function _fsExistsSync(path) {
41
+ return existsSync(path);
42
+ }
43
+
44
+ function _fsRealpathSync(path) {
45
+ return realpathSync(path);
46
+ }
47
+
38
48
  function _getPlatform() {
39
49
  return PLATFORM;
40
50
  }
@@ -113,17 +123,11 @@ async function importWithEnv(targetImportPath, sourceImportMetaUrl, tempEnvVars)
113
123
  }
114
124
 
115
125
  function isMain(fileUrl) {
116
- const extRe = /\.[cm]?js$/;
117
-
126
+ const mainExt = ['', '.js'].find(ext => internal._fsExistsSync(`${process.argv[1]}${ext}`)) ?? '';
127
+ const mainPath = internal._fsRealpathSync(`${process.argv[1]}${mainExt}`);
118
128
  const filePath = fileURLToPath(fileUrl);
119
- const mainPath = process.argv[1];
120
-
121
- const filePathExt = extRe.exec(filePath)?.[0];
122
- const mainPathExt = extRe.exec(mainPath)?.[0];
123
129
 
124
- return (filePath === mainPath) ||
125
- ((filePathExt !== null) && (filePath === `${mainPath}${filePathExt}`)) ||
126
- ((mainPathExt !== null) && (`${filePath}${mainPathExt}` === mainPath));
130
+ return filePath === mainPath;
127
131
  }
128
132
 
129
133
  function loadJson(filePath) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gkalpak/aliases",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "My global aliases.",
5
5
  "keywords": [
6
6
  "Utility"