Scan & Plan विस्तार से
CodeMorph आपका प्रोजेक्ट कैसे पढ़ता है, हर import को कैसे resolve करता है, dependency graph कैसे बनाता है और उसे leaf-first batches में कैसे बदलता है।
Scan & Plan हर माइग्रेशन की नींव है। यह आपका प्रोजेक्ट पढ़ता है, एक dependency graph बनाता है और उस graph को एक क्रमबद्ध प्लान में बदलता है। यह पूरी तरह local है, इसे किसी API key की ज़रूरत नहीं, और यह कभी कोई फ़ाइल नहीं बदलता।
इसे Morph panel में Start Migration से या Ctrl Shift M से शुरू करें।
1. फ़ाइलें ढूँढना
CodeMorph आपके workspace folder में घूमकर इन extensions वाली source फ़ाइलें इकट्ठा करता है:
.js · .jsx · .mjs · .cjs · .ts · .tsx
यह इन्हें छोड़ देता है:
- Git जो कुछ भी ignore करता है। आपके repository root से लेकर workspace folder तक की हर
.gitignoreलागू होती है, nested वाली भी, इसलिएnode_modules,distऔर दूसरा build output कभी graph में नहीं आता। - 1 MB से बड़ी फ़ाइलें। ये लगभग हमेशा generated या bundled code होती हैं। Scan को धीमा करने के बजाय इन्हें skipped के रूप में list किया जाता है।
Multi-root workspace में पहला folder scan होता है।
2. Parsing
हर फ़ाइल को tree-sitter से parse किया जाता है, जिसमें JavaScript, JSX, TypeScript और TSX के grammars इस्तेमाल होते हैं। tree-sitter तेज़ है और errors को झेल लेता है: syntax error वाली फ़ाइल भी एक इस्तेमाल लायक tree बनाती है, और scan fail करने के बजाय CodeMorph record कर लेता है कि फ़ाइल में errors हैं।
हर tree से CodeMorph ये निकालता है:
- Imports:
importstatements,import()calls औरrequire()calls, destructured requires समेत। - Exports: named और default exports,
module.exportsऔरexports.x, और re-exports जैसेexport * fromऔरexport { x } from। - Declarations: functions, classes, variables, types और interfaces, उनकी line ranges के साथ और यह कि वे exported हैं या नहीं।
3. Imports resolve करना
हर import specifier को एक target पर resolve किया जाता है, उन्हीं नियमों से जो आपका toolchain इस्तेमाल करता है। पहला match जीतता है:
- Path aliases। अगर specifier
tsconfig.jsonयाjsconfig.jsonमेंcompilerOptions.pathsसे match करता है, तो उसेbaseUrlके हिसाब से दोबारा लिखा जाता है। - Exact path, import करने वाली फ़ाइल के relative।
- Extensions, इस क्रम में आज़माए जाते हैं:
.ts,.tsx,.js,.jsx,.mjs,.cjs। - Index files:
/indexके तहत वही extensions। - TypeScript-style specifiers। NodeNext नियमों में
./dep.jsका importdep.tsकी ओर इशारा कर सकता है, इसलिए.jsभी.tsऔर.tsxसे match करता है,.jsx.tsxसे,.mjs.mtsसे और.cjs.ctsसे।
हर import को कैसे classify किया जाता है
| Classification | मतलब | उदाहरण |
|---|---|---|
| Local file | आपके प्रोजेक्ट की किसी फ़ाइल पर resolve हुआ | ./lib/db → src/lib/db.js |
| Built-in | Node.js का built-in module | fs, node:path |
| Package | package.json में listed dependency | express, @scope/pkg/sub |
| Asset | Code के अलावा कोई फ़ाइल | ./styles.css, ./data.json |
| Unresolved | Resolve नहीं हो सका, वजह के साथ | कोई missing फ़ाइल, या ऐसा package जो package.json में नहीं है |
हर import edge यह भी record करता है कि वह dynamic (import()) है, type-only (import type) है, सिर्फ़ side-effect (import "./polyfill") है या एक re-export है, और ठीक-ठीक कौन-से names वह लाता है।
4. Graph
सब कुछ एक local SQLite database में store होता है:
- Files, language, lines of code, एक content hash, और test files (
.test.,.spec.,__tests__/), entry points (package.jsonकेmainऔरmoduleसे) और syntax errors के flags के साथ। - Symbols, kind, line range और export status के साथ।
- Edges, files, packages, built-ins और assets के बीच।
- Packages,
package.jsonसे, versions के साथ। - Unresolved imports, उनकी वजहों के साथ।
Morph फ़ाइलें convert करते और सवालों के जवाब देते समय इसी graph को context के रूप में इस्तेमाल करता है।
5. Planning
प्लान file-to-file edges से तैयार होता है:
- Strongly connected components। Tarjan's algorithm उन फ़ाइलों को एक ही component में group करता है जो cycle में एक-दूसरे को import करती हैं। एक cycle को सिर्फ़ पूरे रूप में type किया जा सकता है, इसलिए उसे कभी बाँटा नहीं जाता।
- Topological order। Tarjan's algorithm किसी component को तभी emit करता है जब वे सारे components आ चुके हों जिन पर वह निर्भर है। इससे leaf-first order मिलता है: बिना local imports वाली फ़ाइलें पहले, आपका entry point आख़िर में।
- Batches। Components को लगभग दस फ़ाइलों के batches में पैक किया जाता है। Batch size रफ़्तार और review के लिए है; नीचे का order कभी नहीं बदलता।
सिर्फ़ JavaScript फ़ाइलें batches में जाती हैं। मौजूदा TypeScript फ़ाइलें पहले से typed हैं और typed total में गिनी जाती हैं।
6. प्लान पढ़ना
Plan ready. 4 batches में 38 फ़ाइलें। Leaf modules पहले, ताकि types आपके imports के ज़रिए ऊपर की ओर बहें।
| आपको दिखता है | इसका मतलब |
|---|---|
| JS files | कितनी फ़ाइलें convert होंगी |
| Batches | माइग्रेशन में कितनी review sittings लगेंगी |
| Import edges | प्रोजेक्ट कितना आपस में जुड़ा हुआ है |
| Batch names | हर batch कौन-से folders कवर करता है, जैसे lib/ · utilities या api/ + middleware/ |
यहाँ से आप Start migration या Edit plan कर सकते हैं।

दोबारा scan करना
जब भी आपका code काफ़ी बदल जाए, Scan & Plan फिर से चलाएँ, जैसे कोई बड़ी branch merge करने के बाद। Scanning तेज़ है और हमेशा disk पर मौजूद मौजूदा फ़ाइलों को दिखाती है।
Something unclear or out of date? Tell us.