1
0
mirror of https://github.com/lancedikson/bowser synced 2026-10-22 03:25:55 +00:00

fix: keep ESM consumers on ES5, enable tree-shaking, trim bundled.js (#634)

This commit is contained in:
Naor Peled
2026-09-27 12:10:11 +03:00
committed by GitHub
parent c1208b4a56
commit fd556800ee
6 changed files with 119 additions and 23 deletions

View File

@@ -101,6 +101,12 @@ check('require.resolve("bowser/package.json") works', function () {
assert.ok(fs.existsSync(require.resolve('bowser/package.json')));
});
// Extensionless, like `bowser/es5` — CommonJS resolution appended `.json`
// before the exports map existed.
check('require("bowser/package") works', function () {
assert.strictEqual(require('bowser/package').name, 'bowser');
});
// Before the exports map existed, *every* published file was reachable by
// subpath. An exports map is a closed list, so anything published but not
// enumerated silently becomes ERR_PACKAGE_PATH_NOT_EXPORTED. These four are
@@ -124,6 +130,14 @@ check('main/browser/module/types fields are unchanged', function () {
assert.strictEqual(pkg.types, 'index.d.ts');
});
// Lets esbuild and Vite drop an unused `import 'bowser'` (webpack and Rollup
// already do). `bundled.js` is the one file whose import *is* the point: it
// installs polyfills, so it must never be tree-shaken away.
check('"sideEffects" lists exactly bundled.js', function () {
var pkg = require('bowser/package.json');
assert.deepStrictEqual(pkg.sideEffects, ['./bundled.js']);
});
check('no "engines" field (would warn/fail installs on old Node)', function () {
var pkg = require('bowser/package.json');
assert.strictEqual(pkg.engines, undefined);