【问题标题】:jscodeshift - get count of all imports from a module in projectjscodeshift - 从项目中的模块获取所有导入的计数
【发布时间】:2022-11-11 08:19:50
【问题描述】:

我正在玩 jscodeshift。

我的目标是计算项目中特定模块的所有导入

import { Circle, Triangle, Rectangle } from 'geometry';

结果是

{ Circle: 1, Triangle: 1, Rectangle: 1 }

我已经达到了我想要的here 但唯一的问题是我想要整个项目而不是单个文件的这些统计信息。

知道如何实现这一目标吗?

【问题讨论】:

    标签: javascript jscodeshift


    【解决方案1】:

    不确定我是否理解正确,您是否尝试从模块中导入所有内容而不必显式输入它们的名称(圆形、三角形等)? 或者这可能会有所帮助:

    export const Foo = 1;
    export const Bar = 2;
    
    // geometry2.js|ts
    export const Biz = 3;
    
    // index.js|ts 
    import * as counts from './geometry';
    import * as counts2 from './geometry2';
    
    const data = { ...counts, ...counts2 };
    console.log(data); // logs {Foo: 1, Bar: 2, Biz: 3}
    

    【讨论】:

    • 不,我实际上想检查从整个项目中的特定模块导入功能/组件的次数
    【解决方案2】:

    我实际上也需要答案,找到了这个帖子但还没有找到答案。然后我找到了这个包。

    find-imports

    我想这就是你要找的。

    【讨论】:

      猜你喜欢
      • 2022-11-16
      • 1970-01-01
      • 2017-04-03
      • 2013-05-27
      • 2020-06-08
      • 2016-06-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多