From 7edb0ecbdb3f6f8ce6858d66e398a7118c6165c4 Mon Sep 17 00:00:00 2001 From: Ben Surgison Date: Fri, 18 Nov 2022 15:49:24 +0000 Subject: [PATCH] Retain original package name property --- CHANGELOG.md | 1 + __tests__/spec/migrate.js | 24 +++++++++++++++++++++++- lib/migrator/index.js | 6 +++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b02e0432f8..3d23774547 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - [#1804: Fix previewing templates with JavaScript in management pages](https://github.com/alphagov/govuk-prototype-kit/pull/1804) - [#1803: Stop installing dev dependencies when creating prototype](https://github.com/alphagov/govuk-prototype-kit/pull/1803) - [#1796: Fix link to docs in routes.js](https://github.com/alphagov/govuk-prototype-kit/pull/1796) +- [#1791: Keep existing package name when migrating](https://github.com/alphagov/govuk-prototype-kit/pull/1791) ## 13.0.0 diff --git a/__tests__/spec/migrate.js b/__tests__/spec/migrate.js index b758b141d7..392d3a47aa 100644 --- a/__tests__/spec/migrate.js +++ b/__tests__/spec/migrate.js @@ -13,7 +13,7 @@ const fixtureProjectDirectory = path.join(__dirname, '..', 'fixtures', 'test-v11 const cliPath = path.join(__dirname, '..', '..', 'bin', 'cli') const pkg = { - name: 'govuk-prototype-kit', + name: 'test-prototype', version: '11.0.0', dependencies: { 'govuk-frontend': '^4.3.1', @@ -44,6 +44,28 @@ describe('migrate test prototype', () => { }) }) + it('package.json', () => { + const pkgJson = fse.readJsonSync(path.join(projectDirectory, 'package.json')) + + const { dependencies, name, scripts } = pkgJson + + expect(Object.keys(dependencies)).toEqual([ + '@govuk-prototype-kit/step-by-step', + 'govuk-frontend', + 'govuk-prototype-kit', + 'jquery', + 'notifications-node-client' + ]) + + expect(scripts).toEqual({ + dev: 'govuk-prototype-kit dev', + serve: 'govuk-prototype-kit serve', + start: 'govuk-prototype-kit start' + }) + + expect(name).toEqual('test-prototype') + }) + it('routes.js', () => { const routesFileContents = fs.readFileSync(path.join(appDirectory, 'routes.js'), 'utf8') diff --git a/lib/migrator/index.js b/lib/migrator/index.js index 14b7ee7281..3c9391e250 100644 --- a/lib/migrator/index.js +++ b/lib/migrator/index.js @@ -95,7 +95,11 @@ const patternsToDeleteIfUnchanged = [ const prepareMigration = async (kitDependency, projectDirectory) => { await logger.setup() - await fs.writeJson(path.join(projectDirectory, 'package.json'), {}, packageJsonFormat) + // extract the name from the original package.json if it exists + const pkgJson = await fs.readJson(path.join(projectDirectory, 'package.json')) + const { name } = pkgJson + const pkgData = name ? { name } : {} + await fs.writeJson(path.join(projectDirectory, 'package.json'), pkgData, packageJsonFormat) console.log('Migrating your prototype to v13')