Skip to content

Commit

Permalink
Refactor code to provide better tree shaking and minification of gene…
Browse files Browse the repository at this point in the history
…rated code #1076

- Add Automatic Name replacing / Crunching
  • Loading branch information
MSNev committed Jun 15, 2022
1 parent 796caa3 commit cd1e113
Show file tree
Hide file tree
Showing 131 changed files with 4,194 additions and 2,199 deletions.
64 changes: 64 additions & 0 deletions .aiAutoMinify.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"pkgs": {
"@microsoft/applicationinsights-core-js": {
"constEnums": [
"CallbackType",
"eEventsDiscardedReason",
"eLoggingSeverity",
"_eInternalMessageId",
"SendRequestReason",
"TelemetryUnloadReason",
"TelemetryUpdateReason",
"GetExtCfgMergeType"
]
},
"@microsoft/applicationinsights-perfmarkmeasure-js": {
"constEnums": []
},
"@microsoft/applicationinsights-common": {
"constEnums": [
"eStorageType",
"FieldType",
"eDistributedTracingModes",
"eRequestHeaders",
"DataPointType",
"DependencyKind",
"DependencySourceType",
"eSeverityLevel",
"DataSanitizerValues"
]
},
"@microsoft/applicationinsights-properties-js": {
"constEnums": []
},
"@microsoft/applicationinsights-dependencies-js": {
"constEnums": []
},
"@microsoft/applicationinsights-debugplugin-js": {
"constEnums": []
},
"@microsoft/applicationinsights-channel-js": {
"constEnums": []
},
"@microsoft/applicationinsights-react-native": {
"constEnums": []
},
"@microsoft/applicationinsights-clickanalytics-js": {
"constEnums": [
"_eExtendedInternalMessageId"
]
},
"@microsoft/applicationinsights-web-basic": {
"constEnums": []
},
"@microsoft/applicationinsights-analytics-js": {
"constEnums": []
},
"@microsoft/applicationinsights-web": {
"constEnums": []
},
"@microsoft/applicationinsights-react-js": {
"constEnums": []
}
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,6 @@ aicore.tests.d.ts
ai.tests.d.ts
/.vs
/index.html

# Generated Constant File
**/__DynamicConstants.ts
13 changes: 10 additions & 3 deletions AISKU/Tests/Unit/src/AISKUSize.Tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import * as pako from "pako";
import { Snippet } from "../../../src/Initialization";

export class AISKUSizeCheck extends AITestClass {
private readonly MAX_DEFLATE_SIZE = 44;
private readonly MAX_RAW_SIZE = 118;
private readonly MAX_BUNDLE_SIZE = 114;
private readonly MAX_RAW_DEFLATE_SIZE = 46;
private readonly MAX_BUNDLE_DEFLATE_SIZE = 44;
private readonly rawFilePath = "../dist/applicationinsights-web.min.js";
private readonly prodFilePath = "../browser/ai.2.min.js";

Expand Down Expand Up @@ -50,6 +53,8 @@ export class AISKUSizeCheck extends AITestClass {

private _checkFileSize(isProd: boolean): void {
let _filePath = isProd? this.prodFilePath : this.rawFilePath;
let _maxFullSize = isProd ? this.MAX_BUNDLE_SIZE : this.MAX_RAW_SIZE;
let _maxDeflateSize = isProd ? this.MAX_BUNDLE_DEFLATE_SIZE : this.MAX_RAW_DEFLATE_SIZE;
let postfix = isProd? "" : "-raw";
let fileName = _filePath.split("..")[2];
this.testCase({
Expand All @@ -63,8 +68,10 @@ export class AISKUSizeCheck extends AITestClass {
return;
} else {
return response.text().then(text => {
let size = Math.ceil((pako.deflate(text).length/1024) * 100) / 100.0;
Assert.ok(size <= this.MAX_DEFLATE_SIZE ,`max ${this.MAX_DEFLATE_SIZE} KB, current deflate size is: ${size} KB`);
let size = Math.ceil((text.length/1024) * 100) / 100.0;
Assert.ok(size <= _maxFullSize, `max ${_maxFullSize} KB, current deflate size is: ${size} KB`);
let deflateSize = Math.ceil((pako.deflate(text).length/1024) * 100) / 100.0;
Assert.ok(deflateSize <= _maxDeflateSize ,`max ${_maxDeflateSize} KB, current deflate size is: ${deflateSize} KB`);
}).catch((error: Error) => {
Assert.ok(false, `AISKU${postfix} response error: ${error}`);
});
Expand Down
3 changes: 3 additions & 0 deletions AISKU/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
"build:snippet": "grunt snippetvnext",
"rebuild": "npm run build",
"test": "grunt aiskuunittests",
"mintest": "grunt aisku-mintests",
"perftest": "grunt aiskuperf",
"lint": "tslint -p tsconfig.json",
"dtsgen": "api-extractor run --local && node ../scripts/dtsgen.js 'Microsoft.ApplicationInsights'",
"sri": "node ../tools/subResourceIntegrity/generateIntegrityFile.js",
"ai-min": "grunt aisku-min",
"ai-restore": "grunt aisku-restore",
"nightwatch:chrome": "nightwatch -c Tests/nightwatch/nightwatch.json Tests/nightwatch/run_nightwatch.js --env chrome",
"nightwatch:firefox": "nightwatch -c Tests/nightwatch/nightwatch.json Tests/nightwatch/run_nightwatch.js --env firefox",
"nightwatch:edge": "nightwatch -c Tests/nightwatch/nightwatch.json Tests/nightwatch/run_nightwatch.js --env edge",
Expand Down
4 changes: 2 additions & 2 deletions AISKU/src/ApplicationInsightsContainer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IAppInsightsDeprecated, AppInsightsDeprecated } from "./ApplicationInsightsDeprecated";
import { Initialization as ApplicationInsights, Snippet, IApplicationInsights } from "./Initialization";
import { _legacyCookieMgr } from "@microsoft/applicationinsights-core-js";
import { AppInsightsDeprecated, IAppInsightsDeprecated } from "./ApplicationInsightsDeprecated";
import { IApplicationInsights, Initialization as ApplicationInsights, Snippet } from "./Initialization";

export class ApplicationInsightsContainer {

Expand Down
Loading

0 comments on commit cd1e113

Please sign in to comment.