0

I upgrade to the latest version of @backstage/plugin-scaffolder-backend at 1.15.0. Seemed to broke my code. I can't seem to understand why the code is broken. It breaks on

integrations: integrations,

I get the follow: Type

'import("/PWD/node_modules/@backstage/integration/dist/index").ScmIntegrations' is not assignable to type 'import("/PWD/node_modules/@backstage/backend-plugin-api/node_modules/@backstage/integration/dist/index").ScmIntegrations'. Types have separate declarations of a private property 'byType'

import { CatalogClient } from '@backstage/catalog-client';
import {
  createRouter,
  createBuiltinActions
} from '@backstage/plugin-scaffolder-backend';
import { Router } from 'express';
import type { PluginEnvironment } from '../types';
import { ScmIntegrations } from '@backstage/integration';
import {createHttpBackstageAction} from "@roadiehq/scaffolder-backend-module-http-request";

export default async function createPlugin(
  env: PluginEnvironment,
): Promise<Router> {
  const catalogClient = new CatalogClient({
    discoveryApi: env.discovery,
  });
 
  let gitlabtoken: string = '';
  let integrations: ScmIntegrations = ScmIntegrations.fromConfig(env.config);

  try {
    gitlabtoken = integrations.gitlab.byHost('gitlab.host.com')?.config.token || '';
    env.logger.info('gitlabtoken set');
  } catch(err:any) {
    env.logger.info(
      'Failed loading gitlab integration token ${err}'
    );
  }

  const actions = [
    createHttpBackstageAction({config: env.config}),
      ...createBuiltinActions({
          catalogClient: catalogClient,
          integrations: integrations,
          config: env.config,
          reader: env.reader,
          additionalTemplateGlobals: {
            'gitlabtoken': gitlabtoken,
          },
      }),
  ];

  return createRouter({
    logger: env.logger,
    config: env.config,
    database: env.database,
    reader: env.reader,
    actions: actions,
    additionalTemplateGlobals: {
      'gitlabtoken': gitlabtoken,
    },
    catalogClient: catalogClient,
  });
}

What I tried doing is passing in a builtinActionsOptions but no luck. Any ideas why this is it?

  const builtinActionsOptions: CreateBuiltInActionsOptions = {
    catalogClient: catalogClient,
    integrations: integrations,
    config: env.config,
    reader: env.reader,
  };

  const actions = [
    createHttpBackstageAction({config: env.config}),
      ...createBuiltinActions(builtinActionsOptions),
  ];

1 Answers1

0

the problem happens because the classes are used in different versions.

This fixed it for me in backstage "version":"1.15.0"

Make sure the file: \backstage\packages*backend\package.json*

Contain the latest versions of dependencies:

   "@backstage/integration": "^1.5.0",
   "@backstage/plugin-scaffolder-backend": "^1.15.0",

For me it was necessary to delete the node_modules folder.

then:

yarn install

The problem happened because, @backstage/plugin-scaffolder-backend has in its package the dependency "@backstage/integration.

When we use it through the backstage, we pass another versioned object with a direct dependency declared in the package.json, if they are not the same, the problem happens.

scaffolder.ts

export default async function createPlugin(
  env: PluginEnvironment,
): Promise<Router> {
  const catalogClient = new CatalogClient({ 
    discoveryApi: env.discovery 
  });

  const integrations = ScmIntegrations.fromConfig(env.config);

  const builtInActions = createBuiltinActions({
    integrations: integrations,
    catalogClient,
    config: env.config,
    reader: env.reader,
  });

I hope it helps