Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

⬆️ Electron 3 (Take Two) #18916

Merged
merged 14 commits into from
May 20, 2019
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"url": "https://github.com/atom/atom/issues"
},
"license": "MIT",
"electronVersion": "2.0.18",
"electronVersion": "3.1.8",
jasonrudolph marked this conversation as resolved.
Show resolved Hide resolved
"dependencies": {
"@atom/notify": "1.2.1",
"@atom/nsfw": "1.0.22",
Expand Down Expand Up @@ -40,7 +40,6 @@
"base16-tomorrow-light-theme": "file:packages/base16-tomorrow-light-theme",
"bookmarks": "https://www.atom.io/api/packages/bookmarks/versions/0.46.0/tarball",
"bracket-matcher": "https://www.atom.io/api/packages/bracket-matcher/versions/0.91.0/tarball",
"cached-run-in-this-context": "0.5.0",
"chai": "3.5.0",
"chart.js": "^2.3.0",
"clear-cut": "^2.0.2",
Expand Down
12 changes: 6 additions & 6 deletions script/lib/check-chromedriver-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ const CONFIG = require('../config')
const semver = require('semver')

module.exports = function () {
// Chromedriver should be specified as ~x.y where x and y match Electron major/minor
// Chromedriver should be specified as ^n.x where n matches the Electron major version
const chromedriverVer = buildMetadata.dependencies['electron-chromedriver']
const mksnapshotVer = buildMetadata.dependencies['electron-mksnapshot']

// Always use tilde on electron-chromedriver so that it can pick up the best patch version
if (!chromedriverVer.startsWith('~')) {
throw new Error(`electron-chromedriver version in script/package.json should start with a tilde to match latest patch version.`)
// Always use caret on electron-chromedriver so that it can pick up the best minor/patch versions
if (!chromedriverVer.startsWith('^')) {
throw new Error(`electron-chromedriver version in script/package.json should start with a caret to match latest patch version.`)
}

if (!mksnapshotVer.startsWith('~')) {
throw new Error(`electron-mksnapshot version in script/package.json should start with a tilde to match latest patch version.`)
if (!mksnapshotVer.startsWith('^')) {
throw new Error(`electron-mksnapshot version in script/package.json should start with a caret to match latest patch version.`)
}

const electronVer = CONFIG.appMetadata.electronVersion
Expand Down
35 changes: 24 additions & 11 deletions script/lib/generate-startup-snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ module.exports = function (packagedAppPath) {
requiredModuleRelativePath === path.join('..', 'src', 'electron-shims.js') ||
requiredModuleRelativePath === path.join('..', 'node_modules', 'atom-keymap', 'lib', 'command-event.js') ||
requiredModuleRelativePath === path.join('..', 'node_modules', 'babel-core', 'index.js') ||
requiredModuleRelativePath === path.join('..', 'node_modules', 'cached-run-in-this-context', 'lib', 'main.js') ||
requiredModuleRelativePath === path.join('..', 'node_modules', 'debug', 'node.js') ||
requiredModuleRelativePath === path.join('..', 'node_modules', 'git-utils', 'src', 'git.js') ||
requiredModuleRelativePath === path.join('..', 'node_modules', 'glob', 'glob.js') ||
Expand Down Expand Up @@ -105,22 +104,36 @@ module.exports = function (packagedAppPath) {
{env: Object.assign({}, process.env, {ELECTRON_RUN_AS_NODE: 1})}
)

const generatedStartupBlobPath = path.join(CONFIG.buildOutputPath, 'snapshot_blob.bin')
console.log(`Generating startup blob at "${generatedStartupBlobPath}"`)
childProcess.execFileSync(
path.join(CONFIG.repositoryRootPath, 'script', 'node_modules', 'electron-mksnapshot', 'bin', 'mksnapshot'),
['--no-use_ic', snapshotScriptPath, '--startup_blob', generatedStartupBlobPath]
console.log('Generating startup blob with mksnapshot')
childProcess.spawnSync(
process.execPath, [
path.join(CONFIG.repositoryRootPath, 'script', 'node_modules', 'electron-mksnapshot', 'mksnapshot.js'),
snapshotScriptPath,
'--output_dir',
CONFIG.buildOutputPath
]
)

let startupBlobDestinationPath
if (process.platform === 'darwin') {
startupBlobDestinationPath = `${packagedAppPath}/Contents/Frameworks/Electron Framework.framework/Resources/snapshot_blob.bin`
startupBlobDestinationPath = `${packagedAppPath}/Contents/Frameworks/Electron Framework.framework/Resources`
} else {
startupBlobDestinationPath = path.join(packagedAppPath, 'snapshot_blob.bin')
startupBlobDestinationPath = packagedAppPath
}

console.log(`Moving generated startup blob into "${startupBlobDestinationPath}"`)
fs.unlinkSync(startupBlobDestinationPath)
fs.renameSync(generatedStartupBlobPath, startupBlobDestinationPath)
const snapshotBinaries = ['v8_context_snapshot.bin', 'snapshot_blob.bin']
for (let snapshotBinary of snapshotBinaries) {
const destinationPath = path.join(startupBlobDestinationPath, snapshotBinary)
console.log(`Moving generated startup blob into "${destinationPath}"`)
try {
fs.unlinkSync(destinationPath)
} catch (err) {
// Doesn't matter if the file doesn't exist already
if (!err.code || err.code !== 'ENOENT') {
throw err
}
}
fs.renameSync(path.join(CONFIG.buildOutputPath, snapshotBinary), destinationPath)
}
})
}
15 changes: 8 additions & 7 deletions script/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions script/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"coffeelint": "1.15.7",
"colors": "1.1.2",
"donna": "1.0.16",
"electron-chromedriver": "~2.0",
"electron-chromedriver": "^3.0.0-beta.1",
"electron-link": "0.4.0",
"electron-mksnapshot": "~2.0",
"electron-mksnapshot": "^3.0.10",
"electron-packager": "12.2.0",
"electron-winstaller": "2.6.4",
"eslint-config-standard": "^12.0.0",
Expand Down
4 changes: 2 additions & 2 deletions spec/theme-manager-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,9 @@ h2 {
it('returns a disposable allowing styles applied by the given path to be removed', function () {
const cssPath = require.resolve('./fixtures/css.css')

expect(getComputedStyle(document.body).fontWeight).not.toBe('bold')
expect(getComputedStyle(document.body).fontWeight).not.toBe('700')
const disposable = atom.themes.requireStylesheet(cssPath)
expect(getComputedStyle(document.body).fontWeight).toBe('bold')
expect(getComputedStyle(document.body).fontWeight).toBe('700')

let styleElementRemovedHandler
atom.styles.onDidRemoveStyleElement(
Expand Down
26 changes: 22 additions & 4 deletions src/native-compile-cache.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Module = require('module')
const path = require('path')
const cachedVm = require('cached-run-in-this-context')
const crypto = require('crypto')
const vm = require('vm')

function computeHash (contents) {
return crypto.createHash('sha1').update(contents, 'utf8').digest('hex')
Expand Down Expand Up @@ -34,6 +34,24 @@ class NativeCompileCache {
this.previousModuleCompile = Module.prototype._compile
}

runInThisContext (code, filename) {
// produceCachedData is deprecated after Node 10.6, will need to update
// this for Electron 4.0 to use script.createCachedData()
const script = new vm.Script(code, {filename, produceCachedData: true})
return {
result: script.runInThisContext(),
cacheBuffer: script.cachedData
}
}

runInThisContextCached (code, filename, cachedData) {
const script = new vm.Script(code, {filename, cachedData})
return {
result: script.runInThisContext(),
wasRejected: script.cachedDataRejected
}
}

overrideModuleCompile () {
let self = this
// Here we override Node's module.js
Expand Down Expand Up @@ -64,20 +82,20 @@ class NativeCompileCache {
let compiledWrapper = null
if (self.cacheStore.has(cacheKey)) {
let buffer = self.cacheStore.get(cacheKey)
let compilationResult = cachedVm.runInThisContextCached(wrapper, filename, buffer)
let compilationResult = self.runInThisContextCached(wrapper, filename, buffer)
compiledWrapper = compilationResult.result
if (compilationResult.wasRejected) {
self.cacheStore.delete(cacheKey)
}
} else {
let compilationResult
try {
compilationResult = cachedVm.runInThisContext(wrapper, filename)
compilationResult = self.runInThisContext(wrapper, filename)
} catch (err) {
console.error(`Error running script ${filename}`)
throw err
}
if (compilationResult.cacheBuffer) {
if (compilationResult.cacheBuffer !== null) {
self.cacheStore.set(cacheKey, compilationResult.cacheBuffer)
}
compiledWrapper = compilationResult.result
Expand Down
2 changes: 1 addition & 1 deletion src/text-editor-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -4446,7 +4446,7 @@ class NodePool {

if (element) {
element.className = className || ''
element.styleMap.forEach((value, key) => {
element.attributeStyleMap.forEach((value, key) => {
if (!style || style[key] == null) element.style[key] = ''
})
if (style) Object.assign(element.style, style)
Expand Down
4 changes: 0 additions & 4 deletions static/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
(function () {
// Eagerly require cached-run-in-this-context to prevent a circular require
// when using `NativeCompileCache` for the first time.
require('cached-run-in-this-context')

// Define the window start time before the requires so we get a more accurate
// window:start marker.
const startWindowTime = Date.now()
Expand Down