@salty-css/core 0.1.0-refactor-add-additional-paths-to-config-cache.0 → 0.1.0-refactor-add-additional-paths-to-config-cache.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.
|
@@ -4,29 +4,16 @@ const promises = require("fs/promises");
|
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const CACHE_FILENAME = "config-cache.json";
|
|
6
6
|
const ENV_VAR = "SALTY_CONFIG_CACHE_PATH";
|
|
7
|
-
const
|
|
8
|
-
"",
|
|
9
|
-
"saltygen",
|
|
10
|
-
"src",
|
|
11
|
-
"src/saltygen",
|
|
12
|
-
"cache",
|
|
13
|
-
"src/cache",
|
|
14
|
-
"saltygen/cache",
|
|
15
|
-
"src/saltygen/cache",
|
|
16
|
-
"dist",
|
|
17
|
-
"dist/cache",
|
|
18
|
-
"dist/saltygen/cache",
|
|
19
|
-
"build",
|
|
20
|
-
"build/cache",
|
|
21
|
-
"build/saltygen/cache",
|
|
22
|
-
"public/saltygen/cache",
|
|
23
|
-
".next",
|
|
24
|
-
".next/server",
|
|
25
|
-
".next/server/cache",
|
|
26
|
-
".vercel/output/functions"
|
|
27
|
-
];
|
|
7
|
+
const defaultRoots = ["", "src", "dist", "build", "public", ".next", ".next/server", ".vercel/output/functions"];
|
|
28
8
|
const memo = /* @__PURE__ */ new Map();
|
|
29
9
|
let warned = false;
|
|
10
|
+
const isProduction = () => {
|
|
11
|
+
try {
|
|
12
|
+
return process.env["NODE_ENV"] === "production";
|
|
13
|
+
} catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
30
17
|
const toAbsolute = (p, cwd) => path.isAbsolute(p) ? p : path.join(cwd, p);
|
|
31
18
|
const candidatePathsFrom = (entry, cwd) => {
|
|
32
19
|
const abs = toAbsolute(entry, cwd);
|
|
@@ -34,14 +21,19 @@ const candidatePathsFrom = (entry, cwd) => {
|
|
|
34
21
|
return [path.join(abs, CACHE_FILENAME), path.join(abs, "cache", CACHE_FILENAME), path.join(abs, "saltygen", "cache", CACHE_FILENAME)];
|
|
35
22
|
};
|
|
36
23
|
const tryRead = async (path2) => {
|
|
37
|
-
|
|
24
|
+
const useMemo = isProduction();
|
|
25
|
+
if (useMemo && memo.has(path2)) return memo.get(path2) ?? void 0;
|
|
38
26
|
try {
|
|
39
27
|
const contents = await promises.readFile(path2, "utf8");
|
|
40
|
-
if (!contents)
|
|
28
|
+
if (!contents) {
|
|
29
|
+
if (useMemo) memo.set(path2, null);
|
|
30
|
+
return void 0;
|
|
31
|
+
}
|
|
41
32
|
const parsed = JSON.parse(contents);
|
|
42
|
-
memo.set(path2, parsed);
|
|
33
|
+
if (useMemo) memo.set(path2, parsed);
|
|
43
34
|
return parsed;
|
|
44
35
|
} catch {
|
|
36
|
+
if (useMemo) memo.set(path2, null);
|
|
45
37
|
return void 0;
|
|
46
38
|
}
|
|
47
39
|
};
|
|
@@ -53,7 +45,7 @@ const resolveDynamicConfigCache = async (options = {}) => {
|
|
|
53
45
|
if (options.primaryPath) ordered.push(...candidatePathsFrom(options.primaryPath, cwd));
|
|
54
46
|
if (envPath) ordered.push(...candidatePathsFrom(envPath, cwd));
|
|
55
47
|
if (options.extraPaths) for (const p of options.extraPaths) ordered.push(...candidatePathsFrom(p, cwd));
|
|
56
|
-
for (const
|
|
48
|
+
for (const root of defaultRoots) ordered.push(...candidatePathsFrom(root, cwd));
|
|
57
49
|
for (const candidate of ordered) {
|
|
58
50
|
const result = await tryRead(candidate);
|
|
59
51
|
if (result) return result;
|
|
@@ -2,29 +2,16 @@ import { readFile } from "fs/promises";
|
|
|
2
2
|
import { join, isAbsolute } from "path";
|
|
3
3
|
const CACHE_FILENAME = "config-cache.json";
|
|
4
4
|
const ENV_VAR = "SALTY_CONFIG_CACHE_PATH";
|
|
5
|
-
const
|
|
6
|
-
"",
|
|
7
|
-
"saltygen",
|
|
8
|
-
"src",
|
|
9
|
-
"src/saltygen",
|
|
10
|
-
"cache",
|
|
11
|
-
"src/cache",
|
|
12
|
-
"saltygen/cache",
|
|
13
|
-
"src/saltygen/cache",
|
|
14
|
-
"dist",
|
|
15
|
-
"dist/cache",
|
|
16
|
-
"dist/saltygen/cache",
|
|
17
|
-
"build",
|
|
18
|
-
"build/cache",
|
|
19
|
-
"build/saltygen/cache",
|
|
20
|
-
"public/saltygen/cache",
|
|
21
|
-
".next",
|
|
22
|
-
".next/server",
|
|
23
|
-
".next/server/cache",
|
|
24
|
-
".vercel/output/functions"
|
|
25
|
-
];
|
|
5
|
+
const defaultRoots = ["", "src", "dist", "build", "public", ".next", ".next/server", ".vercel/output/functions"];
|
|
26
6
|
const memo = /* @__PURE__ */ new Map();
|
|
27
7
|
let warned = false;
|
|
8
|
+
const isProduction = () => {
|
|
9
|
+
try {
|
|
10
|
+
return process.env["NODE_ENV"] === "production";
|
|
11
|
+
} catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
28
15
|
const toAbsolute = (p, cwd) => isAbsolute(p) ? p : join(cwd, p);
|
|
29
16
|
const candidatePathsFrom = (entry, cwd) => {
|
|
30
17
|
const abs = toAbsolute(entry, cwd);
|
|
@@ -32,14 +19,19 @@ const candidatePathsFrom = (entry, cwd) => {
|
|
|
32
19
|
return [join(abs, CACHE_FILENAME), join(abs, "cache", CACHE_FILENAME), join(abs, "saltygen", "cache", CACHE_FILENAME)];
|
|
33
20
|
};
|
|
34
21
|
const tryRead = async (path) => {
|
|
35
|
-
|
|
22
|
+
const useMemo = isProduction();
|
|
23
|
+
if (useMemo && memo.has(path)) return memo.get(path) ?? void 0;
|
|
36
24
|
try {
|
|
37
25
|
const contents = await readFile(path, "utf8");
|
|
38
|
-
if (!contents)
|
|
26
|
+
if (!contents) {
|
|
27
|
+
if (useMemo) memo.set(path, null);
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
39
30
|
const parsed = JSON.parse(contents);
|
|
40
|
-
memo.set(path, parsed);
|
|
31
|
+
if (useMemo) memo.set(path, parsed);
|
|
41
32
|
return parsed;
|
|
42
33
|
} catch {
|
|
34
|
+
if (useMemo) memo.set(path, null);
|
|
43
35
|
return void 0;
|
|
44
36
|
}
|
|
45
37
|
};
|
|
@@ -51,7 +43,7 @@ const resolveDynamicConfigCache = async (options = {}) => {
|
|
|
51
43
|
if (options.primaryPath) ordered.push(...candidatePathsFrom(options.primaryPath, cwd));
|
|
52
44
|
if (envPath) ordered.push(...candidatePathsFrom(envPath, cwd));
|
|
53
45
|
if (options.extraPaths) for (const p of options.extraPaths) ordered.push(...candidatePathsFrom(p, cwd));
|
|
54
|
-
for (const
|
|
46
|
+
for (const root of defaultRoots) ordered.push(...candidatePathsFrom(root, cwd));
|
|
55
47
|
for (const candidate of ordered) {
|
|
56
48
|
const result = await tryRead(candidate);
|
|
57
49
|
if (result) return result;
|
package/package.json
CHANGED