diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 5d18f894d..ff5e04e2a 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -59,8 +59,6 @@ jobs: npm run build:prod npm run prod --prefix cordova-plugin-moodleapp - name: JavaScript code compatibility - # 6 BigInt usage errors are expected, they are fine without polyfill because they are only used if available. - # See https://github.com/videojs/mpd-parser/blob/v0.22.1/src/segment/urlType.js run: | - result=$(npx check-es-compat www/*.js --polyfills="{Array,String,TypedArray}.prototype.at,Array.prototype.flatMap,Array.prototype.flat,Array.prototype.includes,globalThis,Object.fromEntries,Object.hasOwn,Promise.prototype.finally,String.prototype.matchAll,String.prototype.trimRight" | grep "6 problems (6 errors, 0 warnings)" | wc -l); test $result -eq 1 + npx check-es-compat www/*.js --polyfills="\{Array,String,TypedArray\}.prototype.at,Array.prototype.flatMap,Array.prototype.flat,Array.prototype.includes,globalThis,Object.fromEntries,Object.hasOwn,Promise.prototype.finally,String.prototype.matchAll,String.prototype.trimRight" | grep "No issues found. Files are compatible with the target runtimes." npx check-es-compat cordova-plugin-moodleapp/www/*.js diff --git a/package-lock.json b/package-lock.json index 79e0edb35..a1481f4fb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -118,7 +118,7 @@ "@types/webpack-env": "^1.18.4", "@typescript-eslint/eslint-plugin": "^6.0.0", "@typescript-eslint/parser": "^6.0.0", - "check-es-compat": "3.1.0", + "check-es-compat": "3.2.0", "concurrently": "^8.2.0", "cordova-plugin-moodleapp": "file:cordova-plugin-moodleapp", "cross-env": "^7.0.3", @@ -159,8 +159,8 @@ "devDependencies": { "chokidar-cli": "^3.0.0", "concurrently": "^8.2.0", - "esbuild": "^0.18.11", - "typescript": "^5.1.6" + "esbuild": "^0.18.20", + "typescript": "^5.3.3" } }, "cordova-plugin-moodleapp/node_modules/@esbuild/android-arm": { @@ -11550,12 +11550,13 @@ } }, "node_modules/check-es-compat": { - "version": "3.1.0", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/check-es-compat/-/check-es-compat-3.2.0.tgz", + "integrity": "sha512-9YfgenvN41ZLBxMAXXXdW5mn4CdrhPIpI6QluAVrsop5wFgrDbF3WP8pXiNru/Y+AbxjQiki2+5I3wDVflqPeA==", "dev": true, - "license": "MIT", "dependencies": { - "eslint": "^8.6.0", - "eslint-plugin-ecmascript-compat": "^3.1.0" + "eslint": "^8.56.0", + "eslint-plugin-ecmascript-compat": "^3.2.0" }, "bin": { "check-es-compat": "bin/cli.mjs" diff --git a/package.json b/package.json index 4d2d95149..7dddd255a 100644 --- a/package.json +++ b/package.json @@ -153,7 +153,7 @@ "@types/webpack-env": "^1.18.4", "@typescript-eslint/eslint-plugin": "^6.0.0", "@typescript-eslint/parser": "^6.0.0", - "check-es-compat": "3.1.0", + "check-es-compat": "3.2.0", "concurrently": "^8.2.0", "cordova-plugin-moodleapp": "file:cordova-plugin-moodleapp", "cross-env": "^7.0.3", diff --git a/patches/check-es-compat+3.1.0.patch b/patches/check-es-compat+3.1.0.patch deleted file mode 100644 index 37bab9c96..000000000 --- a/patches/check-es-compat+3.1.0.patch +++ /dev/null @@ -1,65 +0,0 @@ -diff --git a/node_modules/check-es-compat/bin/cli.mjs b/node_modules/check-es-compat/bin/cli.mjs -index 25c53f5..26ce475 100755 ---- a/node_modules/check-es-compat/bin/cli.mjs -+++ b/node_modules/check-es-compat/bin/cli.mjs -@@ -17,7 +17,8 @@ if (args.length === 0) { - } - } - --async function execute(files) { -+async function execute(args) { -+ const { files, polyfills } = parseArguments(args); - const eslint = new ESLint({ - // Ignore any config files - useEslintrc: false, -@@ -34,7 +35,7 @@ async function execute(files) { - es2021: true, - }, - rules: { -- 'ecmascript-compat/compat': 'error', -+ 'ecmascript-compat/compat': ['error', { polyfills }], - }, - }, - }); -@@ -46,3 +47,41 @@ async function execute(files) { - - return { hasErrors: results.some((result) => result.errorCount > 0) }; - } -+ -+function parseArguments(args) { -+ const files = []; -+ const polyfills = []; -+ let nextArgIsPolyfills = false; -+ -+ for (const arg of args) { -+ if (nextArgIsPolyfills) { -+ nextArgIsPolyfills = false; -+ polyfills.push(...splitPolyfillsArgument(arg)); -+ continue; -+ } -+ -+ if (arg.startsWith('--polyfills')) { -+ if (arg.startsWith('--polyfills=')) { -+ polyfills.push(...splitPolyfillsArgument(arg.slice(12))); -+ } else { -+ nextArgIsPolyfills = true; -+ } -+ -+ continue; -+ } -+ -+ files.push(arg); -+ } -+ -+ return { files, polyfills }; -+} -+ -+function splitPolyfillsArgument(polyfills) { -+ const prototypeAtPolyfill = '{Array,String,TypedArray}.prototype.at'; -+ const prototypeAtPlaceholder = '{{PROTOTYPEAT}}'; -+ -+ return polyfills -+ .replace(prototypeAtPolyfill, prototypeAtPlaceholder) -+ .split(',') -+ .map(polyfill => polyfill === prototypeAtPlaceholder ? prototypeAtPolyfill : polyfill); -+} diff --git a/patches/check-es-compat+3.2.0.patch b/patches/check-es-compat+3.2.0.patch new file mode 100644 index 000000000..b4e78ebc6 --- /dev/null +++ b/patches/check-es-compat+3.2.0.patch @@ -0,0 +1,66 @@ +diff --git a/node_modules/check-es-compat/bin/cli.mjs b/node_modules/check-es-compat/bin/cli.mjs +index f4c0b55..381c321 100755 +--- a/node_modules/check-es-compat/bin/cli.mjs ++++ b/node_modules/check-es-compat/bin/cli.mjs +@@ -17,7 +17,8 @@ if (args.length === 0) { + } + } + +-async function execute(files) { ++async function execute(args) { ++ const { files, polyfills } = parseArguments(args); + const eslint = new ESLint({ + // Ignore any config files + useEslintrc: false, +@@ -34,7 +35,7 @@ async function execute(files) { + es2023: true, + }, + rules: { +- 'ecmascript-compat/compat': 'error', ++ 'ecmascript-compat/compat': ['error', { polyfills }], + }, + }, + }); +@@ -46,3 +47,42 @@ async function execute(files) { + + return { hasErrors: results.some((result) => result.errorCount > 0) }; + } ++ ++function parseArguments(args) { ++ const files = []; ++ const polyfills = []; ++ let nextArgIsPolyfills = false; ++ ++ for (const arg of args) { ++ if (nextArgIsPolyfills) { ++ nextArgIsPolyfills = false; ++ polyfills.push(...splitPolyfillsArgument(arg)); ++ continue; ++ } ++ ++ if (arg.startsWith('--polyfills')) { ++ if (arg.startsWith('--polyfills=')) { ++ polyfills.push(...splitPolyfillsArgument(arg.slice(12))); ++ } else { ++ nextArgIsPolyfills = true; ++ } ++ ++ continue; ++ } ++ ++ files.push(arg); ++ } ++ ++ return { files, polyfills }; ++} ++ ++function splitPolyfillsArgument(polyfills) { ++ const prototypeAtPolyfill = '{Array,String,TypedArray}.prototype.at'; ++ const prototypeAtPlaceholder = '{{PROTOTYPEAT}}'; ++ ++ return polyfills ++ .replaceAll('\\', '') ++ .replace(prototypeAtPolyfill, prototypeAtPlaceholder) ++ .split(',') ++ .map(polyfill => polyfill === prototypeAtPlaceholder ? prototypeAtPolyfill : polyfill); ++}