Skip to content

Commit

Permalink
feat: add support for new "opera" and "ie" esbuild targets (#74)
Browse files Browse the repository at this point in the history
Co-authored-by: Nihal Gonsalves <[email protected]>
  • Loading branch information
jfsiii and nihalgonsalves authored Dec 6, 2022
1 parent 50e07d4 commit c4720bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/resolveToEsbuildTarget.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ describe('resolveToEsbuildTarget', () => {
'firefox 88',
'node 14.16.0',
'ios_saf 14.0-14.4',
'ios_saf 14.0-14.4',
'opera 91',
];

const result = resolveToEsbuildTarget(browserslist(query, {}), logFn);
Expand All @@ -28,34 +30,35 @@ describe('resolveToEsbuildTarget', () => {
{ target: EsbuildEngine.Firefox, version: '88' },
{ target: EsbuildEngine.IOS, version: '14.0' },
{ target: EsbuildEngine.Node, version: '14.16.0' },
{ target: EsbuildEngine.Opera, version: '91' },
]);

expect(logs).toEqual([]);
});

it('throws an error on no targets', () => {
const query = ['ie 11'];
const query = ['ie_mob 11'];

expect(() =>
resolveToEsbuildTarget(browserslist(query, {}), logFn),
).toThrow(/Could not resolve/);

expect(logs).toMatchInlineSnapshot(`
[
"Skipping unknown target: entry=ie 11, browser=ie, version=11",
"Skipping unknown target: entry=ie_mob 11, browser=ie_mob, version=11",
]
`);
});

it('skips unmappable targets', () => {
const query = ['chrome 90', 'ie 11'];
const query = ['chrome 90', 'ie_mob 11'];

const result = resolveToEsbuildTarget(browserslist(query, {}), logFn);

expect(result).toEqual([{ target: EsbuildEngine.Chrome, version: '90' }]);
expect(logs).toMatchInlineSnapshot(`
[
"Skipping unknown target: entry=ie 11, browser=ie, version=11",
"Skipping unknown target: entry=ie_mob 11, browser=ie_mob, version=11",
]
`);
});
Expand Down
8 changes: 7 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@ export enum BrowserslistKind {
Node = 'node',
}

/** https://github.com/evanw/esbuild/blob/v0.11.15/internal/compat/js_table.go#L17-L35 */
/** https://github.com/evanw/esbuild/blob/v0.15.12/internal/compat/js_table.go#L21-L47 */
export enum EsbuildEngine {
Chrome = 'chrome',
Edge = 'edge',
ES = 'es',
Firefox = 'firefox',
Hermes = 'hermes',
IE = 'ie',
IOS = 'ios',
Node = 'node',
Opera = 'opera',
Rhino = 'rhino',
Safari = 'safari',
}

Expand All @@ -53,6 +57,8 @@ export const BrowserslistEsbuildMapping: Partial<
[BrowserslistKind.Safari]: EsbuildEngine.Safari,
[BrowserslistKind.iOS]: EsbuildEngine.IOS,
[BrowserslistKind.Node]: EsbuildEngine.Node,
[BrowserslistKind.IE]: EsbuildEngine.IE,
[BrowserslistKind.Opera]: EsbuildEngine.Opera,
// approximate mapping
[BrowserslistKind.Android]: EsbuildEngine.Chrome,
[BrowserslistKind.AndroidChrome]: EsbuildEngine.Chrome,
Expand Down

0 comments on commit c4720bc

Please sign in to comment.