From 14fca6c8d305e992b62926e1a14f61f6081c3b9e Mon Sep 17 00:00:00 2001 From: Karang Date: Wed, 10 Jun 2020 18:12:16 +0200 Subject: [PATCH 1/2] Remove closure-compiler dependency --- doc/api.md | 4 --- examples/compiled.js | 11 -------- package.json | 1 - src/compiler.js | 60 +------------------------------------------- 4 files changed, 1 insertion(+), 75 deletions(-) diff --git a/doc/api.md b/doc/api.md index 32bd107..d6cc40f 100644 --- a/doc/api.md +++ b/doc/api.md @@ -84,10 +84,6 @@ The `path` is an array of namespace keys which select a path of namespaces to be Compile and return a `ProtoDef` object, optionaly print the generated javascript code. -### ProtoDefCompiler.compileProtoDef(options = { optimize: false, printCode: false, printOptimizedCode: false }) - -Async function, returns a promise. Compile and return a `ProtoDef` object, optionaly print the generated javascript code. When `optimize = true`, use closure-compiler to optimize the generated code. - ## utils Some functions that can be useful to build new datatypes reader and writer. diff --git a/examples/compiled.js b/examples/compiled.js index 81b04fe..37e1d6c 100644 --- a/examples/compiled.js +++ b/examples/compiled.js @@ -55,15 +55,4 @@ const packetData = { time = performance.now() - start ps = nbTests / 10 / time console.log('read / write parser: ' + time.toFixed(2) + ' ms (' + ps.toFixed(2) + 'k packet/s)') - - // Closure optimized: - const optimizedProto = await compiler.compileProtoDef({ optimize: true }) - start = performance.now() - for (let i = 0; i < nbTests; i++) { - const result = optimizedProto.parsePacketBuffer(mainType, buffer).data - optimizedProto.createPacketBuffer(mainType, result) - } - time = performance.now() - start - ps = nbTests / time - console.log('read / write compiled (+closure): ' + time.toFixed(2) + ' ms (' + ps.toFixed(2) + 'k packet/s)') })() diff --git a/package.json b/package.json index 75e372a..1fcd708 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,6 @@ "tonicExampleFilename": "example.js", "license": "MIT", "dependencies": { - "google-closure-compiler": "^20200504.0.0", "lodash.get": "^4.4.2", "lodash.reduce": "^4.6.0", "protodef-validator": "^1.2.2", diff --git a/src/compiler.js b/src/compiler.js index d61210b..5c3aba6 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -1,5 +1,3 @@ -const ClosureCompiler = require('google-closure-compiler').jsCompiler - const numeric = require('./datatypes/numeric') const utils = require('./datatypes/utils') @@ -51,50 +49,6 @@ class ProtoDefCompiler { const readCtx = this.readCompiler.compile(readCode) return new CompiledProtodef(sizeOfCtx, writeCtx, readCtx) } - - compileProtoDef (options = { optimize: false, printCode: false, printOptimizedCode: false }) { - let c = this - return new Promise(resolve => { - const sizeOfCode = c.sizeOfCompiler.generate() - const writeCode = c.writeCompiler.generate() - const readCode = c.readCompiler.generate() - - if (options.printCode) { - console.log('// SizeOf:') - console.log(sizeOfCode) - console.log('// Write:') - console.log(writeCode) - console.log('// Read:') - console.log(readCode) - } - - if (options.optimize) { - optimize(sizeOfCode, (sizeOfCode) => { - optimize(writeCode, (writeCode) => { - optimize(readCode, (readCode) => { - if (options.printOptimizedCode) { - console.log('// SizeOf:') - console.log(sizeOfCode) - console.log('// Write:') - console.log(writeCode) - console.log('// Read:') - console.log(readCode) - } - const sizeOfCtx = c.sizeOfCompiler.compile(sizeOfCode) - const writeCtx = c.writeCompiler.compile(writeCode) - const readCtx = c.readCompiler.compile(readCode) - resolve(new CompiledProtodef(sizeOfCtx, writeCtx, readCtx)) - }) - }) - }) - } else { - const sizeOfCtx = c.sizeOfCompiler.compile(sizeOfCode) - const writeCtx = c.writeCompiler.compile(writeCode) - const readCtx = c.readCompiler.compile(readCode) - resolve(new CompiledProtodef(sizeOfCtx, writeCtx, readCtx)) - } - }) - } } class CompiledProtodef { @@ -458,21 +412,9 @@ class SizeOfCompiler extends Compiler { } } -function optimize (code, cb) { - const closureCompiler = new ClosureCompiler({ - compilation_level: 'SIMPLE' - }) - closureCompiler.run([{ - src: code - }], (exitCode, stdOut, stdErr) => { - cb(stdOut[0].src) - }) -} - module.exports = { ReadCompiler, WriteCompiler, SizeOfCompiler, - ProtoDefCompiler, - optimize + ProtoDefCompiler } From 806878f1202740d33c253de29f405c1eeca8bae8 Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Wed, 10 Jun 2020 20:38:32 +0000 Subject: [PATCH 2/2] Release 1.7.2 --- doc/history.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/history.md b/doc/history.md index 1fc9ca7..8252625 100644 --- a/doc/history.md +++ b/doc/history.md @@ -1,5 +1,9 @@ # History +## 1.7.2 + +* remove closure compiler + ## 1.7.1 * fix option in compiler diff --git a/package.json b/package.json index 1fcd708..ef4a79c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "protodef", - "version": "1.7.1", + "version": "1.7.2", "description": "A simple yet powerful way to define binary protocols", "main": "index.js", "author": "roblabla ",