@liendev/parser 0.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ast/chunker.d.ts +30 -0
- package/dist/ast/chunker.d.ts.map +1 -0
- package/dist/ast/chunker.js +310 -0
- package/dist/ast/chunker.js.map +1 -0
- package/dist/ast/complexity/cognitive.d.ts +16 -0
- package/dist/ast/complexity/cognitive.d.ts.map +1 -0
- package/dist/ast/complexity/cognitive.js +137 -0
- package/dist/ast/complexity/cognitive.js.map +1 -0
- package/dist/ast/complexity/cyclomatic.d.ts +12 -0
- package/dist/ast/complexity/cyclomatic.d.ts.map +1 -0
- package/dist/ast/complexity/cyclomatic.js +54 -0
- package/dist/ast/complexity/cyclomatic.js.map +1 -0
- package/dist/ast/complexity/halstead.d.ts +56 -0
- package/dist/ast/complexity/halstead.d.ts.map +1 -0
- package/dist/ast/complexity/halstead.js +196 -0
- package/dist/ast/complexity/halstead.js.map +1 -0
- package/dist/ast/complexity/index.d.ts +13 -0
- package/dist/ast/complexity/index.d.ts.map +1 -0
- package/dist/ast/complexity/index.js +12 -0
- package/dist/ast/complexity/index.js.map +1 -0
- package/dist/ast/extractors/index.d.ts +35 -0
- package/dist/ast/extractors/index.d.ts.map +1 -0
- package/dist/ast/extractors/index.js +41 -0
- package/dist/ast/extractors/index.js.map +1 -0
- package/dist/ast/extractors/symbol-helpers.d.ts +20 -0
- package/dist/ast/extractors/symbol-helpers.d.ts.map +1 -0
- package/dist/ast/extractors/symbol-helpers.js +58 -0
- package/dist/ast/extractors/symbol-helpers.js.map +1 -0
- package/dist/ast/extractors/types.d.ts +108 -0
- package/dist/ast/extractors/types.d.ts.map +1 -0
- package/dist/ast/extractors/types.js +2 -0
- package/dist/ast/extractors/types.js.map +1 -0
- package/dist/ast/languages/javascript.d.ts +134 -0
- package/dist/ast/languages/javascript.d.ts.map +1 -0
- package/dist/ast/languages/javascript.js +787 -0
- package/dist/ast/languages/javascript.js.map +1 -0
- package/dist/ast/languages/php.d.ts +84 -0
- package/dist/ast/languages/php.d.ts.map +1 -0
- package/dist/ast/languages/php.js +452 -0
- package/dist/ast/languages/php.js.map +1 -0
- package/dist/ast/languages/python.d.ts +96 -0
- package/dist/ast/languages/python.d.ts.map +1 -0
- package/dist/ast/languages/python.js +448 -0
- package/dist/ast/languages/python.js.map +1 -0
- package/dist/ast/languages/registry.d.ts +30 -0
- package/dist/ast/languages/registry.d.ts.map +1 -0
- package/dist/ast/languages/registry.js +95 -0
- package/dist/ast/languages/registry.js.map +1 -0
- package/dist/ast/languages/rust.d.ts +113 -0
- package/dist/ast/languages/rust.d.ts.map +1 -0
- package/dist/ast/languages/rust.js +614 -0
- package/dist/ast/languages/rust.js.map +1 -0
- package/dist/ast/languages/types.d.ts +52 -0
- package/dist/ast/languages/types.d.ts.map +1 -0
- package/dist/ast/languages/types.js +2 -0
- package/dist/ast/languages/types.js.map +1 -0
- package/dist/ast/languages/typescript.d.ts +3 -0
- package/dist/ast/languages/typescript.d.ts.map +1 -0
- package/dist/ast/languages/typescript.js +134 -0
- package/dist/ast/languages/typescript.js.map +1 -0
- package/dist/ast/parser.d.ts +29 -0
- package/dist/ast/parser.d.ts.map +1 -0
- package/dist/ast/parser.js +67 -0
- package/dist/ast/parser.js.map +1 -0
- package/dist/ast/symbols.d.ts +74 -0
- package/dist/ast/symbols.d.ts.map +1 -0
- package/dist/ast/symbols.js +171 -0
- package/dist/ast/symbols.js.map +1 -0
- package/dist/ast/traversers/index.d.ts +19 -0
- package/dist/ast/traversers/index.d.ts.map +1 -0
- package/dist/ast/traversers/index.js +21 -0
- package/dist/ast/traversers/index.js.map +1 -0
- package/dist/ast/traversers/types.d.ts +98 -0
- package/dist/ast/traversers/types.d.ts.map +1 -0
- package/dist/ast/traversers/types.js +2 -0
- package/dist/ast/traversers/types.js.map +1 -0
- package/dist/ast/types.d.ts +54 -0
- package/dist/ast/types.d.ts.map +1 -0
- package/dist/ast/types.js +2 -0
- package/dist/ast/types.js.map +1 -0
- package/dist/chunk-only-index.d.ts +25 -0
- package/dist/chunk-only-index.d.ts.map +1 -0
- package/dist/chunk-only-index.js +107 -0
- package/dist/chunk-only-index.js.map +1 -0
- package/dist/chunker.d.ts +12 -0
- package/dist/chunker.d.ts.map +1 -0
- package/dist/chunker.js +98 -0
- package/dist/chunker.js.map +1 -0
- package/dist/constants.d.ts +8 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +11 -0
- package/dist/constants.js.map +1 -0
- package/dist/content-hash.d.ts +20 -0
- package/dist/content-hash.d.ts.map +1 -0
- package/dist/content-hash.js +91 -0
- package/dist/content-hash.js.map +1 -0
- package/dist/dependency-analyzer.d.ts +79 -0
- package/dist/dependency-analyzer.d.ts.map +1 -0
- package/dist/dependency-analyzer.js +408 -0
- package/dist/dependency-analyzer.js.map +1 -0
- package/dist/ecosystem-presets.d.ts +32 -0
- package/dist/ecosystem-presets.d.ts.map +1 -0
- package/dist/ecosystem-presets.js +325 -0
- package/dist/ecosystem-presets.js.map +1 -0
- package/dist/gitignore.d.ts +22 -0
- package/dist/gitignore.d.ts.map +1 -0
- package/dist/gitignore.js +128 -0
- package/dist/gitignore.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +68 -0
- package/dist/index.js.map +1 -0
- package/dist/insights/chunk-complexity.d.ts +89 -0
- package/dist/insights/chunk-complexity.d.ts.map +1 -0
- package/dist/insights/chunk-complexity.js +332 -0
- package/dist/insights/chunk-complexity.js.map +1 -0
- package/dist/insights/types.d.ts +73 -0
- package/dist/insights/types.d.ts.map +1 -0
- package/dist/insights/types.js +9 -0
- package/dist/insights/types.js.map +1 -0
- package/dist/json-template-chunker.d.ts +12 -0
- package/dist/json-template-chunker.d.ts.map +1 -0
- package/dist/json-template-chunker.js +87 -0
- package/dist/json-template-chunker.js.map +1 -0
- package/dist/liquid-chunker.d.ts +16 -0
- package/dist/liquid-chunker.d.ts.map +1 -0
- package/dist/liquid-chunker.js +274 -0
- package/dist/liquid-chunker.js.map +1 -0
- package/dist/scanner.d.ts +16 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +95 -0
- package/dist/scanner.js.map +1 -0
- package/dist/symbol-extractor.d.ts +18 -0
- package/dist/symbol-extractor.d.ts.map +1 -0
- package/dist/symbol-extractor.js +343 -0
- package/dist/symbol-extractor.js.map +1 -0
- package/dist/test-associations.d.ts +16 -0
- package/dist/test-associations.d.ts.map +1 -0
- package/dist/test-associations.js +43 -0
- package/dist/test-associations.js.map +1 -0
- package/dist/types.d.ts +75 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/path-matching.d.ts +71 -0
- package/dist/utils/path-matching.d.ts.map +1 -0
- package/dist/utils/path-matching.js +258 -0
- package/dist/utils/path-matching.js.map +1 -0
- package/dist/utils/repo-id.d.ts +6 -0
- package/dist/utils/repo-id.d.ts.map +1 -0
- package/dist/utils/repo-id.js +12 -0
- package/dist/utils/repo-id.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liquid-chunker.d.ts","sourceRoot":"","sources":["../src/liquid-chunker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAsX5C;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,SAAS,GAAE,MAAW,EACtB,YAAY,GAAE,MAAW,EACzB,aAAa,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAClD,SAAS,EAAE,CAyBb"}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract schema name from JSON content
|
|
3
|
+
*
|
|
4
|
+
* Extracts the "name" field from Shopify schema JSON.
|
|
5
|
+
* Uses JSON.parse to properly handle escaped quotes and other JSON edge cases.
|
|
6
|
+
*
|
|
7
|
+
* Example:
|
|
8
|
+
* {% schema %}
|
|
9
|
+
* {
|
|
10
|
+
* "name": "My \"Special\" Section",
|
|
11
|
+
* "settings": []
|
|
12
|
+
* }
|
|
13
|
+
* {% endschema %}
|
|
14
|
+
*
|
|
15
|
+
* Returns: 'My "Special" Section' (with literal quotes, unescaped)
|
|
16
|
+
*/
|
|
17
|
+
function extractSchemaName(schemaContent) {
|
|
18
|
+
try {
|
|
19
|
+
// Remove Liquid tags to isolate JSON content
|
|
20
|
+
// Replace {% schema %} and {% endschema %} (with optional whitespace control)
|
|
21
|
+
const jsonContent = schemaContent
|
|
22
|
+
.replace(/\{%-?\s*schema\s*-?%\}/g, '')
|
|
23
|
+
.replace(/\{%-?\s*endschema\s*-?%\}/g, '')
|
|
24
|
+
.trim();
|
|
25
|
+
// Parse the JSON
|
|
26
|
+
const schema = JSON.parse(jsonContent);
|
|
27
|
+
// Ensure name is a string before returning
|
|
28
|
+
return typeof schema.name === 'string' ? schema.name : undefined;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// Invalid JSON - return undefined
|
|
32
|
+
// This is acceptable: schema blocks with invalid JSON won't have names extracted
|
|
33
|
+
}
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Remove Liquid comment blocks from content to avoid extracting tags from comments
|
|
38
|
+
*
|
|
39
|
+
* Example:
|
|
40
|
+
* {% comment %}Don't use {% render 'old-snippet' %}{% endcomment %}
|
|
41
|
+
* → (removed)
|
|
42
|
+
*/
|
|
43
|
+
function removeComments(content) {
|
|
44
|
+
// Remove {% comment %}...{% endcomment %} blocks (with optional whitespace control)
|
|
45
|
+
return content.replace(/\{%-?\s*comment\s*-?%\}[\s\S]*?\{%-?\s*endcomment\s*-?%\}/g, '');
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Extract dependencies from {% render %}, {% include %}, and {% section %} tags
|
|
49
|
+
*
|
|
50
|
+
* Examples:
|
|
51
|
+
* - {% render 'product-card' %} → 'product-card'
|
|
52
|
+
* - {% render "cart-item", product: product %} → 'cart-item'
|
|
53
|
+
* - {% include 'snippets/header' %} → 'snippets/header'
|
|
54
|
+
* - {% section 'announcement-bar' %} → 'announcement-bar'
|
|
55
|
+
*
|
|
56
|
+
* Limitations:
|
|
57
|
+
* - Does not handle escaped quotes in snippet names (e.g., {% render 'name\'s' %})
|
|
58
|
+
* - This is acceptable because Shopify snippet names map to filenames, and
|
|
59
|
+
* filesystem restrictions prevent quotes in filenames (snippets/name's.liquid is invalid)
|
|
60
|
+
* - In practice, Shopify snippet names use only alphanumeric, dash, and underscore
|
|
61
|
+
*
|
|
62
|
+
* Note: Expects content with comments already removed for performance
|
|
63
|
+
*
|
|
64
|
+
* @param contentWithoutComments - Content with Liquid comments already removed
|
|
65
|
+
*/
|
|
66
|
+
function extractRenderTags(contentWithoutComments) {
|
|
67
|
+
const dependencies = new Set();
|
|
68
|
+
// Match {% render 'snippet-name' %} or {% render "snippet-name" %}
|
|
69
|
+
// Note: Does not handle escaped quotes - see function docs for rationale
|
|
70
|
+
const renderPattern = /\{%-?\s*render\s+['"]([^'"]+)['"]/g;
|
|
71
|
+
let match;
|
|
72
|
+
while ((match = renderPattern.exec(contentWithoutComments)) !== null) {
|
|
73
|
+
dependencies.add(match[1]);
|
|
74
|
+
}
|
|
75
|
+
// Match {% include 'snippet-name' %} or {% include "snippet-name" %}
|
|
76
|
+
const includePattern = /\{%-?\s*include\s+['"]([^'"]+)['"]/g;
|
|
77
|
+
while ((match = includePattern.exec(contentWithoutComments)) !== null) {
|
|
78
|
+
dependencies.add(match[1]);
|
|
79
|
+
}
|
|
80
|
+
// Match {% section 'section-name' %} or {% section "section-name" %}
|
|
81
|
+
const sectionPattern = /\{%-?\s*section\s+['"]([^'"]+)['"]/g;
|
|
82
|
+
while ((match = sectionPattern.exec(contentWithoutComments)) !== null) {
|
|
83
|
+
dependencies.add(match[1]);
|
|
84
|
+
}
|
|
85
|
+
return Array.from(dependencies);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Find all special Liquid blocks in the template
|
|
89
|
+
*
|
|
90
|
+
* Limitation: Does not support nested blocks of the same type.
|
|
91
|
+
* - Matches first start tag with first end tag
|
|
92
|
+
* - This is acceptable because Shopify Liquid does not allow nested blocks
|
|
93
|
+
* - Example invalid: {% schema %}...{% schema %}...{% endschema %} (Shopify rejects this)
|
|
94
|
+
* - If malformed input contains nested blocks, only outermost block is extracted
|
|
95
|
+
*/
|
|
96
|
+
function findLiquidBlocks(content) {
|
|
97
|
+
const lines = content.split('\n');
|
|
98
|
+
const blocks = [];
|
|
99
|
+
// Regex patterns for Liquid blocks
|
|
100
|
+
// Note: Matches first start → first end (no nesting support, which is correct for Shopify)
|
|
101
|
+
const blockPatterns = [
|
|
102
|
+
{ type: 'schema', start: /\{%-?\s*schema\s*-?%\}/, end: /\{%-?\s*endschema\s*-?%\}/ },
|
|
103
|
+
{ type: 'style', start: /\{%-?\s*style\s*-?%\}/, end: /\{%-?\s*endstyle\s*-?%\}/ },
|
|
104
|
+
{
|
|
105
|
+
type: 'javascript',
|
|
106
|
+
start: /\{%-?\s*javascript\s*-?%\}/,
|
|
107
|
+
end: /\{%-?\s*endjavascript\s*-?%\}/,
|
|
108
|
+
},
|
|
109
|
+
];
|
|
110
|
+
for (const pattern of blockPatterns) {
|
|
111
|
+
let searchStart = 0;
|
|
112
|
+
while (searchStart < lines.length) {
|
|
113
|
+
// Find start tag
|
|
114
|
+
const startIdx = lines.findIndex((line, idx) => idx >= searchStart && pattern.start.test(line));
|
|
115
|
+
if (startIdx === -1)
|
|
116
|
+
break;
|
|
117
|
+
// Find end tag (allow same line for single-line blocks)
|
|
118
|
+
const endIdx = lines.findIndex((line, idx) => idx >= startIdx && pattern.end.test(line));
|
|
119
|
+
if (endIdx === -1) {
|
|
120
|
+
// No end tag found, treat rest as template
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
// Extract block content
|
|
124
|
+
const blockContent = lines.slice(startIdx, endIdx + 1).join('\n');
|
|
125
|
+
blocks.push({
|
|
126
|
+
type: pattern.type,
|
|
127
|
+
startLine: startIdx,
|
|
128
|
+
endLine: endIdx,
|
|
129
|
+
content: blockContent,
|
|
130
|
+
});
|
|
131
|
+
searchStart = endIdx + 1;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return blocks.sort((a, b) => a.startLine - b.startLine);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Create a CodeChunk with consistent structure
|
|
138
|
+
*/
|
|
139
|
+
function createCodeChunk(content, startLine, endLine, filepath, type, options = {}) {
|
|
140
|
+
return {
|
|
141
|
+
content,
|
|
142
|
+
metadata: {
|
|
143
|
+
file: filepath,
|
|
144
|
+
startLine,
|
|
145
|
+
endLine,
|
|
146
|
+
language: 'liquid',
|
|
147
|
+
type,
|
|
148
|
+
symbolName: options.symbolName,
|
|
149
|
+
symbolType: options.symbolType,
|
|
150
|
+
imports: options.imports?.length ? options.imports : undefined,
|
|
151
|
+
...(options.repoId && { repoId: options.repoId }),
|
|
152
|
+
...(options.orgId && { orgId: options.orgId }),
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Split a large block into multiple chunks with overlap
|
|
158
|
+
*/
|
|
159
|
+
function splitLargeBlock(block, ctx, symbolName, imports, tenantContext) {
|
|
160
|
+
const chunks = [];
|
|
161
|
+
const blockLines = block.content.split('\n');
|
|
162
|
+
const { chunkSize, chunkOverlap, filepath } = ctx.params;
|
|
163
|
+
for (let offset = 0; offset < blockLines.length; offset += chunkSize - chunkOverlap) {
|
|
164
|
+
const endOffset = Math.min(offset + chunkSize, blockLines.length);
|
|
165
|
+
const chunkContent = blockLines.slice(offset, endOffset).join('\n');
|
|
166
|
+
if (chunkContent.trim().length > 0) {
|
|
167
|
+
chunks.push(createCodeChunk(chunkContent, block.startLine + offset + 1, block.startLine + endOffset, filepath, 'block', { symbolName, symbolType: block.type, imports, ...tenantContext }));
|
|
168
|
+
}
|
|
169
|
+
if (endOffset >= blockLines.length)
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
return chunks;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Create chunks from a special Liquid block (schema, style, javascript)
|
|
176
|
+
* Returns the chunks and marks covered lines
|
|
177
|
+
*/
|
|
178
|
+
function processSpecialBlock(block, ctx, coveredLines, tenantContext) {
|
|
179
|
+
// Mark lines as covered
|
|
180
|
+
for (let i = block.startLine; i <= block.endLine; i++) {
|
|
181
|
+
coveredLines.add(i);
|
|
182
|
+
}
|
|
183
|
+
// Extract metadata
|
|
184
|
+
const symbolName = block.type === 'schema' ? extractSchemaName(block.content) : undefined;
|
|
185
|
+
// Extract imports from cleaned content
|
|
186
|
+
const blockContentWithoutComments = ctx.linesWithoutComments
|
|
187
|
+
.slice(block.startLine, block.endLine + 1)
|
|
188
|
+
.join('\n');
|
|
189
|
+
const imports = extractRenderTags(blockContentWithoutComments);
|
|
190
|
+
const blockLineCount = block.endLine - block.startLine + 1;
|
|
191
|
+
const maxBlockSize = ctx.params.chunkSize * 3;
|
|
192
|
+
// Keep small blocks as single chunk, split large ones
|
|
193
|
+
if (blockLineCount <= maxBlockSize) {
|
|
194
|
+
return [
|
|
195
|
+
createCodeChunk(block.content, block.startLine + 1, block.endLine + 1, ctx.params.filepath, 'block', { symbolName, symbolType: block.type, imports, ...tenantContext }),
|
|
196
|
+
];
|
|
197
|
+
}
|
|
198
|
+
return splitLargeBlock(block, ctx, symbolName, imports, tenantContext);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Create a template chunk from accumulated lines
|
|
202
|
+
*/
|
|
203
|
+
function flushTemplateChunk(currentChunk, chunkStartLine, endLine, ctx, tenantContext) {
|
|
204
|
+
if (currentChunk.length === 0)
|
|
205
|
+
return null;
|
|
206
|
+
const chunkContent = currentChunk.join('\n');
|
|
207
|
+
if (chunkContent.trim().length === 0)
|
|
208
|
+
return null;
|
|
209
|
+
const cleanedChunk = ctx.linesWithoutComments.slice(chunkStartLine, endLine).join('\n');
|
|
210
|
+
const imports = extractRenderTags(cleanedChunk);
|
|
211
|
+
return createCodeChunk(chunkContent, chunkStartLine + 1, endLine, ctx.params.filepath, 'template', { imports, ...tenantContext });
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Process uncovered template content into chunks
|
|
215
|
+
*/
|
|
216
|
+
function processTemplateContent(ctx, coveredLines, tenantContext) {
|
|
217
|
+
const chunks = [];
|
|
218
|
+
const { lines, params } = ctx;
|
|
219
|
+
const { chunkSize, chunkOverlap } = params;
|
|
220
|
+
let currentChunk = [];
|
|
221
|
+
let chunkStartLine = 0;
|
|
222
|
+
const flush = (endLine) => {
|
|
223
|
+
const chunk = flushTemplateChunk(currentChunk, chunkStartLine, endLine, ctx, tenantContext);
|
|
224
|
+
if (chunk)
|
|
225
|
+
chunks.push(chunk);
|
|
226
|
+
};
|
|
227
|
+
for (let i = 0; i < lines.length; i++) {
|
|
228
|
+
if (coveredLines.has(i)) {
|
|
229
|
+
flush(i);
|
|
230
|
+
currentChunk = [];
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
if (currentChunk.length === 0) {
|
|
234
|
+
chunkStartLine = i;
|
|
235
|
+
}
|
|
236
|
+
currentChunk.push(lines[i]);
|
|
237
|
+
if (currentChunk.length >= chunkSize) {
|
|
238
|
+
flush(i + 1);
|
|
239
|
+
currentChunk = currentChunk.slice(-chunkOverlap);
|
|
240
|
+
chunkStartLine = Math.max(0, i + 1 - chunkOverlap);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
flush(lines.length);
|
|
244
|
+
return chunks;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Chunk a Liquid template file
|
|
248
|
+
*
|
|
249
|
+
* Special handling for:
|
|
250
|
+
* - {% schema %} blocks (kept together, extract section name)
|
|
251
|
+
* - {% style %} blocks (kept together)
|
|
252
|
+
* - {% javascript %} blocks (kept together)
|
|
253
|
+
* - {% render %}, {% include %}, and {% section %} tags (tracked as imports)
|
|
254
|
+
* - Regular template content (chunked by lines)
|
|
255
|
+
*/
|
|
256
|
+
export function chunkLiquidFile(filepath, content, chunkSize = 75, chunkOverlap = 10, tenantContext) {
|
|
257
|
+
// Build context once for reuse across helpers
|
|
258
|
+
const contentWithoutComments = removeComments(content);
|
|
259
|
+
const ctx = {
|
|
260
|
+
lines: content.split('\n'),
|
|
261
|
+
linesWithoutComments: contentWithoutComments.split('\n'),
|
|
262
|
+
params: { filepath, chunkSize, chunkOverlap },
|
|
263
|
+
};
|
|
264
|
+
// Find special blocks and track covered lines
|
|
265
|
+
const blocks = findLiquidBlocks(content);
|
|
266
|
+
const coveredLines = new Set();
|
|
267
|
+
// Process special blocks
|
|
268
|
+
const blockChunks = blocks.flatMap(block => processSpecialBlock(block, ctx, coveredLines, tenantContext));
|
|
269
|
+
// Process uncovered template content
|
|
270
|
+
const templateChunks = processTemplateContent(ctx, coveredLines, tenantContext);
|
|
271
|
+
// Combine and sort by line number
|
|
272
|
+
return [...blockChunks, ...templateChunks].sort((a, b) => a.metadata.startLine - b.metadata.startLine);
|
|
273
|
+
}
|
|
274
|
+
//# sourceMappingURL=liquid-chunker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liquid-chunker.js","sourceRoot":"","sources":["../src/liquid-chunker.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;GAeG;AACH,SAAS,iBAAiB,CAAC,aAAqB;IAC9C,IAAI,CAAC;QACH,6CAA6C;QAC7C,8EAA8E;QAC9E,MAAM,WAAW,GAAG,aAAa;aAC9B,OAAO,CAAC,yBAAyB,EAAE,EAAE,CAAC;aACtC,OAAO,CAAC,4BAA4B,EAAE,EAAE,CAAC;aACzC,IAAI,EAAE,CAAC;Q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E,CACzC,mBAAmB,CAAC,KAAK,EAAE,GAAG,EAAE,YAAY,EAAE,aAAa,CAAC,CAC7D,CAAC;IAEF,qCAAqC;IACrC,MAAM,cAAc,GAAG,sBAAsB,CAAC,GAAG,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC;IAEhF,kCAAkC;IAClC,OAAO,CAAC,GAAG,WAAW,EAAE,GAAG,cAAc,CAAC,CAAC,IAAI,CAC7C,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,GAAG,CAAC,CAAC,QAAQ,CAAC,SAAS,CACtD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ScanOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Scan codebase for files matching include/exclude patterns.
|
|
4
|
+
*/
|
|
5
|
+
export declare function scanCodebase(options: ScanOptions): Promise<string[]>;
|
|
6
|
+
/**
|
|
7
|
+
* Detect broad file type from extension (includes non-AST languages like Go, Rust, Markdown, etc.).
|
|
8
|
+
* For AST-supported language detection, use the AST parser's detectLanguage instead.
|
|
9
|
+
*/
|
|
10
|
+
export declare function detectFileType(filepath: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Use detectFileType instead. This alias exists for backwards
|
|
13
|
+
* compatibility with deep imports.
|
|
14
|
+
*/
|
|
15
|
+
export declare const detectLanguage: typeof detectFileType;
|
|
16
|
+
//# sourceMappingURL=scanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAkB9C;;GAEG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAoC1E;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAkCvD;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,uBAAiB,CAAC"}
|
package/dist/scanner.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { glob } from 'glob';
|
|
2
|
+
import ignore from 'ignore';
|
|
3
|
+
import fs from 'fs/promises';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { ALWAYS_IGNORE_PATTERNS } from './gitignore.js';
|
|
6
|
+
/**
|
|
7
|
+
* Load .gitignore from the given paths (first match wins) and return an ignore instance.
|
|
8
|
+
*/
|
|
9
|
+
async function loadGitignore(...dirs) {
|
|
10
|
+
for (const dir of dirs) {
|
|
11
|
+
try {
|
|
12
|
+
const content = await fs.readFile(path.join(dir, '.gitignore'), 'utf-8');
|
|
13
|
+
return ignore().add(content);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
// Try next path
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return ignore();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Scan codebase for files matching include/exclude patterns.
|
|
23
|
+
*/
|
|
24
|
+
export async function scanCodebase(options) {
|
|
25
|
+
const { rootDir, includePatterns = [], excludePatterns = [] } = options;
|
|
26
|
+
const ig = await loadGitignore(rootDir);
|
|
27
|
+
ig.add([...ALWAYS_IGNORE_PATTERNS, ...excludePatterns]);
|
|
28
|
+
// Determine patterns to search for
|
|
29
|
+
const patterns = includePatterns.length > 0
|
|
30
|
+
? includePatterns
|
|
31
|
+
: ['**/*.{ts,tsx,js,jsx,py,php,go,rs,java,cpp,c,cs,h,md,mdx}'];
|
|
32
|
+
// Combine always-ignored patterns with exclude patterns for glob
|
|
33
|
+
const globIgnorePatterns = [...ALWAYS_IGNORE_PATTERNS, ...excludePatterns];
|
|
34
|
+
// Find all code files
|
|
35
|
+
const allFiles = [];
|
|
36
|
+
for (const pattern of patterns) {
|
|
37
|
+
const files = await glob(pattern, {
|
|
38
|
+
cwd: rootDir,
|
|
39
|
+
absolute: true,
|
|
40
|
+
nodir: true,
|
|
41
|
+
ignore: globIgnorePatterns,
|
|
42
|
+
});
|
|
43
|
+
allFiles.push(...files);
|
|
44
|
+
}
|
|
45
|
+
// Remove duplicates
|
|
46
|
+
const uniqueFiles = Array.from(new Set(allFiles));
|
|
47
|
+
// Filter using ignore patterns
|
|
48
|
+
return uniqueFiles.filter(file => {
|
|
49
|
+
const relativePath = path.relative(rootDir, file);
|
|
50
|
+
return !ig.ignores(relativePath);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Detect broad file type from extension (includes non-AST languages like Go, Rust, Markdown, etc.).
|
|
55
|
+
* For AST-supported language detection, use the AST parser's detectLanguage instead.
|
|
56
|
+
*/
|
|
57
|
+
export function detectFileType(filepath) {
|
|
58
|
+
const ext = path.extname(filepath).toLowerCase();
|
|
59
|
+
const languageMap = {
|
|
60
|
+
'.ts': 'typescript',
|
|
61
|
+
'.tsx': 'typescript',
|
|
62
|
+
'.js': 'javascript',
|
|
63
|
+
'.jsx': 'javascript',
|
|
64
|
+
'.mjs': 'javascript',
|
|
65
|
+
'.cjs': 'javascript',
|
|
66
|
+
'.vue': 'vue',
|
|
67
|
+
'.py': 'python',
|
|
68
|
+
'.go': 'go',
|
|
69
|
+
'.rs': 'rust',
|
|
70
|
+
'.java': 'java',
|
|
71
|
+
'.cpp': 'cpp',
|
|
72
|
+
'.cc': 'cpp',
|
|
73
|
+
'.cxx': 'cpp',
|
|
74
|
+
'.c': 'c',
|
|
75
|
+
'.h': 'c',
|
|
76
|
+
'.hpp': 'cpp',
|
|
77
|
+
'.php': 'php',
|
|
78
|
+
'.rb': 'ruby',
|
|
79
|
+
'.swift': 'swift',
|
|
80
|
+
'.kt': 'kotlin',
|
|
81
|
+
'.cs': 'csharp',
|
|
82
|
+
'.scala': 'scala',
|
|
83
|
+
'.liquid': 'liquid',
|
|
84
|
+
'.md': 'markdown',
|
|
85
|
+
'.mdx': 'markdown',
|
|
86
|
+
'.markdown': 'markdown',
|
|
87
|
+
};
|
|
88
|
+
return languageMap[ext] || 'unknown';
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* @deprecated Use detectFileType instead. This alias exists for backwards
|
|
92
|
+
* compatibility with deep imports.
|
|
93
|
+
*/
|
|
94
|
+
export const detectLanguage = detectFileType;
|
|
95
|
+
//# sourceMappingURL=scanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAExD;;GAEG;AACH,KAAK,UAAU,aAAa,CAAC,GAAG,IAAc;IAC5C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,YAAY,CAAC,EAAE,OAAO,CAAC,CAAC;YACzE,OAAO,MAAM,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACP,gBAAgB;QAClB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,EAAE,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAAoB;IACrD,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,EAAE,EAAE,eAAe,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;IAExE,MAAM,EAAE,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,CAAC;IACxC,EAAE,CAAC,GAAG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AM,EAAE,YAAY;QACpB,MAAM,EAAE,YAAY;QACpB,MAAM,EAAE,YAAY;QACpB,MAAM,EAAE,KAAK;QACb,KAAK,EAAE,QAAQ;QACf,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,MAAM;QACb,OAAO,EAAE,MAAM;QACf,MAAM,EAAE,KAAK;QACb,KAAK,EAAE,KAAK;QACZ,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,GAAG;QACT,IAAI,EAAE,GAAG;QACT,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,KAAK;QACb,KAAK,EAAE,MAAM;QACb,QAAQ,EAAE,OAAO;QACjB,KAAK,EAAE,QAAQ;QACf,KAAK,EAAE,QAAQ;QACf,QAAQ,EAAE,OAAO;QACjB,SAAS,EAAE,QAAQ;QACnB,KAAK,EAAE,UAAU;QACjB,MAAM,EAAE,UAAU;QAClB,WAAW,EAAE,UAAU;KACxB,CAAC;IAEF,OAAO,WAAW,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC;AACvC,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,cAAc,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbol extraction utilities for different programming languages.
|
|
3
|
+
* Extracts function, class, and interface names from code chunks for better indexing.
|
|
4
|
+
*/
|
|
5
|
+
export interface ExtractedSymbols {
|
|
6
|
+
functions: string[];
|
|
7
|
+
classes: string[];
|
|
8
|
+
interfaces: string[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Extract symbols (functions, classes, interfaces) from code content.
|
|
12
|
+
*
|
|
13
|
+
* @param content - The code content to extract symbols from
|
|
14
|
+
* @param language - The programming language of the content
|
|
15
|
+
* @returns Extracted symbols organized by type
|
|
16
|
+
*/
|
|
17
|
+
export declare function extractSymbols(content: string, language: string): ExtractedSymbols;
|
|
18
|
+
//# sourceMappingURL=symbol-extractor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"symbol-extractor.d.ts","sourceRoot":"","sources":["../src/symbol-extractor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAmDD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,gBAAgB,CAUlF"}
|