codemods: inline core-imports table + fix createApp

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-03-11 11:16:58 +01:00
parent 66ffb38685
commit 224441d0f9
5 changed files with 259 additions and 32 deletions
+5
View File
@@ -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`.
-4
View File
@@ -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:
-3
View File
@@ -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"
@@ -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 = <MyButton />
`;
@@ -57,9 +57,9 @@ const button = <MyButton />
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 = <MyButton />
`;
+250 -21
View File
@@ -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(