Skip to content

Commit 8deec03

Browse files
authored
[5.3] Move tools and source JS to ESM (joomla#44296)
1 parent 20868e5 commit 8deec03

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+580
-550
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ insert_final_newline = true
1515
indent_style = space
1616
indent_size = 4
1717

18-
[*.{js,json,scss,css,yml,vue}]
18+
[*.{mjs,js,json,scss,css,yml,vue}]
1919
indent_style = space
2020
indent_size = 2

build/.eslintrc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,18 @@
2727
// Disable no-params-reassign for properties
2828
"no-param-reassign": ["error", { "props": false }],
2929
// Allow usage of dev-dependencies in js files in build directory
30-
"import/no-extraneous-dependencies": ["error", {"devDependencies": ["build/**/*.js"]}],
30+
"import/no-extraneous-dependencies": [
31+
"error",
32+
{
33+
"devDependencies":
34+
[
35+
"build/**/*.js",
36+
"build/**/*.mjs",
37+
"cypress.config.dist.mjs",
38+
"**/**/cypress.config.mjs"
39+
]
40+
}
41+
],
3142
// Allow strict mode (we are not dealing with modules)
3243
"strict": [0],
3344
// Disable alert rule till we have a CE in place
@@ -46,6 +57,7 @@
4657
],
4758
// Allow extensions on imports
4859
"import/extensions": 0,
60+
"import/prefer-default-export": 0,
4961
"func-names": [
5062
"error",
5163
"as-needed"

build/build-modules-js/compilecss.es6.js renamed to build/build-modules-js/compilecss.mjs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
const { stat } = require('fs-extra');
2-
const { sep } = require('path');
3-
const recursive = require('recursive-readdir');
4-
const { handleScssFile } = require('./stylesheets/handle-scss.es6.js');
5-
const { handleCssFile } = require('./stylesheets/handle-css.es6.js');
1+
import { sep } from 'node:path';
62

3+
import recursive from 'recursive-readdir';
4+
import pkg from 'fs-extra';
5+
6+
import { handleScssFile } from './stylesheets/handle-scss.mjs';
7+
import { handleCssFile } from './stylesheets/handle-css.mjs';
8+
9+
const { stat } = pkg;
710
const RootPath = process.cwd();
811

912
/**
@@ -19,7 +22,7 @@ const RootPath = process.cwd();
1922
* @param {object} options The options
2023
* @param {string} path The folder that needs to be compiled, optional
2124
*/
22-
module.exports.stylesheets = async (options, path) => {
25+
export const stylesheets = async (options, path) => {
2326
const files = [];
2427
let folders = [];
2528

build/build-modules-js/compilejs.es6.js renamed to build/build-modules-js/compilejs.mjs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
const { stat } = require('fs-extra');
2-
const { sep } = require('path');
3-
const recursive = require('recursive-readdir');
4-
const { handleES5File } = require('./javascript/handle-es5.es6.js');
5-
const { handleESMFile } = require('./javascript/compile-to-es2017.es6.js');
1+
import { stat } from 'node:fs/promises';
2+
import { sep } from 'node:path';
3+
4+
import recursive from 'recursive-readdir';
5+
6+
import { handleES5File } from './javascript/handle-es5.mjs';
7+
import { handleESMFile } from './javascript/compile-to-es2017.mjs';
68

79
const RootPath = process.cwd();
810

@@ -21,7 +23,7 @@ const RootPath = process.cwd();
2123
* @param { string } path The folder that needs to be compiled, optional
2224
* @param { string } mode esm for ES2017, es5 for ES5, both for both
2325
*/
24-
module.exports.scripts = async (options, path) => {
26+
export const scripts = async (options, path) => {
2527
const files = [];
2628
let folders = [];
2729

@@ -49,7 +51,7 @@ module.exports.scripts = async (options, path) => {
4951
// Loop to get the files that should be compiled via parameter
5052
// eslint-disable-next-line no-restricted-syntax
5153
for (const folder of folders) {
52-
folderPromises.push(recursive(folder, ['!*.+(js)']));
54+
folderPromises.push(recursive(folder, ['!*.+(m|js)']));
5355
}
5456

5557
const computedFiles = await Promise.all(folderPromises);
@@ -63,9 +65,9 @@ module.exports.scripts = async (options, path) => {
6365
return;
6466
}
6567

66-
if (file.match(/\.es5\.js$/)) {
68+
if (file.endsWith('.es5.js')) {
6769
jsFilesPromises.push(handleES5File(file));
68-
} else if (file.match(/\.es6\.js$/) || file.match(/\.w-c\.es6\.js$/)) {
70+
} else if ((file.endsWith('.es6.js') || file.endsWith('.w-c.es6.js')) && !file.startsWith('_')) {
6971
esmFilesPromises.push(handleESMFile(file));
7072
}
7173
});

build/build-modules-js/compress.es6.js renamed to build/build-modules-js/compress.mjs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
const { readdir } = require('fs').promises;
2-
const { extname } = require('path');
3-
const { compressFile } = require('./utils/compressFile.es6.js');
4-
const { Timer } = require('./utils/timer.es6.js');
1+
import { readdir } from 'node:fs/promises';
2+
import { extname } from 'node:path';
3+
4+
import { compressFile } from './utils/compressFile.mjs';
5+
import { Timer } from './utils/timer.mjs';
56

67
/**
78
* Get files recursively
@@ -11,15 +12,15 @@ const { Timer } = require('./utils/timer.es6.js');
1112
async function getFiles(path) {
1213
// Get files within the current directory
1314
return (await readdir(path, { withFileTypes: true, recursive: true }))
14-
.filter((file) => (!file.isDirectory() && ['.js', '.css'].includes(extname(file.name))))
15+
.filter((file) => !file.isDirectory() && ['.js', '.css'].includes(extname(file.name)))
1516
.map((file) => `${file.path}/${file.name}`);
1617
}
1718

1819
/**
1920
* Method that will pre compress (gzip) all .css/.js files
2021
* in the templates and in the media folder
2122
*/
22-
module.exports.compressFiles = async (enableBrotli = false) => {
23+
export const compressFiles = async (enableBrotli = false) => {
2324
const bench = new Timer('Gzip');
2425
const paths = [
2526
`${process.cwd()}/media`,

build/build-modules-js/css-versioning.es6.js renamed to build/build-modules-js/css-versioning.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const { createHash } = require('node:crypto');
2-
const { readdir, readFile, writeFile } = require('node:fs/promises');
3-
const { existsSync, readFileSync } = require('node:fs');
4-
const { dirname, extname, resolve } = require('node:path');
5-
const { transform, composeVisitors } = require('lightningcss');
6-
const { Timer } = require('./utils/timer.es6.js');
1+
import { createHash } from 'node:crypto';
2+
import { readdir, readFile, writeFile } from 'node:fs/promises';
3+
import { existsSync, readFileSync } from 'node:fs';
4+
import { dirname, extname, resolve } from 'node:path';
5+
import { transform, composeVisitors } from 'lightningcss';
6+
import { Timer } from './utils/timer.mjs';
77

88
const RootPath = process.cwd();
99
const skipExternal = true;
@@ -76,7 +76,7 @@ const fixVersion = async (file) => {
7676
*
7777
* @returns {Promise<void>}
7878
*/
79-
module.exports.cssVersioning = async () => {
79+
export const cssVersioning = async () => {
8080
const bench = new Timer('Versioning');
8181

8282
const cssFiles = (await readdir(`${RootPath}/media`, { withFileTypes: true, recursive: true }))

build/build-modules-js/error-pages.es6.js renamed to build/build-modules-js/error-pages.mjs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
const {
1+
import {
22
access, mkdir, readFile, writeFile,
3-
} = require('fs').promises;
4-
const Ini = require('ini');
5-
const { dirname } = require('path');
6-
const Recurs = require('recursive-readdir');
7-
const { transform } = require('esbuild');
8-
const LightningCSS = require('lightningcss');
3+
} from 'node:fs/promises';
4+
import { dirname } from 'node:path';
5+
6+
import Ini from 'ini';
7+
import Recurs from 'recursive-readdir';
8+
import { transform } from 'esbuild';
9+
import { transform as transformCss } from 'lightningcss';
910

1011
const RootPath = process.cwd();
1112
const dir = `${RootPath}/installation/language`;
@@ -21,7 +22,7 @@ const srcPath = `${RootPath}/build/warning_page`;
2122
* And also specific strings in the languages in the installation folder!
2223
* Also the base strings are held in build/build-modules-js/settings.json
2324
*/
24-
module.exports.createErrorPages = async (options) => {
25+
export const createErrorPages = async (options) => {
2526
const iniFilesProcess = [];
2627
const processPages = [];
2728
global.incompleteObj = {};
@@ -33,7 +34,7 @@ module.exports.createErrorPages = async (options) => {
3334
let cssContent = await readFile(`${srcPath}/template.css`, { encoding: 'utf8' });
3435
let jsContent = await readFile(`${srcPath}/template.js`, { encoding: 'utf8' });
3536

36-
const { code } = LightningCSS.transform({
37+
const { code } = transformCss({
3738
code: Buffer.from(cssContent),
3839
minify: true,
3940
});

build/build-modules-js/init/cleanup-media.es6.js renamed to build/build-modules-js/init/cleanup-media.mjs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
const {
2-
stat, mkdir, copy, remove,
3-
} = require('fs-extra');
4-
const { join } = require('path');
1+
import { join } from 'node:path';
2+
3+
import pkg from 'fs-extra';
54

65
const RootPath = process.cwd();
6+
const {
7+
stat, mkdir, copy, remove,
8+
} = pkg;
79

810
/**
911
* Method that will erase the media/vendor folder
1012
* and populate the debugbar assets
1113
*
1214
* @returns {Promise}
1315
*/
14-
module.exports.cleanVendors = async () => {
16+
export const cleanVendors = async () => {
1517
if (process.env.SKIP_COMPOSER_CHECK === 'YES') {
1618
await mkdir('media/vendor/debugbar', { recursive: true, mode: 0o755 });
1719
// eslint-disable-next-line no-console
@@ -39,7 +41,7 @@ module.exports.cleanVendors = async () => {
3941
await remove(join(RootPath, 'media/vendor/debugbar/vendor/jquery'));
4042
} else {
4143
// eslint-disable-next-line no-console
42-
console.error('You need to run `npm install` AFTER the command `composer install`!!!. The debug plugin HASN\'T installed all its front end assets');
44+
console.error("You need to run `npm install` AFTER the command `composer install`!!!. The debug plugin HASN'T installed all its front end assets");
4345
process.exitCode = 1;
4446
}
4547
};

build/build-modules-js/init/common/concat-files.es6.js renamed to build/build-modules-js/init/common/concat-files.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { readFile, writeFile, existsSync } = require('fs-extra');
1+
import { readFile, writeFile, existsSync } from 'fs-extra';
22

33
const RootPath = process.cwd();
44

@@ -10,7 +10,7 @@ const RootPath = process.cwd();
1010
*
1111
* @returns {void}
1212
*/
13-
module.exports.concatFiles = async (files, output) => {
13+
export const concatFiles = async (files, output) => {
1414
const promises = [];
1515

1616
// eslint-disable-next-line no-restricted-syntax

build/build-modules-js/init/common/copy-all-files.es6.js renamed to build/build-modules-js/init/common/copy-all-files.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
const { copy } = require('fs-extra');
2-
const { join } = require('path');
1+
import { join } from 'node:path';
2+
3+
import { copy } from 'fs-extra';
34

45
const RootPath = process.cwd();
56

@@ -12,7 +13,7 @@ const RootPath = process.cwd();
1213
*
1314
* @returns { void }
1415
*/
15-
module.exports.copyAllFiles = async (dirName, name, type) => {
16+
export const copyAllFiles = async (dirName, name, type) => {
1617
const folderName = dirName === '/' ? '/' : `/${dirName}`;
1718
await copy(
1819
join(RootPath, `node_modules/${name}/${folderName}`),

0 commit comments

Comments
 (0)