1
0
mirror of https://github.com/lancedikson/bowser synced 2026-09-23 20:44:24 +00:00
Files
lancedikson_bowser/index.d.mts

34 lines
1.6 KiB
TypeScript
Raw Normal View History

fix: make dual packaging non-breaking for existing consumers Keeps the published surface of bowser@2.14.1 intact while adding a real ESM build, and rewrites CI so it can actually run the new toolchain. Packaging - Restore the flat artifact layout. es5.js and bundled.js stay at the tarball root next to src/, so unpkg.com/bowser/es5.js and require('bowser/bundled') keep working. bowser.mjs is added alongside. - Build the UMD bundles from dedicated single-default-export entries in build/entries/. src/bowser.js gained named exports (parse, getParser) to fix #511, but a UMD bundle with named exports makes require('bowser') a namespace object instead of the class: typeof flips from 'function' to 'object' and BROWSER_MAP / ENGINE_MAP / OS_MAP / PLATFORMS_MAP disappear, since they are static getters rather than exports. - globalName back to lowercase 'bowser', matching the shipped es5.js. Renaming it to 'Bowser' would break every script-tag consumer. - Enumerate every legacy subpath in the exports map. Conditional exports are honoured from Node 12.16.0 onward, so a "."-only map turns paths that resolve today into ERR_PACKAGE_PATH_NOT_EXPORTED. Subpath patterns ("./src/*") need Node 12.20.0+ and the trailing-slash folder form was removed in Node 17, so explicit per-file keys are the only spelling that works across the whole supported range. Extension-less aliases included: the README documents require('bowser/bundled'). - main, browser and module keep their existing values. No engines field (npm warns EBADENGINE, pnpm fails under engine-strict) and no type field (it would reclassify es5.js as ESM). Build - Minify the UMD bundles with terser instead of rolldown's built-in oxc minifier. oxc prints every string literal as a template literal and rejects any compress.target below es2015, so it cannot emit ES5 and was silently undoing babel's lowering. terser is what webpack 4 used. - Wire up the copyright banner, which was declared but never passed to a config, and restore bundled.js as the polyfilled build via core-js/stable. - Add index.d.mts so the import condition has ESM types. Reusing the export = declarations for both conditions describes an ES module with CommonJS types. CI - Replace npm ci with pnpm across all workflows. This is what was failing: the lockfile was swapped for pnpm-lock.yaml but the workflows still ran npm ci, pinned to Node 12.16.3 and 16. Build now runs on Node 24, which tsdown requires. - Add a pack-smoke job that installs the packed tarball on Node 12.16.3, 14, 18, 20 and 24 and exercises every documented entry point, plus publint and attw on the tarball. This is what makes "non-breaking" a tested claim rather than an argument; it catches all of the above. - Restore test-list-of-ua.js to asserting src against the built es5.js. It had been collapsed to comparing Bowser.parse with itself.
2026-08-01 14:40:56 +03:00
// ESM type definitions for Bowser v2.
//
// `index.d.ts` uses `export =`, which describes the CommonJS/UMD shape of
// `es5.js` (`module.exports = Bowser`). It is reached via the `require`
// condition and stays the source of truth for the type declarations.
//
// This file describes `bowser.mjs`, which is a real ES module: it has a default
// export *and* the `parse` / `getParser` named exports. It is reached via the
// `import` condition. Declaring it separately is what keeps the types honest
// for `moduleResolution: node16`/`bundler` consumers — reusing `index.d.ts` for
// both conditions would describe an ES module with CommonJS types.
import Bowser = require('./index.js');
export default Bowser;
export declare const parse: typeof Bowser.parse;
export declare const getParser: typeof Bowser.getParser;
// BROWSER_MAP / ENGINE_MAP / OS_MAP / PLATFORMS_MAP are *not* named exports of
// bowser.mjs — they exist only as static getters on the class. Declaring them
// here would let TypeScript accept `import { BROWSER_MAP } from 'bowser'`,
// which throws at runtime. Reach them via the default export instead.
fix: make dual packaging non-breaking for existing consumers Keeps the published surface of bowser@2.14.1 intact while adding a real ESM build, and rewrites CI so it can actually run the new toolchain. Packaging - Restore the flat artifact layout. es5.js and bundled.js stay at the tarball root next to src/, so unpkg.com/bowser/es5.js and require('bowser/bundled') keep working. bowser.mjs is added alongside. - Build the UMD bundles from dedicated single-default-export entries in build/entries/. src/bowser.js gained named exports (parse, getParser) to fix #511, but a UMD bundle with named exports makes require('bowser') a namespace object instead of the class: typeof flips from 'function' to 'object' and BROWSER_MAP / ENGINE_MAP / OS_MAP / PLATFORMS_MAP disappear, since they are static getters rather than exports. - globalName back to lowercase 'bowser', matching the shipped es5.js. Renaming it to 'Bowser' would break every script-tag consumer. - Enumerate every legacy subpath in the exports map. Conditional exports are honoured from Node 12.16.0 onward, so a "."-only map turns paths that resolve today into ERR_PACKAGE_PATH_NOT_EXPORTED. Subpath patterns ("./src/*") need Node 12.20.0+ and the trailing-slash folder form was removed in Node 17, so explicit per-file keys are the only spelling that works across the whole supported range. Extension-less aliases included: the README documents require('bowser/bundled'). - main, browser and module keep their existing values. No engines field (npm warns EBADENGINE, pnpm fails under engine-strict) and no type field (it would reclassify es5.js as ESM). Build - Minify the UMD bundles with terser instead of rolldown's built-in oxc minifier. oxc prints every string literal as a template literal and rejects any compress.target below es2015, so it cannot emit ES5 and was silently undoing babel's lowering. terser is what webpack 4 used. - Wire up the copyright banner, which was declared but never passed to a config, and restore bundled.js as the polyfilled build via core-js/stable. - Add index.d.mts so the import condition has ESM types. Reusing the export = declarations for both conditions describes an ES module with CommonJS types. CI - Replace npm ci with pnpm across all workflows. This is what was failing: the lockfile was swapped for pnpm-lock.yaml but the workflows still ran npm ci, pinned to Node 12.16.3 and 16. Build now runs on Node 24, which tsdown requires. - Add a pack-smoke job that installs the packed tarball on Node 12.16.3, 14, 18, 20 and 24 and exercises every documented entry point, plus publint and attw on the tarball. This is what makes "non-breaking" a tested claim rather than an argument; it catches all of the above. - Restore test-list-of-ua.js to asserting src against the built es5.js. It had been collapsed to comparing Bowser.parse with itself.
2026-08-01 14:40:56 +03:00
export type ClientHints = Bowser.ClientHints;
export type Parser = Bowser.Parser.Parser;
export type ParsedResult = Bowser.Parser.ParsedResult;
export type Details = Bowser.Parser.Details;
export type BrowserDetails = Bowser.Parser.BrowserDetails;
export type EngineDetails = Bowser.Parser.EngineDetails;
export type OSDetails = Bowser.Parser.OSDetails;
export type PlatformDetails = Bowser.Parser.PlatformDetails;
export type checkTree = Bowser.Parser.checkTree;