diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-04-20 03:09:25 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-04-24 16:14:29 +0200 |
commit | 82f2b76e25a4a67e01ec67e5ebe39d14ad771ea8 (patch) | |
tree | 965f6eb89b84d65a62b49008fd972c004832ccd1 /thirdparty/systemjs/bench/get-cjs-deps.js | |
parent | e6e0cbc387c2a77b48e4065c229daa65bf1aa0fa (diff) |
Reorganize module loading.
We now use webpack instead of SystemJS, effectively bundling modules
into one file (plus commons chunks) for every entry point. This results
in a much smaller extension size (almost half). Furthermore we use
yarn/npm even for extension run-time dependencies. This relieves us
from manually vendoring and building dependencies. It's also easier to
understand for new developers familiar with node.
Diffstat (limited to 'thirdparty/systemjs/bench/get-cjs-deps.js')
-rw-r--r-- | thirdparty/systemjs/bench/get-cjs-deps.js | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/thirdparty/systemjs/bench/get-cjs-deps.js b/thirdparty/systemjs/bench/get-cjs-deps.js deleted file mode 100644 index b999a1c16..000000000 --- a/thirdparty/systemjs/bench/get-cjs-deps.js +++ /dev/null @@ -1,63 +0,0 @@ -var fs = require('fs'); - -// require('...') || exports[''] = ... || exports.asd = ... || module.exports = ... -var cjsExportsRegEx = /(?:^\uFEFF?|[^$_a-zA-Z\xA0-\uFFFF.])(exports\s*(\[['"]|\.)|module(\.exports|\['exports'\]|\["exports"\])\s*(\[['"]|[=,\.]))/; -// RegEx adjusted from https://github.com/jbrantly/yabble/blob/master/lib/yabble.js#L339 -var cjsRequireRegEx = /(?:^\uFEFF?|[^$_a-zA-Z\xA0-\uFFFF."'])require\s*\(\s*("[^"\\]*(?:\\.[^"\\]*)*"|'[^'\\]*(?:\\.[^'\\]*)*')\s*\)/g; -var commentRegEx = /(^|[^\\])(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg; - -var stringRegEx = /("[^"\\\n\r]*(\\.[^"\\\n\r]*)*"|'[^'\\\n\r]*(\\.[^'\\\n\r]*)*')/g; -function getCJSDeps(source) { - cjsRequireRegEx.lastIndex = commentRegEx.lastIndex = stringRegEx.lastIndex = 0; - - var deps = []; - - var match; - - // track string and comment locations for unminified source - var stringLocations = [], commentLocations = []; - - function inLocation(locations, match) { - for (var i = 0; i < locations.length; i++) - if (locations[i][0] < match.index && locations[i][1] > match.index) - return true; - return false; - } - - if (source.length / source.split('\n').length < 200) { - while (match = stringRegEx.exec(source)) - stringLocations.push([match.index, match.index + match[0].length]); - - // TODO: track template literals here before comments - - while (match = commentRegEx.exec(source)) { - // only track comments not starting in strings - if (!inLocation(stringLocations, match)) - commentLocations.push([match.index + match[1].length, match.index + match[0].length - 1]); - } - } - - while (match = cjsRequireRegEx.exec(source)) { - // ensure we're not within a string or comment location - if (!inLocation(stringLocations, match) && !inLocation(commentLocations, match)) { - var dep = match[1].substr(1, match[1].length - 2); - // skip cases like require('" + file + "') - if (dep.match(/"|'/)) - continue; - // trailing slash requires are removed as they don't map mains in SystemJS - if (dep[dep.length - 1] == '/') - dep = dep.substr(0, dep.length - 1); - deps.push(dep); - } - } - - return deps; -} - -var cjs = fs.readFileSync('./cjs-sample/cjs.js').toString(); - -var startTime = Date.now(); -for (var i = 0; i < 1000; i++) - getCJSDeps(cjs); -console.log(Date.now() - startTime); - |