-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de26962
commit 151e7ce
Showing
11 changed files
with
318 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
. "$(dirname "$0")/_/husky.sh" | ||
|
||
yarn lint && yarn pretty-quick --staged | ||
node ./scripts/scanTs.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
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,29 @@ | ||
/** | ||
* NOTE: This file does NOT really generate a bundle version of sdr | ||
* sdr is bundled directly in salesforcedx-vscode | ||
* The file is only used to detect any potential risks to esbuild. | ||
**/ | ||
const { build } = require('esbuild'); | ||
|
||
const sharedConfig = { | ||
bundle: true, | ||
format: 'cjs', | ||
platform: 'node', | ||
external: [], // The allowlist of dependencies that are not bundle-able | ||
keepNames: true, | ||
plugins: [], | ||
supported: { | ||
'dynamic-import': false, | ||
}, | ||
logOverride: { | ||
'unsupported-dynamic-import': 'error', | ||
}, | ||
}; | ||
|
||
(async () => { | ||
await build({ | ||
...sharedConfig, | ||
entryPoints: ['./lib/src/index.js'], | ||
outdir: 'dist', | ||
}); | ||
})(); |
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,51 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { Project, CallExpression } = require('ts-morph'); | ||
|
||
const SRC_DIR = path.join(__dirname, '..', 'src'); | ||
const project = new Project({ | ||
tsConfigFilePath: path.join(__dirname, '..', 'tsconfig.json'), | ||
}); | ||
|
||
let detected = false; | ||
|
||
const scanDirectory = (dir) => { | ||
const files = fs.readdirSync(dir); | ||
files.forEach((file) => { | ||
const fullPath = path.join(dir, file); | ||
const stat = fs.statSync(fullPath); | ||
if (stat.isDirectory()) { | ||
scanDirectory(fullPath); | ||
} else if (fullPath.endsWith('.ts')) { | ||
analyzeFile(fullPath); | ||
} | ||
}); | ||
}; | ||
|
||
// This function will detect all the usages of fs.read* and send warnings with the location of the usage | ||
const analyzeFile = (filePath) => { | ||
const srcFile = project.addSourceFileAtPath(filePath); | ||
const funcCalls = srcFile.getDescendantsOfKind(CallExpression); | ||
|
||
funcCalls.forEach((callExpression) => { | ||
const exp = callExpression.getExpression(); | ||
if (exp.getText().startsWith('fs.read')) { | ||
detected = true; | ||
console.warn( | ||
`Warning: Usage of "${exp.getText()}" in file "${filePath}" at line ${callExpression.getStartLineNumber()}.\n` | ||
); | ||
} | ||
}); | ||
}; | ||
|
||
scanDirectory(SRC_DIR); | ||
|
||
if (detected) { | ||
console.log('The warnings above do not mean the usages are wrong.'); | ||
console.log(`Avoid reading local artifacts with "fs.read*" since esbuild cannot bundle the artifacts together.`); | ||
console.log('Consider using import instead or reach out to IDEx Foundations team'); | ||
} else { | ||
console.log('No fs.read* usages detected.'); | ||
} | ||
|
||
console.log('Scan complete'); |
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,20 @@ | ||
const { exec } = require('child_process'); | ||
|
||
const commandToRun = 'node ./scripts/esbuild.config.js'; | ||
|
||
// Run the command | ||
exec(commandToRun, (error, stdout, stderr) => { | ||
// Combine stdout and stderr to check the entire output | ||
const output = `${stdout}\n${stderr}`; | ||
if (error) { | ||
console.error(stderr); | ||
process.exit(1); // Exit with an error code | ||
} | ||
// Check if the output contains the error string | ||
if (output.includes('[require-resolve-not-external]')) { | ||
console.error('Error: A dependency that has to be externalized in esbuild process is found. Please resolve it!'); | ||
process.exit(1); // Exit with an error code | ||
} else { | ||
process.exit(0); // Exit with success code | ||
} | ||
}); |
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
Oops, something went wrong.
151e7ce
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
eda-componentSetCreate-linux
241
ms232
ms1.04
eda-sourceToMdapi-linux
2260
ms2395
ms0.94
eda-sourceToZip-linux
1948
ms1902
ms1.02
eda-mdapiToSource-linux
2848
ms2985
ms0.95
lotsOfClasses-componentSetCreate-linux
429
ms433
ms0.99
lotsOfClasses-sourceToMdapi-linux
3563
ms3683
ms0.97
lotsOfClasses-sourceToZip-linux
3078
ms3145
ms0.98
lotsOfClasses-mdapiToSource-linux
3472
ms3568
ms0.97
lotsOfClassesOneDir-componentSetCreate-linux
733
ms772
ms0.95
lotsOfClassesOneDir-sourceToMdapi-linux
6349
ms6541
ms0.97
lotsOfClassesOneDir-sourceToZip-linux
5411
ms5809
ms0.93
lotsOfClassesOneDir-mdapiToSource-linux
6392
ms6522
ms0.98
This comment was automatically generated by workflow using github-action-benchmark.
151e7ce
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
eda-componentSetCreate-win32
677
ms733
ms0.92
eda-sourceToMdapi-win32
4747
ms4698
ms1.01
eda-sourceToZip-win32
3152
ms3200
ms0.98
eda-mdapiToSource-win32
6280
ms6404
ms0.98
lotsOfClasses-componentSetCreate-win32
1301
ms1326
ms0.98
lotsOfClasses-sourceToMdapi-win32
8351
ms8664
ms0.96
lotsOfClasses-sourceToZip-win32
5469
ms5282
ms1.04
lotsOfClasses-mdapiToSource-win32
7789
ms8012
ms0.97
lotsOfClassesOneDir-componentSetCreate-win32
2116
ms2155
ms0.98
lotsOfClassesOneDir-sourceToMdapi-win32
13603
ms14072
ms0.97
lotsOfClassesOneDir-sourceToZip-win32
9202
ms9483
ms0.97
lotsOfClassesOneDir-mdapiToSource-win32
14017
ms14338
ms0.98
This comment was automatically generated by workflow using github-action-benchmark.