1
0
mirror of https://github.com/lancedikson/bowser synced 2026-09-23 04:24:54 +00:00
Files
lancedikson_bowser/.github/workflows/pull-request.yml
naorpeled a78d9d35a2 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

125 lines
3.5 KiB
YAML

name: "Pull Request"
on:
pull_request:
types: [opened, reopened, synchronize]
env:
# tsdown requires Node ^22.18.0 || >=24.11.0. This is the *build* toolchain
# only — see the `pack-smoke` job for the versions the published package
# itself has to keep working on.
BUILD_NODE_VERSION: "24"
jobs:
build:
name: "Build & test"
runs-on: ubuntu-latest
steps:
- name: Checkout latest code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up pnpm
uses: pnpm/action-setup@v4
- name: Set up node
uses: actions/setup-node@v4
with:
node-version: ${{ env.BUILD_NODE_VERSION }}
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run ESLint
run: pnpm lint:check
- name: Build
run: pnpm build
- name: Run tests
run: pnpm test
# package.json intentionally carries no `version` — it is stamped at
# release time by publish.yml. `npm pack` needs one, so use a throwaway.
- name: Pack
run: |
npm version 0.0.0-ci --no-git-tag-version --allow-same-version
npm pack --pack-destination ./tarball
- name: Upload package tarball
uses: actions/upload-artifact@v4
with:
name: package-tarball
path: tarball/*.tgz
pack-smoke:
# Installs the packed tarball and exercises every documented entry point.
# bowser publishes ES5 artifacts and has no `engines` field, so the package
# must keep working far below the version we build on.
name: "Consumer smoke (Node ${{ matrix.node }})"
needs: build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node: ["12.16.3", "14", "18", "20", "24"]
steps:
- name: Checkout latest code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Download package tarball
uses: actions/download-artifact@v4
with:
name: package-tarball
path: tarball
- name: Set up node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
# No install step: bowser has no runtime dependencies and the smoke test
# only uses Node built-ins, so this runs on every version above.
- name: Run package smoke test
run: node test/package/smoke.cjs tarball/*.tgz
package-lint:
name: "Package manifest"
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout latest code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up pnpm
uses: pnpm/action-setup@v4
- name: Set up node
uses: actions/setup-node@v4
with:
node-version: ${{ env.BUILD_NODE_VERSION }}
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build
run: pnpm build
- name: Stamp a throwaway version
run: npm version 0.0.0-ci --no-git-tag-version --allow-same-version
- name: publint
run: pnpm exec publint
# Scoped to the root entrypoint. The legacy `bowser/src/*` subpaths are
# untyped ESM sources in a CJS package — true on every published version
# of bowser, and preserved here on purpose.
- name: Are the types wrong?
run: pnpm exec attw --pack . --profile node16 --entrypoints .