1
0
mirror of https://github.com/lancedikson/bowser synced 2026-10-17 16:43:26 +00:00

perf: trim bundled.js to the 2.14.1 polyfill set, fix stale docs

- Exclude the 10 core-js 3.0 modules with no counterpart in the
  @babel/polyfill set every released bundled.js shipped (concat/splice
  species fixes, Array#flat, Object.fromEntries, the __defineGetter__
  family, NodeList#forEach): 156.1 -> 153.2 kB (49.3 -> 48.4 kB gzip).
  babel rejects unknown exclude names, so a core-js rename fails the build.
- terser `passes: 5`, where output stops shrinking: es5.js 7.52 -> 7.49 kB
  gzip.
- New test: bundled.js must not install polyfills no release ever shipped
  (fails on the previous master build, passes on 2.14.1 and this one).
- README no longer claims named imports shrink the bundle; AGENTS.md
  describes the tsdown build and four-artifact acceptance tests;
  CONTRIBUTING points at the existing lint:check script.
This commit is contained in:
naorpeled
2026-09-27 22:26:39 +03:00
parent fd556800ee
commit 5249a7e4e8
6 changed files with 57 additions and 6 deletions

View File

@@ -179,3 +179,26 @@ test('bundled.js still installs everything @babel/polyfill did', (t) => {
vm.runInContext(fs.readFileSync(path.join(root, 'bundled.js'), 'utf8'), context);
t.deepEqual(BABEL_POLYFILL_SURFACE.filter((ref) => !present(ref)), [], 'bundled.js no longer installs these');
});
/**
* The other side of the contract: polyfills no released `bundled.js` ever
* shipped stay out, because each one is pure weight for existing consumers.
* Adding one back should be a deliberate decision that updates this list, not
* a side effect of switching a core-js entry point.
*/
const NEVER_SHIPPED = [
'this.URL', 'this.URLSearchParams', 'this.queueMicrotask',
'Array.prototype.flat', 'Object.fromEntries', 'NodeList.prototype.forEach',
];
test('bundled.js does not install polyfills no release ever shipped', (t) => {
const context = createEs5Context();
vm.runInContext(NEVER_SHIPPED
.map((ref) => `try { delete ${ref}; } catch (e) {}`)
.join('\n'), context);
vm.runInContext('this.NodeList = function NodeList() {};', context);
const present = (ref) => vm.runInContext(`typeof (${ref})`, context) !== 'undefined';
vm.runInContext(fs.readFileSync(path.join(root, 'bundled.js'), 'utf8'), context);
t.deepEqual(NEVER_SHIPPED.filter(present), []);
});