@bamboocss/config 1.11.4 → 1.12.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.
package/dist/index.cjs CHANGED
@@ -1,18 +1,39 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_diff_config = require("./diff-config-Co_3mDXE.cjs");
3
- const require_resolve_ts_path_pattern = require("./resolve-ts-path-pattern.cjs");
4
- const require_merge_config = require("./merge-config-CcNpHJit.cjs");
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+ //#endregion
5
24
  let _bamboocss_logger = require("@bamboocss/logger");
6
25
  let _bamboocss_shared = require("@bamboocss/shared");
7
26
  let bundle_n_require = require("bundle-n-require");
8
27
  let escalade_sync = require("escalade/sync");
9
- escalade_sync = require_diff_config.__toESM(escalade_sync);
28
+ escalade_sync = __toESM(escalade_sync);
10
29
  let path = require("path");
11
- path = require_diff_config.__toESM(path);
30
+ path = __toESM(path);
31
+ let microdiff = require("microdiff");
32
+ microdiff = __toESM(microdiff);
12
33
  let fs = require("fs");
13
- fs = require_diff_config.__toESM(fs);
34
+ fs = __toESM(fs);
14
35
  let typescript = require("typescript");
15
- typescript = require_diff_config.__toESM(typescript);
36
+ typescript = __toESM(typescript);
16
37
  let _bamboocss_preset_base = require("@bamboocss/preset-base");
17
38
  let _bamboocss_preset_bamboo = require("@bamboocss/preset-bamboo");
18
39
  //#region src/is-bamboo-config.ts
@@ -65,6 +86,183 @@ async function bundleConfig(options) {
65
86
  };
66
87
  }
67
88
  //#endregion
89
+ //#region src/create-matcher.ts
90
+ /**
91
+ * Acts like a .gitignore matcher
92
+ * e.g a list of string to search for nested path with glob and exclusion allowed
93
+ * ["outdir", "theme.recipes", '*.css', '!aaa.*.bbb']
94
+ */
95
+ function createMatcher(id, patterns) {
96
+ if (!patterns?.length) return () => void 0;
97
+ const includePatterns = [];
98
+ const excludePatterns = [];
99
+ new Set(patterns).forEach((pattern) => {
100
+ const regexString = pattern.replace(/\*/g, ".*");
101
+ if (pattern.startsWith("!")) excludePatterns.push(regexString.slice(1));
102
+ else includePatterns.push(regexString);
103
+ });
104
+ const include = new RegExp(includePatterns.join("|"));
105
+ const exclude = new RegExp(excludePatterns.join("|"));
106
+ return (path) => {
107
+ if (excludePatterns.length && exclude.test(path)) return;
108
+ return include.test(path) ? id : void 0;
109
+ };
110
+ }
111
+ //#endregion
112
+ //#region src/config-deps.ts
113
+ const all = [
114
+ "clean",
115
+ "cwd",
116
+ "eject",
117
+ "outdir",
118
+ "forceConsistentTypeExtension",
119
+ "outExtension",
120
+ "emitTokensOnly",
121
+ "presets",
122
+ "plugins",
123
+ "hooks"
124
+ ];
125
+ const format = [
126
+ "syntax",
127
+ "hash",
128
+ "prefix",
129
+ "separator",
130
+ "strictTokens",
131
+ "strictPropertyValues",
132
+ "shorthands"
133
+ ];
134
+ const tokens = [
135
+ "utilities",
136
+ "conditions",
137
+ "theme.tokens",
138
+ "theme.semanticTokens",
139
+ "theme.breakpoints",
140
+ "theme.containerNames",
141
+ "theme.containerSizes"
142
+ ];
143
+ const jsx = [
144
+ "jsxFramework",
145
+ "jsxFactory",
146
+ "jsxStyleProps",
147
+ "syntax"
148
+ ];
149
+ const common = tokens.concat(jsx, format);
150
+ const artifactConfigDeps = {
151
+ helpers: ["syntax", "jsxFramework"],
152
+ keyframes: ["theme.keyframes", "layers"],
153
+ "design-tokens": ["layers", "!utilities.*.className"].concat(tokens),
154
+ types: ["!utilities.*.className"].concat(common),
155
+ "css-fn": common,
156
+ cva: ["syntax"],
157
+ sva: ["syntax"],
158
+ cx: [],
159
+ "create-recipe": [
160
+ "separator",
161
+ "prefix",
162
+ "hash"
163
+ ],
164
+ "recipes-index": ["theme.recipes", "theme.slotRecipes"],
165
+ recipes: ["theme.recipes", "theme.slotRecipes"],
166
+ "patterns-index": ["syntax", "patterns"],
167
+ patterns: ["syntax", "patterns"],
168
+ "jsx-is-valid-prop": common,
169
+ "jsx-factory": jsx,
170
+ "jsx-helpers": jsx,
171
+ "jsx-patterns": jsx.concat("patterns"),
172
+ "jsx-patterns-index": jsx.concat("patterns"),
173
+ "jsx-create-style-context": jsx,
174
+ "css-index": ["syntax"],
175
+ "package.json": ["forceConsistentTypeExtension", "outExtension"],
176
+ "types-styles": ["shorthands"],
177
+ "types-conditions": ["conditions"],
178
+ "types-jsx": jsx,
179
+ "types-entry": [],
180
+ "types-gen": [],
181
+ "types-gen-system": [],
182
+ themes: ["themes"].concat(tokens),
183
+ "static-css": [
184
+ "staticCss",
185
+ "patterns",
186
+ "theme.recipes",
187
+ "theme.slotRecipes"
188
+ ].concat(tokens),
189
+ styles: [],
190
+ "styles.css": []
191
+ };
192
+ const artifactMatchers = Object.entries(artifactConfigDeps).map(([key, paths]) => {
193
+ if (!paths.length) return () => void 0;
194
+ return createMatcher(key, paths.concat(all));
195
+ });
196
+ //#endregion
197
+ //#region src/diff-config.ts
198
+ const runIfFn = (fn) => typeof fn === "function" ? fn() : fn;
199
+ /**
200
+ * Check if recipes were empty before and non-empty now (or vice versa)
201
+ */
202
+ const hasRecipeStateTransition = (prevConfig, nextConfig) => {
203
+ const prevRecipes = prevConfig.theme?.recipes ?? {};
204
+ const prevSlotRecipes = prevConfig.theme?.slotRecipes ?? {};
205
+ const prevHasRecipes = Object.keys(prevRecipes).length > 0 || Object.keys(prevSlotRecipes).length > 0;
206
+ const nextRecipes = nextConfig.theme?.recipes ?? {};
207
+ const nextSlotRecipes = nextConfig.theme?.slotRecipes ?? {};
208
+ return prevHasRecipes !== (Object.keys(nextRecipes).length > 0 || Object.keys(nextSlotRecipes).length > 0);
209
+ };
210
+ /**
211
+ * Diff the two config objects and return the list of affected properties
212
+ */
213
+ function diffConfigs(config, prevConfig) {
214
+ const affected = {
215
+ artifacts: /* @__PURE__ */ new Set(),
216
+ hasConfigChanged: false,
217
+ diffs: []
218
+ };
219
+ if (!prevConfig) {
220
+ affected.hasConfigChanged = true;
221
+ return affected;
222
+ }
223
+ const configDiff = (0, microdiff.default)(prevConfig, runIfFn(config));
224
+ if (!configDiff.length) return affected;
225
+ affected.hasConfigChanged = true;
226
+ affected.diffs = configDiff;
227
+ configDiff.forEach((change) => {
228
+ const changePath = change.path.join(".");
229
+ artifactMatchers.forEach((matcher) => {
230
+ const id = matcher(changePath);
231
+ if (!id) return;
232
+ if (id === "recipes") {
233
+ const name = (0, _bamboocss_shared.dashCase)(change.path.slice(1, 3).join("."));
234
+ affected.artifacts.add(name);
235
+ }
236
+ if (id === "patterns") {
237
+ const name = (0, _bamboocss_shared.dashCase)(change.path.slice(0, 2).join("."));
238
+ affected.artifacts.add(name);
239
+ }
240
+ affected.artifacts.add(id);
241
+ });
242
+ });
243
+ if (affected.artifacts.has("recipes") || affected.artifacts.has("recipes-index")) {
244
+ if (hasRecipeStateTransition(prevConfig, runIfFn(config))) affected.artifacts.add("create-recipe");
245
+ }
246
+ return affected;
247
+ }
248
+ //#endregion
249
+ //#region src/resolve-ts-path-pattern.ts
250
+ /**
251
+ * @see https://github.com/aleclarson/vite-tsconfig-paths/blob/e8f0acf7adfcfbf77edbe937f64b4e5d39557ad0/src/index.ts#LL231C57-L231C57
252
+ */
253
+ const resolveTsPathPattern = (pathMappings, moduleSpecifier) => {
254
+ for (const mapping of pathMappings) {
255
+ const match = moduleSpecifier.match(mapping.pattern);
256
+ if (!match) continue;
257
+ for (const pathTemplate of mapping.paths) {
258
+ let starCount = 0;
259
+ return pathTemplate.replace(/\*/g, () => {
260
+ return match[Math.min(++starCount, match.length - 1)];
261
+ }).split(path.sep).join(path.posix.sep);
262
+ }
263
+ }
264
+ };
265
+ //#endregion
68
266
  //#region src/ts-config-paths.ts
69
267
  /**
70
268
  * @see https://github.com/aleclarson/vite-tsconfig-paths/blob/e8f0acf7adfcfbf77edbe937f64b4e5d39557ad0/src/mappings.ts
@@ -170,7 +368,7 @@ function getDeps(opts, fromAlias) {
170
368
  return;
171
369
  }
172
370
  if (!opts.pathMappings) return;
173
- const filename = require_resolve_ts_path_pattern.resolveTsPathPattern(opts.pathMappings, mod);
371
+ const filename = resolveTsPathPattern(opts.pathMappings, mod);
174
372
  if (!filename) return;
175
373
  getDeps(Object.assign({}, nextOpts, { filename }), mod);
176
374
  } catch {}
@@ -200,6 +398,273 @@ function getConfigDependencies(filePath, tsOptions = { pathMappings: [] }, compi
200
398
  };
201
399
  }
202
400
  //#endregion
401
+ //#region src/merge-hooks.ts
402
+ const mergeHooks = (plugins) => {
403
+ const hooksFns = {};
404
+ plugins.forEach(({ name, hooks }) => {
405
+ Object.entries(hooks ?? {}).forEach(([key, value]) => {
406
+ if (!hooksFns[key]) hooksFns[key] = [];
407
+ hooksFns[key].push([name, value]);
408
+ });
409
+ });
410
+ return Object.fromEntries(Object.entries(hooksFns).map(([key, entries]) => {
411
+ const fns = entries.map(([name, fn]) => tryCatch(name, fn));
412
+ const reducer = key in reducers ? reducers[key] : void 0;
413
+ if (reducer) return [key, reducer(fns)];
414
+ return [key, syncHooks.includes(key) ? callAll(...fns) : callAllAsync(...fns)];
415
+ }));
416
+ };
417
+ const createReducer = (reducer) => reducer;
418
+ const reducers = {
419
+ "config:resolved": createReducer((fns) => async (_args) => {
420
+ const args = Object.assign({}, _args);
421
+ const original = _args.config;
422
+ let config = args.config;
423
+ for (const hookFn of fns) {
424
+ const result = await hookFn(Object.assign(args, {
425
+ config,
426
+ original
427
+ }));
428
+ if (result !== void 0) config = result;
429
+ }
430
+ return config;
431
+ }),
432
+ "parser:before": createReducer((fns) => (_args) => {
433
+ const args = Object.assign({}, _args);
434
+ const original = _args.content;
435
+ let content = args.content;
436
+ for (const hookFn of fns) {
437
+ const result = hookFn(Object.assign(args, {
438
+ content,
439
+ original
440
+ }));
441
+ if (result !== void 0) content = result;
442
+ }
443
+ return content;
444
+ }),
445
+ "parser:preprocess": createReducer((fns) => (_args) => {
446
+ const args = Object.assign({}, _args);
447
+ const original = _args.data;
448
+ let data = args.data;
449
+ for (const hookFn of fns) {
450
+ const result = hookFn(Object.assign(args, {
451
+ data,
452
+ original
453
+ }));
454
+ if (result !== void 0) data = result;
455
+ }
456
+ return data;
457
+ }),
458
+ "cssgen:done": createReducer((fns) => (_args) => {
459
+ const args = Object.assign({}, _args);
460
+ const original = _args.content;
461
+ let content = args.content;
462
+ for (const hookFn of fns) {
463
+ const result = hookFn(Object.assign(args, {
464
+ content,
465
+ original
466
+ }));
467
+ if (result !== void 0) content = result;
468
+ }
469
+ return content;
470
+ }),
471
+ "codegen:prepare": createReducer((fns) => async (_args) => {
472
+ const args = Object.assign({}, _args);
473
+ const original = _args.artifacts;
474
+ let artifacts = args.artifacts;
475
+ for (const hookFn of fns) {
476
+ const result = await hookFn(Object.assign(args, {
477
+ artifacts,
478
+ original
479
+ }));
480
+ if (result) artifacts = result;
481
+ }
482
+ return artifacts;
483
+ }),
484
+ "preset:resolved": createReducer((fns) => async (_args) => {
485
+ const args = Object.assign({}, _args);
486
+ const original = _args.preset;
487
+ let preset = args.preset;
488
+ for (const hookFn of fns) {
489
+ const result = await hookFn(Object.assign(args, {
490
+ preset,
491
+ original
492
+ }));
493
+ if (result !== void 0) preset = result;
494
+ }
495
+ return preset;
496
+ }),
497
+ "css:optimize": createReducer((fns) => (_args) => {
498
+ const args = Object.assign({}, _args);
499
+ const original = _args.css;
500
+ let css = args.css;
501
+ for (const hookFn of fns) {
502
+ const result = hookFn(Object.assign(args, {
503
+ css,
504
+ original
505
+ }));
506
+ if (result !== void 0) css = result;
507
+ }
508
+ return css;
509
+ })
510
+ };
511
+ const syncHooks = [
512
+ "context:created",
513
+ "parser:before",
514
+ "parser:preprocess",
515
+ "parser:after",
516
+ "cssgen:done",
517
+ "css:optimize"
518
+ ];
519
+ const callAllAsync = (...fns) => async (...a) => {
520
+ for (const fn of fns) await fn?.(...a);
521
+ };
522
+ const callAll = (...fns) => (...a) => {
523
+ fns.forEach((fn) => fn?.(...a));
524
+ };
525
+ const tryCatch = (name, fn) => {
526
+ return (...args) => {
527
+ try {
528
+ return fn(...args);
529
+ } catch (e) {
530
+ _bamboocss_logger.logger.caughtError("hooks", `Error in plugin "${name}"`, e);
531
+ }
532
+ };
533
+ };
534
+ //#endregion
535
+ //#region src/validation/utils.ts
536
+ const REFERENCE_REGEX = /({([^}]*)})/g;
537
+ const curlyBracketRegex = /[{}]/g;
538
+ const isValidToken = (token) => (0, _bamboocss_shared.isObject)(token) && Object.hasOwnProperty.call(token, "value");
539
+ const isTokenReference = (value) => typeof value === "string" && REFERENCE_REGEX.test(value);
540
+ const formatPath = (path) => path;
541
+ function getReferences(value) {
542
+ if (typeof value !== "string") return [];
543
+ const matches = value.match(REFERENCE_REGEX);
544
+ if (!matches) return [];
545
+ return matches.map((match) => match.replace(curlyBracketRegex, "")).map((value) => {
546
+ return value.trim().split("/")[0];
547
+ });
548
+ }
549
+ const serializeTokenValue = (value) => {
550
+ if ((0, _bamboocss_shared.isString)(value)) return value;
551
+ if ((0, _bamboocss_shared.isObject)(value)) return Object.values(value).map((v) => serializeTokenValue(v)).join(" ");
552
+ if (Array.isArray(value)) return value.map((v) => serializeTokenValue(v)).join(" ");
553
+ return value.toString();
554
+ };
555
+ //#endregion
556
+ //#region src/merge-config.ts
557
+ /**
558
+ * Collect all `extend` properties into an array (to avoid mutation)
559
+ */
560
+ function getExtends(items) {
561
+ return items.reduce((merged, { extend }) => {
562
+ if (!extend) return merged;
563
+ return (0, _bamboocss_shared.mergeWith)(merged, extend, (originalValue, newValue) => {
564
+ if (newValue === void 0) return originalValue ?? [];
565
+ if (originalValue === void 0) return [newValue];
566
+ if (Array.isArray(originalValue)) return [newValue, ...originalValue];
567
+ return [newValue, originalValue];
568
+ });
569
+ }, {});
570
+ }
571
+ /**
572
+ * Separate the `extend` properties from the rest of the object
573
+ */
574
+ function mergeRecords(records) {
575
+ return {
576
+ ...records.reduce((acc, record) => (0, _bamboocss_shared.assign)(acc, record), {}),
577
+ extend: getExtends(records)
578
+ };
579
+ }
580
+ /**
581
+ * Merge all `extend` properties into the rest of the object
582
+ */
583
+ function mergeExtensions(records) {
584
+ const { extend = [], ...restProps } = mergeRecords(records);
585
+ return (0, _bamboocss_shared.mergeWith)(restProps, extend, (obj, extensions) => {
586
+ return (0, _bamboocss_shared.mergeAndConcat)({}, obj, ...extensions);
587
+ });
588
+ }
589
+ const isEmptyObject = (obj) => typeof obj === "object" && Object.keys(obj).length === 0;
590
+ const compact = (obj) => {
591
+ return Object.keys(obj).reduce((acc, key) => {
592
+ if (obj[key] !== void 0 && !isEmptyObject(obj[key])) acc[key] = obj[key];
593
+ return acc;
594
+ }, {});
595
+ };
596
+ const tokenKeys = [
597
+ "description",
598
+ "extensions",
599
+ "type",
600
+ "value",
601
+ "deprecated"
602
+ ];
603
+ /**
604
+ * Merge all configs into a single config
605
+ */
606
+ function mergeConfigs(configs) {
607
+ const userConfig = configs.at(-1);
608
+ const pluginHooks = userConfig.plugins ?? [];
609
+ if (userConfig.hooks) pluginHooks.push({
610
+ name: _bamboocss_shared.BAMBOO_CONFIG_NAME,
611
+ hooks: userConfig.hooks
612
+ });
613
+ const reversed = Array.from(configs).reverse();
614
+ const withoutEmpty = compact((0, _bamboocss_shared.assign)({
615
+ conditions: mergeExtensions(reversed.map((config) => config.conditions ?? {})),
616
+ theme: mergeExtensions(reversed.map((config) => config.theme ?? {})),
617
+ patterns: mergeExtensions(reversed.map((config) => config.patterns ?? {})),
618
+ utilities: mergeExtensions(reversed.map((config) => config.utilities ?? {})),
619
+ globalCss: mergeExtensions(reversed.map((config) => config.globalCss ?? {})),
620
+ globalVars: mergeExtensions(reversed.map((config) => config.globalVars ?? {})),
621
+ globalFontface: mergeExtensions(reversed.map((config) => config.globalFontface ?? {})),
622
+ globalPositionTry: mergeExtensions(reversed.map((config) => config.globalPositionTry ?? {})),
623
+ staticCss: mergeExtensions(reversed.map((config) => config.staticCss ?? {})),
624
+ themes: mergeExtensions(reversed.map((config) => config.themes ?? {})),
625
+ hooks: mergeHooks(pluginHooks)
626
+ }, ...reversed));
627
+ /**
628
+ * Properly merge tokens between flat/nested forms by setting the flat form as the default
629
+ * preset:
630
+ * ```
631
+ * tokens: {
632
+ * black: {
633
+ * value: "black"
634
+ * }
635
+ * }
636
+ * // color: "black"
637
+ * ```
638
+ *
639
+ * config:
640
+ * ```
641
+ * tokens: {
642
+ * black: {
643
+ * 0: { value: "black" },
644
+ * 10: { value: "black/10" },
645
+ * 20: { value: "black/20" },
646
+ * // ...
647
+ * }
648
+ * }
649
+ *
650
+ * // color: "black.20"
651
+ * ```
652
+ */
653
+ if (withoutEmpty.theme?.tokens) (0, _bamboocss_shared.walkObject)(withoutEmpty.theme.tokens, (args) => args, { stop(token) {
654
+ if (!isValidToken(token)) return false;
655
+ if (Object.keys(token).filter((k) => !tokenKeys.includes(k)).length > 0) {
656
+ token.DEFAULT ||= {};
657
+ tokenKeys.forEach((key) => {
658
+ if (token[key] == null) return;
659
+ token.DEFAULT[key] ||= token[key];
660
+ delete token[key];
661
+ });
662
+ }
663
+ return true;
664
+ } });
665
+ return withoutEmpty;
666
+ }
667
+ //#endregion
203
668
  //#region src/get-resolved-config.ts
204
669
  const hookUtils$1 = {
205
670
  omit: _bamboocss_shared.omit,
@@ -237,7 +702,7 @@ async function getResolvedConfig(config, cwd, hooks) {
237
702
  }
238
703
  configs.unshift(current);
239
704
  }
240
- const merged = require_merge_config.mergeConfigs(configs);
705
+ const merged = mergeConfigs(configs);
241
706
  merged.presets = configs.slice(0, -1);
242
707
  return merged;
243
708
  }
@@ -352,7 +817,7 @@ const validateTokenReferences = (props) => {
352
817
  const configKey = typeByPath.get(path);
353
818
  addError("tokens", `Missing token: \`${currentPath}\` used in \`theme.${configKey}.${path}\``);
354
819
  }
355
- if (require_merge_config.isTokenReference(value) && !refsByPath.has(value)) addError("tokens", `Unknown token reference: \`${currentPath}\` used in \`${value}\``);
820
+ if (isTokenReference(value) && !refsByPath.has(value)) addError("tokens", `Unknown token reference: \`${currentPath}\` used in \`${value}\``);
356
821
  const deps = refsByPath.get(currentPath);
357
822
  if (!deps) continue;
358
823
  for (const transitiveDep of deps) {
@@ -379,12 +844,12 @@ const validateTokens = (options) => {
379
844
  tokenPaths.add(path);
380
845
  valueAtPath.set(path, value);
381
846
  if (path.includes("DEFAULT")) valueAtPath.set(path.replace(".DEFAULT", ""), value);
382
- }, { stop: require_merge_config.isValidToken });
847
+ }, { stop: isValidToken });
383
848
  tokenPaths.forEach((path) => {
384
849
  const itemValue = valueAtPath.get(path);
385
- const formattedPath = require_merge_config.formatPath(path);
850
+ const formattedPath = formatPath(path);
386
851
  typeByPath.set(formattedPath, "tokens");
387
- if (!require_merge_config.isValidToken(itemValue)) {
852
+ if (!isValidToken(itemValue)) {
388
853
  addError("tokens", `Token must contain 'value': \`theme.tokens.${formattedPath}\``);
389
854
  return;
390
855
  }
@@ -392,11 +857,11 @@ const validateTokens = (options) => {
392
857
  addError("tokens", `Token key must not contain spaces: \`theme.tokens.${formattedPath}\``);
393
858
  return;
394
859
  }
395
- const valueStr = require_merge_config.serializeTokenValue(itemValue.value || itemValue);
396
- if (require_merge_config.isTokenReference(valueStr)) refsByPath.set(formattedPath, /* @__PURE__ */ new Set([]));
860
+ const valueStr = serializeTokenValue(itemValue.value || itemValue);
861
+ if (isTokenReference(valueStr)) refsByPath.set(formattedPath, /* @__PURE__ */ new Set([]));
397
862
  const references = refsByPath.get(formattedPath);
398
863
  if (!references) return;
399
- require_merge_config.getReferences(valueStr).forEach((reference) => {
864
+ getReferences(valueStr).forEach((reference) => {
400
865
  references.add(reference);
401
866
  });
402
867
  });
@@ -409,26 +874,26 @@ const validateTokens = (options) => {
409
874
  valueAtPath.set(path, value);
410
875
  tokenPaths.add(path);
411
876
  if (path.includes("DEFAULT")) valueAtPath.set(path.replace(".DEFAULT", ""), value);
412
- if (!require_merge_config.isValidToken(value)) return;
877
+ if (!isValidToken(value)) return;
413
878
  (0, _bamboocss_shared.walkObject)(value, (itemValue, paths) => {
414
879
  const valuePath = paths.join(".");
415
- const formattedPath = require_merge_config.formatPath(path);
880
+ const formattedPath = formatPath(path);
416
881
  typeByPath.set(formattedPath, "semanticTokens");
417
882
  const fullPath = formattedPath + "." + paths.join(".");
418
883
  if (valuePath.includes("value.value")) addError("tokens", `You used \`value\` twice resulting in an invalid token \`theme.tokens.${fullPath}\``);
419
- const valueStr = require_merge_config.serializeTokenValue(itemValue.value || itemValue);
420
- if (require_merge_config.isTokenReference(valueStr)) {
884
+ const valueStr = serializeTokenValue(itemValue.value || itemValue);
885
+ if (isTokenReference(valueStr)) {
421
886
  if (!refsByPath.has(formattedPath)) refsByPath.set(formattedPath, /* @__PURE__ */ new Set());
422
887
  const references = refsByPath.get(formattedPath);
423
888
  if (!references) return;
424
- require_merge_config.getReferences(valueStr).forEach((reference) => {
889
+ getReferences(valueStr).forEach((reference) => {
425
890
  references.add(reference);
426
891
  });
427
892
  }
428
893
  });
429
- }, { stop: require_merge_config.isValidToken });
894
+ }, { stop: isValidToken });
430
895
  tokenPaths.forEach((path) => {
431
- const formattedPath = require_merge_config.formatPath(path);
896
+ const formattedPath = formatPath(path);
432
897
  const value = valueAtPath.get(path);
433
898
  if (path.includes(" ")) {
434
899
  addError("tokens", `Token key must not contain spaces: \`theme.tokens.${formattedPath}\``);
@@ -524,7 +989,7 @@ async function resolveConfig(result, cwd) {
524
989
  name: _bamboocss_shared.BAMBOO_CONFIG_NAME,
525
990
  hooks: userConfig.hooks
526
991
  });
527
- const earlyHooks = require_merge_config.mergeHooks(pluginHooks);
992
+ const earlyHooks = mergeHooks(pluginHooks);
528
993
  const mergedConfig = await getResolvedConfig(result.config, cwd, earlyHooks);
529
994
  const hooks = mergedConfig.hooks ?? {};
530
995
  if (mergedConfig.logLevel) _bamboocss_logger.logger.level = mergedConfig.logLevel;
@@ -565,11 +1030,11 @@ async function loadConfig(options) {
565
1030
  //#endregion
566
1031
  exports.bundleConfig = bundleConfig;
567
1032
  exports.convertTsPathsToRegexes = convertTsPathsToRegexes;
568
- exports.diffConfigs = require_diff_config.diffConfigs;
1033
+ exports.diffConfigs = diffConfigs;
569
1034
  exports.findConfig = findConfig;
570
1035
  exports.getConfigDependencies = getConfigDependencies;
571
1036
  exports.getResolvedConfig = getResolvedConfig;
572
1037
  exports.loadConfig = loadConfig;
573
- exports.mergeConfigs = require_merge_config.mergeConfigs;
574
- exports.mergeHooks = require_merge_config.mergeHooks;
1038
+ exports.mergeConfigs = mergeConfigs;
1039
+ exports.mergeHooks = mergeHooks;
575
1040
  exports.resolveConfig = resolveConfig;
package/dist/index.d.cts CHANGED
@@ -1,7 +1,4 @@
1
- import { diffConfigs } from "./diff-config.cjs";
2
- import { n as convertTsPathsToRegexes, t as PathMapping } from "./ts-config-paths-wVx39QZ0.cjs";
3
- import { n as mergeHooks, t as mergeConfigs } from "./merge-config-DVOlBQJY.cjs";
4
- import { BambooHooks, Config, ConfigTsOptions, LoadConfigResult as LoadConfigResult$1 } from "@bamboocss/types";
1
+ import { BambooHooks as BambooHooks$1, BambooPlugin, Config, ConfigTsOptions, DiffConfigResult, LoadConfigResult as LoadConfigResult$1 } from "@bamboocss/types";
5
2
  import { CompilerOptions, TypeAcquisition } from "typescript";
6
3
 
7
4
  //#region src/types.d.ts
@@ -18,6 +15,13 @@ interface BundleConfigResult<T = Config> {
18
15
  //#region src/bundle-config.d.ts
19
16
  declare function bundleConfig(options: ConfigFileOptions): Promise<BundleConfigResult>;
20
17
  //#endregion
18
+ //#region src/diff-config.d.ts
19
+ type ConfigOrFn = Config | (() => Config);
20
+ /**
21
+ * Diff the two config objects and return the list of affected properties
22
+ */
23
+ declare function diffConfigs(config: ConfigOrFn, prevConfig: Config | undefined): DiffConfigResult;
24
+ //#endregion
21
25
  //#region src/find-config.d.ts
22
26
  declare function findConfig(options: Partial<ConfigFileOptions>): string;
23
27
  //#endregion
@@ -41,6 +45,16 @@ interface TSConfig {
41
45
  * @returns the same `tsconfig.json` object.
42
46
  */
43
47
  //#endregion
48
+ //#region src/ts-config-paths.d.ts
49
+ interface PathMapping {
50
+ pattern: RegExp;
51
+ paths: string[];
52
+ }
53
+ /**
54
+ * @see https://github.com/aleclarson/vite-tsconfig-paths/blob/e8f0acf7adfcfbf77edbe937f64b4e5d39557ad0/src/mappings.ts
55
+ */
56
+ declare function convertTsPathsToRegexes(paths: Record<string, string[]>, baseUrl: string): PathMapping[];
57
+ //#endregion
44
58
  //#region src/get-mod-deps.d.ts
45
59
  interface GetDepsOptions {
46
60
  filename: string;
@@ -58,14 +72,14 @@ declare function getConfigDependencies(filePath: string, tsOptions?: ConfigTsOpt
58
72
  };
59
73
  //#endregion
60
74
  //#region src/get-resolved-config.d.ts
61
- type Extendable<T> = T & {
75
+ type Extendable$1<T> = T & {
62
76
  extend?: T;
63
77
  };
64
- type ExtendableConfig = Extendable<Config>;
78
+ type ExtendableConfig$1 = Extendable$1<Config>;
65
79
  /**
66
80
  * Recursively merge all presets into a single config (depth-first using stack)
67
81
  */
68
- declare function getResolvedConfig(config: ExtendableConfig, cwd: string, hooks?: Partial<BambooHooks>): Promise<Config>;
82
+ declare function getResolvedConfig(config: ExtendableConfig$1, cwd: string, hooks?: Partial<BambooHooks$1>): Promise<Config>;
69
83
  //#endregion
70
84
  //#region src/load-config.d.ts
71
85
  /**
@@ -81,4 +95,17 @@ declare function loadConfig(options: ConfigFileOptions): Promise<LoadConfigResul
81
95
  */
82
96
  declare function resolveConfig(result: BundleConfigResult, cwd: string): Promise<LoadConfigResult$1>;
83
97
  //#endregion
98
+ //#region src/merge-hooks.d.ts
99
+ declare const mergeHooks: (plugins: BambooPlugin[]) => BambooHooks;
100
+ //#endregion
101
+ //#region src/merge-config.d.ts
102
+ type Extendable<T> = T & {
103
+ extend?: T;
104
+ };
105
+ type ExtendableConfig = Extendable<Config>;
106
+ /**
107
+ * Merge all configs into a single config
108
+ */
109
+ declare function mergeConfigs(configs: ExtendableConfig[]): any;
110
+ //#endregion
84
111
  export { type BundleConfigResult, type GetDepsOptions, bundleConfig, convertTsPathsToRegexes, diffConfigs, findConfig, getConfigDependencies, getResolvedConfig, loadConfig, mergeConfigs, mergeHooks, resolveConfig };