diff --git a/__tests__/cookie-functions.test.js b/__tests__/cookie-functions.test.mjs similarity index 99% rename from __tests__/cookie-functions.test.js rename to __tests__/cookie-functions.test.mjs index 34c0bd1432..363af7b5de 100644 --- a/__tests__/cookie-functions.test.js +++ b/__tests__/cookie-functions.test.mjs @@ -2,8 +2,9 @@ * @jest-environment jsdom */ -import * as CookieHelpers from '../src/javascripts/components/cookie-functions' -import * as Analytics from '../src/javascripts/components/analytics' +import * as CookieHelpers from '../src/javascripts/components/cookie-functions.mjs' +import * as Analytics from '../src/javascripts/components/analytics.mjs' + jest.mock('../src/javascripts/components/analytics') describe('Cookie settings', () => { diff --git a/lib/metalsmith.js b/lib/metalsmith.js index 6e5cca6e8f..c226278c0c 100644 --- a/lib/metalsmith.js +++ b/lib/metalsmith.js @@ -168,10 +168,10 @@ module.exports = metalsmith(path.resolve(__dirname, '../')) .use(hashAssets({ pattern: [ '**/*.css?(.map)', - 'javascripts/application?(-ie8).js?(.map)', - 'javascripts/example.js?(.map)', - 'javascripts/govuk-frontend.js?(.map)', - 'javascripts/head-ie8.js?(.map)', + 'javascripts/application?(-ie8).mjs?(.map)', + 'javascripts/example.mjs?(.map)', + 'javascripts/govuk-frontend.mjs?(.map)', + 'javascripts/head-ie8.mjs?(.map)', 'javascripts/vendor/*' ] })) diff --git a/lib/rollup/fixtures/src/javascripts/entry.js b/lib/rollup/fixtures/src/javascripts/entry.mjs similarity index 54% rename from lib/rollup/fixtures/src/javascripts/entry.js rename to lib/rollup/fixtures/src/javascripts/entry.mjs index 9e18ffa861..11e6ea1147 100644 --- a/lib/rollup/fixtures/src/javascripts/entry.js +++ b/lib/rollup/fixtures/src/javascripts/entry.mjs @@ -1,4 +1,4 @@ -import example from './example.js' +import example from './example.mjs' export default () => { return example diff --git a/lib/rollup/fixtures/src/javascripts/example.js b/lib/rollup/fixtures/src/javascripts/example.mjs similarity index 100% rename from lib/rollup/fixtures/src/javascripts/example.js rename to lib/rollup/fixtures/src/javascripts/example.mjs diff --git a/lib/rollup/index.test.js b/lib/rollup/index.test.js index f6f8de8ba3..30670d69b0 100644 --- a/lib/rollup/index.test.js +++ b/lib/rollup/index.test.js @@ -19,7 +19,7 @@ describe('Rollup plugin', () => { .destination(destination) // Rollup example - .use(rollup('javascripts/entry.js', 'entry')) + .use(rollup('javascripts/entry.mjs', 'entry')) // Build .build((err, files) => { @@ -33,18 +33,18 @@ describe('Rollup plugin', () => { }) it('compiles JavaScript to Metalsmith files', () => { - expect(output[normalize('javascripts/entry.js')]) + expect(output[normalize('javascripts/entry.mjs')]) .toMatchObject({ contents: expect.any(Buffer) }) - expect(output[normalize('javascripts/example.js')]) + expect(output[normalize('javascripts/example.mjs')]) .toMatchObject({ contents: expect.any(Buffer) }) }) it('bundles ESM modules to single IIFE file (minified)', () => { - expect(output[normalize('javascripts/entry.js')].contents.toString()) + expect(output[normalize('javascripts/entry.mjs')].contents.toString()) .toEqual(outdent` var entry=function(){"use strict";return()=>"example"}(); - //# sourceMappingURL=entry.js.map + //# sourceMappingURL=entry.mjs.map `) }) }) diff --git a/src/javascripts/application-ie8.js b/src/javascripts/application-ie8.mjs similarity index 68% rename from src/javascripts/application-ie8.js rename to src/javascripts/application-ie8.mjs index b6807d83be..7fb41ff542 100644 --- a/src/javascripts/application-ie8.js +++ b/src/javascripts/application-ie8.mjs @@ -1,7 +1,7 @@ -import { nodeListForEach } from './components/helpers.js' -import Example from './components/example.js' -import AppTabs from './components/tabs.js' -import OptionsTable from './components/options-table.js' +import { nodeListForEach } from './components/helpers.mjs' +import Example from './components/example.mjs' +import AppTabs from './components/tabs.mjs' +import OptionsTable from './components/options-table.mjs' // Initialise example frames var $examples = document.querySelectorAll('[data-module="app-example-frame"]') diff --git a/src/javascripts/application.js b/src/javascripts/application.mjs similarity index 71% rename from src/javascripts/application.js rename to src/javascripts/application.mjs index 8a7ae6b37e..dd8e96e49a 100644 --- a/src/javascripts/application.js +++ b/src/javascripts/application.mjs @@ -1,15 +1,15 @@ -import CookieBanner from './components/cookie-banner.js' -import BackToTop from './components/back-to-top.js' -import { nodeListForEach } from './components/helpers.js' -import Example from './components/example.js' -import AppTabs from './components/tabs.js' -import Copy from './components/copy.js' -import Navigation from './components/navigation.js' -import Search from './components/search.js' -import OptionsTable from './components/options-table.js' -import { getConsentCookie, isValidConsentCookie } from './components/cookie-functions.js' -import Analytics from './components/analytics.js' -import CookiesPage from './components/cookies-page.js' +import CookieBanner from './components/cookie-banner.mjs' +import BackToTop from './components/back-to-top.mjs' +import { nodeListForEach } from './components/helpers.mjs' +import Example from './components/example.mjs' +import AppTabs from './components/tabs.mjs' +import Copy from './components/copy.mjs' +import Navigation from './components/navigation.mjs' +import Search from './components/search.mjs' +import OptionsTable from './components/options-table.mjs' +import { getConsentCookie, isValidConsentCookie } from './components/cookie-functions.mjs' +import Analytics from './components/analytics.mjs' +import CookiesPage from './components/cookies-page.mjs' // Initialise cookie banner var $cookieBanner = document.querySelector('[data-module="govuk-cookie-banner"]') diff --git a/src/javascripts/components/analytics.js b/src/javascripts/components/analytics.mjs similarity index 100% rename from src/javascripts/components/analytics.js rename to src/javascripts/components/analytics.mjs diff --git a/src/javascripts/components/back-to-top.js b/src/javascripts/components/back-to-top.mjs similarity index 100% rename from src/javascripts/components/back-to-top.js rename to src/javascripts/components/back-to-top.mjs diff --git a/src/javascripts/components/cookie-banner.js b/src/javascripts/components/cookie-banner.mjs similarity index 97% rename from src/javascripts/components/cookie-banner.js rename to src/javascripts/components/cookie-banner.mjs index 2df085c314..5b24955177 100644 --- a/src/javascripts/components/cookie-banner.js +++ b/src/javascripts/components/cookie-banner.mjs @@ -1,7 +1,7 @@ -import * as CookieFunctions from './cookie-functions.js' +import * as CookieFunctions from './cookie-functions.mjs' import 'govuk-frontend/govuk/vendor/polyfills/Function/prototype/bind' import 'govuk-frontend/govuk/vendor/polyfills/Event' -import { nodeListForEach } from './helpers.js' +import { nodeListForEach } from './helpers.mjs' var cookieBannerAcceptSelector = '.js-cookie-banner-accept' var cookieBannerRejectSelector = '.js-cookie-banner-reject' diff --git a/src/javascripts/components/cookie-functions.js b/src/javascripts/components/cookie-functions.mjs similarity index 99% rename from src/javascripts/components/cookie-functions.js rename to src/javascripts/components/cookie-functions.mjs index 73ffc622de..58b2290afb 100644 --- a/src/javascripts/components/cookie-functions.js +++ b/src/javascripts/components/cookie-functions.mjs @@ -12,7 +12,7 @@ * The consent cookie version is defined in cookie-banner.njk */ -import Analytics from './analytics.js' +import Analytics from './analytics.mjs' /* Name of the cookie to save users cookie preferences to. */ var CONSENT_COOKIE_NAME = 'design_system_cookies_policy' diff --git a/src/javascripts/components/cookies-page.js b/src/javascripts/components/cookies-page.mjs similarity index 97% rename from src/javascripts/components/cookies-page.js rename to src/javascripts/components/cookies-page.mjs index eede0e2e18..978ae1a582 100644 --- a/src/javascripts/components/cookies-page.js +++ b/src/javascripts/components/cookies-page.mjs @@ -1,5 +1,5 @@ -import { getConsentCookie, setConsentCookie } from './cookie-functions.js' -import { nodeListForEach } from './helpers.js' +import { getConsentCookie, setConsentCookie } from './cookie-functions.mjs' +import { nodeListForEach } from './helpers.mjs' function CookiesPage ($module) { this.$module = $module diff --git a/src/javascripts/components/copy.js b/src/javascripts/components/copy.mjs similarity index 100% rename from src/javascripts/components/copy.js rename to src/javascripts/components/copy.mjs diff --git a/src/javascripts/components/example.js b/src/javascripts/components/example.mjs similarity index 100% rename from src/javascripts/components/example.js rename to src/javascripts/components/example.mjs diff --git a/src/javascripts/components/helpers.js b/src/javascripts/components/helpers.mjs similarity index 80% rename from src/javascripts/components/helpers.js rename to src/javascripts/components/helpers.mjs index 325fb10ea6..65414aed0a 100644 --- a/src/javascripts/components/helpers.js +++ b/src/javascripts/components/helpers.mjs @@ -2,7 +2,7 @@ * This seems to fail in IE8, requires more investigation. * See: https://github.com/imagitama/nodelist-foreach-polyfill */ -function nodeListForEach (nodes, callback) { +export function nodeListForEach (nodes, callback) { if (window.NodeList.prototype.forEach) { return nodes.forEach(callback) } @@ -10,7 +10,3 @@ function nodeListForEach (nodes, callback) { callback.call(window, nodes[i], i, nodes) } } - -export { - nodeListForEach -} diff --git a/src/javascripts/components/navigation.js b/src/javascripts/components/navigation.mjs similarity index 99% rename from src/javascripts/components/navigation.js rename to src/javascripts/components/navigation.mjs index 5e59c37b62..c2b63ef559 100644 --- a/src/javascripts/components/navigation.js +++ b/src/javascripts/components/navigation.mjs @@ -1,5 +1,5 @@ import 'govuk-frontend/govuk/vendor/polyfills/Element/prototype/classList' -import { nodeListForEach } from './helpers.js' +import { nodeListForEach } from './helpers.mjs' var navActiveClass = 'app-navigation--active' var navMenuButtonActiveClass = 'govuk-header__menu-button--open' diff --git a/src/javascripts/components/options-table.js b/src/javascripts/components/options-table.mjs similarity index 100% rename from src/javascripts/components/options-table.js rename to src/javascripts/components/options-table.mjs diff --git a/src/javascripts/components/search.js b/src/javascripts/components/search.mjs similarity index 99% rename from src/javascripts/components/search.js rename to src/javascripts/components/search.mjs index e59db16ba6..b9f33120e1 100644 --- a/src/javascripts/components/search.js +++ b/src/javascripts/components/search.mjs @@ -2,7 +2,7 @@ import accessibleAutocomplete from 'accessible-autocomplete' import lunr from 'lunr' -import { trackSearchResults, trackConfirm } from './search.tracking.js' +import { trackSearchResults, trackConfirm } from './search.tracking.mjs' // CONSTANTS var TIMEOUT = 10 // Time to wait before giving up fetching the search index diff --git a/src/javascripts/components/search.tracking.js b/src/javascripts/components/search.tracking.mjs similarity index 93% rename from src/javascripts/components/search.tracking.js rename to src/javascripts/components/search.tracking.mjs index 49a8cf0f11..c25ef10332 100644 --- a/src/javascripts/components/search.tracking.js +++ b/src/javascripts/components/search.tracking.mjs @@ -14,7 +14,7 @@ function stripPossiblePII (string) { return string } -function trackConfirm (searchQuery, searchResults, result) { +export function trackConfirm (searchQuery, searchResults, result) { if (window.DO_NOT_TRACK_ENABLED) { return } @@ -51,7 +51,7 @@ function trackConfirm (searchQuery, searchResults, result) { }) } -function trackSearchResults (searchQuery, searchResults) { +export function trackSearchResults (searchQuery, searchResults) { if (window.DO_NOT_TRACK_ENABLED) { return } @@ -81,5 +81,3 @@ function trackSearchResults (searchQuery, searchResults) { } }) } - -export { trackConfirm, trackSearchResults } diff --git a/src/javascripts/components/tabs.js b/src/javascripts/components/tabs.mjs similarity index 99% rename from src/javascripts/components/tabs.js rename to src/javascripts/components/tabs.mjs index 4cf0526668..e3752712dd 100644 --- a/src/javascripts/components/tabs.js +++ b/src/javascripts/components/tabs.mjs @@ -1,7 +1,7 @@ import 'govuk-frontend/govuk/vendor/polyfills/Function/prototype/bind' import 'govuk-frontend/govuk/vendor/polyfills/Element/prototype/classList' import 'govuk-frontend/govuk/vendor/polyfills/Event' -import { nodeListForEach } from './helpers.js' +import { nodeListForEach } from './helpers.mjs' /** * The naming of things is a little complicated in here. diff --git a/src/javascripts/example.js b/src/javascripts/example.mjs similarity index 100% rename from src/javascripts/example.js rename to src/javascripts/example.mjs diff --git a/src/javascripts/govuk-frontend.js b/src/javascripts/govuk-frontend.mjs similarity index 99% rename from src/javascripts/govuk-frontend.js rename to src/javascripts/govuk-frontend.mjs index 095acc0419..82ae24143c 100644 --- a/src/javascripts/govuk-frontend.js +++ b/src/javascripts/govuk-frontend.mjs @@ -1,4 +1,5 @@ import { initAll } from 'govuk-frontend' + initAll({ // auto focusing the error summary and notification banner is not useful // when used in examples, and causes the viewport to scroll diff --git a/src/javascripts/head-ie8.js b/src/javascripts/head-ie8.mjs similarity index 100% rename from src/javascripts/head-ie8.js rename to src/javascripts/head-ie8.mjs diff --git a/src/styles/page-template/block-areas/index.njk b/src/styles/page-template/block-areas/index.njk index 2840539605..7f0cdc246a 100644 --- a/src/styles/page-template/block-areas/index.njk +++ b/src/styles/page-template/block-areas/index.njk @@ -17,7 +17,7 @@ stylesheets: {% for stylesheet in stylesheets %} @@ -88,7 +88,7 @@ stylesheets: block: bodyEnd {{ super() }} {# Since we’re not extending the Design System layout we need to add this manually #} - + {% endblock %} @@ -156,7 +156,7 @@ ignore_in_sitemap: true {% endblock %} {% block bodyEnd %} - + {% endblock %} @@ -21,7 +21,7 @@ layout: false {% endblock %} {% block bodyEnd %} - + @@ -46,12 +46,12 @@ {% block footer %}{% endblock %} {% block bodyEnd %} - + - + {% endblock %} diff --git a/views/layouts/layout-example-full-page-govuk.njk b/views/layouts/layout-example-full-page-govuk.njk index 7969d24266..e80888c53a 100644 --- a/views/layouts/layout-example-full-page-govuk.njk +++ b/views/layouts/layout-example-full-page-govuk.njk @@ -11,7 +11,7 @@ {%- endfor %} {% endblock %} @@ -26,8 +26,8 @@ {{ contents | safe }} {% endblock %} {% block bodyEnd %} - - + + {% endblock %} @@ -28,8 +28,8 @@ {{ contents | safe }} {% endblock %} {% block bodyEnd %} - - + + {% endblock %} @@ -40,8 +40,8 @@ {% endblock %} {% block bodyEnd %} - - + +