Skip to content

Commit 6525648

Browse files
authored
Merge pull request #61 from adenvt/feat/new-polyfill-library
feat(deps): migrate from `polyfill-library` to `@mrhenry/polyfill-library`
2 parents c95e90f + d0fdbb0 commit 6525648

File tree

7 files changed

+293
-127
lines changed

7 files changed

+293
-127
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@ on:
1111

1212
jobs:
1313
test:
14-
runs-on: ${{ matrix.os }}
14+
runs-on: ubuntu-latest
1515

1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
os:
20-
- ubuntu-latest
2119
node-version:
22-
- 16
23-
- 18
24-
- 19
20+
- 20
21+
- 22
2522

2623
steps:
2724
- name: Git Checkout
@@ -56,6 +53,6 @@ jobs:
5653

5754
- name: Upload to Codecov
5855
uses: codecov/codecov-action@v4
59-
if: matrix.node-version == 16 && matrix.os == 'ubuntu-latest'
56+
if: matrix.node-version == 20
6057
with:
6158
fail_ci_if_error: false

.github/workflows/release.yml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,12 @@ on:
88
tags:
99
- '*'
1010

11+
env:
12+
NODE_VERSION: 16
13+
1114
jobs:
1215
release:
13-
runs-on: ${{ matrix.os }}
14-
15-
strategy:
16-
fail-fast: false
17-
matrix:
18-
os:
19-
- ubuntu-latest
20-
node-version:
21-
- 16
16+
runs-on: ubuntu-latest
2217

2318
steps:
2419
- name: Git Checkout
@@ -39,10 +34,10 @@ jobs:
3934
restore-keys: |
4035
${{ runner.os }}-yarn-
4136
42-
- name: Use Node.js ${{ matrix.node-version }}
37+
- name: Use Node.js ${{ env.NODE_VERSION }}
4338
uses: actions/setup-node@v4
4439
with:
45-
node-version: ${{ matrix.node-version }}
40+
node-version: ${{ env.NODE_VERSION }}
4641
registry-url: 'https://registry.npmjs.org'
4742
cache: "yarn"
4843

@@ -52,7 +47,7 @@ jobs:
5247
- name: Generate Changelog
5348
run: npx changelogithub --to $GITHUB_REF_NAME
5449
env:
55-
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5651
continue-on-error: true
5752

5853
- name: Publish Package

package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,17 @@
3030
},
3131
"license": "MIT",
3232
"dependencies": {
33-
"browserslist": "^4.21.4",
34-
"meow": "^12.0.0",
35-
"polyfill-library": "^4.6.0",
36-
"semver": "^7.3.8",
37-
"ufo": "^1.0.1"
33+
"@mrhenry/polyfill-library": "^5.1.0",
34+
"browserslist": "^4.23.3",
35+
"meow": "^11.0.0",
36+
"semver": "^7.6.3",
37+
"ufo": "^1.5.4"
3838
},
3939
"devDependencies": {
4040
"@privyid/browserslist-config": "^0.27.0",
4141
"@privyid/eslint-config-persona": "^1.0.0-rc.6",
4242
"@tsconfig/node20": "^20.1.4",
4343
"@types/jest": "^29.4.0",
44-
"@types/polyfill-library": "^3.108.1",
4544
"@types/semver": "^7.3.13",
4645
"@typescript-eslint/eslint-plugin": "5.62.0",
4746
"@typescript-eslint/parser": "5.62.0",

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import browserslist from 'browserslist'
2-
import polyfill from 'polyfill-library'
2+
import polyfill from '@mrhenry/polyfill-library'
33
import getBrowser from './lib/get-browser.js'
44
import getVersionRange from './lib/get-version-range.js'
55
import isVersionMatch from './lib/version-match.js'

src/lib/version-match.spec.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ interface ITestCase {
99
describe('isVersionMatch', () => {
1010
const cases: ITestCase[] = [
1111
{
12-
browserVersion: '14.1', featureVersion: '<15.0', matches: true,
12+
browserVersion: '14.1',
13+
featureVersion: '<15.0',
14+
matches : true,
1315
},
1416
{
15-
browserVersion: '14.1', featureVersion: '>14.1', matches: false,
17+
browserVersion: '14.1',
18+
featureVersion: '>14.1',
19+
matches : false,
1620
},
1721
{
18-
browserVersion: '1.0.1', featureVersion: '1 - 14.1', matches: true,
22+
browserVersion: '1.0.1',
23+
featureVersion: '1 - 14.1',
24+
matches : true,
1925
},
2026
]
2127

src/types.d.ts

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/* eslint-disable @typescript-eslint/triple-slash-reference */
2+
/// <reference types="node" />
3+
4+
declare module '@mrhenry/polyfill-library' {
5+
import type { Readable } from 'node:stream'
6+
7+
export interface PolyfillConfig {
8+
aliases: string[],
9+
dependencies: string[],
10+
spec: string,
11+
repo: string,
12+
docs: string,
13+
license: string,
14+
notes: string[],
15+
browsers: { [browser: string]: string },
16+
install: { [key: string]: string | string[] },
17+
}
18+
19+
export interface PolyfillMeta extends PolyfillConfig {
20+
detectSource: string,
21+
baseDir: string,
22+
hasTests: boolean,
23+
isTestable: boolean,
24+
isPublic: boolean,
25+
size: number,
26+
}
27+
28+
export interface Options {
29+
/**
30+
* Name of the JavaScript function to call after the polyfill bundle is loaded.
31+
* @default false
32+
*/
33+
callback?: false | string,
34+
/**
35+
* Whether to return the minified or raw implementation of the polyfills.
36+
* @default true
37+
*/
38+
minify?: boolean,
39+
/**
40+
* Whether to return all polyfills or no polyfills if the user-agent is unknown or unsupported.
41+
* @default 'polyfill'
42+
*/
43+
unknown?: 'ignore' | 'polyfill',
44+
/**
45+
* Which features should be returned if the user-agent does not support them natively.
46+
* @default {}
47+
*/
48+
features?: { [featureName: string]: { flags: Flag[] | Set<Flag> } },
49+
/**
50+
* Which features should be excluded from the returned object.
51+
* @default []
52+
*/
53+
excludes?: string[],
54+
/**
55+
* The user-agent string to check each feature against.
56+
* @default ''
57+
*/
58+
ua?: {
59+
getFamily: () => string,
60+
satisfies: () => boolean,
61+
isUnknown: () => boolean,
62+
},
63+
/**
64+
* Whether to include a script that reports anonymous usage data in the polyfill bundle.
65+
* @default false
66+
*/
67+
rum?: boolean,
68+
}
69+
70+
export type Flag = 'always' | 'gated'
71+
72+
export interface Feature {
73+
[featureName: string]: {
74+
flags: Set<Flag>,
75+
aliasOf: Set<string>,
76+
dependencyOf: Set<string>,
77+
},
78+
}
79+
80+
export interface AliasesMap {
81+
all: string[],
82+
default: string[],
83+
es5: string[],
84+
es6: string[],
85+
es7: string[],
86+
es2015: string[],
87+
es2016: string[],
88+
es2017: string[],
89+
es2018: string[],
90+
es2019: string[],
91+
es2021: string[],
92+
[aliases: string]: string[],
93+
}
94+
95+
/**
96+
* Get a list of all the aliases which exist within the collection of polyfill sources.
97+
* Returns a promise which resolves with an object mapping all the aliases within the collection
98+
* to the polyfills they include.
99+
*/
100+
export function listAliases (): Promise<AliasesMap>
101+
102+
/**
103+
* Get a list of all the polyfills which exist within the collection of polyfill sources.
104+
* Returns a Promise which resolves with an array of all the polyfills within the collection.
105+
*/
106+
export function listAllPolyfills (): Promise<string[]>
107+
108+
/**
109+
* Get the metadata for a specific polyfill within the collection of polyfill sources.
110+
* @param featureName - The name of a polyfill whose metadata should be returned.
111+
* Returns a Promise which resolves with the metadata or with undefined if no metadata exists
112+
* for the polyfill.
113+
*/
114+
export function describePolyfill (featureName: string): Promise<PolyfillMeta | undefined>
115+
116+
/**
117+
* Create an options object for use with `getPolyfills` or `getPolyfillString`.
118+
* @param opts - Valid keys are uaString, minify, unknown, excludes, rum and features.
119+
* Returns an object which has merged `opts` with the defaults option values.
120+
*/
121+
export function getOptions (opts?: Options): Options
122+
123+
/**
124+
* Given a set of features that should be polyfilled in 'opts.features' (with flags i.e.
125+
* `{<featurename>: {flags:Set[<flaglist>]}, ...}`), determine which have a
126+
* configuration valid for the given opts.uaString, and return a promise of set of canonical
127+
* (unaliased) features (with flags) and polyfills.
128+
* @param opts - Valid keys are uaString, minify, unknown, excludes, rum and features.
129+
* Returns a Promise which resolves to an Object which contains the canonicalised feature
130+
* definitions filtered for UA.
131+
*/
132+
export function getPolyfills (opts?: Options): Promise<Feature>
133+
134+
/**
135+
* Create a polyfill bundle.
136+
* @param opts - Valid keys are uaString, minify, unknown, excludes, rum and features.
137+
* Returns a polyfill bundle as either a utf-8 ReadStream or as a Promise of a utf-8 String.
138+
*/
139+
export function getPolyfillString (opts?: Options): Promise<Readable | string>
140+
141+
}

0 commit comments

Comments
 (0)