-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Validate load options methods in nodes-base (no-changelog) (#5862)
- Loading branch information
Showing
7 changed files
with
106 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/nodes-base/scripts/validate-load-options-methods.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
let referencedMethods; | ||
let definedMethods; | ||
|
||
try { | ||
referencedMethods = require('../dist/methods/referenced.json'); | ||
definedMethods = require('../dist/methods/defined.json'); | ||
} catch (error) { | ||
console.error( | ||
'Failed to find methods to validate. Please run `npm run n8n-generate-ui-types` first.', | ||
); | ||
process.exit(1); | ||
} | ||
|
||
const compareMethods = (base, other) => { | ||
const result = []; | ||
|
||
for (const [nodeName, methods] of Object.entries(base)) { | ||
if (nodeName in other) { | ||
const found = methods.filter((item) => !other[nodeName].includes(item)); | ||
|
||
if (found.length > 0) result.push({ [nodeName]: found }); | ||
} | ||
} | ||
|
||
return result; | ||
}; | ||
|
||
const referencedButUndefined = compareMethods(referencedMethods, definedMethods); | ||
|
||
if (referencedButUndefined.length > 0) { | ||
console.error('ERROR: The following load options methods are referenced but undefined.'); | ||
console.error('Please fix or remove the references or define the methods.'); | ||
console.error(referencedButUndefined); | ||
process.exit(1); | ||
} | ||
|
||
const definedButUnused = compareMethods(definedMethods, referencedMethods); | ||
|
||
if (definedButUnused.length > 0) { | ||
console.warn('Warning: The following load options methods are defined but unused.'); | ||
console.warn('Please consider using or removing the methods.'); | ||
console.warn(definedButUnused); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters