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

Split config, lib and tasks into npm packages #3399

Merged
merged 14 commits into from
Apr 18, 2023
Merged

Conversation

colinrotherham
Copy link
Contributor

@colinrotherham colinrotherham commented Mar 22, 2023

This PR partially implements:

Where each package directory is set up with:

  1. Separate package.json to manage dependencies
  2. Separate tsconfig.json for type checking "squiggles" including tests
  3. Separate npm workspace, e.g. import { npm } from 'govuk-frontend-tasks'

To confirm everything works correctly this branch builds on:

Before

Everything at project level

├── app
├── bin
├── config
├── dist
├── docs
├── lib
├── package
├── src
└── tasks

After

Some dependencies (app, config, lib, tasks) moved to ./shared

├── app
├── bin
├── dist
├── docs
├── package
├── shared
│   ├── config
│   ├── lib
│   └── tasks
└── src

@colinrotherham colinrotherham requested a review from a team as a code owner March 22, 2023 14:48
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3399 March 22, 2023 14:48 Inactive
@colinrotherham colinrotherham changed the base branch from main to build-tasks-gulpfile-app March 22, 2023 14:48
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3399 March 22, 2023 15:24 Inactive
@colinrotherham colinrotherham linked an issue Mar 22, 2023 that may be closed by this pull request
7 tasks
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3399 March 22, 2023 15:28 Inactive
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-app branch from 09453b3 to f9c4970 Compare March 22, 2023 16:43
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3399 March 22, 2023 17:00 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3399 March 22, 2023 17:32 Inactive
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-app branch 2 times, most recently from edeb6d7 to a8b8cd6 Compare March 23, 2023 14:03
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-app branch from a8b8cd6 to 3959731 Compare March 23, 2023 15:20
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3399 March 23, 2023 15:20 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3399 March 23, 2023 17:21 Inactive
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-app branch 2 times, most recently from b5ede3e to 7e7840b Compare March 24, 2023 17:55
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3399 March 24, 2023 18:51 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3399 March 27, 2023 08:44 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3399 March 27, 2023 08:52 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3399 April 13, 2023 16:52 Inactive
Copy link
Member

@romaricpascal romaricpascal left a comment

Choose a reason for hiding this comment

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

Halfway through and looking nice so far, only one major comment 😊 I'll carry on tomorrow morning (note to self: just gone through "Add govuk-frontend-lib helpers package export").

/**
* Puppeteer browser downloader
*/
export async function download () {
Copy link
Member

Choose a reason for hiding this comment

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

I like that this has moved from the browser tasks thanks to the reorganising 😍

lib/index.js Outdated
Comment on lines 1 to 8
const helpers = require('./helpers')

/**
* Shared library
*/
module.exports = {
helpers
}
Copy link
Member

Choose a reason for hiding this comment

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

issue I think this and the helpers/index.js file get in the way more than they help the usage of the lib workspace. Instead of a single import for reaching a specific helper, now we need two instructions: first to import govuk-frontend-lib then to destructure helpers.xxx. I think it'd be simpler to just import directly from govuk-frontend-lib/helpers/xxx.js instead (that reorganisation is super neat), even if it means a little search and replace if we decide to move things inside lib.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep totally agree, there's a later commit that separated "helpers" from "lib" so we could flatten this

I'm happy with destructuring though as it's similar to const { dirname, join } = require('path')

But if we want to avoid it we have some options:

Namespace-style objects

import { files } from 'govuk-frontend-lib'

files.getComponentsData()   // versus getComponentsData()
files.getDirectories()      // versus getDirectories()
files.getFullPageExamples() // versus getFullPageExamples()

Named package exports

import { getComponentsData, getDirectories, getFullPageExamples } from 'govuk-frontend-lib/files'

getComponentsData()
getDirectories()
getFullPageExamples()

Let me know

Copy link
Member

Choose a reason for hiding this comment

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

Replied on the main thread of comments 😄

@romaricpascal
Copy link
Member

Move to workspace makes imports so much tidier without the ../../... Splitting helpers and lib is also a nice way to distinguish what's build/test code and what's not 🙌🏻 Two little things for me:

  • As I've mentioned in this comment, I think index.js files just add more steps for using the lib and helpers. They're one extra file to maintain and lead to extra destructuring to access the actual functions. I'd prefer we use your proposition for named package exports, @colinrotherham, as it both clarifies where the code lies (for people that may not be looking at it in an IDE with shortcuts to move around) and simplifies the access to the function.
  • I'm not sure of the benefits of moving things into shared. We don't have that much complexity in the folders of the project that our root directory is crowded. Having everything at the root of the repository makes it easier to have a view of what's in the repository.

Documentation wise, would it be worth having a little README file in each workspace to complement the docs/application-architecture.md with a quick description of what we want to set in each package?

@colinrotherham
Copy link
Contributor Author

@romaricpascal Brill, I'll add those named entries

Do you want READMEs as a blocker for this PR or something we can improve later?

Using shared came from @36degrees in #3399 (comment) instead of npm workspaces packages:

@romaricpascal
Copy link
Member

I wasn't super strongly against shared so happy to keep it and save moving more code around.

We can add READMEs later, I think, but a line in application-architecture.md to describe shared and more importantly shared/helpers would be good for that PR (had missed that it was missing looking at things commit by commit 😬 ).

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3399 April 14, 2023 11:50 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3399 April 14, 2023 12:03 Inactive
@colinrotherham
Copy link
Contributor Author

colinrotherham commented Apr 14, 2023

@romaricpascal I've added commit 7dbff83 for subpath package exports

Let me know if you're happy with the application-architecture.md edits

Thanks 😊

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3399 April 14, 2023 15:29 Inactive
Was nice to use `URLSearchParams` (coming to Express in future) but the community types don’t expect that
Running `npm run build:types` (optional) will now check the review app
Include "Review app" in `npm run build:types` check
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3399 April 18, 2023 08:51 Inactive
Copy link
Member

@romaricpascal romaricpascal left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks for the amends! 🙌🏻 ⛵

@colinrotherham colinrotherham merged commit ed335d6 into main Apr 18, 2023
@colinrotherham colinrotherham deleted the npm-workspaces branch April 18, 2023 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

Split project into separate app, config, lib and tasks packages
5 participants