Skip to content

Commit

Permalink
Merge pull request #1791 from alphagov/retain-original-package-name-p…
Browse files Browse the repository at this point in the history
…roperty

Keep existing package name when migrating
  • Loading branch information
BenSurgisonGDS authored Nov 25, 2022
2 parents 7082235 + 7edb0ec commit 5e2f79e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 23 additions & 1 deletion __tests__/spec/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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')

Expand Down
6 changes: 5 additions & 1 deletion lib/migrator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down

0 comments on commit 5e2f79e

Please sign in to comment.