Skip to content

Add codemod to cleanup default exports and barrell files#5919

Draft
witoszekdev wants to merge 3 commits intomainfrom
add-codemod-cleanup-exports
Draft

Add codemod to cleanup default exports and barrell files#5919
witoszekdev wants to merge 3 commits intomainfrom
add-codemod-cleanup-exports

Conversation

@witoszekdev
Copy link
Member

This PR adds a codemod that can be run with multiple stages.

It aims to:

  • Remove export default from entire codebase and replace it with named exports
  • Update imports accordingly
  • Ensure that all folders that have code + barell file (index.ts) have other files, otherwise delete that folder and rename it to a single file
    • E.g. src/components/AppList/AppList.tsx -> src/components/AppList.tsx
  • Remove barell files (index.ts) that only re-export files, update imports

Copilot AI review requested due to automatic review settings October 1, 2025 10:54
@changeset-bot
Copy link

changeset-bot bot commented Oct 1, 2025

⚠️ No Changeset found

Latest commit: 3a2bed8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Oct 1, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
saleor-dashboard-storybook Ignored Ignored Preview Oct 20, 2025 3:11pm

💡 Enable Vercel Agent with $100 free credit for automated AI reviews

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a comprehensive codemod script to modernize the codebase by removing default exports and barrel files while reorganizing the project structure for better maintainability.

  • Converts all default exports to named exports throughout the codebase
  • Updates imports from default to named imports accordingly
  • Flattens single-file component folders by moving component files up one level
  • Removes barrel files (index.ts) that only re-export other files

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 5 comments.

File Description
scripts/cleanup-exports-codemod.cjs Main codemod script implementing 4-stage transformation process
package.json Adds ts-morph dependency and reorganizes jotai package position
eslint.config.mjs Disables TypeScript no-require-imports rule for CommonJS files

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

const filePath = sourceFile.getFilePath();

// Exclude graphql barrel file - we want to keep it
if (filePath.includes("src/graphql/index.ts")) {
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coded file path check is fragile and doesn't scale. Consider making excluded paths configurable through a constant array or CLI parameter.

Copilot uses AI. Check for mistakes.
}

// Skip generated files
if (filePath.includes(".generated.") || filePath.includes("/__generated__/")) {
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coded generated file patterns should be extracted to a configurable constant array for easier maintenance and extensibility.

Copilot uses AI. Check for mistakes.

const target = mapping.get(exportedName);
if (!target) {
throw new Error(`Unable to resolve export ${exportedName} from barrel ${barrelPath}`);
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error message should include the file path where the unresolved import occurs to help with debugging. Consider: Unable to resolve export ${exportedName} from barrel ${barrelPath} in file ${filePath}

Suggested change
throw new Error(`Unable to resolve export ${exportedName} from barrel ${barrelPath}`);
throw new Error(`Unable to resolve export ${exportedName} from barrel ${barrelPath} in file ${filePath}`);

Copilot uses AI. Check for mistakes.
}

// Remove the now-empty folder
fs.rmdirSync(folderPath);
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fs.rmdirSync is deprecated. Use fs.rmSync with recursive option instead: fs.rmSync(folderPath, { recursive: true })

Suggested change
fs.rmdirSync(folderPath);
fs.rmSync(folderPath, { recursive: true });

Copilot uses AI. Check for mistakes.
}
barrel.delete();
if (fs.existsSync(filePath)) {
fs.unlinkSync(filePath);
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File deletion should include error handling in case the file is locked or inaccessible. Consider wrapping in try-catch with meaningful error message.

Suggested change
fs.unlinkSync(filePath);
try {
fs.unlinkSync(filePath);
} catch (err) {
console.error(`Error deleting file "${filePath}": ${err.message}`);
continue;
}

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Contributor

github-actions bot commented Oct 1, 2025

Differences Found

⚠️ 6 packages or licenses were added.

Expand
License	Package
MIT	@isaacs/balanced-match
MIT	@isaacs/brace-expansion
MIT	@ts-morph/common
MIT	code-block-writer
MIT	path-browserify
MIT	ts-morph

Summary

Expand
License Name Package Count Packages
0BSD 1
Packages
  • tslib
CC-BY-3.0 1
Packages
  • spdx-exceptions
MIT/X11 1
Packages
  • nub
MPL-1.1 1
Packages
  • harmony-reflect
MPL-2.0 1
Packages
  • dompurify
Public Domain 1
Packages
  • jsonify
Python-2.0 1
Packages
  • argparse
WTFPL 1
Packages
  • utf8-byte-length
<<missing>> 2
Packages
  • busboy
  • streamsearch
CC-BY-4.0 2
Packages
  • @saleor/macaw-ui
  • caniuse-lite
CC0-1.0 2
Packages
  • spdx-license-ids
  • type-fest
SEE LICENSE IN LICENSE 2
Packages
  • posthog-js
  • spawndamnit
BlueOak-1.0.0 3
Packages
  • jackspeak
  • package-json-from-dist
  • path-scurry
BSD-2-Clause 24
Packages
  • browser-process-hrtime
  • css-select
  • css-what
  • domelementtype
  • domhandler
  • domutils
  • dotenv
  • dotenv-expand
  • entities
  • escodegen
  • eslint-scope
  • espree
  • esprima
  • esrecurse
  • estraverse
  • esutils
  • normalize-package-data
  • nth-check
  • regjsparser
  • stringify-object
  • And 4 more...
BSD-3-Clause 43
Packages
  • @saleor/app-sdk
  • @sentry/cli
  • @sentry/cli-darwin
  • @sentry/cli-linux-arm
  • @sentry/cli-linux-arm64
  • @sentry/cli-linux-i686
  • @sentry/cli-linux-x64
  • @sentry/cli-win32-arm64
  • @sentry/cli-win32-i686
  • @sentry/cli-win32-x64
  • @sinonjs/commons
  • @sinonjs/fake-timers
  • abab
  • asn1js
  • babel-plugin-istanbul
  • chroma-js
  • dataloader
  • diff
  • esquery
  • exenv
  • And 23 more...
ISC 50
Packages
  • @isaacs/cliui
  • @istanbuljs/load-nyc-config
  • anymatch
  • boolbase
  • cli-width
  • cliui
  • electron-to-chromium
  • fastq
  • flatted
  • foreground-child
  • fs.realpath
  • get-caller-file
  • get-own-enumerable-property-symbols
  • glob
  • glob-parent
  • graceful-fs
  • hosted-git-info
  • inflight
  • inherits
  • ini
  • And 30 more...
Apache-2.0 57
Packages
  • @ampproject/remapping
  • @editorjs/editorjs
  • @eslint/config-array
  • @eslint/config-helpers
  • @eslint/core
  • @eslint/object-schema
  • @eslint/plugin-kit
  • @humanfs/core
  • @humanfs/node
  • @humanwhocodes/module-importer
  • @humanwhocodes/retry
  • @opentelemetry/api
  • @opentelemetry/semantic-conventions
  • @playwright/test
  • @pollyjs/adapter
  • @pollyjs/core
  • @pollyjs/persister
  • @pollyjs/utils
  • @swc/core
  • @swc/core-darwin-arm64
  • And 37 more...
MIT 1289
Packages
  • @adobe/css-tools
  • @apollo/client
  • @ardatan/relay-compiler
  • @ardatan/sync-fetch
  • @babel/code-frame
  • @babel/compat-data
  • @babel/core
  • @babel/generator
  • @babel/helper-annotate-as-pure
  • @babel/helper-compilation-targets
  • @babel/helper-create-class-features-plugin
  • @babel/helper-globals
  • @babel/helper-member-expression-to-functions
  • @babel/helper-module-imports
  • @babel/helper-module-transforms
  • @babel/helper-optimise-call-expression
  • @babel/helper-plugin-utils
  • @babel/helper-replace-supers
  • @babel/helper-skip-transparent-expression-wrappers
  • @babel/helper-string-parser
  • And 1269 more...

@codecov
Copy link

codecov bot commented Oct 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 39.49%. Comparing base (61cbce3) to head (3a2bed8).

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #5919    +/-   ##
========================================
  Coverage   39.49%   39.49%            
========================================
  Files        2429     2429            
  Lines       39518    39518            
  Branches     8711     9037   +326     
========================================
  Hits        15609    15609            
  Misses      23883    23883            
  Partials       26       26            

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants