diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 1ef5b786..6b995e98 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,4 +1,10 @@ # ANS Release Notes + +### 1.12.3 + +* Prevent the callback function from being called twice during the loading of schemas +* Prevent the load schema function from returning before the full schema is read + ### 1.12.2 * [PPA-825](https://arcpublishing.atlassian.net/browse/PPA-825) - fix a minor issue in previous 1.12.1 diff --git a/lib/schemas.js b/lib/schemas.js index b5065838..3d58e1d4 100644 --- a/lib/schemas.js +++ b/lib/schemas.js @@ -1,5 +1,6 @@ 'use strict'; +const schemaVersionsLoaded = {}; var schemas = {}; var schemasByVersion = {}; var dir = require('node-dir'); @@ -8,7 +9,6 @@ var _ = require('lodash'); var baseDir = path.join(path.dirname(module.filename), '../src/main/resources/schema/ans'); -var callback = undefined; var loaded = false; @@ -19,13 +19,12 @@ var loadSchema = function loadSchema(version, done) { return; } - if (_.isObject(schemasByVersion[version])) { + if (schemasByVersion[version] && schemaVersionsLoaded[version]) { done(null, schemasByVersion[version]); + return; } - var schemaDir = baseDir + '/' + version; - - schemasByVersion[version] = {}; + var schemaDir = baseDir + '/' + version; dir.readFiles( schemaDir, { @@ -33,7 +32,10 @@ var loadSchema = function loadSchema(version, done) { }, function(err, content, filename, next) { if (err) throw err; - + if (!schemasByVersion[version]) { + schemasByVersion[version] = {}; + schemaVersionsLoaded[version] = false; + } var name = path.relative(schemaDir, filename); try { var content = JSON.parse(content); @@ -51,7 +53,7 @@ var loadSchema = function loadSchema(version, done) { return; } } - loaded = true; + schemaVersionsLoaded[version] = true; if (typeof done == 'function') { done(null, schemasByVersion[version]); return; diff --git a/package-lock.json b/package-lock.json index 8fd04bde..71d8014e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@washingtonpost/ans-schema", - "version": "1.12.2", + "version": "1.12.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 7d7727ef..c8b7a61d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@washingtonpost/ans-schema", "description": "The Washington Post's Arc Native Specification", - "version": "1.12.2", + "version": "1.12.3", "homepage": "https://github.com/washingtonpost/ans-schema", "repository": { "type": "git",