newrelic / newrelic-browser-agent

New Relic Browser Agent
Apache License 2.0
77 stars 40 forks source link

chore: remove old assert import keyword #1115

Closed patrickhousley closed 2 months ago

patrickhousley commented 2 months ago

Please add a one-paragraph summary here, suitable for a release notes description. This will help with documentation.

Overview

This removes the old import ... assert ... keyword usage in favor of require. The assert keyword was added in Node 16 but the keyword was changed in Node 18 to with. The assert keyword for imports was removed in Node 22 causing builds of our project to fail when running with Node 22.

The replacement implementation creates a require function using module.createRequire(import.meta.url). This is supported all the way back to Node 12 and is not marked experimental in any way within the Node docs. This should be a stable way to import a JSON file for some time.

The alternative is to use import ... with ... but the with keyword is still under development but it is a tc39 standard that has reached stage 3 and could probably be expected to be pretty stable to use now. This would limit us and ppl forking and building the project to using Node 18 or later.

Related Issue(s)

https://new-relic.atlassian.net/browse/NR-265288

Testing

github-actions[bot] commented 2 months ago

Asset Size Report

Merging this pull request will result in the following asset size changes:

Agent Asset Previous Size New Size Diff
lite loader 32.43 kB / 11.32 kB (gzip) 32.43 kB / 11.32 kB (gzip) 0% / 0% (gzip)
lite async-chunk 49.74 kB / 16.03 kB (gzip) 49.74 kB / 16.03 kB (gzip) 0% / 0% (gzip)
pro loader 53.29 kB / 18.04 kB (gzip) 53.29 kB / 18.04 kB (gzip) 0% / 0% (gzip)
pro async-chunk 95.97 kB / 28.7 kB (gzip) 95.97 kB / 28.7 kB (gzip) 0% / 0% (gzip)
spa loader 61.23 kB / 20.47 kB (gzip) 61.23 kB / 20.47 kB (gzip) 0% / 0% (gzip)
spa async-chunk 111.02 kB / 33.03 kB (gzip) 111.02 kB / 33.03 kB (gzip) 0% / 0% (gzip)
lite-polyfills loader 125.97 kB / 40.61 kB (gzip) 125.97 kB / 40.61 kB (gzip) 0% / 0% (gzip)
lite-polyfills async-chunk 63.67 kB / 18.32 kB (gzip) 63.67 kB / 18.32 kB (gzip) 0% / 0% (gzip)
pro-polyfills loader 148.54 kB / 46.94 kB (gzip) 148.54 kB / 46.94 kB (gzip) 0% / 0% (gzip)
pro-polyfills async-chunk 116 kB / 30.94 kB (gzip) 116 kB / 30.94 kB (gzip) 0% / 0% (gzip)
spa-polyfills loader 156.73 kB / 49.1 kB (gzip) 156.73 kB / 49.1 kB (gzip) 0% / 0% (gzip)
spa-polyfills async-chunk 132.9 kB / 35.6 kB (gzip) 132.9 kB / 35.6 kB (gzip) 0% / 0% (gzip)
codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 87.70%. Comparing base (e5bab92) to head (7a3e4ea).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1115 +/- ## ========================================== + Coverage 87.67% 87.70% +0.02% ========================================== Files 162 162 Lines 7262 7262 Branches 1426 1426 ========================================== + Hits 6367 6369 +2 + Misses 779 778 -1 + Partials 116 115 -1 ``` | [Flag](https://app.codecov.io/gh/newrelic/newrelic-browser-agent/pull/1115/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=newrelic) | Coverage Δ | | |---|---|---| | [unit-tests](https://app.codecov.io/gh/newrelic/newrelic-browser-agent/pull/1115/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=newrelic) | `76.48% <ø> (+0.03%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=newrelic#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.