Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

electron-mksnapshot

Package Overview
Dependencies
Maintainers
5
Versions
227
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-mksnapshot - npm Package Compare versions

Comparing version 3.0.0-beta.1 to 3.0.10

107

mksnapshot.js
#!/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)

13

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc