MCPcopy Create free account
hub / github.com/adobe/react-spectrum / analyzeDeps

Function analyzeDeps

scripts/buildRegistry.mjs:178–227  ·  view source on GitHub ↗
(file, type)

Source from the content-addressed store, hash-verified

176);
177
178function analyzeDeps(file, type) {
179 let content = fs.readFileSync(file, 'utf8');
180 let ast = recast.parse(content, {
181 parser: {
182 parse() {
183 return parse(content, {
184 sourceType: 'module',
185 plugins: ['typescript', 'jsx', 'importAttributes'],
186 sourceFilename: file,
187 tokens: true,
188 errorRecovery: true
189 });
190 }
191 }
192 });
193
194 let dependencies = new Set();
195 let registryDependencies = new Set();
196 let cssImports = new Set();
197 for (let node of ast.program.body) {
198 if (node.type === 'ImportDeclaration') {
199 let source = node.source.value;
200 if (source.startsWith('./')) {
201 if (source.endsWith('.css')) {
202 cssImports.add(path.resolve(path.dirname(file), source));
203 } else {
204 registryDependencies.add(
205 publicUrl + '/' + type + '-' + source.slice(2).toLowerCase() + '.json'
206 );
207 node.source.value =
208 source === './utils'
209 ? '@/registry/react-aria/lib/react-aria-utils'
210 : '@/registry/react-aria/ui/' + source.slice(2);
211 }
212 } else {
213 // Use the bare package name (e.g. `react-aria-components`) rather than the
214 // deep import path (`react-aria-components/Button`). npm treats `owner/repo`
215 // specifiers as GitHub shorthand, so passing deep paths to `shadcn add` (which
216 // runs `npm install <deps>`) would fail to resolve the dependency.
217 let pkg = source.startsWith('@')
218 ? source.split('/').slice(0, 2).join('/')
219 : source.split('/')[0];
220 dependencies.add(pkg);
221 }
222 }
223 }
224
225 content = recast.print(ast, {objectCurlySpacing: false, quote: 'single'}).code;
226 return {dependencies, registryDependencies, cssImports, content};
227}
228
229function analyzeCss(file, seen = new Set()) {
230 if (seen.has(file)) {

Callers 1

buildRegistry.mjsFile · 0.85

Calls 3

sliceMethod · 0.80
addMethod · 0.65
parseMethod · 0.45

Tested by

no test coverage detected