Skip to content

Commit 15c1fbe

Browse files
committed
When LWS is off, globalThis is undefined #633
1 parent c9b8aed commit 15c1fbe

File tree

9 files changed

+36
-32
lines changed

9 files changed

+36
-32
lines changed

build/src/api/core/orgcheck-api-compressor-impl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class Compressor extends CompressorIntf {
1515
constructor() {
1616
super();
1717
// @ts-ignore
18-
this._api = globalThis?.fflate ?? null;
18+
this._api = window?.fflate ?? globalThis?.fflate ?? null;
1919
if (!this._api) throw new Error("fflate library not found");
2020
}
2121

build/src/api/orgcheck-api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export class API {
135135
// --------------------
136136
if (setup?.salesforce?.connection?.useJsForce === true) {
137137
// @ts-ignore
138-
this._sfdcManager = new SalesforceManager(globalThis?.jsforce ?? null, setup?.salesforce?.authentication);
138+
this._sfdcManager = new SalesforceManager(window?.jsforce ?? globalThis?.jsforce ?? null, setup?.salesforce?.authentication);
139139
} else {
140140
this._sfdcManager = new SalesforceManager(setup?.salesforce?.connection?.mockImpl, {});
141141
}

build/src/api/scanner/orgcheck-api-lfs-scanner.js

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,38 +42,33 @@ export class LFSScanner {
4242
* @returns {Promise<Map<string, Array<any>>>} Map of flow version ID to LFS violations
4343
*/
4444
static async scanFlows(flowRecords, CaseSafeId) {
45+
let results = new Map();
4546
try {
4647
// @ts-ignore
47-
const lfsCore = globalThis?.lightningflowscanner ?? null;
48+
const lfsCore = window?.lightningflowscanner ?? globalThis?.lightningflowscanner ?? null;
49+
if (lfsCore) {
50+
// Convert flow records to LFS format
51+
const lfsFlows = flowRecords.filter(record => record.Metadata) // only if flows have metadata!
52+
.map(record => {
53+
/** @type {string} */
54+
const id15 = CaseSafeId(record.Id);
55+
return {
56+
uri: id15,
57+
flow: new lfsCore.Flow(id15, this.normalizeMetadata(record.Metadata))
58+
};
59+
});
4860

49-
if (!lfsCore) {
50-
// console.warn('LFS_Core.js not available, skipping LFS scanning');
51-
return new Map();
52-
}
53-
54-
const { Flow, scan } = lfsCore;
55-
56-
// Convert flow records to LFS format
57-
const lfsFlows = flowRecords.filter(record => record.Metadata) // only if flows have metadata!
58-
.map(record => {
59-
/** @type {string} */
60-
const id15 = CaseSafeId(record.Id);
61-
return {
62-
uri: id15,
63-
flow: new Flow(id15, this.normalizeMetadata(record.Metadata))
64-
};
65-
});
61+
// Scan flows
62+
const scanResults = lfsCore.scan(lfsFlows);
6663

67-
// Scan flows
68-
const scanResults = scan(lfsFlows);
69-
70-
// Map results: flowVersionId -> violations
71-
return this.mapResults(scanResults);
64+
// Map results: flowVersionId -> violations
65+
results = this.mapResults(scanResults);
66+
}
7267

7368
} catch (error) {
74-
console.error('Error scanning flows with LFS: ', error?.message || JSON.stringify(error));
75-
return new Map();
69+
console.info(`Error scanning flows with LFS: returning an empty map (error: ${error?.message})`);
7670
}
71+
return results;
7772
}
7873

7974
/**

build/src/ui/exporter/orgcheck-ui-exporter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class Exporter {
1212
*/
1313
static exportAsXls(source) {
1414
// @ts-ignore
15-
const xlsx = globalThis?.XLSX ?? null;
15+
const xlsx = window?.XLSX ?? globalThis?.XLSX ?? null;
1616
if (!xlsx) {
1717
throw new Error('XLSX not available, skipping XLS export');
1818
}

build/test/api/unit/orgcheck-api-datasets.unit.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ class SimpleLoggerMock extends SimpleLoggerIntf {
116116
describe('tests.api.unit.Datasets', () => {
117117

118118
describe('Basic test for all datasets', () => {
119+
// Mocking Lightning Flow Scanner to avoid errors in tests for datasets that do
120+
// not use it, but still test that the integration does not cause issues
121+
window.lightningflowscanner = {
122+
Flow: function() { return {}; },
123+
scan: function() { return [];}
124+
};
119125
[
120126
DatasetApexClasses, DatasetApexTriggers, DatasetAppPermissions,
121127
DatasetCurrentUserPermissions, DatasetCustomFields,

force-app/main/default/lwc/orgcheckApp/orgcheckApp.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ <h1><span class="slds-page-header__title slds-truncate">Welcome in Org Check ({o
8080
<li><b>fflate</b>: distributed under the MIT license, more info at <a href="https://101arrowz.github.io/fflate" target="_blank" rel="external noopener noreferrer">101arrowz.github.io/fflate</a></li>
8181
<li><b>JsForce</b>: distributed under the MIT license, more info at <a href="https://jsforce.github.io" target="_blank" rel="external noopener noreferrer">jsforce.github.io</a></li>
8282
<li><b>SheetJS</b>: distributed under the Apache license v2.0, more info at <a href="https://sheetjs.com/" target="_blank" rel="external noopener noreferrer">sheetjs.com</a></li>
83+
<li><b>Lightning Flow Scanner</b>: distributed under the MIT License, more info at <a href="https://flow-scanner.github.io/lightning-flow-scanner" target="_blank" rel="external noopener noreferrer">flow-scanner.github.io/lightning-flow-scanner</a></li>
8384
<li><b>Xyris</b>: online website used to animated Org Checky (our mascot), more info at <a href="https://xyris.app/" target="_blank" rel="external noopener noreferrer">xyris.app</a></li>
8485
</ul>
8586
</div>

force-app/main/default/lwc/orgcheckGraphics/orgcheckGraphics.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default class OrgcheckGraphics extends LightningElement {
3838
.then(() => {
3939
this._apiInitialized = true;
4040
// @ts-ignore
41-
this._api = globalThis?.d3 ?? null;
41+
this._api = window?.d3 ?? globalThis?.d3 ?? null;
4242
// draw graph now
4343
this._drawGraph();
4444
})

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"scan:api": "sf code-analyzer run --target ./build/src/api --output-file /tmp/orgcheck-api-scan.html; open /tmp/orgcheck-api-scan.html",
1919
"scan:ui": "sf code-analyzer run --target ./build/src/ui --output-file /tmp/orgcheck-ui-scan.html; open /tmp/orgcheck-ui-scan.html",
2020
"scan:lwc": "sf code-analyzer run --target './force-app/main/default/lwc/*/*.js' --output-file /tmp/orgcheck-lwc-scan.html; open /tmp/orgcheck-lwc-scan.html",
21+
"scan:securityreview": "sf code-analyzer run --rule-selector AppExchange --rule-selector Recommended:Security --output-file /tmp/orgcheck-security-scan.html; open /tmp/orgcheck-security-scan.html",
2122
"sf:open": "sf force org open",
2223
"sf:clean": "sf project deploy start --metadata-dir manifest/destructive",
2324
"git:clean": "git remote update origin --prune; git branch -vv | grep 'gone]' | awk '{print $1}' | xargs git branch -D ",

sfdx-project.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"default": false,
66
"package": "Org Check",
77
"versionName": "Nitrogen",
8-
"versionNumber": "7.4.0.NEXT",
8+
"versionNumber": "7.6.0.NEXT",
99
"versionDescription": "Org Check is an easy-to-install and easy-to-use Salesforce application in order to quickly analyze your org and its technical debt.",
1010
"ancestorVersion": "HIGHEST"
1111
},
@@ -14,7 +14,7 @@
1414
"default": true,
1515
"package": "Org Check (unlocked)",
1616
"versionName": "Nitrogen",
17-
"versionNumber": "7.4.0.NEXT",
17+
"versionNumber": "7.6.0.NEXT",
1818
"versionDescription": "Org Check is an easy-to-install and easy-to-use Salesforce application in order to quickly analyze your org and its technical debt."
1919
}
2020
],
@@ -26,6 +26,7 @@
2626
"Org Check@5.7.0-1-main": "04tKB000000DQHzYAO",
2727
"Org Check (unlocked)": "0Ho2X000000KyjaSAC",
2828
"Org Check (unlocked)@6.4.0-1": "04tKB000000DVKUYA4",
29-
"Org Check (unlocked)@7.4.0-1": "04tKB000000DYYqYAO"
29+
"Org Check (unlocked)@7.4.0-1": "04tKB000000DYYqYAO",
30+
"Org Check (unlocked)@7.5.0-1": "04tKB000000DZIpYAO"
3031
}
3132
}

0 commit comments

Comments
 (0)