From d4ed8a0b735e4980702625dc6b8baf281fe2ed0e Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 4 Sep 2014 10:10:04 -0700 Subject: [PATCH] Defer requiring CoffeeScript Requiring it up front adds about 30-40ms to startup. --- src/browser/main.coffee | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/browser/main.coffee b/src/browser/main.coffee index 87d7b0601..12a8cad90 100644 --- a/src/browser/main.coffee +++ b/src/browser/main.coffee @@ -38,7 +38,7 @@ start = -> args.pathsToOpen = args.pathsToOpen.map (pathToOpen) -> path.resolve(args.executedFrom ? process.cwd(), pathToOpen.toString()) - require('coffee-script').register() + setupCoffeeScript() if args.devMode require(path.join(args.resourcePath, 'src', 'coffee-cache')).register() AtomApplication = require path.join(args.resourcePath, 'src', 'browser', 'atom-application') @@ -55,6 +55,15 @@ global.devResourcePath = path.normalize(global.devResourcePath) if global.devRes setupCrashReporter = -> crashReporter.start(productName: 'Atom', companyName: 'GitHub') +setupCoffeeScript = -> + CoffeeScript = null + + require.extensions['.coffee'] = (module, filePath) -> + CoffeeScript ?= require('coffee-script') + coffee = fs.readFileSync(filePath, 'utf8') + {js} = CoffeeScript.compile(coffee, filename: filePath) + module._compile(js, filePath) + parseCommandLine = -> version = app.getVersion() options = optimist(process.argv[1..])