mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-21 16:08:24 +03:00
Defer requiring 6to5 until it is used
It seems to have a require time of ~250ms
This commit is contained in:
parent
2b0cb11df3
commit
6ad704c1e4
@ -7,7 +7,7 @@ Inspired by https://github.com/atom/atom/blob/6b963a562f8d495fbebe6abdbafbc7caf7
|
||||
crypto = require 'crypto'
|
||||
fs = require 'fs-plus'
|
||||
path = require 'path'
|
||||
to5 = require '6to5-core'
|
||||
to5 = null # Defer until used
|
||||
|
||||
stats =
|
||||
hits: 0
|
||||
@ -89,11 +89,16 @@ create6to5VersionAndOptionsDigest = (version, options) ->
|
||||
updateDigestForJsonValue(shasum, options)
|
||||
shasum.digest('hex')
|
||||
|
||||
cacheDir = path.join(fs.absolute('~/.atom'), 'compile-cache')
|
||||
jsCacheDir = path.join(cacheDir, 'js', '6to5', create6to5VersionAndOptionsDigest(to5.version, defaultOptions))
|
||||
jsCacheDir = null
|
||||
|
||||
getCachePath = (sourceCode) ->
|
||||
digest = crypto.createHash('sha1').update(sourceCode, 'utf8').digest('hex')
|
||||
|
||||
unless jsCacheDir?
|
||||
to5 ?= require '6to5-core'
|
||||
cacheDir = path.join(fs.absolute('~/.atom'), 'compile-cache')
|
||||
jsCacheDir = path.join(cacheDir, 'js', '6to5', create6to5VersionAndOptionsDigest(to5.version, defaultOptions))
|
||||
|
||||
path.join(jsCacheDir, "#{digest}.js")
|
||||
|
||||
getCachedJavaScript = (cachePath) ->
|
||||
@ -113,6 +118,7 @@ createOptions = (filePath) ->
|
||||
|
||||
transpile = (sourceCode, filePath, cachePath) ->
|
||||
options = createOptions(filePath)
|
||||
to5 ?= require '6to5-core'
|
||||
js = to5.transform(sourceCode, options).code
|
||||
stats.misses++
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user