From 4ebcd744c97e3a4c5068359512bba4b527afa550 Mon Sep 17 00:00:00 2001 From: cenfun Date: Fri, 16 Feb 2024 11:06:20 +0800 Subject: [PATCH] added warning for old collection comments --- CHANGELOG.md | 3 +++ lib/utils/util.js | 6 ++++-- lib/visitor.js | 17 +++++++++++++++-- tests/playwright.config.js | 8 +++++++- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3dd1854..2fa46d94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +* 2.3.2 + - added warning for old collection comments + * 2.3.1 - updated coverage reports diff --git a/lib/utils/util.js b/lib/utils/util.js index d4b1566b..cc87965c 100644 --- a/lib/utils/util.js +++ b/lib/utils/util.js @@ -13,10 +13,12 @@ const defaultOptions = require('../default/options.js'); const assetsName = 'assets'; const Util = { + ... Share, - root: process.cwd(), + EC, + CG, - ... Share, + root: process.cwd(), relativePath: function(p, root) { p = `${p}`; diff --git a/lib/visitor.js b/lib/visitor.js index e0c6390a..1825d3d6 100644 --- a/lib/visitor.js +++ b/lib/visitor.js @@ -7,6 +7,19 @@ const { const Util = require('./utils/util.js'); const commentsPlugin = require('./plugins/comments.js'); const defaultColumns = require('./default/columns.js'); + +// retired, just warning for old babel parser +let collectWarning = '"collect.comments()" has been deprecated (replaced with new option "customFieldsInComments: true/false" in version 2.2.0), please remove the code related to "collect.comments()" in custom "visitor".'; +const collect = new Proxy({}, { + get: function(obj, prop) { + if (collectWarning) { + Util.logError(collectWarning); + collectWarning = null; + } + return () => {}; + } +}); + class Visitor { constructor(root, options) { this.root = root; @@ -111,13 +124,13 @@ class Visitor { // for all data if (this.customCommonVisitor) { - await this.customCommonVisitor.call(this, data, metadata); + await this.customCommonVisitor.call(this, data, metadata, collect); } // for single column data (high priority) if (this.customVisitors) { for (const item of this.customVisitors) { - const res = await item.visitor.call(this, data, metadata); + const res = await item.visitor.call(this, data, metadata, collect); if (typeof res !== 'undefined') { data[item.id] = res; } diff --git a/tests/playwright.config.js b/tests/playwright.config.js index 87da7c7b..56cf6a1e 100644 --- a/tests/playwright.config.js +++ b/tests/playwright.config.js @@ -294,7 +294,7 @@ module.exports = { }, // additional custom visitor for columns - visitor: (data, metadata) => { + visitor: (data, metadata, collect) => { // remove secrets and sensitive data if (data.type === 'step') { @@ -314,6 +314,12 @@ module.exports = { } + // test issue #91 + const comments = collect.comments(); + if (comments) { + Object.assign(data, comments); + } + },