@smithy/shared-ini-file-loader 2.0.5 → 2.0.7

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.
@@ -3,6 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getHomeDir = void 0;
4
4
  const os_1 = require("os");
5
5
  const path_1 = require("path");
6
+ const process_1 = require("process");
7
+ const homeDirCache = {};
8
+ const getHomeDirCacheKey = () => {
9
+ if (process_1.geteuid) {
10
+ return `${(0, process_1.geteuid)()}`;
11
+ }
12
+ return "DEFAULT";
13
+ };
6
14
  const getHomeDir = () => {
7
15
  const { HOME, USERPROFILE, HOMEPATH, HOMEDRIVE = `C:${path_1.sep}` } = process.env;
8
16
  if (HOME)
@@ -11,6 +19,9 @@ const getHomeDir = () => {
11
19
  return USERPROFILE;
12
20
  if (HOMEPATH)
13
21
  return `${HOMEDRIVE}${HOMEPATH}`;
14
- return (0, os_1.homedir)();
22
+ const homeDirCacheKey = getHomeDirCacheKey();
23
+ if (!homeDirCache[homeDirCacheKey])
24
+ homeDirCache[homeDirCacheKey] = (0, os_1.homedir)();
25
+ return homeDirCache[homeDirCacheKey];
15
26
  };
16
27
  exports.getHomeDir = getHomeDir;
@@ -1,5 +1,13 @@
1
1
  import { homedir } from "os";
2
2
  import { sep } from "path";
3
+ import { geteuid } from "process";
4
+ const homeDirCache = {};
5
+ const getHomeDirCacheKey = () => {
6
+ if (geteuid) {
7
+ return `${geteuid()}`;
8
+ }
9
+ return "DEFAULT";
10
+ };
3
11
  export const getHomeDir = () => {
4
12
  const { HOME, USERPROFILE, HOMEPATH, HOMEDRIVE = `C:${sep}` } = process.env;
5
13
  if (HOME)
@@ -8,5 +16,8 @@ export const getHomeDir = () => {
8
16
  return USERPROFILE;
9
17
  if (HOMEPATH)
10
18
  return `${HOMEDRIVE}${HOMEPATH}`;
11
- return homedir();
19
+ const homeDirCacheKey = getHomeDirCacheKey();
20
+ if (!homeDirCache[homeDirCacheKey])
21
+ homeDirCache[homeDirCacheKey] = homedir();
22
+ return homeDirCache[homeDirCacheKey];
12
23
  };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@smithy/shared-ini-file-loader",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
4
4
  "dependencies": {
5
- "@smithy/types": "^2.2.2",
5
+ "@smithy/types": "^2.3.0",
6
6
  "tslib": "^2.5.0"
7
7
  },
8
8
  "devDependencies": {