diff --git a/packages/app/src/index.tsx b/packages/app/src/index.tsx index a38159a258..ed1637d2c2 100644 --- a/packages/app/src/index.tsx +++ b/packages/app/src/index.tsx @@ -14,8 +14,7 @@ * limitations under the License. */ -// eslint-disable-next-line monorepo/no-internal-import -import '@backstage/cli/asset-types'; +import '@backstage/cli/asset-types/asset-types'; import React from 'react'; import ReactDOM from 'react-dom'; import App from './App'; diff --git a/packages/cli/package.json b/packages/cli/package.json index 7ae244866d..1e3bfeac1e 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -65,7 +65,7 @@ "eslint-plugin-import": "^2.20.2", "eslint-plugin-jest": "^24.1.0", "eslint-plugin-jsx-a11y": "^6.2.1", - "eslint-plugin-monorepo": "^0.2.1", + "eslint-plugin-monorepo": "^0.3.2", "eslint-plugin-react": "^7.12.4", "eslint-plugin-react-hooks": "^4.0.0", "fork-ts-checker-webpack-plugin": "^4.0.5", diff --git a/packages/cli/src/lib/builder/config.ts b/packages/cli/src/lib/builder/config.ts index 2e7847fdb1..60b8ad20ba 100644 --- a/packages/cli/src/lib/builder/config.ts +++ b/packages/cli/src/lib/builder/config.ts @@ -79,6 +79,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, @@ -90,7 +105,7 @@ export const makeConfigs = async ( }), resolve({ mainFields }), commonjs({ - include: /node_modules/, + include: commonjsInclude, exclude: [/\/[^/]+\.(?:stories|test)\.[^/]+$/], }), postcss(), diff --git a/packages/cli/src/lib/diff/handlers.ts b/packages/cli/src/lib/diff/handlers.ts index 40e3d4c587..588ce2f45f 100644 --- a/packages/cli/src/lib/diff/handlers.ts +++ b/packages/cli/src/lib/diff/handlers.ts @@ -61,7 +61,12 @@ class PackageJsonHandler { await this.syncField('main:src'); } await this.syncField('types'); - await this.syncField('files'); + + // shmidt-i: Skipping `files` for now, + // need more info how to handle + // and what to allow + + // await this.syncField('files'); await this.syncScripts(); await this.syncPublishConfig(); await this.syncDependencies('dependencies'); diff --git a/plugins/github-actions/package.json b/plugins/github-actions/package.json index 8d10760843..95146c740c 100644 --- a/plugins/github-actions/package.json +++ b/plugins/github-actions/package.json @@ -52,6 +52,7 @@ "msw": "^0.21.2" }, "files": [ - "dist" + "dist", + "universal" ] } diff --git a/plugins/github-actions/src/components/Cards/Cards.tsx b/plugins/github-actions/src/components/Cards/Cards.tsx index 1f1e2997df..64de351d4e 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/Cards/RecentWorkflowRunsCard.tsx b/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.tsx index 46f60981a0..78c5239459 100644 --- a/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.tsx +++ b/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.tsx @@ -15,7 +15,7 @@ */ import { Entity } from '@backstage/catalog-model'; import { errorApiRef, useApi } from '@backstage/core-api'; -import { GITHUB_ACTIONS_ANNOTATION } from '../useProjectName'; +import { GITHUB_ACTIONS_ANNOTATION } from '../../../universal'; import { useWorkflowRuns } from '../useWorkflowRuns'; import React, { useEffect } from 'react'; import { EmptyState, InfoCard, Table } from '@backstage/core'; diff --git a/plugins/github-actions/src/components/Router.tsx b/plugins/github-actions/src/components/Router.tsx index e7430d40ed..720f751be6 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 { MissingAnnotationEmptyState } 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..b101b61efc --- /dev/null +++ b/plugins/github-actions/universal.js @@ -0,0 +1,22 @@ +// @ts-check +/* + * 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. + */ + +/** + * Annotation to define on the entity to enable the plugin + * @type {string} + */ +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..7d27688c0b 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'; +import { GITHUB_ACTIONS_ANNOTATION } from '@backstage/plugin-github-actions/universal'; +import { resolvePackagePath } from '@backstage/backend-common'; export class CreateReactAppTemplater implements TemplaterBase { public async run(options: TemplaterRunOptions): Promise { @@ -60,7 +61,9 @@ export class CreateReactAppTemplater implements TemplaterBase { await fs.promises.mkdir(`${finalDir}/.github`); await fs.promises.mkdir(`${finalDir}/.github/workflows`); await fs.promises.copyFile( - `${__dirname}/templates/.github/workflows/main.yml`, + `${resolvePackagePath( + '@backstage/plugin-scaffolder-backend', + )}/templates/.github/workflows/main.yml`, `${finalDir}/.github/workflows/main.yml`, ); diff --git a/plugins/scaffolder/src/components/JobStatusModal/JobStatusModal.tsx b/plugins/scaffolder/src/components/JobStatusModal/JobStatusModal.tsx index e0c95165aa..d5ac80c3d4 100644 --- a/plugins/scaffolder/src/components/JobStatusModal/JobStatusModal.tsx +++ b/plugins/scaffolder/src/components/JobStatusModal/JobStatusModal.tsx @@ -50,10 +50,10 @@ export const JobStatusModal = ({ useEffect(() => { if (jobStatus === 'COMPLETED') { setDialogTitle('Successfully created component'); - onComplete(job); + onComplete(job!); } else if (jobStatus === 'FAILED') setDialogTitle('Failed to create component'); - }, [jobStatus, onComplete, setDialogTitle]); + }, [jobStatus, onComplete, setDialogTitle]); // eslint-disable-line react-hooks/exhaustive-deps return ( diff --git a/yarn.lock b/yarn.lock index 2e55ce5d66..5ee42e7dd9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11023,10 +11023,10 @@ eslint-plugin-jsx-a11y@^6.2.1: has "^1.0.3" jsx-ast-utils "^2.2.1" -eslint-plugin-monorepo@^0.2.1: - version "0.2.1" - resolved "https://registry.npmjs.org/eslint-plugin-monorepo/-/eslint-plugin-monorepo-0.2.1.tgz#96cfc4af241077675f40d7017377897fb8ea537b" - integrity sha512-82JaAjuajVAsDT+pMvdt275H6F55H3MEofaMZbJurGqfXpPDT4eayTgYyyjfd1XR8VD1S+ORbuHCULnSqNyD9g== +eslint-plugin-monorepo@^0.3.2: + version "0.3.2" + resolved "https://registry.npmjs.org/eslint-plugin-monorepo/-/eslint-plugin-monorepo-0.3.2.tgz#bc546cbe84b21ae6a7622f261bf9fe73b1524367" + integrity sha512-CypTAqHjTR05XxzqDj7x88oVu2GiqqQA/datD9kIwciHzpj0oE4YbTdyEFFKADgd7dbd21KliSlUpOvo626FBw== dependencies: eslint-module-utils "^2.1.1" get-monorepo-packages "^1.1.0"