alphagov / govuk-prototype-kit

Rapidly create HTML prototypes of GOV.UK services
https://prototype-kit.service.gov.uk
MIT License
306 stars 236 forks source link

Use ECMAScript Modules #1413

Open lfdebrux opened 2 years ago

lfdebrux commented 2 years ago

What

Convert Node.js files in the Prototype Kit to use ECMAScript import, instead of CommonJS require, and set "type": "module" in package.json.

Why

New users familiar with using import to package their JavaScript code will find it confusing that the Kit uses the old method.

ECMAScript Modules are now the standard way to package JavaScript code, and Node.js and GOV.UK Frontend are both moving to prefer import over require. [1, 2]. Using ECMAScript modules will also let us use top-level awaits [3], which makes writing asynchronous scripts easier.

This change shouldn't affect users. Out of scope of this ticket is changing how JavaScript served to browsers by the kit is written.

Who needs to work on this

Developer

Who needs to review this

Developer

Done when

joelanman commented 1 year ago

Relevant thread:

ruthhammond commented 1 year ago

To be broken down by @HannahJMWood and @ollie-b-gds into tasks so it can be picked off in pieces over time