Deduplicate ANSI subsystem shared logic into ansi-shared package
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Refactoring
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- typescript
- Ambito
- build-system, tooling
Direzione di ricerca
Start by comparing the paired files in packages/lua-runtime/src/ and lua-learning-website/src/components/AnsiGraphicsEditor/, then inspect packages/ansi-shared/src/index.ts and the existing package build configuration. Extract the listed types, rendering, compositing, and cell utilities, rewire both consumers, remove the ANSI exclusions from .jscpd.json, and run the existing tests plus npm run duplicates.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Problem
The ANSI subsystem has intentionally duplicated code between packages/lua-runtime/src/ (runtime) and lua-learning-website/src/components/AnsiGraphicsEditor/ (editor). This duplication is currently suppressed in jscpd via ignore patterns, but the shared logic can be extracted into the existing packages/ansi-shared/ package — eliminating drift risk and removing the need for jscpd exclusions.
Pairs with Extractable Shared Logic
1. Core Types (~60% overlap)
- Runtime:
packages/lua-runtime/src/screenTypes.ts - Editor:
lua-learning-website/src/components/AnsiGraphicsEditor/types.ts - Shared:
RGBColor,AnsiCell,AnsiGrid,Rect,TextAlign,ANSI_COLS,ANSI_ROWS,DEFAULT_FG,DEFAULT_BG,DEFAULT_CELL,TRANSPARENT_HALF,TRANSPARENT_BG,HALF_BLOCK,isGroupLayer(),isDrawableLayer() - Stays separate: Editor-only types (
BrushMode,ScaleMode,DrawTool,BorderStyle,LayerState, richerLayerhierarchy). Runtime-only simplifiedLayerDatatypes.
2. Text Layer Rendering (~85% identical)
- Runtime:
packages/lua-runtime/src/textLayerGrid.ts - Editor:
lua-learning-website/src/components/AnsiGraphicsEditor/textLayerGrid.ts - Shared:
wrapText(),buildRawIndexMap(),justifyLine(),renderTextLayerGrid()— identical implementations - Stays separate: Editor-only
cursorPosToVisual()function
3. Compositing Core (4 identical functions)
- Runtime:
packages/lua-runtime/src/screenCompositor.ts - Editor:
lua-learning-website/src/components/AnsiGraphicsEditor/layerUtils.ts - Shared:
hiddenGroupIds(),visibleDrawableLayers(),compositeCellCore(),compositeGrid() - Stays separate: 47 editor-only functions (layer manipulation, creation, cloning, display ordering). Requires abstract layer interface to bridge
LayerData(runtime) andLayer(editor) types.
4. Cell Comparison Utility
- Runtime:
packages/lua-runtime/src/ansiStringRenderer.ts→cellsEqual() - Editor:
lua-learning-website/src/components/AnsiGraphicsEditor/terminalBuffer.ts→cellsEqual() - Shared: Identical
cellsEqual()function - Note: The rest of these two files are fundamentally different (stateless ANSI string generation vs. stateful double buffer) and should NOT be merged.
NOT in Scope
serialization.ts— editor-only, no runtime counterpart (not actually duplicated)packages/export/src/runtime/**— architecturally different execution model (single-threaded direct draw vs. multi-threaded command queue), cannot be deduplicatedterminalBuffer.ts/ansiStringRenderer.tsbeyondcellsEqual()— fundamentally different abstractions
Implementation Approach
The packages/ansi-shared/ package already exists (currently contains only playbackEngine.ts). New shared modules:
ansi-shared/src/screenTypes.ts— Core types + constantsansi-shared/src/textRendering.ts— Text wrapping and grid renderingansi-shared/src/compositing.ts— Layer compositing with abstract interfacesansi-shared/src/cellUtils.ts—cellsEqual()utility- Update
ansi-shared/src/index.ts— Export all new modules
Both lua-runtime and the editor import from @lua-learning/ansi-shared instead of maintaining their own copies. The compositing module will need abstract interfaces (e.g., HasVisibility & HasId) that both LayerData and Layer satisfy.
Acceptance Criteria
- Shared types, text rendering, compositing, and
cellsEquallive inansi-shared -
packages/lua-runtime/src/imports shared code from@lua-learning/ansi-shared -
lua-learning-website/src/components/AnsiGraphicsEditor/imports shared code from@lua-learning/ansi-shared - No copy-pasted logic remains between the paired files (only side-specific extensions)
- jscpd ANSI exclusions removed from
.jscpd.json(no longer needed) - All existing tests pass
-
npm run duplicatesshows reduced clone count with no new ANSI cross-package hits - Build order respected:
ansi-sharedbuilds beforelua-runtimeandlua-learning-website
Complexity
Medium (~6-8 tasks). Mostly mechanical extraction + import rewiring, but the compositing abstract interface requires care.
- Lingua principale
- TypeScript
- Stelle
- 1
- Fork
- 0
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di jcollard/LuaInTheWeb
-
tech-debt
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
jcollard/LuaInTheWeb#752 ·
-
tech-debt
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
jcollard/LuaInTheWeb#690 ·
-
tech-debt
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
jcollard/LuaInTheWeb#590 ·
-
tech-debt
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
jcollard/LuaInTheWeb#518 ·
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
jcollard/LuaInTheWeb#235 ·
Tutte le issue di jcollard/LuaInTheWeb
Issue simili
-
priority:high
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
immich-app/immich#32426 ·
I maintainer di solito rispondono entro 1 giorno
-
documentation good first issue hacktoberfest help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
libredb/libredb-studio#1756 ·
I maintainer di solito rispondono entro 1 giorno
-
state:triage-needed
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno