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

Build tasks: Create tasks per target without --destination #3372

Merged
merged 10 commits into from
Mar 23, 2023

Conversation

colinrotherham
Copy link
Contributor

@colinrotherham colinrotherham commented Mar 9, 2023

This PR removes our build target --destination flag

We didn't actually use it and there's a lot of complexity including/moving/renaming files via:

isPackage
isPublic
isDist
isDev

This helps to unblock:

Where we'll need to build the JavaScript twice to include version numbers:

1x as Rollup AMD module bundles
1x as Rollup ES module bundles

Task options

All tasks like compileJavaScripts() now accept options to show what's happening:

import { compileJavaScripts } from './tasks/compile-javascripts.mjs'

// Compile GOV.UK Frontend JavaScript (AMD modules)
compileJavaScripts('**/!(*.test).mjs', {
  srcPath: join(paths.src, 'govuk'),
  destPath: join(paths.package, 'govuk'),

  filePath (file) {
    return join(file.dir, `${file.name}.js`)
  }
}),

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3372 March 9, 2023 20:22 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3372 March 10, 2023 07:12 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3372 March 10, 2023 10:42 Inactive
@colinrotherham colinrotherham requested a review from a team as a code owner March 10, 2023 16:40
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3372 March 10, 2023 16:53 Inactive
@colinrotherham colinrotherham changed the base branch from build-tasks to review-app-esm March 13, 2023 10:13
@colinrotherham colinrotherham changed the title [WIP] Build tasks: Create tasks per target without --destination Build tasks: Create tasks per target without --destination Mar 13, 2023
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3372 March 13, 2023 10:46 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3372 March 13, 2023 12:24 Inactive
Base automatically changed from review-app-esm to main March 13, 2023 13:46
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3372 March 13, 2023 14:03 Inactive
@colinrotherham colinrotherham changed the base branch from main to build-tasks March 13, 2023 14:03
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3372 March 14, 2023 13:17 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3372 March 14, 2023 13:31 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3372 March 14, 2023 16:47 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3372 March 15, 2023 09:28 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3372 March 22, 2023 10:47 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3372 March 22, 2023 11:08 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3372 March 22, 2023 16:34 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3372 March 22, 2023 16:39 Inactive
Copy link
Contributor

@domoscargin domoscargin left a comment

Choose a reason for hiding this comment

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

Think this looks great - to my eye this simplifies these workflows a bunch. And thank you for a really easy-to-follow set of commits - despite quite a large overall codebase change.

Coupla questions in addition to a few small separate comments:

  1. I haven't dug into the tests - are we confident they'd detect any issues with this approach? Anything we can take the opportunity to shore up?
  2. This is a fairly big PR. Feels like we could maybe separate out the gulp-task-listing (and maybe the browser tasks?) as they don't seem to rely on --destination?

import { getListing } from '../lib/file-helper.js'
import { componentPathToModuleName } from '../lib/helper-functions.js'

import { writeAsset } from './compile-assets.mjs'
import { isDist, isPackage, isPublic } from './task-arguments.mjs'
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

})

// Compile JavaScript ESM to CommonJS
const bundled = await bundle[!isPackage ? 'generate' : 'write']({
const bundled = await bundle[moduleDestPath.endsWith('.min.js') ? 'generate' : 'write']({
Copy link
Contributor

Choose a reason for hiding this comment

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

Neat!

export const isDist = target === 'dist'
export const isDev = isPublic && tasks.includes('dev')
// Check for development task
export const isDev = tasks.includes('dev')
Copy link
Contributor

Choose a reason for hiding this comment

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

Ha, neat!

@@ -34,7 +34,7 @@ npm scripts are defined in `package.json`. These trigger a number of Gulp tasks.
**`npm run build:app` will do the following:**

- clean the `./public` folder
- output files into `./public`, or another location via the `--destination` flag
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't do this personally, but is it worth checking whether anybody else makes use of --destination to, say, build to a temp directory while developing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've asked on Slack 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking good for removal so far

Split out from this PR now, but I'm happy with destPath being configurable per destination:

Copy link
Contributor

Choose a reason for hiding this comment

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

I think if nobody's doing anything other than standard builds anyway, let's not bother. We can always pop it back in quick enough if folks complain.

@@ -63,9 +63,9 @@ npm scripts are defined in `package.json`. These trigger a number of Gulp tasks.

## Gulp tasks

Gulp tasks are defined in `gulpfile.js` and .`/tasks/gulp/` folder.
Gulp tasks are defined in `gulpfile.mjs` and .`/tasks/` folder.
Copy link
Contributor

Choose a reason for hiding this comment

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

Am I missing something about why the full stop is outside of the <code> element here?

Also, can we tweak it to either "and the ./tasks/ folder" or "and ./tasks/"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm how strange, I didn't even notice. It's been in since 2017 2e64f5b#diff-06cac645496a5082a65db61580c0d7b2d3890e8d164ca7f4d1193e8a28f76a68R92

To avoid lots of rebasing, mind if we add a follow up typo PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@domoscargin Full stop removal included in edeb6d7

package.json Outdated
@@ -55,7 +55,6 @@
"gulp": "^4.0.2",
"gulp-cli": "^2.3.0",
"gulp-rename": "^2.0.0",
"gulp-task-listing": "^1.1.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

🔥

Copy link
Contributor Author

@colinrotherham colinrotherham Mar 23, 2023

Choose a reason for hiding this comment

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

Split out into PR #3402

gulpfile.mjs Outdated
destPath: paths.dist
})
))
gulp.task('build:app', build.app())
Copy link
Contributor

Choose a reason for hiding this comment

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

So satisfying!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Split out into PR #3403

@colinrotherham
Copy link
Contributor Author

colinrotherham commented Mar 23, 2023

Thanks for the review @domoscargin

  1. I haven't dug into the tests - are we confident they'd detect any issues with this approach? Anything we can take the opportunity to shore up?

Tests wise we've still got the postbuild:* npm scripts for package/dist. For the review app, all the Jest behaviour and component tests (plus Percy) hit http://localhost:3000 so we'll see failures for missing styles/scripts/assets

  1. This is a fairly big PR. Feels like we could maybe separate out the gulp-task-listing (and maybe the browser tasks?) as they don't seem to rely on --destination?

I've dropped a few commits from this PR branch and moved them to:

Copy link
Contributor

@domoscargin domoscargin left a comment

Choose a reason for hiding this comment

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

Awesome, nice to simplify things.

I've diffed this against package, dist and public folders and there are no changes in output, so I think this is ready to go.

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.

3 participants