简体   繁体   中英

Listing all files that require/import a specific file

I have a utilities.js file which I would like to move out into it's own yarn package.

Currently there are a lot of files which require utilities.js through a relative path, some examples are

const utils = require('../../../utilities/utilities');
const utilities = require('../../../../../utilities/utilities.js')
const utils = require('./utilities.js')
import { someFunction } from '../../../utilities/utilities.js'

I'm looking for a solution to rename all of the require/imports statements to @myUtilities

I've attempted to use VSCodes find feature with a regex match but I've fallen short or included some undesired matches.

The best pattern I've been able to come up with is

\'(..?\/)*(\/)?utilities(\/utilities)?(.js)?\'

Are there any better solutions?

You can try this

(?:import|require).*?(['"].*utilities(\/utilities)?(.js)?['"])

Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM