@salty-css/core 0.1.0-refactor-add-additional-paths-to-config-cache.1 → 0.1.0

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.
Files changed (60) hide show
  1. package/README.md +355 -374
  2. package/bin/main.cjs +57 -58
  3. package/bin/main.js +1 -2
  4. package/{class-name-generator-CMWY5KTJ.js → class-name-generator-CUEoPowv.js} +18 -4
  5. package/{class-name-generator-DB5aQwC_.cjs → class-name-generator-MtPkBfM_.cjs} +19 -5
  6. package/compiler/helpers.cjs +10 -2
  7. package/compiler/helpers.d.ts +3 -2
  8. package/compiler/helpers.js +11 -3
  9. package/compiler/resolve-import.d.ts +17 -0
  10. package/compiler/salty-compiler.cjs +144 -33
  11. package/compiler/salty-compiler.d.ts +2 -5
  12. package/compiler/salty-compiler.js +149 -38
  13. package/config/index.cjs +4 -0
  14. package/config/index.js +5 -1
  15. package/css/index.cjs +0 -4
  16. package/css/index.d.ts +0 -1
  17. package/css/index.js +0 -4
  18. package/css/keyframes.cjs +2 -2
  19. package/css/keyframes.js +2 -2
  20. package/factories/define-font.d.ts +28 -0
  21. package/factories/define-import.d.ts +14 -0
  22. package/factories/index.cjs +140 -0
  23. package/factories/index.d.ts +2 -0
  24. package/factories/index.js +140 -0
  25. package/generators/index.cjs +3 -3
  26. package/generators/index.js +3 -3
  27. package/helpers/color.d.ts +6 -0
  28. package/instances/classname-instance.cjs +1 -1
  29. package/instances/classname-instance.js +1 -1
  30. package/package.json +1 -13
  31. package/{parse-styles-C54MOrPg.cjs → parse-styles-BbI-2wdn.cjs} +196 -11
  32. package/{parse-styles-CLMTHo2H.js → parse-styles-BgVqQAni.js} +196 -11
  33. package/parsers/index.cjs +93 -5
  34. package/parsers/index.js +97 -9
  35. package/parsers/parse-templates.d.ts +10 -0
  36. package/parsers/parser-regexes.d.ts +1 -0
  37. package/parsers/resolve-template-variants.d.ts +21 -0
  38. package/runtime/index.cjs +16 -3
  39. package/runtime/index.d.ts +7 -0
  40. package/runtime/index.js +16 -3
  41. package/{to-hash-DAN2LcHK.js → to-hash-DSoCPs8D.js} +8 -0
  42. package/{to-hash-C05Y906F.cjs → to-hash-DT2ImSPA.cjs} +8 -0
  43. package/types/config-types.d.ts +33 -2
  44. package/types/font-types.d.ts +53 -0
  45. package/util/index.cjs +3 -4
  46. package/util/index.js +1 -2
  47. package/util/module-type.d.ts +1 -1
  48. package/cache/resolve-dynamic-config-cache.cjs +0 -64
  49. package/cache/resolve-dynamic-config-cache.d.ts +0 -20
  50. package/cache/resolve-dynamic-config-cache.js +0 -64
  51. package/compiler/copy-config-cache.cjs +0 -39
  52. package/compiler/copy-config-cache.d.ts +0 -17
  53. package/compiler/copy-config-cache.js +0 -39
  54. package/css/dynamic-styles.cjs +0 -28
  55. package/css/dynamic-styles.d.ts +0 -49
  56. package/css/dynamic-styles.js +0 -28
  57. package/dash-case-DIwKaYgE.cjs +0 -9
  58. package/dash-case-DblXvymC.js +0 -10
  59. package/logger-7xz0pyAz.cjs +0 -12
  60. package/logger-hHmCwThj.js +0 -13
package/parsers/index.js CHANGED
@@ -1,10 +1,41 @@
1
- import { p as parseAndJoinStyles } from "../parse-styles-CLMTHo2H.js";
2
- import { a, c, d, b, r } from "../parse-styles-CLMTHo2H.js";
3
- import { d as dashCase } from "../dash-case-DblXvymC.js";
4
- import { t as toHash } from "../to-hash-DAN2LcHK.js";
1
+ import { i as isRichTemplateNode, p as parseAndJoinStyles } from "../parse-styles-BgVqQAni.js";
2
+ import { a, d, e, c, r } from "../parse-styles-BgVqQAni.js";
3
+ import { d as dashCase, t as toHash } from "../to-hash-DSoCPs8D.js";
4
+ const RICH_META_KEYS = /* @__PURE__ */ new Set(["base", "variants", "defaultVariants", "compoundVariants", "anyOfVariants"]);
5
+ const isChildEntry = (key, value) => {
6
+ if (RICH_META_KEYS.has(key)) return false;
7
+ return !!value && typeof value === "object" && !Array.isArray(value);
8
+ };
5
9
  const parseTemplates = async (obj, path = []) => {
6
10
  if (!obj) return "";
7
11
  const classes = [];
12
+ if (isRichTemplateNode(obj)) {
13
+ const rich = obj;
14
+ const baseClassName = path.map((p) => dashCase(String(p))).join("-");
15
+ if (rich.base) {
16
+ const hashClass = "t_" + toHash(baseClassName, 4);
17
+ const result = await parseAndJoinStyles(rich.base, `.${baseClassName}, .${hashClass}`);
18
+ classes.push(result);
19
+ }
20
+ if (rich.variants) {
21
+ for (const [axis, valueMap] of Object.entries(rich.variants)) {
22
+ if (!valueMap || typeof valueMap !== "object") continue;
23
+ for (const [value, styles] of Object.entries(valueMap)) {
24
+ if (!styles || typeof styles !== "object") continue;
25
+ const variantClassName = `${baseClassName}-${dashCase(axis)}-${dashCase(value)}`;
26
+ const variantHashClass = "tv_" + toHash(variantClassName, 4);
27
+ const result = await parseAndJoinStyles(styles, `.${variantClassName}, .${variantHashClass}`);
28
+ classes.push(result);
29
+ }
30
+ }
31
+ }
32
+ for (const [key, value] of Object.entries(rich)) {
33
+ if (!isChildEntry(key, value)) continue;
34
+ const result = await parseTemplates(value, [...path, key.trim()]);
35
+ classes.push(result);
36
+ }
37
+ return classes.join("\n");
38
+ }
8
39
  const levelStyles = {};
9
40
  for (const [key, value] of Object.entries(obj)) {
10
41
  if (typeof value === "function") ;
@@ -17,7 +48,7 @@ const parseTemplates = async (obj, path = []) => {
17
48
  }
18
49
  }
19
50
  if (Object.keys(levelStyles).length) {
20
- const className = path.map(dashCase).join("-");
51
+ const className = path.map((p) => dashCase(String(p))).join("-");
21
52
  const hashClass = "t_" + toHash(className, 4);
22
53
  const result = await parseAndJoinStyles(levelStyles, `.${className}, .${hashClass}`);
23
54
  classes.push(result);
@@ -39,22 +70,79 @@ const getTemplateTypes = (templates) => {
39
70
  };
40
71
  const getTemplateTokens = (templates, parent = "", templateTokens = /* @__PURE__ */ new Set()) => {
41
72
  if (!templates) return [];
73
+ if (isRichTemplateNode(templates)) {
74
+ if (parent) templateTokens.add(parent);
75
+ Object.entries(templates).forEach(([key, value]) => {
76
+ if (!isChildEntry(key, value)) return;
77
+ const keyValue = parent ? `${parent}.${key}` : key;
78
+ getTemplateTokens(value, keyValue, templateTokens);
79
+ });
80
+ return [...templateTokens];
81
+ }
42
82
  Object.entries(templates).forEach(([key, value]) => {
43
83
  const keyValue = parent ? `${parent}.${key}` : key;
44
- if (typeof value === "object") return getTemplateTokens(value, keyValue, templateTokens);
84
+ if (value && typeof value === "object") return getTemplateTokens(value, keyValue, templateTokens);
45
85
  return templateTokens.add(parent);
46
86
  });
47
87
  return [...templateTokens];
48
88
  };
89
+ const getTemplateVariantMaps = (templates) => {
90
+ const result = {};
91
+ if (!templates) return result;
92
+ for (const [topKey, topNode] of Object.entries(templates)) {
93
+ if (!topNode || typeof topNode !== "object" || typeof topNode === "function") continue;
94
+ walk(topNode, [], result[topKey] || (result[topKey] = {}), {});
95
+ }
96
+ return result;
97
+ };
98
+ const mergeAxes = (inherited, node) => {
99
+ const next = {};
100
+ for (const [axis, vals] of Object.entries(inherited)) {
101
+ next[axis] = { ...vals };
102
+ }
103
+ if (isRichTemplateNode(node) && node.variants) {
104
+ for (const [axis, valueMap] of Object.entries(node.variants)) {
105
+ next[axis] = next[axis] || {};
106
+ for (const value of Object.keys(valueMap)) next[axis][value] = true;
107
+ }
108
+ }
109
+ return next;
110
+ };
111
+ const walk = (node, path, out, inheritedAxes) => {
112
+ if (!node || typeof node !== "object" || Array.isArray(node)) return;
113
+ const axes = mergeAxes(inheritedAxes, node);
114
+ const dot = path.join(".");
115
+ if (path.length && (isRichTemplateNode(node) || Object.keys(axes).length)) {
116
+ const axisMap = {};
117
+ for (const [axis, valSet] of Object.entries(axes)) {
118
+ const values = Object.keys(valSet);
119
+ const isBooleanOnly = values.length === 1 && values[0] === "true";
120
+ axisMap[axis] = isBooleanOnly ? "boolean" : values.map((v) => `"${v}"`).join(" | ");
121
+ }
122
+ if (Object.keys(axisMap).length) out[dot] = axisMap;
123
+ }
124
+ if (isRichTemplateNode(node)) {
125
+ for (const [key, value] of Object.entries(node)) {
126
+ if (!isChildEntry(key, value)) continue;
127
+ walk(value, [...path, key.trim()], out, axes);
128
+ }
129
+ return;
130
+ }
131
+ for (const [key, value] of Object.entries(node)) {
132
+ if (!value || typeof value !== "object" || Array.isArray(value)) continue;
133
+ walk(value, [...path, key.trim()], out, axes);
134
+ }
135
+ };
49
136
  export {
50
137
  getTemplateKeys,
51
138
  getTemplateTokens,
52
139
  getTemplateTypes,
140
+ getTemplateVariantMaps,
53
141
  parseAndJoinStyles,
54
142
  a as parseStyles,
55
143
  parseTemplates,
56
- c as parseValueModifiers,
57
- d as parseValueTokens,
58
- b as parseVariableTokens,
144
+ d as parseValueModifiers,
145
+ e as parseValueTokens,
146
+ c as parseVariableTokens,
59
147
  r as reportParserIssue
60
148
  };
@@ -2,3 +2,13 @@ export declare const parseTemplates: <T extends object>(obj: T, path?: PropertyK
2
2
  export declare const getTemplateKeys: <T extends object>(templates: T) => string[];
3
3
  export declare const getTemplateTypes: <T extends object>(templates: T) => Record<string, string>;
4
4
  export declare const getTemplateTokens: <T extends object>(templates: T, parent?: string, templateTokens?: Set<string>) => string[];
5
+ /**
6
+ * Walk every rich-template path in a templates root and emit, for each reachable dot-path, the set of
7
+ * variant axes valid at that path (axis name → union of value names, with `boolean` for axes whose only
8
+ * declared value is `true`).
9
+ *
10
+ * Inheritance: a leaf's axis enum is the union of its own values and every ancestor's values for the
11
+ * same axis. Matches the resolver's bottom-up lookup semantics — anything reachable via fallback is a
12
+ * valid call-site value.
13
+ */
14
+ export declare const getTemplateVariantMaps: (templates: Record<string, any>) => Record<string, Record<string, Record<string, string>>>;
@@ -1,3 +1,4 @@
1
1
  export declare const pseudoTypoRegex: RegExp;
2
2
  export declare const templateLiteralLeftoverRegex: RegExp;
3
3
  export declare const bareAtRuleRegex: RegExp;
4
+ export declare const keyframesAtRuleRegex: RegExp;
@@ -0,0 +1,21 @@
1
+ import { RichTemplateNode } from '../types/config-types';
2
+ export type TemplateCallSite = {
3
+ path: string[];
4
+ variants: Record<string, string | boolean>;
5
+ };
6
+ export declare const isRichTemplateNode: (node: unknown) => node is RichTemplateNode;
7
+ /**
8
+ * Parse a template call-site value into its dot-path and the axis values requested at the call site.
9
+ *
10
+ * String form: `'heading.large@weight=heavy&emphasis=loud&italic'`
11
+ * Object form: `{ name: 'heading.large', weight: 'heavy', emphasis: 'loud', italic: true }`
12
+ */
13
+ export declare const parseTemplateCallSite: (value: unknown) => TemplateCallSite | undefined;
14
+ export declare const pathHasRichNode: (root: any, path: string[]) => boolean;
15
+ /**
16
+ * Resolve a rich-template invocation into a flat CSS-in-JS object.
17
+ * Implements docs/template-variants-spec.md §5 (parent-to-leaf inheritance, replace semantics).
18
+ *
19
+ * Returns `undefined` if the path doesn't resolve. Emits console.warn for unknown axes / values.
20
+ */
21
+ export declare const resolveRichTemplate: (root: any, path: string[], callSiteVariants: Record<string, string | boolean>, templateName: string) => Record<string, any> | undefined;
package/runtime/index.cjs CHANGED
@@ -1,11 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const parseStyles = require("../parse-styles-C54MOrPg.cjs");
3
+ const parseStyles = require("../parse-styles-BbI-2wdn.cjs");
4
+ const toHash = require("../to-hash-DT2ImSPA.cjs");
4
5
  const defineRuntime = (config) => {
5
- const getDynamicStylesCss = async (styles, scope) => {
6
+ const className = (styles) => toHash.toHash(styles);
7
+ const css = async (styles, scope) => {
6
8
  const parsed = await parseStyles.parseStyles(styles, scope, config);
7
9
  return parsed.join("\n");
8
10
  };
9
- return { getDynamicStylesCss };
11
+ const resolve = async (styles, scope) => {
12
+ const _className = className(styles);
13
+ const _css = await css(styles, scope || `.${_className}`);
14
+ return { className: _className, css: _css };
15
+ };
16
+ return {
17
+ className,
18
+ css,
19
+ resolve,
20
+ /** @deprecated Use `css` instead. Kept as an alias for backward compatibility with the standalone `getDynamicStylesCss` helper. */
21
+ getDynamicStylesCss: css
22
+ };
10
23
  };
11
24
  exports.defineRuntime = defineRuntime;
@@ -2,6 +2,13 @@ import { CachedConfig, SaltyConfig } from '../config';
2
2
  import { BaseStyles } from '../types';
3
3
  type Config = Partial<SaltyConfig & CachedConfig>;
4
4
  export declare const defineRuntime: (config: Config) => {
5
+ className: (styles: BaseStyles) => string;
6
+ css: (styles: BaseStyles, scope?: string) => Promise<string>;
7
+ resolve: (styles: BaseStyles, scope?: string) => Promise<{
8
+ className: string;
9
+ css: string;
10
+ }>;
11
+ /** @deprecated Use `css` instead. Kept as an alias for backward compatibility with the standalone `getDynamicStylesCss` helper. */
5
12
  getDynamicStylesCss: (styles: BaseStyles, scope?: string) => Promise<string>;
6
13
  };
7
14
  export {};
package/runtime/index.js CHANGED
@@ -1,10 +1,23 @@
1
- import { a as parseStyles } from "../parse-styles-CLMTHo2H.js";
1
+ import { a as parseStyles } from "../parse-styles-BgVqQAni.js";
2
+ import { t as toHash } from "../to-hash-DSoCPs8D.js";
2
3
  const defineRuntime = (config) => {
3
- const getDynamicStylesCss = async (styles, scope) => {
4
+ const className = (styles) => toHash(styles);
5
+ const css = async (styles, scope) => {
4
6
  const parsed = await parseStyles(styles, scope, config);
5
7
  return parsed.join("\n");
6
8
  };
7
- return { getDynamicStylesCss };
9
+ const resolve = async (styles, scope) => {
10
+ const _className = className(styles);
11
+ const _css = await css(styles, scope || `.${_className}`);
12
+ return { className: _className, css: _css };
13
+ };
14
+ return {
15
+ className,
16
+ css,
17
+ resolve,
18
+ /** @deprecated Use `css` instead. Kept as an alias for backward compatibility with the standalone `getDynamicStylesCss` helper. */
19
+ getDynamicStylesCss: css
20
+ };
8
21
  };
9
22
  export {
10
23
  defineRuntime
@@ -1,3 +1,10 @@
1
+ function dashCase(str) {
2
+ if (!str) return "";
3
+ if (typeof str !== "string") return dashCase(String(str));
4
+ return str.replace(/[\s.]/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (s, i) => {
5
+ return (i > 0 ? "-" : "") + s.toLowerCase();
6
+ });
7
+ }
1
8
  const toAlphabeticChar = (code) => String.fromCharCode(code + (code > 25 ? 39 : 97));
2
9
  const toAlphabeticName = (code, length) => {
3
10
  let name = "";
@@ -21,5 +28,6 @@ const toHash = (value, length = 5) => {
21
28
  return toAlphabeticName(numericHash, length);
22
29
  };
23
30
  export {
31
+ dashCase as d,
24
32
  toHash as t
25
33
  };
@@ -1,4 +1,11 @@
1
1
  "use strict";
2
+ function dashCase(str) {
3
+ if (!str) return "";
4
+ if (typeof str !== "string") return dashCase(String(str));
5
+ return str.replace(/[\s.]/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (s, i) => {
6
+ return (i > 0 ? "-" : "") + s.toLowerCase();
7
+ });
8
+ }
2
9
  const toAlphabeticChar = (code) => String.fromCharCode(code + (code > 25 ? 39 : 97));
3
10
  const toAlphabeticName = (code, length) => {
4
11
  let name = "";
@@ -21,4 +28,5 @@ const toHash = (value, length = 5) => {
21
28
  const numericHash = toPhash(5381, JSON.stringify(value)) >>> 0;
22
29
  return toAlphabeticName(numericHash, length);
23
30
  };
31
+ exports.dashCase = dashCase;
24
32
  exports.toHash = toHash;
@@ -1,5 +1,6 @@
1
1
  import { BaseStyles, CssStyles, MediaQueryStyles } from '../types';
2
2
  import { OrString } from '../types/util-types';
3
+ export * from './font-types';
3
4
  export type GlobalStyles = Record<string, BaseStyles>;
4
5
  export type CssVariableTokensObject = Record<string, unknown>;
5
6
  export interface CssResponsiveVariables {
@@ -15,7 +16,38 @@ export interface SaltyVariables {
15
16
  conditional?: CssConditionalVariables;
16
17
  [key: string]: undefined | string | number | CssVariableTokensObject;
17
18
  }
18
- type CssTemplate = MediaQueryStyles | CssStyles | {
19
+ /**
20
+ * A variant axis value bundle: a map from axis name to a map from value name (string keys or `'true'`)
21
+ * to a CSS-in-JS block. `name` is reserved as the call-site object form's path key and cannot be used
22
+ * as an axis name (build-time error).
23
+ */
24
+ export type CssVariantAxes = {
25
+ [axis: string]: {
26
+ [value: string]: CssStyles;
27
+ };
28
+ } & {
29
+ name?: never;
30
+ };
31
+ export interface CssCompoundVariant {
32
+ css: CssStyles;
33
+ [axis: string]: any;
34
+ }
35
+ /**
36
+ * A "rich" template node: declares its own base styles, named variant bundles, defaults, and compound rules.
37
+ * May coexist with child template nodes (descendants) as additional sibling keys.
38
+ */
39
+ export type RichTemplateNode = {
40
+ base?: CssStyles;
41
+ variants?: CssVariantAxes;
42
+ defaultVariants?: {
43
+ [axis: string]: string | boolean;
44
+ };
45
+ compoundVariants?: CssCompoundVariant[];
46
+ anyOfVariants?: CssCompoundVariant[];
47
+ } & {
48
+ [key: PropertyKey]: any;
49
+ };
50
+ type CssTemplate = MediaQueryStyles | CssStyles | RichTemplateNode | {
19
51
  [key: PropertyKey]: CssTemplate;
20
52
  };
21
53
  export interface CssTemplateObject {
@@ -91,4 +123,3 @@ export interface CachedConfig {
91
123
  [key: string]: string;
92
124
  };
93
125
  }
94
- export {};
@@ -0,0 +1,53 @@
1
+ export type FontDisplay = 'auto' | 'block' | 'swap' | 'fallback' | 'optional';
2
+ export type FontFormat = 'woff2' | 'woff' | 'truetype' | 'opentype' | 'embedded-opentype' | 'svg' | 'collection';
3
+ export type FontStyle = 'normal' | 'italic' | 'oblique' | (string & {});
4
+ export type FontWeight = number | 'normal' | 'bold' | 'lighter' | 'bolder' | (string & {});
5
+ export interface FontSrc {
6
+ url: string;
7
+ format?: FontFormat;
8
+ /** Optional `tech(...)` descriptor passed straight through to @font-face. */
9
+ tech?: string;
10
+ }
11
+ export interface FontVariant {
12
+ weight?: FontWeight;
13
+ style?: FontStyle;
14
+ stretch?: string;
15
+ display?: FontDisplay;
16
+ unicodeRange?: string;
17
+ ascentOverride?: string;
18
+ descentOverride?: string;
19
+ lineGapOverride?: string;
20
+ sizeAdjust?: string;
21
+ /**
22
+ * One or more font sources. Strings are treated as URLs and the `format()`
23
+ * descriptor is auto-detected from the file extension when possible. Use
24
+ * the `{ url, format }` object form for CDN/extensionless URLs where the
25
+ * format must be set explicitly.
26
+ */
27
+ src: string | FontSrc | (string | FontSrc)[];
28
+ }
29
+ interface DefineFontBase {
30
+ /** CSS `font-family` value users will see in styles. */
31
+ name: string;
32
+ /**
33
+ * CSS variable name. Accepts `--font-inter` or `font-inter`; we normalize.
34
+ * Optional — when omitted, a deterministic name is derived from the other
35
+ * inputs as `--font-<name>-<hash>`.
36
+ */
37
+ variable?: string;
38
+ /** Default `font-display` applied to variants that don't set their own. */
39
+ display?: FontDisplay;
40
+ /** Family fallback(s) appended after `name` in the generated `font-family` string. */
41
+ fallback?: string;
42
+ }
43
+ export interface DefineFontVariantsOptions extends DefineFontBase {
44
+ variants: FontVariant[];
45
+ import?: never;
46
+ }
47
+ export interface DefineFontImportOptions extends DefineFontBase {
48
+ /** Remote stylesheet URL (e.g. Google Fonts). Emitted as `@import url(...)`. */
49
+ import: string;
50
+ variants?: never;
51
+ }
52
+ export type DefineFontOptions = DefineFontVariantsOptions | DefineFontImportOptions;
53
+ export {};
package/util/index.cjs CHANGED
@@ -1,14 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const dashCase = require("../dash-case-DIwKaYgE.cjs");
3
+ const toHash = require("../to-hash-DT2ImSPA.cjs");
4
4
  const pascalCase = require("../pascal-case-By_l58S-.cjs");
5
- const toHash = require("../to-hash-C05Y906F.cjs");
6
5
  function camelCase(str) {
7
6
  if (!str) return "";
8
7
  if (typeof str !== "string") return camelCase(String(str));
9
8
  return str.replace(/\s/g, "-").replace(/-([a-z])/g, (g) => g[1].toUpperCase());
10
9
  }
11
- exports.dashCase = dashCase.dashCase;
12
- exports.pascalCase = pascalCase.pascalCase;
10
+ exports.dashCase = toHash.dashCase;
13
11
  exports.toHash = toHash.toHash;
12
+ exports.pascalCase = pascalCase.pascalCase;
14
13
  exports.camelCase = camelCase;
package/util/index.js CHANGED
@@ -1,6 +1,5 @@
1
- import { d } from "../dash-case-DblXvymC.js";
1
+ import { d, t } from "../to-hash-DSoCPs8D.js";
2
2
  import { p } from "../pascal-case-F3Usi5Wf.js";
3
- import { t } from "../to-hash-DAN2LcHK.js";
4
3
  function camelCase(str) {
5
4
  if (!str) return "";
6
5
  if (typeof str !== "string") return camelCase(String(str));
@@ -1 +1 @@
1
- export declare const detectCurrentModuleType: (dirname: string) => Promise<"esm" | "cjs">;
1
+ export declare const detectCurrentModuleType: (dirname: string) => Promise<"cjs" | "esm">;
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const promises = require("fs/promises");
4
- const path = require("path");
5
- const CACHE_FILENAME = "config-cache.json";
6
- const ENV_VAR = "SALTY_CONFIG_CACHE_PATH";
7
- const defaultRoots = ["", "src", "dist", "build", "public", ".next", ".next/server", ".vercel/output/functions"];
8
- const memo = /* @__PURE__ */ new Map();
9
- let warned = false;
10
- const isProduction = () => {
11
- try {
12
- return process.env["NODE_ENV"] === "production";
13
- } catch {
14
- return false;
15
- }
16
- };
17
- const toAbsolute = (p, cwd) => path.isAbsolute(p) ? p : path.join(cwd, p);
18
- const candidatePathsFrom = (entry, cwd) => {
19
- const abs = toAbsolute(entry, cwd);
20
- if (abs.endsWith(".json")) return [abs];
21
- return [path.join(abs, CACHE_FILENAME), path.join(abs, "cache", CACHE_FILENAME), path.join(abs, "saltygen", "cache", CACHE_FILENAME)];
22
- };
23
- const tryRead = async (path2) => {
24
- const useMemo = isProduction();
25
- if (useMemo && memo.has(path2)) return memo.get(path2) ?? void 0;
26
- try {
27
- const contents = await promises.readFile(path2, "utf8");
28
- if (!contents) {
29
- if (useMemo) memo.set(path2, null);
30
- return void 0;
31
- }
32
- const parsed = JSON.parse(contents);
33
- if (useMemo) memo.set(path2, parsed);
34
- return parsed;
35
- } catch {
36
- if (useMemo) memo.set(path2, null);
37
- return void 0;
38
- }
39
- };
40
- const resolveDynamicConfigCache = async (options = {}) => {
41
- var _a;
42
- const cwd = options.cwd ?? process.cwd();
43
- const envPath = typeof process !== "undefined" ? (_a = process.env) == null ? void 0 : _a[ENV_VAR] : void 0;
44
- const ordered = [];
45
- if (options.primaryPath) ordered.push(...candidatePathsFrom(options.primaryPath, cwd));
46
- if (envPath) ordered.push(...candidatePathsFrom(envPath, cwd));
47
- if (options.extraPaths) for (const p of options.extraPaths) ordered.push(...candidatePathsFrom(p, cwd));
48
- for (const root of defaultRoots) ordered.push(...candidatePathsFrom(root, cwd));
49
- for (const candidate of ordered) {
50
- const result = await tryRead(candidate);
51
- if (result) return result;
52
- }
53
- if (!warned) {
54
- warned = true;
55
- console.warn(`Could not find config cache file (${CACHE_FILENAME}) in any of the expected locations.`);
56
- }
57
- return {};
58
- };
59
- const _resetDynamicConfigCacheMemo = () => {
60
- memo.clear();
61
- warned = false;
62
- };
63
- exports._resetDynamicConfigCacheMemo = _resetDynamicConfigCacheMemo;
64
- exports.resolveDynamicConfigCache = resolveDynamicConfigCache;
@@ -1,20 +0,0 @@
1
- export interface ResolveDynamicConfigCacheOptions {
2
- /**
3
- * Highest-priority path checked first. If it resolves, no other paths are tried.
4
- * Absolute, or relative to `cwd`.
5
- */
6
- primaryPath?: string;
7
- /**
8
- * Extra paths checked before the built-in defaults. Absolute, or relative to `cwd`.
9
- */
10
- extraPaths?: string[];
11
- /**
12
- * Base directory for resolving relative paths. Defaults to `process.cwd()`.
13
- */
14
- cwd?: string;
15
- }
16
- export declare const resolveDynamicConfigCache: (options?: ResolveDynamicConfigCacheOptions) => Promise<Record<string, unknown>>;
17
- /**
18
- * Clear the in-memory cache of parsed config-cache.json files. Test-only.
19
- */
20
- export declare const _resetDynamicConfigCacheMemo: () => void;
@@ -1,64 +0,0 @@
1
- import { readFile } from "fs/promises";
2
- import { join, isAbsolute } from "path";
3
- const CACHE_FILENAME = "config-cache.json";
4
- const ENV_VAR = "SALTY_CONFIG_CACHE_PATH";
5
- const defaultRoots = ["", "src", "dist", "build", "public", ".next", ".next/server", ".vercel/output/functions"];
6
- const memo = /* @__PURE__ */ new Map();
7
- let warned = false;
8
- const isProduction = () => {
9
- try {
10
- return process.env["NODE_ENV"] === "production";
11
- } catch {
12
- return false;
13
- }
14
- };
15
- const toAbsolute = (p, cwd) => isAbsolute(p) ? p : join(cwd, p);
16
- const candidatePathsFrom = (entry, cwd) => {
17
- const abs = toAbsolute(entry, cwd);
18
- if (abs.endsWith(".json")) return [abs];
19
- return [join(abs, CACHE_FILENAME), join(abs, "cache", CACHE_FILENAME), join(abs, "saltygen", "cache", CACHE_FILENAME)];
20
- };
21
- const tryRead = async (path) => {
22
- const useMemo = isProduction();
23
- if (useMemo && memo.has(path)) return memo.get(path) ?? void 0;
24
- try {
25
- const contents = await readFile(path, "utf8");
26
- if (!contents) {
27
- if (useMemo) memo.set(path, null);
28
- return void 0;
29
- }
30
- const parsed = JSON.parse(contents);
31
- if (useMemo) memo.set(path, parsed);
32
- return parsed;
33
- } catch {
34
- if (useMemo) memo.set(path, null);
35
- return void 0;
36
- }
37
- };
38
- const resolveDynamicConfigCache = async (options = {}) => {
39
- var _a;
40
- const cwd = options.cwd ?? process.cwd();
41
- const envPath = typeof process !== "undefined" ? (_a = process.env) == null ? void 0 : _a[ENV_VAR] : void 0;
42
- const ordered = [];
43
- if (options.primaryPath) ordered.push(...candidatePathsFrom(options.primaryPath, cwd));
44
- if (envPath) ordered.push(...candidatePathsFrom(envPath, cwd));
45
- if (options.extraPaths) for (const p of options.extraPaths) ordered.push(...candidatePathsFrom(p, cwd));
46
- for (const root of defaultRoots) ordered.push(...candidatePathsFrom(root, cwd));
47
- for (const candidate of ordered) {
48
- const result = await tryRead(candidate);
49
- if (result) return result;
50
- }
51
- if (!warned) {
52
- warned = true;
53
- console.warn(`Could not find config cache file (${CACHE_FILENAME}) in any of the expected locations.`);
54
- }
55
- return {};
56
- };
57
- const _resetDynamicConfigCacheMemo = () => {
58
- memo.clear();
59
- warned = false;
60
- };
61
- export {
62
- _resetDynamicConfigCacheMemo,
63
- resolveDynamicConfigCache
64
- };
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const promises = require("fs/promises");
4
- const path = require("path");
5
- const logger = require("../logger-7xz0pyAz.cjs");
6
- const DEFAULT_SUBPATH = path.join("saltygen", "cache", "config-cache.json");
7
- const resolveCopyConfigCacheDestinations = (option, defaultOutDir, cwd = process.cwd()) => {
8
- if (option === false) return [];
9
- const userPaths = [];
10
- if (typeof option === "string") userPaths.push(option);
11
- else if (Array.isArray(option)) userPaths.push(...option);
12
- const destinations = [];
13
- const useDefault = option === void 0 || option === true;
14
- if (useDefault && defaultOutDir) destinations.push(defaultOutDir);
15
- destinations.push(...userPaths);
16
- return destinations.map((entry) => {
17
- const abs = path.isAbsolute(entry) ? entry : path.resolve(cwd, entry);
18
- if (abs.endsWith(".json")) return abs;
19
- return path.join(abs, DEFAULT_SUBPATH);
20
- });
21
- };
22
- const copyConfigCacheTo = async (compiler, destinations) => {
23
- if (destinations.length === 0) return;
24
- const source = await compiler.getConfigCachePath();
25
- await Promise.all(
26
- destinations.map(async (destination) => {
27
- if (destination === source) return;
28
- try {
29
- await promises.mkdir(path.dirname(destination), { recursive: true });
30
- await promises.copyFile(source, destination);
31
- logger.logger.info(`Copied Salty config cache → ${destination}`);
32
- } catch (error) {
33
- logger.logger.warn(`Failed to copy Salty config cache to ${destination}: ${error.message}`);
34
- }
35
- })
36
- );
37
- };
38
- exports.copyConfigCacheTo = copyConfigCacheTo;
39
- exports.resolveCopyConfigCacheDestinations = resolveCopyConfigCacheDestinations;
@@ -1,17 +0,0 @@
1
- import { SaltyCompiler } from './salty-compiler';
2
- /**
3
- * `copyConfigCache` plugin option:
4
- * - `true` → copy to the bundler's resolved output dir (default).
5
- * - `false` → no-op.
6
- * - `string | string[]` → copy to the default destination PLUS each listed path.
7
- *
8
- * Each path can be a directory (the file is written as `saltygen/cache/config-cache.json` inside)
9
- * or a path ending in `.json` (used verbatim).
10
- */
11
- export type CopyConfigCacheOption = boolean | string | string[];
12
- export declare const resolveCopyConfigCacheDestinations: (option: CopyConfigCacheOption | undefined, defaultOutDir: string | undefined, cwd?: string) => string[];
13
- /**
14
- * Copy the compiler's `config-cache.json` to each absolute destination path.
15
- * Creates parent directories as needed; silently skips destinations equal to the source.
16
- */
17
- export declare const copyConfigCacheTo: (compiler: SaltyCompiler, destinations: string[]) => Promise<void>;