@bamboocss/node 1.55.7 → 1.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +465 -531
- package/dist/index.d.cts +361 -720
- package/dist/index.d.mts +361 -720
- package/dist/index.mjs +463 -531
- package/dist/native/darwin-arm64.node +0 -0
- package/dist/native/darwin-x64.node +0 -0
- package/dist/native/linux-arm64-gnu.node +0 -0
- package/dist/native/linux-x64-gnu.node +0 -0
- package/dist/native/win32-x64-msvc.node +0 -0
- package/package.json +21 -14
package/dist/index.cjs
CHANGED
|
@@ -24,25 +24,22 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
//#endregion
|
|
25
25
|
const require_static_compiler = require("./static-compiler.cjs");
|
|
26
26
|
let _bamboocss_logger = require("@bamboocss/logger");
|
|
27
|
-
let _bamboocss_ts_ast = require("@bamboocss/ts-ast");
|
|
28
27
|
let _bamboocss_config = require("@bamboocss/config");
|
|
29
28
|
let _bamboocss_shared = require("@bamboocss/shared");
|
|
30
|
-
let node_crypto = require("node:crypto");
|
|
31
29
|
let fs = require("fs");
|
|
32
30
|
let path = require("path");
|
|
33
31
|
let picomatch = require("picomatch");
|
|
34
32
|
picomatch = __toESM(picomatch);
|
|
35
33
|
let _bamboocss_plugin_svelte = require("@bamboocss/plugin-svelte");
|
|
36
34
|
let _bamboocss_plugin_vue = require("@bamboocss/plugin-vue");
|
|
35
|
+
let node_module = require("node:module");
|
|
37
36
|
let _bamboocss_core = require("@bamboocss/core");
|
|
38
37
|
let _bamboocss_generator = require("@bamboocss/generator");
|
|
39
|
-
let _bamboocss_parser = require("@bamboocss/parser");
|
|
40
38
|
let node_fs = require("node:fs");
|
|
41
39
|
node_fs = __toESM(node_fs);
|
|
42
40
|
let node_path = require("node:path");
|
|
43
41
|
node_path = __toESM(node_path);
|
|
44
42
|
let perfect_debounce = require("perfect-debounce");
|
|
45
|
-
let node_module = require("node:module");
|
|
46
43
|
let node_url = require("node:url");
|
|
47
44
|
let node_process = require("node:process");
|
|
48
45
|
node_process = __toESM(node_process, 1);
|
|
@@ -57,7 +54,6 @@ fast_glob = __toESM(fast_glob);
|
|
|
57
54
|
let fs_extra = require("fs-extra");
|
|
58
55
|
fs_extra = __toESM(fs_extra);
|
|
59
56
|
let matcher = require("matcher");
|
|
60
|
-
let _bamboocss_config_ts_path = require("@bamboocss/config/ts-path");
|
|
61
57
|
let node_readline = require("node:readline");
|
|
62
58
|
node_readline = __toESM(node_readline);
|
|
63
59
|
let look_it_up = require("look-it-up");
|
|
@@ -74,7 +70,9 @@ let child_process = require("child_process");
|
|
|
74
70
|
async function analyze(ctx, options = {}) {
|
|
75
71
|
const { Reporter, formatRecipeReport, formatTokenReport } = await import("@bamboocss/reporter");
|
|
76
72
|
const reporter = new Reporter(ctx, {
|
|
77
|
-
|
|
73
|
+
parserOptions: ctx.parserOptions,
|
|
74
|
+
parseFile: (file) => ctx.parseFile(file),
|
|
75
|
+
prepare: (files) => ctx.prepareNativeExtraction(files),
|
|
78
76
|
getRelativePath: ctx.runtime.path.relative,
|
|
79
77
|
getFiles: ctx.getFiles,
|
|
80
78
|
...options
|
|
@@ -152,6 +150,47 @@ async function codegen(ctx, ids) {
|
|
|
152
150
|
};
|
|
153
151
|
}
|
|
154
152
|
//#endregion
|
|
153
|
+
//#region src/astro-to-tsx.ts
|
|
154
|
+
/**
|
|
155
|
+
* Astro's compiler, loaded the first time a `.astro` file is actually parsed.
|
|
156
|
+
*
|
|
157
|
+
* Every build carries this hook, so a static import would make every build pay to load a
|
|
158
|
+
* compiler most projects never call — the reason the Vue and Svelte plugins load theirs lazily
|
|
159
|
+
* too. The `sync` entry because `parser:before` is synchronous. `@astrojs/compiler` is an
|
|
160
|
+
* optional peer: `astro` depends on it, so a project with `.astro` files already has it.
|
|
161
|
+
*/
|
|
162
|
+
let convert;
|
|
163
|
+
const load = () => convert ??= (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("@astrojs/compiler/sync").convertToTSX;
|
|
164
|
+
/** The inline source map Astro appends, which nothing downstream reads. */
|
|
165
|
+
const SOURCE_MAP_COMMENT = /\n\/\/# sourceMappingURL=data:[^\n]*\s*$/;
|
|
166
|
+
/**
|
|
167
|
+
* A `.astro` file as TSX the extractor can parse.
|
|
168
|
+
*
|
|
169
|
+
* Nothing converted these before: the TypeScript parser read the raw file, recovering from the
|
|
170
|
+
* `---` fences and the template well enough to find calls in it. Oxc, which does all extraction
|
|
171
|
+
* now, rejects that text, failing the build on every Astro component.
|
|
172
|
+
*
|
|
173
|
+
* Astro's own TSX output is what its language tools type-check against — the frontmatter as
|
|
174
|
+
* module code, the template as JSX in a fragment — so it is valid by construction and keeps
|
|
175
|
+
* every expression the template evaluates, `class={css({ … })}` included.
|
|
176
|
+
*/
|
|
177
|
+
const astroToTsx = (code, filename) => {
|
|
178
|
+
let result;
|
|
179
|
+
try {
|
|
180
|
+
result = load()(code, { filename });
|
|
181
|
+
} catch {
|
|
182
|
+
return "";
|
|
183
|
+
}
|
|
184
|
+
return result.code.replace(SOURCE_MAP_COMMENT, "\n");
|
|
185
|
+
};
|
|
186
|
+
/** Built in, rather than a plugin package: Astro support is part of the Vite integration. */
|
|
187
|
+
const pluginAstro = () => ({
|
|
188
|
+
name: "@bamboocss/node:astro",
|
|
189
|
+
hooks: { "parser:before": ({ filePath, content }) => {
|
|
190
|
+
if (filePath.endsWith(".astro")) return astroToTsx(content, filePath);
|
|
191
|
+
} }
|
|
192
|
+
});
|
|
193
|
+
//#endregion
|
|
155
194
|
//#region src/extractable-files.ts
|
|
156
195
|
/**
|
|
157
196
|
* Which of the files `include` matched an extraction pass actually has to read.
|
|
@@ -191,7 +230,7 @@ async function codegen(ctx, ids) {
|
|
|
191
230
|
* one it failed to read.
|
|
192
231
|
*/
|
|
193
232
|
const SPECIFIER = /(?:\bfrom\s*|^\s*(?:import|export)\s*|\bimport\s*\(\s*|\brequire\s*\(\s*)['"]([^'"\n]+)['"]/gm;
|
|
194
|
-
/** The extensions a specifier may omit, in the order
|
|
233
|
+
/** The extensions a specifier may omit, in the order the native resolver tries them. */
|
|
195
234
|
const EXTENSIONS = [
|
|
196
235
|
".ts",
|
|
197
236
|
".tsx",
|
|
@@ -1962,6 +2001,256 @@ var DiffEngine = class {
|
|
|
1962
2001
|
}
|
|
1963
2002
|
};
|
|
1964
2003
|
//#endregion
|
|
2004
|
+
//#region src/parser-result.ts
|
|
2005
|
+
/**
|
|
2006
|
+
* What extraction found in one file, and the encoder calls that turn it into rules.
|
|
2007
|
+
*
|
|
2008
|
+
* Filled from the native analysis by `BambooContext.parseFile`; nothing here reads source.
|
|
2009
|
+
*/
|
|
2010
|
+
var ParserResult = class {
|
|
2011
|
+
context;
|
|
2012
|
+
/** Ordered list of all ResultItem */
|
|
2013
|
+
all = [];
|
|
2014
|
+
css = /* @__PURE__ */ new Set();
|
|
2015
|
+
cva = /* @__PURE__ */ new Set();
|
|
2016
|
+
sva = /* @__PURE__ */ new Set();
|
|
2017
|
+
token = /* @__PURE__ */ new Set();
|
|
2018
|
+
viewTransition = /* @__PURE__ */ new Set();
|
|
2019
|
+
recipe = /* @__PURE__ */ new Map();
|
|
2020
|
+
pattern = /* @__PURE__ */ new Map();
|
|
2021
|
+
filePath;
|
|
2022
|
+
encoder;
|
|
2023
|
+
/** Resolver targets crossed while extracting values which contributed CSS. */
|
|
2024
|
+
dependencies = /* @__PURE__ */ new Set();
|
|
2025
|
+
/** Styles the build could not fully see. @see `UnresolvedStyle` */
|
|
2026
|
+
unresolved = [];
|
|
2027
|
+
/**
|
|
2028
|
+
* Calls to a name the pattern or recipe entrypoint no longer exports.
|
|
2029
|
+
*
|
|
2030
|
+
* Separate from `unresolved`, which grades a call the build *did* see and could only
|
|
2031
|
+
* partly resolve. These it saw and could not resolve at all: the binding is dead, so every
|
|
2032
|
+
* rule the call would have contributed is absent rather than incomplete. Reported by
|
|
2033
|
+
* `assertNoDeadCalls` rather than warned about, for that reason.
|
|
2034
|
+
*/
|
|
2035
|
+
deadCalls = [];
|
|
2036
|
+
/**
|
|
2037
|
+
* Whether each result item is attributed to its call site, for a source map.
|
|
2038
|
+
*
|
|
2039
|
+
* Off for a source a `parser:before` hook rewrote: its positions are the hook's output's,
|
|
2040
|
+
* not the file's, and a wrong line is worse than none.
|
|
2041
|
+
*/
|
|
2042
|
+
origins = true;
|
|
2043
|
+
/** Set on a result the native engine produced, with the reads it reported. @internal */
|
|
2044
|
+
native = false;
|
|
2045
|
+
nativePendingCandidates = [];
|
|
2046
|
+
nativeConfigurationFiles = [];
|
|
2047
|
+
constructor(context, encoder) {
|
|
2048
|
+
this.context = context;
|
|
2049
|
+
this.encoder = encoder ?? context.encoder;
|
|
2050
|
+
}
|
|
2051
|
+
append(result) {
|
|
2052
|
+
this.all.push(result);
|
|
2053
|
+
return result;
|
|
2054
|
+
}
|
|
2055
|
+
set(name, result) {
|
|
2056
|
+
switch (name) {
|
|
2057
|
+
case "css":
|
|
2058
|
+
this.setCss(result);
|
|
2059
|
+
break;
|
|
2060
|
+
case "cva":
|
|
2061
|
+
this.setCva(result);
|
|
2062
|
+
break;
|
|
2063
|
+
case "sva":
|
|
2064
|
+
this.setSva(result);
|
|
2065
|
+
break;
|
|
2066
|
+
case "token":
|
|
2067
|
+
this.setToken(result);
|
|
2068
|
+
break;
|
|
2069
|
+
default: throw new _bamboocss_shared.BambooError("UNKNOWN_RESULT_TYPE", `Unknown parser result type: "${name}". Expected one of: css, cva, sva, token`);
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
setCss(result) {
|
|
2073
|
+
this.css.add(this.append(Object.assign({ type: "css" }, result)));
|
|
2074
|
+
if (result.data.some(Array.isArray)) throw new _bamboocss_shared.BambooError("INVALID_STYLE_ARGUMENT", "An array is not a style argument.", { hint: "Spread it instead, e.g. css(...styles) rather than css(styles)." });
|
|
2075
|
+
const encoder = this.encoder;
|
|
2076
|
+
encoder.withOrigin(this.originOf(result), () => result.data.forEach((obj) => encoder.processAtomic(obj)));
|
|
2077
|
+
}
|
|
2078
|
+
/** The call site of `result`, when the encoder is recording them. */
|
|
2079
|
+
originOf = (result) => {
|
|
2080
|
+
if (!this.origins || !this.encoder.recordOrigins) return void 0;
|
|
2081
|
+
return result.atomOrigin;
|
|
2082
|
+
};
|
|
2083
|
+
setCva(result) {
|
|
2084
|
+
this.cva.add(this.append(Object.assign({ type: "cva" }, result)));
|
|
2085
|
+
const encoder = this.encoder;
|
|
2086
|
+
encoder.withOrigin(this.originOf(result), () => result.data.forEach((data) => encoder.processAtomicRecipe(data)));
|
|
2087
|
+
}
|
|
2088
|
+
setSva(result) {
|
|
2089
|
+
this.sva.add(this.append(Object.assign({ type: "sva" }, result)));
|
|
2090
|
+
const encoder = this.encoder;
|
|
2091
|
+
encoder.withOrigin(this.originOf(result), () => result.data.forEach((data) => encoder.processAtomicSlotRecipe(data)));
|
|
2092
|
+
}
|
|
2093
|
+
/**
|
|
2094
|
+
* `kind` separates the variable reference — `token()` — from `token.value()`, the resolved
|
|
2095
|
+
* literal. They share this set deliberately: everything that reads a result for the token
|
|
2096
|
+
* *path* wants both, and only the fold cares which half was asked for.
|
|
2097
|
+
*/
|
|
2098
|
+
setToken(result, kind = "token") {
|
|
2099
|
+
this.token.add(this.append(Object.assign({ type: kind }, result)));
|
|
2100
|
+
}
|
|
2101
|
+
setViewTransition(result) {
|
|
2102
|
+
this.viewTransition.add(this.append(Object.assign({ type: "viewTransition" }, result)));
|
|
2103
|
+
const encoder = this.encoder;
|
|
2104
|
+
result.data.forEach((obj) => encoder.processViewTransition(obj));
|
|
2105
|
+
}
|
|
2106
|
+
setPattern(name, result) {
|
|
2107
|
+
(0, _bamboocss_shared.getOrCreateSet)(this.pattern, name).add(this.append(Object.assign({
|
|
2108
|
+
type: "pattern",
|
|
2109
|
+
name
|
|
2110
|
+
}, result)));
|
|
2111
|
+
this.encoder.withOrigin(this.originOf(result), () => result.data.forEach((obj) => this.encoder.processPattern(name, obj)));
|
|
2112
|
+
}
|
|
2113
|
+
/**
|
|
2114
|
+
* @param unresolved The variant axes the call site passed and the build could not read.
|
|
2115
|
+
* `button({ size })` with a dynamic `size` and `button()` both arrive as `{}`, and the
|
|
2116
|
+
* difference decides whether a class the encoder is about to emit has a rule behind it.
|
|
2117
|
+
*/
|
|
2118
|
+
setRecipe(recipeName, result, unresolved) {
|
|
2119
|
+
(0, _bamboocss_shared.getOrCreateSet)(this.recipe, recipeName).add(this.append(Object.assign({ type: "recipe" }, result)));
|
|
2120
|
+
const encoder = this.encoder;
|
|
2121
|
+
const recipes = this.context.recipes;
|
|
2122
|
+
if (!recipes.getConfig(recipeName)) return;
|
|
2123
|
+
const axes = unresolved?.size ? new Set(unresolved) : void 0;
|
|
2124
|
+
if (result.type) result.data.forEach((data) => {
|
|
2125
|
+
const [recipeProps, styleProps] = recipes.splitProps(recipeName, data);
|
|
2126
|
+
encoder.processStyleProps(styleProps);
|
|
2127
|
+
encoder.processRecipe(recipeName, recipeProps, axes);
|
|
2128
|
+
});
|
|
2129
|
+
else result.data.forEach((data) => {
|
|
2130
|
+
encoder.processRecipe(recipeName, data, axes);
|
|
2131
|
+
});
|
|
2132
|
+
}
|
|
2133
|
+
isEmpty() {
|
|
2134
|
+
return this.all.length === 0;
|
|
2135
|
+
}
|
|
2136
|
+
setFilePath(filePath) {
|
|
2137
|
+
this.filePath = filePath;
|
|
2138
|
+
return this;
|
|
2139
|
+
}
|
|
2140
|
+
/** @internal Called with each resolver target the native evaluation crossed. */
|
|
2141
|
+
addDependency(filePath) {
|
|
2142
|
+
this.dependencies.add(filePath.replaceAll("\\", "/"));
|
|
2143
|
+
}
|
|
2144
|
+
/** Local source paths crossed while resolving values this extraction encoded. */
|
|
2145
|
+
getDependencies() {
|
|
2146
|
+
const own = this.filePath?.replaceAll("\\", "/");
|
|
2147
|
+
return [...this.dependencies].filter((path) => path !== own).sort();
|
|
2148
|
+
}
|
|
2149
|
+
toArray() {
|
|
2150
|
+
return this.all;
|
|
2151
|
+
}
|
|
2152
|
+
toJSON() {
|
|
2153
|
+
return {
|
|
2154
|
+
css: Array.from(this.css),
|
|
2155
|
+
cva: Array.from(this.cva),
|
|
2156
|
+
sva: Array.from(this.sva),
|
|
2157
|
+
token: Array.from(this.token),
|
|
2158
|
+
viewTransition: Array.from(this.viewTransition),
|
|
2159
|
+
recipe: Object.fromEntries(Array.from(this.recipe.entries()).map(([key, value]) => [key, Array.from(value)])),
|
|
2160
|
+
pattern: Object.fromEntries(Array.from(this.pattern.entries()).map(([key, value]) => [key, Array.from(value)]))
|
|
2161
|
+
};
|
|
2162
|
+
}
|
|
2163
|
+
};
|
|
2164
|
+
//#endregion
|
|
2165
|
+
//#region src/source-project.ts
|
|
2166
|
+
/**
|
|
2167
|
+
* The source view every engine reads: disk, with caller-supplied bytes layered over it.
|
|
2168
|
+
*
|
|
2169
|
+
* Extraction and the Vite compiler run in Rust, and the Rust resolver reads ordinary files
|
|
2170
|
+
* itself. What it cannot see is bytes that exist nowhere on disk — a single-file component's
|
|
2171
|
+
* compiled script, a test's in-memory module — so those are held here, as overlays, and handed
|
|
2172
|
+
* across the native boundary with every analysis. Nothing here parses anything.
|
|
2173
|
+
*/
|
|
2174
|
+
var SourceProject = class {
|
|
2175
|
+
options;
|
|
2176
|
+
/** Bytes explicitly supplied by a caller rather than read from disk, by normalized path. */
|
|
2177
|
+
overlays = /* @__PURE__ */ new Map();
|
|
2178
|
+
compilerOptions;
|
|
2179
|
+
constructor(options) {
|
|
2180
|
+
this.options = options;
|
|
2181
|
+
this.compilerOptions = { ...options.compilerOptions };
|
|
2182
|
+
}
|
|
2183
|
+
normalizePath = (filePath) => filePath.replaceAll("\\", "/");
|
|
2184
|
+
/** The `baseUrl` and `paths` module resolution reads. */
|
|
2185
|
+
get resolutionOptions() {
|
|
2186
|
+
return {
|
|
2187
|
+
baseUrl: this.compilerOptions.baseUrl,
|
|
2188
|
+
paths: this.compilerOptions.paths
|
|
2189
|
+
};
|
|
2190
|
+
}
|
|
2191
|
+
/** A tsconfig reload replaced the options resolution reads. */
|
|
2192
|
+
refreshResolutionConfiguration = (compilerOptions = {}) => {
|
|
2193
|
+
this.compilerOptions = { ...compilerOptions };
|
|
2194
|
+
};
|
|
2195
|
+
/** Source bytes from an overlay, else from disk; `undefined` when neither can be read. */
|
|
2196
|
+
getSourceText = (filePath) => {
|
|
2197
|
+
const overlay = this.overlays.get(this.normalizePath(filePath));
|
|
2198
|
+
if (overlay !== void 0) return overlay;
|
|
2199
|
+
try {
|
|
2200
|
+
return this.options.readFile(filePath);
|
|
2201
|
+
} catch {
|
|
2202
|
+
return;
|
|
2203
|
+
}
|
|
2204
|
+
};
|
|
2205
|
+
/** Whether that same source view can read a path. */
|
|
2206
|
+
sourceExists = (filePath) => this.overlays.has(this.normalizePath(filePath)) || this.options.fileExists(filePath);
|
|
2207
|
+
/** Whether a caller supplied bytes that can differ from the path on disk. */
|
|
2208
|
+
sourceIsOverridden = (filePath) => this.overlays.has(this.normalizePath(filePath));
|
|
2209
|
+
/** Every path a caller supplied bytes for. */
|
|
2210
|
+
getOverriddenSources = () => [...this.overlays.keys()];
|
|
2211
|
+
/** Supply the bytes for a path. */
|
|
2212
|
+
overlaySource = (filePath, content) => {
|
|
2213
|
+
this.overlays.set(this.normalizePath(filePath), content);
|
|
2214
|
+
};
|
|
2215
|
+
/**
|
|
2216
|
+
* Supply the bytes for a module, under the path extraction will ask for.
|
|
2217
|
+
*
|
|
2218
|
+
* A relative path resolves against the project's working directory, as `parseFile` resolves
|
|
2219
|
+
* it — so a module added as `src/a.tsx` is the one `parseFile('src/a.tsx')` reads.
|
|
2220
|
+
*/
|
|
2221
|
+
addSourceFile = (filePath, content) => {
|
|
2222
|
+
this.overlaySource(this.absolute(filePath), content);
|
|
2223
|
+
};
|
|
2224
|
+
absolute = (filePath) => (0, node_path.isAbsolute)(filePath) ? filePath : (0, node_path.join)(this.options.cwd ?? process.cwd(), filePath);
|
|
2225
|
+
/** Forget bytes supplied through `overlaySource`. Returns whether there were any. */
|
|
2226
|
+
removeOverlay = (filePath) => this.overlays.delete(this.normalizePath(filePath));
|
|
2227
|
+
/**
|
|
2228
|
+
* A watched file changed on disk. Disk is now the truth for it, so an overlay that
|
|
2229
|
+
* stood in for it goes.
|
|
2230
|
+
*/
|
|
2231
|
+
reloadSourceFile = (filePath) => {
|
|
2232
|
+
this.removeOverlay(this.absolute(filePath));
|
|
2233
|
+
};
|
|
2234
|
+
/**
|
|
2235
|
+
* A watched file was deleted. Its styles go with it — nothing re-parses a file that is gone,
|
|
2236
|
+
* so they would otherwise outlive it for as long as the context does.
|
|
2237
|
+
*/
|
|
2238
|
+
removeSourceFile = (filePath, encoder = this.options.parserOptions.encoder) => {
|
|
2239
|
+
encoder.releaseFile(this.absolute(filePath));
|
|
2240
|
+
this.removeOverlay(this.absolute(filePath));
|
|
2241
|
+
};
|
|
2242
|
+
/**
|
|
2243
|
+
* Restore an encoder dump from a `.json` file in `include` — the output of `bamboo ship`,
|
|
2244
|
+
* or a library's shipped extraction — and report it as an empty result for that file.
|
|
2245
|
+
*/
|
|
2246
|
+
parseJson = (filePath, encoder = this.options.parserOptions.encoder) => {
|
|
2247
|
+
const content = this.getSourceText(filePath);
|
|
2248
|
+
if (content === void 0) throw new Error(`bamboo: could not read ${filePath}`);
|
|
2249
|
+
encoder.fromJSON(JSON.parse(content));
|
|
2250
|
+
return new ParserResult(this.options.parserOptions, encoder).setFilePath(filePath);
|
|
2251
|
+
};
|
|
2252
|
+
};
|
|
2253
|
+
//#endregion
|
|
1965
2254
|
//#region src/glob-dirname.ts
|
|
1966
2255
|
function globDirname(globs) {
|
|
1967
2256
|
const rootDirs = /* @__PURE__ */ new Set();
|
|
@@ -2318,23 +2607,14 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
2318
2607
|
const config = conf.config;
|
|
2319
2608
|
this.runtime = nodeRuntime;
|
|
2320
2609
|
this.parserHooks = conf.hooks;
|
|
2321
|
-
config.cwd
|
|
2610
|
+
config.cwd = this.runtime.path.resolve(this.runtime.cwd(), config.cwd || ".");
|
|
2322
2611
|
if (config.logLevel) _bamboocss_logger.logger.level = config.logLevel;
|
|
2323
|
-
this.project = new
|
|
2324
|
-
cwd: config.cwd
|
|
2325
|
-
tsConfigFilePath: conf.tsconfigFile ?? `${config.cwd ?? this.runtime.cwd()}/tsconfig.json`,
|
|
2326
|
-
fs: { readFile: (filePath) => this.runtime.fs.readFileSync(filePath) },
|
|
2327
|
-
...conf.tsconfig,
|
|
2328
|
-
deferInitialSourceFiles: true,
|
|
2329
|
-
resolutionConfigFiles: getTsConfigResolutionFiles(conf),
|
|
2330
|
-
getFiles: () => this.getFiles(),
|
|
2612
|
+
this.project = new SourceProject({
|
|
2613
|
+
cwd: config.cwd,
|
|
2331
2614
|
readFile: (filePath) => this.runtime.fs.readFileSync(filePath),
|
|
2332
2615
|
fileExists: (filePath) => this.runtime.fs.existsSync(filePath),
|
|
2333
|
-
|
|
2334
|
-
parserOptions:
|
|
2335
|
-
...this.parserOptions,
|
|
2336
|
-
join: this.runtime.path.join || this.parserOptions.join
|
|
2337
|
-
}
|
|
2616
|
+
compilerOptions: conf.tsconfig?.compilerOptions,
|
|
2617
|
+
parserOptions: this.parserOptions
|
|
2338
2618
|
});
|
|
2339
2619
|
this.output = new OutputEngine(this);
|
|
2340
2620
|
this.diff = new DiffEngine(this);
|
|
@@ -2474,6 +2754,90 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
2474
2754
|
const outdir = this.runtime.path.join(...this.paths.root);
|
|
2475
2755
|
return file === outdir || file.startsWith(outdir + this.runtime.path.sep);
|
|
2476
2756
|
};
|
|
2757
|
+
/**
|
|
2758
|
+
* The text extraction reads for a file: its `parser:before` output, or its bytes when no hook
|
|
2759
|
+
* rewrites it. `undefined` when the file cannot be read at all.
|
|
2760
|
+
*
|
|
2761
|
+
* The same preparation `analyzeMany` is handed, so every scan that compares "what the parser
|
|
2762
|
+
* holds" against "what is on disk" compares against what extraction actually saw.
|
|
2763
|
+
*/
|
|
2764
|
+
parsedSourceText = (filePath, onDisk) => {
|
|
2765
|
+
const original = this.project.getSourceText(filePath) ?? onDisk;
|
|
2766
|
+
if (original === void 0) return void 0;
|
|
2767
|
+
return this.prepareNativeSource(filePath, original).source;
|
|
2768
|
+
};
|
|
2769
|
+
/**
|
|
2770
|
+
* Token accounting for one file's text, in Rust — see `token-accounting.ts` for the rules.
|
|
2771
|
+
*
|
|
2772
|
+
* This used to walk the TypeScript tree, which meant reading `project.getSourceFile` for
|
|
2773
|
+
* every file mentioning a token, and that started the Go compiler over the whole inventory
|
|
2774
|
+
* on every stylesheet build, since `prune.tokens` defaults on.
|
|
2775
|
+
*/
|
|
2776
|
+
accountTokens = (filePath, source) => {
|
|
2777
|
+
const { paths = {} } = this.project.resolutionOptions;
|
|
2778
|
+
return this.loadNativeExtractor().accountTokens(filePath, source, this.imports.value.tokens, Object.entries(paths).map(([pattern, values]) => ({
|
|
2779
|
+
pattern,
|
|
2780
|
+
paths: values
|
|
2781
|
+
})));
|
|
2782
|
+
};
|
|
2783
|
+
/**
|
|
2784
|
+
* What the Vite compiler needs to know about modules, in one native call. See
|
|
2785
|
+
* `native-extractor/src/fold/model.rs`.
|
|
2786
|
+
*
|
|
2787
|
+
* `sources` are the modules to analyze, as the bundler hands them over. Every other module a
|
|
2788
|
+
* value is resolved through is read the way extraction reads it: its `parser:before` output
|
|
2789
|
+
* when a hook rewrites it, disk otherwise, and an overlay the project holds wins over both.
|
|
2790
|
+
*/
|
|
2791
|
+
compileModules = (sources, options) => {
|
|
2792
|
+
const { baseUrl, paths = {} } = this.project.resolutionOptions;
|
|
2793
|
+
const own = new Set(sources.map((source) => source.filename.replaceAll("\\", "/")));
|
|
2794
|
+
const auxiliary = [];
|
|
2795
|
+
for (const filePath of new Set([...this.nativeAuxiliaryFiles, ...this.project.getOverriddenSources()])) {
|
|
2796
|
+
const filename = this.runtime.path.abs(this.config.cwd, filePath);
|
|
2797
|
+
if (own.has(filename.replaceAll("\\", "/"))) continue;
|
|
2798
|
+
const overridden = this.project.sourceIsOverridden(filename);
|
|
2799
|
+
if (!overridden && !this.parserHooks["parser:before"] && this.runtime === nodeRuntime) continue;
|
|
2800
|
+
const original = this.project.getSourceText(filename);
|
|
2801
|
+
if (original === void 0) continue;
|
|
2802
|
+
const prepared = this.prepareNativeSource(filename, original);
|
|
2803
|
+
if (prepared.source !== original || overridden || this.runtime !== nodeRuntime) auxiliary.push({
|
|
2804
|
+
filename,
|
|
2805
|
+
source: prepared.source
|
|
2806
|
+
});
|
|
2807
|
+
}
|
|
2808
|
+
return this.loadNativeExtractor().compileModules(sources, auxiliary, {
|
|
2809
|
+
cwd: this.config.cwd,
|
|
2810
|
+
baseUrl,
|
|
2811
|
+
paths: Object.entries(paths).map(([pattern, values]) => ({
|
|
2812
|
+
pattern,
|
|
2813
|
+
paths: values
|
|
2814
|
+
})),
|
|
2815
|
+
tokens: this.nativeTokens,
|
|
2816
|
+
cssModules: this.imports.value.css,
|
|
2817
|
+
tokenModules: this.imports.value.tokens,
|
|
2818
|
+
recipeModules: this.imports.value.recipe,
|
|
2819
|
+
patternModules: this.imports.value.pattern,
|
|
2820
|
+
recipeNames: this.recipes.keys,
|
|
2821
|
+
patternNames: this.patterns.keys,
|
|
2822
|
+
references: options.references
|
|
2823
|
+
});
|
|
2824
|
+
};
|
|
2825
|
+
/**
|
|
2826
|
+
* The token table as the native evaluator reads it.
|
|
2827
|
+
*
|
|
2828
|
+
* Built once per context rather than per call: `compileModules` runs once per transformed
|
|
2829
|
+
* module, and the table is every token in the project — rebuilding it priced the whole
|
|
2830
|
+
* dictionary into every file, most of which never call `token()`.
|
|
2831
|
+
*/
|
|
2832
|
+
get nativeTokens() {
|
|
2833
|
+
this.nativeTokenTable ??= this.tokens.allTokens.map((token) => ({
|
|
2834
|
+
path: token.name,
|
|
2835
|
+
value: this.tokens.view.get(token.name),
|
|
2836
|
+
variable: this.tokens.view.getVar(token.name)
|
|
2837
|
+
}));
|
|
2838
|
+
return this.nativeTokenTable;
|
|
2839
|
+
}
|
|
2840
|
+
nativeTokenTable;
|
|
2477
2841
|
/** Load the required Rust extractor from the workspace or the published prebuild directory. */
|
|
2478
2842
|
loadNativeExtractor = () => {
|
|
2479
2843
|
const nativeRequire = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
@@ -2521,7 +2885,7 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
2521
2885
|
this.nativeConfigurationFiles.delete(owner);
|
|
2522
2886
|
}
|
|
2523
2887
|
const sources = [];
|
|
2524
|
-
const auxiliary = this.parserHooks["parser:before"] || this.runtime !== nodeRuntime ? this.nativeAuxiliaryFiles : this.nativeAuxiliaryFiles.filter(this.project.sourceIsOverridden);
|
|
2888
|
+
const auxiliary = [...this.parserHooks["parser:before"] || this.runtime !== nodeRuntime ? this.nativeAuxiliaryFiles : this.nativeAuxiliaryFiles.filter(this.project.sourceIsOverridden), ...this.project.getOverriddenSources()];
|
|
2525
2889
|
const inventory = (0, _bamboocss_shared.uniq)([...filePaths, ...auxiliary]);
|
|
2526
2890
|
for (const filePath of inventory) {
|
|
2527
2891
|
if (filePath.endsWith(".json")) continue;
|
|
@@ -2594,11 +2958,7 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
2594
2958
|
pattern,
|
|
2595
2959
|
paths: values
|
|
2596
2960
|
})),
|
|
2597
|
-
tokens: this.
|
|
2598
|
-
path: token.name,
|
|
2599
|
-
value: this.tokens.view.get(token.name),
|
|
2600
|
-
variable: this.tokens.view.getVar(token.name)
|
|
2601
|
-
})),
|
|
2961
|
+
tokens: this.nativeTokens,
|
|
2602
2962
|
jsx: this.jsx.isEnabled
|
|
2603
2963
|
};
|
|
2604
2964
|
let analyses;
|
|
@@ -2645,7 +3005,7 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
2645
3005
|
};
|
|
2646
3006
|
parseNativeFile = (filePath, native, encoder) => {
|
|
2647
3007
|
if (native.errors.length) throw new _bamboocss_shared.BambooError("NATIVE_EXTRACTION", `Native extraction failed for ${filePath}:\n${native.errors.join("\n")}`);
|
|
2648
|
-
const result = new
|
|
3008
|
+
const result = new ParserResult(this.parserOptions, encoder).setFilePath(filePath);
|
|
2649
3009
|
result.native = true;
|
|
2650
3010
|
result.nativePendingCandidates = native.pendingCandidates;
|
|
2651
3011
|
result.nativeConfigurationFiles = native.configurationFiles;
|
|
@@ -2671,7 +3031,7 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
2671
3031
|
name: call.name,
|
|
2672
3032
|
data,
|
|
2673
3033
|
atomOrigin
|
|
2674
|
-
});
|
|
3034
|
+
}, new Set(call.unresolvedKeys));
|
|
2675
3035
|
continue;
|
|
2676
3036
|
}
|
|
2677
3037
|
const item = {
|
|
@@ -2699,7 +3059,7 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
2699
3059
|
].includes(call.importedName)) result.set(call.importedName, item);
|
|
2700
3060
|
else if (call.kind === "css" && call.importedName === "viewTransition") result.setViewTransition(item);
|
|
2701
3061
|
else if (call.kind === "pattern") result.setPattern(call.importedName, item);
|
|
2702
|
-
else if (call.kind === "recipe") result.setRecipe(call.importedName, item);
|
|
3062
|
+
else if (call.kind === "recipe") result.setRecipe(call.importedName, item, new Set(call.unresolvedKeys));
|
|
2703
3063
|
else if (call.kind === "token" || call.kind === "tokenValue") result.setToken(item, call.kind);
|
|
2704
3064
|
else if (call.kind === "dead") result.deadCalls.push({
|
|
2705
3065
|
name: call.importedName,
|
|
@@ -2742,7 +3102,6 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
2742
3102
|
} catch (error) {
|
|
2743
3103
|
this.nativeExtractions.delete(nativeFile);
|
|
2744
3104
|
this.nativeSourceMetadata.delete(nativeFile);
|
|
2745
|
-
if ((0, _bamboocss_ts_ast.isCompilerGone)(error)) throw error;
|
|
2746
3105
|
_bamboocss_logger.logger.caughtError("file:extract", `Failed to parse ${file}`, error);
|
|
2747
3106
|
this.parseFailures.set(file, error);
|
|
2748
3107
|
}
|
|
@@ -2930,14 +3289,19 @@ async function reportRebuildFailure(run) {
|
|
|
2930
3289
|
//#endregion
|
|
2931
3290
|
//#region src/config.ts
|
|
2932
3291
|
const RESOLVED_HOOKS_NAME = "__resolved__";
|
|
2933
|
-
const AUTO_PARSER_HOOKS = Object.freeze([
|
|
3292
|
+
const AUTO_PARSER_HOOKS = Object.freeze([
|
|
3293
|
+
"vue",
|
|
3294
|
+
"svelte",
|
|
3295
|
+
"astro"
|
|
3296
|
+
]);
|
|
2934
3297
|
const autoPluginFactories = {
|
|
3298
|
+
astro: pluginAstro,
|
|
2935
3299
|
svelte: _bamboocss_plugin_svelte.pluginSvelte,
|
|
2936
3300
|
vue: _bamboocss_plugin_vue.pluginVue
|
|
2937
3301
|
};
|
|
2938
3302
|
/**
|
|
2939
3303
|
* Built-in plugins that are auto-injected when using the CLI or PostCSS plugin.
|
|
2940
|
-
* These provide Vue
|
|
3304
|
+
* These provide Vue, Svelte and Astro single-file-component support.
|
|
2941
3305
|
*
|
|
2942
3306
|
* LightningCSS is not among them any more. It was reached through a `lightningcss: true`
|
|
2943
3307
|
* config flag whose only job was to push `pluginLightningcss()` into this list — a second
|
|
@@ -3013,12 +3377,10 @@ function readSnapshot(ctx, filePath) {
|
|
|
3013
3377
|
} catch {
|
|
3014
3378
|
onDisk = void 0;
|
|
3015
3379
|
}
|
|
3016
|
-
const sourceFile = ctx.project.getSourceFile(filePath);
|
|
3017
3380
|
return {
|
|
3018
3381
|
filePath,
|
|
3019
3382
|
onDisk,
|
|
3020
|
-
parsed:
|
|
3021
|
-
sourceFile
|
|
3383
|
+
parsed: ctx.parsedSourceText(filePath, onDisk)
|
|
3022
3384
|
};
|
|
3023
3385
|
}
|
|
3024
3386
|
/**
|
|
@@ -3059,27 +3421,35 @@ const failsStrict = (entry) => entry.reason === "unresolved-reference";
|
|
|
3059
3421
|
* the same files; three separate passes read every file three times.
|
|
3060
3422
|
*/
|
|
3061
3423
|
function accountSnapshot(ctx, snapshot, accounting) {
|
|
3062
|
-
const { filePath, onDisk, parsed
|
|
3424
|
+
const { filePath, onDisk, parsed } = snapshot;
|
|
3063
3425
|
const { paths, prefixes, declined } = accounting;
|
|
3064
|
-
|
|
3065
|
-
if (
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3426
|
+
{
|
|
3427
|
+
if (onDisk == null || parsed == null || parsed !== onDisk) {
|
|
3428
|
+
if (!(mentionsToken(ctx, onDisk) || mentionsToken(ctx, parsed))) return;
|
|
3429
|
+
declined.push({
|
|
3430
|
+
filePath,
|
|
3431
|
+
line: 1,
|
|
3432
|
+
reason: onDisk == null || parsed == null ? "unreadable" : "transformed"
|
|
3433
|
+
});
|
|
3434
|
+
return;
|
|
3435
|
+
}
|
|
3436
|
+
if (!mentionsToken(ctx, parsed)) return;
|
|
3437
|
+
const native = ctx.accountTokens(filePath, parsed);
|
|
3438
|
+
if (native.unparsed) {
|
|
3439
|
+
declined.push({
|
|
3440
|
+
filePath,
|
|
3441
|
+
line: 1,
|
|
3442
|
+
reason: "unparsed"
|
|
3443
|
+
});
|
|
3444
|
+
return;
|
|
3445
|
+
}
|
|
3446
|
+
for (const path of native.paths) paths.add(path);
|
|
3447
|
+
for (const prefix of native.prefixes) prefixes.add(prefix);
|
|
3448
|
+
for (const entry of native.declined) declined.push({
|
|
3076
3449
|
filePath,
|
|
3077
|
-
|
|
3078
|
-
reason: "unparsed"
|
|
3450
|
+
...entry
|
|
3079
3451
|
});
|
|
3080
|
-
return;
|
|
3081
3452
|
}
|
|
3082
|
-
accountFile(ctx, sourceFile, filePath, paths, prefixes, declined);
|
|
3083
3453
|
}
|
|
3084
3454
|
/**
|
|
3085
3455
|
* Whether a file is worth walking — because it can name the artifact, or because a shape in it
|
|
@@ -3111,355 +3481,6 @@ const mentionsToken = (ctx, text) => {
|
|
|
3111
3481
|
if (ctx.imports.value.tokens.some((mod) => text.includes(mod))) return true;
|
|
3112
3482
|
return IMPORTING_CALL.test(text);
|
|
3113
3483
|
};
|
|
3114
|
-
/** Whether a module specifier resolves to the generated tokens artifact. */
|
|
3115
|
-
const isTokensEntrypoint = (ctx, specifier) => {
|
|
3116
|
-
const mods = ctx.imports.value.tokens;
|
|
3117
|
-
if (mods.some((mod) => specifier.includes(mod))) return true;
|
|
3118
|
-
const pathMappings = ctx.conf.tsOptions?.pathMappings;
|
|
3119
|
-
if (!pathMappings) return false;
|
|
3120
|
-
const resolved = (0, _bamboocss_config_ts_path.resolveTsPathPattern)(pathMappings, specifier);
|
|
3121
|
-
if (!resolved) return false;
|
|
3122
|
-
return mods.some((mod) => resolved.includes(mod) || resolved === mod);
|
|
3123
|
-
};
|
|
3124
|
-
const lineOf = (node) => (0, _bamboocss_ts_ast.getLineAndColumnAtPos)(node.getSourceFile(), node.getStart()).line;
|
|
3125
|
-
function accountFile(ctx, sourceFile, filePath, paths, prefixes, declined) {
|
|
3126
|
-
const decline = (node, reason) => declined.push({
|
|
3127
|
-
filePath,
|
|
3128
|
-
line: lineOf(node),
|
|
3129
|
-
reason,
|
|
3130
|
-
start: node.getStart(),
|
|
3131
|
-
end: node.getEnd()
|
|
3132
|
-
});
|
|
3133
|
-
/** Local names bound to the artifact: the `token` export, and any namespace of it. */
|
|
3134
|
-
const bindings = /* @__PURE__ */ new Set();
|
|
3135
|
-
for (const statement of sourceFile.statements) {
|
|
3136
|
-
if (_bamboocss_ts_ast.Node.isExportDeclaration(statement)) {
|
|
3137
|
-
const specifier = (0, _bamboocss_ts_ast.getModuleSpecifierValue)(statement);
|
|
3138
|
-
if (specifier && isTokensEntrypoint(ctx, specifier)) decline(statement, "re-exported");
|
|
3139
|
-
continue;
|
|
3140
|
-
}
|
|
3141
|
-
if (!_bamboocss_ts_ast.Node.isImportDeclaration(statement)) continue;
|
|
3142
|
-
const specifier = (0, _bamboocss_ts_ast.getModuleSpecifierValue)(statement);
|
|
3143
|
-
if (!specifier) continue;
|
|
3144
|
-
const clause = statement.importClause;
|
|
3145
|
-
if (!clause || (0, _bamboocss_ts_ast.isTypeOnly)(statement)) continue;
|
|
3146
|
-
if (!isTokensEntrypoint(ctx, specifier)) {
|
|
3147
|
-
for (const named of (0, _bamboocss_ts_ast.getNamedImports)(clause)) if (!(0, _bamboocss_ts_ast.isTypeOnly)(named) && nameOf((0, _bamboocss_ts_ast.nameNodeOf)(named)) === "token") decline(named, "unclassified-import");
|
|
3148
|
-
const foreignDefault = (0, _bamboocss_ts_ast.getDefaultImport)(clause);
|
|
3149
|
-
if (foreignDefault && nameOf(foreignDefault) === "token") decline(foreignDefault, "unclassified-import");
|
|
3150
|
-
const foreignNamespace = (0, _bamboocss_ts_ast.getNamespaceImport)(clause);
|
|
3151
|
-
if (foreignNamespace && usesTokenMember(sourceFile, foreignNamespace.getText())) decline(foreignNamespace, "unclassified-import");
|
|
3152
|
-
continue;
|
|
3153
|
-
}
|
|
3154
|
-
const defaultImport = (0, _bamboocss_ts_ast.getDefaultImport)(clause);
|
|
3155
|
-
if (defaultImport) decline(defaultImport, "unsupported-import");
|
|
3156
|
-
const namespace = (0, _bamboocss_ts_ast.getNamespaceImport)(clause);
|
|
3157
|
-
if (namespace) bindings.add(namespace.getText());
|
|
3158
|
-
for (const named of (0, _bamboocss_ts_ast.getNamedImports)(clause)) {
|
|
3159
|
-
if ((0, _bamboocss_ts_ast.isTypeOnly)(named)) continue;
|
|
3160
|
-
if (nameOf((0, _bamboocss_ts_ast.nameNodeOf)(named)) !== "token") {
|
|
3161
|
-
if (usedAsValue(sourceFile, ((0, _bamboocss_ts_ast.getAliasNode)(named) ?? (0, _bamboocss_ts_ast.nameNodeOf)(named))?.getText() ?? "", named)) decline(named, "unsupported-import");
|
|
3162
|
-
continue;
|
|
3163
|
-
}
|
|
3164
|
-
bindings.add(((0, _bamboocss_ts_ast.getAliasNode)(named) ?? (0, _bamboocss_ts_ast.nameNodeOf)(named))?.getText() ?? "");
|
|
3165
|
-
}
|
|
3166
|
-
}
|
|
3167
|
-
for (const importEquals of (0, _bamboocss_ts_ast.getDescendantsOfKind)(sourceFile, _bamboocss_ts_ast.SyntaxKind.ImportEqualsDeclaration)) if (importEquals.getText().includes("token")) decline(importEquals, "import-equals");
|
|
3168
|
-
for (const call of (0, _bamboocss_ts_ast.getDescendantsOfKind)(sourceFile, _bamboocss_ts_ast.SyntaxKind.CallExpression)) {
|
|
3169
|
-
const callee = (0, _bamboocss_ts_ast.childOf)(call, "expression");
|
|
3170
|
-
const isRequire = callee !== void 0 && _bamboocss_ts_ast.Node.isIdentifier(callee) && callee.getText() === "require";
|
|
3171
|
-
const isDynamicImport = callee?.kind === _bamboocss_ts_ast.SyntaxKind.ImportKeyword;
|
|
3172
|
-
if (!isRequire && !isDynamicImport) continue;
|
|
3173
|
-
const argument = (0, _bamboocss_ts_ast.childOf)(call, "arguments")?.[0];
|
|
3174
|
-
if (!argument) continue;
|
|
3175
|
-
if (_bamboocss_ts_ast.Node.isStringLiteral(argument) ? isTokensEntrypoint(ctx, (0, _bamboocss_ts_ast.stringLiteralValue)(argument)) : true) decline(call, isRequire ? "require" : "dynamic-import");
|
|
3176
|
-
}
|
|
3177
|
-
const shadows = shadowedScopes(sourceFile);
|
|
3178
|
-
for (const identifier of identifiersNamed(sourceFile, (name) => bindings.has(name) || name === "token")) {
|
|
3179
|
-
const text = nameOf(identifier);
|
|
3180
|
-
const parent = identifier.parent;
|
|
3181
|
-
if (_bamboocss_ts_ast.Node.isExportSpecifier(parent)) {
|
|
3182
|
-
const declaration = (0, _bamboocss_ts_ast.getFirstAncestorByKind)(parent, _bamboocss_ts_ast.SyntaxKind.ExportDeclaration);
|
|
3183
|
-
if (declaration && !(0, _bamboocss_ts_ast.childOf)(declaration, "moduleSpecifier")) decline(identifier, "re-exported");
|
|
3184
|
-
continue;
|
|
3185
|
-
}
|
|
3186
|
-
if (_bamboocss_ts_ast.Node.isPropertyAccessExpression(parent) && parent.name === identifier) {
|
|
3187
|
-
const object = parent.expression;
|
|
3188
|
-
const objectName = _bamboocss_ts_ast.Node.isIdentifier(object) ? object.getText() : void 0;
|
|
3189
|
-
if (objectName && bindings.has(objectName)) continue;
|
|
3190
|
-
decline(identifier, "unresolved-reference");
|
|
3191
|
-
continue;
|
|
3192
|
-
}
|
|
3193
|
-
if (isDeclarationName(identifier, parent)) continue;
|
|
3194
|
-
if (isShadowed(identifier, shadows.get(text))) continue;
|
|
3195
|
-
const resolved = accountedPath(identifier);
|
|
3196
|
-
if (resolved === void 0) {
|
|
3197
|
-
decline(identifier, "unresolved-reference");
|
|
3198
|
-
continue;
|
|
3199
|
-
}
|
|
3200
|
-
if (resolved.kind === "binding") continue;
|
|
3201
|
-
if (resolved.kind === "prefix") {
|
|
3202
|
-
prefixes.add(resolved.value);
|
|
3203
|
-
continue;
|
|
3204
|
-
}
|
|
3205
|
-
paths.add(resolved.value);
|
|
3206
|
-
}
|
|
3207
|
-
}
|
|
3208
|
-
/**
|
|
3209
|
-
* Whether any `<namespace>.token` member access appears, for an unclassified namespace.
|
|
3210
|
-
*
|
|
3211
|
-
* Element access counts too: `ui['token'](k)` reaches the same export and is invisible to a
|
|
3212
|
-
* property-access-only scan.
|
|
3213
|
-
*/
|
|
3214
|
-
function usesTokenMember(sourceFile, namespace) {
|
|
3215
|
-
if ((0, _bamboocss_ts_ast.getDescendantsOfKind)(sourceFile, _bamboocss_ts_ast.SyntaxKind.PropertyAccessExpression).some((access) => (0, _bamboocss_ts_ast.childOf)(access, "expression")?.getText() === namespace && nameOf((0, _bamboocss_ts_ast.nameNodeOf)(access)) === "token")) return true;
|
|
3216
|
-
return (0, _bamboocss_ts_ast.getDescendantsOfKind)(sourceFile, _bamboocss_ts_ast.SyntaxKind.ElementAccessExpression).some((access) => {
|
|
3217
|
-
if ((0, _bamboocss_ts_ast.childOf)(access, "expression")?.getText() !== namespace) return false;
|
|
3218
|
-
const argument = (0, _bamboocss_ts_ast.childOf)(access, "argumentExpression");
|
|
3219
|
-
return argument != null && (!_bamboocss_ts_ast.Node.isStringLiteral(argument) || (0, _bamboocss_ts_ast.stringLiteralValue)(argument) === "token");
|
|
3220
|
-
});
|
|
3221
|
-
}
|
|
3222
|
-
/**
|
|
3223
|
-
* Every `Identifier` in the file whose name passes `wanted`, in document order.
|
|
3224
|
-
*
|
|
3225
|
-
* Not `getDescendantsOfKind(SyntaxKind.Identifier)`. `Identifier` is kind 80 and sorts *below*
|
|
3226
|
-
* `SyntaxKind.FirstNode` (167), which is the boundary between tokens and parse-tree nodes — so
|
|
3227
|
-
* ts-morph cannot search the parse tree for it and falls back to materializing the whole
|
|
3228
|
-
* **token** tree. Measured at 27x this walk for the same 21,466 identifiers across 178 real
|
|
3229
|
-
* files, and `usedAsValue` below pays it once per name, so the file was re-scanned in full for
|
|
3230
|
-
* every binding it asked about.
|
|
3231
|
-
*
|
|
3232
|
-
* The name is tested on the compiler node, before any ts-morph wrapper is built, because the
|
|
3233
|
-
* wrapper is the expensive half and almost every identifier in a file is not one of the handful
|
|
3234
|
-
* this pass cares about. `nameOf` reads the same `escapedText` for an identifier, so the two
|
|
3235
|
-
* agree by construction.
|
|
3236
|
-
*
|
|
3237
|
-
* The JSDoc walk is load-bearing rather than defensive: `ts.forEachChild` does not descend into
|
|
3238
|
-
* JSDoc, but `getDescendantsOfKind` reaches it, and 72 of 1,116 files in this repository carry
|
|
3239
|
-
* an identifier visible only that way. Dropping those reads as "this token is never used" and
|
|
3240
|
-
* prunes a rule that is live — the silent direction, with no failing test to catch it.
|
|
3241
|
-
*/
|
|
3242
|
-
function* identifiersNamed(sourceFile, wanted) {
|
|
3243
|
-
const found = [];
|
|
3244
|
-
const collect = (node) => {
|
|
3245
|
-
if (node.kind === _bamboocss_ts_ast.SyntaxKind.Identifier && wanted(String(node.text))) found.push(node);
|
|
3246
|
-
const jsDoc = node.jsDoc;
|
|
3247
|
-
if (jsDoc) for (const doc of jsDoc) collect(doc);
|
|
3248
|
-
_bamboocss_ts_ast.ts.forEachChild(node, collect);
|
|
3249
|
-
};
|
|
3250
|
-
collect(sourceFile);
|
|
3251
|
-
for (const node of found) yield node;
|
|
3252
|
-
}
|
|
3253
|
-
/**
|
|
3254
|
-
* An identifier's name as the compiler resolves it, not as it is spelled.
|
|
3255
|
-
*
|
|
3256
|
-
* `token` is the identifier `token`; reading `getText()` returns the escape and compares
|
|
3257
|
-
* unequal, which let an import of the artifact's export past the checks that key on the name.
|
|
3258
|
-
*/
|
|
3259
|
-
const nameOf = (node) => _bamboocss_ts_ast.Node.isIdentifier(node) ? String(node.text) : node.getText();
|
|
3260
|
-
/** Every name a binding name binds, following object and array destructuring. */
|
|
3261
|
-
function boundNames(name, bound) {
|
|
3262
|
-
if (!name) return;
|
|
3263
|
-
if (_bamboocss_ts_ast.Node.isIdentifier(name)) {
|
|
3264
|
-
bound(nameOf(name));
|
|
3265
|
-
return;
|
|
3266
|
-
}
|
|
3267
|
-
if (!_bamboocss_ts_ast.Node.isObjectBindingPattern(name) && !_bamboocss_ts_ast.Node.isArrayBindingPattern(name)) return;
|
|
3268
|
-
for (const element of name.elements) if (_bamboocss_ts_ast.Node.isBindingElement(element)) boundNames(element.name, bound);
|
|
3269
|
-
}
|
|
3270
|
-
/**
|
|
3271
|
-
* Scopes that bind a name to something which cannot be the artifact, keyed by that name.
|
|
3272
|
-
*
|
|
3273
|
-
* A parameter named `token` is not the `token` export. `items.map((token) => token.value)`
|
|
3274
|
-
* iterates token *objects* — from `@bamboocss/token-dictionary`, or from any list — and `token`
|
|
3275
|
-
* is the obvious name to reach for. The identifier walk keyed on the spelling alone, so every
|
|
3276
|
-
* read off such a parameter declined as an `unresolved-reference`, and one decline anywhere
|
|
3277
|
-
* keeps every declaration in the project.
|
|
3278
|
-
*
|
|
3279
|
-
* That is not hypothetical: on this repository's own documentation site it was 40 declines
|
|
3280
|
-
* across seven components, none of them a token call, holding a token layer of 500 declarations
|
|
3281
|
-
* where 146 are referenced. Token accounting there emitted a byte-identical
|
|
3282
|
-
* stylesheet and a wall of warnings — the feature reporting loudly that it had done nothing.
|
|
3283
|
-
*
|
|
3284
|
-
* Only the forms that *cannot* hold the artifact are collected. A parameter, a catch variable,
|
|
3285
|
-
* and a function or class declaration each bind something this file defines. A `const token = …`
|
|
3286
|
-
* in general does not — its initializer can be anything, including the artifact reached through a
|
|
3287
|
-
* barrel — so it goes on declining. Declining is free; accepting a reference whose path is never
|
|
3288
|
-
* recorded is the failure this module exists to prevent.
|
|
3289
|
-
*
|
|
3290
|
-
* The one variable form that is collected is a read off a binding already known to be local:
|
|
3291
|
-
* `const { token } = props` is whatever `props` holds, and `props` is a parameter. Rooting the
|
|
3292
|
-
* test at a local binding is what keeps `const { token } = ui` — a namespace import, which a
|
|
3293
|
-
* barrel could make the artifact — declining as before.
|
|
3294
|
-
*/
|
|
3295
|
-
function shadowedScopes(sourceFile) {
|
|
3296
|
-
const scopes = /* @__PURE__ */ new Map();
|
|
3297
|
-
const add = (name, scope) => {
|
|
3298
|
-
if (!scope) return;
|
|
3299
|
-
const existing = scopes.get(name);
|
|
3300
|
-
if (existing) existing.push(scope);
|
|
3301
|
-
else scopes.set(name, [scope]);
|
|
3302
|
-
};
|
|
3303
|
-
const variables = [];
|
|
3304
|
-
(0, _bamboocss_ts_ast.forEachDescendant)(sourceFile, (node) => {
|
|
3305
|
-
if (_bamboocss_ts_ast.Node.isParameterDeclaration(node)) {
|
|
3306
|
-
const scope = node.parent;
|
|
3307
|
-
boundNames(node.name, (name) => add(name, scope));
|
|
3308
|
-
return;
|
|
3309
|
-
}
|
|
3310
|
-
if (_bamboocss_ts_ast.Node.isCatchClause(node)) {
|
|
3311
|
-
boundNames(node.variableDeclaration?.name, (name) => add(name, node));
|
|
3312
|
-
return;
|
|
3313
|
-
}
|
|
3314
|
-
if (_bamboocss_ts_ast.Node.isFunctionDeclaration(node) || _bamboocss_ts_ast.Node.isClassDeclaration(node)) {
|
|
3315
|
-
const name = node.name;
|
|
3316
|
-
if (name) add(nameOf(name), node.parent);
|
|
3317
|
-
return;
|
|
3318
|
-
}
|
|
3319
|
-
if (_bamboocss_ts_ast.Node.isFunctionExpression(node) || _bamboocss_ts_ast.Node.isClassExpression(node)) {
|
|
3320
|
-
const name = node.name;
|
|
3321
|
-
if (name) add(nameOf(name), node);
|
|
3322
|
-
return;
|
|
3323
|
-
}
|
|
3324
|
-
if (_bamboocss_ts_ast.Node.isVariableDeclaration(node)) variables.push(node);
|
|
3325
|
-
});
|
|
3326
|
-
for (const declaration of variables) {
|
|
3327
|
-
if (!_bamboocss_ts_ast.Node.isVariableDeclaration(declaration)) continue;
|
|
3328
|
-
const root = rootIdentifier(declaration.initializer);
|
|
3329
|
-
if (!root || !isShadowed(root, scopes.get(nameOf(root)))) continue;
|
|
3330
|
-
const scope = (0, _bamboocss_ts_ast.getFirstAncestor)(declaration, (ancestor) => _bamboocss_ts_ast.Node.isBlock(ancestor) || _bamboocss_ts_ast.Node.isSourceFile(ancestor) || _bamboocss_ts_ast.Node.isModuleBlock(ancestor) || _bamboocss_ts_ast.Node.isCaseClause(ancestor) || _bamboocss_ts_ast.Node.isDefaultClause(ancestor) || _bamboocss_ts_ast.Node.isForStatement(ancestor) || _bamboocss_ts_ast.Node.isForOfStatement(ancestor) || _bamboocss_ts_ast.Node.isForInStatement(ancestor));
|
|
3331
|
-
boundNames(declaration.name, (name) => add(name, scope));
|
|
3332
|
-
}
|
|
3333
|
-
return scopes;
|
|
3334
|
-
}
|
|
3335
|
-
/**
|
|
3336
|
-
* The identifier an expression is rooted at, for the member reads that keep it local.
|
|
3337
|
-
*
|
|
3338
|
-
* `props`, `props.theme` and `props['theme']` all root at `props`. Anything else — a call, an
|
|
3339
|
-
* `await`, a literal — returns nothing, so the variable it initializes is not treated as local.
|
|
3340
|
-
*/
|
|
3341
|
-
function rootIdentifier(expression) {
|
|
3342
|
-
let current = expression;
|
|
3343
|
-
while (current && (_bamboocss_ts_ast.Node.isPropertyAccessExpression(current) || _bamboocss_ts_ast.Node.isElementAccessExpression(current))) current = current.expression;
|
|
3344
|
-
return current && _bamboocss_ts_ast.Node.isIdentifier(current) ? current : void 0;
|
|
3345
|
-
}
|
|
3346
|
-
/**
|
|
3347
|
-
* Whether an identifier is the *name* of a declaration rather than a read of one.
|
|
3348
|
-
*
|
|
3349
|
-
* `interface Props { token: Token }` names a member and reads nothing, but reached
|
|
3350
|
-
* `accountedPath`, which cannot read it and so declined — and an `unresolved-reference` is the
|
|
3351
|
-
* one decline that fails a strict build. `PropertyAssignment` was already excluded for this
|
|
3352
|
-
* reason; the type and class members are the same statement about a different node.
|
|
3353
|
-
*
|
|
3354
|
-
* `ShorthandPropertyAssignment` is deliberately absent: `{ token }` names a property *and* reads
|
|
3355
|
-
* the binding, so it is a reference like any other.
|
|
3356
|
-
*/
|
|
3357
|
-
function isDeclarationName(identifier, parent) {
|
|
3358
|
-
if (_bamboocss_ts_ast.Node.isPropertyAssignment(parent) || _bamboocss_ts_ast.Node.isPropertySignatureDeclaration(parent) || _bamboocss_ts_ast.Node.isMethodSignatureDeclaration(parent) || _bamboocss_ts_ast.Node.isPropertyDeclaration(parent) || _bamboocss_ts_ast.Node.isMethodDeclaration(parent) || _bamboocss_ts_ast.Node.isEnumMember(parent)) return (0, _bamboocss_ts_ast.nameNodeOf)(parent) === identifier;
|
|
3359
|
-
return false;
|
|
3360
|
-
}
|
|
3361
|
-
/**
|
|
3362
|
-
* Whether an occurrence falls inside one of the scopes that shadow its name.
|
|
3363
|
-
*
|
|
3364
|
-
* Both nodes come from the same file, so containment in the tree is containment in the source
|
|
3365
|
-
* range — which answers it without walking ancestors once per candidate scope.
|
|
3366
|
-
*/
|
|
3367
|
-
function isShadowed(identifier, scopes) {
|
|
3368
|
-
if (!scopes) return false;
|
|
3369
|
-
const start = identifier.getStart();
|
|
3370
|
-
const end = identifier.getEnd();
|
|
3371
|
-
return scopes.some((scope) => scope.getStart() <= start && end <= scope.getEnd());
|
|
3372
|
-
}
|
|
3373
|
-
/**
|
|
3374
|
-
* What one occurrence asks for, or `undefined` if it is not a call this can read.
|
|
3375
|
-
*
|
|
3376
|
-
* Accepts the callee position and nothing else — `token('x')`, `token.value('x')`, and the
|
|
3377
|
-
* namespaced spellings of each. An identifier anywhere else is a value
|
|
3378
|
-
* escaping somewhere this pass cannot follow: assigned (`const t = token`), passed
|
|
3379
|
-
* (`useMemo(() => token)`), spread, or enumerated.
|
|
3380
|
-
*/
|
|
3381
|
-
function accountedPath(identifier) {
|
|
3382
|
-
const parent = identifier.parent;
|
|
3383
|
-
if (!parent) return void 0;
|
|
3384
|
-
if (_bamboocss_ts_ast.Node.isImportSpecifier(parent) || _bamboocss_ts_ast.Node.isNamespaceImport(parent) || _bamboocss_ts_ast.Node.isImportClause(parent) || _bamboocss_ts_ast.Node.isExportSpecifier(parent)) return { kind: "binding" };
|
|
3385
|
-
if (_bamboocss_ts_ast.Node.isCallExpression(parent) && parent.expression === identifier) return literalPath(parent);
|
|
3386
|
-
if (!_bamboocss_ts_ast.Node.isPropertyAccessExpression(parent) || parent.expression !== identifier) return void 0;
|
|
3387
|
-
const property = parent.name.getText();
|
|
3388
|
-
const grandParent = parent.parent;
|
|
3389
|
-
if (property === "value") return _bamboocss_ts_ast.Node.isCallExpression(grandParent) && grandParent.expression === parent ? literalPath(grandParent) : void 0;
|
|
3390
|
-
if (property !== "token") return void 0;
|
|
3391
|
-
if (_bamboocss_ts_ast.Node.isCallExpression(grandParent) && grandParent.expression === parent) return literalPath(grandParent);
|
|
3392
|
-
if (_bamboocss_ts_ast.Node.isPropertyAccessExpression(grandParent) && grandParent.expression === parent) {
|
|
3393
|
-
if (grandParent.name.getText() !== "value") return void 0;
|
|
3394
|
-
const call = grandParent.parent;
|
|
3395
|
-
return _bamboocss_ts_ast.Node.isCallExpression(call) && call.expression === grandParent ? literalPath(call) : void 0;
|
|
3396
|
-
}
|
|
3397
|
-
}
|
|
3398
|
-
/**
|
|
3399
|
-
* The path a call asks for, or the prefix it is bounded by.
|
|
3400
|
-
*
|
|
3401
|
-
* Read through `getLiteralValue()`, never off the source text. The text carries escapes —
|
|
3402
|
-
* `token('colors.red.300')` — and a path recorded raw looks up nothing, which
|
|
3403
|
-
* would accept a reference and keep no declaration for it. That is the exact failure this
|
|
3404
|
-
* module exists to make unrepresentable.
|
|
3405
|
-
*
|
|
3406
|
-
* A template literal with substitutions is not a path, but it is not unbounded either: its
|
|
3407
|
-
* head is a prefix everything it can produce begins with. Declining one cost every token
|
|
3408
|
-
* declaration in the project; bounding it costs the category. The head is the *whole* answer —
|
|
3409
|
-
* `` `colors.${a}.${b}` `` bounds no more tightly than `` `colors.${x}` `` does — and an empty
|
|
3410
|
-
* head bounds nothing at all, so that still declines.
|
|
3411
|
-
*/
|
|
3412
|
-
function literalPath(call) {
|
|
3413
|
-
if (!_bamboocss_ts_ast.Node.isCallExpression(call)) return void 0;
|
|
3414
|
-
const argument = unwrapAssertions(call.arguments[0]);
|
|
3415
|
-
if (!argument) return void 0;
|
|
3416
|
-
if (_bamboocss_ts_ast.Node.isStringLiteral(argument)) return {
|
|
3417
|
-
kind: "path",
|
|
3418
|
-
value: (0, _bamboocss_ts_ast.stringLiteralValue)(argument)
|
|
3419
|
-
};
|
|
3420
|
-
if (_bamboocss_ts_ast.Node.isNoSubstitutionTemplateLiteral(argument)) return {
|
|
3421
|
-
kind: "path",
|
|
3422
|
-
value: (0, _bamboocss_ts_ast.stringLiteralValue)(argument)
|
|
3423
|
-
};
|
|
3424
|
-
if (_bamboocss_ts_ast.Node.isTemplateExpression(argument)) {
|
|
3425
|
-
const head = (0, _bamboocss_ts_ast.getLiteralText)(argument.head);
|
|
3426
|
-
return head ? {
|
|
3427
|
-
kind: "prefix",
|
|
3428
|
-
value: head
|
|
3429
|
-
} : void 0;
|
|
3430
|
-
}
|
|
3431
|
-
}
|
|
3432
|
-
/**
|
|
3433
|
-
* Whether a binding is read anywhere outside a type position.
|
|
3434
|
-
*
|
|
3435
|
-
* `import { Token, token }` brings in a type beside the value, and a type cannot produce a
|
|
3436
|
-
* `var()` — but a binding that is *called* can, whatever it is named, because a barrel
|
|
3437
|
-
* matching the specifier test could re-export `token` under it.
|
|
3438
|
-
*/
|
|
3439
|
-
function usedAsValue(sourceFile, name, declaration) {
|
|
3440
|
-
for (const identifier of identifiersNamed(sourceFile, (candidate) => candidate === name)) {
|
|
3441
|
-
if ((0, _bamboocss_ts_ast.getFirstAncestor)(identifier, (ancestor) => ancestor === declaration)) continue;
|
|
3442
|
-
if (!(0, _bamboocss_ts_ast.getFirstAncestor)(identifier, (ancestor) => _bamboocss_ts_ast.Node.isTypeNode(ancestor))) return true;
|
|
3443
|
-
}
|
|
3444
|
-
return false;
|
|
3445
|
-
}
|
|
3446
|
-
/**
|
|
3447
|
-
* Strip the wrappers that carry no runtime meaning.
|
|
3448
|
-
*
|
|
3449
|
-
* `` token(`animations.${name}` as Token) `` is the shape a *typed* caller writes, and has to
|
|
3450
|
-
* be: the generated `Token` type is a union of template literals, so a `string`-typed
|
|
3451
|
-
* substitution does not typecheck without the assertion. Reading only the outermost node
|
|
3452
|
-
* declined exactly the call this bounding exists for — the one in this repository's own
|
|
3453
|
-
* documentation site.
|
|
3454
|
-
*
|
|
3455
|
-
* Each of these evaluates to its inner expression, so unwrapping changes nothing about what
|
|
3456
|
-
* the call receives.
|
|
3457
|
-
*/
|
|
3458
|
-
function unwrapAssertions(node) {
|
|
3459
|
-
let current = node;
|
|
3460
|
-
while (current && (_bamboocss_ts_ast.Node.isAsExpression(current) || _bamboocss_ts_ast.Node.isSatisfiesExpression(current) || _bamboocss_ts_ast.Node.isNonNullExpression(current) || _bamboocss_ts_ast.Node.isParenthesizedExpression(current) || _bamboocss_ts_ast.Node.isTypeAssertion(current))) current = current.expression;
|
|
3461
|
-
return current;
|
|
3462
|
-
}
|
|
3463
3484
|
//#endregion
|
|
3464
3485
|
//#region src/token-references.ts
|
|
3465
3486
|
/**
|
|
@@ -3925,20 +3946,12 @@ var Builder = class {
|
|
|
3925
3946
|
configGraphMtimes;
|
|
3926
3947
|
/** Per-file source-scan results for `toCss`, valid while each file's mtime stands still. */
|
|
3927
3948
|
sourceScanCache = createSourceScanCache();
|
|
3928
|
-
/**
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
/** Whether each file changed this pass kept its recipe surface; consulted by dependents. */
|
|
3933
|
-
recipeSurfaceStable = /* @__PURE__ */ new Map();
|
|
3934
|
-
/** Files this pass re-extracts because their bytes moved, as `sourcePath` spellings. */
|
|
3935
|
-
changedThisPass = /* @__PURE__ */ new Set();
|
|
3936
|
-
/** Whether this pass selected any owner through resolution-configuration changes. */
|
|
3937
|
-
resolutionAffectedThisPass = false;
|
|
3938
|
-
/** Per-pass digests of re-read values, so N dependents of one edit digest each value once. */
|
|
3939
|
-
readDigestMemo = /* @__PURE__ */ new Map();
|
|
3940
|
-
/** Resolution ledger as it stood before this pass's first physical source mutation. */
|
|
3949
|
+
/**
|
|
3950
|
+
* Dependency edges as they stood before this pass's first source mutation, and the owners
|
|
3951
|
+
* each changed file reached then — before re-extraction replaces the edges that found them.
|
|
3952
|
+
*/
|
|
3941
3953
|
capturedLedger;
|
|
3954
|
+
capturedDependents = /* @__PURE__ */ new Map();
|
|
3942
3955
|
/**
|
|
3943
3956
|
* Reload one edited source, keeping the closure the next extraction pass has to select.
|
|
3944
3957
|
*
|
|
@@ -3954,18 +3967,20 @@ var Builder = class {
|
|
|
3954
3967
|
*/
|
|
3955
3968
|
reloadSource = (filePath) => {
|
|
3956
3969
|
const ctx = this.getContextOrThrow();
|
|
3957
|
-
this.captureResolutionLedger(ctx);
|
|
3958
|
-
|
|
3970
|
+
this.captureResolutionLedger(ctx, filePath);
|
|
3971
|
+
ctx.project.reloadSourceFile(filePath);
|
|
3959
3972
|
};
|
|
3960
3973
|
/** The deletion half of `reloadSource`, with the same snapshot obligation. */
|
|
3961
3974
|
removeSource = (filePath) => {
|
|
3962
3975
|
const ctx = this.getContextOrThrow();
|
|
3963
|
-
this.captureResolutionLedger(ctx);
|
|
3976
|
+
this.captureResolutionLedger(ctx, filePath);
|
|
3977
|
+
ctx.project.removeSourceFile(filePath);
|
|
3964
3978
|
ctx.forgetNativeFile(filePath);
|
|
3965
|
-
return ctx.project.removeSourceFile(filePath);
|
|
3966
3979
|
};
|
|
3967
|
-
captureResolutionLedger = (ctx) => {
|
|
3968
|
-
this.capturedLedger ??= ctx.
|
|
3980
|
+
captureResolutionLedger = (ctx, filePath) => {
|
|
3981
|
+
this.capturedLedger ??= ctx.getNativeDependencyLedger();
|
|
3982
|
+
const file = this.absOwner(ctx, filePath);
|
|
3983
|
+
if (!this.capturedDependents.has(file)) this.capturedDependents.set(file, ctx.getNativeDependents(file));
|
|
3969
3984
|
};
|
|
3970
3985
|
/** @internal Current and missing resolver paths which can change the stylesheet. */
|
|
3971
3986
|
getResolutionReadFiles = () => {
|
|
@@ -4109,9 +4124,8 @@ var Builder = class {
|
|
|
4109
4124
|
this.resolutionConfigurationBytes.clear();
|
|
4110
4125
|
this.sourceScanCache.entries.clear();
|
|
4111
4126
|
this.sourceScanCache.resolvedTokenReferences.clear();
|
|
4112
|
-
this.extractionReadsByOwner.clear();
|
|
4113
|
-
this.recipeSurfaceByOwner.clear();
|
|
4114
4127
|
this.capturedLedger = void 0;
|
|
4128
|
+
this.capturedDependents.clear();
|
|
4115
4129
|
await ctx.hooks["config:change"]?.({
|
|
4116
4130
|
config: ctx.config,
|
|
4117
4131
|
changes: this.affecteds
|
|
@@ -4152,14 +4166,14 @@ var Builder = class {
|
|
|
4152
4166
|
const changedResolutionConfigurations = this.changedResolutionConfigurations(knownChanges);
|
|
4153
4167
|
const changedResolutionSet = new Set(changedResolutionConfigurations);
|
|
4154
4168
|
const resolutionAffected = /* @__PURE__ */ new Set();
|
|
4155
|
-
const resolutionLedger = this.capturedLedger ?? (changedResolutionConfigurations.length ? ctx.
|
|
4169
|
+
const resolutionLedger = this.capturedLedger ?? (changedResolutionConfigurations.length ? ctx.getNativeDependencyLedger() : void 0);
|
|
4170
|
+
const capturedDependents = this.capturedDependents;
|
|
4156
4171
|
this.capturedLedger = void 0;
|
|
4172
|
+
this.capturedDependents = /* @__PURE__ */ new Map();
|
|
4157
4173
|
for (const [owner, configurations] of this.resolutionConfigurationSets) if (configurations.some((file) => changedResolutionSet.has(file))) resolutionAffected.add(owner);
|
|
4158
|
-
this.resolutionAffectedThisPass = resolutionAffected.size > 0;
|
|
4159
4174
|
if (changedResolutionConfigurations.length) {
|
|
4160
4175
|
const tsconfigCandidates = new Set([...previousTsconfigFiles, ...this.tsconfigResolutionFiles]);
|
|
4161
|
-
|
|
4162
|
-
ctx.project.refreshResolutionConfiguration(ctx.conf.tsconfig?.compilerOptions, this.tsconfigResolutionFiles, replaceCompilerOptions);
|
|
4176
|
+
if (changedResolutionConfigurations.some((file) => tsconfigCandidates.has(file))) ctx.project.refreshResolutionConfiguration(ctx.conf.tsconfig?.compilerOptions);
|
|
4163
4177
|
}
|
|
4164
4178
|
const needsInventoryScan = !sourceChanges || sourceChanges.needsInventoryScan || this.sourceInventory === void 0;
|
|
4165
4179
|
const inventory = needsInventoryScan ? ctx.getFiles() : [...this.sourceInventory];
|
|
@@ -4177,10 +4191,10 @@ var Builder = class {
|
|
|
4177
4191
|
for (const [file, meta] of this.filesMeta?.changes ?? []) if (!meta.isUnchanged) this.sourceScanCache.entries.delete(this.absOwner(ctx, file));
|
|
4178
4192
|
if (this.filesMeta?.hasFilesChanged) {
|
|
4179
4193
|
_bamboocss_logger.logger.debug("builder", "Files changed, invalidating them");
|
|
4180
|
-
this.invalidateChangedSources(ctx, inventory, resolutionAffected, resolutionLedger);
|
|
4194
|
+
this.invalidateChangedSources(ctx, inventory, resolutionAffected, resolutionLedger, capturedDependents);
|
|
4181
4195
|
} else if (changedResolutionConfigurations.length) {
|
|
4182
4196
|
ctx.encoder?.reconcileFileOwnerOrder("extract", inventory);
|
|
4183
|
-
this.extractionOrder = this.orderAffectedFiles(inventory, resolutionAffected, resolutionLedger ?? []
|
|
4197
|
+
this.extractionOrder = this.orderAffectedFiles(inventory, resolutionAffected, resolutionLedger ?? []);
|
|
4184
4198
|
this.affectedFiles = new Set(this.extractionOrder.map(this.sourcePath));
|
|
4185
4199
|
} else {
|
|
4186
4200
|
this.affectedFiles = /* @__PURE__ */ new Set();
|
|
@@ -4191,43 +4205,35 @@ var Builder = class {
|
|
|
4191
4205
|
/** Normalize the path identity shared by the Project ledger and file-owner keys. */
|
|
4192
4206
|
sourcePath = (file) => file.replaceAll("\\", "/");
|
|
4193
4207
|
/**
|
|
4194
|
-
*
|
|
4208
|
+
* Refresh changed sources, then select them and their transitive included consumers.
|
|
4195
4209
|
*
|
|
4196
|
-
*
|
|
4197
|
-
*
|
|
4198
|
-
*
|
|
4199
|
-
*
|
|
4210
|
+
* Consumers come from the native evaluator's read graph, which includes paths a consumer
|
|
4211
|
+
* probed and did not find — so a file appearing reaches the importers that were waiting for
|
|
4212
|
+
* it. The graph is read before anything is re-extracted: re-extraction replaces an owner's
|
|
4213
|
+
* edges, and waiting would lose the very closure the rebuild needs. An integration that
|
|
4214
|
+
* mutated sources earlier in the pass captured it then (`reloadSource`, `removeSource`).
|
|
4200
4215
|
*/
|
|
4201
|
-
invalidateChangedSources = (ctx, inventory, seededAffected = /* @__PURE__ */ new Set(), previousLedger) => {
|
|
4202
|
-
const project = ctx.project;
|
|
4216
|
+
invalidateChangedSources = (ctx, inventory, seededAffected = /* @__PURE__ */ new Set(), previousLedger, capturedDependents = /* @__PURE__ */ new Map()) => {
|
|
4203
4217
|
const current = new Set(inventory.map(this.sourcePath));
|
|
4204
4218
|
const changed = [...this.filesMeta?.changes ?? []].filter(([, meta]) => !meta.isUnchanged).map(([file]) => this.sourcePath(file));
|
|
4205
|
-
const ledger = previousLedger ??
|
|
4206
|
-
const pending = project.getUnresolvedImporters().map(this.sourcePath);
|
|
4219
|
+
const ledger = previousLedger ?? ctx.getNativeDependencyLedger();
|
|
4207
4220
|
const affected = new Set(seededAffected);
|
|
4208
|
-
const added = [];
|
|
4209
4221
|
for (const file of changed) {
|
|
4210
4222
|
if (current.has(file)) affected.add(file);
|
|
4211
|
-
for (const dependent of
|
|
4223
|
+
for (const dependent of capturedDependents.get(file) ?? []) affected.add(this.sourcePath(dependent));
|
|
4212
4224
|
for (const dependent of ctx.getNativeDependents(file)) affected.add(this.sourcePath(dependent));
|
|
4213
|
-
if ((0, fs.existsSync)(file) && !project.getSourceFile(file)) added.push(file);
|
|
4214
|
-
}
|
|
4215
|
-
if (added.length) for (const importer of pending) {
|
|
4216
|
-
affected.add(importer);
|
|
4217
|
-
for (const dependent of project.getDependents(importer)) affected.add(this.sourcePath(dependent));
|
|
4218
4225
|
}
|
|
4219
4226
|
for (const file of changed) if (!(0, fs.existsSync)(file)) {
|
|
4220
|
-
project.removeSourceFile(file);
|
|
4227
|
+
ctx.project.removeSourceFile(file);
|
|
4228
|
+
ctx.forgetNativeFile(file);
|
|
4221
4229
|
fileModifiedMap.set(file, -Infinity);
|
|
4222
|
-
} else
|
|
4223
|
-
else project.createSourceFile(file);
|
|
4230
|
+
} else ctx.project.reloadSourceFile(file);
|
|
4224
4231
|
ctx.encoder?.reconcileFileOwnerOrder("extract", inventory);
|
|
4225
|
-
|
|
4226
|
-
this.extractionOrder = this.orderAffectedFiles(inventory, affected, ledger, syntheticEdges);
|
|
4232
|
+
this.extractionOrder = this.orderAffectedFiles(inventory, affected, ledger);
|
|
4227
4233
|
this.affectedFiles = new Set(this.extractionOrder.map(this.sourcePath));
|
|
4228
4234
|
};
|
|
4229
4235
|
/** Deterministic topological order, with current inventory order as the stable tie-break. */
|
|
4230
|
-
orderAffectedFiles = (inventory, affected, ledger
|
|
4236
|
+
orderAffectedFiles = (inventory, affected, ledger) => {
|
|
4231
4237
|
const files = inventory.filter((file) => affected.has(this.sourcePath(file)));
|
|
4232
4238
|
const byPath = new Map(files.map((file) => [this.sourcePath(file), file]));
|
|
4233
4239
|
const inventoryRank = new Map(files.map((file, index) => [this.sourcePath(file), index]));
|
|
@@ -4244,9 +4250,8 @@ var Builder = class {
|
|
|
4244
4250
|
outgoing.set(target, importers);
|
|
4245
4251
|
indegree.set(importer, (indegree.get(importer) ?? 0) + 1);
|
|
4246
4252
|
};
|
|
4247
|
-
for (const
|
|
4253
|
+
for (const [target, importer] of ledger) addEdge(target, importer);
|
|
4248
4254
|
for (const [target, importer] of this.getContextOrThrow().getNativeDependencyLedger()) addEdge(target, importer);
|
|
4249
|
-
for (const [target, importer] of syntheticEdges) addEdge(target, importer);
|
|
4250
4255
|
const compare = (left, right) => (inventoryRank.get(left) ?? 0) - (inventoryRank.get(right) ?? 0);
|
|
4251
4256
|
const ready = new MinPriorityQueue(compare);
|
|
4252
4257
|
for (const [file, degree] of indegree) if (degree === 0) ready.push(file);
|
|
@@ -4310,45 +4315,8 @@ var Builder = class {
|
|
|
4310
4315
|
if (!this.context) throw new _bamboocss_shared.BambooError("NO_CONTEXT", "context not loaded");
|
|
4311
4316
|
return this.context;
|
|
4312
4317
|
};
|
|
4313
|
-
/**
|
|
4314
|
-
* The changed file's recipe surface: every declared `cva`/`sva` config, in declaration
|
|
4315
|
-
* order, plus the text of every export statement. A value edit inside a `css()` call moves
|
|
4316
|
-
* neither; a recipe config edit moves the first; an export alias or re-export edit — which
|
|
4317
|
-
* can re-route what a consumer's call resolves to without any declaration changing — moves
|
|
4318
|
-
* the second. `undefined` when any part cannot be pinned down, which disables skipping.
|
|
4319
|
-
*/
|
|
4320
|
-
digestRecipeSurface = (ctx, file, parserResult) => {
|
|
4321
|
-
try {
|
|
4322
|
-
const recipes = [];
|
|
4323
|
-
for (const set of [parserResult?.cva, parserResult?.sva]) for (const item of set ?? []) recipes.push([item.name ?? "", item.data]);
|
|
4324
|
-
const sourceFile = ctx.project?.getSourceFile?.(file);
|
|
4325
|
-
const exports = sourceFile ? (0, _bamboocss_ts_ast.getExportDeclarations)(sourceFile).map((declaration) => declaration.getText()) : [];
|
|
4326
|
-
const json = JSON.stringify([recipes, exports], (_key, value) => value === void 0 ? "bamboo:undefined" : value);
|
|
4327
|
-
if (json === void 0) return void 0;
|
|
4328
|
-
return (0, node_crypto.createHash)("sha256").update(json).digest("base64");
|
|
4329
|
-
} catch {
|
|
4330
|
-
return;
|
|
4331
|
-
}
|
|
4332
|
-
};
|
|
4333
4318
|
/** One canonical spelling for verification keys: absolute, forward slashes. */
|
|
4334
4319
|
absOwner = (ctx, file) => this.sourcePath(ctx.runtime?.path?.abs ? ctx.runtime.path.abs(ctx.config.cwd, file) : file);
|
|
4335
|
-
/** Whether every changed file this dependent reads kept both its values and its surface. */
|
|
4336
|
-
dependentUnchangedByReads = (ctx, owner) => {
|
|
4337
|
-
if (this.resolutionAffectedThisPass || this.changedThisPass.size === 0) return false;
|
|
4338
|
-
const reads = this.extractionReadsByOwner.get(owner);
|
|
4339
|
-
if (reads === void 0) return false;
|
|
4340
|
-
for (const changed of this.changedThisPass) if (this.recipeSurfaceStable.get(changed) !== true) return false;
|
|
4341
|
-
for (const read of reads) {
|
|
4342
|
-
const readOwner = this.sourcePath(ctx.runtime.path.abs(ctx.config.cwd, read.file));
|
|
4343
|
-
if (!this.changedThisPass.has(readOwner)) continue;
|
|
4344
|
-
if (read.digest === void 0) return false;
|
|
4345
|
-
const key = `${read.file}\u0000${read.name}`;
|
|
4346
|
-
if (!this.readDigestMemo.has(key)) this.readDigestMemo.set(key, ctx.project.digestExportRead(read.file, read.name));
|
|
4347
|
-
const current = this.readDigestMemo.get(key);
|
|
4348
|
-
if (current === void 0 || current !== read.digest) return false;
|
|
4349
|
-
}
|
|
4350
|
-
return true;
|
|
4351
|
-
};
|
|
4352
4320
|
getFileMeta = (file) => {
|
|
4353
4321
|
const mtime = (0, fs.existsSync)(file) ? (0, fs.statSync)(file).mtimeMs : -Infinity;
|
|
4354
4322
|
return {
|
|
@@ -4374,18 +4342,6 @@ var Builder = class {
|
|
|
4374
4342
|
const meta = this.filesMeta?.changes.get(file) ?? this.getFileMeta(file);
|
|
4375
4343
|
const hasConfigChanged = this.affecteds ? this.affecteds.hasConfigChanged : true;
|
|
4376
4344
|
if (meta.isUnchanged && !hasConfigChanged && !this.affectedFiles?.has(this.sourcePath(file))) return;
|
|
4377
|
-
/**
|
|
4378
|
-
* A dependent selected only because a file it reads changed can be verified instead of
|
|
4379
|
-
* re-extracted: its own bytes did not move, so its extraction output moves only if a
|
|
4380
|
-
* value it read moved, or if the changed file's recipe surface — which decides how its
|
|
4381
|
-
* calls classify — moved. Both are checked against digests recorded when this owner was
|
|
4382
|
-
* last extracted; the changed file itself was re-extracted earlier in this same ordered
|
|
4383
|
-
* pass, which is what makes the surface comparison current. Any gap — a read that could
|
|
4384
|
-
* not be digested, a surface this pass has no verdict for, a JSX-component config whose
|
|
4385
|
-
* classification these records do not witness — falls through to the re-extraction this
|
|
4386
|
-
* replaces.
|
|
4387
|
-
*/
|
|
4388
|
-
if (meta.isUnchanged && !hasConfigChanged && !this.changedThisPass.has(this.absOwner(ctx, file)) && !(ctx.jsx?.isEnabled ?? true) && this.dependentUnchangedByReads(ctx, this.absOwner(ctx, file))) return;
|
|
4389
4345
|
const owner = this.sourcePath(file);
|
|
4390
4346
|
const previousReads = this.resolutionReadSets.get(owner) ?? [];
|
|
4391
4347
|
const previousPending = this.pendingResolutionReadSets.get(owner) ?? [];
|
|
@@ -4394,33 +4350,13 @@ var Builder = class {
|
|
|
4394
4350
|
const parserResult = ctx.parseFile(file);
|
|
4395
4351
|
recordResolvedTokenReferences(this.sourceScanCache, this.absOwner(ctx, file), parserResult);
|
|
4396
4352
|
fileModifiedMap.set(file, meta.mtime);
|
|
4397
|
-
{
|
|
4398
|
-
const owner = this.absOwner(ctx, file);
|
|
4399
|
-
const reads = parserResult?.getExportReads?.() ?? [];
|
|
4400
|
-
const parsedNatively = Boolean(parserResult?.native);
|
|
4401
|
-
if (parsedNatively) this.extractionReadsByOwner.delete(owner);
|
|
4402
|
-
else this.extractionReadsByOwner.set(owner, reads);
|
|
4403
|
-
const surface = !parsedNatively && ctx.project ? this.digestRecipeSurface(ctx, file, parserResult) : void 0;
|
|
4404
|
-
if (this.changedThisPass.has(owner)) {
|
|
4405
|
-
const previous = this.recipeSurfaceByOwner.get(owner);
|
|
4406
|
-
this.recipeSurfaceStable.set(owner, previous !== void 0 && surface !== void 0 && previous === surface);
|
|
4407
|
-
}
|
|
4408
|
-
this.recipeSurfaceByOwner.set(owner, surface);
|
|
4409
|
-
}
|
|
4410
4353
|
if (parserResult) {
|
|
4411
|
-
const
|
|
4412
|
-
dependencies: (0, _bamboocss_shared.uniq)(
|
|
4413
|
-
pendingCandidates:
|
|
4414
|
-
}
|
|
4415
|
-
const nativeResult = parserResult;
|
|
4416
|
-
const native = Boolean(nativeResult.native);
|
|
4417
|
-
const dependencies = parserResult.getDependencies();
|
|
4418
|
-
const readSet = native ? {
|
|
4419
|
-
dependencies: (0, _bamboocss_shared.uniq)(dependencies).sort(),
|
|
4420
|
-
pendingCandidates: (0, _bamboocss_shared.uniq)([...nativeResult.nativePendingCandidates ?? []]).sort()
|
|
4421
|
-
} : ctx.project.getResolutionReadSet(file, dependencies, previousReadSet);
|
|
4354
|
+
const readSet = {
|
|
4355
|
+
dependencies: (0, _bamboocss_shared.uniq)(parserResult.getDependencies()).sort(),
|
|
4356
|
+
pendingCandidates: (0, _bamboocss_shared.uniq)([...parserResult.nativePendingCandidates]).sort()
|
|
4357
|
+
};
|
|
4422
4358
|
const currentReads = readSet.dependencies;
|
|
4423
|
-
const currentConfigurations =
|
|
4359
|
+
const currentConfigurations = (0, _bamboocss_shared.uniq)([...currentReads.length || readSet.pendingCandidates.length ? this.tsconfigResolutionFiles : [], ...parserResult.nativeConfigurationFiles]).sort();
|
|
4424
4360
|
this.resolutionReadSets.set(owner, currentReads);
|
|
4425
4361
|
if (readSet.pendingCandidates.length) this.resolutionCandidateSets.set(owner, readSet.pendingCandidates);
|
|
4426
4362
|
else this.resolutionCandidateSets.delete(owner);
|
|
@@ -4456,9 +4392,6 @@ var Builder = class {
|
|
|
4456
4392
|
}
|
|
4457
4393
|
ctx.encoder?.reconcileFileOwnerOrder("extract", files);
|
|
4458
4394
|
const filesToExtract = hasConfigChanged ? ctx.extractableFiles(files) : this.extractionOrder ?? files;
|
|
4459
|
-
this.changedThisPass = new Set([...this.filesMeta?.changes ?? []].filter(([, fileMeta]) => !fileMeta.isUnchanged).map(([changed]) => this.sourcePath(ctx.runtime.path.abs(ctx.config.cwd, changed))));
|
|
4460
|
-
this.recipeSurfaceStable.clear();
|
|
4461
|
-
this.readDigestMemo.clear();
|
|
4462
4395
|
const done = _bamboocss_logger.logger.time.info("Extracted in");
|
|
4463
4396
|
ctx.prepareNativeExtraction(filesToExtract);
|
|
4464
4397
|
for (const file of filesToExtract) this.extractFile(ctx, file);
|
|
@@ -4733,7 +4666,6 @@ async function generate(config, configPath) {
|
|
|
4733
4666
|
await bundleStyles(ctx, [...new Set([filePath, ...dependents])]);
|
|
4734
4667
|
} else if (event === "add") {
|
|
4735
4668
|
const dependents = ctx.getNativeDependents(filePath);
|
|
4736
|
-
ctx.project.createSourceFile(filePath);
|
|
4737
4669
|
await bundleStyles(ctx, [...new Set([filePath, ...dependents])]);
|
|
4738
4670
|
}
|
|
4739
4671
|
});
|
|
@@ -4916,6 +4848,8 @@ const hasUncompilableSources = (options) => {
|
|
|
4916
4848
|
//#endregion
|
|
4917
4849
|
exports.BambooContext = BambooContext;
|
|
4918
4850
|
exports.Builder = Builder;
|
|
4851
|
+
exports.ParserResult = ParserResult;
|
|
4852
|
+
exports.SourceProject = SourceProject;
|
|
4919
4853
|
exports.analyze = analyze;
|
|
4920
4854
|
exports.buildInfo = buildInfo;
|
|
4921
4855
|
exports.codegen = codegen;
|