Migrate default imports to named imports

JavaScript pattern

This pattern combines convert_default_exports and _convert_default_imports to replace default exports to named exports and replace default imports with named imports.


Apply with the Grit CLI
grit apply migrate_default_imports

Basic case

BEFORE
// @filename: foo/mymodule.ts
export default function name() {
  console.log('test');
}

// @filename: foo/module_user.ts
import name from 'mymodule';
import other from 'othermodule';
AFTER
// @filename: foo/mymodule.ts
export function name() {
  console.log('test');
}

// @filename: foo/module_user.ts
import { name } from 'mymodule';
import other from 'othermodule';

Relative paths

BEFORE
// @filename: folder1/foo.js
export default function name() {
  console.log('test');
}

// @filename: folder2/bar.js
import name from '../folder1/foo';

// @filename: folder3/baz
// This is a different folder - ignore it
import name from '../folder4/foo';
AFTER
// @filename: folder1/foo.js
export function name() {
  console.log('test');
}

// @filename: folder2/bar.js
import { name } from '../folder1/foo';

// @filename: folder3/baz
// This is a different folder - ignore it
import name from '../folder4/foo';