Merge pull request #850 from spotify/rugvip/cleancore
packages/core: use cleaner tree of index files in api + remove default exports
This commit is contained in:
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import ApiProvider, { useApi, withApis } from './ApiProvider';
|
||||
import ApiRef from './ApiRef';
|
||||
import ApiRegistry from './ApiRegistry';
|
||||
import { ApiProvider, useApi, withApis } from './ApiProvider';
|
||||
import { ApiRef } from './ApiRef';
|
||||
import { ApiRegistry } from './ApiRegistry';
|
||||
import { render } from '@testing-library/react';
|
||||
import { withLogCollector } from '@backstage/test-utils-core';
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
import React, { FC, createContext, useContext, ReactNode } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import ApiRef from './ApiRef';
|
||||
import { ApiRef } from './ApiRef';
|
||||
import { ApiHolder, TypesToApiRefs } from './types';
|
||||
|
||||
type Props = {
|
||||
@@ -26,7 +26,7 @@ type Props = {
|
||||
|
||||
const Context = createContext<ApiHolder | undefined>(undefined);
|
||||
|
||||
const ApiProvider: FC<Props> = ({ apis, children }) => {
|
||||
export const ApiProvider: FC<Props> = ({ apis, children }) => {
|
||||
return <Context.Provider value={apis} children={children} />;
|
||||
};
|
||||
|
||||
@@ -53,7 +53,7 @@ export function withApis<T>(apis: TypesToApiRefs<T>) {
|
||||
return function withApisWrapper<P extends T>(
|
||||
WrappedComponent: React.ComponentType<P>,
|
||||
) {
|
||||
const Hoc: FC<Omit<P, keyof T>> = props => {
|
||||
const Hoc: FC<Omit<P, keyof T>> = (props) => {
|
||||
const apiHolder = useContext(Context);
|
||||
|
||||
if (!apiHolder) {
|
||||
@@ -84,5 +84,3 @@ export function withApis<T>(apis: TypesToApiRefs<T>) {
|
||||
return Hoc;
|
||||
};
|
||||
}
|
||||
|
||||
export default ApiProvider;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import ApiRef from './ApiRef';
|
||||
import { ApiRef } from './ApiRef';
|
||||
|
||||
describe('ApiRef', () => {
|
||||
it('should be created', () => {
|
||||
|
||||
@@ -19,7 +19,7 @@ export type ApiRefConfig = {
|
||||
description: string;
|
||||
};
|
||||
|
||||
export default class ApiRef<T> {
|
||||
export class ApiRef<T> {
|
||||
constructor(private readonly config: ApiRefConfig) {
|
||||
if (!config.id.match(/^[a-z][a-z0-9]*(\.[a-z][a-z0-9]*)*$/)) {
|
||||
throw new Error(
|
||||
@@ -45,3 +45,7 @@ export default class ApiRef<T> {
|
||||
return `apiRef{${this.config.id}}`;
|
||||
}
|
||||
}
|
||||
|
||||
export function createApiRef<T>(config: ApiRefConfig) {
|
||||
return new ApiRef<T>(config);
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import ApiRegistry from './ApiRegistry';
|
||||
import ApiRef from './ApiRef';
|
||||
import { ApiRegistry } from './ApiRegistry';
|
||||
import { ApiRef } from './ApiRef';
|
||||
|
||||
describe('ApiRegistry', () => {
|
||||
const x1Ref = new ApiRef<number>({ id: 'x', description: '' });
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import ApiRef from './ApiRef';
|
||||
import { ApiRef } from './ApiRef';
|
||||
import { ApiHolder } from './types';
|
||||
|
||||
type ApiImpl<T = unknown> = readonly [ApiRef<T>, T];
|
||||
@@ -33,7 +33,7 @@ class ApiRegistryBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
export default class ApiRegistry implements ApiHolder {
|
||||
export class ApiRegistry implements ApiHolder {
|
||||
static builder() {
|
||||
return new ApiRegistryBuilder();
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import ApiTestRegistry from './ApiTestRegistry';
|
||||
import ApiRef from './ApiRef';
|
||||
import { ApiTestRegistry } from './ApiTestRegistry';
|
||||
import { ApiRef } from './ApiRef';
|
||||
|
||||
describe('ApiTestRegistry', () => {
|
||||
const aRef = new ApiRef<number>({ id: 'a', description: '' });
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import ApiRef from './ApiRef';
|
||||
import { ApiRef } from './ApiRef';
|
||||
import { TypesToApiRefs, AnyApiRef, ApiHolder, ApiFactory } from './types';
|
||||
|
||||
export default class ApiTestRegistry implements ApiHolder {
|
||||
export class ApiTestRegistry implements ApiHolder {
|
||||
private readonly apis = new Map<AnyApiRef, unknown>();
|
||||
private factories = new Map<
|
||||
AnyApiRef,
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import ApiRef from '../ApiRef';
|
||||
import { ApiRef } from '../ApiRef';
|
||||
|
||||
export type AlertMessage = {
|
||||
message: string;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import ApiRef from '../ApiRef';
|
||||
import { ApiRef } from '../ApiRef';
|
||||
|
||||
/**
|
||||
* Mirrors the javascript Error class, for the purpose of
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import ApiRef from '../ApiRef';
|
||||
import { ApiRef } from '../ApiRef';
|
||||
import {
|
||||
UserFlags,
|
||||
FeatureFlagsRegistry,
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { default as ApiProvider, useApi } from './ApiProvider';
|
||||
export { default as ApiRegistry } from './ApiRegistry';
|
||||
export { default as ApiTestRegistry } from './ApiTestRegistry';
|
||||
export { default as ApiRef } from './ApiRef';
|
||||
export { ApiProvider, useApi } from './ApiProvider';
|
||||
export { ApiRegistry } from './ApiRegistry';
|
||||
export { ApiTestRegistry } from './ApiTestRegistry';
|
||||
export * from './ApiRef';
|
||||
export * from './types';
|
||||
export * from './helpers';
|
||||
export * from './definitions';
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import ApiRef from './ApiRef';
|
||||
import { ApiRef } from './ApiRef';
|
||||
|
||||
export type AnyApiRef = ApiRef<any>;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import React, { ComponentType } from 'react';
|
||||
import { Route, Switch, Redirect } from 'react-router-dom';
|
||||
import { AppContextProvider } from './AppContext';
|
||||
import { App } from './types';
|
||||
import BackstagePlugin from '../plugin/Plugin';
|
||||
import { BackstagePlugin } from '../plugin';
|
||||
import { FeatureFlagsRegistryItem } from './FeatureFlags';
|
||||
import { featureFlagsApiRef } from '../apis/definitions/featureFlags';
|
||||
import ErrorPage from '../../layout/ErrorPage';
|
||||
@@ -40,7 +40,7 @@ class AppImpl implements App {
|
||||
}
|
||||
}
|
||||
|
||||
export default class AppBuilder {
|
||||
export class AppBuilder {
|
||||
private apis?: ApiHolder;
|
||||
private systemIcons = { ...defaultSystemIcons };
|
||||
private readonly plugins = new Set<BackstagePlugin>();
|
||||
@@ -145,3 +145,7 @@ export default class AppBuilder {
|
||||
return () => <AppContextProvider app={app} children={rendered} />;
|
||||
}
|
||||
}
|
||||
|
||||
export function createApp() {
|
||||
return new AppBuilder();
|
||||
}
|
||||
|
||||
@@ -14,18 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import ApiRef, { ApiRefConfig } from './apis/ApiRef';
|
||||
import AppBuilder from './app/AppBuilder';
|
||||
import BackstagePlugin, { PluginConfig } from './plugin/Plugin';
|
||||
|
||||
export function createApp() {
|
||||
return new AppBuilder();
|
||||
}
|
||||
|
||||
export function createApiRef<T>(config: ApiRefConfig) {
|
||||
return new ApiRef<T>(config);
|
||||
}
|
||||
|
||||
export function createPlugin(config: PluginConfig): BackstagePlugin {
|
||||
return new BackstagePlugin(config);
|
||||
}
|
||||
export { createApp } from './AppBuilder';
|
||||
export { FeatureFlags } from './FeatureFlags';
|
||||
export { useApp } from './AppContext';
|
||||
export * from './types';
|
||||
@@ -14,8 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from './api';
|
||||
export * from './apis';
|
||||
export * from './app';
|
||||
export * from './navTargets';
|
||||
export { FeatureFlags } from './app/FeatureFlags';
|
||||
export { useApp } from './app/AppContext';
|
||||
export * from './plugin';
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
RoutePath,
|
||||
RouteOptions,
|
||||
FeatureFlagName,
|
||||
BackstagePlugin,
|
||||
} from './types';
|
||||
import { validateBrowserCompat, validateFlagName } from '../app/FeatureFlags';
|
||||
import { NavTarget } from '../navTargets';
|
||||
@@ -58,10 +59,7 @@ export type FeatureFlagsHooks = {
|
||||
register(name: FeatureFlagName): void;
|
||||
};
|
||||
|
||||
export const registerSymbol = Symbol('plugin-register');
|
||||
export const outputSymbol = Symbol('plugin-output');
|
||||
|
||||
export default class Plugin {
|
||||
export class PluginImpl {
|
||||
private storedOutput?: PluginOutput[];
|
||||
|
||||
constructor(private readonly config: PluginConfig) {}
|
||||
@@ -114,3 +112,7 @@ export default class Plugin {
|
||||
return `plugin{${this.config.id}}`;
|
||||
}
|
||||
}
|
||||
|
||||
export function createPlugin(config: PluginConfig): BackstagePlugin {
|
||||
return new PluginImpl(config);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2020 Spotify AB
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { createPlugin } from './Plugin';
|
||||
export * from './types';
|
||||
@@ -57,3 +57,8 @@ export type PluginOutput =
|
||||
| RouteTargetOutput
|
||||
| RedirectRouteOutput
|
||||
| FeatureFlagOutput;
|
||||
|
||||
export type BackstagePlugin = {
|
||||
getId(): string;
|
||||
output(): PluginOutput[];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user