Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep existing package name when migrating #1791

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

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