Skip to content

Commit bb243f0

Browse files
committed
process: add emitExperimentalWarning()
This adds process.emitExperimentalWarning() which can used to communicate to our users that a feature they are using is experimental and can be changed/removed at any time. Ref: nodejs#9036
1 parent 1fcd088 commit bb243f0

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/internal/process/warning.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const prefix = `(${process.release.name}:${process.pid}) `;
44

55
exports.setup = setupProcessWarnings;
66

7+
const experimentalWarnings = new Set();
8+
79
function setupProcessWarnings() {
810
if (!process.noProcessWarnings) {
911
process.on('warning', (warning) => {
@@ -46,4 +48,12 @@ function setupProcessWarnings() {
4648
}
4749
process.nextTick(() => process.emit('warning', warning));
4850
};
51+
52+
process.emitExperimentalWarning = function(feature) {
53+
if (experimentalWarnings.has(feature)) return;
54+
experimentalWarnings.add(feature);
55+
const msg = `${feature} is an experimental feature. ` +
56+
'This feature could change at any time.';
57+
process.emitWarning(msg, 'ExperimentalWarning');
58+
};
4959
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
const warning = 'new_feature is an experimental feature. This feature could ' +
6+
'change at any time.';
7+
common.expectWarning('ExperimentalWarning', warning);
8+
process.emitExperimentalWarning('new_feature');
9+
process.emitExperimentalWarning('new_feature');

0 commit comments

Comments
 (0)