From 869cece7f9ac3bfff9a92332a63372baca7fc629 Mon Sep 17 00:00:00 2001 From: Andreas Kienast <a.fernandez@scripting-base.de> Date: Tue, 23 Apr 2024 14:28:25 +0200 Subject: [PATCH] [TASK] Remove usage of "newer" in grunt build The grunt module `grunt-newer` was introduced with #90200 to help improving build times on consecutive single builds by running tasks on changed files only. This is nowadays not required anymore in JS build context, as it's possible in TypeScript to compile changed files only, which is already incorporated for quite a while. Therefore, the usage of `newer` is now removed in this context. However, to avoid running `terser` multiple times on the same, previously compiled files, the directory `Build/JavaScript` now gets removed before each TypeScript compilation. The postcss calculation is fast enough to not require grunt-newer at all, therefore grunt-newer is dropped here as well. Executed commands: npm remove grunt-newer Resolves: #103712 Releases: main, 12.4 Change-Id: I1c6b88945a45cb9a394a2beaa2ec8198865880b0 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/84006 Tested-by: Benjamin Franzke <ben@bnf.dev> Reviewed-by: Benjamin Franzke <ben@bnf.dev> Reviewed-by: Andreas Kienast <a.fernandez@scripting-base.de> Tested-by: core-ci <typo3@b13.com> Tested-by: Benjamin Kott <benjamin.kott@outlook.com> Reviewed-by: Benjamin Kott <benjamin.kott@outlook.com> Tested-by: Andreas Kienast <a.fernandez@scripting-base.de> --- Build/Gruntfile.js | 39 ++++++++++++++++++++++++--------------- Build/package-lock.json | 38 -------------------------------------- Build/package.json | 1 - 3 files changed, 24 insertions(+), 54 deletions(-) diff --git a/Build/Gruntfile.js b/Build/Gruntfile.js index 1c3ac0f3a3ea..4ab01d6b2f5c 100644 --- a/Build/Gruntfile.js +++ b/Build/Gruntfile.js @@ -454,11 +454,6 @@ module.exports = function (grunt) { ] } }, - newer: { - options: { - cache: './.cache/grunt-newer/' - } - }, npmcopy: { options: { clean: false, @@ -643,7 +638,6 @@ module.exports = function (grunt) { grunt.loadNpmTasks('grunt-exec'); grunt.loadNpmTasks('grunt-eslint'); grunt.loadNpmTasks('grunt-stylelint'); - grunt.loadNpmTasks('grunt-newer'); grunt.loadNpmTasks('grunt-concurrent'); /** @@ -668,7 +662,7 @@ module.exports = function (grunt) { * - sass * - postcss */ - grunt.registerTask('css', ['exec:stylefix', 'sass', 'newer:postcss']); + grunt.registerTask('css', ['exec:stylefix', 'sass', 'postcss']); /** * grunt update task @@ -686,10 +680,11 @@ module.exports = function (grunt) { * call "$ grunt compile-typescript" * * This task does the following things: - * - 1) Check all TypeScript files (*.ts) with ESLint which are located in sysext/<EXTKEY>/Resources/Private/TypeScript/*.ts - * - 2) Compiles all TypeScript files (*.ts) which are located in sysext/<EXTKEY>/Resources/Private/TypeScript/*.ts + * - 1) Remove previously built JS files from local JavaScript directory + * - 2) Check all TypeScript files (*.ts) with ESLint which are located in Sources/TypeScript/<EXTKEY>/*.ts + * - 3) Compiles all TypeScript files (*.ts) which are located in Sources/TypeScript/<EXTKEY>/*.ts */ - grunt.registerTask('compile-typescript', ['tsconfig', 'eslint', 'exec:ts']); + grunt.registerTask('compile-typescript', ['clear-built-js', 'tsconfig', 'eslint', 'exec:ts']); grunt.registerTask('copy-lit', ['es-module-lexer-init', 'copy:lit']); @@ -703,7 +698,7 @@ module.exports = function (grunt) { * - 2) Copy all generated JavaScript files to public folders * - 3) Minify build */ - grunt.registerTask('scripts', ['compile-typescript', 'newer:terser:typescript', 'es-module-lexer-init', 'newer:copy:ts_files']); + grunt.registerTask('scripts', ['compile-typescript', 'terser:typescript', 'es-module-lexer-init', 'copy:ts_files']); /** * grunt clear-build task @@ -712,10 +707,24 @@ module.exports = function (grunt) { * * Removes all build-related assets, e.g. cache and built files */ - grunt.registerTask('clear-build', function () { - grunt.option('force'); - grunt.file.delete('.cache'); - grunt.file.delete('JavaScript'); + grunt.registerTask('clear-build', ['clear-build-cache', 'clear-built-js']); + + /** + * Removes build-related caching information + */ + grunt.registerTask('clear-build-cache', function () { + if (grunt.file.isDir('.cache')) { + grunt.file.delete('.cache'); + } + }); + + /** + * Removes build JavaScript files (incorporated altogether with TypeScript compilations) + */ + grunt.registerTask('clear-built-js', function () { + if (grunt.file.isDir('JavaScript')) { + grunt.file.delete('JavaScript'); + } }); /** diff --git a/Build/package-lock.json b/Build/package-lock.json index 800eb8497a72..e207717673ff 100644 --- a/Build/package-lock.json +++ b/Build/package-lock.json @@ -121,7 +121,6 @@ "grunt-contrib-watch": "~1.1.0", "grunt-eslint": "^24.3.0", "grunt-exec": "^3.0.0", - "grunt-newer": "^1.3.0", "grunt-npmcopy": "^0.2.0", "grunt-sass": "^3.1.0", "grunt-stylelint": "^0.18.0", @@ -5436,13 +5435,6 @@ "node": ">=8" } }, - "node_modules/async": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz", - "integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=", - "dev": true, - "license": "MIT" - }, "node_modules/async-mutex": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/async-mutex/-/async-mutex-0.4.0.tgz", @@ -8692,36 +8684,6 @@ "node": ">= 8" } }, - "node_modules/grunt-newer": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/grunt-newer/-/grunt-newer-1.3.0.tgz", - "integrity": "sha1-g8y3od2ny9irI7BZAk6+YUrS80I=", - "dev": true, - "license": "MIT", - "dependencies": { - "async": "^1.5.2", - "rimraf": "^2.5.2" - }, - "engines": { - "node": ">= 0.8.0" - }, - "peerDependencies": { - "grunt": ">=0.4.1" - } - }, - "node_modules/grunt-newer/node_modules/rimraf": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", - "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", - "dev": true, - "license": "ISC", - "dependencies": { - "glob": "^7.1.3" - }, - "bin": { - "rimraf": "bin.js" - } - }, "node_modules/grunt-npmcopy": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/grunt-npmcopy/-/grunt-npmcopy-0.2.0.tgz", diff --git a/Build/package.json b/Build/package.json index 6cd571b59956..f99ee8d668bb 100644 --- a/Build/package.json +++ b/Build/package.json @@ -48,7 +48,6 @@ "grunt-contrib-watch": "~1.1.0", "grunt-eslint": "^24.3.0", "grunt-exec": "^3.0.0", - "grunt-newer": "^1.3.0", "grunt-npmcopy": "^0.2.0", "grunt-sass": "^3.1.0", "grunt-stylelint": "^0.18.0", -- GitLab