MCPcopy
hub / github.com/plotly/dash / gatherComponents

Function gatherComponents

dash/extract-meta.js:157–808  ·  view source on GitHub ↗
(sources, components = {})

Source from the content-addressed store, hash-verified

155}
156
157function gatherComponents(sources, components = {}) {
158 const names = [];
159 const filepaths = [];
160
161 const gather = filepath => {
162 if (ignorePattern && ignorePattern.test(filepath)) {
163 return;
164 }
165 const extension = path.extname(filepath);
166 if (['.jsx', '.js'].includes(extension)) {
167 components[cleanPath(filepath)] = parseJSX(filepath);
168 } else if (filepath.endsWith('.tsx')) {
169 try {
170 const name = /(.*)\.tsx/.exec(path.basename(filepath))[1];
171 filepaths.push(filepath);
172 names.push(name);
173 } catch (err) {
174 process.stderr.write(
175 `ERROR: Invalid component file ${filepath}: ${err}`
176 );
177 }
178 }
179 };
180
181 sources.forEach(sourcePath => {
182 if (fs.lstatSync(sourcePath).isDirectory()) {
183 fs.readdirSync(sourcePath).forEach(f => {
184 const filepath = path.join(sourcePath, f);
185 if (fs.lstatSync(filepath).isDirectory()) {
186 gatherComponents([filepath], components);
187 } else {
188 gather(filepath);
189 }
190 });
191 } else {
192 gather(sourcePath);
193 }
194 });
195
196 if (!tsEnabled) {
197 return components;
198 }
199
200 const program = ts.createProgram(filepaths, getTsConfigCompilerOptions());
201 const checker = program.getTypeChecker();
202
203 const coerceValue = t => {
204 // May need to improve for shaped/list literals.
205 if (t.isStringLiteral()) return `'${t.value}'`;
206 return t.value;
207 };
208
209 const getComponentFromExport = exp => {
210 const decl = exp.valueDeclaration || exp.declarations[0];
211 const type = checker.getTypeOfSymbolAtLocation(exp, decl);
212 const typeSymbol = type.symbol || type.aliasSymbol;
213
214 if (!typeSymbol) {

Callers 1

extract-meta.jsFile · 0.85

Calls 15

gatherFunction · 0.85
zipArraysFunction · 0.85
getComponentFromExportFunction · 0.85
getDefaultPropsFunction · 0.85
getDefaultPropsValuesFunction · 0.85
getPropInfoFunction · 0.85
docstringWarningFunction · 0.85
cleanPathFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…