MOBILE-3947 chore: Update check-es-compat package

main
Pau Ferrer Ocaña 2024-01-24 11:25:19 +01:00
parent 634d5bc7fc
commit f20a30dbb1
5 changed files with 76 additions and 76 deletions

View File

@ -59,8 +59,6 @@ jobs:
npm run build:prod npm run build:prod
npm run prod --prefix cordova-plugin-moodleapp npm run prod --prefix cordova-plugin-moodleapp
- name: JavaScript code compatibility - 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: | 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 npx check-es-compat cordova-plugin-moodleapp/www/*.js

15
package-lock.json generated
View File

@ -118,7 +118,7 @@
"@types/webpack-env": "^1.18.4", "@types/webpack-env": "^1.18.4",
"@typescript-eslint/eslint-plugin": "^6.0.0", "@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^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", "concurrently": "^8.2.0",
"cordova-plugin-moodleapp": "file:cordova-plugin-moodleapp", "cordova-plugin-moodleapp": "file:cordova-plugin-moodleapp",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
@ -159,8 +159,8 @@
"devDependencies": { "devDependencies": {
"chokidar-cli": "^3.0.0", "chokidar-cli": "^3.0.0",
"concurrently": "^8.2.0", "concurrently": "^8.2.0",
"esbuild": "^0.18.11", "esbuild": "^0.18.20",
"typescript": "^5.1.6" "typescript": "^5.3.3"
} }
}, },
"cordova-plugin-moodleapp/node_modules/@esbuild/android-arm": { "cordova-plugin-moodleapp/node_modules/@esbuild/android-arm": {
@ -11550,12 +11550,13 @@
} }
}, },
"node_modules/check-es-compat": { "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, "dev": true,
"license": "MIT",
"dependencies": { "dependencies": {
"eslint": "^8.6.0", "eslint": "^8.56.0",
"eslint-plugin-ecmascript-compat": "^3.1.0" "eslint-plugin-ecmascript-compat": "^3.2.0"
}, },
"bin": { "bin": {
"check-es-compat": "bin/cli.mjs" "check-es-compat": "bin/cli.mjs"

View File

@ -153,7 +153,7 @@
"@types/webpack-env": "^1.18.4", "@types/webpack-env": "^1.18.4",
"@typescript-eslint/eslint-plugin": "^6.0.0", "@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^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", "concurrently": "^8.2.0",
"cordova-plugin-moodleapp": "file:cordova-plugin-moodleapp", "cordova-plugin-moodleapp": "file:cordova-plugin-moodleapp",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",

View File

@ -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);
+}

View File

@ -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);
+}