@bamboocss/node 1.54.2 → 1.55.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 +322 -29
- package/dist/index.d.cts +23 -2
- package/dist/index.d.mts +23 -2
- package/dist/index.mjs +324 -31
- 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 +15 -14
package/dist/index.cjs
CHANGED
|
@@ -42,6 +42,8 @@ node_fs = __toESM(node_fs);
|
|
|
42
42
|
let node_path = require("node:path");
|
|
43
43
|
node_path = __toESM(node_path);
|
|
44
44
|
let perfect_debounce = require("perfect-debounce");
|
|
45
|
+
let node_module = require("node:module");
|
|
46
|
+
let node_url = require("node:url");
|
|
45
47
|
let node_process = require("node:process");
|
|
46
48
|
node_process = __toESM(node_process, 1);
|
|
47
49
|
let node_os = require("node:os");
|
|
@@ -160,14 +162,14 @@ async function codegen(ctx, ids) {
|
|
|
160
162
|
* from one. A file with no such chain cannot hold a call, whatever else is in it.
|
|
161
163
|
*
|
|
162
164
|
* On a real application that is most of the tree. Measured over 6,425 files: 4,062 could reach
|
|
163
|
-
* an entrypoint and 2,363 provably could not, and not handing the
|
|
165
|
+
* an entrypoint and 2,363 provably could not, and not handing the extractor the latter took the
|
|
164
166
|
* pass from 88.9s to 26.3s with byte-identical CSS out. The scan itself costs ~300ms, because
|
|
165
167
|
* it reads text and never parses.
|
|
166
168
|
*
|
|
167
169
|
* ## Skipping is not the same as ignoring
|
|
168
170
|
*
|
|
169
171
|
* A file left out here is still *reachable*. Cross-file composition works by resolving an
|
|
170
|
-
* import and
|
|
172
|
+
* import and reading what it names, so a module that exports a style object still arrives
|
|
171
173
|
* the moment something that qualifies imports it. What is skipped is only asking "does this
|
|
172
174
|
* file *originate* a call", of a file that has no binding to originate one with.
|
|
173
175
|
*
|
|
@@ -277,8 +279,8 @@ const localTargetOf = (specifier, importer, options) => {
|
|
|
277
279
|
* one — a recipe defined with `cva` in one file and called in another is exactly that shape.
|
|
278
280
|
*
|
|
279
281
|
* The edges are worth more than the walk they were built for. Every one of them names a module
|
|
280
|
-
* that is *going* to be demanded, so the same scan that decides what to parse also says
|
|
281
|
-
*
|
|
282
|
+
* that is *going* to be demanded, so the same scan that decides what to parse also says which
|
|
283
|
+
* virtual or transformed sources the native source map may need — see `auxiliary`.
|
|
282
284
|
*/
|
|
283
285
|
const selectExtractable = (files, options) => {
|
|
284
286
|
const keep = /* @__PURE__ */ new Set();
|
|
@@ -2242,6 +2244,13 @@ var OutputEngine = class {
|
|
|
2242
2244
|
//#region src/create-context.ts
|
|
2243
2245
|
/** A thrown value's message, for a `catch` binding that is typed `unknown`. */
|
|
2244
2246
|
const messageOf = (error) => error instanceof Error ? error.message : String(error);
|
|
2247
|
+
const nativeBinaryName = () => {
|
|
2248
|
+
if (process.platform === "darwin" && process.arch === "arm64") return "darwin-arm64.node";
|
|
2249
|
+
if (process.platform === "darwin" && process.arch === "x64") return "darwin-x64.node";
|
|
2250
|
+
if (process.platform === "linux" && process.arch === "arm64") return "linux-arm64-gnu.node";
|
|
2251
|
+
if (process.platform === "linux" && process.arch === "x64") return "linux-x64-gnu.node";
|
|
2252
|
+
if (process.platform === "win32" && process.arch === "x64") return "win32-x64-msvc.node";
|
|
2253
|
+
};
|
|
2245
2254
|
/**
|
|
2246
2255
|
* What each loss is, and what the author can do about it.
|
|
2247
2256
|
*
|
|
@@ -2292,10 +2301,23 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
2292
2301
|
* never take.
|
|
2293
2302
|
*/
|
|
2294
2303
|
deadCalls = /* @__PURE__ */ new Map();
|
|
2304
|
+
/** Extraction results produced without materializing TypeScript ASTs. */
|
|
2305
|
+
nativeExtractions = /* @__PURE__ */ new Map();
|
|
2306
|
+
/** Native semantic reads retained across incremental passes. */
|
|
2307
|
+
nativeDependencies = /* @__PURE__ */ new Map();
|
|
2308
|
+
nativePendingCandidates = /* @__PURE__ */ new Map();
|
|
2309
|
+
nativeConfigurationFiles = /* @__PURE__ */ new Map();
|
|
2310
|
+
nativeAuxiliaryFiles = [];
|
|
2311
|
+
/** Parser-hook output staged by the prefilter for the following native boundary. */
|
|
2312
|
+
nativePreparedSources = /* @__PURE__ */ new Map();
|
|
2313
|
+
/** Per-file parser-hook options and whether a transform invalidated source locations. */
|
|
2314
|
+
nativeSourceMetadata = /* @__PURE__ */ new Map();
|
|
2315
|
+
parserHooks;
|
|
2295
2316
|
constructor(conf) {
|
|
2296
2317
|
super(conf);
|
|
2297
2318
|
const config = conf.config;
|
|
2298
2319
|
this.runtime = nodeRuntime;
|
|
2320
|
+
this.parserHooks = conf.hooks;
|
|
2299
2321
|
config.cwd ||= this.runtime.cwd();
|
|
2300
2322
|
if (config.logLevel) _bamboocss_logger.logger.level = config.logLevel;
|
|
2301
2323
|
this.project = new _bamboocss_parser.Project({
|
|
@@ -2307,6 +2329,7 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
2307
2329
|
resolutionConfigFiles: getTsConfigResolutionFiles(conf),
|
|
2308
2330
|
getFiles: () => this.getFiles(),
|
|
2309
2331
|
readFile: (filePath) => this.runtime.fs.readFileSync(filePath),
|
|
2332
|
+
fileExists: (filePath) => this.runtime.fs.existsSync(filePath),
|
|
2310
2333
|
hooks: conf.hooks,
|
|
2311
2334
|
parserOptions: {
|
|
2312
2335
|
...this.parserOptions,
|
|
@@ -2451,16 +2474,274 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
2451
2474
|
const outdir = this.runtime.path.join(...this.paths.root);
|
|
2452
2475
|
return file === outdir || file.startsWith(outdir + this.runtime.path.sep);
|
|
2453
2476
|
};
|
|
2477
|
+
/** Load the required Rust extractor from the workspace or the published prebuild directory. */
|
|
2478
|
+
loadNativeExtractor = () => {
|
|
2479
|
+
const nativeRequire = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
2480
|
+
try {
|
|
2481
|
+
return nativeRequire("@bamboocss/native-extractor");
|
|
2482
|
+
} catch (workspaceError) {
|
|
2483
|
+
const binary = nativeBinaryName();
|
|
2484
|
+
if (!binary) throw new _bamboocss_shared.BambooError("NATIVE_EXTRACTION", `Native extraction is not available for ${process.platform}-${process.arch}.`, { cause: workspaceError });
|
|
2485
|
+
try {
|
|
2486
|
+
return nativeRequire((0, node_path.join)((0, node_path.dirname)((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href)), "native", binary));
|
|
2487
|
+
} catch (publishedError) {
|
|
2488
|
+
throw new _bamboocss_shared.BambooError("NATIVE_EXTRACTION", `Failed to load the native extractor binary ${binary}.`, { cause: publishedError });
|
|
2489
|
+
}
|
|
2490
|
+
}
|
|
2491
|
+
};
|
|
2492
|
+
prepareNativeSource = (filePath, original) => {
|
|
2493
|
+
let parserOptions = {};
|
|
2494
|
+
const source = this.parserHooks["parser:before"]?.({
|
|
2495
|
+
filePath,
|
|
2496
|
+
content: original,
|
|
2497
|
+
configure: (options) => {
|
|
2498
|
+
parserOptions = {
|
|
2499
|
+
...parserOptions,
|
|
2500
|
+
...options
|
|
2501
|
+
};
|
|
2502
|
+
}
|
|
2503
|
+
}) ?? original;
|
|
2504
|
+
return {
|
|
2505
|
+
original,
|
|
2506
|
+
source,
|
|
2507
|
+
metadata: {
|
|
2508
|
+
options: parserOptions,
|
|
2509
|
+
origins: source === original
|
|
2510
|
+
}
|
|
2511
|
+
};
|
|
2512
|
+
};
|
|
2513
|
+
/** Prepare a whole extraction pass in one coarse native invocation. */
|
|
2514
|
+
prepareNativeExtraction = (filePaths) => {
|
|
2515
|
+
this.nativeExtractions.clear();
|
|
2516
|
+
this.nativeSourceMetadata.clear();
|
|
2517
|
+
const owners = new Set(filePaths.map((filePath) => this.runtime.path.abs(this.config.cwd, filePath).replaceAll("\\", "/")));
|
|
2518
|
+
for (const owner of owners) {
|
|
2519
|
+
this.nativeDependencies.delete(owner);
|
|
2520
|
+
this.nativePendingCandidates.delete(owner);
|
|
2521
|
+
this.nativeConfigurationFiles.delete(owner);
|
|
2522
|
+
}
|
|
2523
|
+
const sources = [];
|
|
2524
|
+
const auxiliary = this.parserHooks["parser:before"] || this.runtime !== nodeRuntime ? this.nativeAuxiliaryFiles : this.nativeAuxiliaryFiles.filter(this.project.sourceIsOverridden);
|
|
2525
|
+
const inventory = (0, _bamboocss_shared.uniq)([...filePaths, ...auxiliary]);
|
|
2526
|
+
for (const filePath of inventory) {
|
|
2527
|
+
if (filePath.endsWith(".json")) continue;
|
|
2528
|
+
const filename = this.runtime.path.abs(this.config.cwd, filePath);
|
|
2529
|
+
const sourceKey = filename.replaceAll("\\", "/");
|
|
2530
|
+
let prepared = this.nativePreparedSources.get(sourceKey);
|
|
2531
|
+
if (!prepared) {
|
|
2532
|
+
let original = this.project.getSourceText(filename);
|
|
2533
|
+
if (original === void 0) try {
|
|
2534
|
+
original = this.runtime.fs.readFileSync(filename);
|
|
2535
|
+
} catch (error) {
|
|
2536
|
+
if ([
|
|
2537
|
+
"ENOENT",
|
|
2538
|
+
"EISDIR",
|
|
2539
|
+
"ENOTDIR"
|
|
2540
|
+
].includes(error.code ?? "")) continue;
|
|
2541
|
+
throw error;
|
|
2542
|
+
}
|
|
2543
|
+
prepared = this.prepareNativeSource(filename, original);
|
|
2544
|
+
}
|
|
2545
|
+
if (owners.has(sourceKey)) {
|
|
2546
|
+
this.nativeSourceMetadata.set(sourceKey, prepared.metadata);
|
|
2547
|
+
sources.push({
|
|
2548
|
+
filename,
|
|
2549
|
+
source: prepared.source
|
|
2550
|
+
});
|
|
2551
|
+
} else if (prepared.source !== prepared.original || this.runtime !== nodeRuntime || this.project.sourceIsOverridden(filename)) sources.push({
|
|
2552
|
+
filename,
|
|
2553
|
+
source: prepared.source
|
|
2554
|
+
});
|
|
2555
|
+
}
|
|
2556
|
+
if (!sources.length) {
|
|
2557
|
+
this.nativePreparedSources.clear();
|
|
2558
|
+
return;
|
|
2559
|
+
}
|
|
2560
|
+
const entrypoints = [
|
|
2561
|
+
{
|
|
2562
|
+
kind: "css",
|
|
2563
|
+
modules: this.imports.value.css,
|
|
2564
|
+
names: [
|
|
2565
|
+
"css",
|
|
2566
|
+
"cva",
|
|
2567
|
+
"sva",
|
|
2568
|
+
"cx",
|
|
2569
|
+
"fallback",
|
|
2570
|
+
"viewTransition"
|
|
2571
|
+
]
|
|
2572
|
+
},
|
|
2573
|
+
{
|
|
2574
|
+
kind: "token",
|
|
2575
|
+
modules: this.imports.value.tokens,
|
|
2576
|
+
names: ["token"]
|
|
2577
|
+
},
|
|
2578
|
+
{
|
|
2579
|
+
kind: "recipe",
|
|
2580
|
+
modules: this.imports.value.recipe,
|
|
2581
|
+
names: this.recipes.keys
|
|
2582
|
+
},
|
|
2583
|
+
{
|
|
2584
|
+
kind: "pattern",
|
|
2585
|
+
modules: this.imports.value.pattern,
|
|
2586
|
+
names: this.patterns.keys
|
|
2587
|
+
}
|
|
2588
|
+
];
|
|
2589
|
+
const { baseUrl, paths = {} } = this.project.resolutionOptions;
|
|
2590
|
+
const options = {
|
|
2591
|
+
cwd: this.config.cwd,
|
|
2592
|
+
baseUrl,
|
|
2593
|
+
paths: Object.entries(paths).map(([pattern, values]) => ({
|
|
2594
|
+
pattern,
|
|
2595
|
+
paths: values
|
|
2596
|
+
})),
|
|
2597
|
+
tokens: this.tokens.allTokens.map((token) => ({
|
|
2598
|
+
path: token.name,
|
|
2599
|
+
value: this.tokens.view.get(token.name),
|
|
2600
|
+
variable: this.tokens.view.getVar(token.name)
|
|
2601
|
+
})),
|
|
2602
|
+
jsx: this.jsx.isEnabled
|
|
2603
|
+
};
|
|
2604
|
+
let analyses;
|
|
2605
|
+
try {
|
|
2606
|
+
analyses = this.loadNativeExtractor().analyzeMany(sources, entrypoints, options);
|
|
2607
|
+
} finally {
|
|
2608
|
+
this.nativePreparedSources.clear();
|
|
2609
|
+
}
|
|
2610
|
+
for (const analysis of analyses) {
|
|
2611
|
+
const owner = analysis.filename.replaceAll("\\", "/");
|
|
2612
|
+
if (!owners.has(owner)) continue;
|
|
2613
|
+
this.nativeExtractions.set(owner, analysis);
|
|
2614
|
+
this.nativeDependencies.set(owner, analysis.dependencies);
|
|
2615
|
+
this.nativePendingCandidates.set(owner, analysis.pendingCandidates);
|
|
2616
|
+
this.nativeConfigurationFiles.set(owner, analysis.configurationFiles);
|
|
2617
|
+
}
|
|
2618
|
+
};
|
|
2619
|
+
/** Included extraction owners whose native value graph reaches `filePath`, transitively. */
|
|
2620
|
+
getNativeDependents = (filePath) => {
|
|
2621
|
+
const changed = filePath.replaceAll("\\", "/");
|
|
2622
|
+
const selected = /* @__PURE__ */ new Set();
|
|
2623
|
+
let frontier = [changed];
|
|
2624
|
+
while (frontier.length) {
|
|
2625
|
+
const next = [];
|
|
2626
|
+
for (const dependency of frontier) for (const [owner, dependencies] of this.nativeDependencies) {
|
|
2627
|
+
const pending = this.nativePendingCandidates.get(owner) ?? [];
|
|
2628
|
+
if (selected.has(owner) || ![...dependencies, ...pending].some((item) => item.replaceAll("\\", "/") === dependency)) continue;
|
|
2629
|
+
selected.add(owner);
|
|
2630
|
+
next.push(owner);
|
|
2631
|
+
}
|
|
2632
|
+
frontier = next;
|
|
2633
|
+
}
|
|
2634
|
+
return [...selected];
|
|
2635
|
+
};
|
|
2636
|
+
/** @internal Native dependency edges, from dependency to extraction owner. */
|
|
2637
|
+
getNativeDependencyLedger = () => [...this.nativeDependencies].flatMap(([owner, dependencies]) => dependencies.map((dependency) => [dependency.replaceAll("\\", "/"), owner]));
|
|
2638
|
+
forgetNativeFile = (filePath) => {
|
|
2639
|
+
const file = this.runtime.path.abs(this.config.cwd, filePath).replaceAll("\\", "/");
|
|
2640
|
+
this.nativeDependencies.delete(file);
|
|
2641
|
+
this.nativePendingCandidates.delete(file);
|
|
2642
|
+
this.nativeConfigurationFiles.delete(file);
|
|
2643
|
+
this.nativeExtractions.delete(file);
|
|
2644
|
+
this.nativeSourceMetadata.delete(file);
|
|
2645
|
+
};
|
|
2646
|
+
parseNativeFile = (filePath, native, encoder) => {
|
|
2647
|
+
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 _bamboocss_parser.ParserResult(this.parserOptions, encoder).setFilePath(filePath);
|
|
2649
|
+
result.native = true;
|
|
2650
|
+
result.nativePendingCandidates = native.pendingCandidates;
|
|
2651
|
+
result.nativeConfigurationFiles = native.configurationFiles;
|
|
2652
|
+
for (const dependency of native.dependencies) result.addDependency(dependency);
|
|
2653
|
+
const metadata = this.nativeSourceMetadata.get(filePath.replaceAll("\\", "/"));
|
|
2654
|
+
result.origins = metadata?.origins ?? true;
|
|
2655
|
+
for (const call of native.calls) {
|
|
2656
|
+
const atomOrigin = encoder.recordOrigins && result.origins ? {
|
|
2657
|
+
filePath,
|
|
2658
|
+
line: call.line,
|
|
2659
|
+
column: call.column
|
|
2660
|
+
} : void 0;
|
|
2661
|
+
if (call.kind === "jsx") {
|
|
2662
|
+
const recipeTag = [call.name, call.importedName].find((tag) => this.jsx.isJsxTagRecipe(tag));
|
|
2663
|
+
const isBambooComponent = Boolean(recipeTag);
|
|
2664
|
+
if (!(metadata?.options.matchTag ? metadata.options.matchTagMode === "override" ? metadata.options.matchTag(call.name, isBambooComponent) : isBambooComponent || metadata.options.matchTag(call.name, isBambooComponent) : isBambooComponent) || !recipeTag) continue;
|
|
2665
|
+
const data = call.arguments.map((properties) => Object.fromEntries(Object.entries(properties).filter(([property]) => {
|
|
2666
|
+
const isRecipeProperty = this.jsx.isRecipeProp(recipeTag, property);
|
|
2667
|
+
return metadata?.options.matchTagProp ? isRecipeProperty && metadata.options.matchTagProp(call.name, property) : isRecipeProperty;
|
|
2668
|
+
})));
|
|
2669
|
+
for (const recipe of this.recipes.filter(recipeTag)) result.setRecipe(recipe.baseName, {
|
|
2670
|
+
type: "jsx-recipe",
|
|
2671
|
+
name: call.name,
|
|
2672
|
+
data,
|
|
2673
|
+
atomOrigin
|
|
2674
|
+
});
|
|
2675
|
+
continue;
|
|
2676
|
+
}
|
|
2677
|
+
const item = {
|
|
2678
|
+
name: call.importedName,
|
|
2679
|
+
data: call.arguments,
|
|
2680
|
+
atomOrigin,
|
|
2681
|
+
tokenCalleeRange: call.kind === "token" || call.kind === "tokenValue" ? {
|
|
2682
|
+
start: call.calleeStart,
|
|
2683
|
+
end: call.calleeEnd
|
|
2684
|
+
} : void 0
|
|
2685
|
+
};
|
|
2686
|
+
const recipeConfig = call.kind === "css" && (call.importedName === "cva" || call.importedName === "sva");
|
|
2687
|
+
if (!(recipeConfig && item.data.every((data) => typeof data.className === "string" && data.className !== ""))) for (const loss of call.losses) result.unresolved.push({
|
|
2688
|
+
kind: recipeConfig ? "recipe" : "atomic",
|
|
2689
|
+
prop: loss.prop,
|
|
2690
|
+
filePath,
|
|
2691
|
+
line: call.line,
|
|
2692
|
+
column: call.column,
|
|
2693
|
+
reason: loss.reason
|
|
2694
|
+
});
|
|
2695
|
+
if (call.kind === "css" && [
|
|
2696
|
+
"css",
|
|
2697
|
+
"cva",
|
|
2698
|
+
"sva"
|
|
2699
|
+
].includes(call.importedName)) result.set(call.importedName, item);
|
|
2700
|
+
else if (call.kind === "css" && call.importedName === "viewTransition") result.setViewTransition(item);
|
|
2701
|
+
else if (call.kind === "pattern") result.setPattern(call.importedName, item);
|
|
2702
|
+
else if (call.kind === "recipe") result.setRecipe(call.importedName, item);
|
|
2703
|
+
else if (call.kind === "token" || call.kind === "tokenValue") result.setToken(item, call.kind);
|
|
2704
|
+
else if (call.kind === "dead") result.deadCalls.push({
|
|
2705
|
+
name: call.importedName,
|
|
2706
|
+
alias: call.name,
|
|
2707
|
+
mod: call.module,
|
|
2708
|
+
entrypoint: this.imports.value.pattern.some((module) => call.module.includes(module)) ? "pattern" : "recipe"
|
|
2709
|
+
});
|
|
2710
|
+
}
|
|
2711
|
+
this.parserHooks["parser:after"]?.({
|
|
2712
|
+
filePath,
|
|
2713
|
+
result
|
|
2714
|
+
});
|
|
2715
|
+
return result;
|
|
2716
|
+
};
|
|
2454
2717
|
parseFile = (filePath, styleEncoder) => {
|
|
2455
2718
|
const file = this.runtime.path.abs(this.config.cwd, filePath);
|
|
2719
|
+
const nativeFile = file.replaceAll("\\", "/");
|
|
2456
2720
|
_bamboocss_logger.logger.debug("file:extract", file);
|
|
2457
2721
|
const measure = _bamboocss_logger.logger.time.debug(`Parsed ${file}`);
|
|
2458
2722
|
let result;
|
|
2459
2723
|
try {
|
|
2460
2724
|
const encoder = styleEncoder || this.parserOptions.encoder;
|
|
2461
|
-
result = encoder.withOwner("extract", file, () => this.project.
|
|
2725
|
+
if (file.endsWith(".json")) result = encoder.withOwner("extract", file, () => this.project.parseJson(file, encoder));
|
|
2726
|
+
else {
|
|
2727
|
+
if (!this.nativeExtractions.has(nativeFile)) this.prepareNativeExtraction([file]);
|
|
2728
|
+
const native = this.nativeExtractions.get(nativeFile);
|
|
2729
|
+
if (!native && !this.runtime.fs.existsSync(file)) {
|
|
2730
|
+
encoder.releaseFile(file);
|
|
2731
|
+
this.parseFailures.delete(file);
|
|
2732
|
+
this.deadCalls.delete(file);
|
|
2733
|
+
measure();
|
|
2734
|
+
return;
|
|
2735
|
+
}
|
|
2736
|
+
if (!native) throw new _bamboocss_shared.BambooError("NATIVE_EXTRACTION", `Native extraction produced no result for ${file}.`);
|
|
2737
|
+
result = encoder.withOwner("extract", file, () => this.parseNativeFile(file, native, encoder));
|
|
2738
|
+
}
|
|
2739
|
+
this.nativeExtractions.delete(nativeFile);
|
|
2740
|
+
this.nativeSourceMetadata.delete(nativeFile);
|
|
2462
2741
|
this.parseFailures.delete(file);
|
|
2463
2742
|
} catch (error) {
|
|
2743
|
+
this.nativeExtractions.delete(nativeFile);
|
|
2744
|
+
this.nativeSourceMetadata.delete(nativeFile);
|
|
2464
2745
|
if ((0, _bamboocss_ts_ast.isCompilerGone)(error)) throw error;
|
|
2465
2746
|
_bamboocss_logger.logger.caughtError("file:extract", `Failed to parse ${file}`, error);
|
|
2466
2747
|
this.parseFailures.set(file, error);
|
|
@@ -2498,6 +2779,7 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
2498
2779
|
* what is *parsed*, not what the project holds.
|
|
2499
2780
|
*/
|
|
2500
2781
|
extractableFiles = (files) => {
|
|
2782
|
+
this.nativePreparedSources.clear();
|
|
2501
2783
|
const { baseUrl, paths } = this.project.resolutionOptions;
|
|
2502
2784
|
const measure = _bamboocss_logger.logger.time.debug("Selected extractable files");
|
|
2503
2785
|
const { auxiliary, extractable } = selectExtractable(files, {
|
|
@@ -2505,28 +2787,28 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
2505
2787
|
cwd: this.config.cwd,
|
|
2506
2788
|
entrypoints: this.entrypointSpecifiers,
|
|
2507
2789
|
paths,
|
|
2790
|
+
fileExists: this.project.sourceExists,
|
|
2508
2791
|
readFile: (filePath) => {
|
|
2509
2792
|
try {
|
|
2510
|
-
|
|
2793
|
+
const original = this.project.getSourceText(filePath) ?? this.runtime.fs.readFileSync(filePath);
|
|
2794
|
+
const filename = this.runtime.path.abs(this.config.cwd, filePath);
|
|
2795
|
+
const prepared = this.prepareNativeSource(filename, original);
|
|
2796
|
+
this.nativePreparedSources.set(filename.replaceAll("\\", "/"), prepared);
|
|
2797
|
+
return prepared.source;
|
|
2511
2798
|
} catch {
|
|
2512
2799
|
return;
|
|
2513
2800
|
}
|
|
2514
2801
|
}
|
|
2515
2802
|
});
|
|
2516
|
-
|
|
2517
|
-
_bamboocss_logger.logger.debug("file:extract", `${extractable.length} of ${files.length} file(s) can reach a bamboo entrypoint; ${files.length - extractable.length} cannot and are not parsed; ${auxiliary.length} import target(s) outside the inventory
|
|
2803
|
+
this.nativeAuxiliaryFiles = auxiliary;
|
|
2804
|
+
_bamboocss_logger.logger.debug("file:extract", `${extractable.length} of ${files.length} file(s) can reach a bamboo entrypoint; ${files.length - extractable.length} cannot and are not parsed; ${auxiliary.length} local import target(s) sit outside the inventory`);
|
|
2518
2805
|
measure();
|
|
2519
2806
|
return extractable;
|
|
2520
2807
|
};
|
|
2521
|
-
/** Path/content pairs for a bulk install, skipping anything that cannot be read. */
|
|
2522
|
-
readSources = function* (files) {
|
|
2523
|
-
for (const file of files) try {
|
|
2524
|
-
yield [file, this.runtime.fs.readFileSync(file)];
|
|
2525
|
-
} catch {}
|
|
2526
|
-
};
|
|
2527
2808
|
parseFiles = (styleEncoder) => {
|
|
2528
2809
|
const encoder = styleEncoder || this.parserOptions.encoder;
|
|
2529
2810
|
const files = this.extractableFiles(this.getFiles());
|
|
2811
|
+
this.prepareNativeExtraction(files);
|
|
2530
2812
|
const filesWithCss = [];
|
|
2531
2813
|
const results = [];
|
|
2532
2814
|
files.forEach((file) => {
|
|
@@ -3679,6 +3961,7 @@ var Builder = class {
|
|
|
3679
3961
|
removeSource = (filePath) => {
|
|
3680
3962
|
const ctx = this.getContextOrThrow();
|
|
3681
3963
|
this.captureResolutionLedger(ctx);
|
|
3964
|
+
ctx.forgetNativeFile(filePath);
|
|
3682
3965
|
return ctx.project.removeSourceFile(filePath);
|
|
3683
3966
|
};
|
|
3684
3967
|
captureResolutionLedger = (ctx) => {
|
|
@@ -3926,6 +4209,7 @@ var Builder = class {
|
|
|
3926
4209
|
for (const file of changed) {
|
|
3927
4210
|
if (current.has(file)) affected.add(file);
|
|
3928
4211
|
for (const dependent of project.getDependents(file)) affected.add(this.sourcePath(dependent));
|
|
4212
|
+
for (const dependent of ctx.getNativeDependents(file)) affected.add(this.sourcePath(dependent));
|
|
3929
4213
|
if ((0, fs.existsSync)(file) && !project.getSourceFile(file)) added.push(file);
|
|
3930
4214
|
}
|
|
3931
4215
|
if (added.length) for (const importer of pending) {
|
|
@@ -3961,6 +4245,7 @@ var Builder = class {
|
|
|
3961
4245
|
indegree.set(importer, (indegree.get(importer) ?? 0) + 1);
|
|
3962
4246
|
};
|
|
3963
4247
|
for (const fact of ledger) addEdge(fact.target, fact.importer);
|
|
4248
|
+
for (const [target, importer] of this.getContextOrThrow().getNativeDependencyLedger()) addEdge(target, importer);
|
|
3964
4249
|
for (const [target, importer] of syntheticEdges) addEdge(target, importer);
|
|
3965
4250
|
const compare = (left, right) => (inventoryRank.get(left) ?? 0) - (inventoryRank.get(right) ?? 0);
|
|
3966
4251
|
const ready = new MinPriorityQueue(compare);
|
|
@@ -4112,8 +4397,10 @@ var Builder = class {
|
|
|
4112
4397
|
{
|
|
4113
4398
|
const owner = this.absOwner(ctx, file);
|
|
4114
4399
|
const reads = parserResult?.getExportReads?.() ?? [];
|
|
4115
|
-
|
|
4116
|
-
|
|
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;
|
|
4117
4404
|
if (this.changedThisPass.has(owner)) {
|
|
4118
4405
|
const previous = this.recipeSurfaceByOwner.get(owner);
|
|
4119
4406
|
this.recipeSurfaceStable.set(owner, previous !== void 0 && surface !== void 0 && previous === surface);
|
|
@@ -4125,9 +4412,15 @@ var Builder = class {
|
|
|
4125
4412
|
dependencies: (0, _bamboocss_shared.uniq)([...previousReads, ...previousPending]).sort(),
|
|
4126
4413
|
pendingCandidates: previousCandidates
|
|
4127
4414
|
} : void 0;
|
|
4128
|
-
const
|
|
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);
|
|
4129
4422
|
const currentReads = readSet.dependencies;
|
|
4130
|
-
const currentConfigurations = ctx.project.getResolutionConfigurationFiles(file,
|
|
4423
|
+
const currentConfigurations = native ? (0, _bamboocss_shared.uniq)([...currentReads.length || readSet.pendingCandidates.length ? this.tsconfigResolutionFiles : [], ...nativeResult.nativeConfigurationFiles ?? []]).sort() : ctx.project.getResolutionConfigurationFiles(file, dependencies, meta.isUnchanged ? previousConfigurations : []);
|
|
4131
4424
|
this.resolutionReadSets.set(owner, currentReads);
|
|
4132
4425
|
if (readSet.pendingCandidates.length) this.resolutionCandidateSets.set(owner, readSet.pendingCandidates);
|
|
4133
4426
|
else this.resolutionCandidateSets.delete(owner);
|
|
@@ -4167,6 +4460,7 @@ var Builder = class {
|
|
|
4167
4460
|
this.recipeSurfaceStable.clear();
|
|
4168
4461
|
this.readDigestMemo.clear();
|
|
4169
4462
|
const done = _bamboocss_logger.logger.time.info("Extracted in");
|
|
4463
|
+
ctx.prepareNativeExtraction(filesToExtract);
|
|
4170
4464
|
for (const file of filesToExtract) this.extractFile(ctx, file);
|
|
4171
4465
|
done();
|
|
4172
4466
|
this.sourceInventory = [...files];
|
|
@@ -4319,10 +4613,11 @@ async function debug(ctx, options) {
|
|
|
4319
4613
|
return;
|
|
4320
4614
|
}
|
|
4321
4615
|
const filesWithCss = [];
|
|
4616
|
+
ctx.prepareNativeExtraction(files);
|
|
4322
4617
|
files.map((file) => {
|
|
4323
4618
|
const measure = _bamboocss_logger.logger.time.debug(`Parsed ${file}`);
|
|
4324
4619
|
const encoder = ctx.encoder.clone();
|
|
4325
|
-
const result = ctx.
|
|
4620
|
+
const result = ctx.parseFile(file, encoder);
|
|
4326
4621
|
measure();
|
|
4327
4622
|
if (!result || result.isEmpty() || encoder.isEmpty()) return;
|
|
4328
4623
|
const styles = ctx.decoder.clone().collect(encoder);
|
|
@@ -4406,9 +4701,9 @@ async function generate(config, configPath) {
|
|
|
4406
4701
|
*/
|
|
4407
4702
|
const bundleStyles = async (ctx, changedFilePaths, inventoryChanged = false) => {
|
|
4408
4703
|
let parsed = 0;
|
|
4409
|
-
|
|
4704
|
+
ctx.prepareNativeExtraction(changedFilePaths);
|
|
4410
4705
|
for (const filePath of changedFilePaths) {
|
|
4411
|
-
const result =
|
|
4706
|
+
const result = ctx.parseFile(filePath);
|
|
4412
4707
|
recordResolvedTokenReferences(sourceScanCache, filePath, result);
|
|
4413
4708
|
if (result) parsed++;
|
|
4414
4709
|
}
|
|
@@ -4426,22 +4721,20 @@ async function generate(config, configPath) {
|
|
|
4426
4721
|
ctx.watchFiles(async (event, file) => {
|
|
4427
4722
|
const filePath = ctx.runtime.path.abs(cwd, file);
|
|
4428
4723
|
if (event === "unlink") {
|
|
4429
|
-
const dependents = ctx.
|
|
4724
|
+
const dependents = ctx.getNativeDependents(filePath);
|
|
4430
4725
|
ctx.project.removeSourceFile(filePath);
|
|
4726
|
+
ctx.forgetNativeFile(filePath);
|
|
4431
4727
|
sourceScanCache.entries.delete(filePath);
|
|
4432
4728
|
sourceScanCache.resolvedTokenReferences.delete(filePath);
|
|
4433
4729
|
await bundleStyles(ctx, dependents, true);
|
|
4434
4730
|
} else if (event === "change") {
|
|
4731
|
+
const dependents = ctx.getNativeDependents(filePath);
|
|
4435
4732
|
ctx.project.reloadSourceFile(filePath);
|
|
4436
|
-
await bundleStyles(ctx, [filePath, ...
|
|
4733
|
+
await bundleStyles(ctx, [...new Set([filePath, ...dependents])]);
|
|
4437
4734
|
} else if (event === "add") {
|
|
4438
|
-
const
|
|
4735
|
+
const dependents = ctx.getNativeDependents(filePath);
|
|
4439
4736
|
ctx.project.createSourceFile(filePath);
|
|
4440
|
-
await bundleStyles(ctx, [...new Set([
|
|
4441
|
-
filePath,
|
|
4442
|
-
...ctx.project.getDependents(filePath),
|
|
4443
|
-
...pendingClosure
|
|
4444
|
-
])]);
|
|
4737
|
+
await bundleStyles(ctx, [...new Set([filePath, ...dependents])]);
|
|
4445
4738
|
}
|
|
4446
4739
|
});
|
|
4447
4740
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -130,6 +130,18 @@ declare class BambooContext extends Generator {
|
|
|
130
130
|
* never take.
|
|
131
131
|
*/
|
|
132
132
|
deadCalls: Map<string, DeadImport[]>;
|
|
133
|
+
/** Extraction results produced without materializing TypeScript ASTs. */
|
|
134
|
+
private nativeExtractions;
|
|
135
|
+
/** Native semantic reads retained across incremental passes. */
|
|
136
|
+
private nativeDependencies;
|
|
137
|
+
private nativePendingCandidates;
|
|
138
|
+
private nativeConfigurationFiles;
|
|
139
|
+
private nativeAuxiliaryFiles;
|
|
140
|
+
/** Parser-hook output staged by the prefilter for the following native boundary. */
|
|
141
|
+
private nativePreparedSources;
|
|
142
|
+
/** Per-file parser-hook options and whether a transform invalidated source locations. */
|
|
143
|
+
private nativeSourceMetadata;
|
|
144
|
+
private parserHooks;
|
|
133
145
|
constructor(conf: LoadConfigResult);
|
|
134
146
|
/**
|
|
135
147
|
* Report `css()` calls whose styles the build could not fully see.
|
|
@@ -195,6 +207,17 @@ declare class BambooContext extends Generator {
|
|
|
195
207
|
* project that excludes its `outdir` should not lose them.
|
|
196
208
|
*/
|
|
197
209
|
private isGenerated;
|
|
210
|
+
/** Load the required Rust extractor from the workspace or the published prebuild directory. */
|
|
211
|
+
private loadNativeExtractor;
|
|
212
|
+
private prepareNativeSource;
|
|
213
|
+
/** Prepare a whole extraction pass in one coarse native invocation. */
|
|
214
|
+
prepareNativeExtraction: (filePaths: readonly string[]) => void;
|
|
215
|
+
/** Included extraction owners whose native value graph reaches `filePath`, transitively. */
|
|
216
|
+
getNativeDependents: (filePath: string) => string[];
|
|
217
|
+
/** @internal Native dependency edges, from dependency to extraction owner. */
|
|
218
|
+
getNativeDependencyLedger: () => Array<readonly [string, string]>;
|
|
219
|
+
forgetNativeFile: (filePath: string) => void;
|
|
220
|
+
private parseNativeFile;
|
|
198
221
|
parseFile: (filePath: string, styleEncoder?: StyleEncoder) => ParserResult | undefined;
|
|
199
222
|
/**
|
|
200
223
|
* Extract every file in one pass, and fail on the ones that could not be read.
|
|
@@ -219,8 +242,6 @@ declare class BambooContext extends Generator {
|
|
|
219
242
|
* what is *parsed*, not what the project holds.
|
|
220
243
|
*/
|
|
221
244
|
extractableFiles: (files: readonly string[]) => string[];
|
|
222
|
-
/** Path/content pairs for a bulk install, skipping anything that cannot be read. */
|
|
223
|
-
private readSources;
|
|
224
245
|
parseFiles: (styleEncoder?: StyleEncoder) => {
|
|
225
246
|
filesWithCss: string[];
|
|
226
247
|
files: string[];
|
package/dist/index.d.mts
CHANGED
|
@@ -130,6 +130,18 @@ declare class BambooContext extends Generator {
|
|
|
130
130
|
* never take.
|
|
131
131
|
*/
|
|
132
132
|
deadCalls: Map<string, DeadImport[]>;
|
|
133
|
+
/** Extraction results produced without materializing TypeScript ASTs. */
|
|
134
|
+
private nativeExtractions;
|
|
135
|
+
/** Native semantic reads retained across incremental passes. */
|
|
136
|
+
private nativeDependencies;
|
|
137
|
+
private nativePendingCandidates;
|
|
138
|
+
private nativeConfigurationFiles;
|
|
139
|
+
private nativeAuxiliaryFiles;
|
|
140
|
+
/** Parser-hook output staged by the prefilter for the following native boundary. */
|
|
141
|
+
private nativePreparedSources;
|
|
142
|
+
/** Per-file parser-hook options and whether a transform invalidated source locations. */
|
|
143
|
+
private nativeSourceMetadata;
|
|
144
|
+
private parserHooks;
|
|
133
145
|
constructor(conf: LoadConfigResult);
|
|
134
146
|
/**
|
|
135
147
|
* Report `css()` calls whose styles the build could not fully see.
|
|
@@ -195,6 +207,17 @@ declare class BambooContext extends Generator {
|
|
|
195
207
|
* project that excludes its `outdir` should not lose them.
|
|
196
208
|
*/
|
|
197
209
|
private isGenerated;
|
|
210
|
+
/** Load the required Rust extractor from the workspace or the published prebuild directory. */
|
|
211
|
+
private loadNativeExtractor;
|
|
212
|
+
private prepareNativeSource;
|
|
213
|
+
/** Prepare a whole extraction pass in one coarse native invocation. */
|
|
214
|
+
prepareNativeExtraction: (filePaths: readonly string[]) => void;
|
|
215
|
+
/** Included extraction owners whose native value graph reaches `filePath`, transitively. */
|
|
216
|
+
getNativeDependents: (filePath: string) => string[];
|
|
217
|
+
/** @internal Native dependency edges, from dependency to extraction owner. */
|
|
218
|
+
getNativeDependencyLedger: () => Array<readonly [string, string]>;
|
|
219
|
+
forgetNativeFile: (filePath: string) => void;
|
|
220
|
+
private parseNativeFile;
|
|
198
221
|
parseFile: (filePath: string, styleEncoder?: StyleEncoder) => ParserResult | undefined;
|
|
199
222
|
/**
|
|
200
223
|
* Extract every file in one pass, and fail on the ones that could not be read.
|
|
@@ -219,8 +242,6 @@ declare class BambooContext extends Generator {
|
|
|
219
242
|
* what is *parsed*, not what the project holds.
|
|
220
243
|
*/
|
|
221
244
|
extractableFiles: (files: readonly string[]) => string[];
|
|
222
|
-
/** Path/content pairs for a bulk install, skipping anything that cannot be read. */
|
|
223
|
-
private readSources;
|
|
224
245
|
parseFiles: (styleEncoder?: StyleEncoder) => {
|
|
225
246
|
filesWithCss: string[];
|
|
226
247
|
files: string[];
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isStaticCompilerActive, markStaticCompilerActive } from "./static-compiler.mjs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
2
3
|
import { colors, logger, quote } from "@bamboocss/logger";
|
|
3
4
|
import { Node, SyntaxKind, childOf, forEachDescendant, getAliasNode, getDefaultImport, getDescendantsOfKind, getExportDeclarations, getFirstAncestor, getFirstAncestorByKind, getLineAndColumnAtPos, getLiteralText, getModuleSpecifierValue, getNamedImports, getNamespaceImport, isCompilerGone, isTypeOnly, nameNodeOf, stringLiteralValue, ts } from "@bamboocss/ts-ast";
|
|
4
5
|
import { convertTsPathsToRegexes, diffConfigs, findConfig, loadConfig, mergeHooks } from "@bamboocss/config";
|
|
@@ -11,10 +12,11 @@ import { pluginSvelte } from "@bamboocss/plugin-svelte";
|
|
|
11
12
|
import { pluginVue } from "@bamboocss/plugin-vue";
|
|
12
13
|
import { checkNamingAgreement, formatNamingDisagreement, messages, prunesPreflight } from "@bamboocss/core";
|
|
13
14
|
import { Generator, generatePackageExports } from "@bamboocss/generator";
|
|
14
|
-
import { Project } from "@bamboocss/parser";
|
|
15
|
+
import { ParserResult, Project } from "@bamboocss/parser";
|
|
15
16
|
import fs, { existsSync as existsSync$1, promises } from "node:fs";
|
|
16
|
-
import path, { dirname as dirname$1, isAbsolute as isAbsolute$1, resolve as resolve$1 } from "node:path";
|
|
17
|
+
import path, { dirname as dirname$1, isAbsolute as isAbsolute$1, join as join$1, resolve as resolve$1 } from "node:path";
|
|
17
18
|
import { debounce } from "perfect-debounce";
|
|
19
|
+
import { fileURLToPath } from "node:url";
|
|
18
20
|
import process$1 from "node:process";
|
|
19
21
|
import os from "node:os";
|
|
20
22
|
import tty from "node:tty";
|
|
@@ -148,14 +150,14 @@ async function codegen(ctx, ids) {
|
|
|
148
150
|
* from one. A file with no such chain cannot hold a call, whatever else is in it.
|
|
149
151
|
*
|
|
150
152
|
* On a real application that is most of the tree. Measured over 6,425 files: 4,062 could reach
|
|
151
|
-
* an entrypoint and 2,363 provably could not, and not handing the
|
|
153
|
+
* an entrypoint and 2,363 provably could not, and not handing the extractor the latter took the
|
|
152
154
|
* pass from 88.9s to 26.3s with byte-identical CSS out. The scan itself costs ~300ms, because
|
|
153
155
|
* it reads text and never parses.
|
|
154
156
|
*
|
|
155
157
|
* ## Skipping is not the same as ignoring
|
|
156
158
|
*
|
|
157
159
|
* A file left out here is still *reachable*. Cross-file composition works by resolving an
|
|
158
|
-
* import and
|
|
160
|
+
* import and reading what it names, so a module that exports a style object still arrives
|
|
159
161
|
* the moment something that qualifies imports it. What is skipped is only asking "does this
|
|
160
162
|
* file *originate* a call", of a file that has no binding to originate one with.
|
|
161
163
|
*
|
|
@@ -265,8 +267,8 @@ const localTargetOf = (specifier, importer, options) => {
|
|
|
265
267
|
* one — a recipe defined with `cva` in one file and called in another is exactly that shape.
|
|
266
268
|
*
|
|
267
269
|
* The edges are worth more than the walk they were built for. Every one of them names a module
|
|
268
|
-
* that is *going* to be demanded, so the same scan that decides what to parse also says
|
|
269
|
-
*
|
|
270
|
+
* that is *going* to be demanded, so the same scan that decides what to parse also says which
|
|
271
|
+
* virtual or transformed sources the native source map may need — see `auxiliary`.
|
|
270
272
|
*/
|
|
271
273
|
const selectExtractable = (files, options) => {
|
|
272
274
|
const keep = /* @__PURE__ */ new Set();
|
|
@@ -2230,6 +2232,13 @@ var OutputEngine = class {
|
|
|
2230
2232
|
//#region src/create-context.ts
|
|
2231
2233
|
/** A thrown value's message, for a `catch` binding that is typed `unknown`. */
|
|
2232
2234
|
const messageOf = (error) => error instanceof Error ? error.message : String(error);
|
|
2235
|
+
const nativeBinaryName = () => {
|
|
2236
|
+
if (process.platform === "darwin" && process.arch === "arm64") return "darwin-arm64.node";
|
|
2237
|
+
if (process.platform === "darwin" && process.arch === "x64") return "darwin-x64.node";
|
|
2238
|
+
if (process.platform === "linux" && process.arch === "arm64") return "linux-arm64-gnu.node";
|
|
2239
|
+
if (process.platform === "linux" && process.arch === "x64") return "linux-x64-gnu.node";
|
|
2240
|
+
if (process.platform === "win32" && process.arch === "x64") return "win32-x64-msvc.node";
|
|
2241
|
+
};
|
|
2233
2242
|
/**
|
|
2234
2243
|
* What each loss is, and what the author can do about it.
|
|
2235
2244
|
*
|
|
@@ -2280,10 +2289,23 @@ var BambooContext = class extends Generator {
|
|
|
2280
2289
|
* never take.
|
|
2281
2290
|
*/
|
|
2282
2291
|
deadCalls = /* @__PURE__ */ new Map();
|
|
2292
|
+
/** Extraction results produced without materializing TypeScript ASTs. */
|
|
2293
|
+
nativeExtractions = /* @__PURE__ */ new Map();
|
|
2294
|
+
/** Native semantic reads retained across incremental passes. */
|
|
2295
|
+
nativeDependencies = /* @__PURE__ */ new Map();
|
|
2296
|
+
nativePendingCandidates = /* @__PURE__ */ new Map();
|
|
2297
|
+
nativeConfigurationFiles = /* @__PURE__ */ new Map();
|
|
2298
|
+
nativeAuxiliaryFiles = [];
|
|
2299
|
+
/** Parser-hook output staged by the prefilter for the following native boundary. */
|
|
2300
|
+
nativePreparedSources = /* @__PURE__ */ new Map();
|
|
2301
|
+
/** Per-file parser-hook options and whether a transform invalidated source locations. */
|
|
2302
|
+
nativeSourceMetadata = /* @__PURE__ */ new Map();
|
|
2303
|
+
parserHooks;
|
|
2283
2304
|
constructor(conf) {
|
|
2284
2305
|
super(conf);
|
|
2285
2306
|
const config = conf.config;
|
|
2286
2307
|
this.runtime = nodeRuntime;
|
|
2308
|
+
this.parserHooks = conf.hooks;
|
|
2287
2309
|
config.cwd ||= this.runtime.cwd();
|
|
2288
2310
|
if (config.logLevel) logger.level = config.logLevel;
|
|
2289
2311
|
this.project = new Project({
|
|
@@ -2295,6 +2317,7 @@ var BambooContext = class extends Generator {
|
|
|
2295
2317
|
resolutionConfigFiles: getTsConfigResolutionFiles(conf),
|
|
2296
2318
|
getFiles: () => this.getFiles(),
|
|
2297
2319
|
readFile: (filePath) => this.runtime.fs.readFileSync(filePath),
|
|
2320
|
+
fileExists: (filePath) => this.runtime.fs.existsSync(filePath),
|
|
2298
2321
|
hooks: conf.hooks,
|
|
2299
2322
|
parserOptions: {
|
|
2300
2323
|
...this.parserOptions,
|
|
@@ -2439,16 +2462,274 @@ var BambooContext = class extends Generator {
|
|
|
2439
2462
|
const outdir = this.runtime.path.join(...this.paths.root);
|
|
2440
2463
|
return file === outdir || file.startsWith(outdir + this.runtime.path.sep);
|
|
2441
2464
|
};
|
|
2465
|
+
/** Load the required Rust extractor from the workspace or the published prebuild directory. */
|
|
2466
|
+
loadNativeExtractor = () => {
|
|
2467
|
+
const nativeRequire = createRequire(import.meta.url);
|
|
2468
|
+
try {
|
|
2469
|
+
return nativeRequire("@bamboocss/native-extractor");
|
|
2470
|
+
} catch (workspaceError) {
|
|
2471
|
+
const binary = nativeBinaryName();
|
|
2472
|
+
if (!binary) throw new BambooError("NATIVE_EXTRACTION", `Native extraction is not available for ${process.platform}-${process.arch}.`, { cause: workspaceError });
|
|
2473
|
+
try {
|
|
2474
|
+
return nativeRequire(join$1(dirname$1(fileURLToPath(import.meta.url)), "native", binary));
|
|
2475
|
+
} catch (publishedError) {
|
|
2476
|
+
throw new BambooError("NATIVE_EXTRACTION", `Failed to load the native extractor binary ${binary}.`, { cause: publishedError });
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2479
|
+
};
|
|
2480
|
+
prepareNativeSource = (filePath, original) => {
|
|
2481
|
+
let parserOptions = {};
|
|
2482
|
+
const source = this.parserHooks["parser:before"]?.({
|
|
2483
|
+
filePath,
|
|
2484
|
+
content: original,
|
|
2485
|
+
configure: (options) => {
|
|
2486
|
+
parserOptions = {
|
|
2487
|
+
...parserOptions,
|
|
2488
|
+
...options
|
|
2489
|
+
};
|
|
2490
|
+
}
|
|
2491
|
+
}) ?? original;
|
|
2492
|
+
return {
|
|
2493
|
+
original,
|
|
2494
|
+
source,
|
|
2495
|
+
metadata: {
|
|
2496
|
+
options: parserOptions,
|
|
2497
|
+
origins: source === original
|
|
2498
|
+
}
|
|
2499
|
+
};
|
|
2500
|
+
};
|
|
2501
|
+
/** Prepare a whole extraction pass in one coarse native invocation. */
|
|
2502
|
+
prepareNativeExtraction = (filePaths) => {
|
|
2503
|
+
this.nativeExtractions.clear();
|
|
2504
|
+
this.nativeSourceMetadata.clear();
|
|
2505
|
+
const owners = new Set(filePaths.map((filePath) => this.runtime.path.abs(this.config.cwd, filePath).replaceAll("\\", "/")));
|
|
2506
|
+
for (const owner of owners) {
|
|
2507
|
+
this.nativeDependencies.delete(owner);
|
|
2508
|
+
this.nativePendingCandidates.delete(owner);
|
|
2509
|
+
this.nativeConfigurationFiles.delete(owner);
|
|
2510
|
+
}
|
|
2511
|
+
const sources = [];
|
|
2512
|
+
const auxiliary = this.parserHooks["parser:before"] || this.runtime !== nodeRuntime ? this.nativeAuxiliaryFiles : this.nativeAuxiliaryFiles.filter(this.project.sourceIsOverridden);
|
|
2513
|
+
const inventory = uniq([...filePaths, ...auxiliary]);
|
|
2514
|
+
for (const filePath of inventory) {
|
|
2515
|
+
if (filePath.endsWith(".json")) continue;
|
|
2516
|
+
const filename = this.runtime.path.abs(this.config.cwd, filePath);
|
|
2517
|
+
const sourceKey = filename.replaceAll("\\", "/");
|
|
2518
|
+
let prepared = this.nativePreparedSources.get(sourceKey);
|
|
2519
|
+
if (!prepared) {
|
|
2520
|
+
let original = this.project.getSourceText(filename);
|
|
2521
|
+
if (original === void 0) try {
|
|
2522
|
+
original = this.runtime.fs.readFileSync(filename);
|
|
2523
|
+
} catch (error) {
|
|
2524
|
+
if ([
|
|
2525
|
+
"ENOENT",
|
|
2526
|
+
"EISDIR",
|
|
2527
|
+
"ENOTDIR"
|
|
2528
|
+
].includes(error.code ?? "")) continue;
|
|
2529
|
+
throw error;
|
|
2530
|
+
}
|
|
2531
|
+
prepared = this.prepareNativeSource(filename, original);
|
|
2532
|
+
}
|
|
2533
|
+
if (owners.has(sourceKey)) {
|
|
2534
|
+
this.nativeSourceMetadata.set(sourceKey, prepared.metadata);
|
|
2535
|
+
sources.push({
|
|
2536
|
+
filename,
|
|
2537
|
+
source: prepared.source
|
|
2538
|
+
});
|
|
2539
|
+
} else if (prepared.source !== prepared.original || this.runtime !== nodeRuntime || this.project.sourceIsOverridden(filename)) sources.push({
|
|
2540
|
+
filename,
|
|
2541
|
+
source: prepared.source
|
|
2542
|
+
});
|
|
2543
|
+
}
|
|
2544
|
+
if (!sources.length) {
|
|
2545
|
+
this.nativePreparedSources.clear();
|
|
2546
|
+
return;
|
|
2547
|
+
}
|
|
2548
|
+
const entrypoints = [
|
|
2549
|
+
{
|
|
2550
|
+
kind: "css",
|
|
2551
|
+
modules: this.imports.value.css,
|
|
2552
|
+
names: [
|
|
2553
|
+
"css",
|
|
2554
|
+
"cva",
|
|
2555
|
+
"sva",
|
|
2556
|
+
"cx",
|
|
2557
|
+
"fallback",
|
|
2558
|
+
"viewTransition"
|
|
2559
|
+
]
|
|
2560
|
+
},
|
|
2561
|
+
{
|
|
2562
|
+
kind: "token",
|
|
2563
|
+
modules: this.imports.value.tokens,
|
|
2564
|
+
names: ["token"]
|
|
2565
|
+
},
|
|
2566
|
+
{
|
|
2567
|
+
kind: "recipe",
|
|
2568
|
+
modules: this.imports.value.recipe,
|
|
2569
|
+
names: this.recipes.keys
|
|
2570
|
+
},
|
|
2571
|
+
{
|
|
2572
|
+
kind: "pattern",
|
|
2573
|
+
modules: this.imports.value.pattern,
|
|
2574
|
+
names: this.patterns.keys
|
|
2575
|
+
}
|
|
2576
|
+
];
|
|
2577
|
+
const { baseUrl, paths = {} } = this.project.resolutionOptions;
|
|
2578
|
+
const options = {
|
|
2579
|
+
cwd: this.config.cwd,
|
|
2580
|
+
baseUrl,
|
|
2581
|
+
paths: Object.entries(paths).map(([pattern, values]) => ({
|
|
2582
|
+
pattern,
|
|
2583
|
+
paths: values
|
|
2584
|
+
})),
|
|
2585
|
+
tokens: this.tokens.allTokens.map((token) => ({
|
|
2586
|
+
path: token.name,
|
|
2587
|
+
value: this.tokens.view.get(token.name),
|
|
2588
|
+
variable: this.tokens.view.getVar(token.name)
|
|
2589
|
+
})),
|
|
2590
|
+
jsx: this.jsx.isEnabled
|
|
2591
|
+
};
|
|
2592
|
+
let analyses;
|
|
2593
|
+
try {
|
|
2594
|
+
analyses = this.loadNativeExtractor().analyzeMany(sources, entrypoints, options);
|
|
2595
|
+
} finally {
|
|
2596
|
+
this.nativePreparedSources.clear();
|
|
2597
|
+
}
|
|
2598
|
+
for (const analysis of analyses) {
|
|
2599
|
+
const owner = analysis.filename.replaceAll("\\", "/");
|
|
2600
|
+
if (!owners.has(owner)) continue;
|
|
2601
|
+
this.nativeExtractions.set(owner, analysis);
|
|
2602
|
+
this.nativeDependencies.set(owner, analysis.dependencies);
|
|
2603
|
+
this.nativePendingCandidates.set(owner, analysis.pendingCandidates);
|
|
2604
|
+
this.nativeConfigurationFiles.set(owner, analysis.configurationFiles);
|
|
2605
|
+
}
|
|
2606
|
+
};
|
|
2607
|
+
/** Included extraction owners whose native value graph reaches `filePath`, transitively. */
|
|
2608
|
+
getNativeDependents = (filePath) => {
|
|
2609
|
+
const changed = filePath.replaceAll("\\", "/");
|
|
2610
|
+
const selected = /* @__PURE__ */ new Set();
|
|
2611
|
+
let frontier = [changed];
|
|
2612
|
+
while (frontier.length) {
|
|
2613
|
+
const next = [];
|
|
2614
|
+
for (const dependency of frontier) for (const [owner, dependencies] of this.nativeDependencies) {
|
|
2615
|
+
const pending = this.nativePendingCandidates.get(owner) ?? [];
|
|
2616
|
+
if (selected.has(owner) || ![...dependencies, ...pending].some((item) => item.replaceAll("\\", "/") === dependency)) continue;
|
|
2617
|
+
selected.add(owner);
|
|
2618
|
+
next.push(owner);
|
|
2619
|
+
}
|
|
2620
|
+
frontier = next;
|
|
2621
|
+
}
|
|
2622
|
+
return [...selected];
|
|
2623
|
+
};
|
|
2624
|
+
/** @internal Native dependency edges, from dependency to extraction owner. */
|
|
2625
|
+
getNativeDependencyLedger = () => [...this.nativeDependencies].flatMap(([owner, dependencies]) => dependencies.map((dependency) => [dependency.replaceAll("\\", "/"), owner]));
|
|
2626
|
+
forgetNativeFile = (filePath) => {
|
|
2627
|
+
const file = this.runtime.path.abs(this.config.cwd, filePath).replaceAll("\\", "/");
|
|
2628
|
+
this.nativeDependencies.delete(file);
|
|
2629
|
+
this.nativePendingCandidates.delete(file);
|
|
2630
|
+
this.nativeConfigurationFiles.delete(file);
|
|
2631
|
+
this.nativeExtractions.delete(file);
|
|
2632
|
+
this.nativeSourceMetadata.delete(file);
|
|
2633
|
+
};
|
|
2634
|
+
parseNativeFile = (filePath, native, encoder) => {
|
|
2635
|
+
if (native.errors.length) throw new BambooError("NATIVE_EXTRACTION", `Native extraction failed for ${filePath}:\n${native.errors.join("\n")}`);
|
|
2636
|
+
const result = new ParserResult(this.parserOptions, encoder).setFilePath(filePath);
|
|
2637
|
+
result.native = true;
|
|
2638
|
+
result.nativePendingCandidates = native.pendingCandidates;
|
|
2639
|
+
result.nativeConfigurationFiles = native.configurationFiles;
|
|
2640
|
+
for (const dependency of native.dependencies) result.addDependency(dependency);
|
|
2641
|
+
const metadata = this.nativeSourceMetadata.get(filePath.replaceAll("\\", "/"));
|
|
2642
|
+
result.origins = metadata?.origins ?? true;
|
|
2643
|
+
for (const call of native.calls) {
|
|
2644
|
+
const atomOrigin = encoder.recordOrigins && result.origins ? {
|
|
2645
|
+
filePath,
|
|
2646
|
+
line: call.line,
|
|
2647
|
+
column: call.column
|
|
2648
|
+
} : void 0;
|
|
2649
|
+
if (call.kind === "jsx") {
|
|
2650
|
+
const recipeTag = [call.name, call.importedName].find((tag) => this.jsx.isJsxTagRecipe(tag));
|
|
2651
|
+
const isBambooComponent = Boolean(recipeTag);
|
|
2652
|
+
if (!(metadata?.options.matchTag ? metadata.options.matchTagMode === "override" ? metadata.options.matchTag(call.name, isBambooComponent) : isBambooComponent || metadata.options.matchTag(call.name, isBambooComponent) : isBambooComponent) || !recipeTag) continue;
|
|
2653
|
+
const data = call.arguments.map((properties) => Object.fromEntries(Object.entries(properties).filter(([property]) => {
|
|
2654
|
+
const isRecipeProperty = this.jsx.isRecipeProp(recipeTag, property);
|
|
2655
|
+
return metadata?.options.matchTagProp ? isRecipeProperty && metadata.options.matchTagProp(call.name, property) : isRecipeProperty;
|
|
2656
|
+
})));
|
|
2657
|
+
for (const recipe of this.recipes.filter(recipeTag)) result.setRecipe(recipe.baseName, {
|
|
2658
|
+
type: "jsx-recipe",
|
|
2659
|
+
name: call.name,
|
|
2660
|
+
data,
|
|
2661
|
+
atomOrigin
|
|
2662
|
+
});
|
|
2663
|
+
continue;
|
|
2664
|
+
}
|
|
2665
|
+
const item = {
|
|
2666
|
+
name: call.importedName,
|
|
2667
|
+
data: call.arguments,
|
|
2668
|
+
atomOrigin,
|
|
2669
|
+
tokenCalleeRange: call.kind === "token" || call.kind === "tokenValue" ? {
|
|
2670
|
+
start: call.calleeStart,
|
|
2671
|
+
end: call.calleeEnd
|
|
2672
|
+
} : void 0
|
|
2673
|
+
};
|
|
2674
|
+
const recipeConfig = call.kind === "css" && (call.importedName === "cva" || call.importedName === "sva");
|
|
2675
|
+
if (!(recipeConfig && item.data.every((data) => typeof data.className === "string" && data.className !== ""))) for (const loss of call.losses) result.unresolved.push({
|
|
2676
|
+
kind: recipeConfig ? "recipe" : "atomic",
|
|
2677
|
+
prop: loss.prop,
|
|
2678
|
+
filePath,
|
|
2679
|
+
line: call.line,
|
|
2680
|
+
column: call.column,
|
|
2681
|
+
reason: loss.reason
|
|
2682
|
+
});
|
|
2683
|
+
if (call.kind === "css" && [
|
|
2684
|
+
"css",
|
|
2685
|
+
"cva",
|
|
2686
|
+
"sva"
|
|
2687
|
+
].includes(call.importedName)) result.set(call.importedName, item);
|
|
2688
|
+
else if (call.kind === "css" && call.importedName === "viewTransition") result.setViewTransition(item);
|
|
2689
|
+
else if (call.kind === "pattern") result.setPattern(call.importedName, item);
|
|
2690
|
+
else if (call.kind === "recipe") result.setRecipe(call.importedName, item);
|
|
2691
|
+
else if (call.kind === "token" || call.kind === "tokenValue") result.setToken(item, call.kind);
|
|
2692
|
+
else if (call.kind === "dead") result.deadCalls.push({
|
|
2693
|
+
name: call.importedName,
|
|
2694
|
+
alias: call.name,
|
|
2695
|
+
mod: call.module,
|
|
2696
|
+
entrypoint: this.imports.value.pattern.some((module) => call.module.includes(module)) ? "pattern" : "recipe"
|
|
2697
|
+
});
|
|
2698
|
+
}
|
|
2699
|
+
this.parserHooks["parser:after"]?.({
|
|
2700
|
+
filePath,
|
|
2701
|
+
result
|
|
2702
|
+
});
|
|
2703
|
+
return result;
|
|
2704
|
+
};
|
|
2442
2705
|
parseFile = (filePath, styleEncoder) => {
|
|
2443
2706
|
const file = this.runtime.path.abs(this.config.cwd, filePath);
|
|
2707
|
+
const nativeFile = file.replaceAll("\\", "/");
|
|
2444
2708
|
logger.debug("file:extract", file);
|
|
2445
2709
|
const measure = logger.time.debug(`Parsed ${file}`);
|
|
2446
2710
|
let result;
|
|
2447
2711
|
try {
|
|
2448
2712
|
const encoder = styleEncoder || this.parserOptions.encoder;
|
|
2449
|
-
result = encoder.withOwner("extract", file, () => this.project.
|
|
2713
|
+
if (file.endsWith(".json")) result = encoder.withOwner("extract", file, () => this.project.parseJson(file, encoder));
|
|
2714
|
+
else {
|
|
2715
|
+
if (!this.nativeExtractions.has(nativeFile)) this.prepareNativeExtraction([file]);
|
|
2716
|
+
const native = this.nativeExtractions.get(nativeFile);
|
|
2717
|
+
if (!native && !this.runtime.fs.existsSync(file)) {
|
|
2718
|
+
encoder.releaseFile(file);
|
|
2719
|
+
this.parseFailures.delete(file);
|
|
2720
|
+
this.deadCalls.delete(file);
|
|
2721
|
+
measure();
|
|
2722
|
+
return;
|
|
2723
|
+
}
|
|
2724
|
+
if (!native) throw new BambooError("NATIVE_EXTRACTION", `Native extraction produced no result for ${file}.`);
|
|
2725
|
+
result = encoder.withOwner("extract", file, () => this.parseNativeFile(file, native, encoder));
|
|
2726
|
+
}
|
|
2727
|
+
this.nativeExtractions.delete(nativeFile);
|
|
2728
|
+
this.nativeSourceMetadata.delete(nativeFile);
|
|
2450
2729
|
this.parseFailures.delete(file);
|
|
2451
2730
|
} catch (error) {
|
|
2731
|
+
this.nativeExtractions.delete(nativeFile);
|
|
2732
|
+
this.nativeSourceMetadata.delete(nativeFile);
|
|
2452
2733
|
if (isCompilerGone(error)) throw error;
|
|
2453
2734
|
logger.caughtError("file:extract", `Failed to parse ${file}`, error);
|
|
2454
2735
|
this.parseFailures.set(file, error);
|
|
@@ -2486,6 +2767,7 @@ var BambooContext = class extends Generator {
|
|
|
2486
2767
|
* what is *parsed*, not what the project holds.
|
|
2487
2768
|
*/
|
|
2488
2769
|
extractableFiles = (files) => {
|
|
2770
|
+
this.nativePreparedSources.clear();
|
|
2489
2771
|
const { baseUrl, paths } = this.project.resolutionOptions;
|
|
2490
2772
|
const measure = logger.time.debug("Selected extractable files");
|
|
2491
2773
|
const { auxiliary, extractable } = selectExtractable(files, {
|
|
@@ -2493,28 +2775,28 @@ var BambooContext = class extends Generator {
|
|
|
2493
2775
|
cwd: this.config.cwd,
|
|
2494
2776
|
entrypoints: this.entrypointSpecifiers,
|
|
2495
2777
|
paths,
|
|
2778
|
+
fileExists: this.project.sourceExists,
|
|
2496
2779
|
readFile: (filePath) => {
|
|
2497
2780
|
try {
|
|
2498
|
-
|
|
2781
|
+
const original = this.project.getSourceText(filePath) ?? this.runtime.fs.readFileSync(filePath);
|
|
2782
|
+
const filename = this.runtime.path.abs(this.config.cwd, filePath);
|
|
2783
|
+
const prepared = this.prepareNativeSource(filename, original);
|
|
2784
|
+
this.nativePreparedSources.set(filename.replaceAll("\\", "/"), prepared);
|
|
2785
|
+
return prepared.source;
|
|
2499
2786
|
} catch {
|
|
2500
2787
|
return;
|
|
2501
2788
|
}
|
|
2502
2789
|
}
|
|
2503
2790
|
});
|
|
2504
|
-
|
|
2505
|
-
logger.debug("file:extract", `${extractable.length} of ${files.length} file(s) can reach a bamboo entrypoint; ${files.length - extractable.length} cannot and are not parsed; ${auxiliary.length} import target(s) outside the inventory
|
|
2791
|
+
this.nativeAuxiliaryFiles = auxiliary;
|
|
2792
|
+
logger.debug("file:extract", `${extractable.length} of ${files.length} file(s) can reach a bamboo entrypoint; ${files.length - extractable.length} cannot and are not parsed; ${auxiliary.length} local import target(s) sit outside the inventory`);
|
|
2506
2793
|
measure();
|
|
2507
2794
|
return extractable;
|
|
2508
2795
|
};
|
|
2509
|
-
/** Path/content pairs for a bulk install, skipping anything that cannot be read. */
|
|
2510
|
-
readSources = function* (files) {
|
|
2511
|
-
for (const file of files) try {
|
|
2512
|
-
yield [file, this.runtime.fs.readFileSync(file)];
|
|
2513
|
-
} catch {}
|
|
2514
|
-
};
|
|
2515
2796
|
parseFiles = (styleEncoder) => {
|
|
2516
2797
|
const encoder = styleEncoder || this.parserOptions.encoder;
|
|
2517
2798
|
const files = this.extractableFiles(this.getFiles());
|
|
2799
|
+
this.prepareNativeExtraction(files);
|
|
2518
2800
|
const filesWithCss = [];
|
|
2519
2801
|
const results = [];
|
|
2520
2802
|
files.forEach((file) => {
|
|
@@ -3667,6 +3949,7 @@ var Builder = class {
|
|
|
3667
3949
|
removeSource = (filePath) => {
|
|
3668
3950
|
const ctx = this.getContextOrThrow();
|
|
3669
3951
|
this.captureResolutionLedger(ctx);
|
|
3952
|
+
ctx.forgetNativeFile(filePath);
|
|
3670
3953
|
return ctx.project.removeSourceFile(filePath);
|
|
3671
3954
|
};
|
|
3672
3955
|
captureResolutionLedger = (ctx) => {
|
|
@@ -3914,6 +4197,7 @@ var Builder = class {
|
|
|
3914
4197
|
for (const file of changed) {
|
|
3915
4198
|
if (current.has(file)) affected.add(file);
|
|
3916
4199
|
for (const dependent of project.getDependents(file)) affected.add(this.sourcePath(dependent));
|
|
4200
|
+
for (const dependent of ctx.getNativeDependents(file)) affected.add(this.sourcePath(dependent));
|
|
3917
4201
|
if (existsSync(file) && !project.getSourceFile(file)) added.push(file);
|
|
3918
4202
|
}
|
|
3919
4203
|
if (added.length) for (const importer of pending) {
|
|
@@ -3949,6 +4233,7 @@ var Builder = class {
|
|
|
3949
4233
|
indegree.set(importer, (indegree.get(importer) ?? 0) + 1);
|
|
3950
4234
|
};
|
|
3951
4235
|
for (const fact of ledger) addEdge(fact.target, fact.importer);
|
|
4236
|
+
for (const [target, importer] of this.getContextOrThrow().getNativeDependencyLedger()) addEdge(target, importer);
|
|
3952
4237
|
for (const [target, importer] of syntheticEdges) addEdge(target, importer);
|
|
3953
4238
|
const compare = (left, right) => (inventoryRank.get(left) ?? 0) - (inventoryRank.get(right) ?? 0);
|
|
3954
4239
|
const ready = new MinPriorityQueue(compare);
|
|
@@ -4100,8 +4385,10 @@ var Builder = class {
|
|
|
4100
4385
|
{
|
|
4101
4386
|
const owner = this.absOwner(ctx, file);
|
|
4102
4387
|
const reads = parserResult?.getExportReads?.() ?? [];
|
|
4103
|
-
|
|
4104
|
-
|
|
4388
|
+
const parsedNatively = Boolean(parserResult?.native);
|
|
4389
|
+
if (parsedNatively) this.extractionReadsByOwner.delete(owner);
|
|
4390
|
+
else this.extractionReadsByOwner.set(owner, reads);
|
|
4391
|
+
const surface = !parsedNatively && ctx.project ? this.digestRecipeSurface(ctx, file, parserResult) : void 0;
|
|
4105
4392
|
if (this.changedThisPass.has(owner)) {
|
|
4106
4393
|
const previous = this.recipeSurfaceByOwner.get(owner);
|
|
4107
4394
|
this.recipeSurfaceStable.set(owner, previous !== void 0 && surface !== void 0 && previous === surface);
|
|
@@ -4113,9 +4400,15 @@ var Builder = class {
|
|
|
4113
4400
|
dependencies: uniq([...previousReads, ...previousPending]).sort(),
|
|
4114
4401
|
pendingCandidates: previousCandidates
|
|
4115
4402
|
} : void 0;
|
|
4116
|
-
const
|
|
4403
|
+
const nativeResult = parserResult;
|
|
4404
|
+
const native = Boolean(nativeResult.native);
|
|
4405
|
+
const dependencies = parserResult.getDependencies();
|
|
4406
|
+
const readSet = native ? {
|
|
4407
|
+
dependencies: uniq(dependencies).sort(),
|
|
4408
|
+
pendingCandidates: uniq([...nativeResult.nativePendingCandidates ?? []]).sort()
|
|
4409
|
+
} : ctx.project.getResolutionReadSet(file, dependencies, previousReadSet);
|
|
4117
4410
|
const currentReads = readSet.dependencies;
|
|
4118
|
-
const currentConfigurations = ctx.project.getResolutionConfigurationFiles(file,
|
|
4411
|
+
const currentConfigurations = native ? uniq([...currentReads.length || readSet.pendingCandidates.length ? this.tsconfigResolutionFiles : [], ...nativeResult.nativeConfigurationFiles ?? []]).sort() : ctx.project.getResolutionConfigurationFiles(file, dependencies, meta.isUnchanged ? previousConfigurations : []);
|
|
4119
4412
|
this.resolutionReadSets.set(owner, currentReads);
|
|
4120
4413
|
if (readSet.pendingCandidates.length) this.resolutionCandidateSets.set(owner, readSet.pendingCandidates);
|
|
4121
4414
|
else this.resolutionCandidateSets.delete(owner);
|
|
@@ -4155,6 +4448,7 @@ var Builder = class {
|
|
|
4155
4448
|
this.recipeSurfaceStable.clear();
|
|
4156
4449
|
this.readDigestMemo.clear();
|
|
4157
4450
|
const done = logger.time.info("Extracted in");
|
|
4451
|
+
ctx.prepareNativeExtraction(filesToExtract);
|
|
4158
4452
|
for (const file of filesToExtract) this.extractFile(ctx, file);
|
|
4159
4453
|
done();
|
|
4160
4454
|
this.sourceInventory = [...files];
|
|
@@ -4307,10 +4601,11 @@ async function debug(ctx, options) {
|
|
|
4307
4601
|
return;
|
|
4308
4602
|
}
|
|
4309
4603
|
const filesWithCss = [];
|
|
4604
|
+
ctx.prepareNativeExtraction(files);
|
|
4310
4605
|
files.map((file) => {
|
|
4311
4606
|
const measure = logger.time.debug(`Parsed ${file}`);
|
|
4312
4607
|
const encoder = ctx.encoder.clone();
|
|
4313
|
-
const result = ctx.
|
|
4608
|
+
const result = ctx.parseFile(file, encoder);
|
|
4314
4609
|
measure();
|
|
4315
4610
|
if (!result || result.isEmpty() || encoder.isEmpty()) return;
|
|
4316
4611
|
const styles = ctx.decoder.clone().collect(encoder);
|
|
@@ -4394,9 +4689,9 @@ async function generate(config, configPath) {
|
|
|
4394
4689
|
*/
|
|
4395
4690
|
const bundleStyles = async (ctx, changedFilePaths, inventoryChanged = false) => {
|
|
4396
4691
|
let parsed = 0;
|
|
4397
|
-
|
|
4692
|
+
ctx.prepareNativeExtraction(changedFilePaths);
|
|
4398
4693
|
for (const filePath of changedFilePaths) {
|
|
4399
|
-
const result =
|
|
4694
|
+
const result = ctx.parseFile(filePath);
|
|
4400
4695
|
recordResolvedTokenReferences(sourceScanCache, filePath, result);
|
|
4401
4696
|
if (result) parsed++;
|
|
4402
4697
|
}
|
|
@@ -4414,22 +4709,20 @@ async function generate(config, configPath) {
|
|
|
4414
4709
|
ctx.watchFiles(async (event, file) => {
|
|
4415
4710
|
const filePath = ctx.runtime.path.abs(cwd, file);
|
|
4416
4711
|
if (event === "unlink") {
|
|
4417
|
-
const dependents = ctx.
|
|
4712
|
+
const dependents = ctx.getNativeDependents(filePath);
|
|
4418
4713
|
ctx.project.removeSourceFile(filePath);
|
|
4714
|
+
ctx.forgetNativeFile(filePath);
|
|
4419
4715
|
sourceScanCache.entries.delete(filePath);
|
|
4420
4716
|
sourceScanCache.resolvedTokenReferences.delete(filePath);
|
|
4421
4717
|
await bundleStyles(ctx, dependents, true);
|
|
4422
4718
|
} else if (event === "change") {
|
|
4719
|
+
const dependents = ctx.getNativeDependents(filePath);
|
|
4423
4720
|
ctx.project.reloadSourceFile(filePath);
|
|
4424
|
-
await bundleStyles(ctx, [filePath, ...
|
|
4721
|
+
await bundleStyles(ctx, [...new Set([filePath, ...dependents])]);
|
|
4425
4722
|
} else if (event === "add") {
|
|
4426
|
-
const
|
|
4723
|
+
const dependents = ctx.getNativeDependents(filePath);
|
|
4427
4724
|
ctx.project.createSourceFile(filePath);
|
|
4428
|
-
await bundleStyles(ctx, [...new Set([
|
|
4429
|
-
filePath,
|
|
4430
|
-
...ctx.project.getDependents(filePath),
|
|
4431
|
-
...pendingClosure
|
|
4432
|
-
])]);
|
|
4725
|
+
await bundleStyles(ctx, [...new Set([filePath, ...dependents])]);
|
|
4433
4726
|
}
|
|
4434
4727
|
});
|
|
4435
4728
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bamboocss/node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.55.0",
|
|
4
4
|
"description": "The core css bamboo library",
|
|
5
5
|
"homepage": "https://bamboocss.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -61,23 +61,24 @@
|
|
|
61
61
|
"pkg-types": "2.3.0",
|
|
62
62
|
"pluralize": "8.0.0",
|
|
63
63
|
"ts-pattern": "5.9.0",
|
|
64
|
-
"@bamboocss/config": "1.
|
|
65
|
-
"@bamboocss/core": "1.
|
|
66
|
-
"@bamboocss/generator": "1.
|
|
67
|
-
"@bamboocss/logger": "1.
|
|
68
|
-
"@bamboocss/parser": "1.
|
|
69
|
-
"@bamboocss/plugin-svelte": "1.
|
|
70
|
-
"@bamboocss/plugin-vue": "1.
|
|
71
|
-
"@bamboocss/reporter": "1.
|
|
72
|
-
"@bamboocss/shared": "1.
|
|
73
|
-
"@bamboocss/token-dictionary": "1.
|
|
74
|
-
"@bamboocss/ts-ast": "1.
|
|
75
|
-
"@bamboocss/types": "1.
|
|
64
|
+
"@bamboocss/config": "1.55.0",
|
|
65
|
+
"@bamboocss/core": "1.55.0",
|
|
66
|
+
"@bamboocss/generator": "1.55.0",
|
|
67
|
+
"@bamboocss/logger": "1.55.0",
|
|
68
|
+
"@bamboocss/parser": "1.55.0",
|
|
69
|
+
"@bamboocss/plugin-svelte": "1.55.0",
|
|
70
|
+
"@bamboocss/plugin-vue": "1.55.0",
|
|
71
|
+
"@bamboocss/reporter": "1.55.0",
|
|
72
|
+
"@bamboocss/shared": "1.55.0",
|
|
73
|
+
"@bamboocss/token-dictionary": "1.55.0",
|
|
74
|
+
"@bamboocss/ts-ast": "1.55.0",
|
|
75
|
+
"@bamboocss/types": "1.55.0"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@types/fs-extra": "11.0.4",
|
|
79
79
|
"@types/picomatch": "4.0.2",
|
|
80
|
-
"boxen": "8.0.1"
|
|
80
|
+
"boxen": "8.0.1",
|
|
81
|
+
"@bamboocss/native-extractor": "1.55.0"
|
|
81
82
|
},
|
|
82
83
|
"scripts": {
|
|
83
84
|
"build": "tsdown --tsconfig tsconfig.build.json src/index.ts src/static-compiler.ts --format=cjs,esm --shims --dts",
|