diff --git a/packages/cli/src/commands/create-plugin/createPlugin.ts b/packages/cli/src/commands/create-plugin/createPlugin.ts index b603e732b8..f54a62f613 100644 --- a/packages/cli/src/commands/create-plugin/createPlugin.ts +++ b/packages/cli/src/commands/create-plugin/createPlugin.ts @@ -28,7 +28,7 @@ import { getCodeownersFilePath, } from '../../lib/codeowners'; import { paths } from '../../lib/paths'; -import { versions } from '../../lib/version'; +import { packageVersions } from '../../lib/version'; import { Task, templatingTask } from '../../lib/tasks'; const exec = promisify(execCb); @@ -269,7 +269,7 @@ export default async (cmd: Command) => { privatePackage, npmRegistry, }, - versions, + packageVersions, ); Task.section('Moving to final location'); diff --git a/packages/cli/src/lib/diff/read.ts b/packages/cli/src/lib/diff/read.ts index a4a7355d2d..d37dfe4b03 100644 --- a/packages/cli/src/lib/diff/read.ts +++ b/packages/cli/src/lib/diff/read.ts @@ -24,7 +24,7 @@ import handlebars from 'handlebars'; import recursiveReadDir from 'recursive-readdir'; import { paths } from '../paths'; import { FileDiff } from './types'; -import { versions } from '../../lib/version'; +import { packageVersions } from '../../lib/version'; export type TemplatedFile = { path: string; @@ -43,9 +43,9 @@ async function readTemplateFile( return handlebars.compile(contents)(templateVars, { helpers: { - version(name: string) { - if (versions[name]) { - return versions[name]; + version(name: keyof typeof packageVersions) { + if (name in packageVersions) { + return packageVersions[name]; } throw new Error(`No version available for package ${name}`); }, diff --git a/packages/cli/src/lib/tasks.test.ts b/packages/cli/src/lib/tasks.test.ts index a42902c60b..88d8050290 100644 --- a/packages/cli/src/lib/tasks.test.ts +++ b/packages/cli/src/lib/tasks.test.ts @@ -50,7 +50,7 @@ describe('templatingTask', () => { tmplDir, destDir, { - version: '0.0.0', + pluginVersion: '0.0.0', }, { 'mock-pkg': '0.1.2' }, ); diff --git a/packages/cli/src/lib/version.ts b/packages/cli/src/lib/version.ts index 5cc3eb7fbb..b2b793717d 100644 --- a/packages/cli/src/lib/version.ts +++ b/packages/cli/src/lib/version.ts @@ -39,7 +39,7 @@ import { version as devUtils } from '@backstage/dev-utils/package.json'; import { version as testUtils } from '@backstage/test-utils/package.json'; import { version as theme } from '@backstage/theme/package.json'; -export const versions: { [name: string]: string } = { +export const packageVersions = { '@backstage/backend-common': backendCommon, '@backstage/cli': cli, '@backstage/config': config, diff --git a/packages/create-app/src/createApp.ts b/packages/create-app/src/createApp.ts index c0874d4032..775d53dfdc 100644 --- a/packages/create-app/src/createApp.ts +++ b/packages/create-app/src/createApp.ts @@ -22,7 +22,6 @@ import inquirer, { Answers, Question } from 'inquirer'; import { exec as execCb } from 'child_process'; import { resolve as resolvePath } from 'path'; import { findPaths } from '@backstage/cli-common'; -import { versions } from './versions'; import os from 'os'; import { Task, templatingTask } from './lib/tasks'; @@ -133,7 +132,7 @@ export default async (cmd: Command): Promise => { await createTemporaryAppFolder(tempDir); Task.section('Preparing files'); - await templatingTask(templateDir, tempDir, answers, versions); + await templatingTask(templateDir, tempDir, answers); Task.section('Moving to final location'); await moveApp(tempDir, appDir, answers.name); diff --git a/packages/create-app/src/lib/tasks.ts b/packages/create-app/src/lib/tasks.ts index 73db175709..b615692830 100644 --- a/packages/create-app/src/lib/tasks.ts +++ b/packages/create-app/src/lib/tasks.ts @@ -20,6 +20,7 @@ import handlebars from 'handlebars'; import ora from 'ora'; import { basename, dirname } from 'path'; import recursive from 'recursive-readdir'; +import { packageVersions } from './versions'; const TASK_NAME_MAX_LENGTH = 14; @@ -68,7 +69,6 @@ export async function templatingTask( templateDir: string, destinationDir: string, context: any, - versions: { [name: string]: string }, ) { const files = await recursive(templateDir).catch(error => { throw new Error(`Failed to read template directory: ${error.message}`); @@ -88,9 +88,9 @@ export async function templatingTask( { name: basename(destination), ...context }, { helpers: { - version(name: string) { - if (versions[name]) { - return versions[name]; + version(name: keyof typeof packageVersions) { + if (name in packageVersions) { + return packageVersions[name]; } throw new Error(`No version available for package ${name}`); }, diff --git a/packages/create-app/src/versions.ts b/packages/create-app/src/lib/versions.ts similarity index 99% rename from packages/create-app/src/versions.ts rename to packages/create-app/src/lib/versions.ts index ed03903469..196e0004c1 100644 --- a/packages/create-app/src/versions.ts +++ b/packages/create-app/src/lib/versions.ts @@ -54,7 +54,7 @@ import { version as pluginUserSettings } from '@backstage/plugin-user-settings/p import { version as testUtils } from '@backstage/test-utils/package.json'; import { version as theme } from '@backstage/theme/package.json'; -export const versions = { +export const packageVersions = { '@backstage/backend-common': backendCommon, '@backstage/catalog-model': catalogModel, '@backstage/cli': cli,