Refactoring JavaScript Barrel File
Answered

test.js
const {bar, foo} = require('./group1');
const {oof, rab} = require('./group2');
foo();
bar();
oof();
rab();
group1/index.js
const bar = require('./bar')
const foo = require('./foo')
module.exports = {
bar,
foo,
}
group1/bar.js
const bar = () => {
console.log('bar');
}
module.exports = bar;
Given this type of project how would refactoring foo into group2 work using IntelliJ? Is there a refactoring tool that could do this for me? If I want to be able to refactor should I avoid using barrel files?
Please sign in to leave a comment.
Hello,
As far as I understand you want to move the foo.js file to group2. If so, unfortunately, WebStrom does not support refactoring for such usage scenarios at the moment. The current behavior relates to the following issue: https://youtrack.jetbrains.com/issue/WEB-44288/Typescript-Refactoring-does-not-respect-barrel-files. Please feel free to vote for it to raise its priority.