Skip to content

Commit

Permalink
Merge branch 'main' into reduce-memory-consumption--rational-bull-ter…
Browse files Browse the repository at this point in the history
…rier-d4ef3d281a
  • Loading branch information
romainmenke authored Jul 1, 2024
2 parents ff16383 + e585f3a commit c5a426c
Show file tree
Hide file tree
Showing 272 changed files with 100 additions and 46 deletions.
4 changes: 2 additions & 2 deletions .github/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ This folder contains 4 files:
- [config.toml](#configtoml)
- [detect.js](#detectjs)
- [polyfill.js](#polyfilljs)
- [tests.js](#testsjs)
- [polyfill.test.js](#polyfilltestjs)

### config.toml

Expand Down Expand Up @@ -127,7 +127,7 @@ If your polyfill requires other features to work [list them in the config file](

Make sure your polyfill [does not squat on proposed names in speculative polyfills](https://www.w3.org/2001/tag/doc/polyfills/#don-t-squat-on-proposed-names-in-speculative-polyfills).

### tests.js
### polyfill.test.js

You should refer to the feature's specification to see how the feature should work.

Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
merge_group:
pull_request:
workflow_dispatch:
push:
branches:
- main

permissions:
security-events: write
Expand Down Expand Up @@ -43,7 +46,7 @@ jobs:
- name: setup node
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
cache: 'npm'

- run: npm ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
fetch-depth: 1
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
cache: 'npm'
- run: npm ci
- run: npm run build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-polyfills-exhaustive.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
cache: 'npm'

- name: env
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-polyfills.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
# <insert integration tests needing secrets>
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
cache: 'npm'

- name: env
Expand Down
16 changes: 15 additions & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,28 @@ on:
jobs:
unit-test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node: [18, 20, 22]
include:
- node: 18
older_node_version: true
- node: 20
older_node_version: true
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: ${{ matrix.node }}
cache: 'npm'
- run: npm ci
- run: npm run build

- run: npm run test-older-node
if: ${{ (matrix.older_node_version) }}

- run: npm run test
if: ${{ !(matrix.older_node_version) }}
9 changes: 4 additions & 5 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const ignores = [
// We ignore the polyfill.js files for third-party polyfills
// because we do not control their implementation.

// We do not ignore the config.json, detect.js or tests.js
// We do not ignore the config.json, detect.js or polyfill.test.js
// because we do control their implementation.
"polyfills/AbortController/polyfill.js",
"polyfills/ArrayBuffer/polyfill.js",
Expand Down Expand Up @@ -94,7 +94,7 @@ export default [
ignores: [
"tasks/polyfill-templates/polyfill.js",
"tasks/polyfill-templates/detect.js",
"tasks/polyfill-templates/tests.js",
"tasks/polyfill-templates/polyfill.test.js",
],
languageOptions: {
ecmaVersion: 2022,
Expand Down Expand Up @@ -178,9 +178,8 @@ export default [
},
{
files: [
"polyfills/**/tests.js",
"polyfills/**/*_tests.js",
"tasks/polyfill-templates/tests.js",
"polyfills/**/*.test.js",
"tasks/polyfill-templates/*.test.js",
],
languageOptions: {
...browserScriptDefaults.languageOptions,
Expand Down
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async function getPolyfills(options_) {

/*
A feature would be removed in these scenarios:
- If it has been specified to be excluded from the bundle via the exlcudes option.
- If it has been specified to be excluded from the bundle via the excludes option.
- If the feature is not meant to be in the bundle it does not target the browser.
Targeting a browser happens if the feature has the always option applied or
the browser is unsupported/unknown and the unknown option is set to polyfill
Expand Down Expand Up @@ -179,7 +179,7 @@ async function getPolyfills(options_) {
if (!meta) {
// this is a bit strange but the best thing I could come up with.
// by adding the feature, it will show up as an "unrecognized" polyfill
// which I think is better than just pretending it doesn't exsist.
// which I think is better than just pretending it doesn't exist.
addFeature(featureName);
continue;
}
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
"build": "npm run clean && node tasks/updatesources && node tasks/buildsources/buildsources",
"watch": "npm run clean && node tasks/updatesources && node tasks/buildsources/watchsource",
"fmt": "eslint . --fix",
"test-end-to-end": "node --test test/end-to-end",
"test-node": "node --test test/node",
"test-unit": "node --test test/unit",
"test": "node --test test/unit && node --test test/node && node --test test/end-to-end",
"test-end-to-end": "node --test 'test/end-to-end/**/*.test.js'",
"test-node": "node --test 'test/node/**/*.test.js'",
"test-unit": "node --test 'test/unit/**/*.test.js'",
"test": "node --test 'test/unit/**/*.test.js' && node --test 'test/node/**/*.test.js' && node --test 'test/end-to-end/**/*.test.js'",
"test-older-node": "node --test 'test/unit' && node --test 'test/node' && node --test 'test/end-to-end'",
"prepublishOnly": "npm run build",
"create-new-polyfill": "node ./tasks/create-new-polyfill.js",
"update-browserstack-list": "node ./tasks/updatebrowserstacklist.js"
Expand Down Expand Up @@ -63,6 +64,6 @@
"webdriverio": "^8.0.0"
},
"volta": {
"node": "20.11.1"
"node": "22.3.0"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
describe('Event.scrollend', function () {
// Scrolling and scroll events can be flaky in headless mode.
// CI environments are often headless.
this.retries(3);

var el;

before(function () {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Still keeping them here in case date/time issues arise.
* Currently only has a set of dates for type="week", but more sets can be created.
*
* To run change the filename to `tests.js`.
* To run change the filename to `polyfill.test.js`.
*/

/* globals JSON */
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions polyfills/ResizeObserver/patch.jsdiff
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
===================================================================
--- a/polyfills/ResizeObserver/polyfill.js
+++ b/polyfills/ResizeObserver/polyfill.js
@@ -1,8 +1,4 @@
-(function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ResizeObserver = {}));
-})(this, (function (exports) { 'use strict';
+(function (global) {

var resizeObservers = [];

@@ -109,7 +105,7 @@

var cache = new WeakMap();
var scrollRegexp = /auto|scroll/;
- var verticalRegexp = /^tb|vertical/;
+ var verticalRegexp = /^tb|^vertical/;
var IE = (/msie|trident/i).test(global.navigator && global.navigator.userAgent);
var parseDimension = function (pixel) { return parseFloat(pixel || '0'); };
var size = function (inlineSize, blockSize, switchSizes) {
@@ -503,10 +499,7 @@
return ResizeObserver;
}());

- exports.ResizeObserver = ResizeObserver;
- exports.ResizeObserverEntry = ResizeObserverEntry;
- exports.ResizeObserverSize = ResizeObserverSize;
+ global.ResizeObserver = ResizeObserver;
+ global.ResizeObserverEntry = ResizeObserverEntry;

- Object.defineProperty(exports, '__esModule', { value: true });
-
-}));
+}(self));
18 changes: 5 additions & 13 deletions polyfills/ResizeObserver/polyfill.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ResizeObserver = {}));
})(this, (function (exports) { 'use strict';
(function (global) {

var resizeObservers = [];

Expand Down Expand Up @@ -109,7 +105,7 @@

var cache = new WeakMap();
var scrollRegexp = /auto|scroll/;
var verticalRegexp = /^tb|vertical/;
var verticalRegexp = /^tb|^vertical/;
var IE = (/msie|trident/i).test(global.navigator && global.navigator.userAgent);
var parseDimension = function (pixel) { return parseFloat(pixel || '0'); };
var size = function (inlineSize, blockSize, switchSizes) {
Expand Down Expand Up @@ -503,11 +499,7 @@
return ResizeObserver;
}());

exports.ResizeObserver = ResizeObserver;
exports.ResizeObserverEntry = ResizeObserverEntry;
exports.ResizeObserverSize = ResizeObserverSize;
global.ResizeObserver = ResizeObserver;
global.ResizeObserverEntry = ResizeObserverEntry;

Object.defineProperty(exports, '__esModule', { value: true });

}));
;self.ResizeObserverEntry = ResizeObserver.ResizeObserverEntry;self.ResizeObserver=ResizeObserver.ResizeObserver;
}(self));
File renamed without changes.
13 changes: 9 additions & 4 deletions polyfills/ResizeObserver/update.task.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
'use strict';

var fs = require('fs');
var diff = require('diff');
var process = require('process');
var path = require('path');
var resizeObserverPolyfillOutput = path.resolve('polyfills/ResizeObserver/polyfill.js');

var polyfill = fs.readFileSync(resizeObserverPolyfillOutput, 'utf-8');
polyfill += ';self.ResizeObserverEntry = ResizeObserver.ResizeObserverEntry;self.ResizeObserver=ResizeObserver.ResizeObserver;'
fs.writeFileSync(resizeObserverPolyfillOutput, polyfill, 'utf-8');
var polyfill = fs.readFileSync(path.join(__dirname, './polyfill.js'), 'utf8');
var patch = fs.readFileSync(path.join(__dirname, './patch.jsdiff'), 'utf8');

var patched = diff.applyPatch(polyfill, patch);

if (patched === false) {process.exit(1);}
fs.writeFileSync(path.join(__dirname, './polyfill.js'), patched);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ it('returns the current script element when invoked during synchronous evaluatio
proclaim.equal(cs.ownerDocument, document);

// The rest of this test is highly dependent on the inner workings of the test runner...
proclaim.include(cs.src, 'http://bs-local.com:9876/tests.js');
proclaim.include(cs.src, 'http://bs-local.com:9876/polyfill.test.js');
proclaim.equal(cs.innerHTML, '');
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions tasks/buildsources/polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ module.exports = class Polyfill {
}

/**
* Path to "tests.js".
* Path to "polyfill.test.js".
*
* @type {string}
*/
get testsPath() {
return path.join(this.path.absolute, 'tests.js');
return path.join(this.path.absolute, 'polyfill.test.js');
}

/**
Expand Down Expand Up @@ -173,7 +173,7 @@ module.exports = class Polyfill {
throw new Error(`Incorrect spelling of license property in ${this.name}`);
}

this.config.hasTests = fs.existsSync(path.join(this.path.absolute, 'tests.js'));
this.config.hasTests = fs.existsSync(path.join(this.path.absolute, 'polyfill.test.js'));
this.config.isTestable = !('test' in this.config && 'ci' in this.config.test && this.config.test.ci === false);
this.config.isPublic = this.name.indexOf('_') !== 0;
});
Expand Down
4 changes: 2 additions & 2 deletions tasks/create-new-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ const polyfillTemplateFolderPath = path.join(__dirname, './polyfill-templates');
const configTemplate = fs.readFileSync(path.join(polyfillTemplateFolderPath, 'config.toml'), { encoding: 'utf-8'});
const polyfillTemplate = fs.readFileSync(path.join(polyfillTemplateFolderPath, 'polyfill.js'), { encoding: 'utf-8'});
const detectTemplate = fs.readFileSync(path.join(polyfillTemplateFolderPath, 'detect.js'), { encoding: 'utf-8'});
const testsTemplate = fs.readFileSync(path.join(polyfillTemplateFolderPath, 'tests.js'), { encoding: 'utf-8'});
const testsTemplate = fs.readFileSync(path.join(polyfillTemplateFolderPath, 'olyfill.test.js'), { encoding: 'utf-8'});

const polyfillFolderPath = path.join(__dirname, "../polyfills/", dotToSlash(newPolyfill));
fs.mkdirSync(polyfillFolderPath, {recursive: true});

fs.writeFileSync(path.join(polyfillFolderPath, 'polyfill.js'), polyfillTemplate, {encoding: 'utf-8'});
fs.writeFileSync(path.join(polyfillFolderPath, 'config.toml'), configTemplate, {encoding: 'utf-8'});
fs.writeFileSync(path.join(polyfillFolderPath, 'detect.js'), detectTemplate, {encoding: 'utf-8'});
fs.writeFileSync(path.join(polyfillFolderPath, 'tests.js'), testsTemplate.replace('REPLACE_ME', newPolyfill), {encoding: 'utf-8'});
fs.writeFileSync(path.join(polyfillFolderPath, 'polyfill.test.js'), testsTemplate.replace('REPLACE_ME', newPolyfill), {encoding: 'utf-8'});

console.log(`Created a new polyfill template at ${polyfillFolderPath}.`);

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions test/polyfills/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ app.get(
);

app.get(
"/tests.js",
"/polyfill.test.js",
cacheFor1Day,
async (request, response) => {
const feature = request.query.feature;
Expand Down Expand Up @@ -185,7 +185,7 @@ async function testablePolyfills(ua) {
}
if (config && config.isTestable && config.isPublic && config.hasTests) {
const baseDirectory = path.resolve(__dirname, "../../polyfills");
const testFile = path.join(baseDirectory, config.baseDir, "/tests.js");
const testFile = path.join(baseDirectory, config.baseDir, "/polyfill.test.js");
const testSuite = `describe('${polyfill}', function() {
it('passes the feature detect', function() {
proclaim.ok((function() {
Expand Down
2 changes: 1 addition & 1 deletion test/polyfills/test-runner.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<script src="/mocha.js"></script>
<script src="/proclaim.js"></script>
<script>mocha.setup('bdd');</script>
<script src="/tests.js{{#requestedFeature}}?feature={{features}}{{/requestedFeature}}"></script>
<script src="/polyfill.test.js{{#requestedFeature}}?feature={{features}}{{/requestedFeature}}"></script>
</head>
<body>

Expand Down

0 comments on commit c5a426c

Please sign in to comment.