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

Turn the Task runner’s Listr tasks to ESM #27262

Merged
merged 4 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion disallowed-strings.js → disallowed-strings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const readerRevenueConfig = {

// pathspecs are git pathspecs: https://git-scm.com/docs/gitglossary#gitglossary-aiddefpathspecapathspec
// To search all files under version control, set pathspecs to an empty array.
module.exports = [
export default [
// These are commented out because they would currently fail the build.
// Until we refactor to eliminate the duplicates, they can serve as examples
// in case anyone wants to add more immediately feasible rules!
Expand Down
2 changes: 1 addition & 1 deletion git-hooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const confirmIfMain = execa
const validate = () =>
execa(
'./tools/task-runner/runner.mjs',
['validate/scalafmt.js', 'validate-head/index.js', 'validate/check-for-disallowed-strings.js'],
['validate-head/index.mjs'],
{
stdio: 'inherit',
}
Expand Down
23 changes: 11 additions & 12 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,49 +40,48 @@ sbt: # PRIVATE

# Compile all assets in production.
compile: install
@NODE_ENV=production ./tools/task-runner/runner.mjs compile/index.js
@NODE_ENV=production ./tools/task-runner/runner.mjs compile/index.mjs

# 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
@NODE_ENV=development ./tools/task-runner/runner.mjs compile/index.dev.mjs

# Compile atom-specific JS
compile-atoms: install
@./tools/task-runner/runner.mjs compile/javascript/index.atoms.js
@./tools/task-runner/runner.mjs compile/javascript/index.atoms.mjs

# Compile all assets for watch.
compile-watch: install # PRIVATE
@NODE_ENV=development ./tools/task-runner/runner.mjs compile/index.watch.js
@NODE_ENV=development ./tools/task-runner/runner.mjs compile/index.watch.mjs

compile-javascript: install # PRIVATE
@./tools/task-runner/runner.mjs compile/javascript/index.js
@./tools/task-runner/runner.mjs compile/javascript/index.mjs

compile-javascript-dev: install # PRIVATE
@./tools/task-runner/runner.mjs compile/javascript/index.dev.js
@./tools/task-runner/runner.mjs compile/javascript/index.dev.mjs

compile-css: install # PRIVATE
@./tools/task-runner/runner.mjs compile/css/index.js
@./tools/task-runner/runner.mjs compile/css/index.mjs

compile-images: install # PRIVATE
@./tools/task-runner/runner.mjs compile/images/index.js
@./tools/task-runner/runner.mjs compile/images/index.mjs

compile-svgs: install # PRIVATE
@./tools/task-runner/runner.mjs compile/inline-svgs/index.js
@./tools/task-runner/runner.mjs compile/inline-svgs/index.mjs

# *********************** CHECKS ***********************

# Run the JS test suite.
test: install
@./tools/task-runner/runner.mjs test/javascript/index.js --verbose
@./tools/task-runner/runner.mjs test/javascript/index.mjs --verbose

# Run the modern JS test suite in watch mode.
test-watch: install
@yarn test -- --watch --coverage

# Validate all assets.
validate: install
@./tools/task-runner/runner.mjs validate/index.js --verbose
@./tools/task-runner/runner.mjs validate/index.mjs --verbose
@yarn prettier */test/resources/*.json --check

# Validate all SCSS.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');
const rimraf = require('rimraf');
import path from 'node:path';
import rimraf from 'rimraf';

const { paths } = require('../../config');
import { paths } from '../../config.mjs';

/** @type {import('listr2').ListrTask} */
const task = {
Expand All @@ -10,4 +10,4 @@ const task = {
rimraf.sync(path.resolve(paths.root, 'common', 'conf', 'assets')),
};

module.exports = task;
export default task;
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const path = require('path');
const cpy = require('cpy');
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import cpy from 'cpy';

const { paths } = require('../../config');
import { paths } from '../../config.mjs';

/** @type {import('listr2').ListrTask} */
const task = {
Expand All @@ -10,7 +11,7 @@ const task = {
Promise.all([
cpy('curl.js', paths.conf, {
cwd: path.resolve(
path.dirname(require.resolve('curl')),
path.dirname(fileURLToPath(import.meta.resolve('curl'))),
'..',
'dist',
'curl-with-js-and-domReady',
Expand All @@ -32,4 +33,4 @@ const task = {
]),
};

module.exports = task;
export default task;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const copy = require('./copy.js');
const inlineSVGs = require('../inline-svgs/index.js');
import copy from './copy.mjs';
import inlineSVGs from '../inline-svgs/index.mjs';

/** @type {import('listr2').ListrTask} */
const task = {
Expand All @@ -15,4 +15,4 @@ const task = {
),
};

module.exports = task;
export default task;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');
const rimraf = require('rimraf');
import path from 'node:path';
import rimraf from 'rimraf';

const { paths } = require('../../config');
import { paths } from '../../config.mjs';

/** @type {import('listr2').ListrTask} */
const task = {
Expand All @@ -12,4 +12,4 @@ const task = {
},
};

module.exports = task;
export default task;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const clean = require('./clean.js');
const mkdir = require('./mkdir.js');
const images = require('../images/index.js');
const sass = require('./sass.js');
import clean from './clean.mjs';
import mkdir from './mkdir.mjs';
import images from '../images/index.mjs';
import sass from './sass.mjs';

/** @type {import('listr2').ListrTask} */
const task = {
Expand All @@ -19,4 +19,4 @@ const task = {
),
};

module.exports = task;
export default task;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const clean = require('./clean.js');
const mkdir = require('./mkdir.js');
const images = require('../images/index.js');
const sass = require('./sass.js');
import clean from './clean.mjs';
import mkdir from './mkdir.mjs';
import images from '../images/index.mjs';
import sass from './sass.mjs';

/** @type {import('listr2').ListrTask} */
const task = {
Expand All @@ -19,4 +19,4 @@ const task = {
),
};

module.exports = task;
export default task;
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const mkdirp = require('mkdirp');
const { paths } = require('../../config');
import mkdirp from 'mkdirp';
import { paths } from '../../config.mjs';

/** @type {import('listr2').ListrTask} */
const task = {
title: 'Create CSS target directory',
task: () => mkdirp.sync(`${paths.target}/stylesheets`),
};

module.exports = task;
export default task;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const compile = require('../../../compile-css');
import compile from '../../../compile-css.mjs';

/** @type {import('listr2').ListrTask} */
const task = {
Expand Down Expand Up @@ -48,4 +48,4 @@ const task = {
),
};

module.exports = task;
export default task;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');
const cpy = require('cpy');
import path from 'node:path';
import cpy from 'cpy';

const { paths } = require('../../config');
import { paths } from '../../config.mjs';

// Source
const ampIframeHtml = path.join(paths.vendor, 'data/amp-iframe.html');
Expand All @@ -20,4 +20,4 @@ const task = {
}),
};

module.exports = task;
export default task;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');
const rimraf = require('rimraf');
import path from 'node:path';
import rimraf from 'rimraf';

const { paths } = require('../../config');
import { paths } from '../../config.mjs';

/** @type {import('listr2').ListrTask} */
const task = {
Expand All @@ -12,4 +12,4 @@ const task = {
},
};

module.exports = task;
export default task;
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const path = require('path');
const fs = require('fs');
const request = require('request');
const chalk = require('chalk');
import path from 'node:path';
import fs from 'node:fs';
import request from 'request';
import chalk from 'chalk';

const warning = chalk.keyword('orange');

const { paths } = require('../../config');
import { paths } from '../../config.mjs';

// Sources
const vendorListOfficialUrl = 'https://vendorlist.consensu.org/vendorlist.json';
Expand Down Expand Up @@ -72,4 +72,4 @@ const task = {
),
};

module.exports = task;
export default task;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const clean = require('./clean.js');
const download = require('./download.js');
const amp = require('./amp.js');
import clean from './clean.mjs';
import download from './download.mjs';
import amp from './amp.mjs';

/** @type {import('listr2').ListrTask} */
const task = {
Expand All @@ -17,4 +17,4 @@ const task = {
),
};

module.exports = task;
export default task;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const clean = require('./clean.js');
const download = require('./download.js');
const amp = require('./amp.js');
import clean from './clean.mjs';
import download from './download.mjs';
import amp from './amp.mjs';

/** @type {import('listr2').ListrTask} */
const task = {
Expand All @@ -17,4 +17,4 @@ const task = {
),
};

module.exports = task;
export default task;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const clean = require('./clean.js');
const download = require('./download.js');
const amp = require('./amp.js');
import clean from './clean.mjs';
import download from './download.mjs';
import amp from './amp.mjs';

/** @type {import('listr2').ListrTask} */
const task = {
Expand All @@ -17,4 +17,4 @@ const task = {
),
};

module.exports = task;
export default task;
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const path = require('path');
const rimraf = require('rimraf');
import path from 'node:path';
import rimraf from 'rimraf';

const { paths } = require('../../config');
import { paths } from '../../config.mjs';

/** @type {import('listr2').ListrTask} */
const task = {
title: 'Clear asset hash artefacts',
task: () => rimraf.sync(path.resolve(paths.hash, 'assets')),
};

module.exports = task;
export default task;
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const path = require('path');
const fs = require('fs');
import path from 'node:path';
import fs from 'node:fs';

const glob = require('glob');
const hasha = require('hasha');
const cpFile = require('cp-file');
const mkdirp = require('mkdirp');
const pify = require('pify');
import glob from 'glob';
import hasha from 'hasha';
import cpFile from 'cp-file';
import mkdirp from 'mkdirp';
import pify from 'pify';

const writeFile = pify(fs.writeFile);

const clean = require('./clean.js');
const { paths } = require('../../config');
import clean from './clean.mjs';
import { paths } from '../../config.mjs';

/** @type {import('listr2').ListrTask} */
const task = {
Expand Down Expand Up @@ -164,4 +164,4 @@ const task = {
),
};

module.exports = task;
export default task;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');
const rimraf = require('rimraf');
import path from 'node:path';
import rimraf from 'rimraf';

const { paths } = require('../../config');
import { paths } from '../../config.mjs';

/** @type {import('listr2').ListrTask} */
const task = {
Expand All @@ -13,4 +13,4 @@ const task = {
},
};

module.exports = task;
export default task;
Loading
Loading