commonjs-to-es-module-codemod icon indicating copy to clipboard operation
commonjs-to-es-module-codemod copied to clipboard

Fails on immediate destructuring

Open webbertakken opened this issue 3 months ago • 0 comments

Hi there 👋🏼

Thank you so much for the mod, it's very useful!

Just reporting a case where it failed

Example failure

Given the following imports

const [filePlugin] = require('@size-limit/file');
const [webpackPlugin] = require('@size-limit/webpack');
const { Plugins } = require('size-limit/load-plugins');

When running the mod, you'll get this result

import { Plugins } from 'size-limit/load-plugins';

Note that the directly destructuring syntax is removed completely.

Suggested resolution

import filePluginModule from '@size-limit/file';
import webpackPluginModule from '@size-limit/webpack';
import { Plugins } from 'size-limit/load-plugins';

const [filePlugin] = filePluginModule;
const [webpackPlugin] = webpackPluginModule;

webbertakken avatar Sep 24 '25 16:09 webbertakken