@bamboocss/node 1.51.6 → 1.52.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 +207 -5
- package/dist/index.d.cts +16 -0
- package/dist/index.d.mts +16 -0
- package/dist/index.mjs +205 -3
- 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,171 @@ 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
|
+
const selectExtractable = (files, options) => {
|
|
280
|
+
const keep = /* @__PURE__ */ new Set();
|
|
281
|
+
const importers = /* @__PURE__ */ new Map();
|
|
282
|
+
for (const file of files) {
|
|
283
|
+
const text = options.readFile(file);
|
|
284
|
+
if (text === void 0) {
|
|
285
|
+
keep.add(file);
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (options.entrypoints.some((entrypoint) => text.includes(entrypoint))) {
|
|
289
|
+
keep.add(file);
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
const specifiers = scanSpecifiers(text);
|
|
293
|
+
if (specifiers === void 0) {
|
|
294
|
+
keep.add(file);
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
for (const specifier of specifiers) {
|
|
298
|
+
const target = localTargetOf(specifier, file, options);
|
|
299
|
+
if (!target) continue;
|
|
300
|
+
const seen = importers.get(target);
|
|
301
|
+
if (seen) seen.push(file);
|
|
302
|
+
else importers.set(target, [file]);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
let frontier = [...keep];
|
|
306
|
+
while (frontier.length) {
|
|
307
|
+
const next = [];
|
|
308
|
+
for (const target of frontier) for (const importer of importers.get(target) ?? []) {
|
|
309
|
+
if (keep.has(importer)) continue;
|
|
310
|
+
keep.add(importer);
|
|
311
|
+
next.push(importer);
|
|
312
|
+
}
|
|
313
|
+
frontier = next;
|
|
314
|
+
}
|
|
315
|
+
return files.filter((file) => keep.has(file));
|
|
316
|
+
};
|
|
317
|
+
//#endregion
|
|
153
318
|
//#region ../../node_modules/.pnpm/ansi-regex@6.2.2/node_modules/ansi-regex/index.js
|
|
154
319
|
function ansiRegex({ onlyFirst = false } = {}) {
|
|
155
320
|
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 +2475,46 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
2310
2475
|
* disagree about what a failure means. This one used to let the first throw out, which is
|
|
2311
2476
|
* why `cssgen` and a bundler build reported different things about the same source.
|
|
2312
2477
|
*/
|
|
2478
|
+
/**
|
|
2479
|
+
* The entrypoint specifiers, as `ImportMap` matches them.
|
|
2480
|
+
*
|
|
2481
|
+
* Every `mods` list at once rather than the `css` one alone: a file whose only bamboo import
|
|
2482
|
+
* is a recipe, a pattern or `token` originates calls just as surely, and leaving those out
|
|
2483
|
+
* would skip it.
|
|
2484
|
+
*/
|
|
2485
|
+
get entrypointSpecifiers() {
|
|
2486
|
+
return (0, _bamboocss_shared.uniq)(Object.values(this.imports.matchers).flatMap((matcher) => matcher.mods));
|
|
2487
|
+
}
|
|
2488
|
+
/**
|
|
2489
|
+
* The files this pass has to read, out of everything `include` matched.
|
|
2490
|
+
*
|
|
2491
|
+
* See `selectExtractable`. Kept behind a method so the reasons live in one place and a caller
|
|
2492
|
+
* that wants the whole inventory — the watcher, the token scan — is unaffected: this narrows
|
|
2493
|
+
* what is *parsed*, not what the project holds.
|
|
2494
|
+
*/
|
|
2495
|
+
extractableFiles = (files) => {
|
|
2496
|
+
const { baseUrl, paths } = this.project.resolutionOptions;
|
|
2497
|
+
const measure = _bamboocss_logger.logger.time.debug("Selected extractable files");
|
|
2498
|
+
const extractable = selectExtractable(files, {
|
|
2499
|
+
baseUrl,
|
|
2500
|
+
cwd: this.config.cwd,
|
|
2501
|
+
entrypoints: this.entrypointSpecifiers,
|
|
2502
|
+
paths,
|
|
2503
|
+
readFile: (filePath) => {
|
|
2504
|
+
try {
|
|
2505
|
+
return this.runtime.fs.readFileSync(filePath);
|
|
2506
|
+
} catch {
|
|
2507
|
+
return;
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2510
|
+
});
|
|
2511
|
+
_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`);
|
|
2512
|
+
measure();
|
|
2513
|
+
return extractable;
|
|
2514
|
+
};
|
|
2313
2515
|
parseFiles = (styleEncoder) => {
|
|
2314
2516
|
const encoder = styleEncoder || this.parserOptions.encoder;
|
|
2315
|
-
const files = this.getFiles();
|
|
2517
|
+
const files = this.extractableFiles(this.getFiles());
|
|
2316
2518
|
const filesWithCss = [];
|
|
2317
2519
|
const results = [];
|
|
2318
2520
|
files.forEach((file) => {
|
package/dist/index.d.cts
CHANGED
|
@@ -203,6 +203,22 @@ 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[];
|
|
206
222
|
parseFiles: (styleEncoder?: StyleEncoder) => {
|
|
207
223
|
filesWithCss: string[];
|
|
208
224
|
files: string[];
|
package/dist/index.d.mts
CHANGED
|
@@ -203,6 +203,22 @@ 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[];
|
|
206
222
|
parseFiles: (styleEncoder?: StyleEncoder) => {
|
|
207
223
|
filesWithCss: string[];
|
|
208
224
|
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,171 @@ 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
|
+
const selectExtractable = (files, options) => {
|
|
268
|
+
const keep = /* @__PURE__ */ new Set();
|
|
269
|
+
const importers = /* @__PURE__ */ new Map();
|
|
270
|
+
for (const file of files) {
|
|
271
|
+
const text = options.readFile(file);
|
|
272
|
+
if (text === void 0) {
|
|
273
|
+
keep.add(file);
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
if (options.entrypoints.some((entrypoint) => text.includes(entrypoint))) {
|
|
277
|
+
keep.add(file);
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
const specifiers = scanSpecifiers(text);
|
|
281
|
+
if (specifiers === void 0) {
|
|
282
|
+
keep.add(file);
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
for (const specifier of specifiers) {
|
|
286
|
+
const target = localTargetOf(specifier, file, options);
|
|
287
|
+
if (!target) continue;
|
|
288
|
+
const seen = importers.get(target);
|
|
289
|
+
if (seen) seen.push(file);
|
|
290
|
+
else importers.set(target, [file]);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
let frontier = [...keep];
|
|
294
|
+
while (frontier.length) {
|
|
295
|
+
const next = [];
|
|
296
|
+
for (const target of frontier) for (const importer of importers.get(target) ?? []) {
|
|
297
|
+
if (keep.has(importer)) continue;
|
|
298
|
+
keep.add(importer);
|
|
299
|
+
next.push(importer);
|
|
300
|
+
}
|
|
301
|
+
frontier = next;
|
|
302
|
+
}
|
|
303
|
+
return files.filter((file) => keep.has(file));
|
|
304
|
+
};
|
|
305
|
+
//#endregion
|
|
141
306
|
//#region ../../node_modules/.pnpm/ansi-regex@6.2.2/node_modules/ansi-regex/index.js
|
|
142
307
|
function ansiRegex({ onlyFirst = false } = {}) {
|
|
143
308
|
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 +2463,46 @@ var BambooContext = class extends Generator {
|
|
|
2298
2463
|
* disagree about what a failure means. This one used to let the first throw out, which is
|
|
2299
2464
|
* why `cssgen` and a bundler build reported different things about the same source.
|
|
2300
2465
|
*/
|
|
2466
|
+
/**
|
|
2467
|
+
* The entrypoint specifiers, as `ImportMap` matches them.
|
|
2468
|
+
*
|
|
2469
|
+
* Every `mods` list at once rather than the `css` one alone: a file whose only bamboo import
|
|
2470
|
+
* is a recipe, a pattern or `token` originates calls just as surely, and leaving those out
|
|
2471
|
+
* would skip it.
|
|
2472
|
+
*/
|
|
2473
|
+
get entrypointSpecifiers() {
|
|
2474
|
+
return uniq(Object.values(this.imports.matchers).flatMap((matcher) => matcher.mods));
|
|
2475
|
+
}
|
|
2476
|
+
/**
|
|
2477
|
+
* The files this pass has to read, out of everything `include` matched.
|
|
2478
|
+
*
|
|
2479
|
+
* See `selectExtractable`. Kept behind a method so the reasons live in one place and a caller
|
|
2480
|
+
* that wants the whole inventory — the watcher, the token scan — is unaffected: this narrows
|
|
2481
|
+
* what is *parsed*, not what the project holds.
|
|
2482
|
+
*/
|
|
2483
|
+
extractableFiles = (files) => {
|
|
2484
|
+
const { baseUrl, paths } = this.project.resolutionOptions;
|
|
2485
|
+
const measure = logger.time.debug("Selected extractable files");
|
|
2486
|
+
const extractable = selectExtractable(files, {
|
|
2487
|
+
baseUrl,
|
|
2488
|
+
cwd: this.config.cwd,
|
|
2489
|
+
entrypoints: this.entrypointSpecifiers,
|
|
2490
|
+
paths,
|
|
2491
|
+
readFile: (filePath) => {
|
|
2492
|
+
try {
|
|
2493
|
+
return this.runtime.fs.readFileSync(filePath);
|
|
2494
|
+
} catch {
|
|
2495
|
+
return;
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
});
|
|
2499
|
+
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`);
|
|
2500
|
+
measure();
|
|
2501
|
+
return extractable;
|
|
2502
|
+
};
|
|
2301
2503
|
parseFiles = (styleEncoder) => {
|
|
2302
2504
|
const encoder = styleEncoder || this.parserOptions.encoder;
|
|
2303
|
-
const files = this.getFiles();
|
|
2505
|
+
const files = this.extractableFiles(this.getFiles());
|
|
2304
2506
|
const filesWithCss = [];
|
|
2305
2507
|
const results = [];
|
|
2306
2508
|
files.forEach((file) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bamboocss/node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.52.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.52.0",
|
|
65
|
+
"@bamboocss/core": "1.52.0",
|
|
66
|
+
"@bamboocss/generator": "1.52.0",
|
|
67
|
+
"@bamboocss/logger": "1.52.0",
|
|
68
|
+
"@bamboocss/parser": "1.52.0",
|
|
69
|
+
"@bamboocss/plugin-svelte": "1.52.0",
|
|
70
|
+
"@bamboocss/plugin-vue": "1.52.0",
|
|
71
|
+
"@bamboocss/reporter": "1.52.0",
|
|
72
|
+
"@bamboocss/shared": "1.52.0",
|
|
73
|
+
"@bamboocss/token-dictionary": "1.52.0",
|
|
74
|
+
"@bamboocss/ts-ast": "1.52.0",
|
|
75
|
+
"@bamboocss/types": "1.52.0"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@types/fs-extra": "11.0.4",
|