electron-mksnapshot
Advanced tools
Comparing version 3.0.0-beta.1 to 3.0.10
#!/usr/bin/env node | ||
var ChildProcess = require('child_process') | ||
var path = require('path') | ||
const fs = require('fs') | ||
const { spawnSync } = require('child_process') | ||
const path = require('path') | ||
const temp = require('temp').track() | ||
const workingDir = temp.mkdirSync('mksnapshot-workdir') | ||
var command = path.join(__dirname, 'bin', 'mksnapshot') | ||
var args = process.argv.slice(2) | ||
var options = { | ||
cwd: process.cwd(), | ||
/* | ||
* Copy mksnapshot files to temporary working directory because | ||
* v8_context_snapshot_generator expects to run everything from the same | ||
* directory. | ||
*/ | ||
function copyMksnapshotFiles (mksnapshotDir, workingDir) { | ||
const mksnapshotFiles = fs.readdirSync(mksnapshotDir) | ||
mksnapshotFiles.forEach(file => { | ||
fs.copyFileSync(path.join(mksnapshotDir, file), path.join(workingDir, file)) | ||
}) | ||
} | ||
function getBinaryPath (binary, binaryPath) { | ||
if (process.platform === 'win32') { | ||
return path.join(binaryPath, `${binary}.exe`) | ||
} else { | ||
return path.join(binaryPath, binary) | ||
} | ||
} | ||
const args = process.argv.slice(2) | ||
if (args.length === 0 || args.includes('--help')) { | ||
console.log(`Usage: mksnapshot file.js (--output_dir OUTPUT_DIR). ` + | ||
`Additional mksnapshot args except for --startup_blob are supported:`) | ||
args.push('--help') | ||
} | ||
const outDirIdx = args.indexOf('--output_dir') | ||
let outputDir = process.cwd() | ||
let mksnapshotArgs = args | ||
if (outDirIdx > -1) { | ||
mksnapshotArgs = args.slice(0, outDirIdx) | ||
if (args.length >= (outDirIdx + 2)) { | ||
outputDir = args[(outDirIdx + 1)] | ||
if (args.length > (outDirIdx + 2)) { | ||
mksnapshotArgs = mksnapshotArgs.concat(args.slice(outDirIdx + 2)) | ||
} | ||
} else { | ||
console.log('Error! Output directory argument given but directory not specified.') | ||
process.exit(1) | ||
} | ||
} | ||
if (args.includes('--startup_blob')) { | ||
console.log('--startup_blob argument not supported. Use --output_dir to specify where to output snapshot_blob.bin') | ||
process.exit(1) | ||
} else { | ||
mksnapshotArgs = mksnapshotArgs.concat(['--startup_blob', 'snapshot_blob.bin']) | ||
} | ||
if (!mksnapshotArgs.includes('--turbo_instruction_scheduling')) { | ||
mksnapshotArgs.push('--turbo_instruction_scheduling') | ||
} | ||
const mksnapshotDir = path.join(__dirname, 'bin') | ||
copyMksnapshotFiles(mksnapshotDir, workingDir) | ||
const options = { | ||
cwd: workingDir, | ||
env: process.env, | ||
@@ -14,18 +69,34 @@ stdio: 'inherit' | ||
var mksnapshotProcess = ChildProcess.spawn(command, args, options) | ||
mksnapshotProcess.on('exit', function (code, signal) { | ||
if (code == null && signal === 'SIGILL') { | ||
const mksnapshotCommand = getBinaryPath('mksnapshot', workingDir) | ||
const mksnapshotProcess = spawnSync(mksnapshotCommand, mksnapshotArgs, options) | ||
if (mksnapshotProcess.status !== 0) { | ||
let code = mksnapshotProcess.status | ||
if (code == null && mksnapshotProcess.signal === 'SIGILL') { | ||
code = 1 | ||
} | ||
console.log('Error running mksnapshot.') | ||
process.exit(code) | ||
}) | ||
} | ||
if (args.includes('--help')) { | ||
process.exit(0) | ||
} | ||
var killMksnapshot = function () { | ||
try { | ||
mksnapshotProcess.kill() | ||
} catch (ignored) { | ||
} | ||
fs.copyFileSync(path.join(workingDir, 'snapshot_blob.bin'), | ||
path.join(outputDir, 'snapshot_blob.bin')) | ||
const v8ContextGenCommand = getBinaryPath('v8_context_snapshot_generator', workingDir) | ||
const v8ContextGenArgs = [ | ||
`--output_file=${path.join(outputDir, 'v8_context_snapshot.bin')}` | ||
] | ||
const v8ContextGenOptions = { | ||
cwd: mksnapshotDir, | ||
env: process.env, | ||
stdio: 'inherit' | ||
} | ||
process.on('exit', killMksnapshot) | ||
process.on('SIGTERM', killMksnapshot) | ||
const v8ContextGenProcess = spawnSync(v8ContextGenCommand, v8ContextGenArgs, v8ContextGenOptions) | ||
if (v8ContextGenProcess.status !== 0) { | ||
console.log('Error running the v8 context snapshot generator.', v8ContextGenProcess) | ||
process.exit(v8ContextGenProcess.status) | ||
} | ||
process.exit(0) |
{ | ||
"name": "electron-mksnapshot", | ||
"version": "3.0.0-beta.1", | ||
"version": "3.0.10", | ||
"description": "Electron version of the mksnapshot binary", | ||
@@ -16,8 +16,8 @@ "repository": "https://github.com/electron/mksnapshot", | ||
"electron-download": "^4.1.0", | ||
"extract-zip": "^1.6.5" | ||
"extract-zip": "^1.6.5", | ||
"temp": "^0.8.3" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^3.2.0", | ||
"standard": "^8.6.0", | ||
"temp": "^0.8.3" | ||
"mocha": "^5.2.0", | ||
"standard": "^8.6.0" | ||
}, | ||
@@ -28,3 +28,6 @@ "standard": { | ||
] | ||
}, | ||
"engines": { | ||
"node": ">=8.5.0" | ||
} | ||
} |
@@ -25,4 +25,8 @@ # Electron mksnapshot | ||
npm install --save-dev electron-mksnapshot | ||
mksnapshot --help | ||
mksnapshot.js file.js (--output_dir OUTPUT_DIR). | ||
``` | ||
Running mksnapshot.js will generate both a snapshot_blob.bin and v8_context_snapshot.bin files which | ||
are needed to use custom snapshots in Electron. | ||
If an output directory isn't specified, the current directory will be used. | ||
(Additional mksnapshot args except for --startup_blob are supported, run mksnapshot --help to see options) | ||
@@ -29,0 +33,0 @@ ## Custom Mirror |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
9195
2
126
1
45
3
9
+ Addedtemp@^0.8.3
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedrimraf@2.6.3(transitive)
+ Addedtemp@0.8.4(transitive)
+ Addedwrappy@1.0.2(transitive)