634ab45095
The devtools profiler is not attached at the point we run out init scripts (or our apps preload scripts), we do not really want to change when we run these init scripts but for when a dev is doing performance work it makes sense to give them an option to make the devtools profiler actually work on both our init scripts and their preload script. This PR adds that logic behind an environment variable ELECTRON_PROFILE_INIT_SCRIPTS.
38 lines
1,023 B
JavaScript
38 lines
1,023 B
JavaScript
const fs = require('fs');
|
|
const path = require('path')
|
|
const webpack = require('webpack')
|
|
|
|
const configPath = process.argv[2]
|
|
const outPath = path.resolve(process.argv[3])
|
|
const config = require(configPath)
|
|
config.output = {
|
|
path: path.dirname(outPath),
|
|
filename: path.basename(outPath)
|
|
}
|
|
|
|
const { wrapInitWithProfilingTimeout } = config;
|
|
delete config.wrapInitWithProfilingTimeout;
|
|
|
|
webpack(config, (err, stats) => {
|
|
if (err) {
|
|
console.error(err)
|
|
process.exit(1)
|
|
} else if (stats.hasErrors()) {
|
|
console.error(stats.toString('normal'))
|
|
process.exit(1)
|
|
} else {
|
|
if (wrapInitWithProfilingTimeout) {
|
|
const contents = fs.readFileSync(outPath, 'utf8');
|
|
const newContents = `function ___electron_webpack_init__() {
|
|
${contents}
|
|
};
|
|
if ((globalThis.process || binding.process).argv.includes("--profile-electron-init")) {
|
|
setTimeout(___electron_webpack_init__, 0);
|
|
} else {
|
|
___electron_webpack_init__();
|
|
}`;
|
|
fs.writeFileSync(outPath, newContents);
|
|
}
|
|
process.exit(0)
|
|
}
|
|
})
|