@salty-css/core 0.0.1-alpha.327 → 0.0.1-alpha.329

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,13 +2,24 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const promises = require("fs/promises");
4
4
  const path = require("path");
5
- const compiler_helpers = require("../compiler/helpers.cjs");
6
5
  const resolveDynamicConfigCache = async () => {
7
- const corePackageRoot = compiler_helpers.getCorePackageRoot();
8
- if (!corePackageRoot) throw new Error("Could not resolve core package root");
9
- const coreConfigDest = path.join(corePackageRoot, "cache/config-cache.json");
10
- const contents = await promises.readFile(coreConfigDest, "utf8");
11
- if (!contents) throw new Error(`Could not find config cache file at ${coreConfigDest}`);
6
+ const currentDir = process.cwd();
7
+ const filename = "config-cache.json";
8
+ const patterns = ["", "saltygen", "src", "src/saltygen", "cache", "src/cache", "src/saltygen/cache"];
9
+ let contents = "";
10
+ for (const pattern of patterns) {
11
+ const potentialPath = path.join(currentDir, pattern, filename);
12
+ console.log(`Trying to read config cache from: ${potentialPath}`);
13
+ try {
14
+ contents = await promises.readFile(potentialPath, "utf8");
15
+ break;
16
+ } catch {
17
+ }
18
+ }
19
+ if (!contents) {
20
+ console.warn(`Could not find config cache file (${filename}) in any of the expected locations.`);
21
+ return {};
22
+ }
12
23
  return JSON.parse(contents);
13
24
  };
14
25
  exports.resolveDynamicConfigCache = resolveDynamicConfigCache;
@@ -1,12 +1,23 @@
1
1
  import { readFile } from "fs/promises";
2
2
  import { join } from "path";
3
- import { getCorePackageRoot } from "../compiler/helpers.js";
4
3
  const resolveDynamicConfigCache = async () => {
5
- const corePackageRoot = getCorePackageRoot();
6
- if (!corePackageRoot) throw new Error("Could not resolve core package root");
7
- const coreConfigDest = join(corePackageRoot, "cache/config-cache.json");
8
- const contents = await readFile(coreConfigDest, "utf8");
9
- if (!contents) throw new Error(`Could not find config cache file at ${coreConfigDest}`);
4
+ const currentDir = process.cwd();
5
+ const filename = "config-cache.json";
6
+ const patterns = ["", "saltygen", "src", "src/saltygen", "cache", "src/cache", "src/saltygen/cache"];
7
+ let contents = "";
8
+ for (const pattern of patterns) {
9
+ const potentialPath = join(currentDir, pattern, filename);
10
+ console.log(`Trying to read config cache from: ${potentialPath}`);
11
+ try {
12
+ contents = await readFile(potentialPath, "utf8");
13
+ break;
14
+ } catch {
15
+ }
16
+ }
17
+ if (!contents) {
18
+ console.warn(`Could not find config cache file (${filename}) in any of the expected locations.`);
19
+ return {};
20
+ }
10
21
  return JSON.parse(contents);
11
22
  };
12
23
  export {
@@ -3,21 +3,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const path = require("path");
4
4
  var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
5
5
  const getCorePackageRoot = () => {
6
- try {
7
- console.log("getCorePackageRoot import.meta.url:", typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("compiler/helpers.cjs", document.baseURI).href);
8
- console.log("getCorePackageRoot process.cwd():", process.cwd());
9
- const currentDir = (typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("compiler/helpers.cjs", document.baseURI).href) || process.cwd();
10
- console.log("getCorePackageRoot currentDir:", currentDir);
11
- let { pathname } = new URL(currentDir);
12
- console.log("getCorePackageRoot pathname start:", pathname);
13
- while (/core\/?(src\/)?$/.test(pathname) === false) {
14
- pathname = path.join(pathname, "../");
15
- }
16
- return pathname;
17
- } catch (error) {
18
- console.error("Error in getCorePackageRoot:", error);
19
- return void 0;
6
+ let { pathname } = new URL(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("compiler/helpers.cjs", document.baseURI).href);
7
+ while (/core\/?(src\/)?$/.test(pathname) === false) {
8
+ pathname = path.join(pathname, "../");
20
9
  }
10
+ return pathname;
21
11
  };
22
12
  const resolveExportValue = async (value, maxLevel = 10, _level = 0) => {
23
13
  if (_level >= maxLevel) return value;
@@ -1,4 +1,4 @@
1
- export declare const getCorePackageRoot: () => string | undefined;
1
+ export declare const getCorePackageRoot: () => string;
2
2
  export declare const resolveExportValue: <T>(value: unknown, maxLevel?: number, _level?: number) => Promise<T>;
3
3
  export declare const saltyFileExtensions: string[];
4
4
  export declare const saltyFileRegExp: (additional?: string[]) => RegExp;
@@ -1,20 +1,10 @@
1
1
  import { join } from "path";
2
2
  const getCorePackageRoot = () => {
3
- try {
4
- console.log("getCorePackageRoot import.meta.url:", import.meta.url);
5
- console.log("getCorePackageRoot process.cwd():", process.cwd());
6
- const currentDir = import.meta.url || process.cwd();
7
- console.log("getCorePackageRoot currentDir:", currentDir);
8
- let { pathname } = new URL(currentDir);
9
- console.log("getCorePackageRoot pathname start:", pathname);
10
- while (/core\/?(src\/)?$/.test(pathname) === false) {
11
- pathname = join(pathname, "../");
12
- }
13
- return pathname;
14
- } catch (error) {
15
- console.error("Error in getCorePackageRoot:", error);
16
- return void 0;
3
+ let { pathname } = new URL(import.meta.url);
4
+ while (/core\/?(src\/)?$/.test(pathname) === false) {
5
+ pathname = join(pathname, "../");
17
6
  }
7
+ return pathname;
18
8
  };
19
9
  const resolveExportValue = async (value, maxLevel = 10, _level = 0) => {
20
10
  if (_level >= maxLevel) return value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.0.1-alpha.327",
3
+ "version": "0.0.1-alpha.329",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",