From d9ebb97a113da5a45616427f0ca6073de337bb14 Mon Sep 17 00:00:00 2001 From: Max Duval Date: Mon, 24 Jun 2024 17:34:27 +0100 Subject: [PATCH 1/6] refactor: use ESM for the task runner remove unused and gone tasks --- .github/workflows/build.yml | 4 +-- git-hooks/pre-push | 4 +-- makefile | 36 ++++++++----------- .../__tasks__/compile/javascript/index.dev.js | 4 +-- tools/task-runner/README.md | 6 ++-- ...mater.js => run-task-verbose-formater.mjs} | 8 ++--- tools/task-runner/{runner => runner.mjs} | 34 ++++++++++-------- 7 files changed, 46 insertions(+), 50 deletions(-) rename tools/task-runner/{run-task-verbose-formater.js => run-task-verbose-formater.mjs} (90%) rename tools/task-runner/{runner => runner.mjs} (89%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 36007802c58..cd5e636e1fb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,10 +35,10 @@ jobs: - run: make reinstall - name: assets test - run: ./tools/task-runner/runner validate test + run: ./tools/task-runner/runner.mjs validate test - name: assets compile - run: ./tools/task-runner/runner compile + run: ./tools/task-runner/runner.mjs compile env: NODE_ENV: production diff --git a/git-hooks/pre-push b/git-hooks/pre-push index 8888695eefc..f5dc8dd02f8 100755 --- a/git-hooks/pre-push +++ b/git-hooks/pre-push @@ -41,8 +41,8 @@ const confirmIfMain = execa .catch(() => Promise.reject(new Error('Ok, stopping 😉'))); const validate = () => execa( - './tools/task-runner/runner', - ['validate/scalafmt', 'validate-head/index', 'validate/check-for-disallowed-strings'], + './tools/task-runner/runner.mjs', + ['validate/scalafmt.js', 'validate-head/index.js', 'validate/check-for-disallowed-strings.js'], { stdio: 'inherit', } diff --git a/makefile b/makefile index 6abcbdedb9c..3fb069abb7e 100644 --- a/makefile +++ b/makefile @@ -40,73 +40,67 @@ sbt: # PRIVATE # Compile all assets in production. compile: install - @NODE_ENV=production ./tools/task-runner/runner compile + @NODE_ENV=production ./tools/task-runner/runner.mjs compile/index.js # Compile all assets in development. compile-dev: install @NODE_ENV=development ./tools/task-runner/runner compile/index.dev + @NODE_ENV=development ./tools/task-runner/runner.mjs compile/index.dev.js # Compile atom-specific JS compile-atoms: install - @./tools/task-runner/runner compile/javascript/index.atoms + @./tools/task-runner/runner.mjs compile/javascript/index.atoms.js # Compile all assets for watch. compile-watch: install # PRIVATE - @NODE_ENV=development ./tools/task-runner/runner compile/index.watch + @NODE_ENV=development ./tools/task-runner/runner.mjs compile/index.watch.js compile-javascript: install # PRIVATE - @./tools/task-runner/runner compile/javascript + @./tools/task-runner/runner.mjs compile/javascript/index.js compile-javascript-dev: install # PRIVATE - @./tools/task-runner/runner compile/javascript/index.dev + @./tools/task-runner/runner.mjs compile/javascript/index.dev.js compile-css: install # PRIVATE - @./tools/task-runner/runner compile/css + @./tools/task-runner/runner.mjs compile/css/index.js compile-images: install # PRIVATE - @./tools/task-runner/runner compile/images + @./tools/task-runner/runner.mjs compile/images/index.js compile-svgs: install # PRIVATE - @./tools/task-runner/runner compile/inline-svgs - -compile-fonts: install # PRIVATE - @./tools/task-runner/runner compile/fonts + @./tools/task-runner/runner.mjs compile/inline-svgs/index.js # *********************** CHECKS *********************** # Run the JS test suite. test: install - @./tools/task-runner/runner test/javascript --verbose + @./tools/task-runner/runner.mjs test/javascript/index.js --verbose # Run the modern JS test suite in watch mode. test-watch: install @yarn test -- --watch --coverage -# Check the JS test suite coverage. -coverage: install - @./tools/task-runner/runner test/javascript/coverage --stdout - # Validate all assets. validate: install - @./tools/task-runner/runner validate --verbose + @./tools/task-runner/runner.mjs validate/index.js --verbose @yarn prettier */test/resources/*.json --check # Validate all SCSS. validate-sass: install # PRIVATE - @./tools/task-runner/runner validate/sass --verbose + @./tools/task-runner/runner.mjs validate/sass.js --verbose # Validate all JS. validate-javascript: install # PRIVATE - @./tools/task-runner/runner validate/javascript + @./tools/task-runner/runner.mjs validate/javascript.js # Fix JS linting errors. fix: install - @./tools/task-runner/runner validate/javascript-fix + @./tools/task-runner/runner.mjs validate/javascript-fix.js @yarn prettier */test/resources/*.json --write # Fix committed JS linting errors. fix-commits: install - @./tools/task-runner/runner validate-head/javascript-fix + @./tools/task-runner/runner.mjs validate-head/javascript-fix.js # Update caniuse db used by browserslist # https://github.com/browserslist/update-db diff --git a/tools/__tasks__/compile/javascript/index.dev.js b/tools/__tasks__/compile/javascript/index.dev.js index 4f9540cf99d..13edc604a2e 100644 --- a/tools/__tasks__/compile/javascript/index.dev.js +++ b/tools/__tasks__/compile/javascript/index.dev.js @@ -1,8 +1,8 @@ const inlineSVGs = require('../inline-svgs/index.js'); const clean = require('./clean.js'); const copy = require('./copy.js'); -const webpack = require('./webpack.dev'); -const bundlePolyfills = require('./bundle-polyfills'); +const webpack = require('./webpack.dev.js'); +const bundlePolyfills = require('./bundle-polyfills.js'); const task = { description: 'Prepare JS for development', diff --git a/tools/task-runner/README.md b/tools/task-runner/README.md index 009abd1e7c9..3a172ec2e89 100644 --- a/tools/task-runner/README.md +++ b/tools/task-runner/README.md @@ -9,7 +9,7 @@ It's intended to exist ‘behind the scenes’, and you should probably be runni It takes one or more tasks to run as arguments, which should be relative paths within the `__tasks__` directory, so that: ``` -./tools/task-runner/runner fakemodule/fakemodule +./tools/task-runner/runner.mjs fakemodule/fakemodule ``` will run the task defined in `tools/__tasks__/fakemodule/fakemodule.js`. @@ -19,7 +19,7 @@ will run the task defined in `tools/__tasks__/fakemodule/fakemodule.js`. You can pass a `--dev` flag to prefer a dev version, if it exists (suffix the task's filename with `.dev`), so that: ``` -./tools/task-runner/runner fakemodule/fakemodule --dev +./tools/task-runner/runner.mjs fakemodule/fakemodule --dev ``` - runs `tools/__tasks__/fakemodule/fakemodule.dev.js` if it exists @@ -31,7 +31,7 @@ Tasks can be run with `--verbose` flag for fuller output, but this shouldn't usu ### Options -For a full list, run `./tools/task-runner/runner -h`. +For a full list, run `./tools/task-runner/runner.mjs -h`. ## Defining tasks diff --git a/tools/task-runner/run-task-verbose-formater.js b/tools/task-runner/run-task-verbose-formater.mjs similarity index 90% rename from tools/task-runner/run-task-verbose-formater.js rename to tools/task-runner/run-task-verbose-formater.mjs index 22e514742a1..9ae392dc882 100644 --- a/tools/task-runner/run-task-verbose-formater.js +++ b/tools/task-runner/run-task-verbose-formater.mjs @@ -1,5 +1,5 @@ -const figures = require('figures'); -const chalk = require('chalk'); +import figures from 'figures'; +import chalk from 'chalk'; const log = (title, parents, message = '') => { console.log( @@ -39,7 +39,7 @@ const render = (tasks, parents = []) => { } }; -class VerboseRenderer { +export class VerboseRenderer { constructor(tasks) { // eslint-disable-next-line no-underscore-dangle this._tasks = tasks; @@ -60,5 +60,3 @@ class VerboseRenderer { // do nothing } } - -module.exports = { VerboseRenderer }; diff --git a/tools/task-runner/runner b/tools/task-runner/runner.mjs similarity index 89% rename from tools/task-runner/runner rename to tools/task-runner/runner.mjs index e925197f075..d46a7028d7e 100755 --- a/tools/task-runner/runner +++ b/tools/task-runner/runner.mjs @@ -1,20 +1,20 @@ #!/usr/bin/env node -/* eslint-disable import/no-dynamic-require, global-require */ // force any plugins that use `chalk` to output in full colour process.env.FORCE_COLOR = true; -const path = require('path'); -const os = require('os'); +import path from 'node:path'; +import os from 'node:os'; +import { fileURLToPath } from 'node:url'; -const yargs = require('yargs'); -const { hideBin } = require('yargs/helpers'); -const { Listr } = require('listr2'); -const execa = require('execa'); -const chalk = require('chalk'); -const figures = require('figures'); -const uniq = require('lodash.uniq'); -const { VerboseRenderer } = require('./run-task-verbose-formater.js'); +import yargs from 'yargs'; +import { hideBin } from 'yargs/helpers'; +import { Listr } from 'listr2'; +import execa from 'execa'; +import chalk from 'chalk'; +import figures from 'figures'; +import uniq from 'lodash.uniq'; +import { VerboseRenderer } from './run-task-verbose-formater.mjs'; // name of the tasks directory const tasksDirectory = '__tasks__'; @@ -68,7 +68,11 @@ const { const VERBOSE = IS_VERBOSE || IS_DEBUG; // look here for tasks that come in from yargs -const taskSrc = path.resolve(__dirname, '..', tasksDirectory); +const taskSrc = path.resolve( + path.dirname(fileURLToPath(import.meta.url)), + '..', + tasksDirectory, +); // we will store tasks that we run in here, to prevent running them more than once // e.g. if two tasks rely on the same thing @@ -170,10 +174,10 @@ function listrify(steps, { concurrent = false } = {}) { } // resolve the tasks from yargs to actual files -const getTasksFromModule = (taskName) => { +const getTasksFromModule = async (taskName) => { try { const modulePath = path.resolve(taskSrc, taskName); - return require(modulePath); + return (await import(modulePath)).default; } catch (e) { // we can't find any modules, or something else has gone wrong in resolving it // so output an erroring task @@ -185,7 +189,7 @@ const getTasksFromModule = (taskName) => { }; // get a list of the tasks we're going to run -const taskModules = TASKS.map(getTasksFromModule); +const taskModules = await Promise.all(TASKS.map(getTasksFromModule)); // run them! listrify(taskModules) From 12fb41aa68eb19cf9d4018f79decebdae5c92a4d Mon Sep 17 00:00:00 2001 From: Max Duval Date: Mon, 24 Jun 2024 17:15:44 +0100 Subject: [PATCH 2/6] refactor: use makefile in Github Actions --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cd5e636e1fb..4301c6a513f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,11 +34,11 @@ jobs: - run: make reinstall - - name: assets test - run: ./tools/task-runner/runner.mjs validate test + - run: make validate - - name: assets compile - run: ./tools/task-runner/runner.mjs compile + - run: make test + + - run: make compile env: NODE_ENV: production From 66b37861195b1c06a1b38d977ea8ad0dd263ec80 Mon Sep 17 00:00:00 2001 From: Max Duval Date: Mon, 24 Jun 2024 17:16:41 +0100 Subject: [PATCH 3/6] docs: make docs clearer --- tools/task-runner/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/task-runner/README.md b/tools/task-runner/README.md index 3a172ec2e89..78ff46c6b3f 100644 --- a/tools/task-runner/README.md +++ b/tools/task-runner/README.md @@ -9,7 +9,7 @@ It's intended to exist ‘behind the scenes’, and you should probably be runni It takes one or more tasks to run as arguments, which should be relative paths within the `__tasks__` directory, so that: ``` -./tools/task-runner/runner.mjs fakemodule/fakemodule +./tools/task-runner/runner.mjs fakemodule/fakemodule.js ``` will run the task defined in `tools/__tasks__/fakemodule/fakemodule.js`. @@ -19,7 +19,7 @@ will run the task defined in `tools/__tasks__/fakemodule/fakemodule.js`. You can pass a `--dev` flag to prefer a dev version, if it exists (suffix the task's filename with `.dev`), so that: ``` -./tools/task-runner/runner.mjs fakemodule/fakemodule --dev +./tools/task-runner/runner.mjs fakemodule/fakemodule.dev.js ``` - runs `tools/__tasks__/fakemodule/fakemodule.dev.js` if it exists From c714dcf67ddd6ed23a89589101bea00354405744 Mon Sep 17 00:00:00 2001 From: Max Duval Date: Mon, 24 Jun 2024 18:02:33 +0100 Subject: [PATCH 4/6] refactor: remove redundant NODE_ENV --- .github/workflows/build.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4301c6a513f..50fc4c661a7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -39,8 +39,6 @@ jobs: - run: make test - run: make compile - env: - NODE_ENV: production - name: Test, compile # Australia/Sydney -because it is too easy for devs to forget about timezones From 18a8220aed5c9373148d9b226fc2aa63ad6d63ce Mon Sep 17 00:00:00 2001 From: Max Duval Date: Mon, 24 Jun 2024 18:09:12 +0100 Subject: [PATCH 5/6] docs: update examples --- tools/task-runner/runner.mjs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tools/task-runner/runner.mjs b/tools/task-runner/runner.mjs index d46a7028d7e..d1e1c55dd7f 100755 --- a/tools/task-runner/runner.mjs +++ b/tools/task-runner/runner.mjs @@ -48,15 +48,12 @@ const { }) .usage('Usage: $0 [] [--dev]') .command('task', `Run a task defined in '${tasksDirectory}'.`) - .example('$0 copy', 'Run all the copy tasks.') - .example('$0 javascript/copy', 'Run the javascript copy task.') + .example('$0 copy/index.js', 'Run all the copy tasks.') + .example('$0 javascript/copy.js', 'Run the javascript copy task.') + .example('$0 compile/index.dev.js', 'Run the compile dev copy task.') .example( - '$0 javascript/copy --dev', - 'Run the javascript copy task, and prefer the development version, if it exists.', - ) - .example( - '$0 javascript/copy css/copy --dev', - 'Run the javascript and css copy tasks, and prefer the development versions, if they exist.', + '$0 compile/javascript/copy.js compile/css/copy.js', + 'Run the javascript copy and css copy tasks.', ) .demand(1) .help() From c0c81fbd0d4e46455cf07efced9f53106a2a9051 Mon Sep 17 00:00:00 2001 From: Max Duval Date: Mon, 24 Jun 2024 18:09:56 +0100 Subject: [PATCH 6/6] chore: remove unused eslint comments --- tools/task-runner/runner.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/task-runner/runner.mjs b/tools/task-runner/runner.mjs index d1e1c55dd7f..0b448a84bc1 100755 --- a/tools/task-runner/runner.mjs +++ b/tools/task-runner/runner.mjs @@ -57,9 +57,9 @@ const { ) .demand(1) .help() - .alias('h', 'help') // eslint-disable-line newline-per-chained-call + .alias('h', 'help') .version() - .alias('v', 'version').argv; // eslint-disable-line newline-per-chained-call + .alias('v', 'version').argv; // if this is true, we log as much as we can const VERBOSE = IS_VERBOSE || IS_DEBUG;