diff --git a/packages/cli/src/lib/builder/config.ts b/packages/cli/src/lib/builder/config.ts index afcedaae59..44ccc85824 100644 --- a/packages/cli/src/lib/builder/config.ts +++ b/packages/cli/src/lib/builder/config.ts @@ -77,6 +77,21 @@ export const makeConfigs = async ( mainFields.unshift('browser'); } + const commonjsInclude: Array = [/node_modules/]; + + // Purpose of this file is + // to be bridge between + // frontend- and backend- + // plugins' code + const UNIVERSAL_FILE = 'universal.js'; + const universalPath = paths.resolveTarget(UNIVERSAL_FILE); + const universalFileExists = fs.existsSync(universalPath); + + if (universalFileExists) { + mainFields.push(UNIVERSAL_FILE); + commonjsInclude.push(UNIVERSAL_FILE); + } + configs.push({ input: 'src/index.ts', output, @@ -88,7 +103,7 @@ export const makeConfigs = async ( }), resolve({ mainFields }), commonjs({ - include: /node_modules/, + include: commonjsInclude, exclude: [/\/[^/]+\.(?:stories|test)\.[^/]+$/], }), postcss(), diff --git a/plugins/github-actions/package.json b/plugins/github-actions/package.json index 9d1538ce99..0000e07d23 100644 --- a/plugins/github-actions/package.json +++ b/plugins/github-actions/package.json @@ -50,6 +50,7 @@ "jest-fetch-mock": "^3.0.3" }, "files": [ - "dist" + "dist", + "universal.js" ] } diff --git a/plugins/github-actions/src/components/Cards/Cards.tsx b/plugins/github-actions/src/components/Cards/Cards.tsx index 28783efdea..f963be7569 100644 --- a/plugins/github-actions/src/components/Cards/Cards.tsx +++ b/plugins/github-actions/src/components/Cards/Cards.tsx @@ -32,7 +32,7 @@ import { useApi, } from '@backstage/core'; import ExternalLinkIcon from '@material-ui/icons/Launch'; -import { GITHUB_ACTIONS_ANNOTATION } from '../useProjectName'; +import { GITHUB_ACTIONS_ANNOTATION } from '../../../universal'; const useStyles = makeStyles({ externalLinkIcon: { diff --git a/plugins/github-actions/src/components/Router.tsx b/plugins/github-actions/src/components/Router.tsx index 7d340fb8b8..8314981ed6 100644 --- a/plugins/github-actions/src/components/Router.tsx +++ b/plugins/github-actions/src/components/Router.tsx @@ -19,7 +19,7 @@ import { Routes, Route } from 'react-router'; import { rootRouteRef, buildRouteRef } from '../plugin'; import { WorkflowRunDetails } from './WorkflowRunDetails'; import { WorkflowRunsTable } from './WorkflowRunsTable'; -import { GITHUB_ACTIONS_ANNOTATION } from './useProjectName'; +import { GITHUB_ACTIONS_ANNOTATION } from '../../universal'; import { WarningPanel } from '@backstage/core'; export const isPluginApplicableToEntity = (entity: Entity) => diff --git a/plugins/github-actions/src/components/useProjectName.ts b/plugins/github-actions/src/components/useProjectName.ts index ec7158bd27..226cc6c775 100644 --- a/plugins/github-actions/src/components/useProjectName.ts +++ b/plugins/github-actions/src/components/useProjectName.ts @@ -16,8 +16,7 @@ import { useAsync } from 'react-use'; import { Entity } from '@backstage/catalog-model'; - -export const GITHUB_ACTIONS_ANNOTATION = 'github.com/project-slug'; +import { GITHUB_ACTIONS_ANNOTATION } from '../../universal'; export const useProjectName = (entity: Entity) => { const { value, loading, error } = useAsync(async () => { diff --git a/plugins/github-actions/src/index.ts b/plugins/github-actions/src/index.ts index 24fe6fc90d..5c89c7f920 100644 --- a/plugins/github-actions/src/index.ts +++ b/plugins/github-actions/src/index.ts @@ -18,4 +18,3 @@ export { plugin } from './plugin'; export * from './api'; export { Router, isPluginApplicableToEntity } from './components/Router'; export * from './components/Cards'; -export { GITHUB_ACTIONS_ANNOTATION } from './components/useProjectName'; diff --git a/plugins/github-actions/universal.js b/plugins/github-actions/universal.js new file mode 100644 index 0000000000..a414b71749 --- /dev/null +++ b/plugins/github-actions/universal.js @@ -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. + */ + +// This file is shared between frontend and backend plugins +module.exports.GITHUB_ACTIONS_ANNOTATION = 'github.com/project-slug'; diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/templater/cra/index.ts b/plugins/scaffolder-backend/src/scaffolder/stages/templater/cra/index.ts index e771ada8c3..61a7064dc0 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/templater/cra/index.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/templater/cra/index.ts @@ -19,7 +19,8 @@ import { TemplaterBase, TemplaterRunOptions } from '..'; import path from 'path'; import { TemplaterRunResult } from '../types'; import * as yaml from 'yaml'; -import { GITHUB_ACTIONS_ANNOTATION } from '@backstage/plugin-github-actions'; +// eslint-disable-next-line monorepo/no-internal-import +import { GITHUB_ACTIONS_ANNOTATION } from '@backstage/plugin-github-actions/universal'; export class CreateReactAppTemplater implements TemplaterBase { public async run(options: TemplaterRunOptions): Promise {