From ea586cd6ae2f3f0b4550fb67ebd13ec0527cf62c Mon Sep 17 00:00:00 2001 From: Max Duval Date: Mon, 24 Jun 2024 15:15:15 +0100 Subject: [PATCH 1/2] refactor: all require are static --- tools/__tasks__/compile/conf/index.js | 7 +++++-- tools/__tasks__/compile/css/index.dev.js | 13 ++++++++---- tools/__tasks__/compile/css/index.js | 13 ++++++++---- tools/__tasks__/compile/data/index.dev.js | 10 +++++++--- tools/__tasks__/compile/data/index.js | 11 +++++++--- tools/__tasks__/compile/data/index.watch.js | 10 +++++++--- tools/__tasks__/compile/hash/index.js | 3 ++- tools/__tasks__/compile/images/icons.js | 2 -- tools/__tasks__/compile/images/index.js | 13 ++++++++---- tools/__tasks__/compile/index.dev.js | 16 ++++++++++----- tools/__tasks__/compile/index.js | 19 ++++++++++++------ tools/__tasks__/compile/index.watch.js | 16 ++++++++++----- .../compile/javascript/index.atoms.js | 10 +++++++--- .../__tasks__/compile/javascript/index.dev.js | 20 ++++++++++++------- tools/__tasks__/compile/javascript/index.js | 19 ++++++++++++------ .../compile/javascript/index.watch.js | 13 ++++++++---- .../compile/javascript/webpack-atoms.js | 6 ++---- .../compile/javascript/webpack.dev.js | 6 ++---- tools/__tasks__/compile/javascript/webpack.js | 6 ++---- tools/__tasks__/test/index.js | 7 +++++-- tools/__tasks__/validate-head/index.js | 7 +++++-- tools/__tasks__/validate/index.js | 13 ++++++++---- 22 files changed, 158 insertions(+), 82 deletions(-) diff --git a/tools/__tasks__/compile/conf/index.js b/tools/__tasks__/compile/conf/index.js index 9e2898d5650c..24a4597c400f 100644 --- a/tools/__tasks__/compile/conf/index.js +++ b/tools/__tasks__/compile/conf/index.js @@ -1,9 +1,12 @@ +const copy = require('./copy.js'); +const inlineSVGs = require('../inline-svgs/index.js'); + const task = { description: 'Compile assets for template rendering in Play', task: [ // prettier: multi-line - require('./copy'), - require('../inline-svgs'), + copy, + inlineSVGs, ], }; diff --git a/tools/__tasks__/compile/css/index.dev.js b/tools/__tasks__/compile/css/index.dev.js index ab0f461335ee..6ca6e39d66c3 100644 --- a/tools/__tasks__/compile/css/index.dev.js +++ b/tools/__tasks__/compile/css/index.dev.js @@ -1,11 +1,16 @@ +const clean = require('./clean.js'); +const mkdir = require('./mkdir.js'); +const images = require('../images/index.js'); +const sass = require('./sass.js'); + const task = { description: 'Compile CSS', task: [ // prettier: multi-line - require('./clean'), - require('./mkdir'), - require('../images'), - require('./sass'), + clean, + mkdir, + images, + sass, ], }; diff --git a/tools/__tasks__/compile/css/index.js b/tools/__tasks__/compile/css/index.js index ab0f461335ee..6ca6e39d66c3 100644 --- a/tools/__tasks__/compile/css/index.js +++ b/tools/__tasks__/compile/css/index.js @@ -1,11 +1,16 @@ +const clean = require('./clean.js'); +const mkdir = require('./mkdir.js'); +const images = require('../images/index.js'); +const sass = require('./sass.js'); + const task = { description: 'Compile CSS', task: [ // prettier: multi-line - require('./clean'), - require('./mkdir'), - require('../images'), - require('./sass'), + clean, + mkdir, + images, + sass, ], }; diff --git a/tools/__tasks__/compile/data/index.dev.js b/tools/__tasks__/compile/data/index.dev.js index 0219475dc03e..6e4e1b950c5e 100644 --- a/tools/__tasks__/compile/data/index.dev.js +++ b/tools/__tasks__/compile/data/index.dev.js @@ -1,10 +1,14 @@ +const clean = require('./clean.js'); +const download = require('./download.js'); +const amp = require('./amp.js'); + const task = { description: 'Clean download and build data assets (dev)', task: [ // prettier: multi-line - require('./clean'), - require('./download'), - require('./amp'), + clean, + download, + amp, ], }; diff --git a/tools/__tasks__/compile/data/index.js b/tools/__tasks__/compile/data/index.js index ed94c89af481..ee7ab43f2582 100644 --- a/tools/__tasks__/compile/data/index.js +++ b/tools/__tasks__/compile/data/index.js @@ -1,10 +1,15 @@ +const clean = require('./clean.js'); +const download = require('./download.js'); +const amp = require('./amp.js'); + const task = { description: 'Clean download and build data assets', task: [ // prettier: multi-line - require('./clean'), - require('./download'), - require('./amp'), + clean, + download, + amp, ], }; + module.exports = task; diff --git a/tools/__tasks__/compile/data/index.watch.js b/tools/__tasks__/compile/data/index.watch.js index a24d24796b0a..ea88e83551bd 100644 --- a/tools/__tasks__/compile/data/index.watch.js +++ b/tools/__tasks__/compile/data/index.watch.js @@ -1,10 +1,14 @@ +const clean = require('./clean.js'); +const download = require('./download.js'); +const amp = require('./amp.js'); + const task = { description: 'Clean, download and build data assets (watch)', task: [ // prettier: multi-line - require('./clean'), - require('./download'), - require('./amp'), + clean, + download, + amp, ], }; diff --git a/tools/__tasks__/compile/hash/index.js b/tools/__tasks__/compile/hash/index.js index 6580e3d1b396..c347ee8229d2 100644 --- a/tools/__tasks__/compile/hash/index.js +++ b/tools/__tasks__/compile/hash/index.js @@ -9,12 +9,13 @@ const pify = require('pify'); const writeFile = pify(fs.writeFile); +const clean = require('./clean.js'); const { paths } = require('../../config'); const task = { description: 'Version assets', task: [ - require('./clean'), + clean, { description: 'Hash assets', task: () => { diff --git a/tools/__tasks__/compile/images/icons.js b/tools/__tasks__/compile/images/icons.js index 72da1f8311b1..2b7e520286d5 100644 --- a/tools/__tasks__/compile/images/icons.js +++ b/tools/__tasks__/compile/images/icons.js @@ -1,5 +1,3 @@ -#!/usr/bin/env node - const { paths } = require('../../config'); const fs = require('fs'); diff --git a/tools/__tasks__/compile/images/index.js b/tools/__tasks__/compile/images/index.js index 3be860817e8b..c250bc2cf5a7 100644 --- a/tools/__tasks__/compile/images/index.js +++ b/tools/__tasks__/compile/images/index.js @@ -1,11 +1,16 @@ +const clean = require('./clean.js'); +const copy = require('./copy.js'); +const icons = require('./icons.js'); +const svg = require('./svg.js'); + const task = { description: 'Compile images', task: [ // prettier: multi-line - require('./clean'), - require('./copy'), - require('./icons'), - require('./svg'), + clean, + copy, + icons, + svg, ], }; diff --git a/tools/__tasks__/compile/index.dev.js b/tools/__tasks__/compile/index.dev.js index 1bdda0b6e92e..d26cee3c2e59 100644 --- a/tools/__tasks__/compile/index.dev.js +++ b/tools/__tasks__/compile/index.dev.js @@ -1,12 +1,18 @@ +const clean = require('./conf/clean.js'); +const css = require('./css/index.dev.js'); +const data = require('./data/index.dev.js'); +const javascript = require('./javascript/index.dev.js'); +const conf = require('./conf/index.js'); + const task = { description: 'Compile assets for development', task: [ // prettier: multi-line - require('./conf/clean'), - require('./css/index.dev'), - require('./data/index.dev'), - require('./javascript/index.dev'), - require('./conf'), + clean, + css, + data, + javascript, + conf, ], }; diff --git a/tools/__tasks__/compile/index.js b/tools/__tasks__/compile/index.js index 4632a11987cb..9a5a73e84175 100755 --- a/tools/__tasks__/compile/index.js +++ b/tools/__tasks__/compile/index.js @@ -1,13 +1,20 @@ +const clean = require('./conf/clean.js'); +const css = require('./css/index.js'); +const data = require('./data/index.js'); +const javascript = require('./javascript/index.js'); +const hash = require('./hash/index.js'); +const conf = require('./conf/index.js'); + const task = { description: 'Compile assets for production', task: [ // prettier: multi-line - require('./conf/clean'), - require('./css'), - require('./data'), - require('./javascript'), - require('./hash'), - require('./conf'), + clean, + css, + data, + javascript, + hash, + conf, ], }; diff --git a/tools/__tasks__/compile/index.watch.js b/tools/__tasks__/compile/index.watch.js index cbabca5e61e2..e9d781a8c606 100644 --- a/tools/__tasks__/compile/index.watch.js +++ b/tools/__tasks__/compile/index.watch.js @@ -1,12 +1,18 @@ +const clean = require('./conf/clean.js'); +const css = require('./css/index.dev.js'); +const data = require('./data/index.watch.js'); +const javascript = require('./javascript/index.watch.js'); +const conf = require('./conf/index.js'); + const task = { description: 'Compile assets for development', task: [ // prettier: multi-line - require('./conf/clean'), - require('./css/index.dev'), - require('./data/index.watch'), - require('./javascript/index.watch'), - require('./conf'), + clean, + css, + data, + javascript, + conf, ], }; diff --git a/tools/__tasks__/compile/javascript/index.atoms.js b/tools/__tasks__/compile/javascript/index.atoms.js index 8a2ebaf90e49..a2e5dd7e9428 100644 --- a/tools/__tasks__/compile/javascript/index.atoms.js +++ b/tools/__tasks__/compile/javascript/index.atoms.js @@ -1,10 +1,14 @@ +const clean = require('./clean'); +const inlineSVGs = require('../inline-svgs'); +const webpackAtoms = require('./webpack-atoms'); + const task = { description: 'Compile JS', task: [ // prettier: multi-line - require('./clean'), - require('../inline-svgs'), - require('./webpack-atoms'), + clean, + inlineSVGs, + webpackAtoms, ], }; diff --git a/tools/__tasks__/compile/javascript/index.dev.js b/tools/__tasks__/compile/javascript/index.dev.js index c7d0773bd4b7..f40e69b7e2e8 100644 --- a/tools/__tasks__/compile/javascript/index.dev.js +++ b/tools/__tasks__/compile/javascript/index.dev.js @@ -1,14 +1,20 @@ +const inlineSVGs = require('../inline-svgs/index.js'); +const clean = require('./clean.js'); +const copy = require('./copy.js'); +const webpack = require('./webpack.dev'); +const webpackDCR = require('./webpack-dcr.dev'); +const bundlePolyfills = require('./bundle-polyfills'); + const task = { description: 'Prepare JS for development', task: [ // prettier: multi-line - require('../inline-svgs'), - require('./clean'), - require('./copy'), - require('../../commercial/compile'), - require('./webpack.dev'), - require('./webpack-dcr.dev'), - require('./bundle-polyfills'), + inlineSVGs, + clean, + copy, + webpack, + webpackDCR, + bundlePolyfills, ], }; diff --git a/tools/__tasks__/compile/javascript/index.js b/tools/__tasks__/compile/javascript/index.js index 8b9ad2d69c14..1283f43a3380 100644 --- a/tools/__tasks__/compile/javascript/index.js +++ b/tools/__tasks__/compile/javascript/index.js @@ -1,13 +1,20 @@ +const clean = require('./clean.js'); +const inlineSVGs = require('../inline-svgs/index.js'); +const copy = require('./copy.js'); +const webpack = require('./webpack.js'); +const webpackAtoms = require('./webpack-atoms.js'); +const bundlePolyfills = require('./bundle-polyfills.js'); + const task = { description: 'Compile JS', task: [ // prettier: multi-line - require('./clean'), - require('../inline-svgs'), - require('./copy'), - require('./webpack'), - require('./webpack-atoms'), - require('./bundle-polyfills'), + clean, + inlineSVGs, + copy, + webpack, + webpackAtoms, + bundlePolyfills, ], }; diff --git a/tools/__tasks__/compile/javascript/index.watch.js b/tools/__tasks__/compile/javascript/index.watch.js index d5b4315f814c..397b7a74bf7f 100644 --- a/tools/__tasks__/compile/javascript/index.watch.js +++ b/tools/__tasks__/compile/javascript/index.watch.js @@ -1,11 +1,16 @@ +const inlineSVGs = require('../inline-svgs/index.js'); +const clean = require('./clean.js'); +const copy = require('./copy.js'); +const bundlePolyfills = require('./bundle-polyfills.js'); + const task = { description: 'Prepare JS for development', task: [ // prettier: multi-line - require('../inline-svgs'), - require('./clean'), - require('./copy'), - require('./bundle-polyfills'), + inlineSVGs, + clean, + copy, + bundlePolyfills, ], }; diff --git a/tools/__tasks__/compile/javascript/webpack-atoms.js b/tools/__tasks__/compile/javascript/webpack-atoms.js index 7a62a6dabeb0..3ef41e062b61 100644 --- a/tools/__tasks__/compile/javascript/webpack-atoms.js +++ b/tools/__tasks__/compile/javascript/webpack-atoms.js @@ -6,15 +6,13 @@ const webpack = require('webpack'); const chalk = require('chalk'); const config = require('../../../../webpack.config.atoms.js'); +const reporter = require('../../../webpack-progress-reporter.js'); const task = { description: 'Create Webpack bundles for atoms', task: () => new Observable((observer) => { - config.plugins = [ - require('../../../webpack-progress-reporter')(observer), - ...config.plugins, - ]; + config.plugins = [reporter(observer), ...config.plugins]; const bundler = webpack(config); diff --git a/tools/__tasks__/compile/javascript/webpack.dev.js b/tools/__tasks__/compile/javascript/webpack.dev.js index acb73fcc0e5a..76b4f20b2796 100644 --- a/tools/__tasks__/compile/javascript/webpack.dev.js +++ b/tools/__tasks__/compile/javascript/webpack.dev.js @@ -6,15 +6,13 @@ const webpack = require('webpack'); const chalk = require('chalk'); const config = require('../../../../webpack.config.dev.js'); +const reporter = require('../../../webpack-progress-reporter.js'); const task = { description: 'Create Webpack bundles', task: () => new Observable((observer) => { - config.plugins = [ - require('../../../webpack-progress-reporter')(observer), - ...config.plugins, - ]; + config.plugins = [reporter(observer), ...config.plugins]; const bundler = webpack(config); diff --git a/tools/__tasks__/compile/javascript/webpack.js b/tools/__tasks__/compile/javascript/webpack.js index 79435c0bf0d0..606f6bdb9cb6 100644 --- a/tools/__tasks__/compile/javascript/webpack.js +++ b/tools/__tasks__/compile/javascript/webpack.js @@ -6,15 +6,13 @@ const webpack = require('webpack'); const chalk = require('chalk'); const config = require('../../../../webpack.config.prod.js'); +const reporter = require('../../../webpack-progress-reporter.js'); const task = { description: 'Create Webpack bundles', task: () => new Observable((observer) => { - config.plugins = [ - require('../../../webpack-progress-reporter')(observer), - ...config.plugins, - ]; + config.plugins = [reporter(observer), ...config.plugins]; const bundler = webpack(config); diff --git a/tools/__tasks__/test/index.js b/tools/__tasks__/test/index.js index cc55b1f6828b..98ee25922706 100644 --- a/tools/__tasks__/test/index.js +++ b/tools/__tasks__/test/index.js @@ -1,9 +1,12 @@ +const data = require('../compile/data/index.js'); +const javascript = require('./javascript/index.js'); + const task = { description: 'Test assets', task: [ // prettier: multi-line - require('../compile/data'), - require('./javascript'), + data, + javascript, ], concurrent: true, }; diff --git a/tools/__tasks__/validate-head/index.js b/tools/__tasks__/validate-head/index.js index 044406ec767b..b4b8a82b9809 100644 --- a/tools/__tasks__/validate-head/index.js +++ b/tools/__tasks__/validate-head/index.js @@ -1,9 +1,12 @@ +const javascript = require('./javascript'); +const sass = require('./sass'); + const task = { description: 'Validate commits', task: [ // prettier: multi-line - require('./javascript'), - require('./sass'), + javascript, + sass, ], concurrent: true, }; diff --git a/tools/__tasks__/validate/index.js b/tools/__tasks__/validate/index.js index 9bcaf89ee4f5..02030b2bced7 100644 --- a/tools/__tasks__/validate/index.js +++ b/tools/__tasks__/validate/index.js @@ -1,11 +1,16 @@ +const javascript = require('./javascript.js'); +const typescript = require('./typescript.js'); +const sass = require('./sass.js'); +const checkForDisallowedStrings = require('./check-for-disallowed-strings.js'); + const task = { description: 'Lint assets', task: [ // prettier: multi-line - require('./javascript'), - require('./typescript'), - require('./sass'), - require('./check-for-disallowed-strings'), + javascript, + typescript, + sass, + checkForDisallowedStrings, ], concurrent: true, }; From 27bf297701c13bc4360631273a56eaff11f7e73a Mon Sep 17 00:00:00 2001 From: Max Duval Date: Mon, 24 Jun 2024 16:09:03 +0100 Subject: [PATCH 2/2] refactor: explicit extension --- tools/__tasks__/validate-head/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/__tasks__/validate-head/index.js b/tools/__tasks__/validate-head/index.js index b4b8a82b9809..71ff7f2b4b53 100644 --- a/tools/__tasks__/validate-head/index.js +++ b/tools/__tasks__/validate-head/index.js @@ -1,5 +1,5 @@ -const javascript = require('./javascript'); -const sass = require('./sass'); +const javascript = require('./javascript.js'); +const sass = require('./sass.js'); const task = { description: 'Validate commits',