Tree-Shaking Enhancements / Recommendations

March 17, 2021 ยท View on GitHub

As part of changes introduced in version 2.6.0 we are deprecating and removing the internal usages of the static helper classes CoreUtils, EventHelper, Util, UrlHelper, DateTimeUtils and ConnectionStringParser to provide better support for tree-shaking algorithms so that unused code can be safely dropped when using NPM packages.

As part of these changes we are now exporting the functions as top level root (direct) from the modules so that you can simply refactor your code to achieve better tree-shaking.

To further assist with some tree-shakers, we have also changed these from static classes to const objects that reference the new exported functions (mostly). Future changes are required to continue refactoring out further the references below that have no currently available replacement or are not listed.

Why?

Simplistically, any reference to any property or function that was defined in these static classes would require that ALL of the properties and functions must be included in the resulting code as this code becomes unshakable (using static analysis).

Note: While we have tagged the classes as deprecated, they will continue to be exported and we are not currently planning on removing them from the current packages that they are exported from.

Deprecated functions and replacements

ExistingReplacement
CoreUtils@microsoft/applicationinsights-core-js
CoreUtils._canUseCookiesNone - Do not use as this will cause all of CoreUtils reference to be included in your final code.
Refactor your cookie handling to use the appInsights.getCookieMgr().setEnabled(true/false) to set the value and appInsights.getCookieMgr().isEnabled() to check the value.
CoreUtils.isTypeofisTypeof
CoreUtils.isUndefinedisUndefined
CoreUtils.isNullOrUndefinedisNullOrUndefined
CoreUtils.hasOwnPropertyhasOwnProperty
CoreUtils.isFunctionisFunction
CoreUtils.isObjectisObject
CoreUtils.isDateisDate
CoreUtils.isArrayisArray
CoreUtils.isErrorisError
CoreUtils.isStringisString
CoreUtils.isNumberisNumber
CoreUtils.isBooleanisBoolean
CoreUtils.toISOStringtoISOString or getISOString
CoreUtils.arrForEacharrForEach
CoreUtils.arrIndexOfarrIndexOf
CoreUtils.arrMaparrMap
CoreUtils.arrReducearrReduce
CoreUtils.strTrimstrTrim
CoreUtils.objCreateobjCreateFn
CoreUtils.objKeysobjKeys
CoreUtils.objDefineAccessorsobjDefineAccessors
CoreUtils.addEventHandleraddEventHandler
CoreUtils.dateNowdateNow
CoreUtils.isIEisIE
CoreUtils.disableCookiesdisableCookies
Referencing either will cause CoreUtils to be referenced for backward compatibility.
Refactor your cookie handling to use the appInsights.getCookieMgr().setEnabled(false)
CoreUtils.newGuidnewGuid
CoreUtils.perfNowperfNow
CoreUtils.newIdnewId
CoreUtils.randomValuerandomValue
CoreUtils.random32random32
CoreUtils.mwcRandomSeedmwcRandomSeed
CoreUtils.mwcRandom32mwcRandom32
CoreUtils.generateW3CIdgenerateW3CId
EventHelper@microsoft/applicationinsights-core-js
EventHelper.AttachattachEvent
EventHelper.AttachEventattachEvent
EventHelper.DetachdetachEvent
EventHelper.DetachEventdetachEvent
Util@microsoft/applicationinsights-common-js
Util.NotSpecifiedstrNotSpecified
Util.createDomEventcreateDomEvent
Util.disableStorageutlDisableStorage
Util.isInternalApplicationInsightsEndpointisInternalApplicationInsightsEndpoint
Util.canUseLocalStorageutlCanUseLocalStorage
Util.getStorageutlGetLocalStorage
Util.setStorageutlSetLocalStorage
Util.removeStorageutlRemoveStorage
Util.canUseSessionStorageutlCanUseSessionStorage
Util.getSessionStorageKeysutlGetSessionStorageKeys
Util.getSessionStorageutlGetSessionStorage
Util.setSessionStorageutlSetSessionStorage
Util.removeSessionStorageutlRemoveSessionStorage
Util.disableCookiesdisableCookies
Referencing either will cause CoreUtils to be referenced for backward compatibility.
Refactor your cookie handling to use the appInsights.getCookieMgr().setEnabled(false)
Util.canUseCookiescanUseCookies
Referencing either will cause CoreUtils to be referenced for backward compatibility.
Refactor your cookie handling to use the appInsights.getCookieMgr().isEnabled()
Util.disallowsSameSiteNoneuaDisallowsSameSiteNone
Util.setCookiecoreSetCookie
Referencing will cause CoreUtils to be referenced for backward compatibility.
Refactor your cookie handling to use the appInsights.getCookieMgr().set(name: string, value: string)
Util.stringToBoolOrDefaultstringToBoolOrDefault
Util.getCookiecoreGetCookie
Referencing will cause CoreUtils to be referenced for backward compatibility.
Refactor your cookie handling to use the appInsights.getCookieMgr().get(name: string)
Util.deleteCookiecoreDeleteCookie
Referencing will cause CoreUtils to be referenced for backward compatibility.
Refactor your cookie handling to use the appInsights.getCookieMgr().del(name: string, path?: string)
Util.trimstrTrim
Util.newIdnewId
Util.random32---
No replacement, refactor your code to use the core random32(true)
Util.generateW3CIdgenerateW3CId
Util.isArrayisArray
Util.isErrorisError
Util.isDateisDate
Util.toISOStringForIE8toISOString
Util.getIEVersiongetIEVersion
Util.msToTimeSpanmsToTimeSpan
Util.isCrossOriginErrorisCrossOriginError
Util.dumpdumpObj
Util.getExceptionNamegetExceptionName
Util.addEventHandlerattachEvent
Util.IsBeaconApiSupportedisBeaconApiSupported
Util.getExtensiongetExtensionByName
UrlHelper@microsoft/applicationinsights-common-js
UrlHelper.parseUrlurlParseUrl
UrlHelper.getAbsoluteUrlurlGetAbsoluteUrl
UrlHelper.getPathNameurlGetPathName
UrlHelper.getCompeteUrlurlGetCompleteUrl
UrlHelper.parseHosturlParseHost
UrlHelper.parseFullHosturlParseFullHost
DateTimeUtils@microsoft/applicationinsights-common-js
DateTimeUtils.NowdateTimeUtilsNow
DateTimeUtils.GetDurationdateTimeUtilsDuration
ConnectionStringParser@microsoft/applicationinsights-common-js
ConnectionStringParser.parseparseConnectionString