diff --git a/script/lib/generate-startup-snapshot.js b/script/lib/generate-startup-snapshot.js index f7951daac..479fbbbf0 100644 --- a/script/lib/generate-startup-snapshot.js +++ b/script/lib/generate-startup-snapshot.js @@ -28,7 +28,6 @@ module.exports = function (packagedAppPath) { (relativePath.startsWith(path.join('..', 'src')) && relativePath.endsWith('-element.js')) || relativePath == path.join('..', 'exports', 'atom.js') || relativePath == path.join('..', 'src', 'config-schema.js') || - relativePath == path.join('..', 'src', 'compile-cache.js') || relativePath == path.join('..', 'src', 'electron-shims.js') || relativePath == path.join('..', 'src', 'safe-clipboard.js') || relativePath == path.join('..', 'node_modules', 'archive-view', 'node_modules', 'fs-plus', 'lib', 'fs-plus.js') || diff --git a/script/lib/transpile-babel-paths.js b/script/lib/transpile-babel-paths.js index 0a6a15f93..3c440a4bd 100644 --- a/script/lib/transpile-babel-paths.js +++ b/script/lib/transpile-babel-paths.js @@ -28,7 +28,6 @@ function getPathsToTranspile () { paths = paths.concat(glob.sync(path.join(CONFIG.intermediateAppPath, 'benchmarks', '**', '*.js'))) paths = paths.concat(glob.sync(path.join(CONFIG.intermediateAppPath, 'exports', '**', '*.js'))) paths = paths.concat(glob.sync(path.join(CONFIG.intermediateAppPath, 'src', '**', '*.js'))) - paths = paths.concat(glob.sync(path.join(CONFIG.intermediateAppPath, '**', 'atom-select-list', 'src', 'select-list-view.js'))) for (let packageName of Object.keys(CONFIG.appMetadata.packageDependencies)) { paths = paths.concat(glob.sync( path.join(CONFIG.intermediateAppPath, 'node_modules', packageName, '**', '*.js'), diff --git a/src/compile-cache.js b/src/compile-cache.js index 8a4451d90..e15674a2e 100644 --- a/src/compile-cache.js +++ b/src/compile-cache.js @@ -7,6 +7,7 @@ var path = require('path') var fs = require('fs-plus') +var sourceMapSupport = require('source-map-support') var PackageTranspilationRegistry = require('./package-transpilation-registry') var CSON = null @@ -113,109 +114,112 @@ function writeCachedJavascript (relativeCachePath, code) { var INLINE_SOURCE_MAP_REGEXP = /\/\/[#@]\s*sourceMappingURL=([^'"\n]+)\s*$/mg -require('source-map-support').install({ - handleUncaughtExceptions: false, +exports.install = function (nodeRequire) { + sourceMapSupport.install({ + handleUncaughtExceptions: false, - // Most of this logic is the same as the default implementation in the - // source-map-support module, but we've overridden it to read the javascript - // code from our cache directory. - retrieveSourceMap: function (filePath) { - if (!cacheDirectory || !fs.isFileSync(filePath)) { - return null - } + // Most of this logic is the same as the default implementation in the + // source-map-support module, but we've overridden it to read the javascript + // code from our cache directory. + retrieveSourceMap: function (filePath) { + if (!cacheDirectory || !fs.isFileSync(filePath)) { + return null + } - try { - var sourceCode = fs.readFileSync(filePath, 'utf8') - } catch (error) { - console.warn('Error reading source file', error.stack) - return null - } + try { + var sourceCode = fs.readFileSync(filePath, 'utf8') + } catch (error) { + console.warn('Error reading source file', error.stack) + return null + } - var compiler = COMPILERS[path.extname(filePath)] - if (!compiler) compiler = COMPILERS['.js'] + var compiler = COMPILERS[path.extname(filePath)] + if (!compiler) compiler = COMPILERS['.js'] - try { - var fileData = readCachedJavascript(compiler.getCachePath(sourceCode, filePath)) - } catch (error) { - console.warn('Error reading compiled file', error.stack) - return null - } + try { + var fileData = readCachedJavascript(compiler.getCachePath(sourceCode, filePath)) + } catch (error) { + console.warn('Error reading compiled file', error.stack) + return null + } - if (fileData == null) { - return null - } + if (fileData == null) { + return null + } - var match, lastMatch - INLINE_SOURCE_MAP_REGEXP.lastIndex = 0 - while ((match = INLINE_SOURCE_MAP_REGEXP.exec(fileData))) { - lastMatch = match - } - if (lastMatch == null) { - return null - } + var match, lastMatch + INLINE_SOURCE_MAP_REGEXP.lastIndex = 0 + while ((match = INLINE_SOURCE_MAP_REGEXP.exec(fileData))) { + lastMatch = match + } + if (lastMatch == null) { + return null + } - var sourceMappingURL = lastMatch[1] - var rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(',') + 1) + var sourceMappingURL = lastMatch[1] + var rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(',') + 1) - try { - var sourceMap = JSON.parse(new Buffer(rawData, 'base64')) - } catch (error) { - console.warn('Error parsing source map', error.stack) - return null - } + try { + var sourceMap = JSON.parse(new Buffer(rawData, 'base64')) + } catch (error) { + console.warn('Error parsing source map', error.stack) + return null + } - return { - map: sourceMap, - url: null - } - } -}) - -var prepareStackTraceWithSourceMapping = Error.prepareStackTrace -var prepareStackTrace = prepareStackTraceWithSourceMapping - -function prepareStackTraceWithRawStackAssignment (error, frames) { - if (error.rawStack) { // avoid infinite recursion - return prepareStackTraceWithSourceMapping(error, frames) - } else { - error.rawStack = frames - return prepareStackTrace(error, frames) - } -} - -Error.stackTraceLimit = 30 - -Object.defineProperty(Error, 'prepareStackTrace', { - get: function () { - return prepareStackTraceWithRawStackAssignment - }, - - set: function (newValue) { - prepareStackTrace = newValue - process.nextTick(function () { - prepareStackTrace = prepareStackTraceWithSourceMapping - }) - } -}) - -Error.prototype.getRawStack = function () { // eslint-disable-line no-extend-native - // Access this.stack to ensure prepareStackTrace has been run on this error - // because it assigns this.rawStack as a side-effect - this.stack - return this.rawStack -} - -Object.keys(COMPILERS).forEach(function (extension) { - var compiler = COMPILERS[extension] - - Object.defineProperty(require.extensions, extension, { - enumerable: true, - writable: false, - value: function (module, filePath) { - var code = compileFileAtPath(compiler, filePath, extension) - return module._compile(code, filePath) + return { + map: sourceMap, + url: null + } } }) -}) + + var prepareStackTraceWithSourceMapping = Error.prepareStackTrace + var prepareStackTrace = prepareStackTraceWithSourceMapping + + function prepareStackTraceWithRawStackAssignment (error, frames) { + if (error.rawStack) { // avoid infinite recursion + return prepareStackTraceWithSourceMapping(error, frames) + } else { + error.rawStack = frames + return prepareStackTrace(error, frames) + } + } + + Error.stackTraceLimit = 30 + + Object.defineProperty(Error, 'prepareStackTrace', { + get: function () { + return prepareStackTraceWithRawStackAssignment + }, + + set: function (newValue) { + prepareStackTrace = newValue + process.nextTick(function () { + prepareStackTrace = prepareStackTraceWithSourceMapping + }) + } + }) + + Error.prototype.getRawStack = function () { // eslint-disable-line no-extend-native + // Access this.stack to ensure prepareStackTrace has been run on this error + // because it assigns this.rawStack as a side-effect + this.stack + return this.rawStack + } + + Object.keys(COMPILERS).forEach(function (extension) { + var compiler = COMPILERS[extension] + + Object.defineProperty(nodeRequire.extensions, extension, { + enumerable: true, + writable: false, + value: function (module, filePath) { + var code = compileFileAtPath(compiler, filePath, extension) + return module._compile(code, filePath) + } + }) + }) +} + exports.resetCacheStats() diff --git a/src/initialize-application-window.coffee b/src/initialize-application-window.coffee index 507818998..13562fae2 100644 --- a/src/initialize-application-window.coffee +++ b/src/initialize-application-window.coffee @@ -24,6 +24,7 @@ require('deprecation-cop') require('dev-live-reload') require('encoding-selector') require('exception-reporting') +require('dalek') require('find-and-replace') require('fuzzy-finder') require('git-diff') diff --git a/src/main-process/start.js b/src/main-process/start.js index f54d263e0..368370939 100644 --- a/src/main-process/start.js +++ b/src/main-process/start.js @@ -83,4 +83,5 @@ function handleStartupEventWithSquirrel () { function setupCompileCache () { const CompileCache = require('../compile-cache') CompileCache.setAtomHomeDirectory(process.env.ATOM_HOME) + CompileCache.install(require) } diff --git a/src/task.coffee b/src/task.coffee index 9f115e869..182d9df88 100644 --- a/src/task.coffee +++ b/src/task.coffee @@ -73,6 +73,7 @@ class Task snapshotResult.setGlobals(global, process, global, {}, require) CompileCache = #{compileCacheRequire} CompileCache.setCacheDirectory('#{compileCachePath}'); + CompileCache.install(require) #{taskBootstrapRequire} """ bootstrap = bootstrap.replace(/\\/g, "\\\\") diff --git a/static/index.js b/static/index.js index fa240fcdb..4b7543dff 100644 --- a/static/index.js +++ b/static/index.js @@ -1,10 +1,10 @@ (function () { const electron = require('electron') const path = require('path') + const fs = require('fs-plus') const Module = require('module') const getWindowLoadSettings = require('../src/get-window-load-settings') const entryPointDirPath = __dirname - let CompileCache = null let blobStore = null let devMode = false let useSnapshot = false @@ -39,16 +39,17 @@ Module.prototype.require = function (module) { const absoluteFilePath = Module._resolveFilename(module, this, false) const relativeFilePath = path.relative(entryPointDirPath, absoluteFilePath) - const cachedModule = snapshotResult.customRequire.cache[relativeFilePath] - return cachedModule ? cachedModule : Module._load(module, this, false) + let cachedModule = snapshotResult.customRequire.cache[relativeFilePath] + if (!cachedModule) { + cachedModule = Module._load(module, this, false) + snapshotResult.customRequire.cache[relativeFilePath] = cachedModule + } + return cachedModule } snapshotResult.setGlobals(global, process, window, document, require) } - CompileCache = require('../src/compile-cache') - CompileCache.setAtomHomeDirectory(process.env.ATOM_HOME) - // const FileSystemBlobStore = requireFunction('../src/file-system-blob-store.js') // blobStore = FileSystemBlobStore.load( // path.join(process.env.ATOM_HOME, 'blob-store/') @@ -86,6 +87,10 @@ } function setupWindow () { + const CompileCache = requireFunction('../src/compile-cache.js') + CompileCache.setAtomHomeDirectory(process.env.ATOM_HOME) + CompileCache.install(require) + const ModuleCache = requireFunction('../src/module-cache.js') ModuleCache.register(getWindowLoadSettings())