@bamboocss/config 1.11.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.
- package/LICENSE.md +16 -0
- package/dist/chunk-6TQW6KOI.mjs +154 -0
- package/dist/chunk-RIBK22OM.mjs +265 -0
- package/dist/chunk-RPIVZP2I.mjs +22 -0
- package/dist/diff-config.js +188 -0
- package/dist/diff-config.mjs +6 -0
- package/dist/index.js +1086 -0
- package/dist/index.mjs +630 -0
- package/dist/merge-config.js +259 -0
- package/dist/merge-config.mjs +8 -0
- package/dist/resolve-ts-path-pattern.js +46 -0
- package/dist/resolve-ts-path-pattern.mjs +6 -0
- package/package.json +81 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Segun Adebayo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
6
|
+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
|
7
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
8
|
+
persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
11
|
+
Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
14
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
15
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
16
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// src/diff-config.ts
|
|
2
|
+
import { dashCase } from "@bamboocss/shared";
|
|
3
|
+
import microdiff from "microdiff";
|
|
4
|
+
|
|
5
|
+
// src/create-matcher.ts
|
|
6
|
+
function createMatcher(id, patterns) {
|
|
7
|
+
if (!patterns?.length) return () => void 0;
|
|
8
|
+
const includePatterns = [];
|
|
9
|
+
const excludePatterns = [];
|
|
10
|
+
const deduped = new Set(patterns);
|
|
11
|
+
deduped.forEach((pattern) => {
|
|
12
|
+
const regexString = pattern.replace(/\*/g, ".*");
|
|
13
|
+
if (pattern.startsWith("!")) {
|
|
14
|
+
excludePatterns.push(regexString.slice(1));
|
|
15
|
+
} else {
|
|
16
|
+
includePatterns.push(regexString);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const include = new RegExp(includePatterns.join("|"));
|
|
20
|
+
const exclude = new RegExp(excludePatterns.join("|"));
|
|
21
|
+
return (path) => {
|
|
22
|
+
if (excludePatterns.length && exclude.test(path)) return;
|
|
23
|
+
return include.test(path) ? id : void 0;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/config-deps.ts
|
|
28
|
+
var all = [
|
|
29
|
+
"clean",
|
|
30
|
+
"cwd",
|
|
31
|
+
"eject",
|
|
32
|
+
"outdir",
|
|
33
|
+
"forceConsistentTypeExtension",
|
|
34
|
+
"outExtension",
|
|
35
|
+
"emitTokensOnly",
|
|
36
|
+
"presets",
|
|
37
|
+
"plugins",
|
|
38
|
+
"hooks"
|
|
39
|
+
];
|
|
40
|
+
var format = [
|
|
41
|
+
"syntax",
|
|
42
|
+
"hash",
|
|
43
|
+
"prefix",
|
|
44
|
+
"separator",
|
|
45
|
+
"strictTokens",
|
|
46
|
+
"strictPropertyValues",
|
|
47
|
+
"shorthands"
|
|
48
|
+
];
|
|
49
|
+
var tokens = [
|
|
50
|
+
"utilities",
|
|
51
|
+
"conditions",
|
|
52
|
+
"theme.tokens",
|
|
53
|
+
"theme.semanticTokens",
|
|
54
|
+
"theme.breakpoints",
|
|
55
|
+
"theme.containerNames",
|
|
56
|
+
"theme.containerSizes"
|
|
57
|
+
];
|
|
58
|
+
var jsx = ["jsxFramework", "jsxFactory", "jsxStyleProps", "syntax"];
|
|
59
|
+
var common = tokens.concat(jsx, format);
|
|
60
|
+
var artifactConfigDeps = {
|
|
61
|
+
helpers: ["syntax", "jsxFramework"],
|
|
62
|
+
keyframes: ["theme.keyframes", "layers"],
|
|
63
|
+
"design-tokens": ["layers", "!utilities.*.className"].concat(tokens),
|
|
64
|
+
types: ["!utilities.*.className"].concat(common),
|
|
65
|
+
"css-fn": common,
|
|
66
|
+
cva: ["syntax"],
|
|
67
|
+
sva: ["syntax"],
|
|
68
|
+
cx: [],
|
|
69
|
+
"create-recipe": ["separator", "prefix", "hash"],
|
|
70
|
+
"recipes-index": ["theme.recipes", "theme.slotRecipes"],
|
|
71
|
+
recipes: ["theme.recipes", "theme.slotRecipes"],
|
|
72
|
+
"patterns-index": ["syntax", "patterns"],
|
|
73
|
+
patterns: ["syntax", "patterns"],
|
|
74
|
+
"jsx-is-valid-prop": common,
|
|
75
|
+
"jsx-factory": jsx,
|
|
76
|
+
"jsx-helpers": jsx,
|
|
77
|
+
"jsx-patterns": jsx.concat("patterns"),
|
|
78
|
+
"jsx-patterns-index": jsx.concat("patterns"),
|
|
79
|
+
"jsx-create-style-context": jsx,
|
|
80
|
+
"css-index": ["syntax"],
|
|
81
|
+
"package.json": ["forceConsistentTypeExtension", "outExtension"],
|
|
82
|
+
"types-styles": ["shorthands"],
|
|
83
|
+
"types-conditions": ["conditions"],
|
|
84
|
+
"types-jsx": jsx,
|
|
85
|
+
"types-entry": [],
|
|
86
|
+
"types-gen": [],
|
|
87
|
+
"types-gen-system": [],
|
|
88
|
+
themes: ["themes"].concat(tokens),
|
|
89
|
+
// staticCss depends on tokens (for wildcards) and recipes (for recipe rules)
|
|
90
|
+
"static-css": ["staticCss", "patterns", "theme.recipes", "theme.slotRecipes"].concat(tokens),
|
|
91
|
+
// Split CSS artifacts (generated via cssgen --splitting)
|
|
92
|
+
styles: [],
|
|
93
|
+
"styles.css": []
|
|
94
|
+
};
|
|
95
|
+
var artifactMatchers = Object.entries(artifactConfigDeps).map(([key, paths]) => {
|
|
96
|
+
if (!paths.length) return () => void 0;
|
|
97
|
+
return createMatcher(key, paths.concat(all));
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// src/diff-config.ts
|
|
101
|
+
var runIfFn = (fn) => typeof fn === "function" ? fn() : fn;
|
|
102
|
+
var hasRecipeStateTransition = (prevConfig, nextConfig) => {
|
|
103
|
+
const prevRecipes = prevConfig.theme?.recipes ?? {};
|
|
104
|
+
const prevSlotRecipes = prevConfig.theme?.slotRecipes ?? {};
|
|
105
|
+
const prevHasRecipes = Object.keys(prevRecipes).length > 0 || Object.keys(prevSlotRecipes).length > 0;
|
|
106
|
+
const nextRecipes = nextConfig.theme?.recipes ?? {};
|
|
107
|
+
const nextSlotRecipes = nextConfig.theme?.slotRecipes ?? {};
|
|
108
|
+
const nextHasRecipes = Object.keys(nextRecipes).length > 0 || Object.keys(nextSlotRecipes).length > 0;
|
|
109
|
+
return prevHasRecipes !== nextHasRecipes;
|
|
110
|
+
};
|
|
111
|
+
function diffConfigs(config, prevConfig) {
|
|
112
|
+
const affected = {
|
|
113
|
+
artifacts: /* @__PURE__ */ new Set(),
|
|
114
|
+
hasConfigChanged: false,
|
|
115
|
+
diffs: []
|
|
116
|
+
};
|
|
117
|
+
if (!prevConfig) {
|
|
118
|
+
affected.hasConfigChanged = true;
|
|
119
|
+
return affected;
|
|
120
|
+
}
|
|
121
|
+
const configDiff = microdiff(prevConfig, runIfFn(config));
|
|
122
|
+
if (!configDiff.length) {
|
|
123
|
+
return affected;
|
|
124
|
+
}
|
|
125
|
+
affected.hasConfigChanged = true;
|
|
126
|
+
affected.diffs = configDiff;
|
|
127
|
+
configDiff.forEach((change) => {
|
|
128
|
+
const changePath = change.path.join(".");
|
|
129
|
+
artifactMatchers.forEach((matcher) => {
|
|
130
|
+
const id = matcher(changePath);
|
|
131
|
+
if (!id) return;
|
|
132
|
+
if (id === "recipes") {
|
|
133
|
+
const name = dashCase(change.path.slice(1, 3).join("."));
|
|
134
|
+
affected.artifacts.add(name);
|
|
135
|
+
}
|
|
136
|
+
if (id === "patterns") {
|
|
137
|
+
const name = dashCase(change.path.slice(0, 2).join("."));
|
|
138
|
+
affected.artifacts.add(name);
|
|
139
|
+
}
|
|
140
|
+
affected.artifacts.add(id);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
if (affected.artifacts.has("recipes") || affected.artifacts.has("recipes-index")) {
|
|
144
|
+
const nextConfig = runIfFn(config);
|
|
145
|
+
if (hasRecipeStateTransition(prevConfig, nextConfig)) {
|
|
146
|
+
affected.artifacts.add("create-recipe");
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return affected;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export {
|
|
153
|
+
diffConfigs
|
|
154
|
+
};
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
// src/merge-config.ts
|
|
2
|
+
import { BAMBOO_CONFIG_NAME, assign, mergeWith, mergeAndConcat, walkObject } from "@bamboocss/shared";
|
|
3
|
+
|
|
4
|
+
// src/merge-hooks.ts
|
|
5
|
+
import { logger } from "@bamboocss/logger";
|
|
6
|
+
var mergeHooks = (plugins) => {
|
|
7
|
+
const hooksFns = {};
|
|
8
|
+
plugins.forEach(({ name, hooks }) => {
|
|
9
|
+
Object.entries(hooks ?? {}).forEach(([key, value]) => {
|
|
10
|
+
if (!hooksFns[key]) {
|
|
11
|
+
hooksFns[key] = [];
|
|
12
|
+
}
|
|
13
|
+
hooksFns[key].push([name, value]);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
const mergedHooks = Object.fromEntries(
|
|
17
|
+
Object.entries(hooksFns).map(([key, entries]) => {
|
|
18
|
+
const fns = entries.map(([name, fn]) => tryCatch(name, fn));
|
|
19
|
+
const reducer = key in reducers ? reducers[key] : void 0;
|
|
20
|
+
if (reducer) {
|
|
21
|
+
return [key, reducer(fns)];
|
|
22
|
+
}
|
|
23
|
+
return [key, syncHooks.includes(key) ? callAll(...fns) : callAllAsync(...fns)];
|
|
24
|
+
})
|
|
25
|
+
);
|
|
26
|
+
return mergedHooks;
|
|
27
|
+
};
|
|
28
|
+
var createReducer = (reducer) => reducer;
|
|
29
|
+
var reducers = {
|
|
30
|
+
"config:resolved": createReducer((fns) => async (_args) => {
|
|
31
|
+
const args = Object.assign({}, _args);
|
|
32
|
+
const original = _args.config;
|
|
33
|
+
let config = args.config;
|
|
34
|
+
for (const hookFn of fns) {
|
|
35
|
+
const result = await hookFn(Object.assign(args, { config, original }));
|
|
36
|
+
if (result !== void 0) {
|
|
37
|
+
config = result;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return config;
|
|
41
|
+
}),
|
|
42
|
+
"parser:before": createReducer((fns) => (_args) => {
|
|
43
|
+
const args = Object.assign({}, _args);
|
|
44
|
+
const original = _args.content;
|
|
45
|
+
let content = args.content;
|
|
46
|
+
for (const hookFn of fns) {
|
|
47
|
+
const result = hookFn(Object.assign(args, { content, original }));
|
|
48
|
+
if (result !== void 0) {
|
|
49
|
+
content = result;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return content;
|
|
53
|
+
}),
|
|
54
|
+
"parser:preprocess": createReducer((fns) => (_args) => {
|
|
55
|
+
const args = Object.assign({}, _args);
|
|
56
|
+
const original = _args.data;
|
|
57
|
+
let data = args.data;
|
|
58
|
+
for (const hookFn of fns) {
|
|
59
|
+
const result = hookFn(Object.assign(args, { data, original }));
|
|
60
|
+
if (result !== void 0) {
|
|
61
|
+
data = result;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return data;
|
|
65
|
+
}),
|
|
66
|
+
"cssgen:done": createReducer((fns) => (_args) => {
|
|
67
|
+
const args = Object.assign({}, _args);
|
|
68
|
+
const original = _args.content;
|
|
69
|
+
let content = args.content;
|
|
70
|
+
for (const hookFn of fns) {
|
|
71
|
+
const result = hookFn(Object.assign(args, { content, original }));
|
|
72
|
+
if (result !== void 0) {
|
|
73
|
+
content = result;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return content;
|
|
77
|
+
}),
|
|
78
|
+
"codegen:prepare": createReducer((fns) => async (_args) => {
|
|
79
|
+
const args = Object.assign({}, _args);
|
|
80
|
+
const original = _args.artifacts;
|
|
81
|
+
let artifacts = args.artifacts;
|
|
82
|
+
for (const hookFn of fns) {
|
|
83
|
+
const result = await hookFn(Object.assign(args, { artifacts, original }));
|
|
84
|
+
if (result) {
|
|
85
|
+
artifacts = result;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return artifacts;
|
|
89
|
+
}),
|
|
90
|
+
"preset:resolved": createReducer((fns) => async (_args) => {
|
|
91
|
+
const args = Object.assign({}, _args);
|
|
92
|
+
const original = _args.preset;
|
|
93
|
+
let preset = args.preset;
|
|
94
|
+
for (const hookFn of fns) {
|
|
95
|
+
const result = await hookFn(Object.assign(args, { preset, original }));
|
|
96
|
+
if (result !== void 0) {
|
|
97
|
+
preset = result;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return preset;
|
|
101
|
+
}),
|
|
102
|
+
"css:optimize": createReducer((fns) => (_args) => {
|
|
103
|
+
const args = Object.assign({}, _args);
|
|
104
|
+
const original = _args.css;
|
|
105
|
+
let css = args.css;
|
|
106
|
+
for (const hookFn of fns) {
|
|
107
|
+
const result = hookFn(Object.assign(args, { css, original }));
|
|
108
|
+
if (result !== void 0) {
|
|
109
|
+
css = result;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return css;
|
|
113
|
+
})
|
|
114
|
+
};
|
|
115
|
+
var syncHooks = [
|
|
116
|
+
"context:created",
|
|
117
|
+
"parser:before",
|
|
118
|
+
"parser:preprocess",
|
|
119
|
+
"parser:after",
|
|
120
|
+
"cssgen:done",
|
|
121
|
+
"css:optimize"
|
|
122
|
+
];
|
|
123
|
+
var callAllAsync = (...fns) => async (...a) => {
|
|
124
|
+
for (const fn of fns) {
|
|
125
|
+
await fn?.(...a);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
var callAll = (...fns) => (...a) => {
|
|
129
|
+
fns.forEach((fn) => fn?.(...a));
|
|
130
|
+
};
|
|
131
|
+
var tryCatch = (name, fn) => {
|
|
132
|
+
return (...args) => {
|
|
133
|
+
try {
|
|
134
|
+
return fn(...args);
|
|
135
|
+
} catch (e) {
|
|
136
|
+
logger.caughtError("hooks", `Error in plugin "${name}"`, e);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// src/validation/utils.ts
|
|
142
|
+
import { isObject, isString } from "@bamboocss/shared";
|
|
143
|
+
var REFERENCE_REGEX = /({([^}]*)})/g;
|
|
144
|
+
var curlyBracketRegex = /[{}]/g;
|
|
145
|
+
var isValidToken = (token) => isObject(token) && Object.hasOwnProperty.call(token, "value");
|
|
146
|
+
var isTokenReference = (value) => typeof value === "string" && REFERENCE_REGEX.test(value);
|
|
147
|
+
var formatPath = (path) => path;
|
|
148
|
+
var SEP = ".";
|
|
149
|
+
function getReferences(value) {
|
|
150
|
+
if (typeof value !== "string") return [];
|
|
151
|
+
const matches = value.match(REFERENCE_REGEX);
|
|
152
|
+
if (!matches) return [];
|
|
153
|
+
return matches.map((match) => match.replace(curlyBracketRegex, "")).map((value2) => {
|
|
154
|
+
return value2.trim().split("/")[0];
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
var serializeTokenValue = (value) => {
|
|
158
|
+
if (isString(value)) {
|
|
159
|
+
return value;
|
|
160
|
+
}
|
|
161
|
+
if (isObject(value)) {
|
|
162
|
+
return Object.values(value).map((v) => serializeTokenValue(v)).join(" ");
|
|
163
|
+
}
|
|
164
|
+
if (Array.isArray(value)) {
|
|
165
|
+
return value.map((v) => serializeTokenValue(v)).join(" ");
|
|
166
|
+
}
|
|
167
|
+
return value.toString();
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// src/merge-config.ts
|
|
171
|
+
function getExtends(items) {
|
|
172
|
+
return items.reduce((merged, { extend }) => {
|
|
173
|
+
if (!extend) return merged;
|
|
174
|
+
return mergeWith(merged, extend, (originalValue, newValue) => {
|
|
175
|
+
if (newValue === void 0) {
|
|
176
|
+
return originalValue ?? [];
|
|
177
|
+
}
|
|
178
|
+
if (originalValue === void 0) {
|
|
179
|
+
return [newValue];
|
|
180
|
+
}
|
|
181
|
+
if (Array.isArray(originalValue)) {
|
|
182
|
+
return [newValue, ...originalValue];
|
|
183
|
+
}
|
|
184
|
+
return [newValue, originalValue];
|
|
185
|
+
});
|
|
186
|
+
}, {});
|
|
187
|
+
}
|
|
188
|
+
function mergeRecords(records) {
|
|
189
|
+
return {
|
|
190
|
+
...records.reduce((acc, record) => assign(acc, record), {}),
|
|
191
|
+
extend: getExtends(records)
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function mergeExtensions(records) {
|
|
195
|
+
const { extend = [], ...restProps } = mergeRecords(records);
|
|
196
|
+
return mergeWith(restProps, extend, (obj, extensions) => {
|
|
197
|
+
return mergeAndConcat({}, obj, ...extensions);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
var isEmptyObject = (obj) => typeof obj === "object" && Object.keys(obj).length === 0;
|
|
201
|
+
var compact = (obj) => {
|
|
202
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
203
|
+
if (obj[key] !== void 0 && !isEmptyObject(obj[key])) {
|
|
204
|
+
acc[key] = obj[key];
|
|
205
|
+
}
|
|
206
|
+
return acc;
|
|
207
|
+
}, {});
|
|
208
|
+
};
|
|
209
|
+
var tokenKeys = ["description", "extensions", "type", "value", "deprecated"];
|
|
210
|
+
function mergeConfigs(configs) {
|
|
211
|
+
const userConfig = configs.at(-1);
|
|
212
|
+
const pluginHooks = userConfig.plugins ?? [];
|
|
213
|
+
if (userConfig.hooks) {
|
|
214
|
+
pluginHooks.push({ name: BAMBOO_CONFIG_NAME, hooks: userConfig.hooks });
|
|
215
|
+
}
|
|
216
|
+
const reversed = Array.from(configs).reverse();
|
|
217
|
+
const mergedResult = assign(
|
|
218
|
+
{
|
|
219
|
+
conditions: mergeExtensions(reversed.map((config) => config.conditions ?? {})),
|
|
220
|
+
theme: mergeExtensions(reversed.map((config) => config.theme ?? {})),
|
|
221
|
+
patterns: mergeExtensions(reversed.map((config) => config.patterns ?? {})),
|
|
222
|
+
utilities: mergeExtensions(reversed.map((config) => config.utilities ?? {})),
|
|
223
|
+
globalCss: mergeExtensions(reversed.map((config) => config.globalCss ?? {})),
|
|
224
|
+
globalVars: mergeExtensions(reversed.map((config) => config.globalVars ?? {})),
|
|
225
|
+
globalFontface: mergeExtensions(reversed.map((config) => config.globalFontface ?? {})),
|
|
226
|
+
globalPositionTry: mergeExtensions(reversed.map((config) => config.globalPositionTry ?? {})),
|
|
227
|
+
staticCss: mergeExtensions(reversed.map((config) => config.staticCss ?? {})),
|
|
228
|
+
themes: mergeExtensions(reversed.map((config) => config.themes ?? {})),
|
|
229
|
+
hooks: mergeHooks(pluginHooks)
|
|
230
|
+
},
|
|
231
|
+
...reversed
|
|
232
|
+
);
|
|
233
|
+
const withoutEmpty = compact(mergedResult);
|
|
234
|
+
if (withoutEmpty.theme?.tokens) {
|
|
235
|
+
walkObject(withoutEmpty.theme.tokens, (args) => args, {
|
|
236
|
+
stop(token) {
|
|
237
|
+
if (!isValidToken(token)) return false;
|
|
238
|
+
const keys = Object.keys(token);
|
|
239
|
+
const nestedKeys = keys.filter((k) => !tokenKeys.includes(k));
|
|
240
|
+
const nested = nestedKeys.length > 0;
|
|
241
|
+
if (nested) {
|
|
242
|
+
token.DEFAULT ||= {};
|
|
243
|
+
tokenKeys.forEach((key) => {
|
|
244
|
+
if (token[key] == null) return;
|
|
245
|
+
token.DEFAULT[key] ||= token[key];
|
|
246
|
+
delete token[key];
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
return withoutEmpty;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export {
|
|
257
|
+
mergeHooks,
|
|
258
|
+
isValidToken,
|
|
259
|
+
isTokenReference,
|
|
260
|
+
formatPath,
|
|
261
|
+
SEP,
|
|
262
|
+
getReferences,
|
|
263
|
+
serializeTokenValue,
|
|
264
|
+
mergeConfigs
|
|
265
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/resolve-ts-path-pattern.ts
|
|
2
|
+
import { posix, sep } from "path";
|
|
3
|
+
var resolveTsPathPattern = (pathMappings, moduleSpecifier) => {
|
|
4
|
+
for (const mapping of pathMappings) {
|
|
5
|
+
const match = moduleSpecifier.match(mapping.pattern);
|
|
6
|
+
if (!match) {
|
|
7
|
+
continue;
|
|
8
|
+
}
|
|
9
|
+
for (const pathTemplate of mapping.paths) {
|
|
10
|
+
let starCount = 0;
|
|
11
|
+
const mappedId = pathTemplate.replace(/\*/g, () => {
|
|
12
|
+
const matchIndex = Math.min(++starCount, match.length - 1);
|
|
13
|
+
return match[matchIndex];
|
|
14
|
+
});
|
|
15
|
+
return mappedId.split(sep).join(posix.sep);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
resolveTsPathPattern
|
|
22
|
+
};
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all2) => {
|
|
9
|
+
for (var name in all2)
|
|
10
|
+
__defProp(target, name, { get: all2[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/diff-config.ts
|
|
31
|
+
var diff_config_exports = {};
|
|
32
|
+
__export(diff_config_exports, {
|
|
33
|
+
diffConfigs: () => diffConfigs
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(diff_config_exports);
|
|
36
|
+
var import_shared = require("@bamboocss/shared");
|
|
37
|
+
var import_microdiff = __toESM(require("microdiff"));
|
|
38
|
+
|
|
39
|
+
// src/create-matcher.ts
|
|
40
|
+
function createMatcher(id, patterns) {
|
|
41
|
+
if (!patterns?.length) return () => void 0;
|
|
42
|
+
const includePatterns = [];
|
|
43
|
+
const excludePatterns = [];
|
|
44
|
+
const deduped = new Set(patterns);
|
|
45
|
+
deduped.forEach((pattern) => {
|
|
46
|
+
const regexString = pattern.replace(/\*/g, ".*");
|
|
47
|
+
if (pattern.startsWith("!")) {
|
|
48
|
+
excludePatterns.push(regexString.slice(1));
|
|
49
|
+
} else {
|
|
50
|
+
includePatterns.push(regexString);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const include = new RegExp(includePatterns.join("|"));
|
|
54
|
+
const exclude = new RegExp(excludePatterns.join("|"));
|
|
55
|
+
return (path) => {
|
|
56
|
+
if (excludePatterns.length && exclude.test(path)) return;
|
|
57
|
+
return include.test(path) ? id : void 0;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/config-deps.ts
|
|
62
|
+
var all = [
|
|
63
|
+
"clean",
|
|
64
|
+
"cwd",
|
|
65
|
+
"eject",
|
|
66
|
+
"outdir",
|
|
67
|
+
"forceConsistentTypeExtension",
|
|
68
|
+
"outExtension",
|
|
69
|
+
"emitTokensOnly",
|
|
70
|
+
"presets",
|
|
71
|
+
"plugins",
|
|
72
|
+
"hooks"
|
|
73
|
+
];
|
|
74
|
+
var format = [
|
|
75
|
+
"syntax",
|
|
76
|
+
"hash",
|
|
77
|
+
"prefix",
|
|
78
|
+
"separator",
|
|
79
|
+
"strictTokens",
|
|
80
|
+
"strictPropertyValues",
|
|
81
|
+
"shorthands"
|
|
82
|
+
];
|
|
83
|
+
var tokens = [
|
|
84
|
+
"utilities",
|
|
85
|
+
"conditions",
|
|
86
|
+
"theme.tokens",
|
|
87
|
+
"theme.semanticTokens",
|
|
88
|
+
"theme.breakpoints",
|
|
89
|
+
"theme.containerNames",
|
|
90
|
+
"theme.containerSizes"
|
|
91
|
+
];
|
|
92
|
+
var jsx = ["jsxFramework", "jsxFactory", "jsxStyleProps", "syntax"];
|
|
93
|
+
var common = tokens.concat(jsx, format);
|
|
94
|
+
var artifactConfigDeps = {
|
|
95
|
+
helpers: ["syntax", "jsxFramework"],
|
|
96
|
+
keyframes: ["theme.keyframes", "layers"],
|
|
97
|
+
"design-tokens": ["layers", "!utilities.*.className"].concat(tokens),
|
|
98
|
+
types: ["!utilities.*.className"].concat(common),
|
|
99
|
+
"css-fn": common,
|
|
100
|
+
cva: ["syntax"],
|
|
101
|
+
sva: ["syntax"],
|
|
102
|
+
cx: [],
|
|
103
|
+
"create-recipe": ["separator", "prefix", "hash"],
|
|
104
|
+
"recipes-index": ["theme.recipes", "theme.slotRecipes"],
|
|
105
|
+
recipes: ["theme.recipes", "theme.slotRecipes"],
|
|
106
|
+
"patterns-index": ["syntax", "patterns"],
|
|
107
|
+
patterns: ["syntax", "patterns"],
|
|
108
|
+
"jsx-is-valid-prop": common,
|
|
109
|
+
"jsx-factory": jsx,
|
|
110
|
+
"jsx-helpers": jsx,
|
|
111
|
+
"jsx-patterns": jsx.concat("patterns"),
|
|
112
|
+
"jsx-patterns-index": jsx.concat("patterns"),
|
|
113
|
+
"jsx-create-style-context": jsx,
|
|
114
|
+
"css-index": ["syntax"],
|
|
115
|
+
"package.json": ["forceConsistentTypeExtension", "outExtension"],
|
|
116
|
+
"types-styles": ["shorthands"],
|
|
117
|
+
"types-conditions": ["conditions"],
|
|
118
|
+
"types-jsx": jsx,
|
|
119
|
+
"types-entry": [],
|
|
120
|
+
"types-gen": [],
|
|
121
|
+
"types-gen-system": [],
|
|
122
|
+
themes: ["themes"].concat(tokens),
|
|
123
|
+
// staticCss depends on tokens (for wildcards) and recipes (for recipe rules)
|
|
124
|
+
"static-css": ["staticCss", "patterns", "theme.recipes", "theme.slotRecipes"].concat(tokens),
|
|
125
|
+
// Split CSS artifacts (generated via cssgen --splitting)
|
|
126
|
+
styles: [],
|
|
127
|
+
"styles.css": []
|
|
128
|
+
};
|
|
129
|
+
var artifactMatchers = Object.entries(artifactConfigDeps).map(([key, paths]) => {
|
|
130
|
+
if (!paths.length) return () => void 0;
|
|
131
|
+
return createMatcher(key, paths.concat(all));
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// src/diff-config.ts
|
|
135
|
+
var runIfFn = (fn) => typeof fn === "function" ? fn() : fn;
|
|
136
|
+
var hasRecipeStateTransition = (prevConfig, nextConfig) => {
|
|
137
|
+
const prevRecipes = prevConfig.theme?.recipes ?? {};
|
|
138
|
+
const prevSlotRecipes = prevConfig.theme?.slotRecipes ?? {};
|
|
139
|
+
const prevHasRecipes = Object.keys(prevRecipes).length > 0 || Object.keys(prevSlotRecipes).length > 0;
|
|
140
|
+
const nextRecipes = nextConfig.theme?.recipes ?? {};
|
|
141
|
+
const nextSlotRecipes = nextConfig.theme?.slotRecipes ?? {};
|
|
142
|
+
const nextHasRecipes = Object.keys(nextRecipes).length > 0 || Object.keys(nextSlotRecipes).length > 0;
|
|
143
|
+
return prevHasRecipes !== nextHasRecipes;
|
|
144
|
+
};
|
|
145
|
+
function diffConfigs(config, prevConfig) {
|
|
146
|
+
const affected = {
|
|
147
|
+
artifacts: /* @__PURE__ */ new Set(),
|
|
148
|
+
hasConfigChanged: false,
|
|
149
|
+
diffs: []
|
|
150
|
+
};
|
|
151
|
+
if (!prevConfig) {
|
|
152
|
+
affected.hasConfigChanged = true;
|
|
153
|
+
return affected;
|
|
154
|
+
}
|
|
155
|
+
const configDiff = (0, import_microdiff.default)(prevConfig, runIfFn(config));
|
|
156
|
+
if (!configDiff.length) {
|
|
157
|
+
return affected;
|
|
158
|
+
}
|
|
159
|
+
affected.hasConfigChanged = true;
|
|
160
|
+
affected.diffs = configDiff;
|
|
161
|
+
configDiff.forEach((change) => {
|
|
162
|
+
const changePath = change.path.join(".");
|
|
163
|
+
artifactMatchers.forEach((matcher) => {
|
|
164
|
+
const id = matcher(changePath);
|
|
165
|
+
if (!id) return;
|
|
166
|
+
if (id === "recipes") {
|
|
167
|
+
const name = (0, import_shared.dashCase)(change.path.slice(1, 3).join("."));
|
|
168
|
+
affected.artifacts.add(name);
|
|
169
|
+
}
|
|
170
|
+
if (id === "patterns") {
|
|
171
|
+
const name = (0, import_shared.dashCase)(change.path.slice(0, 2).join("."));
|
|
172
|
+
affected.artifacts.add(name);
|
|
173
|
+
}
|
|
174
|
+
affected.artifacts.add(id);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
if (affected.artifacts.has("recipes") || affected.artifacts.has("recipes-index")) {
|
|
178
|
+
const nextConfig = runIfFn(config);
|
|
179
|
+
if (hasRecipeStateTransition(prevConfig, nextConfig)) {
|
|
180
|
+
affected.artifacts.add("create-recipe");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return affected;
|
|
184
|
+
}
|
|
185
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
186
|
+
0 && (module.exports = {
|
|
187
|
+
diffConfigs
|
|
188
|
+
});
|