From 41dd83f27a1f1b865ee23f15b57db1684406878b Mon Sep 17 00:00:00 2001 From: Faisal Salman Date: Wed, 10 Dec 2025 11:21:45 +0700 Subject: [PATCH] Fix #814 - Resolve syntax error related to import renaming in ESM version build --- package.json | 6 ++++-- script/build-esm.js | 1 + script/test-all.sh | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index a42f132..0d25f2c 100755 --- a/package.json +++ b/package.json @@ -232,9 +232,9 @@ "fuzz": "jazzer ./test/fuzz/redos.js --sync", "test": "./script/test-all.sh", "test:dts-lint": "tsd --typings src/main/ua-parser.d.ts --files test/static/dts-lint.ts", - "test:eslint": "eslint src && eslint script", + "test:eslint": "eslint --no-config-lookup src", "test:jshint": "jshint src/main", - "test:lockfile-lint": "npx lockfile-lint -p package-lock.json", + "test:lockfile-lint": "lockfile-lint -p package-lock.json", "test:mocha": "mocha --recursive test/unit", "test:playwright": "npx playwright install && playwright test test/e2e --browser all" }, @@ -247,7 +247,9 @@ "@babel/parser": "7.15.8", "@babel/traverse": "7.23.2", "@playwright/test": "^1.57.0", + "eslint": "^9.39.1", "jshint": "~2.13.6", + "lockfile-lint": "^4.14.1", "mocha": "~8.2.0", "requirejs": "2.3.2", "safe-regex": "^2.1.1", diff --git a/script/build-esm.js b/script/build-esm.js index 89f390b..2ea0c0b 100755 --- a/script/build-esm.js +++ b/script/build-esm.js @@ -4,6 +4,7 @@ const fs = require('fs'); const defaultReplacements = { mjs: [ + [/(?<=const.+)(:)(?=.+require)/ig, ' as'], [/const (.+?)\s*=\s*require\(\'\.(.+)\'\)/ig, 'import $1 from \'\.$2.mjs\''], [/const (.+?)\s*=\s*require\(\'(.+)\'\)/ig, 'import $1 from \'$2\''], [/module\.exports =/ig, 'export'] diff --git a/script/test-all.sh b/script/test-all.sh index f00fea2..e7e0c7e 100755 --- a/script/test-all.sh +++ b/script/test-all.sh @@ -9,7 +9,7 @@ echo ' - lint js code ' npm run test:jshint || exit 1 -#npm run test:eslint || exit 1 +npm run test:eslint || exit 1 echo ' - test using mocha