Repository navigation
css: emit @layer statements that precede @import before the imported files #41572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
2ea3972
css: emit @layer statements that precede @import before the imported …
robobun f00b578
Merge remote-tracking branch 'origin/main' into robobun/b6517831/css-…
robobun d6fd4ac
css: scan the rule prefix once and shorten the comments
robobun b535d7d
ci: retrigger
robobun 7190a15
Merge remote-tracking branch 'origin/main' into robobun/b6517831/css-…
robobun 7f376f8
css: keep a layer list that prints as a block behind the hoisted exte…
robobun cd727fc
test: keep the layer tests clear of the external-import cases
robobun b7db12f
css: only a file with an @import gets the early layer entry, and its …
robobun e8af3c6
css: port esbuild's layer merging test, and mark where the hoist depa…
robobun 1290f3d
css: do not strip inside an anonymous layer, and shorten comments
robobun 2dc63d9
css: keep a layer list that another layer wraps, declare the layer of…
robobun e38e9fe
Merge remote-tracking branch 'origin/main' into robobun/b6517831/css-…
robobun c636745
test: a differential check of the cascade layers in bundled CSS
robobun b8d4a24
css: keep empty named @layer blocks as @layer statements
robobun ecbb1b5
test: pin random import graphs for the layer order, and the empty blo…
robobun 5f26697
Merge remote-tracking branch 'origin/main' into robobun/b6517831/css-…
robobun d94ae00
css: shorten three comments
robobun da54e71
Merge remote-tracking branch 'origin/main' into robobun/b6517831/css-…
robobun 21b1a6b
Revert "css: keep empty named @layer blocks as @layer statements"
robobun 773b826
css: change nothing for a bundle with no @layer statement ahead of an…
robobun db16556
test: expectations for the layer check that is on only with a pre-imp…
robobun b3bb517
css: the hoist predicate keeps only what this change needs
robobun f6d6172
[autofix.ci] apply automated fixes
autofix-ci[bot] 477ec6e
css: with a pre-import entry, declare the layer of a cyclic import an…
robobun d344bcd
css: a file keeps every copy only when a layer is first declared unde…
robobun 93c82f7
css: narrow the changes that depend on a pre-import entry
robobun f9da5ec
css: shorten two comments and restore one comment of main
robobun 1bae41a
css test: add the two-entry input that waits for #46357 as a todo case
robobun 438aa2d
Merge remote-tracking branch 'origin/main' into robobun/b6517831/css-…
robobun e2a9317
css: keep the copy of a CSS module with composes under a layer, and f…
robobun 8cf330a
css: name Layers::PreImport in the SAFETY comment of Chunk
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| // bun scripts/css-layer-fuzz.ts <bun> <graphs> [first seed] [baseline bun] | ||
| // [--cycles] [--anonymous] [--no-leading-statements] [--empty-blocks] | ||
| // Runs test/bundler/css-layer-order.ts over many seeds against <bun> and prints the seeds where the bundle does not | ||
| // have the cascade layers of its sources. `<graphs>` = 1 prints the files of that seed too. With a baseline binary it | ||
| // also prints the seeds the baseline gets right and <bun> gets wrong, and how many are the other way round. It does | ||
| // that twice: for the whole check, and for the rule that `.t` gets alone, which is what a page shows. | ||
| import { resolve } from "node:path"; | ||
| import { | ||
| checkGraph, | ||
| generateGraph, | ||
| isWinnerProblem, | ||
| type GraphOptions, | ||
| type GraphResult, | ||
| } from "../test/bundler/css-layer-order"; | ||
|
|
||
| const known = ["--cycles", "--anonymous", "--no-leading-statements", "--empty-blocks"]; | ||
| const flags = process.argv.slice(2).filter(arg => arg.startsWith("--")); | ||
| const [bun, count = "100", first = "1", baseline] = process.argv.slice(2).filter(arg => !arg.startsWith("--")); | ||
| if (!bun || flags.some(flag => !known.includes(flag))) { | ||
| console.error( | ||
| `usage: bun scripts/css-layer-fuzz.ts <bun> <graphs> [first seed] [baseline bun] [${known.join("] [")}]`, | ||
| ); | ||
| process.exit(1); | ||
| } | ||
| const options: GraphOptions = { | ||
| cycles: flags.includes("--cycles"), | ||
| anonymous: flags.includes("--anonymous"), | ||
| leadingStatements: !flags.includes("--no-leading-statements"), | ||
| emptyBlocks: flags.includes("--empty-blocks"), | ||
| }; | ||
| const locate = (binary: string) => Bun.which(binary) ?? resolve(binary); | ||
| const [target, before] = [locate(bun), baseline && locate(baseline)]; | ||
| if (Number(count) === 1) { | ||
| for (const [name, css] of Object.entries(generateGraph(Number(first), options).files)) | ||
| console.log(`/* ${name} */\n${css}`); | ||
| } | ||
| const tally = { ok: 0, wrong: 0, skipped: 0, wrongWinner: 0 }; | ||
| const wrongWinner = (result: GraphResult) => result.status === "wrong" && result.problems.some(isWinnerProblem); | ||
| const regressed = { whole: [] as number[], winner: [] as number[] }; | ||
| const repaired = { whole: 0, winner: 0 }; | ||
| const parallel = 8; | ||
| const end = Number(first) + Number(count); | ||
| for (let seed = Number(first); seed < end; seed += parallel) { | ||
| const batch: Promise<[GraphResult, GraphResult | undefined]>[] = []; | ||
| for (let s = seed; s < Math.min(end, seed + parallel); s++) { | ||
| batch.push(Promise.all([checkGraph(target, s, options), before ? checkGraph(before, s, options) : undefined])); | ||
| } | ||
| for (const [result, old] of await Promise.all(batch)) { | ||
| tally[result.status]++; | ||
| if (wrongWinner(result)) tally.wrongWinner++; | ||
| if (result.status !== "ok") | ||
| console.log(`seed ${result.seed} ${result.status}:\n ` + result.problems.slice(0, 6).join("\n ")); | ||
| if (!old || old.status === "skipped" || result.status === "skipped") continue; | ||
| if (old.status === "ok" && result.status === "wrong") regressed.whole.push(result.seed); | ||
| if (old.status === "wrong" && result.status === "ok") repaired.whole++; | ||
| if (!wrongWinner(old) && wrongWinner(result)) regressed.winner.push(result.seed); | ||
| if (wrongWinner(old) && !wrongWinner(result)) repaired.winner++; | ||
| } | ||
| } | ||
| if (before) { | ||
| const seeds = (list: number[]) => `${list.length} graphs` + (list.length ? ` (seeds ${list.join(", ")})` : ""); | ||
| console.log(`right with the baseline, wrong with <bun>: ${seeds(regressed.whole)}`); | ||
| console.log(`wrong with the baseline, right with <bun>: ${repaired.whole} graphs`); | ||
| console.log(`.t gets the right rule with the baseline and another with <bun>: ${seeds(regressed.winner)}`); | ||
| console.log(`.t gets another rule with the baseline and the right one with <bun>: ${repaired.winner} graphs`); | ||
| } | ||
| console.log(JSON.stringify({ graphs: Number(count), firstSeed: Number(first), ...tally })); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.