electron-mksnapshot 7.0.0 → 9.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -40,7 +40,7 @@ jobs:
40
40
 
41
41
  install-test-osx:
42
42
  macos:
43
- xcode: "9.0"
43
+ xcode: "11.1.0"
44
44
  steps:
45
45
  - checkout
46
46
 
package/README.md CHANGED
@@ -41,3 +41,37 @@ ELECTRON_MIRROR="https://npm.taobao.org/mirrors/electron/"
41
41
  # Example of requested URL: http://localhost:8080/1.2.0/mksnapshot-v1.2.0-darwin-x64.zip
42
42
  ELECTRON_MIRROR="http://localhost:8080/"
43
43
  ```
44
+
45
+ ## Overriding the version downloaded
46
+
47
+ The version downloaded can be overriden by setting the `ELECTRON_CUSTOM_VERSION` environment variable.
48
+
49
+ ```sh
50
+ # Install mksnapshot for Electron v8.3.0
51
+ ELECTRON_CUSTOM_VERSION=8.3.0 npm install
52
+ ```
53
+
54
+ ## Generating snapshots for ARM hardware
55
+
56
+ If you need to generate snapshots for Linux on 32 bit ARM, Linux on ARM64, or Windows on ARM64 you will need to install a cross arch mksnapshot on an Intel x64 machine. To do so, set the npm config `arch` to the proper arch and then run `npm install --save-dev electron-mksnapshot`. For example:
57
+
58
+ ### Linux on ARM64
59
+ From an Intel x64 Linux OS run:
60
+ ```sh
61
+ npm config set arch arm64
62
+ npm install --save-dev electron-mksnapshot
63
+ ```
64
+
65
+ ### Linux on 32 bit ARM
66
+ From an Intel x64 Linux OS run:
67
+ ```sh
68
+ npm config set arch armv7l
69
+ npm install --save-dev electron-mksnapshot
70
+ ```
71
+
72
+ ### Windows on ARM (64-bit)
73
+ From an Intel x64 Windows OS run:
74
+ ```sh
75
+ npm config set arch arm64
76
+ npm install --save-dev electron-mksnapshot
77
+ ```
@@ -1,38 +1,65 @@
1
- var fs = require('fs')
2
- var path = require('path')
3
- var electronDownload = require('electron-download')
4
- var extractZip = require('extract-zip')
5
- var versionToDownload = require('./package').version
1
+ const fs = require('fs')
2
+ const path = require('path')
3
+ const { downloadArtifact } = require('@electron/get')
4
+ const extractZip = require('extract-zip')
5
+ const versionToDownload = require('./package').version
6
+ let archToDownload = process.env.npm_config_arch
6
7
 
7
- function download (version, callback) {
8
- electronDownload({
8
+ if (process.arch.indexOf('arm') === 0) {
9
+ console.log(`WARNING: mksnapshot does not run on ${process.arch}. Download
10
+ https://github.com/electron/electron/releases/download/v${versionToDownload}/mksnapshot-v${versionToDownload}-${process.platform}-${process.arch}-x64.zip
11
+ on a x64 ${process.platform} OS to generate ${archToDownload} snapshots.`)
12
+ process.exit(1)
13
+ }
14
+
15
+ if (archToDownload && archToDownload.indexOf('arm') === 0) {
16
+ if (process.platform !== 'darwin') {
17
+ archToDownload += '-x64'
18
+ } else {
19
+ console.log(`WARNING: mksnapshot for ${archToDownload} is not available on macOS. Download
20
+ https://github.com/electron/electron/releases/download/v${versionToDownload}/mksnapshot-v${versionToDownload}-linux-${archToDownload}-x64.zip
21
+ on a x64 Linux OS to generate ${archToDownload} snapshots.`)
22
+ process.exit(1)
23
+ }
24
+ }
25
+
26
+ function download (version) {
27
+ return downloadArtifact({
9
28
  version: version,
10
- mksnapshot: true,
29
+ artifactName: 'mksnapshot',
11
30
  platform: process.env.npm_config_platform,
12
- arch: process.env.npm_config_arch,
13
- strictSSL: process.env.npm_config_strict_ssl === 'true',
31
+ arch: archToDownload,
32
+ rejectUnauthorized: process.env.npm_config_strict_ssl === 'true',
14
33
  quiet: ['info', 'verbose', 'silly', 'http'].indexOf(process.env.npm_config_loglevel) === -1
15
- }, callback)
34
+ })
16
35
  }
17
36
 
18
- function processDownload (err, zipPath) {
19
- if (err != null) throw err
20
- extractZip(zipPath, { dir: path.join(__dirname, 'bin') }, function (error) {
21
- if (error != null) throw error
22
- if (process.platform !== 'win32') {
23
- fs.chmod(path.join(__dirname, 'bin', 'mksnapshot'), '755', function (error) {
24
- if (error != null) throw error
25
- })
37
+ async function attemptDownload (version) {
38
+ try {
39
+ const targetFolder = path.join(__dirname, 'bin')
40
+ const zipPath = await download(version)
41
+ await extractZip(zipPath, { dir: targetFolder })
42
+ const platform = process.env.npm_config_platform || process.platform
43
+ if (platform !== 'win32') {
44
+ const mksnapshotPath = path.join(__dirname, 'bin', 'mksnapshot')
45
+ if (fs.existsSync(mksnapshotPath)) {
46
+ fs.chmod(mksnapshotPath, '755', function (error) {
47
+ if (error != null) throw error
48
+ })
49
+ }
26
50
  }
27
- })
28
- }
51
+ } catch (err) {
52
+ // attempt to fall back to semver minor
53
+ const parts = version.split('.')
54
+ const baseVersion = `${parts[0]}.${parts[1]}.0`
29
55
 
30
- download(versionToDownload, function (err, zipPath) {
31
- if (err) {
32
- var versionSegments = versionToDownload.split('.')
33
- var baseVersion = versionSegments[0] + '.' + versionSegments[1] + '.0'
34
- download(baseVersion, processDownload)
35
- } else {
36
- processDownload(err, zipPath)
56
+ // don't recurse infinitely
57
+ if (baseVersion === version) {
58
+ throw err
59
+ } else {
60
+ await attemptDownload(baseVersion)
61
+ }
37
62
  }
38
- })
63
+ }
64
+
65
+ attemptDownload(versionToDownload)
package/mksnapshot.js CHANGED
@@ -5,6 +5,11 @@ const { spawnSync } = require('child_process')
5
5
  const path = require('path')
6
6
  const temp = require('temp').track()
7
7
  const workingDir = temp.mkdirSync('mksnapshot-workdir')
8
+ const crossArchDirs = [
9
+ 'clang_x86_v8_arm',
10
+ 'clang_x64_v8_arm64',
11
+ 'win_clang_x64'
12
+ ]
8
13
 
9
14
  function getBinaryPath (binary, binaryPath) {
10
15
  if (process.platform === 'win32') {
@@ -38,11 +43,6 @@ if (outDirIdx > -1) {
38
43
  if (args.includes('--startup_blob')) {
39
44
  console.log('--startup_blob argument not supported. Use --output_dir to specify where to output snapshot_blob.bin')
40
45
  process.exit(1)
41
- } else {
42
- mksnapshotArgs = mksnapshotArgs.concat(['--startup_blob', 'snapshot_blob.bin'])
43
- }
44
- if (!mksnapshotArgs.includes('--turbo_instruction_scheduling')) {
45
- mksnapshotArgs.push('--turbo_instruction_scheduling')
46
46
  }
47
47
 
48
48
  const mksnapshotDir = path.join(__dirname, 'bin')
@@ -52,13 +52,48 @@ const mksnapshotDir = path.join(__dirname, 'bin')
52
52
  // directory.
53
53
  fs.copySync(mksnapshotDir, workingDir)
54
54
 
55
+ const argsFile = path.join(mksnapshotDir, 'mksnapshot_args')
56
+ let mksnapshotBinaryDir = workingDir
57
+ if (fs.existsSync(argsFile)) {
58
+ // Use args from args file if it is provided as these match what is used to generate the original snapshot
59
+ const mksnapshotArgsFile = fs.readFileSync(argsFile, 'utf8')
60
+ const newlineRegEx = /(\r\n|\r|\n)/g
61
+ const mksnapshotArgsFromFile = mksnapshotArgsFile.split(newlineRegEx).filter((arg) => {
62
+ return (!arg.match(newlineRegEx) && arg !== '')
63
+ })
64
+ const mksnapshotBinaryPath = path.parse(mksnapshotArgsFromFile[0])
65
+ if (mksnapshotBinaryPath.dir) {
66
+ mksnapshotBinaryDir = path.join(workingDir, mksnapshotBinaryPath.dir)
67
+ }
68
+ mksnapshotArgs = mksnapshotArgs.concat(mksnapshotArgsFromFile.slice(1))
69
+ } else {
70
+ mksnapshotArgs = mksnapshotArgs.concat(['--startup_blob', 'snapshot_blob.bin'])
71
+ if (!mksnapshotArgs.includes('--turbo_instruction_scheduling')) {
72
+ mksnapshotArgs.push('--turbo_instruction_scheduling')
73
+ }
74
+ if (!fs.existsSync(getBinaryPath('mksnapshot', mksnapshotBinaryDir))) {
75
+ const matchingDir = crossArchDirs.find((crossArchDir) => {
76
+ const candidatePath = path.join(mksnapshotBinaryDir, crossArchDir)
77
+ if (fs.existsSync(getBinaryPath('mksnapshot', candidatePath))) {
78
+ return true
79
+ }
80
+ })
81
+ if (matchingDir) {
82
+ mksnapshotBinaryDir = path.join(workingDir, matchingDir)
83
+ } else {
84
+ console.log('ERROR: Could not find mksnapshot')
85
+ process.exit(1)
86
+ }
87
+ }
88
+ }
89
+
55
90
  const options = {
56
91
  cwd: workingDir,
57
92
  env: process.env,
58
93
  stdio: 'inherit'
59
94
  }
60
95
 
61
- const mksnapshotCommand = getBinaryPath('mksnapshot', workingDir)
96
+ const mksnapshotCommand = getBinaryPath('mksnapshot', mksnapshotBinaryDir)
62
97
  const mksnapshotProcess = spawnSync(mksnapshotCommand, mksnapshotArgs, options)
63
98
  if (mksnapshotProcess.status !== 0) {
64
99
  let code = mksnapshotProcess.status
@@ -75,7 +110,7 @@ if (args.includes('--help')) {
75
110
  fs.copyFileSync(path.join(workingDir, 'snapshot_blob.bin'),
76
111
  path.join(outputDir, 'snapshot_blob.bin'))
77
112
 
78
- const v8ContextGenCommand = getBinaryPath('v8_context_snapshot_generator', workingDir)
113
+ const v8ContextGenCommand = getBinaryPath('v8_context_snapshot_generator', mksnapshotBinaryDir)
79
114
  const v8ContextGenArgs = [
80
115
  `--output_file=${path.join(outputDir, 'v8_context_snapshot.bin')}`
81
116
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electron-mksnapshot",
3
- "version": "7.0.0",
3
+ "version": "9.0.2",
4
4
  "description": "Electron version of the mksnapshot binary",
5
5
  "repository": "https://github.com/electron/mksnapshot",
6
6
  "bin": {
@@ -12,13 +12,13 @@
12
12
  },
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
- "electron-download": "^4.1.0",
16
- "extract-zip": "^1.6.5",
15
+ "@electron/get": "^1.12.2",
16
+ "extract-zip": "^2.0.0",
17
17
  "fs-extra": "^7.0.1",
18
18
  "temp": "^0.8.3"
19
19
  },
20
20
  "devDependencies": {
21
- "mocha": "^5.2.0",
21
+ "mocha": "^7.1.2",
22
22
  "standard": "^14.3.1"
23
23
  },
24
24
  "standard": {