From 54337ecf9be96ea43a5a80f0944800b37c3ad500 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sun, 5 Nov 2017 12:37:35 +0000 Subject: [PATCH 01/12] refactor: remove support for generators, remove regenerator --- index.js | 136 ++++++--------------------------------------------- package.json | 9 ++-- 2 files changed, 19 insertions(+), 126 deletions(-) diff --git a/index.js b/index.js index 096325b..fb3266a 100644 --- a/index.js +++ b/index.js @@ -1,139 +1,33 @@ 'use strict'; -module.exports = function (ajv) { - setupAsyncOpts(ajv._opts, true); - return ajv; -}; - -var ASYNC = { - '*': checkGenerators, - 'co*': checkGenerators, - 'es7': checkAsyncFunction -}; - -var TRANSPILE = { - 'nodent': getNodent, - 'regenerator': getRegenerator -}; - -var MODES = [ - { async: 'es7' }, - { async: 'co*' }, - { async: 'es7', transpile: 'nodent' }, - { async: 'co*', transpile: 'regenerator' } -]; - - -var regenerator, nodent; - +var nodent = require('nodent')({ log: false, dontInstallRequireHook: true }); -function setupAsyncOpts(opts, required) { - var async = opts.async - , transpile = opts.transpile - , check; - switch (typeof transpile) { - case 'string': - var get = TRANSPILE[transpile]; - if (!get) throw new Error('bad transpiler: ' + transpile); - return (opts.processCode = get(opts, required)); - case 'undefined': - case 'boolean': - if (typeof async == 'string') { - check = ASYNC[async]; - if (!check) throw new Error('bad async mode: ' + async); - return (opts.transpile = check(opts, required)); - } - - for (var i=0; i Date: Sun, 5 Nov 2017 20:38:00 +0000 Subject: [PATCH 02/12] test: ajv transpile option --- .travis.yml | 6 ++++++ package.json | 19 +++++++++++++++++- spec/transpile.spec.js | 45 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 .travis.yml create mode 100644 spec/transpile.spec.js diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c5cea94 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +language: node_js +node_js: + - "4" + - "6" +after_script: + - coveralls < coverage/lcov.info diff --git a/package.json b/package.json index 97d67ae..ec9a4c6 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,9 @@ "description": "Configure async validation mode in Ajv - JSON-Schema validator", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test-spec": "mocha spec/*.spec.js -R spec", + "test-cov": "nyc npm run test-spec", + "test": "npm run test-cov" }, "repository": { "type": "git", @@ -40,5 +42,20 @@ }, "dependencies": { "nodent": "^3.1.3" + }, + "devDependencies": { + "mocha": "^4.0.1", + "nyc": "^11.3.0", + "pre-commit": "^1.2.2" + }, + "nyc": { + "exclude": [ + "**/spec/**", + "node_modules" + ], + "reporter": [ + "lcov", + "text-summary" + ] } } diff --git a/spec/transpile.spec.js b/spec/transpile.spec.js new file mode 100644 index 0000000..7da34c1 --- /dev/null +++ b/spec/transpile.spec.js @@ -0,0 +1,45 @@ +'use strict'; + +var Ajv = require('ajv'); +var setupAsync = require('../index.js'); +var assert = require('assert'); + + +describe('transpile option', function() { + var majorNodeVersion; + if (typeof process != 'undefined') + majorNodeVersion = +process.versions.node.split('.')[0]; + + it('should set processCode if async not supported', function() { + var ajv = setupAsync(new Ajv); + if (majorNodeVersion >= 7) + assert.strictEqual(ajv._opts.processCode, undefined); + else + assert.equal(typeof ajv._opts.processCode, 'function'); + }); + + it('should always set processCode if transpile: true', function() { + var ajv = setupAsync(new Ajv({ transpile: true })); + assert.equal(typeof ajv._opts.processCode, 'function'); + }); + + it('should throw error if async not supported and transpile: false', function() { + if (majorNodeVersion >= 7) assert.doesNotThrow(test); + else assert.throws(test, /async functions not supported/); + + function test() { + setupAsync(new Ajv({ transpile: false })); + } + }); + + it('should throw error with unknown transpile option', function() { + test('nodent'); + test({}); + + function test(transpile) { + assert.throws(function() { + setupAsync(new Ajv({ transpile: transpile })); + }, /transpile option must be boolean or undefined/); + } + }); +}); From 4b0e1feefe0e298cd5b678f7b6386bc234b1f553 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sun, 5 Nov 2017 20:42:07 +0000 Subject: [PATCH 03/12] 1.0.0-beta.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ec9a4c6..4dedc9b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ajv-async", - "version": "0.1.1", + "version": "1.0.0-beta.0", "description": "Configure async validation mode in Ajv - JSON-Schema validator", "main": "index.js", "scripts": { From e14452669a517216f866b74106713eb7057c3b4b Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Tue, 7 Nov 2017 18:09:07 +0000 Subject: [PATCH 04/12] script to create browser bundle --- .gitignore | 3 +++ package.json | 6 +++++- scripts/bundle | 17 +++++++++++++++++ scripts/info | 10 ++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100755 scripts/bundle create mode 100755 scripts/info diff --git a/.gitignore b/.gitignore index 5148e52..2bbbcf5 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,6 @@ jspm_packages # Optional REPL history .node_repl_history + +# browser bundles +dist/ diff --git a/package.json b/package.json index 4dedc9b..52396f3 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,8 @@ "description": "Configure async validation mode in Ajv - JSON-Schema validator", "main": "index.js", "scripts": { + "bundle": "rm -rf dist && ./scripts/bundle", + "prepublish": "npm run bundle", "test-spec": "mocha spec/*.spec.js -R spec", "test-cov": "nyc npm run test-spec", "test": "npm run test-cov" @@ -44,9 +46,11 @@ "nodent": "^3.1.3" }, "devDependencies": { + "browserify": "^14.5.0", "mocha": "^4.0.1", "nyc": "^11.3.0", - "pre-commit": "^1.2.2" + "pre-commit": "^1.2.2", + "uglify-js": "^3.1.8" }, "nyc": { "exclude": [ diff --git a/scripts/bundle b/scripts/bundle new file mode 100755 index 0000000..03f05c7 --- /dev/null +++ b/scripts/bundle @@ -0,0 +1,17 @@ +#!/usr/bin/env sh + +set -e + +name=$(./scripts/info name) +main=$(./scripts/info main) +version=$(./scripts/info version) +description=$(./scripts/info description) + +mkdir -p dist + +browserify -r "./$main:$name" \ + -o "dist/$name.bundle.js" + +uglifyjs "dist/$name.bundle.js" -o "dist/$name.min.js" \ + -c -m --source-map \ + -b "beautify=false, preamble='/* $name $version: $description */'" diff --git a/scripts/info b/scripts/info new file mode 100755 index 0000000..0dca1f4 --- /dev/null +++ b/scripts/info @@ -0,0 +1,10 @@ +#!/usr/bin/env node + +'use strict'; + +var fs = require('fs'); +var property = process.argv[2] || 'version'; +var name = process.argv[3] || '.'; +if (name != '.') name = 'node_modules/' + name; +var json = JSON.parse(fs.readFileSync(name + '/package.json', 'utf8')); +console.log(json[property]); From f1feb89bb458bea15e6c727e8dd7e26f9da50327 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Wed, 8 Nov 2017 20:42:50 +0000 Subject: [PATCH 05/12] standalone bundle --- scripts/bundle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/bundle b/scripts/bundle index 03f05c7..52720b0 100755 --- a/scripts/bundle +++ b/scripts/bundle @@ -10,7 +10,8 @@ description=$(./scripts/info description) mkdir -p dist browserify -r "./$main:$name" \ - -o "dist/$name.bundle.js" + -o "dist/$name.bundle.js" \ + -s ajvAsync uglifyjs "dist/$name.bundle.js" -o "dist/$name.min.js" \ -c -m --source-map \ From 4f122a800e37509f8c685f397223ae668eb04401 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Wed, 8 Nov 2017 20:44:44 +0000 Subject: [PATCH 06/12] 1.0.0-beta.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 52396f3..d43489d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ajv-async", - "version": "1.0.0-beta.0", + "version": "1.0.0-beta.1", "description": "Configure async validation mode in Ajv - JSON-Schema validator", "main": "index.js", "scripts": { From f0a8150568f7efe12f22723d2f834ffc3d8da437 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Wed, 8 Nov 2017 21:28:09 +0000 Subject: [PATCH 07/12] package.json files --- package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/package.json b/package.json index d43489d..1d77a65 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,10 @@ "pre-commit": "^1.2.2", "uglify-js": "^3.1.8" }, + "files": [ + "index.js", + "dist/" + ], "nyc": { "exclude": [ "**/spec/**", From 4c47f7649035682b4d72ec22ba64a2b488052f9a Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Wed, 8 Nov 2017 21:31:32 +0000 Subject: [PATCH 08/12] fix missing dev dependnecy ajv --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 1d77a65..e47115b 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "nodent": "^3.1.3" }, "devDependencies": { + "ajv": "^6.0.0-beta.0", "browserify": "^14.5.0", "mocha": "^4.0.1", "nyc": "^11.3.0", From 040fd790b1aecb7c07dd3b2e5d4e6b6aed5595da Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Wed, 8 Nov 2017 21:47:52 +0000 Subject: [PATCH 09/12] 1.0.0-beta.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e47115b..6d35aa7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ajv-async", - "version": "1.0.0-beta.1", + "version": "1.0.0-beta.2", "description": "Configure async validation mode in Ajv - JSON-Schema validator", "main": "index.js", "scripts": { From 119bc5f9c7e7ef395fccf3dafd6b4628fcfec579 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sun, 7 Jan 2018 12:45:18 +0000 Subject: [PATCH 10/12] chore: update ajv version --- .gitignore | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 2bbbcf5..5537bc5 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,5 @@ jspm_packages # browser bundles dist/ + +package-lock.json diff --git a/package.json b/package.json index 6d35aa7..2d0328f 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "homepage": "https://github.com/epoberezkin/ajv-async#readme", "peerDependencies": { - "ajv": "^6.0.0-beta.0" + "ajv": ">= 6.0.0-beta.0" }, "dependencies": { "nodent": "^3.1.3" From ce38af67daad5442eabaf8a1189d25784f322558 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sun, 7 Jan 2018 12:46:42 +0000 Subject: [PATCH 11/12] 1.0.0-rc.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2d0328f..d86631b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ajv-async", - "version": "1.0.0-beta.2", + "version": "1.0.0-rc.0", "description": "Configure async validation mode in Ajv - JSON-Schema validator", "main": "index.js", "scripts": { From 30a592596ad2984cb1e1186be8f2a4ef514e72b7 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sun, 7 Jan 2018 13:02:04 +0000 Subject: [PATCH 12/12] 1.0.0 --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index d86631b..059ff7a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ajv-async", - "version": "1.0.0-rc.0", + "version": "1.0.0", "description": "Configure async validation mode in Ajv - JSON-Schema validator", "main": "index.js", "scripts": { @@ -40,13 +40,13 @@ }, "homepage": "https://github.com/epoberezkin/ajv-async#readme", "peerDependencies": { - "ajv": ">= 6.0.0-beta.0" + "ajv": "^6.0.0" }, "dependencies": { "nodent": "^3.1.3" }, "devDependencies": { - "ajv": "^6.0.0-beta.0", + "ajv": "^6.0.0", "browserify": "^14.5.0", "mocha": "^4.0.1", "nyc": "^11.3.0",