2026-06-14 23:40:58 +09:00
|
|
|
import { defineConfig } from 'tsdown';
|
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
|
|
|
import babel from '@rolldown/plugin-babel';
|
|
|
|
|
import { minify } from 'terser';
|
2026-06-14 23:40:58 +09:00
|
|
|
|
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
|
|
|
const banner = `/*!
|
|
|
|
|
* Bowser - a browser detector
|
|
|
|
|
* https://github.com/lancedikson/bowser
|
|
|
|
|
* MIT License | (c) Dustin Diaz 2012-2015
|
|
|
|
|
* MIT License | (c) Denis Demchenko 2015-2026
|
|
|
|
|
*/`;
|
2026-06-14 23:40:58 +09:00
|
|
|
|
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
|
|
|
/**
|
|
|
|
|
* The browser targets the UMD bundles are transpiled down to. Unchanged from
|
|
|
|
|
* the webpack build these bundles replaced — the published `es5.js` is relied
|
|
|
|
|
* on by script-tag and CDN consumers on very old browsers.
|
|
|
|
|
*/
|
|
|
|
|
const legacyTargets = {
|
|
|
|
|
ie: '8',
|
|
|
|
|
browsers: '>2%',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* `useBuiltIns: false` for `es5.js` (syntax transpilation only) and `'entry'`
|
|
|
|
|
* for `bundled.js`, which expands the `core-js/stable` import in its entry.
|
|
|
|
|
*/
|
|
|
|
|
const legacyBabel = (useBuiltIns: false | 'entry') => babel({
|
|
|
|
|
presets: [['@babel/preset-env', {
|
|
|
|
|
// Let rolldown emit the UMD wrapper; babel only lowers syntax here.
|
|
|
|
|
modules: false,
|
|
|
|
|
loose: true,
|
|
|
|
|
useBuiltIns,
|
|
|
|
|
...(useBuiltIns ? { corejs: '3' } : {}),
|
|
|
|
|
targets: legacyTargets,
|
|
|
|
|
}]],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Minifies the UMD chunks with terser instead of rolldown's built-in (oxc)
|
|
|
|
|
* minifier.
|
|
|
|
|
*
|
|
|
|
|
* This is not a preference. oxc's minifier prints every string literal as a
|
|
|
|
|
* template literal and refuses any `compress.target` below `es2015`, so it
|
|
|
|
|
* cannot emit ES5 — it would silently undo babel's lowering and break the very
|
|
|
|
|
* old browsers `es5.js` exists to serve. terser (`ecma: 5`) is also what the
|
|
|
|
|
* webpack 4 build this replaced used, via terser-webpack-plugin.
|
|
|
|
|
*/
|
|
|
|
|
const terser = () => ({
|
|
|
|
|
name: 'bowser:terser',
|
2026-08-29 23:50:17 +03:00
|
|
|
async renderChunk(code: string, chunk: { fileName: string }) {
|
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
|
|
|
const result = await minify(code, {
|
|
|
|
|
ecma: 5,
|
|
|
|
|
// IE 8: reserved words as property names must stay quoted.
|
|
|
|
|
ie8: true,
|
|
|
|
|
safari10: true,
|
|
|
|
|
format: {
|
|
|
|
|
// Keep the `/*!` banner.
|
|
|
|
|
comments: /^!/,
|
|
|
|
|
},
|
|
|
|
|
});
|
2026-08-29 23:50:17 +03:00
|
|
|
if (typeof result.code !== 'string') {
|
|
|
|
|
throw new Error(`terser produced no output for ${chunk.fileName}`);
|
|
|
|
|
}
|
|
|
|
|
return { code: result.code };
|
2026-06-14 23:40:58 +09:00
|
|
|
},
|
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
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const umd = (name: string, entry: string, useBuiltIns: false | 'entry') => ({
|
|
|
|
|
entry: { [name]: entry },
|
|
|
|
|
format: ['umd' as const],
|
|
|
|
|
// Lowercase, matching the global the webpack build published. Renaming this
|
|
|
|
|
// to `Bowser` would break every `<script src=".../bowser/es5.js">` consumer.
|
|
|
|
|
globalName: 'bowser',
|
|
|
|
|
outputOptions: {
|
|
|
|
|
// `module.exports = Bowser` rather than `{ default: Bowser }`.
|
|
|
|
|
exports: 'default' as const,
|
|
|
|
|
// Default would be `<name>.umd.js`; these files are published paths.
|
|
|
|
|
entryFileNames: '[name].js',
|
|
|
|
|
},
|
|
|
|
|
outDir: '.',
|
|
|
|
|
platform: 'browser' as const,
|
|
|
|
|
plugins: [legacyBabel(useBuiltIns), terser()],
|
|
|
|
|
// webpack ran in `mode: 'production'`; minification happens in `terser()`
|
|
|
|
|
// above, so rolldown's own minifier stays off. See its comment for why.
|
|
|
|
|
minify: false,
|
|
|
|
|
banner,
|
|
|
|
|
dts: false,
|
|
|
|
|
// outDir is the repo root — never let tsdown clean it.
|
|
|
|
|
clean: false,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default defineConfig([
|
|
|
|
|
umd('es5', 'build/entries/es5.js', false),
|
|
|
|
|
umd('bundled', 'build/entries/bundled.js', 'entry'),
|
2026-06-14 23:40:58 +09:00
|
|
|
{
|
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
|
|
|
// Modern ESM build. Reached via the `import` condition of the exports map.
|
|
|
|
|
// Deliberately not run through babel: `module` still points at the raw
|
|
|
|
|
// `src/bowser.js`, so this must not be *more* conservative than that.
|
|
|
|
|
entry: { bowser: 'src/bowser.js' },
|
2026-06-14 23:40:58 +09:00
|
|
|
format: ['esm'],
|
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
|
|
|
outDir: '.',
|
|
|
|
|
outExtensions: () => ({ js: '.mjs' }),
|
|
|
|
|
platform: 'browser',
|
|
|
|
|
banner,
|
2026-06-14 23:40:58 +09:00
|
|
|
dts: false,
|
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
|
|
|
clean: false,
|
2026-06-14 23:40:58 +09:00
|
|
|
},
|
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
|
|
|
]);
|