Skip to content
CodeMorph

Download CodeMorph

Free to download. Sign in for CodeMorph AI, or bring your own API key.

Esc
  • No results: ""

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: import statements, 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 जीतता है:

  1. Path aliases। अगर specifier tsconfig.json या jsconfig.json में compilerOptions.paths से match करता है, तो उसे baseUrl के हिसाब से दोबारा लिखा जाता है।
  2. Exact path, import करने वाली फ़ाइल के relative।
  3. Extensions, इस क्रम में आज़माए जाते हैं: .ts, .tsx, .js, .jsx, .mjs, .cjs।
  4. Index files: /index के तहत वही extensions।
  5. TypeScript-style specifiers। NodeNext नियमों में ./dep.js का import dep.ts की ओर इशारा कर सकता है, इसलिए .js भी .ts और .tsx से match करता है, .jsx .tsx से, .mjs .mts से और .cjs .cts से।

हर import को कैसे classify किया जाता है

Classificationमतलबउदाहरण
Local fileआपके प्रोजेक्ट की किसी फ़ाइल पर resolve हुआ./lib/db → src/lib/db.js
Built-inNode.js का built-in modulefs, node:path
Packagepackage.json में listed dependencyexpress, @scope/pkg/sub
AssetCode के अलावा कोई फ़ाइल./styles.css, ./data.json
UnresolvedResolve नहीं हो सका, वजह के साथकोई 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 से तैयार होता है:

  1. Strongly connected components। Tarjan's algorithm उन फ़ाइलों को एक ही component में group करता है जो cycle में एक-दूसरे को import करती हैं। एक cycle को सिर्फ़ पूरे रूप में type किया जा सकता है, इसलिए उसे कभी बाँटा नहीं जाता।
  2. Topological order। Tarjan's algorithm किसी component को तभी emit करता है जब वे सारे components आ चुके हों जिन पर वह निर्भर है। इससे leaf-first order मिलता है: बिना local imports वाली फ़ाइलें पहले, आपका entry point आख़िर में।
  3. 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 कर सकते हैं।

The migration plan in the Migrate panel: 3 files in 2 steps, leaf modules first, each step listing its files, the review mode set to Review each, and a Migrate 3 files button.
The migration plan: leaf modules first

दोबारा scan करना

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

Something unclear or out of date? Tell us.