@bamboocss/config 1.11.1 → 1.11.2
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/diff-config-Co_3mDXE.cjs +197 -0
- package/dist/diff-config-KDQWMnQN.mjs +163 -0
- package/dist/diff-config.cjs +3 -0
- package/dist/diff-config.d.cts +10 -0
- package/dist/diff-config.d.mts +10 -0
- package/dist/diff-config.mjs +2 -6
- package/dist/index.cjs +575 -0
- package/dist/index.d.cts +84 -0
- package/dist/index.d.mts +84 -0
- package/dist/index.mjs +520 -589
- package/dist/merge-config-CcNpHJit.cjs +312 -0
- package/dist/merge-config-DI__LOWx.mjs +270 -0
- package/dist/merge-config-DVOlBQJY.d.cts +16 -0
- package/dist/merge-config-oEiBYbfB.d.mts +16 -0
- package/dist/merge-config.cjs +4 -0
- package/dist/merge-config.d.cts +2 -0
- package/dist/merge-config.d.mts +2 -0
- package/dist/merge-config.mjs +2 -8
- package/dist/resolve-ts-path-pattern.cjs +21 -0
- package/dist/resolve-ts-path-pattern.d.cts +9 -0
- package/dist/resolve-ts-path-pattern.d.mts +9 -0
- package/dist/resolve-ts-path-pattern.mjs +18 -5
- package/dist/ts-config-paths-CvGId8kq.d.mts +11 -0
- package/dist/ts-config-paths-wVx39QZ0.d.cts +11 -0
- package/package.json +19 -19
- package/dist/chunk-6TQW6KOI.mjs +0 -154
- package/dist/chunk-RIBK22OM.mjs +0 -265
- package/dist/chunk-RPIVZP2I.mjs +0 -22
- package/dist/diff-config.js +0 -188
- package/dist/index.js +0 -1086
- package/dist/merge-config.js +0 -259
- package/dist/resolve-ts-path-pattern.js +0 -46
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
require("./diff-config-Co_3mDXE.cjs");
|
|
2
|
+
let _bamboocss_logger = require("@bamboocss/logger");
|
|
3
|
+
let _bamboocss_shared = require("@bamboocss/shared");
|
|
4
|
+
//#region src/merge-hooks.ts
|
|
5
|
+
const mergeHooks = (plugins) => {
|
|
6
|
+
const hooksFns = {};
|
|
7
|
+
plugins.forEach(({ name, hooks }) => {
|
|
8
|
+
Object.entries(hooks ?? {}).forEach(([key, value]) => {
|
|
9
|
+
if (!hooksFns[key]) hooksFns[key] = [];
|
|
10
|
+
hooksFns[key].push([name, value]);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
return Object.fromEntries(Object.entries(hooksFns).map(([key, entries]) => {
|
|
14
|
+
const fns = entries.map(([name, fn]) => tryCatch(name, fn));
|
|
15
|
+
const reducer = key in reducers ? reducers[key] : void 0;
|
|
16
|
+
if (reducer) return [key, reducer(fns)];
|
|
17
|
+
return [key, syncHooks.includes(key) ? callAll(...fns) : callAllAsync(...fns)];
|
|
18
|
+
}));
|
|
19
|
+
};
|
|
20
|
+
const createReducer = (reducer) => reducer;
|
|
21
|
+
const reducers = {
|
|
22
|
+
"config:resolved": createReducer((fns) => async (_args) => {
|
|
23
|
+
const args = Object.assign({}, _args);
|
|
24
|
+
const original = _args.config;
|
|
25
|
+
let config = args.config;
|
|
26
|
+
for (const hookFn of fns) {
|
|
27
|
+
const result = await hookFn(Object.assign(args, {
|
|
28
|
+
config,
|
|
29
|
+
original
|
|
30
|
+
}));
|
|
31
|
+
if (result !== void 0) config = result;
|
|
32
|
+
}
|
|
33
|
+
return config;
|
|
34
|
+
}),
|
|
35
|
+
"parser:before": createReducer((fns) => (_args) => {
|
|
36
|
+
const args = Object.assign({}, _args);
|
|
37
|
+
const original = _args.content;
|
|
38
|
+
let content = args.content;
|
|
39
|
+
for (const hookFn of fns) {
|
|
40
|
+
const result = hookFn(Object.assign(args, {
|
|
41
|
+
content,
|
|
42
|
+
original
|
|
43
|
+
}));
|
|
44
|
+
if (result !== void 0) content = result;
|
|
45
|
+
}
|
|
46
|
+
return content;
|
|
47
|
+
}),
|
|
48
|
+
"parser:preprocess": createReducer((fns) => (_args) => {
|
|
49
|
+
const args = Object.assign({}, _args);
|
|
50
|
+
const original = _args.data;
|
|
51
|
+
let data = args.data;
|
|
52
|
+
for (const hookFn of fns) {
|
|
53
|
+
const result = hookFn(Object.assign(args, {
|
|
54
|
+
data,
|
|
55
|
+
original
|
|
56
|
+
}));
|
|
57
|
+
if (result !== void 0) data = result;
|
|
58
|
+
}
|
|
59
|
+
return data;
|
|
60
|
+
}),
|
|
61
|
+
"cssgen:done": createReducer((fns) => (_args) => {
|
|
62
|
+
const args = Object.assign({}, _args);
|
|
63
|
+
const original = _args.content;
|
|
64
|
+
let content = args.content;
|
|
65
|
+
for (const hookFn of fns) {
|
|
66
|
+
const result = hookFn(Object.assign(args, {
|
|
67
|
+
content,
|
|
68
|
+
original
|
|
69
|
+
}));
|
|
70
|
+
if (result !== void 0) content = result;
|
|
71
|
+
}
|
|
72
|
+
return content;
|
|
73
|
+
}),
|
|
74
|
+
"codegen:prepare": createReducer((fns) => async (_args) => {
|
|
75
|
+
const args = Object.assign({}, _args);
|
|
76
|
+
const original = _args.artifacts;
|
|
77
|
+
let artifacts = args.artifacts;
|
|
78
|
+
for (const hookFn of fns) {
|
|
79
|
+
const result = await hookFn(Object.assign(args, {
|
|
80
|
+
artifacts,
|
|
81
|
+
original
|
|
82
|
+
}));
|
|
83
|
+
if (result) artifacts = result;
|
|
84
|
+
}
|
|
85
|
+
return artifacts;
|
|
86
|
+
}),
|
|
87
|
+
"preset:resolved": createReducer((fns) => async (_args) => {
|
|
88
|
+
const args = Object.assign({}, _args);
|
|
89
|
+
const original = _args.preset;
|
|
90
|
+
let preset = args.preset;
|
|
91
|
+
for (const hookFn of fns) {
|
|
92
|
+
const result = await hookFn(Object.assign(args, {
|
|
93
|
+
preset,
|
|
94
|
+
original
|
|
95
|
+
}));
|
|
96
|
+
if (result !== void 0) preset = result;
|
|
97
|
+
}
|
|
98
|
+
return preset;
|
|
99
|
+
}),
|
|
100
|
+
"css:optimize": createReducer((fns) => (_args) => {
|
|
101
|
+
const args = Object.assign({}, _args);
|
|
102
|
+
const original = _args.css;
|
|
103
|
+
let css = args.css;
|
|
104
|
+
for (const hookFn of fns) {
|
|
105
|
+
const result = hookFn(Object.assign(args, {
|
|
106
|
+
css,
|
|
107
|
+
original
|
|
108
|
+
}));
|
|
109
|
+
if (result !== void 0) css = result;
|
|
110
|
+
}
|
|
111
|
+
return css;
|
|
112
|
+
})
|
|
113
|
+
};
|
|
114
|
+
const syncHooks = [
|
|
115
|
+
"context:created",
|
|
116
|
+
"parser:before",
|
|
117
|
+
"parser:preprocess",
|
|
118
|
+
"parser:after",
|
|
119
|
+
"cssgen:done",
|
|
120
|
+
"css:optimize"
|
|
121
|
+
];
|
|
122
|
+
const callAllAsync = (...fns) => async (...a) => {
|
|
123
|
+
for (const fn of fns) await fn?.(...a);
|
|
124
|
+
};
|
|
125
|
+
const callAll = (...fns) => (...a) => {
|
|
126
|
+
fns.forEach((fn) => fn?.(...a));
|
|
127
|
+
};
|
|
128
|
+
const tryCatch = (name, fn) => {
|
|
129
|
+
return (...args) => {
|
|
130
|
+
try {
|
|
131
|
+
return fn(...args);
|
|
132
|
+
} catch (e) {
|
|
133
|
+
_bamboocss_logger.logger.caughtError("hooks", `Error in plugin "${name}"`, e);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/validation/utils.ts
|
|
139
|
+
const REFERENCE_REGEX = /({([^}]*)})/g;
|
|
140
|
+
const curlyBracketRegex = /[{}]/g;
|
|
141
|
+
const isValidToken = (token) => (0, _bamboocss_shared.isObject)(token) && Object.hasOwnProperty.call(token, "value");
|
|
142
|
+
const isTokenReference = (value) => typeof value === "string" && REFERENCE_REGEX.test(value);
|
|
143
|
+
const formatPath = (path) => path;
|
|
144
|
+
function getReferences(value) {
|
|
145
|
+
if (typeof value !== "string") return [];
|
|
146
|
+
const matches = value.match(REFERENCE_REGEX);
|
|
147
|
+
if (!matches) return [];
|
|
148
|
+
return matches.map((match) => match.replace(curlyBracketRegex, "")).map((value) => {
|
|
149
|
+
return value.trim().split("/")[0];
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
const serializeTokenValue = (value) => {
|
|
153
|
+
if ((0, _bamboocss_shared.isString)(value)) return value;
|
|
154
|
+
if ((0, _bamboocss_shared.isObject)(value)) return Object.values(value).map((v) => serializeTokenValue(v)).join(" ");
|
|
155
|
+
if (Array.isArray(value)) return value.map((v) => serializeTokenValue(v)).join(" ");
|
|
156
|
+
return value.toString();
|
|
157
|
+
};
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/merge-config.ts
|
|
160
|
+
/**
|
|
161
|
+
* Collect all `extend` properties into an array (to avoid mutation)
|
|
162
|
+
*/
|
|
163
|
+
function getExtends(items) {
|
|
164
|
+
return items.reduce((merged, { extend }) => {
|
|
165
|
+
if (!extend) return merged;
|
|
166
|
+
return (0, _bamboocss_shared.mergeWith)(merged, extend, (originalValue, newValue) => {
|
|
167
|
+
if (newValue === void 0) return originalValue ?? [];
|
|
168
|
+
if (originalValue === void 0) return [newValue];
|
|
169
|
+
if (Array.isArray(originalValue)) return [newValue, ...originalValue];
|
|
170
|
+
return [newValue, originalValue];
|
|
171
|
+
});
|
|
172
|
+
}, {});
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Separate the `extend` properties from the rest of the object
|
|
176
|
+
*/
|
|
177
|
+
function mergeRecords(records) {
|
|
178
|
+
return {
|
|
179
|
+
...records.reduce((acc, record) => (0, _bamboocss_shared.assign)(acc, record), {}),
|
|
180
|
+
extend: getExtends(records)
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Merge all `extend` properties into the rest of the object
|
|
185
|
+
*/
|
|
186
|
+
function mergeExtensions(records) {
|
|
187
|
+
const { extend = [], ...restProps } = mergeRecords(records);
|
|
188
|
+
return (0, _bamboocss_shared.mergeWith)(restProps, extend, (obj, extensions) => {
|
|
189
|
+
return (0, _bamboocss_shared.mergeAndConcat)({}, obj, ...extensions);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
const isEmptyObject = (obj) => typeof obj === "object" && Object.keys(obj).length === 0;
|
|
193
|
+
const compact = (obj) => {
|
|
194
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
195
|
+
if (obj[key] !== void 0 && !isEmptyObject(obj[key])) acc[key] = obj[key];
|
|
196
|
+
return acc;
|
|
197
|
+
}, {});
|
|
198
|
+
};
|
|
199
|
+
const tokenKeys = [
|
|
200
|
+
"description",
|
|
201
|
+
"extensions",
|
|
202
|
+
"type",
|
|
203
|
+
"value",
|
|
204
|
+
"deprecated"
|
|
205
|
+
];
|
|
206
|
+
/**
|
|
207
|
+
* Merge all configs into a single config
|
|
208
|
+
*/
|
|
209
|
+
function mergeConfigs(configs) {
|
|
210
|
+
const userConfig = configs.at(-1);
|
|
211
|
+
const pluginHooks = userConfig.plugins ?? [];
|
|
212
|
+
if (userConfig.hooks) pluginHooks.push({
|
|
213
|
+
name: _bamboocss_shared.BAMBOO_CONFIG_NAME,
|
|
214
|
+
hooks: userConfig.hooks
|
|
215
|
+
});
|
|
216
|
+
const reversed = Array.from(configs).reverse();
|
|
217
|
+
const withoutEmpty = compact((0, _bamboocss_shared.assign)({
|
|
218
|
+
conditions: mergeExtensions(reversed.map((config) => config.conditions ?? {})),
|
|
219
|
+
theme: mergeExtensions(reversed.map((config) => config.theme ?? {})),
|
|
220
|
+
patterns: mergeExtensions(reversed.map((config) => config.patterns ?? {})),
|
|
221
|
+
utilities: mergeExtensions(reversed.map((config) => config.utilities ?? {})),
|
|
222
|
+
globalCss: mergeExtensions(reversed.map((config) => config.globalCss ?? {})),
|
|
223
|
+
globalVars: mergeExtensions(reversed.map((config) => config.globalVars ?? {})),
|
|
224
|
+
globalFontface: mergeExtensions(reversed.map((config) => config.globalFontface ?? {})),
|
|
225
|
+
globalPositionTry: mergeExtensions(reversed.map((config) => config.globalPositionTry ?? {})),
|
|
226
|
+
staticCss: mergeExtensions(reversed.map((config) => config.staticCss ?? {})),
|
|
227
|
+
themes: mergeExtensions(reversed.map((config) => config.themes ?? {})),
|
|
228
|
+
hooks: mergeHooks(pluginHooks)
|
|
229
|
+
}, ...reversed));
|
|
230
|
+
/**
|
|
231
|
+
* Properly merge tokens between flat/nested forms by setting the flat form as the default
|
|
232
|
+
* preset:
|
|
233
|
+
* ```
|
|
234
|
+
* tokens: {
|
|
235
|
+
* black: {
|
|
236
|
+
* value: "black"
|
|
237
|
+
* }
|
|
238
|
+
* }
|
|
239
|
+
* // color: "black"
|
|
240
|
+
* ```
|
|
241
|
+
*
|
|
242
|
+
* config:
|
|
243
|
+
* ```
|
|
244
|
+
* tokens: {
|
|
245
|
+
* black: {
|
|
246
|
+
* 0: { value: "black" },
|
|
247
|
+
* 10: { value: "black/10" },
|
|
248
|
+
* 20: { value: "black/20" },
|
|
249
|
+
* // ...
|
|
250
|
+
* }
|
|
251
|
+
* }
|
|
252
|
+
*
|
|
253
|
+
* // color: "black.20"
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
if (withoutEmpty.theme?.tokens) (0, _bamboocss_shared.walkObject)(withoutEmpty.theme.tokens, (args) => args, { stop(token) {
|
|
257
|
+
if (!isValidToken(token)) return false;
|
|
258
|
+
if (Object.keys(token).filter((k) => !tokenKeys.includes(k)).length > 0) {
|
|
259
|
+
token.DEFAULT ||= {};
|
|
260
|
+
tokenKeys.forEach((key) => {
|
|
261
|
+
if (token[key] == null) return;
|
|
262
|
+
token.DEFAULT[key] ||= token[key];
|
|
263
|
+
delete token[key];
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
return true;
|
|
267
|
+
} });
|
|
268
|
+
return withoutEmpty;
|
|
269
|
+
}
|
|
270
|
+
//#endregion
|
|
271
|
+
Object.defineProperty(exports, "formatPath", {
|
|
272
|
+
enumerable: true,
|
|
273
|
+
get: function() {
|
|
274
|
+
return formatPath;
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
Object.defineProperty(exports, "getReferences", {
|
|
278
|
+
enumerable: true,
|
|
279
|
+
get: function() {
|
|
280
|
+
return getReferences;
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
Object.defineProperty(exports, "isTokenReference", {
|
|
284
|
+
enumerable: true,
|
|
285
|
+
get: function() {
|
|
286
|
+
return isTokenReference;
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
Object.defineProperty(exports, "isValidToken", {
|
|
290
|
+
enumerable: true,
|
|
291
|
+
get: function() {
|
|
292
|
+
return isValidToken;
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
Object.defineProperty(exports, "mergeConfigs", {
|
|
296
|
+
enumerable: true,
|
|
297
|
+
get: function() {
|
|
298
|
+
return mergeConfigs;
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
Object.defineProperty(exports, "mergeHooks", {
|
|
302
|
+
enumerable: true,
|
|
303
|
+
get: function() {
|
|
304
|
+
return mergeHooks;
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
Object.defineProperty(exports, "serializeTokenValue", {
|
|
308
|
+
enumerable: true,
|
|
309
|
+
get: function() {
|
|
310
|
+
return serializeTokenValue;
|
|
311
|
+
}
|
|
312
|
+
});
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { logger } from "@bamboocss/logger";
|
|
2
|
+
import { BAMBOO_CONFIG_NAME, assign, isObject, isString, mergeAndConcat, mergeWith, walkObject } from "@bamboocss/shared";
|
|
3
|
+
//#region src/merge-hooks.ts
|
|
4
|
+
const mergeHooks = (plugins) => {
|
|
5
|
+
const hooksFns = {};
|
|
6
|
+
plugins.forEach(({ name, hooks }) => {
|
|
7
|
+
Object.entries(hooks ?? {}).forEach(([key, value]) => {
|
|
8
|
+
if (!hooksFns[key]) hooksFns[key] = [];
|
|
9
|
+
hooksFns[key].push([name, value]);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
return Object.fromEntries(Object.entries(hooksFns).map(([key, entries]) => {
|
|
13
|
+
const fns = entries.map(([name, fn]) => tryCatch(name, fn));
|
|
14
|
+
const reducer = key in reducers ? reducers[key] : void 0;
|
|
15
|
+
if (reducer) return [key, reducer(fns)];
|
|
16
|
+
return [key, syncHooks.includes(key) ? callAll(...fns) : callAllAsync(...fns)];
|
|
17
|
+
}));
|
|
18
|
+
};
|
|
19
|
+
const createReducer = (reducer) => reducer;
|
|
20
|
+
const reducers = {
|
|
21
|
+
"config:resolved": createReducer((fns) => async (_args) => {
|
|
22
|
+
const args = Object.assign({}, _args);
|
|
23
|
+
const original = _args.config;
|
|
24
|
+
let config = args.config;
|
|
25
|
+
for (const hookFn of fns) {
|
|
26
|
+
const result = await hookFn(Object.assign(args, {
|
|
27
|
+
config,
|
|
28
|
+
original
|
|
29
|
+
}));
|
|
30
|
+
if (result !== void 0) config = result;
|
|
31
|
+
}
|
|
32
|
+
return config;
|
|
33
|
+
}),
|
|
34
|
+
"parser:before": createReducer((fns) => (_args) => {
|
|
35
|
+
const args = Object.assign({}, _args);
|
|
36
|
+
const original = _args.content;
|
|
37
|
+
let content = args.content;
|
|
38
|
+
for (const hookFn of fns) {
|
|
39
|
+
const result = hookFn(Object.assign(args, {
|
|
40
|
+
content,
|
|
41
|
+
original
|
|
42
|
+
}));
|
|
43
|
+
if (result !== void 0) content = result;
|
|
44
|
+
}
|
|
45
|
+
return content;
|
|
46
|
+
}),
|
|
47
|
+
"parser:preprocess": createReducer((fns) => (_args) => {
|
|
48
|
+
const args = Object.assign({}, _args);
|
|
49
|
+
const original = _args.data;
|
|
50
|
+
let data = args.data;
|
|
51
|
+
for (const hookFn of fns) {
|
|
52
|
+
const result = hookFn(Object.assign(args, {
|
|
53
|
+
data,
|
|
54
|
+
original
|
|
55
|
+
}));
|
|
56
|
+
if (result !== void 0) data = result;
|
|
57
|
+
}
|
|
58
|
+
return data;
|
|
59
|
+
}),
|
|
60
|
+
"cssgen:done": createReducer((fns) => (_args) => {
|
|
61
|
+
const args = Object.assign({}, _args);
|
|
62
|
+
const original = _args.content;
|
|
63
|
+
let content = args.content;
|
|
64
|
+
for (const hookFn of fns) {
|
|
65
|
+
const result = hookFn(Object.assign(args, {
|
|
66
|
+
content,
|
|
67
|
+
original
|
|
68
|
+
}));
|
|
69
|
+
if (result !== void 0) content = result;
|
|
70
|
+
}
|
|
71
|
+
return content;
|
|
72
|
+
}),
|
|
73
|
+
"codegen:prepare": createReducer((fns) => async (_args) => {
|
|
74
|
+
const args = Object.assign({}, _args);
|
|
75
|
+
const original = _args.artifacts;
|
|
76
|
+
let artifacts = args.artifacts;
|
|
77
|
+
for (const hookFn of fns) {
|
|
78
|
+
const result = await hookFn(Object.assign(args, {
|
|
79
|
+
artifacts,
|
|
80
|
+
original
|
|
81
|
+
}));
|
|
82
|
+
if (result) artifacts = result;
|
|
83
|
+
}
|
|
84
|
+
return artifacts;
|
|
85
|
+
}),
|
|
86
|
+
"preset:resolved": createReducer((fns) => async (_args) => {
|
|
87
|
+
const args = Object.assign({}, _args);
|
|
88
|
+
const original = _args.preset;
|
|
89
|
+
let preset = args.preset;
|
|
90
|
+
for (const hookFn of fns) {
|
|
91
|
+
const result = await hookFn(Object.assign(args, {
|
|
92
|
+
preset,
|
|
93
|
+
original
|
|
94
|
+
}));
|
|
95
|
+
if (result !== void 0) preset = result;
|
|
96
|
+
}
|
|
97
|
+
return preset;
|
|
98
|
+
}),
|
|
99
|
+
"css:optimize": createReducer((fns) => (_args) => {
|
|
100
|
+
const args = Object.assign({}, _args);
|
|
101
|
+
const original = _args.css;
|
|
102
|
+
let css = args.css;
|
|
103
|
+
for (const hookFn of fns) {
|
|
104
|
+
const result = hookFn(Object.assign(args, {
|
|
105
|
+
css,
|
|
106
|
+
original
|
|
107
|
+
}));
|
|
108
|
+
if (result !== void 0) css = result;
|
|
109
|
+
}
|
|
110
|
+
return css;
|
|
111
|
+
})
|
|
112
|
+
};
|
|
113
|
+
const syncHooks = [
|
|
114
|
+
"context:created",
|
|
115
|
+
"parser:before",
|
|
116
|
+
"parser:preprocess",
|
|
117
|
+
"parser:after",
|
|
118
|
+
"cssgen:done",
|
|
119
|
+
"css:optimize"
|
|
120
|
+
];
|
|
121
|
+
const callAllAsync = (...fns) => async (...a) => {
|
|
122
|
+
for (const fn of fns) await fn?.(...a);
|
|
123
|
+
};
|
|
124
|
+
const callAll = (...fns) => (...a) => {
|
|
125
|
+
fns.forEach((fn) => fn?.(...a));
|
|
126
|
+
};
|
|
127
|
+
const tryCatch = (name, fn) => {
|
|
128
|
+
return (...args) => {
|
|
129
|
+
try {
|
|
130
|
+
return fn(...args);
|
|
131
|
+
} catch (e) {
|
|
132
|
+
logger.caughtError("hooks", `Error in plugin "${name}"`, e);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/validation/utils.ts
|
|
138
|
+
const REFERENCE_REGEX = /({([^}]*)})/g;
|
|
139
|
+
const curlyBracketRegex = /[{}]/g;
|
|
140
|
+
const isValidToken = (token) => isObject(token) && Object.hasOwnProperty.call(token, "value");
|
|
141
|
+
const isTokenReference = (value) => typeof value === "string" && REFERENCE_REGEX.test(value);
|
|
142
|
+
const formatPath = (path) => path;
|
|
143
|
+
function getReferences(value) {
|
|
144
|
+
if (typeof value !== "string") return [];
|
|
145
|
+
const matches = value.match(REFERENCE_REGEX);
|
|
146
|
+
if (!matches) return [];
|
|
147
|
+
return matches.map((match) => match.replace(curlyBracketRegex, "")).map((value) => {
|
|
148
|
+
return value.trim().split("/")[0];
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
const serializeTokenValue = (value) => {
|
|
152
|
+
if (isString(value)) return value;
|
|
153
|
+
if (isObject(value)) return Object.values(value).map((v) => serializeTokenValue(v)).join(" ");
|
|
154
|
+
if (Array.isArray(value)) return value.map((v) => serializeTokenValue(v)).join(" ");
|
|
155
|
+
return value.toString();
|
|
156
|
+
};
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/merge-config.ts
|
|
159
|
+
/**
|
|
160
|
+
* Collect all `extend` properties into an array (to avoid mutation)
|
|
161
|
+
*/
|
|
162
|
+
function getExtends(items) {
|
|
163
|
+
return items.reduce((merged, { extend }) => {
|
|
164
|
+
if (!extend) return merged;
|
|
165
|
+
return mergeWith(merged, extend, (originalValue, newValue) => {
|
|
166
|
+
if (newValue === void 0) return originalValue ?? [];
|
|
167
|
+
if (originalValue === void 0) return [newValue];
|
|
168
|
+
if (Array.isArray(originalValue)) return [newValue, ...originalValue];
|
|
169
|
+
return [newValue, originalValue];
|
|
170
|
+
});
|
|
171
|
+
}, {});
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Separate the `extend` properties from the rest of the object
|
|
175
|
+
*/
|
|
176
|
+
function mergeRecords(records) {
|
|
177
|
+
return {
|
|
178
|
+
...records.reduce((acc, record) => assign(acc, record), {}),
|
|
179
|
+
extend: getExtends(records)
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Merge all `extend` properties into the rest of the object
|
|
184
|
+
*/
|
|
185
|
+
function mergeExtensions(records) {
|
|
186
|
+
const { extend = [], ...restProps } = mergeRecords(records);
|
|
187
|
+
return mergeWith(restProps, extend, (obj, extensions) => {
|
|
188
|
+
return mergeAndConcat({}, obj, ...extensions);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
const isEmptyObject = (obj) => typeof obj === "object" && Object.keys(obj).length === 0;
|
|
192
|
+
const compact = (obj) => {
|
|
193
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
194
|
+
if (obj[key] !== void 0 && !isEmptyObject(obj[key])) acc[key] = obj[key];
|
|
195
|
+
return acc;
|
|
196
|
+
}, {});
|
|
197
|
+
};
|
|
198
|
+
const tokenKeys = [
|
|
199
|
+
"description",
|
|
200
|
+
"extensions",
|
|
201
|
+
"type",
|
|
202
|
+
"value",
|
|
203
|
+
"deprecated"
|
|
204
|
+
];
|
|
205
|
+
/**
|
|
206
|
+
* Merge all configs into a single config
|
|
207
|
+
*/
|
|
208
|
+
function mergeConfigs(configs) {
|
|
209
|
+
const userConfig = configs.at(-1);
|
|
210
|
+
const pluginHooks = userConfig.plugins ?? [];
|
|
211
|
+
if (userConfig.hooks) pluginHooks.push({
|
|
212
|
+
name: BAMBOO_CONFIG_NAME,
|
|
213
|
+
hooks: userConfig.hooks
|
|
214
|
+
});
|
|
215
|
+
const reversed = Array.from(configs).reverse();
|
|
216
|
+
const withoutEmpty = compact(assign({
|
|
217
|
+
conditions: mergeExtensions(reversed.map((config) => config.conditions ?? {})),
|
|
218
|
+
theme: mergeExtensions(reversed.map((config) => config.theme ?? {})),
|
|
219
|
+
patterns: mergeExtensions(reversed.map((config) => config.patterns ?? {})),
|
|
220
|
+
utilities: mergeExtensions(reversed.map((config) => config.utilities ?? {})),
|
|
221
|
+
globalCss: mergeExtensions(reversed.map((config) => config.globalCss ?? {})),
|
|
222
|
+
globalVars: mergeExtensions(reversed.map((config) => config.globalVars ?? {})),
|
|
223
|
+
globalFontface: mergeExtensions(reversed.map((config) => config.globalFontface ?? {})),
|
|
224
|
+
globalPositionTry: mergeExtensions(reversed.map((config) => config.globalPositionTry ?? {})),
|
|
225
|
+
staticCss: mergeExtensions(reversed.map((config) => config.staticCss ?? {})),
|
|
226
|
+
themes: mergeExtensions(reversed.map((config) => config.themes ?? {})),
|
|
227
|
+
hooks: mergeHooks(pluginHooks)
|
|
228
|
+
}, ...reversed));
|
|
229
|
+
/**
|
|
230
|
+
* Properly merge tokens between flat/nested forms by setting the flat form as the default
|
|
231
|
+
* preset:
|
|
232
|
+
* ```
|
|
233
|
+
* tokens: {
|
|
234
|
+
* black: {
|
|
235
|
+
* value: "black"
|
|
236
|
+
* }
|
|
237
|
+
* }
|
|
238
|
+
* // color: "black"
|
|
239
|
+
* ```
|
|
240
|
+
*
|
|
241
|
+
* config:
|
|
242
|
+
* ```
|
|
243
|
+
* tokens: {
|
|
244
|
+
* black: {
|
|
245
|
+
* 0: { value: "black" },
|
|
246
|
+
* 10: { value: "black/10" },
|
|
247
|
+
* 20: { value: "black/20" },
|
|
248
|
+
* // ...
|
|
249
|
+
* }
|
|
250
|
+
* }
|
|
251
|
+
*
|
|
252
|
+
* // color: "black.20"
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
if (withoutEmpty.theme?.tokens) walkObject(withoutEmpty.theme.tokens, (args) => args, { stop(token) {
|
|
256
|
+
if (!isValidToken(token)) return false;
|
|
257
|
+
if (Object.keys(token).filter((k) => !tokenKeys.includes(k)).length > 0) {
|
|
258
|
+
token.DEFAULT ||= {};
|
|
259
|
+
tokenKeys.forEach((key) => {
|
|
260
|
+
if (token[key] == null) return;
|
|
261
|
+
token.DEFAULT[key] ||= token[key];
|
|
262
|
+
delete token[key];
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
return true;
|
|
266
|
+
} });
|
|
267
|
+
return withoutEmpty;
|
|
268
|
+
}
|
|
269
|
+
//#endregion
|
|
270
|
+
export { isValidToken as a, isTokenReference as i, formatPath as n, serializeTokenValue as o, getReferences as r, mergeHooks as s, mergeConfigs as t };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BambooPlugin, Config } from "@bamboocss/types";
|
|
2
|
+
|
|
3
|
+
//#region src/merge-hooks.d.ts
|
|
4
|
+
declare const mergeHooks: (plugins: BambooPlugin[]) => BambooHooks;
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/merge-config.d.ts
|
|
7
|
+
type Extendable<T> = T & {
|
|
8
|
+
extend?: T;
|
|
9
|
+
};
|
|
10
|
+
type ExtendableConfig = Extendable<Config>;
|
|
11
|
+
/**
|
|
12
|
+
* Merge all configs into a single config
|
|
13
|
+
*/
|
|
14
|
+
declare function mergeConfigs(configs: ExtendableConfig[]): any;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { mergeHooks as n, mergeConfigs as t };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BambooPlugin, Config } from "@bamboocss/types";
|
|
2
|
+
|
|
3
|
+
//#region src/merge-hooks.d.ts
|
|
4
|
+
declare const mergeHooks: (plugins: BambooPlugin[]) => BambooHooks;
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/merge-config.d.ts
|
|
7
|
+
type Extendable<T> = T & {
|
|
8
|
+
extend?: T;
|
|
9
|
+
};
|
|
10
|
+
type ExtendableConfig = Extendable<Config>;
|
|
11
|
+
/**
|
|
12
|
+
* Merge all configs into a single config
|
|
13
|
+
*/
|
|
14
|
+
declare function mergeConfigs(configs: ExtendableConfig[]): any;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { mergeHooks as n, mergeConfigs as t };
|
package/dist/merge-config.mjs
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("./diff-config-Co_3mDXE.cjs");
|
|
3
|
+
let path = require("path");
|
|
4
|
+
//#region src/resolve-ts-path-pattern.ts
|
|
5
|
+
/**
|
|
6
|
+
* @see https://github.com/aleclarson/vite-tsconfig-paths/blob/e8f0acf7adfcfbf77edbe937f64b4e5d39557ad0/src/index.ts#LL231C57-L231C57
|
|
7
|
+
*/
|
|
8
|
+
const resolveTsPathPattern = (pathMappings, moduleSpecifier) => {
|
|
9
|
+
for (const mapping of pathMappings) {
|
|
10
|
+
const match = moduleSpecifier.match(mapping.pattern);
|
|
11
|
+
if (!match) continue;
|
|
12
|
+
for (const pathTemplate of mapping.paths) {
|
|
13
|
+
let starCount = 0;
|
|
14
|
+
return pathTemplate.replace(/\*/g, () => {
|
|
15
|
+
return match[Math.min(++starCount, match.length - 1)];
|
|
16
|
+
}).split(path.sep).join(path.posix.sep);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
exports.resolveTsPathPattern = resolveTsPathPattern;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { t as PathMapping } from "./ts-config-paths-wVx39QZ0.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/resolve-ts-path-pattern.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* @see https://github.com/aleclarson/vite-tsconfig-paths/blob/e8f0acf7adfcfbf77edbe937f64b4e5d39557ad0/src/index.ts#LL231C57-L231C57
|
|
6
|
+
*/
|
|
7
|
+
declare const resolveTsPathPattern: (pathMappings: PathMapping[], moduleSpecifier: string) => string | undefined;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { resolveTsPathPattern };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { t as PathMapping } from "./ts-config-paths-CvGId8kq.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/resolve-ts-path-pattern.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* @see https://github.com/aleclarson/vite-tsconfig-paths/blob/e8f0acf7adfcfbf77edbe937f64b4e5d39557ad0/src/index.ts#LL231C57-L231C57
|
|
6
|
+
*/
|
|
7
|
+
declare const resolveTsPathPattern: (pathMappings: PathMapping[], moduleSpecifier: string) => string | undefined;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { resolveTsPathPattern };
|