Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web worker: TypeScript and rollup #2289

Merged
merged 7 commits into from
Jan 29, 2025
Merged

Conversation

djskinner
Copy link
Contributor

@djskinner djskinner commented Jan 22, 2025

Goal

  • Convert @bugsnag/web-worker TypeScript and distribute as es modules

Design

  • Use TypeScript to transpile and rollup to bundle consistent with @bugsnag/browser

Changeset

  • Convert notifier source to typescript
  • Use rollup in build script to produce: esm and umd outputs

Testing

  • Existing web-worker fixture is in TypeScript, tests passing

const name = 'Bugsnag Web Worker'
const url = 'https://github.com/bugsnag/bugsnag-js'
// @ts-ignore
const version = __BUGSNAG_NOTIFIER_VERSION__ // eslint-disable-line no-undef
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why but there seems to be a problem with this being __VERSION__ specifically. If I try to use that rollup blows up with:

[!] RollupError: src/bugsnag.ts (14:25): Expected a semicolon (Note that you need plugins to import files that are not JavaScript)
src/bugsnag.ts (14:25)
12: var name = 'Bugsnag Web Worker';
13: var url = 'https://github.com/bugsnag/bugsnag-js';
14: var version = __VERSION__;
                             ^
15: var schema = assign({}, baseConfig, workerConfig);

Copy link

github-actions bot commented Jan 22, 2025

@bugsnag/browser bundle size diff

Minified Minfied + Gzipped
Before 48.86 kB 15.14 kB
After 48.87 kB 15.14 kB
± ⚠️ +3 bytes ⚠️ +2 bytes

code coverage diff

<temporarily disabled>

Generated by 🚫 dangerJS against f9268fa

Comment on lines 34 to 35
const version = '__VERSION__'
// @ts-ignore
const version = __BUGSNAG_NOTIFIER_VERSION__ // eslint-disable-line no-undef
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix version in browser notifier. maybe we need a test for this, if possible. See also comment below about strange problems with __VERSION__

Comment on lines -34 to -35
"build:dist:esm": "webpack --config esm.config.js",
"build:dist:esm.min": "webpack --config esm.config.js --optimization-minimize --output-filename=bugsnag.web-worker.min.mjs",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these don't appear to have been used. it looks like we're also publishing this to cdn but then there are no docs for that. so do we need to support cdn for web workers?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's one for @tomlongridge - as far I understand the CDN was a requirement, but if it's not been documented we will need to remedy that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like it, but also opens the question about whether we have tests to cover that scenario. I'd suggest ticketing for future, but keep doing what we're doing now as far as publishing is concerned so we don't stop publishing if anyone is using it?

Base automatically changed from plat-13423 to integration/typescript January 23, 2025 08:20
@@ -33,7 +33,7 @@ const plugins = [
preventAssignment: true,
values: {
'process.env.NODE_ENV': JSON.stringify('production'),
values: { __VERSION__: packageJson.version },
__BUGSNAG_NOTIFIER_VERSION__: JSON.stringify(packageJson.version),
Copy link
Contributor Author

@djskinner djskinner Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix version in browser notifier. maybe we need a test for this, if possible. See also comment below about strange problems with __VERSION__

// configure a client with user supplied options
const bugsnag = new ClientWithInternals(opts, schema, internalPlugins, { name, version, url })

bugsnag._setDelivery(client => delivery(client, self.fetch))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delivery-fetchis implemented likeconst delivery = (client, fetch = global.fetch) => ({`

In webpack this global.fetch gets converted to a webpack require that somehow resolves this properly for web workers. However in rollup it remains as global.fetch which is undefined. We could perhaps replace the default value with globalThis.fetch but I'd think I'd rather see the default omitted requiring the notifier implementation to explicitly state what fetch to use.

if (!opts) opts = {} as unknown as Config

const internalPlugins = [
pluginBrowserDevice(navigator, null),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per delivery-fetch comment below maybe these plugins would be better off not assuming what environment they are running in

@@ -82,4 +82,6 @@ export default class ClientWithInternals<T extends Config = Config> extends Clie
_loadPlugin(plugin: Plugin): void

_isBreadcrumbTypeEnabled(type: string): boolean

public addOnError(fn: OnErrorCallback, front?: boolean): void;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the public types do not currently expose the second param

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as this is now in the public types, could we name it something to describe what it does? like moveToFront or something?

const name = 'Bugsnag Web Worker'
const url = 'https://github.com/bugsnag/bugsnag-js'
// @ts-ignore
const version = __BUGSNAG_NOTIFIER_VERSION__
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why but there seems to be a problem with this being __VERSION__ specifically. If I try to use that rollup blows up with:

[!] RollupError: src/bugsnag.ts (14:25): Expected a semicolon (Note that you need plugins to import files that are not JavaScript)
src/bugsnag.ts (14:25)
12: var name = 'Bugsnag Web Worker';
13: var url = 'https://github.com/bugsnag/bugsnag-js';
14: var version = __VERSION__;
                             ^
15: var schema = assign({}, baseConfig, workerConfig);

@djskinner djskinner marked this pull request as ready for review January 23, 2025 11:18
@djskinner djskinner requested a review from gingerbenw January 23, 2025 11:18
@@ -82,4 +82,6 @@ export default class ClientWithInternals<T extends Config = Config> extends Clie
_loadPlugin(plugin: Plugin): void

_isBreadcrumbTypeEnabled(type: string): boolean

public addOnError(fn: OnErrorCallback, front?: boolean): void;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as this is now in the public types, could we name it something to describe what it does? like moveToFront or something?

@djskinner djskinner merged commit 4a7dfca into integration/typescript Jan 29, 2025
54 of 55 checks passed
@djskinner djskinner deleted the plat-13218 branch January 29, 2025 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants