@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
package/dist/index.js
DELETED
|
@@ -1,1086 +0,0 @@
|
|
|
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/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
bundleConfig: () => bundleConfig,
|
|
34
|
-
convertTsPathsToRegexes: () => convertTsPathsToRegexes,
|
|
35
|
-
diffConfigs: () => diffConfigs,
|
|
36
|
-
findConfig: () => findConfig,
|
|
37
|
-
getConfigDependencies: () => getConfigDependencies,
|
|
38
|
-
getResolvedConfig: () => getResolvedConfig,
|
|
39
|
-
loadConfig: () => loadConfig,
|
|
40
|
-
mergeConfigs: () => mergeConfigs,
|
|
41
|
-
mergeHooks: () => mergeHooks,
|
|
42
|
-
resolveConfig: () => resolveConfig
|
|
43
|
-
});
|
|
44
|
-
module.exports = __toCommonJS(index_exports);
|
|
45
|
-
|
|
46
|
-
// src/bundle-config.ts
|
|
47
|
-
var import_logger = require("@bamboocss/logger");
|
|
48
|
-
var import_shared2 = require("@bamboocss/shared");
|
|
49
|
-
var import_bundle_n_require = require("bundle-n-require");
|
|
50
|
-
|
|
51
|
-
// src/find-config.ts
|
|
52
|
-
var import_shared = require("@bamboocss/shared");
|
|
53
|
-
var import_sync = __toESM(require("escalade/sync"));
|
|
54
|
-
var import_path = require("path");
|
|
55
|
-
|
|
56
|
-
// src/is-bamboo-config.ts
|
|
57
|
-
var configName = "bamboo";
|
|
58
|
-
var bambooConfigFiles = /* @__PURE__ */ new Set([
|
|
59
|
-
`${configName}.config.ts`,
|
|
60
|
-
`${configName}.config.js`,
|
|
61
|
-
`${configName}.config.mts`,
|
|
62
|
-
`${configName}.config.mjs`,
|
|
63
|
-
`${configName}.config.cts`,
|
|
64
|
-
`${configName}.config.cjs`
|
|
65
|
-
]);
|
|
66
|
-
var isBambooConfig = (file) => bambooConfigFiles.has(file);
|
|
67
|
-
|
|
68
|
-
// src/find-config.ts
|
|
69
|
-
function findConfig(options) {
|
|
70
|
-
const { cwd = process.cwd(), file } = options;
|
|
71
|
-
if (file) {
|
|
72
|
-
return (0, import_path.resolve)(cwd, file);
|
|
73
|
-
}
|
|
74
|
-
const configPath = (0, import_sync.default)(cwd, (_dir, paths) => paths.find(isBambooConfig));
|
|
75
|
-
if (!configPath) {
|
|
76
|
-
throw new import_shared.BambooError(
|
|
77
|
-
"CONFIG_NOT_FOUND",
|
|
78
|
-
`Cannot find config file \`bamboo.config.{ts,js,mjs,mts}\`. Did you forget to run \`bamboo init\`?`
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
return configPath;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// src/bundle-config.ts
|
|
85
|
-
async function bundle(filepath, cwd) {
|
|
86
|
-
const { mod, dependencies } = await (0, import_bundle_n_require.bundleNRequire)(filepath, {
|
|
87
|
-
cwd,
|
|
88
|
-
interopDefault: true
|
|
89
|
-
});
|
|
90
|
-
const config = mod?.default ?? mod;
|
|
91
|
-
return {
|
|
92
|
-
config,
|
|
93
|
-
dependencies
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
async function bundleConfig(options) {
|
|
97
|
-
const { cwd, file } = options;
|
|
98
|
-
const filePath = findConfig({ cwd, file });
|
|
99
|
-
import_logger.logger.debug("config:path", filePath);
|
|
100
|
-
const result = await bundle(filePath, cwd);
|
|
101
|
-
if (typeof result.config !== "object") {
|
|
102
|
-
throw new import_shared2.BambooError("CONFIG_ERROR", `\u{1F4A5} Config must export or return an object.`);
|
|
103
|
-
}
|
|
104
|
-
result.config.outdir ??= "styled-system";
|
|
105
|
-
result.config.validation ??= "warn";
|
|
106
|
-
return {
|
|
107
|
-
...result,
|
|
108
|
-
config: result.config,
|
|
109
|
-
path: filePath
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// src/diff-config.ts
|
|
114
|
-
var import_shared3 = require("@bamboocss/shared");
|
|
115
|
-
var import_microdiff = __toESM(require("microdiff"));
|
|
116
|
-
|
|
117
|
-
// src/create-matcher.ts
|
|
118
|
-
function createMatcher(id, patterns) {
|
|
119
|
-
if (!patterns?.length) return () => void 0;
|
|
120
|
-
const includePatterns = [];
|
|
121
|
-
const excludePatterns = [];
|
|
122
|
-
const deduped = new Set(patterns);
|
|
123
|
-
deduped.forEach((pattern) => {
|
|
124
|
-
const regexString = pattern.replace(/\*/g, ".*");
|
|
125
|
-
if (pattern.startsWith("!")) {
|
|
126
|
-
excludePatterns.push(regexString.slice(1));
|
|
127
|
-
} else {
|
|
128
|
-
includePatterns.push(regexString);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
const include = new RegExp(includePatterns.join("|"));
|
|
132
|
-
const exclude = new RegExp(excludePatterns.join("|"));
|
|
133
|
-
return (path2) => {
|
|
134
|
-
if (excludePatterns.length && exclude.test(path2)) return;
|
|
135
|
-
return include.test(path2) ? id : void 0;
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// src/config-deps.ts
|
|
140
|
-
var all = [
|
|
141
|
-
"clean",
|
|
142
|
-
"cwd",
|
|
143
|
-
"eject",
|
|
144
|
-
"outdir",
|
|
145
|
-
"forceConsistentTypeExtension",
|
|
146
|
-
"outExtension",
|
|
147
|
-
"emitTokensOnly",
|
|
148
|
-
"presets",
|
|
149
|
-
"plugins",
|
|
150
|
-
"hooks"
|
|
151
|
-
];
|
|
152
|
-
var format = [
|
|
153
|
-
"syntax",
|
|
154
|
-
"hash",
|
|
155
|
-
"prefix",
|
|
156
|
-
"separator",
|
|
157
|
-
"strictTokens",
|
|
158
|
-
"strictPropertyValues",
|
|
159
|
-
"shorthands"
|
|
160
|
-
];
|
|
161
|
-
var tokens = [
|
|
162
|
-
"utilities",
|
|
163
|
-
"conditions",
|
|
164
|
-
"theme.tokens",
|
|
165
|
-
"theme.semanticTokens",
|
|
166
|
-
"theme.breakpoints",
|
|
167
|
-
"theme.containerNames",
|
|
168
|
-
"theme.containerSizes"
|
|
169
|
-
];
|
|
170
|
-
var jsx = ["jsxFramework", "jsxFactory", "jsxStyleProps", "syntax"];
|
|
171
|
-
var common = tokens.concat(jsx, format);
|
|
172
|
-
var artifactConfigDeps = {
|
|
173
|
-
helpers: ["syntax", "jsxFramework"],
|
|
174
|
-
keyframes: ["theme.keyframes", "layers"],
|
|
175
|
-
"design-tokens": ["layers", "!utilities.*.className"].concat(tokens),
|
|
176
|
-
types: ["!utilities.*.className"].concat(common),
|
|
177
|
-
"css-fn": common,
|
|
178
|
-
cva: ["syntax"],
|
|
179
|
-
sva: ["syntax"],
|
|
180
|
-
cx: [],
|
|
181
|
-
"create-recipe": ["separator", "prefix", "hash"],
|
|
182
|
-
"recipes-index": ["theme.recipes", "theme.slotRecipes"],
|
|
183
|
-
recipes: ["theme.recipes", "theme.slotRecipes"],
|
|
184
|
-
"patterns-index": ["syntax", "patterns"],
|
|
185
|
-
patterns: ["syntax", "patterns"],
|
|
186
|
-
"jsx-is-valid-prop": common,
|
|
187
|
-
"jsx-factory": jsx,
|
|
188
|
-
"jsx-helpers": jsx,
|
|
189
|
-
"jsx-patterns": jsx.concat("patterns"),
|
|
190
|
-
"jsx-patterns-index": jsx.concat("patterns"),
|
|
191
|
-
"jsx-create-style-context": jsx,
|
|
192
|
-
"css-index": ["syntax"],
|
|
193
|
-
"package.json": ["forceConsistentTypeExtension", "outExtension"],
|
|
194
|
-
"types-styles": ["shorthands"],
|
|
195
|
-
"types-conditions": ["conditions"],
|
|
196
|
-
"types-jsx": jsx,
|
|
197
|
-
"types-entry": [],
|
|
198
|
-
"types-gen": [],
|
|
199
|
-
"types-gen-system": [],
|
|
200
|
-
themes: ["themes"].concat(tokens),
|
|
201
|
-
// staticCss depends on tokens (for wildcards) and recipes (for recipe rules)
|
|
202
|
-
"static-css": ["staticCss", "patterns", "theme.recipes", "theme.slotRecipes"].concat(tokens),
|
|
203
|
-
// Split CSS artifacts (generated via cssgen --splitting)
|
|
204
|
-
styles: [],
|
|
205
|
-
"styles.css": []
|
|
206
|
-
};
|
|
207
|
-
var artifactMatchers = Object.entries(artifactConfigDeps).map(([key, paths]) => {
|
|
208
|
-
if (!paths.length) return () => void 0;
|
|
209
|
-
return createMatcher(key, paths.concat(all));
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
// src/diff-config.ts
|
|
213
|
-
var runIfFn = (fn) => typeof fn === "function" ? fn() : fn;
|
|
214
|
-
var hasRecipeStateTransition = (prevConfig, nextConfig) => {
|
|
215
|
-
const prevRecipes = prevConfig.theme?.recipes ?? {};
|
|
216
|
-
const prevSlotRecipes = prevConfig.theme?.slotRecipes ?? {};
|
|
217
|
-
const prevHasRecipes = Object.keys(prevRecipes).length > 0 || Object.keys(prevSlotRecipes).length > 0;
|
|
218
|
-
const nextRecipes = nextConfig.theme?.recipes ?? {};
|
|
219
|
-
const nextSlotRecipes = nextConfig.theme?.slotRecipes ?? {};
|
|
220
|
-
const nextHasRecipes = Object.keys(nextRecipes).length > 0 || Object.keys(nextSlotRecipes).length > 0;
|
|
221
|
-
return prevHasRecipes !== nextHasRecipes;
|
|
222
|
-
};
|
|
223
|
-
function diffConfigs(config, prevConfig) {
|
|
224
|
-
const affected = {
|
|
225
|
-
artifacts: /* @__PURE__ */ new Set(),
|
|
226
|
-
hasConfigChanged: false,
|
|
227
|
-
diffs: []
|
|
228
|
-
};
|
|
229
|
-
if (!prevConfig) {
|
|
230
|
-
affected.hasConfigChanged = true;
|
|
231
|
-
return affected;
|
|
232
|
-
}
|
|
233
|
-
const configDiff = (0, import_microdiff.default)(prevConfig, runIfFn(config));
|
|
234
|
-
if (!configDiff.length) {
|
|
235
|
-
return affected;
|
|
236
|
-
}
|
|
237
|
-
affected.hasConfigChanged = true;
|
|
238
|
-
affected.diffs = configDiff;
|
|
239
|
-
configDiff.forEach((change) => {
|
|
240
|
-
const changePath = change.path.join(".");
|
|
241
|
-
artifactMatchers.forEach((matcher) => {
|
|
242
|
-
const id = matcher(changePath);
|
|
243
|
-
if (!id) return;
|
|
244
|
-
if (id === "recipes") {
|
|
245
|
-
const name = (0, import_shared3.dashCase)(change.path.slice(1, 3).join("."));
|
|
246
|
-
affected.artifacts.add(name);
|
|
247
|
-
}
|
|
248
|
-
if (id === "patterns") {
|
|
249
|
-
const name = (0, import_shared3.dashCase)(change.path.slice(0, 2).join("."));
|
|
250
|
-
affected.artifacts.add(name);
|
|
251
|
-
}
|
|
252
|
-
affected.artifacts.add(id);
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
if (affected.artifacts.has("recipes") || affected.artifacts.has("recipes-index")) {
|
|
256
|
-
const nextConfig = runIfFn(config);
|
|
257
|
-
if (hasRecipeStateTransition(prevConfig, nextConfig)) {
|
|
258
|
-
affected.artifacts.add("create-recipe");
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
return affected;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// src/get-mod-deps.ts
|
|
265
|
-
var import_fs = __toESM(require("fs"));
|
|
266
|
-
var import_path4 = __toESM(require("path"));
|
|
267
|
-
var import_typescript = __toESM(require("typescript"));
|
|
268
|
-
|
|
269
|
-
// src/resolve-ts-path-pattern.ts
|
|
270
|
-
var import_path2 = require("path");
|
|
271
|
-
var resolveTsPathPattern = (pathMappings, moduleSpecifier) => {
|
|
272
|
-
for (const mapping of pathMappings) {
|
|
273
|
-
const match = moduleSpecifier.match(mapping.pattern);
|
|
274
|
-
if (!match) {
|
|
275
|
-
continue;
|
|
276
|
-
}
|
|
277
|
-
for (const pathTemplate of mapping.paths) {
|
|
278
|
-
let starCount = 0;
|
|
279
|
-
const mappedId = pathTemplate.replace(/\*/g, () => {
|
|
280
|
-
const matchIndex = Math.min(++starCount, match.length - 1);
|
|
281
|
-
return match[matchIndex];
|
|
282
|
-
});
|
|
283
|
-
return mappedId.split(import_path2.sep).join(import_path2.posix.sep);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
// src/ts-config-paths.ts
|
|
289
|
-
var import_path3 = require("path");
|
|
290
|
-
function convertTsPathsToRegexes(paths, baseUrl) {
|
|
291
|
-
const sortedPatterns = Object.keys(paths).sort((a, b) => getPrefixLength(b) - getPrefixLength(a));
|
|
292
|
-
const resolved = [];
|
|
293
|
-
for (let pattern of sortedPatterns) {
|
|
294
|
-
const relativePaths = paths[pattern];
|
|
295
|
-
pattern = escapeStringRegexp(pattern).replace(/\*/g, "(.+)");
|
|
296
|
-
resolved.push({
|
|
297
|
-
pattern: new RegExp("^" + pattern + "$"),
|
|
298
|
-
paths: relativePaths.map((relativePath) => (0, import_path3.resolve)(baseUrl, relativePath))
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
return resolved;
|
|
302
|
-
}
|
|
303
|
-
function getPrefixLength(pattern) {
|
|
304
|
-
const prefixLength = pattern.indexOf("*");
|
|
305
|
-
return pattern.substr(0, prefixLength).length;
|
|
306
|
-
}
|
|
307
|
-
function escapeStringRegexp(string) {
|
|
308
|
-
return string.replace(/[|\\{}()[\]^$+?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// src/get-mod-deps.ts
|
|
312
|
-
var jsExtensions = [".js", ".cjs", ".mjs"];
|
|
313
|
-
var jsResolutionOrder = ["", ".js", ".cjs", ".mjs", ".ts", ".cts", ".mts", ".jsx", ".tsx"];
|
|
314
|
-
var tsResolutionOrder = ["", ".ts", ".cts", ".mts", ".tsx", ".js", ".cjs", ".mjs", ".jsx"];
|
|
315
|
-
function resolveWithExtension(file, extensions) {
|
|
316
|
-
for (const ext of extensions) {
|
|
317
|
-
const full = `${file}${ext}`;
|
|
318
|
-
if (import_fs.default.existsSync(full) && import_fs.default.statSync(full).isFile()) {
|
|
319
|
-
return full;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
for (const ext of extensions) {
|
|
323
|
-
const full = `${file}/index${ext}`;
|
|
324
|
-
if (import_fs.default.existsSync(full)) {
|
|
325
|
-
return full;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
return null;
|
|
329
|
-
}
|
|
330
|
-
var importRegex = /import[\s\S]*?['"](.{3,}?)['"]/gi;
|
|
331
|
-
var importFromRegex = /import[\s\S]*from[\s\S]*?['"](.{3,}?)['"]/gi;
|
|
332
|
-
var requireRegex = /require\(['"`](.+)['"`]\)/gi;
|
|
333
|
-
var exportRegex = /export[\s\S]*from[\s\S]*?['"](.{3,}?)['"]/gi;
|
|
334
|
-
function getDeps(opts, fromAlias) {
|
|
335
|
-
const { filename, seen } = opts;
|
|
336
|
-
const { moduleResolution: _, ...compilerOptions } = opts.compilerOptions ?? {};
|
|
337
|
-
const absoluteFile = resolveWithExtension(
|
|
338
|
-
import_path4.default.resolve(opts.cwd, filename),
|
|
339
|
-
jsExtensions.includes(opts.ext) ? jsResolutionOrder : tsResolutionOrder
|
|
340
|
-
);
|
|
341
|
-
if (absoluteFile === null) return;
|
|
342
|
-
if (fromAlias) {
|
|
343
|
-
opts.foundModuleAliases.set(fromAlias, absoluteFile);
|
|
344
|
-
}
|
|
345
|
-
if (seen.size > 1 && seen.has(absoluteFile)) return;
|
|
346
|
-
seen.add(absoluteFile);
|
|
347
|
-
const contents = import_fs.default.readFileSync(absoluteFile, "utf-8");
|
|
348
|
-
const fileDeps = [
|
|
349
|
-
...contents.matchAll(importRegex),
|
|
350
|
-
...contents.matchAll(importFromRegex),
|
|
351
|
-
...contents.matchAll(requireRegex),
|
|
352
|
-
...contents.matchAll(exportRegex)
|
|
353
|
-
];
|
|
354
|
-
if (!fileDeps.length) return;
|
|
355
|
-
const nextOpts = {
|
|
356
|
-
// Resolve new base for new imports/requires
|
|
357
|
-
cwd: import_path4.default.dirname(absoluteFile),
|
|
358
|
-
ext: import_path4.default.extname(absoluteFile),
|
|
359
|
-
seen,
|
|
360
|
-
baseUrl: opts.baseUrl,
|
|
361
|
-
pathMappings: opts.pathMappings,
|
|
362
|
-
foundModuleAliases: opts.foundModuleAliases
|
|
363
|
-
};
|
|
364
|
-
fileDeps.forEach((match) => {
|
|
365
|
-
const mod = match[1];
|
|
366
|
-
if (mod[0] === ".") {
|
|
367
|
-
getDeps(Object.assign({}, nextOpts, { filename: mod }));
|
|
368
|
-
return;
|
|
369
|
-
}
|
|
370
|
-
try {
|
|
371
|
-
const found = import_typescript.default.resolveModuleName(mod, absoluteFile, compilerOptions, import_typescript.default.sys).resolvedModule;
|
|
372
|
-
if (found && found.extension.endsWith("ts")) {
|
|
373
|
-
getDeps(Object.assign({}, nextOpts, { filename: found.resolvedFileName }));
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
if (!opts.pathMappings) return;
|
|
377
|
-
const filename2 = resolveTsPathPattern(opts.pathMappings, mod);
|
|
378
|
-
if (!filename2) return;
|
|
379
|
-
getDeps(Object.assign({}, nextOpts, { filename: filename2 }), mod);
|
|
380
|
-
} catch {
|
|
381
|
-
}
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
function getConfigDependencies(filePath, tsOptions = { pathMappings: [] }, compilerOptions) {
|
|
385
|
-
if (filePath === null) return { deps: /* @__PURE__ */ new Set(), aliases: /* @__PURE__ */ new Map() };
|
|
386
|
-
const foundModuleAliases = /* @__PURE__ */ new Map();
|
|
387
|
-
const deps = /* @__PURE__ */ new Set();
|
|
388
|
-
deps.add(filePath);
|
|
389
|
-
getDeps({
|
|
390
|
-
filename: filePath,
|
|
391
|
-
ext: import_path4.default.extname(filePath),
|
|
392
|
-
cwd: import_path4.default.dirname(filePath),
|
|
393
|
-
seen: deps,
|
|
394
|
-
baseUrl: tsOptions.baseUrl,
|
|
395
|
-
pathMappings: tsOptions.pathMappings ?? [],
|
|
396
|
-
foundModuleAliases,
|
|
397
|
-
compilerOptions
|
|
398
|
-
});
|
|
399
|
-
return { deps, aliases: foundModuleAliases };
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
// src/get-resolved-config.ts
|
|
403
|
-
var import_shared6 = require("@bamboocss/shared");
|
|
404
|
-
|
|
405
|
-
// src/merge-config.ts
|
|
406
|
-
var import_shared5 = require("@bamboocss/shared");
|
|
407
|
-
|
|
408
|
-
// src/merge-hooks.ts
|
|
409
|
-
var import_logger2 = require("@bamboocss/logger");
|
|
410
|
-
var mergeHooks = (plugins) => {
|
|
411
|
-
const hooksFns = {};
|
|
412
|
-
plugins.forEach(({ name, hooks }) => {
|
|
413
|
-
Object.entries(hooks ?? {}).forEach(([key, value]) => {
|
|
414
|
-
if (!hooksFns[key]) {
|
|
415
|
-
hooksFns[key] = [];
|
|
416
|
-
}
|
|
417
|
-
hooksFns[key].push([name, value]);
|
|
418
|
-
});
|
|
419
|
-
});
|
|
420
|
-
const mergedHooks = Object.fromEntries(
|
|
421
|
-
Object.entries(hooksFns).map(([key, entries]) => {
|
|
422
|
-
const fns = entries.map(([name, fn]) => tryCatch(name, fn));
|
|
423
|
-
const reducer = key in reducers ? reducers[key] : void 0;
|
|
424
|
-
if (reducer) {
|
|
425
|
-
return [key, reducer(fns)];
|
|
426
|
-
}
|
|
427
|
-
return [key, syncHooks.includes(key) ? callAll(...fns) : callAllAsync(...fns)];
|
|
428
|
-
})
|
|
429
|
-
);
|
|
430
|
-
return mergedHooks;
|
|
431
|
-
};
|
|
432
|
-
var createReducer = (reducer) => reducer;
|
|
433
|
-
var reducers = {
|
|
434
|
-
"config:resolved": createReducer((fns) => async (_args) => {
|
|
435
|
-
const args = Object.assign({}, _args);
|
|
436
|
-
const original = _args.config;
|
|
437
|
-
let config = args.config;
|
|
438
|
-
for (const hookFn of fns) {
|
|
439
|
-
const result = await hookFn(Object.assign(args, { config, original }));
|
|
440
|
-
if (result !== void 0) {
|
|
441
|
-
config = result;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
return config;
|
|
445
|
-
}),
|
|
446
|
-
"parser:before": createReducer((fns) => (_args) => {
|
|
447
|
-
const args = Object.assign({}, _args);
|
|
448
|
-
const original = _args.content;
|
|
449
|
-
let content = args.content;
|
|
450
|
-
for (const hookFn of fns) {
|
|
451
|
-
const result = hookFn(Object.assign(args, { content, original }));
|
|
452
|
-
if (result !== void 0) {
|
|
453
|
-
content = result;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
return content;
|
|
457
|
-
}),
|
|
458
|
-
"parser:preprocess": createReducer((fns) => (_args) => {
|
|
459
|
-
const args = Object.assign({}, _args);
|
|
460
|
-
const original = _args.data;
|
|
461
|
-
let data = args.data;
|
|
462
|
-
for (const hookFn of fns) {
|
|
463
|
-
const result = hookFn(Object.assign(args, { data, original }));
|
|
464
|
-
if (result !== void 0) {
|
|
465
|
-
data = result;
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
return data;
|
|
469
|
-
}),
|
|
470
|
-
"cssgen:done": createReducer((fns) => (_args) => {
|
|
471
|
-
const args = Object.assign({}, _args);
|
|
472
|
-
const original = _args.content;
|
|
473
|
-
let content = args.content;
|
|
474
|
-
for (const hookFn of fns) {
|
|
475
|
-
const result = hookFn(Object.assign(args, { content, original }));
|
|
476
|
-
if (result !== void 0) {
|
|
477
|
-
content = result;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
return content;
|
|
481
|
-
}),
|
|
482
|
-
"codegen:prepare": createReducer((fns) => async (_args) => {
|
|
483
|
-
const args = Object.assign({}, _args);
|
|
484
|
-
const original = _args.artifacts;
|
|
485
|
-
let artifacts = args.artifacts;
|
|
486
|
-
for (const hookFn of fns) {
|
|
487
|
-
const result = await hookFn(Object.assign(args, { artifacts, original }));
|
|
488
|
-
if (result) {
|
|
489
|
-
artifacts = result;
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
return artifacts;
|
|
493
|
-
}),
|
|
494
|
-
"preset:resolved": createReducer((fns) => async (_args) => {
|
|
495
|
-
const args = Object.assign({}, _args);
|
|
496
|
-
const original = _args.preset;
|
|
497
|
-
let preset = args.preset;
|
|
498
|
-
for (const hookFn of fns) {
|
|
499
|
-
const result = await hookFn(Object.assign(args, { preset, original }));
|
|
500
|
-
if (result !== void 0) {
|
|
501
|
-
preset = result;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
return preset;
|
|
505
|
-
}),
|
|
506
|
-
"css:optimize": createReducer((fns) => (_args) => {
|
|
507
|
-
const args = Object.assign({}, _args);
|
|
508
|
-
const original = _args.css;
|
|
509
|
-
let css = args.css;
|
|
510
|
-
for (const hookFn of fns) {
|
|
511
|
-
const result = hookFn(Object.assign(args, { css, original }));
|
|
512
|
-
if (result !== void 0) {
|
|
513
|
-
css = result;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
return css;
|
|
517
|
-
})
|
|
518
|
-
};
|
|
519
|
-
var syncHooks = [
|
|
520
|
-
"context:created",
|
|
521
|
-
"parser:before",
|
|
522
|
-
"parser:preprocess",
|
|
523
|
-
"parser:after",
|
|
524
|
-
"cssgen:done",
|
|
525
|
-
"css:optimize"
|
|
526
|
-
];
|
|
527
|
-
var callAllAsync = (...fns) => async (...a) => {
|
|
528
|
-
for (const fn of fns) {
|
|
529
|
-
await fn?.(...a);
|
|
530
|
-
}
|
|
531
|
-
};
|
|
532
|
-
var callAll = (...fns) => (...a) => {
|
|
533
|
-
fns.forEach((fn) => fn?.(...a));
|
|
534
|
-
};
|
|
535
|
-
var tryCatch = (name, fn) => {
|
|
536
|
-
return (...args) => {
|
|
537
|
-
try {
|
|
538
|
-
return fn(...args);
|
|
539
|
-
} catch (e) {
|
|
540
|
-
import_logger2.logger.caughtError("hooks", `Error in plugin "${name}"`, e);
|
|
541
|
-
}
|
|
542
|
-
};
|
|
543
|
-
};
|
|
544
|
-
|
|
545
|
-
// src/validation/utils.ts
|
|
546
|
-
var import_shared4 = require("@bamboocss/shared");
|
|
547
|
-
var REFERENCE_REGEX = /({([^}]*)})/g;
|
|
548
|
-
var curlyBracketRegex = /[{}]/g;
|
|
549
|
-
var isValidToken = (token) => (0, import_shared4.isObject)(token) && Object.hasOwnProperty.call(token, "value");
|
|
550
|
-
var isTokenReference = (value) => typeof value === "string" && REFERENCE_REGEX.test(value);
|
|
551
|
-
var formatPath = (path2) => path2;
|
|
552
|
-
var SEP = ".";
|
|
553
|
-
function getReferences(value) {
|
|
554
|
-
if (typeof value !== "string") return [];
|
|
555
|
-
const matches = value.match(REFERENCE_REGEX);
|
|
556
|
-
if (!matches) return [];
|
|
557
|
-
return matches.map((match) => match.replace(curlyBracketRegex, "")).map((value2) => {
|
|
558
|
-
return value2.trim().split("/")[0];
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
var serializeTokenValue = (value) => {
|
|
562
|
-
if ((0, import_shared4.isString)(value)) {
|
|
563
|
-
return value;
|
|
564
|
-
}
|
|
565
|
-
if ((0, import_shared4.isObject)(value)) {
|
|
566
|
-
return Object.values(value).map((v) => serializeTokenValue(v)).join(" ");
|
|
567
|
-
}
|
|
568
|
-
if (Array.isArray(value)) {
|
|
569
|
-
return value.map((v) => serializeTokenValue(v)).join(" ");
|
|
570
|
-
}
|
|
571
|
-
return value.toString();
|
|
572
|
-
};
|
|
573
|
-
|
|
574
|
-
// src/merge-config.ts
|
|
575
|
-
function getExtends(items) {
|
|
576
|
-
return items.reduce((merged, { extend }) => {
|
|
577
|
-
if (!extend) return merged;
|
|
578
|
-
return (0, import_shared5.mergeWith)(merged, extend, (originalValue, newValue) => {
|
|
579
|
-
if (newValue === void 0) {
|
|
580
|
-
return originalValue ?? [];
|
|
581
|
-
}
|
|
582
|
-
if (originalValue === void 0) {
|
|
583
|
-
return [newValue];
|
|
584
|
-
}
|
|
585
|
-
if (Array.isArray(originalValue)) {
|
|
586
|
-
return [newValue, ...originalValue];
|
|
587
|
-
}
|
|
588
|
-
return [newValue, originalValue];
|
|
589
|
-
});
|
|
590
|
-
}, {});
|
|
591
|
-
}
|
|
592
|
-
function mergeRecords(records) {
|
|
593
|
-
return {
|
|
594
|
-
...records.reduce((acc, record) => (0, import_shared5.assign)(acc, record), {}),
|
|
595
|
-
extend: getExtends(records)
|
|
596
|
-
};
|
|
597
|
-
}
|
|
598
|
-
function mergeExtensions(records) {
|
|
599
|
-
const { extend = [], ...restProps } = mergeRecords(records);
|
|
600
|
-
return (0, import_shared5.mergeWith)(restProps, extend, (obj, extensions) => {
|
|
601
|
-
return (0, import_shared5.mergeAndConcat)({}, obj, ...extensions);
|
|
602
|
-
});
|
|
603
|
-
}
|
|
604
|
-
var isEmptyObject = (obj) => typeof obj === "object" && Object.keys(obj).length === 0;
|
|
605
|
-
var compact = (obj) => {
|
|
606
|
-
return Object.keys(obj).reduce((acc, key) => {
|
|
607
|
-
if (obj[key] !== void 0 && !isEmptyObject(obj[key])) {
|
|
608
|
-
acc[key] = obj[key];
|
|
609
|
-
}
|
|
610
|
-
return acc;
|
|
611
|
-
}, {});
|
|
612
|
-
};
|
|
613
|
-
var tokenKeys = ["description", "extensions", "type", "value", "deprecated"];
|
|
614
|
-
function mergeConfigs(configs) {
|
|
615
|
-
const userConfig = configs.at(-1);
|
|
616
|
-
const pluginHooks = userConfig.plugins ?? [];
|
|
617
|
-
if (userConfig.hooks) {
|
|
618
|
-
pluginHooks.push({ name: import_shared5.BAMBOO_CONFIG_NAME, hooks: userConfig.hooks });
|
|
619
|
-
}
|
|
620
|
-
const reversed = Array.from(configs).reverse();
|
|
621
|
-
const mergedResult = (0, import_shared5.assign)(
|
|
622
|
-
{
|
|
623
|
-
conditions: mergeExtensions(reversed.map((config) => config.conditions ?? {})),
|
|
624
|
-
theme: mergeExtensions(reversed.map((config) => config.theme ?? {})),
|
|
625
|
-
patterns: mergeExtensions(reversed.map((config) => config.patterns ?? {})),
|
|
626
|
-
utilities: mergeExtensions(reversed.map((config) => config.utilities ?? {})),
|
|
627
|
-
globalCss: mergeExtensions(reversed.map((config) => config.globalCss ?? {})),
|
|
628
|
-
globalVars: mergeExtensions(reversed.map((config) => config.globalVars ?? {})),
|
|
629
|
-
globalFontface: mergeExtensions(reversed.map((config) => config.globalFontface ?? {})),
|
|
630
|
-
globalPositionTry: mergeExtensions(reversed.map((config) => config.globalPositionTry ?? {})),
|
|
631
|
-
staticCss: mergeExtensions(reversed.map((config) => config.staticCss ?? {})),
|
|
632
|
-
themes: mergeExtensions(reversed.map((config) => config.themes ?? {})),
|
|
633
|
-
hooks: mergeHooks(pluginHooks)
|
|
634
|
-
},
|
|
635
|
-
...reversed
|
|
636
|
-
);
|
|
637
|
-
const withoutEmpty = compact(mergedResult);
|
|
638
|
-
if (withoutEmpty.theme?.tokens) {
|
|
639
|
-
(0, import_shared5.walkObject)(withoutEmpty.theme.tokens, (args) => args, {
|
|
640
|
-
stop(token) {
|
|
641
|
-
if (!isValidToken(token)) return false;
|
|
642
|
-
const keys = Object.keys(token);
|
|
643
|
-
const nestedKeys = keys.filter((k) => !tokenKeys.includes(k));
|
|
644
|
-
const nested = nestedKeys.length > 0;
|
|
645
|
-
if (nested) {
|
|
646
|
-
token.DEFAULT ||= {};
|
|
647
|
-
tokenKeys.forEach((key) => {
|
|
648
|
-
if (token[key] == null) return;
|
|
649
|
-
token.DEFAULT[key] ||= token[key];
|
|
650
|
-
delete token[key];
|
|
651
|
-
});
|
|
652
|
-
}
|
|
653
|
-
return true;
|
|
654
|
-
}
|
|
655
|
-
});
|
|
656
|
-
}
|
|
657
|
-
return withoutEmpty;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
// src/get-resolved-config.ts
|
|
661
|
-
var hookUtils = {
|
|
662
|
-
omit: import_shared6.omit,
|
|
663
|
-
pick: import_shared6.pick,
|
|
664
|
-
traverse: import_shared6.traverse
|
|
665
|
-
};
|
|
666
|
-
async function getResolvedConfig(config, cwd, hooks) {
|
|
667
|
-
const stack = [config];
|
|
668
|
-
const configs = [];
|
|
669
|
-
while (stack.length > 0) {
|
|
670
|
-
const current = stack.pop();
|
|
671
|
-
const subPresets = current.presets ?? [];
|
|
672
|
-
for (const subPreset of subPresets) {
|
|
673
|
-
let presetConfig;
|
|
674
|
-
let presetName;
|
|
675
|
-
if (typeof subPreset === "string") {
|
|
676
|
-
const presetModule = await bundle(subPreset, cwd);
|
|
677
|
-
presetConfig = presetModule.config;
|
|
678
|
-
presetName = subPreset;
|
|
679
|
-
} else {
|
|
680
|
-
presetConfig = await subPreset;
|
|
681
|
-
presetName = presetConfig.name || "unknown-preset";
|
|
682
|
-
}
|
|
683
|
-
if (hooks?.["preset:resolved"]) {
|
|
684
|
-
const resolvedPreset = await hooks["preset:resolved"]({
|
|
685
|
-
preset: presetConfig,
|
|
686
|
-
name: presetName,
|
|
687
|
-
utils: hookUtils
|
|
688
|
-
});
|
|
689
|
-
if (resolvedPreset !== void 0) {
|
|
690
|
-
presetConfig = resolvedPreset;
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
stack.push(presetConfig);
|
|
694
|
-
}
|
|
695
|
-
configs.unshift(current);
|
|
696
|
-
}
|
|
697
|
-
const merged = mergeConfigs(configs);
|
|
698
|
-
merged.presets = configs.slice(0, -1);
|
|
699
|
-
return merged;
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
// src/resolve-config.ts
|
|
703
|
-
var import_logger4 = require("@bamboocss/logger");
|
|
704
|
-
var import_shared11 = require("@bamboocss/shared");
|
|
705
|
-
|
|
706
|
-
// src/bundled-preset.ts
|
|
707
|
-
var import_preset_base = require("@bamboocss/preset-base");
|
|
708
|
-
var import_preset_bamboo = require("@bamboocss/preset-bamboo");
|
|
709
|
-
var bundledPresets = {
|
|
710
|
-
"@bamboocss/preset-base": import_preset_base.preset,
|
|
711
|
-
"@bamboocss/preset-bamboo": import_preset_bamboo.preset,
|
|
712
|
-
"@bamboocss/dev/presets": import_preset_bamboo.preset
|
|
713
|
-
};
|
|
714
|
-
var bundledPresetsNames = Object.keys(bundledPresets);
|
|
715
|
-
var isBundledPreset = (preset) => bundledPresetsNames.includes(preset);
|
|
716
|
-
var getBundledPreset = (preset) => {
|
|
717
|
-
return typeof preset === "string" && isBundledPreset(preset) ? bundledPresets[preset] : void 0;
|
|
718
|
-
};
|
|
719
|
-
|
|
720
|
-
// src/validate-config.ts
|
|
721
|
-
var import_logger3 = require("@bamboocss/logger");
|
|
722
|
-
var import_shared10 = require("@bamboocss/shared");
|
|
723
|
-
|
|
724
|
-
// src/validation/validate-artifact.ts
|
|
725
|
-
var validateArtifactNames = (names, addError) => {
|
|
726
|
-
names.recipes.forEach((recipeName) => {
|
|
727
|
-
if (names.slotRecipes.has(recipeName)) {
|
|
728
|
-
addError("recipes", `This recipe name is already used in \`theme.slotRecipes\`: ${recipeName}`);
|
|
729
|
-
}
|
|
730
|
-
if (names.patterns.has(recipeName)) {
|
|
731
|
-
addError("recipes", `This recipe name is already used in \`patterns\`: \`${recipeName}\``);
|
|
732
|
-
}
|
|
733
|
-
});
|
|
734
|
-
names.slotRecipes.forEach((recipeName) => {
|
|
735
|
-
if (names.patterns.has(recipeName)) {
|
|
736
|
-
addError("recipes", `This recipe name is already used in \`patterns\`: ${recipeName}`);
|
|
737
|
-
}
|
|
738
|
-
});
|
|
739
|
-
};
|
|
740
|
-
|
|
741
|
-
// src/validation/validate-breakpoints.ts
|
|
742
|
-
var import_shared7 = require("@bamboocss/shared");
|
|
743
|
-
var validateBreakpoints = (breakpoints, addError) => {
|
|
744
|
-
if (!breakpoints) return;
|
|
745
|
-
const units = /* @__PURE__ */ new Set();
|
|
746
|
-
const values = Object.values(breakpoints);
|
|
747
|
-
for (const value of values) {
|
|
748
|
-
const unit = (0, import_shared7.getUnit)(value) ?? "px";
|
|
749
|
-
units.add(unit);
|
|
750
|
-
}
|
|
751
|
-
if (units.size > 1) {
|
|
752
|
-
addError("breakpoints", `All breakpoints must use the same unit: \`${values.join(", ")}\``);
|
|
753
|
-
}
|
|
754
|
-
};
|
|
755
|
-
|
|
756
|
-
// src/validation/validate-condition.ts
|
|
757
|
-
var import_shared8 = require("@bamboocss/shared");
|
|
758
|
-
var validateObjectCondition = (obj, addError) => {
|
|
759
|
-
let hasSlot = false;
|
|
760
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
761
|
-
if (!key.startsWith("@") && !key.includes("&")) {
|
|
762
|
-
addError("conditions", `Selectors should contain the \`&\` character: \`${key}\``);
|
|
763
|
-
}
|
|
764
|
-
if (value === "@slot") {
|
|
765
|
-
hasSlot = true;
|
|
766
|
-
continue;
|
|
767
|
-
}
|
|
768
|
-
if (typeof value === "string") {
|
|
769
|
-
addError(
|
|
770
|
-
"conditions",
|
|
771
|
-
`Object condition leaves must be the literal string \`'@slot'\`, got \`${JSON.stringify(value)}\` at \`${key}\``
|
|
772
|
-
);
|
|
773
|
-
continue;
|
|
774
|
-
}
|
|
775
|
-
if (typeof value === "object" && value !== null) {
|
|
776
|
-
const nested = validateObjectCondition(value, addError);
|
|
777
|
-
if (nested.hasSlot) hasSlot = true;
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
return { hasSlot };
|
|
781
|
-
};
|
|
782
|
-
var validateConditions = (conditions, addError) => {
|
|
783
|
-
if (!conditions) return;
|
|
784
|
-
Object.values(conditions).forEach((condition) => {
|
|
785
|
-
if ((0, import_shared8.isString)(condition)) {
|
|
786
|
-
if (!condition.startsWith("@") && !condition.includes("&")) {
|
|
787
|
-
addError("conditions", `Selectors should contain the \`&\` character: \`${condition}\``);
|
|
788
|
-
}
|
|
789
|
-
return;
|
|
790
|
-
}
|
|
791
|
-
if (Array.isArray(condition)) {
|
|
792
|
-
condition.forEach((c) => {
|
|
793
|
-
if (!c.startsWith("@") && !c.includes("&")) {
|
|
794
|
-
addError("conditions", `Selectors should contain the \`&\` character: \`${c}\``);
|
|
795
|
-
}
|
|
796
|
-
});
|
|
797
|
-
return;
|
|
798
|
-
}
|
|
799
|
-
const { hasSlot } = validateObjectCondition(condition, addError);
|
|
800
|
-
if (!hasSlot) {
|
|
801
|
-
addError("conditions", `Object conditions must contain at least one \`'@slot'\` marker`);
|
|
802
|
-
}
|
|
803
|
-
});
|
|
804
|
-
};
|
|
805
|
-
|
|
806
|
-
// src/validation/validate-patterns.ts
|
|
807
|
-
var validatePatterns = (patterns, names) => {
|
|
808
|
-
if (!patterns) return;
|
|
809
|
-
Object.keys(patterns).forEach((patternName) => {
|
|
810
|
-
names.patterns.add(patternName);
|
|
811
|
-
});
|
|
812
|
-
};
|
|
813
|
-
|
|
814
|
-
// src/validation/validate-recipes.ts
|
|
815
|
-
var validateRecipes = (options) => {
|
|
816
|
-
const {
|
|
817
|
-
config: { theme },
|
|
818
|
-
artifacts
|
|
819
|
-
} = options;
|
|
820
|
-
if (!theme) return;
|
|
821
|
-
if (theme.recipes) {
|
|
822
|
-
Object.keys(theme.recipes).forEach((recipeName) => {
|
|
823
|
-
artifacts.recipes.add(recipeName);
|
|
824
|
-
});
|
|
825
|
-
}
|
|
826
|
-
if (theme.slotRecipes) {
|
|
827
|
-
Object.keys(theme.slotRecipes).forEach((recipeName) => {
|
|
828
|
-
artifacts.slotRecipes.add(recipeName);
|
|
829
|
-
});
|
|
830
|
-
}
|
|
831
|
-
return artifacts;
|
|
832
|
-
};
|
|
833
|
-
|
|
834
|
-
// src/validation/validate-tokens.ts
|
|
835
|
-
var import_shared9 = require("@bamboocss/shared");
|
|
836
|
-
|
|
837
|
-
// src/validation/validate-token-references.ts
|
|
838
|
-
var validateTokenReferences = (props) => {
|
|
839
|
-
const { valueAtPath, refsByPath, addError, typeByPath } = props;
|
|
840
|
-
refsByPath.forEach((refs, path2) => {
|
|
841
|
-
if (refs.has(path2)) {
|
|
842
|
-
addError("tokens", `Self token reference: \`${path2}\``);
|
|
843
|
-
}
|
|
844
|
-
const stack = [path2];
|
|
845
|
-
while (stack.length > 0) {
|
|
846
|
-
let currentPath = stack.pop();
|
|
847
|
-
if (currentPath.includes("/")) {
|
|
848
|
-
const [tokenPath] = currentPath.split("/");
|
|
849
|
-
currentPath = tokenPath;
|
|
850
|
-
}
|
|
851
|
-
const value = valueAtPath.get(currentPath);
|
|
852
|
-
if (!value) {
|
|
853
|
-
const configKey = typeByPath.get(path2);
|
|
854
|
-
addError("tokens", `Missing token: \`${currentPath}\` used in \`theme.${configKey}.${path2}\``);
|
|
855
|
-
}
|
|
856
|
-
if (isTokenReference(value) && !refsByPath.has(value)) {
|
|
857
|
-
addError("tokens", `Unknown token reference: \`${currentPath}\` used in \`${value}\``);
|
|
858
|
-
}
|
|
859
|
-
const deps = refsByPath.get(currentPath);
|
|
860
|
-
if (!deps) continue;
|
|
861
|
-
for (const transitiveDep of deps) {
|
|
862
|
-
if (path2 === transitiveDep) {
|
|
863
|
-
addError(
|
|
864
|
-
"tokens",
|
|
865
|
-
`Circular token reference: \`${transitiveDep}\` -> \`${currentPath}\` -> ... -> \`${path2}\``
|
|
866
|
-
);
|
|
867
|
-
break;
|
|
868
|
-
}
|
|
869
|
-
stack.push(transitiveDep);
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
});
|
|
873
|
-
};
|
|
874
|
-
|
|
875
|
-
// src/validation/validate-tokens.ts
|
|
876
|
-
var validateTokens = (options) => {
|
|
877
|
-
const {
|
|
878
|
-
config: { theme },
|
|
879
|
-
tokens: tokens2,
|
|
880
|
-
addError
|
|
881
|
-
} = options;
|
|
882
|
-
if (!theme) return;
|
|
883
|
-
const { tokenNames, semanticTokenNames, valueAtPath, refsByPath, typeByPath } = tokens2;
|
|
884
|
-
if (theme.tokens) {
|
|
885
|
-
const tokenPaths = /* @__PURE__ */ new Set();
|
|
886
|
-
(0, import_shared9.walkObject)(
|
|
887
|
-
theme.tokens,
|
|
888
|
-
(value, paths) => {
|
|
889
|
-
const path2 = paths.join(SEP);
|
|
890
|
-
tokenNames.add(path2);
|
|
891
|
-
tokenPaths.add(path2);
|
|
892
|
-
valueAtPath.set(path2, value);
|
|
893
|
-
if (path2.includes("DEFAULT")) {
|
|
894
|
-
valueAtPath.set(path2.replace(SEP + "DEFAULT", ""), value);
|
|
895
|
-
}
|
|
896
|
-
},
|
|
897
|
-
{
|
|
898
|
-
stop: isValidToken
|
|
899
|
-
}
|
|
900
|
-
);
|
|
901
|
-
tokenPaths.forEach((path2) => {
|
|
902
|
-
const itemValue = valueAtPath.get(path2);
|
|
903
|
-
const formattedPath = formatPath(path2);
|
|
904
|
-
typeByPath.set(formattedPath, "tokens");
|
|
905
|
-
if (!isValidToken(itemValue)) {
|
|
906
|
-
addError("tokens", `Token must contain 'value': \`theme.tokens.${formattedPath}\``);
|
|
907
|
-
return;
|
|
908
|
-
}
|
|
909
|
-
if (path2.includes(" ")) {
|
|
910
|
-
addError("tokens", `Token key must not contain spaces: \`theme.tokens.${formattedPath}\``);
|
|
911
|
-
return;
|
|
912
|
-
}
|
|
913
|
-
const valueStr = serializeTokenValue(itemValue.value || itemValue);
|
|
914
|
-
if (isTokenReference(valueStr)) {
|
|
915
|
-
refsByPath.set(formattedPath, /* @__PURE__ */ new Set([]));
|
|
916
|
-
}
|
|
917
|
-
const references = refsByPath.get(formattedPath);
|
|
918
|
-
if (!references) return;
|
|
919
|
-
getReferences(valueStr).forEach((reference) => {
|
|
920
|
-
references.add(reference);
|
|
921
|
-
});
|
|
922
|
-
});
|
|
923
|
-
}
|
|
924
|
-
if (theme.semanticTokens) {
|
|
925
|
-
const tokenPaths = /* @__PURE__ */ new Set();
|
|
926
|
-
(0, import_shared9.walkObject)(
|
|
927
|
-
theme.semanticTokens,
|
|
928
|
-
(value, paths) => {
|
|
929
|
-
const path2 = paths.join(SEP);
|
|
930
|
-
semanticTokenNames.add(path2);
|
|
931
|
-
valueAtPath.set(path2, value);
|
|
932
|
-
tokenPaths.add(path2);
|
|
933
|
-
if (path2.includes("DEFAULT")) {
|
|
934
|
-
valueAtPath.set(path2.replace(SEP + "DEFAULT", ""), value);
|
|
935
|
-
}
|
|
936
|
-
if (!isValidToken(value)) return;
|
|
937
|
-
(0, import_shared9.walkObject)(value, (itemValue, paths2) => {
|
|
938
|
-
const valuePath = paths2.join(SEP);
|
|
939
|
-
const formattedPath = formatPath(path2);
|
|
940
|
-
typeByPath.set(formattedPath, "semanticTokens");
|
|
941
|
-
const fullPath = formattedPath + "." + paths2.join(SEP);
|
|
942
|
-
if (valuePath.includes("value" + SEP + "value")) {
|
|
943
|
-
addError("tokens", `You used \`value\` twice resulting in an invalid token \`theme.tokens.${fullPath}\``);
|
|
944
|
-
}
|
|
945
|
-
const valueStr = serializeTokenValue(itemValue.value || itemValue);
|
|
946
|
-
if (isTokenReference(valueStr)) {
|
|
947
|
-
if (!refsByPath.has(formattedPath)) {
|
|
948
|
-
refsByPath.set(formattedPath, /* @__PURE__ */ new Set());
|
|
949
|
-
}
|
|
950
|
-
const references = refsByPath.get(formattedPath);
|
|
951
|
-
if (!references) return;
|
|
952
|
-
getReferences(valueStr).forEach((reference) => {
|
|
953
|
-
references.add(reference);
|
|
954
|
-
});
|
|
955
|
-
}
|
|
956
|
-
});
|
|
957
|
-
},
|
|
958
|
-
{
|
|
959
|
-
stop: isValidToken
|
|
960
|
-
}
|
|
961
|
-
);
|
|
962
|
-
tokenPaths.forEach((path2) => {
|
|
963
|
-
const formattedPath = formatPath(path2);
|
|
964
|
-
const value = valueAtPath.get(path2);
|
|
965
|
-
if (path2.includes(" ")) {
|
|
966
|
-
addError("tokens", `Token key must not contain spaces: \`theme.tokens.${formattedPath}\``);
|
|
967
|
-
return;
|
|
968
|
-
}
|
|
969
|
-
if (!(0, import_shared9.isObject)(value) && !path2.includes("value")) {
|
|
970
|
-
addError("tokens", `Token must contain 'value': \`theme.semanticTokens.${formattedPath}\``);
|
|
971
|
-
}
|
|
972
|
-
});
|
|
973
|
-
}
|
|
974
|
-
validateTokenReferences({ valueAtPath, refsByPath, addError, typeByPath });
|
|
975
|
-
};
|
|
976
|
-
|
|
977
|
-
// src/validate-config.ts
|
|
978
|
-
var validateConfig = (config) => {
|
|
979
|
-
if (config.validation === "none") return;
|
|
980
|
-
const warnings = /* @__PURE__ */ new Set();
|
|
981
|
-
const addError = (scope, message) => {
|
|
982
|
-
warnings.add(`[${scope}] ` + message);
|
|
983
|
-
};
|
|
984
|
-
validateBreakpoints(config.theme?.breakpoints, addError);
|
|
985
|
-
validateConditions(config.conditions, addError);
|
|
986
|
-
const artifacts = {
|
|
987
|
-
recipes: /* @__PURE__ */ new Set(),
|
|
988
|
-
slotRecipes: /* @__PURE__ */ new Set(),
|
|
989
|
-
patterns: /* @__PURE__ */ new Set()
|
|
990
|
-
};
|
|
991
|
-
const tokens2 = {
|
|
992
|
-
tokenNames: /* @__PURE__ */ new Set(),
|
|
993
|
-
semanticTokenNames: /* @__PURE__ */ new Set(),
|
|
994
|
-
valueAtPath: /* @__PURE__ */ new Map(),
|
|
995
|
-
refsByPath: /* @__PURE__ */ new Map(),
|
|
996
|
-
typeByPath: /* @__PURE__ */ new Map()
|
|
997
|
-
};
|
|
998
|
-
if (config.theme) {
|
|
999
|
-
validateTokens({ config, tokens: tokens2, addError });
|
|
1000
|
-
validateRecipes({ config, tokens: tokens2, artifacts, addError });
|
|
1001
|
-
}
|
|
1002
|
-
validatePatterns(config.patterns, artifacts);
|
|
1003
|
-
validateArtifactNames(artifacts, addError);
|
|
1004
|
-
if (warnings.size) {
|
|
1005
|
-
const errors = `\u26A0\uFE0F Invalid config:
|
|
1006
|
-
${Array.from(warnings).map((err) => "- " + err).join("\n")}
|
|
1007
|
-
`;
|
|
1008
|
-
if (config.validation === "error") {
|
|
1009
|
-
throw new import_shared10.BambooError("CONFIG_ERROR", errors);
|
|
1010
|
-
}
|
|
1011
|
-
import_logger3.logger.warn("config", errors);
|
|
1012
|
-
return warnings;
|
|
1013
|
-
}
|
|
1014
|
-
};
|
|
1015
|
-
|
|
1016
|
-
// src/resolve-config.ts
|
|
1017
|
-
var hookUtils2 = {
|
|
1018
|
-
omit: import_shared11.omit,
|
|
1019
|
-
pick: import_shared11.pick,
|
|
1020
|
-
traverse: import_shared11.traverse
|
|
1021
|
-
};
|
|
1022
|
-
async function resolveConfig(result, cwd) {
|
|
1023
|
-
const presets = /* @__PURE__ */ new Set();
|
|
1024
|
-
if (!result.config.eject) {
|
|
1025
|
-
presets.add(import_preset_base.preset);
|
|
1026
|
-
}
|
|
1027
|
-
if (result.config.presets) {
|
|
1028
|
-
result.config.presets.forEach((preset) => {
|
|
1029
|
-
presets.add(getBundledPreset(preset) ?? preset);
|
|
1030
|
-
});
|
|
1031
|
-
} else if (!result.config.eject) {
|
|
1032
|
-
presets.add(import_preset_bamboo.preset);
|
|
1033
|
-
}
|
|
1034
|
-
result.config.presets = Array.from(presets);
|
|
1035
|
-
const userConfig = result.config;
|
|
1036
|
-
const pluginHooks = userConfig.plugins ?? [];
|
|
1037
|
-
if (userConfig.hooks) {
|
|
1038
|
-
pluginHooks.push({ name: import_shared11.BAMBOO_CONFIG_NAME, hooks: userConfig.hooks });
|
|
1039
|
-
}
|
|
1040
|
-
const earlyHooks = mergeHooks(pluginHooks);
|
|
1041
|
-
const mergedConfig = await getResolvedConfig(result.config, cwd, earlyHooks);
|
|
1042
|
-
const hooks = mergedConfig.hooks ?? {};
|
|
1043
|
-
if (mergedConfig.logLevel) {
|
|
1044
|
-
import_logger4.logger.level = mergedConfig.logLevel;
|
|
1045
|
-
}
|
|
1046
|
-
validateConfig(mergedConfig);
|
|
1047
|
-
const loadConfigResult = {
|
|
1048
|
-
...result,
|
|
1049
|
-
config: mergedConfig
|
|
1050
|
-
};
|
|
1051
|
-
if (hooks["config:resolved"]) {
|
|
1052
|
-
const result2 = await hooks["config:resolved"]({
|
|
1053
|
-
config: loadConfigResult.config,
|
|
1054
|
-
path: loadConfigResult.path,
|
|
1055
|
-
dependencies: loadConfigResult.dependencies,
|
|
1056
|
-
utils: hookUtils2
|
|
1057
|
-
});
|
|
1058
|
-
if (result2) {
|
|
1059
|
-
loadConfigResult.config = result2;
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
const serialized = (0, import_shared11.stringifyJson)(
|
|
1063
|
-
Object.assign({}, loadConfigResult.config, { name: import_shared11.BAMBOO_CONFIG_NAME, presets: [] })
|
|
1064
|
-
);
|
|
1065
|
-
const deserialize = () => (0, import_shared11.parseJson)(serialized);
|
|
1066
|
-
return { ...loadConfigResult, serialized, deserialize, hooks };
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
// src/load-config.ts
|
|
1070
|
-
async function loadConfig(options) {
|
|
1071
|
-
const result = await bundleConfig(options);
|
|
1072
|
-
return resolveConfig(result, options.cwd);
|
|
1073
|
-
}
|
|
1074
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1075
|
-
0 && (module.exports = {
|
|
1076
|
-
bundleConfig,
|
|
1077
|
-
convertTsPathsToRegexes,
|
|
1078
|
-
diffConfigs,
|
|
1079
|
-
findConfig,
|
|
1080
|
-
getConfigDependencies,
|
|
1081
|
-
getResolvedConfig,
|
|
1082
|
-
loadConfig,
|
|
1083
|
-
mergeConfigs,
|
|
1084
|
-
mergeHooks,
|
|
1085
|
-
resolveConfig
|
|
1086
|
-
});
|