From 32151353283cb2e188a18bcfeaecac9f3e0d31a1 Mon Sep 17 00:00:00 2001 From: Min Kim Date: Sat, 21 Dec 2024 19:53:37 -0500 Subject: [PATCH] Remove lerna considerations for calculating baseVersion Signed-off-by: Min Kim --- packages/cli/src/commands/new/new.ts | 2 +- packages/cli/src/lib/new/utils.test.ts | 34 +++++++++++++------------- packages/cli/src/lib/new/utils.ts | 22 +++-------------- 3 files changed, 21 insertions(+), 37 deletions(-) diff --git a/packages/cli/src/commands/new/new.ts b/packages/cli/src/commands/new/new.ts index eb7d98a218..6581fb4cb9 100644 --- a/packages/cli/src/commands/new/new.ts +++ b/packages/cli/src/commands/new/new.ts @@ -57,7 +57,7 @@ export default async () => { globals, codeOwnersFilePath, }); - const options = await populateOptions(prompts, template); + const options = populateOptions(prompts, template); const tempDirs = new Array(); async function createTemporaryDirectory(name: string): Promise { diff --git a/packages/cli/src/lib/new/utils.test.ts b/packages/cli/src/lib/new/utils.test.ts index 611ad4f1b6..e759b72862 100644 --- a/packages/cli/src/lib/new/utils.test.ts +++ b/packages/cli/src/lib/new/utils.test.ts @@ -84,24 +84,24 @@ describe('resolvePackageName', () => { }); describe('populateOptions', () => { - it('should return default values if not provided', async () => { - expect( - await populateOptions({}, { targetPath: '/example' } as Template), - ).toEqual({ - id: '', - private: false, - baseVersion: '0.0.0', - owner: '', - license: 'Apache-2.0', - targetPath: '/example', - scope: '', - moduleId: '', - }); + it('should return default values if not provided', () => { + expect(populateOptions({}, { targetPath: '/example' } as Template)).toEqual( + { + id: '', + private: false, + baseVersion: '0.0.0', + owner: '', + license: 'Apache-2.0', + targetPath: '/example', + scope: '', + moduleId: '', + }, + ); }); - it('should include all non-standard global and prompt values', async () => { + it('should include all non-standard global and prompt values', () => { expect( - await populateOptions({ foo: 'bar' }, { + populateOptions({ foo: 'bar' }, { targetPath: '/example', } as Template), ).toEqual({ @@ -117,9 +117,9 @@ describe('populateOptions', () => { }); }); - it('should priority global targetPath over the targetPath specified in template', async () => { + it('should priority global targetPath over the targetPath specified in template', () => { expect( - await populateOptions({ targetPath: '/global' }, { + populateOptions({ targetPath: '/global' }, { targetPath: '/example', } as Template), ).toEqual({ diff --git a/packages/cli/src/lib/new/utils.ts b/packages/cli/src/lib/new/utils.ts index 4b7a7b83c3..84723352a7 100644 --- a/packages/cli/src/lib/new/utils.ts +++ b/packages/cli/src/lib/new/utils.ts @@ -13,8 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import fs from 'fs-extra'; -import { paths } from '../paths'; import { Template } from './types'; export interface Options extends Record { @@ -52,28 +50,14 @@ export const resolvePackageName = (options: { return plugin ? `backstage-plugin-${baseName}` : baseName; }; -async function calculateBaseVersion(baseVersion: string | undefined) { - if (!baseVersion) { - const lernaVersion = await fs - .readJson(paths.resolveTargetRoot('lerna.json')) - .then(pkg => pkg.version) - .catch(() => undefined); - if (lernaVersion) { - return lernaVersion; - } - return '0.1.0'; - } - return baseVersion; -} - -export async function populateOptions( +export function populateOptions( prompts: Record, template: Template, -): Promise { +): Options { return { id: prompts.id ?? '', private: !!prompts.private, - baseVersion: await calculateBaseVersion(prompts.baseVersion), + baseVersion: prompts.baseVersion ?? '0.1.0', owner: prompts.owner ?? '', license: prompts.license ?? 'Apache-2.0', targetPath: template.targetPath,