@splendidlabz/utils 1.10.5 → 1.10.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @splendidlabz/utils
2
2
 
3
+ ## 1.10.7
4
+
5
+ ### Patch Changes
6
+
7
+ - Allow fileCache to accept absolute urls
8
+
9
+ ## 1.10.6
10
+
11
+ ### Patch Changes
12
+
13
+ - Bump
14
+
3
15
  ## 1.10.5
4
16
 
5
17
  ### Patch Changes
@@ -38,8 +38,11 @@ var import_promises = __toESM(require("fs/promises"), 1);
38
38
  var import_glob = require("glob");
39
39
  var import_node_path = __toESM(require("node:path"), 1);
40
40
  var import_arrays = require("../lib/arrays/index.js");
41
+ function resolveDirPath(dirPath) {
42
+ return import_node_path.default.isAbsolute(dirPath) ? dirPath : import_node_path.default.join(process.cwd(), dirPath);
43
+ }
41
44
  async function createCache(dir) {
42
- const absDirpath = import_node_path.default.join(process.cwd(), dir);
45
+ const absDirpath = resolveDirPath(dir);
43
46
  await import_promises.default.mkdir(absDirpath, { recursive: true });
44
47
  return {
45
48
  async cacheAt(file) {
@@ -52,7 +55,7 @@ async function createCache(dir) {
52
55
  return 0;
53
56
  }
54
57
  } else {
55
- return getLastModifiedTime(dir + "/**/*");
58
+ return getLastModifiedTime(absDirpath + "/**/*");
56
59
  }
57
60
  },
58
61
  getAbsPath(file) {
@@ -94,8 +97,9 @@ async function createCache(dir) {
94
97
  };
95
98
  }
96
99
  async function fileCache({ dir, file }) {
97
- await import_promises.default.mkdir(import_node_path.default.join(process.cwd(), dir), { recursive: true });
98
- const cachePath = import_node_path.default.join(process.cwd(), dir, `${file}`);
100
+ const absDirpath = resolveDirPath(dir);
101
+ await import_promises.default.mkdir(absDirpath, { recursive: true });
102
+ const cachePath = import_node_path.default.join(absDirpath, `${file}`);
99
103
  let modifiedAt = 0;
100
104
  try {
101
105
  const stat = await import_promises.default.stat(cachePath);
@@ -2,8 +2,11 @@ import fs from "fs/promises";
2
2
  import { glob } from "glob";
3
3
  import path from "node:path";
4
4
  import { sort } from "../lib/arrays/index.js";
5
+ function resolveDirPath(dirPath) {
6
+ return path.isAbsolute(dirPath) ? dirPath : path.join(process.cwd(), dirPath);
7
+ }
5
8
  async function createCache(dir) {
6
- const absDirpath = path.join(process.cwd(), dir);
9
+ const absDirpath = resolveDirPath(dir);
7
10
  await fs.mkdir(absDirpath, { recursive: true });
8
11
  return {
9
12
  async cacheAt(file) {
@@ -16,7 +19,7 @@ async function createCache(dir) {
16
19
  return 0;
17
20
  }
18
21
  } else {
19
- return getLastModifiedTime(dir + "/**/*");
22
+ return getLastModifiedTime(absDirpath + "/**/*");
20
23
  }
21
24
  },
22
25
  getAbsPath(file) {
@@ -58,8 +61,9 @@ async function createCache(dir) {
58
61
  };
59
62
  }
60
63
  async function fileCache({ dir, file }) {
61
- await fs.mkdir(path.join(process.cwd(), dir), { recursive: true });
62
- const cachePath = path.join(process.cwd(), dir, `${file}`);
64
+ const absDirpath = resolveDirPath(dir);
65
+ await fs.mkdir(absDirpath, { recursive: true });
66
+ const cachePath = path.join(absDirpath, `${file}`);
63
67
  let modifiedAt = 0;
64
68
  try {
65
69
  const stat = await fs.stat(cachePath);
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Creates a file cache instance for managing cached files in a directory
3
- * @param {string} dir - Relative path to cache directory
3
+ * @param {string} dir - Absolute or relative path to cache directory
4
4
  * @returns {Promise<object>} Cache instance
5
5
  * @property {function(string): Promise<number>} cacheAt - Returns the cached file's modified timestamp, or directory's last modified time if no file specified
6
6
  * @property {function(string): string} getAbsPath - Returns absolute path for a file in cache
@@ -14,7 +14,7 @@ declare function createCache(dir: string): Promise<object>;
14
14
  /**
15
15
  * Legacy file cache API for managing a single cached file
16
16
  * @param {Object} options
17
- * @param {string} options.dir - Relative path to cache directory
17
+ * @param {string} options.dir - Absolute or relative path to cache directory
18
18
  * @param {string} options.file - Filename to cache
19
19
  * @returns {Promise<{
20
20
  * modifiedAt: number,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splendidlabz/utils",
3
- "version": "1.10.5",
3
+ "version": "1.10.7",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "homepage": "https://splendidlabz.com/docs/utils",
@@ -47,6 +47,7 @@
47
47
  "type-check": "tsc --noEmit",
48
48
  "build": "tsup --config tsup.config.mjs",
49
49
  "build:watch": "tsup --config tsup.config.mjs --watch",
50
+ "dev": "npm run build:watch",
50
51
  "clean": "rm -rf dist",
51
52
  "prepublishOnly": "npm run clean && npm run build"
52
53
  },
@@ -3,9 +3,18 @@ import { glob } from 'glob'
3
3
  import path from 'node:path'
4
4
  import { sort } from '../lib/arrays/index.js'
5
5
 
6
+ /**
7
+ * Resolves a path to an absolute path, handling both absolute and relative paths
8
+ * @param {string} dirPath - Absolute or relative path to directory
9
+ * @returns {string} Absolute path
10
+ */
11
+ function resolveDirPath(dirPath) {
12
+ return path.isAbsolute(dirPath) ? dirPath : path.join(process.cwd(), dirPath)
13
+ }
14
+
6
15
  /**
7
16
  * Creates a file cache instance for managing cached files in a directory
8
- * @param {string} dir - Relative path to cache directory
17
+ * @param {string} dir - Absolute or relative path to cache directory
9
18
  * @returns {Promise<object>} Cache instance
10
19
  * @property {function(string): Promise<number>} cacheAt - Returns the cached file's modified timestamp, or directory's last modified time if no file specified
11
20
  * @property {function(string): string} getAbsPath - Returns absolute path for a file in cache
@@ -16,7 +25,7 @@ import { sort } from '../lib/arrays/index.js'
16
25
  * @property {function(string, object): Promise<void>} saveJSON - Saves object as JSON to cache file
17
26
  */
18
27
  export async function createCache(dir) {
19
- const absDirpath = path.join(process.cwd(), dir)
28
+ const absDirpath = resolveDirPath(dir)
20
29
  await fs.mkdir(absDirpath, { recursive: true })
21
30
 
22
31
  return {
@@ -32,7 +41,7 @@ export async function createCache(dir) {
32
41
  }
33
42
  } else {
34
43
  // Return the last modified timestamp of the cache directory
35
- return getLastModifiedTime(dir + '/**/*')
44
+ return getLastModifiedTime(absDirpath + '/**/*')
36
45
  }
37
46
  },
38
47
 
@@ -83,7 +92,7 @@ export async function createCache(dir) {
83
92
  /**
84
93
  * Legacy file cache API for managing a single cached file
85
94
  * @param {Object} options
86
- * @param {string} options.dir - Relative path to cache directory
95
+ * @param {string} options.dir - Absolute or relative path to cache directory
87
96
  * @param {string} options.file - Filename to cache
88
97
  * @returns {Promise<{
89
98
  * modifiedAt: number,
@@ -95,8 +104,9 @@ export async function createCache(dir) {
95
104
  */
96
105
  export async function fileCache({ dir, file }) {
97
106
  // Makes the path if it doesn't exist
98
- await fs.mkdir(path.join(process.cwd(), dir), { recursive: true })
99
- const cachePath = path.join(process.cwd(), dir, `${file}`)
107
+ const absDirpath = resolveDirPath(dir)
108
+ await fs.mkdir(absDirpath, { recursive: true })
109
+ const cachePath = path.join(absDirpath, `${file}`)
100
110
 
101
111
  let modifiedAt = 0
102
112