From c9ed04e7c7b9e24fe616c1632fa9410e3e3bee8a Mon Sep 17 00:00:00 2001 From: Aakash Singh Date: Thu, 19 Sep 2024 19:20:01 +0530 Subject: [PATCH] Convert supported browsers command to a script (#8564) --- package.json | 4 ++-- scripts/generate-supported-browsers.mjs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 scripts/generate-supported-browsers.mjs diff --git a/package.json b/package.json index cfc0b3389a2..cc2c7b955c2 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "scripts": { "build:react": "cross-env NODE_ENV=production vite build", "build": "npm run generate-build-meta && npm run supported-browsers && npm run build:react", - "dev": "vite", + "dev": "npm run supported-browsers && vite", "preview": "cross-env NODE_ENV=production vite preview", "generate-build-meta": "node ./scripts/generate-build-version.js", "test": "snyk test", @@ -41,7 +41,7 @@ "lint": "eslint ./src", "lint-fix": "eslint ./src --fix", "format": "prettier ./src --write", - "supported-browsers": "echo \"export default $(browserslist-useragent-regexp --allowHigherVersions --ignorePatch --ignoreMinor);\" | sed 's/\\x1b\\[[0-9;]*m//g' > src/supportedBrowsers.ts" + "supported-browsers": "node ./scripts/generate-supported-browsers.mjs" }, "dependencies": { "@fontsource/inter": "^5.0.21", diff --git a/scripts/generate-supported-browsers.mjs b/scripts/generate-supported-browsers.mjs new file mode 100644 index 00000000000..2f8b627c57d --- /dev/null +++ b/scripts/generate-supported-browsers.mjs @@ -0,0 +1,17 @@ +import { getUserAgentRegex } from 'browserslist-useragent-regexp'; +import fs from 'fs'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +const regex = getUserAgentRegex({ + ignoreMinor: true, + ignorePatch: true, + allowZeroSubversions: false, + allowHigherVersions: true, +}); + +const supportedBrowsersPath = path.resolve(__dirname, '../src/supportedBrowsers.ts'); +fs.writeFileSync(supportedBrowsersPath, `export default ${regex};`);