@bamboocss/node 1.51.6 → 1.53.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 +220 -7
- package/dist/index.d.cts +18 -0
- package/dist/index.d.mts +18 -0
- package/dist/index.mjs +218 -5
- package/package.json +13 -13
package/dist/index.cjs
CHANGED
|
@@ -37,6 +37,10 @@ let _bamboocss_plugin_vue = require("@bamboocss/plugin-vue");
|
|
|
37
37
|
let _bamboocss_core = require("@bamboocss/core");
|
|
38
38
|
let _bamboocss_generator = require("@bamboocss/generator");
|
|
39
39
|
let _bamboocss_parser = require("@bamboocss/parser");
|
|
40
|
+
let node_fs = require("node:fs");
|
|
41
|
+
node_fs = __toESM(node_fs);
|
|
42
|
+
let node_path = require("node:path");
|
|
43
|
+
node_path = __toESM(node_path);
|
|
40
44
|
let perfect_debounce = require("perfect-debounce");
|
|
41
45
|
let node_process = require("node:process");
|
|
42
46
|
node_process = __toESM(node_process, 1);
|
|
@@ -44,10 +48,6 @@ let node_os = require("node:os");
|
|
|
44
48
|
node_os = __toESM(node_os, 1);
|
|
45
49
|
let node_tty = require("node:tty");
|
|
46
50
|
node_tty = __toESM(node_tty, 1);
|
|
47
|
-
let node_fs = require("node:fs");
|
|
48
|
-
node_fs = __toESM(node_fs);
|
|
49
|
-
let node_path = require("node:path");
|
|
50
|
-
node_path = __toESM(node_path);
|
|
51
51
|
let chokidar = require("chokidar");
|
|
52
52
|
chokidar = __toESM(chokidar);
|
|
53
53
|
let fast_glob = require("fast-glob");
|
|
@@ -150,6 +150,176 @@ async function codegen(ctx, ids) {
|
|
|
150
150
|
};
|
|
151
151
|
}
|
|
152
152
|
//#endregion
|
|
153
|
+
//#region src/extractable-files.ts
|
|
154
|
+
/**
|
|
155
|
+
* Which of the files `include` matched an extraction pass actually has to read.
|
|
156
|
+
*
|
|
157
|
+
* A file can only contribute to the stylesheet by *calling* something bamboo owns — `css`, a
|
|
158
|
+
* recipe, a pattern, `token`. Every one of those arrives as a binding, and a binding arrives
|
|
159
|
+
* through an import: either straight from an entrypoint, or from a local module that got it
|
|
160
|
+
* from one. A file with no such chain cannot hold a call, whatever else is in it.
|
|
161
|
+
*
|
|
162
|
+
* 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 compiler the latter took the
|
|
164
|
+
* pass from 88.9s to 26.3s with byte-identical CSS out. The scan itself costs ~300ms, because
|
|
165
|
+
* it reads text and never parses.
|
|
166
|
+
*
|
|
167
|
+
* ## Skipping is not the same as ignoring
|
|
168
|
+
*
|
|
169
|
+
* A file left out here is still *reachable*. Cross-file composition works by resolving an
|
|
170
|
+
* import and installing what it names, so a module that exports a style object still arrives
|
|
171
|
+
* the moment something that qualifies imports it. What is skipped is only asking "does this
|
|
172
|
+
* file *originate* a call", of a file that has no binding to originate one with.
|
|
173
|
+
*
|
|
174
|
+
* ## Everything here fails open
|
|
175
|
+
*
|
|
176
|
+
* The failure this must not have is dropping a rule, which is silent: the build stays green and
|
|
177
|
+
* the class the component asks for has nothing behind it. So every uncertainty resolves toward
|
|
178
|
+
* including the file, and the cases are named rather than left to a catch-all — a file that
|
|
179
|
+
* cannot be read, a source whose imports could not be scanned, a specifier that looks local and
|
|
180
|
+
* resolves to nothing. Being wrong in that direction costs time; being wrong in the other costs
|
|
181
|
+
* correctness.
|
|
182
|
+
*/
|
|
183
|
+
/**
|
|
184
|
+
* Module specifiers, from the four places one can appear.
|
|
185
|
+
*
|
|
186
|
+
* Deliberately loose about what surrounds them. A specifier missed here costs an edge, and an
|
|
187
|
+
* edge missed can exclude a file that should have been kept — so the pattern is written to
|
|
188
|
+
* over-match rather than to parse, and `scanSpecifiers` treats a source it found nothing in as
|
|
189
|
+
* one it failed to read.
|
|
190
|
+
*/
|
|
191
|
+
const SPECIFIER = /(?:\bfrom\s*|^\s*(?:import|export)\s*|\bimport\s*\(\s*|\brequire\s*\(\s*)['"]([^'"\n]+)['"]/gm;
|
|
192
|
+
/** The extensions a specifier may omit, in the order `@bamboocss/ts-ast` tries them. */
|
|
193
|
+
const EXTENSIONS = [
|
|
194
|
+
".ts",
|
|
195
|
+
".tsx",
|
|
196
|
+
".d.ts",
|
|
197
|
+
".mts",
|
|
198
|
+
".cts",
|
|
199
|
+
".js",
|
|
200
|
+
".jsx",
|
|
201
|
+
".mjs",
|
|
202
|
+
".cjs"
|
|
203
|
+
];
|
|
204
|
+
/** What a `.js`-family specifier may actually name, source first. */
|
|
205
|
+
const EMITTED = [
|
|
206
|
+
[".js", [
|
|
207
|
+
".ts",
|
|
208
|
+
".tsx",
|
|
209
|
+
".d.ts",
|
|
210
|
+
".js",
|
|
211
|
+
".jsx"
|
|
212
|
+
]],
|
|
213
|
+
[".mjs", [
|
|
214
|
+
".mts",
|
|
215
|
+
".d.mts",
|
|
216
|
+
".mjs"
|
|
217
|
+
]],
|
|
218
|
+
[".cjs", [
|
|
219
|
+
".cts",
|
|
220
|
+
".d.cts",
|
|
221
|
+
".cjs"
|
|
222
|
+
]]
|
|
223
|
+
];
|
|
224
|
+
/** Every specifier in a source, or `undefined` when the text could not be scanned at all. */
|
|
225
|
+
const scanSpecifiers = (text) => {
|
|
226
|
+
const found = [];
|
|
227
|
+
for (const match of text.matchAll(SPECIFIER)) if (match[1]) found.push(match[1]);
|
|
228
|
+
if (found.length) return found;
|
|
229
|
+
return /\b(?:import|require)\b/.test(text) ? void 0 : found;
|
|
230
|
+
};
|
|
231
|
+
/** A candidate path with every extension a specifier may have omitted. */
|
|
232
|
+
const candidatesFor = (base) => {
|
|
233
|
+
const emitted = EMITTED.find(([suffix]) => base.endsWith(suffix));
|
|
234
|
+
return [...emitted ? emitted[1].map((extension) => base.slice(0, -emitted[0].length) + extension) : [base, ...EXTENSIONS.map((extension) => base + extension)], ...EXTENSIONS.map((extension) => `${base}/index${extension}`)];
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* Where a specifier points, when that is somewhere inside the project.
|
|
238
|
+
*
|
|
239
|
+
* `undefined` means "nothing local", which is the answer for a package as well as for a broken
|
|
240
|
+
* path — and both are correct here, because neither can hand this file a binding bamboo owns.
|
|
241
|
+
* bamboo's own resolution stops at the same boundary: a target outside the project reads as
|
|
242
|
+
* non-local, so nothing it exports is ever extracted from.
|
|
243
|
+
*/
|
|
244
|
+
const localTargetOf = (specifier, importer, options) => {
|
|
245
|
+
const bases = [];
|
|
246
|
+
if (specifier.startsWith(".")) bases.push((0, node_path.resolve)((0, node_path.dirname)(importer), specifier));
|
|
247
|
+
else if ((0, node_path.isAbsolute)(specifier)) bases.push(specifier);
|
|
248
|
+
else {
|
|
249
|
+
for (const [pattern, targets] of Object.entries(options.paths ?? {})) {
|
|
250
|
+
const star = pattern.indexOf("*");
|
|
251
|
+
if (star === -1) {
|
|
252
|
+
if (pattern !== specifier) continue;
|
|
253
|
+
for (const target of targets) bases.push((0, node_path.resolve)(options.cwd, target));
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
const head = pattern.slice(0, star);
|
|
257
|
+
const tail = pattern.slice(star + 1);
|
|
258
|
+
if (!specifier.startsWith(head) || !specifier.endsWith(tail)) continue;
|
|
259
|
+
const filled = specifier.slice(head.length, specifier.length - tail.length);
|
|
260
|
+
for (const target of targets) bases.push((0, node_path.resolve)(options.cwd, target.replace("*", filled)));
|
|
261
|
+
}
|
|
262
|
+
if (options.baseUrl) bases.push((0, node_path.resolve)(options.cwd, options.baseUrl, specifier));
|
|
263
|
+
}
|
|
264
|
+
const exists = options.fileExists ?? node_fs.existsSync;
|
|
265
|
+
const root = options.cwd.endsWith("/") ? options.cwd : `${options.cwd}/`;
|
|
266
|
+
for (const base of bases) {
|
|
267
|
+
if (!base.startsWith(root)) continue;
|
|
268
|
+
for (const candidate of candidatesFor(base)) if (exists(candidate)) return candidate;
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* The subset of `files` that could hold a call to something bamboo owns.
|
|
273
|
+
*
|
|
274
|
+
* Two passes over text and no parsing. The first marks every file that names an entrypoint and
|
|
275
|
+
* records where each file's other imports point; the second walks those edges backwards from
|
|
276
|
+
* the marked set, because a file that imports a module carrying bamboo bindings may be using
|
|
277
|
+
* one — a recipe defined with `cva` in one file and called in another is exactly that shape.
|
|
278
|
+
*
|
|
279
|
+
* 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 what to
|
|
281
|
+
* install — see `auxiliary`.
|
|
282
|
+
*/
|
|
283
|
+
const selectExtractable = (files, options) => {
|
|
284
|
+
const keep = /* @__PURE__ */ new Set();
|
|
285
|
+
const importers = /* @__PURE__ */ new Map();
|
|
286
|
+
for (const file of files) {
|
|
287
|
+
const text = options.readFile(file);
|
|
288
|
+
if (text === void 0) {
|
|
289
|
+
keep.add(file);
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
if (options.entrypoints.some((entrypoint) => text.includes(entrypoint))) keep.add(file);
|
|
293
|
+
const specifiers = scanSpecifiers(text);
|
|
294
|
+
if (specifiers === void 0) {
|
|
295
|
+
keep.add(file);
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
for (const specifier of specifiers) {
|
|
299
|
+
const target = localTargetOf(specifier, file, options);
|
|
300
|
+
if (!target) continue;
|
|
301
|
+
const seen = importers.get(target);
|
|
302
|
+
if (seen) seen.push(file);
|
|
303
|
+
else importers.set(target, [file]);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
let frontier = [...keep];
|
|
307
|
+
while (frontier.length) {
|
|
308
|
+
const next = [];
|
|
309
|
+
for (const target of frontier) for (const importer of importers.get(target) ?? []) {
|
|
310
|
+
if (keep.has(importer)) continue;
|
|
311
|
+
keep.add(importer);
|
|
312
|
+
next.push(importer);
|
|
313
|
+
}
|
|
314
|
+
frontier = next;
|
|
315
|
+
}
|
|
316
|
+
const inventory = new Set(files);
|
|
317
|
+
return {
|
|
318
|
+
auxiliary: [...importers.keys()].filter((target) => !inventory.has(target)),
|
|
319
|
+
extractable: files.filter((file) => keep.has(file))
|
|
320
|
+
};
|
|
321
|
+
};
|
|
322
|
+
//#endregion
|
|
153
323
|
//#region ../../node_modules/.pnpm/ansi-regex@6.2.2/node_modules/ansi-regex/index.js
|
|
154
324
|
function ansiRegex({ onlyFirst = false } = {}) {
|
|
155
325
|
return new RegExp(`(?:\\u001B\\][\\s\\S]*?(?:\\u0007|\\u001B\\u005C|\\u009C))|[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]`, onlyFirst ? void 0 : "g");
|
|
@@ -2310,9 +2480,53 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
2310
2480
|
* disagree about what a failure means. This one used to let the first throw out, which is
|
|
2311
2481
|
* why `cssgen` and a bundler build reported different things about the same source.
|
|
2312
2482
|
*/
|
|
2483
|
+
/**
|
|
2484
|
+
* The entrypoint specifiers, as `ImportMap` matches them.
|
|
2485
|
+
*
|
|
2486
|
+
* Every `mods` list at once rather than the `css` one alone: a file whose only bamboo import
|
|
2487
|
+
* is a recipe, a pattern or `token` originates calls just as surely, and leaving those out
|
|
2488
|
+
* would skip it.
|
|
2489
|
+
*/
|
|
2490
|
+
get entrypointSpecifiers() {
|
|
2491
|
+
return (0, _bamboocss_shared.uniq)(Object.values(this.imports.matchers).flatMap((matcher) => matcher.mods));
|
|
2492
|
+
}
|
|
2493
|
+
/**
|
|
2494
|
+
* The files this pass has to read, out of everything `include` matched.
|
|
2495
|
+
*
|
|
2496
|
+
* See `selectExtractable`. Kept behind a method so the reasons live in one place and a caller
|
|
2497
|
+
* that wants the whole inventory — the watcher, the token scan — is unaffected: this narrows
|
|
2498
|
+
* what is *parsed*, not what the project holds.
|
|
2499
|
+
*/
|
|
2500
|
+
extractableFiles = (files) => {
|
|
2501
|
+
const { baseUrl, paths } = this.project.resolutionOptions;
|
|
2502
|
+
const measure = _bamboocss_logger.logger.time.debug("Selected extractable files");
|
|
2503
|
+
const { auxiliary, extractable } = selectExtractable(files, {
|
|
2504
|
+
baseUrl,
|
|
2505
|
+
cwd: this.config.cwd,
|
|
2506
|
+
entrypoints: this.entrypointSpecifiers,
|
|
2507
|
+
paths,
|
|
2508
|
+
readFile: (filePath) => {
|
|
2509
|
+
try {
|
|
2510
|
+
return this.runtime.fs.readFileSync(filePath);
|
|
2511
|
+
} catch {
|
|
2512
|
+
return;
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
});
|
|
2516
|
+
if (auxiliary.length) this.project.addSourceFiles(this.readSources(auxiliary));
|
|
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 installed up front`);
|
|
2518
|
+
measure();
|
|
2519
|
+
return extractable;
|
|
2520
|
+
};
|
|
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
|
+
};
|
|
2313
2527
|
parseFiles = (styleEncoder) => {
|
|
2314
2528
|
const encoder = styleEncoder || this.parserOptions.encoder;
|
|
2315
|
-
const files = this.getFiles();
|
|
2529
|
+
const files = this.extractableFiles(this.getFiles());
|
|
2316
2530
|
const filesWithCss = [];
|
|
2317
2531
|
const results = [];
|
|
2318
2532
|
files.forEach((file) => {
|
|
@@ -2574,8 +2788,8 @@ function accountSnapshot(ctx, snapshot, accounting) {
|
|
|
2574
2788
|
});
|
|
2575
2789
|
return;
|
|
2576
2790
|
}
|
|
2791
|
+
if (!mentionsToken(ctx, parsed)) return;
|
|
2577
2792
|
if (ctx.project.getSyntacticDiagnosticCount(filePath)) {
|
|
2578
|
-
if (!mentionsToken(ctx, parsed)) return;
|
|
2579
2793
|
declined.push({
|
|
2580
2794
|
filePath,
|
|
2581
2795
|
line: 1,
|
|
@@ -2583,7 +2797,6 @@ function accountSnapshot(ctx, snapshot, accounting) {
|
|
|
2583
2797
|
});
|
|
2584
2798
|
return;
|
|
2585
2799
|
}
|
|
2586
|
-
if (!mentionsToken(ctx, parsed)) return;
|
|
2587
2800
|
accountFile(ctx, sourceFile, filePath, paths, prefixes, declined);
|
|
2588
2801
|
}
|
|
2589
2802
|
/**
|
package/dist/index.d.cts
CHANGED
|
@@ -203,6 +203,24 @@ declare class BambooContext extends Generator {
|
|
|
203
203
|
* disagree about what a failure means. This one used to let the first throw out, which is
|
|
204
204
|
* why `cssgen` and a bundler build reported different things about the same source.
|
|
205
205
|
*/
|
|
206
|
+
/**
|
|
207
|
+
* The entrypoint specifiers, as `ImportMap` matches them.
|
|
208
|
+
*
|
|
209
|
+
* Every `mods` list at once rather than the `css` one alone: a file whose only bamboo import
|
|
210
|
+
* is a recipe, a pattern or `token` originates calls just as surely, and leaving those out
|
|
211
|
+
* would skip it.
|
|
212
|
+
*/
|
|
213
|
+
private get entrypointSpecifiers();
|
|
214
|
+
/**
|
|
215
|
+
* The files this pass has to read, out of everything `include` matched.
|
|
216
|
+
*
|
|
217
|
+
* See `selectExtractable`. Kept behind a method so the reasons live in one place and a caller
|
|
218
|
+
* that wants the whole inventory — the watcher, the token scan — is unaffected: this narrows
|
|
219
|
+
* what is *parsed*, not what the project holds.
|
|
220
|
+
*/
|
|
221
|
+
extractableFiles: (files: readonly string[]) => string[];
|
|
222
|
+
/** Path/content pairs for a bulk install, skipping anything that cannot be read. */
|
|
223
|
+
private readSources;
|
|
206
224
|
parseFiles: (styleEncoder?: StyleEncoder) => {
|
|
207
225
|
filesWithCss: string[];
|
|
208
226
|
files: string[];
|
package/dist/index.d.mts
CHANGED
|
@@ -203,6 +203,24 @@ declare class BambooContext extends Generator {
|
|
|
203
203
|
* disagree about what a failure means. This one used to let the first throw out, which is
|
|
204
204
|
* why `cssgen` and a bundler build reported different things about the same source.
|
|
205
205
|
*/
|
|
206
|
+
/**
|
|
207
|
+
* The entrypoint specifiers, as `ImportMap` matches them.
|
|
208
|
+
*
|
|
209
|
+
* Every `mods` list at once rather than the `css` one alone: a file whose only bamboo import
|
|
210
|
+
* is a recipe, a pattern or `token` originates calls just as surely, and leaving those out
|
|
211
|
+
* would skip it.
|
|
212
|
+
*/
|
|
213
|
+
private get entrypointSpecifiers();
|
|
214
|
+
/**
|
|
215
|
+
* The files this pass has to read, out of everything `include` matched.
|
|
216
|
+
*
|
|
217
|
+
* See `selectExtractable`. Kept behind a method so the reasons live in one place and a caller
|
|
218
|
+
* that wants the whole inventory — the watcher, the token scan — is unaffected: this narrows
|
|
219
|
+
* what is *parsed*, not what the project holds.
|
|
220
|
+
*/
|
|
221
|
+
extractableFiles: (files: readonly string[]) => string[];
|
|
222
|
+
/** Path/content pairs for a bulk install, skipping anything that cannot be read. */
|
|
223
|
+
private readSources;
|
|
206
224
|
parseFiles: (styleEncoder?: StyleEncoder) => {
|
|
207
225
|
filesWithCss: string[];
|
|
208
226
|
files: string[];
|
package/dist/index.mjs
CHANGED
|
@@ -12,12 +12,12 @@ import { pluginVue } from "@bamboocss/plugin-vue";
|
|
|
12
12
|
import { checkNamingAgreement, formatNamingDisagreement, messages, prunesPreflight } from "@bamboocss/core";
|
|
13
13
|
import { Generator, generatePackageExports } from "@bamboocss/generator";
|
|
14
14
|
import { Project } from "@bamboocss/parser";
|
|
15
|
+
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";
|
|
15
17
|
import { debounce } from "perfect-debounce";
|
|
16
18
|
import process$1 from "node:process";
|
|
17
19
|
import os from "node:os";
|
|
18
20
|
import tty from "node:tty";
|
|
19
|
-
import fs, { promises } from "node:fs";
|
|
20
|
-
import path from "node:path";
|
|
21
21
|
import chokidar from "chokidar";
|
|
22
22
|
import glob from "fast-glob";
|
|
23
23
|
import fsExtra from "fs-extra";
|
|
@@ -138,6 +138,176 @@ async function codegen(ctx, ids) {
|
|
|
138
138
|
};
|
|
139
139
|
}
|
|
140
140
|
//#endregion
|
|
141
|
+
//#region src/extractable-files.ts
|
|
142
|
+
/**
|
|
143
|
+
* Which of the files `include` matched an extraction pass actually has to read.
|
|
144
|
+
*
|
|
145
|
+
* A file can only contribute to the stylesheet by *calling* something bamboo owns — `css`, a
|
|
146
|
+
* recipe, a pattern, `token`. Every one of those arrives as a binding, and a binding arrives
|
|
147
|
+
* through an import: either straight from an entrypoint, or from a local module that got it
|
|
148
|
+
* from one. A file with no such chain cannot hold a call, whatever else is in it.
|
|
149
|
+
*
|
|
150
|
+
* 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 compiler the latter took the
|
|
152
|
+
* pass from 88.9s to 26.3s with byte-identical CSS out. The scan itself costs ~300ms, because
|
|
153
|
+
* it reads text and never parses.
|
|
154
|
+
*
|
|
155
|
+
* ## Skipping is not the same as ignoring
|
|
156
|
+
*
|
|
157
|
+
* A file left out here is still *reachable*. Cross-file composition works by resolving an
|
|
158
|
+
* import and installing what it names, so a module that exports a style object still arrives
|
|
159
|
+
* the moment something that qualifies imports it. What is skipped is only asking "does this
|
|
160
|
+
* file *originate* a call", of a file that has no binding to originate one with.
|
|
161
|
+
*
|
|
162
|
+
* ## Everything here fails open
|
|
163
|
+
*
|
|
164
|
+
* The failure this must not have is dropping a rule, which is silent: the build stays green and
|
|
165
|
+
* the class the component asks for has nothing behind it. So every uncertainty resolves toward
|
|
166
|
+
* including the file, and the cases are named rather than left to a catch-all — a file that
|
|
167
|
+
* cannot be read, a source whose imports could not be scanned, a specifier that looks local and
|
|
168
|
+
* resolves to nothing. Being wrong in that direction costs time; being wrong in the other costs
|
|
169
|
+
* correctness.
|
|
170
|
+
*/
|
|
171
|
+
/**
|
|
172
|
+
* Module specifiers, from the four places one can appear.
|
|
173
|
+
*
|
|
174
|
+
* Deliberately loose about what surrounds them. A specifier missed here costs an edge, and an
|
|
175
|
+
* edge missed can exclude a file that should have been kept — so the pattern is written to
|
|
176
|
+
* over-match rather than to parse, and `scanSpecifiers` treats a source it found nothing in as
|
|
177
|
+
* one it failed to read.
|
|
178
|
+
*/
|
|
179
|
+
const SPECIFIER = /(?:\bfrom\s*|^\s*(?:import|export)\s*|\bimport\s*\(\s*|\brequire\s*\(\s*)['"]([^'"\n]+)['"]/gm;
|
|
180
|
+
/** The extensions a specifier may omit, in the order `@bamboocss/ts-ast` tries them. */
|
|
181
|
+
const EXTENSIONS = [
|
|
182
|
+
".ts",
|
|
183
|
+
".tsx",
|
|
184
|
+
".d.ts",
|
|
185
|
+
".mts",
|
|
186
|
+
".cts",
|
|
187
|
+
".js",
|
|
188
|
+
".jsx",
|
|
189
|
+
".mjs",
|
|
190
|
+
".cjs"
|
|
191
|
+
];
|
|
192
|
+
/** What a `.js`-family specifier may actually name, source first. */
|
|
193
|
+
const EMITTED = [
|
|
194
|
+
[".js", [
|
|
195
|
+
".ts",
|
|
196
|
+
".tsx",
|
|
197
|
+
".d.ts",
|
|
198
|
+
".js",
|
|
199
|
+
".jsx"
|
|
200
|
+
]],
|
|
201
|
+
[".mjs", [
|
|
202
|
+
".mts",
|
|
203
|
+
".d.mts",
|
|
204
|
+
".mjs"
|
|
205
|
+
]],
|
|
206
|
+
[".cjs", [
|
|
207
|
+
".cts",
|
|
208
|
+
".d.cts",
|
|
209
|
+
".cjs"
|
|
210
|
+
]]
|
|
211
|
+
];
|
|
212
|
+
/** Every specifier in a source, or `undefined` when the text could not be scanned at all. */
|
|
213
|
+
const scanSpecifiers = (text) => {
|
|
214
|
+
const found = [];
|
|
215
|
+
for (const match of text.matchAll(SPECIFIER)) if (match[1]) found.push(match[1]);
|
|
216
|
+
if (found.length) return found;
|
|
217
|
+
return /\b(?:import|require)\b/.test(text) ? void 0 : found;
|
|
218
|
+
};
|
|
219
|
+
/** A candidate path with every extension a specifier may have omitted. */
|
|
220
|
+
const candidatesFor = (base) => {
|
|
221
|
+
const emitted = EMITTED.find(([suffix]) => base.endsWith(suffix));
|
|
222
|
+
return [...emitted ? emitted[1].map((extension) => base.slice(0, -emitted[0].length) + extension) : [base, ...EXTENSIONS.map((extension) => base + extension)], ...EXTENSIONS.map((extension) => `${base}/index${extension}`)];
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* Where a specifier points, when that is somewhere inside the project.
|
|
226
|
+
*
|
|
227
|
+
* `undefined` means "nothing local", which is the answer for a package as well as for a broken
|
|
228
|
+
* path — and both are correct here, because neither can hand this file a binding bamboo owns.
|
|
229
|
+
* bamboo's own resolution stops at the same boundary: a target outside the project reads as
|
|
230
|
+
* non-local, so nothing it exports is ever extracted from.
|
|
231
|
+
*/
|
|
232
|
+
const localTargetOf = (specifier, importer, options) => {
|
|
233
|
+
const bases = [];
|
|
234
|
+
if (specifier.startsWith(".")) bases.push(resolve$1(dirname$1(importer), specifier));
|
|
235
|
+
else if (isAbsolute$1(specifier)) bases.push(specifier);
|
|
236
|
+
else {
|
|
237
|
+
for (const [pattern, targets] of Object.entries(options.paths ?? {})) {
|
|
238
|
+
const star = pattern.indexOf("*");
|
|
239
|
+
if (star === -1) {
|
|
240
|
+
if (pattern !== specifier) continue;
|
|
241
|
+
for (const target of targets) bases.push(resolve$1(options.cwd, target));
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
const head = pattern.slice(0, star);
|
|
245
|
+
const tail = pattern.slice(star + 1);
|
|
246
|
+
if (!specifier.startsWith(head) || !specifier.endsWith(tail)) continue;
|
|
247
|
+
const filled = specifier.slice(head.length, specifier.length - tail.length);
|
|
248
|
+
for (const target of targets) bases.push(resolve$1(options.cwd, target.replace("*", filled)));
|
|
249
|
+
}
|
|
250
|
+
if (options.baseUrl) bases.push(resolve$1(options.cwd, options.baseUrl, specifier));
|
|
251
|
+
}
|
|
252
|
+
const exists = options.fileExists ?? existsSync$1;
|
|
253
|
+
const root = options.cwd.endsWith("/") ? options.cwd : `${options.cwd}/`;
|
|
254
|
+
for (const base of bases) {
|
|
255
|
+
if (!base.startsWith(root)) continue;
|
|
256
|
+
for (const candidate of candidatesFor(base)) if (exists(candidate)) return candidate;
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
/**
|
|
260
|
+
* The subset of `files` that could hold a call to something bamboo owns.
|
|
261
|
+
*
|
|
262
|
+
* Two passes over text and no parsing. The first marks every file that names an entrypoint and
|
|
263
|
+
* records where each file's other imports point; the second walks those edges backwards from
|
|
264
|
+
* the marked set, because a file that imports a module carrying bamboo bindings may be using
|
|
265
|
+
* one — a recipe defined with `cva` in one file and called in another is exactly that shape.
|
|
266
|
+
*
|
|
267
|
+
* 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 what to
|
|
269
|
+
* install — see `auxiliary`.
|
|
270
|
+
*/
|
|
271
|
+
const selectExtractable = (files, options) => {
|
|
272
|
+
const keep = /* @__PURE__ */ new Set();
|
|
273
|
+
const importers = /* @__PURE__ */ new Map();
|
|
274
|
+
for (const file of files) {
|
|
275
|
+
const text = options.readFile(file);
|
|
276
|
+
if (text === void 0) {
|
|
277
|
+
keep.add(file);
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
if (options.entrypoints.some((entrypoint) => text.includes(entrypoint))) keep.add(file);
|
|
281
|
+
const specifiers = scanSpecifiers(text);
|
|
282
|
+
if (specifiers === void 0) {
|
|
283
|
+
keep.add(file);
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
for (const specifier of specifiers) {
|
|
287
|
+
const target = localTargetOf(specifier, file, options);
|
|
288
|
+
if (!target) continue;
|
|
289
|
+
const seen = importers.get(target);
|
|
290
|
+
if (seen) seen.push(file);
|
|
291
|
+
else importers.set(target, [file]);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
let frontier = [...keep];
|
|
295
|
+
while (frontier.length) {
|
|
296
|
+
const next = [];
|
|
297
|
+
for (const target of frontier) for (const importer of importers.get(target) ?? []) {
|
|
298
|
+
if (keep.has(importer)) continue;
|
|
299
|
+
keep.add(importer);
|
|
300
|
+
next.push(importer);
|
|
301
|
+
}
|
|
302
|
+
frontier = next;
|
|
303
|
+
}
|
|
304
|
+
const inventory = new Set(files);
|
|
305
|
+
return {
|
|
306
|
+
auxiliary: [...importers.keys()].filter((target) => !inventory.has(target)),
|
|
307
|
+
extractable: files.filter((file) => keep.has(file))
|
|
308
|
+
};
|
|
309
|
+
};
|
|
310
|
+
//#endregion
|
|
141
311
|
//#region ../../node_modules/.pnpm/ansi-regex@6.2.2/node_modules/ansi-regex/index.js
|
|
142
312
|
function ansiRegex({ onlyFirst = false } = {}) {
|
|
143
313
|
return new RegExp(`(?:\\u001B\\][\\s\\S]*?(?:\\u0007|\\u001B\\u005C|\\u009C))|[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]`, onlyFirst ? void 0 : "g");
|
|
@@ -2298,9 +2468,53 @@ var BambooContext = class extends Generator {
|
|
|
2298
2468
|
* disagree about what a failure means. This one used to let the first throw out, which is
|
|
2299
2469
|
* why `cssgen` and a bundler build reported different things about the same source.
|
|
2300
2470
|
*/
|
|
2471
|
+
/**
|
|
2472
|
+
* The entrypoint specifiers, as `ImportMap` matches them.
|
|
2473
|
+
*
|
|
2474
|
+
* Every `mods` list at once rather than the `css` one alone: a file whose only bamboo import
|
|
2475
|
+
* is a recipe, a pattern or `token` originates calls just as surely, and leaving those out
|
|
2476
|
+
* would skip it.
|
|
2477
|
+
*/
|
|
2478
|
+
get entrypointSpecifiers() {
|
|
2479
|
+
return uniq(Object.values(this.imports.matchers).flatMap((matcher) => matcher.mods));
|
|
2480
|
+
}
|
|
2481
|
+
/**
|
|
2482
|
+
* The files this pass has to read, out of everything `include` matched.
|
|
2483
|
+
*
|
|
2484
|
+
* See `selectExtractable`. Kept behind a method so the reasons live in one place and a caller
|
|
2485
|
+
* that wants the whole inventory — the watcher, the token scan — is unaffected: this narrows
|
|
2486
|
+
* what is *parsed*, not what the project holds.
|
|
2487
|
+
*/
|
|
2488
|
+
extractableFiles = (files) => {
|
|
2489
|
+
const { baseUrl, paths } = this.project.resolutionOptions;
|
|
2490
|
+
const measure = logger.time.debug("Selected extractable files");
|
|
2491
|
+
const { auxiliary, extractable } = selectExtractable(files, {
|
|
2492
|
+
baseUrl,
|
|
2493
|
+
cwd: this.config.cwd,
|
|
2494
|
+
entrypoints: this.entrypointSpecifiers,
|
|
2495
|
+
paths,
|
|
2496
|
+
readFile: (filePath) => {
|
|
2497
|
+
try {
|
|
2498
|
+
return this.runtime.fs.readFileSync(filePath);
|
|
2499
|
+
} catch {
|
|
2500
|
+
return;
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
});
|
|
2504
|
+
if (auxiliary.length) this.project.addSourceFiles(this.readSources(auxiliary));
|
|
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 installed up front`);
|
|
2506
|
+
measure();
|
|
2507
|
+
return extractable;
|
|
2508
|
+
};
|
|
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
|
+
};
|
|
2301
2515
|
parseFiles = (styleEncoder) => {
|
|
2302
2516
|
const encoder = styleEncoder || this.parserOptions.encoder;
|
|
2303
|
-
const files = this.getFiles();
|
|
2517
|
+
const files = this.extractableFiles(this.getFiles());
|
|
2304
2518
|
const filesWithCss = [];
|
|
2305
2519
|
const results = [];
|
|
2306
2520
|
files.forEach((file) => {
|
|
@@ -2562,8 +2776,8 @@ function accountSnapshot(ctx, snapshot, accounting) {
|
|
|
2562
2776
|
});
|
|
2563
2777
|
return;
|
|
2564
2778
|
}
|
|
2779
|
+
if (!mentionsToken(ctx, parsed)) return;
|
|
2565
2780
|
if (ctx.project.getSyntacticDiagnosticCount(filePath)) {
|
|
2566
|
-
if (!mentionsToken(ctx, parsed)) return;
|
|
2567
2781
|
declined.push({
|
|
2568
2782
|
filePath,
|
|
2569
2783
|
line: 1,
|
|
@@ -2571,7 +2785,6 @@ function accountSnapshot(ctx, snapshot, accounting) {
|
|
|
2571
2785
|
});
|
|
2572
2786
|
return;
|
|
2573
2787
|
}
|
|
2574
|
-
if (!mentionsToken(ctx, parsed)) return;
|
|
2575
2788
|
accountFile(ctx, sourceFile, filePath, paths, prefixes, declined);
|
|
2576
2789
|
}
|
|
2577
2790
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bamboocss/node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.53.0",
|
|
4
4
|
"description": "The core css bamboo library",
|
|
5
5
|
"homepage": "https://bamboocss.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -61,18 +61,18 @@
|
|
|
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.53.0",
|
|
65
|
+
"@bamboocss/core": "1.53.0",
|
|
66
|
+
"@bamboocss/generator": "1.53.0",
|
|
67
|
+
"@bamboocss/logger": "1.53.0",
|
|
68
|
+
"@bamboocss/parser": "1.53.0",
|
|
69
|
+
"@bamboocss/plugin-svelte": "1.53.0",
|
|
70
|
+
"@bamboocss/plugin-vue": "1.53.0",
|
|
71
|
+
"@bamboocss/reporter": "1.53.0",
|
|
72
|
+
"@bamboocss/shared": "1.53.0",
|
|
73
|
+
"@bamboocss/token-dictionary": "1.53.0",
|
|
74
|
+
"@bamboocss/ts-ast": "1.53.0",
|
|
75
|
+
"@bamboocss/types": "1.53.0"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@types/fs-extra": "11.0.4",
|