Repository navigation
feat: drop component-selector markers no module selects in one-shot production builds - #1027
Merged
Merged
Conversation
…selector can read them A styled component a file keeps to itself and no selector in that file names can never be selected, so it renders without a marker, also when it is only extended or given withComponent there. Selected and exported components keep theirs: a module importing an export may select it, and per-file compilation cannot yet show that none does. The limitations page says so. Refs #690 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ives test.tsx Another test may number a file between the reset and the extraction, so the expected classes come from component_marker instead of fixed names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r-marker-when-referenced Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nent-markers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and selects by Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the reservation scan Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
formatJson counted a trailing comma after every array, so an array that ends its object and fills exactly 80 columns was split over lines while Prettier keeps it on one. main's refresh wrote such a row (devup-ui-large-turbo-wasm), and `bun run lint` rejects history.json again. The comma now counts only when one follows, and history.json is rewritten. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-shot production builds The loader reports what each module gives and selects to the build's ledger. After the transforms, a production build that is not watching compares them with the start-of-build scan: if every selecting module was scanned, markers no module selects (and no untransformed module wrote) leave the script assets; otherwise every marker stays and a warning names each module the scan missed and why. The scan also follows require.context and import.meta.glob calls whose arguments are written out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ot production builds Each transform reports what its module gives and selects; buildStart takes what the start-of-build scan selects. renderChunk of a production build that is not watching drops the markers no module selects or wrote, with a source map, or keeps every marker and warns once which modules the scan missed and why. Documents the behaviour and the cases that still keep markers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r tests rstest copies only the attributes written after the cases onto each case, so #[serial] above them left the cases running alongside each other and the other tests that reset the shared file and class maps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
29 tasks done
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… follows it formatJson counted a trailing comma after every array, so the last array of an object, exactly 80 characters wide, was split over lines that Prettier joins, and `bun run lint` failed on the recorded history. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…from its cache A warm build restores modules from webpack's persistent cache without running the loader, so their reports never reached the ledger and the build kept the markers a cold build dropped. The loader now keeps each report in the module's buildInfo, which the cache restores, and the plugin reads them back before it plans. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 4 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nto feat/cross-file-component-markers
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Refs #690. Follow-up to #1009 (merged).
The owner chose option (b): drop a component-selector marker only when the build is certain no module selects it, and never fail the build. If the build is not certain, it keeps every marker and warns, naming each module and the reason. Each reason has its own category, so the cases can be closed one at a time until the stripping can be on everywhere.
How it works
ExtractOutput.component_markerslists the markers a file gives (only those it actually emits) and the markers its selectors select, including markers of components imported from other modules (named, namespace, re-exported,withComponent). The WASM and N-APIOutputexpose these asgivenMarkersandselectedMarkers.reserveClassSlotsnow returns the markers the scanned inventory selects (reserve_class_slots_selecting). The scan is the same inventory that already seeds file numbers, so the marker names match the real transforms.ComponentMarkerLedgerin plugin-utils). Every transform records what its module gives and selects. Once every module is transformed,plan()decides:a--btokens in authored source, or in modules devup did not transform, are never touched)processAssetsatPROCESS_ASSETS_STAGE_OPTIMIZE, throughReplaceSource, so source maps stay correctrenderChunk, which returns a word-boundary source mapWarning format
Known cases and whether the inventory covers them
src/,app/, the import closure of static entries,includepackagesrequire.context('./dir', recursive, /re/)with literal argumentscontext-modulecontextImports)import.meta.glob('./**/*.tsx')/['/a/*.tsx', '!…']with literal patternscontext-modulerequire.context/import.meta.globwith computed arguments, computedimport()context-modulevirtual:,\0ids, files that don't exist)virtual-modulecompiled-sourceentryoutside-scanpages//components/not imported fromsrc/app/entriesoutside-scanscan-failed--watch/ HMRbuildInfo, which the cache restoresResidual risk: a module that selects a component, is missed by the scan, and is compiled only in a different process than the one that dropped the marker. The scan is the shared ground truth across compilations, so this needs a module that no file backs and that is generated only in that other process.
Tests
extraction_lists_the_markers_it_gives_and_selects_bymarkers_of_imported_components_are_selected_by_the_importer(named and namespace imports)reservation_returns_the_markers_the_inputs_select(wasm)unscannedCause, marker edits, the source map, the registry,contextImportsand its reservation integration. 100% coverage.#[serial]below the#[case]s incomponent_selector_markers.rs: rstest only copies the attributes written after the cases onto each case, so the test(extractor): pin that component-selector markers go only where a selector can read them #1009 tests ran concurrently with other tests that reset the shared maps, and flaked locally.formatJson/benchmark/history.jsonfix comes from fix(benchmark): fit a last array of exactly 80 columns on one line #1018 (merged in here with a merge commit), so this PR merges cleanly with or after fix(benchmark): fit a last array of exactly 80 columns on one line #1018.요약
Refs #690. #1009(머지됨)의 후속 작업입니다.
오너가 선택한 (b) 방식입니다. 어느 모듈도 선택하지 않는다고 빌드가 확신할 때만 component-selector marker를 제거하고, 빌드를 실패시키지는 않습니다. 확신하지 못하면 모든 marker를 유지하고, 원인이 된 모듈과 이유를 경고로 남깁니다. 이유는 카테고리별로 나뉘어 있어서, 경우를 하나씩 막아 가다 보면 결국 모든 빌드에서 제거를 켤 수 있습니다.
동작 방식
ExtractOutput.component_markers에 파일이 주는 marker(실제로 출력한 것만)와 selector가 선택하는 marker가 담깁니다. 다른 모듈에서 import한 컴포넌트(named, namespace, re-export,withComponent)의 marker도 포함됩니다. WASM과 N-APIOutput에서는givenMarkers,selectedMarkers로 노출됩니다.reserveClassSlots가 스캔한 인벤토리가 선택하는 marker를 반환합니다. 파일 번호를 정하는 인벤토리와 같은 것이라서 marker 이름이 실제 transform과 일치합니다.ComponentMarkerLedger). 모든 transform이 자기 모듈이 주고 선택하는 marker를 기록합니다. 모든 모듈의 transform이 끝나면plan()이 다음과 같이 결정합니다.a--b토큰은 건드리지 않습니다.PROCESS_ASSETS_STAGE_OPTIMIZE의processAssets에서ReplaceSource로 처리하므로 source map이 유지됩니다.renderChunk에서 처리하고, 단어 경계마다 매핑된 source map을 반환합니다.알려진 경우와 인벤토리 커버 여부
src/,app/, static entry의 import closure,include패키지require.context('./dir', recursive, /re/)context-moduleimport.meta.globcontext-modulerequire.context/import.meta.glob, 계산된import()context-modulevirtual:,\0, 디스크에 없는 파일)virtual-modulecompiled-sourceentryoutside-scansrc/app/entry에서 import되지 않는 루트pages//components/outside-scanscan-failed--watch/ HMRbuildInfo에 남기고, 캐시가 이를 복원남은 위험: 컴포넌트를 선택하는데 스캔이 놓친 모듈이, marker를 제거한 프로세스와 다른 프로세스에서만 컴파일되는 경우입니다. 스캔이 compilation 간에 공유되는 기준이므로, 이 경우가 생기려면 파일이 없고 그 다른 프로세스에서만 생성되는 모듈이 있어야 합니다.
테스트
component_selector_markers.rs에서#[serial]을#[case]아래로 옮겼습니다. rstest는 case 뒤에 쓴 attribute만 각 case에 복사하므로, #1009의 테스트가 공유 map을 초기화하는 다른 테스트와 동시에 실행되어 로컬에서 간헐적으로 실패했습니다.formatJson/benchmark/history.json수정은 #1018의 것을 merge commit으로 가져왔습니다. #1018과 함께 또는 그 뒤에 충돌 없이 머지됩니다.🤖 Generated with Claude Code