Socket
Socket
Sign inDemoInstall

browserslist-to-esbuild

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browserslist-to-esbuild - npm Package Compare versions

Comparing version 1.2.0 to 2.0.0

cli/index.js

30

package.json
{
"name": "browserslist-to-esbuild",
"version": "1.2.0",
"description": "Use browserslist with esbuild",
"version": "2.0.0",
"description": "Get esbuild-compatible targets from a browserlist config",
"license": "MIT",

@@ -18,8 +18,12 @@ "repository": "marcofugaro/browserslist-to-esbuild",

],
"type": "commonjs",
"main": "./src/index.js",
"exports": "./src/index.js",
"types": "./src/index.d.ts",
"type": "module",
"exports": {
"types": "./src/index.d.ts",
"default": "./src/index.js"
},
"bin": {
"browserslist-to-esbuild": "./cli/index.js"
},
"engines": {
"node": ">=12"
"node": ">=18"
},

@@ -30,10 +34,16 @@ "scripts": {

"files": [
"src/"
"src/",
"cli/"
],
"peerDependencies": {
"browserslist": "*"
},
"dependencies": {
"browserslist": "^4.17.3"
"meow": "^13.0.0"
},
"devDependencies": {
"ava": "^3.15.0"
"ava": "^6.0.1",
"browserslist": "^4.22.2",
"sinon": "^17.0.1"
}
}

@@ -9,2 +9,4 @@ # browserslist-to-esbuild

Make sure you have `browserslist` already installed in your project, then:
```

@@ -30,3 +32,3 @@ npm install --save-dev browserslist-to-esbuild

build({
await build({
entryPoints: ['input.js'],

@@ -36,3 +38,3 @@ outfile: 'output.js',

target: browserslistToEsbuild(), // --> ["chrome79", "edge92", "firefox91", "safari13.1"]
}).catch(() => process.exit(1))
})
```

@@ -55,1 +57,19 @@

An array of string of browsers [compatible with browserslist](https://github.com/browserslist/browserslist#full-list). If none is passed, a browserslist config is searched in the script running directory.
## CLI
You can also use this package on the cli to test out the command in your project.
If no argument is passed, the browserslist config is searched in the script running directory.
Here is some example usage:
```bash
$ npx browserslist-to-esbuild
chrome109 edge118 firefox115 ios15.6 opera102 safari15.6
$ npx browserslist-to-esbuild '>0.2%, not dead'
chrome103 edge87 firefox115 ios12.2 opera102 safari14.1
$ npx browserslist-to-esbuild '>0.2%' 'not dead'
chrome103 edge87 firefox115 ios12.2 opera102 safari14.1
```

@@ -1,2 +0,2 @@

declare const browserslistToEsbuild: (browserslistConfig?: string[] | string) => string[]
declare const browserslistToEsbuild: (browserslistConfig?: readonly string[] | string) => string[]
export default browserslistToEsbuild

@@ -1,6 +0,6 @@

const browserslist = require('browserslist')
import browserslist from 'browserslist'
// convert the browserslist field in package.json to
// esbuild compatible array of browsers
function browserslistToEsbuild(browserslistConfig) {
export default function browserslistToEsbuild(browserslistConfig) {
if (!browserslistConfig) {

@@ -14,3 +14,13 @@ // the path from where the script is run

const SUPPORTED_ESBUILD_TARGETS = ['es', 'chrome', 'edge', 'firefox', 'ios', 'node', 'safari']
const SUPPORTED_ESBUILD_TARGETS = [
'es',
'chrome',
'edge',
'firefox',
'ios',
'node',
'safari',
'opera',
'ie',
]

@@ -31,2 +41,10 @@ // https://github.com/eBay/browserslist-config/issues/16#issuecomment-863870093

.filter((b) => !UNSUPPORTED.some((u) => b.startsWith(u)))
// replaces safari TP with latest safari version
.map((b) => {
if (b === 'safari TP') {
return browserslist('last 1 safari version')[0]
}
return b
})
// transform into ['chrome', '88']

@@ -58,5 +76,9 @@ .map((b) => b.split(separator))

})
// only get the ones supported by esbuild
// removes invalid versions that will break esbuild
// https://github.com/evanw/esbuild/blob/35c0d65b9d4f29a26176404d2890d1b499634e9f/compat-table/src/caniuse.ts#L119-L122
.filter((b) => /^\d+(\.\d+)*$/.test(b[1]))
// only get the targets supported by esbuild
.filter((b) => SUPPORTED_ESBUILD_TARGETS.includes(b[0]))
// only get the oldest version
// only get the oldest version, assuming that the older version
// is last in the array
.reduce((acc, b) => {

@@ -76,3 +98,1 @@ const existingIndex = acc.findIndex((br) => br[0] === b[0])

}
module.exports = browserslistToEsbuild
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc