diff --git a/.changeset/poor-ads-grab.md b/.changeset/poor-ads-grab.md new file mode 100644 index 0000000000..75a56bf974 --- /dev/null +++ b/.changeset/poor-ads-grab.md @@ -0,0 +1,5 @@ +--- +'@backstage/codemods': patch +--- + +Inlined the table of symbols used by the `core-imports` codemod so that future updates to the core packages don't break the codemod. An entry for has also been added to direct imports of `createApp` to `@backstage/app-defaults`. diff --git a/.github/workflows/verify_windows.yml b/.github/workflows/verify_windows.yml index 5326e293d3..6899b6ec2b 100644 --- a/.github/workflows/verify_windows.yml +++ b/.github/workflows/verify_windows.yml @@ -55,10 +55,6 @@ jobs: - name: verify type dependencies run: yarn lint:type-deps - # The core packages need to be built for the codemods tests to work - - name: build core packages - run: lerna run --scope @backstage/core-* build - - name: test run: yarn lerna -- run test env: diff --git a/packages/codemods/package.json b/packages/codemods/package.json index cc5f3fd987..7c1e9a0d12 100644 --- a/packages/codemods/package.json +++ b/packages/codemods/package.json @@ -35,9 +35,6 @@ }, "dependencies": { "@backstage/cli-common": "^0.1.8", - "@backstage/core-app-api": "*", - "@backstage/core-components": "0.9.1", - "@backstage/core-plugin-api": "*", "chalk": "^4.0.0", "jscodeshift": "^0.13.0", "jscodeshift-add-imports": "^1.0.10" diff --git a/packages/codemods/src/tests/core-imports.test.ts b/packages/codemods/src/tests/core-imports.test.ts index 0b416e5c8e..56500fd914 100644 --- a/packages/codemods/src/tests/core-imports.test.ts +++ b/packages/codemods/src/tests/core-imports.test.ts @@ -45,9 +45,9 @@ return something() it('should refactor imports', () => { const input = ` /* COPYRIGHT: ME */ -import { Button as MyButton, createApiRef, createSpecializedApp } from '@backstage/core'; +import { Button as MyButton, createApiRef, createApp } from '@backstage/core'; -const app = createSpecializedApp(); +const app = createApp(); const apiRef = createApiRef(); const button = `; @@ -57,9 +57,9 @@ const button = import { Button as MyButton } from '@backstage/core-components'; import { createApiRef } from '@backstage/core-plugin-api'; -import { createSpecializedApp } from '@backstage/core-app-api'; +import { createApp } from '@backstage/app-defaults'; -const app = createSpecializedApp(); +const app = createApp(); const apiRef = createApiRef(); const button = `; diff --git a/packages/codemods/transforms/core-imports.js b/packages/codemods/transforms/core-imports.js index f744a9c412..bcce7554d4 100644 --- a/packages/codemods/transforms/core-imports.js +++ b/packages/codemods/transforms/core-imports.js @@ -15,29 +15,258 @@ */ const addImports = require('jscodeshift-add-imports'); -const { resolve: resolvePath } = require('path'); -const fs = require('fs'); - -function findExports(packageName) { - const packagePath = require.resolve(`${packageName}/package.json`); - const typesPath = resolvePath(packagePath, '../dist/index.d.ts'); - const content = fs.readFileSync(typesPath, 'utf8'); - - // For each export statement in the type declarations we grab the exported symbol names - return content - .split(/export \{ (.*) \}/) - .filter((_, i) => i % 2) - .flatMap(symbolsStr => - symbolsStr - .split(', ') - .map(exported => exported.match(/.* as (.*)/)?.[1] || exported), - ); -} +// The symbols in this table are out of date, but it does NOT need updating. +// They're from a snapshot in the past and only need to handle the migration +// away from @backstage/core. const symbolTable = { - '@backstage/core-app-api': findExports('@backstage/core-app-api'), - '@backstage/core-components': findExports('@backstage/core-components'), - '@backstage/core-plugin-api': findExports('@backstage/core-plugin-api'), + '@backstage/app-defaults': ['createApp'], + '@backstage/core-app-api': [ + 'ConfigReader', + 'AlertApiForwarder', + 'ApiFactoryHolder', + 'ApiFactoryRegistry', + 'ApiProvider', + 'ApiRegistry', + 'ApiResolver', + 'AppComponents', + 'AppConfigLoader', + 'AppContext', + 'AppOptions', + 'AppRouteBinder', + 'AppThemeSelector', + 'Auth0Auth', + 'BackstageApp', + 'BackstagePluginWithAnyOutput', + 'BootErrorPageProps', + 'ErrorAlerter', + 'ErrorApiForwarder', + 'ErrorBoundaryFallbackProps', + 'FeatureFlagged', + 'FeatureFlaggedProps', + 'FlatRoutes', + 'GithubAuth', + 'GithubSession', + 'GitlabAuth', + 'GoogleAuth', + 'LocalStorageFeatureFlags', + 'MicrosoftAuth', + 'OAuth2', + 'OAuth2Session', + 'OAuthRequestManager', + 'OktaAuth', + 'OneLoginAuth', + 'SamlAuth', + 'SignInPageProps', + 'SignInResult', + 'UrlPatternDiscovery', + 'WebStorage', + ], + '@backstage/core-components': [ + 'AlertDisplay', + 'Avatar', + 'Breadcrumbs', + 'BrokenImageIcon', + 'Button', + 'CardTab', + 'CatalogIcon', + 'ChatIcon', + 'CodeSnippet', + 'Content', + 'ContentHeader', + 'CopyTextButton', + 'DashboardIcon', + 'DependencyGraph', + 'DependencyGraphTypes', + 'DismissableBanner', + 'DocsIcon', + 'EmailIcon', + 'EmptyState', + 'ErrorBoundary', + 'ErrorPage', + 'ErrorPanel', + 'ErrorPanelProps', + 'FeatureCalloutCircular', + 'Gauge', + 'GaugeCard', + 'GitHubIcon', + 'GroupIcon', + 'Header', + 'HeaderIconLinkRow', + 'HeaderLabel', + 'HeaderTabs', + 'HelpIcon', + 'HomepageTimer', + 'HorizontalScrollGrid', + 'IconLinkVerticalProps', + 'InfoCard', + 'InfoCardVariants', + 'IntroCard', + 'ItemCard', + 'ItemCardGrid', + 'ItemCardGridProps', + 'ItemCardHeader', + 'ItemCardHeaderProps', + 'Lifecycle', + 'LinearGauge', + 'Link', + 'LinkProps', + 'MarkdownContent', + 'MissingAnnotationEmptyState', + 'OAuthRequestDialog', + 'OverflowTooltip', + 'Page', + 'Progress', + 'ResponseErrorPanel', + 'RoutedTabs', + 'SIDEBAR_INTRO_LOCAL_STORAGE', + 'Select', + 'Sidebar', + 'SidebarContext', + 'SidebarContextType', + 'SidebarDivider', + 'SidebarIntro', + 'SidebarItem', + 'SidebarPage', + 'SidebarPinStateContext', + 'SidebarPinStateContextType', + 'SidebarSearchField', + 'SidebarSpace', + 'SidebarSpacer', + 'SignInPage', + 'SignInProviderConfig', + 'SimpleStepper', + 'SimpleStepperStep', + 'StatusAborted', + 'StatusError', + 'StatusOK', + 'StatusPending', + 'StatusRunning', + 'StatusWarning', + 'StructuredMetadataTable', + 'SubvalueCell', + 'SupportButton', + 'SupportConfig', + 'SupportItem', + 'SupportItemLink', + 'Tab', + 'TabbedCard', + 'TabbedLayout', + 'Table', + 'TableColumn', + 'TableFilter', + 'TableProps', + 'TableState', + 'Tabs', + 'TrendLine', + 'UserIcon', + 'WarningIcon', + 'WarningPanel', + 'sidebarConfig', + 'useQueryParamState', + 'useSupportConfig', + ], + '@backstage/core-plugin-api': [ + 'AlertApi', + 'AlertMessage', + 'AnyApiFactory', + 'AnyApiRef', + 'ApiFactory', + 'ApiHolder', + 'ApiRef', + 'ApiRefType', + 'ApiRefsToTypes', + 'AppComponents', + 'AppContext', + 'AppTheme', + 'AppThemeApi', + 'AuthProvider', + 'AuthRequestOptions', + 'AuthRequester', + 'AuthRequesterOptions', + 'BackstageIdentity', + 'BackstageIdentityApi', + 'BackstagePlugin', + 'BootErrorPageProps', + 'ConfigApi', + 'DiscoveryApi', + 'ElementCollection', + 'ErrorApi', + 'ErrorBoundaryFallbackProps', + 'ErrorContext', + 'Extension', + 'ExternalRouteRef', + 'FeatureFlag', + 'FeatureFlagOutput', + 'FeatureFlagState', + 'FeatureFlagsApi', + 'FeatureFlagsHooks', + 'FeatureFlagsSaveOptions', + 'IconComponent', + 'IdentityApi', + 'OAuthApi', + 'OAuthRequestApi', + 'OAuthScope', + 'Observable', + 'Observer', + 'OpenIdConnectApi', + 'PendingAuthRequest', + 'PluginConfig', + 'PluginHooks', + 'PluginOutput', + 'ProfileInfo', + 'ProfileInfoApi', + 'RouteOptions', + 'RoutePath', + 'RouteRef', + 'SessionApi', + 'SessionState', + 'SignInPageProps', + 'SignInResult', + 'StorageApi', + 'StorageValueChange', + 'SubRouteRef', + 'Subscription', + 'TypesToApiRefs', + 'UserFlags', + 'alertApiRef', + 'appThemeApiRef', + 'attachComponentData', + 'auth0AuthApiRef', + 'configApiRef', + 'createApiFactory', + 'createApiRef', + 'createComponentExtension', + 'createExternalRouteRef', + 'createPlugin', + 'createReactExtension', + 'createRoutableExtension', + 'createRouteRef', + 'createSubRouteRef', + 'discoveryApiRef', + 'errorApiRef', + 'featureFlagsApiRef', + 'getComponentData', + 'githubAuthApiRef', + 'gitlabAuthApiRef', + 'googleAuthApiRef', + 'identityApiRef', + 'microsoftAuthApiRef', + 'oauth2ApiRef', + 'oauthRequestApiRef', + 'oidcAuthApiRef', + 'oktaAuthApiRef', + 'oneloginAuthApiRef', + 'samlAuthApiRef', + 'storageApiRef', + 'useApi', + 'useApiHolder', + 'useApp', + 'useElementFilter', + 'useRouteRef', + 'useRouteRefParams', + 'withApis', + ], }; const reverseSymbolTable = Object.entries(symbolTable).reduce(